From 3a2f7dfd95135cdd2fc0988194759cf1554cc180 Mon Sep 17 00:00:00 2001 From: fedorovdg Date: Thu, 15 Aug 2024 20:46:44 +0300 Subject: [PATCH 1/2] feat: add getLsdApy --- src/index.ts | 12 +++++++++++- src/utils.ts | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index f56fa5c..59bf7c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 ( @@ -34,6 +43,7 @@ const crvusd = { ensureAllowance, getUsdRate, totalSupply, + getLsdApy, getLlammaList: _crvusd.getLlammaList, estimateGas: { ensureAllowance: ensureAllowanceEstimateGas, diff --git a/src/utils.ts b/src/utils.ts index f86f8fa..3b0dd1a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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)); @@ -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() }; -} \ No newline at end of file +} + +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 +}); \ No newline at end of file From 151ac0f3c8a18437b23f09f9da4704dd1008146a Mon Sep 17 00:00:00 2001 From: fedorovdg Date: Thu, 15 Aug 2024 20:47:49 +0300 Subject: [PATCH 2/2] build: v1.5.6 --- package.json | 2 +- src/utils.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e55f9bf..3dc3d85 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/utils.ts b/src/utils.ts index 3b0dd1a..65b4c40 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -292,8 +292,9 @@ export const totalSupply = async (): Promise<{ total: string, minted: string, pe } export const getLsdApy = memoize(async(name: 'wstETH' | 'sfrxETH'): Promise<{ - apy: number, - baseApy: number, + apy: number, + baseApy: number, + apyMean30d: number, }> => { const response = await axios.get('https://yields.llama.fi/pools'); const {data} = response.data; @@ -323,6 +324,7 @@ export const getLsdApy = memoize(async(name: 'wstETH' | 'sfrxETH'): Promise<{ return { apy: result.apy, baseApy: result.apyBase, + apyMean30d: result.apyMean30d, }; }