File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
projects/interest-protocol-stable-swap Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ const sui = require ( "../helper/chain/sui" )
2
+
3
+ const PACKAGE_ID = '0x50052aca3d7b971bd9824e1bb151748d03870adfe3ba06dce384d2a77297c719' ;
4
+
5
+ const POW_9 = 1_000_000_000n ;
6
+
7
+ function normalizeAddress (
8
+ value ,
9
+ forceAdd0x = true ,
10
+ ) {
11
+ let address = value . toLowerCase ( ) ;
12
+ if ( ! forceAdd0x && address . startsWith ( '0x' ) ) {
13
+ address = address . slice ( 2 ) ;
14
+ }
15
+ return `0x${ address . padStart ( 32 * 2 , '0' ) } ` ;
16
+ }
17
+
18
+ const tvl = async ( api ) => {
19
+ const newPoolEvents = await sui . queryEvents ( {
20
+ eventType : `${ PACKAGE_ID } ::event_wrapper::InterestStableSwapEvent<${ PACKAGE_ID } ::events::NewPool>`
21
+ } ) ;
22
+
23
+ const statesIds = newPoolEvents . map (
24
+ ( event ) => event . pos0 . state
25
+ ) ;
26
+
27
+ const states = await sui . getObjects ( statesIds ) ;
28
+
29
+ states . forEach ( ( state ) => {
30
+ state . fields . coins . forEach ( ( typeName , index ) => {
31
+ const [ package , module , otw ] = typeName . fields . name . split ( '::' )
32
+ api . add ( `${ normalizeAddress ( package ) } ::${ module } ::${ otw } ` , BigInt ( state . fields . balances [ index ] ) / POW_9 ) ;
33
+ } ) ;
34
+ } ) ;
35
+ }
36
+
37
+ module . exports = {
38
+ timetravel : false ,
39
+ sui : {
40
+ tvl,
41
+ } ,
42
+ }
You can’t perform that action at this time.
0 commit comments