Skip to content

Commit 0fcc469

Browse files
authored
Add Swap X (DefiLlama#12929)
1 parent 45b1fda commit 0fcc469

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

projects/SwapX-algebra/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { uniV3Export } = require("../helper/uniswapV3");
2+
3+
const SWAPX_ALGEBRA_FACTORY = "0x8121a3F8c4176E9765deEa0B95FA2BDfD3016794"
4+
5+
module.exports = uniV3Export({
6+
sonic: {
7+
factory: SWAPX_ALGEBRA_FACTORY,
8+
fromBlock: 1440914,
9+
isAlgebra: true
10+
}
11+
});

projects/SwapX-v2/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)