Skip to content

Commit 2f1c150

Browse files
Centure2222DEVNODEREACTg1nt0ki
authored
Update Cellana finance - Fix err text and add CELL token balances (DefiLlama#9190)
* add cellana aptos tvl * minor fix * Fix err text and add CELL token balance * minor refactor * lint fix --------- Co-authored-by: HS <[email protected]> Co-authored-by: g1nt0ki <[email protected]>
1 parent adf3a3c commit 2f1c150

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

projects/cellana/index.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
1-
const sdk = require("@defillama/sdk");
21
const { getResources, } = require("../helper/chain/aptos");
3-
const { transformBalances } = require("../helper/portedTokens");
4-
5-
let resourcesCache
2+
const ADDRESSES = require('../helper/coreAssets.json')
3+
const CELL_fungible_asset_address = '0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12'
4+
const APT_fungible_asset_address = '0xedc2704f2cef417a06d1756a04a16a9fa6faaed13af469be9cdfcac5a21a8e2e'
65

76
async function _getResources() {
7+
let resourcesCache;
88
if (!resourcesCache) resourcesCache = getResources("0x3b38735644d0be8ac37ebd84a1e42fa5c2487495ef8782f6c694b1a147f82426")
99
return resourcesCache
1010
}
11+
1112
const extractCoinAddress = (str) => str.slice(str.indexOf("<") + 1, str.lastIndexOf(">"));
1213
const reserveContrainerFilter = (i) => i.type.includes("0x1::coin::CoinStore")
1314

15+
async function _getCELLbalances(api) {
16+
const data = await getResources('0x4bf51972879e3b95c4781a5cdcb9e1ee24ef483e7d22f2d903626f126df62bd1')
17+
const poolsAddresses = data.find(i => i.type.includes('::liquidity_pool::LiquidityPoolConfigs'))?.data.all_pools?.inline_vec
18+
for (const pool of poolsAddresses) {
19+
const fungibleAssetPoolStore = (await getResources(pool.inner)).find(i => i.type.includes('liquidity_pool::LiquidityPool'))?.data
20+
const fungibleAssetAddressToken1 = fungibleAssetPoolStore?.token_store_1?.inner
21+
const fungibleAssetAddressToken2 = fungibleAssetPoolStore?.token_store_2?.inner
22+
23+
const fungibleAssetTokenStore_1 = (await getResources(fungibleAssetAddressToken1)).find(i => i.type.includes('fungible_asset::FungibleStore'))?.data
24+
const fungibleAssetTokenStore_2 = (await getResources(fungibleAssetAddressToken2)).find(i => i.type.includes('fungible_asset::FungibleStore'))?.data
25+
const token_1_address = fungibleAssetTokenStore_1?.metadata?.inner
26+
const token_2_address = fungibleAssetTokenStore_2?.metadata?.inner
27+
if (token_1_address == CELL_fungible_asset_address) {
28+
addBalance(token_2_address, fungibleAssetTokenStore_2?.balance || 0);
29+
} else if (token_2_address == CELL_fungible_asset_address) {
30+
addBalance(token_1_address, fungibleAssetTokenStore_1?.balance || 0);
31+
}
32+
}
33+
34+
async function addBalance(token, balance) {
35+
if (token === APT_fungible_asset_address)
36+
api.add(ADDRESSES.aptos.APT, balance)
37+
}
38+
}
39+
1440
module.exports = {
1541
timetravel: false,
1642
misrepresentedTokens: true,
1743
methodology:
18-
"Counts the lamports in each coin container in the Aries contract account.",
44+
"Counts the lamports in each coin container in the Cellena contract account.",
1945
aptos: {
20-
tvl: async () => {
21-
const balances = {};
46+
tvl: async (_, _1, _2, { api }) => {
2247
const data = await _getResources()
2348
const coinContainers = data.filter(reserveContrainerFilter)
2449
.map((i) => ({
@@ -27,11 +52,9 @@ module.exports = {
2752
}));
2853

2954
coinContainers.forEach(({ lamports, tokenAddress }) => {
30-
sdk.util.sumSingleBalance(balances, tokenAddress, lamports);
55+
api.add(tokenAddress, lamports);
3156
});
32-
33-
return transformBalances("aptos", balances);
34-
},
35-
36-
},
37-
};
57+
await _getCELLbalances(api)
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)