@gearbox-protocol/sdk 11.1.3 → 11.1.4
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.
|
@@ -261,7 +261,7 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
261
261
|
}).map(({ token, balance }) => {
|
|
262
262
|
return {
|
|
263
263
|
token,
|
|
264
|
-
balance: priceOracle
|
|
264
|
+
balance: this.#convertToUSDForSort(priceOracle, token, balance)
|
|
265
265
|
};
|
|
266
266
|
}).sort((a, b) => {
|
|
267
267
|
return a.balance > b.balance ? -1 : 1;
|
|
@@ -284,6 +284,18 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
284
284
|
}
|
|
285
285
|
return (token) => map.get(token) ?? 1n;
|
|
286
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Tries to get some value even when prices are broken, since it's only needed for sorting
|
|
289
|
+
* @param oracle
|
|
290
|
+
* @param token
|
|
291
|
+
* @param amount
|
|
292
|
+
* @returns
|
|
293
|
+
*/
|
|
294
|
+
#convertToUSDForSort(oracle, token, amount) {
|
|
295
|
+
const scale = 10n ** BigInt(this.sdk.tokensMeta.get(token)?.decimals ?? 0);
|
|
296
|
+
const price = oracle.mainPrices.get(token)?.price || oracle.reservePrices.get(token)?.price || scale;
|
|
297
|
+
return amount * price / scale;
|
|
298
|
+
}
|
|
287
299
|
#debugTokenData(tData) {
|
|
288
300
|
return tData.map((t) => ({
|
|
289
301
|
token: this.labelAddress(t.token),
|
|
@@ -238,7 +238,7 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
238
238
|
}).map(({ token, balance }) => {
|
|
239
239
|
return {
|
|
240
240
|
token,
|
|
241
|
-
balance: priceOracle
|
|
241
|
+
balance: this.#convertToUSDForSort(priceOracle, token, balance)
|
|
242
242
|
};
|
|
243
243
|
}).sort((a, b) => {
|
|
244
244
|
return a.balance > b.balance ? -1 : 1;
|
|
@@ -261,6 +261,18 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
261
261
|
}
|
|
262
262
|
return (token) => map.get(token) ?? 1n;
|
|
263
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Tries to get some value even when prices are broken, since it's only needed for sorting
|
|
266
|
+
* @param oracle
|
|
267
|
+
* @param token
|
|
268
|
+
* @param amount
|
|
269
|
+
* @returns
|
|
270
|
+
*/
|
|
271
|
+
#convertToUSDForSort(oracle, token, amount) {
|
|
272
|
+
const scale = 10n ** BigInt(this.sdk.tokensMeta.get(token)?.decimals ?? 0);
|
|
273
|
+
const price = oracle.mainPrices.get(token)?.price || oracle.reservePrices.get(token)?.price || scale;
|
|
274
|
+
return amount * price / scale;
|
|
275
|
+
}
|
|
264
276
|
#debugTokenData(tData) {
|
|
265
277
|
return tData.map((t) => ({
|
|
266
278
|
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.4",
|
|
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",
|