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(#58): add conway related protocol parameters #59

Merged
merged 3 commits into from
Sep 19, 2024
Merged
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
98 changes: 97 additions & 1 deletion blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Blockfrost.Types.Cardano.Epochs
, PoolStakeDistribution (..)
, ProtocolParams (..)
, CostModels (..)
, CostModelsRaw (..)
, StakeDistribution (..)
) where

Expand Down Expand Up @@ -77,6 +78,7 @@ data ProtocolParams = ProtocolParams
, _protocolParamsMinPoolCost :: Lovelaces -- ^ Minimum stake cost forced on the pool
, _protocolParamsNonce :: Text -- ^ Epoch number only used once
, _protocolParamsCostModels :: CostModels -- ^ Cost models parameters for Plutus Core scripts
, _protocolParamsCostModelsRaw :: CostModelsRaw
, _protocolParamsPriceMem :: Rational -- ^ The per word cost of script memory usage
, _protocolParamsPriceStep :: Rational -- ^ The cost of script execution step usage
, _protocolParamsMaxTxExMem :: Quantity -- ^ The maximum number of execution memory allowed to be used in a single transaction
Expand All @@ -88,10 +90,32 @@ data ProtocolParams = ProtocolParams
, _protocolParamsMaxCollateralInputs :: Integer -- ^ The maximum number of collateral inputs allowed in a transaction
, _protocolParamsCoinsPerUtxoSize :: Lovelaces -- ^ The cost per UTxO size. Cost per UTxO *word* for Alozno. Cost per UTxO *byte* for Babbage and later
, _protocolParamsCoinsPerUtxoWord :: Lovelaces -- ^ The cost per UTxO word (DEPRECATED)
, _protocolParamsPvtMotionNoConfidence :: Maybe Rational
, _protocolParamsPvtCommitteeNormal :: Maybe Rational
, _protocolParamsPvtCommitteeNoConfidence :: Maybe Rational
, _protocolParamsPvtHardForkInitiation :: Maybe Rational
, _protocolParamsPvtppSecurityGroup :: Maybe Rational
, _protocolParamsDvtMotionNoConfidence :: Maybe Rational
, _protocolParamsDvtCommitteeNormal :: Maybe Rational
, _protocolParamsDvtCommitteeNoConfidence :: Maybe Rational
, _protocolParamsDvtUpdateToConstitution :: Maybe Rational
, _protocolParamsDvtHardForkInitiation :: Maybe Rational
, _protocolParamsDvtPPNetworkGroup :: Maybe Rational
, _protocolParamsDvtPPEconomicGroup :: Maybe Rational
, _protocolParamsDvtPPTechnicalGroup :: Maybe Rational
, _protocolParamsDvtPPGovGroup :: Maybe Rational
, _protocolParamsDvtTreasuryWithdrawal :: Maybe Rational
, _protocolParamsCommitteeMinSize :: Maybe Quantity
, _protocolParamsCommitteeMaxTermLength :: Maybe Quantity
, _protocolParamsGovActionLifetime :: Maybe Quantity
, _protocolParamsGovActionDeposit :: Maybe Lovelaces
, _protocolParamsDrepDeposit :: Maybe Lovelaces
, _protocolParamsDrepActivity :: Maybe Quantity
, _protocolParamsMinFeeRefScriptCostPerByte :: Maybe Rational
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is chosen as Maybe Rational instead of Maybe Integer as corresponding type defined in cardano-ledger codebase is (loosely put) Ratio Word64.

}
deriving stock (Show, Eq, Generic)
deriving (FromJSON, ToJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "_protocolParams", CamelToSnake]] ProtocolParams
via CustomJSON '[FieldLabelModifier '[StripPrefix "_protocolParams", CamelToSnake, Rename "dvt_pp_network_group" "dvt_p_p_network_group", Rename "dvt_pp_economic_group" "dvt_p_p_economic_group", Rename "dvt_pp_technical_group" "dvt_p_p_technical_group", Rename "dvt_pp_gov_group" "dvt_p_p_gov_group"]] ProtocolParams

