@meshsdk/core-cst 1.9.0-beta.17 → 1.9.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +112 -95
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +111 -95
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -3600,6 +3600,7 @@ __export(index_exports, {
|
|
|
3600
3600
|
buildRewardAddress: () => buildRewardAddress,
|
|
3601
3601
|
buildScriptPubkey: () => buildScriptPubkey,
|
|
3602
3602
|
bytesToHex: () => bytesToHex,
|
|
3603
|
+
calculateFees: () => calculateFees,
|
|
3603
3604
|
checkSignature: () => checkSignature,
|
|
3604
3605
|
clampScalar: () => clampScalar,
|
|
3605
3606
|
computeAuxiliaryDataHash: () => computeAuxiliaryDataHash,
|
|
@@ -4980,7 +4981,7 @@ var plutusDataToAddrBech32 = (plutusData, networkId = 0) => {
|
|
|
4980
4981
|
}
|
|
4981
4982
|
const cardanoPaymentCredential = {
|
|
4982
4983
|
hash: Hash28ByteBase162(Buffer.from(paymentBytes).toString("hex")),
|
|
4983
|
-
type: paymentConstrData.getAlternative()
|
|
4984
|
+
type: Number(paymentConstrData.getAlternative())
|
|
4984
4985
|
};
|
|
4985
4986
|
const delegationData = plutusDataList.get(1);
|
|
4986
4987
|
const delegationConstrData = delegationData.asConstrPlutusData();
|
|
@@ -5015,15 +5016,27 @@ var plutusDataToAddrBech32 = (plutusData, networkId = 0) => {
|
|
|
5015
5016
|
"Error: serializeAddressObj: Delegation inner part must contain 1 element"
|
|
5016
5017
|
);
|
|
5017
5018
|
}
|
|
5018
|
-
const
|
|
5019
|
+
const delegationCredential = delegationDataInnerList.get(0).asConstrPlutusData();
|
|
5020
|
+
if (!delegationCredential) {
|
|
5021
|
+
throw new Error(
|
|
5022
|
+
"Error: serializeAddressObj: Delegation inner part must be a constructor"
|
|
5023
|
+
);
|
|
5024
|
+
}
|
|
5025
|
+
const delegationBytesList = delegationCredential.getData();
|
|
5026
|
+
if (delegationBytesList.getLength() !== 1) {
|
|
5027
|
+
throw new Error(
|
|
5028
|
+
"Error: serializeAddressObj: Delegation bytes part must contain 1 element"
|
|
5029
|
+
);
|
|
5030
|
+
}
|
|
5031
|
+
const delegationBytes = delegationBytesList.get(0).asBoundedBytes();
|
|
5019
5032
|
if (!delegationBytes) {
|
|
5020
5033
|
throw new Error(
|
|
5021
|
-
"Error: serializeAddressObj: Delegation
|
|
5034
|
+
"Error: serializeAddressObj: Delegation bytes part must be of type bytes"
|
|
5022
5035
|
);
|
|
5023
5036
|
}
|
|
5024
5037
|
const cardanoStakeCredential = {
|
|
5025
5038
|
hash: Hash28ByteBase162(Buffer.from(delegationBytes).toString("hex")),
|
|
5026
|
-
type:
|
|
5039
|
+
type: Number(delegationCredential.getAlternative())
|
|
5027
5040
|
};
|
|
5028
5041
|
return BaseAddress.fromCredentials(
|
|
5029
5042
|
networkId,
|
|
@@ -5170,6 +5183,54 @@ var addVKeyWitnessSetToTransaction = (txHex, vkeyWitnessSet) => {
|
|
|
5170
5183
|
return tx.toCbor();
|
|
5171
5184
|
};
|
|
5172
5185
|
|
|
5186
|
+
// src/utils/fee.ts
|
|
5187
|
+
var calculateFees = (minFeeA, minFeeB, minFeeRefScriptCostPerByte, priceMem, priceStep, tx, refScriptSize) => {
|
|
5188
|
+
let fee = minFeeB + tx.toCbor().length / 2 * minFeeA;
|
|
5189
|
+
fee += calculateRefScriptFees(refScriptSize, minFeeRefScriptCostPerByte);
|
|
5190
|
+
let scriptFee = BigInt(0);
|
|
5191
|
+
let priceMemNumerator = priceMem;
|
|
5192
|
+
let priceMemDenominator = 1;
|
|
5193
|
+
while (priceMemNumerator % 1) {
|
|
5194
|
+
priceMemNumerator *= 10;
|
|
5195
|
+
priceMemDenominator *= 10;
|
|
5196
|
+
}
|
|
5197
|
+
let priceStepNumerator = priceStep;
|
|
5198
|
+
let priceStepDenominator = 1;
|
|
5199
|
+
while (priceStepNumerator % 1) {
|
|
5200
|
+
priceStepNumerator *= 10;
|
|
5201
|
+
priceStepDenominator *= 10;
|
|
5202
|
+
}
|
|
5203
|
+
if (tx.witnessSet().redeemers()) {
|
|
5204
|
+
for (const redeemer of tx.witnessSet().redeemers().values()) {
|
|
5205
|
+
scriptFee += redeemer.exUnits().mem() * BigInt(priceMemNumerator.toString()) / BigInt(priceMemDenominator.toString());
|
|
5206
|
+
scriptFee += redeemer.exUnits().steps() * BigInt(priceStepNumerator.toString()) / BigInt(priceStepDenominator.toString());
|
|
5207
|
+
if (priceMemNumerator % priceMemDenominator !== 0) {
|
|
5208
|
+
scriptFee += BigInt(1);
|
|
5209
|
+
}
|
|
5210
|
+
if (priceStepNumerator % priceStepDenominator !== 0) {
|
|
5211
|
+
scriptFee += BigInt(1);
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
}
|
|
5215
|
+
return BigInt(fee) + scriptFee;
|
|
5216
|
+
};
|
|
5217
|
+
var calculateRefScriptFees = (refScriptSize, minFeeRefScriptCostPerByte, tierMultiplier = 1.2) => {
|
|
5218
|
+
let fee = 0;
|
|
5219
|
+
const tierSize = 25600;
|
|
5220
|
+
let currentRefScriptSize = refScriptSize;
|
|
5221
|
+
let multiplier = 1;
|
|
5222
|
+
while (currentRefScriptSize >= tierSize) {
|
|
5223
|
+
fee += tierSize * multiplier * minFeeRefScriptCostPerByte;
|
|
5224
|
+
currentRefScriptSize -= tierSize;
|
|
5225
|
+
multiplier *= tierMultiplier;
|
|
5226
|
+
}
|
|
5227
|
+
if (currentRefScriptSize > 0) {
|
|
5228
|
+
fee += currentRefScriptSize * multiplier * minFeeRefScriptCostPerByte;
|
|
5229
|
+
}
|
|
5230
|
+
fee = Math.ceil(fee);
|
|
5231
|
+
return fee;
|
|
5232
|
+
};
|
|
5233
|
+
|
|
5173
5234
|
// src/resolvers/index.ts
|
|
5174
5235
|
var resolveDataHash = (data) => {
|
|
5175
5236
|
const plutusData = toPlutusData(data);
|
|
@@ -5401,7 +5462,7 @@ var toCardanoCert = (cert) => {
|
|
|
5401
5462
|
return Certificate.newStakeDelegation(
|
|
5402
5463
|
new import_core5.Serialization.StakeDelegation(
|
|
5403
5464
|
rewardAddress.getPaymentCredential(),
|
|
5404
|
-
Ed25519KeyHashHex2(cert.poolId)
|
|
5465
|
+
cert.poolId.startsWith("pool1") ? import_core5.Cardano.PoolId.toKeyHash(import_core5.Cardano.PoolId(cert.poolId)) : Ed25519KeyHashHex2(cert.poolId)
|
|
5405
5466
|
)
|
|
5406
5467
|
);
|
|
5407
5468
|
}
|
|
@@ -5423,7 +5484,7 @@ var toCardanoCert = (cert) => {
|
|
|
5423
5484
|
case "RetirePool": {
|
|
5424
5485
|
return Certificate.newPoolRetirement(
|
|
5425
5486
|
new import_core5.Serialization.PoolRetirement(
|
|
5426
|
-
Ed25519KeyHashHex2(cert.poolId),
|
|
5487
|
+
cert.poolId.startsWith("pool1") ? import_core5.Cardano.PoolId.toKeyHash(import_core5.Cardano.PoolId(cert.poolId)) : Ed25519KeyHashHex2(cert.poolId),
|
|
5427
5488
|
import_core5.Cardano.EpochNo(cert.epoch)
|
|
5428
5489
|
)
|
|
5429
5490
|
);
|
|
@@ -5676,54 +5737,6 @@ var toCardanoCert = (cert) => {
|
|
|
5676
5737
|
}
|
|
5677
5738
|
};
|
|
5678
5739
|
|
|
5679
|
-
// src/utils/fee.ts
|
|
5680
|
-
var calculateFees = (minFeeA, minFeeB, minFeeRefScriptCostPerByte, priceMem, priceStep, tx, refScriptSize) => {
|
|
5681
|
-
let fee = minFeeB + tx.toCbor().length / 2 * minFeeA;
|
|
5682
|
-
fee += calculateRefScriptFees(refScriptSize, minFeeRefScriptCostPerByte);
|
|
5683
|
-
let scriptFee = BigInt(0);
|
|
5684
|
-
let priceMemNumerator = priceMem;
|
|
5685
|
-
let priceMemDenominator = 1;
|
|
5686
|
-
while (priceMemNumerator % 1) {
|
|
5687
|
-
priceMemNumerator *= 10;
|
|
5688
|
-
priceMemDenominator *= 10;
|
|
5689
|
-
}
|
|
5690
|
-
let priceStepNumerator = priceStep;
|
|
5691
|
-
let priceStepDenominator = 1;
|
|
5692
|
-
while (priceStepNumerator % 1) {
|
|
5693
|
-
priceStepNumerator *= 10;
|
|
5694
|
-
priceStepDenominator *= 10;
|
|
5695
|
-
}
|
|
5696
|
-
if (tx.witnessSet().redeemers()) {
|
|
5697
|
-
for (const redeemer of tx.witnessSet().redeemers().values()) {
|
|
5698
|
-
scriptFee += redeemer.exUnits().mem() * BigInt(priceMemNumerator.toString()) / BigInt(priceMemDenominator.toString());
|
|
5699
|
-
scriptFee += redeemer.exUnits().steps() * BigInt(priceStepNumerator.toString()) / BigInt(priceStepDenominator.toString());
|
|
5700
|
-
if (priceMemNumerator % priceMemDenominator !== 0) {
|
|
5701
|
-
scriptFee += BigInt(1);
|
|
5702
|
-
}
|
|
5703
|
-
if (priceStepNumerator % priceStepDenominator !== 0) {
|
|
5704
|
-
scriptFee += BigInt(1);
|
|
5705
|
-
}
|
|
5706
|
-
}
|
|
5707
|
-
}
|
|
5708
|
-
return BigInt(fee) + scriptFee;
|
|
5709
|
-
};
|
|
5710
|
-
var calculateRefScriptFees = (refScriptSize, minFeeRefScriptCostPerByte, tierMultiplier = 1.2) => {
|
|
5711
|
-
let fee = 0;
|
|
5712
|
-
const tierSize = 25600;
|
|
5713
|
-
let currentRefScriptSize = refScriptSize;
|
|
5714
|
-
let multiplier = 1;
|
|
5715
|
-
while (currentRefScriptSize >= tierSize) {
|
|
5716
|
-
fee += tierSize * multiplier * minFeeRefScriptCostPerByte;
|
|
5717
|
-
currentRefScriptSize -= tierSize;
|
|
5718
|
-
multiplier *= tierMultiplier;
|
|
5719
|
-
}
|
|
5720
|
-
if (currentRefScriptSize > 0) {
|
|
5721
|
-
fee += currentRefScriptSize * multiplier * minFeeRefScriptCostPerByte;
|
|
5722
|
-
}
|
|
5723
|
-
fee = Math.ceil(fee);
|
|
5724
|
-
return fee;
|
|
5725
|
-
};
|
|
5726
|
-
|
|
5727
5740
|
// src/utils/metadata.ts
|
|
5728
5741
|
var toCardanoMetadataMap = (metadata) => {
|
|
5729
5742
|
let cardanoMetadataMap = /* @__PURE__ */ new Map();
|
|
@@ -6207,6 +6220,10 @@ var CardanoSDKSerializerCore = class {
|
|
|
6207
6220
|
withdrawals,
|
|
6208
6221
|
votes
|
|
6209
6222
|
} = txBuilderBody;
|
|
6223
|
+
const uniqueRefInputs = this.removeBodyInputRefInputOverlap(
|
|
6224
|
+
inputs,
|
|
6225
|
+
referenceInputs
|
|
6226
|
+
);
|
|
6210
6227
|
this.addAllInputs(inputs);
|
|
6211
6228
|
this.sanitizeOutputs(outputs);
|
|
6212
6229
|
this.addAllOutputs(outputs);
|
|
@@ -6215,7 +6232,7 @@ var CardanoSDKSerializerCore = class {
|
|
|
6215
6232
|
this.addAllWithdrawals(withdrawals);
|
|
6216
6233
|
this.addAllVotes(votes);
|
|
6217
6234
|
this.addAllCollateralInputs(collaterals);
|
|
6218
|
-
this.addAllReferenceInputs(
|
|
6235
|
+
this.addAllReferenceInputs(uniqueRefInputs);
|
|
6219
6236
|
this.removeInputRefInputOverlap();
|
|
6220
6237
|
this.setValidityInterval(validityRange);
|
|
6221
6238
|
this.addAllRequiredSignatures(requiredSignatures);
|
|
@@ -6334,16 +6351,10 @@ var CardanoSDKSerializerCore = class {
|
|
|
6334
6351
|
fromBuilderToPlutusData(currentTxIn.scriptTxIn.datumSource.data)
|
|
6335
6352
|
);
|
|
6336
6353
|
} else if (currentTxIn.scriptTxIn.datumSource.type === "Inline") {
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
TransactionId(currentTxIn.txIn.txHash),
|
|
6342
|
-
BigInt(currentTxIn.txIn.txIndex)
|
|
6343
|
-
)
|
|
6344
|
-
);
|
|
6345
|
-
referenceInputs.setValues(referenceInputsList);
|
|
6346
|
-
this.txBody.setReferenceInputs(referenceInputs);
|
|
6354
|
+
this.addReferenceInput({
|
|
6355
|
+
txHash: currentTxIn.txIn.txHash,
|
|
6356
|
+
txIndex: currentTxIn.txIn.txIndex
|
|
6357
|
+
});
|
|
6347
6358
|
}
|
|
6348
6359
|
let exUnits = currentTxIn.scriptTxIn.redeemer.exUnits;
|
|
6349
6360
|
let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
|
|
@@ -6451,6 +6462,10 @@ var CardanoSDKSerializerCore = class {
|
|
|
6451
6462
|
addReferenceInput = (refInput) => {
|
|
6452
6463
|
let referenceInputs = this.txBody.referenceInputs() ?? import_core8.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
|
|
6453
6464
|
let referenceInputsList = [...referenceInputs.values()];
|
|
6465
|
+
if (referenceInputsList.some(
|
|
6466
|
+
(input) => input.transactionId().toString() === refInput.txHash && input.index().toString() === refInput.txIndex.toString()
|
|
6467
|
+
))
|
|
6468
|
+
return;
|
|
6454
6469
|
referenceInputsList.push(
|
|
6455
6470
|
new TransactionInput(
|
|
6456
6471
|
TransactionId(refInput.txHash),
|
|
@@ -6458,6 +6473,9 @@ var CardanoSDKSerializerCore = class {
|
|
|
6458
6473
|
)
|
|
6459
6474
|
);
|
|
6460
6475
|
referenceInputs.setValues(referenceInputsList);
|
|
6476
|
+
if (refInput.scriptSize) {
|
|
6477
|
+
this.refScriptSize += refInput.scriptSize;
|
|
6478
|
+
}
|
|
6461
6479
|
this.txBody.setReferenceInputs(referenceInputs);
|
|
6462
6480
|
};
|
|
6463
6481
|
addAllMints = (mints) => {
|
|
@@ -6835,6 +6853,18 @@ var CardanoSDKSerializerCore = class {
|
|
|
6835
6853
|
);
|
|
6836
6854
|
}
|
|
6837
6855
|
};
|
|
6856
|
+
removeBodyInputRefInputOverlap = (inputs, refInputs) => {
|
|
6857
|
+
let finalRefInputs = [];
|
|
6858
|
+
for (let i = 0; i < refInputs.length; i++) {
|
|
6859
|
+
let refInput = refInputs[i];
|
|
6860
|
+
if (!inputs.some(
|
|
6861
|
+
(input) => input.txIn.txHash === refInput.txHash && input.txIn.txIndex === refInput.txIndex
|
|
6862
|
+
)) {
|
|
6863
|
+
finalRefInputs.push(refInput);
|
|
6864
|
+
}
|
|
6865
|
+
}
|
|
6866
|
+
return finalRefInputs;
|
|
6867
|
+
};
|
|
6838
6868
|
balanceTx = (changeAddress) => {
|
|
6839
6869
|
if (changeAddress === "") {
|
|
6840
6870
|
throw new Error("Can't balance tx without a change address");
|
|
@@ -7024,16 +7054,16 @@ var CardanoSDKSerializerCore = class {
|
|
|
7024
7054
|
if (scriptSource.type !== "Inline") {
|
|
7025
7055
|
return;
|
|
7026
7056
|
}
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7057
|
+
if (!scriptSource.scriptSize) {
|
|
7058
|
+
throw new Error(
|
|
7059
|
+
"A reference script was used without providing its size, this must be provided as fee calculations are based on it"
|
|
7060
|
+
);
|
|
7061
|
+
}
|
|
7062
|
+
this.addReferenceInput({
|
|
7063
|
+
txHash: scriptSource.txHash,
|
|
7064
|
+
txIndex: scriptSource.txIndex,
|
|
7065
|
+
scriptSize: Number(scriptSource.scriptSize)
|
|
7066
|
+
});
|
|
7037
7067
|
switch (scriptSource.version) {
|
|
7038
7068
|
case "V1": {
|
|
7039
7069
|
this.usedLanguages[PlutusLanguageVersion.V1] = true;
|
|
@@ -7048,35 +7078,21 @@ var CardanoSDKSerializerCore = class {
|
|
|
7048
7078
|
break;
|
|
7049
7079
|
}
|
|
7050
7080
|
}
|
|
7051
|
-
if (scriptSource.scriptSize) {
|
|
7052
|
-
this.refScriptSize += Number(scriptSource.scriptSize);
|
|
7053
|
-
} else {
|
|
7054
|
-
throw new Error(
|
|
7055
|
-
"A reference script was used without providing its size, this must be provided as fee calculations are based on it"
|
|
7056
|
-
);
|
|
7057
|
-
}
|
|
7058
7081
|
};
|
|
7059
7082
|
addSimpleScriptRef = (simpleScriptSource) => {
|
|
7060
7083
|
if (simpleScriptSource.type !== "Inline") {
|
|
7061
7084
|
return;
|
|
7062
7085
|
}
|
|
7063
|
-
|
|
7064
|
-
let referenceInputsList = [...referenceInputs.values()];
|
|
7065
|
-
referenceInputsList.push(
|
|
7066
|
-
new TransactionInput(
|
|
7067
|
-
TransactionId(simpleScriptSource.txHash),
|
|
7068
|
-
BigInt(simpleScriptSource.txIndex)
|
|
7069
|
-
)
|
|
7070
|
-
);
|
|
7071
|
-
if (simpleScriptSource.scriptSize) {
|
|
7072
|
-
this.refScriptSize += Number(simpleScriptSource.scriptSize);
|
|
7073
|
-
} else {
|
|
7086
|
+
if (!simpleScriptSource.scriptSize) {
|
|
7074
7087
|
throw new Error(
|
|
7075
7088
|
"A reference script was used without providing its size, this must be provided as fee calculations are based on it"
|
|
7076
7089
|
);
|
|
7077
7090
|
}
|
|
7078
|
-
|
|
7079
|
-
|
|
7091
|
+
this.addReferenceInput({
|
|
7092
|
+
txHash: simpleScriptSource.txHash,
|
|
7093
|
+
txIndex: simpleScriptSource.txIndex,
|
|
7094
|
+
scriptSize: Number(simpleScriptSource.scriptSize)
|
|
7095
|
+
});
|
|
7080
7096
|
};
|
|
7081
7097
|
countNumberOfRequiredWitnesses() {
|
|
7082
7098
|
let requiredWitnesses = /* @__PURE__ */ new Set();
|
|
@@ -7608,6 +7624,7 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
|
|
|
7608
7624
|
buildRewardAddress,
|
|
7609
7625
|
buildScriptPubkey,
|
|
7610
7626
|
bytesToHex,
|
|
7627
|
+
calculateFees,
|
|
7611
7628
|
checkSignature,
|
|
7612
7629
|
clampScalar,
|
|
7613
7630
|
computeAuxiliaryDataHash,
|
package/dist/index.d.cts
CHANGED
|
@@ -406,6 +406,8 @@ declare const hexToBech32: (prefix: string, hex: string) => string;
|
|
|
406
406
|
|
|
407
407
|
declare const addVKeyWitnessSetToTransaction: (txHex: string, vkeyWitnessSet: string) => string;
|
|
408
408
|
|
|
409
|
+
declare const calculateFees: (minFeeA: number, minFeeB: number, minFeeRefScriptCostPerByte: number, priceMem: number, priceStep: number, tx: Transaction, refScriptSize: number) => bigint;
|
|
410
|
+
|
|
409
411
|
/**
|
|
410
412
|
* MIT License
|
|
411
413
|
*
|
|
@@ -451,4 +453,4 @@ declare const normalizePlutusScript: (plutusScript: string, encoding: OutputEnco
|
|
|
451
453
|
declare const applyEncoding: (plutusScript: Uint8Array, outputEncoding: OutputEncoding) => Uint8Array;
|
|
452
454
|
declare const applyParamsToScript: (rawScript: string, params: object[] | Data[], type?: PlutusDataType) => string;
|
|
453
455
|
|
|
454
|
-
export { Address, AddressType, AssetFingerprint, AssetId, AssetName, type AuxiliaryData, AuxilliaryData, BaseAddress, Bip32PrivateKey, Bip32PrivateKeyHex, Bip32PublicKey, Bip32PublicKeyHex, CardanoSDKSerializer, CborSet, CborWriter, CertIndex, Certificate, CertificateType, ConstrPlutusData, CoseSign1, CostModel, type CostModels, Costmdls, Credential, type CredentialCore, CredentialType, DRep, DRepID, Datum, DatumHash, DatumKind, Ed25519KeyHash, Ed25519KeyHashHex, Ed25519PrivateExtendedKeyHex, Ed25519PrivateKey, Ed25519PrivateNormalKeyHex, Ed25519PublicKey, Ed25519PublicKeyHex, Ed25519Signature, Ed25519SignatureHex, EnterpriseAddress, ExUnits, Hash, Hash28ByteBase16, Hash32ByteBase16, HexBlob, type Metadatum, MetadatumList, MetadatumMap, NativeScript, NetworkId, type OutputEncoding, PaymentAddress, PlutusData, PlutusDataKind, PlutusLanguageVersion, PlutusList, PlutusMap, PlutusV1Script, PlutusV2Script, PlutusV3Script, PointerAddress, PolicyId, PoolId, Redeemer, RedeemerPurpose, RedeemerTag, Redeemers, RequireAllOf, RequireAnyOf, RequireNOf, RequireSignature, RequireTimeAfter, RequireTimeBefore, RewardAccount, RewardAddress, Script, ScriptHash, ScriptPubkey, type Signatures, type Signer, Slot, StakeCredentialStatus, StakeDelegation, type StakeDelegationCertificate, StakeRegistration, type TokenMap, Transaction, TransactionBody, TransactionId, TransactionInput, type TransactionInputSet, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, type TransactionWitnessPlutusData, TransactionWitnessSet, TxCBOR, TxIndex, Value, VkeyWitness, VrfVkBech32, type Witness, addVKeyWitnessSetToTransaction, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, addressToBech32, applyEncoding, applyParamsToScript, assetTypes, blake2b, buildBaseAddress, buildBip32PrivateKey, buildDRepID, buildEd25519PrivateKeyFromSecretKey, buildEnterpriseAddress, buildKeys, buildRewardAddress, buildScriptPubkey, bytesToHex, checkSignature, clampScalar, computeAuxiliaryDataHash, deserializeAddress, deserializeBech32Address, deserializeDataHash, deserializeEd25519KeyHash, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxHash, deserializeTxUnspentOutput, deserializeValue, empty, fromBuilderToPlutusData, fromJsonToPlutusData, fromNativeScript, fromPlutusDataToJson, fromScriptRef, fromTxUnspentOutput, fromValue, generateNonce, getCoseKeyFromPublicKey, getDRepIds, getPublicKeyFromCoseKey, hexToBech32, hexToBytes, keyHashToRewardAddress, mergeValue, negateValue, negatives, normalizePlutusScript, parseDatumCbor, parseInlineDatum, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, scriptHashToBech32, scriptHashToRewardAddress, serializeAddressObj, serializePlutusAddressToBech32, serialzeAddress, signData, subValue, toAddress, toBaseAddress, toCardanoAddress, toDRep, toEnterpriseAddress, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toTxUnspentOutput, toValue, utf8ToBytes, utf8ToHex, v2ScriptToBech32 };
|
|
456
|
+
export { Address, AddressType, AssetFingerprint, AssetId, AssetName, type AuxiliaryData, AuxilliaryData, BaseAddress, Bip32PrivateKey, Bip32PrivateKeyHex, Bip32PublicKey, Bip32PublicKeyHex, CardanoSDKSerializer, CborSet, CborWriter, CertIndex, Certificate, CertificateType, ConstrPlutusData, CoseSign1, CostModel, type CostModels, Costmdls, Credential, type CredentialCore, CredentialType, DRep, DRepID, Datum, DatumHash, DatumKind, Ed25519KeyHash, Ed25519KeyHashHex, Ed25519PrivateExtendedKeyHex, Ed25519PrivateKey, Ed25519PrivateNormalKeyHex, Ed25519PublicKey, Ed25519PublicKeyHex, Ed25519Signature, Ed25519SignatureHex, EnterpriseAddress, ExUnits, Hash, Hash28ByteBase16, Hash32ByteBase16, HexBlob, type Metadatum, MetadatumList, MetadatumMap, NativeScript, NetworkId, type OutputEncoding, PaymentAddress, PlutusData, PlutusDataKind, PlutusLanguageVersion, PlutusList, PlutusMap, PlutusV1Script, PlutusV2Script, PlutusV3Script, PointerAddress, PolicyId, PoolId, Redeemer, RedeemerPurpose, RedeemerTag, Redeemers, RequireAllOf, RequireAnyOf, RequireNOf, RequireSignature, RequireTimeAfter, RequireTimeBefore, RewardAccount, RewardAddress, Script, ScriptHash, ScriptPubkey, type Signatures, type Signer, Slot, StakeCredentialStatus, StakeDelegation, type StakeDelegationCertificate, StakeRegistration, type TokenMap, Transaction, TransactionBody, TransactionId, TransactionInput, type TransactionInputSet, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, type TransactionWitnessPlutusData, TransactionWitnessSet, TxCBOR, TxIndex, Value, VkeyWitness, VrfVkBech32, type Witness, addVKeyWitnessSetToTransaction, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, addressToBech32, applyEncoding, applyParamsToScript, assetTypes, blake2b, buildBaseAddress, buildBip32PrivateKey, buildDRepID, buildEd25519PrivateKeyFromSecretKey, buildEnterpriseAddress, buildKeys, buildRewardAddress, buildScriptPubkey, bytesToHex, calculateFees, checkSignature, clampScalar, computeAuxiliaryDataHash, deserializeAddress, deserializeBech32Address, deserializeDataHash, deserializeEd25519KeyHash, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxHash, deserializeTxUnspentOutput, deserializeValue, empty, fromBuilderToPlutusData, fromJsonToPlutusData, fromNativeScript, fromPlutusDataToJson, fromScriptRef, fromTxUnspentOutput, fromValue, generateNonce, getCoseKeyFromPublicKey, getDRepIds, getPublicKeyFromCoseKey, hexToBech32, hexToBytes, keyHashToRewardAddress, mergeValue, negateValue, negatives, normalizePlutusScript, parseDatumCbor, parseInlineDatum, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, scriptHashToBech32, scriptHashToRewardAddress, serializeAddressObj, serializePlutusAddressToBech32, serialzeAddress, signData, subValue, toAddress, toBaseAddress, toCardanoAddress, toDRep, toEnterpriseAddress, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toTxUnspentOutput, toValue, utf8ToBytes, utf8ToHex, v2ScriptToBech32 };
|
package/dist/index.d.ts
CHANGED
|
@@ -406,6 +406,8 @@ declare const hexToBech32: (prefix: string, hex: string) => string;
|
|
|
406
406
|
|
|
407
407
|
declare const addVKeyWitnessSetToTransaction: (txHex: string, vkeyWitnessSet: string) => string;
|
|
408
408
|
|
|
409
|
+
declare const calculateFees: (minFeeA: number, minFeeB: number, minFeeRefScriptCostPerByte: number, priceMem: number, priceStep: number, tx: Transaction, refScriptSize: number) => bigint;
|
|
410
|
+
|
|
409
411
|
/**
|
|
410
412
|
* MIT License
|
|
411
413
|
*
|
|
@@ -451,4 +453,4 @@ declare const normalizePlutusScript: (plutusScript: string, encoding: OutputEnco
|
|
|
451
453
|
declare const applyEncoding: (plutusScript: Uint8Array, outputEncoding: OutputEncoding) => Uint8Array;
|
|
452
454
|
declare const applyParamsToScript: (rawScript: string, params: object[] | Data[], type?: PlutusDataType) => string;
|
|
453
455
|
|
|
454
|
-
export { Address, AddressType, AssetFingerprint, AssetId, AssetName, type AuxiliaryData, AuxilliaryData, BaseAddress, Bip32PrivateKey, Bip32PrivateKeyHex, Bip32PublicKey, Bip32PublicKeyHex, CardanoSDKSerializer, CborSet, CborWriter, CertIndex, Certificate, CertificateType, ConstrPlutusData, CoseSign1, CostModel, type CostModels, Costmdls, Credential, type CredentialCore, CredentialType, DRep, DRepID, Datum, DatumHash, DatumKind, Ed25519KeyHash, Ed25519KeyHashHex, Ed25519PrivateExtendedKeyHex, Ed25519PrivateKey, Ed25519PrivateNormalKeyHex, Ed25519PublicKey, Ed25519PublicKeyHex, Ed25519Signature, Ed25519SignatureHex, EnterpriseAddress, ExUnits, Hash, Hash28ByteBase16, Hash32ByteBase16, HexBlob, type Metadatum, MetadatumList, MetadatumMap, NativeScript, NetworkId, type OutputEncoding, PaymentAddress, PlutusData, PlutusDataKind, PlutusLanguageVersion, PlutusList, PlutusMap, PlutusV1Script, PlutusV2Script, PlutusV3Script, PointerAddress, PolicyId, PoolId, Redeemer, RedeemerPurpose, RedeemerTag, Redeemers, RequireAllOf, RequireAnyOf, RequireNOf, RequireSignature, RequireTimeAfter, RequireTimeBefore, RewardAccount, RewardAddress, Script, ScriptHash, ScriptPubkey, type Signatures, type Signer, Slot, StakeCredentialStatus, StakeDelegation, type StakeDelegationCertificate, StakeRegistration, type TokenMap, Transaction, TransactionBody, TransactionId, TransactionInput, type TransactionInputSet, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, type TransactionWitnessPlutusData, TransactionWitnessSet, TxCBOR, TxIndex, Value, VkeyWitness, VrfVkBech32, type Witness, addVKeyWitnessSetToTransaction, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, addressToBech32, applyEncoding, applyParamsToScript, assetTypes, blake2b, buildBaseAddress, buildBip32PrivateKey, buildDRepID, buildEd25519PrivateKeyFromSecretKey, buildEnterpriseAddress, buildKeys, buildRewardAddress, buildScriptPubkey, bytesToHex, checkSignature, clampScalar, computeAuxiliaryDataHash, deserializeAddress, deserializeBech32Address, deserializeDataHash, deserializeEd25519KeyHash, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxHash, deserializeTxUnspentOutput, deserializeValue, empty, fromBuilderToPlutusData, fromJsonToPlutusData, fromNativeScript, fromPlutusDataToJson, fromScriptRef, fromTxUnspentOutput, fromValue, generateNonce, getCoseKeyFromPublicKey, getDRepIds, getPublicKeyFromCoseKey, hexToBech32, hexToBytes, keyHashToRewardAddress, mergeValue, negateValue, negatives, normalizePlutusScript, parseDatumCbor, parseInlineDatum, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, scriptHashToBech32, scriptHashToRewardAddress, serializeAddressObj, serializePlutusAddressToBech32, serialzeAddress, signData, subValue, toAddress, toBaseAddress, toCardanoAddress, toDRep, toEnterpriseAddress, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toTxUnspentOutput, toValue, utf8ToBytes, utf8ToHex, v2ScriptToBech32 };
|
|
456
|
+
export { Address, AddressType, AssetFingerprint, AssetId, AssetName, type AuxiliaryData, AuxilliaryData, BaseAddress, Bip32PrivateKey, Bip32PrivateKeyHex, Bip32PublicKey, Bip32PublicKeyHex, CardanoSDKSerializer, CborSet, CborWriter, CertIndex, Certificate, CertificateType, ConstrPlutusData, CoseSign1, CostModel, type CostModels, Costmdls, Credential, type CredentialCore, CredentialType, DRep, DRepID, Datum, DatumHash, DatumKind, Ed25519KeyHash, Ed25519KeyHashHex, Ed25519PrivateExtendedKeyHex, Ed25519PrivateKey, Ed25519PrivateNormalKeyHex, Ed25519PublicKey, Ed25519PublicKeyHex, Ed25519Signature, Ed25519SignatureHex, EnterpriseAddress, ExUnits, Hash, Hash28ByteBase16, Hash32ByteBase16, HexBlob, type Metadatum, MetadatumList, MetadatumMap, NativeScript, NetworkId, type OutputEncoding, PaymentAddress, PlutusData, PlutusDataKind, PlutusLanguageVersion, PlutusList, PlutusMap, PlutusV1Script, PlutusV2Script, PlutusV3Script, PointerAddress, PolicyId, PoolId, Redeemer, RedeemerPurpose, RedeemerTag, Redeemers, RequireAllOf, RequireAnyOf, RequireNOf, RequireSignature, RequireTimeAfter, RequireTimeBefore, RewardAccount, RewardAddress, Script, ScriptHash, ScriptPubkey, type Signatures, type Signer, Slot, StakeCredentialStatus, StakeDelegation, type StakeDelegationCertificate, StakeRegistration, type TokenMap, Transaction, TransactionBody, TransactionId, TransactionInput, type TransactionInputSet, TransactionMetadatum, TransactionOutput, TransactionUnspentOutput, type TransactionWitnessPlutusData, TransactionWitnessSet, TxCBOR, TxIndex, Value, VkeyWitness, VrfVkBech32, type Witness, addVKeyWitnessSetToTransaction, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, addressToBech32, applyEncoding, applyParamsToScript, assetTypes, blake2b, buildBaseAddress, buildBip32PrivateKey, buildDRepID, buildEd25519PrivateKeyFromSecretKey, buildEnterpriseAddress, buildKeys, buildRewardAddress, buildScriptPubkey, bytesToHex, calculateFees, checkSignature, clampScalar, computeAuxiliaryDataHash, deserializeAddress, deserializeBech32Address, deserializeDataHash, deserializeEd25519KeyHash, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxHash, deserializeTxUnspentOutput, deserializeValue, empty, fromBuilderToPlutusData, fromJsonToPlutusData, fromNativeScript, fromPlutusDataToJson, fromScriptRef, fromTxUnspentOutput, fromValue, generateNonce, getCoseKeyFromPublicKey, getDRepIds, getPublicKeyFromCoseKey, hexToBech32, hexToBytes, keyHashToRewardAddress, mergeValue, negateValue, negatives, normalizePlutusScript, parseDatumCbor, parseInlineDatum, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolvePaymentKeyHash, resolvePlutusScriptAddress, resolvePlutusScriptHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, resolveTxHash, scriptHashToBech32, scriptHashToRewardAddress, serializeAddressObj, serializePlutusAddressToBech32, serialzeAddress, signData, subValue, toAddress, toBaseAddress, toCardanoAddress, toDRep, toEnterpriseAddress, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toTxUnspentOutput, toValue, utf8ToBytes, utf8ToHex, v2ScriptToBech32 };
|
package/dist/index.js
CHANGED
|
@@ -4817,7 +4817,7 @@ var plutusDataToAddrBech32 = (plutusData, networkId = 0) => {
|
|
|
4817
4817
|
}
|
|
4818
4818
|
const cardanoPaymentCredential = {
|
|
4819
4819
|
hash: Hash28ByteBase162(Buffer.from(paymentBytes).toString("hex")),
|
|
4820
|
-
type: paymentConstrData.getAlternative()
|
|
4820
|
+
type: Number(paymentConstrData.getAlternative())
|
|
4821
4821
|
};
|
|
4822
4822
|
const delegationData = plutusDataList.get(1);
|
|
4823
4823
|
const delegationConstrData = delegationData.asConstrPlutusData();
|
|
@@ -4852,15 +4852,27 @@ var plutusDataToAddrBech32 = (plutusData, networkId = 0) => {
|
|
|
4852
4852
|
"Error: serializeAddressObj: Delegation inner part must contain 1 element"
|
|
4853
4853
|
);
|
|
4854
4854
|
}
|
|
4855
|
-
const
|
|
4855
|
+
const delegationCredential = delegationDataInnerList.get(0).asConstrPlutusData();
|
|
4856
|
+
if (!delegationCredential) {
|
|
4857
|
+
throw new Error(
|
|
4858
|
+
"Error: serializeAddressObj: Delegation inner part must be a constructor"
|
|
4859
|
+
);
|
|
4860
|
+
}
|
|
4861
|
+
const delegationBytesList = delegationCredential.getData();
|
|
4862
|
+
if (delegationBytesList.getLength() !== 1) {
|
|
4863
|
+
throw new Error(
|
|
4864
|
+
"Error: serializeAddressObj: Delegation bytes part must contain 1 element"
|
|
4865
|
+
);
|
|
4866
|
+
}
|
|
4867
|
+
const delegationBytes = delegationBytesList.get(0).asBoundedBytes();
|
|
4856
4868
|
if (!delegationBytes) {
|
|
4857
4869
|
throw new Error(
|
|
4858
|
-
"Error: serializeAddressObj: Delegation
|
|
4870
|
+
"Error: serializeAddressObj: Delegation bytes part must be of type bytes"
|
|
4859
4871
|
);
|
|
4860
4872
|
}
|
|
4861
4873
|
const cardanoStakeCredential = {
|
|
4862
4874
|
hash: Hash28ByteBase162(Buffer.from(delegationBytes).toString("hex")),
|
|
4863
|
-
type:
|
|
4875
|
+
type: Number(delegationCredential.getAlternative())
|
|
4864
4876
|
};
|
|
4865
4877
|
return BaseAddress.fromCredentials(
|
|
4866
4878
|
networkId,
|
|
@@ -5007,6 +5019,54 @@ var addVKeyWitnessSetToTransaction = (txHex, vkeyWitnessSet) => {
|
|
|
5007
5019
|
return tx.toCbor();
|
|
5008
5020
|
};
|
|
5009
5021
|
|
|
5022
|
+
// src/utils/fee.ts
|
|
5023
|
+
var calculateFees = (minFeeA, minFeeB, minFeeRefScriptCostPerByte, priceMem, priceStep, tx, refScriptSize) => {
|
|
5024
|
+
let fee = minFeeB + tx.toCbor().length / 2 * minFeeA;
|
|
5025
|
+
fee += calculateRefScriptFees(refScriptSize, minFeeRefScriptCostPerByte);
|
|
5026
|
+
let scriptFee = BigInt(0);
|
|
5027
|
+
let priceMemNumerator = priceMem;
|
|
5028
|
+
let priceMemDenominator = 1;
|
|
5029
|
+
while (priceMemNumerator % 1) {
|
|
5030
|
+
priceMemNumerator *= 10;
|
|
5031
|
+
priceMemDenominator *= 10;
|
|
5032
|
+
}
|
|
5033
|
+
let priceStepNumerator = priceStep;
|
|
5034
|
+
let priceStepDenominator = 1;
|
|
5035
|
+
while (priceStepNumerator % 1) {
|
|
5036
|
+
priceStepNumerator *= 10;
|
|
5037
|
+
priceStepDenominator *= 10;
|
|
5038
|
+
}
|
|
5039
|
+
if (tx.witnessSet().redeemers()) {
|
|
5040
|
+
for (const redeemer of tx.witnessSet().redeemers().values()) {
|
|
5041
|
+
scriptFee += redeemer.exUnits().mem() * BigInt(priceMemNumerator.toString()) / BigInt(priceMemDenominator.toString());
|
|
5042
|
+
scriptFee += redeemer.exUnits().steps() * BigInt(priceStepNumerator.toString()) / BigInt(priceStepDenominator.toString());
|
|
5043
|
+
if (priceMemNumerator % priceMemDenominator !== 0) {
|
|
5044
|
+
scriptFee += BigInt(1);
|
|
5045
|
+
}
|
|
5046
|
+
if (priceStepNumerator % priceStepDenominator !== 0) {
|
|
5047
|
+
scriptFee += BigInt(1);
|
|
5048
|
+
}
|
|
5049
|
+
}
|
|
5050
|
+
}
|
|
5051
|
+
return BigInt(fee) + scriptFee;
|
|
5052
|
+
};
|
|
5053
|
+
var calculateRefScriptFees = (refScriptSize, minFeeRefScriptCostPerByte, tierMultiplier = 1.2) => {
|
|
5054
|
+
let fee = 0;
|
|
5055
|
+
const tierSize = 25600;
|
|
5056
|
+
let currentRefScriptSize = refScriptSize;
|
|
5057
|
+
let multiplier = 1;
|
|
5058
|
+
while (currentRefScriptSize >= tierSize) {
|
|
5059
|
+
fee += tierSize * multiplier * minFeeRefScriptCostPerByte;
|
|
5060
|
+
currentRefScriptSize -= tierSize;
|
|
5061
|
+
multiplier *= tierMultiplier;
|
|
5062
|
+
}
|
|
5063
|
+
if (currentRefScriptSize > 0) {
|
|
5064
|
+
fee += currentRefScriptSize * multiplier * minFeeRefScriptCostPerByte;
|
|
5065
|
+
}
|
|
5066
|
+
fee = Math.ceil(fee);
|
|
5067
|
+
return fee;
|
|
5068
|
+
};
|
|
5069
|
+
|
|
5010
5070
|
// src/resolvers/index.ts
|
|
5011
5071
|
var resolveDataHash = (data) => {
|
|
5012
5072
|
const plutusData = toPlutusData(data);
|
|
@@ -5253,7 +5313,7 @@ var toCardanoCert = (cert) => {
|
|
|
5253
5313
|
return Certificate.newStakeDelegation(
|
|
5254
5314
|
new Serialization4.StakeDelegation(
|
|
5255
5315
|
rewardAddress.getPaymentCredential(),
|
|
5256
|
-
Ed25519KeyHashHex2(cert.poolId)
|
|
5316
|
+
cert.poolId.startsWith("pool1") ? Cardano3.PoolId.toKeyHash(Cardano3.PoolId(cert.poolId)) : Ed25519KeyHashHex2(cert.poolId)
|
|
5257
5317
|
)
|
|
5258
5318
|
);
|
|
5259
5319
|
}
|
|
@@ -5275,7 +5335,7 @@ var toCardanoCert = (cert) => {
|
|
|
5275
5335
|
case "RetirePool": {
|
|
5276
5336
|
return Certificate.newPoolRetirement(
|
|
5277
5337
|
new Serialization4.PoolRetirement(
|
|
5278
|
-
Ed25519KeyHashHex2(cert.poolId),
|
|
5338
|
+
cert.poolId.startsWith("pool1") ? Cardano3.PoolId.toKeyHash(Cardano3.PoolId(cert.poolId)) : Ed25519KeyHashHex2(cert.poolId),
|
|
5279
5339
|
Cardano3.EpochNo(cert.epoch)
|
|
5280
5340
|
)
|
|
5281
5341
|
);
|
|
@@ -5528,54 +5588,6 @@ var toCardanoCert = (cert) => {
|
|
|
5528
5588
|
}
|
|
5529
5589
|
};
|
|
5530
5590
|
|
|
5531
|
-
// src/utils/fee.ts
|
|
5532
|
-
var calculateFees = (minFeeA, minFeeB, minFeeRefScriptCostPerByte, priceMem, priceStep, tx, refScriptSize) => {
|
|
5533
|
-
let fee = minFeeB + tx.toCbor().length / 2 * minFeeA;
|
|
5534
|
-
fee += calculateRefScriptFees(refScriptSize, minFeeRefScriptCostPerByte);
|
|
5535
|
-
let scriptFee = BigInt(0);
|
|
5536
|
-
let priceMemNumerator = priceMem;
|
|
5537
|
-
let priceMemDenominator = 1;
|
|
5538
|
-
while (priceMemNumerator % 1) {
|
|
5539
|
-
priceMemNumerator *= 10;
|
|
5540
|
-
priceMemDenominator *= 10;
|
|
5541
|
-
}
|
|
5542
|
-
let priceStepNumerator = priceStep;
|
|
5543
|
-
let priceStepDenominator = 1;
|
|
5544
|
-
while (priceStepNumerator % 1) {
|
|
5545
|
-
priceStepNumerator *= 10;
|
|
5546
|
-
priceStepDenominator *= 10;
|
|
5547
|
-
}
|
|
5548
|
-
if (tx.witnessSet().redeemers()) {
|
|
5549
|
-
for (const redeemer of tx.witnessSet().redeemers().values()) {
|
|
5550
|
-
scriptFee += redeemer.exUnits().mem() * BigInt(priceMemNumerator.toString()) / BigInt(priceMemDenominator.toString());
|
|
5551
|
-
scriptFee += redeemer.exUnits().steps() * BigInt(priceStepNumerator.toString()) / BigInt(priceStepDenominator.toString());
|
|
5552
|
-
if (priceMemNumerator % priceMemDenominator !== 0) {
|
|
5553
|
-
scriptFee += BigInt(1);
|
|
5554
|
-
}
|
|
5555
|
-
if (priceStepNumerator % priceStepDenominator !== 0) {
|
|
5556
|
-
scriptFee += BigInt(1);
|
|
5557
|
-
}
|
|
5558
|
-
}
|
|
5559
|
-
}
|
|
5560
|
-
return BigInt(fee) + scriptFee;
|
|
5561
|
-
};
|
|
5562
|
-
var calculateRefScriptFees = (refScriptSize, minFeeRefScriptCostPerByte, tierMultiplier = 1.2) => {
|
|
5563
|
-
let fee = 0;
|
|
5564
|
-
const tierSize = 25600;
|
|
5565
|
-
let currentRefScriptSize = refScriptSize;
|
|
5566
|
-
let multiplier = 1;
|
|
5567
|
-
while (currentRefScriptSize >= tierSize) {
|
|
5568
|
-
fee += tierSize * multiplier * minFeeRefScriptCostPerByte;
|
|
5569
|
-
currentRefScriptSize -= tierSize;
|
|
5570
|
-
multiplier *= tierMultiplier;
|
|
5571
|
-
}
|
|
5572
|
-
if (currentRefScriptSize > 0) {
|
|
5573
|
-
fee += currentRefScriptSize * multiplier * minFeeRefScriptCostPerByte;
|
|
5574
|
-
}
|
|
5575
|
-
fee = Math.ceil(fee);
|
|
5576
|
-
return fee;
|
|
5577
|
-
};
|
|
5578
|
-
|
|
5579
5591
|
// src/utils/metadata.ts
|
|
5580
5592
|
var toCardanoMetadataMap = (metadata) => {
|
|
5581
5593
|
let cardanoMetadataMap = /* @__PURE__ */ new Map();
|
|
@@ -6059,6 +6071,10 @@ var CardanoSDKSerializerCore = class {
|
|
|
6059
6071
|
withdrawals,
|
|
6060
6072
|
votes
|
|
6061
6073
|
} = txBuilderBody;
|
|
6074
|
+
const uniqueRefInputs = this.removeBodyInputRefInputOverlap(
|
|
6075
|
+
inputs,
|
|
6076
|
+
referenceInputs
|
|
6077
|
+
);
|
|
6062
6078
|
this.addAllInputs(inputs);
|
|
6063
6079
|
this.sanitizeOutputs(outputs);
|
|
6064
6080
|
this.addAllOutputs(outputs);
|
|
@@ -6067,7 +6083,7 @@ var CardanoSDKSerializerCore = class {
|
|
|
6067
6083
|
this.addAllWithdrawals(withdrawals);
|
|
6068
6084
|
this.addAllVotes(votes);
|
|
6069
6085
|
this.addAllCollateralInputs(collaterals);
|
|
6070
|
-
this.addAllReferenceInputs(
|
|
6086
|
+
this.addAllReferenceInputs(uniqueRefInputs);
|
|
6071
6087
|
this.removeInputRefInputOverlap();
|
|
6072
6088
|
this.setValidityInterval(validityRange);
|
|
6073
6089
|
this.addAllRequiredSignatures(requiredSignatures);
|
|
@@ -6186,16 +6202,10 @@ var CardanoSDKSerializerCore = class {
|
|
|
6186
6202
|
fromBuilderToPlutusData(currentTxIn.scriptTxIn.datumSource.data)
|
|
6187
6203
|
);
|
|
6188
6204
|
} else if (currentTxIn.scriptTxIn.datumSource.type === "Inline") {
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
TransactionId(currentTxIn.txIn.txHash),
|
|
6194
|
-
BigInt(currentTxIn.txIn.txIndex)
|
|
6195
|
-
)
|
|
6196
|
-
);
|
|
6197
|
-
referenceInputs.setValues(referenceInputsList);
|
|
6198
|
-
this.txBody.setReferenceInputs(referenceInputs);
|
|
6205
|
+
this.addReferenceInput({
|
|
6206
|
+
txHash: currentTxIn.txIn.txHash,
|
|
6207
|
+
txIndex: currentTxIn.txIn.txIndex
|
|
6208
|
+
});
|
|
6199
6209
|
}
|
|
6200
6210
|
let exUnits = currentTxIn.scriptTxIn.redeemer.exUnits;
|
|
6201
6211
|
let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
|
|
@@ -6303,6 +6313,10 @@ var CardanoSDKSerializerCore = class {
|
|
|
6303
6313
|
addReferenceInput = (refInput) => {
|
|
6304
6314
|
let referenceInputs = this.txBody.referenceInputs() ?? Serialization7.CborSet.fromCore([], TransactionInput.fromCore);
|
|
6305
6315
|
let referenceInputsList = [...referenceInputs.values()];
|
|
6316
|
+
if (referenceInputsList.some(
|
|
6317
|
+
(input) => input.transactionId().toString() === refInput.txHash && input.index().toString() === refInput.txIndex.toString()
|
|
6318
|
+
))
|
|
6319
|
+
return;
|
|
6306
6320
|
referenceInputsList.push(
|
|
6307
6321
|
new TransactionInput(
|
|
6308
6322
|
TransactionId(refInput.txHash),
|
|
@@ -6310,6 +6324,9 @@ var CardanoSDKSerializerCore = class {
|
|
|
6310
6324
|
)
|
|
6311
6325
|
);
|
|
6312
6326
|
referenceInputs.setValues(referenceInputsList);
|
|
6327
|
+
if (refInput.scriptSize) {
|
|
6328
|
+
this.refScriptSize += refInput.scriptSize;
|
|
6329
|
+
}
|
|
6313
6330
|
this.txBody.setReferenceInputs(referenceInputs);
|
|
6314
6331
|
};
|
|
6315
6332
|
addAllMints = (mints) => {
|
|
@@ -6687,6 +6704,18 @@ var CardanoSDKSerializerCore = class {
|
|
|
6687
6704
|
);
|
|
6688
6705
|
}
|
|
6689
6706
|
};
|
|
6707
|
+
removeBodyInputRefInputOverlap = (inputs, refInputs) => {
|
|
6708
|
+
let finalRefInputs = [];
|
|
6709
|
+
for (let i = 0; i < refInputs.length; i++) {
|
|
6710
|
+
let refInput = refInputs[i];
|
|
6711
|
+
if (!inputs.some(
|
|
6712
|
+
(input) => input.txIn.txHash === refInput.txHash && input.txIn.txIndex === refInput.txIndex
|
|
6713
|
+
)) {
|
|
6714
|
+
finalRefInputs.push(refInput);
|
|
6715
|
+
}
|
|
6716
|
+
}
|
|
6717
|
+
return finalRefInputs;
|
|
6718
|
+
};
|
|
6690
6719
|
balanceTx = (changeAddress) => {
|
|
6691
6720
|
if (changeAddress === "") {
|
|
6692
6721
|
throw new Error("Can't balance tx without a change address");
|
|
@@ -6876,16 +6905,16 @@ var CardanoSDKSerializerCore = class {
|
|
|
6876
6905
|
if (scriptSource.type !== "Inline") {
|
|
6877
6906
|
return;
|
|
6878
6907
|
}
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6908
|
+
if (!scriptSource.scriptSize) {
|
|
6909
|
+
throw new Error(
|
|
6910
|
+
"A reference script was used without providing its size, this must be provided as fee calculations are based on it"
|
|
6911
|
+
);
|
|
6912
|
+
}
|
|
6913
|
+
this.addReferenceInput({
|
|
6914
|
+
txHash: scriptSource.txHash,
|
|
6915
|
+
txIndex: scriptSource.txIndex,
|
|
6916
|
+
scriptSize: Number(scriptSource.scriptSize)
|
|
6917
|
+
});
|
|
6889
6918
|
switch (scriptSource.version) {
|
|
6890
6919
|
case "V1": {
|
|
6891
6920
|
this.usedLanguages[PlutusLanguageVersion.V1] = true;
|
|
@@ -6900,35 +6929,21 @@ var CardanoSDKSerializerCore = class {
|
|
|
6900
6929
|
break;
|
|
6901
6930
|
}
|
|
6902
6931
|
}
|
|
6903
|
-
if (scriptSource.scriptSize) {
|
|
6904
|
-
this.refScriptSize += Number(scriptSource.scriptSize);
|
|
6905
|
-
} else {
|
|
6906
|
-
throw new Error(
|
|
6907
|
-
"A reference script was used without providing its size, this must be provided as fee calculations are based on it"
|
|
6908
|
-
);
|
|
6909
|
-
}
|
|
6910
6932
|
};
|
|
6911
6933
|
addSimpleScriptRef = (simpleScriptSource) => {
|
|
6912
6934
|
if (simpleScriptSource.type !== "Inline") {
|
|
6913
6935
|
return;
|
|
6914
6936
|
}
|
|
6915
|
-
|
|
6916
|
-
let referenceInputsList = [...referenceInputs.values()];
|
|
6917
|
-
referenceInputsList.push(
|
|
6918
|
-
new TransactionInput(
|
|
6919
|
-
TransactionId(simpleScriptSource.txHash),
|
|
6920
|
-
BigInt(simpleScriptSource.txIndex)
|
|
6921
|
-
)
|
|
6922
|
-
);
|
|
6923
|
-
if (simpleScriptSource.scriptSize) {
|
|
6924
|
-
this.refScriptSize += Number(simpleScriptSource.scriptSize);
|
|
6925
|
-
} else {
|
|
6937
|
+
if (!simpleScriptSource.scriptSize) {
|
|
6926
6938
|
throw new Error(
|
|
6927
6939
|
"A reference script was used without providing its size, this must be provided as fee calculations are based on it"
|
|
6928
6940
|
);
|
|
6929
6941
|
}
|
|
6930
|
-
|
|
6931
|
-
|
|
6942
|
+
this.addReferenceInput({
|
|
6943
|
+
txHash: simpleScriptSource.txHash,
|
|
6944
|
+
txIndex: simpleScriptSource.txIndex,
|
|
6945
|
+
scriptSize: Number(simpleScriptSource.scriptSize)
|
|
6946
|
+
});
|
|
6932
6947
|
};
|
|
6933
6948
|
countNumberOfRequiredWitnesses() {
|
|
6934
6949
|
let requiredWitnesses = /* @__PURE__ */ new Set();
|
|
@@ -7465,6 +7480,7 @@ export {
|
|
|
7465
7480
|
buildRewardAddress,
|
|
7466
7481
|
buildScriptPubkey,
|
|
7467
7482
|
bytesToHex,
|
|
7483
|
+
calculateFees,
|
|
7468
7484
|
checkSignature,
|
|
7469
7485
|
clampScalar,
|
|
7470
7486
|
computeAuxiliaryDataHash,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/core-cst",
|
|
3
|
-
"version": "1.9.0-beta.
|
|
3
|
+
"version": "1.9.0-beta.19",
|
|
4
4
|
"description": "Types and utilities functions between Mesh and cardano-js-sdk",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@harmoniclabs/cbor": "1.3.0",
|
|
43
43
|
"@harmoniclabs/plutus-data": "1.2.4",
|
|
44
44
|
"@harmoniclabs/uplc": "1.2.4",
|
|
45
|
-
"@meshsdk/common": "1.9.0-beta.
|
|
45
|
+
"@meshsdk/common": "1.9.0-beta.19",
|
|
46
46
|
"@types/base32-encoding": "^1.0.2",
|
|
47
47
|
"base32-encoding": "^1.0.0",
|
|
48
48
|
"bech32": "^2.0.0",
|