Skip to content

Commit 567fad9

Browse files
committed
feat(core): update serialization with new protocol params update fields
1 parent 780745b commit 567fad9

File tree

5 files changed

+71
-17
lines changed

5 files changed

+71
-17
lines changed

packages/core/src/Serialization/Update/PoolVotingThresholds.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CborReader, CborWriter } from '../CBOR';
33
import { HexBlob, InvalidArgumentError } from '@cardano-sdk/util';
44
import { UnitInterval } from '../Common';
55

6-
const POOL_VOTING_THRESHOLDS_SIZE = 4;
6+
const POOL_VOTING_THRESHOLDS_SIZE = 5;
77

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

2223
/**
@@ -35,12 +36,14 @@ export class PoolVotingThresholds {
3536
motionNoConfidence: UnitInterval,
3637
committeeNormal: UnitInterval,
3738
committeeNoConfidence: UnitInterval,
38-
hardForkInitiation: UnitInterval
39+
hardForkInitiation: UnitInterval,
40+
securityRelevantParamVotingThreshold: UnitInterval
3941
) {
4042
this.#motionNoConfidence = motionNoConfidence;
4143
this.#committeeNormal = committeeNormal;
4244
this.#committeeNoConfidence = committeeNoConfidence;
4345
this.#hardForkInitiation = hardForkInitiation;
46+
this.#securityRelevantParamVotingThreshold = securityRelevantParamVotingThreshold;
4447
}
4548

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

6569
writer.writeEncodedValue(Buffer.from(this.#motionNoConfidence.toCbor(), 'hex'));
6670
writer.writeEncodedValue(Buffer.from(this.#committeeNormal.toCbor(), 'hex'));
6771
writer.writeEncodedValue(Buffer.from(this.#committeeNoConfidence.toCbor(), 'hex'));
6872
writer.writeEncodedValue(Buffer.from(this.#hardForkInitiation.toCbor(), 'hex'));
73+
writer.writeEncodedValue(Buffer.from(this.#securityRelevantParamVotingThreshold.toCbor(), 'hex'));
6974

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

95101
reader.readEndArray();
96102

97103
const thresholds = new PoolVotingThresholds(
98104
motionNoConfidence,
99105
committeeNormal,
100106
committeeNoConfidence,
101-
hardForkInitiation
107+
hardForkInitiation,
108+
securityRelevantParamVotingThreshold
102109
);
103110

104111
thresholds.#originalBytes = cbor;
@@ -107,7 +114,7 @@ export class PoolVotingThresholds {
107114
}
108115

109116
/**
110-
* Creates a Core PoolVotingThresholdsSHOLDS_SIZE object from the current PoolVotingThresholds object.
117+
* Creates a Core PoolVotingThresholds object from the current PoolVotingThresholds object.
111118
*
112119
* @returns The Core Prices object.
113120
*/
@@ -116,7 +123,8 @@ export class PoolVotingThresholds {
116123
commiteeNoConfidence: this.#committeeNoConfidence.toCore(),
117124
committeeNormal: this.#committeeNormal.toCore(),
118125
hardForkInitiation: this.#hardForkInitiation.toCore(),
119-
motionNoConfidence: this.#motionNoConfidence.toCore()
126+
motionNoConfidence: this.#motionNoConfidence.toCore(),
127+
securityRelevantParamVotingThreshold: this.#securityRelevantParamVotingThreshold.toCore()
120128
};
121129
}
122130

@@ -130,7 +138,8 @@ export class PoolVotingThresholds {
130138
UnitInterval.fromCore(core.motionNoConfidence),
131139
UnitInterval.fromCore(core.committeeNormal),
132140
UnitInterval.fromCore(core.commiteeNoConfidence),
133-
UnitInterval.fromCore(core.hardForkInitiation)
141+
UnitInterval.fromCore(core.hardForkInitiation),
142+
UnitInterval.fromCore(core.securityRelevantParamVotingThreshold)
134143
);
135144
}
136145

@@ -223,4 +232,13 @@ export class PoolVotingThresholds {
223232
hardForkInitiation(): UnitInterval {
224233
return this.#hardForkInitiation;
225234
}
235+
236+
/**
237+
* Gets the security relevant parameter voting threshold
238+
*
239+
* @returns security relevant parameter voting threshold.
240+
*/
241+
securityRelevantParamVotingThreshold(): UnitInterval {
242+
return this.#securityRelevantParamVotingThreshold;
243+
}
226244
}

