Skip to content

Commit f98c175

Browse files
committed
fix: remove hardcoded pool rewards
1 parent a721ccd commit f98c175

File tree

2 files changed

+38
-105
lines changed

2 files changed

+38
-105
lines changed

src/sdk/sdk-legacy/core/endpoint.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ export class GearboxBackendApi {
9595
static getReferralUrl = () => REFERRAL_API;
9696

9797
static apyServerAllRewards = (chainId: number) =>
98-
URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/all", {
98+
URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/tokens/all", {
9999
params: { chain_id: chainId },
100100
});
101101
static apyServerGearAPY = (chainId: number) =>
102102
URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/gear-apy", {
103103
params: { chain_id: chainId },
104104
});
105+
static apyServerAllPoolRewards = (chainId: number) =>
106+
URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/pools/all", {
107+
params: { chain_id: chainId },
108+
});
105109
}
106110

107111
interface Options {
Lines changed: 33 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import axios from "axios";
22
import type { Address } from "viem";
33

4-
import { chains, type NetworkType } from "../../chain";
4+
import type { NetworkType } from "../../chain";
5+
import { chains } from "../../chain";
56
import { PERCENTAGE_FACTOR } from "../../constants";
67
import type { Asset } from "../../router";
7-
import type { SupportedToken } from "../../sdk-gov-legacy";
8-
import { type PartialRecord, TypedObjectUtils } from "../../utils";
9-
import { poolByNetwork } from "../contracts/contractsRegister";
108
import { GearboxBackendApi } from "../core/endpoint";
119
import type { PoolData_Legacy } from "../core/pool";
1210
import type { TokenData } from "../tokens/tokenData";
1311
import { toBN } from "../utils/formatter";
1412
import { BigIntMath } from "../utils/math";
1513

14+
export interface PoolPointsInfo {
15+
pool: Address;
16+
token: Address;
17+
symbol: string;
18+
19+
amount: bigint;
20+
duration: string;
21+
name: string;
22+
estimation: "absolute" | "relative";
23+
}
24+
1625
export interface GetPointsByPoolProps {
26+
poolRewards: Record<Address, Record<Address, PoolPointsInfo>>;
27+
1728
totalTokenBalances: Record<Address, Asset>;
1829
pools: Array<PoolData_Legacy>;
19-
currentTokenData: Record<SupportedToken, Address>;
2030
tokensList: Record<Address, TokenData>;
21-
network: NetworkType;
2231
}
2332

2433
interface WalletResult {
@@ -31,104 +40,26 @@ interface GetBalanceAtResponse {
3140
}
3241

3342
export interface GetTotalTokensOnProtocolProps {
34-
currentTokenData: Record<SupportedToken, Address>;
43+
tokensToCheck: Array<Address>;
44+
3545
tokensList: Record<Address, TokenData>;
3646
network: NetworkType;
37-
38-
extraTokens?: Array<SupportedToken>;
39-
}
40-
41-
interface PoolPointsInfo {
42-
amount: bigint;
43-
symbol: SupportedToken;
44-
duration: string;
45-
name: string;
46-
estimation: "absolute" | "relative";
4747
}
4848

49-
const POOL_POINTS: Record<
50-
NetworkType,
51-
Record<Address, PartialRecord<SupportedToken, PoolPointsInfo>>
52-
> = {
53-
Mainnet: {
54-
[poolByNetwork.Mainnet.WETH_V3_TRADE]: {
55-
rsETH: {
56-
amount: 7500n * 10000n,
57-
symbol: "rsETH",
58-
duration: "hour",
59-
name: "Kelp Mile",
60-
estimation: "relative",
61-
},
62-
},
63-
[poolByNetwork.Mainnet.WBTC_V3_TRADE]: {
64-
LBTC: {
65-
amount: 2000n * 10000n,
66-
symbol: "LBTC",
67-
duration: "day",
68-
name: "Lombard LUX",
69-
estimation: "absolute",
70-
},
71-
pumpBTC: {
72-
amount: 172_800n * 10000n,
73-
symbol: "pumpBTC",
74-
duration: "day",
75-
name: "Pump BTC",
76-
estimation: "absolute",
77-
},
78-
},
79-
},
80-
Arbitrum: {},
81-
Optimism: {},
82-
Base: {},
83-
};
84-
85-
const TOKENS = TypedObjectUtils.entries(POOL_POINTS).reduce<
86-
Record<NetworkType, Array<SupportedToken>>
87-
>(
88-
(acc, [network, pools]) => {
89-
const r = Object.values(pools).reduce<Array<SupportedToken>>(
90-
(acc, tokens) => {
91-
const l = Object.keys(tokens) as Array<SupportedToken>;
92-
acc.push(...l);
93-
return acc;
94-
},
95-
[],
96-
);
97-
98-
acc[network] = r;
99-
100-
return acc;
101-
},
102-
{} as Record<NetworkType, Array<SupportedToken>>,
103-
);
104-
105-
const CA_REWARDS: Record<NetworkType, Array<SupportedToken>> = {
106-
Mainnet: [],
107-
Arbitrum: [],
108-
Optimism: ["ezETH"],
109-
Base: [],
110-
};
111-
11249
export class GearboxRewardsExtraApy {
11350
static async getTotalTokensOnProtocol({
114-
currentTokenData,
51+
tokensToCheck,
52+
11553
tokensList,
11654
network,
117-
118-
extraTokens = [],
11955
}: GetTotalTokensOnProtocolProps) {
120-
const poolTokens = TOKENS[network];
121-
const caTokens = CA_REWARDS[network];
122-
123-
const list = [...new Set([...poolTokens, ...caTokens, ...extraTokens])];
56+
const list = [...new Set(tokensToCheck)];
12457

12558
const res = await Promise.allSettled(
126-
list.map(s =>
127-
this.getTokenTotal(currentTokenData[s], network, tokensList),
128-
),
59+
list.map(t => this.getTokenTotal(t, network, tokensList)),
12960
);
13061

131-
return res.map((r, i): [SupportedToken, PromiseSettledResult<Asset>] => [
62+
return res.map((r, i): [Address, PromiseSettledResult<Asset>] => [
13263
list[i],
13364
r,
13465
]);
@@ -139,9 +70,9 @@ export class GearboxRewardsExtraApy {
13970
network: NetworkType,
14071
tokensList: Record<Address, TokenData>,
14172
) {
142-
const chain = chains[network];
73+
const chainId = chains[network]?.id;
14374

144-
const url = GearboxBackendApi.getChartsUrl("getBalanceAt", chain.id, {
75+
const url = GearboxBackendApi.getChartsUrl("getBalanceAt", chainId, {
14576
params: {
14677
asset: token,
14778
},
@@ -158,21 +89,19 @@ export class GearboxRewardsExtraApy {
15889
}
15990

16091
static getPointsByPool({
92+
poolRewards,
93+
16194
totalTokenBalances,
16295
pools,
16396
tokensList,
164-
currentTokenData,
165-
network,
16697
}: GetPointsByPoolProps) {
16798
const r = pools.reduce<Record<Address, Array<Asset>>>((acc, p) => {
168-
const poolPointsInfo = Object.values(
169-
POOL_POINTS[network]?.[p.address] || [],
170-
);
99+
const pointsInfo = Object.values(poolRewards[p.address] || {});
171100

172-
const poolPointsList = poolPointsInfo.reduce<Array<Asset>>(
101+
const poolPointsList = pointsInfo.reduce<Array<Asset>>(
173102
(acc, pointsInfo) => {
174-
const tokenBalance =
175-
totalTokenBalances[currentTokenData[pointsInfo.symbol] || ""];
103+
const { address: tokenAddress } = tokensList[pointsInfo.token];
104+
const tokenBalance = totalTokenBalances[tokenAddress || ""];
176105

177106
const points = this.getPoolTokenPoints(
178107
tokenBalance,
@@ -226,11 +155,11 @@ export class GearboxRewardsExtraApy {
226155
}
227156

228157
static getPoolPointsTip(
229-
network: NetworkType,
158+
poolRewards: Record<Address, Record<Address, PoolPointsInfo>>,
230159
pool: Address,
231-
token: SupportedToken,
160+
token: Address,
232161
) {
233-
const p = POOL_POINTS[network]?.[pool]?.[token];
162+
const p = poolRewards[pool]?.[token];
234163
return p;
235164
}
236165
}

0 commit comments

Comments
 (0)