@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
@@ -57,12 +57,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
57
57
  );
58
58
  }
59
59
  /**
60
- * Returns single credit account data, or undefined if it's not found
61
- * Performs all necessary price feed updates under the hood
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
- * Methods to get all credit accounts with some optional filtering
105
- * Performs all necessary price feed updates under the hood
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
- * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
164
- Assosiates rewards by adapter + stakedPhantomToken
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
- * Method to get all connected bots for credit account
208
- * @param {Array<AccountToCheck>} accountsToCheck - list of credit accounts
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
- * Generates transaction to liquidate credit account
316
- * @param props - {@link FullyLiquidateProps}
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
- * Closes credit account or closes credit account and keeps it open with zero debt.
369
- - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
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
- * Updates quota of credit account.
415
- - CA quota updated in the following order: price update -> update quotas
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
- * Adds a single collateral to credit account and updates quotas
445
- - Collateral is added in the following order: price update -> add collateral (with permit) -> update quotas
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
- * Increases or decreases debt of credit account; debt decrease uses token ON CREDIT ACCOUNT
488
- - Debt is changed in the following order: price update -> (enables underlying if it was disabled) -> change debt
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
- * Executes swap specified by given calls, update quotas of affected tokens
533
- - Swap is executed in the following order: price update -> execute swap path -> update quotas
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
- * Preview delayed withdrawal for given token
568
- * @param props - {@link PreviewDelayedWithdrawalProps}
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
- * Get claimable and pending withdrawals of an account
595
- * @param props - {@link GetPendingWithdrawalsProps}
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
- * Start delayed withdrawal for given token
624
- - Withdrawal is executed in the following order: price update -> execute withdraw calls -> update quotas
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
- * Claim tokens with delayed withdrawal
684
- - Claim is executed in the following order: price update -> execute claim calls -> update quotas
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
- * Executes swap specified by given calls, update quotas of affected tokens
749
- - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
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
- * Returns borrow rate with 4 digits precision (10000 = 100%)
807
- * @param ca
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
- * Returns optimal HF for partial liquidation with 4 digits precision (10000 = 100%)
836
- * @param ca
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
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
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
- * Returns account price updates that can be used in credit facade multicall or liquidator calls
964
- * @param options
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
- * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
983
- * - If there are desiredQuotas and creditAccount update quotaBalance > 0 || (balance > 10n && isEnabled). Is used when account has both: balances and quota buys.
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
- * Implements {@link ICreditAccountsService.setBot}
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
- * Implements {@link ICreditAccountsService.withdrawCollateral}
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
- * Implements {@link ICreditAccountsService.repayCreditAccount}
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
- * Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
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
- * Implements {@link ICreditAccountsService.claimFarmRewards}
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
- * Updates (or not) contract's internal state from event
85
- * @param _log
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 stingifyFunctionData}, but throws if error occurs
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)({
@@ -32,8 +32,8 @@ class ChainContractsRegister {
32
32
  labels = new import_AddressMap.AddressMap([], "labels");
33
33
  client;
34
34
  /**
35
- * Token metadata such as symbol and decimals
36
- */
35
+ * Shared token metadata (symbol, decimals) for all tokens known on this chain.
36
+ **/
37
37
  tokensMeta;
38
38
  logger;
