@gearbox-protocol/sdk 13.3.3 → 13.3.5

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 (80) hide show
  1. package/dist/cjs/sdk/GearboxSDK.js +135 -20
  2. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +78 -157
  3. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +5 -5
  4. package/dist/cjs/sdk/base/BaseContract.js +26 -6
  5. package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
  6. package/dist/cjs/sdk/base/Construct.js +15 -3
  7. package/dist/cjs/sdk/base/TokensMeta.js +23 -0
  8. package/dist/cjs/sdk/constants/address-provider.js +0 -22
  9. package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
  10. package/dist/cjs/sdk/market/MarketRegister.js +74 -3
  11. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  12. package/dist/cjs/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  13. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  14. package/dist/cjs/sdk/options.js +30 -24
  15. package/dist/cjs/sdk/plugins/BasePlugin.js +24 -0
  16. package/dist/cjs/sdk/pools/AbstractPoolService.js +6 -0
  17. package/dist/cjs/sdk/router/AbstractRouterContract.js +4 -1
  18. package/dist/cjs/sdk/router/RouterV310Contract.js +20 -15
  19. package/dist/cjs/sdk/utils/AddressMap.js +53 -17
  20. package/dist/cjs/sdk/utils/AddressSet.js +9 -0
  21. package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
  22. package/dist/esm/sdk/GearboxSDK.js +135 -20
  23. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +78 -157
  24. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +5 -5
  25. package/dist/esm/sdk/base/BaseContract.js +26 -6
  26. package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
  27. package/dist/esm/sdk/base/Construct.js +15 -3
  28. package/dist/esm/sdk/base/TokensMeta.js +23 -0
  29. package/dist/esm/sdk/constants/address-provider.js +0 -21
  30. package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
  31. package/dist/esm/sdk/market/MarketRegister.js +74 -3
  32. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  33. package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  34. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  35. package/dist/esm/sdk/options.js +30 -24
  36. package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
  37. package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
  38. package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
  39. package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
  40. package/dist/esm/sdk/utils/AddressMap.js +53 -17
  41. package/dist/esm/sdk/utils/AddressSet.js +9 -0
  42. package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
  43. package/dist/types/sdk/GearboxSDK.d.ts +236 -34
  44. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +56 -142
  45. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
  46. package/dist/types/sdk/accounts/types.d.ts +230 -18
  47. package/dist/types/sdk/base/BaseContract.d.ts +67 -6
  48. package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
  49. package/dist/types/sdk/base/Construct.d.ts +31 -0
  50. package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
  51. package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
  52. package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
  53. package/dist/types/sdk/base/types.d.ts +185 -25
  54. package/dist/types/sdk/chain/chains.d.ts +78 -18
  55. package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
  56. package/dist/types/sdk/constants/address-provider.d.ts +4 -3
  57. package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
  58. package/dist/types/sdk/core/types.d.ts +46 -0
  59. package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
  60. package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
  61. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
  62. package/dist/types/sdk/market/oracle/types.d.ts +76 -57
  63. package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -0
  64. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +3 -0
  65. package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +22 -2
  66. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +77 -13
  67. package/dist/types/sdk/market/pricefeeds/types.d.ts +70 -10
  68. package/dist/types/sdk/options.d.ts +13 -4
  69. package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
  70. package/dist/types/sdk/plugins/types.d.ts +73 -43
  71. package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
  72. package/dist/types/sdk/pools/types.d.ts +75 -6
  73. package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
  74. package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
  75. package/dist/types/sdk/router/types.d.ts +51 -69
  76. package/dist/types/sdk/types/state.d.ts +32 -3
  77. package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
  78. package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
  79. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
  80. package/package.json +4 -2
@@ -6,52 +6,167 @@ import type { GearboxSDK } from "../GearboxSDK.js";
6
6
  import type { CreditSuite, OnDemandPriceUpdates, UpdatePriceFeedsResult } from "../market/index.js";
7
7
  import type { Asset, CreditAccountTokensSlice, 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
- */
94
+ * If true, exclude reserve price feed updates from the query.
95
+ **/
32
96
  ignoreReservePrices?: boolean;
33
97
  }
