From 70893de6c03e3041655bacf4cc75fa3750737e8c Mon Sep 17 00:00:00 2001 From: hzhu Date: Sat, 10 Aug 2024 23:55:42 -0700 Subject: [PATCH] fix: remove hardcoded settler meta txn contract Settler contract addresses are dynamic. To distinguish the contract, function selector for executeMetaTxn instead. --- src/constants.ts | 14 ++------------ src/index.ts | 13 ++----------- src/tests/index.test.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 007362e..c762cfc 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -29,6 +29,8 @@ export const SETTLER_ABI = [ }, ]; +export const FUNCTION_SELECTORS = { EXECUTE_META_TXN: "0xfd3ad6d4" }; + export const NATIVE_TOKEN_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; @@ -43,18 +45,6 @@ export const NATIVE_SYMBOL_BY_CHAIN_ID: { [key in SupportedChainId]: string } = 43114: "AVAX", // Avalanche }; -export const SETTLER_META_TXN_BY_CHAIN_ID: { - [key in SupportedChainId]: string; -} = { - 1: "0x7C39a136EA20B3483e402EA031c1f3C019bAb24b", - 10: "0x4069560a180EbD76bB1aF947f5119Fe555BB4eA0", - 56: "0x73C25Ef091Ce3F2451946Be3f982549776bFED31", - 137: "0xF9332450385291b6dcE301917aF6905e28E8f35f", - 8453: "0x5CE929DDB01804bfF35B2F5c77b735bdB094AAc8", - 42161: "0x1aa84EB5cb62f686FC0D908AFd85864f4A05d5Ee", - 43114: "0x2adb2cE26848B94E13d2f7fE0fF7E945050D741c", -}; - export const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11"; export const NATIVE_ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; diff --git a/src/index.ts b/src/index.ts index 3a1925f..0649ea6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,9 +8,9 @@ import { import { SETTLER_ABI, MULTICALL3_ADDRESS, + FUNCTION_SELECTORS, NATIVE_TOKEN_ADDRESS, NATIVE_SYMBOL_BY_CHAIN_ID, - SETTLER_META_TXN_BY_CHAIN_ID, } from "./constants"; import { transferLogs, @@ -106,10 +106,7 @@ export async function parseSwap({ } } - const isSettlerMetaTxn = - to?.toLowerCase() === SETTLER_META_TXN_BY_CHAIN_ID[chainId].toLowerCase(); - - if (isSettlerMetaTxn) { + if (transaction.input.startsWith(FUNCTION_SELECTORS.EXECUTE_META_TXN)) { const { args } = decodeFunctionData({ abi: SETTLER_ABI, data: transaction.input, @@ -173,12 +170,6 @@ 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 2f12068..3dea4b0 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -476,6 +476,37 @@ test("parse a gasless swap on Base (USDC for ETH) for SettlerMetaTxn", async () }); }); +// https://basescan.org/tx/0x29b3f7bcd154e20e050793aa62d90309a860296aa846fd1158dc21356d1a3deb +test("parse a gasless swap on Base (weirdo for ETH) 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 = + "0x29b3f7bcd154e20e050793aa62d90309a860296aa846fd1158dc21356d1a3deb"; + + const result = await parseSwap({ + publicClient, + transactionHash, + }); + + expect(result).toEqual({ + tokenIn: { + symbol: "weirdo", + amount: "3145398.30971883", + address: "0x76734B57dFe834F102fB61E1eBF844Adf8DD931e", + }, + tokenOut: { + symbol: "ETH", + amount: "0.039633073597929391", + address: NATIVE_ETH_ADDRESS, + }, + }); +}); + // https://basescan.org/tx/0xe595dec22a7e2c2c5bdb0c1a7e59b2302ede72e5d2210c6cd7071222ea6dc2b2 test("parse a gasless swap on Base (DEGEN for USDC) for SettlerMetaTxn", async () => { const publicClient = createPublicClient({