From 25ef731ecfdf21a761b4f34f426c01a94a6dd53f Mon Sep 17 00:00:00 2001 From: esser Date: Thu, 9 Jan 2025 14:37:41 +0800 Subject: [PATCH] Revert "Merge pull request #6 from Gearbox-protocol/points" This reverts commit 31d1bf544311819186eb2a4ff8e2257ab365c67c, reversing changes made to 606c37e3357e3ba710bdeb83e7946fa399406428. --- src/endpoints.ts | 88 ++++-------- src/fetcher.ts | 76 ++++------ src/points/constants.ts | 299 ---------------------------------------- src/points/index.ts | 1 - src/points/points.ts | 31 ----- src/utils/index.ts | 14 +- 6 files changed, 57 insertions(+), 452 deletions(-) delete mode 100644 src/points/constants.ts delete mode 100644 src/points/index.ts delete mode 100644 src/points/points.ts diff --git a/src/endpoints.ts b/src/endpoints.ts index 175c245..d15f0eb 100644 --- a/src/endpoints.ts +++ b/src/endpoints.ts @@ -3,8 +3,7 @@ import { isAddress } from "viem"; import type { GearAPY } from "./apy"; import type { ApyDetails, Fetcher } from "./fetcher"; -import type { PointsInfo } from "./points/constants"; -import { isSupportedNetwork, toJSONWithBigint } from "./utils"; +import { isSupportedNetwork } from "./utils"; interface Response { status: string; @@ -18,7 +17,6 @@ interface OutputDetails { symbol: string; rewards: { apy: Array; - points: Array; }; } @@ -33,22 +31,23 @@ export async function getByChainAndToken(req: any, res: any, fetcher: Fetcher) { if (!checkResp(isTokenValid, res)) { return; } - - const a = fetcher.cache[chainId]?.apyList?.[tokenAddress as Address]; - const p = fetcher.cache[chainId]?.pointsList?.[tokenAddress as Address]; - const data: OutputDetails = { chainId: chainId, address: tokenAddress.toLowerCase(), - symbol: a?.symbol || p?.symbol || "", + symbol: "", rewards: { - apy: a.apys || [], - points: p ? [p] : [], + apy: [], }, }; + const d = fetcher.cache[chainId]?.tokens?.[tokenAddress as Address]; + if (d) { + data.rewards.apy = d.apys; + data.symbol = d.symbol; + } + res.set({ "Content-Type": "application/json" }); - res.send(toJSONWithBigint({ data: data, status: "ok" } as Response)); + res.send(JSON.stringify({ data: data, status: "ok" } as Response)); // } @@ -57,45 +56,21 @@ export async function getAll(req: any, res: any, fetcher: Fetcher) { if (!checkResp(isChainIdValid, res)) { return; } + const data: Array = []; - const data = Object.entries(fetcher.cache[chainId]?.apyList || {}).reduce< - Record - >((acc, [t, a]) => { - acc[t as Address] = { + Object.entries(fetcher.cache[chainId]?.tokens).forEach(([token, apy]) => { + data.push({ chainId: chainId, - address: t, - symbol: a.symbol, + address: token, + symbol: apy.symbol, rewards: { - apy: a.apys, - points: [], + apy: apy.apys, }, - }; - - return acc; - }, {}); - - Object.entries(fetcher.cache[chainId]?.pointsList || {}).forEach(([t, p]) => { - const token = t as Address; - - if (data[token]) { - data[token].rewards.points.push(p); - } else { - data[token] = { - chainId: chainId, - address: t, - symbol: p.symbol, - rewards: { - apy: [], - points: [p], - }, - }; - } + }); }); res.set({ "Content-Type": "application/json" }); - res.send( - toJSONWithBigint({ data: Object.values(data), status: "ok" } as Response), - ); + res.send(JSON.stringify({ data: data, status: "ok" } as Response)); } export async function getRewardList(req: any, res: any, fetcher: Fetcher) { @@ -108,30 +83,27 @@ export async function getRewardList(req: any, res: any, fetcher: Fetcher) { res, ); } - const [isTokenList, tokenList] = checkTokenList(toJSONWithBigint(req.body)); + const [isTokenList, tokenList] = checkTokenList(JSON.stringify(req.body)); if (!checkResp(isTokenList, res)) { return; } const data: Array = []; - for (const t of tokenList) { - const a = fetcher.cache[t.chain_id]?.apyList?.[t.token_address as Address]; - const p = - fetcher.cache[t.chain_id]?.pointsList?.[t.token_address as Address]; - + for (const entry of tokenList) { + const apys = + fetcher.cache[entry.chain_id]?.tokens?.[entry.token_address as Address]; data.push({ - chainId: t.chain_id, - address: t.token_address.toLowerCase(), - symbol: a.symbol, + chainId: entry.chain_id, + address: entry.token_address.toLowerCase(), + symbol: apys.symbol, rewards: { - apy: a.apys || [], - points: p ? [p] : [], + apy: apys.apys, }, }); } res.set({ "Content-Type": "application/json" }); - res.send(toJSONWithBigint({ data: data, status: "ok" } as Response)); + res.send(JSON.stringify({ data: data, status: "ok" } as Response)); } export async function getGearAPY(req: any, res: any, fetcher: Fetcher) { @@ -142,7 +114,7 @@ export async function getGearAPY(req: any, res: any, fetcher: Fetcher) { res.set({ "Content-Type": "application/json" }); res.send( - toJSONWithBigint({ + JSON.stringify({ data: fetcher.cache[chainId]?.gear, status: "ok", } as Response), @@ -185,13 +157,13 @@ function checkTokenAddress(data: any): [Response, string] { "", ]; } - return [{ status: "ok" }, notUndefined.toString()]; + return [{ status: "ok" }, (notUndefined as Address).toString()]; } export function checkResp(res: Response, out: any): boolean { if (res.status === "error") { out.set({ "Content-Type": "application/json" }); - out.send(toJSONWithBigint(res)); + out.send(JSON.stringify(res)); return false; } return true; diff --git a/src/fetcher.ts b/src/fetcher.ts index af976b7..0fd34c1 100644 --- a/src/fetcher.ts +++ b/src/fetcher.ts @@ -12,8 +12,6 @@ import { getAPYYearn, getGearAPY, } from "./apy"; -import { getPoints } from "./points"; -import type { PointsInfo } from "./points/constants"; import type { Apy, APYResult, NetworkType, TokenAPY } from "./utils"; import { getChainId, supportedChains } from "./utils"; @@ -21,15 +19,13 @@ export type ApyDetails = Apy & { lastUpdated: string }; type TokenDetails = TokenAPY; interface NetworkState { - apyList: Record; - pointsList: Record; + tokens: Record; gear: GearAPY; } function log( network: NetworkType, allProtocolAPYs: Array>, - pointsList: PromiseSettledResult>, gearAPY: PromiseSettledResult, ) { const list = allProtocolAPYs.map(apyRes => { @@ -56,16 +52,6 @@ function log( } else { console.log(`Gear error: ${gearAPY.reason}`); } - - if (pointsList.status === "fulfilled") { - console.log( - `Fetched points for ${Object.values(pointsList.value) - .map(p => p.symbol) - .join(", ")} for ${network}`, - ); - } else { - console.log(`Points error: ${pointsList.reason}`); - } } export class Fetcher { @@ -76,11 +62,8 @@ export class Fetcher { } private async getNetworkState(network: NetworkType): Promise { - const [gearAPY, points, ...allProtocolAPYs] = await Promise.allSettled([ + const [gearAPY, ...allProtocolAPYs] = await Promise.allSettled([ getGearAPY(network), - - getPoints(network), - getAPYCurve(network), getAPYEthena(network), getAPYLama(network), @@ -89,46 +72,39 @@ export class Fetcher { getAPYYearn(network), getAPYConstant(network), ]); - log(network, allProtocolAPYs, points, gearAPY); + log(network, allProtocolAPYs, gearAPY); + const result: Record = {}; const time = moment().utc().format(); - const apyList = allProtocolAPYs.reduce>( - (acc, apyRes) => { - if (apyRes.status === "fulfilled") { - Object.entries(apyRes.value).forEach(([addr, tokenAPY]) => { - const address = addr.toLowerCase() as Address; - - const apyList = tokenAPY?.apys.map( - ({ reward, ...rest }): ApyDetails => ({ - ...rest, - lastUpdated: time, - reward: reward.toLowerCase() as Address, - }), - ); - - acc[address] = { - ...tokenAPY, - address, - apys: [...(acc[address]?.apys || []), ...apyList], - }; - }); - } - - return acc; - }, - {}, - ); - - const pointsList = points.status === "fulfilled" ? points.value : {}; + allProtocolAPYs.forEach(apyRes => { + if (apyRes.status === "fulfilled") { + Object.entries(apyRes.value).forEach(([addr, tokenAPY]) => { + const address = addr.toLowerCase() as Address; + + const apyList = tokenAPY?.apys.map( + ({ reward, ...rest }): ApyDetails => ({ + ...rest, + lastUpdated: time, + reward: reward.toLowerCase() as Address, + }), + ); + + result[address] = { + ...tokenAPY, + address, + apys: [...(result[address]?.apys || []), ...apyList], + }; + }); + } + }); return { gear: gearAPY.status === "fulfilled" ? gearAPY.value : { base: 0, crv: 0, gear: 0 }, - apyList, - pointsList, + tokens: result, }; } diff --git a/src/points/constants.ts b/src/points/constants.ts deleted file mode 100644 index 329b52e..0000000 --- a/src/points/constants.ts +++ /dev/null @@ -1,299 +0,0 @@ -import type { Address } from "viem"; - -import type { NetworkType } from "../utils"; - -type PointsType = - | "eigenlayer" - | "renzo" - | "etherfi" - | "kelp" - | "swell" - | "puffer" - | "ethena" - | "symbiotic" - | "mellow" - | "lombard" - | "babylon" - | "veda" - | "karak" - | "pumpBTC"; - -interface PointsReward { - name: string; - units: string; - multiplier: number | "soon"; - type: PointsType; -} - -interface DebtReward extends PointsReward { - cm: Address; -} - -type CommonReward = - CM extends undefined ? PointsReward : DebtReward; - -const REWARDS_BASE_INFO = { - eigenlayer: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Eigenlayer", - units: "points", - multiplier, - type: "eigenlayer", - }), - renzo: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Renzo", - units: "points", - multiplier, - type: "renzo", - }), - etherfi: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Ether.fi", - units: "points", - multiplier, - type: "etherfi", - }), - kelp: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Kelp", - units: "Miles", - multiplier, - type: "kelp", - }), - swell: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Swell", - units: "points", - multiplier, - type: "swell", - }), - puffer: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Puffer", - units: "points", - multiplier, - type: "puffer", - }), - ethena: ( - multiplier: PointsReward["multiplier"], - cm?: CM, - ): CommonReward => { - return { - name: "Ethena", - units: "sats", - multiplier, - type: "ethena", - ...(cm ? { cm } : {}), - } as CommonReward; - }, - - symbiotic: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Symbiotic", - units: "points", - multiplier, - type: "symbiotic", - }), - mellow: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Mellow", - units: "points", - multiplier, - type: "mellow", - }), - - lombard: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Lombard", - units: "points", - multiplier, - type: "lombard", - }), - babylon: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Babylon", - units: "points", - multiplier, - type: "babylon", - }), - - veda: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Veda", - units: "points", - multiplier, - type: "veda", - }), - karak: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Karak", - units: "points", - multiplier, - type: "karak", - }), - - pumpBTC: (multiplier: PointsReward["multiplier"]): PointsReward => ({ - name: "Pump BTC", - units: "points", - multiplier, - type: "pumpBTC", - }), -}; - -export interface PointsInfo { - symbol: string; - address: Address; - rewards: Array; - debtRewards?: Array; -} - -export const POINTS_INFO_BY_NETWORK: Record> = { - Mainnet: [ - { - address: "0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee", - symbol: "weETH", - rewards: [ - REWARDS_BASE_INFO.eigenlayer(100), - REWARDS_BASE_INFO.etherfi(200), - ], - }, - { - address: "0xbf5495Efe5DB9ce00f80364C8B423567e58d2110", - symbol: "ezETH", - rewards: [ - REWARDS_BASE_INFO.eigenlayer(100), - REWARDS_BASE_INFO.renzo(300), - ], - }, - { - address: "0xA1290d69c65A6Fe4DF752f95823fae25cB99e5A7", - symbol: "rsETH", - rewards: [REWARDS_BASE_INFO.eigenlayer(100), REWARDS_BASE_INFO.kelp(200)], - }, - { - address: "0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0", - symbol: "rswETH", - rewards: [ - REWARDS_BASE_INFO.eigenlayer(100), - REWARDS_BASE_INFO.swell(450), - ], - }, - { - address: "0xD9A442856C234a39a81a089C06451EBAa4306a72", - symbol: "pufETH", - rewards: [ - REWARDS_BASE_INFO.eigenlayer(100), - REWARDS_BASE_INFO.puffer(100), - ], - }, - - { - address: "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497", - symbol: "sUSDe", - rewards: [REWARDS_BASE_INFO.ethena(500)], - debtRewards: [ - REWARDS_BASE_INFO.ethena( - 500, - "0x58c8e983d9479b69b64970f79e8965ea347189c9", - ), - ], - }, - { - address: "0x4c9EDD5852cd905f086C759E8383e09bff1E68B3", - symbol: "USDe", - rewards: [REWARDS_BASE_INFO.ethena(2000)], - debtRewards: [ - REWARDS_BASE_INFO.ethena( - 500, - "0x58c8e983d9479b69b64970f79e8965ea347189c9", - ), - ], - }, - - { - address: "0x8c9532a60E0E7C6BbD2B2c1303F63aCE1c3E9811", - symbol: "pzETH", - rewards: [ - REWARDS_BASE_INFO.renzo(300), - REWARDS_BASE_INFO.symbiotic(100), - REWARDS_BASE_INFO.mellow(200), - ], - }, - { - address: "0x7a4EffD87C2f3C55CA251080b1343b605f327E3a", - symbol: "rstETH", - rewards: [ - REWARDS_BASE_INFO.symbiotic(100), - REWARDS_BASE_INFO.mellow(200), - ], - }, - { - address: "0xBEEF69Ac7870777598A04B2bd4771c71212E6aBc", - symbol: "steakLRT", - rewards: [ - REWARDS_BASE_INFO.symbiotic(100), - REWARDS_BASE_INFO.mellow(200), - ], - }, - { - address: "0x5fD13359Ba15A84B76f7F87568309040176167cd", - symbol: "amphrETH", - rewards: [ - REWARDS_BASE_INFO.symbiotic(100), - REWARDS_BASE_INFO.mellow(200), - ], - }, - - { - address: "0x8236a87084f8B84306f72007F36F2618A5634494", - symbol: "LBTC", - rewards: [REWARDS_BASE_INFO.babylon(100), REWARDS_BASE_INFO.lombard(300)], - }, - { - address: "0x84631c0d0081FDe56DeB72F6DE77abBbF6A9f93a", - symbol: "Re7LRT", - rewards: [ - REWARDS_BASE_INFO.symbiotic(100), - REWARDS_BASE_INFO.mellow(200), - ], - }, - - { - address: "0x657e8C867D8B37dCC18fA4Caead9C45EB088C642", - symbol: "eBTC", - rewards: [ - REWARDS_BASE_INFO.babylon(100), - REWARDS_BASE_INFO.symbiotic(100), - REWARDS_BASE_INFO.etherfi(200), - REWARDS_BASE_INFO.lombard(400), - REWARDS_BASE_INFO.veda(300), - REWARDS_BASE_INFO.karak(200), - ], - }, - - { - address: "0xF469fBD2abcd6B9de8E169d128226C0Fc90a012e", - symbol: "pumpBTC", - rewards: [REWARDS_BASE_INFO.babylon(100), REWARDS_BASE_INFO.pumpBTC(200)], - }, - ], - Arbitrum: [ - { - address: "0x2416092f143378750bb29b79eD961ab195CcEea5", - symbol: "ezETH", - rewards: [ - REWARDS_BASE_INFO.eigenlayer(100), - REWARDS_BASE_INFO.renzo(300), - ], - }, - { - address: "0x5d3a1Ff2b6BAb83b63cd9AD0787074081a52ef34", - symbol: "USDe", - rewards: [REWARDS_BASE_INFO.ethena(2000)], - }, - { - address: "0x4186BFC76E2E237523CBC30FD220FE055156b41F", - symbol: "rsETH", - rewards: [REWARDS_BASE_INFO.eigenlayer(100), REWARDS_BASE_INFO.kelp(300)], - }, - ], - Optimism: [ - { - address: "0x2416092f143378750bb29b79eD961ab195CcEea5", - symbol: "ezETH", - rewards: [ - REWARDS_BASE_INFO.eigenlayer(100), - REWARDS_BASE_INFO.renzo(300), - ], - }, - ], -}; diff --git a/src/points/index.ts b/src/points/index.ts deleted file mode 100644 index 1ce67fa..0000000 --- a/src/points/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./points"; diff --git a/src/points/points.ts b/src/points/points.ts deleted file mode 100644 index bcf3a21..0000000 --- a/src/points/points.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type { Address } from "viem"; - -import type { PointsHandler, PointsResult } from "../utils"; -import { POINTS_INFO_BY_NETWORK } from "./constants"; - -const getPoints: PointsHandler = async network => { - const points = POINTS_INFO_BY_NETWORK[network]; - - const result = points.reduce((acc, p) => { - const address = p.address.toLowerCase() as Address; - - acc[address] = { - ...p, - address, - ...(p.debtRewards - ? { - debtRewards: p.debtRewards.map(r => ({ - ...r, - cm: r.cm.toLowerCase() as Address, - })), - } - : {}), - }; - - return acc; - }, {}); - - return result; -}; - -export { getPoints }; diff --git a/src/utils/index.ts b/src/utils/index.ts index a98b609..bae3478 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,5 @@ import type { Address } from "viem"; -import type { PointsInfo } from "../points/constants"; - export interface Apy { reward: Address; symbol: string; @@ -18,10 +16,8 @@ export interface TokenAPY { } export type APYResult = Record; -export type APYHandler = (network: NetworkType) => Promise; -export type PointsResult = Record; -export type PointsHandler = (network: NetworkType) => Promise; +export type APYHandler = (network: NetworkType) => Promise; export const supportedChains = ["Mainnet", "Arbitrum", "Optimism"] as const; export type NetworkType = (typeof supportedChains)[number]; @@ -38,11 +34,3 @@ export function getChainId(network: NetworkType) { export function isSupportedNetwork(chainId: number) { return Object.values(CHAINS).includes(chainId); } - -export function toJSONWithBigint(o: any) { - const r = JSON.stringify(o, (_, v) => - typeof v === "bigint" ? v.toString() : v, - ); - - return r; -}