@gearbox-protocol/sdk 13.3.2 → 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.
Files changed (92) hide show
  1. package/dist/cjs/rewards/rewards/api.js +4 -124
  2. package/dist/cjs/rewards/rewards/extra-apy.js +5 -7
  3. package/dist/cjs/rewards/rewards/index.js +1 -5
  4. package/dist/cjs/sdk/GearboxSDK.js +135 -20
  5. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +40 -141
  6. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +5 -5
  7. package/dist/cjs/sdk/base/BaseContract.js +26 -6
  8. package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
  9. package/dist/cjs/sdk/base/Construct.js +15 -3
  10. package/dist/cjs/sdk/base/TokensMeta.js +23 -0
  11. package/dist/cjs/sdk/constants/address-provider.js +0 -22
  12. package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
  13. package/dist/cjs/sdk/market/MarketRegister.js +74 -3
  14. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  15. package/dist/cjs/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  16. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  17. package/dist/cjs/sdk/options.js +30 -24
  18. package/dist/cjs/sdk/plugins/BasePlugin.js +24 -0
  19. package/dist/cjs/sdk/pools/AbstractPoolService.js +6 -0
  20. package/dist/cjs/sdk/router/AbstractRouterContract.js +4 -1
  21. package/dist/cjs/sdk/router/RouterV310Contract.js +20 -15
  22. package/dist/cjs/sdk/utils/AddressMap.js +53 -17
  23. package/dist/cjs/sdk/utils/AddressSet.js +9 -0
  24. package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
  25. package/dist/esm/rewards/rewards/api.js +4 -124
  26. package/dist/esm/rewards/rewards/extra-apy.js +4 -6
  27. package/dist/esm/rewards/rewards/index.js +0 -2
  28. package/dist/esm/sdk/GearboxSDK.js +135 -20
  29. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +40 -141
  30. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +5 -5
  31. package/dist/esm/sdk/base/BaseContract.js +26 -6
  32. package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
  33. package/dist/esm/sdk/base/Construct.js +15 -3
  34. package/dist/esm/sdk/base/TokensMeta.js +23 -0
  35. package/dist/esm/sdk/constants/address-provider.js +0 -21
  36. package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
  37. package/dist/esm/sdk/market/MarketRegister.js +74 -3
  38. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  39. package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  40. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  41. package/dist/esm/sdk/options.js +30 -24
  42. package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
  43. package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
  44. package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
  45. package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
  46. package/dist/esm/sdk/utils/AddressMap.js +53 -17
  47. package/dist/esm/sdk/utils/AddressSet.js +9 -0
  48. package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
  49. package/dist/types/rewards/rewards/api.d.ts +5 -28
  50. package/dist/types/rewards/rewards/extra-apy.d.ts +1 -1
  51. package/dist/types/rewards/rewards/index.d.ts +0 -2
  52. package/dist/types/sdk/GearboxSDK.d.ts +236 -34
  53. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +55 -141
  54. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
  55. package/dist/types/sdk/accounts/types.d.ts +219 -17
  56. package/dist/types/sdk/base/BaseContract.d.ts +67 -6
  57. package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
  58. package/dist/types/sdk/base/Construct.d.ts +31 -0
  59. package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
  60. package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
  61. package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
  62. package/dist/types/sdk/base/types.d.ts +185 -25
  63. package/dist/types/sdk/chain/chains.d.ts +78 -18
  64. package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
  65. package/dist/types/sdk/constants/address-provider.d.ts +4 -3
  66. package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
  67. package/dist/types/sdk/core/types.d.ts +46 -0
  68. package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
  69. package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
  70. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
  71. package/dist/types/sdk/market/oracle/types.d.ts +76 -57
  72. package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -0
  73. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +3 -0
  74. package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +22 -2
  75. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +77 -13
  76. package/dist/types/sdk/market/pricefeeds/types.d.ts +70 -10
  77. package/dist/types/sdk/options.d.ts +13 -4
  78. package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
  79. package/dist/types/sdk/plugins/types.d.ts +73 -43
  80. package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
  81. package/dist/types/sdk/pools/types.d.ts +75 -6
  82. package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
  83. package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
  84. package/dist/types/sdk/router/types.d.ts +51 -69
  85. package/dist/types/sdk/types/state.d.ts +32 -3
  86. package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
  87. package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
  88. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
  89. package/package.json +4 -2
  90. package/dist/cjs/rewards/rewards/apy.js +0 -177
  91. package/dist/esm/rewards/rewards/apy.js +0 -160
  92. package/dist/types/rewards/rewards/apy.d.ts +0 -44
