@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
@@ -20,16 +20,54 @@ interface PermitResult {
20
20
  deadline: bigint;
21
21
  nonce: bigint;
22
22
  }
23
+ /**
24
+ * Parameters for depositing liquidity into a Gearbox lending pool.
25
+ *
26
+ * When a `zapper` is provided, the deposit is routed through a zapper
27
+ * contract that handles token conversions (e.g. native ETH wrapping or
28
+ * ERC-20 permit-based approvals). Without a zapper, the deposit goes
29
+ * directly to the pool contract.
30
+ **/
23
31
  export interface AddLiquidityProps {
32
+ /**
33
+ * Token and amount to deposit.
34
+ **/
24
35
  collateral: Asset;
36
+ /**
37
+ * Address of the Gearbox lending pool.
38
+ **/
25
39
  pool: Address;
40
+ /**
41
+ * Recipient of the pool shares (diesel tokens).
42
+ **/
26
43
  account: Address;
44
+ /**
45
+ * Whether this deposit is part of a pool migration.
46
+ * When `true`, a zapper is required.
47
+ **/
27
48
  migrate: boolean;
49
+ /**
50
+ * Optional zapper to route the deposit through.
51
+ **/
28
52
  zapper: IZapper | undefined;
53
+ /**
54
+ * Optional ERC-2612 permit for gasless token approval.
55
+ **/
29
56
  permit: PermitResult | undefined;
57
+ /**
58
+ * Address of the chain's native-token wrapper (e.g. WETH).
59
+ **/
30
60
  nativeTokenAddress: Address;
61
+ /**
62
+ * Optional referral code for tracking the deposit source.
63
+ **/
31
64
  referralCode: bigint | undefined;
32
65
  }
