@gearbox-protocol/sdk 11.1.3 → 11.1.5
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.
|
@@ -146,9 +146,16 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
146
146
|
* Implements {@link IRouterContract.findClaimAllRewards}
|
|
147
147
|
*/
|
|
148
148
|
async findClaimAllRewards(props) {
|
|
149
|
-
const
|
|
149
|
+
const record = props.tokensToClaim.reduce(
|
|
150
|
+
(acc, a) => {
|
|
151
|
+
acc[a.token.toLowerCase()] = a;
|
|
152
|
+
return acc;
|
|
153
|
+
},
|
|
154
|
+
{}
|
|
155
|
+
);
|
|
156
|
+
const tData = props.creditAccount.tokens.map((a) => ({
|
|
150
157
|
balance: 0n,
|
|
151
|
-
claimRewards:
|
|
158
|
+
claimRewards: !!record[a.token.toLowerCase()],
|
|
152
159
|
leftoverBalance: 0n,
|
|
153
160
|
numSplits: 1n,
|
|
154
161
|
token: a.token
|
|
@@ -261,7 +268,7 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
261
268
|
}).map(({ token, balance }) => {
|
|
262
269
|
return {
|
|
263
270
|
token,
|
|
264
|
-
balance: priceOracle
|
|
271
|
+
balance: this.#convertToUSDForSort(priceOracle, token, balance)
|
|
265
272
|
};
|
|
266
273
|
}).sort((a, b) => {
|
|
267
274
|
return a.balance > b.balance ? -1 : 1;
|
|
@@ -284,6 +291,18 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
284
291
|
}
|
|
285
292
|
return (token) => map.get(token) ?? 1n;
|
|
286
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Tries to get some value even when prices are broken, since it's only needed for sorting
|
|
296
|
+
* @param oracle
|
|
297
|
+
* @param token
|
|
298
|
+
* @param amount
|
|
299
|
+
* @returns
|
|
300
|
+
*/
|
|
301
|
+
#convertToUSDForSort(oracle, token, amount) {
|
|
302
|
+
const scale = 10n ** BigInt(this.sdk.tokensMeta.get(token)?.decimals ?? 0);
|
|
303
|
+
const price = oracle.mainPrices.get(token)?.price || oracle.reservePrices.get(token)?.price || scale;
|
|
304
|
+
return amount * price / scale;
|
|
305
|
+
}
|
|
287
306
|
#debugTokenData(tData) {
|
|
288
307
|
return tData.map((t) => ({
|
|
289
308
|
token: this.labelAddress(t.token),
|
|
@@ -123,9 +123,16 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
123
123
|
* Implements {@link IRouterContract.findClaimAllRewards}
|
|
124
124
|
*/
|
|
125
125
|
async findClaimAllRewards(props) {
|
|
126
|
-
const
|
|
126
|
+
const record = props.tokensToClaim.reduce(
|
|
127
|
+
(acc, a) => {
|
|
128
|
+
acc[a.token.toLowerCase()] = a;
|
|
129
|
+
return acc;
|
|
130
|
+
},
|
|
131
|
+
{}
|
|
132
|
+
);
|
|
133
|
+
const tData = props.creditAccount.tokens.map((a) => ({
|
|
127
134
|
balance: 0n,
|
|
128
|
-
claimRewards:
|
|
135
|
+
claimRewards: !!record[a.token.toLowerCase()],
|
|
129
136
|
leftoverBalance: 0n,
|
|
130
137
|
numSplits: 1n,
|
|
131
138
|
token: a.token
|
|
@@ -238,7 +245,7 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
238
245
|
}).map(({ token, balance }) => {
|
|
239
246
|
return {
|
|
240
247
|
token,
|
|
241
|
-
balance: priceOracle
|
|
248
|
+
balance: this.#convertToUSDForSort(priceOracle, token, balance)
|
|
242
249
|
};
|
|
243
250
|
}).sort((a, b) => {
|
|
244
251
|
return a.balance > b.balance ? -1 : 1;
|
|
@@ -261,6 +268,18 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
261
268
|
}
|
|
262
269
|
return (token) => map.get(token) ?? 1n;
|
|
263
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Tries to get some value even when prices are broken, since it's only needed for sorting
|
|
273
|
+
* @param oracle
|
|
274
|
+
* @param token
|
|
275
|
+
* @param amount
|
|
276
|
+
* @returns
|
|
277
|
+
*/
|
|
278
|
+
#convertToUSDForSort(oracle, token, amount) {
|
|
279
|
+
const scale = 10n ** BigInt(this.sdk.tokensMeta.get(token)?.decimals ?? 0);
|
|
280
|
+
const price = oracle.mainPrices.get(token)?.price || oracle.reservePrices.get(token)?.price || scale;
|
|
281
|
+
return amount * price / scale;
|
|
282
|
+
}
|
|
264
283
|
#debugTokenData(tData) {
|
|
265
284
|
return tData.map((t) => ({
|
|
266
285
|
token: this.labelAddress(t.token),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.5",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"lint-staged": "^16.2.6",
|
|
77
77
|
"pino": "^10.1.0",
|
|
78
78
|
"pino-pretty": "^13.1.2",
|
|
79
|
-
"tsup": "^8.5.
|
|
79
|
+
"tsup": "^8.5.1",
|
|
80
80
|
"tsx": "^4.20.6",
|
|
81
81
|
"typescript": "^5.9.3",
|
|
82
82
|
"viem-deal": "^2.0.4",
|