Skip to content

Commit

Permalink
Add method to calculate pool APY
Browse files Browse the repository at this point in the history
  • Loading branch information
julianfssen committed Oct 16, 2024
1 parent 42bf625 commit 2437345
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ const JUPITER_PERPETUALS_PROGRAM = new PublicKey(
"PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu",
);

async function getCustodyAssets() {
try {
const connection = new Connection("https://api.mainnet-beta.solana.com");
const JLP_POOL_ACCOUNT = new PublicKey(
"5BUwFW4nRbftYTDMbgxykoFWqWHPzahFSNAaaaJtVKsq",
);

const program = new Program<Perpetuals>(
IDL,
JUPITER_PERPETUALS_PROGRAM,
new AnchorProvider(
connection,
new Wallet(Keypair.generate()),
AnchorProvider.defaultOptions(),
),
);
const connection = new Connection("https://api.mainnet-beta.solana.com");

const program = new Program<Perpetuals>(
IDL,
JUPITER_PERPETUALS_PROGRAM,
new AnchorProvider(
connection,
new Wallet(Keypair.generate()),
AnchorProvider.defaultOptions(),
),
);

async function getCustodyAssets() {
try {
const solCustody = await program.account.custody.fetch(
new PublicKey("7xS2gz2bTp3fwCC7knJvUWTEU9Tycczu6VhJYKgi1wdz"),
);
Expand Down Expand Up @@ -150,5 +154,15 @@ async function getEvents() {
);
}

getCustodyAssets();
getEvents();
async function getPoolApy() {
const pool = await program.account.pool.fetch(JLP_POOL_ACCOUNT);

const poolApr = pool.poolApr.feeAprBps.toNumber() / 100;

const compoundToAPY = (apr: number, frequency = 365) => {
const apy = (Math.pow(apr / 100 / frequency + 1, frequency) - 1) * 100;
return apy;
};

console.log("Pool APY (%):", compoundToAPY(poolApr));
}

0 comments on commit 2437345

Please sign in to comment.