@gearbox-protocol/sdk 13.3.3 → 13.3.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.
- package/dist/cjs/sdk/GearboxSDK.js +135 -20
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +40 -141
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +5 -5
- package/dist/cjs/sdk/base/BaseContract.js +26 -6
- package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
- package/dist/cjs/sdk/base/Construct.js +15 -3
- package/dist/cjs/sdk/base/TokensMeta.js +23 -0
- package/dist/cjs/sdk/constants/address-provider.js +0 -22
- package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
- package/dist/cjs/sdk/market/MarketRegister.js +74 -3
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
- package/dist/cjs/sdk/options.js +30 -24
- package/dist/cjs/sdk/plugins/BasePlugin.js +24 -0
- package/dist/cjs/sdk/pools/AbstractPoolService.js +6 -0
- package/dist/cjs/sdk/router/AbstractRouterContract.js +4 -1
- package/dist/cjs/sdk/router/RouterV310Contract.js +20 -15
- package/dist/cjs/sdk/utils/AddressMap.js +53 -17
- package/dist/cjs/sdk/utils/AddressSet.js +9 -0
- package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
- package/dist/esm/sdk/GearboxSDK.js +135 -20
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +40 -141
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +5 -5
- package/dist/esm/sdk/base/BaseContract.js +26 -6
- package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
- package/dist/esm/sdk/base/Construct.js +15 -3
- package/dist/esm/sdk/base/TokensMeta.js +23 -0
- package/dist/esm/sdk/constants/address-provider.js +0 -21
- package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
- package/dist/esm/sdk/market/MarketRegister.js +74 -3
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
- package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
- package/dist/esm/sdk/options.js +30 -24
- package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
- package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
- package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
- package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
- package/dist/esm/sdk/utils/AddressMap.js +53 -17
- package/dist/esm/sdk/utils/AddressSet.js +9 -0
- package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
- package/dist/types/sdk/GearboxSDK.d.ts +236 -34
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +55 -141
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
- package/dist/types/sdk/accounts/types.d.ts +219 -17
- package/dist/types/sdk/base/BaseContract.d.ts +67 -6
- package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
- package/dist/types/sdk/base/Construct.d.ts +31 -0
- package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
- package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
- package/dist/types/sdk/base/types.d.ts +185 -25
- package/dist/types/sdk/chain/chains.d.ts +78 -18
- package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
- package/dist/types/sdk/constants/address-provider.d.ts +4 -3
- package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
- package/dist/types/sdk/core/types.d.ts +46 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
- package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
- package/dist/types/sdk/market/oracle/types.d.ts +76 -57
- package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +22 -2
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +77 -13
- package/dist/types/sdk/market/pricefeeds/types.d.ts +70 -10
- package/dist/types/sdk/options.d.ts +13 -4
- package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
- package/dist/types/sdk/plugins/types.d.ts +73 -43
- package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
- package/dist/types/sdk/pools/types.d.ts +75 -6
- package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
- package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
- package/dist/types/sdk/router/types.d.ts +51 -69
- package/dist/types/sdk/types/state.d.ts +32 -3
- package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
- package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
- package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
- package/package.json +4 -2
|
@@ -76,24 +76,50 @@ async function attachClient(options, network) {
|
|
|
76
76
|
}
|
|
77
77
|
class GearboxSDK extends import_base.ChainContractsRegister {
|
|
78
78
|
#hooks = new import_internal.Hooks();
|
|
79
|
+
/**
|
|
80
|
+
* Registered plugin instances, keyed by plugin name.
|
|
81
|
+
**/
|
|
79
82
|
plugins;
|
|
80
|
-
// Block which was use for data query
|
|
81
83
|
#currentBlock;
|
|
82
84
|
#timestamp;
|
|
83
85
|
#syncing = false;
|
|
84
|
-
// Collection of core singleton contracts
|
|
85
86
|
#addressProvider;
|
|
86
87
|
#attachConfig;
|
|
87
|
-
// Collection of markets
|
|
88
88
|
#marketRegister;
|
|
89
89
|
#priceFeeds;
|
|
90
|
+
/**
|
|
91
|
+
* Gas limit applied to read-only `eth_call` requests.
|
|
92
|
+
* `undefined` means that gas limit will not be set on read-only calls,
|
|
93
|
+
* leaving it to rpc provider to decide.
|
|
94
|
+
**/
|
|
90
95
|
gasLimit;
|
|
91
96
|
/**
|
|
92
|
-
*
|
|
93
|
-
|
|
97
|
+
* When `true`, the SDK throws on unrecognised contract types instead of
|
|
98
|
+
* falling back to a generic contract wrapper.
|
|
99
|
+
**/
|
|
94
100
|
strictContractTypes;
|
|
101
|
+
/**
|
|
102
|
+
* Registers a callback for an SDK lifecycle event.
|
|
103
|
+
*
|
|
104
|
+
* @see {@link SDKHooks} for available event names.
|
|
105
|
+
**/
|
|
95
106
|
addHook = this.#hooks.addHook.bind(this.#hooks);
|
|
107
|
+
/**
|
|
108
|
+
* Removes a previously registered lifecycle callback.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link SDKHooks} for available event names.
|
|
111
|
+
**/
|
|
96
112
|
removeHook = this.#hooks.removeHook.bind(this.#hooks);
|
|
113
|
+
/**
|
|
114
|
+
* Creates and initialises a new SDK instance by reading live on-chain state.
|
|
115
|
+
*
|
|
116
|
+
* This is the primary way to bootstrap the SDK. The method connects to the
|
|
117
|
+
* chain, discovers the address provider and all configured markets, and
|
|
118
|
+
* attaches any supplied plugins.
|
|
119
|
+
*
|
|
120
|
+
* @param options - Combined SDK, client, and (optional) network options.
|
|
121
|
+
* @returns A fully initialised SDK instance.
|
|
122
|
+
**/
|
|
97
123
|
static async attach(options) {
|
|
98
124
|
const {
|
|
99
125
|
logger,
|
|
@@ -129,6 +155,19 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
129
155
|
pyth
|
|
130
156
|
});
|
|
131
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Creates a new SDK instance from a previously serialised {@link GearboxState}
|
|
160
|
+
* snapshot, without making any on-chain calls.
|
|
161
|
+
*
|
|
162
|
+
* Use this for fast startup when a recent state snapshot is available
|
|
163
|
+
* (e.g. loaded from a file or received from a backend service).
|
|
164
|
+
*
|
|
165
|
+
* @param options - SDK and client options (block number and address provider
|
|
166
|
+
* are taken from the snapshot).
|
|
167
|
+
* @param state - Serialised state obtained from {@link GearboxSDK.state}.
|
|
168
|
+
* @returns A fully initialised SDK instance.
|
|
169
|
+
* @throws If the snapshot's {@link STATE_VERSION} does not match.
|
|
170
|
+
**/
|
|
132
171
|
static hydrate(options, state) {
|
|
133
172
|
const { logger, plugins, strictContractTypes, gasLimit, ...rest } = options;
|
|
134
173
|
const client = createClient(options, {
|
|
@@ -281,9 +320,15 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
281
320
|
return this;
|
|
282
321
|
}
|
|
283
322
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
|
|
323
|
+
* Re-attaches the SDK using the same configuration, discarding all cached
|
|
324
|
+
* state and re-reading everything from the chain.
|
|
325
|
+
*
|
|
326
|
+
* Useful when the SDK needs a full refresh (e.g. after a protocol upgrade).
|
|
327
|
+
* Note that if the original `blockNumber` was pinned, the same block is
|
|
328
|
+
* re-used — call {@link syncState} instead if you want to advance.
|
|
329
|
+
*
|
|
330
|
+
* @throws If the SDK has not been attached yet.
|
|
331
|
+
**/
|
|
287
332
|
async reattach() {
|
|
288
333
|
if (!this.#attachConfig) {
|
|
289
334
|
throw new Error("cannot reattach, attach config is not set");
|
|
@@ -291,8 +336,15 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
291
336
|
await this.#attach(this.#attachConfig);
|
|
292
337
|
}
|
|
293
338
|
/**
|
|
294
|
-
*
|
|
295
|
-
|
|
339
|
+
* Replaces the SDK's in-memory state with a new serialised snapshot
|
|
340
|
+
* without re-creating the instance.
|
|
341
|
+
*
|
|
342
|
+
* After hydration the `rehydrate` hook is triggered so that listeners
|
|
343
|
+
* can react to the state change.
|
|
344
|
+
*
|
|
345
|
+
* @param state - Serialised state obtained from {@link GearboxSDK.state}.
|
|
346
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
347
|
+
**/
|
|
296
348
|
async rehydrate(state) {
|
|
297
349
|
if (!this.#attachConfig) {
|
|
298
350
|
throw new Error("cannot rehydrate, attach config is not set");
|
|
@@ -308,9 +360,20 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
308
360
|
timestamp: state.timestamp
|
|
309
361
|
});
|
|
310
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`).
|
|
365
|
+
**/
|
|
311
366
|
get networkType() {
|
|
312
367
|
return this.client.chain.network;
|
|
313
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Returns a human-readable snapshot of the entire SDK state, suitable
|
|
371
|
+
* for logging or diagnostic inspection.
|
|
372
|
+
*
|
|
373
|
+
* @param raw - When `true`, include raw numeric values alongside
|
|
374
|
+
* formatted ones.
|
|
375
|
+
* @default true
|
|
376
|
+
**/
|
|
314
377
|
stateHuman(raw = true) {
|
|
315
378
|
return {
|
|
316
379
|
block: Number(this.currentBlock),
|
|
@@ -328,6 +391,13 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
328
391
|
...this.marketRegister.stateHuman(raw)
|
|
329
392
|
};
|
|
330
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Serialisable snapshot of the current SDK state.
|
|
396
|
+
*
|
|
397
|
+
* The returned object can be persisted (e.g. written to a file) and later
|
|
398
|
+
* passed to {@link GearboxSDK.hydrate} for instant restoration without
|
|
399
|
+
* on-chain reads.
|
|
400
|
+
**/
|
|
331
401
|
get state() {
|
|
332
402
|
return {
|
|
333
403
|
version: STATE_VERSION,
|
|
@@ -346,10 +416,20 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
346
416
|
};
|
|
347
417
|
}
|
|
348
418
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
|
|
419
|
+
* Incrementally updates the SDK state by replaying on-chain events from the
|
|
420
|
+
* last processed block up to the target block (defaults to `latest`).
|
|
421
|
+
*
|
|
422
|
+
* Use the to periodically update sdk state on cron, or subscribe to new blocks
|
|
423
|
+
* using viem's `watchBlocks`
|
|
424
|
+
*
|
|
425
|
+
* On failure the SDK reverts to the previous block/timestamp so that
|
|
426
|
+
* subsequent calls can retry.
|
|
427
|
+
*
|
|
428
|
+
* @param opts - Target block and sync behaviour. When omitted the latest
|
|
429
|
+
* block is fetched automatically.
|
|
430
|
+
* @returns `true` if the sync completed successfully, `false` if it was
|
|
431
|
+
* skipped or failed.
|
|
432
|
+
**/
|
|
353
433
|
async syncState(opts) {
|
|
354
434
|
let {
|
|
355
435
|
blockNumber,
|
|
@@ -451,12 +531,22 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
451
531
|
}
|
|
452
532
|
return success;
|
|
453
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* Block number that the SDK state corresponds to.
|
|
536
|
+
*
|
|
537
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
538
|
+
**/
|
|
454
539
|
get currentBlock() {
|
|
455
540
|
if (this.#currentBlock === void 0) {
|
|
456
541
|
throw ERR_NOT_ATTACHED;
|
|
457
542
|
}
|
|
458
543
|
return this.#currentBlock;
|
|
459
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* Block timestamp (Unix epoch seconds) corresponding to {@link currentBlock}.
|
|
547
|
+
*
|
|
548
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
549
|
+
**/
|
|
460
550
|
get timestamp() {
|
|
461
551
|
if (this.#timestamp === void 0) {
|
|
462
552
|
throw ERR_NOT_ATTACHED;
|
|
@@ -464,14 +554,23 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
464
554
|
return this.#timestamp;
|
|
465
555
|
}
|
|
466
556
|
/**
|
|
467
|
-
*
|
|
468
|
-
|
|
557
|
+
* Global registry of all price feeds known to the SDK (on all markets).
|
|
558
|
+
*
|
|
559
|
+
* Unlike per-oracle price feed references, this register does not carry
|
|
560
|
+
* oracle-specific metadata (staleness period, main/reserve designation, etc.).
|
|
561
|
+
*
|
|
562
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
563
|
+
**/
|
|
469
564
|
get priceFeeds() {
|
|
470
565
|
if (this.#priceFeeds === void 0) {
|
|
471
566
|
throw ERR_NOT_ATTACHED;
|
|
472
567
|
}
|
|
473
568
|
return this.#priceFeeds;
|
|
474
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Address of the GEAR governance token on this chain, or `undefined`
|
|
572
|
+
* if the address provider does not list it.
|
|
573
|
+
**/
|
|
475
574
|
get gear() {
|
|
476
575
|
try {
|
|
477
576
|
const g = this.addressProvider.getAddress(import_constants.AP_GEAR_TOKEN, import_constants.NO_VERSION);
|
|
@@ -481,12 +580,23 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
481
580
|
return void 0;
|
|
482
581
|
}
|
|
483
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* The chain's address provider contract, the central directory for all
|
|
585
|
+
* protocol-wide Gearbox protocol addresses.
|
|
586
|
+
*
|
|
587
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
588
|
+
**/
|
|
484
589
|
get addressProvider() {
|
|
485
590
|
if (this.#addressProvider === void 0) {
|
|
486
591
|
throw ERR_NOT_ATTACHED;
|
|
487
592
|
}
|
|
488
593
|
return this.#addressProvider;
|
|
489
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* Registry of all loaded markets (pools, credit managers, oracles, etc.).
|
|
597
|
+
*
|
|
598
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
599
|
+
**/
|
|
490
600
|
get marketRegister() {
|
|
491
601
|
if (this.#marketRegister === void 0) {
|
|
492
602
|
throw ERR_NOT_ATTACHED;
|
|
@@ -494,10 +604,15 @@ class GearboxSDK extends import_base.ChainContractsRegister {
|
|
|
494
604
|
return this.#marketRegister;
|
|
495
605
|
}
|
|
496
606
|
/**
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
|
|
607
|
+
* Resolves the appropriate router contract for a given credit manager,
|
|
608
|
+
* credit facade, or explicit version range.
|
|
609
|
+
*
|
|
610
|
+
* @param params - Identifies the context: a credit manager address/state,
|
|
611
|
+
* a credit facade address/state, or a {@link VersionRange}.
|
|
612
|
+
* @returns The matching router contract instance.
|
|
613
|
+
* @throws If the credit facade version is unsupported or no router is
|
|
614
|
+
* registered for the resolved version range.
|
|
615
|
+
**/
|
|
501
616
|
routerFor(params) {
|
|
502
617
|
let routerRange;
|
|
503
618
|
if (Array.isArray(params)) {
|
|
@@ -57,12 +57,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
* @param account
|
|
63
|
-
* @param blockNumber
|
|
64
|
-
* @returns
|
|
65
|
-
*/
|
|
60
|
+
* {@inheritDoc ICreditAccountsService.getCreditAccountData}
|
|
61
|
+
**/
|
|
66
62
|
async getCreditAccountData(account, blockNumber) {
|
|
67
63
|
let raw;
|
|
68
64
|
try {
|
|
@@ -101,13 +97,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
101
97
|
return cad;
|
|
102
98
|
}
|
|
103
99
|
/**
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
* @param options
|
|
108
|
-
* @param blockNumber
|
|
109
|
-
* @returns returned credit accounts are sorted by health factor in ascending order
|
|
110
|
-
*/
|
|
100
|
+
* {@inheritDoc ICreditAccountsService.getCreditAccounts}
|
|
101
|
+
**/
|
|
111
102
|
async getCreditAccounts(options, blockNumber) {
|
|
112
103
|
const {
|
|
113
104
|
creditManager,
|
|
@@ -160,11 +151,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
160
151
|
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
161
152
|
}
|
|
162
153
|
/**
|
|
163
|
-
*
|
|
164
|
-
|
|
165
|
-
* @param {Address} creditAccount - address of credit account to get rewards for
|
|
166
|
-
* @returns {Array<Rewards>} list of {@link Rewards} that can be claimed
|
|
167
|
-
*/
|
|
154
|
+
* {@inheritDoc ICreditAccountsService.getRewards}
|
|
155
|
+
**/
|
|
168
156
|
async getRewards(creditAccount) {
|
|
169
157
|
const rewards = await this.client.readContract({
|
|
170
158
|
abi: import_rewardsCompressor.rewardsCompressorAbi,
|
|
@@ -204,11 +192,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
204
192
|
return Object.values(r);
|
|
205
193
|
}
|
|
206
194
|
/**
|
|
207
|
-
*
|
|
208
|
-
|
|
209
|
-
and their credit managers to check connected bots on
|
|
210
|
-
* @returns call result of getConnectedBots for each credit account
|
|
211
|
-
*/
|
|
195
|
+
* {@inheritDoc ICreditAccountsService.getConnectedBots}
|
|
196
|
+
**/
|
|
212
197
|
async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
|
|
213
198
|
const allResp = await this.client.multicall({
|
|
214
199
|
contracts: [
|
|
@@ -312,10 +297,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
312
297
|
return void 0;
|
|
313
298
|
}
|
|
314
299
|
/**
|
|
315
|
-
*
|
|
316
|
-
|
|
317
|
-
* @returns
|
|
318
|
-
*/
|
|
300
|
+
* {@inheritDoc ICreditAccountsService.fullyLiquidate}
|
|
301
|
+
**/
|
|
319
302
|
async fullyLiquidate(props) {
|
|
320
303
|
const {
|
|
321
304
|
account,
|
|
@@ -365,21 +348,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
365
348
|
};
|
|
366
349
|
}
|
|
367
350
|
/**
|
|
368
|
-
*
|
|
369
|
-
|
|
370
|
-
-> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens tokens -> withdraw underlying tokenz
|
|
371
|
-
* @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
|
|
372
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
373
|
-
* @param {Array<Address>} assetsToWithdraw - tokens to withdraw from credit account.
|
|
374
|
-
For credit account closing this is the underlying token, because during the closure,
|
|
375
|
-
all tokens on account are swapped into the underlying,
|
|
376
|
-
and only the underlying token will remain on the credit account
|
|
377
|
-
* @param {Address} to - Wallet address to withdraw underlying to
|
|
378
|
-
* @param {number} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
379
|
-
* @default 50n
|
|
380
|
-
* @param {RouterCloseResult | undefined} closePath - result of findBestClosePath method from router; if omited, calls marketRegister.findCreditManager {@link RouterCloseResult}
|
|
381
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
382
|
-
*/
|
|
351
|
+
* {@inheritDoc ICreditAccountsService.closeCreditAccount}
|
|
352
|
+
**/
|
|
383
353
|
async closeCreditAccount({
|
|
384
354
|
operation,
|
|
385
355
|
assetsToWithdraw,
|
|
@@ -411,13 +381,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
411
381
|
return { tx, calls, routerCloseResult, creditFacade: cm.creditFacade };
|
|
412
382
|
}
|
|
413
383
|
/**
|
|
414
|
-
*
|
|
415
|
-
|
|
416
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
417
|
-
* @param {Array<Asset>} averageQuota - average quota for desired tokens {@link Asset}
|
|
418
|
-
* @param {Array<Asset>} minQuota - minimum quota for desired tokens {@link Asset}
|
|
419
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
420
|
-
*/
|
|
384
|
+
* {@inheritDoc ICreditAccountsService.updateQuotas}
|
|
385
|
+
**/
|
|
421
386
|
async updateQuotas({
|
|
422
387
|
minQuota,
|
|
423
388
|
averageQuota,
|
|
@@ -441,16 +406,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
441
406
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
442
407
|
}
|
|
443
408
|
/**
|
|
444
|
-
*
|
|
445
|
-
|
|
446
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
447
|
-
* @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
|
|
448
|
-
* @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
|
|
449
|
-
* @param {Asset} asset - asset to add as collateral {@link Asset}
|
|
450
|
-
* @param {PermitResult | undefined} permits - permits of collateral asset if it is permittable {@link PermitResult}
|
|
451
|
-
* @param {bigint} ethAmount - native token amount to attach to tx
|
|
452
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
453
|
-
*/
|
|
409
|
+
* {@inheritDoc ICreditAccountsService.addCollateral}
|
|
410
|
+
**/
|
|
454
411
|
async addCollateral({
|
|
455
412
|
creditAccount,
|
|
456
413
|
asset,
|
|
@@ -484,15 +441,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
484
441
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
485
442
|
}
|
|
486
443
|
/**
|
|
487
|
-
*
|
|
488
|
-
|
|
489
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
490
|
-
* @param {bigint} amount - amount to change debt by;
|
|
491
|
-
0 - prohibited value;
|
|
492
|
-
negative value for debt decrease;
|
|
493
|
-
positive value for debt increase.
|
|
494
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
495
|
-
*/
|
|
444
|
+
* {@inheritDoc ICreditAccountsService.changeDebt}
|
|
445
|
+
**/
|
|
496
446
|
async changeDebt({
|
|
497
447
|
creditAccount,
|
|
498
448
|
amount,
|
|
@@ -529,14 +479,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
529
479
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
530
480
|
}
|
|
531
481
|
/**
|
|
532
|
-
*
|
|
533
|
-
|
|
534
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
535
|
-
* @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
|
|
536
|
-
* @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
|
|
537
|
-
* @param {Array<MultiCall>} calls - array of MultiCall from router methods getSingleSwap or getAllSwaps {@link MultiCall}
|
|
538
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
539
|
-
*/
|
|
482
|
+
* {@inheritDoc ICreditAccountsService.executeSwap}
|
|
483
|
+
**/
|
|
540
484
|
async executeSwap({
|
|
541
485
|
creditAccount,
|
|
542
486
|
calls: swapCalls,
|
|
@@ -564,10 +508,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
564
508
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
565
509
|
}
|
|
566
510
|
/**
|
|
567
|
-
*
|
|
568
|
-
|
|
569
|
-
* @returns
|
|
570
|
-
*/
|
|
511
|
+
* {@inheritDoc ICreditAccountsService.previewDelayedWithdrawal}
|
|
512
|
+
**/
|
|
571
513
|
async previewDelayedWithdrawal({
|
|
572
514
|
creditAccount,
|
|
573
515
|
amount,
|
|
@@ -591,10 +533,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
591
533
|
return resp;
|
|
592
534
|
}
|
|
593
535
|
/**
|
|
594
|
-
*
|
|
595
|
-
|
|
596
|
-
* @returns
|
|
597
|
-
*/
|
|
536
|
+
* {@inheritDoc ICreditAccountsService.getPendingWithdrawals}
|
|
537
|
+
**/
|
|
598
538
|
async getPendingWithdrawals({
|
|
599
539
|
creditAccount
|
|
600
540
|
}) {
|
|
@@ -620,11 +560,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
620
560
|
return respResult;
|
|
621
561
|
}
|
|
622
562
|
/**
|
|
623
|
-
*
|
|
624
|
-
|
|
625
|
-
* @param props - {@link StartDelayedWithdrawalProps}
|
|
626
|
-
* @returns
|
|
627
|
-
*/
|
|
563
|
+
* {@inheritDoc ICreditAccountsService.startDelayedWithdrawal}
|
|
564
|
+
**/
|
|
628
565
|
async startDelayedWithdrawal({
|
|
629
566
|
creditAccount,
|
|
630
567
|
minQuota,
|
|
@@ -680,11 +617,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
680
617
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
681
618
|
}
|
|
682
619
|
/**
|
|
683
|
-
*
|
|
684
|
-
|
|
685
|
-
* @param props - {@link ClaimDelayedProps}
|
|
686
|
-
* @returns
|
|
687
|
-
*/
|
|
620
|
+
* {@inheritDoc ICreditAccountsService.claimDelayed}
|
|
621
|
+
**/
|
|
688
622
|
async claimDelayed({
|
|
689
623
|
creditAccount,
|
|
690
624
|
minQuota,
|
|
@@ -745,29 +679,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
745
679
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
746
680
|
}
|
|
747
681
|
/**
|
|
748
|
-
*
|
|
749
|
-
|
|
750
|
-
-> update quotas -> (optionally: execute swap path for trading/strategy) ->
|
|
751
|
-
-> (optionally: withdraw debt for lending)
|
|
752
|
-
- Basic open credit account: price update -> increase debt -> add collateral -> update quotas
|
|
753
|
-
- Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
|
|
754
|
-
- Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
|
|
755
|
-
- In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
|
|
756
|
-
* @param {bigint} ethAmount - native token amount to attach to tx
|
|
757
|
-
* @param {Address} creditManager - address of credit manager to open credit account on
|
|
758
|
-
* @param {Array<Asset>} collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
|
|
759
|
-
* @param {Record<Address, PermitResult>} permits - permits of collateral tokens (in any permittable token is present) {@link PermitResult}
|
|
760
|
-
* @param {bigint} debt - debt to open credit account with
|
|
761
|
-
* @param {boolean} withdrawDebt - flag to withdraw debt to wallet after opening credit account;
|
|
762
|
-
used for borrowing functionality
|
|
763
|
-
* @param {bigint} referralCode - referral code to open credit account with
|
|
764
|
-
* @param {Address} to - wallet address to transfer credit account to\
|
|
765
|
-
* @param {Array<MultiCall>} calls - array of MultiCall from router methods findOpenStrategyPath {@link MultiCall}.
|
|
766
|
-
Used for trading and strategy functionality
|
|
767
|
-
* @param {Array<Asset>} averageQuota - average quota for tokens after open {@link Asset}
|
|
768
|
-
* @param {Array<Asset>} minQuota - minimum quota for tokens after open {@link Asset}
|
|
769
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
770
|
-
*/
|
|
682
|
+
* {@inheritDoc ICreditAccountsService.openCA}
|
|
683
|
+
**/
|
|
771
684
|
async openCA({
|
|
772
685
|
ethAmount,
|
|
773
686
|
creditManager,
|
|
@@ -803,10 +716,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
803
716
|
return { calls, tx, creditFacade: cmSuite.creditFacade };
|
|
804
717
|
}
|
|
805
718
|
/**
|
|
806
|
-
*
|
|
807
|
-
|
|
808
|
-
* @returns
|
|
809
|
-
*/
|
|
719
|
+
* {@inheritDoc ICreditAccountsService.getBorrowRate}
|
|
720
|
+
**/
|
|
810
721
|
getBorrowRate(ca) {
|
|
811
722
|
const { creditManager } = this.sdk.marketRegister.findCreditManager(
|
|
812
723
|
ca.creditManager
|
|
@@ -832,9 +743,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
832
743
|
return r + qr;
|
|
833
744
|
}
|
|
834
745
|
/**
|
|
835
|
-
*
|
|
836
|
-
|
|
837
|
-
*/
|
|
746
|
+
* {@inheritDoc ICreditAccountsService.getOptimalHFForPartialLiquidation}
|
|
747
|
+
**/
|
|
838
748
|
getOptimalHFForPartialLiquidation(ca) {
|
|
839
749
|
const borrowRate = this.getBorrowRate(ca);
|
|
840
750
|
return import_constants.PERCENTAGE_FACTOR + (borrowRate < 100n ? borrowRate : 100n);
|
|
@@ -883,12 +793,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
883
793
|
return resp;
|
|
884
794
|
}
|
|
885
795
|
/**
|
|
886
|
-
*
|
|
887
|
-
|
|
888
|
-
* This can be used by batch liquidator
|
|
889
|
-
* @param accounts
|
|
890
|
-
* @returns
|
|
891
|
-
*/
|
|
796
|
+
* {@inheritDoc ICreditAccountsService.getUpdateForAccounts}
|
|
797
|
+
**/
|
|
892
798
|
async getUpdateForAccounts(accounts) {
|
|
893
799
|
const tokensByPool = /* @__PURE__ */ new Map();
|
|
894
800
|
const oracleByPool = /* @__PURE__ */ new Map();
|
|
@@ -960,10 +866,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
960
866
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
961
867
|
}
|
|
962
868
|
/**
|
|
963
|
-
*
|
|
964
|
-
|
|
965
|
-
* @returns
|
|
966
|
-
*/
|
|
869
|
+
* {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
|
|
870
|
+
**/
|
|
967
871
|
async getOnDemandPriceUpdates(options) {
|
|
968
872
|
const { creditManager, creditAccount } = options;
|
|
969
873
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
@@ -979,13 +883,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
979
883
|
);
|
|
980
884
|
}
|
|
981
885
|
/**
|
|
982
|
-
*
|
|
983
|
-
|
|
984
|
-
* - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
|
|
985
|
-
* - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
|
|
986
|
-
* @param acc
|
|
987
|
-
* @returns
|
|
988
|
-
*/
|
|
886
|
+
* {@inheritDoc ICreditAccountsService.getPriceUpdatesForFacade}
|
|
887
|
+
**/
|
|
989
888
|
async getPriceUpdatesForFacade(options) {
|
|
990
889
|
const updates = await this.getOnDemandPriceUpdates(options);
|
|
991
890
|
return updates.multicall;
|
|
@@ -27,7 +27,7 @@ var import_math = require("../constants/math.js");
|
|
|
27
27
|
var import_AbstractCreditAccountsService = require("./AbstractCreditAccountsService.js");
|
|
28
28
|
class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.AbstractCreditAccountService {
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* {@inheritDoc ICreditAccountsService.setBot}
|
|
31
31
|
*/
|
|
32
32
|
async setBot({
|
|
33
33
|
botAddress,
|
|
@@ -69,7 +69,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
69
69
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
72
|
+
* {@inheritDoc ICreditAccountsService.withdrawCollateral}
|
|
73
73
|
*/
|
|
74
74
|
async withdrawCollateral({
|
|
75
75
|
creditAccount,
|
|
@@ -104,7 +104,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
104
104
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* {@inheritDoc ICreditAccountsService.repayCreditAccount}
|
|
108
108
|
*/
|
|
109
109
|
async repayCreditAccount({
|
|
110
110
|
operation,
|
|
@@ -140,7 +140,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
140
140
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
-
*
|
|
143
|
+
* {@inheritDoc ICreditAccountsService.repayAndLiquidateCreditAccount}
|
|
144
144
|
*/
|
|
145
145
|
async repayAndLiquidateCreditAccount({
|
|
146
146
|
collateralAssets,
|
|
@@ -177,7 +177,7 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
177
177
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
178
178
|
}
|
|
179
179
|
/**
|
|
180
|
-
*
|
|
180
|
+
* {@inheritDoc ICreditAccountsService.claimFarmRewards}
|
|
181
181
|
*/
|
|
182
182
|
async claimFarmRewards({
|
|
183
183
|
calls: externalCalls,
|
|
@@ -45,11 +45,30 @@ class ContractParseError extends import_viem.BaseError {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
class BaseContract extends import_Construct.Construct {
|
|
48
|
+
/**
|
|
49
|
+
* Viem contract instance for direct read calls
|
|
50
|
+
**/
|
|
48
51
|
contract;
|
|
52
|
+
/**
|
|
53
|
+
* Contract ABI
|
|
54
|
+
**/
|
|
49
55
|
abi;
|
|
56
|
+
/**
|
|
57
|
+
* Gearbox contract type identifier (e.g. `"CREDIT_MANAGER"`), or empty string if unknown.
|
|
58
|
+
**/
|
|
50
59
|
contractType;
|
|
60
|
+
/**
|
|
61
|
+
* Contract version number.
|
|
62
|
+
* @default 0
|
|
63
|
+
**/
|
|
51
64
|
version;
|
|
65
|
+
/**
|
|
66
|
+
* On-chain address of the contract.
|
|
67
|
+
**/
|
|
52
68
|
address;
|
|
69
|
+
/**
|
|
70
|
+
* Display name for the contract.
|
|
71
|
+
**/
|
|
53
72
|
name;
|
|
54
73
|
constructor(options, args) {
|
|
55
74
|
super(options);
|
|
@@ -73,6 +92,7 @@ class BaseContract extends import_Construct.Construct {
|
|
|
73
92
|
register.setAddressLabel(this.address, this.name);
|
|
74
93
|
}
|
|
75
94
|
}
|
|
95
|
+
/** {@inheritDoc IBaseContract.stateHuman} */
|
|
76
96
|
stateHuman(_ = true) {
|
|
77
97
|
return {
|
|
78
98
|
address: this.labelAddress(this.address),
|
|
@@ -81,9 +101,10 @@ class BaseContract extends import_Construct.Construct {
|
|
|
81
101
|
};
|
|
82
102
|
}
|
|
83
103
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
|
|
104
|
+
* Applies an on-chain event to update this contract's local state.
|
|
105
|
+
*
|
|
106
|
+
* @param _log - Decoded event log emitted by this contract.
|
|
107
|
+
**/
|
|
87
108
|
processLog(_log) {
|
|
88
109
|
}
|
|
89
110
|
/**
|
|
@@ -158,9 +179,8 @@ class BaseContract extends import_Construct.Construct {
|
|
|
158
179
|
}
|
|
159
180
|
}
|
|
160
181
|
/**
|
|
161
|
-
* Same as {@link
|
|
162
|
-
* @param calldata
|
|
163
|
-
* @returns
|
|
182
|
+
* Same as {@link stringifyFunctionData}, but throws if error occurs.
|
|
183
|
+
* @param calldata - Raw ABI-encoded calldata.
|
|
164
184
|
*/
|
|
165
185
|
mustStringifyFunctionData(calldata) {
|
|
166
186
|
const decoded = (0, import_viem.decodeFunctionData)({
|