Skip to content

Commit

Permalink
swapx refactor (#13051)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebruce0x authored Jan 10, 2025
2 parents 63a9293 + 96b527d commit 3564e48
Showing 1 changed file with 3 additions and 41 deletions.
44 changes: 3 additions & 41 deletions projects/SwapX-v2/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,9 @@
const { transformDexBalances } = require("../helper/portedTokens");
const { getLogs } = require("../helper/cache/getLogs");

const SWAPX_V2_FACTORY = "0x05c1be79d3aC21Cc4B727eeD58C9B2fF757F5663"
const PAIR_CREATED_TOPIC_1 = "0xc4805696c66d7cf352fc1d6bb633ad5ee82f6cb577c453024b6e0eb8306c6fc9"; // keccak256 hash of the event signature
const PAIR_CREATED_EVENT_ABI_1 = "event PairCreated(address indexed token0, address indexed token1, bool stable, address pair, uint)";
const fromBlock = 1333667;
const erc20Abi = "erc20:balanceOf";

async function tvl(api) {
const getPairs = (logs) => {
return logs.map(log => ({
token0: log.token0,
token1: log.token1,
pair: log.pair
}));
}

const logs = getPairs(await getLogs({
api,
target: SWAPX_V2_FACTORY,
fromBlock,
topic: PAIR_CREATED_TOPIC_1,
onlyArgs: true,
eventAbi: PAIR_CREATED_EVENT_ABI_1
}));

const tok0Bals = await api.multiCall({ abi: erc20Abi, calls: logs.map(log => ({ target: log.token0, params: log.pair })) })
const tok1Bals = await api.multiCall({ abi: erc20Abi, calls: logs.map(log => ({ target: log.token1, params: log.pair })) })

return transformDexBalances({
chain: api.chain,
data: logs.map((log, i) => ({
token0: log.token0,
token0Bal: tok0Bals[i],
token1: log.token1,
token1Bal: tok1Bals[i],
}))
})
}
const { uniTvlExport } = require("../helper/calculateUniTvl");

module.exports = {
misrepresentedTokens: true,
sonic: {
tvl
tvl: uniTvlExport("0x05c1be79d3aC21Cc4B727eeD58C9B2fF757F5663", undefined, undefined, {
}, { useDefaultCoreAssets: true, hasStablePools: true, }),
}
};

0 comments on commit 3564e48

Please sign in to comment.