@@ -67,24 +67,50 @@ async function attachClient(options, network) {
67
67
  }
68
68
  class GearboxSDK extends ChainContractsRegister {
69
69
  #hooks = new Hooks();
70
+ /**
71
+ * Registered plugin instances, keyed by plugin name.
72
+ **/
70
73
  plugins;
71
- // Block which was use for data query
72
74
  #currentBlock;
73
75
  #timestamp;
74
76
  #syncing = false;
75
- // Collection of core singleton contracts
76
77
  #addressProvider;
77
78
  #attachConfig;
78
- // Collection of markets
79
79
  #marketRegister;
80
80
  #priceFeeds;
81
+ /**
82
+ * Gas limit applied to read-only `eth_call` requests.
83
+ * `undefined` means that gas limit will not be set on read-only calls,
84
+ * leaving it to rpc provider to decide.
85
+ **/
81
86
  gasLimit;
82
87
  /**
83
- * Will throw an error if contract type is not supported, otherwise will try to use generic contract first, if possible
84
- */
88
+ * When `true`, the SDK throws on unrecognised contract types instead of
89
+ * falling back to a generic contract wrapper.
90
+ **/
85
91
  strictContractTypes;
92
+ /**
93
+ * Registers a callback for an SDK lifecycle event.
94
+ *
95
+ * @see {@link SDKHooks} for available event names.
96
+ **/
86
97
  addHook = this.#hooks.addHook.bind(this.#hooks);
98
+ /**
99
+ * Removes a previously registered lifecycle callback.
100
+ *
101
+ * @see {@link SDKHooks} for available event names.
102
+ **/
87
103
  removeHook = this.#hooks.removeHook.bind(this.#hooks);
104
+ /**
105
+ * Creates and initialises a new SDK instance by reading live on-chain state.
106
+ *
107
+ * This is the primary way to bootstrap the SDK. The method connects to the
108
+ * chain, discovers the address provider and all configured markets, and
109
+ * attaches any supplied plugins.
110
+ *
111
+ * @param options - Combined SDK, client, and (optional) network options.
112
+ * @returns A fully initialised SDK instance.
113
+ **/
88
114
  static async attach(options) {
89
115
  const {
90
116
  logger,
@@ -120,6 +146,19 @@ class GearboxSDK extends ChainContractsRegister {
120
146
  pyth
121
147
  });
122
148
  }
149
+ /**
150
+ * Creates a new SDK instance from a previously serialised {@link GearboxState}
151
+ * snapshot, without making any on-chain calls.
152
+ *
153
+ * Use this for fast startup when a recent state snapshot is available
154
+ * (e.g. loaded from a file or received from a backend service).
155
+ *
156
+ * @param options - SDK and client options (block number and address provider
157
+ * are taken from the snapshot).
158
+ * @param state - Serialised state obtained from {@link GearboxSDK.state}.
159
+ * @returns A fully initialised SDK instance.
160
+ * @throws If the snapshot's {@link STATE_VERSION} does not match.
161
+ **/
123
162
  static hydrate(options, state) {
124
163
  const { logger, plugins, strictContractTypes, gasLimit, ...rest } = options;
125
164
  const client = createClient(options, {
@@ -272,9 +311,15 @@ class GearboxSDK extends ChainContractsRegister {
272
311
  return this;
273
312
  }
274
313
  /**
275
- * Reattach SDK with the same config as before, without re-creating instance. Will load all state from scratch
276
- * Be mindful of block number, for example
277
- */
314
+ * Re-attaches the SDK using the same configuration, discarding all cached
315
+ * state and re-reading everything from the chain.
316
+ *
317
+ * Useful when the SDK needs a full refresh (e.g. after a protocol upgrade).
318
+ * Note that if the original `blockNumber` was pinned, the same block is
319
+ * re-used — call {@link syncState} instead if you want to advance.
320
+ *
321
+ * @throws If the SDK has not been attached yet.
322
+ **/
278
323
  async reattach() {
279
324
  if (!this.#attachConfig) {
280
325
  throw new Error("cannot reattach, attach config is not set");
@@ -282,8 +327,15 @@ class GearboxSDK extends ChainContractsRegister {
282
327
  await this.#attach(this.#attachConfig);
283
328
  }
284
329
  /**
285
- * Rehydrate existing SDK from new state without re-creating instance
286
- */
330
+ * Replaces the SDK's in-memory state with a new serialised snapshot
331
+ * without re-creating the instance.
332
+ *
333
+ * After hydration the `rehydrate` hook is triggered so that listeners
334
+ * can react to the state change.
335
+ *
336
+ * @param state - Serialised state obtained from {@link GearboxSDK.state}.
337
+ * @throws If the SDK has not been attached or hydrated yet.
338
+ **/
287
339
  async rehydrate(state) {
288
340
  if (!this.#attachConfig) {
289
341
  throw new Error("cannot rehydrate, attach config is not set");
@@ -299,9 +351,20 @@ class GearboxSDK extends ChainContractsRegister {
299
351
  timestamp: state.timestamp
300
352
  });
301
353
  }
354
+ /**
355
+ * Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`).
356
+ **/
302
357
  get networkType() {
303
358
  return this.client.chain.network;
304
359
  }
360
+ /**
361
+ * Returns a human-readable snapshot of the entire SDK state, suitable
362
+ * for logging or diagnostic inspection.
363
+ *
364
+ * @param raw - When `true`, include raw numeric values alongside
365
+ * formatted ones.
366
+ * @default true
367
+ **/
305
368
  stateHuman(raw = true) {
306
369
  return {
307
370
  block: Number(this.currentBlock),
@@ -319,6 +382,13 @@ class GearboxSDK extends ChainContractsRegister {
319
382
  ...this.marketRegister.stateHuman(raw)
320
383
  };
321
384
  }
385
+ /**
386
+ * Serialisable snapshot of the current SDK state.
387
+ *
388
+ * The returned object can be persisted (e.g. written to a file) and later
389
+ * passed to {@link GearboxSDK.hydrate} for instant restoration without
390
+ * on-chain reads.
391
+ **/
322
392
  get state() {
323
393
  return {
324
394
  version: STATE_VERSION,
@@ -337,10 +407,20 @@ class GearboxSDK extends ChainContractsRegister {
337
407
  };
338
408
  }
339
409
  /**
340
- * Reloads markets states based on events from last processed block to new block (defaults to latest block)
341
- * @param opts
342
- * @returns true if successful, false if was skipped or failed
343
- */
410
+ * Incrementally updates the SDK state by replaying on-chain events from the
411
+ * last processed block up to the target block (defaults to `latest`).
412
+ *
413
+ * Use the to periodically update sdk state on cron, or subscribe to new blocks
414
+ * using viem's `watchBlocks`
415
+ *
416
+ * On failure the SDK reverts to the previous block/timestamp so that
417
+ * subsequent calls can retry.
418
+ *
419
+ * @param opts - Target block and sync behaviour. When omitted the latest
420
+ * block is fetched automatically.
421
+ * @returns `true` if the sync completed successfully, `false` if it was
422
+ * skipped or failed.
423
+ **/
344
424
  async syncState(opts) {
345
425
  let {
346
426
  blockNumber,
@@ -442,12 +522,22 @@ class GearboxSDK extends ChainContractsRegister {
442
522
  }
443
523
  return success;
444
524
  }
525
+ /**
526
+ * Block number that the SDK state corresponds to.
527
+ *
528
+ * @throws If the SDK has not been attached or hydrated yet.
529
+ **/
445
530
  get currentBlock() {
446
531
  if (this.#currentBlock === void 0) {
447
532
  throw ERR_NOT_ATTACHED;
448
533
  }
449
534
  return this.#currentBlock;
450
535
  }
536
+ /**
537
+ * Block timestamp (Unix epoch seconds) corresponding to {@link currentBlock}.
538
+ *
539
+ * @throws If the SDK has not been attached or hydrated yet.
540
+ **/
451
541
  get timestamp() {
452
542
  if (this.#timestamp === void 0) {
453
543
  throw ERR_NOT_ATTACHED;
@@ -455,14 +545,23 @@ class GearboxSDK extends ChainContractsRegister {
455
545
  return this.#timestamp;
456
546
  }
457
547
  /**
458
- * All price feeds known to sdk, without oracle-related data (stalenessPeriod, main/reserve, etc.)
459
- */
548
+ * Global registry of all price feeds known to the SDK (on all markets).
549
+ *
550
+ * Unlike per-oracle price feed references, this register does not carry
551
+ * oracle-specific metadata (staleness period, main/reserve designation, etc.).
552
+ *
553
+ * @throws If the SDK has not been attached or hydrated yet.
554
+ **/
460
555
  get priceFeeds() {
461
556
  if (this.#priceFeeds === void 0) {
462
557
  throw ERR_NOT_ATTACHED;
463
558
  }
464
559
  return this.#priceFeeds;
465
560
  }
561
+ /**
562
+ * Address of the GEAR governance token on this chain, or `undefined`
563
+ * if the address provider does not list it.
564
+ **/
466
565
  get gear() {
467
566
  try {
468
567
  const g = this.addressProvider.getAddress(AP_GEAR_TOKEN, NO_VERSION);
@@ -472,12 +571,23 @@ class GearboxSDK extends ChainContractsRegister {
472
571
  return void 0;
473
572
  }
474
573
  }
574
+ /**
575
+ * The chain's address provider contract, the central directory for all
576
+ * protocol-wide Gearbox protocol addresses.
577
+ *
578
+ * @throws If the SDK has not been attached or hydrated yet.
579
+ **/
475
580
  get addressProvider() {
476
581
  if (this.#addressProvider === void 0) {
477
582
  throw ERR_NOT_ATTACHED;
478
583
  }
479
584
  return this.#addressProvider;
480
585
  }
586
+ /**
587
+ * Registry of all loaded markets (pools, credit managers, oracles, etc.).
588
+ *
589
+ * @throws If the SDK has not been attached or hydrated yet.
590
+ **/
481
591
  get marketRegister() {
482
592
  if (this.#marketRegister === void 0) {
483
593
  throw ERR_NOT_ATTACHED;
@@ -485,10 +595,15 @@ class GearboxSDK extends ChainContractsRegister {
485
595
  return this.#marketRegister;
486
596
  }
487
597
  /**
488
- * Returns router contract that will work for given credit manager or credit facade, or simply version range
489
- * @param params
490
- * @returns
491
- */
598
+ * Resolves the appropriate router contract for a given credit manager,
599
+ * credit facade, or explicit version range.
600
+ *
601
+ * @param params - Identifies the context: a credit manager address/state,
602
+ * a credit facade address/state, or a {@link VersionRange}.
603
+ * @returns The matching router contract instance.
604
+ * @throws If the credit facade version is unsupported or no router is
605
+ * registered for the resolved version range.
606
+ **/
492
607
  routerFor(params) {
493
608
  let routerRange;
494
609
  if (Array.isArray(params)) {
@@ -46,12 +46,8 @@ class AbstractCreditAccountService extends SDKConstruct {
46
46
  );
47
47
  }
48
48
  /**
49
- * Returns single credit account data, or undefined if it's not found
50
- * Performs all necessary price feed updates under the hood
51
- * @param account
52
- * @param blockNumber
53
- * @returns
54
- */
49
+ * {@inheritDoc ICreditAccountsService.getCreditAccountData}
50
+ **/
55
51
  async getCreditAccountData(account, blockNumber) {
56
52
  let raw;
57
53
  try {
@@ -90,13 +86,8 @@ class AbstractCreditAccountService extends SDKConstruct {
90
86
  return cad;
91
87
  }
92
88
  /**
93
- * Methods to get all credit accounts with some optional filtering
94
- * Performs all necessary price feed updates under the hood
95
- *
96
- * @param options
97
- * @param blockNumber
98
- * @returns returned credit accounts are sorted by health factor in ascending order
99
- */
89
+ * {@inheritDoc ICreditAccountsService.getCreditAccounts}
90
+ **/
100
91
  async getCreditAccounts(options, blockNumber) {
101
92
  const {
102
93
  creditManager,
@@ -149,11 +140,8 @@ class AbstractCreditAccountService extends SDKConstruct {
149
140
  return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
150
141
  }
151
142
  /**
152
- * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
153
- Assosiates rewards by adapter + stakedPhantomToken
154
- * @param {Address} creditAccount - address of credit account to get rewards for
155
- * @returns {Array<Rewards>} list of {@link Rewards} that can be claimed
156
- */
143
+ * {@inheritDoc ICreditAccountsService.getRewards}
144
+ **/
157
145
  async getRewards(creditAccount) {
158
146
  const rewards = await this.client.readContract({
159
147
  abi: rewardsCompressorAbi,
@@ -193,11 +181,8 @@ class AbstractCreditAccountService extends SDKConstruct {
193
181
  return Object.values(r);
194
182
  }
195
183
  /**
196
- * Method to get all connected bots for credit account
197
- * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
198
- and their credit managers to check connected bots on
199
- * @returns call result of getConnectedBots for each credit account
200
- */
184
+ * {@inheritDoc ICreditAccountsService.getConnectedBots}
185
+ **/
201
186
  async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
202
187
  const allResp = await this.client.multicall({
203
188
  contracts: [
@@ -301,10 +286,8 @@ class AbstractCreditAccountService extends SDKConstruct {
301
286
  return void 0;
302
287
  }
303
288
  /**
304
- * Generates transaction to liquidate credit account
305
- * @param props - {@link FullyLiquidateProps}
306
- * @returns
307
- */
289
+ * {@inheritDoc ICreditAccountsService.fullyLiquidate}
290
+ **/
308
291
  async fullyLiquidate(props) {
309
292
  const {
310
293
  account,
@@ -354,21 +337,8 @@ class AbstractCreditAccountService extends SDKConstruct {
354
337
  };
355
338
  }
356
339
  /**
357
- * Closes credit account or closes credit account and keeps it open with zero debt.
358
- - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
359
- -> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens tokens -> withdraw underlying tokenz
360
- * @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
361
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
362
- * @param {Array<Address>} assetsToWithdraw - tokens to withdraw from credit account.
363
- For credit account closing this is the underlying token, because during the closure,
364
- all tokens on account are swapped into the underlying,
365
- and only the underlying token will remain on the credit account
366
- * @param {Address} to - Wallet address to withdraw underlying to
367
- * @param {number} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
368
- * @default 50n
369
- * @param {RouterCloseResult | undefined} closePath - result of findBestClosePath method from router; if omited, calls marketRegister.findCreditManager {@link RouterCloseResult}
370
- * @returns All necessary data to execute the transaction (call, credit facade)
371
- */
340
+ * {@inheritDoc ICreditAccountsService.closeCreditAccount}
341
+ **/
372
342
  async closeCreditAccount({
373
343
  operation,
374
344
  assetsToWithdraw,
@@ -400,13 +370,8 @@ class AbstractCreditAccountService extends SDKConstruct {
400
370
  return { tx, calls, routerCloseResult, creditFacade: cm.creditFacade };
401
371
  }
402
372
  /**
403
- * Updates quota of credit account.
404
- - CA quota updated in the following order: price update -> update quotas
405
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
406
- * @param {Array<Asset>} averageQuota - average quota for desired tokens {@link Asset}
407
- * @param {Array<Asset>} minQuota - minimum quota for desired tokens {@link Asset}
408
- * @returns All necessary data to execute the transaction (call, credit facade)
409
- */
373
+ * {@inheritDoc ICreditAccountsService.updateQuotas}
374
+ **/
410
375
  async updateQuotas({
411
376
  minQuota,
412
377
  averageQuota,
@@ -430,16 +395,8 @@ class AbstractCreditAccountService extends SDKConstruct {
430
395
  return { tx, calls, creditFacade: cm.creditFacade };
431
396
  }
432
397
  /**
433
- * Adds a single collateral to credit account and updates quotas
434
- - Collateral is added in the following order: price update -> add collateral (with permit) -> update quotas
435
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
436
- * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
437
- * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
438
- * @param {Asset} asset - asset to add as collateral {@link Asset}
439
- * @param {PermitResult | undefined} permits - permits of collateral asset if it is permittable {@link PermitResult}
440
- * @param {bigint} ethAmount - native token amount to attach to tx
441
- * @returns All necessary data to execute the transaction (call, credit facade)
442
- */
398
+ * {@inheritDoc ICreditAccountsService.addCollateral}
399
+ **/
443
400
  async addCollateral({
444
401
  creditAccount,
445
402
  asset,
@@ -473,15 +430,8 @@ class AbstractCreditAccountService extends SDKConstruct {
473
430
  return { tx, calls, creditFacade: cm.creditFacade };
474
431
  }
475
432
  /**
476
- * Increases or decreases debt of credit account; debt decrease uses token ON CREDIT ACCOUNT
477
- - Debt is changed in the following order: price update -> (enables underlying if it was disabled) -> change debt
478
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
479
- * @param {bigint} amount - amount to change debt by;
480
- 0 - prohibited value;
481
- negative value for debt decrease;
482
- positive value for debt increase.
483
- * @returns All necessary data to execute the transaction (call, credit facade)
484
- */
433
+ * {@inheritDoc ICreditAccountsService.changeDebt}
434
+ **/
485
435
  async changeDebt({
486
436
  creditAccount,
487
437
  amount,
@@ -518,14 +468,8 @@ class AbstractCreditAccountService extends SDKConstruct {
518
468
  return { tx, calls, creditFacade: cm.creditFacade };
519
469
  }
520
470
  /**
521
- * Executes swap specified by given calls, update quotas of affected tokens
522
- - Swap is executed in the following order: price update -> execute swap path -> update quotas
523
- * @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
524
- * @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
525
- * @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
526
- * @param {Array<MultiCall>} calls - array of MultiCall from router methods getSingleSwap or getAllSwaps {@link MultiCall}
527
- * @returns All necessary data to execute the transaction (call, credit facade)
528
- */
471
+ * {@inheritDoc ICreditAccountsService.executeSwap}
472
+ **/
529
473
  async executeSwap({
530
474
  creditAccount,
531
475
  calls: swapCalls,
@@ -553,10 +497,8 @@ class AbstractCreditAccountService extends SDKConstruct {
553
497
  return { tx, calls, creditFacade: cm.creditFacade };
554
498
  }
555
499
  /**
556
- * Preview delayed withdrawal for given token
557
- * @param props - {@link PreviewDelayedWithdrawalProps}
558
- * @returns
559
- */
500
+ * {@inheritDoc ICreditAccountsService.previewDelayedWithdrawal}
501
+ **/
560
502
  async previewDelayedWithdrawal({
561
503
  creditAccount,
562
504
  amount,
@@ -580,10 +522,8 @@ class AbstractCreditAccountService extends SDKConstruct {
580
522
  return resp;
581
523
  }
582
524
  /**
583
- * Get claimable and pending withdrawals of an account
584
- * @param props - {@link GetPendingWithdrawalsProps}
585
- * @returns
586
- */
525
+ * {@inheritDoc ICreditAccountsService.getPendingWithdrawals}
526
+ **/
587
527
  async getPendingWithdrawals({
588
528
  creditAccount
589
529
  }) {
@@ -609,11 +549,8 @@ class AbstractCreditAccountService extends SDKConstruct {
609
549
  return respResult;
610
550
  }
611
551
  /**
612
- * Start delayed withdrawal for given token
613
- - Withdrawal is executed in the following order: price update -> execute withdraw calls -> update quotas
614
- * @param props - {@link StartDelayedWithdrawalProps}
615
- * @returns
616
- */
552
+ * {@inheritDoc ICreditAccountsService.startDelayedWithdrawal}
553
+ **/
617
554
  async startDelayedWithdrawal({
618
555
  creditAccount,
619
556
  minQuota,
@@ -669,11 +606,8 @@ class AbstractCreditAccountService extends SDKConstruct {
669
606
  return { tx, calls, creditFacade: cm.creditFacade };
670
607
  }
671
608
  /**
672
- * Claim tokens with delayed withdrawal
673
- - Claim is executed in the following order: price update -> execute claim calls -> update quotas
674
- * @param props - {@link ClaimDelayedProps}
675
- * @returns
676
- */
609
+ * {@inheritDoc ICreditAccountsService.claimDelayed}
610
+ **/
677
611
  async claimDelayed({
678
612
  creditAccount,
679
613
  minQuota,
@@ -734,29 +668,8 @@ class AbstractCreditAccountService extends SDKConstruct {
734
668
  return { tx, calls, creditFacade: cm.creditFacade };
735
669
  }
736
670
  /**
737
- * Executes swap specified by given calls, update quotas of affected tokens
738
- - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
739
- -> update quotas -> (optionally: execute swap path for trading/strategy) ->
740
- -> (optionally: withdraw debt for lending)
741
- - Basic open credit account: price update -> increase debt -> add collateral -> update quotas
742
- - Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
743
- - Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
744
- - In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
745
- * @param {bigint} ethAmount - native token amount to attach to tx
746
- * @param {Address} creditManager - address of credit manager to open credit account on
747
- * @param {Array<Asset>} collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
748
- * @param {Record<Address, PermitResult>} permits - permits of collateral tokens (in any permittable token is present) {@link PermitResult}
749
- * @param {bigint} debt - debt to open credit account with
750
- * @param {boolean} withdrawDebt - flag to withdraw debt to wallet after opening credit account;
751
- used for borrowing functionality
752
- * @param {bigint} referralCode - referral code to open credit account with
753
- * @param {Address} to - wallet address to transfer credit account to\
754
- * @param {Array<MultiCall>} calls - array of MultiCall from router methods findOpenStrategyPath {@link MultiCall}.
755
- Used for trading and strategy functionality
756
- * @param {Array<Asset>} averageQuota - average quota for tokens after open {@link Asset}
757
- * @param {Array<Asset>} minQuota - minimum quota for tokens after open {@link Asset}
758
- * @returns All necessary data to execute the transaction (call, credit facade)
759
- */
671
+ * {@inheritDoc ICreditAccountsService.openCA}
672
+ **/
760
673
  async openCA({
761
674
  ethAmount,
762
675
  creditManager,
@@ -792,10 +705,8 @@ class AbstractCreditAccountService extends SDKConstruct {
792
705
  return { calls, tx, creditFacade: cmSuite.creditFacade };
793
706
  }
794
707
  /**
795
- * Returns borrow rate with 4 digits precision (10000 = 100%)
796
- * @param ca
797
- * @returns
798
- */
708
+ * {@inheritDoc ICreditAccountsService.getBorrowRate}
709
+ **/
799
710
  getBorrowRate(ca) {
800
711
  const { creditManager } = this.sdk.marketRegister.findCreditManager(
801
712
  ca.creditManager
@@ -821,9 +732,8 @@ class AbstractCreditAccountService extends SDKConstruct {
821
732
  return r + qr;
822
733
  }
823
734
  /**
824
- * Returns optimal HF for partial liquidation with 4 digits precision (10000 = 100%)
825
- * @param ca
826
- */
735
+ * {@inheritDoc ICreditAccountsService.getOptimalHFForPartialLiquidation}
736
+ **/
827
737
  getOptimalHFForPartialLiquidation(ca) {
828
738
  const borrowRate = this.getBorrowRate(ca);
829
739
  return PERCENTAGE_FACTOR + (borrowRate < 100n ? borrowRate : 100n);
@@ -872,12 +782,8 @@ class AbstractCreditAccountService extends SDKConstruct {
872
782
  return resp;
873
783
  }
874
784
  /**
875
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
876
- *
877
- * This can be used by batch liquidator
878
- * @param accounts
879
- * @returns
880
- */
785
+ * {@inheritDoc ICreditAccountsService.getUpdateForAccounts}
786
+ **/
881
787
  async getUpdateForAccounts(accounts) {
882
788
  const tokensByPool = /* @__PURE__ */ new Map();
883
789
  const oracleByPool = /* @__PURE__ */ new Map();
@@ -949,10 +855,8 @@ class AbstractCreditAccountService extends SDKConstruct {
949
855
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
950
856
  }
951
857
  /**
952
- * Returns account price updates that can be used in credit facade multicall or liquidator calls
953
- * @param options
954
- * @returns
955
- */
858
+ * {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
859
+ **/
956
860
  async getOnDemandPriceUpdates(options) {
957
861
  const { creditManager, creditAccount } = options;
958
862
  const market = this.sdk.marketRegister.findByCreditManager(creditManager);
@@ -968,13 +872,8 @@ class AbstractCreditAccountService extends SDKConstruct {
968
872
  );
969
873
  }
970
874
  /**
971
- * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
972
- * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
973
- * - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
974
- * - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
975
- * @param acc
976
- * @returns
977
- */
875
+ * {@inheritDoc ICreditAccountsService.getPriceUpdatesForFacade}
876
+ **/
978
877
  async getPriceUpdatesForFacade(options) {
979
878
  const updates = await this.getOnDemandPriceUpdates(options);
980
879
  return updates.multicall;
@@ -4,7 +4,7 @@ import { MAX_UINT256 } from "../constants/math.js";
4
4
  import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
5
5
  class CreditAccountServiceV310 extends AbstractCreditAccountService {
6
6
  /**
7
- * Implements {@link ICreditAccountsService.setBot}
7
+ * {@inheritDoc ICreditAccountsService.setBot}
8
8
  */
9
9
  async setBot({
10
10
  botAddress,
@@ -46,7 +46,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
46
46
  return { tx, calls, creditFacade: cm.creditFacade };
47
47
  }
48
48
  /**
49
- * Implements {@link ICreditAccountsService.withdrawCollateral}
49
+ * {@inheritDoc ICreditAccountsService.withdrawCollateral}
50
50
  */
51
51
  async withdrawCollateral({
52
52
  creditAccount,
@@ -81,7 +81,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
81
81
  return { tx, calls, creditFacade: cm.creditFacade };
82
82
  }
83
83
  /**
84
- * Implements {@link ICreditAccountsService.repayCreditAccount}
84
+ * {@inheritDoc ICreditAccountsService.repayCreditAccount}
85
85
  */
86
86
  async repayCreditAccount({
87
87
  operation,
@@ -117,7 +117,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
117
117
  return { tx, calls, creditFacade: cm.creditFacade };
118
118
  }
119
119
  /**
120
- * Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
120
+ * {@inheritDoc ICreditAccountsService.repayAndLiquidateCreditAccount}
121
121
  */
122
122
  async repayAndLiquidateCreditAccount({
123
123
  collateralAssets,
@@ -154,7 +154,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
154
154
  return { tx, calls, creditFacade: cm.creditFacade };
155
155
  }
156
156
  /**
157
- * Implements {@link ICreditAccountsService.claimFarmRewards}
157
+ * {@inheritDoc ICreditAccountsService.claimFarmRewards}
158
158
  */
159
159
  async claimFarmRewards({
160
160
  calls: externalCalls,
@@ -35,11 +35,30 @@ class ContractParseError extends BaseError {
35
35
  }
36
36
  }
37
37
  class BaseContract extends Construct {
38
+ /**
39
+ * Viem contract instance for direct read calls
40
+ **/
38
41
  contract;
42
+ /**
43
+ * Contract ABI
44
+ **/
39
45
  abi;
46
+ /**
47
+ * Gearbox contract type identifier (e.g. `"CREDIT_MANAGER"`), or empty string if unknown.
48
+ **/
40
49
  contractType;
50
+ /**
51
+ * Contract version number.
52
+ * @default 0
53
+ **/
41
54
  version;
55
+ /**
56
+ * On-chain address of the contract.
57
+ **/
42
58
  address;
59
+ /**
60
+ * Display name for the contract.
61
+ **/
43
62
  name;
44
63
  constructor(options, args) {
45
64
  super(options);
@@ -63,6 +82,7 @@ class BaseContract extends Construct {
63
82
  register.setAddressLabel(this.address, this.name);
64
83
  }
65
84
  }
85
+ /** {@inheritDoc IBaseContract.stateHuman} */
66
86
  stateHuman(_ = true) {
67
87
  return {
68
88
  address: this.labelAddress(this.address),
@@ -71,9 +91,10 @@ class BaseContract extends Construct {
71
91
  };
72
92
  }
73
93
  /**
74
- * Updates (or not) contract's internal state from event
75
- * @param _log
76
- */
94
+ * Applies an on-chain event to update this contract's local state.
95
+ *
96
+ * @param _log - Decoded event log emitted by this contract.
97
+ **/
77
98
  processLog(_log) {
78
99
  }
79
100
  /**
@@ -148,9 +169,8 @@ class BaseContract extends Construct {
148
169
  }
149
170
  }
150
171
  /**
151
- * Same as {@link stingifyFunctionData}, but throws if error occurs
152
- * @param calldata
153
- * @returns
172
+ * Same as {@link stringifyFunctionData}, but throws if error occurs.
173
+ * @param calldata - Raw ABI-encoded calldata.
154
174
  */
155
175
  mustStringifyFunctionData(calldata) {
156
176
  const decoded = decodeFunctionData({