@gearbox-protocol/sdk 3.0.0-next.283 → 3.0.0-next.285
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
|
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,56 @@ 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
|
|
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 aprIdsList = currentActiveCampaigns
|
|
19
|
+
.map(c =>
|
|
20
|
+
// apr token for campaigns with a single reward is obvious
|
|
21
|
+
c.aprRecord.breakdowns.length > 1
|
|
22
|
+
? c.aprRecord.breakdowns.map(b => {
|
|
23
|
+
return {
|
|
24
|
+
campaignId: c.id,
|
|
25
|
+
aprId: b.identifier,
|
|
26
|
+
};
|
|
27
|
+
})
|
|
28
|
+
: [])
|
|
29
|
+
.flat(1);
|
|
30
|
+
const aprIdsResponse = await Promise.allSettled(aprIdsList.map(id => axios_1.default.get(merklAPI_1.MerkleXYZApi.getGearboxRewardCampaignUrl(id.aprId))));
|
|
31
|
+
const aprCampaignByAPRId = aprIdsResponse.reduce((acc, r, i) => {
|
|
32
|
+
const id = aprIdsList[i].aprId;
|
|
33
|
+
acc[id] = r.status === "fulfilled" ? r.value.data : undefined;
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
const r = currentActiveCampaigns.reduce((acc, campaign) => {
|
|
37
|
+
const rewardSource = (campaign.tokens[0]?.address || campaign.identifier).toLowerCase();
|
|
38
|
+
const allRewards = campaign.aprRecord.breakdowns
|
|
39
|
+
.map((r, i) => {
|
|
40
|
+
const apy = r.value;
|
|
41
|
+
const { rewardToken } = aprCampaignByAPRId[r.identifier]?.[0] || {};
|
|
42
|
+
const tokenRewardsRecord = campaign.rewardsRecord.breakdowns[i]?.token;
|
|
43
|
+
const { address = tokenRewardsRecord?.address || "" } = rewardToken || {};
|
|
44
|
+
const tokenLc = address.toLowerCase();
|
|
45
|
+
const { symbol = rewardToken?.symbol || tokenRewardsRecord?.symbol || "", } = tokensList[tokenLc] || {};
|
|
46
|
+
const apyObject = {
|
|
47
|
+
token: rewardSource,
|
|
48
|
+
balance: null,
|
|
49
|
+
apy: apy,
|
|
50
|
+
rewardToken: tokenLc,
|
|
51
|
+
rewardTokenSymbol: symbol,
|
|
52
|
+
};
|
|
53
|
+
return apyObject;
|
|
54
|
+
})
|
|
55
|
+
.filter(r => r.apy > 0);
|
|
56
|
+
acc[rewardSource] = [...(acc[rewardSource] || []), ...allRewards];
|
|
57
|
+
return acc;
|
|
58
|
+
}, {});
|
|
59
|
+
return r;
|
|
60
|
+
}
|
|
61
|
+
static async getLmRewardsInfo({ pools, provider, tokensList, }) {
|
|
25
62
|
const poolByStakedDiesel = Object.values(pools).reduce((acc, p) => {
|
|
26
63
|
p.stakedDieselToken.forEach(t => {
|
|
27
64
|
if (t)
|
|
@@ -40,15 +77,6 @@ class GearboxRewardsApi {
|
|
|
40
77
|
const poolByItsToken = { ...poolByStakedDiesel, ...poolByDiesel };
|
|
41
78
|
const poolStakedTokens = sdk_gov_1.TypedObjectUtils.keys(poolByStakedDiesel);
|
|
42
79
|
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
80
|
const farmInfoCalls = poolStakedTokens.map(address => ({
|
|
53
81
|
address,
|
|
54
82
|
abi: types_1.iFarmingPoolAbi,
|
|
@@ -67,34 +95,13 @@ class GearboxRewardsApi {
|
|
|
67
95
|
functionName: "rewardsToken",
|
|
68
96
|
args: [],
|
|
69
97
|
}));
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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;
|
|
98
|
+
const mc = await provider.multicall({
|
|
99
|
+
allowFailure: false,
|
|
100
|
+
multicallAddress: sdk_gov_1.MULTICALL_ADDRESS,
|
|
101
|
+
contracts: [...farmInfoCalls, ...farmSupplyCalls, ...rewardTokenCalls],
|
|
102
|
+
});
|
|
103
|
+
const mcResponse = mc;
|
|
104
|
+
const [...restMCResponse] = mcResponse;
|
|
98
105
|
const farmInfoCallsEnd = farmInfoCalls.length;
|
|
99
106
|
const farmInfo = restMCResponse.slice(0, farmInfoCallsEnd);
|
|
100
107
|
const farmSupplyCallsEnd = farmInfoCallsEnd + farmSupplyCalls.length;
|
|
@@ -114,34 +121,6 @@ class GearboxRewardsApi {
|
|
|
114
121
|
}
|
|
115
122
|
return acc;
|
|
116
123
|
}, {});
|
|
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
124
|
const stakedTokenRewards = allPoolTokens.reduce((acc, pool) => {
|
|
146
125
|
const info = infoByPool[pool];
|
|
147
126
|
const token = rewardTokenPool[pool];
|
|
@@ -156,13 +135,11 @@ class GearboxRewardsApi {
|
|
|
156
135
|
symbol: tokenData.symbol,
|
|
157
136
|
}
|
|
158
137
|
: undefined;
|
|
159
|
-
const extra = extraRewards[pool] || [];
|
|
160
138
|
if (baseReward)
|
|
161
139
|
acc.base[pool] = baseReward;
|
|
162
|
-
acc.
|
|
163
|
-
acc.all[pool] = [...(baseReward ? [baseReward] : []), ...extra];
|
|
140
|
+
acc.all[pool] = [...(baseReward ? [baseReward] : [])];
|
|
164
141
|
return acc;
|
|
165
|
-
}, { base: {},
|
|
142
|
+
}, { base: {}, all: {} });
|
|
166
143
|
const rewardPoolsSupply = allPoolTokens.reduce((acc, address, i) => {
|
|
167
144
|
acc[address] = farmSupply[i] || 0n;
|
|
168
145
|
return acc;
|
|
@@ -170,7 +147,6 @@ class GearboxRewardsApi {
|
|
|
170
147
|
return {
|
|
171
148
|
rewardPoolsInfo: stakedTokenRewards.all,
|
|
172
149
|
baseRewardPoolsInfo: stakedTokenRewards.base,
|
|
173
|
-
extraRewardPoolsInfo: stakedTokenRewards.extra,
|
|
174
150
|
rewardPoolsSupply,
|
|
175
151
|
};
|
|
176
152
|
}
|
|
@@ -21,7 +21,8 @@ export interface ExtraRewardApy {
|
|
|
21
21
|
token: Address;
|
|
22
22
|
balance: bigint | null;
|
|
23
23
|
apy: number;
|
|
24
|
-
|
|
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
|
-
|
|
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 {
|
|
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,26 +19,109 @@ export interface MerkleXYZUserRewards {
|
|
|
18
19
|
unclaimed: BigNumberish;
|
|
19
20
|
}
|
|
20
21
|
export type MerkleXYZUserRewardsResponse = Record<string, MerkleXYZUserRewards>;
|
|
21
|
-
interface
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
interface MerkleXYZChain {
|
|
23
|
+
id: number;
|
|
24
|
+
name: string;
|
|
25
|
+
icon: string;
|
|
26
|
+
}
|
|
27
|
+
interface MerkleXYZToken {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
chainId: number;
|
|
31
|
+
address: Address;
|
|
32
|
+
decimals: number;
|
|
33
|
+
icon: string;
|
|
34
|
+
verified: boolean;
|
|
35
|
+
isTest: boolean;
|
|
36
|
+
price: number | null;
|
|
37
|
+
symbol: string;
|
|
38
|
+
}
|
|
39
|
+
export interface MerklXYZV4Campaign {
|
|
40
|
+
chainId: number;
|
|
41
|
+
type: string;
|
|
42
|
+
identifier: Address;
|
|
43
|
+
name: string;
|
|
44
|
+
status: "LIVE" | "PAST";
|
|
45
|
+
action: "LEND" | "BORROW";
|
|
46
|
+
tvl: number;
|
|
47
|
+
apr: number;
|
|
48
|
+
dailyRewards: number;
|
|
49
|
+
tags: Array<string>;
|
|
50
|
+
id: string;
|
|
51
|
+
tokens: Array<MerkleXYZToken>;
|
|
52
|
+
chain: MerkleXYZChain;
|
|
53
|
+
aprRecord: {
|
|
54
|
+
cumulated: number;
|
|
55
|
+
timestamp: string;
|
|
56
|
+
breakdowns: Array<{
|
|
57
|
+
id: number;
|
|
58
|
+
identifier: Address;
|
|
59
|
+
type: "CAMPAIGN";
|
|
60
|
+
value: number;
|
|
61
|
+
aprRecordId: string;
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
tvlRecord: {
|
|
65
|
+
id: string;
|
|
66
|
+
total: number;
|
|
67
|
+
timestamp: string;
|
|
68
|
+
breakdowns: [];
|
|
69
|
+
};
|
|
70
|
+
rewardsRecord: {
|
|
71
|
+
id: string;
|
|
72
|
+
total: number;
|
|
73
|
+
timestamp: string;
|
|
74
|
+
breakdowns: Array<{
|
|
75
|
+
token: MerkleXYZToken;
|
|
76
|
+
amount: string;
|
|
77
|
+
id: number;
|
|
78
|
+
value: number;
|
|
79
|
+
campaignId: string;
|
|
80
|
+
dailyRewardsRecordid: string;
|
|
81
|
+
}>;
|
|
26
82
|
};
|
|
27
83
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
84
|
+
export type MerkleXYZV4CampaignsResponse = Array<MerklXYZV4Campaign>;
|
|
85
|
+
export interface MerklXYZV4RewardCampaign {
|
|
86
|
+
id: string;
|
|
87
|
+
computeChainId: number;
|
|
88
|
+
distributionChainId: number;
|
|
89
|
+
campaignId: Address;
|
|
90
|
+
rewardTokenId: string;
|
|
91
|
+
amount: string;
|
|
92
|
+
opportunityId: string;
|
|
93
|
+
startTimestamp: string;
|
|
94
|
+
endTimestamp: string;
|
|
95
|
+
creatorAddress: Address;
|
|
96
|
+
params: {
|
|
97
|
+
url: string;
|
|
98
|
+
duration: number;
|
|
99
|
+
blacklist: Array<Address>;
|
|
100
|
+
whitelist: Array<Address>;
|
|
101
|
+
forwarders: Array<Address>;
|
|
102
|
+
targetToken: Address;
|
|
103
|
+
symbolRewardToken: string;
|
|
104
|
+
symbolTargetToken: string;
|
|
105
|
+
decimalsRewardToken: number;
|
|
106
|
+
decimalsTargetToken: number;
|
|
107
|
+
};
|
|
108
|
+
chain: MerkleXYZChain;
|
|
109
|
+
rewardToken: MerkleXYZToken;
|
|
110
|
+
distributionChain: MerkleXYZChain;
|
|
111
|
+
campaignStatus: {
|
|
112
|
+
campaignId: string;
|
|
113
|
+
computedUntil: string;
|
|
114
|
+
processingStarted: string;
|
|
115
|
+
status: "SUCCESS";
|
|
116
|
+
error: string;
|
|
117
|
+
details: string;
|
|
118
|
+
};
|
|
36
119
|
}
|
|
37
|
-
export type
|
|
120
|
+
export type MerkleXYZV4RewardCampaignResponse = Array<MerklXYZV4RewardCampaign>;
|
|
38
121
|
export declare class MerkleXYZApi {
|
|
39
122
|
static domain: string;
|
|
40
123
|
static getUserRewardsUrl: (options: UserOptions) => string;
|
|
41
|
-
static
|
|
124
|
+
static getGearboxCampaignsUrl: () => string;
|
|
125
|
+
static getGearboxRewardCampaignUrl: (campaignId: Address) => string;
|
|
42
126
|
}
|
|
43
127
|
export {};
|
|
@@ -6,6 +6,7 @@ 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
|
|
9
|
+
static getGearboxCampaignsUrl = () => "https://api.merkl.xyz/v4/opportunities?name=gearbox";
|
|
10
|
+
static getGearboxRewardCampaignUrl = (campaignId) => `https://api.merkl.xyz/v4/campaigns?campaignId=${campaignId}`;
|
|
10
11
|
}
|
|
11
12
|
exports.MerkleXYZApi = MerkleXYZApi;
|