Skip to content

Commit

Permalink
fix: account for bnb txs that do not...
Browse files Browse the repository at this point in the history
transfer tokens to taker, but instead to exchange proxy
which then transfers token to taker
  • Loading branch information
hzhu committed Mar 1, 2024
1 parent b4cb7ba commit 8dc1480
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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…");
});
23 changes: 23 additions & 0 deletions src/tests/sellToPancakeSwap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
});
});
});

0 comments on commit 8dc1480

Please sign in to comment.