Skip to content

Commit

Permalink
add tvl from v2 program
Browse files Browse the repository at this point in the history
  • Loading branch information
LidoKing committed Aug 15, 2024
1 parent 96ed695 commit fa5f45f
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 6 deletions.
21 changes: 15 additions & 6 deletions projects/nxfinance/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
const { Program } = require("@project-serum/anchor");
const { getProvider, } = require("../helper/solana");
const nxIdl = require("./nx-idl.json");
const nxIdlV1 = require("./nx-idl-v1.json");
const nxIdlV2 = require("./nx-idl-v2.json");

const NX_PROGRAM_ADDR = "EHBN9YKtMmrZhj8JZqyBQRGqyyeHw5xUB1Q5eAHszuMt";
const NX_PROGRAM_ADDR_V1 = "EHBN9YKtMmrZhj8JZqyBQRGqyyeHw5xUB1Q5eAHszuMt";
const NX_PROGRAM_ADDR_V2 = "NXFiKimQN3QSL3CDhCXddyVmLfrai8HK36bHKaAzK7g";

async function tvl(api) {
const provider = getProvider();
const nx_program = new Program(nxIdl, NX_PROGRAM_ADDR, provider);
const accounts = await nx_program.account.marginPool.all()

for (let { account: pool } of accounts)
api.add(pool.tokenMint.toBase58(), pool.depositTokens.toString())
const nx_program_v1 = new Program(nxIdlV1, NX_PROGRAM_ADDR_V1, provider)
const nx_program_v2 = new Program(nxIdlV2, NX_PROGRAM_ADDR_V2, provider)
const res = await Promise.all([
nx_program_v1.account.marginPool.all(),
nx_program_v2.account.collateralPool.all(),
nx_program_v2.account.lendingPool.all()
])

for (let value of res)
for (let { account: pool } of value)
api.add(pool.tokenMint.toBase58(), pool.depositTokens.toString())
}

module.exports = {
Expand Down
File renamed without changes.
167 changes: 167 additions & 0 deletions projects/nxfinance/nx-idl-v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"version": "0.1.0",
"name": "nx_lend",
"instructions": [],
"accounts": [
{
"name": "CollateralPool",
"type": {
"kind": "struct",
"fields": [
{
"name": "nxMarket",
"docs": [
"Market's pubkey"
],
"type": "publicKey"
},
{
"name": "marketAuthority",
"docs": [
"The pool authority to act"
],
"type": "publicKey"
},
{
"name": "tokenMint",
"docs": [
"The token the pool allows lending and borrowing on"
],
"type": "publicKey"
},
{
"name": "depositTokens",
"docs": [
"The total amount of tokens available in the pool's vault"
],
"type": "u64"
},
{
"name": "depositNotes",
"docs": [
"The total amount of notes issued to depositors of tokens."
],
"type": "u64"
}
]
}
},
{
"name": "LendingPool",
"type": {
"kind": "struct",
"fields": [
{
"name": "nxMarket",
"docs": [
"Market's pubkey"
],
"type": "publicKey"
},
{
"name": "tokenMint",
"docs": [
"The pool authority to act",
"The token the pool allows lending and borrowing on"
],
"type": "publicKey"
},
{
"name": "borrowTokens",
"docs": [
"The total amount of tokens borrowed, that need to be repaid to",
"the pool."
],
"type": "u64"
},
{
"name": "borrowNotes",
"docs": [
"The total amount of notes issued to borrowers of tokens"
],
"type": "u64"
},
{
"name": "depositTokens",
"docs": [
"The total amount of tokens available in the pool's vault"
],
"type": "u64"
},
{
"name": "depositNotes",
"docs": [
"The total amount of notes issued to depositors of tokens."
],
"type": "u64"
},
{
"name": "depositInterest",
"type": "u64"
},
{
"name": "borrowInterest",
"docs": [
"Amount of unrepaid interest by borrowers, for loan note exchange rate calculation"
],
"type": "u64"
},
{
"name": "protocolFee",
"docs": [
"10% of interest goes to the protocol,"
],
"type": "u64"
},
{
"name": "accruedUntil",
"docs": [
"The time the interest was last accrued up to"
],
"type": "i64"
},
{
"name": "utilizationFlag",
"docs": [
"If the utilization rate is flagged as full"
],
"type": "u16"
},
{
"name": "interestRateConfigs",
"type": {
"vec": {
"defined": "InterestRateData"
}
}
}
]
}
}
],
"types": [
{
"name": "InterestRateData",
"type": {
"kind": "struct",
"fields": [
{
"name": "utilizationRate",
"docs": [
"y=kx+b x=utilization_rate y=interest_rate"
],
"type": "i32"
},
{
"name": "kValue",
"type": "i32"
},
{
"name": "bValue",
"type": "i32"
}
]
}
}
]
}

0 comments on commit fa5f45f

Please sign in to comment.