diff --git a/packages/bcp/src/decode.spec.ts b/packages/bcp/src/decode.spec.ts index b769c00b..346bf27d 100644 --- a/packages/bcp/src/decode.spec.ts +++ b/packages/bcp/src/decode.spec.ts @@ -209,10 +209,56 @@ describe("decode", () => { }); describe("parseUnsignedTx", () => { - it("works", () => { - expect(parseUnsignedTx(cosmoshub.tx.value, testdata.chainId, defaultTokens)).toEqual( - testdata.sendTxJson, - ); + it("works for bank send transaction", () => { + expect( + parseUnsignedTx(cosmoshub.tx.value, testdata.chainId, defaultTokens, defaultErc20Tokens), + ).toEqual(testdata.sendTxJson); + }); + + it("works for ERC20 send transaction", () => { + const msg: types.MsgExecuteContract = { + type: "wasm/execute", + value: { + sender: "cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r", + contract: defaultErc20Tokens[0].contractAddress, + msg: { + transfer: { + amount: "887878484", + recipient: "cosmos1z7g5w84ynmjyg0kqpahdjqpj7yq34v3suckp0e", + }, + }, + sent_funds: [], + }, + }; + const tx: types.StdTx = { + msg: [msg], + memo: defaultMemo, + fee: { + amount: [ + { + denom: "uatom", + amount: "5000", + }, + ], + gas: "200000", + }, + signatures: [], + }; + const unsigned = parseUnsignedTx(tx, testdata.chainId, defaultTokens, defaultErc20Tokens); + assert(isSendTransaction(unsigned)); + expect(unsigned).toEqual({ + kind: "bcp/send", + chainId: testdata.chainId, + sender: "cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r" as Address, + recipient: "cosmos1z7g5w84ynmjyg0kqpahdjqpj7yq34v3suckp0e" as Address, + amount: { + quantity: "887878484", + tokenTicker: "ASH" as TokenTicker, + fractionalDigits: 5, + }, + memo: defaultMemo, + fee: defaultFee, + }); }); }); diff --git a/packages/bcp/src/decode.ts b/packages/bcp/src/decode.ts index 0aede7e5..37420252 100644 --- a/packages/bcp/src/decode.ts +++ b/packages/bcp/src/decode.ts @@ -144,6 +144,7 @@ export function parseUnsignedTx( txValue: types.StdTx, chainId: ChainId, tokens: BankTokens, + erc20Tokens: readonly Erc20Token[], ): UnsignedTransaction { if (!types.isStdTx(txValue)) { throw new Error("Only StdTx is supported"); @@ -152,7 +153,7 @@ export function parseUnsignedTx( throw new Error("Only single-message transactions currently supported"); } - const msg = parseMsg(txValue.msg[0], txValue.memo, chainId, tokens); + const msg = parseMsg(txValue.msg[0], txValue.memo, chainId, tokens, erc20Tokens); const fee = parseFee(txValue.fee, tokens); return { @@ -170,7 +171,7 @@ export function parseSignedTx( ): SignedTransaction { const [primarySignature] = txValue.signatures.map(signature => decodeFullSignature(signature, nonce)); return { - transaction: parseUnsignedTx(txValue, chainId, tokens), + transaction: parseUnsignedTx(txValue, chainId, tokens, []), signatures: [primarySignature], }; } @@ -183,7 +184,7 @@ export function parseTxsResponseUnsigned( ): ConfirmedTransaction { const height = parseInt(response.height, 10); return { - transaction: parseUnsignedTx(response.tx.value, chainId, tokens), + transaction: parseUnsignedTx(response.tx.value, chainId, tokens, []), height: height, confirmations: currentHeight - height + 1, transactionId: response.txhash as TransactionId, diff --git a/packages/bcp/types/decode.d.ts b/packages/bcp/types/decode.d.ts index 95035554..65105b0c 100644 --- a/packages/bcp/types/decode.d.ts +++ b/packages/bcp/types/decode.d.ts @@ -31,6 +31,7 @@ export declare function parseUnsignedTx( txValue: types.StdTx, chainId: ChainId, tokens: BankTokens, + erc20Tokens: readonly Erc20Token[], ): UnsignedTransaction; export declare function parseSignedTx( txValue: types.StdTx,