diff --git a/packages/mesh-transaction/src/mesh-tx-builder/index.ts b/packages/mesh-transaction/src/mesh-tx-builder/index.ts index e3b248cf1..718c09bbd 100644 --- a/packages/mesh-transaction/src/mesh-tx-builder/index.ts +++ b/packages/mesh-transaction/src/mesh-tx-builder/index.ts @@ -1729,6 +1729,12 @@ export class MeshTxBuilder extends MeshTxBuilderCore { stepUnits += BigInt(vote.redeemer.exUnits.steps); } } + for (let proposal of this.meshTxBuilderBody.proposals) { + if (proposal.type === "ScriptProposal" && proposal.redeemer) { + memUnits += BigInt(proposal.redeemer.exUnits.mem); + stepUnits += BigInt(proposal.redeemer.exUnits.steps); + } + } memUnits = BigInt( new BigNumber(memUnits).integerValue(BigNumber.ROUND_CEIL).toString(), ); diff --git a/packages/mesh-transaction/test/mesh-tx-builder/proposal-fee-test.ts b/packages/mesh-transaction/test/mesh-tx-builder/proposal-fee-test.ts new file mode 100644 index 000000000..3e67f646a --- /dev/null +++ b/packages/mesh-transaction/test/mesh-tx-builder/proposal-fee-test.ts @@ -0,0 +1,230 @@ +import { + applyCborEncoding, + GovernanceAction, + MeshTxBuilder, +} from "@meshsdk/core"; +import { Transaction } from "@meshsdk/core-cst"; + +const PlutusV1CostModels = [ + 100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, + 8356, 4, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, + 100, 100, 100, 16000, 100, 94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, + 22151, 32, 91189, 769, 4, 2, 85848, 228465, 122, 0, 1, 1, 1000, 42921, 4, 2, + 30623, 28755, 75, 1, 898148, 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1, + 141895, 32, 83150, 32, 15299, 32, 76049, 1, 13169, 4, 22100, 10, 28999, 74, 1, + 28999, 74, 1, 43285, 552, 1, 44749, 541, 1, 33852, 32, 68246, 32, 72362, 32, + 7243, 32, 7391, 32, 11546, 32, 85848, 228465, 122, 0, 1, 1, 90434, 519, 0, 1, + 74433, 32, 85848, 228465, 122, 0, 1, 1, 85848, 228465, 122, 0, 1, 1, 270652, + 22588, 4, 1457325, 64566, 4, 20467, 1, 4, 0, 141992, 32, 100788, 420, 1, 1, + 81663, 32, 59498, 32, 20142, 32, 24588, 32, 20744, 32, 25933, 32, 24623, 32, + 53384111, 14333, 10, 955506, 213312, 0, 2, 43053543, 10, 43574283, 26308, 10, + 16000, 100, 16000, 100, 962335, 18, 2780678, 6, 442008, 1, 52538055, 3756, 18, + 267929, 18, 76433006, 8868, 18, 52948122, 18, 1995836, 36, 3227919, 12, + 901022, 1, 166917843, 4307, 36, 284546, 36, 158221314, 26549, 36, 74698472, + 36, 333849714, 1, 254006273, 72, 2174038, 72, 2261318, 64571, 4, 207616, 8310, + 4, 1293828, 28716, 63, 0, 1, 1006041, 43623, 251, 0, 1, 100181, 726, 719, 0, + 1, 100181, 726, 719, 0, 1, 100181, 726, 719, 0, 1, 107878, 680, 0, 1, 95336, + 1, 281145, 18848, 0, 1, 180194, 159, 1, 1, 158519, 8942, 0, 1, 159378, 8813, + 0, 1, 107490, 3298, 1, 106057, 655, 1, 1964219, 24520, 3, 607153, 231697, + 53144, 0, 1, 116711, 1957, 4, 231883, 10, 1000, 24838, 7, 1, 232010, 32, + 321837444, 25087669, 18, 617887431, 67302824, 36, 356924, 18413, 45, 21, + 219951, 9444, 1, 1000, 172116, 183150, 6, 24, 21, 213283, 618401, 1998, 28258, + 1, 1000, 38159, 2, 22, 1000, 95933, 1, 1, 11, 1000, 277577, 12, 21, +]; +const PlutusV2CostModels = [ + 100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, + 8356, 4, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, + 100, 100, 100, 16000, 100, 94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, + 22151, 32, 91189, 769, 4, 2, 85848, 228465, 122, 0, 1, 1, 1000, 42921, 4, 2, + 30623, 28755, 75, 1, 898148, 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1, + 141895, 32, 83150, 32, 15299, 32, 76049, 1, 13169, 4, 22100, 10, 28999, 74, 1, + 28999, 74, 1, 43285, 552, 1, 44749, 541, 1, 33852, 32, 68246, 32, 72362, 32, + 7243, 32, 7391, 32, 11546, 32, 85848, 228465, 122, 0, 1, 1, 90434, 519, 0, 1, + 74433, 32, 85848, 228465, 122, 0, 1, 1, 85848, 228465, 122, 0, 1, 1, 955506, + 213312, 0, 2, 270652, 22588, 4, 1457325, 64566, 4, 20467, 1, 4, 0, 141992, 32, + 100788, 420, 1, 1, 81663, 32, 59498, 32, 20142, 32, 24588, 32, 20744, 32, + 25933, 32, 24623, 32, 43053543, 10, 53384111, 14333, 10, 43574283, 26308, 10, + 1293828, 28716, 63, 0, 1, 1006041, 43623, 251, 0, 1, 16000, 100, 16000, 100, + 962335, 18, 2780678, 6, 442008, 1, 52538055, 3756, 18, 267929, 18, 76433006, + 8868, 18, 52948122, 18, 1995836, 36, 3227919, 12, 901022, 1, 166917843, 4307, + 36, 284546, 36, 158221314, 26549, 36, 74698472, 36, 333849714, 1, 254006273, + 72, 2174038, 72, 2261318, 64571, 4, 207616, 8310, 4, 100181, 726, 719, 0, 1, + 100181, 726, 719, 0, 1, 100181, 726, 719, 0, 1, 107878, 680, 0, 1, 95336, 1, + 281145, 18848, 0, 1, 180194, 159, 1, 1, 158519, 8942, 0, 1, 159378, 8813, 0, + 1, 107490, 3298, 1, 106057, 655, 1, 1964219, 24520, 3, 607153, 231697, 53144, + 0, 1, 116711, 1957, 4, 231883, 10, 1000, 24838, 7, 1, 232010, 32, 321837444, + 25087669, 18, 617887431, 67302824, 36, 356924, 18413, 45, 21, 219951, 9444, 1, + 1000, 172116, 183150, 6, 24, 21, 213283, 618401, 1998, 28258, 1, 1000, 38159, + 2, 22, 1000, 95933, 1, 1, 11, 1000, 277577, 12, 21, +]; +const PlutusV3CostModels = [ + 100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, + 8356, 4, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, + 100, 100, 100, 16000, 100, 94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, + 22151, 32, 91189, 769, 4, 2, 85848, 123203, 7305, -900, 1716, 960, 57, 85848, + 0, 1, 1, 1000, 42921, 4, 2, 30623, 28755, 75, 1, 898148, 27279, 1, 51775, 558, + 1, 39184, 1000, 60594, 1, 141895, 32, 83150, 32, 15299, 32, 76049, 1, 13169, + 4, 22100, 10, 28999, 74, 1, 28999, 74, 1, 43285, 552, 1, 44749, 541, 1, 33852, + 32, 68246, 32, 72362, 32, 7243, 32, 7391, 32, 11546, 32, 85848, 123203, 7305, + -900, 1716, 960, 57, 85848, 0, 1, 90434, 519, 0, 1, 74433, 32, 85848, 123203, + 7305, -900, 1716, 960, 57, 85848, 0, 1, 1, 85848, 123203, 7305, -900, 1716, + 960, 57, 85848, 0, 1, 955506, 213312, 0, 2, 270652, 22588, 4, 1457325, 64566, + 4, 20467, 1, 4, 0, 141992, 32, 100788, 420, 1, 1, 81663, 32, 59498, 32, 20142, + 32, 24588, 32, 20744, 32, 25933, 32, 24623, 32, 43053543, 10, 53384111, 14333, + 10, 43574283, 26308, 10, 16000, 100, 16000, 100, 962335, 18, 2780678, 6, + 442008, 1, 52538055, 3756, 18, 267929, 18, 76433006, 8868, 18, 52948122, 18, + 1995836, 36, 3227919, 12, 901022, 1, 166917843, 4307, 36, 284546, 36, + 158221314, 26549, 36, 74698472, 36, 333849714, 1, 254006273, 72, 2174038, 72, + 2261318, 64571, 4, 207616, 8310, 4, 1293828, 28716, 63, 0, 1, 1006041, 43623, + 251, 0, 1, 100181, 726, 719, 0, 1, 100181, 726, 719, 0, 1, 100181, 726, 719, + 0, 1, 107878, 680, 0, 1, 95336, 1, 281145, 18848, 0, 1, 180194, 159, 1, 1, + 158519, 8942, 0, 1, 159378, 8813, 0, 1, 107490, 3298, 1, 106057, 655, 1, + 1964219, 24520, 3, 607153, 231697, 53144, 0, 1, 116711, 1957, 4, 231883, 10, + 1000, 24838, 7, 1, 232010, 32, 321837444, 25087669, 18, 617887431, 67302824, + 36, 356924, 18413, 45, 21, 219951, 9444, 1, 1000, 172116, 183150, 6, 24, 21, + 213283, 618401, 1998, 28258, 1, 1000, 38159, 2, 22, 1000, 95933, 1, 1, 11, + 1000, 277577, 12, 21, +]; + +describe("mesh-scalus-emulator", () => { + it("calculates fees from script vote proposal correctly", async () => { + const initialUtxos = [ + { + input: { + txHash: + "565d611be830b31c636b594f942817a93100832b888fbaff0c868ae1f7340aef", + outputIndex: 0, + }, + output: { + address: + "addr_test1qrzp76pjtwdfzd0dmcceapsu9ejy8aenljmlls4ltxaysx3u080jygg8tuery7al925ves3t854ux94swmn99m4fktxsajvrd7", + amount: [{ unit: "lovelace", quantity: "10000000000" }], + }, + }, + { + input: { + txHash: + "66b98c314f5fec34e44099b3772cadcdd47083ea4bd15d4d47307addf59ddd10", + outputIndex: 0, + }, + output: { + address: + "addr_test1qrzp76pjtwdfzd0dmcceapsu9ejy8aenljmlls4ltxaysx3u080jygg8tuery7al925ves3t854ux94swmn99m4fktxsajvrd7", + amount: [{ unit: "lovelace", quantity: "500000000" }], + }, + }, + { + input: { + txHash: + "66b98c314f5fec34e44099b3772cadcdd47083ea4bd15d4d47307addf59ddd10", + outputIndex: 1, + }, + output: { + address: + "addr_test1qrzp76pjtwdfzd0dmcceapsu9ejy8aenljmlls4ltxaysx3u080jygg8tuery7al925ves3t854ux94swmn99m4fktxsajvrd7", + amount: [{ unit: "lovelace", quantity: "53092243057" }], + }, + }, + { + input: { + txHash: + "66b98c314f5fec34e44099b3772cadcdd47083ea4bd15d4d47307addf59ddd10", + outputIndex: 2, + }, + output: { + address: + "addr_test1qrzp76pjtwdfzd0dmcceapsu9ejy8aenljmlls4ltxaysx3u080jygg8tuery7al925ves3t854ux94swmn99m4fktxsajvrd7", + amount: [{ unit: "lovelace", quantity: "26546211847" }], + }, + }, + { + input: { + txHash: + "66b98c314f5fec34e44099b3772cadcdd47083ea4bd15d4d47307addf59ddd10", + outputIndex: 3, + }, + output: { + address: + "addr_test1qrzp76pjtwdfzd0dmcceapsu9ejy8aenljmlls4ltxaysx3u080jygg8tuery7al925ves3t854ux94swmn99m4fktxsajvrd7", + amount: [{ unit: "lovelace", quantity: "13273105924" }], + }, + }, + { + input: { + txHash: + "66b98c314f5fec34e44099b3772cadcdd47083ea4bd15d4d47307addf59ddd10", + outputIndex: 4, + }, + output: { + address: + "addr_test1qrzp76pjtwdfzd0dmcceapsu9ejy8aenljmlls4ltxaysx3u080jygg8tuery7al925ves3t854ux94swmn99m4fktxsajvrd7", + amount: [{ unit: "lovelace", quantity: "13273105924" }], + }, + }, + { + input: { + txHash: + "66b98c314f5fec34e44099b3772cadcdd47083ea4bd15d4d47307addf59ddd10", + outputIndex: 5, + }, + output: { + address: + "addr_test1qrzp76pjtwdfzd0dmcceapsu9ejy8aenljmlls4ltxaysx3u080jygg8tuery7al925ves3t854ux94swmn99m4fktxsajvrd7", + amount: [{ unit: "lovelace", quantity: "5000000" }], + }, + }, + ]; + + const guardrailsScript = { + type: "PlutusScriptV3", + description: "", + cborHex: + "5908510101003232323232323232323232323232323232323232323232323232323232323232323232323232323232259323255333573466e1d20000011180098111bab357426ae88d55cf00104554ccd5cd19b87480100044600422c6aae74004dd51aba1357446ae88d55cf1baa3255333573466e1d200a35573a002226ae84d5d11aab9e00111637546ae84d5d11aba235573c6ea800642b26006003149a2c8a4c301f801c0052000c00e0070018016006901e4070c00e003000c00d20d00fc000c0003003800a4005801c00e003002c00d20c09a0c80e1801c006001801a4101b5881380018000600700148013003801c006005801a410100078001801c006001801a4101001f8001800060070014801b0038018096007001800600690404002600060001801c0052008c00e006025801c006001801a41209d8001800060070014802b003801c006005801a410112f501c3003800c00300348202b7881300030000c00e00290066007003800c00b003482032ad7b806038403060070014803b00380180960003003800a4021801c00e003002c00d20f40380e1801c006001801a41403f800100a0c00e0029009600f0030078040c00e002900a600f003800c00b003301a483403e01a600700180060066034904801e00060001801c0052016c01e00600f801c006001801980c2402900e30000c00e002901060070030128060c00e00290116007003800c00b003483c0ba03860070018006006906432e00040283003800a40498003003800a404d802c00e00f003800c00b003301a480cb0003003800c003003301a4802b00030001801c01e0070018016006603490605c0160006007001800600660349048276000600030000c00e0029014600b003801c00c04b003800c00300348203a2489b00030001801c00e006025801c006001801a4101b11dc2df80018000c0003003800a4055802c00e007003012c00e003000c00d2080b8b872c000c0006007003801809600700180060069040607e4155016000600030000c00e00290166007003012c00e003000c00d2080c001c000c0003003800a405d801c00e003002c00d20c80180e1801c006001801a412007800100a0c00e00290186007003013c0006007001480cb005801801e006003801800e00600500403003800a4069802c00c00f003001c00c007003803c00e003002c00c05300333023480692028c0004014c00c00b003003c00c00f003003c00e00f003800c00b00301480590052008003003800a406d801c00e003002c00d2000c00d2006c00060070018006006900a600060001801c0052038c00e007001801600690006006901260003003800c003003483281300020141801c005203ac00e006027801c006001801a403d800180006007001480f3003801804e00700180060069040404af3c4e302600060001801c005203ec00e006013801c006001801a4101416f0fd20b80018000600700148103003801c006005801a403501c3003800c0030034812b00030000c00e0029021600f003800c00a01ac00e003000c00ccc08d20d00f4800b00030000c0000000000803c00c016008401e006009801c006001801807e0060298000c000401e006007801c0060018018074020c000400e00f003800c00b003010c000802180020070018006006019801805e0003000400600580180760060138000800c00b00330134805200c400e00300080330004006005801a4001801a410112f58000801c00600901260008019806a40118002007001800600690404a75ee01e00060008018046000801801e000300c4832004c025201430094800a0030028052003002c00d2002c000300648010c0092002300748028c0312000300b48018c0292012300948008c0212066801a40018000c0192008300a2233335573e00250002801994004d55ce800cd55cf0008d5d08014c00cd5d10011263009222532900389800a4d2219002912c80344c01526910c80148964cc04cdd68010034564cc03801400626601800e0071801226601800e01518010096400a3000910c008600444002600244004a664600200244246466004460044460040064600444600200646a660080080066a00600224446600644b20051800484ccc02600244666ae68cdc3801000c00200500a91199ab9a33710004003000801488ccd5cd19b89002001800400a44666ae68cdc4801000c00a00122333573466e20008006005000912a999ab9a3371200400222002220052255333573466e2400800444008440040026eb400a42660080026eb000a4264666015001229002914801c8954ccd5cd19b8700400211333573466e1c00c006001002118011229002914801c88cc044cdc100200099b82002003245200522900391199ab9a3371066e08010004cdc1001001c002004403245200522900391199ab9a3371266e08010004cdc1001001c00a00048a400a45200722333573466e20cdc100200099b820020038014000912c99807001000c40062004912c99807001000c400a2002001199919ab9a357466ae880048cc028dd69aba1003375a6ae84008d5d1000934000dd60010a40064666ae68d5d1800c0020052225933006003357420031330050023574400318010600a444aa666ae68cdc3a400000222c22aa666ae68cdc4000a4000226600666e05200000233702900000088994004cdc2001800ccdc20010008cc010008004c01088954ccd5cd19b87480000044400844cc00c004cdc300100091119803112c800c60012219002911919806912c800c4c02401a442b26600a004019130040018c008002590028c804c8888888800d1900991111111002a244b267201722222222008001000c600518000001112a999ab9a3370e004002230001155333573466e240080044600823002229002914801c88ccd5cd19b893370400800266e0800800e00100208c8c0040048c0088cc008008005", + }; + const proposal: GovernanceAction = { + kind: "TreasuryWithdrawalsAction", + action: { + withdrawals: { + stake_test1uq78nhezyyr47v3j0wlj42xvcg4n627rz6c8dejja65m9ng7z899t: + "10", + }, + policyHash: { + bytes: "fa24fb305126805cf2164c161d852a0e7330cf988f1fe558cf7d4a64", + }, + }, + }; + const txBuilder = new MeshTxBuilder({}); + const txHex = await txBuilder + .selectUtxosFrom(initialUtxos) + .txInCollateral( + initialUtxos[0]!.input.txHash, + initialUtxos[0]!.input.outputIndex, + initialUtxos[0]!.output.amount, + initialUtxos[0]!.output.address, + ) + .proposal( + proposal, + { + anchorUrl: "ipfs://Qmca3PC1bbHWAKu93nXZit4vTvWzp3zvChnf6QBbSqJCpT", + anchorDataHash: + "566e486264b960ac0a36f6824db5d803177cca5cbc642869a31d23cc68c6a839", + }, + "stake_test1uq78nhezyyr47v3j0wlj42xvcg4n627rz6c8dejja65m9ng7z899t", + String(100_000_000_000), + ) + .proposalScript(applyCborEncoding(guardrailsScript.cborHex), "V3") + .proposalRedeemerValue(0) + .changeAddress( + "addr_test1qrzp76pjtwdfzd0dmcceapsu9ejy8aenljmlls4ltxaysx3u080jygg8tuery7al925ves3t854ux94swmn99m4fktxsajvrd7", + ) + .setCostModels([ + PlutusV1CostModels, + PlutusV2CostModels, + PlutusV3CostModels, + ]) + .complete(); + + const tx = Transaction.fromCbor(txHex); + expect(tx.body().fee().valueOf()).toBeGreaterThan(900000); + }); +});