Skip to content

Commit 9ffdf54

Browse files
committed
add: add partial support for EVO DEX on supra
1 parent be3ffc9 commit 9ffdf54

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

projects/evo/index.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const { invokeViewFunction } = require("../helper/chain/supra");
2+
3+
// Constants
4+
const EVO_CLMM_PACKAGE =
5+
"0x3a56a0fcb8f23212fe880485c206dd03e08011ae88f02dbf9d0842be99eeac4b";
6+
const GET_ALL_POOLS_FUNCTION = `${EVO_CLMM_PACKAGE}::evo_clamm_liquidity_pool::get_all_pools`;
7+
const GET_POOL_VIEW_FUNCTION = `${EVO_CLMM_PACKAGE}::evo_clamm_liquidity_pool::get_pool_view`;
8+
9+
/**
10+
* Retrieves all pool IDs from EVO CLMM contract
11+
* @param {string} chain - The blockchain name
12+
* @returns {Promise<Array<string>>} - Array of pool IDs
13+
*/
14+
const getPoolIds = async chain => {
15+
try {
16+
const pools = await invokeViewFunction(
17+
GET_ALL_POOLS_FUNCTION,
18+
[],
19+
[]
20+
);
21+
return pools[0].map(pool => pool.inner);
22+
} catch (error) {
23+
console.error(`Error fetching pool IDs: ${error.message}`);
24+
return [];
25+
}
26+
};
27+
28+
/**
29+
* Fetches data for a specific pool
30+
* @param {string} poolId - Pool identifier
31+
* @param {string} chain - The blockchain name
32+
* @returns {Promise<Object|null>} - Pool data or null if error
33+
*/
34+
const getPoolData = async (poolId, chain) => {
35+
try {
36+
const result = await invokeViewFunction(
37+
GET_POOL_VIEW_FUNCTION,
38+
[],
39+
[poolId]
40+
);
41+
return result[0];
42+
} catch (error) {
43+
console.error(`Error fetching data for pool ${poolId}: ${error.message}`);
44+
return null;
45+
}
46+
};
47+
48+
module.exports = {
49+
timetravel: false,
50+
methodology: "Aggregates TVL in all pools in EVO CLMM.",
51+
supra: {
52+
tvl: async api => {
53+
const poolIds = await getPoolIds(api.chain);
54+
console.log("poolIds: ", poolIds)
55+
// Process pools in parallel for better performance
56+
const poolDataPromises = poolIds.map(id => getPoolData(id, api.chain));
57+
const poolsData = await Promise.all(poolDataPromises);
58+
59+
console.log("poolsData: ", poolsData)
60+
61+
// Add token reserves to TVL
62+
poolsData.forEach(pool => {
63+
if (pool) {
64+
console.log('Adding token:', pool.token_0, 'with reserve:', pool.token_0_reserve);
65+
api.add(pool.token_0, pool.token_0_reserve);
66+
console.log('Adding token:', pool.token_1, 'with reserve:', pool.token_1_reserve);
67+
api.add(pool.token_1, pool.token_1_reserve);
68+
}
69+
});
70+
71+
console.log('Final balances:', api.getBalances());
72+
}
73+
}
74+
};

0 commit comments

Comments
 (0)