instance ToSample ProtocolParams where
toSamples = pure $ singleSample
Expand All @@ -117,6 +141,7 @@ instance ToSample ProtocolParams where
, _protocolParamsMinPoolCost = 340000000
, _protocolParamsNonce = "1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81"
, _protocolParamsCostModels = costModelsSample
, _protocolParamsCostModelsRaw = costModelsRawSample
, _protocolParamsPriceMem = 0.0577
, _protocolParamsPriceStep = 0.0000721
, _protocolParamsMaxTxExMem = 10000000
Expand All @@ -128,6 +153,28 @@ instance ToSample ProtocolParams where
, _protocolParamsMaxCollateralInputs = 3
, _protocolParamsCoinsPerUtxoSize = 34482
, _protocolParamsCoinsPerUtxoWord = 34482
, _protocolParamsPvtMotionNoConfidence = Just 0.51
, _protocolParamsPvtCommitteeNormal = Just 0.51
, _protocolParamsPvtCommitteeNoConfidence = Just 0.51
, _protocolParamsPvtHardForkInitiation = Just 0.51
, _protocolParamsPvtppSecurityGroup = Just 0.51
, _protocolParamsDvtMotionNoConfidence = Just 0.67
, _protocolParamsDvtCommitteeNormal = Just 0.67
, _protocolParamsDvtCommitteeNoConfidence = Just 0.6
, _protocolParamsDvtUpdateToConstitution = Just 0.75
, _protocolParamsDvtHardForkInitiation = Just 0.6
, _protocolParamsDvtPPNetworkGroup = Just 0.67
, _protocolParamsDvtPPEconomicGroup = Just 0.67
, _protocolParamsDvtPPTechnicalGroup = Just 0.67
, _protocolParamsDvtPPGovGroup = Just 0.75
, _protocolParamsDvtTreasuryWithdrawal = Just 0.67
, _protocolParamsCommitteeMinSize = Just 7
, _protocolParamsCommitteeMaxTermLength = Just 146
, _protocolParamsGovActionLifetime = Just 6
, _protocolParamsGovActionDeposit = Just 100000000000
, _protocolParamsDrepDeposit = Just 500000000
, _protocolParamsDrepActivity = Just 20
, _protocolParamsMinFeeRefScriptCostPerByte = Just 15
}

newtype CostModels = CostModels { unCostModels :: Map ScriptType (Map Text Integer) }
Expand Down Expand Up @@ -169,6 +216,37 @@ instance FromJSON CostModels where

pure $ CostModels $ Data.Map.fromList langs

newtype CostModelsRaw = CostModelsRaw { unCostModelsRaw :: Map ScriptType [Integer] }
deriving (Eq, Show, Generic)

instance ToJSON CostModelsRaw where
toJSON =
object
. map (\(lang, params) ->
( Data.Aeson.Key.fromString $ show lang
, toJSON params)
)
. Data.Map.toList
. unCostModelsRaw

instance FromJSON CostModelsRaw where
parseJSON = withObject "CostModelsRaw" $ \o -> do
langs <- mapM
(\(kLang, vParams) -> do
l <- parseJSON
$ toJSON
$ (\lang -> case lang of
[] -> fail "Absurd empty language in CostModelsRaw"
(x:xs) -> Data.Char.toLower x:xs
)
$ Data.Aeson.Key.toString kLang
ps <- parseJSON vParams
pure (l, ps)
)
$ Data.Aeson.KeyMap.toList o

pure $ CostModelsRaw $ Data.Map.fromList langs

costModelsSample :: CostModels
costModelsSample = CostModels
$ Data.Map.fromList
Expand All @@ -189,6 +267,24 @@ costModelsSample = CostModels
instance ToSample CostModels where
toSamples = pure $ singleSample costModelsSample

costModelsRawSample :: CostModelsRaw
costModelsRawSample = CostModelsRaw
$ Data.Map.fromList
[ ( PlutusV1
, [ 197209
, 0
]
)
, (PlutusV2
, [ 197209
, 0
]
)
]

instance ToSample CostModelsRaw where
toSamples = pure $ singleSample costModelsRawSample

