@gearbox-protocol/sdk 3.0.0-next.283 → 3.0.0-next.284

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.
@@ -2,6 +2,7 @@ import { NetworkType, SupportedToken } from "@gearbox-protocol/sdk-gov";
2
2
  import { Address, PublicClient, WalletClient } from "viem";
3
3
  import { PoolData } from "../core/pool";
4
4
  import { TokenData } from "../tokens/tokenData";
5
+ import { ExtraRewardApy } from "./apy";
5
6
  export interface GearboxExtraMerkleLmReward {
6
7
  pool: Address;
7
8
  poolToken: Address;
@@ -41,16 +42,15 @@ export interface FarmInfo {
41
42
  balance: bigint;
42
43
  symbol: SupportedToken;
43
44
  }
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
48
  tokensList: Record<Address, TokenData>;
49
49
  provider: PublicClient;
50
- multicallAddress: Address;
51
- poolsWithExtraRewards?: PoolsWithExtraRewardsList;
52
- network: NetworkType;
53
- reportError?: ReportHandler;
50
+ }
51
+ export interface GetExtraRewardsProps {
52
+ chainId: number;
53
+ tokensList: Record<Address, TokenData>;
54
54
  }
55
55
  export interface GetLmRewardsProps {
56
56
  baseRewardPoolsInfo: Record<string, FarmInfo>;
@@ -75,10 +75,10 @@ export interface ClaimLmRewardsV3Props {
75
75
  signer: WalletClient;
76
76
  }
77
77
  export declare class GearboxRewardsApi {
78
- static getLmRewardsInfo({ pools, provider, multicallAddress, tokensList, poolsWithExtraRewards, network, reportError, }: GetLmRewardsInfoProps): Promise<{
78
+ static getExtraRewards({ chainId, tokensList }: GetExtraRewardsProps): Promise<Record<`0x${string}`, ExtraRewardApy[]>>;
79
+ static getLmRewardsInfo({ pools, provider, tokensList, }: GetLmRewardsInfoProps): Promise<{
79
80
  rewardPoolsInfo: Record<string, FarmInfo[]>;
80
81
  baseRewardPoolsInfo: Record<string, FarmInfo>;
81
- extraRewardPoolsInfo: Record<string, FarmInfo[]>;
82
82
  rewardPoolsSupply: Record<string, bigint>;
83
83
  }>;
84
84
  static getLmRewardsV2({ provider, account, currentTokenData, network, airdropDistributorAddress, }: GetLmRewardsProps): Promise<{
@@ -9,19 +9,35 @@ const axios_1 = __importDefault(require("axios"));
9
9
  const viem_1 = require("viem");
10
10
  const endpoint_1 = require("../core/endpoint");
11
11
  const types_1 = require("../types");
12
- const formatter_1 = require("../utils/formatter");
13
12
  const math_1 = require("../utils/math");
14
13
  const merklAPI_1 = require("./merklAPI");
15
- const DEFAULT_POOLS_WITH_EXTRA_REWARDS = {
16
- Mainnet: [
17
- "0x7354EC6E852108411e681D13E11185c3a2567981", // dtBTCV3
18
- ],
19
- Arbitrum: [],
20
- Optimism: [],
21
- Base: [],
22
- };
23
14
  class GearboxRewardsApi {
24
- static async getLmRewardsInfo({ pools, provider, multicallAddress, tokensList, poolsWithExtraRewards = DEFAULT_POOLS_WITH_EXTRA_REWARDS, network, reportError, }) {
15
+ static async getExtraRewards({ chainId, tokensList }) {
16
+ const res = await axios_1.default.get(merklAPI_1.MerkleXYZApi.getGearboxCampaignsUrl());
17
+ const currentActiveCampaigns = res.data.filter(c => c.status === "LIVE" && c.chainId === chainId);
18
+ const r = currentActiveCampaigns.reduce((acc, campaign) => {
19
+ const rewardSource = (campaign.tokens[0]?.address || campaign.identifier).toLowerCase();
20
+ const allRewards = campaign.rewardsRecord.breakdowns
21
+ .map((r, i) => {
22
+ const tokenLc = r.token.address.toLowerCase();
23
+ const { symbol = r.token.symbol } = tokensList[tokenLc] || {};
24
+ const apy = campaign.aprRecord.breakdowns[i]?.value || 0;
25
+ const apyObject = {
26
+ token: rewardSource,
27
+ balance: null,
28
+ apy: apy,
29
+ rewardToken: tokenLc,
30
+ rewardTokenSymbol: symbol,
31
+ };
32
+ return apyObject;
33
+ })
34
+ .filter(r => r.apy > 0);
35
+ acc[rewardSource] = [...(acc[rewardSource] || []), ...allRewards];
36
+ return acc;
37
+ }, {});
38
+ return r;
39
+ }
40
+ static async getLmRewardsInfo({ pools, provider, tokensList, }) {
25
41
  const poolByStakedDiesel = Object.values(pools).reduce((acc, p) => {
26
42
  p.stakedDieselToken.forEach(t => {
27
43
  if (t)
@@ -40,15 +56,6 @@ class GearboxRewardsApi {
40
56
  const poolByItsToken = { ...poolByStakedDiesel, ...poolByDiesel };
41
57
  const poolStakedTokens = sdk_gov_1.TypedObjectUtils.keys(poolByStakedDiesel);
42
58
  const allPoolTokens = sdk_gov_1.TypedObjectUtils.keys(poolByItsToken);
43
- const chainId = sdk_gov_1.CHAINS[network];
44
- const poolTokensWithExtraReward = (poolsWithExtraRewards[network] || []).filter(p => {
45
- const token = tokensList[p.toLowerCase()];
46
- if (!token) {
47
- console.error(`Pool token not found ${p}`);
48
- return false;
49
- }
50
- return true;
51
- });
52
59
  const farmInfoCalls = poolStakedTokens.map(address => ({
53
60
  address,
54
61
  abi: types_1.iFarmingPoolAbi,
@@ -67,34 +74,13 @@ class GearboxRewardsApi {
67
74
  functionName: "rewardsToken",
68
75
  args: [],
69
76
  }));
70
- const [mc, ...extra] = await Promise.allSettled([
71
- provider.multicall({
72
- allowFailure: false,
73
- multicallAddress: sdk_gov_1.MULTICALL_ADDRESS,
74
- contracts: [
75
- {
76
- address: multicallAddress,
77
- abi: types_1.iMulticall3Abi,
78
- functionName: "getCurrentBlockTimestamp",
79
- args: [],
80
- },
81
- ...farmInfoCalls,
82
- ...farmSupplyCalls,
83
- ...rewardTokenCalls,
84
- ],
85
- }),
86
- ...poolTokensWithExtraReward.map(t => {
87
- return axios_1.default.get(merklAPI_1.MerkleXYZApi.getRewardsCampaignsUrl({
88
- params: {
89
- chainId,
90
- mainParameter: (0, viem_1.getAddress)(t),
91
- },
92
- }));
93
- }),
94
- ]);
95
- const mcResponse = this.extractFulfilled(mc, reportError, "rewardsInfoMulticall") || [];
96
- const [ts = 0n, ...restMCResponse] = mcResponse;
97
- const blockTimestamp = ts || 0n;
77
+ const mc = await provider.multicall({
78
+ allowFailure: false,
79
+ multicallAddress: sdk_gov_1.MULTICALL_ADDRESS,
80
+ contracts: [...farmInfoCalls, ...farmSupplyCalls, ...rewardTokenCalls],
81
+ });
82
+ const mcResponse = mc;
83
+ const [...restMCResponse] = mcResponse;
98
84
  const farmInfoCallsEnd = farmInfoCalls.length;
99
85
  const farmInfo = restMCResponse.slice(0, farmInfoCallsEnd);
100
86
  const farmSupplyCallsEnd = farmInfoCallsEnd + farmSupplyCalls.length;
@@ -114,34 +100,6 @@ class GearboxRewardsApi {
114
100
  }
115
101
  return acc;
116
102
  }, {});
117
- const extraRewards = extra.reduce((acc, r, index) => {
118
- const p = poolTokensWithExtraReward[index].toLowerCase();
119
- const safeResp = this.extractFulfilled(r, reportError, `merkleCampaign: ${p}`);
120
- const l = safeResp?.data.reduce((infos, d) => {
121
- const started = (0, sdk_gov_1.toBigInt)(d.startTimestamp || 0);
122
- const finished = (0, sdk_gov_1.toBigInt)(d.endTimestamp || 0);
123
- if (blockTimestamp >= started && blockTimestamp <= finished) {
124
- const rewardTokenLc = (d.rewardToken || "").toLowerCase();
125
- const rewardTokenData = tokensList[rewardTokenLc];
126
- const reward = (0, formatter_1.toBN)(d.amountDecimal, rewardTokenData?.decimals || 18);
127
- if (rewardTokenData && reward > 0) {
128
- infos.push({
129
- pool: poolByItsToken[p],
130
- duration: (0, sdk_gov_1.toBigInt)(d.endTimestamp - d.startTimestamp),
131
- finished,
132
- reward,
133
- balance: 0n,
134
- symbol: rewardTokenData.symbol,
135
- });
136
- }
137
- }
138
- return infos;
139
- }, []);
140
- if (l) {
141
- acc[p] = l;
142
- }
143
- return acc;
144
- }, {});
145
103
  const stakedTokenRewards = allPoolTokens.reduce((acc, pool) => {
146
104
  const info = infoByPool[pool];
147
105
  const token = rewardTokenPool[pool];
@@ -156,13 +114,11 @@ class GearboxRewardsApi {
156
114
  symbol: tokenData.symbol,
157
115
  }
158
116
  : undefined;
159
- const extra = extraRewards[pool] || [];
160
117
  if (baseReward)
161
118
  acc.base[pool] = baseReward;
162
- acc.extra[pool] = extra;
163
- acc.all[pool] = [...(baseReward ? [baseReward] : []), ...extra];
119
+ acc.all[pool] = [...(baseReward ? [baseReward] : [])];
164
120
  return acc;
165
- }, { base: {}, extra: {}, all: {} });
121
+ }, { base: {}, all: {} });
166
122
  const rewardPoolsSupply = allPoolTokens.reduce((acc, address, i) => {
167
123
  acc[address] = farmSupply[i] || 0n;
168
124
  return acc;
@@ -170,7 +126,6 @@ class GearboxRewardsApi {
170
126
  return {
171
127
  rewardPoolsInfo: stakedTokenRewards.all,
172
128
  baseRewardPoolsInfo: stakedTokenRewards.base,
173
- extraRewardPoolsInfo: stakedTokenRewards.extra,
174
129
  rewardPoolsSupply,
175
130
  };
176
131
  }
@@ -21,7 +21,8 @@ export interface ExtraRewardApy {
21
21
  token: Address;
22
22
  balance: bigint | null;
23
23
  apy: number;
24
- rewardInfo: FarmInfo;
24
+ rewardToken: Address;
25
+ rewardTokenSymbol: string;
25
26
  }
26
27
  interface GetPoolExtraAPY_V3Props {
27
28
  stakedDieselToken: Address | undefined;
@@ -47,7 +47,8 @@ class GearboxRewardsApy {
47
47
  token: stakedDieselToken,
48
48
  balance: null,
49
49
  apy: r,
50
- rewardInfo: rewardPoolsInfo,
50
+ rewardToken: rewardAddress,
51
+ rewardTokenSymbol: rewardPoolsInfo.symbol,
51
52
  };
52
53
  }
53
54
  static calculateAPY_V3({ info, supply, reward, currentTimestamp, }) {
@@ -103,7 +104,13 @@ class GearboxRewardsApy {
103
104
  decimals: rewardDecimals,
104
105
  },
105
106
  }) / Number(sdk_gov_1.PERCENTAGE_FACTOR);
106
- return { token, balance, rewardInfo, apy: r };
107
+ return {
108
+ token,
109
+ balance,
110
+ apy: r,
111
+ rewardToken: rewardAddress,
112
+ rewardTokenSymbol: rewardInfo.symbol,
113
+ };
107
114
  }
108
115
  }
109
116
  exports.GearboxRewardsApy = GearboxRewardsApy;
@@ -1,3 +1,4 @@
1
+ import { Address } from "viem";
1
2
  import { BigNumberish } from "../utils/formatter";
2
3
  interface UserOptions {
3
4
  params: {
@@ -18,13 +19,79 @@ export interface MerkleXYZUserRewards {
18
19
  unclaimed: BigNumberish;
19
20
  }
20
21
  export type MerkleXYZUserRewardsResponse = Record<string, MerkleXYZUserRewards>;
21
- interface CampaignsOptions {
22
- params: {
22
+ export interface MerklXYZV4Campaign {
23
+ chainId: number;
24
+ type: string;
25
+ identifier: Address;
26
+ name: string;
27
+ status: "LIVE" | "PAST";
28
+ action: "LEND" | "BORROW";
29
+ tvl: number;
30
+ apr: number;
31
+ dailyRewards: number;
32
+ tags: Array<string>;
33
+ id: string;
34
+ tokens: Array<{
35
+ id: string;
36
+ name: string;
23
37
  chainId: number;
24
- mainParameter?: string;
25
- rewardToken?: string;
38
+ address: Address;
39
+ decimals: number;
40
+ icon: string;
41
+ verified: boolean;
42
+ isTest: boolean;
43
+ price: number | null;
44
+ symbol: string;
45
+ }>;
46
+ chain: {
47
+ id: number;
48
+ name: string;
49
+ icon: string;
50
+ };
51
+ aprRecord: {
52
+ cumulated: number;
53
+ timestamp: string;
54
+ breakdowns: Array<{
55
+ id: number;
56
+ identifier: Address;
57
+ type: "CAMPAIGN";
58
+ value: number;
59
+ aprRecordId: string;
60
+ }>;
61
+ };
62
+ tvlRecord: {
63
+ id: string;
64
+ total: number;
65
+ timestamp: string;
66
+ breakdowns: [];
67
+ };
68
+ rewardsRecord: {
69
+ id: string;
70
+ total: number;
71
+ timestamp: string;
72
+ breakdowns: Array<{
73
+ token: {
74
+ id: string;
75
+ name: string;
76
+ chainId: number;
77
+ address: Address;
78
+ decimals: 18;
79
+ symbol: string;
80
+ displaySymbol: string;
81
+ icon: string;
82
+ verified: boolean;
83
+ isTest: boolean;
84
+ price: number;
85
+ };
86
+ amount: string;
87
+ id: number;
88
+ value: number;
89
+ campaignId: string;
90
+ dailyRewardsRecordid: string;
91
+ }>;
26
92
  };
27
93
  }
94
+ export type MerkleXYZV4CampaignsResponse = Array<MerklXYZV4Campaign>;
28
95
  interface Campaign {
29
96
  amountDecimal: string;
30
97
  campaignId: string;
@@ -38,6 +105,6 @@ export type MerkleXYZRewardsCampaignsResponse = Array<Campaign>;
38
105
  export declare class MerkleXYZApi {
39
106
  static domain: string;
40
107
  static getUserRewardsUrl: (options: UserOptions) => string;
41
- static getRewardsCampaignsUrl: (options: CampaignsOptions) => string;
108
+ static getGearboxCampaignsUrl: () => string;
42
109
  }
43
110
  export {};
@@ -6,6 +6,6 @@ const endpoint_1 = require("../core/endpoint");
6
6
  class MerkleXYZApi {
7
7
  static domain = "https://api.merkl.xyz/v3";
8
8
  static getUserRewardsUrl = (options) => endpoint_1.URLApi.getRelativeUrl([this.domain, "userRewards"].join("/"), options);
9
- static getRewardsCampaignsUrl = (options) => endpoint_1.URLApi.getRelativeUrl([this.domain, "campaignsForMainParameter"].join("/"), options);
9
+ static getGearboxCampaignsUrl = () => "https://api.merkl.xyz/v4/opportunities?name=gearbox";
10
10
  }
11
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.283",
3
+ "version": "3.0.0-next.284",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",