@gearbox-protocol/sdk 4.1.9 → 4.2.0-next.2
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/sdk/GearboxSDK.js +68 -47
- package/dist/cjs/sdk/core/address-provider/{AddressProviderV3Contract.js → AddressProviderV300Contract.js} +9 -9
- package/dist/cjs/sdk/core/address-provider/{AddressProviderV3_1Contract.js → AddressProviderV310Contract.js} +9 -9
- package/dist/cjs/sdk/core/address-provider/createAddressProvider.js +25 -29
- package/dist/cjs/sdk/core/address-provider/index.js +4 -4
- package/dist/cjs/sdk/gauges/GaugeStakingService.js +15 -9
- package/dist/cjs/sdk/market/MarketRegister.js +5 -14
- package/dist/cjs/sdk/market/credit/CreditSuite.js +0 -5
- package/dist/cjs/sdk/utils/index.js +3 -1
- package/dist/cjs/sdk/{types/tvl.js → utils/version.js} +21 -2
- package/dist/esm/sdk/GearboxSDK.js +69 -53
- package/dist/esm/sdk/core/address-provider/{AddressProviderV3Contract.js → AddressProviderV300Contract.js} +5 -5
- package/dist/esm/sdk/core/address-provider/{AddressProviderV3_1Contract.js → AddressProviderV310Contract.js} +5 -5
- package/dist/esm/sdk/core/address-provider/createAddressProvider.js +23 -28
- package/dist/esm/sdk/core/address-provider/index.js +2 -2
- package/dist/esm/sdk/gauges/GaugeStakingService.js +15 -9
- package/dist/esm/sdk/market/MarketRegister.js +5 -14
- package/dist/esm/sdk/market/credit/CreditSuite.js +0 -5
- package/dist/esm/sdk/utils/index.js +1 -0
- package/dist/esm/sdk/utils/version.js +10 -0
- package/dist/types/sdk/GearboxSDK.d.ts +8 -3
- package/dist/types/sdk/core/address-provider/{AddressProviderV3Contract.d.ts → AddressProviderV300Contract.d.ts} +2 -2
- package/dist/types/sdk/core/address-provider/{AddressProviderV3_1Contract.d.ts → AddressProviderV310Contract.d.ts} +2 -2
- package/dist/types/sdk/core/address-provider/createAddressProvider.d.ts +2 -5
- package/dist/types/sdk/core/address-provider/index.d.ts +2 -2
- package/dist/types/sdk/market/MarketRegister.d.ts +3 -3
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +1 -2
- package/dist/types/sdk/types/index.d.ts +0 -1
- package/dist/types/sdk/types/state-human.d.ts +2 -2
- package/dist/types/sdk/types/state.d.ts +9 -0
- package/dist/types/sdk/utils/index.d.ts +1 -0
- package/dist/types/sdk/utils/version.d.ts +2 -0
- package/package.json +1 -1
- package/dist/esm/sdk/types/tvl.js +0 -0
- package/dist/types/sdk/types/tvl.d.ts +0 -4
|
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var GearboxSDK_exports = {};
|
|
20
20
|
__export(GearboxSDK_exports, {
|
|
21
|
-
GearboxSDK: () => GearboxSDK
|
|
21
|
+
GearboxSDK: () => GearboxSDK,
|
|
22
|
+
STATE_VERSION: () => STATE_VERSION
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(GearboxSDK_exports);
|
|
24
25
|
var import_viem = require("viem");
|
|
@@ -34,6 +35,7 @@ var import_utils = require("./utils/index.js");
|
|
|
34
35
|
var import_internal = require("./utils/internal/index.js");
|
|
35
36
|
var import_viem2 = require("./utils/viem/index.js");
|
|
36
37
|
const ERR_NOT_ATTACHED = new Error("Gearbox SDK not attached");
|
|
38
|
+
const STATE_VERSION = 1;
|
|
37
39
|
class GearboxSDK {
|
|
38
40
|
#hooks = new import_internal.Hooks();
|
|
39
41
|
// Represents chain object
|
|
@@ -45,13 +47,9 @@ class GearboxSDK {
|
|
|
45
47
|
#syncing = false;
|
|
46
48
|
// Collection of core singleton contracts
|
|
47
49
|
#addressProvider;
|
|
48
|
-
#botListContract;
|
|
49
|
-
#gearStakingContract;
|
|
50
50
|
#attachConfig;
|
|
51
51
|
// Collection of markets
|
|
52
52
|
#marketRegister;
|
|
53
|
-
// Routers by address
|
|
54
|
-
#routers = new import_utils.AddressMap();
|
|
55
53
|
logger;
|
|
56
54
|
/**
|
|
57
55
|
* Interest rate models can be reused across chain (and SDK operates on chain level)
|
|
@@ -119,6 +117,15 @@ class GearboxSDK {
|
|
|
119
117
|
marketConfigurators
|
|
120
118
|
});
|
|
121
119
|
}
|
|
120
|
+
static hydrate(options, state) {
|
|
121
|
+
const { logger, ...rest } = options;
|
|
122
|
+
const provider = new import_chain.Provider({
|
|
123
|
+
...rest,
|
|
124
|
+
chainId: state.chainId,
|
|
125
|
+
networkType: state.network
|
|
126
|
+
});
|
|
127
|
+
return new GearboxSDK({ provider, logger }).#hydrate(rest, state);
|
|
128
|
+
}
|
|
122
129
|
constructor(options) {
|
|
123
130
|
this.#provider = options.provider;
|
|
124
131
|
this.logger = options.logger;
|
|
@@ -139,7 +146,6 @@ class GearboxSDK {
|
|
|
139
146
|
addressProvider,
|
|
140
147
|
blockNumber,
|
|
141
148
|
redstoneHistoricTimestamp,
|
|
142
|
-
redstoneGateways,
|
|
143
149
|
ignoreUpdateablePrices,
|
|
144
150
|
marketConfigurators
|
|
145
151
|
} = opts;
|
|
@@ -167,12 +173,7 @@ class GearboxSDK {
|
|
|
167
173
|
);
|
|
168
174
|
this.#currentBlock = block.number;
|
|
169
175
|
this.#timestamp = block.timestamp;
|
|
170
|
-
|
|
171
|
-
this.priceFeeds.redstoneUpdater.historicalTimestamp = redstoneHistoricTimestamp === true ? Number(block.timestamp) * 1e3 : redstoneHistoricTimestamp;
|
|
172
|
-
}
|
|
173
|
-
if (redstoneGateways?.length) {
|
|
174
|
-
this.priceFeeds.redstoneUpdater.gateways = redstoneGateways;
|
|
175
|
-
}
|
|
176
|
+
this.#confugureRedstone(opts);
|
|
176
177
|
this.logger?.debug(
|
|
177
178
|
`${re}attach block number ${this.currentBlock} timestamp ${this.timestamp}`
|
|
178
179
|
);
|
|
@@ -181,23 +182,6 @@ class GearboxSDK {
|
|
|
181
182
|
`address provider version: ${this.#addressProvider.version}`
|
|
182
183
|
);
|
|
183
184
|
await this.#addressProvider.syncState(this.currentBlock);
|
|
184
|
-
try {
|
|
185
|
-
const botListAddress = this.#addressProvider.getAddress(
|
|
186
|
-
import_constants.AP_BOT_LIST,
|
|
187
|
-
import_constants.NO_VERSION
|
|
188
|
-
);
|
|
189
|
-
this.#botListContract = new import_core.BotListContract(this, botListAddress);
|
|
190
|
-
} catch (e) {
|
|
191
|
-
this.logger?.error(e);
|
|
192
|
-
}
|
|
193
|
-
const gearStakingAddress = this.#addressProvider.getAddress(
|
|
194
|
-
import_constants.AP_GEAR_STAKING,
|
|
195
|
-
import_constants.NO_VERSION
|
|
196
|
-
);
|
|
197
|
-
this.#gearStakingContract = new import_core.GearStakingContract(
|
|
198
|
-
this,
|
|
199
|
-
gearStakingAddress
|
|
200
|
-
);
|
|
201
185
|
this.#marketRegister = new import_MarketRegister.MarketRegister(this);
|
|
202
186
|
await this.#marketRegister.loadMarkets(
|
|
203
187
|
marketConfigurators,
|
|
@@ -224,13 +208,48 @@ class GearboxSDK {
|
|
|
224
208
|
this.logger?.info(`${re}attach time: ${Date.now() - time} ms`);
|
|
225
209
|
return this;
|
|
226
210
|
}
|
|
211
|
+
#hydrate(options, state) {
|
|
212
|
+
const { logger: _logger, ...opts } = options;
|
|
213
|
+
if (state.version !== STATE_VERSION) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
`hydrated state version is ${state.version}, but expected ${STATE_VERSION}`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
this.#currentBlock = state.currentBlock;
|
|
219
|
+
this.#timestamp = state.timestamp;
|
|
220
|
+
this.#confugureRedstone(opts);
|
|
221
|
+
this.#addressProvider = (0, import_core.hydrateAddressProvider)(this, state.addressProvider);
|
|
222
|
+
this.logger?.debug(
|
|
223
|
+
`address provider version: ${this.#addressProvider.version}`
|
|
224
|
+
);
|
|
225
|
+
this.#marketRegister = new import_MarketRegister.MarketRegister(this);
|
|
226
|
+
this.#marketRegister.hydrate(state.markets);
|
|
227
|
+
this.#attachConfig = {
|
|
228
|
+
...opts,
|
|
229
|
+
addressProvider: this.addressProvider.address,
|
|
230
|
+
marketConfigurators: this.marketRegister.marketConfigurators.map(
|
|
231
|
+
(m) => m.address
|
|
232
|
+
),
|
|
233
|
+
blockNumber: this.currentBlock
|
|
234
|
+
};
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
#confugureRedstone(opts) {
|
|
238
|
+
const { redstoneGateways, redstoneHistoricTimestamp } = opts;
|
|
239
|
+
if (redstoneHistoricTimestamp) {
|
|
240
|
+
this.priceFeeds.redstoneUpdater.historicalTimestamp = redstoneHistoricTimestamp === true ? Number(this.timestamp) * 1e3 : redstoneHistoricTimestamp;
|
|
241
|
+
}
|
|
242
|
+
if (redstoneGateways?.length) {
|
|
243
|
+
this.priceFeeds.redstoneUpdater.gateways = redstoneGateways;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
227
246
|
/**
|
|
228
247
|
* Reattach SDK with the same config as before, without re-creating instance. Will load all state from scratch
|
|
229
248
|
* Be mindful of block number, for example
|
|
230
249
|
*/
|
|
231
250
|
async reattach() {
|
|
232
251
|
if (!this.#attachConfig) {
|
|
233
|
-
throw new Error("
|
|
252
|
+
throw new Error("cannot reattach, attach config is not set");
|
|
234
253
|
}
|
|
235
254
|
await this.#attach(this.#attachConfig);
|
|
236
255
|
}
|
|
@@ -288,8 +307,8 @@ class GearboxSDK {
|
|
|
288
307
|
timestamp: Number(this.timestamp),
|
|
289
308
|
core: {
|
|
290
309
|
addressProviderV3: this.addressProvider.stateHuman(raw),
|
|
291
|
-
botList: this.botListContract
|
|
292
|
-
gearStakingV3: this.gearStakingContract
|
|
310
|
+
botList: this.botListContract?.stateHuman(raw),
|
|
311
|
+
gearStakingV3: this.gearStakingContract?.stateHuman(raw)
|
|
293
312
|
},
|
|
294
313
|
tokens: this.tokensMeta.values(),
|
|
295
314
|
plugins: Object.fromEntries(
|
|
@@ -303,16 +322,15 @@ class GearboxSDK {
|
|
|
303
322
|
}
|
|
304
323
|
get state() {
|
|
305
324
|
return {
|
|
325
|
+
version: STATE_VERSION,
|
|
326
|
+
network: this.provider.networkType,
|
|
327
|
+
chainId: this.provider.chainId,
|
|
306
328
|
currentBlock: this.currentBlock,
|
|
329
|
+
timestamp: this.timestamp,
|
|
307
330
|
addressProvider: this.addressProvider.state,
|
|
308
331
|
markets: this.marketRegister.state
|
|
309
332
|
};
|
|
310
333
|
}
|
|
311
|
-
async tvl() {
|
|
312
|
-
const { tvl, tvlUSD } = await this.marketRegister.tvl();
|
|
313
|
-
this.logger?.info(tvl);
|
|
314
|
-
this.logger?.info(`Total TVL: ${(0, import_utils.formatBN)(tvlUSD, 8)}`);
|
|
315
|
-
}
|
|
316
334
|
/**
|
|
317
335
|
* Reloads markets states based on events from last processed block to new block (defaults to latest block)
|
|
318
336
|
* @param opts
|
|
@@ -419,16 +437,18 @@ class GearboxSDK {
|
|
|
419
437
|
return this.#addressProvider;
|
|
420
438
|
}
|
|
421
439
|
get botListContract() {
|
|
422
|
-
|
|
423
|
-
|
|
440
|
+
const addr = this.addressProvider.getAddress(import_constants.AP_BOT_LIST, import_constants.NO_VERSION);
|
|
441
|
+
if (!this.contracts.has(addr)) {
|
|
442
|
+
return new import_core.BotListContract(this, addr);
|
|
424
443
|
}
|
|
425
|
-
return this
|
|
444
|
+
return this.contracts.get(addr);
|
|
426
445
|
}
|
|
427
446
|
get gearStakingContract() {
|
|
428
|
-
|
|
429
|
-
|
|
447
|
+
const addr = this.addressProvider.getAddress(import_constants.AP_GEAR_STAKING, import_constants.NO_VERSION);
|
|
448
|
+
if (!this.contracts.has(addr)) {
|
|
449
|
+
return new import_core.GearStakingContract(this, addr);
|
|
430
450
|
}
|
|
431
|
-
return this
|
|
451
|
+
return this.contracts.get(addr);
|
|
432
452
|
}
|
|
433
453
|
get marketRegister() {
|
|
434
454
|
if (this.#marketRegister === void 0) {
|
|
@@ -463,13 +483,14 @@ class GearboxSDK {
|
|
|
463
483
|
);
|
|
464
484
|
}
|
|
465
485
|
const [routerAddr, routerV] = routerEntry;
|
|
466
|
-
if (!this
|
|
467
|
-
|
|
486
|
+
if (!this.contracts.has(routerAddr)) {
|
|
487
|
+
return (0, import_router.createRouter)(this, routerAddr, routerV);
|
|
468
488
|
}
|
|
469
|
-
return this
|
|
489
|
+
return this.contracts.get(routerAddr);
|
|
470
490
|
}
|
|
471
491
|
}
|
|
472
492
|
// Annotate the CommonJS export names for ESM import in node:
|
|
473
493
|
0 && (module.exports = {
|
|
474
|
-
GearboxSDK
|
|
494
|
+
GearboxSDK,
|
|
495
|
+
STATE_VERSION
|
|
475
496
|
});
|
|
@@ -26,26 +26,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var AddressProviderV300Contract_exports = {};
|
|
30
|
+
__export(AddressProviderV300Contract_exports, {
|
|
31
|
+
AddressProviderV300Contract: () => AddressProviderV300Contract
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(AddressProviderV300Contract_exports);
|
|
34
34
|
var import_viem = require("viem");
|
|
35
35
|
var import_v300 = require("../../../abi/v300.js");
|
|
36
36
|
var import_constants = require("../../constants/index.js");
|
|
37
37
|
var import_viem2 = require("../../utils/viem/index.js");
|
|
38
38
|
var import_AbstractAddressProviderContract = __toESM(require("./AbstractAddressProviderContract.js"));
|
|
39
39
|
const abi = import_v300.iAddressProviderV300Abi;
|
|
40
|
-
class
|
|
41
|
-
constructor(sdk, address, addresses = {}) {
|
|
40
|
+
class AddressProviderV300Contract extends import_AbstractAddressProviderContract.default {
|
|
41
|
+
constructor(sdk, address, version, addresses = {}) {
|
|
42
42
|
super(
|
|
43
43
|
sdk,
|
|
44
44
|
{
|
|
45
45
|
addr: address,
|
|
46
|
-
name: "
|
|
46
|
+
name: "AddressProviderV300",
|
|
47
47
|
abi,
|
|
48
|
-
version
|
|
48
|
+
version
|
|
49
49
|
},
|
|
50
50
|
addresses
|
|
51
51
|
);
|
|
@@ -108,5 +108,5 @@ class AddressProviderContractV3 extends import_AbstractAddressProviderContract.d
|
|
|
108
108
|
}
|
|
109
109
|
// Annotate the CommonJS export names for ESM import in node:
|
|
110
110
|
0 && (module.exports = {
|
|
111
|
-
|
|
111
|
+
AddressProviderV300Contract
|
|
112
112
|
});
|
|
@@ -26,24 +26,24 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
|
|
29
|
+
var AddressProviderV310Contract_exports = {};
|
|
30
|
+
__export(AddressProviderV310Contract_exports, {
|
|
31
|
+
AddressProviderV310Contract: () => AddressProviderV310Contract
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(AddressProviderV310Contract_exports);
|
|
34
34
|
var import_viem = require("viem");
|
|
35
35
|
var import_v310 = require("../../../abi/v310.js");
|
|
36
36
|
var import_AbstractAddressProviderContract = __toESM(require("./AbstractAddressProviderContract.js"));
|
|
37
37
|
const abi = import_v310.iAddressProviderV310Abi;
|
|
38
|
-
class
|
|
39
|
-
constructor(sdk, address, addresses = {}) {
|
|
38
|
+
class AddressProviderV310Contract extends import_AbstractAddressProviderContract.default {
|
|
39
|
+
constructor(sdk, address, version, addresses = {}) {
|
|
40
40
|
super(
|
|
41
41
|
sdk,
|
|
42
42
|
{
|
|
43
43
|
addr: address,
|
|
44
|
-
name: "
|
|
44
|
+
name: "AddressProviderV310",
|
|
45
45
|
abi,
|
|
46
|
-
version
|
|
46
|
+
version
|
|
47
47
|
},
|
|
48
48
|
addresses
|
|
49
49
|
);
|
|
@@ -93,5 +93,5 @@ class AddressProviderContractV3_1 extends import_AbstractAddressProviderContract
|
|
|
93
93
|
}
|
|
94
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
95
95
|
0 && (module.exports = {
|
|
96
|
-
|
|
96
|
+
AddressProviderV310Contract
|
|
97
97
|
});
|
|
@@ -18,41 +18,37 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var createAddressProvider_exports = {};
|
|
20
20
|
__export(createAddressProvider_exports, {
|
|
21
|
-
createAddressProvider: () => createAddressProvider
|
|
21
|
+
createAddressProvider: () => createAddressProvider,
|
|
22
|
+
hydrateAddressProvider: () => hydrateAddressProvider
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(createAddressProvider_exports);
|
|
24
25
|
var import_iVersion = require("../../../abi/iVersion.js");
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
var import_utils = require("../../utils/index.js");
|
|
27
|
+
var import_AddressProviderV300Contract = require("./AddressProviderV300Contract.js");
|
|
28
|
+
var import_AddressProviderV310Contract = require("./AddressProviderV310Contract.js");
|
|
29
|
+
async function createAddressProvider(sdk, address) {
|
|
30
|
+
const v = await sdk.provider.publicClient.readContract({
|
|
31
|
+
address,
|
|
32
|
+
abi: import_iVersion.iVersionAbi,
|
|
33
|
+
functionName: "version"
|
|
34
|
+
});
|
|
35
|
+
return newAddressProvider(sdk, address, Number(v));
|
|
36
|
+
}
|
|
37
|
+
function hydrateAddressProvider(sdk, state) {
|
|
38
|
+
const { addr, version } = state.baseParams;
|
|
39
|
+
return newAddressProvider(sdk, addr, Number(version), state.addresses);
|
|
40
|
+
}
|
|
41
|
+
function newAddressProvider(sdk, address, version, addresses) {
|
|
42
|
+
if ((0, import_utils.isV300)(version)) {
|
|
43
|
+
return new import_AddressProviderV300Contract.AddressProviderV300Contract(sdk, address, version, addresses);
|
|
37
44
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return new import_AddressProviderV3Contract.AddressProviderContractV3(
|
|
41
|
-
sdk,
|
|
42
|
-
addr,
|
|
43
|
-
options?.state?.addresses
|
|
44
|
-
);
|
|
45
|
-
case 310:
|
|
46
|
-
return new import_AddressProviderV3_1Contract.AddressProviderContractV3_1(
|
|
47
|
-
sdk,
|
|
48
|
-
addr,
|
|
49
|
-
options?.state?.addresses
|
|
50
|
-
);
|
|
51
|
-
default:
|
|
52
|
-
throw new Error(`Unsupported address provider version: ${v}`);
|
|
45
|
+
if ((0, import_utils.isV310)(version)) {
|
|
46
|
+
return new import_AddressProviderV310Contract.AddressProviderV310Contract(sdk, address, version, addresses);
|
|
53
47
|
}
|
|
48
|
+
throw new Error(`unsupported address provider version: ${version}`);
|
|
54
49
|
}
|
|
55
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
51
|
0 && (module.exports = {
|
|
57
|
-
createAddressProvider
|
|
52
|
+
createAddressProvider,
|
|
53
|
+
hydrateAddressProvider
|
|
58
54
|
});
|
|
@@ -15,14 +15,14 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var address_provider_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(address_provider_exports);
|
|
18
|
-
__reExport(address_provider_exports, require("./
|
|
19
|
-
__reExport(address_provider_exports, require("./
|
|
18
|
+
__reExport(address_provider_exports, require("./AddressProviderV300Contract.js"), module.exports);
|
|
19
|
+
__reExport(address_provider_exports, require("./AddressProviderV310Contract.js"), module.exports);
|
|
20
20
|
__reExport(address_provider_exports, require("./createAddressProvider.js"), module.exports);
|
|
21
21
|
__reExport(address_provider_exports, require("./types.js"), module.exports);
|
|
22
22
|
// Annotate the CommonJS export names for ESM import in node:
|
|
23
23
|
0 && (module.exports = {
|
|
24
|
-
...require("./
|
|
25
|
-
...require("./
|
|
24
|
+
...require("./AddressProviderV300Contract.js"),
|
|
25
|
+
...require("./AddressProviderV310Contract.js"),
|
|
26
26
|
...require("./createAddressProvider.js"),
|
|
27
27
|
...require("./types.js")
|
|
28
28
|
});
|
|
@@ -37,7 +37,13 @@ class GaugeStakingService extends import_base.SDKConstruct {
|
|
|
37
37
|
*/
|
|
38
38
|
async getGaugeStakingData(wallet) {
|
|
39
39
|
const marketFilter = this.sdk.marketRegister.marketFilter;
|
|
40
|
-
|
|
40
|
+
const gearStaking = this.sdk.gearStakingContract;
|
|
41
|
+
if (!marketFilter) {
|
|
42
|
+
throw new Error("market filter is not set");
|
|
43
|
+
}
|
|
44
|
+
if (!gearStaking) {
|
|
45
|
+
throw new Error("gear staking contract is not set");
|
|
46
|
+
}
|
|
41
47
|
const [gauges, availableBalance, totalBalance, withdrawableAmounts, epoch] = await this.provider.publicClient.multicall({
|
|
42
48
|
allowFailure: false,
|
|
43
49
|
contracts: [
|
|
@@ -48,26 +54,26 @@ class GaugeStakingService extends import_base.SDKConstruct {
|
|
|
48
54
|
args: [marketFilter, wallet]
|
|
49
55
|
},
|
|
50
56
|
{
|
|
51
|
-
address:
|
|
52
|
-
abi:
|
|
57
|
+
address: gearStaking.address,
|
|
58
|
+
abi: gearStaking.abi,
|
|
53
59
|
functionName: "availableBalance",
|
|
54
60
|
args: [wallet]
|
|
55
61
|
},
|
|
56
62
|
{
|
|
57
|
-
address:
|
|
58
|
-
abi:
|
|
63
|
+
address: gearStaking.address,
|
|
64
|
+
abi: gearStaking.abi,
|
|
59
65
|
functionName: "balanceOf",
|
|
60
66
|
args: [wallet]
|
|
61
67
|
},
|
|
62
68
|
{
|
|
63
|
-
address:
|
|
64
|
-
abi:
|
|
69
|
+
address: gearStaking.address,
|
|
70
|
+
abi: gearStaking.abi,
|
|
65
71
|
functionName: "getWithdrawableAmounts",
|
|
66
72
|
args: [wallet]
|
|
67
73
|
},
|
|
68
74
|
{
|
|
69
|
-
address:
|
|
70
|
-
abi:
|
|
75
|
+
address: gearStaking.address,
|
|
76
|
+
abi: gearStaking.abi,
|
|
71
77
|
functionName: "getCurrentEpoch",
|
|
72
78
|
args: []
|
|
73
79
|
}
|
|
@@ -34,10 +34,13 @@ class MarketRegister extends import_base.SDKConstruct {
|
|
|
34
34
|
*/
|
|
35
35
|
#markets = new import_utils.AddressMap(void 0, "markets");
|
|
36
36
|
#marketFilter;
|
|
37
|
-
constructor(sdk
|
|
37
|
+
constructor(sdk) {
|
|
38
38
|
super(sdk);
|
|
39
39
|
this.#logger = (0, import_utils.childLogger)("MarketRegister", sdk.logger);
|
|
40
|
-
|
|
40
|
+
}
|
|
41
|
+
hydrate(state) {
|
|
42
|
+
this.#markets.clear();
|
|
43
|
+
for (const data of state) {
|
|
41
44
|
this.#markets.upsert(
|
|
42
45
|
data.pool.baseParams.addr,
|
|
43
46
|
new import_MarketSuite.MarketSuite(this.sdk, data)
|
|
@@ -230,18 +233,6 @@ class MarketRegister extends import_base.SDKConstruct {
|
|
|
230
233
|
get markets() {
|
|
231
234
|
return this.#markets.values();
|
|
232
235
|
}
|
|
233
|
-
async tvl() {
|
|
234
|
-
const creditManagers = this.creditManagers;
|
|
235
|
-
const tvls = await Promise.all(creditManagers.map((cm) => cm.tvl()));
|
|
236
|
-
return tvls.reduce(
|
|
237
|
-
(acc, curr) => {
|
|
238
|
-
acc.tvl += curr.tvl;
|
|
239
|
-
acc.tvlUSD += curr.tvlUSD;
|
|
240
|
-
return acc;
|
|
241
|
-
},
|
|
242
|
-
{ tvl: 0n, tvlUSD: 0n }
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
236
|
}
|
|
246
237
|
// Annotate the CommonJS export names for ESM import in node:
|
|
247
238
|
0 && (module.exports = {
|
|
@@ -58,11 +58,6 @@ class CreditSuite extends import_base.SDKConstruct {
|
|
|
58
58
|
get router() {
|
|
59
59
|
return this.sdk.routerFor(this);
|
|
60
60
|
}
|
|
61
|
-
async tvl() {
|
|
62
|
-
const tvl = 0n;
|
|
63
|
-
const tvlUSD = 0n;
|
|
64
|
-
return { tvl, tvlUSD };
|
|
65
|
-
}
|
|
66
61
|
get dirty() {
|
|
67
62
|
return this.creditFacade.dirty || this.creditManager.dirty || this.creditConfigurator.dirty;
|
|
68
63
|
}
|
|
@@ -27,6 +27,7 @@ __reExport(utils_exports, require("./json.js"), module.exports);
|
|
|
27
27
|
__reExport(utils_exports, require("./mappers.js"), module.exports);
|
|
28
28
|
__reExport(utils_exports, require("./retry.js"), module.exports);
|
|
29
29
|
__reExport(utils_exports, require("./toAddress.js"), module.exports);
|
|
30
|
+
__reExport(utils_exports, require("./version.js"), module.exports);
|
|
30
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
32
|
0 && (module.exports = {
|
|
32
33
|
...require("./AddressMap.js"),
|
|
@@ -40,5 +41,6 @@ __reExport(utils_exports, require("./toAddress.js"), module.exports);
|
|
|
40
41
|
...require("./json.js"),
|
|
41
42
|
...require("./mappers.js"),
|
|
42
43
|
...require("./retry.js"),
|
|
43
|
-
...require("./toAddress.js")
|
|
44
|
+
...require("./toAddress.js"),
|
|
45
|
+
...require("./version.js")
|
|
44
46
|
});
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
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
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -12,5 +16,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
16
|
return to;
|
|
13
17
|
};
|
|
14
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
|
|
19
|
+
var version_exports = {};
|
|
20
|
+
__export(version_exports, {
|
|
21
|
+
isV300: () => isV300,
|
|
22
|
+
isV310: () => isV310
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(version_exports);
|
|
25
|
+
function isV300(version) {
|
|
26
|
+
return version >= 300 && version < 310;
|
|
27
|
+
}
|
|
28
|
+
function isV310(version) {
|
|
29
|
+
return version >= 310 && version < 320;
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
isV300,
|
|
34
|
+
isV310
|
|
35
|
+
});
|
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
BotListContract,
|
|
19
19
|
createAddressProvider,
|
|
20
|
-
GearStakingContract
|
|
20
|
+
GearStakingContract,
|
|
21
|
+
hydrateAddressProvider
|
|
21
22
|
} from "./core/index.js";
|
|
22
23
|
import { MarketRegister } from "./market/MarketRegister.js";
|
|
23
24
|
import { PriceFeedRegister } from "./market/pricefeeds/index.js";
|
|
@@ -25,15 +26,11 @@ import {
|
|
|
25
26
|
defaultPlugins
|
|
26
27
|
} from "./plugins/index.js";
|
|
27
28
|
import { createRouter } from "./router/index.js";
|
|
28
|
-
import {
|
|
29
|
-
AddressMap,
|
|
30
|
-
formatBN,
|
|
31
|
-
toAddress,
|
|
32
|
-
TypedObjectUtils
|
|
33
|
-
} from "./utils/index.js";
|
|
29
|
+
import { AddressMap, toAddress, TypedObjectUtils } from "./utils/index.js";
|
|
34
30
|
import { Hooks } from "./utils/internal/index.js";
|
|
35
31
|
import { getLogsSafe } from "./utils/viem/index.js";
|
|
36
32
|
const ERR_NOT_ATTACHED = new Error("Gearbox SDK not attached");
|
|
33
|
+
const STATE_VERSION = 1;
|
|
37
34
|
class GearboxSDK {
|
|
38
35
|
#hooks = new Hooks();
|
|
39
36
|
// Represents chain object
|
|
@@ -45,13 +42,9 @@ class GearboxSDK {
|
|
|
45
42
|
#syncing = false;
|
|
46
43
|
// Collection of core singleton contracts
|
|
47
44
|
#addressProvider;
|
|
48
|
-
#botListContract;
|
|
49
|
-
#gearStakingContract;
|
|
50
45
|
#attachConfig;
|
|
51
46
|
// Collection of markets
|
|
52
47
|
#marketRegister;
|
|
53
|
-
// Routers by address
|
|
54
|
-
#routers = new AddressMap();
|
|
55
48
|
logger;
|
|
56
49
|
/**
|
|
57
50
|
* Interest rate models can be reused across chain (and SDK operates on chain level)
|
|
@@ -119,6 +112,15 @@ class GearboxSDK {
|
|
|
119
112
|
marketConfigurators
|
|
120
113
|
});
|
|
121
114
|
}
|
|
115
|
+
static hydrate(options, state) {
|
|
116
|
+
const { logger, ...rest } = options;
|
|
117
|
+
const provider = new Provider({
|
|
118
|
+
...rest,
|
|
119
|
+
chainId: state.chainId,
|
|
120
|
+
networkType: state.network
|
|
121
|
+
});
|
|
122
|
+
return new GearboxSDK({ provider, logger }).#hydrate(rest, state);
|
|
123
|
+
}
|
|
122
124
|
constructor(options) {
|
|
123
125
|
this.#provider = options.provider;
|
|
124
126
|
this.logger = options.logger;
|
|
@@ -139,7 +141,6 @@ class GearboxSDK {
|
|
|
139
141
|
addressProvider,
|
|
140
142
|
blockNumber,
|
|
141
143
|
redstoneHistoricTimestamp,
|
|
142
|
-
redstoneGateways,
|
|
143
144
|
ignoreUpdateablePrices,
|
|
144
145
|
marketConfigurators
|
|
145
146
|
} = opts;
|
|
@@ -167,12 +168,7 @@ class GearboxSDK {
|
|
|
167
168
|
);
|
|
168
169
|
this.#currentBlock = block.number;
|
|
169
170
|
this.#timestamp = block.timestamp;
|
|
170
|
-
|
|
171
|
-
this.priceFeeds.redstoneUpdater.historicalTimestamp = redstoneHistoricTimestamp === true ? Number(block.timestamp) * 1e3 : redstoneHistoricTimestamp;
|
|
172
|
-
}
|
|
173
|
-
if (redstoneGateways?.length) {
|
|
174
|
-
this.priceFeeds.redstoneUpdater.gateways = redstoneGateways;
|
|
175
|
-
}
|
|
171
|
+
this.#confugureRedstone(opts);
|
|
176
172
|
this.logger?.debug(
|
|
177
173
|
`${re}attach block number ${this.currentBlock} timestamp ${this.timestamp}`
|
|
178
174
|
);
|
|
@@ -181,23 +177,6 @@ class GearboxSDK {
|
|
|
181
177
|
`address provider version: ${this.#addressProvider.version}`
|
|
182
178
|
);
|
|
183
179
|
await this.#addressProvider.syncState(this.currentBlock);
|
|
184
|
-
try {
|
|
185
|
-
const botListAddress = this.#addressProvider.getAddress(
|
|
186
|
-
AP_BOT_LIST,
|
|
187
|
-
NO_VERSION
|
|
188
|
-
);
|
|
189
|
-
this.#botListContract = new BotListContract(this, botListAddress);
|
|
190
|
-
} catch (e) {
|
|
191
|
-
this.logger?.error(e);
|
|
192
|
-
}
|
|
193
|
-
const gearStakingAddress = this.#addressProvider.getAddress(
|
|
194
|
-
AP_GEAR_STAKING,
|
|
195
|
-
NO_VERSION
|
|
196
|
-
);
|
|
197
|
-
this.#gearStakingContract = new GearStakingContract(
|
|
198
|
-
this,
|
|
199
|
-
gearStakingAddress
|
|
200
|
-
);
|
|
201
180
|
this.#marketRegister = new MarketRegister(this);
|
|
202
181
|
await this.#marketRegister.loadMarkets(
|
|
203
182
|
marketConfigurators,
|
|
@@ -224,13 +203,48 @@ class GearboxSDK {
|
|
|
224
203
|
this.logger?.info(`${re}attach time: ${Date.now() - time} ms`);
|
|
225
204
|
return this;
|
|
226
205
|
}
|
|
206
|
+
#hydrate(options, state) {
|
|
207
|
+
const { logger: _logger, ...opts } = options;
|
|
208
|
+
if (state.version !== STATE_VERSION) {
|
|
209
|
+
throw new Error(
|
|
210
|
+
`hydrated state version is ${state.version}, but expected ${STATE_VERSION}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
this.#currentBlock = state.currentBlock;
|
|
214
|
+
this.#timestamp = state.timestamp;
|
|
215
|
+
this.#confugureRedstone(opts);
|
|
216
|
+
this.#addressProvider = hydrateAddressProvider(this, state.addressProvider);
|
|
217
|
+
this.logger?.debug(
|
|
218
|
+
`address provider version: ${this.#addressProvider.version}`
|
|
219
|
+
);
|
|
220
|
+
this.#marketRegister = new MarketRegister(this);
|
|
221
|
+
this.#marketRegister.hydrate(state.markets);
|
|
222
|
+
this.#attachConfig = {
|
|
223
|
+
...opts,
|
|
224
|
+
addressProvider: this.addressProvider.address,
|
|
225
|
+
marketConfigurators: this.marketRegister.marketConfigurators.map(
|
|
226
|
+
(m) => m.address
|
|
227
|
+
),
|
|
228
|
+
blockNumber: this.currentBlock
|
|
229
|
+
};
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
#confugureRedstone(opts) {
|
|
233
|
+
const { redstoneGateways, redstoneHistoricTimestamp } = opts;
|
|
234
|
+
if (redstoneHistoricTimestamp) {
|
|
235
|
+
this.priceFeeds.redstoneUpdater.historicalTimestamp = redstoneHistoricTimestamp === true ? Number(this.timestamp) * 1e3 : redstoneHistoricTimestamp;
|
|
236
|
+
}
|
|
237
|
+
if (redstoneGateways?.length) {
|
|
238
|
+
this.priceFeeds.redstoneUpdater.gateways = redstoneGateways;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
227
241
|
/**
|
|
228
242
|
* Reattach SDK with the same config as before, without re-creating instance. Will load all state from scratch
|
|
229
243
|
* Be mindful of block number, for example
|
|
230
244
|
*/
|
|
231
245
|
async reattach() {
|
|
232
246
|
if (!this.#attachConfig) {
|
|
233
|
-
throw new Error("
|
|
247
|
+
throw new Error("cannot reattach, attach config is not set");
|
|
234
248
|
}
|
|
235
249
|
await this.#attach(this.#attachConfig);
|
|
236
250
|
}
|
|
@@ -288,8 +302,8 @@ class GearboxSDK {
|
|
|
288
302
|
timestamp: Number(this.timestamp),
|
|
289
303
|
core: {
|
|
290
304
|
addressProviderV3: this.addressProvider.stateHuman(raw),
|
|
291
|
-
botList: this.botListContract
|
|
292
|
-
gearStakingV3: this.gearStakingContract
|
|
305
|
+
botList: this.botListContract?.stateHuman(raw),
|
|
306
|
+
gearStakingV3: this.gearStakingContract?.stateHuman(raw)
|
|
293
307
|
},
|
|
294
308
|
tokens: this.tokensMeta.values(),
|
|
295
309
|
plugins: Object.fromEntries(
|
|
@@ -303,16 +317,15 @@ class GearboxSDK {
|
|
|
303
317
|
}
|
|
304
318
|
get state() {
|
|
305
319
|
return {
|
|
320
|
+
version: STATE_VERSION,
|
|
321
|
+
network: this.provider.networkType,
|
|
322
|
+
chainId: this.provider.chainId,
|
|
306
323
|
currentBlock: this.currentBlock,
|
|
324
|
+
timestamp: this.timestamp,
|
|
307
325
|
addressProvider: this.addressProvider.state,
|
|
308
326
|
markets: this.marketRegister.state
|
|
309
327
|
};
|
|
310
328
|
}
|
|
311
|
-
async tvl() {
|
|
312
|
-
const { tvl, tvlUSD } = await this.marketRegister.tvl();
|
|
313
|
-
this.logger?.info(tvl);
|
|
314
|
-
this.logger?.info(`Total TVL: ${formatBN(tvlUSD, 8)}`);
|
|
315
|
-
}
|
|
316
329
|
/**
|
|
317
330
|
* Reloads markets states based on events from last processed block to new block (defaults to latest block)
|
|
318
331
|
* @param opts
|
|
@@ -419,16 +432,18 @@ class GearboxSDK {
|
|
|
419
432
|
return this.#addressProvider;
|
|
420
433
|
}
|
|
421
434
|
get botListContract() {
|
|
422
|
-
|
|
423
|
-
|
|
435
|
+
const addr = this.addressProvider.getAddress(AP_BOT_LIST, NO_VERSION);
|
|
436
|
+
if (!this.contracts.has(addr)) {
|
|
437
|
+
return new BotListContract(this, addr);
|
|
424
438
|
}
|
|
425
|
-
return this
|
|
439
|
+
return this.contracts.get(addr);
|
|
426
440
|
}
|
|
427
441
|
get gearStakingContract() {
|
|
428
|
-
|
|
429
|
-
|
|
442
|
+
const addr = this.addressProvider.getAddress(AP_GEAR_STAKING, NO_VERSION);
|
|
443
|
+
if (!this.contracts.has(addr)) {
|
|
444
|
+
return new GearStakingContract(this, addr);
|
|
430
445
|
}
|
|
431
|
-
return this
|
|
446
|
+
return this.contracts.get(addr);
|
|
432
447
|
}
|
|
433
448
|
get marketRegister() {
|
|
434
449
|
if (this.#marketRegister === void 0) {
|
|
@@ -463,12 +478,13 @@ class GearboxSDK {
|
|
|
463
478
|
);
|
|
464
479
|
}
|
|
465
480
|
const [routerAddr, routerV] = routerEntry;
|
|
466
|
-
if (!this
|
|
467
|
-
|
|
481
|
+
if (!this.contracts.has(routerAddr)) {
|
|
482
|
+
return createRouter(this, routerAddr, routerV);
|
|
468
483
|
}
|
|
469
|
-
return this
|
|
484
|
+
return this.contracts.get(routerAddr);
|
|
470
485
|
}
|
|
471
486
|
}
|
|
472
487
|
export {
|
|
473
|
-
GearboxSDK
|
|
488
|
+
GearboxSDK,
|
|
489
|
+
STATE_VERSION
|
|
474
490
|
};
|
|
@@ -4,15 +4,15 @@ import { ADDRESS_PROVIDER_BLOCK } from "../../constants/index.js";
|
|
|
4
4
|
import { getLogsSafe } from "../../utils/viem/index.js";
|
|
5
5
|
import AbstractAddressProviderContract from "./AbstractAddressProviderContract.js";
|
|
6
6
|
const abi = iAddressProviderV300Abi;
|
|
7
|
-
class
|
|
8
|
-
constructor(sdk, address, addresses = {}) {
|
|
7
|
+
class AddressProviderV300Contract extends AbstractAddressProviderContract {
|
|
8
|
+
constructor(sdk, address, version, addresses = {}) {
|
|
9
9
|
super(
|
|
10
10
|
sdk,
|
|
11
11
|
{
|
|
12
12
|
addr: address,
|
|
13
|
-
name: "
|
|
13
|
+
name: "AddressProviderV300",
|
|
14
14
|
abi,
|
|
15
|
-
version
|
|
15
|
+
version
|
|
16
16
|
},
|
|
17
17
|
addresses
|
|
18
18
|
);
|
|
@@ -74,5 +74,5 @@ class AddressProviderContractV3 extends AbstractAddressProviderContract {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
export {
|
|
77
|
-
|
|
77
|
+
AddressProviderV300Contract
|
|
78
78
|
};
|
|
@@ -2,15 +2,15 @@ import { bytesToString, parseEventLogs, toBytes } from "viem";
|
|
|
2
2
|
import { iAddressProviderV310Abi } from "../../../abi/v310.js";
|
|
3
3
|
import AbstractAddressProviderContract from "./AbstractAddressProviderContract.js";
|
|
4
4
|
const abi = iAddressProviderV310Abi;
|
|
5
|
-
class
|
|
6
|
-
constructor(sdk, address, addresses = {}) {
|
|
5
|
+
class AddressProviderV310Contract extends AbstractAddressProviderContract {
|
|
6
|
+
constructor(sdk, address, version, addresses = {}) {
|
|
7
7
|
super(
|
|
8
8
|
sdk,
|
|
9
9
|
{
|
|
10
10
|
addr: address,
|
|
11
|
-
name: "
|
|
11
|
+
name: "AddressProviderV310",
|
|
12
12
|
abi,
|
|
13
|
-
version
|
|
13
|
+
version
|
|
14
14
|
},
|
|
15
15
|
addresses
|
|
16
16
|
);
|
|
@@ -59,5 +59,5 @@ class AddressProviderContractV3_1 extends AbstractAddressProviderContract {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
export {
|
|
62
|
-
|
|
62
|
+
AddressProviderV310Contract
|
|
63
63
|
};
|
|
@@ -1,34 +1,29 @@
|
|
|
1
1
|
import { iVersionAbi } from "../../../abi/iVersion.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { isV300, isV310 } from "../../utils/index.js";
|
|
3
|
+
import { AddressProviderV300Contract } from "./AddressProviderV300Contract.js";
|
|
4
|
+
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
5
|
+
async function createAddressProvider(sdk, address) {
|
|
6
|
+
const v = await sdk.provider.publicClient.readContract({
|
|
7
|
+
address,
|
|
8
|
+
abi: iVersionAbi,
|
|
9
|
+
functionName: "version"
|
|
10
|
+
});
|
|
11
|
+
return newAddressProvider(sdk, address, Number(v));
|
|
12
|
+
}
|
|
13
|
+
function hydrateAddressProvider(sdk, state) {
|
|
14
|
+
const { addr, version } = state.baseParams;
|
|
15
|
+
return newAddressProvider(sdk, addr, Number(version), state.addresses);
|
|
16
|
+
}
|
|
17
|
+
function newAddressProvider(sdk, address, version, addresses) {
|
|
18
|
+
if (isV300(version)) {
|
|
19
|
+
return new AddressProviderV300Contract(sdk, address, version, addresses);
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return new AddressProviderContractV3(
|
|
18
|
-
sdk,
|
|
19
|
-
addr,
|
|
20
|
-
options?.state?.addresses
|
|
21
|
-
);
|
|
22
|
-
case 310:
|
|
23
|
-
return new AddressProviderContractV3_1(
|
|
24
|
-
sdk,
|
|
25
|
-
addr,
|
|
26
|
-
options?.state?.addresses
|
|
27
|
-
);
|
|
28
|
-
default:
|
|
29
|
-
throw new Error(`Unsupported address provider version: ${v}`);
|
|
21
|
+
if (isV310(version)) {
|
|
22
|
+
return new AddressProviderV310Contract(sdk, address, version, addresses);
|
|
30
23
|
}
|
|
24
|
+
throw new Error(`unsupported address provider version: ${version}`);
|
|
31
25
|
}
|
|
32
26
|
export {
|
|
33
|
-
createAddressProvider
|
|
27
|
+
createAddressProvider,
|
|
28
|
+
hydrateAddressProvider
|
|
34
29
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./AddressProviderV300Contract.js";
|
|
2
|
+
export * from "./AddressProviderV310Contract.js";
|
|
3
3
|
export * from "./createAddressProvider.js";
|
|
4
4
|
export * from "./types.js";
|
|
@@ -14,7 +14,13 @@ class GaugeStakingService extends SDKConstruct {
|
|
|
14
14
|
*/
|
|
15
15
|
async getGaugeStakingData(wallet) {
|
|
16
16
|
const marketFilter = this.sdk.marketRegister.marketFilter;
|
|
17
|
-
|
|
17
|
+
const gearStaking = this.sdk.gearStakingContract;
|
|
18
|
+
if (!marketFilter) {
|
|
19
|
+
throw new Error("market filter is not set");
|
|
20
|
+
}
|
|
21
|
+
if (!gearStaking) {
|
|
22
|
+
throw new Error("gear staking contract is not set");
|
|
23
|
+
}
|
|
18
24
|
const [gauges, availableBalance, totalBalance, withdrawableAmounts, epoch] = await this.provider.publicClient.multicall({
|
|
19
25
|
allowFailure: false,
|
|
20
26
|
contracts: [
|
|
@@ -25,26 +31,26 @@ class GaugeStakingService extends SDKConstruct {
|
|
|
25
31
|
args: [marketFilter, wallet]
|
|
26
32
|
},
|
|
27
33
|
{
|
|
28
|
-
address:
|
|
29
|
-
abi:
|
|
34
|
+
address: gearStaking.address,
|
|
35
|
+
abi: gearStaking.abi,
|
|
30
36
|
functionName: "availableBalance",
|
|
31
37
|
args: [wallet]
|
|
32
38
|
},
|
|
33
39
|
{
|
|
34
|
-
address:
|
|
35
|
-
abi:
|
|
40
|
+
address: gearStaking.address,
|
|
41
|
+
abi: gearStaking.abi,
|
|
36
42
|
functionName: "balanceOf",
|
|
37
43
|
args: [wallet]
|
|
38
44
|
},
|
|
39
45
|
{
|
|
40
|
-
address:
|
|
41
|
-
abi:
|
|
46
|
+
address: gearStaking.address,
|
|
47
|
+
abi: gearStaking.abi,
|
|
42
48
|
functionName: "getWithdrawableAmounts",
|
|
43
49
|
args: [wallet]
|
|
44
50
|
},
|
|
45
51
|
{
|
|
46
|
-
address:
|
|
47
|
-
abi:
|
|
52
|
+
address: gearStaking.address,
|
|
53
|
+
abi: gearStaking.abi,
|
|
48
54
|
functionName: "getCurrentEpoch",
|
|
49
55
|
args: []
|
|
50
56
|
}
|
|
@@ -11,10 +11,13 @@ class MarketRegister extends SDKConstruct {
|
|
|
11
11
|
*/
|
|
12
12
|
#markets = new AddressMap(void 0, "markets");
|
|
13
13
|
#marketFilter;
|
|
14
|
-
constructor(sdk
|
|
14
|
+
constructor(sdk) {
|
|
15
15
|
super(sdk);
|
|
16
16
|
this.#logger = childLogger("MarketRegister", sdk.logger);
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
hydrate(state) {
|
|
19
|
+
this.#markets.clear();
|
|
20
|
+
for (const data of state) {
|
|
18
21
|
this.#markets.upsert(
|
|
19
22
|
data.pool.baseParams.addr,
|
|
20
23
|
new MarketSuite(this.sdk, data)
|
|
@@ -207,18 +210,6 @@ class MarketRegister extends SDKConstruct {
|
|
|
207
210
|
get markets() {
|
|
208
211
|
return this.#markets.values();
|
|
209
212
|
}
|
|
210
|
-
async tvl() {
|
|
211
|
-
const creditManagers = this.creditManagers;
|
|
212
|
-
const tvls = await Promise.all(creditManagers.map((cm) => cm.tvl()));
|
|
213
|
-
return tvls.reduce(
|
|
214
|
-
(acc, curr) => {
|
|
215
|
-
acc.tvl += curr.tvl;
|
|
216
|
-
acc.tvlUSD += curr.tvlUSD;
|
|
217
|
-
return acc;
|
|
218
|
-
},
|
|
219
|
-
{ tvl: 0n, tvlUSD: 0n }
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
213
|
}
|
|
223
214
|
export {
|
|
224
215
|
MarketRegister
|
|
@@ -25,11 +25,6 @@ class CreditSuite extends SDKConstruct {
|
|
|
25
25
|
get router() {
|
|
26
26
|
return this.sdk.routerFor(this);
|
|
27
27
|
}
|
|
28
|
-
async tvl() {
|
|
29
|
-
const tvl = 0n;
|
|
30
|
-
const tvlUSD = 0n;
|
|
31
|
-
return { tvl, tvlUSD };
|
|
32
|
-
}
|
|
33
28
|
get dirty() {
|
|
34
29
|
return this.creditFacade.dirty || this.creditManager.dirty || this.creditConfigurator.dirty;
|
|
35
30
|
}
|
|
@@ -11,6 +11,10 @@ import { type PluginInstances, type PluginMap } from "./plugins/index.js";
|
|
|
11
11
|
import { type IRouterContract } from "./router/index.js";
|
|
12
12
|
import type { GearboxState, GearboxStateHuman, ILogger, MultiCall } from "./types/index.js";
|
|
13
13
|
import { AddressMap } from "./utils/index.js";
|
|
14
|
+
/**
|
|
15
|
+
* State version, checked duryng hydration
|
|
16
|
+
*/
|
|
17
|
+
export declare const STATE_VERSION = 1;
|
|
14
18
|
export interface SDKOptions<Plugins extends PluginMap = {}> {
|
|
15
19
|
/**
|
|
16
20
|
* If not set, address provider address is determinted automatically from networkType
|
|
@@ -51,6 +55,7 @@ export interface SDKOptions<Plugins extends PluginMap = {}> {
|
|
|
51
55
|
*/
|
|
52
56
|
logger?: ILogger;
|
|
53
57
|
}
|
|
58
|
+
export type HydrateOptions = Pick<SDKOptions, "ignoreUpdateablePrices" | "logger" | "redstoneGateways" | "redstoneHistoricTimestamp" | "strictContractTypes">;
|
|
54
59
|
export interface SyncStateOptions {
|
|
55
60
|
blockNumber: bigint;
|
|
56
61
|
timestamp: bigint;
|
|
@@ -87,6 +92,7 @@ export declare class GearboxSDK<Plugins extends PluginMap = {}> {
|
|
|
87
92
|
addHook: <K extends "syncState">(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
|
|
88
93
|
removeHook: <K extends "syncState">(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
|
|
89
94
|
static attach<Plugins extends PluginMap>(options: SDKOptions<Plugins> & Partial<NetworkOptions> & ConnectionOptions & TransportOptions): Promise<GearboxSDK<Plugins>>;
|
|
95
|
+
static hydrate(options: HydrateOptions & ConnectionOptions & TransportOptions, state: GearboxState): GearboxSDK;
|
|
90
96
|
private constructor();
|
|
91
97
|
/**
|
|
92
98
|
* Reattach SDK with the same config as before, without re-creating instance. Will load all state from scratch
|
|
@@ -135,7 +141,6 @@ export declare class GearboxSDK<Plugins extends PluginMap = {}> {
|
|
|
135
141
|
} | null)[];
|
|
136
142
|
stateHuman(raw?: boolean): GearboxStateHuman;
|
|
137
143
|
get state(): GearboxState;
|
|
138
|
-
tvl(): Promise<void>;
|
|
139
144
|
/**
|
|
140
145
|
* Reloads markets states based on events from last processed block to new block (defaults to latest block)
|
|
141
146
|
* @param opts
|
|
@@ -147,8 +152,8 @@ export declare class GearboxSDK<Plugins extends PluginMap = {}> {
|
|
|
147
152
|
get timestamp(): bigint;
|
|
148
153
|
get gear(): Address | undefined;
|
|
149
154
|
get addressProvider(): IAddressProviderContract;
|
|
150
|
-
get botListContract(): BotListContract;
|
|
151
|
-
get gearStakingContract(): GearStakingContract;
|
|
155
|
+
get botListContract(): BotListContract | undefined;
|
|
156
|
+
get gearStakingContract(): GearStakingContract | undefined;
|
|
152
157
|
get marketRegister(): MarketRegister;
|
|
153
158
|
/**
|
|
154
159
|
* Returns router contract that will work for given credit manager or credit facade
|
|
@@ -88,8 +88,8 @@ declare const abi: readonly [{
|
|
|
88
88
|
readonly anonymous: false;
|
|
89
89
|
}];
|
|
90
90
|
type abi = typeof abi;
|
|
91
|
-
export declare class
|
|
92
|
-
constructor(sdk: GearboxSDK, address: Address, addresses?: Record<string, Record<number, Address>>);
|
|
91
|
+
export declare class AddressProviderV300Contract extends AbstractAddressProviderContract<abi> implements IAddressProviderContract {
|
|
92
|
+
constructor(sdk: GearboxSDK, address: Address, version: number, addresses?: Record<string, Record<number, Address>>);
|
|
93
93
|
protected parseFunctionParams(params: DecodeFunctionDataReturnType<abi>): Array<string> | undefined;
|
|
94
94
|
processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
|
|
95
95
|
syncState(blockNumber?: bigint): Promise<void>;
|
|
@@ -253,8 +253,8 @@ declare const abi: readonly [{
|
|
|
253
253
|
readonly name: "ZeroAddressException";
|
|
254
254
|
}];
|
|
255
255
|
type abi = typeof abi;
|
|
256
|
-
export declare class
|
|
257
|
-
constructor(sdk: GearboxSDK, address: Address, addresses?: Record<string, Record<number, Address>>);
|
|
256
|
+
export declare class AddressProviderV310Contract extends AbstractAddressProviderContract<abi> implements IAddressProviderContract {
|
|
257
|
+
constructor(sdk: GearboxSDK, address: Address, version: number, addresses?: Record<string, Record<number, Address>>);
|
|
258
258
|
protected parseFunctionParams(params: DecodeFunctionDataReturnType<abi>): Array<string> | undefined;
|
|
259
259
|
processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
|
|
260
260
|
syncState(blockNumber?: bigint): Promise<void>;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
import type { GearboxSDK } from "../../GearboxSDK.js";
|
|
3
3
|
import type { AddressProviderState, IAddressProviderContract } from "./types.js";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
state?: AddressProviderState;
|
|
7
|
-
}
|
|
8
|
-
export declare function createAddressProvider(sdk: GearboxSDK, address: Address, options?: CreateAddressProviderOptions): Promise<IAddressProviderContract>;
|
|
4
|
+
export declare function createAddressProvider(sdk: GearboxSDK, address: Address): Promise<IAddressProviderContract>;
|
|
5
|
+
export declare function hydrateAddressProvider(sdk: GearboxSDK, state: AddressProviderState): IAddressProviderContract;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./AddressProviderV300Contract.js";
|
|
2
|
+
export * from "./AddressProviderV310Contract.js";
|
|
3
3
|
export * from "./createAddressProvider.js";
|
|
4
4
|
export * from "./types.js";
|
|
@@ -2,7 +2,7 @@ import type { Address } from "viem";
|
|
|
2
2
|
import type { MarketData } from "../base/index.js";
|
|
3
3
|
import { SDKConstruct } from "../base/index.js";
|
|
4
4
|
import type { GearboxSDK } from "../GearboxSDK.js";
|
|
5
|
-
import type { MarketStateHuman
|
|
5
|
+
import type { MarketStateHuman } from "../types/index.js";
|
|
6
6
|
import { AddressMap } from "../utils/index.js";
|
|
7
7
|
import type { CreditSuite } from "./credit/index.js";
|
|
8
8
|
import type { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
|
|
@@ -10,7 +10,8 @@ import { MarketSuite } from "./MarketSuite.js";
|
|
|
10
10
|
import type { PoolSuite } from "./pool/index.js";
|
|
11
11
|
export declare class MarketRegister extends SDKConstruct {
|
|
12
12
|
#private;
|
|
13
|
-
constructor(sdk: GearboxSDK
|
|
13
|
+
constructor(sdk: GearboxSDK);
|
|
14
|
+
hydrate(state: MarketData[]): void;
|
|
14
15
|
loadMarkets(marketConfigurators: Address[], ignoreUpdateablePrices?: boolean): Promise<void>;
|
|
15
16
|
get marketFilter(): {
|
|
16
17
|
configurators: readonly `0x${string}`[];
|
|
@@ -37,5 +38,4 @@ export declare class MarketRegister extends SDKConstruct {
|
|
|
37
38
|
findByPool(address: Address): MarketSuite;
|
|
38
39
|
get marketsMap(): AddressMap<MarketSuite>;
|
|
39
40
|
get markets(): MarketSuite[];
|
|
40
|
-
tvl(): Promise<TVL>;
|
|
41
41
|
}
|
|
@@ -3,7 +3,7 @@ import type { CreditSuiteState, MarketData } from "../../base/index.js";
|
|
|
3
3
|
import { SDKConstruct } from "../../base/index.js";
|
|
4
4
|
import type { GearboxSDK } from "../../GearboxSDK.js";
|
|
5
5
|
import type { IRouterContract } from "../../router/index.js";
|
|
6
|
-
import type { CreditSuiteStateHuman
|
|
6
|
+
import type { CreditSuiteStateHuman } from "../../types/index.js";
|
|
7
7
|
import type { CreditFacadeContract, ICreditConfiguratorContract, ICreditManagerContract } from "./types.js";
|
|
8
8
|
export declare class CreditSuite extends SDKConstruct {
|
|
9
9
|
readonly name: string;
|
|
@@ -15,7 +15,6 @@ export declare class CreditSuite extends SDKConstruct {
|
|
|
15
15
|
readonly state: CreditSuiteState;
|
|
16
16
|
constructor(sdk: GearboxSDK, marketData: MarketData, index: number);
|
|
17
17
|
get router(): IRouterContract;
|
|
18
|
-
tvl(): Promise<TVL>;
|
|
19
18
|
get dirty(): boolean;
|
|
20
19
|
get watchAddresses(): Set<Address>;
|
|
21
20
|
stateHuman(raw?: boolean): CreditSuiteStateHuman;
|
|
@@ -16,8 +16,8 @@ export interface GearStakingV3StateHuman extends BaseContractStateHuman {
|
|
|
16
16
|
export type BotListStateHuman = BaseContractStateHuman;
|
|
17
17
|
export interface CoreStateHuman {
|
|
18
18
|
addressProviderV3: AddressProviderV3StateHuman;
|
|
19
|
-
botList
|
|
20
|
-
gearStakingV3
|
|
19
|
+
botList?: BotListStateHuman;
|
|
20
|
+
gearStakingV3?: GearStakingV3StateHuman;
|
|
21
21
|
}
|
|
22
22
|
export type PriceFeedStateHuman = BoundedOracleStateHuman | AssetPriceFeedStateHuman | RedstonePriceFeedStateHuman | LPPriceFeedStateHuman | BalancerWeightedPriceFeedStateHuman;
|
|
23
23
|
export interface BasePriceFeedStateHuman extends BaseContractStateHuman {
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { MarketData } from "../base/index.js";
|
|
2
|
+
import type { NetworkType } from "../chain/chains.js";
|
|
2
3
|
import type { AddressProviderState } from "../core/index.js";
|
|
3
4
|
export interface GearboxState {
|
|
5
|
+
/**
|
|
6
|
+
* State version, checked duryng hydration
|
|
7
|
+
* This is not the same as @gearbox-protocol/sdk package version
|
|
8
|
+
*/
|
|
9
|
+
version: number;
|
|
10
|
+
network: NetworkType;
|
|
11
|
+
chainId: number;
|
|
4
12
|
currentBlock: bigint;
|
|
13
|
+
timestamp: bigint;
|
|
5
14
|
addressProvider: AddressProviderState;
|
|
6
15
|
markets: MarketData[];
|
|
7
16
|
}
|
package/package.json
CHANGED
|
File without changes
|