-- | Active stake distribution for an epoch
data StakeDistribution = StakeDistribution
{ _stakeDistributionStakeAddress :: Address -- ^ Stake address
Expand Down
79 changes: 78 additions & 1 deletion blockfrost-api/test/Cardano/Epochs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ protocolParamsSample = [r|
"addInteger-cpu-arguments-slope": 0
}
},
"cost_models_raw": {
"PlutusV1": [
197209,
0
],
"PlutusV2": [
197209,
0
],
"PlutusV3": [
197209,
0
]
},
"price_mem": 0.0577,
"price_step": 0.0000721,
"max_tx_ex_mem": "10000000",
Expand All @@ -110,7 +124,29 @@ protocolParamsSample = [r|
"collateral_percent": 150,
"max_collateral_inputs": 3,
"coins_per_utxo_size": "34482",
"coins_per_utxo_word": "34482"
"coins_per_utxo_word": "34482",
"pvt_motion_no_confidence": 0.51,
"pvt_committee_normal": 0.51,
"pvt_committee_no_confidence": 0.51,
"pvt_hard_fork_initiation": 0.51,
"dvt_motion_no_confidence": 0.67,
"dvt_committee_normal": 0.67,
"dvt_committee_no_confidence": 0.6,
"dvt_update_to_constitution": 0.75,
"dvt_hard_fork_initiation": 0.6,
"dvt_p_p_network_group": 0.67,
"dvt_p_p_economic_group": 0.67,
"dvt_p_p_technical_group": 0.67,
"dvt_p_p_gov_group": 0.75,
"dvt_treasury_withdrawal": 0.67,
"committee_min_size": "7",
"committee_max_term_length": "146",
"gov_action_lifetime": "6",
"gov_action_deposit": "100000000000",
"drep_deposit": "500000000",
"drep_activity": "20",
"pvtpp_security_group": 0.51,
"min_fee_ref_script_cost_per_byte": 15
}
|]

Expand Down Expand Up @@ -152,6 +188,25 @@ protocolParamsExpected =
]
)
]
, _protocolParamsCostModelsRaw =
CostModelsRaw
$ Data.Map.fromList
[ ( PlutusV1
, [ 197209
, 0
]
)
, (PlutusV2
, [ 197209
, 0
]
)
, (PlutusV3
, [ 197209
, 0
]
)
]
, _protocolParamsPriceMem = 0.0577
, _protocolParamsPriceStep = 0.0000721
, _protocolParamsMaxTxExMem = 10000000
Expand All @@ -164,6 +219,28 @@ protocolParamsExpected =
, _protocolParamsCoinsPerUtxoSize = 34482
-- deprecated
, _protocolParamsCoinsPerUtxoWord = 34482
, _protocolParamsPvtMotionNoConfidence = Just 0.51
, _protocolParamsPvtCommitteeNormal = Just 0.51
, _protocolParamsPvtCommitteeNoConfidence = Just 0.51
, _protocolParamsPvtHardForkInitiation = Just 0.51
, _protocolParamsPvtppSecurityGroup = Just 0.51
, _protocolParamsDvtMotionNoConfidence = Just 0.67
, _protocolParamsDvtCommitteeNormal = Just 0.67
, _protocolParamsDvtCommitteeNoConfidence = Just 0.6
, _protocolParamsDvtUpdateToConstitution = Just 0.75
, _protocolParamsDvtHardForkInitiation = Just 0.6
, _protocolParamsDvtPPNetworkGroup = Just 0.67
, _protocolParamsDvtPPEconomicGroup = Just 0.67
, _protocolParamsDvtPPTechnicalGroup = Just 0.67
, _protocolParamsDvtPPGovGroup = Just 0.75
, _protocolParamsDvtTreasuryWithdrawal = Just 0.67
, _protocolParamsCommitteeMinSize = Just 7
, _protocolParamsCommitteeMaxTermLength = Just 146
, _protocolParamsGovActionLifetime = Just 6
, _protocolParamsGovActionDeposit = Just 100000000000
, _protocolParamsDrepDeposit = Just 500000000
, _protocolParamsDrepActivity = Just 20
, _protocolParamsMinFeeRefScriptCostPerByte = Just 15
}

stakeDistributionSample = [r|
Expand Down