Skip to content

Commit

Permalink
fix: filter from logs from taker for initial input
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhu committed Jul 17, 2024
1 parent 07d9008 commit fb218e5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parseSwapV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ export async function parseSwapV2({
transactionReceipt,
});

let input = logs[0];
const fromTaker = logs.filter(
(log) => log.from.toLowerCase() === taker.toLowerCase()
);

let input = fromTaker.length ? fromTaker[0] : logs[0];

let output =
nativeTransferAmount === "0"
Expand Down
31 changes: 31 additions & 0 deletions src/tests/parseSwapV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,37 @@ test("parse a gasless swap on Optimism (USDC for OP) for executeMetaTxn", async
});
});

// https://optimistic.etherscan.io/tx/0x9abc33ffc67ff9348af9a29f109c4f27b36ee5bc80dd81ae3814e69309449a61
test("parse a gasless swap on Optimism (USDC for OP) for execute", async () => {
const publicClient = createPublicClient({
chain: optimism,
transport: http(
`https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
),
}) as PublicClient<Transport, Chain>;

const transactionHash =
"0x9abc33ffc67ff9348af9a29f109c4f27b36ee5bc80dd81ae3814e69309449a61";

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

expect(result).toEqual({
tokenIn: {
symbol: "USDC",
amount: "5",
address: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
},
tokenOut: {
symbol: "OP",
amount: "2.73214427938472425",
address: "0x4200000000000000000000000000000000000042",
},
});
});

// https://bscscan.com/tx/0xdda12da1e32c3320082355c985d6f2c6559169989de51e3cc83123395516c057
test("parse a swap on BNB Chain (ETH for USDC) for execute", async () => {
const publicClient = createPublicClient({
Expand Down

0 comments on commit fb218e5

Please sign in to comment.