Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update maestro sdk #343

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ cabal.project.local~
maestro-config.json
blockfrost-config.json
*.skey
.direnv
.direnv
.vscode
secrets
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ package strict-containers
source-repository-package
type: git
location: https://github.com/maestro-org/haskell-sdk
tag: d70479ce3be06d6b7c52bf39d783f36d6771e36d
--sha256: sha256-8se+xlIB1BDEuKGwjaldmW5G4LpCujD1ABgBaY0cY6Y=
tag: v1.7.2
--sha256: sha256-nXnelHH4a+V0nguP8oUDlyEz/fLQ/i1fs/flyZTmvAc=

source-repository-package
type: git
Expand Down
63 changes: 23 additions & 40 deletions src/GeniusYield/Providers/Maestro.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Control.Exception (try)
import Control.Monad ((<=<))
import qualified Data.Aeson as Aeson
import Data.Either.Combinators (maybeToRight)
import Data.Int (Int64)
import qualified Data.Map.Strict as M
import Data.Maybe (fromJust)
import qualified Data.Set as Set
Expand Down Expand Up @@ -437,45 +438,45 @@ maestroProtocolParams env = do
Maestro.ProtocolParameters {..} <- handleMaestroError "ProtocolParams" <=< try $ Maestro.getTimestampedData <$> Maestro.getProtocolParameters env
pure $
Api.S.ProtocolParameters
{ protocolParamProtocolVersion = (Maestro.protocolVersionMajor protocolParametersProtocolVersion, Maestro.protocolVersionMinor protocolParametersProtocolVersion)
{ protocolParamProtocolVersion = (Maestro.protocolVersionMajor protocolParametersVersion, Maestro.protocolVersionMinor protocolParametersVersion)
, protocolParamDecentralization = Nothing -- Also known as `d`, got deprecated in Babbage.
, protocolParamExtraPraosEntropy = Nothing -- Also known as `extraEntropy`, got deprecated in Babbage.
, protocolParamMaxBlockHeaderSize = protocolParametersMaxBlockHeaderSize
, protocolParamMaxBlockBodySize = protocolParametersMaxBlockBodySize
, protocolParamMaxTxSize = protocolParametersMaxTxSize
, protocolParamTxFeeFixed = Api.Lovelace $ toInteger protocolParametersMinFeeConstant
, protocolParamMaxBlockHeaderSize = Maestro.asBytesBytes protocolParametersMaxBlockHeaderSize
, protocolParamMaxBlockBodySize = Maestro.asBytesBytes protocolParametersMaxBlockBodySize
, protocolParamMaxTxSize = Maestro.asBytesBytes protocolParametersMaxTransactionSize
, protocolParamTxFeeFixed = Api.Lovelace $ toInteger $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersMinFeeConstant
, protocolParamTxFeePerByte = Api.Lovelace $ toInteger protocolParametersMinFeeCoefficient
, protocolParamMinUTxOValue = Nothing -- Deprecated in Alonzo.
, protocolParamStakeAddressDeposit = Api.Lovelace $ toInteger protocolParametersStakeKeyDeposit
, protocolParamStakePoolDeposit = Api.Lovelace $ toInteger protocolParametersPoolDeposit
, protocolParamMinPoolCost = Api.Lovelace $ toInteger protocolParametersMinPoolCost
, protocolParamStakeAddressDeposit = Api.Lovelace $ toInteger $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersStakeCredentialDeposit
, protocolParamStakePoolDeposit = Api.Lovelace $ toInteger $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersStakePoolDeposit
, protocolParamMinPoolCost = Api.Lovelace $ toInteger $ Maestro.asLovelaceLovelace $ Maestro.asAdaAda protocolParametersMinStakePoolCost
, protocolParamPoolRetireMaxEpoch = Ledger.EpochInterval . fromIntegral
$ Maestro.unEpochNo protocolParametersPoolRetirementEpochBound
, protocolParamStakePoolTargetNum = protocolParametersDesiredNumberOfPools
, protocolParamPoolPledgeInfluence = Maestro.unMaestroRational protocolParametersPoolInfluence
$ Maestro.unEpochNo protocolParametersStakePoolRetirementEpochBound
, protocolParamStakePoolTargetNum = protocolParametersDesiredNumberOfStakePools
, protocolParamPoolPledgeInfluence = Maestro.unMaestroRational protocolParametersStakePoolPledgeInfluence
, protocolParamMonetaryExpansion = Maestro.unMaestroRational protocolParametersMonetaryExpansion
, protocolParamTreasuryCut = Maestro.unMaestroRational protocolParametersTreasuryExpansion
, protocolParamPrices = Just $ Api.S.ExecutionUnitPrices
(Maestro.unMaestroRational $ Maestro.memoryStepsWithSteps protocolParametersPrices)
(Maestro.unMaestroRational $ Maestro.memoryStepsWithMemory protocolParametersPrices)
(Maestro.unMaestroRational $ Maestro.memoryCpuWithCpu protocolParametersScriptExecutionPrices)
(Maestro.unMaestroRational $ Maestro.memoryCpuWithMemory protocolParametersScriptExecutionPrices)
, protocolParamMaxTxExUnits = Just $ Api.ExecutionUnits
(Maestro.memoryStepsWithSteps protocolParametersMaxExecutionUnitsPerTransaction)
(Maestro.memoryStepsWithMemory protocolParametersMaxExecutionUnitsPerTransaction)
(Maestro.memoryCpuWithCpu protocolParametersMaxExecutionUnitsPerTransaction)
(Maestro.memoryCpuWithMemory protocolParametersMaxExecutionUnitsPerTransaction)
, protocolParamMaxBlockExUnits = Just $ Api.ExecutionUnits
(Maestro.memoryStepsWithSteps protocolParametersMaxExecutionUnitsPerBlock)
(Maestro.memoryStepsWithMemory protocolParametersMaxExecutionUnitsPerBlock)
, protocolParamMaxValueSize = Just protocolParametersMaxValueSize
(Maestro.memoryCpuWithCpu protocolParametersMaxExecutionUnitsPerBlock)
(Maestro.memoryCpuWithMemory protocolParametersMaxExecutionUnitsPerBlock)
, protocolParamMaxValueSize = Just $ Maestro.asBytesBytes protocolParametersMaxValueSize
, protocolParamCollateralPercent = Just protocolParametersCollateralPercentage
, protocolParamMaxCollateralInputs = Just protocolParametersMaxCollateralInputs
, protocolParamCostModels = M.fromList
[ ( Api.S.AnyPlutusScriptVersion Api.PlutusScriptV1
, Api.CostModel $ M.elems $ coerce $ Maestro.costModelsPlutusV1 protocolParametersCostModels
, Api.CostModel $ fromIntegral <$> coerce @_ @[Int64] (Maestro.costModelsPlutusV1 protocolParametersPlutusCostModels)
)
, ( Api.S.AnyPlutusScriptVersion Api.PlutusScriptV2
, Api.CostModel $ M.elems $ coerce $ Maestro.costModelsPlutusV2 protocolParametersCostModels
, Api.CostModel $ fromIntegral <$> coerce @_ @[Int64] (Maestro.costModelsPlutusV2 protocolParametersPlutusCostModels)
)
]
, protocolParamUTxOCostPerByte = Just . Api.Lovelace $ toInteger protocolParametersCoinsPerUtxoByte
, protocolParamUTxOCostPerByte = Just . Api.Lovelace $ toInteger protocolParametersMinUtxoDepositCoefficient
}

-- | Returns a set of all Stake Pool's 'Api.S.PoolId'.
Expand All @@ -501,25 +502,7 @@ maestroSystemStart env = fmap (CTime.SystemStart . Time.localTimeToUTC Time.utc)

-- | Returns the 'Api.EraHistory' queried from Maestro.
maestroEraHistory :: Maestro.MaestroEnv 'Maestro.V1 -> IO Api.EraHistory
maestroEraHistory env = do
eraSumms <- handleMaestroError "EraHistory" =<< try (Maestro.getTimestampedData <$> Maestro.getEraHistory env)
maybe (throwIO $ MspvIncorrectEraHistoryLength eraSumms) pure $ parseEraHist mkEra eraSumms
where
mkBound Maestro.EraBound {eraBoundEpoch, eraBoundSlot, eraBoundTime} = Ouroboros.Bound
{ boundTime = CTime.RelativeTime eraBoundTime
, boundSlot = CSlot.SlotNo $ fromIntegral eraBoundSlot
, boundEpoch = CSlot.EpochNo $ fromIntegral eraBoundEpoch
}
mkEraParams Maestro.EraParameters {eraParametersEpochLength, eraParametersSlotLength, eraParametersSafeZone} = Ouroboros.EraParams
{ eraEpochSize = CSlot.EpochSize $ fromIntegral eraParametersEpochLength
, eraSlotLength = CTime.mkSlotLength eraParametersSlotLength
, eraSafeZone = Ouroboros.StandardSafeZone $ fromJust eraParametersSafeZone
}
mkEra Maestro.EraSummary {eraSummaryStart, eraSummaryEnd, eraSummaryParameters} = Ouroboros.EraSummary
{ eraStart = mkBound eraSummaryStart
, eraEnd = maybe Ouroboros.EraUnbounded (Ouroboros.EraEnd . mkBound) eraSummaryEnd
, eraParams = mkEraParams eraSummaryParameters
}
maestroEraHistory _ = pure $ Api.EraHistory mainnetEraHist

-------------------------------------------------------------------------------
-- Datum lookup
Expand Down