Skip to content

Rewrite transaction balance / fee calculation logic #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c033c5e
chore: adds hvf coin selection and test coverage
cjkoepke Jan 9, 2025
4b089c5
chore: fmt
cjkoepke Jan 9, 2025
031dad6
chore: expose coin selectors
cjkoepke Jan 9, 2025
d658d46
wip: test case
cjkoepke Jan 10, 2025
e376078
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Jan 21, 2025
e495f26
fix: fmt
cjkoepke Jan 21, 2025
2829122
chore: fix test case
cjkoepke Jan 21, 2025
5c81060
chore: changeset
cjkoepke Jan 21, 2025
b44dc08
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Jan 21, 2025
bbb76c2
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Jan 24, 2025
593dc58
chore: more tests
cjkoepke Jan 27, 2025
ae6e780
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Jan 31, 2025
e5fedde
wip: use coin selection to determine collateral
cjkoepke Jan 31, 2025
a89f667
chore: update prepareCollateral to use coinSelector
cjkoepke Feb 5, 2025
c7fe2f9
chore: cleanup
cjkoepke Feb 5, 2025
5a138ee
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Feb 5, 2025
697c0f7
fix: test
cjkoepke Feb 5, 2025
47ddfc1
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Feb 6, 2025
29ccb85
chore: cleanup
cjkoepke Feb 6, 2025
50c7652
chore: review comments
cjkoepke Feb 6, 2025
024e93d
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Feb 6, 2025
f2fffe4
wip: reconfigure tx completion
cjkoepke Feb 7, 2025
a1e7402
wip: more progress on transaction balancing, etc
cjkoepke Feb 10, 2025
d436a89
chore: enable tracing
cjkoepke Feb 10, 2025
8a0af38
chore: fix prepareCollateral tests
cjkoepke Feb 11, 2025
017243d
chore: passing tests
cjkoepke Feb 14, 2025
cf980b2
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Feb 18, 2025
99e771b
chore: add donation support
cjkoepke Feb 18, 2025
bdf5d56
chore: comment for fee calculation
cjkoepke Feb 19, 2025
1c3e8cc
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Feb 20, 2025
f608146
ci/cd: snapshot releases
micahkendall Feb 21, 2025
9a75940
fix: use release command
micahkendall Feb 21, 2025
bb2c8de
correct token
micahkendall Feb 21, 2025
3fda65a
simple snapshot names
micahkendall Feb 21, 2025
bce8739
dev release command with tag
micahkendall Feb 21, 2025
2d957ee
--no-git-tag
micahkendall Feb 21, 2025
cdfd54b
name snapshots
micahkendall Feb 21, 2025
900d968
Merge branch 'feat/collateral' of github.com:butaneprotocol/blaze-car…
cjkoepke Feb 24, 2025
4af073a
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Feb 24, 2025
53f2360
Merge branch 'main' of github.com:butaneprotocol/blaze-cardano into f…
cjkoepke Feb 28, 2025
ce41d40
chore: abstract some utilities out of TxBuilder
cjkoepke Feb 28, 2025
1ad9ccd
chore: just a bit more cleanup
cjkoepke Feb 28, 2025
71448c5
chore: abstract out required witnesses logic
cjkoepke Mar 4, 2025
d110e01
fmt
cjkoepke Mar 5, 2025
2a3bb74
fix: tests
cjkoepke Mar 12, 2025
d1e7fcd
chore: remove console log
cjkoepke Mar 12, 2025
0fa0748
chore: review comments
cjkoepke Mar 12, 2025
47f03b8
chore: fmt
cjkoepke Mar 12, 2025
15a04e2
chore: throw error instead of early return
cjkoepke Mar 12, 2025
f2d95e0
chore: throw error instead of early return
cjkoepke Mar 12, 2025
5994313
chore: revert committed blueprint change
cjkoepke Mar 12, 2025
de6d86b
chore: review comments
cjkoepke Mar 12, 2025
1a1f633
chore: fmt
cjkoepke Mar 12, 2025
4e44cf0
chore: review comments and changeset
cjkoepke Mar 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilled-bats-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blaze-cardano/tx": minor
---

Completely rewrites a lot of the completion logic for building transactions, including fee calculation and collateral selection. It also adds a new coin selection algorithm as an optional export, based on the HVF algorithm.
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Release

