1- const ADDRESSES = require ( '../helper/coreAssets.json' )
21const sui = require ( "../helper/chain/sui" ) ;
3-
4- const LST_CREATE_EVENT_TYPE = '0xb0575765166030556a6eafd3b1b970eba8183ff748860680245b9edd41c716e7::events::Event<0xb0575765166030556a6eafd3b1b970eba8183ff748860680245b9edd41c716e7::liquid_staking::CreateEvent>' ;
5- const SUI_COIN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
6- const SPRINGSUI_COIN_TYPE = '0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI' ;
2+
73const REGISTRY_PARENT_ID = '0xdc00dfa5ea142a50f6809751ba8dcf84ae5c60ca5f383e51b3438c9f6d72a86e' ;
84const BLACKLISTED_LENDING_MARKET_IDS = [
95 "0x6d9478307d1cb8417470bec42e38000422b448e9638d6b43b821301179ac8caf" , // STEAMM LM (old)
@@ -12,61 +8,28 @@ const BLACKLISTED_LENDING_MARKET_IDS = [
128 "0x02b4b27b3aa136405c2aaa8e2e08191670f3971d495bfcd2dda17184895c20ad" , // Test 3
139] ;
1410
11+ const isBlacklistedToken = coin => coin . includes ( 'STEAMM_LP' )
1512
16- async function tvl ( api ) {
13+ async function tvl ( api ) {
1714 const lendingMarketIds = await getLendingMarketIds ( )
18- const redemptionRates = await getRedemptionRates ( )
19- for ( const lendingMarketId of lendingMarketIds ) {
20- const object = await sui . getObject ( lendingMarketId )
15+ for ( const object of lendingMarketIds ) {
2116 for ( const reserve of object . fields . reserves ) {
2217 const coinType = '0x' + reserve . fields . coin_type . fields . name ;
23- if ( redemptionRates [ coinType ] ) {
24- api . add ( SUI_COIN_TYPE , redemptionRates [ coinType ] * reserve . fields . available_amount )
25- } else {
18+ if ( ! isBlacklistedToken ( coinType ) )
2619 api . add ( coinType , reserve . fields . available_amount )
27- }
2820 }
2921 }
3022}
3123
3224async function borrowed ( api ) {
3325 const lendingMarketIds = await getLendingMarketIds ( )
34- const redemptionRates = await getRedemptionRates ( )
35- for ( const lendingMarketId of lendingMarketIds ) {
36- const object = await sui . getObject ( lendingMarketId )
26+ for ( const object of lendingMarketIds ) {
3727 for ( const reserve of object . fields . reserves ) {
3828 const coinType = '0x' + reserve . fields . coin_type . fields . name ;
39- if ( redemptionRates [ coinType ] ) {
40- api . add ( SUI_COIN_TYPE , redemptionRates [ coinType ] * reserve . fields . borrowed_amount . fields . value / 1e18 )
41- } else {
29+ if ( ! isBlacklistedToken ( coinType ) )
4230 api . add ( coinType , reserve . fields . borrowed_amount . fields . value / 1e18 )
43- }
44- }
45- }
46- }
47-
48-
49- async function getRedemptionRates ( ) {
50- const events = ( await sui . queryEvents ( {
51- eventType : LST_CREATE_EVENT_TYPE ,
52- } ) )
53- const coinTypeToRate = { } ;
54- for ( const event of events ) {
55- const coinType = '0x' + event . event . typename . name ;
56- if ( coinType === SPRINGSUI_COIN_TYPE ) {
57- continue ;
58- }
59- try {
60- const poolId = event . event . liquid_staking_info_id ;
61- const data = await sui . getObject ( poolId ) ;
62- const totalSupply = parseInt ( data . fields . lst_treasury_cap . fields . total_supply . fields . value ) ;
63- const stakedSui = parseInt ( data . fields . storage . fields . total_sui_supply ) ;
64- coinTypeToRate [ coinType ] = stakedSui / totalSupply ;
65- } catch ( e ) {
66- continue ;
6731 }
6832 }
69- return coinTypeToRate ;
7033}
7134
7235async function getLendingMarketIds ( ) {
@@ -78,13 +41,13 @@ async function getLendingMarketIds() {
7841 ids . push ( lendingMarketId ) ;
7942 }
8043 }
81- return ids ;
44+ return sui . getObjects ( ids ) ;
8245}
8346
8447module . exports = {
8548 timetravel : false ,
8649 sui : {
87- tvl : tvl ,
88- borrowed : borrowed ,
50+ tvl,
51+ borrowed,
8952 } ,
9053}
0 commit comments