Skip to content

Commit

Permalink
Fixes Collateral Calculation (#184)
Browse files Browse the repository at this point in the history
* fix: incorrect math for collateral

* chore: changeset
  • Loading branch information
cjkoepke authored Sep 26, 2024
1 parent 6212771 commit 0a667b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/weak-squids-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@blaze-cardano/emulator": minor
"@blaze-cardano/tx": minor
---

This fixes incorrect calculation for collateral values from a recent fix.
2 changes: 1 addition & 1 deletion packages/blaze-emulator/src/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export class Emulator {

// Minimum collateral amount included
const minCollateral = BigInt(
Math.ceil((this.params.collateralPercentage * Number(body.fee())) / 100),
Math.ceil((this.params.collateralPercentage / 100) * Number(body.fee())),
);

// If any scripts have been invoked, minimum collateral must be included
Expand Down
5 changes: 2 additions & 3 deletions packages/blaze-tx/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1413,9 +1413,8 @@ export class TxBuilder {
// Calculate the total collateral based on the transaction fee and collateral percentage.
const totalCollateral = BigInt(
Math.ceil(
(this.params.collateralPercentage *
Number(bigintMax(this.fee, this.minimumFee) + this.feePadding)) /
100,
(this.params.collateralPercentage / 100) *
Number(bigintMax(this.fee, this.minimumFee) + this.feePadding),
),
);
// Calculate the collateral value by summing up the amounts from collateral inputs.
Expand Down

0 comments on commit 0a667b8

Please sign in to comment.