1
- const sdk = require ( "@defillama/sdk" ) ;
2
1
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'
6
5
7
6
async function _getResources ( ) {
7
+ let resourcesCache ;
8
8
if ( ! resourcesCache ) resourcesCache = getResources ( "0x3b38735644d0be8ac37ebd84a1e42fa5c2487495ef8782f6c694b1a147f82426" )
9
9
return resourcesCache
10
10
}
11
+
11
12
const extractCoinAddress = ( str ) => str . slice ( str . indexOf ( "<" ) + 1 , str . lastIndexOf ( ">" ) ) ;
12
13
const reserveContrainerFilter = ( i ) => i . type . includes ( "0x1::coin::CoinStore" )
13
14
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
+
14
40
module . exports = {
15
41
timetravel : false ,
16
42
misrepresentedTokens : true ,
17
43
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." ,
19
45
aptos : {
20
- tvl : async ( ) => {
21
- const balances = { } ;
46
+ tvl : async ( _ , _1 , _2 , { api } ) => {
22
47
const data = await _getResources ( )
23
48
const coinContainers = data . filter ( reserveContrainerFilter )
24
49
. map ( ( i ) => ( {
@@ -27,11 +52,9 @@ module.exports = {
27
52
} ) ) ;
28
53
29
54
coinContainers . forEach ( ( { lamports, tokenAddress } ) => {
30
- sdk . util . sumSingleBalance ( balances , tokenAddress , lamports ) ;
55
+ api . add ( tokenAddress , lamports ) ;
31
56
} ) ;
32
-
33
- return transformBalances ( "aptos" , balances ) ;
34
- } ,
35
-
36
- } ,
37
- } ;
57
+ await _getCELLbalances ( api )
58
+ }
59
+ }
60
+ }
0 commit comments