File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ const { getConfig } = require ( '../helper/cache' )
2
+ const { getProvider, sumTokens2 } = require ( '../helper/solana' )
3
+ const { Program } = require ( "@coral-xyz/anchor" ) ;
4
+
5
+ async function getData ( ) {
6
+ const LIQUIDITY_IDL_URL = "https://raw.githubusercontent.com/jup-ag/jupiter-lend/refs/heads/main/target/idl/liquidity.json" ;
7
+ const LIQUIDITY_PROGRAM_ID = "jupeiUmn818Jg1ekPURTpr4mFo29p46vygyykFJ3wZC" ;
8
+
9
+ const idl = await getConfig ( 'jupiter-lend' , LIQUIDITY_IDL_URL )
10
+ const provider = getProvider ( ) ;
11
+ idl . metadata . address = LIQUIDITY_PROGRAM_ID ;
12
+ const program = new Program ( idl , provider ) ;
13
+ return ( await program . account . tokenReserve . all ( ) ) . map ( i => i . account )
14
+ }
15
+
16
+ const EXCHANGE_PRICE_PRECISION = 1e12
17
+ async function tvl ( ) {
18
+ const tokenReserves = await getData ( ) ;
19
+ const tokenAccounts = tokenReserves . map ( i => i . vault . toBase58 ( ) )
20
+ return sumTokens2 ( { tokenAccounts } )
21
+ }
22
+ async function borrowed ( api ) {
23
+ const tokenReserves = await getData ( )
24
+ tokenReserves . forEach ( i => {
25
+ const totalBorrowed = ( + i . totalBorrowWithInterest . toString ( ) * + i . borrowExchangePrice . toString ( ) / EXCHANGE_PRICE_PRECISION ) + + i . totalBorrowInterestFree . toString ( )
26
+ api . add ( i . mint . toBase58 ( ) , totalBorrowed )
27
+ } )
28
+ }
29
+
30
+ module . exports = {
31
+ solana : { tvl, borrowed, } ,
32
+ }
You can’t perform that action at this time.
0 commit comments