Skip to content

Commit 558f621

Browse files
committed
feat(sdk-coin-ada): use 1 ada as min fees
Ticket: WIN-7481
1 parent 7de29c6 commit 558f621

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

modules/sdk-coin-ada/src/lib/transactionBuilder.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const FEE_COEFFICIENTS = {
2626
B_COEFFICIENT: '155381',
2727
/** Additional safety margin for the fee */
2828
SAFETY_MARGIN: '440',
29+
/* Min fee required for token transaction */
30+
MIN_TOKEN_TRANSACTION_FEE: '1000000',
2931
};
3032

3133
export abstract class TransactionBuilder extends BaseTransactionBuilder {
@@ -377,7 +379,15 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
377379
);
378380

379381
// Calculate the fee based off our dummy transaction
380-
const fee = CardanoWasm.min_fee(txDraft, linearFee).checked_add(BigNum.from_str(FEE_COEFFICIENTS.SAFETY_MARGIN));
382+
let fee = CardanoWasm.min_fee(txDraft, linearFee).checked_add(BigNum.from_str(FEE_COEFFICIENTS.SAFETY_MARGIN));
383+
/**
384+
* In some cases especially with token transactions the calculated fee can be very low than the fee expected from the node
385+
* So, ensure a minimum fee is always set
386+
*/
387+
const minTokenFee = BigNum.from_str(FEE_COEFFICIENTS.MIN_TOKEN_TRANSACTION_FEE);
388+
if (fee.less_than(minTokenFee)) {
389+
fee = minTokenFee;
390+
}
381391
this._fee = fee;
382392
}
383393

modules/sdk-coin-ada/test/unit/tokenWithdrawal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('ADA Token Operations', async () => {
3939
totalInput -
4040
1500000 /* min ada for change token utxo */ -
4141
1500000 /* min ada for recipient token utxo*/ -
42-
173597
42+
1000000
4343
) /* fee */
4444
.toString();
4545
const expectedChangeToken = '80';
@@ -127,7 +127,7 @@ describe('ADA Token Operations', async () => {
127127
1500000 /* min ada for change token utxo */ -
128128
1500000 /* min ada for recipient token utxo*/ -
129129
1500000 /* min ada for unsupported token change utxo */ -
130-
179889
130+
1000000
131131
) /* fee */
132132
.toString();
133133
const expectedChangeToken = '80';

0 commit comments

Comments
 (0)