Skip to content

Commit d5a0fe6

Browse files
authored
Merge pull request #25 from curvefi/feat/add-getLsdApy
feat: add getLsdApy
2 parents 0a3e970 + 151ac0f commit d5a0fe6

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curvefi/stablecoin-api",
3-
"version": "1.5.5",
3+
"version": "1.5.6",
44
"description": "JavaScript library for Curve Stablecoin",
55
"main": "lib/index.js",
66
"author": "Macket",

src/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { ethers } from "ethers";
22
import { Networkish } from "@ethersproject/networks";
33
import { LlammaTemplate, getLlamma } from "./llammas";
44
import { crvusd as _crvusd } from "./crvusd";
5-
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, totalSupply } from "./utils";
5+
import {
6+
getBalances,
7+
getAllowance,
8+
hasAllowance,
9+
ensureAllowanceEstimateGas,
10+
ensureAllowance,
11+
getUsdRate,
12+
totalSupply,
13+
getLsdApy,
14+
} from "./utils";
615

716

817
async function init (
@@ -34,6 +43,7 @@ const crvusd = {
3443
ensureAllowance,
3544
getUsdRate,
3645
totalSupply,
46+
getLsdApy,
3747
getLlammaList: _crvusd.getLlammaList,
3848
estimateGas: {
3949
ensureAllowance: ensureAllowanceEstimateGas,

src/utils.ts

+46-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import BigNumber from 'bignumber.js';
44
import { IDict } from "./interfaces";
55
import { _getPoolsFromApi } from "./external-api";
66
import { crvusd } from "./crvusd";
7+
import memoize from "memoizee";
78

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

290291
return { total: mintedBN.plus(pegKeepersBN).toString(), minted: mintedBN.toString(), pegKeepersDebt: pegKeepersBN.toString() };
291-
}
292+
}
293+
294+
export const getLsdApy = memoize(async(name: 'wstETH' | 'sfrxETH'): Promise<{
295+
apy: number,
296+
baseApy: number,
297+
apyMean30d: number,
298+
}> => {
299+
const response = await axios.get('https://yields.llama.fi/pools');
300+
const {data} = response.data;
301+
302+
const params = {
303+
'wstETH': {
304+
project: 'lido',
305+
symbol: 'STETH',
306+
},
307+
'sfrxETH': {
308+
project: 'frax-ether',
309+
symbol: 'SFRXETH',
310+
},
311+
}
312+
313+
const result = data.find(({
314+
chain,
315+
project,
316+
symbol,
317+
}: any) => (
318+
chain === 'Ethereum' &&
319+
project === params[name].project &&
320+
symbol === params[name].symbol
321+
));
322+
323+
if(result) {
324+
return {
325+
apy: result.apy,
326+
baseApy: result.apyBase,
327+
apyMean30d: result.apyMean30d,
328+
};
329+
}
330+
331+
throw new Error('Pool not found')
332+
},
333+
{
334+
promise: true,
335+
maxAge: 60 * 1000, // 1m
336+
});

0 commit comments

Comments
 (0)