-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathProtocolParamUpdate.ts
1249 lines (1129 loc) · 42 KB
/
ProtocolParamUpdate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable sonarjs/cognitive-complexity, complexity, sonarjs/max-switch-cases, max-statements */
import * as Cardano from '../../Cardano';
import { CborReader, CborReaderState, CborWriter } from '../CBOR';
import { Costmdls } from './Costmdls';
import { DrepVotingThresholds } from './DrepVotingThresholds';
import { ExUnitPrices } from './ExUnitPrices';
import { ExUnits, ProtocolVersion, UnitInterval } from '../Common';
import { HexBlob } from '@cardano-sdk/util';
import { PoolVotingThresholds } from './PoolVotingThresholds';
/**
* The ProtocolParamUpdate structure in Cardano is used to propose changes to
* the protocol parameters of the blockchain. Protocol parameters govern various
* aspects of the Cardano network.
*/
export class ProtocolParamUpdate {
#minFeeA: Cardano.Lovelace | undefined;
#minFeeB: Cardano.Lovelace | undefined;
#maxBlockBodySize: number | undefined;
#maxTxSize: number | undefined;
#maxBlockHeaderSize: number | undefined;
#keyDeposit: Cardano.Lovelace | undefined;
#poolDeposit: Cardano.Lovelace | undefined;
#maxEpoch: number | undefined;
#nOpt: number | undefined;
#poolPledgeInfluence: UnitInterval | undefined;
#expansionRate: UnitInterval | undefined;
#treasuryGrowthRate: UnitInterval | undefined;
#d: UnitInterval | undefined;
#extraEntropy: HexBlob | undefined;
#protocolVersion: ProtocolVersion | undefined;
#minPoolCost: Cardano.Lovelace | undefined;
#adaPerUtxoByte: Cardano.Lovelace | undefined;
#costModels: Costmdls | undefined;
#executionCosts: ExUnitPrices | undefined;
#maxTxExUnits: ExUnits | undefined;
#maxBlockExUnits: ExUnits | undefined;
#maxValueSize: number | undefined;
#collateralPercentage: number | undefined;
#maxCollateralInputs: number | undefined;
#poolVotingThresholds: PoolVotingThresholds | undefined;
#drepVotingThresholds: DrepVotingThresholds | undefined;
#minCommitteeSize: number | undefined;
#committeeTermLimit: number | undefined;
#governanceActionValidityPeriod: number | undefined;
#governanceActionDeposit: number | undefined;
#drepDeposit: number | undefined;
#drepInactivityPeriod: number | undefined;
#minFeeRefScriptCostPerByte: UnitInterval | undefined;
#originalBytes: HexBlob | undefined = undefined;
/**
* Serializes a ProtocolParamUpdate into CBOR format.
*
* @returns The ProtocolParamUpdate in CBOR format.
*/
// eslint-disable-next-line max-statements
toCbor(): HexBlob {
const writer = new CborWriter();
if (this.#originalBytes) return this.#originalBytes;
// CDDL
// protocol_param_update =
// { ? 0: uint ; minfee A
// , ? 1: uint ; minfee B
// , ? 2: uint ; max block body size
// , ? 3: uint ; max transaction size
// , ? 4: uint ; max block header size
// , ? 5: coin ; key deposit
// , ? 6: coin ; pool deposit
// , ? 7: epoch ; maximum epoch
// , ? 8: uint ; n_opt: desired number of stake pools
// , ? 9: rational ; pool pledge influence
// , ? 10: unit_interval ; expansion rate
// , ? 11: unit_interval ; treasury growth rate
// , ? 16: coin ; min pool cost
// , ? 17: coin ; ada per utxo byte
// , ? 18: costmdls ; cost models for script languages
// , ? 19: ex_unit_prices ; execution costs
// , ? 20: ex_units ; max tx ex units
// , ? 21: ex_units ; max block ex units
// , ? 22: uint ; max value size
// , ? 23: uint ; collateral percentage
// , ? 24: uint ; max collateral inputs
// , ? 25: pool_voting_thresholds ; pool voting thresholds
// , ? 26: drep_voting_thresholds ; DRep voting thresholds
// , ? 27: uint ; min committee size
// , ? 28: uint ; committee term limit
// , ? 29: epoch ; governance action validity period
// , ? 30: coin ; governance action deposit
// , ? 31: coin ; DRep deposit
// , ? 32: epoch ; DRep inactivity period
// , ? 33: nonnegative_interval ; MinFee RefScriptCostPerByte
// }
writer.writeStartMap(this.#getMapSize());
if (this.#minFeeA) {
writer.writeInt(0n);
writer.writeInt(this.#minFeeA);
}
if (this.#minFeeB) {
writer.writeInt(1n);
writer.writeInt(this.#minFeeB);
}
if (this.#maxBlockBodySize) {
writer.writeInt(2n);
writer.writeInt(this.#maxBlockBodySize);
}
if (this.#maxTxSize) {
writer.writeInt(3n);
writer.writeInt(this.#maxTxSize);
}
if (this.#maxBlockHeaderSize) {
writer.writeInt(4n);
writer.writeInt(this.#maxBlockHeaderSize);
}
if (this.#keyDeposit) {
writer.writeInt(5n);
writer.writeInt(this.#keyDeposit);
}
if (this.#poolDeposit) {
writer.writeInt(6n);
writer.writeInt(this.#poolDeposit);
}
if (this.#maxEpoch) {
writer.writeInt(7n);
writer.writeInt(this.#maxEpoch);
}
if (this.#nOpt) {
writer.writeInt(8n);
writer.writeInt(this.#nOpt);
}
if (this.#poolPledgeInfluence) {
writer.writeInt(9n);
writer.writeEncodedValue(Buffer.from(this.#poolPledgeInfluence.toCbor(), 'hex'));
}
if (this.#expansionRate) {
writer.writeInt(10n);
writer.writeEncodedValue(Buffer.from(this.#expansionRate.toCbor(), 'hex'));
}
if (this.#treasuryGrowthRate) {
writer.writeInt(11n);
writer.writeEncodedValue(Buffer.from(this.#treasuryGrowthRate.toCbor(), 'hex'));
}
if (this.#d) {
writer.writeInt(12n);
writer.writeEncodedValue(Buffer.from(this.#d.toCbor(), 'hex'));
}
if (this.#extraEntropy) {
writer.writeInt(13n);
writer.writeStartArray(2);
writer.writeInt(1);
writer.writeByteString(Buffer.from(this.#extraEntropy, 'hex'));
}
if (this.#protocolVersion) {
writer.writeInt(14n);
writer.writeEncodedValue(Buffer.from(this.#protocolVersion.toCbor(), 'hex'));
}
if (this.#minPoolCost) {
writer.writeInt(16n);
writer.writeInt(this.#minPoolCost);
}
if (this.#adaPerUtxoByte) {
writer.writeInt(17n);
writer.writeInt(this.#adaPerUtxoByte);
}
if (this.#costModels) {
writer.writeInt(18n);
writer.writeEncodedValue(Buffer.from(this.#costModels.toCbor(), 'hex'));
}
if (this.#executionCosts) {
writer.writeInt(19n);
writer.writeEncodedValue(Buffer.from(this.#executionCosts.toCbor(), 'hex'));
}
if (this.#maxTxExUnits) {
writer.writeInt(20n);
writer.writeEncodedValue(Buffer.from(this.#maxTxExUnits.toCbor(), 'hex'));
}
if (this.#maxBlockExUnits) {
writer.writeInt(21n);
writer.writeEncodedValue(Buffer.from(this.#maxBlockExUnits.toCbor(), 'hex'));
}
if (this.#maxValueSize) {
writer.writeInt(22n);
writer.writeInt(this.#maxValueSize);
}
if (this.#collateralPercentage) {
writer.writeInt(23n);
writer.writeInt(this.#collateralPercentage);
}
if (this.#maxCollateralInputs) {
writer.writeInt(24n);
writer.writeInt(this.#maxCollateralInputs);
}
if (this.#poolVotingThresholds) {
writer.writeInt(25n);
writer.writeEncodedValue(Buffer.from(this.#poolVotingThresholds.toCbor(), 'hex'));
}
if (this.#drepVotingThresholds) {
writer.writeInt(26n);
writer.writeEncodedValue(Buffer.from(this.#drepVotingThresholds.toCbor(), 'hex'));
}
if (this.#minCommitteeSize) {
writer.writeInt(27n);
writer.writeInt(this.#minCommitteeSize);
}
if (this.#committeeTermLimit) {
writer.writeInt(28n);
writer.writeInt(this.#committeeTermLimit);
}
if (this.#governanceActionValidityPeriod) {
writer.writeInt(29n);
writer.writeInt(this.#governanceActionValidityPeriod);
}
if (this.#governanceActionDeposit) {
writer.writeInt(30n);
writer.writeInt(this.#governanceActionDeposit);
}
if (this.#drepDeposit) {
writer.writeInt(31n);
writer.writeInt(this.#drepDeposit);
}
if (this.#drepInactivityPeriod) {
writer.writeInt(32n);
writer.writeInt(this.#drepInactivityPeriod);
}
if (this.#minFeeRefScriptCostPerByte) {
writer.writeInt(33n);
writer.writeEncodedValue(Buffer.from(this.#minFeeRefScriptCostPerByte.toCbor(), 'hex'));
}
return writer.encodeAsHex();
}
/**
* Deserializes the ProtocolParamUpdate from a CBOR byte array.
*
* @param cbor The CBOR encoded ProtocolParamUpdate object.
* @returns The new ProtocolParamUpdate instance.
*/
static fromCbor(cbor: HexBlob): ProtocolParamUpdate {
const reader = new CborReader(cbor);
const params = new ProtocolParamUpdate();
reader.readStartMap();
while (reader.peekState() !== CborReaderState.EndMap) {
const key = reader.readInt();
switch (key) {
case 0n:
params.#minFeeA = reader.readInt();
break;
case 1n:
params.#minFeeB = reader.readInt();
break;
case 2n:
params.#maxBlockBodySize = Number(reader.readInt());
break;
case 3n:
params.#maxTxSize = Number(reader.readInt());
break;
case 4n:
params.#maxBlockHeaderSize = Number(reader.readInt());
break;
case 5n:
params.#keyDeposit = reader.readInt();
break;
case 6n:
params.#poolDeposit = reader.readInt();
break;
case 7n:
params.#maxEpoch = Number(reader.readInt());
break;
case 8n:
params.#nOpt = Number(reader.readInt());
break;
case 9n:
params.#poolPledgeInfluence = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 10n:
params.#expansionRate = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 11n:
params.#treasuryGrowthRate = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 12n:
params.#d = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 13n:
// entropy is encoded as an array of two elements, where the second elements is the entropy value
reader.readStartArray();
reader.readEncodedValue();
params.#extraEntropy = HexBlob.fromBytes(reader.readByteString());
reader.readEndArray();
break;
case 14n:
params.#protocolVersion = ProtocolVersion.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 16n:
params.#minPoolCost = reader.readInt();
break;
case 17n:
params.#adaPerUtxoByte = reader.readInt();
break;
case 18n:
params.#costModels = Costmdls.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 19n:
params.#executionCosts = ExUnitPrices.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 20n:
params.#maxTxExUnits = ExUnits.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 21n:
params.#maxBlockExUnits = ExUnits.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 22n:
params.#maxValueSize = Number(reader.readInt());
break;
case 23n:
params.#collateralPercentage = Number(reader.readInt());
break;
case 24n:
params.#maxCollateralInputs = Number(reader.readInt());
break;
case 25n:
params.#poolVotingThresholds = PoolVotingThresholds.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 26n:
params.#drepVotingThresholds = DrepVotingThresholds.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
case 27n:
params.#minCommitteeSize = Number(reader.readInt());
break;
case 28n:
params.#committeeTermLimit = Number(reader.readInt());
break;
case 29n:
params.#governanceActionValidityPeriod = Number(reader.readInt());
break;
case 30n:
params.#governanceActionDeposit = Number(reader.readInt());
break;
case 31n:
params.#drepDeposit = Number(reader.readInt());
break;
case 32n:
params.#drepInactivityPeriod = Number(reader.readInt());
break;
case 33n:
params.#minFeeRefScriptCostPerByte = UnitInterval.fromCbor(HexBlob.fromBytes(reader.readEncodedValue()));
break;
}
}
reader.readEndMap();
params.#originalBytes = cbor;
return params;
}
/**
* Creates a Core ProtocolParamUpdate object from the current ProtocolParamUpdate object.
*
* @returns The Core ProtocolParamUpdate object.
*/
toCore(): Cardano.ProtocolParametersUpdate {
return {
coinsPerUtxoByte: this.#adaPerUtxoByte ? Number(this.#adaPerUtxoByte) : undefined,
collateralPercentage: this.#collateralPercentage,
committeeTermLimit: this.#committeeTermLimit ? Cardano.EpochNo(this.#committeeTermLimit) : undefined,
costModels: this.#costModels?.toCore(),
dRepDeposit: this.#drepDeposit,
dRepInactivityPeriod: this.#drepInactivityPeriod ? Cardano.EpochNo(this.#drepInactivityPeriod) : undefined,
dRepVotingThresholds: this.#drepVotingThresholds?.toCore(),
decentralizationParameter: this.#d ? this.#d.toFloat().toString() : undefined,
desiredNumberOfPools: this.#nOpt,
extraEntropy: this.#extraEntropy,
governanceActionDeposit: this.#governanceActionDeposit,
governanceActionValidityPeriod: this.#governanceActionValidityPeriod
? Cardano.EpochNo(this.#governanceActionValidityPeriod)
: undefined,
maxBlockBodySize: this.#maxBlockBodySize,
maxBlockHeaderSize: this.#maxBlockHeaderSize,
maxCollateralInputs: this.#maxCollateralInputs,
maxExecutionUnitsPerBlock: this.#maxBlockExUnits?.toCore(),
maxExecutionUnitsPerTransaction: this.#maxTxExUnits?.toCore(),
maxTxSize: this.#maxTxSize ? Number(this.#maxTxSize) : undefined,
maxValueSize: this.#maxValueSize,
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,
poolInfluence: this.#poolPledgeInfluence ? this.#poolPledgeInfluence.toFloat().toString() : undefined,
poolRetirementEpochBound: this.#maxEpoch,
poolVotingThresholds: this.#poolVotingThresholds?.toCore(),
prices: this.#executionCosts?.toCore(),
protocolVersion: this.#protocolVersion?.toCore(),
stakeKeyDeposit: this.#keyDeposit ? Number(this.#keyDeposit) : undefined,
treasuryExpansion: this.#treasuryGrowthRate ? this.#treasuryGrowthRate.toFloat().toString() : undefined
};
}
/**
* Creates a ProtocolParamUpdate object from the given Core ProtocolParamUpdate object.
*
* @param parametersUpdate core parametersUpdate object.
*/
static fromCore<T extends Cardano.ProtocolParametersUpdateConway = Cardano.ProtocolParametersUpdate>(
parametersUpdate: T
) {
const params = new ProtocolParamUpdate();
params.#minFeeA = parametersUpdate.minFeeCoefficient ? BigInt(parametersUpdate.minFeeCoefficient) : undefined;
params.#maxBlockBodySize = parametersUpdate.maxBlockBodySize;
params.#minFeeB = parametersUpdate.minFeeConstant ? BigInt(parametersUpdate.minFeeConstant) : undefined;
params.#maxBlockHeaderSize = parametersUpdate.maxBlockHeaderSize;
params.#keyDeposit = parametersUpdate.stakeKeyDeposit ? BigInt(parametersUpdate.stakeKeyDeposit) : undefined;
params.#poolDeposit = parametersUpdate.poolDeposit ? BigInt(parametersUpdate.poolDeposit) : undefined;
params.#maxEpoch = parametersUpdate.poolRetirementEpochBound;
params.#nOpt = parametersUpdate.desiredNumberOfPools;
params.#poolPledgeInfluence = parametersUpdate.poolInfluence
? UnitInterval.fromFloat(Number(parametersUpdate.poolInfluence))
: undefined;
params.#expansionRate = parametersUpdate.monetaryExpansion
? UnitInterval.fromFloat(Number(parametersUpdate.monetaryExpansion))
: undefined;
params.#treasuryGrowthRate = parametersUpdate.treasuryExpansion
? UnitInterval.fromFloat(Number(parametersUpdate.treasuryExpansion))
: undefined;
params.#d = parametersUpdate.decentralizationParameter
? UnitInterval.fromFloat(Number(parametersUpdate.decentralizationParameter))
: undefined;
params.#minPoolCost = parametersUpdate.minPoolCost ? BigInt(parametersUpdate.minPoolCost) : undefined;
params.#maxValueSize = parametersUpdate.maxValueSize;
params.#maxTxSize = parametersUpdate.maxTxSize;
params.#collateralPercentage = parametersUpdate.collateralPercentage;
params.#maxCollateralInputs = parametersUpdate.maxCollateralInputs;
params.#costModels = parametersUpdate.costModels ? Costmdls.fromCore(parametersUpdate.costModels) : undefined;
params.#executionCosts = parametersUpdate.prices ? ExUnitPrices.fromCore(parametersUpdate.prices) : undefined;
params.#maxTxExUnits = parametersUpdate.maxExecutionUnitsPerTransaction
? ExUnits.fromCore(parametersUpdate.maxExecutionUnitsPerTransaction)
: undefined;
params.#maxBlockExUnits = parametersUpdate.maxExecutionUnitsPerBlock
? ExUnits.fromCore(parametersUpdate.maxExecutionUnitsPerBlock)
: undefined;
params.#adaPerUtxoByte = parametersUpdate.coinsPerUtxoByte ? BigInt(parametersUpdate.coinsPerUtxoByte) : undefined;
params.#poolVotingThresholds = parametersUpdate.poolVotingThresholds
? PoolVotingThresholds.fromCore(parametersUpdate.poolVotingThresholds)
: undefined;
params.#drepVotingThresholds = parametersUpdate.dRepVotingThresholds
? DrepVotingThresholds.fromCore(parametersUpdate.dRepVotingThresholds)
: undefined;
params.#minCommitteeSize = parametersUpdate.minCommitteeSize;
params.#committeeTermLimit = parametersUpdate.committeeTermLimit;
params.#governanceActionValidityPeriod = parametersUpdate.governanceActionValidityPeriod;
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;
}
/**
* minfeeA and minfeeB are two separate parameters in Cardano's fee calculation
* to ensure flexibility and fine-grained control over how transaction fees are
* determined. Both of these parameters come into play when deciding the cost of
* a transaction, and they serve different purposes.
*
* The transaction fee in Cardano is computed as: fee = minfeeA * size + minfeeB.
*
* minfeeA it's multiplied by the size of the transaction. This means it's primarily responsible
* for how the fee scales with the transaction's size. If minfeeA is high, then the cost per byte
* of transaction data is high. This encourages users to minimize the size of their transactions.
*
* Conversely, if minfeeA is low, the cost per byte is low, but other factors (like minfeeB) can still
* influence the overall fee.
*
* @param minFeeA fee to be multiplied by the transaction size.
*/
setMinFeeA(minFeeA: Cardano.Lovelace): void {
this.#minFeeA = minFeeA;
}
/**
* Gets the minFeeA component of the transaction fee computation.
*
* @returns The transaction fee to be multiplied by the transaction size, or undefined
* if not set.
*/
minFeeA(): Cardano.Lovelace | undefined {
return this.#minFeeA;
}
/**
* minfeeB it's a constant added to the transaction fee irrespective of the transaction's size.
* Think of it as a "base fee" for processing the transaction. A higher minfeeB means every
* transaction will have a higher minimum cost, regardless of its size.
*
* This discourages spamming the network with a large number of tiny transactions.
*
* @param minFeeB fee to be added to every transaction regardless of its size, or undefined
* if not set.
*/
setMinFeeB(minFeeB: Cardano.Lovelace): void {
this.#minFeeB = minFeeB;
this.#originalBytes = undefined;
}
/**
* Gets the minFeeB component of the transaction fee computation.
*
* @returns The transaction fee to be added to every transaction regardless of its size, or undefined
* if not set.
*/
minFeeB(): Cardano.Lovelace | undefined {
return this.#minFeeB;
}
/**
* Sets the maximum block body size. It sets an upper limit on the size of the block's body.
*
* @param maxBlockBodySize The block body size in bytes.
*/
setMaxBlockBodySize(maxBlockBodySize: number): void {
this.#maxBlockBodySize = maxBlockBodySize;
this.#originalBytes = undefined;
}
/**
* Gets the maximum block body size.
*
* @returns The maximum block body size in bytes, or undefined
* if not set.
*/
maxBlockBodySize(): number | undefined {
return this.#maxBlockBodySize;
}
/**
* Sets the maximum transaction size. This limits the size of individual transactions.
*
* @param maxTxSize The transaction size in bytes.
*/
setMaxTxSize(maxTxSize: number): void {
this.#maxTxSize = maxTxSize;
this.#originalBytes = undefined;
}
/**
* Gets the maximum transaction size. This limits the size of individual transactions.
*
* @returns The transaction size in bytes, or undefined
* if not set.
*/
maxTxSize(): number | undefined {
return this.#maxTxSize;
}
/**
* Sets the maximum block header size.
*
* @param maxBlockHeaderSize The block header size in bytes.
*/
setMaxBlockHeaderSize(maxBlockHeaderSize: number): void {
this.#maxBlockHeaderSize = maxBlockHeaderSize;
this.#originalBytes = undefined;
}
/**
* Gets the maximum block header size.
*
* @returns The block header size in bytes, or undefined
* if not set.
*/
maxBlockHeaderSize(): number | undefined {
return this.#maxBlockHeaderSize;
}
/**
* Sets the amount of ADA required as a deposit for staking key registration.
*
* @param keyDeposit The amount of ADA required in lovelace.
*/
setKeyDeposit(keyDeposit: Cardano.Lovelace): void {
this.#keyDeposit = keyDeposit;
this.#originalBytes = undefined;
}
/**
* Gets the amount of ADA required as a deposit for staking key registration.
*
* @returns The amount of ADA required in lovelace, or undefined
* if not set.
*/
keyDeposit(): Cardano.Lovelace | undefined {
return this.#keyDeposit;
}
/**
* Sets the amount of ADA required as a deposit for stake pool registration.
*
* @param poolDeposit The amount of ADA required in lovelace, or undefined
* if not set.
*/
setPoolDeposit(poolDeposit: Cardano.Lovelace): void {
this.#poolDeposit = poolDeposit;
this.#originalBytes = undefined;
}
/**
* Gets the amount of ADA required as a deposit for stake pool registration.
*
* @returns The amount of ADA required in lovelace, or undefined
* if not set.
*/
poolDeposit(): Cardano.Lovelace | undefined {
return this.#poolDeposit;
}
/**
* Sets the maximum epoch (number of epochs) for which a pool can be ranked in
* the non-myopic member rewards.
*
* @param maxEpoch The maximum number of epochs.
*/
setMaxEpoch(maxEpoch: number): void {
this.#maxEpoch = maxEpoch;
this.#originalBytes = undefined;
}
/**
* Gets the maximum epoch (number of epochs) for which a pool can be ranked in
* the non-myopic member rewards.
*
* @returns The maximum epoch number of epochs, or undefined
* if not set.
*/
maxEpoch(): number | undefined {
return this.#maxEpoch;
}
/**
* Sets the desired number of stake pools. It's used in the rewards calculation
* to encourage a certain number of active stake pools.
*
* @param nOpt The desired number of stake pools.
*/
setNOpt(nOpt: number): void {
this.#nOpt = nOpt;
this.#originalBytes = undefined;
}
/**
* Gets the desired number of stake pools. It's used in the rewards calculation
* to encourage a certain number of active stake pools.
*
* @returns The desired number of stake pools, or undefined
* if not set.
*/
nOpt(): number | undefined {
return this.#nOpt;
}
/**
* Sets the pool pledge power of influencing rewards for stake pools, determining how
* much stake pool owners versus delegators get.
*
* @param poolPledgeInfluence The pool pledge power of influence over rewards (a0).
*/
setPoolPledgeInfluence(poolPledgeInfluence: UnitInterval): void {
this.#poolPledgeInfluence = poolPledgeInfluence;
this.#originalBytes = undefined;
}
/**
* Gets the pool pledge power of influencing rewards for stake pools, determining how
* much stake pool owners versus delegators get.
*
* @returns The pool pledge power of influence over rewards (a0), or undefined
* if not set.
*/
poolPledgeInfluence(): UnitInterval | undefined {
return this.#poolPledgeInfluence;
}
/**
* Sets the rate at which ADA is taken from the reserves and used for epoch rewards and treasury.
*
* @param expansionRate The rate at which ADA is taken from the reserves.
*/
setExpansionRate(expansionRate: UnitInterval): void {
this.#expansionRate = expansionRate;
this.#originalBytes = undefined;
}
/**
* Gets the rate at which ADA is taken from the reserves and used for epoch rewards and treasury.
*
* @returns The rate at which ADA is taken from the reserves, or undefined
* if not set.
*/
expansionRate(): UnitInterval | undefined {
return this.#expansionRate;
}
/**
* Sets the percentage of rewards taken from the total to populate the treasury.
*
* @param treasuryGrowthRate The percentage of rewards.
*/
setTreasuryGrowthRate(treasuryGrowthRate: UnitInterval): void {
this.#treasuryGrowthRate = treasuryGrowthRate;
this.#originalBytes = undefined;
}
/**
* Gets the percentage of rewards taken from the total to populate the treasury.
*
* @returns The percentage of rewards, or undefined
* if not set.
*/
treasuryGrowthRate(): UnitInterval | undefined {
return this.#treasuryGrowthRate;
}
// Alonzo
/**
* Sets the degree of decentralization; ranges from 0 to 1. A value of 1 indicates
* complete decentralization, i.e., all blocks are produced by community stake pools,
* while 0 would indicate a fully centralized scenario.
*
* REMARK: This parameter is only used in the Alonzo era. Do not set it for other eras.
*
* @param d The degree of decentralization.
*/
setD(d: UnitInterval): void {
this.#d = d;
this.#originalBytes = undefined;
}
/**
* Gets the degree of decentralization; ranges from 0 to 1. A value of 1 indicates
* complete decentralization, i.e., all blocks are produced by community stake pools,
* while 0 would indicate a fully centralized scenario.
*
* @returns The degree of decentralization, or undefined
* if not set.
*/
d(): UnitInterval | undefined {
return this.#d;
}
/**
* Sets additional randomness used to seed the pseudo-random number generator for leader election.
*
* REMARK: This parameter is only used in the Alonzo era. Do not set it for other eras.
*
* @param extraEntropy The additional randomness.
*/
setExtraEntropy(extraEntropy: HexBlob): void {
this.#extraEntropy = extraEntropy;
this.#originalBytes = undefined;
}
/**
* Gets additional randomness used to seed the pseudo-random number generator for leader election.
*
* @returns The additional randomness, or undefined
* if not set.
*/
extraEntropy(): HexBlob | undefined {
return this.#extraEntropy;
}
/**
* Sets the proposed protocol version. It's a tuple two numbers: major and minor.
*
* @param protocolVersion the protocol version.
*/
setProtocolVersion(protocolVersion: ProtocolVersion): void {
this.#protocolVersion = protocolVersion;
this.#originalBytes = undefined;
}
/**
* Gets the proposed protocol version. It's a tuple two numbers: major and minor.
*
* @returns The protocol version, or undefined
* if not set.
*/
protocolVersion(): ProtocolVersion | undefined {
return this.#protocolVersion;
}
/**
* Sets the minimum operational cost for a stake pool per epoch, ensuring that
* stake pools cannot advertise a cost that is too low.
*
* @param minPoolCost The minimum operational cost.
*/
setMinPoolCost(minPoolCost: Cardano.Lovelace): void {
this.#minPoolCost = minPoolCost;
this.#originalBytes = undefined;
}
/**
* Gets the minimum operational cost for a stake pool per epoch, ensuring that
* stake pools cannot advertise a cost that is too low.
*
* @returns The minimum operational cost, or undefined
* if not set.
*/
minPoolCost(): Cardano.Lovelace | undefined {
return this.#minPoolCost;
}
/**
* Sets the cost in Lovelaces for storing one byte of data.
*
* @param adaPerUtxoByte The cost in Lovelaces for storing one byte of data.
*/
setAdaPerUtxoByte(adaPerUtxoByte: Cardano.Lovelace): void {
this.#adaPerUtxoByte = adaPerUtxoByte;
this.#originalBytes = undefined;
}
/**
* Gets the cost for storing one byte of data.
*
* @returns The cost for storing one byte of data, or undefined
* if not set.
*/
adaPerUtxoByte(): Cardano.Lovelace | undefined {
return this.#adaPerUtxoByte;
}
/**
* Sets the cost models for Plutus scripts, defining the resources each
* operation in a Plutus script consumes.
*
* @param costModels The cost models for Plutus scripts.
*/
setCostModels(costModels: Costmdls): void {
this.#costModels = costModels;
this.#originalBytes = undefined;
}
/**
* Gets the cost models for Plutus scripts, defining the resources each
* operation in a Plutus script consumes.
*
* @returns The cost models for Plutus scripts, or undefined
* if not set.
*/
costModels(): Costmdls | undefined {
return this.#costModels;
}
/**
* Sets the prices for the ExUnits consumed by Plutus scripts.
*
* @param executionCosts The prices for the ExUnits.
*/
setExecutionCosts(executionCosts: ExUnitPrices): void {
this.#executionCosts = executionCosts;
this.#originalBytes = undefined;
}
/**
* Gets the prices for the ExUnits consumed by Plutus scripts.
*
* @returns The prices for the ExUnits, or undefined
* if not set.
*/
executionCosts(): ExUnitPrices | undefined {
return this.#executionCosts;
}
/**
* Sets the maximum ExUnits that a transaction can consume.
*
* @param maxTxExUnits The maximum ExUnits.
*/
setMaxTxExUnits(maxTxExUnits: ExUnits): void {
this.#maxTxExUnits = maxTxExUnits;
this.#originalBytes = undefined;
}
/**
* Gets the maximum ExUnits that a transaction can consume.
*
* @returns The maximum ExUnits, or undefined
* if not set.
*/
maxTxExUnits(): ExUnits | undefined {
return this.#maxTxExUnits;
}
/**
* Sets the maximum ExUnits that a block can consume.
*
* @param maxBlockExUnits The maximum ExUnits.
*/
setMaxBlockExUnits(maxBlockExUnits: ExUnits): void {
this.#maxBlockExUnits = maxBlockExUnits;
this.#originalBytes = undefined;
}
/**
* Gets the maximum ExUnits that a block can consume.
*
* @returns The maximum ExUnits, or undefined
* if not set.
*/
maxBlockExUnits(): ExUnits | undefined {
return this.#maxBlockExUnits;
}
/**
* Sets the maximum serialized length (in bytes) of a multi-asset value (token bundle)
* in a transaction output.
*
* @param maxValueSize The maximum serialized length (in bytes).
*/
setMaxValueSize(maxValueSize: number): void {
this.#maxValueSize = maxValueSize;
this.#originalBytes = undefined;
}
/**
* Gets the maximum serialized length (in bytes) of a multi-asset value (token bundle)
* in a transaction output.
*
* @returns The maximum serialized length (in bytes), or undefined
* if not set.
*/
maxValueSize(): number | undefined {
return this.#maxValueSize;
}
/**
* Sets the percentage of the total transaction fee its collateral must (at minimum) cover.
*
* @param collateralPercentage The percentage of the total transaction fee.
*/
setCollateralPercentage(collateralPercentage: number): void {
this.#collateralPercentage = collateralPercentage;
this.#originalBytes = undefined;
}