@gearbox-protocol/sdk 3.0.0-next.194 → 3.0.0-next.196

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.
@@ -225,12 +225,12 @@ class CreditManagerData {
225
225
  static getTier(name) {
226
226
  const DEFAULT_TIER = 99;
227
227
  const l = name.split(" ") || [];
228
- const [word, number] = l.slice(-2);
229
- if (word.toLowerCase() === "tier") {
230
- const n = Number(number || DEFAULT_TIER);
231
- return Number.isNaN(n) ? DEFAULT_TIER : n;
232
- }
233
- return DEFAULT_TIER;
228
+ const index = l.findIndex(w => w.toLowerCase() === "tier");
229
+ if (index < 0)
230
+ return DEFAULT_TIER;
231
+ const number = l[index + 1];
232
+ const n = Number(number || DEFAULT_TIER);
233
+ return Number.isNaN(n) ? DEFAULT_TIER : n;
234
234
  }
235
235
  static getType(name) {
236
236
  const [identity = ""] = name.split(" ") || [];
@@ -33,10 +33,13 @@ type FarmInfoOutput = ExcludeArrayProps<FarmAccounting.InfoStructOutput>;
33
33
  export type FarmInfo = FarmInfoOutput & {
34
34
  symbol: SupportedToken;
35
35
  };
36
+ type PoolsWithExtraRewardsList = Record<NetworkType, Array<SupportedToken>>;
36
37
  export interface GetLmRewardsInfoProps {
37
38
  currentTokenData: Record<SupportedToken, string>;
38
39
  provider: Provider | Signer;
39
40
  multicallAddress: string;
41
+ poolsWithExtraRewards?: PoolsWithExtraRewardsList;
42
+ network: NetworkType;
40
43
  }
41
44
  export interface GetLmRewardsProps {
42
45
  baseRewardPoolsInfo: Record<string, FarmInfo>;
@@ -58,18 +61,17 @@ export interface ClaimLmRewardsV3Props {
58
61
  signer: Signer;
59
62
  }
60
63
  export declare class GearboxRewardsApi {
61
- static getLmRewardsInfo({ currentTokenData, provider, multicallAddress, }: GetLmRewardsInfoProps): Promise<{
64
+ static getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards, network, }: GetLmRewardsInfoProps): Promise<{
62
65
  rewardPoolsInfo: Record<string, FarmInfo[]>;
63
66
  baseRewardPoolsInfo: Record<string, FarmInfo>;
67
+ extraRewardPoolsInfo: Record<string, FarmInfo[]>;
64
68
  rewardPoolsSupply: Record<string, bigint>;
65
69
  }>;
66
70
  static getLmRewardsV2({ provider, account, currentTokenData, network, airdropDistributorAddress, }: GetLmRewardsProps): Promise<{
67
- rewards: GearboxLmReward[][];
68
- totalAvailable: bigint;
71
+ rewards: GearboxLmReward[];
69
72
  }>;
70
73
  static getLmRewardsV3({ baseRewardPoolsInfo, currentTokenData, provider, account, network, }: GetLmRewardsProps): Promise<{
71
- rewards: GearboxLmReward[][];
72
- totalAvailable: bigint;
74
+ rewards: (GearboxLmReward | GearboxLmReward[])[];
73
75
  }>;
74
76
  static claimLmRewardsV2({ signer, account, provider, network, airdropDistributorAddress, }: ClaimLmRewardsV2Props): Promise<import("ethers").TransactionResponse | import("../utils/calls").MinimalTxInfo>;
75
77
  static claimLmRewardsV3({ reward, signer }: ClaimLmRewardsV3Props): Promise<import("ethers").TransactionResponse | import("../utils/calls").MinimalTxInfo>;
@@ -7,38 +7,20 @@ exports.GearboxRewardsApi = void 0;
7
7
  const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const ethers_1 = require("ethers");
10
- const endpoint_1 = require("../core/endpoint");
11
10
  const types_1 = require("../types");
12
11
  const calls_1 = require("../utils/calls");
13
12
  const formatter_1 = require("../utils/formatter");
14
13
  const math_1 = require("../utils/math");
15
14
  const abi_1 = require("./abi");
16
- const EXTRA_LM_MINING = {
17
- [sdk_gov_1.tokenDataByNetwork.Mainnet.sdGHOV3.toLowerCase()]: (_) => {
18
- const REWARD_PERIOD = 14 * 24 * 60 * 60;
19
- // const REWARDS_1_END = 1712844000;
20
- // const REWARDS_2_END = 1714150800;
21
- // const REWARDS_3_END = 1715374800;
22
- // const REWARDS_4_END = 1716793200;
23
- const REWARDS_5_END = 1718024669;
24
- // const REWARD_1_PART = toBN("15000", decimals.GHO);
25
- // const REWARD_2_PART = toBN("15000", decimals.GHO);
26
- // const REWARD_3_PART = toBN("15000", decimals.GHO);
27
- // const REWARD_4_PART = toBN("7500", decimals.GHO);
28
- const REWARD_5_PART = (0, formatter_1.toBN)("3750", sdk_gov_1.decimals.GHO);
29
- const reward = REWARD_5_PART;
30
- const finished = REWARDS_5_END;
31
- return {
32
- balance: 0n,
33
- duration: BigInt(REWARD_PERIOD),
34
- finished: BigInt(finished),
35
- reward: reward,
36
- symbol: "GHO",
37
- };
38
- },
15
+ const merklAPI_1 = require("./merklAPI");
16
+ const DEFAULT_POOLS_WITH_EXTRA_REWARDS = {
17
+ Mainnet: ["sdGHOV3", "sdcrvUSDV3"],
18
+ Arbitrum: [],
19
+ Optimism: [],
20
+ Base: [],
39
21
  };
40
22
  class GearboxRewardsApi {
41
- static async getLmRewardsInfo({ currentTokenData, provider, multicallAddress, }) {
23
+ static async getLmRewardsInfo({ currentTokenData, provider, multicallAddress, poolsWithExtraRewards = DEFAULT_POOLS_WITH_EXTRA_REWARDS, network, }) {
42
24
  const poolTokens = sdk_gov_1.TypedObjectUtils.entries(currentTokenData).filter(([symbol]) => (0, sdk_gov_1.isDieselStakedToken)(symbol));
43
25
  const farmInfoCalls = poolTokens.map(([, address]) => ({
44
26
  address: address,
@@ -61,24 +43,56 @@ class GearboxRewardsApi {
61
43
  interface: abi_1.MULTICALL_EXTENDED_INTERFACE,
62
44
  method: "getCurrentBlockTimestamp()",
63
45
  };
64
- const [blockTimestamp, ...mcResponse] = await (0, sdk_gov_1.multicall)([
65
- blockTimestampCall,
66
- ...farmInfoCalls,
67
- ...farmSupplyCalls,
68
- ...rewardTokenCalls,
69
- ], provider);
46
+ const tokenWithExtraRewards = poolsWithExtraRewards[network] || [];
47
+ const chainId = sdk_gov_1.CHAINS[network];
48
+ const [[blockTimestamp, ...mcResponse], ...extraRewardsResponses] = await Promise.all([
49
+ (0, sdk_gov_1.multicall)([
50
+ blockTimestampCall,
51
+ ...farmInfoCalls,
52
+ ...farmSupplyCalls,
53
+ ...rewardTokenCalls,
54
+ ], provider),
55
+ ...tokenWithExtraRewards.map(symbol => axios_1.default.get(merklAPI_1.MerkleXYZApi.getRewardsCampaignsUrl({
56
+ params: {
57
+ chainId,
58
+ mainParameter: (0, ethers_1.getAddress)(currentTokenData[symbol]),
59
+ },
60
+ }))),
61
+ ]);
70
62
  const farmInfoCallsEnd = farmInfoCalls.length;
71
63
  const farmInfo = mcResponse.slice(0, farmInfoCallsEnd);
72
64
  const farmSupplyCallsEnd = farmInfoCallsEnd + farmSupplyCalls.length;
73
65
  const farmSupply = mcResponse.slice(farmInfoCallsEnd, farmSupplyCallsEnd);
74
66
  const rewardTokenCallsEnd = farmSupplyCallsEnd + rewardTokenCalls.length;
75
67
  const rewardTokens = mcResponse.slice(farmSupplyCallsEnd, rewardTokenCallsEnd);
68
+ const extraRewards = extraRewardsResponses.reduce((acc, r, index) => {
69
+ const stakedSymbol = tokenWithExtraRewards[index];
70
+ const l = r.data.reduce((infos, d) => {
71
+ const finished = (0, sdk_gov_1.toBigInt)(d.endTimestamp || 0);
72
+ if (finished - blockTimestamp > 0) {
73
+ const rewardTokenLc = (d.rewardToken || "").toLowerCase();
74
+ const [rewardSymbol, decimals = 18] = (0, sdk_gov_1.extractTokenData)(rewardTokenLc);
75
+ const reward = (0, formatter_1.toBN)(d.amountDecimal, decimals);
76
+ if (rewardSymbol && reward > 0) {
77
+ infos.push({
78
+ duration: (0, sdk_gov_1.toBigInt)(d.endTimestamp - d.startTimestamp),
79
+ finished,
80
+ reward,
81
+ balance: 0n,
82
+ symbol: rewardSymbol,
83
+ });
84
+ }
85
+ }
86
+ return infos;
87
+ }, []);
88
+ acc[currentTokenData[stakedSymbol]] = l;
89
+ return acc;
90
+ }, {});
76
91
  const rewardPoolsInfo = poolTokens.reduce((acc, [, address], i) => {
77
92
  const currentInfo = farmInfo[i];
78
93
  const [symbol] = (0, sdk_gov_1.extractTokenData)(rewardTokens[i] || "");
79
94
  if (!symbol)
80
95
  throw new Error(`Can't get reward token for: ${(0, sdk_gov_1.extractTokenData)(address)[0]} [${address}]`);
81
- const otherRewards = EXTRA_LM_MINING[address];
82
96
  const baseReward = {
83
97
  duration: currentInfo.duration,
84
98
  finished: currentInfo.finished,
@@ -86,13 +100,12 @@ class GearboxRewardsApi {
86
100
  balance: currentInfo.balance,
87
101
  symbol: symbol,
88
102
  };
89
- const extraReward = otherRewards
90
- ? [otherRewards(Number(blockTimestamp))]
91
- : [];
103
+ const extra = extraRewards[address] || [];
92
104
  acc.base[address] = baseReward;
93
- acc.all[address] = [baseReward, ...extraReward];
105
+ acc.extra[address] = extra;
106
+ acc.all[address] = [baseReward, ...extra];
94
107
  return acc;
95
- }, { base: {}, all: {} });
108
+ }, { base: {}, extra: {}, all: {} });
96
109
  const rewardPoolsSupply = poolTokens.reduce((acc, [, address], i) => {
97
110
  acc[address] = farmSupply[i] || 0n;
98
111
  return acc;
@@ -100,12 +113,13 @@ class GearboxRewardsApi {
100
113
  return {
101
114
  rewardPoolsInfo: rewardPoolsInfo.all,
102
115
  baseRewardPoolsInfo: rewardPoolsInfo.base,
116
+ extraRewardPoolsInfo: rewardPoolsInfo.extra,
103
117
  rewardPoolsSupply,
104
118
  };
105
119
  }
106
120
  static async getLmRewardsV2({ provider, account, currentTokenData, network, airdropDistributorAddress, }) {
107
121
  if (!airdropDistributorAddress)
108
- return { rewards: [], totalAvailable: 0n };
122
+ return { rewards: [] };
109
123
  const distributor = types_1.IAirdropDistributor__factory.connect(airdropDistributorAddress, provider);
110
124
  const [claimedResp, merkleDataResp] = await Promise.all([
111
125
  this.getClaimed({ distributor, account }),
@@ -124,8 +138,7 @@ class GearboxRewardsApi {
124
138
  rewardToken: currentTokenData.GEAR,
125
139
  },
126
140
  ];
127
- const totalAvailable = rewards.reduce((sum, r) => sum + (r.amount || 0n), 0n);
128
- return { rewards: [rewards], totalAvailable };
141
+ return { rewards: rewards };
129
142
  }
130
143
  static async getLmRewardsV3({ baseRewardPoolsInfo, currentTokenData, provider, account, network, }) {
131
144
  const poolTokens = Object.keys(baseRewardPoolsInfo);
@@ -135,29 +148,40 @@ class GearboxRewardsApi {
135
148
  method: "farmed(address)",
136
149
  params: [account],
137
150
  }));
138
- const hasGHOReward = network === "Mainnet" && EXTRA_LM_MINING[currentTokenData.sdGHOV3];
139
151
  const [gearboxLmResponse, merkleXYZLMResponse] = await Promise.allSettled([
140
152
  (0, sdk_gov_1.multicall)(farmedCalls, provider),
141
- hasGHOReward
142
- ? axios_1.default.get(MerkleXYZApi.getRewardsUrl({
143
- params: {
144
- chainId: 1,
145
- user: (0, ethers_1.getAddress)(account),
146
- mainParameter: (0, ethers_1.getAddress)(currentTokenData.sdGHOV3),
147
- rewardToken: (0, ethers_1.getAddress)(currentTokenData.GHO),
148
- },
149
- }))
150
- : undefined,
153
+ axios_1.default.get(merklAPI_1.MerkleXYZApi.getUserRewardsUrl({
154
+ params: {
155
+ chainId: sdk_gov_1.CHAINS[network],
156
+ user: (0, ethers_1.getAddress)(account),
157
+ },
158
+ })),
151
159
  ]);
152
160
  const gearboxLm = gearboxLmResponse.status === "fulfilled" ? gearboxLmResponse.value : [];
153
161
  const merkleXYZLM = merkleXYZLMResponse.status === "fulfilled"
154
162
  ? merkleXYZLMResponse.value?.data
155
163
  : undefined;
156
- const merkleXYZLMLc = Object.entries(merkleXYZLM || {}).reduce((acc, [k, v]) => {
157
- acc[k.toLowerCase()] = v;
164
+ const PREFIX = "ERC20";
165
+ const REWARD_KEYS_RECORD = poolTokens.reduce((acc, t) => {
166
+ const key = [PREFIX, (0, ethers_1.getAddress)(t)].join("_");
167
+ acc[key] = t;
158
168
  return acc;
159
169
  }, {});
160
- const ghoLM = merkleXYZLMLc[currentTokenData.GHO];
170
+ const extraRewards = Object.entries(merkleXYZLM || {}).reduce((acc, [k, v]) => {
171
+ const rewardToken = k.toLowerCase();
172
+ Object.entries(v.reasons).forEach(([key, reason]) => {
173
+ const poolToken = REWARD_KEYS_RECORD[key];
174
+ if (poolToken && sdk_gov_1.tokenSymbolByAddress[rewardToken]) {
175
+ acc.push({
176
+ poolToken,
177
+ rewardToken,
178
+ amount: (0, sdk_gov_1.toBigInt)(reason.unclaimed || 0n),
179
+ type: "extraMerkle",
180
+ });
181
+ }
182
+ });
183
+ return acc;
184
+ }, []);
161
185
  const gearboxLmRewards = poolTokens.map((address, i) => {
162
186
  return {
163
187
  poolToken: address,
@@ -166,38 +190,18 @@ class GearboxRewardsApi {
166
190
  type: "stakedV3",
167
191
  };
168
192
  });
169
- const { zero, nonZero, total } = gearboxLmRewards.reduce((acc, r) => {
193
+ const { zero, nonZero } = gearboxLmRewards.reduce((acc, r) => {
170
194
  const amount = r.amount || 0n;
171
195
  if (amount > 0n) {
172
- acc.nonZero.push([r]);
196
+ acc.nonZero.push(r);
173
197
  }
174
198
  else {
175
199
  acc.zero.push(r);
176
200
  }
177
- acc.total = acc.total + amount;
178
201
  return acc;
179
- }, { total: 0n, nonZero: [], zero: [] });
180
- const extraRewards = ghoLM
181
- ? [
182
- [
183
- {
184
- poolToken: currentTokenData.sdGHOV3,
185
- rewardToken: currentTokenData.GHO,
186
- amount: (0, sdk_gov_1.toBigInt)(ghoLM.unclaimed),
187
- type: "extraMerkle",
188
- },
189
- ],
190
- ]
191
- : [];
192
- const extraTotal = extraRewards.reduce((sum, group) => {
193
- const groupTotal = group.reduce((groupSum, reward) => {
194
- return groupSum + (reward.amount || 0n);
195
- }, 0n);
196
- return sum + groupTotal;
197
- }, 0n);
202
+ }, { nonZero: [], zero: [] });
198
203
  return {
199
204
  rewards: [...nonZero, ...extraRewards, zero],
200
- totalAvailable: total + extraTotal,
201
205
  };
202
206
  }
203
207
  static async claimLmRewardsV2({ signer, account, provider, network, airdropDistributorAddress, }) {
@@ -239,11 +243,6 @@ class GearboxRewardsApi {
239
243
  }
240
244
  }
241
245
  exports.GearboxRewardsApi = GearboxRewardsApi;
242
- // https://api.merkl.xyz/v3/campaignsForMainParameter?chainId=1&mainParameter=0xE2037090f896A858E3168B978668F22026AC52e7
243
- class MerkleXYZApi {
244
- static domain = "https://api.merkl.xyz/v3";
245
- static getRewardsUrl = (options) => endpoint_1.ChartsApi.getRelativeUrl([this.domain, "userRewards"].join("/"), options);
246
- }
247
246
  const POOL_REWARDS_ABI = [
248
247
  {
249
248
  inputs: [],
@@ -0,0 +1,43 @@
1
+ import { BigNumberish } from "ethers";
2
+ interface UserOptions {
3
+ params: {
4
+ user: string;
5
+ chainId: number;
6
+ mainParameter?: string;
7
+ rewardToken?: string;
8
+ };
9
+ }
10
+ export interface MerkleXYZUserRewards {
11
+ accumulated: BigNumberish;
12
+ decimals: number;
13
+ reasons: Record<string, {
14
+ accumulated: BigNumberish;
15
+ unclaimed: BigNumberish;
16
+ }>;
17
+ symbol: string;
18
+ unclaimed: BigNumberish;
19
+ }
20
+ export type MerkleXYZUserRewardsResponse = Record<string, MerkleXYZUserRewards>;
21
+ interface CampaignsOptions {
22
+ params: {
23
+ chainId: number;
24
+ mainParameter?: string;
25
+ rewardToken?: string;
26
+ };
27
+ }
28
+ interface Campaign {
29
+ amountDecimal: string;
30
+ campaignId: string;
31
+ campaignType: number;
32
+ endTimestamp: number;
33
+ rewardToken: string;
34
+ rewardTokenSymbol: string;
35
+ startTimestamp: number;
36
+ }
37
+ export type MerkleXYZRewardsCampaignsResponse = Array<Campaign>;
38
+ export declare class MerkleXYZApi {
39
+ static domain: string;
40
+ static getUserRewardsUrl: (options: UserOptions) => string;
41
+ static getRewardsCampaignsUrl: (options: CampaignsOptions) => string;
42
+ }
43
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MerkleXYZApi = void 0;
4
+ const endpoint_1 = require("../core/endpoint");
5
+ // https://api.merkl.xyz/v3/campaignsForMainParameter?chainId=1&mainParameter=0xE2037090f896A858E3168B978668F22026AC52e7
6
+ class MerkleXYZApi {
7
+ static domain = "https://api.merkl.xyz/v3";
8
+ static getUserRewardsUrl = (options) => endpoint_1.ChartsApi.getRelativeUrl([this.domain, "userRewards"].join("/"), options);
9
+ static getRewardsCampaignsUrl = (options) => endpoint_1.ChartsApi.getRelativeUrl([this.domain, "campaignsForMainParameter"].join("/"), options);
10
+ }
11
+ exports.MerkleXYZApi = MerkleXYZApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.194",
3
+ "version": "3.0.0-next.196",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@gearbox-protocol/bots-v3": "^1.5.1",
34
- "@gearbox-protocol/sdk-gov": "^2.7.0",
34
+ "@gearbox-protocol/sdk-gov": "^2.7.3",
35
35
  "axios": "^1.2.6",
36
36
  "decimal.js-light": "^2.5.1",
37
37
  "deep-eql": "^4.1.0",