Skip to content

Commit f6a825c

Browse files
committed
fix: parse latest executeMetaTxn from base
1 parent bd0f841 commit f6a825c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Diff for: src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ export async function parseSwap({
173173
};
174174
}
175175

176+
if (!output && input.from) {
177+
output = logs.find(
178+
(log) => log.to.toLowerCase() === input.from.toLowerCase()
179+
);
180+
}
181+
176182
/* v8 ignore start */
177183
if (!output) {
178184
console.error(

Diff for: src/tests/index.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,37 @@ test("throws an error for unsupported chains)", async () => {
259259
}).rejects.toThrowError("chainId 42220 is unsupported…");
260260
});
261261

262+
// https://basescan.org/tx/0x314ea35ef3120934ee4714f4815dc3b08dc2ab0e32e0662bfba3cdbcff14d79b
263+
test("parse a gasless swap on Base (DAI for USDC)", async () => {
264+
const publicClient = createPublicClient({
265+
chain: base,
266+
transport: http(
267+
`https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
268+
),
269+
}) as PublicClient<Transport, Chain>;
270+
271+
const transactionHash =
272+
"0x314ea35ef3120934ee4714f4815dc3b08dc2ab0e32e0662bfba3cdbcff14d79b";
273+
274+
const result = await parseSwap({
275+
publicClient,
276+
transactionHash,
277+
});
278+
279+
expect(result).toEqual({
280+
tokenIn: {
281+
symbol: "DAI",
282+
amount: "1.998484821908329022",
283+
address: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
284+
},
285+
tokenOut: {
286+
symbol: "USDC",
287+
amount: "1.982641",
288+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
289+
},
290+
});
291+
});
292+
262293
// https://basescan.org/tx/0xa09cb1606e30c3aed8a842723fd6c23cecd838a59f750ab3dbc5ef2c7486e696
263294
test("parse a swap on Base (USDC for DAI)", async () => {
264295
const publicClient = createPublicClient({

0 commit comments

Comments
 (0)