Skip to content

Commit

Permalink
Merge pull request #4408 from BitGo/WP-1652-Add-FlushTokenV4-support
Browse files Browse the repository at this point in the history
fix(abstract-eth): fix flush v4 tx building from hex
  • Loading branch information
dpkjnr authored Apr 8, 2024
2 parents 7c488c8 + f20dc10 commit 5f1a1cf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions modules/abstract-eth/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface ERC1155TransferData extends TokenTransferData {
export interface FlushTokensData {
forwarderAddress: string;
tokenAddress: string;
forwarderVersion?: number;
}

export interface NativeTransferData extends TransferData {
Expand Down
8 changes: 7 additions & 1 deletion modules/abstract-eth/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
break;
case TransactionType.FlushTokens:
this.setContract(transactionJson.to);
const { forwarderAddress, tokenAddress } = decodeFlushTokensData(transactionJson.data, transactionJson.to);
const { forwarderAddress, tokenAddress, forwarderVersion } = decodeFlushTokensData(
transactionJson.data,
transactionJson.to
);
if (forwarderVersion === 4) {
this.forwarderVersion(4);
}
this.forwarderAddress(forwarderAddress);
this.tokenAddress(tokenAddress);
break;
Expand Down
1 change: 1 addition & 0 deletions modules/abstract-eth/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ export function decodeFlushTokensData(data: string, to?: string): FlushTokensDat
return {
forwarderAddress: to,
tokenAddress: addHexPrefix(tokenAddress as string),
forwarderVersion: 4,
};
} else {
throw new BuildTransactionError(`Invalid transfer bytecode: ${data}`);
Expand Down
19 changes: 11 additions & 8 deletions modules/sdk-coin-eth/test/unit/transactionBuilder/flushTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ describe('Eth Transaction builder flush tokens', function () {
forwarderVersion: 4,
});
const txBuiderFromRaw: any = getBuilder('teth');
txBuiderFromRaw.fromImplementation(tx.toBroadcastFormat());
// txBuiderFromRaw.type.should.equal(TransactionType.FlushTokens);
txBuiderFromRaw._forwarderAddress.should.equal('0x53b8e91bb3b8f618b5f01004ef108f134f219573');
txBuiderFromRaw._tokenAddress.should.equal('0xbcf935d206ca32929e1b887a07ed240f0d8ccd22');
txBuiderFromRaw.from(tx.toBroadcastFormat());
const result = await txBuiderFromRaw.build();
const txJson = result.toJson();
txJson.to.should.equal('0x53b8e91bb3b8f618b5f01004ef108f134f219573');
txJson.data.should.containEql('bcf935d206ca32929e1b887a07ed240f0d8ccd22');
});

it('decode wallet flush forwarder transaction with forwarder Version < 4', async () => {
Expand All @@ -182,10 +183,12 @@ describe('Eth Transaction builder flush tokens', function () {
forwarderVersion: 2,
});
const txBuiderFromRaw: any = getBuilder('teth');
txBuiderFromRaw.fromImplementation(tx.toBroadcastFormat());
// txBuiderFromRaw.type.should.equal(TransactionType.FlushTokens);
txBuiderFromRaw._forwarderAddress.should.equal('0x53b8e91bb3b8f618b5f01004ef108f134f219573');
txBuiderFromRaw._tokenAddress.should.equal('0xbcf935d206ca32929e1b887a07ed240f0d8ccd22');
txBuiderFromRaw.from(tx.toBroadcastFormat());
const result = await txBuiderFromRaw.build();
const txJson = result.toJson();
txJson.to.should.equal('0x8f977e912ef500548a0c3be6ddde9899f1199b81');
txJson.data.should.containEql('bcf935d206ca32929e1b887a07ed240f0d8ccd22');
txJson.data.should.containEql('53b8e91bb3b8f618b5f01004ef108f134f219573');
});

it('an unsigned flush transaction from serialized', async () => {
Expand Down

0 comments on commit 5f1a1cf

Please sign in to comment.