@gearbox-protocol/sdk 3.0.0-next.281 → 3.0.0-next.282
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/gearboxRewards/api.d.ts +2 -3
- package/lib/gearboxRewards/api.js +60 -39
- package/package.json +1 -1
|
@@ -41,11 +41,10 @@ export interface FarmInfo {
|
|
|
41
41
|
balance: bigint;
|
|
42
42
|
symbol: SupportedToken;
|
|
43
43
|
}
|
|
44
|
-
type PoolsWithExtraRewardsList = Record<NetworkType, Array<
|
|
44
|
+
type PoolsWithExtraRewardsList = Record<NetworkType, Array<Address>>;
|
|
45
45
|
type ReportHandler = (e: unknown, description?: string) => void;
|
|
46
46
|
export interface GetLmRewardsInfoProps {
|
|
47
47
|
pools: Record<Address, PoolData>;
|
|
48
|
-
currentTokenData: Record<SupportedToken, Address>;
|
|
49
48
|
tokensList: Record<Address, TokenData>;
|
|
50
49
|
provider: PublicClient;
|
|
51
50
|
multicallAddress: Address;
|
|
@@ -76,7 +75,7 @@ export interface ClaimLmRewardsV3Props {
|
|
|
76
75
|
signer: WalletClient;
|
|
77
76
|
}
|
|
78
77
|
export declare class GearboxRewardsApi {
|
|
79
|
-
static getLmRewardsInfo({ pools,
|
|
78
|
+
static getLmRewardsInfo({ pools, provider, multicallAddress, tokensList, poolsWithExtraRewards, network, reportError, }: GetLmRewardsInfoProps): Promise<{
|
|
80
79
|
rewardPoolsInfo: Record<string, FarmInfo[]>;
|
|
81
80
|
baseRewardPoolsInfo: Record<string, FarmInfo>;
|
|
82
81
|
extraRewardPoolsInfo: Record<string, FarmInfo[]>;
|
|
@@ -13,14 +13,16 @@ const formatter_1 = require("../utils/formatter");
|
|
|
13
13
|
const math_1 = require("../utils/math");
|
|
14
14
|
const merklAPI_1 = require("./merklAPI");
|
|
15
15
|
const DEFAULT_POOLS_WITH_EXTRA_REWARDS = {
|
|
16
|
-
Mainnet: [
|
|
16
|
+
Mainnet: [
|
|
17
|
+
"0x7354EC6E852108411e681D13E11185c3a2567981", // dtBTCV3
|
|
18
|
+
],
|
|
17
19
|
Arbitrum: [],
|
|
18
20
|
Optimism: [],
|
|
19
21
|
Base: [],
|
|
20
22
|
};
|
|
21
23
|
class GearboxRewardsApi {
|
|
22
|
-
static async getLmRewardsInfo({ pools,
|
|
23
|
-
const
|
|
24
|
+
static async getLmRewardsInfo({ pools, provider, multicallAddress, tokensList, poolsWithExtraRewards = DEFAULT_POOLS_WITH_EXTRA_REWARDS, network, reportError, }) {
|
|
25
|
+
const poolByStakedDiesel = Object.values(pools).reduce((acc, p) => {
|
|
24
26
|
p.stakedDieselToken.forEach(t => {
|
|
25
27
|
if (t)
|
|
26
28
|
acc[t] = p.address;
|
|
@@ -31,29 +33,35 @@ class GearboxRewardsApi {
|
|
|
31
33
|
});
|
|
32
34
|
return acc;
|
|
33
35
|
}, {});
|
|
34
|
-
const
|
|
36
|
+
const poolByDiesel = Object.values(pools).reduce((acc, p) => {
|
|
37
|
+
acc[p.dieselToken] = p.address;
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
const poolByItsToken = { ...poolByStakedDiesel, ...poolByDiesel };
|
|
41
|
+
const poolStakedTokens = sdk_gov_1.TypedObjectUtils.keys(poolByStakedDiesel);
|
|
42
|
+
const allPoolTokens = sdk_gov_1.TypedObjectUtils.keys(poolByItsToken);
|
|
35
43
|
const chainId = sdk_gov_1.CHAINS[network];
|
|
36
|
-
const poolTokensWithExtraReward = (poolsWithExtraRewards[network] || []).filter(
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
console.error(`Pool
|
|
44
|
+
const poolTokensWithExtraReward = (poolsWithExtraRewards[network] || []).filter(p => {
|
|
45
|
+
const token = tokensList[p.toLowerCase()];
|
|
46
|
+
if (!token) {
|
|
47
|
+
console.error(`Pool token not found ${p}`);
|
|
40
48
|
return false;
|
|
41
49
|
}
|
|
42
50
|
return true;
|
|
43
51
|
});
|
|
44
|
-
const farmInfoCalls =
|
|
52
|
+
const farmInfoCalls = poolStakedTokens.map(address => ({
|
|
45
53
|
address,
|
|
46
54
|
abi: types_1.iFarmingPoolAbi,
|
|
47
55
|
functionName: "farmInfo",
|
|
48
56
|
args: [],
|
|
49
57
|
}));
|
|
50
|
-
const farmSupplyCalls =
|
|
58
|
+
const farmSupplyCalls = allPoolTokens.map(address => ({
|
|
51
59
|
address,
|
|
52
60
|
abi: types_1.iFarmingPoolAbi,
|
|
53
61
|
functionName: "totalSupply",
|
|
54
62
|
args: [],
|
|
55
63
|
}));
|
|
56
|
-
const rewardTokenCalls =
|
|
64
|
+
const rewardTokenCalls = poolStakedTokens.map(address => ({
|
|
57
65
|
address,
|
|
58
66
|
abi: POOL_REWARDS_ABI,
|
|
59
67
|
functionName: "rewardsToken",
|
|
@@ -75,12 +83,11 @@ class GearboxRewardsApi {
|
|
|
75
83
|
...rewardTokenCalls,
|
|
76
84
|
],
|
|
77
85
|
}),
|
|
78
|
-
...poolTokensWithExtraReward.map(
|
|
79
|
-
const addr = currentTokenData[symbol];
|
|
86
|
+
...poolTokensWithExtraReward.map(t => {
|
|
80
87
|
return axios_1.default.get(merklAPI_1.MerkleXYZApi.getRewardsCampaignsUrl({
|
|
81
88
|
params: {
|
|
82
89
|
chainId,
|
|
83
|
-
mainParameter: (0, viem_1.getAddress)(
|
|
90
|
+
mainParameter: (0, viem_1.getAddress)(t),
|
|
84
91
|
},
|
|
85
92
|
}));
|
|
86
93
|
}),
|
|
@@ -94,9 +101,22 @@ class GearboxRewardsApi {
|
|
|
94
101
|
const farmSupply = restMCResponse.slice(farmInfoCallsEnd, farmSupplyCallsEnd);
|
|
95
102
|
const rewardTokenCallsEnd = farmSupplyCallsEnd + rewardTokenCalls.length;
|
|
96
103
|
const rewardTokens = restMCResponse.slice(farmSupplyCallsEnd, rewardTokenCallsEnd);
|
|
104
|
+
const infoByPool = poolStakedTokens.reduce((acc, p, index) => {
|
|
105
|
+
const info = farmInfo[index];
|
|
106
|
+
if (info)
|
|
107
|
+
acc[p] = info;
|
|
108
|
+
return acc;
|
|
109
|
+
}, {});
|
|
110
|
+
const rewardTokenPool = poolStakedTokens.reduce((acc, p, index) => {
|
|
111
|
+
const token = rewardTokens[index];
|
|
112
|
+
if (token) {
|
|
113
|
+
acc[p] = token.toLowerCase();
|
|
114
|
+
}
|
|
115
|
+
return acc;
|
|
116
|
+
}, {});
|
|
97
117
|
const extraRewards = extra.reduce((acc, r, index) => {
|
|
98
|
-
const
|
|
99
|
-
const safeResp = this.extractFulfilled(r, reportError, `merkleCampaign: ${
|
|
118
|
+
const p = poolTokensWithExtraReward[index].toLowerCase();
|
|
119
|
+
const safeResp = this.extractFulfilled(r, reportError, `merkleCampaign: ${p}`);
|
|
100
120
|
const l = safeResp?.data.reduce((infos, d) => {
|
|
101
121
|
const started = (0, sdk_gov_1.toBigInt)(d.startTimestamp || 0);
|
|
102
122
|
const finished = (0, sdk_gov_1.toBigInt)(d.endTimestamp || 0);
|
|
@@ -106,7 +126,7 @@ class GearboxRewardsApi {
|
|
|
106
126
|
const reward = (0, formatter_1.toBN)(d.amountDecimal, rewardTokenData?.decimals || 18);
|
|
107
127
|
if (rewardTokenData && reward > 0) {
|
|
108
128
|
infos.push({
|
|
109
|
-
pool:
|
|
129
|
+
pool: poolByItsToken[p],
|
|
110
130
|
duration: (0, sdk_gov_1.toBigInt)(d.endTimestamp - d.startTimestamp),
|
|
111
131
|
finished,
|
|
112
132
|
reward,
|
|
@@ -118,38 +138,39 @@ class GearboxRewardsApi {
|
|
|
118
138
|
return infos;
|
|
119
139
|
}, []);
|
|
120
140
|
if (l) {
|
|
121
|
-
acc[
|
|
141
|
+
acc[p] = l;
|
|
122
142
|
}
|
|
123
143
|
return acc;
|
|
124
144
|
}, {});
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
const tokenData = tokensList[
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
pool:
|
|
132
|
-
duration: BigInt(
|
|
133
|
-
finished: BigInt(
|
|
134
|
-
reward:
|
|
135
|
-
balance:
|
|
145
|
+
const stakedTokenRewards = allPoolTokens.reduce((acc, pool) => {
|
|
146
|
+
const info = infoByPool[pool];
|
|
147
|
+
const token = rewardTokenPool[pool];
|
|
148
|
+
const tokenData = tokensList[token];
|
|
149
|
+
const baseReward = info && tokenData
|
|
150
|
+
? {
|
|
151
|
+
pool: poolByItsToken[pool],
|
|
152
|
+
duration: BigInt(info.duration),
|
|
153
|
+
finished: BigInt(info.finished),
|
|
154
|
+
reward: info.reward,
|
|
155
|
+
balance: info.balance,
|
|
136
156
|
symbol: tokenData.symbol,
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
acc.
|
|
142
|
-
|
|
157
|
+
}
|
|
158
|
+
: undefined;
|
|
159
|
+
const extra = extraRewards[pool] || [];
|
|
160
|
+
if (baseReward)
|
|
161
|
+
acc.base[pool] = baseReward;
|
|
162
|
+
acc.extra[pool] = extra;
|
|
163
|
+
acc.all[pool] = [...(baseReward ? [baseReward] : []), ...extra];
|
|
143
164
|
return acc;
|
|
144
165
|
}, { base: {}, extra: {}, all: {} });
|
|
145
|
-
const rewardPoolsSupply =
|
|
166
|
+
const rewardPoolsSupply = allPoolTokens.reduce((acc, address, i) => {
|
|
146
167
|
acc[address] = farmSupply[i] || 0n;
|
|
147
168
|
return acc;
|
|
148
169
|
}, {});
|
|
149
170
|
return {
|
|
150
|
-
rewardPoolsInfo:
|
|
151
|
-
baseRewardPoolsInfo:
|
|
152
|
-
extraRewardPoolsInfo:
|
|
171
|
+
rewardPoolsInfo: stakedTokenRewards.all,
|
|
172
|
+
baseRewardPoolsInfo: stakedTokenRewards.base,
|
|
173
|
+
extraRewardPoolsInfo: stakedTokenRewards.extra,
|
|
153
174
|
rewardPoolsSupply,
|
|
154
175
|
};
|
|
155
176
|
}
|