on:
push:
branches:
Expand All @@ -19,10 +18,8 @@ jobs:
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4

- name: 📦 Setup pnpm
uses: pnpm/action-setup@v4

- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"docs": "typedoc --skipErrorChecking && mkdir docs/logo && cp logo/BLAZE_LOGO2.svg docs/logo/BLAZE_LOGO2.svg",
"fmt": "prettier -w .",
"changeset": "changeset",
"release": "turbo run build && changeset publish"
"release": "turbo run build && changeset publish",
"release-dev": "turbo run build && changeset version --snapshot && changeset publish --tag dev"
},
"devDependencies": {
"@blaze-cardano/eslint-config": "workspace:*",
Expand Down
121 changes: 85 additions & 36 deletions packages/blaze-blueprint/test/plutus.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,99 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { type Script } from "@blaze-cardano/core";
import { applyParamsToScript, cborToScript } from "@blaze-cardano/uplc";import { type PlutusData } from "@blaze-cardano/core";
import { applyParamsToScript, cborToScript } from "@blaze-cardano/uplc";


export type ByteArray = string;
export type Data = any;
export type Int = bigint;


export interface AlwaysTrueScriptSpend {
new (_param1:bigint,_param2:string): Script;
_datum: Array<bigint>;
_redeemer: bigint;
};
scriptBytes: string;
new(_param1: Int,
_param2: ByteArray): Script;
_datum: Array<Int>;
_redeemer: Int;
}
export const AlwaysTrueScriptSpend = Object.assign(
function (_param1: Int,_param2: ByteArray) {
return cborToScript(
applyParamsToScript(
AlwaysTrueScriptSpend.scriptBytes,
[_param1, _param2],
{"dataType":"list","items":[{"dataType":"integer"},{"dataType":"bytes"}]} as any,
),
"PlutusV3",
);
},
{ scriptBytes: "58650101003232323232232232253330063232323232533300b3370e900118061baa0011323322324a26eb4014c03c004c03cc040004c034dd50008b1806980700198060011805801180580098041baa00114984d958dd70009bad0015734aae7555cf2ba15745" },
{ _datum: {"dataType":"list","items":{"dataType":"integer"}} },
{ _redeemer: {"dataType":"integer"} },
) as unknown as AlwaysTrueScriptSpend;

export const AlwaysTrueScriptSpend = Object.assign(
function (_param1:bigint,_param2:string) {return cborToScript(applyParamsToScript("58650101003232323232232232253330063232323232533300b3370e900118061baa0011323322324a26eb4014c03c004c03cc040004c034dd50008b1806980700198060011805801180580098041baa00114984d958dd70009bad0015734aae7555cf2ba15745", [_param1,_param2], {"dataType":"list","items":[{"dataType":"integer"},{"dataType":"bytes"}]} as any), "PlutusV3");},
{_datum: {"dataType":"list","items":{"dataType":"integer"}}},
{_redeemer: {"dataType":"integer"}},
) as unknown as AlwaysTrueScriptSpend;

export interface AlwaysTrueScriptElse {
new (_param1:bigint,_param2:string): Script;

};
scriptBytes: string;
new(_param1: Int,
_param2: ByteArray): Script;
undefined: any;
}
export const AlwaysTrueScriptElse = Object.assign(
function (_param1: Int,_param2: ByteArray) {
return cborToScript(
applyParamsToScript(
AlwaysTrueScriptElse.scriptBytes,
[_param1, _param2],
{"dataType":"list","items":[{"dataType":"integer"},{"dataType":"bytes"}]} as any,
),
"PlutusV3",
);
},
{ scriptBytes: "58650101003232323232232232253330063232323232533300b3370e900118061baa0011323322324a26eb4014c03c004c03cc040004c034dd50008b1806980700198060011805801180580098041baa00114984d958dd70009bad0015734aae7555cf2ba15745" },
{ undefined: {} },
) as unknown as AlwaysTrueScriptElse;

export const AlwaysTrueScriptElse = Object.assign(
function (_param1:bigint,_param2:string) {return cborToScript(applyParamsToScript("58650101003232323232232232253330063232323232533300b3370e900118061baa0011323322324a26eb4014c03c004c03cc040004c034dd50008b1806980700198060011805801180580098041baa00114984d958dd70009bad0015734aae7555cf2ba15745", [_param1,_param2], {"dataType":"list","items":[{"dataType":"integer"},{"dataType":"bytes"}]} as any), "PlutusV3");},


) as unknown as AlwaysTrueScriptElse;

