11const ADDRESSES = require ( '../helper/coreAssets.json' )
22const sui = require ( "../helper/chain/sui" ) ;
33
4- const SUILEND_LENDING_MARKET_ID = "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1" ;
54const LST_CREATE_EVENT_TYPE = '0xb0575765166030556a6eafd3b1b970eba8183ff748860680245b9edd41c716e7::events::Event<0xb0575765166030556a6eafd3b1b970eba8183ff748860680245b9edd41c716e7::liquid_staking::CreateEvent>' ;
65const SUI_COIN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
76const SPRINGSUI_COIN_TYPE = '0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI' ;
7+ const REGISTRY_PARENT_ID = '0xdc00dfa5ea142a50f6809751ba8dcf84ae5c60ca5f383e51b3438c9f6d72a86e' ;
8+ const BLACKLISTED_LENDING_MARKET_IDS = [
9+ "0x6d9478307d1cb8417470bec42e38000422b448e9638d6b43b821301179ac8caf" , // STEAMM LM (old)
10+ "0x8742d26532a245955630ff230b0d4b14aff575a0f3261efe50f571f84c4e4773" , // Test 1
11+ "0x8843ed2e29bd36683c7c99bf7e529fcee124a175388ad4b9886b48f1009e6285" , // Test 2
12+ "0x02b4b27b3aa136405c2aaa8e2e08191670f3971d495bfcd2dda17184895c20ad" , // Test 3
13+ ] ;
814
9- async function tvl ( api ) {
10- const redemptionRates = await getRedemtionRates ( )
11- const object = await sui . getObject ( SUILEND_LENDING_MARKET_ID )
1215
13- for ( const reserve of object . fields . reserves ) {
14- const coinType = '0x' + reserve . fields . coin_type . fields . name ;
15- if ( redemptionRates [ coinType ] ) {
16- api . add ( SUI_COIN_TYPE , redemptionRates [ coinType ] * reserve . fields . available_amount )
17- } else {
18- api . add ( coinType , reserve . fields . available_amount )
16+ async function tvl ( api ) {
17+ const lendingMarketIds = await getLendingMarketIds ( )
18+ const redemptionRates = await getRedemptionRates ( )
19+ for ( const lendingMarketId of lendingMarketIds ) {
20+ const object = await sui . getObject ( lendingMarketId )
21+ for ( const reserve of object . fields . reserves ) {
22+ 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 {
26+ api . add ( coinType , reserve . fields . available_amount )
27+ }
1928 }
2029 }
2130}
2231
2332async function borrowed ( api ) {
24- const redemptionRates = await getRedemtionRates ( )
25- const object = await sui . getObject ( SUILEND_LENDING_MARKET_ID )
26- for ( const reserve of object . fields . reserves ) {
27- const coinType = '0x' + reserve . fields . coin_type . fields . name ;
28- if ( redemptionRates [ coinType ] ) {
29- api . add ( SUI_COIN_TYPE , redemptionRates [ coinType ] * reserve . fields . borrowed_amount . fields . value / 1e18 )
30- } else {
31- api . add ( coinType , reserve . fields . borrowed_amount . fields . value / 1e18 )
33+ const lendingMarketIds = await getLendingMarketIds ( )
34+ const redemptionRates = await getRedemptionRates ( )
35+ for ( const lendingMarketId of lendingMarketIds ) {
36+ const object = await sui . getObject ( lendingMarketId )
37+ for ( const reserve of object . fields . reserves ) {
38+ 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 {
42+ api . add ( coinType , reserve . fields . borrowed_amount . fields . value / 1e18 )
43+ }
3244 }
3345 }
3446}
3547
3648
37- async function getRedemtionRates ( ) {
49+ async function getRedemptionRates ( ) {
3850 const events = ( await sui . queryEvents ( {
3951 eventType : LST_CREATE_EVENT_TYPE ,
4052 } ) )
@@ -46,18 +58,28 @@ async function getRedemtionRates() {
4658 }
4759 try {
4860 const poolId = event . event . liquid_staking_info_id ;
49- const data = await sui . getObject ( poolId )
50- const totalSupply = parseInt ( data . fields . lst_treasury_cap . fields . total_supply . fields . value )
61+ const data = await sui . getObject ( poolId ) ;
62+ const totalSupply = parseInt ( data . fields . lst_treasury_cap . fields . total_supply . fields . value ) ;
5163 const stakedSui = parseInt ( data . fields . storage . fields . total_sui_supply ) ;
5264 coinTypeToRate [ coinType ] = stakedSui / totalSupply ;
53- } catch ( e ) {
54- continue
65+ } catch ( e ) {
66+ continue ;
5567 }
5668 }
5769 return coinTypeToRate ;
5870}
5971
60-
72+ async function getLendingMarketIds ( ) {
73+ const dynamicFields = await sui . getDynamicFieldObjects ( { parent : REGISTRY_PARENT_ID } ) ;
74+ const ids = [ ] ;
75+ for ( const field of dynamicFields ) {
76+ const lendingMarketId = field . fields . value ;
77+ if ( ! BLACKLISTED_LENDING_MARKET_IDS . includes ( lendingMarketId ) ) {
78+ ids . push ( lendingMarketId ) ;
79+ }
80+ }
81+ return ids ;
82+ }
6183
6284module . exports = {
6385 timetravel : false ,
0 commit comments