39
39
  constructor(client, logger) {
@@ -41,6 +41,9 @@ class ChainContractsRegister {
41
41
  this.tokensMeta = new import_TokensMeta.TokensMeta(client);
42
42
  this.logger = logger;
43
43
  }
44
+ /**
45
+ * Clears all registered contracts, address labels, and token metadata.
46
+ **/
44
47
  resetContracts() {
45
48
  this.logger?.debug(
46
49
  `resetting contacts register with ${this.contracts.size} contracts`
@@ -49,9 +52,19 @@ class ChainContractsRegister {
49
52
  this.contracts.clear();
50
53
  this.tokensMeta.reset();
51
54
  }
55
+ /**
56
+ * Looks up a contract by address.
57
+ * @param address - On-chain address.
58
+ * @returns The contract wrapper, or `undefined` if not registered.
59
+ */
52
60
  getContract(address) {
53
61
  return this.contracts.get(address);
54
62
  }
63
+ /**
64
+ * Looks up a contract by address, throwing if not found.
65
+ * @param address - On-chain address.
66
+ * @throws If no contract is registered at this address.
67
+ */
55
68
  mustGetContract(address) {
56
69
  const contract = this.contracts.mustGet(address);
57
70
  if (!contract) {
@@ -59,9 +72,21 @@ class ChainContractsRegister {
59
72
  }
60
73
  return contract;
61
74
  }
75
+ /**
76
+ * Registers (or replaces) a contract at the given address.
77
+ * @param address - On-chain address.
78
+ * @param contract - Contract wrapper instance.
79
+ */
62
80
  setContract(address, contract) {
63
81
  this.contracts.upsert(address, contract);
64
82
  }
83
+ /**
84
+ * Assigns a human-readable label to an address for use in logging and
85
+ * parsed call output.
86
+ * @param address - On-chain address.
87
+ * @param label - Static label string, or a function that receives the
88
+ * current label and returns a new one.
89
+ */
65
90
  setAddressLabel(address, label) {
66
91
  if (address === import_addresses.NOT_DEPLOYED) {
67
92
  return;
@@ -72,13 +97,25 @@ class ChainContractsRegister {
72
97
  this.labels.upsert(address, label(this.labels.get(address)));
73
98
  }
74
99
  }
100
+ /**
101
+ * Returns a display string for an address, incorporating its label if one exists.
102
+ * @param address - On-chain address.
103
+ * @param omitAddress - When `true`, returns only the label (no address prefix).
104
+ * Falls back to the raw address when no label is set.
105
+ */
75
106
  labelAddress(address, omitAddress) {
76
107
  const label = this.labels.get(address);
77
108
  return label ? omitAddress ? label : `${address} [${label}]` : address;
78
109
  }
110
+ /**
111
+ * The viem {@link Chain} object for this register's connected client.
112
+ **/
79
113
  get chain() {
80
114
  return this.client.chain;
81
115
  }
116
+ /**
117
+ * Numeric chain ID (e.g. `1` for Ethereum mainnet).
118
+ **/
82
119
  get chainId() {
83
120
  return this.client.chain.id;
84
121
  }
@@ -27,9 +27,6 @@ class Construct {
27
27
  logger;
28
28
  client;
29
29
  #register;
30
- /**
31
- * Indicates that contract state needs to be updated
32
- */
33
30
  #dirty = false;
34
31
  constructor(options) {
35
32
  if (options instanceof import_ChainContractsRegister.ChainContractsRegister) {
@@ -61,12 +58,22 @@ class Construct {
61
58
  safeGetRegister() {
62
59
  return this.#register;
63
60
  }
61
+ /**
62
+ * The viem {@link Chain} object associated with the connected client.
63
+ **/
64
64
  get chain() {
65
65
  return this.client.chain;
66
66
  }
67
+ /**
68
+ * Numeric chain ID (e.g. `1` for Ethereum mainnet).
69
+ **/
67
70
  get chainId() {
68
71
  return this.client.chain.id;
69
72
  }
73
+ /**
74
+ * Gearbox network type for this chain (e.g. `"Mainnet"`, `"Arbitrum"`).
75
+ * @throws If the chain was not created by the Gearbox SDK.
76
+ */
70
77
  get networkType() {
71
78
  if ("network" in this.chain) {
72
79
  return this.chain.network;
@@ -74,6 +81,7 @@ class Construct {
74
81
  throw new Error(`chain ${this.chain.id} is not a Gearbox SDK chain`);
75
82
  }
76
83
  /**
84
+ * @internal
77
85
  * Indicates that contract state diverged from onchain state and needs to be updated
78
86
  */
79
87
  get dirty() {
@@ -82,6 +90,9 @@ class Construct {
82
90
  set dirty(value) {
83
91
  this.#dirty = value;
84
92
  }
93
+ /**
94
+ * Information about tokens known on this chain
95
+ */
85
96
  get tokensMeta() {
86
97
  return this.register.tokensMeta;
87
98
  }
@@ -89,6 +100,7 @@ class Construct {
89
100
  return this.#register?.labelAddress(address, omitAddress) ?? address;
90
101
  }
91
102
  /**
103
+ * @internal
92
104
  * Returns list of addresses that should be watched for events to sync state
93
105
  */
94
106
  get watchAddresses() {
@@ -30,13 +30,26 @@ class TokensMeta extends import_utils.AddressMap {
30
30
  super(void 0, "tokensMeta");
31
31
  this.#client = client;
32
32
  }
33
+ /**
34
+ * Clears all token metadata
35
+ **/
33
36
  reset() {
34
37
  this.clear();
35
38
  this.#phantomTokensLoaded = void 0;
36
39
  }
40
+ /**
41
+ * Returns the symbol string for a token.
42
+ * @param token - Token address.
43
+ * @throws If the token is not in the registry.
44
+ */
37
45
  symbol(token) {
38
46
  return this.mustGet(token).symbol;
39
47
  }
48
+ /**
49
+ * Returns the decimal count for a token.
50
+ * @param token - Token address.
51
+ * @throws If the token is not in the registry.
52
+ */
40
53
  decimals(token) {
41
54
  return this.mustGet(token).decimals;
42
55
  }
@@ -71,9 +84,19 @@ class TokensMeta extends import_utils.AddressMap {
71
84
  const asStr = (0, import_utils.formatBN)(amount, this.decimals(token), precision);
72
85
  return symbol ? `${asStr} ${this.symbol(token)}` : asStr;
73
86
  }
87
+ /**
88
+ * Finds a token by its symbol (e.g. `"USDC"`).
89
+ * @param symbol - Case-sensitive ticker symbol.
90
+ * @returns The matching metadata, or `undefined` if no token has this symbol.
91
+ */
74
92
  findBySymbol(symbol) {
75
93
  return this.values().find((v) => v.symbol === symbol);
76
94
  }
95
+ /**
96
+ * Finds a token by its symbol, throwing if not found.
97
+ * @param symbol - Case-sensitive ticker symbol.
98
+ * @throws If no token matches the symbol.
99
+ */
77
100
  mustFindBySymbol(symbol) {
78
101
  const meta = this.findBySymbol(symbol);
79
102
  if (!meta) {
@@ -18,7 +18,6 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var address_provider_exports = {};
20
20
  __export(address_provider_exports, {
21
- ADDRESS_PROVIDER: () => ADDRESS_PROVIDER,
22
21
  ADDRESS_PROVIDER_V310: () => ADDRESS_PROVIDER_V310,
23
22
  AP_ACCOUNT_FACTORY: () => AP_ACCOUNT_FACTORY,
24
23
  AP_ACL: () => AP_ACL,
@@ -55,7 +54,6 @@ __export(address_provider_exports, {
55
54
  NO_VERSION: () => NO_VERSION
56
55
  });
57
56
  module.exports = __toCommonJS(address_provider_exports);
58
- var import_addresses = require("./addresses.js");
59
57
  const NO_VERSION = 0;
60
58
  const AP_ACCOUNT_FACTORY = "ACCOUNT_FACTORY";
61
59
  const AP_ACL = "ACL";
@@ -89,29 +87,9 @@ const AP_WETH_GATEWAY = "WETH_GATEWAY";
89
87
  const AP_WETH_TOKEN = "WETH_TOKEN";
90
88
  const AP_ZAPPER_REGISTER = "ZAPPER_REGISTER";
91
89
  const AP_ZERO_PRICE_FEED = "ZERO_PRICE_FEED";
92
- const ADDRESS_PROVIDER = {
93
- Mainnet: "0x9ea7b04Da02a5373317D745c1571c84aaD03321D",
94
- Arbitrum: "0x7d04eCdb892Ae074f03B5D0aBA03796F90F3F2af",
95
- Optimism: "0x3761ca4BFAcFCFFc1B8034e69F19116dD6756726",
96
- Base: import_addresses.NOT_DEPLOYED,
97
- Sonic: "0x4b27b296273B72d7c7bfee1ACE93DC081467C41B",
98
- // New networks
99
- MegaETH: import_addresses.NOT_DEPLOYED,
100
- Monad: import_addresses.NOT_DEPLOYED,
101
- Berachain: import_addresses.NOT_DEPLOYED,
102
- Avalanche: import_addresses.NOT_DEPLOYED,
103
- BNB: import_addresses.NOT_DEPLOYED,
104
- WorldChain: import_addresses.NOT_DEPLOYED,
105
- Etherlink: import_addresses.NOT_DEPLOYED,
106
- Hemi: import_addresses.NOT_DEPLOYED,
107
- Lisk: import_addresses.NOT_DEPLOYED,
108
- Plasma: import_addresses.NOT_DEPLOYED,
109
- Somnia: import_addresses.NOT_DEPLOYED
110
- };
111
90
  const ADDRESS_PROVIDER_V310 = "0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38";
112
91
  // Annotate the CommonJS export names for ESM import in node:
113
92
  0 && (module.exports = {
114
- ADDRESS_PROVIDER,
115
93
  ADDRESS_PROVIDER_V310,
116
94
  AP_ACCOUNT_FACTORY,
117
95
  AP_ACL,