@gearbox-protocol/sdk 7.6.0 → 7.6.1
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.
|
@@ -474,27 +474,30 @@ class GearboxSDK {
|
|
|
474
474
|
return this.#marketRegister;
|
|
475
475
|
}
|
|
476
476
|
/**
|
|
477
|
-
* Returns router contract that will work for given credit manager or credit facade
|
|
477
|
+
* Returns router contract that will work for given credit manager or credit facade, or simply version range
|
|
478
478
|
* @param params
|
|
479
479
|
* @returns
|
|
480
480
|
*/
|
|
481
481
|
routerFor(params) {
|
|
482
|
-
let
|
|
483
|
-
if (
|
|
484
|
-
|
|
482
|
+
let routerRange;
|
|
483
|
+
if (Array.isArray(params)) {
|
|
484
|
+
routerRange = params;
|
|
485
485
|
} else {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
486
|
+
let facadeAddr;
|
|
487
|
+
if ("creditFacade" in params) {
|
|
488
|
+
facadeAddr = (0, import_utils.toAddress)(params.creditFacade);
|
|
489
|
+
} else {
|
|
490
|
+
const cm = this.marketRegister.findCreditManager(
|
|
491
|
+
(0, import_utils.toAddress)(params.creditManager)
|
|
492
|
+
);
|
|
493
|
+
facadeAddr = cm.creditFacade.address;
|
|
494
|
+
}
|
|
495
|
+
const facadeV = this.contracts.mustGet(facadeAddr).version;
|
|
496
|
+
routerRange = (0, import_constants.isV310)(facadeV) ? import_constants.VERSION_RANGE_310 : import_constants.VERSION_RANGE_300;
|
|
490
497
|
}
|
|
491
|
-
const facadeV = this.contracts.mustGet(facadeAddr).version;
|
|
492
|
-
const routerRange = (0, import_constants.isV310)(facadeV) ? import_constants.VERSION_RANGE_310 : import_constants.VERSION_RANGE_300;
|
|
493
498
|
const routerEntry = this.addressProvider.getLatest(import_constants.AP_ROUTER, routerRange);
|
|
494
499
|
if (!routerEntry) {
|
|
495
|
-
throw new Error(
|
|
496
|
-
`router not found for facade v ${facadeV} at ${facadeAddr}`
|
|
497
|
-
);
|
|
500
|
+
throw new Error(`router not found in version range ${routerRange}`);
|
|
498
501
|
}
|
|
499
502
|
const [routerAddr, routerV] = routerEntry;
|
|
500
503
|
if (!this.contracts.has(routerAddr)) {
|
|
@@ -472,27 +472,30 @@ class GearboxSDK {
|
|
|
472
472
|
return this.#marketRegister;
|
|
473
473
|
}
|
|
474
474
|
/**
|
|
475
|
-
* Returns router contract that will work for given credit manager or credit facade
|
|
475
|
+
* Returns router contract that will work for given credit manager or credit facade, or simply version range
|
|
476
476
|
* @param params
|
|
477
477
|
* @returns
|
|
478
478
|
*/
|
|
479
479
|
routerFor(params) {
|
|
480
|
-
let
|
|
481
|
-
if (
|
|
482
|
-
|
|
480
|
+
let routerRange;
|
|
481
|
+
if (Array.isArray(params)) {
|
|
482
|
+
routerRange = params;
|
|
483
483
|
} else {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
484
|
+
let facadeAddr;
|
|
485
|
+
if ("creditFacade" in params) {
|
|
486
|
+
facadeAddr = toAddress(params.creditFacade);
|
|
487
|
+
} else {
|
|
488
|
+
const cm = this.marketRegister.findCreditManager(
|
|
489
|
+
toAddress(params.creditManager)
|
|
490
|
+
);
|
|
491
|
+
facadeAddr = cm.creditFacade.address;
|
|
492
|
+
}
|
|
493
|
+
const facadeV = this.contracts.mustGet(facadeAddr).version;
|
|
494
|
+
routerRange = isV310(facadeV) ? VERSION_RANGE_310 : VERSION_RANGE_300;
|
|
488
495
|
}
|
|
489
|
-
const facadeV = this.contracts.mustGet(facadeAddr).version;
|
|
490
|
-
const routerRange = isV310(facadeV) ? VERSION_RANGE_310 : VERSION_RANGE_300;
|
|
491
496
|
const routerEntry = this.addressProvider.getLatest(AP_ROUTER, routerRange);
|
|
492
497
|
if (!routerEntry) {
|
|
493
|
-
throw new Error(
|
|
494
|
-
`router not found for facade v ${facadeV} at ${facadeAddr}`
|
|
495
|
-
);
|
|
498
|
+
throw new Error(`router not found in version range ${routerRange}`);
|
|
496
499
|
}
|
|
497
500
|
const [routerAddr, routerV] = routerEntry;
|
|
498
501
|
if (!this.contracts.has(routerAddr)) {
|
|
@@ -3,6 +3,7 @@ import type { BaseContract, BaseState, IBaseContract } from "./base/index.js";
|
|
|
3
3
|
import { TokensMeta } from "./base/index.js";
|
|
4
4
|
import type { ConnectionOptions, NetworkOptions, TransportOptions } from "./chain/index.js";
|
|
5
5
|
import { Provider } from "./chain/index.js";
|
|
6
|
+
import type { VersionRange } from "./constants/index.js";
|
|
6
7
|
import type { IAddressProviderContract } from "./core/index.js";
|
|
7
8
|
import { BotListContract, GearStakingContract } from "./core/index.js";
|
|
8
9
|
import { MarketRegister } from "./market/MarketRegister.js";
|
|
@@ -152,7 +153,7 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
|
|
|
152
153
|
get gearStakingContract(): GearStakingContract | undefined;
|
|
153
154
|
get marketRegister(): MarketRegister;
|
|
154
155
|
/**
|
|
155
|
-
* Returns router contract that will work for given credit manager or credit facade
|
|
156
|
+
* Returns router contract that will work for given credit manager or credit facade, or simply version range
|
|
156
157
|
* @param params
|
|
157
158
|
* @returns
|
|
158
159
|
*/
|
|
@@ -160,5 +161,5 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
|
|
|
160
161
|
creditManager: Address | BaseState | IBaseContract;
|
|
161
162
|
} | {
|
|
162
163
|
creditFacade: Address | BaseState | IBaseContract;
|
|
163
|
-
}): IRouterContract;
|
|
164
|
+
} | VersionRange): IRouterContract;
|
|
164
165
|
}
|