nx-finance
v0.3.2
Published
### Example ```ts import { PublicKey } from '@solana/web3.js' import * as dotenv from 'dotenv' import { NXProgramV1, NXProgramV2 } from "nx-finance";
Downloads
308
Readme
NX Finance
Example
import { PublicKey } from '@solana/web3.js'
import * as dotenv from 'dotenv'
import { NXProgramV1, NXProgramV2 } from "nx-finance";
const rpc = process.env.RPC_URL
const user = new PublicKey('USER_ADDRESS')
// fetch v1 pool info
const programV1 = new NXProgramV1(rpc)
const v1_pools = await programV1.fetchAllLendingPool()
console.log(`v1 lending pool: ${v1_pools}`)
// fetch v1 lending position info for user
try {
const lendingPositionInfo = await programV1.fetchLendingPositionByOwner(user, v1_pools)
console.log(`v1 lending position info of user: ${lendingPositionInfo}`)
} catch (error) {
console.error(error)
}
// fetch v1 leverage position info for user
try {
const leveragePositionInfo = await programV1.fetchLeveragePositionByOwner(user, v1_pools)
console.log(`v1 leverage position info of user: ${leveragePositionInfo}`)
} catch (error) {
console.error(error)
}
// fetch v2 pool info
const programV2 = new NXProgramV2(rpc)
const v2_pools = await programV1.fetchAllLendingPool()
console.log(`v2 lending pool: ${v2_pools}`)
// fetch v2 lending position info for user
try {
const lendingPositionInfo = await programV2.fetchLendingPositionByOwner(user, v2_pools)
console.log(`v2 lending position info of user: ${lendingPositionInfo}`)
} catch (error) {
console.error(error)
}
// fetch v2 the Vault leverage position info for user
try {
const leveragePositionInfo = await programV2.fetchVSolStrategyByOwner(user, v2_pools)
console.log(`v2 the Vault leverage position info of user: ${leveragePositionInfo}`)
} catch (error) {
console.error(error)
}
// fetch v2 Solayer leverage position info for user
try {
const pubPosition = await program.fetchPubPositionByOwner(user, v2_pools)
const stakeAccountInfo = await program.fetchAllStakeAccountInfo()
const SolayerStrategy = await program.fetchSolayerStrategyByOwner(user, pubPosition, stakeAccountInfo)
console.log(`v2 solayer leverage position info of user:\n`, JSON.stringify(SolayerStrategy, null, 2))
} catch (error) {
console.error(error)
}