Skip to content

Commit b0919d3

Browse files
committed
track jupiter lend
1 parent 7621670 commit b0919d3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

projects/jupiter-lend/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)