@gearbox-protocol/sdk 13.3.3 → 13.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +3 -15
  2. package/dist/cjs/sdk/GearboxSDK.js +135 -20
  3. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +196 -340
  4. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +30 -35
  5. package/dist/cjs/sdk/accounts/multicall-utils.js +91 -0
  6. package/dist/cjs/sdk/base/BaseContract.js +26 -6
  7. package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
  8. package/dist/cjs/sdk/base/Construct.js +15 -3
  9. package/dist/cjs/sdk/base/TokensMeta.js +23 -0
  10. package/dist/cjs/sdk/constants/address-provider.js +0 -22
  11. package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
  12. package/dist/cjs/sdk/market/MarketRegister.js +74 -3
  13. package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
  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/esm/permissionless/utils/price-update/get-price-update-tx.js +6 -20
  25. package/dist/esm/sdk/GearboxSDK.js +135 -20
  26. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +204 -342
  27. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +30 -35
  28. package/dist/esm/sdk/accounts/multicall-utils.js +69 -0
  29. package/dist/esm/sdk/base/BaseContract.js +26 -6
  30. package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
  31. package/dist/esm/sdk/base/Construct.js +15 -3
  32. package/dist/esm/sdk/base/TokensMeta.js +23 -0
  33. package/dist/esm/sdk/constants/address-provider.js +0 -21
  34. package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
  35. package/dist/esm/sdk/market/MarketRegister.js +74 -3
  36. package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
  37. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  38. package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  39. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  40. package/dist/esm/sdk/options.js +30 -24
  41. package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
  42. package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
  43. package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
  44. package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
  45. package/dist/esm/sdk/utils/AddressMap.js +53 -17
  46. package/dist/esm/sdk/utils/AddressSet.js +9 -0
  47. package/dist/types/permissionless/bindings/price-feed-store.d.ts +1 -2
  48. package/dist/types/permissionless/bindings/types.d.ts +0 -4
  49. package/dist/types/permissionless/utils/price-update/get-price-update-tx.d.ts +1 -3
  50. package/dist/types/sdk/GearboxSDK.d.ts +236 -34
  51. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +92 -147
  52. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
  53. package/dist/types/sdk/accounts/multicall-utils.d.ts +39 -0
  54. package/dist/types/sdk/accounts/types.d.ts +237 -40
  55. package/dist/types/sdk/base/BaseContract.d.ts +67 -6
  56. package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
  57. package/dist/types/sdk/base/Construct.d.ts +31 -0
  58. package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
  59. package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
  60. package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
  61. package/dist/types/sdk/base/types.d.ts +185 -25
  62. package/dist/types/sdk/chain/chains.d.ts +78 -18
  63. package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
  64. package/dist/types/sdk/constants/address-provider.d.ts +4 -3
  65. package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
  66. package/dist/types/sdk/core/types.d.ts +46 -0
  67. package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
  68. package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
  69. package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +1 -0
  70. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
  71. package/dist/types/sdk/market/oracle/types.d.ts +78 -59
  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 +80 -16
  76. package/dist/types/sdk/market/pricefeeds/getRawPriceUpdates.d.ts +2 -2
  77. package/dist/types/sdk/market/pricefeeds/types.d.ts +75 -11
  78. package/dist/types/sdk/options.d.ts +13 -4
  79. package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
  80. package/dist/types/sdk/plugins/types.d.ts +73 -43
  81. package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
  82. package/dist/types/sdk/pools/types.d.ts +75 -6
  83. package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
  84. package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
  85. package/dist/types/sdk/router/types.d.ts +47 -70
  86. package/dist/types/sdk/types/state.d.ts +32 -3
  87. package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
  88. package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
  89. package/package.json +4 -2
