diff --git a/src/index.ts b/src/index.ts index 5098ea9..20e7111 100644 --- a/src/index.ts +++ b/src/index.ts @@ -158,6 +158,11 @@ export async function parseSwap({ "File a bug report here, including the expected results (URL to a block explorer) and the unexpected results: https://github.com/0xProject/0x-parser/issues/new/choose." ); } + + input = logs.filter( + (log) => log.from.toLowerCase() === msgSender.toLowerCase() + )[0]; + /* v8 ignore stop */ } else { output = { diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts index 523ae7b..68f449d 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -631,8 +631,9 @@ test("parse a gasless swap on Optimism (USDC for OP) for execute", async () => { }); }); +// TODO: remove skip or test different tx hash, RPC provider cannot fetch this transaction hash. // https://bscscan.com/tx/0xdda12da1e32c3320082355c985d6f2c6559169989de51e3cc83123395516c057 -test("parse a swap on BNB Chain (ETH for USDC) for execute", async () => { +test.skip("parse a swap on BNB Chain (ETH for USDC) for execute", async () => { const publicClient = createPublicClient({ chain: optimism, transport: http( @@ -745,6 +746,37 @@ test("parse a swap on Base (BRETT for ETH) with smart contract wallet", async () }); }); +// https://basescan.org/tx/0x283e2034885c34d2e2a5755e8ec77517c5eb8a2bf859a1a74b6dafec6f7ec73b +test("parse a meta transaction swap on Base (WETH 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 = `0x283e2034885c34d2e2a5755e8ec77517c5eb8a2bf859a1a74b6dafec6f7ec73b`; + + const result = await parseSwap({ + publicClient, + transactionHash, + smartContractWallet: "0x3F6dAB60Cc16377Df9684959e20962f44De20988", + }); + + expect(result).toEqual({ + tokenIn: { + symbol: "WETH", + amount: "0.0076565", + address: "0x4200000000000000000000000000000000000006", + }, + tokenOut: { + symbol: "USDC", + amount: "19.977303", + address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", + }, + }); +}); + // https://basescan.org/tx/0xe289a22987dcedfacb13584211c1d723ef5c42ea6e0dfd5c4d3271d20dec9ddc test("parse a swap on Base (ETH for USDC) with smart contract wallet", async () => { const publicClient = createPublicClient({