66
+ /**
67
+ * Tuple describing a single contract call to execute an add-liquidity
68
+ * operation. The exact variant depends on whether a zapper and/or
69
+ * permit is used.
70
+ **/
33
71
  export type AddLiquidityCall = [
34
72
  {
35
73
  target: Address;
@@ -54,13 +92,39 @@ export type AddLiquidityCall = [
54
92
  args: [bigint, Address, bigint];
55
93
  }
56
94
  ];
95
+ /**
96
+ * Parameters for withdrawing liquidity from a Gearbox lending pool.
97
+ *
98
+ * Withdrawals are routed through a zapper that redeems pool shares
99
+ * (diesel tokens) for the underlying asset.
100
+ **/
57
101
  export interface RemoveLiquidityProps {
102
+ /**
103
+ * Address of the Gearbox lending pool.
104
+ **/
58
105
  pool: Address;
106
+ /**
107
+ * Amount of pool shares (diesel tokens) to redeem.
108
+ **/
59
109
  amount: bigint;
110
+ /**
111
+ * Recipient of the redeemed underlying tokens.
112
+ **/
60
113
  account: Address;
114
+ /**
115
+ * Optional ERC-2612 permit for gasless token approval.
116
+ **/
61
117
  permit: PermitResult | undefined;
118
+ /**
119
+ * Zapper to route the redemption through.
120
+ **/
62
121
  zapper: IZapper;
63
122
  }
123
+ /**
124
+ * Tuple describing a single contract call to execute a remove-liquidity
125
+ * operation. The exact variant depends on whether a permit is used and
126
+ * whether the withdrawal goes through a zapper or directly to the pool.
127
+ **/
64
128
  export type RemoveLiquidityCall = [
65
129
  {
66
130
  target: Address;
@@ -79,18 +143,23 @@ export type RemoveLiquidityCall = [
79
143
  args: [bigint, Address, Address];
80
144
  }
81
145
  ];
146
+ /**
147
+ * Service interface for pool liquidity operations.
148
+ **/
82
149
  export interface IPoolsService {
83
150
  /**
84
- * Add liquidity to a pool
151
+ * Construct a call to add liquidity to a Gearbox lending pool.
152
+ *
85
153
  * @param props - {@link AddLiquidityProps}
86
- * @returns - {@link AddLiquidityCall}
87
- */
154
+ * @returns A single-element tuple with the encoded contract call.
155
+ **/
88
156
  addLiquidity(props: AddLiquidityProps): AddLiquidityCall;
89
157
  /**
90
- * Remove liquidity from a pool
158
+ * Construct a call to remove liquidity from a Gearbox lending pool.
159
+ *
91
160
  * @param props - {@link RemoveLiquidityProps}
92
- * @returns - {@link RemoveLiquidityCall}
93
- */
161
+ * @returns A single-element tuple with the encoded contract call.
162
+ **/
94
163
  removeLiquidity(props: RemoveLiquidityProps): RemoveLiquidityCall;
95
164
  }
96
165
  export {};
@@ -3,19 +3,38 @@ import { BaseContract, type BaseContractArgs } from "../base/index.js";
3
3
  import type { GearboxSDK } from "../GearboxSDK.js";
4
4
  import type { IPriceOracleContract } from "../market/index.js";
5
5
  import { AddressMap, AddressSet } from "../utils/index.js";
6
- import type { Asset, ExpectedAndLeftoverOptions, RouterCASlice, RouterCMSlice } from "./types.js";
6
+ import type { Asset, RouterCASlice, RouterCMSlice } from "./types.js";
7
+ export interface ExpectedAndLeftoverOptions {
8
+ balances?: Leftovers;
9
+ keepAssets?: Address[];
10
+ debtOnly?: boolean;
11
+ }
7
12
  export interface Leftovers {
8
13
  expectedBalances: AddressMap<Asset>;
9
14
  leftoverBalances: AddressMap<Asset>;
10
15
  tokensToClaim: AddressMap<Asset>;
11
16
  }
17
+ /**
18
+ * @internal
19
+ * Base class for router contract wrappers.
20
+ *
21
+ * Provides helpers that classify credit-account token balances into
22
+ * "expected" (to be swapped) and "leftover" (to be kept) categories,
23
+ * which concrete router implementations use when building optimised
24
+ * multi-call swap paths.
25
+ *
26
+ * @typeParam abi - ABI type of the underlying router contract.
27
+ **/
12
28
  export declare abstract class AbstractRouterContract<abi extends Abi | readonly unknown[]> extends BaseContract<abi> {
29
+ /**
30
+ * Reference to the parent SDK instance.
31
+ **/
13
32
  readonly sdk: GearboxSDK;
14
33
  constructor(sdk: GearboxSDK, args: BaseContractArgs<abi>);
15
34
  protected getExpectedAndLeftover(ca: RouterCASlice, cm: RouterCMSlice, options?: ExpectedAndLeftoverOptions): Leftovers;
16
35
  protected getDefaultExpectedAndLeftover(ca: RouterCASlice, keepAssets?: Address[], debtOnly?: boolean): Leftovers;
17
36
  /**
18
- * Tries to sell just enought of most valuable token to cover debt
37
+ * Tries to sell just enough of the most valuable token to cover debt.
19
38
  * @param ca
20
39
  * @param keepAssets
21
40
  * @returns
@@ -884,35 +884,47 @@ declare const abi: readonly [{
884
884
  }];
885
885
  }];
886
886
  type abi = typeof abi;
887
+ /**
888
+ * V3.10 implementation of the {@link IRouterContract} interface.
889
+ *
890
+ * Uses the on-chain Gearbox router to find optimal multi-hop swap
891
+ * paths, splitting large positions across multiple routes to reduce
892
+ * price impact.
893
+ **/
887
894
  export declare class RouterV310Contract extends AbstractRouterContract<abi> implements IRouterContract {
888
895
  #private;
889
896
  constructor(sdk: GearboxSDK, address: Address, version: number);
890
897
  /**
891
- * Implements {@link IRouterContract.findOneTokenPath}
892
- */
898
+ * {@inheritDoc IRouterContract.findOneTokenPath}
899
+ **/
893
900
  findOneTokenPath(props: FindOneTokenPathProps): Promise<RouterResult>;
894
901
  /**
895
- * Implements {@link IRouterContract.findOpenStrategyPath}
896
- */
902
+ * {@inheritDoc IRouterContract.findOpenStrategyPath}
903
+ **/
897
904
  findOpenStrategyPath(props: FindOpenStrategyPathProps): Promise<OpenStrategyResult>;
898
905
  /**
899
- * Implements {@link IRouterContract.findClaimAllRewards}
900
- */
906
+ * {@inheritDoc IRouterContract.findClaimAllRewards}
907
+ **/
901
908
  findClaimAllRewards(props: FindClaimAllRewardsProps): Promise<RouterRewardsResult>;
902
909
  /**
903
- * Implements {@link IRouterContract.findBestClosePath}
904
- */
910
+ * {@inheritDoc IRouterContract.findBestClosePath}
911
+ **/
905
912
  findBestClosePath(props: FindBestClosePathProps): Promise<RouterCloseResult>;
906
913
  /**
907
- * v310-specific method to set explicitly number of splits for a token
908
- * @param token
909
- * @param numSplits
910
- */
914
+ * Override the number of route splits used when swapping a specific token.
915
+ *
916
+ * @param token - Token address to configure.
917
+ * @param numSplits - Number of parallel route splits.
918
+ * @internal
919
+ **/
911
920
  setNumSplits(token: Address, numSplits: bigint): void;
912
921
  /**
913
- * v310-specific method to set default number of splits for a token
914
- * @param numSplits
915
- */
922
+ * Set the default number of route splits applied to the highest-value
923
+ * token in each swap.
924
+ *
925
+ * @param numSplits - Default number of parallel route splits.
926
+ * @internal
927
+ **/
916
928
  setDefaultNumSplits(numSplits: bigint): void;
917
929
  }
918
930
  export {};
@@ -1,14 +1,14 @@
1
1
  import type { Address } from "viem";
2
2
  import type { CreditAccountData, IBaseContract } from "../base/index.js";
3
3
  import type { MultiCall } from "../types/index.js";
4
- import type { Leftovers } from "./AbstractRouterContract.js";
4
+ /**
5
+ * Type of swap the router should perform.
6
+ *
7
+ * - `"EXACT_INPUT"` — swap an exact amount of the input token.
8
+ * - `"EXACT_INPUT_ALL"` — swap the entire balance of the input token.
9
+ * - `"EXACT_OUTPUT"` — swap to receive an exact amount of the output token (no longer supported by the router).
10
+ **/
5
11
  export type SwapOperation = "EXACT_INPUT" | "EXACT_INPUT_ALL" | "EXACT_OUTPUT";
6
- export interface PathOption {
7
- target: Address;
8
- option: number;
9
- totalOptions: number;
10
- }
11
- export type PathOptionSerie = Array<PathOption>;
12
12
  /**
13
13
  * Result returned from router contract
14
14
  */
@@ -65,8 +65,18 @@ export interface RouterCloseResult extends RouterResult {
65
65
  */
66
66
  underlyingBalance: bigint;
67
67
  }
68
+ /**
69
+ * A token address paired with a balance, used throughout the router to
70
+ * represent holdings, collateral inputs, and leftover targets.
71
+ **/
68
72
  export interface Asset {
73
+ /**
74
+ * ERC-20 token address.
75
+ **/
69
76
  token: Address;
77
+ /**
78
+ * Token amount in the token's native decimals.
79
+ **/
70
80
  balance: bigint;
71
81
  }
72
82
  /**
@@ -78,50 +88,9 @@ export interface RouterCMSlice {
78
88
  collateralTokens: Array<Address>;
79
89
  }
80
90
  /**
81
- * Slice of credit account data required for router operations
82
- */
91
+ * Minimal slice of credit-account data required by router operations.
92
+ **/
83
93
  export type RouterCASlice = Pick<CreditAccountData, "tokens" | "enabledTokensMask" | "underlying" | "creditAccount" | "creditFacade" | "debt" | "totalDebtUSD" | "creditManager">;
84
- export type CreditAccountTokensSlice = Pick<CreditAccountData, "creditAccount" | "tokens" | "enabledTokensMask">;
85
- export interface FindAllSwapsProps {
86
- /**
87
- * Minimal credit account data on which operation is performed
88
- */
89
- creditAccount: RouterCASlice;
90
- /**
91
- * Minimal credit manager data on which operation is performed
92
- */
93
- creditManager: RouterCMSlice;
94
- /**
95
- * {@link SwapOperation} = "EXACT_INPUT" | "EXACT_INPUT_ALL" | "EXACT_OUTPUT"; however router stopped to support EXACT_OUTPUT
96
- */
97
- swapOperation: SwapOperation;
98
- /**
99
- * Address of input token
100
- */
101
- tokenIn: Address;
102
- /**
103
- * Address of target token
104
- */
105
- tokenOut: Address;
106
- /**
107
- * Incoming amount of tokenIn to swap
108
- */
109
- amount: bigint;
110
- /**
111
- * Amount that should be left on account after swap; technically equals to 0 in the most of the cases
112
- */
113
- leftoverAmount: bigint;
114
- /**
115
- * Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
116
- */
117
- slippage: number | bigint;
118
- }
119
- export interface FindClosePathInput {
120
- pathOptions: Array<PathOptionSerie>;
121
- expected: Array<Asset>;
122
- leftover: Array<Asset>;
123
- connectors: Array<Address>;
124
- }
125
94
  export interface FindOneTokenPathProps {
126
95
  /**
127
96
  * Minimal credit account data on which operation is performed
@@ -136,7 +105,7 @@ export interface FindOneTokenPathProps {
136
105
  */
137
106
  tokenIn: Address;
138
107
  /**
139
- * Adddress of target token
108
+ * Address of target token
140
109
  */
141
110
  tokenOut: Address;
142
111
  /**
@@ -206,7 +175,7 @@ export interface FindBestClosePathProps {
206
175
  */
207
176
  keepAssets?: Address[];
208
177
  /**
209
- * Debt only mode - will try to sell just enought of most valuable token to cover debt
178
+ * Debt only mode - will try to sell just enough of most valuable token to cover debt
210
179
  */
211
180
  debtOnly?: boolean;
212
181
  }
@@ -228,35 +197,43 @@ export interface ClosePathBalances {
228
197
  */
229
198
  tokensToClaim?: Array<Asset>;
230
199
  }
231
- export interface ExpectedAndLeftoverOptions {
232
- balances?: Leftovers;
233
- keepAssets?: Address[];
234
- debtOnly?: boolean;
235
- }
200
+ /**
201
+ * On-chain router contract that finds optimal multi-hop swap paths
202
+ * for credit-account operations: single-token swaps, open-strategy
203
+ * collateral conversion, reward claiming, and full account closure.
204
+ **/
236
205
  export interface IRouterContract extends IBaseContract {
237
206
  /**
238
- * Find the best path to swap token A to token B (target token).
207
+ * Find the best path to swap one token into another.
208
+ *
239
209
  * @param props - {@link FindOneTokenPathProps}
240
- * @return result - {@link RouterResult}
241
- */
210
+ * @returns The optimal swap result including amount, slippage-adjusted
211
+ * minimum, and the multi-call sequence to execute.
212
+ **/
242
213
  findOneTokenPath: (props: FindOneTokenPathProps) => Promise<RouterResult>;
243
214
  /**
244
- * Finds the best path for opening Credit Account; converts all expectedBalances besides leftoverBalances into target token
215
+ * Find the best path for opening a credit account by converting all
216
+ * collateral (except leftovers) into a single target token.
217
+ *
245
218
  * @param props - {@link FindOpenStrategyPathProps}
246
- * @returns result - {@link OpenStrategyResult}
247
- */
219
+ * @returns Swap result with projected post-open balances.
220
+ **/
248
221
  findOpenStrategyPath: (props: FindOpenStrategyPathProps) => Promise<OpenStrategyResult>;
249
222
  /**
250
- * Constructs calls to claim all rewards for Credit Account
223
+ * Construct calls to claim all pending rewards on a credit account
224
+ * and swap them to the underlying token.
225
+ *
251
226
  * @param props - {@link FindClaimAllRewardsProps}
252
- * @returns result - {@link RouterRewardsResult}
253
- */
227
+ * @returns Multi-call sequence for claiming and swapping rewards.
228
+ **/
254
229
  findClaimAllRewards: (props: FindClaimAllRewardsProps) => Promise<RouterRewardsResult>;
255
230
  /**
256
- * Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
257
- * Can be used for closing Credit Account and for liquidations as well.
231
+ * Find the best path to swap all credit-account assets into the
232
+ * underlying token. Used for account closure and liquidation.
233
+ *
258
234
  * @param props - {@link FindBestClosePathProps}
259
- * @return result - {@link RouterCloseResult}
260
- */
235
+ * @returns Swap result including the total underlying balance
236
+ * after all swaps.
237
+ **/
261
238
  findBestClosePath: (props: FindBestClosePathProps) => Promise<RouterCloseResult>;
262
239
  }
@@ -2,17 +2,46 @@ import type { MarketData } from "../base/index.js";
2
2
  import type { NetworkType } from "../chain/chains.js";
3
3
  import type { AddressProviderState } from "../core/index.js";
4
4
  import type { PluginStatesMap, PluginsMap } from "../plugins/index.js";
5
+ /**
6
+ * Complete serialisable snapshot of the Gearbox SDK state.
7
+ *
8
+ * Produced by {@link GearboxSDK.state} and consumed by
9
+ * {@link GearboxSDK.hydrate} for instant offline restoration.
10
+ *
11
+ * @typeParam Plugins - Map of plugin names to plugin instances.
12
+ **/
5
13
  export interface GearboxState<Plugins extends PluginsMap = {}> {
6
14
  /**
7
- * State version, checked duryng hydration
8
- * This is not the same as @gearbox-protocol/sdk package version
9
- */
15
+ * State format version, checked during hydration.
16
+ * This is *not* the `@gearbox-protocol/sdk` package version.
17
+ **/
10
18
  version: number;
19
+ /**
20
+ * Gearbox network type the snapshot was taken from.
21
+ **/
11
22
  network: NetworkType;
23
+ /**
24
+ * EVM chain ID the snapshot was taken from.
25
+ **/
12
26
  chainId: number;
27
+ /**
28
+ * Block number the snapshot corresponds to.
29
+ **/
13
30
  currentBlock: bigint;
31
+ /**
32
+ * Block timestamp (Unix epoch seconds).
33
+ **/
14
34
  timestamp: bigint;
35
+ /**
36
+ * Address provider contract state.
37
+ **/
15
38
  addressProvider: AddressProviderState;
39
+ /**
40
+ * All loaded market data.
41
+ **/
16
42
  markets: MarketData[];
43
+ /**
44
+ * Per-plugin serialised state.
45
+ **/
17
46
  plugins: PluginStatesMap<Plugins>;
18
47
  }
@@ -1,50 +1,94 @@
1
1
  import type { Address } from "viem";
2
+ /**
3
+ * Case-insensitive map keyed by EVM addresses.
4
+ *
5
+ * All keys are checksummed via viem's {@link getAddress} on insertion and
6
+ * lookup, so `0xabc...` and `0xABC...` resolve to the same entry.
7
+ *
8
+ * @typeParam T - Type of values stored in the map.
9
+ */
2
10
  export declare class AddressMap<T> {
3
11
  #private;
12
+ /**
13
+ * @param entries - Optional initial key-value pairs. Address strings are checksummed automatically.
14
+ * @param name - Optional label used in error messages when a lookup fails.
15
+ */
4
16
  constructor(entries?: Array<[string, T]>, name?: string);
5
17
  /**
6
- * Adds or updates value, undefined removes value
7
- * @param address
8
- * @param value
18
+ * Adds or updates a value. Passing `undefined` removes the entry.
19
+ * @param address - EVM address (checksummed automatically).
20
+ * @param value - Value to store, or `undefined` to delete the entry.
21
+ * @throws If the map has been {@link freeze | frozen}.
9
22
  */
10
23
  upsert(address: string, value: T | undefined): void;
11
24
  /**
12
- * Adds value, throws if this address is already used
13
- * @param address
14
- * @param value
25
+ * Inserts a value, throwing if the address is already present.
26
+ * @param address - EVM address (checksummed automatically).
27
+ * @param value - Value to store.
28
+ * @throws If the map has been {@link freeze | frozen} or if `address` already exists.
15
29
  */
16
30
  insert(address: string, value: T): void;
17
31
  /**
18
- * Checks if address is present in map
19
- * @param address
20
- * @returns
32
+ * Checks whether an address is present in the map.
33
+ * @param address - EVM address (case-insensitive).
21
34
  */
22
35
  has(address: string): boolean;
23
36
  /**
24
- * Returns value, or undefined if the address is not in map
25
- * @param address
26
- * @returns
37
+ * Looks up a value by EVM address (case-insensitive).
38
+ * @param address - EVM address to look up.
39
+ * @returns The stored value, or `undefined` if not present.
27
40
  */
28
41
  get(address: string): T | undefined;
29
42
  /**
30
- * Gets address from map, throws if not found
31
- * @param address
32
- * @returns
43
+ * Looks up a value by EVM address, throwing if the address is absent.
44
+ * @param address - EVM address to look up.
45
+ * @throws If `address` is not in the map.
33
46
  */
34
47
  mustGet(address: string): T;
35
48
  /**
36
- * Deletes address from map
37
- * @param address
49
+ * Removes an entry by address. No-op if the address is absent.
50
+ * @param address - EVM address to remove.
38
51
  */
39
52
  delete(address: string): void;
53
+ /**
54
+ * Removes all entries from the map.
55
+ **/
40
56
  clear(): void;
57
+ /**
58
+ * Returns all entries as an array of `[checksummedAddress, value]` tuples.
59
+ **/
41
60
  entries(): Array<[Address, T]>;
61
+ /**
62
+ * Returns all values in insertion order.
63
+ **/
42
64
  values(): T[];
65
+ /**
66
+ * Returns all checksummed addresses in insertion order.
67
+ **/
43
68
  keys(): Address[];
69
+ /**
70
+ * Converts the map to a plain `Record<Address, T>` object.
71
+ **/
44
72
  asRecord(): Record<Address, T>;
73
+ /**
74
+ * Number of entries in the map.
75
+ **/
45
76
  get size(): number;
77
+ /**
78
+ * Prevents further mutations. Any subsequent call to {@link upsert},
79
+ * {@link insert}, or {@link delete} will throw.
80
+ */
46
81
  freeze(): void;
47
82
  protected get name(): string | undefined;
83
+ /**
84
+ * Creates an `AddressMap` from a plain record object.
85
+ * @param record - Object whose keys are EVM addresses.
86
+ */
48
87
  static fromRecord<T>(record: Record<Address, T>): AddressMap<T>;
88
+ /**
89
+ * Creates an `AddressMap` by extracting an address from each array element.
90
+ * @param array - Source items.
91
+ * @param mapFn - Function that returns the address key for a given item.
92
+ */
49
93
  static fromMappedArray<T>(array: T[], mapFn: (item: T) => Address): AddressMap<T>;
50
94
  }
@@ -1,9 +1,24 @@
1
1
  import { type Address } from "viem";
2
+ /**
3
+ * Case-insensitive set of EVM addresses.
4
+ *
5
+ * All addresses are checksummed via viem's {@link getAddress} on insertion and
6
+ * lookup, so `0xabc...` and `0xABC...` are treated as the same entry.
7
+ */
2
8
  export declare class AddressSet extends Set<Address> {
9
+ /**
10
+ * @param entries - Optional initial addresses. Each is checksummed automatically.
11
+ */
3
12
  constructor(entries?: Iterable<Address>);
4
13
  add(value: Address): this;
5
14
  delete(value: Address): boolean;
6
15
  has(value: Address): boolean;
16
+ /**
17
+ * Returns all addresses as an array.
18
+ **/
7
19
  asArray(): Address[];
20
+ /**
21
+ * Maps each address through `fn` and returns the resulting array.
22
+ **/
8
23
  map<T>(fn: (address: Address) => T): T[];
9
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "13.3.3",
3
+ "version": "13.4.0-beta.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -70,7 +70,8 @@
70
70
  "check:ci": "biome check --diagnostic-level=error",
71
71
  "typecheck:ci": "tsc --noEmit",
72
72
  "docs": "NODE_OPTIONS='--max-old-space-size=8192' pnpm --filter @gearbox-protocol/sdk-docs build",
73
- "docs:dev": "pnpm --filter @gearbox-protocol/sdk-docs start"
73
+ "docs:dev": "pnpm --filter @gearbox-protocol/sdk-docs start",
74
+ "docs:serve": "pnpm --filter @gearbox-protocol/sdk-docs serve"
74
75
  },
75
76
  "dependencies": {
76
77
  "@gearbox-protocol/integrations-v3": "1.54.2",
@@ -103,6 +104,7 @@
103
104
  "tsx": "^4.21.0",
104
105
  "typescript": "^5.9.3",
105
106
  "viem-deal": "^2.0.4",
107
+ "vite": "^8.0.3",
106
108
  "vitest": "^4.1.2"
107
109
  },
108
110
  "peerDependencies": {