From 329a1fdf9654527cd5f10634bffc50c9e9f0b0c4 Mon Sep 17 00:00:00 2001 From: hzhu Date: Wed, 10 Jul 2024 10:28:50 -0700 Subject: [PATCH] fix: erc-20 transfers for SettlerMetaTxn --- src/parseSwapV2.ts | 14 +++++++++----- src/tests/parseSwapV2.test.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/parseSwapV2.ts b/src/parseSwapV2.ts index 84180d6..84d9b09 100644 --- a/src/parseSwapV2.ts +++ b/src/parseSwapV2.ts @@ -303,11 +303,15 @@ export async function parseSwapV2({ const nativeTransferAmount = extractNativeTransfer(trace, taker); - output = { - symbol: NATIVE_SYMBOL_BY_CHAIN_ID[chainId], - amount: nativeTransferAmount, - address: NATIVE_TOKEN_ADDRESS, - }; + if (nativeTransferAmount === "0") { + output = logs[logs.length - 1]; + } else { + output = { + symbol: NATIVE_SYMBOL_BY_CHAIN_ID[chainId], + amount: nativeTransferAmount, + address: NATIVE_TOKEN_ADDRESS, + }; + } } if (isNativeSell) { diff --git a/src/tests/parseSwapV2.test.ts b/src/tests/parseSwapV2.test.ts index 9736d9d..4ff6130 100644 --- a/src/tests/parseSwapV2.test.ts +++ b/src/tests/parseSwapV2.test.ts @@ -445,6 +445,37 @@ test("parse a gasless swap on Base (USDC for ETH) for SettlerMetaTxn", async () }); }); +// https://basescan.org/tx/0xe595dec22a7e2c2c5bdb0c1a7e59b2302ede72e5d2210c6cd7071222ea6dc2b2 +test("parse a gasless swap on Base (DEGEN for USDC) for SettlerMetaTxn", async () => { + const publicClient = createPublicClient({ + chain: base, + transport: http( + `https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}` + ), + }) as PublicClient; + + const transactionHash = + "0xe595dec22a7e2c2c5bdb0c1a7e59b2302ede72e5d2210c6cd7071222ea6dc2b2"; + + const result = await parseSwapV2({ + publicClient, + transactionHash, + }); + + expect(result).toEqual({ + tokenIn: { + symbol: "DEGEN", + amount: "1392.424785087824779911", + address: "0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed", + }, + tokenOut: { + symbol: "USDC", + amount: "9.915288", + address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", + }, + }); +}); + // https://arbiscan.io/tx/0xb2c05194e4ec9ae0f82098ec82a606df544e87c8d6b7726bbb4b1dcc023cb9d7 test("parse a gasless swap on on Arbitrum (ARB for ETH)", async () => { const publicClient = createPublicClient({