@gearbox-protocol/sdk 3.0.0-next.200 → 3.0.0-next.201

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.
@@ -34,12 +34,14 @@ export type FarmInfo = FarmInfoOutput & {
34
34
  symbol: SupportedToken;
35
35
  };
36
36
  type PoolsWithExtraRewardsList = Record<NetworkType, Array<SupportedToken>>;
37
+ type ReportHandler = (e: unknown, description?: string) => void;
37
38
  export interface GetLmRewardsInfoProps {
38
39
  currentTokenData: Record<SupportedToken, string>;
39
40
  provider: Provider | Signer;
40
41
  multicallAddress: string;
41
42
  poolsWithExtraRewards?: PoolsWithExtraRewardsList;
42
43
  network: NetworkType;
44
+ reportError?: ReportHandler;
43
45
  }
44
46
  export interface GetLmRewardsProps {
45
47
  baseRewardPoolsInfo: Record<string, FarmInfo>;
@@ -48,6 +50,7 @@ export interface GetLmRewardsProps {
48
50
  provider: Provider | Signer;
49
51
  airdropDistributorAddress: string | undefined;
50
52
  network: NetworkType;
53
+ reportError?: ReportHandler;
51
54
  }
52
55
  export interface ClaimLmRewardsV2Props {
53
56
  signer: Signer;
@@ -61,7 +64,7 @@ export interface ClaimLmRewardsV3Props {
61
64
  signer: Signer;
62
65
  }
63
66
  export declare class GearboxRewardsApi {
64
- static getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards, network, }: GetLmRewardsInfoProps): Promise<{
67
+ static getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards, network, reportError, }: GetLmRewardsInfoProps): Promise<{
65
68
  rewardPoolsInfo: Record<string, FarmInfo[]>;
66
69
  baseRewardPoolsInfo: Record<string, FarmInfo>;
67
70
  extraRewardPoolsInfo: Record<string, FarmInfo[]>;
@@ -70,9 +73,10 @@ export declare class GearboxRewardsApi {
70
73
  static getLmRewardsV2({ provider, account, currentTokenData, network, airdropDistributorAddress, }: GetLmRewardsProps): Promise<{
71
74
  rewards: GearboxLmReward[];
72
75
  }>;
73
- static getLmRewardsV3({ baseRewardPoolsInfo, currentTokenData, provider, account, network, }: GetLmRewardsProps): Promise<{
76
+ static getLmRewardsV3({ baseRewardPoolsInfo, currentTokenData, provider, account, network, reportError, }: GetLmRewardsProps): Promise<{
74
77
  rewards: (GearboxLmReward | GearboxLmReward[])[];
75
78
  }>;
79
+ private static extractFulfilled;
76
80
  static claimLmRewardsV2({ signer, account, provider, network, airdropDistributorAddress, }: ClaimLmRewardsV2Props): Promise<import("ethers").TransactionResponse | import("../utils/calls").MinimalTxInfo>;
77
81
  static claimLmRewardsV3({ reward, signer }: ClaimLmRewardsV3Props): Promise<import("ethers").TransactionResponse | import("../utils/calls").MinimalTxInfo>;
78
82
  private static getMerkle;
@@ -14,13 +14,13 @@ const math_1 = require("../utils/math");
14
14
  const abi_1 = require("./abi");
15
15
  const merklAPI_1 = require("./merklAPI");
16
16
  const DEFAULT_POOLS_WITH_EXTRA_REWARDS = {
17
- Mainnet: ["sdGHOV3", "sdcrvUSDV3"],
17
+ Mainnet: ["sdcrvUSDV3"],
18
18
  Arbitrum: [],
19
19
  Optimism: [],
20
20
  Base: [],
21
21
  };
22
22
  class GearboxRewardsApi {
23
- static async getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards = DEFAULT_POOLS_WITH_EXTRA_REWARDS, network, }) {
23
+ static async getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards = DEFAULT_POOLS_WITH_EXTRA_REWARDS, network, reportError, }) {
24
24
  const poolTokens = sdk_gov_1.TypedObjectUtils.entries(currentTokenData).filter(([symbol]) => (0, sdk_gov_1.isDieselStakedToken)(symbol));
25
25
  const farmInfoCalls = poolTokens.map(([, address]) => ({
26
26
  address: address,
@@ -45,7 +45,7 @@ class GearboxRewardsApi {
45
45
  };
46
46
  const tokenWithExtraRewards = poolsWithExtraRewards[network] || [];
47
47
  const chainId = sdk_gov_1.CHAINS[network];
48
- const [[blockTimestamp, ...mcResponse], ...extraRewardsResponses] = await Promise.all([
48
+ const [mc, ...extra] = await Promise.allSettled([
49
49
  (0, sdk_gov_1.multicall)([
50
50
  blockTimestampCall,
51
51
  ...farmInfoCalls,
@@ -59,15 +59,18 @@ class GearboxRewardsApi {
59
59
  },
60
60
  }))),
61
61
  ]);
62
+ const mcResponse = this.extractFulfilled(mc, reportError, "rewardsInfoMulticall") || [];
63
+ const [blockTimestamp = 0n, ...restMCResponse] = mcResponse;
62
64
  const farmInfoCallsEnd = farmInfoCalls.length;
63
- const farmInfo = mcResponse.slice(0, farmInfoCallsEnd);
65
+ const farmInfo = restMCResponse.slice(0, farmInfoCallsEnd);
64
66
  const farmSupplyCallsEnd = farmInfoCallsEnd + farmSupplyCalls.length;
65
- const farmSupply = mcResponse.slice(farmInfoCallsEnd, farmSupplyCallsEnd);
67
+ const farmSupply = restMCResponse.slice(farmInfoCallsEnd, farmSupplyCallsEnd);
66
68
  const rewardTokenCallsEnd = farmSupplyCallsEnd + rewardTokenCalls.length;
67
- const rewardTokens = mcResponse.slice(farmSupplyCallsEnd, rewardTokenCallsEnd);
68
- const extraRewards = extraRewardsResponses.reduce((acc, r, index) => {
69
+ const rewardTokens = restMCResponse.slice(farmSupplyCallsEnd, rewardTokenCallsEnd);
70
+ const extraRewards = extra.reduce((acc, r, index) => {
69
71
  const stakedSymbol = tokenWithExtraRewards[index];
70
- const l = r.data.reduce((infos, d) => {
72
+ const safeResp = this.extractFulfilled(r, reportError, `merkleCampaign: ${stakedSymbol}`);
73
+ const l = safeResp?.data.reduce((infos, d) => {
71
74
  const started = (0, sdk_gov_1.toBigInt)(d.startTimestamp || 0);
72
75
  const finished = (0, sdk_gov_1.toBigInt)(d.endTimestamp || 0);
73
76
  if (blockTimestamp >= started && blockTimestamp <= finished) {
@@ -86,25 +89,27 @@ class GearboxRewardsApi {
86
89
  }
87
90
  return infos;
88
91
  }, []);
89
- acc[currentTokenData[stakedSymbol]] = l;
92
+ if (l) {
93
+ acc[currentTokenData[stakedSymbol]] = l;
94
+ }
90
95
  return acc;
91
96
  }, {});
92
97
  const rewardPoolsInfo = poolTokens.reduce((acc, [, address], i) => {
93
98
  const currentInfo = farmInfo[i];
94
99
  const [symbol] = (0, sdk_gov_1.extractTokenData)(rewardTokens[i] || "");
95
- if (!symbol)
96
- throw new Error(`Can't get reward token for: ${(0, sdk_gov_1.extractTokenData)(address)[0]} [${address}]`);
97
- const baseReward = {
98
- duration: currentInfo.duration,
99
- finished: currentInfo.finished,
100
- reward: currentInfo.reward,
101
- balance: currentInfo.balance,
102
- symbol: symbol,
103
- };
104
- const extra = extraRewards[address] || [];
105
- acc.base[address] = baseReward;
106
- acc.extra[address] = extra;
107
- acc.all[address] = [baseReward, ...extra];
100
+ if (symbol) {
101
+ const baseReward = {
102
+ duration: currentInfo.duration,
103
+ finished: currentInfo.finished,
104
+ reward: currentInfo.reward,
105
+ balance: currentInfo.balance,
106
+ symbol: symbol,
107
+ };
108
+ const extra = extraRewards[address] || [];
109
+ acc.base[address] = baseReward;
110
+ acc.extra[address] = extra;
111
+ acc.all[address] = [baseReward, ...extra];
112
+ }
108
113
  return acc;
109
114
  }, { base: {}, extra: {}, all: {} });
110
115
  const rewardPoolsSupply = poolTokens.reduce((acc, [, address], i) => {
@@ -141,7 +146,7 @@ class GearboxRewardsApi {
141
146
  ];
142
147
  return { rewards: rewards };
143
148
  }
144
- static async getLmRewardsV3({ baseRewardPoolsInfo, currentTokenData, provider, account, network, }) {
149
+ static async getLmRewardsV3({ baseRewardPoolsInfo, currentTokenData, provider, account, network, reportError, }) {
145
150
  const poolTokens = Object.keys(baseRewardPoolsInfo);
146
151
  const farmedCalls = poolTokens.map(address => ({
147
152
  address: address,
@@ -158,10 +163,8 @@ class GearboxRewardsApi {
158
163
  },
159
164
  })),
160
165
  ]);
161
- const gearboxLm = gearboxLmResponse.status === "fulfilled" ? gearboxLmResponse.value : [];
162
- const merkleXYZLM = merkleXYZLMResponse.status === "fulfilled"
163
- ? merkleXYZLMResponse.value?.data
164
- : undefined;
166
+ const gearboxLm = this.extractFulfilled(gearboxLmResponse, reportError, "v3Rewards") || [];
167
+ const merkleXYZLM = this.extractFulfilled(merkleXYZLMResponse, reportError, "merkleRewards")?.data;
165
168
  const PREFIX = "ERC20";
166
169
  const REWARD_KEYS_RECORD = poolTokens.reduce((acc, t) => {
167
170
  const key = [PREFIX, (0, ethers_1.getAddress)(t)].join("_");
@@ -205,6 +208,20 @@ class GearboxRewardsApi {
205
208
  rewards: [...nonZero, ...extraRewards, zero],
206
209
  };
207
210
  }
211
+ static extractFulfilled(r, reportError, description) {
212
+ if (r.status === "fulfilled") {
213
+ return r.value;
214
+ }
215
+ else {
216
+ if (reportError) {
217
+ reportError(r.reason, description);
218
+ }
219
+ else {
220
+ console.error(r.reason);
221
+ }
222
+ return undefined;
223
+ }
224
+ }
208
225
  static async claimLmRewardsV2({ signer, account, provider, network, airdropDistributorAddress, }) {
209
226
  if (!airdropDistributorAddress)
210
227
  throw new Error(`V2 rewards are not supported on chain: ${network}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.200",
3
+ "version": "3.0.0-next.201",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",