export interface NestedSometimesTrueScriptSpend {
new (param:bigint): Script;
datum: PlutusData;
redeemer: bigint;
};
scriptBytes: string;
new(param: Int): Script;
datum: Data;
redeemer: Int;
}
export const NestedSometimesTrueScriptSpend = Object.assign(
function (param: Int) {
return cborToScript(
applyParamsToScript(
NestedSometimesTrueScriptSpend.scriptBytes,
[param],
{"dataType":"list","items":[{"dataType":"integer"}]} as any,
),
"PlutusV3",
);
},
{ scriptBytes: "5862010100323232323223225333004323232323253330093370e900118051baa0011323322337100146eb4014c034004c034c038004c02cdd50008b1805980600198050011804801180480098031baa00114984d958dd6800ab9a5573aaae795d0aba21" },
{ datum: {"title":"Data","description":"Any Plutus data."} },
{ redeemer: {"dataType":"integer"} },
) as unknown as NestedSometimesTrueScriptSpend;

export const NestedSometimesTrueScriptSpend = Object.assign(
function (param:bigint) {return cborToScript(applyParamsToScript("5862010100323232323223225333004323232323253330093370e900118051baa0011323322337100146eb4014c034004c034c038004c02cdd50008b1805980600198050011804801180480098031baa00114984d958dd6800ab9a5573aaae795d0aba21", [param], {"dataType":"list","items":[{"dataType":"integer"}]} as any), "PlutusV3");},
{datum: {"title":"Data","description":"Any Plutus data."}},
{redeemer: {"dataType":"integer"}},
) as unknown as NestedSometimesTrueScriptSpend;

export interface NestedSometimesTrueScriptElse {
new (param:bigint): Script;

};

export const NestedSometimesTrueScriptElse = Object.assign(
function (param:bigint) {return cborToScript(applyParamsToScript("5862010100323232323223225333004323232323253330093370e900118051baa0011323322337100146eb4014c034004c034c038004c02cdd50008b1805980600198050011804801180480098031baa00114984d958dd6800ab9a5573aaae795d0aba21", [param], {"dataType":"list","items":[{"dataType":"integer"}]} as any), "PlutusV3");},


) as unknown as NestedSometimesTrueScriptElse;
scriptBytes: string;
new(param: Int): Script;
undefined: any;
}
export const NestedSometimesTrueScriptElse = Object.assign(
function (param: Int) {
return cborToScript(
applyParamsToScript(
NestedSometimesTrueScriptElse.scriptBytes,
[param],
{"dataType":"list","items":[{"dataType":"integer"}]} as any,
),
"PlutusV3",
);
},
{ scriptBytes: "5862010100323232323223225333004323232323253330093370e900118051baa0011323322337100146eb4014c034004c034c038004c02cdd50008b1805980600198050011804801180480098031baa00114984d958dd6800ab9a5573aaae795d0aba21" },
{ undefined: {} },
) as unknown as NestedSometimesTrueScriptElse;
6 changes: 5 additions & 1 deletion packages/blaze-emulator/src/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,15 +709,19 @@ export class Emulator {
),
);

let refScriptFee = 0n;
if (refInputs && this.params.minFeeReferenceScripts) {
const refScripts = [...inputs, ...refInputs]
.map((x) => this.getOutput(x)!.scriptRef())
.filter((x) => x !== undefined);
fee += BigInt(

refScriptFee += BigInt(
Math.ceil(calculateReferenceScriptFee(refScripts, this.params)),
);
}

fee += refScriptFee;

if (fee > body.fee())
throw new Error(
`Insufficient transaction fee. Supplied: ${body.fee()}, Required: ${fee}`,
Expand Down
3 changes: 1 addition & 2 deletions packages/blaze-emulator/test/Emulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("Emulator", () => {
expect(out.amount().coin()).toEqual(2_000_000_000n);
});

test("Should be able to spend from a script", async () => {
test("Should be able to spend from a script only", async () => {
const tx = await blaze
.newTransaction()
.lockAssets(
Expand Down Expand Up @@ -136,7 +136,6 @@ describe("Emulator", () => {
// refIn,
// emulator.getOutput(refIn)!
// );

const tx = await blaze
.newTransaction()
.lockAssets(
Expand Down
Loading