@@ -3,55 +3,154 @@ import type { creditAccountCompressorAbi } from "../../abi/compressors/creditAcc
3
3
  import type { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
4
4
  import type { ConnectedBotData, Construct, CreditAccountData } from "../base/index.js";
5
5
  import type { GearboxSDK } from "../GearboxSDK.js";
6
- import type { CreditSuite, OnDemandPriceUpdates, UpdatePriceFeedsResult } from "../market/index.js";
7
- import type { Asset, CreditAccountTokensSlice, RouterCASlice, RouterCloseResult } from "../router/index.js";
6
+ import type { CreditSuite, PriceUpdate } from "../market/index.js";
7
+ import type { Asset, RouterCASlice, RouterCloseResult } from "../router/index.js";
8
8
  import type { MultiCall, RawTx } from "../types/index.js";
9
+ /**
10
+ * @internal
11
+ * Arguments tuple for the credit account compressor's `getCreditAccounts` view method.
12
+ **/
9
13
  export type GetCreditAccountsArgs = ContractFunctionArgs<typeof creditAccountCompressorAbi, "pure" | "view", "getCreditAccounts">;
14
+ /**
15
+ * @internal
16
+ * Filtering criteria applied to individual credit accounts when querying the compressor.
17
+ **/
10
18
  export interface CreditAccountFilter {
19
+ /**
20
+ * Filter by account owner address.
21
+ **/
11
22
  owner: Address;
23
+ /**
24
+ * Whether to include accounts with zero outstanding debt.
25
+ **/
12
26
  includeZeroDebt: boolean;
27
+ /**
28
+ * Minimum health factor threshold (inclusive).
29
+ * 18 digits precision (10^18 = 1)
30
+ **/
13
31
  minHealthFactor: bigint;
32
+ /**
33
+ * Maximum health factor threshold (inclusive).
34
+ * 18 digits precision (10^18 = 1)
35
+ **/
14
36
  maxHealthFactor: bigint;
37
+ /**
38
+ * Whether to return only accounts whose health computation reverts.
39
+ **/
15
40
  reverting: boolean;
16
41
  }
42
+ /**
43
+ * @internal
44
+ * Filtering criteria to select which credit managers to query.
45
+ **/
17
46
  export interface CreditManagerFilter {
47
+ /**
48
+ * Only include credit managers owned by these market configurators.
49
+ **/
18
50
  configurators: readonly Address[];
51
+ /**
52
+ * Only include these specific credit manager addresses.
53
+ **/
19
54
  creditManagers: readonly Address[];
55
+ /**
56
+ * Only include credit managers linked to these pool addresses.
57
+ **/
20
58
  pools: readonly Address[];
59
+ /**
60
+ * Only include credit managers with this underlying token.
61
+ **/
21
62
  underlying: Address;
22
63
  }
64
+ /**
65
+ * Options for fetching credit accounts, allowing filtering by credit manager, owner, and health factor range.
66
+ **/
23
67
  export interface GetCreditAccountsOptions {
68
+ /**
69
+ * If set, only return accounts from this credit manager; otherwise query all attached markets.
70
+ **/
24
71
  creditManager?: Address;
72
+ /**
73
+ * If set, only return accounts owned by this address.
74
+ **/
25
75
  owner?: Address;
76
+ /**
77
+ * Whether to include accounts with zero outstanding debt.
78
+ * @default false
79
+ **/
26
80
  includeZeroDebt?: boolean;
81
+ /**
82
+ * Minimum health factor threshold (inclusive).
83
+ * 18 digits precision (10^18 = 1)
84
+ * @default 0n
85
+ **/
27
86
  minHealthFactor?: bigint;
87
+ /**
88
+ * Maximum health factor threshold (inclusive).
89
+ * 18 digits precision (10^18 = 1)
90
+ * @default MAX_UINT256
91
+ **/
28
92
  maxHealthFactor?: bigint;
29
93
  /**
30
- * If true, will filter out reserve price updates
31
- */
32
- ignoreReservePrices?: boolean;
33
- }
34
- export interface PriceUpdatesOptions {
35
- creditManager: Address;
36
- creditAccount?: CreditAccountTokensSlice;
37
- desiredQuotas?: Asset[];
94
+ * If true, exclude reserve price feed updates from the query.
95
+ **/
38
96
  ignoreReservePrices?: boolean;
39
97
  }
98
+ /**
99
+ * Lightweight slice of credit-account data containing only token
100
+ * balances and the enabled-tokens bitmask.
101
+ **/
102
+ export type CreditAccountTokensSlice = Pick<CreditAccountData, "creditManager" | "creditAccount" | "tokens" | "enabledTokensMask">;
103
+ /**
104
+ * Result of closing or liquidating a credit account, including the router's optimal close path.
105
+ **/
40
106
  export interface CloseCreditAccountResult extends CreditAccountOperationResult {
107
+ /**
108
+ * Router result describing the swap path used to convert account tokens into the underlying.
109
+ **/
41
110
  routerCloseResult: RouterCloseResult;
42
111
  }
112
+ /**
113
+ * Result of a full liquidation, extending the close result with optional loss policy data.
114
+ **/
43
115
  export interface FullyLiquidateResult extends CloseCreditAccountResult {
116
+ /**
117
+ * Encoded loss policy data submitted with the liquidation, if a loss policy was applied.
118
+ **/
44
119
  lossPolicyData?: Hex;
45
120
  }
121
+ /**
122
+ * Result of a credit account operation, containing everything needed to execute the transaction.
123
+ **/
46
124
  export interface CreditAccountOperationResult {
125
+ /**
126
+ * Raw transaction data ready to be signed and submitted.
127
+ **/
47
128
  tx: RawTx;
129
+ /**
130
+ * Ordered multicall entries that make up the operation.
131
+ **/
48
132
  calls: Array<MultiCall>;
133
+ /**
134
+ * Credit facade contract used for the operation.
135
+ **/
49
136
  creditFacade: CreditSuite["creditFacade"];
50
137
  }
138
+ /**
139
+ * Lightweight operation result without a raw transaction, containing only multicall data.
140
+ **/
51
141
  export interface CreditManagerOperationResult {
142
+ /**
143
+ * Ordered multicall entries that make up the operation.
144
+ **/
52
145
  calls: Array<MultiCall>;
146
+ /**
147
+ * Credit facade contract used for the operation.
148
+ **/
53
149
  creditFacade: CreditSuite["creditFacade"];
54
150
  }
151
+ /**
152
+ * Close operation type: `"close"` fully closes the account, `"zeroDebt"` repays all debt but keeps the account open.
153
+ **/
55
154
  export type CloseOptions = "close" | "zeroDebt";
56
155
  export interface CloseCreditAccountProps {
57
156
  /**
@@ -90,10 +189,10 @@ export interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountP
90
189
  }
91
190
  export interface RepayAndLiquidateCreditAccountProps {
92
191
  /**
93
- * tokens to repay dept.
94
- In the current implementation, this is the (debt+interest+fess) * buffer,
95
- where buffer refers to amount of tokens which will exceed current debt
96
- in order to cover possible debt increase over tx execution
192
+ * Tokens to repay debt.
193
+ * In the current implementation, this is the (debt+interest+fees) * buffer,
194
+ * where buffer refers to amount of tokens which will exceed current debt
195
+ * in order to cover possible debt increase over tx execution.
97
196
  */
98
197
  collateralAssets: Array<Asset>;
99
198
  /**
@@ -103,7 +202,7 @@ export interface RepayAndLiquidateCreditAccountProps {
103
202
  */
104
203
  assetsToWithdraw: Array<Asset>;
105
204
  /**
106
- * minimal credit account data on which operation is performed on which operation is performed
205
+ * Minimal credit account data on which operation is performed.
107
206
  */
108
207
  creditAccount: RouterCASlice;
109
208
  /**
@@ -111,7 +210,7 @@ export interface RepayAndLiquidateCreditAccountProps {
111
210
  */
112
211
  to: Address;
113
212
  /**
114
- * permits of tokens to withdraw (in any permittable token is present)
213
+ * Permits of tokens to withdraw (if any permittable token is present).
115
214
  */
116
215
  permits: Record<string, PermitResult>;
117
216
  tokensToClaim: Asset[];
@@ -164,8 +263,17 @@ export interface WithdrawCollateralProps extends PrepareUpdateQuotasProps {
164
263
  */
165
264
  creditAccount: RouterCASlice;
166
265
  }
266
+ /**
267
+ * Credit account and credit manager address pair, used for batch queries such as connected bot lookups.
268
+ **/
167
269
  export type AccountToCheck = {
270
+ /**
271
+ * Address of the credit account.
272
+ **/
168
273
  creditAccount: Address;
274
+ /**
275
+ * Address of the credit manager that manages this account.
276
+ **/
169
277
  creditManager: Address;
170
278
  };
171
279
  export interface ExecuteSwapProps extends PrepareUpdateQuotasProps {
@@ -199,12 +307,30 @@ export interface GetPendingWithdrawalsProps {
199
307
  creditAccount: Address;
200
308
  }
201
309
  type WithdrawalCompressorV310InstanceType = GetContractReturnType<typeof iWithdrawalCompressorV310Abi, PublicClient>;
310
+ /**
311
+ * Result of previewing a delayed withdrawal request, as returned by the withdrawal compressor.
312
+ **/
202
313
  export type PreviewDelayedWithdrawalResult = Awaited<ReturnType<WithdrawalCompressorV310InstanceType["read"]["getWithdrawalRequestResult"]>>;
203
314
  type PendingWithdrawalResult = Awaited<ReturnType<WithdrawalCompressorV310InstanceType["read"]["getCurrentWithdrawals"]>>;
315
+ /**
316
+ * A single pending delayed withdrawal that is not yet claimable.
317
+ **/
204
318
  export type PendingWithdrawal = PendingWithdrawalResult[1][number];
319
+ /**
320
+ * A single delayed withdrawal that is ready to be claimed.
321
+ **/
205
322
  export type ClaimableWithdrawal = PendingWithdrawalResult[0][number];
323
+ /**
324
+ * Aggregated delayed withdrawal status, split into immediately claimable and still-pending entries.
325
+ **/
206
326
  export interface GetPendingWithdrawalsResult {
327
+ /**
328
+ * Withdrawals that have matured and can be claimed now.
329
+ **/
207
330
  claimableNow: Array<ClaimableWithdrawal>;
331
+ /**
332
+ * Withdrawals that are still in their delay period.
333
+ **/
208
334
  pending: Array<PendingWithdrawal>;
209
335
  }
210
336
  export interface StartDelayedWithdrawalProps extends PrepareUpdateQuotasProps {
@@ -330,25 +456,70 @@ export interface FullyLiquidateProps {
330
456
  */
331
457
  applyLossPolicy?: boolean;
332
458
  /**
333
- * Debt only mode - will try to sell just enought of most valuable token to cover debt
459
+ * Debt only mode will try to sell just enough of the most valuable token to cover debt.
334
460
  */
335
461
  debtOnly?: boolean;
336
462
  }
463
+ /**
464
+ * EIP-2612 permit signature data for a token, enabling gasless approval for credit account operations.
465
+ **/
337
466
  export interface PermitResult {
467
+ /**
468
+ * ECDSA signature `r` component.
469
+ **/
338
470
  r: Address;
471
+ /**
472
+ * ECDSA signature `s` component.
473
+ **/
339
474
  s: Address;
475
+ /**
476
+ * ECDSA signature `v` component.
477
+ **/
340
478
  v: number;
479
+ /**
480
+ * Token address the permit is for.
481
+ **/
341
482
  token: Address;
483
+ /**
484
+ * Address of the token holder granting the permit.
485
+ **/
342
486
  owner: Address;
487
+ /**
488
+ * Address authorized to spend the tokens.
489
+ **/
343
490
  spender: Address;
491
+ /**
492
+ * Amount of tokens approved.
493
+ **/
344
494
  value: bigint;
495
+ /**
496
+ * Timestamp after which the permit expires.
497
+ **/
345
498
  deadline: bigint;
499
+ /**
500
+ * Owner's current permit nonce.
501
+ **/
346
502
  nonce: bigint;
347
503
  }
504
+ /**
505
+ * Claimable reward tokens associated with a single staking adapter and phantom token pair.
506
+ **/
348
507
  export interface Rewards {
508
+ /**
509
+ * Address of the reward pool adapter on the credit account.
510
+ **/
349
511
  adapter: Address;
512
+ /**
513
+ * Address of the staked phantom token representing the staking position.
514
+ **/
350
515
  stakedPhantomToken: Address;
516
+ /**
517
+ * Multicall entries to claim these rewards.
518
+ **/
351
519
  calls: Array<MultiCall>;
520
+ /**
521
+ * List of reward token amounts claimable from this adapter.
522
+ **/
352
523
  rewards: Array<Asset>;
353
524
  }
354
525
  interface CMSlice {
@@ -374,6 +545,9 @@ export interface SetBotProps {
374
545
  type: "creditAccount";
375
546
  }) | CMSlice;
376
547
  }
548
+ /**
549
+ * Multicall result of querying connected bots across multiple credit accounts.
550
+ **/
377
551
  export type GetConnectedBotsResult = Array<{
378
552
  error?: undefined;
379
553
  result: readonly ConnectedBotData[];
@@ -383,6 +557,9 @@ export type GetConnectedBotsResult = Array<{
383
557
  result?: undefined;
384
558
  status: "failure";
385
559
  }>;
560
+ /**
561
+ * Result of querying a migration bot's status across credit accounts, or `undefined` if no migration bot was provided.
562
+ **/
386
563
  export type GetConnectedMigrationBotsResult = {
387
564
  result: ({
388
565
  error: Error;
@@ -395,17 +572,26 @@ export type GetConnectedMigrationBotsResult = {
395
572
  })[];
396
573
  botAddress: Address;
397
574
  } | undefined;
575
+ /**
576
+ * Input for previewing a proportional Llamathena withdrawal.
577
+ **/
398
578
  export interface PreviewWithdrawLlamathenaProportionallyProps {
579
+ /**
580
+ * Llamathena token and amount to withdraw.
581
+ **/
399
582
  llamathena: Asset;
400
583
  }
584
+ /**
585
+ * Result of a proportional Llamathena withdrawal preview.
586
+ **/
401
587
  export interface PreviewWithdrawLlamathenaProportionallyResult {
402
588
  /**
403
- * Assets to get
404
- */
589
+ * Underlying assets received from the withdrawal.
590
+ **/
405
591
  assets: [Asset];
406
592
  /**
407
- * Llamathena asset
408
- */
593
+ * Staked Llamathena token consumed.
594
+ **/
409
595
  stkLlamathena: [Asset];
410
596
  }
411
597
  export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotasProps {
@@ -414,7 +600,7 @@ export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotas
414
600
  */
415
601
  preview: PreviewWithdrawLlamathenaProportionallyResult;
416
602
  /**
417
- * minimal credit account data on which operation is performed on which operation is performed
603
+ * Minimal credit account data on which operation is performed.
418
604
  */
419
605
  creditAccount: RouterCASlice;
420
606
  }
@@ -438,8 +624,8 @@ export interface ICreditAccountsService extends Construct {
438
624
  */
439
625
  getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
440
626
  /**
441
- * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
442
- * Assosiates rewards by adapter + stakedPhantomToken
627
+ * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards).
628
+ * Associates rewards by adapter + stakedPhantomToken.
443
629
  * @param {Address} creditAccount - address of credit account to get rewards for
444
630
  * @returns {Array<Rewards>} list of {@link Rewards} that can be claimed
445
631
  */
@@ -471,7 +657,7 @@ export interface ICreditAccountsService extends Construct {
471
657
  /**
472
658
  * Closes credit account or closes credit account and keeps it open with zero debt.
473
659
  * - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
474
- * -> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens tokens -> withdraw underlying tokenz
660
+ * -> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens -> withdraw underlying tokens
475
661
  * @param props - {@link CloseCreditAccountProps}
476
662
  * @returns All necessary data to execute the transaction (call, credit facade)
477
663
  */
@@ -554,26 +740,37 @@ export interface ICreditAccountsService extends Construct {
554
740
  * @param ca
555
741
  */
556
742
  getOptimalHFForPartialLiquidation(ca: CreditAccountData): bigint;
557
- /**
558
- * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
559
- *
560
- * This can be used by batch liquidator
561
- * @param accounts
562
- * @returns
563
- */
564
- getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
565
743
  /**
566
744
  * Returns account price updates that can be used in credit facade multicall or liquidator calls
567
- * @param options
568
- * @returns
745
+ * @param account - Credit account to get price updates for
746
+ * @param ignoreReservePrices - If true, exclude reserve price feed updates
747
+ * @returns Array of price updates
569
748
  */
570
- getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<OnDemandPriceUpdates>;
749
+ getOnDemandPriceUpdates(account: CreditAccountTokensSlice, ignoreReservePrices?: boolean): Promise<PriceUpdate[]>;
571
750
  /**
572
- * Returns price updates in format that is accepted by various credit facade methods (multicall, close/liquidate, etc...).
573
- * @param options
574
- * @returns
751
+ * Executes a multicall on a credit account, automatically prepending
752
+ * necessary on-demand price feed updates inferred from the calls array.
753
+ *
754
+ * @param creditAccount - Credit account to execute multicall on
755
+ * @param calls - Array of multicall operations (price updates will be inferred)
756
+ * @param options - Optional settings for price update generation
757
+ * @returns Raw transaction ready to be signed and sent
575
758
  */
576
- getPriceUpdatesForFacade(options: PriceUpdatesOptions): Promise<Array<MultiCall>>;
759
+ multicall(creditAccount: RouterCASlice, calls: Array<MultiCall>, options?: {
760
+ ignoreReservePrices?: boolean;
761
+ }): Promise<RawTx>;
762
+ /**
763
+ * Executes a bot multicall on a credit account, automatically prepending
764
+ * necessary on-demand price feed updates inferred from the calls array.
765
+ *
766
+ * @param creditAccount - Credit account to execute bot multicall on
767
+ * @param calls - Array of multicall operations (price updates will be inferred)
768
+ * @param options - Optional settings for price update generation
769
+ * @returns Raw transaction ready to be signed and sent
770
+ */
771
+ botMulticall(creditAccount: RouterCASlice, calls: Array<MultiCall>, options?: {
772
+ ignoreReservePrices?: boolean;
773
+ }): Promise<RawTx>;
577
774
  /**
578
775
  * Withdraws a single collateral from credit account to wallet to and updates quotas;
579
776
  * technically can withdraw several tokens at once
@@ -3,37 +3,99 @@ import { BaseError } from "viem";
3
3
  import type { BaseContractStateHuman, RawTx } from "../types/index.js";
4
4
  import { Construct, type ConstructOptions } from "./Construct.js";
5
5
  import type { IBaseContract, ParsedCall, ParsedCallArgs, ParsedCallV2 } from "./types.js";
6
+ /**
7
+ * Arguments for constructing a {@link BaseContract}.
8
+ **/
6
9
  export interface BaseContractArgs<abi extends Abi | readonly unknown[]> {
10
+ /**
11
+ * Contract ABI used for encoding/decoding.
12
+ **/
7
13
  abi: abi;
14
+ /**
15
+ * On-chain address of the contract.
16
+ **/
8
17
  addr: Address;
18
+ /**
19
+ * Optional display name for the contract.
20
+ **/
9
21
  name?: string;
22
+ /**
23
+ * Contract version
24
+ * @default 0
25
+ **/
10
26
  version?: number | bigint;
27
+ /**
28
+ * Gearbox contract type identifier (hex bytes32 or parsed string).
29
+ **/
11
30
  contractType?: string;
12
31
  }
32
+ /**
33
+ * Options supplied to the {@link ContractParseError} constructor.
34
+ **/
13
35
  export interface ContractParseErrorOptions {
36
+ /**
37
+ * Address of the contract where parsing failed.
38
+ **/
14
39
  address: Address;
40
+ /**
41
+ * Raw calldata that could not be decoded.
42
+ **/
15
43
  callData: Hex;
44
+ /**
45
+ * Optional display name for the contract.
46
+ **/
16
47
  contractName?: string;
17
48
  }
49
+ /**
50
+ * Error thrown when calldata cannot be decoded against a contract's ABI.
51
+ * Captures the target address and raw calldata for diagnostics.
52
+ */
18
53
  export declare class ContractParseError extends BaseError {
19
54
  readonly address: Address;
20
55
  readonly callData: Hex;
21
56
  readonly selector: Hex;
22
57
  constructor(cause: Error, options: ContractParseErrorOptions);
23
58
  }
59
+ /**
60
+ * Wrapper around a single on-chain contract, providing calldata decoding,
61
+ * event fetching, and human-readable state output.
62
+ *
63
+ * @typeParam abi - Narrowed ABI type for this contract.
64
+ **/
24
65
  export declare class BaseContract<abi extends Abi | readonly unknown[]> extends Construct implements IBaseContract {
66
+ /**
67
+ * Viem contract instance for direct read calls
68
+ **/
25
69
  readonly contract: GetContractReturnType<abi, PublicClient<Transport, Chain>, Address>;
70
+ /**
71
+ * Contract ABI
72
+ **/
26
73
  readonly abi: abi;
74
+ /**
75
+ * Gearbox contract type identifier (e.g. `"CREDIT_MANAGER"`), or empty string if unknown.
76
+ **/
27
77
  readonly contractType: string;
78
+ /**
79
+ * Contract version number.
80
+ * @default 0
81
+ **/
28
82
  readonly version: number;
83
+ /**
84
+ * On-chain address of the contract.
85
+ **/
29
86
  readonly address: Address;
87
+ /**
88
+ * Display name for the contract.
89
+ **/
30
90
  readonly name: string;
31
91
  constructor(options: ConstructOptions, args: BaseContractArgs<abi>);
92
+ /** {@inheritDoc IBaseContract.stateHuman} */
32
93
  stateHuman(_?: boolean): BaseContractStateHuman;
33
94
  /**
34
- * Updates (or not) contract's internal state from event
35
- * @param _log
36
- */
95
+ * Applies an on-chain event to update this contract's local state.
96
+ *
97
+ * @param _log - Decoded event log emitted by this contract.
98
+ **/
37
99
  processLog(_log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
38
100
  /**
39
101
  * Return parsed args and function name from calldata belonging to this contract
@@ -64,9 +126,8 @@ export declare class BaseContract<abi extends Abi | readonly unknown[]> extends
64
126
  */
65
127
  stringifyFunctionData(calldata: Hex): string;
66
128
  /**
67
- * Same as {@link stingifyFunctionData}, but throws if error occurs
68
- * @param calldata
69
- * @returns
129
+ * Same as {@link stringifyFunctionData}, but throws if error occurs.
130
+ * @param calldata - Raw ABI-encoded calldata.
70
131
  */
71
132
  mustStringifyFunctionData(calldata: Hex): string;
72
133
  /**
@@ -4,24 +4,73 @@ import type { ILogger } from "../types/logger.js";
4
4
  import type { BaseContract } from "./BaseContract.js";
5
5
  import { TokensMeta } from "./TokensMeta.js";
6
6
  import type { ParsedCall, ParsedCallV2 } from "./types.js";
7
+ /**
8
+ * @internal
9
+ * Conditional type that resolves to `BaseContract<T>` when `T` is an ABI type,
10
+ * or returns `T` unchanged otherwise. Used by register lookup methods to
11
+ * provide strongly-typed contract references.
12
+ */
7
13
  export type ContractOrInterface<T> = T extends Abi | readonly unknown[] ? BaseContract<T> : T;
14
+ /**
15
+ * Central registry of all known contracts on a single chain.
16
+ *
17
+ * Used to share information between contracts, enables instances of {@link BaseContract} to discover each other
18
+ * This is critical for parsing of calls that involve multiple contracts
19
+ */
8
20
  export declare class ChainContractsRegister {
9
21
  private readonly contracts;
10
22
  private readonly labels;
11
23
  readonly client: PublicClient<Transport, Chain>;
12
24
  /**
13
- * Token metadata such as symbol and decimals
14
- */
25
+ * Shared token metadata (symbol, decimals) for all tokens known on this chain.
26
+ **/
15
27
  readonly tokensMeta: TokensMeta;
16
28
  readonly logger?: ILogger;
17
29
  constructor(client: PublicClient<Transport, Chain>, logger?: ILogger);
30
+ /**
31
+ * Clears all registered contracts, address labels, and token metadata.
32
+ **/
18
33
  resetContracts(): void;
34
+ /**
35
+ * Looks up a contract by address.
36
+ * @param address - On-chain address.
37
+ * @returns The contract wrapper, or `undefined` if not registered.
38
+ */
19
39
  getContract<T = unknown[]>(address: Address): ContractOrInterface<T> | undefined;
40
+ /**
41
+ * Looks up a contract by address, throwing if not found.
42
+ * @param address - On-chain address.
43
+ * @throws If no contract is registered at this address.
44
+ */
20
45
  mustGetContract<T = unknown[]>(address: Address): ContractOrInterface<T>;
46
+ /**
47
+ * Registers (or replaces) a contract at the given address.
48
+ * @param address - On-chain address.
49
+ * @param contract - Contract wrapper instance.
50
+ */
21
51
  setContract(address: Address, contract: BaseContract<any>): void;
52
+ /**
53
+ * Assigns a human-readable label to an address for use in logging and
54
+ * parsed call output.
55
+ * @param address - On-chain address.
56
+ * @param label - Static label string, or a function that receives the
57
+ * current label and returns a new one.
58
+ */
22
59
  setAddressLabel(address: Address, label: string | ((oldLabel?: string) => string)): void;
60
+ /**
61
+ * Returns a display string for an address, incorporating its label if one exists.
62
+ * @param address - On-chain address.
63
+ * @param omitAddress - When `true`, returns only the label (no address prefix).
64
+ * Falls back to the raw address when no label is set.
65
+ */
23
66
  labelAddress(address: Address, omitAddress?: boolean): string;
67
+ /**
68
+ * The viem {@link Chain} object for this register's connected client.
69
+ **/
24
70
  get chain(): Chain;
71
+ /**
72
+ * Numeric chain ID (e.g. `1` for Ethereum mainnet).
73
+ **/
25
74
  get chainId(): number;
26
75
  /**
27
76
  * Converts contract call into some human-friendly string