98
+ /**
99
+ * Options for generating on-demand price feed updates scoped to a specific credit manager.
100
+ **/
34
101
  export interface PriceUpdatesOptions {
102
+ /**
103
+ * Credit manager whose collateral tokens determine which price feeds to update.
104
+ **/
35
105
  creditManager: Address;
106
+ /**
107
+ * Credit account token balances; when provided, only tokens with non-dust enabled balances are updated.
108
+ **/
36
109
  creditAccount?: CreditAccountTokensSlice;
110
+ /**
111
+ * Tokens for which quota is being bought; their price feeds are updated even if the account has no balance yet.
112
+ **/
37
113
  desiredQuotas?: Asset[];
114
+ /**
115
+ * If true, exclude reserve price feed updates.
116
+ **/
38
117
  ignoreReservePrices?: boolean;
39
118
  }
119
+ /**
120
+ * Result of closing or liquidating a credit account, including the router's optimal close path.
121
+ **/
40
122
  export interface CloseCreditAccountResult extends CreditAccountOperationResult {
123
+ /**
124
+ * Router result describing the swap path used to convert account tokens into the underlying.
125
+ **/
41
126
  routerCloseResult: RouterCloseResult;
42
127
  }
128
+ /**
129
+ * Result of a full liquidation, extending the close result with optional loss policy data.
130
+ **/
43
131
  export interface FullyLiquidateResult extends CloseCreditAccountResult {
132
+ /**
133
+ * Encoded loss policy data submitted with the liquidation, if a loss policy was applied.
134
+ **/
44
135
  lossPolicyData?: Hex;
45
136
  }
137
+ /**
138
+ * Result of a credit account operation, containing everything needed to execute the transaction.
139
+ **/
46
140
  export interface CreditAccountOperationResult {
141
+ /**
142
+ * Raw transaction data ready to be signed and submitted.
143
+ **/
47
144
  tx: RawTx;
145
+ /**
146
+ * Ordered multicall entries that make up the operation.
147
+ **/
48
148
  calls: Array<MultiCall>;
149
+ /**
150
+ * Credit facade contract used for the operation.
151
+ **/
49
152
  creditFacade: CreditSuite["creditFacade"];
50
153
  }
154
+ /**
155
+ * Lightweight operation result without a raw transaction, containing only multicall data.
156
+ **/
51
157
  export interface CreditManagerOperationResult {
158
+ /**
159
+ * Ordered multicall entries that make up the operation.
160
+ **/
52
161
  calls: Array<MultiCall>;
162
+ /**
163
+ * Credit facade contract used for the operation.
164
+ **/
53
165
  creditFacade: CreditSuite["creditFacade"];
54
166
  }
167
+ /**
168
+ * Close operation type: `"close"` fully closes the account, `"zeroDebt"` repays all debt but keeps the account open.
169
+ **/
55
170
  export type CloseOptions = "close" | "zeroDebt";
