|
| 1 | +const { transformDexBalances } = require("../helper/portedTokens"); |
| 2 | +const { getLogs } = require("../helper/cache/getLogs"); |
| 3 | + |
| 4 | +const SWAPX_V2_FACTORY = "0x05c1be79d3aC21Cc4B727eeD58C9B2fF757F5663" |
| 5 | +const PAIR_CREATED_TOPIC_1 = "0xc4805696c66d7cf352fc1d6bb633ad5ee82f6cb577c453024b6e0eb8306c6fc9"; // keccak256 hash of the event signature |
| 6 | +const PAIR_CREATED_EVENT_ABI_1 = "event PairCreated(address indexed token0, address indexed token1, bool stable, address pair, uint)"; |
| 7 | +const fromBlock = 1333667; |
| 8 | +const erc20Abi = "erc20:balanceOf"; |
| 9 | + |
| 10 | +async function tvl(api) { |
| 11 | + const getPairs = (logs) => { |
| 12 | + return logs.map(log => ({ |
| 13 | + token0: log.token0, |
| 14 | + token1: log.token1, |
| 15 | + pair: log.pair |
| 16 | + })); |
| 17 | + } |
| 18 | + |
| 19 | + const logs = getPairs(await getLogs({ |
| 20 | + api, |
| 21 | + target: SWAPX_V2_FACTORY, |
| 22 | + fromBlock, |
| 23 | + topic: PAIR_CREATED_TOPIC_1, |
| 24 | + onlyArgs: true, |
| 25 | + eventAbi: PAIR_CREATED_EVENT_ABI_1 |
| 26 | + })); |
| 27 | + |
| 28 | + const tok0Bals = await api.multiCall({ abi: erc20Abi, calls: logs.map(log => ({ target: log.token0, params: log.pair })) }) |
| 29 | + const tok1Bals = await api.multiCall({ abi: erc20Abi, calls: logs.map(log => ({ target: log.token1, params: log.pair })) }) |
| 30 | + |
| 31 | + return transformDexBalances({ |
| 32 | + chain: api.chain, |
| 33 | + data: logs.map((log, i) => ({ |
| 34 | + token0: log.token0, |
| 35 | + token0Bal: tok0Bals[i], |
| 36 | + token1: log.token1, |
| 37 | + token1Bal: tok1Bals[i], |
| 38 | + })) |
| 39 | + }) |
| 40 | +} |
| 41 | + |
| 42 | +module.exports = { |
| 43 | + misrepresentedTokens: true, |
| 44 | + sonic: { |
| 45 | + tvl |
| 46 | + } |
| 47 | +}; |
0 commit comments