diff --git a/src/parsers/index.ts b/src/parsers/index.ts index 87104e1..a3d6391 100644 --- a/src/parsers/index.ts +++ b/src/parsers/index.ts @@ -447,6 +447,10 @@ export async function sellToPancakeSwap({ outputLog = logs.find((log) => log.from !== exchangeProxy); } + if (!logs.some((log) => log.to === from)) { + outputLog = logs.find((log) => log.to === exchangeProxy); + } + if (inputLog && outputLog) { return extractTokenInfo(inputLog, outputLog); } diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts index a2a749f..5aac512 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -1,7 +1,7 @@ import { it, expect } from "vitest"; import { parseSwap } from "../index"; import { EXCHANGE_PROXY_ABI_URL } from "../constants"; -import { exchangeProxyAbi } from "../abi/ExchangeProxyAbi" +import { exchangeProxyAbi } from "../abi/ExchangeProxyAbi"; require("dotenv").config(); @@ -66,7 +66,7 @@ it("throws an error if the chainId is not supported", () => { exchangeProxyAbi, rpcUrl: "https://rpc.gnosis.gateway.fm", transactionHash: - "0x689eaa9ad3db373b241330be646e450d5b8bb3faad7f0c3260c63b9ef6765fcb", + "0x2cd8904d385dbf4347c28062d8c20d1307202ee5e1d3aacf4b3fc067ca783a29", }); }).rejects.toThrowError("chainId 100 is unsupported…"); }); diff --git a/src/tests/sellToPancakeSwap.test.ts b/src/tests/sellToPancakeSwap.test.ts index 4ecdf44..7459f93 100644 --- a/src/tests/sellToPancakeSwap.test.ts +++ b/src/tests/sellToPancakeSwap.test.ts @@ -73,4 +73,27 @@ describe("sellToPancakeSwap", () => { }); }); }); + + // https://bscscan.com/tx/0xba7e86dd27ba9b14cca0c98edc5df9c753ec8ae27ace3bacb80e87cbde33f850 + it("parses swap from sellToPancakeSwap with transfer events that transfer output amount to exchange proxy", async () => { + const data = await parseSwap({ + exchangeProxyAbi, + rpcUrl: BSC_RPC, + transactionHash: + "0xba7e86dd27ba9b14cca0c98edc5df9c753ec8ae27ace3bacb80e87cbde33f850", + }); + + expect(data).toEqual({ + tokenIn: { + symbol: "IDIA", + amount: "50", + address: "0x0b15Ddf19D47E6a86A56148fb4aFFFc6929BcB89", + }, + tokenOut: { + symbol: "WBNB", + amount: "0.011285266969864419", + address: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", + }, + }); + }); });