From f6a825c79a0f47efcf85209a2ba8c4673caa9b36 Mon Sep 17 00:00:00 2001 From: hzhu Date: Tue, 30 Jul 2024 22:48:57 -0700 Subject: [PATCH] fix: parse latest executeMetaTxn from base --- src/index.ts | 6 ++++++ src/tests/index.test.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/index.ts b/src/index.ts index b3f00e7..3a1925f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -173,6 +173,12 @@ export async function parseSwap({ }; } + if (!output && input.from) { + output = logs.find( + (log) => log.to.toLowerCase() === input.from.toLowerCase() + ); + } + /* v8 ignore start */ if (!output) { console.error( diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts index 6305417..2f12068 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -259,6 +259,37 @@ test("throws an error for unsupported chains)", async () => { }).rejects.toThrowError("chainId 42220 is unsupported…"); }); +// https://basescan.org/tx/0x314ea35ef3120934ee4714f4815dc3b08dc2ab0e32e0662bfba3cdbcff14d79b +test("parse a gasless swap on Base (DAI for USDC)", async () => { + const publicClient = createPublicClient({ + chain: base, + transport: http( + `https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}` + ), + }) as PublicClient; + + const transactionHash = + "0x314ea35ef3120934ee4714f4815dc3b08dc2ab0e32e0662bfba3cdbcff14d79b"; + + const result = await parseSwap({ + publicClient, + transactionHash, + }); + + expect(result).toEqual({ + tokenIn: { + symbol: "DAI", + amount: "1.998484821908329022", + address: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb", + }, + tokenOut: { + symbol: "USDC", + amount: "1.982641", + address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", + }, + }); +}); + // https://basescan.org/tx/0xa09cb1606e30c3aed8a842723fd6c23cecd838a59f750ab3dbc5ef2c7486e696 test("parse a swap on Base (USDC for DAI)", async () => { const publicClient = createPublicClient({