packages/core/src/Serialization/Update/ProtocolParamUpdate.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class ProtocolParamUpdate {
4646
#governanceActionDeposit: number | undefined;
4747
#drepDeposit: number | undefined;
4848
#drepInactivityPeriod: number | undefined;
49+
#minFeeRefScriptCostPerByte: UnitInterval | undefined;
4950
#originalBytes: HexBlob | undefined = undefined;
5051

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

@@ -254,6 +256,12 @@ export class ProtocolParamUpdate {
254256
writer.writeInt(32n);
255257
writer.writeInt(this.#drepInactivityPeriod);
256258
}
259+
260+
if (this.#minFeeRefScriptCostPerByte) {
261+
writer.writeInt(33n);
262+
writer.writeEncodedValue(Buffer.from(this.#minFeeRefScriptCostPerByte.toCbor(), 'hex'));
263+
}
264+
257265
return writer.encodeAsHex();
258266
}
259267

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

@@ -392,7 +403,7 @@ export class ProtocolParamUpdate {
392403
return {
393404
coinsPerUtxoByte: this.#adaPerUtxoByte ? Number(this.#adaPerUtxoByte) : undefined,
394405
collateralPercentage: this.#collateralPercentage,
395-
committeeTermLimit: this.#committeeTermLimit,
406+
committeeTermLimit: this.#committeeTermLimit ? Cardano.EpochNo(this.#committeeTermLimit) : undefined,
396407
costModels: this.#costModels?.toCore(),
397408
dRepDeposit: this.#drepDeposit,
398409
dRepInactivityPeriod: this.#drepInactivityPeriod ? Cardano.EpochNo(this.#drepInactivityPeriod) : undefined,
@@ -414,6 +425,9 @@ export class ProtocolParamUpdate {
414425
minCommitteeSize: this.#minCommitteeSize,
415426
minFeeCoefficient: this.#minFeeA ? Number(this.#minFeeA) : undefined,
416427
minFeeConstant: this.#minFeeB ? Number(this.#minFeeB) : undefined,
428+
minFeeRefScriptCostPerByte: this.#minFeeRefScriptCostPerByte
429+
? this.#minFeeRefScriptCostPerByte.toFloat().toString()
430+
: undefined,
417431
minPoolCost: this.#minPoolCost ? Number(this.#minPoolCost) : undefined,
418432
monetaryExpansion: this.#expansionRate ? this.#expansionRate.toFloat().toString() : undefined,
419433
poolDeposit: this.#poolDeposit ? Number(this.#poolDeposit) : undefined,
@@ -485,6 +499,9 @@ export class ProtocolParamUpdate {
485499
params.#governanceActionDeposit = parametersUpdate.governanceActionDeposit;
486500
params.#drepDeposit = parametersUpdate.dRepDeposit;
487501
params.#drepInactivityPeriod = parametersUpdate.dRepInactivityPeriod;
502+
params.#minFeeRefScriptCostPerByte = parametersUpdate.minFeeRefScriptCostPerByte
503+
? UnitInterval.fromFloat(Number(parametersUpdate.minFeeRefScriptCostPerByte))
504+
: undefined;
488505

489506
return params;
490507
}
@@ -1177,6 +1194,10 @@ export class ProtocolParamUpdate {
11771194
return this.#drepInactivityPeriod;
11781195
}
11791196

1197+
minFeeRefScriptCostPerByte(): UnitInterval | undefined {
1198+
return this.#minFeeRefScriptCostPerByte;
1199+
}
1200+
11801201
/**
11811202
* Gets the size of the serialized map.
11821203
*
@@ -1217,6 +1238,7 @@ export class ProtocolParamUpdate {
12171238
if (this.#governanceActionDeposit !== undefined) ++mapSize;
12181239
if (this.#drepDeposit !== undefined) ++mapSize;
12191240
if (this.#drepInactivityPeriod !== undefined) ++mapSize;
1241+
if (this.#minFeeRefScriptCostPerByte !== undefined) ++mapSize;
12201242

12211243
return mapSize;
12221244
}

packages/core/test/Serialization/TransactionBody/ProposalProcedure/ParameterChangeAction.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ParameterChangeAction } from '../../../../src/Serialization';
77

88
// Test data used in the following tests was generated with the cardano-serialization-lib
99
const cbor = HexBlob(
10-
'8400825820000000000000000000000000000000000000000000000000000000000000000003b8200018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d8201582000000000000000000000000000000000000000000000000000000000000000000e820103101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181984d81e820000d81e820101d81e820202d81e820303181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388581c8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
10+
'8400825820000000000000000000000000000000000000000000000000000000000000000003b8200018640118c80219012c03190190041901f4051a001e8480061a0bebc200071903200819038409d81e8201020ad81e8201030bd81e8201040cd81e8201050d8201582000000000000000000000000000000000000000000000000000000000000000000e820103101903e8111988b812a20098a61a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0374f693194a1f0a0198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a0223accc0a1a0374f693194a1f0a1a02515e841980b30a1382d81e820102d81e82010214821b00000001000000001b000000010000000015821b00000001000000001b0000000100000000161903ba1719035418181864181985d81e820000d81e820101d81e820202d81e820303d81e820101181a8ad81e820000d81e820101d81e820202d81e820303d81e820404d81e820505d81e820606d81e820707d81e820808d81e820909181b1864181c18c8181d19012c181e1903e8181f1907d01820191388581c8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'
1111
);
1212

1313
const vasilPlutusV1Costmdls = [
@@ -84,7 +84,8 @@ const core = {
8484
commiteeNoConfidence: { denominator: 2, numerator: 2 },
8585
committeeNormal: { denominator: 1, numerator: 1 },
8686
hardForkInitiation: { denominator: 3, numerator: 3 },
87-
motionNoConfidence: { denominator: 0, numerator: 0 }
87+
motionNoConfidence: { denominator: 0, numerator: 0 },
88+
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
8889
},
8990
prices: { memory: 0.5, steps: 0.5 },
9091
protocolVersion: { major: 1, minor: 3 },

packages/core/test/Serialization/Update/PoolVotingThresholds.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/* eslint-disable sonarjs/no-duplicate-string */
2+
import { Cardano } from '../../../src';
23
import { HexBlob } from '@cardano-sdk/util';
34
import { PoolVotingThresholds } from '../../../src/Serialization';
45

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

7-
const cbor = HexBlob('84d81e820000d81e820101d81e820202d81e820303');
8+
const cbor = HexBlob('85d81e820000d81e820101d81e820202d81e820303d81e820101');
89

9-
const core = {
10+
const core: Cardano.PoolVotingThresholds = {
1011
commiteeNoConfidence: { denominator: 2, numerator: 2 },
1112
committeeNormal: { denominator: 1, numerator: 1 },
1213
hardForkInitiation: { denominator: 3, numerator: 3 },
13-
motionNoConfidence: { denominator: 0, numerator: 0 }
14+
motionNoConfidence: { denominator: 0, numerator: 0 },
15+
securityRelevantParamVotingThreshold: { denominator: 1, numerator: 1 }
1416
};
1517

1618
describe('PoolVotingThresholds', () => {
@@ -21,6 +23,9 @@ describe('PoolVotingThresholds', () => {
2123
expect(thresholds.committeeNormal().toCore()).toEqual(core.committeeNormal);
2224
expect(thresholds.hardForkInitiation().toCore()).toEqual(core.hardForkInitiation);
2325
expect(thresholds.motionNoConfidence().toCore()).toEqual(core.motionNoConfidence);
26+
expect(thresholds.securityRelevantParamVotingThreshold().toCore()).toEqual(
27+
core.securityRelevantParamVotingThreshold
28+
);
2429
});
2530

2631
it('can decode PoolVotingThresholds from Core', () => {
@@ -30,6 +35,9 @@ describe('PoolVotingThresholds', () => {
3035
expect(thresholds.committeeNormal().toCore()).toEqual(core.committeeNormal);
3136
expect(thresholds.hardForkInitiation().toCore()).toEqual(core.hardForkInitiation);
3237
expect(thresholds.motionNoConfidence().toCore()).toEqual(core.motionNoConfidence);
38+
expect(thresholds.securityRelevantParamVotingThreshold().toCore()).toEqual(
39+
core.securityRelevantParamVotingThreshold
40+
);
3341
});
3442

3543
it('can encode PoolVotingThresholds to CBOR', () => {

0 commit comments

Comments
 (0)