Getting Exchange Rate
Before you continue, please refer to Using the TypeScript SDKto learn how to use the SDK
After you have the SDK installed, please follow the example below which demonstrates how to get the pool token price and core pool data:
import { stakePoolInfo } from "@ignitionfi/spl-stake-pool"
import { Connection, PublicKey } from "@solana/web3.js"
const poolAddress = "PooLqqJBxaeCe7UXdsFZ7G5DqtNLCoAqj25sKGKWoCV"
const rpcUrl = "https://testnet.fogo.io/"
async function getPoolInfo() {
const connection = new Connection(rpcUrl)
const poolInfo = await stakePoolInfo(connection, new PublicKey(poolAddress))
const poolData = {
poolMint: poolInfo.poolMint,
totalPoolTokens: poolInfo.poolTokenSupply,
totalFogo: poolInfo.totalLamports,
reserveStakeLamports: poolInfo.details.reserveStakeLamports,
// iFOGO price (iFOGO / FOGO):
rate:
Number(poolInfo.poolTokenSupply) > 0
? Number(poolInfo.totalLamports) / Number(poolInfo.poolTokenSupply)
: 1,
}
console.log(poolData)
return poolData
}Output
The function returns an object with the following fields:
{
poolMint: '5VM3GV1V5G64ozKZLDEfpJCAPGrAMPzBzYENMsF2tmHU',
totalPoolTokens: '112374503160',
totalFogo: '121729227645',
reserveStakeLamports: 21730227645,
rate: 1.083245969699022,
}Last updated
