Skip to content

Commit

Permalink
Merge pull request #25 from curvefi/feat/add-getLsdApy
Browse files Browse the repository at this point in the history
feat: add getLsdApy
  • Loading branch information
fedorovdg committed Aug 15, 2024
2 parents 0a3e970 + 151ac0f commit d5a0fe6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/stablecoin-api",
"version": "1.5.5",
"version": "1.5.6",
"description": "JavaScript library for Curve Stablecoin",
"main": "lib/index.js",
"author": "Macket",
Expand Down
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
47 changes: 46 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,48 @@ 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,
apyMean30d: 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,
apyMean30d: result.apyMean30d,
};
}

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

0 comments on commit d5a0fe6

Please sign in to comment.