import { CostModels, parseCostModels } from "./cost-model"; export type RawProtocolParamUpdate = Map< number, | bigint | number | [number, number] | [bigint, bigint] | RawCostModels | RawExUnitPrices | RawPoolVotingThresholds | RawDRepVotingThresholds >; // costmdls = // { ? 0 : [ 166* int ] ; Plutus v1, only 166 integers are used, but more are accepted (and ignored) // , ? 1 : [ 175* int ] ; Plutus v2, only 175 integers are used, but more are accepted (and ignored) // , ? 2 : [ 233* int ] ; Plutus v3, only 233 integers are used, but more are accepted (and ignored) // , ? 3 : [ int ] ; Any 8-bit unsigned number can be used as a key. // } type RawCostModels = Map; // ex_unit_prices = // [ mem_price: nonnegative_interval, step_price: nonnegative_interval ] type RawExUnitPrices = [[bigint, bigint], [bigint, bigint]]; type RawUnitInterval = [number | bigint, number | bigint]; // pool_voting_thresholds = // [ unit_interval ; motion no confidence // , unit_interval ; committee normal // , unit_interval ; committee no confidence // , unit_interval ; hard fork initiation // , unit_interval ; security relevant parameter voting threshold // ] type RawPoolVotingThresholds = RawUnitInterval[]; // drep_voting_thresholds = // [ unit_interval ; motion no confidence // , unit_interval ; committee normal // , unit_interval ; committee no confidence // , unit_interval ; update constitution // , unit_interval ; hard fork initiation // , unit_interval ; PP network group // , unit_interval ; PP economic group // , unit_interval ; PP technical group // , unit_interval ; PP governance group // , unit_interval ; treasury withdrawal // ] type RawDRepVotingThresholds = RawUnitInterval[]; export type ProtocolParamUpdate = { minFeeA?: number | bigint; minFeeB?: number | bigint; maxBlockBodySize?: number | bigint; maxTransactionSize?: number | bigint; maxBlockHeaderSize?: number | bigint; keyDeposit?: number | bigint; poolDeposit?: number | bigint; maximumEpoch?: number | bigint; nOpt?: number | bigint; poolPledgeInfluence?: NonNegativeInterval; expansionRate?: UintInterval; treasuryGrowthRate?: UintInterval; minPoolCost?: number | bigint; adaPerUtxoByte?: number | bigint; costModels?: CostModels; executionCosts?: ExUnitPrices; maxTxExUnits?: ExUnits; maxBlockExUnits?: ExUnits; maxValueSize?: number | bigint; collateralPercentage?: number | bigint; maxCollateralInputs?: number | bigint; poolVotingThresholds?: PoolVotingThresholds; drepVotingThresholds?: DRepVotingThresholds; minCommitteeSize?: number | bigint; committeeTermList?: number | bigint; governanceActionValidityPeriod?: number | bigint; governanceActoinDeposit?: number | bigint; drepDeposit?: number | bigint; drepInactivityPeriod?: number | bigint; minfeeRefScriptCostPerByte?: NonNegativeInterval; }; type NonNegativeNumber = number; export type UintInterval = [number | bigint, number | bigint]; type NonNegativeInterval = [NonNegativeNumber, NonNegativeNumber]; type ExUnitPrices = { memPrice: NonNegativeInterval; stepPrice: NonNegativeInterval; }; function parseExUnitPrices(exUnitPrices: any[]): ExUnitPrices { return { memPrice: exUnitPrices[0], stepPrice: exUnitPrices[1] }; } export type ExUnits = [number | bigint, number | bigint]; type PoolVotingThresholds = { motionNoConfidence: UintInterval; committeeNormal: UintInterval; committeeNoConfidence: UintInterval; hardForkInitiation: UintInterval; securityRelevantParameterVoringThreshold: UintInterval; }; function parsePoolVotingThresholds(poolVotingThresholds: any[]): PoolVotingThresholds { return { motionNoConfidence: poolVotingThresholds[0], committeeNormal: poolVotingThresholds[1], committeeNoConfidence: poolVotingThresholds[2], hardForkInitiation: poolVotingThresholds[3], securityRelevantParameterVoringThreshold: poolVotingThresholds[4], }; } type DRepVotingThresholds = { motionNoConfidence: UintInterval; committeeNormal: UintInterval; committeeNoConfidence: UintInterval; updateConstitution: UintInterval; hardForkInitiation: UintInterval; ppNetworkGroup: UintInterval; ppEconomicGroup: UintInterval; ppTechnicalGroup: UintInterval; ppGovernanceGroup: UintInterval; treasuryWithdrawal: UintInterval; }; function parseDRepVotingThresholds(dRepVotingThresholds: any[]): DRepVotingThresholds { return { motionNoConfidence: dRepVotingThresholds[0], committeeNormal: dRepVotingThresholds[1], committeeNoConfidence: dRepVotingThresholds[2], updateConstitution: dRepVotingThresholds[3], hardForkInitiation: dRepVotingThresholds[4], ppNetworkGroup: dRepVotingThresholds[5], ppEconomicGroup: dRepVotingThresholds[6], ppTechnicalGroup: dRepVotingThresholds[7], ppGovernanceGroup: dRepVotingThresholds[8], treasuryWithdrawal: dRepVotingThresholds[9], }; } export function parseProtocolParams(pParams: Map): ProtocolParamUpdate { const minFeeA = pParams.get(0) ? pParams.get(0) : undefined; const minFeeB = pParams.get(1) ? pParams.get(1) : undefined; const maxBlockBodySize = pParams.get(2) ? pParams.get(2) : undefined; const maxTransactionSize = pParams.get(3) ? pParams.get(3) : undefined; const maxBlockHeaderSize = pParams.get(4) ? pParams.get(4) : undefined; const keyDeposit = pParams.get(5) ? pParams.get(5) : undefined; const poolDeposit = pParams.get(6) ? pParams.get(6) : undefined; const maximumEpoch = pParams.get(7) ? pParams.get(7) : undefined; const nOpt = pParams.get(8) ? pParams.get(8) : undefined; const poolPledgeInfluence = pParams.get(9) ? pParams.get(9) : undefined; const expansionRate = pParams.get(10) ? pParams.get(10) : undefined; const treasuryGrowthRate = pParams.get(11) ? pParams.get(11) : undefined; const minPoolCost = pParams.get(16) ? pParams.get(16) : undefined; const adaPerUtxoByte = pParams.get(17) ? pParams.get(17) : undefined; const costModels = pParams.get(18) ? parseCostModels(pParams.get(18)) : undefined; const executionCosts = pParams.get(19) ? parseExUnitPrices(pParams.get(19)) : undefined; const maxTxExUnits = pParams.get(20) ? pParams.get(20) : undefined; const maxBlockExUnits = pParams.get(21) ? pParams.get(21) : undefined; const maxValueSize = pParams.get(22) ? pParams.get(22) : undefined; const collateralPercentage = pParams.get(23) ? pParams.get(23) : undefined; const maxCollateralInputs = pParams.get(24) ? pParams.get(24) : undefined; const poolVotingThresholds = pParams.get(25) ? parsePoolVotingThresholds(pParams.get(25)) : undefined; const drepVotingThresholds = pParams.get(26) ? parseDRepVotingThresholds(pParams.get(26)) : undefined; const minCommitteeSize = pParams.get(27) ? pParams.get(27) : undefined; const committeeTermList = pParams.get(28) ? pParams.get(28) : undefined; const governanceActionValidityPeriod = pParams.get(29) ? pParams.get(29) : undefined; const governanceActoinDeposit = pParams.get(30) ? pParams.get(30) : undefined; const drepDeposit = pParams.get(31) ? pParams.get(31) : undefined; const drepInactivityPeriod = pParams.get(32) ? pParams.get(32) : undefined; const minfeeRefScriptCostPerByte = pParams.get(33) ? pParams.get(33) : undefined; return { minFeeA: minFeeA, minFeeB: minFeeB, maxBlockBodySize: maxBlockBodySize, maxTransactionSize: maxTransactionSize, maxBlockHeaderSize: maxBlockHeaderSize, keyDeposit: keyDeposit, poolDeposit: poolDeposit, maximumEpoch: maximumEpoch, nOpt: nOpt, poolPledgeInfluence: poolPledgeInfluence, expansionRate: expansionRate, treasuryGrowthRate: treasuryGrowthRate, minPoolCost: minPoolCost, adaPerUtxoByte: adaPerUtxoByte, costModels: costModels, executionCosts: executionCosts, maxTxExUnits: maxTxExUnits, maxBlockExUnits: maxBlockExUnits, maxValueSize: maxValueSize, collateralPercentage: collateralPercentage, maxCollateralInputs: maxCollateralInputs, poolVotingThresholds: poolVotingThresholds, drepVotingThresholds: drepVotingThresholds, minCommitteeSize: minCommitteeSize, committeeTermList: committeeTermList, governanceActionValidityPeriod: governanceActionValidityPeriod, governanceActoinDeposit: governanceActoinDeposit, drepDeposit: drepDeposit, drepInactivityPeriod: drepInactivityPeriod, minfeeRefScriptCostPerByte: minfeeRefScriptCostPerByte, }; }