Skip to content

Commit 8281d49

Browse files
committed
fix(sdk-coin-flr): update import transaction fee validation
Ticket: WIN-8633
1 parent dbe6273 commit 8281d49

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

modules/sdk-coin-flr/src/flr.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,15 @@ export class Flr extends AbstractEthLikeNewCoins {
386386

387387
// Get the P-chain import fee from network configuration
388388
const flrpCoin = coins.get(this.getFlrP());
389-
const importTxFee = (flrpCoin.network as any).txFee || '1000000';
389+
const minImportTxFee = (flrpCoin.network as any).minImportToPFee || '1261000';
390390

391391
// Then validate that the tx params actually equal the requested params to nano flr plus import tx fee.
392-
const originalAmount = new BigNumber(recipients[0].amount).div(1e9).plus(importTxFee).toFixed(0);
392+
const originalAmount = new BigNumber(recipients[0].amount).div(1e9).plus(minImportTxFee).toFixed(0);
393393
const originalDestination: string | undefined = recipients[0].address;
394394
const hopAmount = explainHopExportTx.outputAmount;
395395
const hopDestination = explainHopExportTx.outputs[0].address;
396-
if (originalAmount !== hopAmount) {
397-
throw new Error(`Hop amount: ${hopAmount} does not equal original amount: ${originalAmount}`);
396+
if (new BigNumber(hopAmount).isLessThan(originalAmount)) {
397+
throw new Error(`Hop amount: ${hopAmount} is less than required amount: ${originalAmount}`);
398398
}
399399
if (originalDestination && hopDestination.toLowerCase() !== originalDestination.toLowerCase()) {
400400
throw new Error(

modules/sdk-coin-flr/test/unit/flr.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as should from 'should';
22

33
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
44
import { BitGoAPI } from '@bitgo/sdk-api';
5+
import { coins } from '@bitgo/statics';
56

67
import { Flr, Tflr } from '../../src/index';
78
import { ExplainTransactionOptions } from '../../src/iface';
@@ -606,9 +607,10 @@ describe('flr', function () {
606607
const hopDestinationAddress =
607608
'P-costwo15msvr27szvhhpmah0c38gcml7vm29xjh7tcek8~P-costwo1cwrdtrgf4xh80ncu7palrjw7gn4mpj0n4dxghh~P-costwo1zt9n96hey4fsvnde35n3k4kt5pu7c784dzewzd';
608609
const hopAddress = '0x28A05933dC76e4e6c25f35D5c9b2A58769700E76';
609-
const importTxFee = 200000; // Match FlarePTestnet txFee from networks.ts
610-
// Adjusted amount to work backwards from hop amount (50000000): 50000000 - 200000 = 49800000 nanoFLR
611-
const amount = 49800000000000000;
610+
const flrpCoin = coins.get('tflrp');
611+
const importTxFee = Number((flrpCoin.network as any).minImportToPFee);
612+
// Adjusted amount to work backwards from hop amount (50000000): 50000000 - importTxFee nanoFLR
613+
const amount = (50000000 - importTxFee) * 1e9;
612614
const txParams = {
613615
recipients: [{ amount, address: hopDestinationAddress }],
614616
wallet: wallet,
@@ -675,9 +677,7 @@ describe('flr', function () {
675677
await tflrCoin
676678
.verifyTransaction(verifyFlrTransactionOptions)
677679
.should.be.rejectedWith(
678-
`Hop amount: ${amount / 1e9 + importTxFee} does not equal original amount: ${
679-
amount / 1e9 + importTxFee + 1
680-
}`
680+
`Hop amount: ${amount / 1e9 + importTxFee} is less than required amount: ${amount / 1e9 + importTxFee + 1}`
681681
);
682682
});
683683

@@ -802,11 +802,13 @@ describe('flr', function () {
802802

803803
await (tflrCoin as any)
804804
.validateHopPrebuild(wallet, hopPrebuild, originalParams)
805-
.should.be.rejectedWith(/Hop amount: .* does not equal original amount/);
805+
.should.be.rejectedWith(/Hop amount: .* is less than required amount/);
806806
});
807807

808808
it('should throw error for Export hop prebuild with mismatched destination', async function () {
809809
const wallet = new Wallet(bitgo, tflrCoin, {});
810+
const flrpCoin = coins.get('tflrp');
811+
const minImportToPFee = Number((flrpCoin.network as any).minImportToPFee);
810812
const hopPrebuild = {
811813
tx: hopExportTx,
812814
id: hopExportTxId,
@@ -826,7 +828,7 @@ describe('flr', function () {
826828
recipients: [
827829
{
828830
address: 'P-costwo1different~P-costwo1address~P-costwo1here',
829-
amount: '49800000000000000', // 50000000 - 200000 (txFee) = 49800000 nanoFLR = 49800000000000000 wei
831+
amount: String((50000000 - minImportToPFee) * 1e9), // Correct amount so destination check is reached
830832
},
831833
],
832834
};

modules/sdk-coin-flrp/src/lib/ImportInCTxBuilder.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ export class ImportInCTxBuilder extends AtomicInCTransactionBuilder {
147147
throw new BuildTransactionError('threshold is required');
148148
}
149149

150-
const estimatedGasUnits = BigInt(this.transaction._network.txFee) || 200000n;
151-
const baseFeeInWei = BigInt(this.transaction._fee.fee);
152-
const baseFeeGwei = baseFeeInWei / BigInt(1e9);
153-
const actualFeeNFlr = baseFeeGwei * estimatedGasUnits;
150+
const actualFeeNFlr = BigInt(this.transaction._fee.fee);
154151
const sourceChain = 'P';
155152

156153
// Convert decoded UTXOs to native FlareJS Utxo objects

0 commit comments

Comments
 (0)