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
16 changes: 7 additions & 9 deletions modules/sdk-coin-avaxp/src/lib/exportInCTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ export class ExportInCTxBuilder extends AtomicInCTransactionBuilder {
const inputAmount = new BN((input as any).amount);
const outputAmount = (output.getOutput() as AmountOutput).getAmount();
const fee = inputAmount.sub(outputAmount);
this._amount = outputAmount.subn(Number(this.fixedFee));
this.transaction._fee.feeRate = fee.toNumber();
this.transaction._fee.fee = this.transaction._fee.feeRate.toString();
this._amount = outputAmount;
this.transaction._fee.feeRate = fee.toNumber() - Number(this.fixedFee);
this.transaction._fee.fee = fee.toString();
this.transaction._fee.size = 1;
this.transaction._fromAddresses = [input.getAddress()];

Expand Down Expand Up @@ -153,17 +153,15 @@ export class ExportInCTxBuilder extends AtomicInCTransactionBuilder {
if (!this._nonce === undefined) {
throw new Error('nonce is required');
}
const txFee = Number(this.fixedFee);

const fee: number = this.transaction._fee.feeRate;
const fee: number = this.transaction._fee.feeRate + txFee;
this.transaction._fee.fee = fee.toString();
this.transaction._fee.size = 1;

// The amount arrives after import tx. Then a fixed fee will be paid upon import.
const importTxFee = Number(this.fixedFee);

const input = new EVMInput(
this.transaction._fromAddresses[0],
this._amount.addn(fee).addn(importTxFee),
this._amount.addn(fee),
this.transaction._assetId,
this._nonce
);
Expand All @@ -181,7 +179,7 @@ export class ExportInCTxBuilder extends AtomicInCTransactionBuilder {
new TransferableOutput(
this.transaction._assetId,
new SECPTransferOutput(
this._amount.addn(importTxFee),
this._amount,
this.transaction._to,
this.transaction._locktime,
this.transaction._threshold
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-avaxp/test/resources/tx/exportC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const EXPORT_C = {
'0x000000000001000000057fc93d85c6d62c5b2ac0b519c87010ea5294012d1e407030d6acd0021cac10d500000000000000000000000000000000000000000000000000000000000000000000000147c0b1f5d366ea8f1d0cd2ce108321d2be3b338600000000009896803d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa0000000000000009000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa0000000700000000008954270000000000000000000000020000000320829837bfba5d602b19cb9102b99eb3f895d5e47c71b9ae100e813e6332eddad2554ec12a0591fcbb6de9adcfbf2e0dfeffbe7792afd0c4085fdd37000000010000000900000001175782fa48b5b308d8f378832e5e637febb1fbcbec8f75fd6a65b657418575777b45c17a01b548a559d99e1a570d1efebe9b595dca383b0e39d5a961f16dd27500bdc89d2b',
txhash: 'jHRxuZjnSHYNwWpUUyob7RpfHwj1wfuQa8DGWQrkDh2RQ5Jb3',
privKey: 'PrivateKey-2Ny9WLHyaKUWNGbwHeki8kxLab3vniB8oeVw4MLfCNSFbZKsEb',
amount: '7999975',
amount: '8999975',
cHexAddress: '0x47c0b1f5d366ea8f1d0cd2ce108321d2be3b3386',
pAddresses: [
'P-fuji103cmntssp6qnucejahddy42wcy4qty0uj42822',
Expand All @@ -15,5 +15,5 @@ export const EXPORT_C = {
targetChainId: '11111111111111111111111111111111LpoYY',
nonce: 9,
threshold: 2,
fee: '1000025',
fee: '25',
};
10 changes: 4 additions & 6 deletions modules/sdk-coin-avaxp/test/unit/avaxp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,27 +388,25 @@ describe('Avaxp', function () {
});

it('should explain a unsigned export in C transaction', async () => {
const importInPFee = 1000000;
const testData = EXPORT_C;
const txExplain = await basecoin.explainTransaction({ txHex: testData.unsignedTxHex });
txExplain.outputAmount.should.equal((Number(testData.amount) + importInPFee).toString());
txExplain.outputAmount.should.equal(Number(testData.amount).toString());
txExplain.type.should.equal(TransactionType.Export);
txExplain.inputs[0].address.should.equal(testData.cHexAddress);
txExplain.outputs[0].address.should.equal(testData.pAddresses.slice().sort().join('~'));
txExplain.fee.fee.should.equal(testData.fee);
txExplain.fee.feeRate.should.equal(Number(testData.fee));
txExplain.changeOutputs.should.be.empty();
should.not.exist(txExplain.memo);
});

it('should explain a signed export in C transaction', async () => {
const importInPFee = 1000000;
const testData = EXPORT_C;
const txExplain = await basecoin.explainTransaction({ txHex: testData.fullsigntxHex });
txExplain.outputAmount.should.equal((Number(testData.amount) + importInPFee).toString());
txExplain.outputAmount.should.equal(Number(testData.amount).toString());
txExplain.type.should.equal(TransactionType.Export);
txExplain.inputs[0].address.should.equal(testData.cHexAddress);
txExplain.outputs[0].address.should.equal(testData.pAddresses.slice().sort().join('~'));
txExplain.fee.fee.should.equal(testData.fee);
txExplain.fee.feeRate.should.equal(Number(testData.fee));
txExplain.changeOutputs.should.be.empty();
should.not.exist(txExplain.memo);
});
Expand Down