Skip to content

Commit 8ce1c3e

Browse files
authored
feat: integrate mosaic (DefiLlama#14269)
1 parent bb8e5a2 commit 8ce1c3e

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

projects/mosaic/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const { function_view } = require("../helper/chain/aptos");
2+
3+
// Constants
4+
const MOSAIC_AMM_PACKAGE =
5+
"0x26a95d4bd7d7fc3debf6469ff94837e03e887088bef3a3f2d08d1131141830d3";
6+
const GET_ALL_POOLS_FUNCTION = `${MOSAIC_AMM_PACKAGE}::liquidity_pool::all_pools`;
7+
const GET_POOL_VIEW_FUNCTION = `${MOSAIC_AMM_PACKAGE}::liquidity_pool::get_pool_view`;
8+
9+
/**
10+
* Retrieves all pool IDs from Mosaic AMM contract
11+
* @param {string} chain - The blockchain name
12+
* @returns {Promise<Array<string>>} - Array of pool IDs
13+
*/
14+
const getPoolIds = async chain => {
15+
const pools = await function_view({
16+
functionStr: GET_ALL_POOLS_FUNCTION,
17+
type_arguments: [],
18+
args: [],
19+
chain
20+
});
21+
22+
return pools.map(pool => pool.inner);
23+
};
24+
25+
/**
26+
* Fetches data for a specific pool
27+
* @param {string} poolId - Pool identifier
28+
* @param {string} chain - The blockchain name
29+
* @returns {Promise<Object>} - Pool data
30+
*/
31+
const getPoolData = async (poolId, chain) => {
32+
return await function_view({
33+
functionStr: GET_POOL_VIEW_FUNCTION,
34+
type_arguments: [],
35+
args: [poolId],
36+
chain
37+
});
38+
};
39+
40+
module.exports = {
41+
timetravel: false,
42+
methodology: "Aggregates TVL of Mosaic AMM.",
43+
move: {
44+
tvl: async api => {
45+
const poolIds = await getPoolIds(api.chain);
46+
47+
// Process pools in parallel for better performance
48+
const poolDataPromises = poolIds.map(id => getPoolData(id, api.chain));
49+
const poolsData = await Promise.all(poolDataPromises);
50+
51+
// Add token reserves to TVL
52+
poolsData.forEach(pool => {
53+
if (pool) {
54+
api.add(pool.token_x, pool.token_x_reserve);
55+
api.add(pool.token_y, pool.token_y_reserve);
56+
}
57+
});
58+
}
59+
}
60+
};

0 commit comments

Comments
 (0)