56
171
  export interface CloseCreditAccountProps {
57
172
  /**
@@ -90,10 +205,10 @@ export interface RepayCreditAccountProps extends RepayAndLiquidateCreditAccountP
90
205
  }
91
206
  export interface RepayAndLiquidateCreditAccountProps {
92
207
  /**
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
208
+ * Tokens to repay debt.
209
+ * In the current implementation, this is the (debt+interest+fees) * buffer,
210
+ * where buffer refers to amount of tokens which will exceed current debt
211
+ * in order to cover possible debt increase over tx execution.
97
212
  */
98
213
  collateralAssets: Array<Asset>;
99
214
  /**
@@ -103,7 +218,7 @@ export interface RepayAndLiquidateCreditAccountProps {
103
218
  */
104
219
  assetsToWithdraw: Array<Asset>;
105
220
  /**
106
- * minimal credit account data on which operation is performed on which operation is performed
221
+ * Minimal credit account data on which operation is performed.
107
222
  */
108
223
  creditAccount: RouterCASlice;
109
224
  /**
@@ -111,7 +226,7 @@ export interface RepayAndLiquidateCreditAccountProps {
111
226
  */
112
227
  to: Address;
113
228
  /**
114
- * permits of tokens to withdraw (in any permittable token is present)
229
+ * Permits of tokens to withdraw (if any permittable token is present).
115
230
  */
116
231
  permits: Record<string, PermitResult>;
117
232
  tokensToClaim: Asset[];
@@ -164,8 +279,17 @@ export interface WithdrawCollateralProps extends PrepareUpdateQuotasProps {
164
279
  */
165
280
  creditAccount: RouterCASlice;
166
281
  }
282
+ /**
283
+ * Credit account and credit manager address pair, used for batch queries such as connected bot lookups.
284
+ **/
167
285
  export type AccountToCheck = {
286
+ /**
287
+ * Address of the credit account.
288
+ **/
168
289
  creditAccount: Address;
290
+ /**
291
+ * Address of the credit manager that manages this account.
292
+ **/
169
293
  creditManager: Address;
170
294
  };
171
295
  export interface ExecuteSwapProps extends PrepareUpdateQuotasProps {
@@ -199,12 +323,30 @@ export interface GetPendingWithdrawalsProps {
199
323
  creditAccount: Address;
200
324
  }
201
325
  type WithdrawalCompressorV310InstanceType = GetContractReturnType<typeof iWithdrawalCompressorV310Abi, PublicClient>;
326
+ /**
327
+ * Result of previewing a delayed withdrawal request, as returned by the withdrawal compressor.
328
+ **/
202
329
  export type PreviewDelayedWithdrawalResult = Awaited<ReturnType<WithdrawalCompressorV310InstanceType["read"]["getWithdrawalRequestResult"]>>;
203
330
  type PendingWithdrawalResult = Awaited<ReturnType<WithdrawalCompressorV310InstanceType["read"]["getCurrentWithdrawals"]>>;
331
+ /**
332
+ * A single pending delayed withdrawal that is not yet claimable.
333
+ **/
204
334
  export type PendingWithdrawal = PendingWithdrawalResult[1][number];
335
+ /**
336
+ * A single delayed withdrawal that is ready to be claimed.
337
+ **/
205
338
  export type ClaimableWithdrawal = PendingWithdrawalResult[0][number];
339
+ /**
340
+ * Aggregated delayed withdrawal status, split into immediately claimable and still-pending entries.
341
+ **/
206
342
  export interface GetPendingWithdrawalsResult {
343
+ /**
344
+ * Withdrawals that have matured and can be claimed now.
345
+ **/
207
346
  claimableNow: Array<ClaimableWithdrawal>;
347
+ /**
348
+ * Withdrawals that are still in their delay period.
349
+ **/
208
350
  pending: Array<PendingWithdrawal>;
209
351
  }
210
352
  export interface StartDelayedWithdrawalProps extends PrepareUpdateQuotasProps {
@@ -263,8 +405,9 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
263
405
  /**
264
406
  * Flag to withdraw debt to wallet after opening credit account;
265
407
  * used for borrowing functionality
408
+ * If true, will withdraw underlying token, otherwise will withdraw specified token
266
409
  */
267
- withdrawDebt?: boolean;
410
+ withdrawToken?: boolean | Address;
268
411
  /**
269
412
  * Permits of collateral tokens (in any permittable token is present) {@link PermitResult}
270
413
  */
@@ -274,10 +417,19 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
274
417
  * Used for trading and strategy functionality
275
418
  */
276
419
  calls: Array<MultiCall>;
420
+ /**
421
+ * Slot for optional call to execute after main tx.
422
+ * For example: add bots
423
+ */
424
+ callsAfter?: Array<MultiCall>;
277
425
  /**
278
426
  * Address of credit manager to open credit account on
279
427
  */
280
428
  creditManager: Address;
429
+ /**
430
+ * Optional address of credit account to reopen
431
+ */
432
+ reopenCreditAccount?: Address;
281
433
  /**
282
434
  * Wallet address to transfer credit account to
283
435
  */
@@ -330,25 +482,70 @@ export interface FullyLiquidateProps {
330
482
  */
331
483
  applyLossPolicy?: boolean;
332
484
  /**
333
- * Debt only mode - will try to sell just enought of most valuable token to cover debt
485
+ * Debt only mode will try to sell just enough of the most valuable token to cover debt.
334
486
  */
335
487
  debtOnly?: boolean;
336
488
  }
489
+ /**
490
+ * EIP-2612 permit signature data for a token, enabling gasless approval for credit account operations.
491
+ **/
337
492
  export interface PermitResult {
493
+ /**
494
+ * ECDSA signature `r` component.
495
+ **/
338
496
  r: Address;
497
+ /**
498
+ * ECDSA signature `s` component.
499
+ **/
339
500
  s: Address;
501
+ /**
502
+ * ECDSA signature `v` component.
503
+ **/
340
504
  v: number;
505
+ /**
506
+ * Token address the permit is for.
507
+ **/
341
508
  token: Address;
509
+ /**
510
+ * Address of the token holder granting the permit.
511
+ **/
342
512
  owner: Address;
513
+ /**
514
+ * Address authorized to spend the tokens.
515
+ **/
343
516
  spender: Address;
517
+ /**
518
+ * Amount of tokens approved.
519
+ **/
344
520
  value: bigint;
521
+ /**
522
+ * Timestamp after which the permit expires.
523
+ **/
345
524
  deadline: bigint;
525
+ /**
526
+ * Owner's current permit nonce.
527
+ **/
346
528
  nonce: bigint;
347
529
  }
530
+ /**
531
+ * Claimable reward tokens associated with a single staking adapter and phantom token pair.
532
+ **/
348
533
  export interface Rewards {
534
+ /**
535
+ * Address of the reward pool adapter on the credit account.
536
+ **/
349
537
  adapter: Address;
538
+ /**
539
+ * Address of the staked phantom token representing the staking position.
540
+ **/
350
541
  stakedPhantomToken: Address;
542
+ /**
543
+ * Multicall entries to claim these rewards.
544
+ **/
351
545
  calls: Array<MultiCall>;
546
+ /**
547
+ * List of reward token amounts claimable from this adapter.
548
+ **/
352
549
  rewards: Array<Asset>;
353
550
  }
354
551
  interface CMSlice {
@@ -374,6 +571,9 @@ export interface SetBotProps {
374
571
  type: "creditAccount";
375
572
  }) | CMSlice;
376
573
  }
574
+ /**
575
+ * Multicall result of querying connected bots across multiple credit accounts.
576
+ **/
377
577
  export type GetConnectedBotsResult = Array<{
378
578
  error?: undefined;
379
579
  result: readonly ConnectedBotData[];
@@ -383,6 +583,9 @@ export type GetConnectedBotsResult = Array<{
383
583
  result?: undefined;
384
584
  status: "failure";
385
585
  }>;
586
+ /**
587
+ * Result of querying a migration bot's status across credit accounts, or `undefined` if no migration bot was provided.
588
+ **/
386
589
  export type GetConnectedMigrationBotsResult = {
387
590
  result: ({
388
591
  error: Error;
@@ -395,17 +598,26 @@ export type GetConnectedMigrationBotsResult = {
395
598
  })[];
396
599
  botAddress: Address;
397
600
  } | undefined;
601
+ /**
602
+ * Input for previewing a proportional Llamathena withdrawal.
603
+ **/
398
604
  export interface PreviewWithdrawLlamathenaProportionallyProps {
605
+ /**
606
+ * Llamathena token and amount to withdraw.
607
+ **/
399
608
  llamathena: Asset;
400
609
  }
610
+ /**
611
+ * Result of a proportional Llamathena withdrawal preview.
612
+ **/
401
613
  export interface PreviewWithdrawLlamathenaProportionallyResult {
402
614
  /**
403
- * Assets to get
404
- */
615
+ * Underlying assets received from the withdrawal.
616
+ **/
405
617
  assets: [Asset];
406
618
  /**
407
- * Llamathena asset
408
- */
619
+ * Staked Llamathena token consumed.
620
+ **/
409
621
  stkLlamathena: [Asset];
410
622
  }
411
623
  export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotasProps {
@@ -414,7 +626,7 @@ export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotas
414
626
  */
415
627
  preview: PreviewWithdrawLlamathenaProportionallyResult;
416
628
  /**
417
- * minimal credit account data on which operation is performed on which operation is performed
629
+ * Minimal credit account data on which operation is performed.
418
630
  */
419
631
  creditAccount: RouterCASlice;
420
632
  }
@@ -438,8 +650,8 @@ export interface ICreditAccountsService extends Construct {
438
650
  */
439
651
  getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
440
652
  /**
441
- * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
442
- * Assosiates rewards by adapter + stakedPhantomToken
653
+ * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards).
654
+ * Associates rewards by adapter + stakedPhantomToken.
443
655
  * @param {Address} creditAccount - address of credit account to get rewards for
444
656
  * @returns {Array<Rewards>} list of {@link Rewards} that can be claimed
445
657
  */
@@ -471,7 +683,7 @@ export interface ICreditAccountsService extends Construct {
471
683
  /**
472
684
  * Closes credit account or closes credit account and keeps it open with zero debt.
473
685
  * - 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
686
+ * -> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens -> withdraw underlying tokens
475
687
  * @param props - {@link CloseCreditAccountProps}
476
688
  * @returns All necessary data to execute the transaction (call, credit facade)
477
689
  */
@@ -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
@@ -3,6 +3,15 @@ import type { NetworkType } from "../chain/index.js";
3
3
  import type { ILogger } from "../types/index.js";
4
4
  import { ChainContractsRegister } from "./ChainContractsRegister.js";
5
5
  import type { TokensMeta } from "./TokensMeta.js";
6
+ /**
7
+ * Options accepted by the {@link Construct} base class constructor.
8
+ *
9
+ * @param register - A {@link ChainContractsRegister} instance to use for cross-contract lookups.
10
+ * You may choose not to pass it if you plan to instantiate contracts manually and do not need any cross-contract lookups.
11
+ * @param client - A viem {@link PublicClient} instance to use for chain access.
12
+ * @param logger - An optional logger instance to use for logging
13
+ *
14
+ */
6
15
  export type ConstructOptions = ChainContractsRegister | {
7
16
  client: PublicClient<Transport, Chain>;
8
17
  logger?: ILogger;
@@ -10,6 +19,13 @@ export type ConstructOptions = ChainContractsRegister | {
10
19
  register: ChainContractsRegister;
11
20
  logger?: ILogger;
12
21
  };
22
+ /**
23
+ * Base class for all SDK objects that need chain access.
24
+ *
25
+ * Provides a viem {@link PublicClient}, optional structured logging, and an
26
+ * optional {@link ChainContractsRegister} for cross-contract lookups.
27
+ * Most SDK classes inherit from this (or from {@link SDKConstruct}).
28
+ */
13
29
  export declare class Construct {
14
30
  #private;
15
31
  readonly logger?: ILogger;
@@ -21,17 +37,32 @@ export declare class Construct {
21
37
  */
22
38
  get register(): ChainContractsRegister;
23
39
  protected safeGetRegister(): ChainContractsRegister | undefined;
40
+ /**
41
+ * The viem {@link Chain} object associated with the connected client.
42
+ **/
24
43
  get chain(): Chain;
44
+ /**
45
+ * Numeric chain ID (e.g. `1` for Ethereum mainnet).
46
+ **/
25
47
  get chainId(): number;
48
+ /**
49
+ * Gearbox network type for this chain (e.g. `"Mainnet"`, `"Arbitrum"`).
50
+ * @throws If the chain was not created by the Gearbox SDK.
51
+ */
26
52
  get networkType(): NetworkType;
27
53
  /**
54
+ * @internal
28
55
  * Indicates that contract state diverged from onchain state and needs to be updated
29
56
  */
30
57
  get dirty(): boolean;
31
58
  protected set dirty(value: boolean);
59
+ /**
60
+ * Information about tokens known on this chain
61
+ */
32
62
  protected get tokensMeta(): TokensMeta;
33
63
  protected labelAddress(address: Address, omitAddress?: boolean): string;
34
64
  /**
65
+ * @internal
35
66
  * Returns list of addresses that should be watched for events to sync state
36
67
  */
37
68
  get watchAddresses(): Set<Address>;
@@ -3,6 +3,9 @@ import { BaseContract } from "./BaseContract.js";
3
3
  import type { ConstructOptions } from "./index.js";
4
4
  declare const abi: unknown[];
5
5
  type abi = typeof abi;
6
+ /**
7
+ * @internal
8
+ */
6
9
  export declare class PlaceholderContract extends BaseContract<abi> {
7
10
  constructor(options: ConstructOptions, args: Omit<BaseContractArgs<abi>, "abi">);
8
11
  }