Skip to content

Commit

Permalink
fix: remove hardcoded settler meta txn contract
Browse files Browse the repository at this point in the history
Settler contract addresses are dynamic. To distinguish the contract,
function selector for executeMetaTxn instead.
  • Loading branch information
hzhu committed Aug 11, 2024
1 parent 82b65a3 commit 70893de
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
14 changes: 2 additions & 12 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const SETTLER_ABI = [
},
];

export const FUNCTION_SELECTORS = { EXECUTE_META_TXN: "0xfd3ad6d4" };

export const NATIVE_TOKEN_ADDRESS =
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";

Expand All @@ -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";
13 changes: 2 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<any[]>({
abi: SETTLER_ABI,
data: transaction.input,
Expand Down Expand Up @@ -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(
Expand Down
31 changes: 31 additions & 0 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transport, Chain>;

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({
Expand Down

0 comments on commit 70893de

Please sign in to comment.