Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions projects/evo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const { invokeViewFunction } = require("../helper/chain/supra");

// Constants
const EVO_CLMM_PACKAGE =
"0x3a56a0fcb8f23212fe880485c206dd03e08011ae88f02dbf9d0842be99eeac4b";
const GET_ALL_POOLS_FUNCTION = `${EVO_CLMM_PACKAGE}::evo_clamm_liquidity_pool::get_all_pools`;
const GET_POOL_VIEW_FUNCTION = `${EVO_CLMM_PACKAGE}::evo_clamm_liquidity_pool::get_pool_view`;

/**
* Retrieves all pool IDs from EVO CLMM contract
* @param {string} chain - The blockchain name
* @returns {Promise<Array<string>>} - Array of pool IDs
*/
const getPoolIds = async chain => {
try {
const pools = await invokeViewFunction(
GET_ALL_POOLS_FUNCTION,
[],
[]
);
return pools[0].map(pool => pool.inner);
} catch (error) {
console.error(`Error fetching pool IDs: ${error.message}`);
return [];
}
};

/**
* Fetches data for a specific pool
* @param {string} poolId - Pool identifier
* @param {string} chain - The blockchain name
* @returns {Promise<Object|null>} - Pool data or null if error
*/
const getPoolData = async (poolId, chain) => {
try {
const result = await invokeViewFunction(
GET_POOL_VIEW_FUNCTION,
[],
[poolId]
);
return result[0];
} catch (error) {
console.error(`Error fetching data for pool ${poolId}: ${error.message}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please no try catch and please remove any console logs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I get that, they were left on purpose as instructed on Discord. Would you already have FA support so I can run the test again on my end and confirm TVL is showing correctly?

Will remove the try and console lgos as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link me to the message? What is FA? You can test using node test.js <path to adapter>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversation we had on Discord is linked within the original PR under Important information. It also states what the "issue" is with the adapter and why it is posted like that.

Supra is a Aptos-based blockchain, where there are multiple type of assets. In the above mentioned section, the "coreAssets.json" which is likely used to compute prices is only supporting the "Legacy" version of Supra (chain's base currency); The DEX is using the "Fungible Asset" version.

I was also aware of the test command, since that is also mentioned within my section and what the result/issue is.

Useful links:
Supra Fungible Asset
Aptos Legacy Coin
Aptos Fungible Asset

return null;
}
};

module.exports = {
timetravel: false,
methodology: "Aggregates TVL in all pools in EVO CLMM.",
supra: {
tvl: async api => {
const poolIds = await getPoolIds(api.chain);
console.log("poolIds: ", poolIds)
// Process pools in parallel for better performance
const poolDataPromises = poolIds.map(id => getPoolData(id, api.chain));
const poolsData = await Promise.all(poolDataPromises);

console.log("poolsData: ", poolsData)

// Add token reserves to TVL
poolsData.forEach(pool => {
if (pool) {
console.log('Adding token:', pool.token_0, 'with reserve:', pool.token_0_reserve);
api.add(pool.token_0, pool.token_0_reserve);
console.log('Adding token:', pool.token_1, 'with reserve:', pool.token_1_reserve);
api.add(pool.token_1, pool.token_1_reserve);
}
});

console.log('Final balances:', api.getBalances());
}
}
};
Loading