From fa5f45f4ce8bbf6b765a24ec56242d56f5987271 Mon Sep 17 00:00:00 2001 From: LidoKing <55234791+LidoKing@users.noreply.github.com> Date: Thu, 15 Aug 2024 11:18:33 +0800 Subject: [PATCH] add tvl from v2 program --- projects/nxfinance/index.js | 21 ++- .../nxfinance/{nx-idl.json => nx-idl-v1.json} | 0 projects/nxfinance/nx-idl-v2.json | 167 ++++++++++++++++++ 3 files changed, 182 insertions(+), 6 deletions(-) rename projects/nxfinance/{nx-idl.json => nx-idl-v1.json} (100%) create mode 100644 projects/nxfinance/nx-idl-v2.json diff --git a/projects/nxfinance/index.js b/projects/nxfinance/index.js index 98400c018acd..01d45f48f78a 100644 --- a/projects/nxfinance/index.js +++ b/projects/nxfinance/index.js @@ -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 = { diff --git a/projects/nxfinance/nx-idl.json b/projects/nxfinance/nx-idl-v1.json similarity index 100% rename from projects/nxfinance/nx-idl.json rename to projects/nxfinance/nx-idl-v1.json diff --git a/projects/nxfinance/nx-idl-v2.json b/projects/nxfinance/nx-idl-v2.json new file mode 100644 index 000000000000..deb4ab748646 --- /dev/null +++ b/projects/nxfinance/nx-idl-v2.json @@ -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" + } + ] + } + } + ] +} \ No newline at end of file