From 8b5264725390f387e6eaac6fb157ad6b6d57871d Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 6 Sep 2024 19:22:24 +0530 Subject: [PATCH 1/3] feat(#58): add conway related protocol parameters --- .../src/Blockfrost/Types/Cardano/Epochs.hs | 46 ++++++++++++++++++- blockfrost-api/test/Cardano/Epochs.hs | 46 ++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs b/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs index a0c8df6..3114f21 100644 --- a/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs +++ b/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs @@ -88,10 +88,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 Integer } 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 @@ -128,6 +150,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) } diff --git a/blockfrost-api/test/Cardano/Epochs.hs b/blockfrost-api/test/Cardano/Epochs.hs index ffd78b1..29b5045 100644 --- a/blockfrost-api/test/Cardano/Epochs.hs +++ b/blockfrost-api/test/Cardano/Epochs.hs @@ -110,7 +110,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 } |] @@ -164,6 +186,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| From 08eea3cb4519d7a21fb4f4d31f236bb779a5c505 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Fri, 6 Sep 2024 19:39:32 +0530 Subject: [PATCH 2/3] feat(#58): change underlying type of `_protocolParamsMinFeeRefScriptCostPerByte` to `Rational` from `Integer` --- blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs b/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs index 3114f21..4206c47 100644 --- a/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs +++ b/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs @@ -109,7 +109,7 @@ data ProtocolParams = ProtocolParams , _protocolParamsGovActionDeposit :: Maybe Lovelaces , _protocolParamsDrepDeposit :: Maybe Lovelaces , _protocolParamsDrepActivity :: Maybe Quantity - , _protocolParamsMinFeeRefScriptCostPerByte :: Maybe Integer + , _protocolParamsMinFeeRefScriptCostPerByte :: Maybe Rational } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) From a0247472e3932a5cad523d8566a4404130ca6747 Mon Sep 17 00:00:00 2001 From: sourabhxyz Date: Mon, 16 Sep 2024 17:01:37 +0530 Subject: [PATCH 3/3] feat(#58): add `cost_models_raw` --- .../src/Blockfrost/Types/Cardano/Epochs.hs | 52 +++++++++++++++++++ blockfrost-api/test/Cardano/Epochs.hs | 33 ++++++++++++ 2 files changed, 85 insertions(+) diff --git a/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs b/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs index 4206c47..621bca3 100644 --- a/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs +++ b/blockfrost-api/src/Blockfrost/Types/Cardano/Epochs.hs @@ -5,6 +5,7 @@ module Blockfrost.Types.Cardano.Epochs , PoolStakeDistribution (..) , ProtocolParams (..) , CostModels (..) + , CostModelsRaw (..) , StakeDistribution (..) ) where @@ -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 @@ -139,6 +141,7 @@ instance ToSample ProtocolParams where , _protocolParamsMinPoolCost = 340000000 , _protocolParamsNonce = "1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81" , _protocolParamsCostModels = costModelsSample + , _protocolParamsCostModelsRaw = costModelsRawSample , _protocolParamsPriceMem = 0.0577 , _protocolParamsPriceStep = 0.0000721 , _protocolParamsMaxTxExMem = 10000000 @@ -213,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 @@ -233,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 diff --git a/blockfrost-api/test/Cardano/Epochs.hs b/blockfrost-api/test/Cardano/Epochs.hs index 29b5045..679c436 100644 --- a/blockfrost-api/test/Cardano/Epochs.hs +++ b/blockfrost-api/test/Cardano/Epochs.hs @@ -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", @@ -174,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