Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions modules/sdk-coin-flr/src/flr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,15 @@ export class Flr extends AbstractEthLikeNewCoins {

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

// Then validate that the tx params actually equal the requested params to nano flr plus import tx fee.
const originalAmount = new BigNumber(recipients[0].amount).div(1e9).plus(importTxFee).toFixed(0);
const originalAmount = new BigNumber(recipients[0].amount).div(1e9).plus(minImportTxFee).toFixed(0);
const originalDestination: string | undefined = recipients[0].address;
const hopAmount = explainHopExportTx.outputAmount;
const hopDestination = explainHopExportTx.outputs[0].address;
if (originalAmount !== hopAmount) {
throw new Error(`Hop amount: ${hopAmount} does not equal original amount: ${originalAmount}`);
if (new BigNumber(hopAmount).isLessThan(originalAmount)) {
throw new Error(`Hop amount: ${hopAmount} is less than required amount: ${originalAmount}`);
}
if (originalDestination && hopDestination.toLowerCase() !== originalDestination.toLowerCase()) {
throw new Error(
Expand Down
18 changes: 10 additions & 8 deletions modules/sdk-coin-flr/test/unit/flr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as should from 'should';

import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';
import { coins } from '@bitgo/statics';

import { Flr, Tflr } from '../../src/index';
import { ExplainTransactionOptions } from '../../src/iface';
Expand Down Expand Up @@ -606,9 +607,10 @@ describe('flr', function () {
const hopDestinationAddress =
'P-costwo15msvr27szvhhpmah0c38gcml7vm29xjh7tcek8~P-costwo1cwrdtrgf4xh80ncu7palrjw7gn4mpj0n4dxghh~P-costwo1zt9n96hey4fsvnde35n3k4kt5pu7c784dzewzd';
const hopAddress = '0x28A05933dC76e4e6c25f35D5c9b2A58769700E76';
const importTxFee = 200000; // Match FlarePTestnet txFee from networks.ts
// Adjusted amount to work backwards from hop amount (50000000): 50000000 - 200000 = 49800000 nanoFLR
const amount = 49800000000000000;
const flrpCoin = coins.get('tflrp');
const importTxFee = Number((flrpCoin.network as any).minImportToPFee);
// Adjusted amount to work backwards from hop amount (50000000): 50000000 - importTxFee nanoFLR
const amount = (50000000 - importTxFee) * 1e9;
const txParams = {
recipients: [{ amount, address: hopDestinationAddress }],
wallet: wallet,
Expand Down Expand Up @@ -675,9 +677,7 @@ describe('flr', function () {
await tflrCoin
.verifyTransaction(verifyFlrTransactionOptions)
.should.be.rejectedWith(
`Hop amount: ${amount / 1e9 + importTxFee} does not equal original amount: ${
amount / 1e9 + importTxFee + 1
}`
`Hop amount: ${amount / 1e9 + importTxFee} is less than required amount: ${amount / 1e9 + importTxFee + 1}`
);
});

Expand Down Expand Up @@ -802,11 +802,13 @@ describe('flr', function () {

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

it('should throw error for Export hop prebuild with mismatched destination', async function () {
const wallet = new Wallet(bitgo, tflrCoin, {});
const flrpCoin = coins.get('tflrp');
const minImportToPFee = Number((flrpCoin.network as any).minImportToPFee);
const hopPrebuild = {
tx: hopExportTx,
id: hopExportTxId,
Expand All @@ -826,7 +828,7 @@ describe('flr', function () {
recipients: [
{
address: 'P-costwo1different~P-costwo1address~P-costwo1here',
amount: '49800000000000000', // 50000000 - 200000 (txFee) = 49800000 nanoFLR = 49800000000000000 wei
amount: String((50000000 - minImportToPFee) * 1e9), // Correct amount so destination check is reached
},
],
};
Expand Down
5 changes: 1 addition & 4 deletions modules/sdk-coin-flrp/src/lib/ImportInCTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ export class ImportInCTxBuilder extends AtomicInCTransactionBuilder {
throw new BuildTransactionError('threshold is required');
}

const estimatedGasUnits = BigInt(this.transaction._network.txFee) || 200000n;
const baseFeeInWei = BigInt(this.transaction._fee.fee);
const baseFeeGwei = baseFeeInWei / BigInt(1e9);
const actualFeeNFlr = baseFeeGwei * estimatedGasUnits;
const actualFeeNFlr = BigInt(this.transaction._fee.fee);
const sourceChain = 'P';

// Convert decoded UTXOs to native FlareJS Utxo objects
Expand Down
Loading