Skip to content

Commit

Permalink
fix: parse latest executeMetaTxn from base
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhu committed Jul 31, 2024
1 parent bd0f841 commit f6a825c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ 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 @@ -259,6 +259,37 @@ test("throws an error for unsupported chains)", async () => {
}).rejects.toThrowError("chainId 42220 is unsupported…");
});

// https://basescan.org/tx/0x314ea35ef3120934ee4714f4815dc3b08dc2ab0e32e0662bfba3cdbcff14d79b
test("parse a gasless swap on Base (DAI for USDC)", 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 =
"0x314ea35ef3120934ee4714f4815dc3b08dc2ab0e32e0662bfba3cdbcff14d79b";

const result = await parseSwap({
publicClient,
transactionHash,
});

expect(result).toEqual({
tokenIn: {
symbol: "DAI",
amount: "1.998484821908329022",
address: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
},
tokenOut: {
symbol: "USDC",
amount: "1.982641",
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
},
});
});

// https://basescan.org/tx/0xa09cb1606e30c3aed8a842723fd6c23cecd838a59f750ab3dbc5ef2c7486e696
test("parse a swap on Base (USDC for DAI)", async () => {
const publicClient = createPublicClient({
Expand Down

0 comments on commit f6a825c

Please sign in to comment.