Skip to content

Commit

Permalink
feat: add getLsdApy
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorovdg committed Aug 15, 2024
1 parent 578cb6c commit 3a2f7df
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { ethers } from "ethers";
import { Networkish } from "@ethersproject/networks";
import { LlammaTemplate, getLlamma } from "./llammas";
import { crvusd as _crvusd } from "./crvusd";
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, totalSupply } from "./utils";
import {
getBalances,
getAllowance,
hasAllowance,
ensureAllowanceEstimateGas,
ensureAllowance,
getUsdRate,
totalSupply,
getLsdApy,
} from "./utils";


async function init (
Expand Down Expand Up @@ -34,6 +43,7 @@ const crvusd = {
ensureAllowance,
getUsdRate,
totalSupply,
getLsdApy,
getLlammaList: _crvusd.getLlammaList,
estimateGas: {
ensureAllowance: ensureAllowanceEstimateGas,
Expand Down
45 changes: 44 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BigNumber from 'bignumber.js';
import { IDict } from "./interfaces";
import { _getPoolsFromApi } from "./external-api";
import { crvusd } from "./crvusd";
import memoize from "memoizee";

export const MAX_ALLOWANCE = ethers.BigNumber.from(2).pow(ethers.BigNumber.from(256)).sub(ethers.BigNumber.from(1));
export const MAX_ACTIVE_BAND = ethers.BigNumber.from(2).pow(ethers.BigNumber.from(255)).sub(ethers.BigNumber.from(1));
Expand Down Expand Up @@ -288,4 +289,46 @@ export const totalSupply = async (): Promise<{ total: string, minted: string, pe
}

return { total: mintedBN.plus(pegKeepersBN).toString(), minted: mintedBN.toString(), pegKeepersDebt: pegKeepersBN.toString() };
}
}

export const getLsdApy = memoize(async(name: 'wstETH' | 'sfrxETH'): Promise<{
apy: number,
baseApy: number,
}> => {
const response = await axios.get('https://yields.llama.fi/pools');
const {data} = response.data;

const params = {
'wstETH': {
project: 'lido',
symbol: 'STETH',
},
'sfrxETH': {
project: 'frax-ether',
symbol: 'SFRXETH',
},
}

const result = data.find(({
chain,
project,
symbol,
}: any) => (
chain === 'Ethereum' &&
project === params[name].project &&
symbol === params[name].symbol
));

if(result) {
return {
apy: result.apy,
baseApy: result.apyBase,
};
}

throw new Error('Pool not found')
},
{
promise: true,
maxAge: 60 * 1000, // 1m
});

0 comments on commit 3a2f7df

Please sign in to comment.