Skip to content

Commit

Permalink
feat: remove sdk-gov
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-98 committed Dec 24, 2024
1 parent 44b385e commit bb3481a
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 396 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@gearbox-protocol/sdk-gov": "^2.32.0",
"axios": "^1.7.9",
"cors": "^2.8.5",
"dotenv": "^16.4.7",
Expand Down
104 changes: 75 additions & 29 deletions src/apy/curveAPY.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import {
curveTokens,
NetworkType,
PartialRecord,
PERCENTAGE_FACTOR,
SupportedToken,
tokenDataByNetwork,
TypedObjectUtils,
CHAINS,
APYResult, ApyDetails, getTokenAPY, NetworkType,
NOT_DEPLOYED,
} from "@gearbox-protocol/sdk-gov";
import { APYResult, ApyDetails, getTokenAPY } from "./type";
import { CurveLPToken } from "@gearbox-protocol/sdk-gov/lib/tokens/curveLP";
import { GearboxToken } from "@gearbox-protocol/sdk-gov/lib/tokens/gear";
} from "./type";
import { TokenStore } from "./token_store";
import axios from "axios";
import { Address } from "viem";

Expand Down Expand Up @@ -86,15 +77,14 @@ interface CurvePoolDataResponse {
type PoolRecord = Record<string, CurvePoolData>;
type VolumeRecord = Record<string, VolumesResponse["data"]["pools"][number]>;

type CurveAPYTokens = CurveLPToken | GearboxToken;

const GEAR_POOL = "0x5Be6C45e2d074fAa20700C49aDA3E88a1cc0025d".toLowerCase();

const CURVE_CHAINS: Record<NetworkType, string> = {
Arbitrum: "arbitrum",
Mainnet: "ethereum",
Optimism: "optimism",
Base: "base",
// Base: "base",
};

// const CRYPTO = "https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/crypto";
Expand All @@ -116,8 +106,7 @@ const getFactoryStableNgURL = (n: NetworkType) =>
`https://api.curve.fi/api/getPools/${CURVE_CHAINS[n]}/factory-stable-ng`;


export async function getCurveAPY(network: NetworkType): Promise<APYResult> {
const currentTokens = tokenDataByNetwork[network];
export async function getCurveAPY(network: NetworkType, store: TokenStore): Promise<APYResult> {
const { mainnetVolumes, mainnetFactoryPools, volumes, pools } =
await getCurvePools(network);

Expand All @@ -133,20 +122,30 @@ export async function getCurveAPY(network: NetworkType): Promise<APYResult> {
const { poolData = [] } = poolCategory?.data?.data || {};

poolData.forEach(p => {
acc[p.lpTokenAddress.toLowerCase()] = p;
// if (p.lpTokenAddress.toLowerCase() == "0xed4064f376cb8d68f770fb1ff088a3d0f3ff5c4d") {
// console.log(p)
// }
if (!p.symbol || p.usdTotal == 0) {
return;
}
let sym = p.symbol.toLowerCase();
acc[sym] = p;
if (sym.endsWith("-f")) {
acc[sym.slice(0, -2)] = p;
}
});

return acc;
}, {});

let curveAPY = TypedObjectUtils.entries(curveTokens).reduce<APYResult>(
(acc, [curveSymbol]) => {
const address = (currentTokens?.[curveSymbol] || "").toLowerCase();
if (address == NOT_DEPLOYED) {
let crv = store.getBysymbol(network, "CRV");
let curveAPY = curveTokens.reduce<APYResult>(
(acc, curveSymbol) => {

const pool = poolDataByAddress[curveSymbol.toLowerCase()];
if (!pool) {
return acc;
}

const pool = poolDataByAddress[address];
const volume = volumeByAddress[(pool?.address || "").toLowerCase()];

const baseAPY = volume?.latestDailyApyPcent || 0;
Expand All @@ -163,15 +162,15 @@ export async function getCurveAPY(network: NetworkType): Promise<APYResult> {
);

let curveAPYs = [{
reward: address as Address,
reward: pool.lpTokenAddress,
symbol: curveSymbol,
value: curveAPYToBn(baseAPY),
}, {
reward: currentTokens?.["CRV"],
symbol: "CRV",
reward: crv.address,
symbol: crv.symbol,
value: curveAPYToBn(maxCrv),
}, ...extraRewards];
acc[address as Address] = getTokenAPY(curveSymbol, curveAPYs);
acc[pool.lpTokenAddress] = getTokenAPY(curveSymbol, curveAPYs);
return acc;
},
{} as APYResult,
Expand Down Expand Up @@ -201,8 +200,8 @@ export async function getCurveAPY(network: NetworkType): Promise<APYResult> {
value: curveAPYToBn(gearVolume?.latestDailyApyPcent || 0),
},
{
reward: currentTokens?.["CRV"],
symbol: "CRV",
reward: crv.address,
symbol: crv.symbol,
value: curveAPYToBn(Math.max(...(gearPool?.gaugeCrvApy || []), 0)),
},
...(gearPool?.gaugeRewards || []).map(
Expand Down Expand Up @@ -231,6 +230,7 @@ async function getCurvePools(network: NetworkType) {
axios.get<CurvePoolDataResponse>(getCryptoURL(network)),
axios.get<CurvePoolDataResponse>(getFactoryTriCryptoURL(network)),
axios.get<CurvePoolDataResponse>(getFactoryCrvUsdURL(network)),
axios.get<CurvePoolDataResponse>(getFactoryStableNgURL(network)),
]);
return {
mainnetVolumes: volumes,
Expand Down Expand Up @@ -302,3 +302,49 @@ export async function getCurveGearPool(): Promise<CurvePoolData | undefined> {
const gearPool = poolDataByAddress[GEAR_POOL];
return gearPool;
}


const curveTokens = [
"3Crv",
"steCRV",
"crvPlain3andSUSD",
"crvFRAX",
"crvCRVETH",
"crvCVXETH",
"crvUSDTWBTCWETH",
"LDOETH",
"crvUSDUSDC",
"crvUSDUSDT",
"crvUSDFRAX",
"crvUSDETHCRV",
"rETH-f",
"USDeUSDC",
"FRAXUSDe",
"USDecrvUSD",
"USDeDAI",
"MtEthena",
"GHOUSDe",
"pufETHwstE",
"GHOcrvUSD",
"ezETHWETH",
"ezpzETH",
"LBTCWBTC",
"eBTCWBTC",
"pumpBTCWBTC",
"TriBTC",
"FRAXsDAI",
"DOLAsUSDe",
"DOLAFRAXBP3CRV-f",
"crvUSDDOLA-f",
"crvUsUSDe",
"llamathena",
"2CRV",
"3c-crvUSD",
"crvUSDC",
"crvUSDT",
"crvUSDC-e",
"USDEUSDC",
"3CRV",
"wstETHCRV",
"gusd3CRV", // for mainnet
];
43 changes: 19 additions & 24 deletions src/apy/defiLamaAPY.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import {
NetworkType,
PartialRecord,
PERCENTAGE_FACTOR,
TypedObjectUtils,
tokenDataByNetwork,
NOT_DEPLOYED,
} from "@gearbox-protocol/sdk-gov";
} from "./type";
import axios from "axios";

// import { GearboxBackendApi } from "../core/endpoint";
import { APYResult, getTokenAPY, TokensWithAPY } from ".";
import { APYResult, getTokenAPY } from ".";
import { TokenStore } from "./token_store";

interface LamaItem {
apy: number;
Expand All @@ -29,7 +26,7 @@ interface LamaResponse {
}

export async function getDefiLamaAPY(
network: NetworkType,
network: NetworkType, store: TokenStore
): Promise<APYResult> {
const currentNormal = NORMAL_TO_LAMA[network];
const idList = Object.values(currentNormal);
Expand All @@ -46,30 +43,28 @@ export async function getDefiLamaAPY(



const currentTokens = tokenDataByNetwork[network];

const allAPY = TypedObjectUtils.entries(
currentNormal as Record<TokensWithAPY, string>,
).reduce<APYResult>((acc, [symbol, pool]) => {
const { apy = 0 } = itemsRecord[pool] || {};
let address = currentTokens?.[symbol];
if (address != NOT_DEPLOYED) {
acc[address] = getTokenAPY(symbol, [{
reward: address,
symbol: symbol,
value: apy,
}]);
}
const allAPY =
Object.entries(currentNormal).reduce<APYResult>((acc, [symbol, pool]) => {
const { apy = 0 } = itemsRecord[pool] || {};
let token = store.getBysymbol(network, symbol);
if (token.address != NOT_DEPLOYED) {
acc[token.address] = getTokenAPY(token.symbol, [{
reward: token.address,
symbol: symbol,
value: apy,
}]);
}

return acc;
}, {});
return acc;
}, {});

return allAPY;
}

const NORMAL_TO_LAMA: Record<
NetworkType,
PartialRecord<TokensWithAPY, string>
Record<string, string> // symbol to pool
> = {
Mainnet: {
sDAI: "c8a24fee-ec00-4f38-86c0-9f6daebc4225",
Expand Down Expand Up @@ -107,6 +102,6 @@ const NORMAL_TO_LAMA: Record<

sfrxETH: "77020688-e1f9-443c-9388-e51ace15cc32",
},
Base: {},
// Base: {},
};

Loading

0 comments on commit bb3481a

Please sign in to comment.