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/lw 9927 review protocol params update #1212

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -67,11 +67,12 @@ export const toProtocolParams = ({
governance_action_validity_period,
governance_action_deposit,
drep_deposit,
drep_inactivity_period
drep_inactivity_period,
min_fee_ref_script_cost_per_byte
}: ProtocolParamsModel): Cardano.ProtocolParameters => ({
coinsPerUtxoByte: Number(coins_per_utxo_size),
collateralPercentage: collateral_percent,
committeeTermLimit: Number(committee_term_limit),
committeeTermLimit: Cardano.EpochNo(committee_term_limit),
costModels: mapCostModels(costs),
dRepDeposit: Number(drep_deposit),
dRepInactivityPeriod: Cardano.EpochNo(drep_inactivity_period),
@@ -96,6 +97,7 @@ export const toProtocolParams = ({
minCommitteeSize: Number(min_committee_size),
minFeeCoefficient: min_fee_a,
minFeeConstant: min_fee_b,
minFeeRefScriptCostPerByte: String(min_fee_ref_script_cost_per_byte),
minPoolCost: Number(min_pool_cost),
monetaryExpansion: String(monetary_expand_rate),
poolDeposit: Number(pool_deposit),
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ export interface ProtocolParamsModel {
max_bh_size: number;
optimal_pool_count: number;
influence: number;
min_fee_ref_script_cost_per_byte: number;
monetary_expand_rate: number;
treasury_growth_rate: number;
decentralisation: number;
4 changes: 2 additions & 2 deletions packages/core/src/Cardano/types/Governance.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import * as Crypto from '@cardano-sdk/crypto';
import { Credential, CredentialType, RewardAccount } from '../Address';
import { EpochNo, Fraction, ProtocolVersion, TransactionId } from '.';
import { Lovelace } from './Value';
import { ProtocolParametersUpdate } from './ProtocolParameters';
import { ProtocolParametersUpdateConway } from './ProtocolParameters';

export type Anchor = {
url: string;
@@ -43,7 +43,7 @@ export type Constitution = {
export type ParameterChangeAction = {
__typename: GovernanceActionType.parameter_change_action;
governanceActionId: GovernanceActionId | null;
protocolParamUpdate: ProtocolParametersUpdate;
protocolParamUpdate: ProtocolParametersUpdateConway;
policyHash: Crypto.Hash28ByteBase16 | null;
};

19 changes: 11 additions & 8 deletions packages/core/src/Cardano/types/ProtocolParameters.ts
Original file line number Diff line number Diff line change
@@ -110,11 +110,13 @@ type BabbageProtocolParameters = Omit<AlonzoProtocolParams, 'coinsPerUtxoWord' |
export interface PoolVotingThresholds {
motionNoConfidence: Fraction;
committeeNormal: Fraction;
commiteeNoConfidence: Fraction;
committeeNoConfidence: Fraction;
hardForkInitiation: Fraction;
securityRelevantParamVotingThreshold: Fraction;
}

export interface DelegateRepresentativeThresholds extends PoolVotingThresholds {
export interface DelegateRepresentativeThresholds
extends Omit<PoolVotingThresholds, 'securityRelevantParamVotingThreshold'> {
updateConstitution: Fraction;
ppNetworkGroup: Fraction;
ppEconomicGroup: Fraction;
@@ -127,20 +129,21 @@ type NewProtocolParamsInConway = {
poolVotingThresholds: PoolVotingThresholds;
dRepVotingThresholds: DelegateRepresentativeThresholds;
minCommitteeSize: number;
committeeTermLimit: number;
committeeTermLimit: EpochNo;
governanceActionValidityPeriod: EpochNo;
governanceActionDeposit: number;
dRepDeposit: number;
dRepInactivityPeriod: EpochNo;
minFeeRefScriptCostPerByte: string;
};

type ConwayProtocolParameters = BabbageProtocolParameters & NewProtocolParamsInConway;
export type ProtocolParameters = BabbageProtocolParameters & NewProtocolParamsInConway;
export type ConwayProtocolParameters = Omit<ProtocolParameters, 'protocolVersion'>;

export type ProtocolParameters = ConwayProtocolParameters;

// Even tho extraEntropy was deprecated on babbage era, it is still present in the ProtocolParametersUpdate structure
// since this structure is backward compatible with all eras.
// Even tho extraEntropy was deprecated on babbage era, and protocolVersion was deprecated in conway era,
// they are still present in the ProtocolParametersUpdate structure since this structure is backward compatible with all eras.
export type ProtocolParametersUpdate = Partial<ProtocolParameters & Pick<AlonzoProtocolParams, 'extraEntropy'>>;
export type ProtocolParametersUpdateConway = Partial<ConwayProtocolParameters>;

export type GenesisDelegateKeyHash = Crypto.Hash28ByteBase16;
export type ProposedProtocolParameterUpdates = Map<GenesisDelegateKeyHash, ProtocolParametersUpdate>;
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ export class DrepVotingThresholds {
*/
toCore(): Cardano.DelegateRepresentativeThresholds {
return {
commiteeNoConfidence: this.#committeeNoConfidence.toCore(),
committeeNoConfidence: this.#committeeNoConfidence.toCore(),
committeeNormal: this.#committeeNormal.toCore(),
hardForkInitiation: this.#hardForkInitiation.toCore(),
motionNoConfidence: this.#motionNoConfidence.toCore(),
@@ -190,7 +190,7 @@ export class DrepVotingThresholds {
return new DrepVotingThresholds(
UnitInterval.fromCore(core.motionNoConfidence),
UnitInterval.fromCore(core.committeeNormal),
UnitInterval.fromCore(core.commiteeNoConfidence),
UnitInterval.fromCore(core.committeeNoConfidence),
UnitInterval.fromCore(core.updateConstitution),
UnitInterval.fromCore(core.hardForkInitiation),
UnitInterval.fromCore(core.ppNetworkGroup),
34 changes: 26 additions & 8 deletions packages/core/src/Serialization/Update/PoolVotingThresholds.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { CborReader, CborWriter } from '../CBOR';
import { HexBlob, InvalidArgumentError } from '@cardano-sdk/util';
import { UnitInterval } from '../Common';

const POOL_VOTING_THRESHOLDS_SIZE = 4;
const POOL_VOTING_THRESHOLDS_SIZE = 5;

/**
* Governance actions are ratified through on-chain voting. Different
@@ -17,6 +17,7 @@ export class PoolVotingThresholds {
#committeeNormal: UnitInterval;
#committeeNoConfidence: UnitInterval;
#hardForkInitiation: UnitInterval;
#securityRelevantParamVotingThreshold: UnitInterval;
#originalBytes: HexBlob | undefined = undefined;

/**
@@ -35,12 +36,14 @@ export class PoolVotingThresholds {
motionNoConfidence: UnitInterval,
committeeNormal: UnitInterval,
committeeNoConfidence: UnitInterval,
hardForkInitiation: UnitInterval
hardForkInitiation: UnitInterval,
securityRelevantParamVotingThreshold: UnitInterval
) {
this.#motionNoConfidence = motionNoConfidence;
this.#committeeNormal = committeeNormal;
this.#committeeNoConfidence = committeeNoConfidence;
this.#hardForkInitiation = hardForkInitiation;
this.#securityRelevantParamVotingThreshold = securityRelevantParamVotingThreshold;
}

/**
@@ -59,13 +62,15 @@ export class PoolVotingThresholds {
// , unit_interval ; committee normal
// , unit_interval ; committee no confidence
// , unit_interval ; hard fork initiation
// , unit_interval ; security relevant parameter voting threshold
// ]
writer.writeStartArray(POOL_VOTING_THRESHOLDS_SIZE);

writer.writeEncodedValue(Buffer.from(this.#motionNoConfidence.toCbor(), 'hex'));
writer.writeEncodedValue(Buffer.from(this.#committeeNormal.toCbor(), 'hex'));
writer.writeEncodedValue(Buffer.from(this.#committeeNoConfidence.toCbor(), 'hex'));
writer.writeEncodedValue(Buffer.from(this.#hardForkInitiation.toCbor(), 'hex'));
writer.writeEncodedValue(Buffer.from(this.#securityRelevantParamVotingThreshold.toCbor(), 'hex'));

return writer.encodeAsHex();
}
@@ -91,14 +96,16 @@ export class PoolVotingThresholds {
const committeeNormal = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
const committeeNoConfidence = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
const hardForkInitiation = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
const securityRelevantParamVotingThreshold = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));

reader.readEndArray();

const thresholds = new PoolVotingThresholds(
motionNoConfidence,
committeeNormal,
committeeNoConfidence,
hardForkInitiation
hardForkInitiation,
securityRelevantParamVotingThreshold
);

thresholds.#originalBytes = cbor;
@@ -107,16 +114,17 @@ export class PoolVotingThresholds {
}

/**
* Creates a Core PoolVotingThresholdsSHOLDS_SIZE object from the current PoolVotingThresholds object.
* Creates a Core PoolVotingThresholds object from the current PoolVotingThresholds object.
*
* @returns The Core Prices object.
*/
toCore(): Cardano.PoolVotingThresholds {
return {
commiteeNoConfidence: this.#committeeNoConfidence.toCore(),
committeeNoConfidence: this.#committeeNoConfidence.toCore(),
committeeNormal: this.#committeeNormal.toCore(),
hardForkInitiation: this.#hardForkInitiation.toCore(),
motionNoConfidence: this.#motionNoConfidence.toCore()
motionNoConfidence: this.#motionNoConfidence.toCore(),
securityRelevantParamVotingThreshold: this.#securityRelevantParamVotingThreshold.toCore()
};
}

@@ -129,8 +137,9 @@ export class PoolVotingThresholds {
return new PoolVotingThresholds(
UnitInterval.fromCore(core.motionNoConfidence),
UnitInterval.fromCore(core.committeeNormal),
UnitInterval.fromCore(core.commiteeNoConfidence),
UnitInterval.fromCore(core.hardForkInitiation)
UnitInterval.fromCore(core.committeeNoConfidence),
UnitInterval.fromCore(core.hardForkInitiation),
UnitInterval.fromCore(core.securityRelevantParamVotingThreshold)
);
}

@@ -223,4 +232,13 @@ export class PoolVotingThresholds {
hardForkInitiation(): UnitInterval {
return this.#hardForkInitiation;
}

/**
* Gets the security relevant parameter voting threshold
*
* @returns security relevant parameter voting threshold.
*/
securityRelevantParamVotingThreshold(): UnitInterval {
return this.#securityRelevantParamVotingThreshold;
}
}
38 changes: 32 additions & 6 deletions packages/core/src/Serialization/Update/ProtocolParamUpdate.ts
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ export class ProtocolParamUpdate {
#governanceActionDeposit: number | undefined;
#drepDeposit: number | undefined;
#drepInactivityPeriod: number | undefined;
#minFeeRefScriptCostPerByte: UnitInterval | undefined;
#originalBytes: HexBlob | undefined = undefined;

/**
@@ -90,6 +91,7 @@ export class ProtocolParamUpdate {
// , ? 30: coin ; governance action deposit
// , ? 31: coin ; DRep deposit
// , ? 32: epoch ; DRep inactivity period
// , ? 33: nonnegative_interval ; MinFee RefScriptCostPerByte
// }
writer.writeStartMap(this.#getMapSize());

@@ -254,6 +256,12 @@ export class ProtocolParamUpdate {
writer.writeInt(32n);
writer.writeInt(this.#drepInactivityPeriod);
}

if (this.#minFeeRefScriptCostPerByte) {
writer.writeInt(33n);
writer.writeEncodedValue(Buffer.from(this.#minFeeRefScriptCostPerByte.toCbor(), 'hex'));
}

return writer.encodeAsHex();
}

@@ -373,6 +381,9 @@ export class ProtocolParamUpdate {
case 32n:
params.#drepInactivityPeriod = Number(reader.readInt());
break;
case 33n:
params.#minFeeRefScriptCostPerByte = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
}
}

@@ -392,7 +403,7 @@ export class ProtocolParamUpdate {
return {
coinsPerUtxoByte: this.#adaPerUtxoByte ? Number(this.#adaPerUtxoByte) : undefined,
collateralPercentage: this.#collateralPercentage,
committeeTermLimit: this.#committeeTermLimit,
committeeTermLimit: this.#committeeTermLimit ? Cardano.EpochNo(this.#committeeTermLimit) : undefined,
costModels: this.#costModels?.toCore(),
dRepDeposit: this.#drepDeposit,
dRepInactivityPeriod: this.#drepInactivityPeriod ? Cardano.EpochNo(this.#drepInactivityPeriod) : undefined,
@@ -414,6 +425,9 @@ export class ProtocolParamUpdate {
minCommitteeSize: this.#minCommitteeSize,
minFeeCoefficient: this.#minFeeA ? Number(this.#minFeeA) : undefined,
minFeeConstant: this.#minFeeB ? Number(this.#minFeeB) : undefined,
minFeeRefScriptCostPerByte: this.#minFeeRefScriptCostPerByte
? this.#minFeeRefScriptCostPerByte.toFloat().toString()
: undefined,
minPoolCost: this.#minPoolCost ? Number(this.#minPoolCost) : undefined,
monetaryExpansion: this.#expansionRate ? this.#expansionRate.toFloat().toString() : undefined,
poolDeposit: this.#poolDeposit ? Number(this.#poolDeposit) : undefined,
@@ -432,7 +446,9 @@ export class ProtocolParamUpdate {
*
* @param parametersUpdate core parametersUpdate object.
*/
static fromCore(parametersUpdate: Cardano.ProtocolParametersUpdate) {
static fromCore<T extends Cardano.ProtocolParametersUpdateConway = Cardano.ProtocolParametersUpdate>(
parametersUpdate: T
) {
const params = new ProtocolParamUpdate();

params.#minFeeA = parametersUpdate.minFeeCoefficient ? BigInt(parametersUpdate.minFeeCoefficient) : undefined;
@@ -456,14 +472,10 @@ export class ProtocolParamUpdate {
? UnitInterval.fromFloat(Number(parametersUpdate.decentralizationParameter))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

decentralizationParameter was also removed in conway era.
I am investigating this and a few other serialization issues on the conway-era branch.
I will update this PR once the implementation is stable.

Copy link
Member

@AngelCastilloB AngelCastilloB Apr 18, 2024

Choose a reason for hiding this comment

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

decentralizationParameter was actually deprecated in babbage era, but there shouldn't be a need to remove this, that way the serialization utils can be use to serialize/deserialize older transactions too. When this fields are deprecated their key is no longer used (in this case I believe is 12), but no other field can take its place, so there is no harm on leaving them there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my particular case (e2e test), the raw txBuilder is passing a manually built protocol params to a conway params update proposal.
I am trying to prevent this by building the typesafe version of the fromCore when called via conway governance.
Otherwise, the effect is that txbuilder will build the tx for you, even if those protocol params were deprecated.
But the change will not cripple the ser/des part, it will only make it more restrictive when called from the gov path

Copy link
Member

Choose a reason for hiding this comment

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

thats a pretty good solution 🚀

: undefined;
params.#minPoolCost = parametersUpdate.minPoolCost ? BigInt(parametersUpdate.minPoolCost) : undefined;
params.#protocolVersion = parametersUpdate.protocolVersion
? ProtocolVersion.fromCore(parametersUpdate.protocolVersion)
: undefined;
params.#maxValueSize = parametersUpdate.maxValueSize;
params.#maxTxSize = parametersUpdate.maxTxSize;
params.#collateralPercentage = parametersUpdate.collateralPercentage;
params.#maxCollateralInputs = parametersUpdate.maxCollateralInputs;
params.#extraEntropy = parametersUpdate.extraEntropy ? HexBlob(parametersUpdate.extraEntropy) : undefined;
params.#costModels = parametersUpdate.costModels ? Costmdls.fromCore(parametersUpdate.costModels) : undefined;
params.#executionCosts = parametersUpdate.prices ? ExUnitPrices.fromCore(parametersUpdate.prices) : undefined;
params.#maxTxExUnits = parametersUpdate.maxExecutionUnitsPerTransaction
@@ -485,6 +497,15 @@ export class ProtocolParamUpdate {
params.#governanceActionDeposit = parametersUpdate.governanceActionDeposit;
params.#drepDeposit = parametersUpdate.dRepDeposit;
params.#drepInactivityPeriod = parametersUpdate.dRepInactivityPeriod;
params.#minFeeRefScriptCostPerByte = parametersUpdate.minFeeRefScriptCostPerByte
? UnitInterval.fromFloat(Number(parametersUpdate.minFeeRefScriptCostPerByte))
: undefined;

const { protocolVersion, extraEntropy } = parametersUpdate as unknown as Cardano.ProtocolParametersUpdate;
if (protocolVersion !== undefined || extraEntropy !== undefined) {
params.#protocolVersion = protocolVersion ? ProtocolVersion.fromCore(protocolVersion) : undefined;
params.#extraEntropy = extraEntropy ? HexBlob(extraEntropy) : undefined;
}

return params;
}
@@ -1177,6 +1198,10 @@ export class ProtocolParamUpdate {
return this.#drepInactivityPeriod;
}

minFeeRefScriptCostPerByte(): UnitInterval | undefined {
return this.#minFeeRefScriptCostPerByte;
}

/**
* Gets the size of the serialized map.
*
@@ -1217,6 +1242,7 @@ export class ProtocolParamUpdate {
if (this.#governanceActionDeposit !== undefined) ++mapSize;
if (this.#drepDeposit !== undefined) ++mapSize;
if (this.#drepInactivityPeriod !== undefined) ++mapSize;
if (this.#minFeeRefScriptCostPerByte !== undefined) ++mapSize;

return mapSize;
}
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import { ParameterChangeAction } from '../../../../src/Serialization';

// Test data used in the following tests was generated with the cardano-serialization-lib
const cbor = HexBlob(
'8400825820000000000000000000000000000000000000000000000000000000000000000003b8200018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d8201582000000000000000000000000000000000000000000000000000000000000000000e820103101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181984d81e820000d81e820101d81e820202d81e820303181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388581c8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
'8400825820000000000000000000000000000000000000000000000000000000000000000003b81f0018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d820158200000000000000000000000000000000000000000000000000000000000000000101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181985d81e820000d81e820101d81e820202d81e820303d81e820101181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388581c8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
);

const vasilPlutusV1Costmdls = [
@@ -36,20 +36,23 @@ const vasilPlutusV2Costmdls = [

const core = {
__typename: Cardano.GovernanceActionType.parameter_change_action,
governanceActionId: { actionIndex: 3, id: '0000000000000000000000000000000000000000000000000000000000000000' },
governanceActionId: {
actionIndex: 3,
id: Cardano.TransactionId('0000000000000000000000000000000000000000000000000000000000000000')
},
policyHash: Hash28ByteBase16('8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'),
protocolParamUpdate: {
coinsPerUtxoByte: 35_000,
collateralPercentage: 852,
committeeTermLimit: 200,
committeeTermLimit: Cardano.EpochNo(200),
costModels: new Map([
[PlutusLanguageVersion.V1, vasilPlutusV1Costmdls],
[PlutusLanguageVersion.V2, vasilPlutusV2Costmdls]
]),
dRepDeposit: 2000,
dRepInactivityPeriod: EpochNo(5000),
dRepVotingThresholds: {
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 4, numerator: 4 },
motionNoConfidence: { denominator: 0, numerator: 0 },
@@ -81,13 +84,13 @@ const core = {
poolInfluence: '0.5',
poolRetirementEpochBound: 800,
poolVotingThresholds: {
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 3, numerator: 3 },
motionNoConfidence: { denominator: 0, numerator: 0 }
motionNoConfidence: { denominator: 0, numerator: 0 },
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
},
prices: { memory: 0.5, steps: 0.5 },
protocolVersion: { major: 1, minor: 3 },
stakeKeyDeposit: 2_000_000,
treasuryExpansion: '0.25'
}
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ const cbor = HexBlob(
);

const core = {
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 4, numerator: 4 },
motionNoConfidence: { denominator: 0, numerator: 0 },
@@ -25,7 +25,7 @@ describe('DrepVotingThresholds', () => {
it('can decode DrepVotingThresholds from CBOR', () => {
const thresholds = DrepVotingThresholds.fromCbor(cbor);

expect(thresholds.committeeNoConfidence().toCore()).toEqual(core.commiteeNoConfidence);
expect(thresholds.committeeNoConfidence().toCore()).toEqual(core.committeeNoConfidence);
expect(thresholds.committeeNormal().toCore()).toEqual(core.committeeNormal);
expect(thresholds.hardForkInitiation().toCore()).toEqual(core.hardForkInitiation);
expect(thresholds.motionNoConfidence().toCore()).toEqual(core.motionNoConfidence);
@@ -40,7 +40,7 @@ describe('DrepVotingThresholds', () => {
it('can decode DrepVotingThresholds from Core', () => {
const thresholds = DrepVotingThresholds.fromCore(core);

expect(thresholds.committeeNoConfidence().toCore()).toEqual(core.commiteeNoConfidence);
expect(thresholds.committeeNoConfidence().toCore()).toEqual(core.committeeNoConfidence);
expect(thresholds.committeeNormal().toCore()).toEqual(core.committeeNormal);
expect(thresholds.hardForkInitiation().toCore()).toEqual(core.hardForkInitiation);
expect(thresholds.motionNoConfidence().toCore()).toEqual(core.motionNoConfidence);
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { Cardano } from '../../../src';
import { HexBlob } from '@cardano-sdk/util';
import { PoolVotingThresholds } from '../../../src/Serialization';

// Test data used in the following tests was generated with the cardano-serialization-lib

const cbor = HexBlob('84d81e820000d81e820101d81e820202d81e820303');
const cbor = HexBlob('85d81e820000d81e820101d81e820202d81e820303d81e820101');

const core = {
commiteeNoConfidence: { denominator: 2, numerator: 2 },
const core: Cardano.PoolVotingThresholds = {
committeeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 3, numerator: 3 },
motionNoConfidence: { denominator: 0, numerator: 0 }
motionNoConfidence: { denominator: 0, numerator: 0 },
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
};

describe('PoolVotingThresholds', () => {
it('can decode PoolVotingThresholds from CBOR', () => {
const thresholds = PoolVotingThresholds.fromCbor(cbor);

expect(thresholds.committeeNoConfidence().toCore()).toEqual(core.commiteeNoConfidence);
expect(thresholds.committeeNoConfidence().toCore()).toEqual(core.committeeNoConfidence);
expect(thresholds.committeeNormal().toCore()).toEqual(core.committeeNormal);
expect(thresholds.hardForkInitiation().toCore()).toEqual(core.hardForkInitiation);
expect(thresholds.motionNoConfidence().toCore()).toEqual(core.motionNoConfidence);
expect(thresholds.securityRelevantParamVotingThreshold().toCore()).toEqual(
core.securityRelevantParamVotingThreshold
);
});

it('can decode PoolVotingThresholds from Core', () => {
const thresholds = PoolVotingThresholds.fromCore(core);

expect(thresholds.committeeNoConfidence().toCore()).toEqual(core.commiteeNoConfidence);
expect(thresholds.committeeNoConfidence().toCore()).toEqual(core.committeeNoConfidence);
expect(thresholds.committeeNormal().toCore()).toEqual(core.committeeNormal);
expect(thresholds.hardForkInitiation().toCore()).toEqual(core.hardForkInitiation);
expect(thresholds.motionNoConfidence().toCore()).toEqual(core.motionNoConfidence);
expect(thresholds.securityRelevantParamVotingThreshold().toCore()).toEqual(
core.securityRelevantParamVotingThreshold
);
});

it('can encode PoolVotingThresholds to CBOR', () => {
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { Cardano } from '../../../src';
import { EpochNo, PlutusLanguageVersion } from '../../../src/Cardano';
import { HexBlob } from '@cardano-sdk/util';
import { ProtocolParamUpdate } from '../../../src/Serialization/Update/ProtocolParamUpdate';
@@ -34,7 +35,7 @@ const cbor = HexBlob(
);

const conwayCbor = HexBlob(
'b8200018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d8201582000000000000000000000000000000000000000000000000000000000000000000e820103101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181984d81e820000d81e820101d81e820202d81e820303181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388'
'b8210018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d8201582000000000000000000000000000000000000000000000000000000000000000000e820103101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181985d81e820000d81e820101d81e820202d81e820303d81e820101181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d018201913881821d81e82185902'
);

const core = {
@@ -67,18 +68,18 @@ const core = {
treasuryExpansion: '0.25'
};

const conwayCore = {
const conwayCore: Cardano.ProtocolParametersUpdate = {
coinsPerUtxoByte: 35_000,
collateralPercentage: 852,
committeeTermLimit: 200,
committeeTermLimit: EpochNo(200),
costModels: new Map([
[PlutusLanguageVersion.V1, vasilPlutusV1Costmdls],
[PlutusLanguageVersion.V2, vasilPlutusV2Costmdls]
]),
dRepDeposit: 2000,
dRepInactivityPeriod: EpochNo(5000),
dRepVotingThresholds: {
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 4, numerator: 4 },
motionNoConfidence: { denominator: 0, numerator: 0 },
@@ -104,16 +105,18 @@ const conwayCore = {
minCommitteeSize: 100,
minFeeCoefficient: 100,
minFeeConstant: 200,
minFeeRefScriptCostPerByte: '44.5',
minPoolCost: 1000,
monetaryExpansion: '0.3333333333333333',
poolDeposit: 200_000_000,
poolInfluence: '0.5',
poolRetirementEpochBound: 800,
poolVotingThresholds: {
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 3, numerator: 3 },
motionNoConfidence: { denominator: 0, numerator: 0 }
motionNoConfidence: { denominator: 0, numerator: 0 },
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
},
prices: { memory: 0.5, steps: 0.5 },
protocolVersion: { major: 1, minor: 3 },
@@ -211,7 +214,7 @@ describe('ProtocolParamUpdate', () => {
expect(proposedParams.drepDeposit()).toEqual(2000);
expect(proposedParams.drepInactivityPeriod()).toEqual(5000);
expect(proposedParams.drepVotingThresholds()?.toCore()).toEqual({
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 4, numerator: 4 },
motionNoConfidence: { denominator: 0, numerator: 0 },
@@ -223,11 +226,13 @@ describe('ProtocolParamUpdate', () => {
updateConstitution: { denominator: 3, numerator: 3 }
});
expect(proposedParams.poolVotingThresholds()?.toCore()).toEqual({
commiteeNoConfidence: { denominator: 2, numerator: 2 },
committeeNoConfidence: { denominator: 2, numerator: 2 },
committeeNormal: { denominator: 1, numerator: 1 },
hardForkInitiation: { denominator: 3, numerator: 3 },
motionNoConfidence: { denominator: 0, numerator: 0 }
motionNoConfidence: { denominator: 0, numerator: 0 },
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
});
expect(proposedParams.minFeeRefScriptCostPerByte()?.toFloat()).toEqual(44.5);
});

// eslint-disable-next-line max-statements
2 changes: 1 addition & 1 deletion packages/util-dev/src/mockProviders/mockData.ts
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ export const protocolParameters = {
prices: { memory: 0.0577, steps: 0.000_007_21 },
protocolVersion: { major: 5, minor: 0 },
stakeKeyDeposit: 2_000_000
} as Cardano.ProtocolParameters;
} as Required<Cardano.ProtocolParametersUpdate>;

export const epochRewards = [
{