@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
@@ -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 {
@@ -330,25 +472,70 @@ export interface FullyLiquidateProps {
330
472
  */
331
473
  applyLossPolicy?: boolean;
332
474
  /**
333
- * Debt only mode - will try to sell just enought of most valuable token to cover debt
475
+ * Debt only mode will try to sell just enough of the most valuable token to cover debt.
334
476
  */
335
477
  debtOnly?: boolean;
336
478
  }
479
+ /**
480
+ * EIP-2612 permit signature data for a token, enabling gasless approval for credit account operations.
481
+ **/
337
482
  export interface PermitResult {
483
+ /**
484
+ * ECDSA signature `r` component.
485
+ **/
338
486
  r: Address;
487
+ /**
488
+ * ECDSA signature `s` component.
489
+ **/
339
490
  s: Address;
491
+ /**
492
+ * ECDSA signature `v` component.
493
+ **/
340
494
  v: number;
495
+ /**
496
+ * Token address the permit is for.
497
+ **/
341
498
  token: Address;
499
+ /**
500
+ * Address of the token holder granting the permit.
501
+ **/
342
502
  owner: Address;
503
+ /**
504
+ * Address authorized to spend the tokens.
505
+ **/
343
506
  spender: Address;
507
+ /**
508
+ * Amount of tokens approved.
509
+ **/
344
510
  value: bigint;
511
+ /**
512
+ * Timestamp after which the permit expires.
513
+ **/
345
514
  deadline: bigint;
515
+ /**
516
+ * Owner's current permit nonce.
517
+ **/
346
518
  nonce: bigint;
347
519
  }
520
+ /**
521
+ * Claimable reward tokens associated with a single staking adapter and phantom token pair.
522
+ **/
348
523
  export interface Rewards {
524
+ /**
525
+ * Address of the reward pool adapter on the credit account.
526
+ **/
349
527
  adapter: Address;
528
+ /**
529
+ * Address of the staked phantom token representing the staking position.
530
+ **/
350
531
  stakedPhantomToken: Address;
532
+ /**
533
+ * Multicall entries to claim these rewards.
534
+ **/
351
535
  calls: Array<MultiCall>;
536
+ /**
537
+ * List of reward token amounts claimable from this adapter.
538
+ **/
352
539
  rewards: Array<Asset>;
353
540
  }
354
541
  interface CMSlice {
@@ -374,6 +561,9 @@ export interface SetBotProps {
374
561
  type: "creditAccount";
375
562
  }) | CMSlice;
376
563
  }
564
+ /**
565
+ * Multicall result of querying connected bots across multiple credit accounts.
566
+ **/
377
567
  export type GetConnectedBotsResult = Array<{
378
568
  error?: undefined;
379
569
  result: readonly ConnectedBotData[];
@@ -383,6 +573,9 @@ export type GetConnectedBotsResult = Array<{
383
573
  result?: undefined;
384
574
  status: "failure";
385
575
  }>;
576
+ /**
577
+ * Result of querying a migration bot's status across credit accounts, or `undefined` if no migration bot was provided.
578
+ **/
386
579
  export type GetConnectedMigrationBotsResult = {
387
580
  result: ({
388
581
  error: Error;
@@ -395,17 +588,26 @@ export type GetConnectedMigrationBotsResult = {
395
588
  })[];
396
589
  botAddress: Address;
397
590
  } | undefined;
591
+ /**
592
+ * Input for previewing a proportional Llamathena withdrawal.
593
+ **/
398
594
  export interface PreviewWithdrawLlamathenaProportionallyProps {
595
+ /**
596
+ * Llamathena token and amount to withdraw.
597
+ **/
399
598
  llamathena: Asset;
400
599
  }
600
+ /**
601
+ * Result of a proportional Llamathena withdrawal preview.
602
+ **/
401
603
  export interface PreviewWithdrawLlamathenaProportionallyResult {
402
604
  /**
403
- * Assets to get
404
- */
605
+ * Underlying assets received from the withdrawal.
606
+ **/
405
607
  assets: [Asset];
406
608
  /**
407
- * Llamathena asset
408
- */
609
+ * Staked Llamathena token consumed.
610
+ **/
409
611
  stkLlamathena: [Asset];
410
612
  }
411
613
  export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotasProps {
@@ -414,7 +616,7 @@ export interface LlamathenaProportionalWithdrawProps extends PrepareUpdateQuotas
414
616
  */
415
617
  preview: PreviewWithdrawLlamathenaProportionallyResult;
416
618
  /**
417
- * minimal credit account data on which operation is performed on which operation is performed
619
+ * Minimal credit account data on which operation is performed.
418
620
  */
419
621
  creditAccount: RouterCASlice;
420
622
  }
@@ -438,8 +640,8 @@ export interface ICreditAccountsService extends Construct {
438
640
  */
439
641
  getCreditAccounts(options?: GetCreditAccountsOptions, blockNumber?: bigint): Promise<Array<CreditAccountData>>;
440
642
  /**
441
- * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards)
442
- * Assosiates rewards by adapter + stakedPhantomToken
643
+ * Method to get all claimable rewards for credit account (ex. stkUSDS SKY rewards).
644
+ * Associates rewards by adapter + stakedPhantomToken.
443
645
  * @param {Address} creditAccount - address of credit account to get rewards for
444
646
  * @returns {Array<Rewards>} list of {@link Rewards} that can be claimed
445
647
  */
@@ -471,7 +673,7 @@ export interface ICreditAccountsService extends Construct {
471
673
  /**
472
674
  * Closes credit account or closes credit account and keeps it open with zero debt.
473
675
  * - 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
676
+ * -> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens -> withdraw underlying tokens
475
677
  * @param props - {@link CloseCreditAccountProps}
476
678
  * @returns All necessary data to execute the transaction (call, credit facade)
477
679
  */
@@ -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
  }
@@ -1,6 +1,16 @@
1
1
  import type { GearboxSDK } from "../GearboxSDK.js";
2
2
  import type { PluginsMap } from "../plugins/index.js";
3
3
  import { Construct } from "./Construct.js";
4
+ /**
5
+ * @internal
6
+ * Extended base class for SDK components that need a reference to the
7
+ * top-level {@link GearboxSDK} instance (and its plugins).
8
+ *
9
+ * Prefer this over {@link Construct} when the component accesses SDK-level
10
+ * services such as market registers, plugins, or hooks.
11
+ *
12
+ * @typeParam Plugins - Map of attached plugin types.
13
+ */
4
14
  export declare class SDKConstruct<const Plugins extends PluginsMap = {}> extends Construct {
5
15
  readonly sdk: GearboxSDK<Plugins>;
6
16
  constructor(sdk: GearboxSDK<Plugins>);