@gearbox-protocol/sdk 13.3.1 → 13.3.3
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/dist/cjs/rewards/rewards/api.js +4 -124
- package/dist/cjs/rewards/rewards/extra-apy.js +5 -7
- package/dist/cjs/rewards/rewards/index.js +1 -5
- package/dist/esm/rewards/rewards/api.js +4 -124
- package/dist/esm/rewards/rewards/extra-apy.js +4 -6
- package/dist/esm/rewards/rewards/index.js +0 -2
- package/dist/types/rewards/rewards/api.d.ts +5 -28
- package/dist/types/rewards/rewards/extra-apy.d.ts +1 -1
- package/dist/types/rewards/rewards/index.d.ts +0 -2
- package/package.json +1 -1
- package/dist/cjs/rewards/rewards/apy.js +0 -177
- package/dist/esm/rewards/rewards/apy.js +0 -160
- package/dist/types/rewards/rewards/apy.d.ts +0 -41
|
@@ -18,106 +18,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var api_exports = {};
|
|
20
20
|
__export(api_exports, {
|
|
21
|
-
|
|
21
|
+
RewardAmountAPI: () => RewardAmountAPI
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(api_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
|
-
var import_iFarmingPool = require("../../abi/iFarmingPool.js");
|
|
26
25
|
var import_common_utils = require("../../common-utils/index.js");
|
|
27
26
|
var import_sdk = require("../../sdk/index.js");
|
|
28
27
|
var import_merkl_api = require("./merkl-api.js");
|
|
29
|
-
class
|
|
28
|
+
class RewardAmountAPI {
|
|
30
29
|
constructor() {
|
|
31
30
|
}
|
|
32
|
-
static async getLmRewardsV3({
|
|
33
|
-
pools,
|
|
34
|
-
tokensList,
|
|
35
|
-
provider,
|
|
36
|
-
account,
|
|
37
|
-
reportError
|
|
38
|
-
}) {
|
|
39
|
-
const poolByStakedDiesel = Object.values(pools).reduce((acc, p) => {
|
|
40
|
-
p.stakedDieselToken.forEach((t) => {
|
|
41
|
-
if (t) acc[t] = p.address;
|
|
42
|
-
});
|
|
43
|
-
p.stakedDieselToken_old.forEach((t) => {
|
|
44
|
-
if (t) acc[t] = p.address;
|
|
45
|
-
});
|
|
46
|
-
return acc;
|
|
47
|
-
}, {});
|
|
48
|
-
const stakedDieselTokens = Object.keys(poolByStakedDiesel);
|
|
49
|
-
const farmInfoCalls = stakedDieselTokens.map((address) => ({
|
|
50
|
-
address,
|
|
51
|
-
abi: import_iFarmingPool.iFarmingPoolAbi,
|
|
52
|
-
functionName: "farmInfo",
|
|
53
|
-
args: []
|
|
54
|
-
}));
|
|
55
|
-
const rewardTokenCalls = stakedDieselTokens.map((address) => ({
|
|
56
|
-
address,
|
|
57
|
-
abi: POOL_REWARDS_ABI,
|
|
58
|
-
functionName: "rewardsToken",
|
|
59
|
-
args: []
|
|
60
|
-
}));
|
|
61
|
-
const farmedCalls = stakedDieselTokens.map((address) => ({
|
|
62
|
-
address,
|
|
63
|
-
abi: import_iFarmingPool.iFarmingPoolAbi,
|
|
64
|
-
functionName: "farmed",
|
|
65
|
-
args: [account]
|
|
66
|
-
}));
|
|
67
|
-
const [response] = await Promise.allSettled([
|
|
68
|
-
provider.multicall({
|
|
69
|
-
allowFailure: false,
|
|
70
|
-
contracts: [...farmInfoCalls, ...rewardTokenCalls, ...farmedCalls],
|
|
71
|
-
batchSize: 0
|
|
72
|
-
})
|
|
73
|
-
]);
|
|
74
|
-
const safeResponse = GearboxRewardsApi.extractFulfilled(response, reportError, "v3Rewards") || [];
|
|
75
|
-
const farmInfoCallsEnd = farmInfoCalls.length;
|
|
76
|
-
const farmInfo = safeResponse.slice(
|
|
77
|
-
0,
|
|
78
|
-
farmInfoCallsEnd
|
|
79
|
-
);
|
|
80
|
-
const rewardTokenCallsEnd = farmInfoCallsEnd + rewardTokenCalls.length;
|
|
81
|
-
const rewardTokens = safeResponse.slice(
|
|
82
|
-
farmInfoCallsEnd,
|
|
83
|
-
rewardTokenCallsEnd
|
|
84
|
-
);
|
|
85
|
-
const farmedCallsEnd = rewardTokenCallsEnd + farmedCalls.length;
|
|
86
|
-
const farmedList = safeResponse.slice(
|
|
87
|
-
rewardTokenCallsEnd,
|
|
88
|
-
farmedCallsEnd
|
|
89
|
-
);
|
|
90
|
-
const gearboxLmRewards = stakedDieselTokens.map(
|
|
91
|
-
(address, i) => {
|
|
92
|
-
const pool = poolByStakedDiesel[address];
|
|
93
|
-
const info = farmInfo[i];
|
|
94
|
-
const rewardToken = rewardTokens[i]?.toLowerCase();
|
|
95
|
-
const farmed = farmedList[i];
|
|
96
|
-
if (!pool || !info || !rewardToken) return void 0;
|
|
97
|
-
return {
|
|
98
|
-
pool,
|
|
99
|
-
poolToken: address,
|
|
100
|
-
rewardToken,
|
|
101
|
-
rewardTokenDecimals: tokensList[rewardToken]?.decimals || 18,
|
|
102
|
-
rewardTokenSymbol: tokensList[rewardToken]?.symbol || "unknown",
|
|
103
|
-
amount: farmed ?? 0n,
|
|
104
|
-
type: "stakedV3"
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
const { zero, nonZero } = gearboxLmRewards.reduce(
|
|
109
|
-
(acc, r) => {
|
|
110
|
-
if (r && r.amount > 0n) {
|
|
111
|
-
acc.nonZero.push(r);
|
|
112
|
-
} else if (r) {
|
|
113
|
-
acc.zero.push(r);
|
|
114
|
-
}
|
|
115
|
-
return acc;
|
|
116
|
-
},
|
|
117
|
-
{ nonZero: [], zero: [] }
|
|
118
|
-
);
|
|
119
|
-
return [...nonZero, zero];
|
|
120
|
-
}
|
|
121
31
|
static async getLmRewardsMerkle({
|
|
122
32
|
pools,
|
|
123
33
|
account,
|
|
@@ -134,7 +44,7 @@ class GearboxRewardsApi {
|
|
|
134
44
|
})
|
|
135
45
|
)
|
|
136
46
|
]);
|
|
137
|
-
const merkleXYZLm =
|
|
47
|
+
const merkleXYZLm = RewardAmountAPI.extractFulfilled(
|
|
138
48
|
merkleXYZLMResponse,
|
|
139
49
|
reportError,
|
|
140
50
|
"merkleXYZLm"
|
|
@@ -189,38 +99,8 @@ class GearboxRewardsApi {
|
|
|
189
99
|
return void 0;
|
|
190
100
|
}
|
|
191
101
|
}
|
|
192
|
-
static async claimLmRewardsV3({
|
|
193
|
-
reward,
|
|
194
|
-
signer,
|
|
195
|
-
account
|
|
196
|
-
}) {
|
|
197
|
-
const pool = (0, import_viem.getContract)({
|
|
198
|
-
address: reward.poolToken,
|
|
199
|
-
abi: import_iFarmingPool.iFarmingPoolAbi,
|
|
200
|
-
client: signer
|
|
201
|
-
});
|
|
202
|
-
return pool.write.claim({
|
|
203
|
-
account,
|
|
204
|
-
chain: signer.chain
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
102
|
}
|
|
208
|
-
const POOL_REWARDS_ABI = [
|
|
209
|
-
{
|
|
210
|
-
inputs: [],
|
|
211
|
-
name: "rewardsToken",
|
|
212
|
-
outputs: [
|
|
213
|
-
{
|
|
214
|
-
internalType: "contract IERC20",
|
|
215
|
-
name: "",
|
|
216
|
-
type: "address"
|
|
217
|
-
}
|
|
218
|
-
],
|
|
219
|
-
stateMutability: "view",
|
|
220
|
-
type: "function"
|
|
221
|
-
}
|
|
222
|
-
];
|
|
223
103
|
// Annotate the CommonJS export names for ESM import in node:
|
|
224
104
|
0 && (module.exports = {
|
|
225
|
-
|
|
105
|
+
RewardAmountAPI
|
|
226
106
|
});
|
|
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var extra_apy_exports = {};
|
|
30
30
|
__export(extra_apy_exports, {
|
|
31
|
-
|
|
31
|
+
PoolPointsAPI: () => PoolPointsAPI,
|
|
32
32
|
getKeyForPoolPointsInfo: () => getKeyForPoolPointsInfo
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(extra_apy_exports);
|
|
@@ -47,7 +47,7 @@ function getKeyForPoolPointsInfo(i) {
|
|
|
47
47
|
i.condition
|
|
48
48
|
].join("-");
|
|
49
49
|
}
|
|
50
|
-
class
|
|
50
|
+
class PoolPointsAPI {
|
|
51
51
|
constructor() {
|
|
52
52
|
}
|
|
53
53
|
static async getTotalTokensOnProtocol({
|
|
@@ -57,9 +57,7 @@ class GearboxRewardsExtraApy {
|
|
|
57
57
|
}) {
|
|
58
58
|
const list = [...new Set(tokensToCheck)];
|
|
59
59
|
const res = await Promise.allSettled(
|
|
60
|
-
list.map(
|
|
61
|
-
(t) => GearboxRewardsExtraApy.getTokenTotal(t, network, tokensList)
|
|
62
|
-
)
|
|
60
|
+
list.map((t) => PoolPointsAPI.getTokenTotal(t, network, tokensList))
|
|
63
61
|
);
|
|
64
62
|
return res.map((r, i) => [
|
|
65
63
|
list[i],
|
|
@@ -89,7 +87,7 @@ class GearboxRewardsExtraApy {
|
|
|
89
87
|
(acc2, pointsInfo2) => {
|
|
90
88
|
const { address: tokenAddress } = tokensList[pointsInfo2.token] || {};
|
|
91
89
|
const tokenBalance = totalTokenBalances[tokenAddress || ""];
|
|
92
|
-
const points =
|
|
90
|
+
const points = PoolPointsAPI.getPoolTokenPoints(
|
|
93
91
|
tokenBalance,
|
|
94
92
|
p,
|
|
95
93
|
tokensList,
|
|
@@ -127,6 +125,6 @@ class GearboxRewardsExtraApy {
|
|
|
127
125
|
}
|
|
128
126
|
// Annotate the CommonJS export names for ESM import in node:
|
|
129
127
|
0 && (module.exports = {
|
|
130
|
-
|
|
128
|
+
PoolPointsAPI,
|
|
131
129
|
getKeyForPoolPointsInfo
|
|
132
130
|
});
|
|
@@ -16,13 +16,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var rewards_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(rewards_exports);
|
|
18
18
|
__reExport(rewards_exports, require("./api.js"), module.exports);
|
|
19
|
-
__reExport(rewards_exports, require("./apy.js"), module.exports);
|
|
20
19
|
__reExport(rewards_exports, require("./extra-apy.js"), module.exports);
|
|
21
|
-
__reExport(rewards_exports, require("./merkl-api.js"), module.exports);
|
|
22
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
23
21
|
0 && (module.exports = {
|
|
24
22
|
...require("./api.js"),
|
|
25
|
-
...require("./apy.js")
|
|
26
|
-
...require("./extra-apy.js"),
|
|
27
|
-
...require("./merkl-api.js")
|
|
23
|
+
...require("./extra-apy.js")
|
|
28
24
|
});
|
|
@@ -1,102 +1,12 @@
|
|
|
1
|
-
import { getAddress
|
|
2
|
-
import { iFarmingPoolAbi } from "../../abi/iFarmingPool.js";
|
|
1
|
+
import { getAddress } from "viem";
|
|
3
2
|
import { BigIntMath } from "../../common-utils/index.js";
|
|
4
3
|
import { chains, toBigInt } from "../../sdk/index.js";
|
|
5
4
|
import {
|
|
6
5
|
MerkleXYZApi
|
|
7
6
|
} from "./merkl-api.js";
|
|
8
|
-
class
|
|
7
|
+
class RewardAmountAPI {
|
|
9
8
|
constructor() {
|
|
10
9
|
}
|
|
11
|
-
static async getLmRewardsV3({
|
|
12
|
-
pools,
|
|
13
|
-
tokensList,
|
|
14
|
-
provider,
|
|
15
|
-
account,
|
|
16
|
-
reportError
|
|
17
|
-
}) {
|
|
18
|
-
const poolByStakedDiesel = Object.values(pools).reduce((acc, p) => {
|
|
19
|
-
p.stakedDieselToken.forEach((t) => {
|
|
20
|
-
if (t) acc[t] = p.address;
|
|
21
|
-
});
|
|
22
|
-
p.stakedDieselToken_old.forEach((t) => {
|
|
23
|
-
if (t) acc[t] = p.address;
|
|
24
|
-
});
|
|
25
|
-
return acc;
|
|
26
|
-
}, {});
|
|
27
|
-
const stakedDieselTokens = Object.keys(poolByStakedDiesel);
|
|
28
|
-
const farmInfoCalls = stakedDieselTokens.map((address) => ({
|
|
29
|
-
address,
|
|
30
|
-
abi: iFarmingPoolAbi,
|
|
31
|
-
functionName: "farmInfo",
|
|
32
|
-
args: []
|
|
33
|
-
}));
|
|
34
|
-
const rewardTokenCalls = stakedDieselTokens.map((address) => ({
|
|
35
|
-
address,
|
|
36
|
-
abi: POOL_REWARDS_ABI,
|
|
37
|
-
functionName: "rewardsToken",
|
|
38
|
-
args: []
|
|
39
|
-
}));
|
|
40
|
-
const farmedCalls = stakedDieselTokens.map((address) => ({
|
|
41
|
-
address,
|
|
42
|
-
abi: iFarmingPoolAbi,
|
|
43
|
-
functionName: "farmed",
|
|
44
|
-
args: [account]
|
|
45
|
-
}));
|
|
46
|
-
const [response] = await Promise.allSettled([
|
|
47
|
-
provider.multicall({
|
|
48
|
-
allowFailure: false,
|
|
49
|
-
contracts: [...farmInfoCalls, ...rewardTokenCalls, ...farmedCalls],
|
|
50
|
-
batchSize: 0
|
|
51
|
-
})
|
|
52
|
-
]);
|
|
53
|
-
const safeResponse = GearboxRewardsApi.extractFulfilled(response, reportError, "v3Rewards") || [];
|
|
54
|
-
const farmInfoCallsEnd = farmInfoCalls.length;
|
|
55
|
-
const farmInfo = safeResponse.slice(
|
|
56
|
-
0,
|
|
57
|
-
farmInfoCallsEnd
|
|
58
|
-
);
|
|
59
|
-
const rewardTokenCallsEnd = farmInfoCallsEnd + rewardTokenCalls.length;
|
|
60
|
-
const rewardTokens = safeResponse.slice(
|
|
61
|
-
farmInfoCallsEnd,
|
|
62
|
-
rewardTokenCallsEnd
|
|
63
|
-
);
|
|
64
|
-
const farmedCallsEnd = rewardTokenCallsEnd + farmedCalls.length;
|
|
65
|
-
const farmedList = safeResponse.slice(
|
|
66
|
-
rewardTokenCallsEnd,
|
|
67
|
-
farmedCallsEnd
|
|
68
|
-
);
|
|
69
|
-
const gearboxLmRewards = stakedDieselTokens.map(
|
|
70
|
-
(address, i) => {
|
|
71
|
-
const pool = poolByStakedDiesel[address];
|
|
72
|
-
const info = farmInfo[i];
|
|
73
|
-
const rewardToken = rewardTokens[i]?.toLowerCase();
|
|
74
|
-
const farmed = farmedList[i];
|
|
75
|
-
if (!pool || !info || !rewardToken) return void 0;
|
|
76
|
-
return {
|
|
77
|
-
pool,
|
|
78
|
-
poolToken: address,
|
|
79
|
-
rewardToken,
|
|
80
|
-
rewardTokenDecimals: tokensList[rewardToken]?.decimals || 18,
|
|
81
|
-
rewardTokenSymbol: tokensList[rewardToken]?.symbol || "unknown",
|
|
82
|
-
amount: farmed ?? 0n,
|
|
83
|
-
type: "stakedV3"
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
const { zero, nonZero } = gearboxLmRewards.reduce(
|
|
88
|
-
(acc, r) => {
|
|
89
|
-
if (r && r.amount > 0n) {
|
|
90
|
-
acc.nonZero.push(r);
|
|
91
|
-
} else if (r) {
|
|
92
|
-
acc.zero.push(r);
|
|
93
|
-
}
|
|
94
|
-
return acc;
|
|
95
|
-
},
|
|
96
|
-
{ nonZero: [], zero: [] }
|
|
97
|
-
);
|
|
98
|
-
return [...nonZero, zero];
|
|
99
|
-
}
|
|
100
10
|
static async getLmRewardsMerkle({
|
|
101
11
|
pools,
|
|
102
12
|
account,
|
|
@@ -113,7 +23,7 @@ class GearboxRewardsApi {
|
|
|
113
23
|
})
|
|
114
24
|
)
|
|
115
25
|
]);
|
|
116
|
-
const merkleXYZLm =
|
|
26
|
+
const merkleXYZLm = RewardAmountAPI.extractFulfilled(
|
|
117
27
|
merkleXYZLMResponse,
|
|
118
28
|
reportError,
|
|
119
29
|
"merkleXYZLm"
|
|
@@ -168,37 +78,7 @@ class GearboxRewardsApi {
|
|
|
168
78
|
return void 0;
|
|
169
79
|
}
|
|
170
80
|
}
|
|
171
|
-
static async claimLmRewardsV3({
|
|
172
|
-
reward,
|
|
173
|
-
signer,
|
|
174
|
-
account
|
|
175
|
-
}) {
|
|
176
|
-
const pool = getContract({
|
|
177
|
-
address: reward.poolToken,
|
|
178
|
-
abi: iFarmingPoolAbi,
|
|
179
|
-
client: signer
|
|
180
|
-
});
|
|
181
|
-
return pool.write.claim({
|
|
182
|
-
account,
|
|
183
|
-
chain: signer.chain
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
81
|
}
|
|
187
|
-
const POOL_REWARDS_ABI = [
|
|
188
|
-
{
|
|
189
|
-
inputs: [],
|
|
190
|
-
name: "rewardsToken",
|
|
191
|
-
outputs: [
|
|
192
|
-
{
|
|
193
|
-
internalType: "contract IERC20",
|
|
194
|
-
name: "",
|
|
195
|
-
type: "address"
|
|
196
|
-
}
|
|
197
|
-
],
|
|
198
|
-
stateMutability: "view",
|
|
199
|
-
type: "function"
|
|
200
|
-
}
|
|
201
|
-
];
|
|
202
82
|
export {
|
|
203
|
-
|
|
83
|
+
RewardAmountAPI
|
|
204
84
|
};
|
|
@@ -17,7 +17,7 @@ function getKeyForPoolPointsInfo(i) {
|
|
|
17
17
|
i.condition
|
|
18
18
|
].join("-");
|
|
19
19
|
}
|
|
20
|
-
class
|
|
20
|
+
class PoolPointsAPI {
|
|
21
21
|
constructor() {
|
|
22
22
|
}
|
|
23
23
|
static async getTotalTokensOnProtocol({
|
|
@@ -27,9 +27,7 @@ class GearboxRewardsExtraApy {
|
|
|
27
27
|
}) {
|
|
28
28
|
const list = [...new Set(tokensToCheck)];
|
|
29
29
|
const res = await Promise.allSettled(
|
|
30
|
-
list.map(
|
|
31
|
-
(t) => GearboxRewardsExtraApy.getTokenTotal(t, network, tokensList)
|
|
32
|
-
)
|
|
30
|
+
list.map((t) => PoolPointsAPI.getTokenTotal(t, network, tokensList))
|
|
33
31
|
);
|
|
34
32
|
return res.map((r, i) => [
|
|
35
33
|
list[i],
|
|
@@ -59,7 +57,7 @@ class GearboxRewardsExtraApy {
|
|
|
59
57
|
(acc2, pointsInfo2) => {
|
|
60
58
|
const { address: tokenAddress } = tokensList[pointsInfo2.token] || {};
|
|
61
59
|
const tokenBalance = totalTokenBalances[tokenAddress || ""];
|
|
62
|
-
const points =
|
|
60
|
+
const points = PoolPointsAPI.getPoolTokenPoints(
|
|
63
61
|
tokenBalance,
|
|
64
62
|
p,
|
|
65
63
|
tokensList,
|
|
@@ -96,6 +94,6 @@ class GearboxRewardsExtraApy {
|
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
96
|
export {
|
|
99
|
-
|
|
97
|
+
PoolPointsAPI,
|
|
100
98
|
getKeyForPoolPointsInfo
|
|
101
99
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Address
|
|
1
|
+
import type { Address } from "viem";
|
|
2
2
|
import { type NetworkType } from "../../sdk/index.js";
|
|
3
|
-
import type { PoolData
|
|
3
|
+
import type { PoolData } from "./common.js";
|
|
4
4
|
export interface GearboxExtraMerkleLmReward {
|
|
5
5
|
pool: Address;
|
|
6
6
|
poolToken: Address;
|
|
@@ -10,40 +10,17 @@ export interface GearboxExtraMerkleLmReward {
|
|
|
10
10
|
amount: bigint;
|
|
11
11
|
type: "extraMerkle";
|
|
12
12
|
}
|
|
13
|
-
export
|
|
14
|
-
pool: Address;
|
|
15
|
-
poolToken: Address;
|
|
16
|
-
rewardTokenSymbol: string;
|
|
17
|
-
rewardTokenDecimals: number;
|
|
18
|
-
rewardToken: Address;
|
|
19
|
-
amount: bigint;
|
|
20
|
-
type: "stakedV3";
|
|
21
|
-
}
|
|
22
|
-
export type GearboxLmReward = GearboxStakedV3LmReward | GearboxExtraMerkleLmReward;
|
|
13
|
+
export type GearboxLmReward = GearboxExtraMerkleLmReward;
|
|
23
14
|
type ReportHandler = (e: unknown, description?: string) => void;
|
|
24
|
-
export interface GetLmRewardsV3Props {
|
|
25
|
-
pools: Record<`0x${string}`, PoolData>;
|
|
26
|
-
tokensList: Record<Address, TokenData>;
|
|
27
|
-
account: Address;
|
|
28
|
-
provider: PublicClient;
|
|
29
|
-
reportError?: ReportHandler;
|
|
30
|
-
}
|
|
31
15
|
export interface GetLmRewardsMerkleProps {
|
|
32
16
|
pools: Record<Address, PoolData>;
|
|
33
17
|
account: Address;
|
|
34
18
|
network: NetworkType;
|
|
35
19
|
reportError?: ReportHandler;
|
|
36
20
|
}
|
|
37
|
-
export
|
|
38
|
-
reward: GearboxStakedV3LmReward;
|
|
39
|
-
account: Address;
|
|
40
|
-
signer: WalletClient;
|
|
41
|
-
}
|
|
42
|
-
export declare class GearboxRewardsApi {
|
|
21
|
+
export declare class RewardAmountAPI {
|
|
43
22
|
private constructor();
|
|
44
|
-
static
|
|
45
|
-
static getLmRewardsMerkle({ pools, account, network, reportError, }: GetLmRewardsMerkleProps): Promise<GearboxLmReward[]>;
|
|
23
|
+
static getLmRewardsMerkle({ pools, account, network, reportError, }: GetLmRewardsMerkleProps): Promise<GearboxExtraMerkleLmReward[]>;
|
|
46
24
|
private static extractFulfilled;
|
|
47
|
-
static claimLmRewardsV3({ reward, signer, account, }: ClaimLmRewardsV3Props): Promise<`0x${string}`>;
|
|
48
25
|
}
|
|
49
26
|
export {};
|
|
@@ -20,7 +20,7 @@ export type PoolPointsBase = Record<Address, Array<{
|
|
|
20
20
|
points: bigint;
|
|
21
21
|
}>>;
|
|
22
22
|
export declare function getKeyForPoolPointsInfo(i: PoolPointsInfo<string>): string;
|
|
23
|
-
export declare class
|
|
23
|
+
export declare class PoolPointsAPI {
|
|
24
24
|
private constructor();
|
|
25
25
|
static getTotalTokensOnProtocol({ tokensToCheck, tokensList, network, }: GetTotalTokensOnProtocolProps): Promise<[`0x${string}`, PromiseSettledResult<Asset>][]>;
|
|
26
26
|
private static getTokenTotal;
|
package/package.json
CHANGED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var apy_exports = {};
|
|
20
|
-
__export(apy_exports, {
|
|
21
|
-
GearboxRewardsApy: () => GearboxRewardsApy
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(apy_exports);
|
|
24
|
-
var import_common_utils = require("../../common-utils/index.js");
|
|
25
|
-
var import_sdk = require("../../sdk/index.js");
|
|
26
|
-
const PERCENTAGE_FACTOR_1KK = import_sdk.PERCENTAGE_DECIMALS * import_sdk.PERCENTAGE_FACTOR;
|
|
27
|
-
const ONE = PERCENTAGE_FACTOR_1KK * 10n;
|
|
28
|
-
class GearboxRewardsApy {
|
|
29
|
-
constructor() {
|
|
30
|
-
}
|
|
31
|
-
static getPoolExtraAPY_V3({
|
|
32
|
-
rewardPoolsInfo,
|
|
33
|
-
stakedDieselToken,
|
|
34
|
-
...restProps
|
|
35
|
-
}) {
|
|
36
|
-
const { version } = restProps.pool;
|
|
37
|
-
const isV3 = version >= 300 && version < 400;
|
|
38
|
-
if (!isV3 || !stakedDieselToken) return [];
|
|
39
|
-
const info = rewardPoolsInfo[stakedDieselToken];
|
|
40
|
-
if (!info) return [];
|
|
41
|
-
const extra = (Array.isArray(info) ? info : [info]).map(
|
|
42
|
-
(inf) => GearboxRewardsApy.getPoolSingleExtraLmAPY_V3({
|
|
43
|
-
...restProps,
|
|
44
|
-
stakedDieselToken,
|
|
45
|
-
rewardPoolsInfo: inf
|
|
46
|
-
})
|
|
47
|
-
);
|
|
48
|
-
return extra;
|
|
49
|
-
}
|
|
50
|
-
static getPoolSingleExtraLmAPY_V3({
|
|
51
|
-
stakedDieselToken,
|
|
52
|
-
pool,
|
|
53
|
-
prices,
|
|
54
|
-
rewardPoolsInfo,
|
|
55
|
-
rewardPoolsSupply,
|
|
56
|
-
tokensList,
|
|
57
|
-
currentTimestamp
|
|
58
|
-
}) {
|
|
59
|
-
const { underlyingToken, dieselRateRay } = pool;
|
|
60
|
-
const safeSupply = rewardPoolsSupply[stakedDieselToken] ?? 0n;
|
|
61
|
-
const { decimals: underlyingDecimals = 18 } = tokensList[underlyingToken] || {};
|
|
62
|
-
const underlyingPrice = prices[underlyingToken] ?? 0n;
|
|
63
|
-
const dieselPrice = underlyingPrice * dieselRateRay / import_sdk.RAY;
|
|
64
|
-
const rewardAddress = rewardPoolsInfo?.token || "";
|
|
65
|
-
const { decimals: rewardDecimals = 18 } = tokensList[rewardAddress] || {};
|
|
66
|
-
const rewardPrice = prices[rewardAddress] ?? 0n;
|
|
67
|
-
const r = GearboxRewardsApy.calculateAPY_V3({
|
|
68
|
-
currentTimestamp,
|
|
69
|
-
info: rewardPoolsInfo,
|
|
70
|
-
supply: {
|
|
71
|
-
amount: safeSupply,
|
|
72
|
-
decimals: underlyingDecimals,
|
|
73
|
-
price: dieselPrice
|
|
74
|
-
},
|
|
75
|
-
reward: {
|
|
76
|
-
price: rewardPrice,
|
|
77
|
-
decimals: rewardDecimals
|
|
78
|
-
}
|
|
79
|
-
}) / Number(import_sdk.PERCENTAGE_FACTOR);
|
|
80
|
-
return {
|
|
81
|
-
token: stakedDieselToken,
|
|
82
|
-
balance: null,
|
|
83
|
-
apy: r,
|
|
84
|
-
rewardToken: rewardAddress,
|
|
85
|
-
rewardTokenSymbol: rewardPoolsInfo.symbol
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
static calculateAPY_V3({
|
|
89
|
-
info,
|
|
90
|
-
supply,
|
|
91
|
-
reward,
|
|
92
|
-
currentTimestamp
|
|
93
|
-
}) {
|
|
94
|
-
const finished = info.finished <= currentTimestamp;
|
|
95
|
-
if (finished) return 0;
|
|
96
|
-
if (supply.amount <= 0n) return 0;
|
|
97
|
-
if (supply.price === 0n || reward.price === 0n) return 0;
|
|
98
|
-
if (info.duration === 0n) return 0;
|
|
99
|
-
const supplyMoney = import_common_utils.PriceUtils.calcTotalPrice(
|
|
100
|
-
supply.price,
|
|
101
|
-
supply.amount,
|
|
102
|
-
supply.decimals
|
|
103
|
-
);
|
|
104
|
-
const rewardMoney = import_common_utils.PriceUtils.calcTotalPrice(
|
|
105
|
-
reward.price,
|
|
106
|
-
info.reward,
|
|
107
|
-
reward.decimals
|
|
108
|
-
);
|
|
109
|
-
const durationRatio = (0, import_sdk.toBigInt)(import_sdk.SECONDS_PER_YEAR) * import_sdk.WAD / info.duration;
|
|
110
|
-
const apyBn = rewardMoney * ONE / supplyMoney * durationRatio / import_sdk.WAD;
|
|
111
|
-
return Math.round(Number(apyBn) / 10);
|
|
112
|
-
}
|
|
113
|
-
static getCAExtraAPY_V3({
|
|
114
|
-
rewardInfo,
|
|
115
|
-
assets,
|
|
116
|
-
...restProps
|
|
117
|
-
}) {
|
|
118
|
-
const extra = assets.reduce(
|
|
119
|
-
(acc, asset) => {
|
|
120
|
-
const { token } = asset;
|
|
121
|
-
const info = rewardInfo[token || ""];
|
|
122
|
-
if (!info || info.length === 0) return acc;
|
|
123
|
-
const extra2 = info.map(
|
|
124
|
-
(inf) => GearboxRewardsApy.getCASingleExtraAPY_V3({
|
|
125
|
-
...restProps,
|
|
126
|
-
asset,
|
|
127
|
-
rewardInfo: inf
|
|
128
|
-
})
|
|
129
|
-
);
|
|
130
|
-
acc.push(...extra2);
|
|
131
|
-
return acc;
|
|
132
|
-
},
|
|
133
|
-
[]
|
|
134
|
-
);
|
|
135
|
-
return extra;
|
|
136
|
-
}
|
|
137
|
-
static getCASingleExtraAPY_V3({
|
|
138
|
-
asset,
|
|
139
|
-
prices,
|
|
140
|
-
rewardInfo,
|
|
141
|
-
supply,
|
|
142
|
-
tokensList,
|
|
143
|
-
currentTimestamp
|
|
144
|
-
}) {
|
|
145
|
-
const { token, balance } = asset;
|
|
146
|
-
const safeSupply = supply[token] ?? 0n;
|
|
147
|
-
const { decimals: tokenDecimals = 18 } = tokensList[token] || {};
|
|
148
|
-
const tokenPrice = prices[token] ?? 0n;
|
|
149
|
-
const rewardAddress = rewardInfo?.token || "";
|
|
150
|
-
const { decimals: rewardDecimals = 18 } = tokensList[rewardAddress] || {};
|
|
151
|
-
const rewardPrice = prices[rewardAddress] ?? 0n;
|
|
152
|
-
const r = GearboxRewardsApy.calculateAPY_V3({
|
|
153
|
-
currentTimestamp,
|
|
154
|
-
info: rewardInfo,
|
|
155
|
-
supply: {
|
|
156
|
-
amount: typeof safeSupply === "bigint" ? safeSupply : safeSupply.balance,
|
|
157
|
-
decimals: tokenDecimals,
|
|
158
|
-
price: tokenPrice
|
|
159
|
-
},
|
|
160
|
-
reward: {
|
|
161
|
-
price: rewardPrice,
|
|
162
|
-
decimals: rewardDecimals
|
|
163
|
-
}
|
|
164
|
-
}) / Number(import_sdk.PERCENTAGE_FACTOR);
|
|
165
|
-
return {
|
|
166
|
-
token,
|
|
167
|
-
balance,
|
|
168
|
-
apy: r,
|
|
169
|
-
rewardToken: rewardAddress,
|
|
170
|
-
rewardTokenSymbol: rewardInfo.symbol
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
-
0 && (module.exports = {
|
|
176
|
-
GearboxRewardsApy
|
|
177
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { PriceUtils } from "../../common-utils/index.js";
|
|
2
|
-
import {
|
|
3
|
-
PERCENTAGE_DECIMALS,
|
|
4
|
-
PERCENTAGE_FACTOR,
|
|
5
|
-
RAY,
|
|
6
|
-
SECONDS_PER_YEAR,
|
|
7
|
-
toBigInt,
|
|
8
|
-
WAD
|
|
9
|
-
} from "../../sdk/index.js";
|
|
10
|
-
const PERCENTAGE_FACTOR_1KK = PERCENTAGE_DECIMALS * PERCENTAGE_FACTOR;
|
|
11
|
-
const ONE = PERCENTAGE_FACTOR_1KK * 10n;
|
|
12
|
-
class GearboxRewardsApy {
|
|
13
|
-
constructor() {
|
|
14
|
-
}
|
|
15
|
-
static getPoolExtraAPY_V3({
|
|
16
|
-
rewardPoolsInfo,
|
|
17
|
-
stakedDieselToken,
|
|
18
|
-
...restProps
|
|
19
|
-
}) {
|
|
20
|
-
const { version } = restProps.pool;
|
|
21
|
-
const isV3 = version >= 300 && version < 400;
|
|
22
|
-
if (!isV3 || !stakedDieselToken) return [];
|
|
23
|
-
const info = rewardPoolsInfo[stakedDieselToken];
|
|
24
|
-
if (!info) return [];
|
|
25
|
-
const extra = (Array.isArray(info) ? info : [info]).map(
|
|
26
|
-
(inf) => GearboxRewardsApy.getPoolSingleExtraLmAPY_V3({
|
|
27
|
-
...restProps,
|
|
28
|
-
stakedDieselToken,
|
|
29
|
-
rewardPoolsInfo: inf
|
|
30
|
-
})
|
|
31
|
-
);
|
|
32
|
-
return extra;
|
|
33
|
-
}
|
|
34
|
-
static getPoolSingleExtraLmAPY_V3({
|
|
35
|
-
stakedDieselToken,
|
|
36
|
-
pool,
|
|
37
|
-
prices,
|
|
38
|
-
rewardPoolsInfo,
|
|
39
|
-
rewardPoolsSupply,
|
|
40
|
-
tokensList,
|
|
41
|
-
currentTimestamp
|
|
42
|
-
}) {
|
|
43
|
-
const { underlyingToken, dieselRateRay } = pool;
|
|
44
|
-
const safeSupply = rewardPoolsSupply[stakedDieselToken] ?? 0n;
|
|
45
|
-
const { decimals: underlyingDecimals = 18 } = tokensList[underlyingToken] || {};
|
|
46
|
-
const underlyingPrice = prices[underlyingToken] ?? 0n;
|
|
47
|
-
const dieselPrice = underlyingPrice * dieselRateRay / RAY;
|
|
48
|
-
const rewardAddress = rewardPoolsInfo?.token || "";
|
|
49
|
-
const { decimals: rewardDecimals = 18 } = tokensList[rewardAddress] || {};
|
|
50
|
-
const rewardPrice = prices[rewardAddress] ?? 0n;
|
|
51
|
-
const r = GearboxRewardsApy.calculateAPY_V3({
|
|
52
|
-
currentTimestamp,
|
|
53
|
-
info: rewardPoolsInfo,
|
|
54
|
-
supply: {
|
|
55
|
-
amount: safeSupply,
|
|
56
|
-
decimals: underlyingDecimals,
|
|
57
|
-
price: dieselPrice
|
|
58
|
-
},
|
|
59
|
-
reward: {
|
|
60
|
-
price: rewardPrice,
|
|
61
|
-
decimals: rewardDecimals
|
|
62
|
-
}
|
|
63
|
-
}) / Number(PERCENTAGE_FACTOR);
|
|
64
|
-
return {
|
|
65
|
-
token: stakedDieselToken,
|
|
66
|
-
balance: null,
|
|
67
|
-
apy: r,
|
|
68
|
-
rewardToken: rewardAddress,
|
|
69
|
-
rewardTokenSymbol: rewardPoolsInfo.symbol
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
static calculateAPY_V3({
|
|
73
|
-
info,
|
|
74
|
-
supply,
|
|
75
|
-
reward,
|
|
76
|
-
currentTimestamp
|
|
77
|
-
}) {
|
|
78
|
-
const finished = info.finished <= currentTimestamp;
|
|
79
|
-
if (finished) return 0;
|
|
80
|
-
if (supply.amount <= 0n) return 0;
|
|
81
|
-
if (supply.price === 0n || reward.price === 0n) return 0;
|
|
82
|
-
if (info.duration === 0n) return 0;
|
|
83
|
-
const supplyMoney = PriceUtils.calcTotalPrice(
|
|
84
|
-
supply.price,
|
|
85
|
-
supply.amount,
|
|
86
|
-
supply.decimals
|
|
87
|
-
);
|
|
88
|
-
const rewardMoney = PriceUtils.calcTotalPrice(
|
|
89
|
-
reward.price,
|
|
90
|
-
info.reward,
|
|
91
|
-
reward.decimals
|
|
92
|
-
);
|
|
93
|
-
const durationRatio = toBigInt(SECONDS_PER_YEAR) * WAD / info.duration;
|
|
94
|
-
const apyBn = rewardMoney * ONE / supplyMoney * durationRatio / WAD;
|
|
95
|
-
return Math.round(Number(apyBn) / 10);
|
|
96
|
-
}
|
|
97
|
-
static getCAExtraAPY_V3({
|
|
98
|
-
rewardInfo,
|
|
99
|
-
assets,
|
|
100
|
-
...restProps
|
|
101
|
-
}) {
|
|
102
|
-
const extra = assets.reduce(
|
|
103
|
-
(acc, asset) => {
|
|
104
|
-
const { token } = asset;
|
|
105
|
-
const info = rewardInfo[token || ""];
|
|
106
|
-
if (!info || info.length === 0) return acc;
|
|
107
|
-
const extra2 = info.map(
|
|
108
|
-
(inf) => GearboxRewardsApy.getCASingleExtraAPY_V3({
|
|
109
|
-
...restProps,
|
|
110
|
-
asset,
|
|
111
|
-
rewardInfo: inf
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
acc.push(...extra2);
|
|
115
|
-
return acc;
|
|
116
|
-
},
|
|
117
|
-
[]
|
|
118
|
-
);
|
|
119
|
-
return extra;
|
|
120
|
-
}
|
|
121
|
-
static getCASingleExtraAPY_V3({
|
|
122
|
-
asset,
|
|
123
|
-
prices,
|
|
124
|
-
rewardInfo,
|
|
125
|
-
supply,
|
|
126
|
-
tokensList,
|
|
127
|
-
currentTimestamp
|
|
128
|
-
}) {
|
|
129
|
-
const { token, balance } = asset;
|
|
130
|
-
const safeSupply = supply[token] ?? 0n;
|
|
131
|
-
const { decimals: tokenDecimals = 18 } = tokensList[token] || {};
|
|
132
|
-
const tokenPrice = prices[token] ?? 0n;
|
|
133
|
-
const rewardAddress = rewardInfo?.token || "";
|
|
134
|
-
const { decimals: rewardDecimals = 18 } = tokensList[rewardAddress] || {};
|
|
135
|
-
const rewardPrice = prices[rewardAddress] ?? 0n;
|
|
136
|
-
const r = GearboxRewardsApy.calculateAPY_V3({
|
|
137
|
-
currentTimestamp,
|
|
138
|
-
info: rewardInfo,
|
|
139
|
-
supply: {
|
|
140
|
-
amount: typeof safeSupply === "bigint" ? safeSupply : safeSupply.balance,
|
|
141
|
-
decimals: tokenDecimals,
|
|
142
|
-
price: tokenPrice
|
|
143
|
-
},
|
|
144
|
-
reward: {
|
|
145
|
-
price: rewardPrice,
|
|
146
|
-
decimals: rewardDecimals
|
|
147
|
-
}
|
|
148
|
-
}) / Number(PERCENTAGE_FACTOR);
|
|
149
|
-
return {
|
|
150
|
-
token,
|
|
151
|
-
balance,
|
|
152
|
-
apy: r,
|
|
153
|
-
rewardToken: rewardAddress,
|
|
154
|
-
rewardTokenSymbol: rewardInfo.symbol
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
export {
|
|
159
|
-
GearboxRewardsApy
|
|
160
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import { type Asset } from "../../sdk/index.js";
|
|
3
|
-
import type { FarmInfo } from "../index.js";
|
|
4
|
-
import type { PoolData, TokenData } from "./common.js";
|
|
5
|
-
interface InnerFarmInfo extends FarmInfo {
|
|
6
|
-
token: Address;
|
|
7
|
-
}
|
|
8
|
-
export interface ExtraRewardApy {
|
|
9
|
-
token: Address;
|
|
10
|
-
balance: bigint | null;
|
|
11
|
-
apy: number;
|
|
12
|
-
rewardToken: Address;
|
|
13
|
-
rewardTokenSymbol: string;
|
|
14
|
-
endTimestamp?: number;
|
|
15
|
-
}
|
|
16
|
-
interface GetPoolExtraAPY_V3Props {
|
|
17
|
-
stakedDieselToken: Address | undefined;
|
|
18
|
-
pool: PoolData;
|
|
19
|
-
prices: Record<Address, bigint>;
|
|
20
|
-
rewardPoolsInfo: Record<Address, Array<InnerFarmInfo>> | Record<Address, InnerFarmInfo>;
|
|
21
|
-
rewardPoolsSupply: Record<Address, bigint>;
|
|
22
|
-
tokensList: Record<Address, TokenData>;
|
|
23
|
-
currentTimestamp: number;
|
|
24
|
-
}
|
|
25
|
-
interface GetCAExtraAPYProps {
|
|
26
|
-
assets: Array<Asset>;
|
|
27
|
-
supply: Record<Address, bigint> | Record<Address, Asset>;
|
|
28
|
-
rewardInfo: Record<Address, Array<InnerFarmInfo>>;
|
|
29
|
-
currentTimestamp: number;
|
|
30
|
-
prices: Record<Address, bigint>;
|
|
31
|
-
tokensList: Record<Address, TokenData>;
|
|
32
|
-
}
|
|
33
|
-
export declare class GearboxRewardsApy {
|
|
34
|
-
private constructor();
|
|
35
|
-
static getPoolExtraAPY_V3({ rewardPoolsInfo, stakedDieselToken, ...restProps }: GetPoolExtraAPY_V3Props): Array<ExtraRewardApy>;
|
|
36
|
-
private static getPoolSingleExtraLmAPY_V3;
|
|
37
|
-
private static calculateAPY_V3;
|
|
38
|
-
static getCAExtraAPY_V3({ rewardInfo, assets, ...restProps }: GetCAExtraAPYProps): Array<ExtraRewardApy>;
|
|
39
|
-
private static getCASingleExtraAPY_V3;
|
|
40
|
-
}
|
|
41
|
-
export {};
|