Skip to content

Commit

Permalink
fix: use output log that has WETH for sellTokenForEthToUniswapV3
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhu committed Mar 19, 2024
1 parent fab530b commit 7660957
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export async function sellTokenForEthToUniswapV3({
const logs = await transferLogs({ publicClient, transactionReceipt });
const from = getAddress(transactionReceipt.from);
const inputLog = logs.find((log) => log.from === from);
const outputLog = logs.find((log) => log.from !== from);
const outputLog = logs.find((log) => log.address === CONTRACTS.weth);

if (inputLog && outputLog) {
outputLog.symbol = NATIVE_ASSET.symbol;
Expand Down
29 changes: 26 additions & 3 deletions src/tests/sellTokenForEthToUniswapV3.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { parseSwap } from "../index";
import { NATIVE_ASSET } from "../constants";
import { exchangeProxyAbi } from "../abi/ExchangeProxyAbi"
import { exchangeProxyAbi } from "../abi/ExchangeProxyAbi";

require("dotenv").config();

Expand All @@ -17,14 +17,15 @@ describe("parseSwap", () => {
const data = await parseSwap({
exchangeProxyAbi,
rpcUrl: ETH_MAINNET_RPC,
transactionHash: '0x822d38c0746b19544cedddd9a1ebaacadd3e5da55dc293738ae135fc595e269b',
transactionHash:
"0x822d38c0746b19544cedddd9a1ebaacadd3e5da55dc293738ae135fc595e269b",
});

expect(data).toEqual({
tokenIn: {
symbol: "✺RUG",
amount: "56322.215316673764925169",
address: '0xD2d8D78087D0E43BC4804B6F946674b2Ee406b80',
address: "0xD2d8D78087D0E43BC4804B6F946674b2Ee406b80",
},
tokenOut: {
symbol: NATIVE_ASSET.symbol,
Expand All @@ -33,4 +34,26 @@ describe("parseSwap", () => {
},
});
});

it("parses swap from sellTokenForEthToUniswapV3", async () => {
const data = await parseSwap({
exchangeProxyAbi,
rpcUrl: ETH_MAINNET_RPC,
transactionHash:
"0xf6271c6ae709c31b2679f9190798bc64e636feb8b49d498e6239f171783884df",
});

expect(data).toEqual({
tokenIn: {
symbol: "ETHFI",
amount: "609.2",
address: "0xFe0c30065B384F05761f15d0CC899D4F9F9Cc0eB",
},
tokenOut: {
symbol: NATIVE_ASSET.symbol,
amount: "0.519590258364550926",
address: NATIVE_ASSET.address,
},
});
});
});

0 comments on commit 7660957

Please sign in to comment.