@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
@@ -5,44 +5,78 @@ import type { GearboxSDK } from "../../GearboxSDK.js";
5
5
  import type { RawTx } from "../../types/index.js";
6
6
  import type { IHooks } from "../../utils/internal/index.js";
7
7
  import { type PartialPriceFeedTreeNode } from "./AbstractPriceFeed.js";
8
- import type { IPriceFeedContract, PriceUpdateV310, UpdatePriceFeedsResult } from "./types.js";
9
- import type { IPriceUpdater, IPriceUpdateTask, PythOptions, RedstoneOptions } from "./updates/index.js";
8
+ import type { IPriceFeedContract, PriceUpdate, UpdatePriceFeedsResult } from "./types.js";
9
+ import type { IPriceUpdateTask, PythOptions, RedstoneOptions } from "./updates/index.js";
10
10
  export type PriceFeedRegisterHooks = {
11
11
  /**
12
12
  * Emitted when transactions to update price feeds have been generated, but before they're used anywhere
13
13
  */
14
14
  updatesGenerated: [UpdatePriceFeedsResult];
15
15
  };
16
+ /**
17
+ * Configuration for external price-update providers supported by the register.
18
+ **/
16
19
  export interface PriceFeedRegisterOptions {
20
+ /**
21
+ * Redstone price-update provider options.
22
+ **/
17
23
  redstone?: RedstoneOptions;
24
+ /**
25
+ * Pyth price-update provider options.
26
+ **/
18
27
  pyth?: PythOptions;
19
28
  }
29
+ /**
30
+ * @internal
31
+ * Diagnostic snapshot of the most recent price-update round.
32
+ **/
20
33
  export interface LatestUpdate {
34
+ /**
35
+ * Unix timestamp (seconds) of the most recent update.
36
+ **/
21
37
  timestamp: number;
38
+ /**
39
+ * Individual update tasks that were executed.
40
+ **/
22
41
  updates: IPriceUpdateTask[];
23
42
  }
24
43
  /**
25
- * PriceFeedRegister acts as a chain-level cache to avoid creating multiple contract instances.
26
- * It's reused by PriceOracles belonging to different markets
44
+ * Chain-level cache of price feed contract instances.
27
45
  *
46
+ * All {@link IPriceOracleContract}s across different markets share a single
47
+ * `PriceFeedRegister`, avoiding duplicate contract wrappers for the same
48
+ * on-chain feed. The register also orchestrates off-chain price updates
49
+ * (Pyth, Redstone, etc.).
28
50
  **/
29
51
  export declare class PriceFeedRegister extends SDKConstruct implements IHooks<PriceFeedRegisterHooks> {
30
52
  #private;
31
- readonly updaters: IPriceUpdater[];
32
53
  constructor(sdk: GearboxSDK, opts?: PriceFeedRegisterOptions);
54
+ /**
55
+ * @internal
56
+ * Registers a callback for price-feed register lifecycle events.
57
+ * @param event - Event name.
58
+ * @param handler - Callback to invoke.
59
+ **/
33
60
  addHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: PriceFeedRegisterHooks[K]) => void | Promise<void>) => void;
61
+ /**
62
+ * @internal
63
+ * Removes a previously registered hook.
64
+ * @param event - Event name.
65
+ * @param handler - Callback to remove.
66
+ **/
34
67
  removeHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: PriceFeedRegisterHooks[K]) => void | Promise<void>) => void;
35
68
  /**
36
69
  * Returns all price feeds known to sdk
37
70
  */
38
71
  get feeds(): readonly IPriceFeedContract[];
39
72
  /**
40
- * Returns RawTxs to update price feeds
41
- * @param priceFeeds Array oftop-level price feeds, actual updatable price feeds will be derived.
42
- * Or filter criteria, that will gather all main or reserve price feeds from all oracles
43
- * If not provided will use all price feeds that are attached
44
- * @returns
45
- */
73
+ * Generates transactions to push fresh off-chain prices to updatable feeds.
74
+ *
75
+ * @param priceFeeds - Top-level price feeds whose updatable dependencies
76
+ * will be resolved, or a filter (`{ main: true }` / `{ reserve: true }`)
77
+ * to gather feeds from all oracles. When omitted, all registered feeds
78
+ * are used.
79
+ **/
46
80
  generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[] | {
47
81
  main: true;
48
82
  } | {
@@ -57,7 +91,7 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
57
91
  main: true;
58
92
  } | {
59
93
  reserve: true;
60
- }): Promise<PriceUpdateV310[]>;
94
+ }): Promise<PriceUpdate[]>;
61
95
  /**
62
96
  * Similar to {@link generatePriceFeedsUpdates}, but returns raw transaction to PriceFeedStore.updatePrices
63
97
  * @param priceFeeds
@@ -69,7 +103,7 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
69
103
  reserve: true;
70
104
  }): Promise<RawTx>;
71
105
  /**
72
- * Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds
106
+ * Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds (not known to sdk)
73
107
  * This does not add feeds to this register, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
74
108
  * @param feeds
75
109
  * @param block
@@ -90,18 +124,48 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
90
124
  blockNumber: bigint;
91
125
  } | {
92
126
  blockTag: BlockTag;
93
- }): Promise<PriceUpdateV310[]>;
127
+ }): Promise<PriceUpdate[]>;
128
+ /**
129
+ * Checks whether a price feed is already registered at the given address.
130
+ * @param address - On-chain address to look up.
131
+ **/
94
132
  has(address: Address): boolean;
133
+ /**
134
+ * Returns the cached price feed contract at the given address.
135
+ * @param address - On-chain address to look up.
136
+ * @throws If no feed is registered at that address.
137
+ **/
95
138
  mustGet(address: Address): IPriceFeedContract;
139
+ /**
140
+ * Inserts or updates a price feed from a full tree node.
141
+ *
142
+ * If a fully loaded feed already exists at the same address, only the
143
+ * answer is refreshed. Otherwise a new contract wrapper is created and
144
+ * cached.
145
+ *
146
+ * @param data - Full price feed tree node from the compressor.
147
+ * @returns The cached (or newly created) feed instance.
148
+ * @throws If the created feed is only partially initialized.
149
+ **/
96
150
  upsert(data: PriceFeedTreeNode): IPriceFeedContract;
97
151
  /**
98
152
  * Loads PARTIAL information about all updatable price feeds from MarketCompressor
99
153
  * Discovered price feeds are not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
100
154
  */
101
155
  getPartialUpdatablePriceFeeds(configurators: Address[], pools?: Address[]): Promise<IPriceFeedContract[]>;
156
+ /**
157
+ * Instantiates the appropriate price feed contract wrapper based on
158
+ * the `contractType` discriminator in the node's base params.
159
+ *
160
+ * @param data - Partial or full price feed tree node.
161
+ * @returns A new (uncached) feed contract instance.
162
+ * @throws If the contract type is unsupported and strict mode is enabled.
163
+ **/
102
164
  create(data: PartialPriceFeedTreeNode): IPriceFeedContract;
103
165
  /**
104
- * Information update latest update of updatable price feeds, for diagnostic purposes
105
- */
166
+ * @internal
167
+ * Diagnostic snapshot of the most recent price-update round, or
168
+ * `undefined` if no updates have been generated yet.
169
+ **/
106
170
  get latestUpdate(): LatestUpdate | undefined;
107
171
  }
@@ -1,2 +1,2 @@
1
- import type { PriceUpdateV310, UpdatePriceFeedsResult } from "./types.js";
2
- export declare function getRawPriceUpdates(updates: UpdatePriceFeedsResult): PriceUpdateV310[];
1
+ import type { PriceUpdate, UpdatePriceFeedsResult } from "./types.js";
2
+ export declare function getRawPriceUpdates(updates: UpdatePriceFeedsResult): PriceUpdate[];
@@ -2,43 +2,107 @@ import type { Address, Hex, UnionOmit } from "viem";
2
2
  import type { IBaseContract, PriceFeedAnswer } from "../../base/index.js";
3
3
  import type { IPriceUpdateTx, PriceFeedStateHuman, RawTx } from "../../types/index.js";
4
4
  import type { PriceFeedRef } from "./PriceFeedRef.js";
5
+ /**
6
+ * @internal
7
+ * Indicates whether a price feed is used as the primary ("Main") or
8
+ * fallback ("Reserve") oracle for a token. Gearbox uses dual-oracle
9
+ * pricing to protect against oracle manipulation.
10
+ **/
5
11
  export type PriceFeedUsageType = "Main" | "Reserve";
12
+ /**
13
+ * Discriminator for the various on-chain price feed contract implementations
14
+ * (e.g. Curve LP, Balancer, Pyth, Redstone).
15
+ **/
6
16
  export type PriceFeedContractType = "PRICE_FEED::BALANCER_STABLE" | "PRICE_FEED::BALANCER_WEIGHTED" | "PRICE_FEED::BOUNDED" | "PRICE_FEED::COMPOSITE" | "PRICE_FEED::CONSTANT" | "PRICE_FEED::CURVE_CRYPTO" | "PRICE_FEED::CURVE_STABLE" | "PRICE_FEED::CURVE_USD" | "PRICE_FEED::ERC4626" | "PRICE_FEED::EXTERNAL" | "PRICE_FEED::MELLOW_LRT" | "PRICE_FEED::PENDLE_PT_TWAP" | "PRICE_FEED::PYTH" | "PRICE_FEED::REDSTONE" | "PRICE_FEED::WSTETH" | "PRICE_FEED::YEARN" | "PRICE_FEED::ZERO";
17
+ /**
18
+ * Public interface for a single price feed contract.
19
+ *
20
+ * A price feed converts an on-chain or off-chain data source into a
21
+ * USD-denominated price with 8 decimals. Feeds are organized into trees:
22
+ * composite feeds may depend on several underlying feeds.
23
+ **/
7
24
  export interface IPriceFeedContract extends IBaseContract {
25
+ /**
26
+ * Whether this price feed enforces a lower-bound cap on its answer.
27
+ **/
8
28
  readonly hasLowerBoundCap: boolean;
29
+ /**
30
+ * Discriminator identifying gearbox price feed type
31
+ **/
9
32
  readonly priceFeedType: PriceFeedContractType;
33
+ /**
34
+ * Number of decimals in the price answer (typically 8).
35
+ **/
10
36
  readonly decimals: number;
11
37
  /**
12
- * True if the contract deployed at this address implements IUpdatablePriceFeed interface
13
- */
38
+ * `true` if the on-chain contract implements `IUpdatablePriceFeed`,
39
+ * meaning its price can be refreshed via an off-chain data push.
40
+ **/
14
41
  readonly updatable: boolean;
15
42
  /**
16
- * It's possible to create PriceFeed with base params only.
17
- * This flag idicates that all the price feed data (decimals, skip check, dependencies...) has been loaded from compressor
18
- */
43
+ * @internal
44
+ * `true` once the full feed configuration (decimals, skip-check flag,
45
+ * dependencies, etc.) has been loaded. A feed created from base params
46
+ * alone will have `loaded === false`.
47
+ **/
19
48
  readonly loaded: boolean;
20
49
  /**
21
- * Latest answer for this price feed
22
- */
50
+ * Latest price answer for this feed.
51
+ **/
23
52
  readonly answer: PriceFeedAnswer;
53
+ /**
54
+ * Whether price feed implements its own safety and staleness checks
55
+ **/
24
56
  readonly skipCheck: boolean;
57
+ /**
58
+ * Immediate child feeds that this composite feed depends on.
59
+ **/
25
60
  readonly underlyingPriceFeeds: readonly PriceFeedRef[];
61
+ /**
62
+ * Replaces the cached answer with a new value.
63
+ * @param answer - New price answer to store.
64
+ **/
26
65
  updateAnswer: (answer: PriceFeedAnswer) => void;
66
+ /**
67
+ * Returns a human-readable snapshot of this feed's state.
68
+ * @param raw - When `true`, includes raw/unformatted values.
69
+ **/
27
70
  stateHuman: (raw?: boolean) => UnionOmit<PriceFeedStateHuman, "stalenessPeriod">;
28
71
  /**
29
- * Returns all updatable depenedencies (uderlying price feeds) of this price feed, including price feed itself, if it's updatable
30
- * @returns
31
- */
72
+ * Collects all updatable feeds in this feed's dependency tree,
73
+ * including this feed itself when it is updatable.
74
+ **/
32
75
  updatableDependencies: () => IUpdatablePriceFeedContract[];
33
76
  }
77
+ /**
78
+ * Extended price feed interface for feeds whose price can be refreshed
79
+ * via an off-chain data push (e.g. Pyth or Redstone feeds).
80
+ **/
34
81
  export interface IUpdatablePriceFeedContract extends IPriceFeedContract {
82
+ /**
83
+ * Builds a raw transaction that pushes new price data to the on-chain feed.
84
+ * @param data - ABI-encoded update payload.
85
+ **/
35
86
  createPriceUpdateTx: (data: `0x${string}`) => RawTx;
36
87
  }
88
+ /**
89
+ * Result of generating price-feed update transactions.
90
+ **/
37
91
  export interface UpdatePriceFeedsResult {
92
+ /**
93
+ * Transactions that push fresh prices to updatable feeds.
94
+ **/
38
95
  txs: IPriceUpdateTx[];
96
+ /**
97
+ * Latest timestamp among all fetched price updates (unix seconds).
98
+ **/
39
99
  timestamp: number;
40
100
  }
41
- export interface PriceUpdateV310 {
101
+ /**
102
+ * Pair: updatable price feed address and
103
+ * data can be passed to IUpdatablePriceFeed.updatePrice
104
+ */
105
+ export interface PriceUpdate {
42
106
  /**
43
107
  * IUpdatablePriceFeed contract address
44
108
  */
@@ -1,6 +1,9 @@
1
1
  import { z } from "zod/v4";
2
2
  import type { PluginsMap } from "./plugins/index.js";
3
3
  import type { ILogger } from "./types/index.js";
4
+ /**
5
+ * Zod schema for validating {@link SDKOptions} at runtime.
6
+ **/
4
7
  export declare const SDKOptions: z.ZodObject<{
5
8
  addressProvider: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>;
6
9
  marketConfigurators: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>>;
@@ -25,13 +28,19 @@ export declare const SDKOptions: z.ZodObject<{
25
28
  }, z.core.$strip>>;
26
29
  gasLimit: z.ZodOptional<z.ZodNullable<z.ZodBigInt>>;
27
30
  }, z.core.$strip>;
31
+ /**
32
+ * Configuration options accepted by {@link GearboxSDK.attach} and related
33
+ * factory methods.
34
+ *
35
+ * @typeParam Plugins - Map of plugin names to plugin instances.
36
+ **/
28
37
  export type SDKOptions<Plugins extends PluginsMap> = Omit<z.infer<typeof SDKOptions>, "logger" | "plugins"> & {
29
38
  /**
30
- * Plugins to extends SDK functionality
31
- */
39
+ * Plugins that extend SDK functionality.
40
+ **/
32
41
  plugins?: Plugins;
33
42
  /**
34
- * Bring your own logger
35
- */
43
+ * Custom logger implementation.
44
+ **/
36
45
  logger?: ILogger;
37
46
  };
@@ -2,18 +2,57 @@ import type { Address, PublicClient } from "viem";
2
2
  import type { NetworkType } from "../chain/index.js";
3
3
  import type { GearboxSDK } from "../GearboxSDK.js";
4
4
  import type { ILogger } from "../index.js";
5
+ /**
6
+ * Convenience base class for {@link IGearboxSDKPlugin} implementations.
7
+ *
8
+ * Handles the SDK attachment lifecycle, logger setup, and provides
9
+ * common accessors (`network`, `client`). Subclasses only need to
10
+ * implement {@link load} to supply their domain-specific state.
11
+ *
12
+ * @typeParam TState - Plugin-specific state shape.
13
+ **/
5
14
  export declare abstract class BasePlugin<TState extends Record<keyof TState, unknown> = {}> {
6
15
  #private;
7
16
  protected logger?: ILogger;
17
+ /**
18
+ * Plugin state version for hydration compatibility checks.
19
+ * @default 1
20
+ **/
8
21
  readonly version: number;
22
+ /**
23
+ * When `true`, state is fetched eagerly during the `attach` phase
24
+ * rather than waiting for an explicit `load` call.
25
+ **/
9
26
  readonly loadOnAttach: boolean;
10
27
  constructor(loadOnAttach?: boolean);
28
+ /**
29
+ * Reference to the parent SDK instance.
30
+ * @throws Error if the SDK has not been attached yet.
31
+ **/
11
32
  get sdk(): GearboxSDK<any>;
12
33
  set sdk(sdk: GearboxSDK<any>);
34
+ /**
35
+ * {@inheritDoc IGearboxSDKPlugin.attach}
36
+ **/
13
37
  attach(): Promise<void>;
38
+ /**
39
+ * {@inheritDoc IGearboxSDKPlugin.syncState}
40
+ **/
14
41
  syncState(): Promise<void>;
42
+ /**
43
+ * Loads or refreshes the plugin state.
44
+ *
45
+ * @param force - When `true`, re-fetch even if state is already loaded.
46
+ * @returns The loaded plugin state.
47
+ **/
15
48
  abstract load(force?: boolean): Promise<TState>;
49
+ /**
50
+ * Network type of the connected chain (e.g. `"Mainnet"`, `"Arbitrum"`).
51
+ **/
16
52
  get network(): NetworkType;
53
+ /**
54
+ * Viem public client for read-only chain interactions.
55
+ **/
17
56
  get client(): PublicClient;
18
57
  protected labelAddress(address: Address): string;
19
58
  }
@@ -1,5 +1,13 @@
1
1
  import type { BaseState, IBaseContract } from "../base/index.js";
2
2
  import type { GearboxSDK } from "../GearboxSDK.js";
3
+ /**
4
+ * Serialisable snapshot of a plugin's state, used for hydration.
5
+ *
6
+ * When `loaded` is `false` only the `version` field is present;
7
+ * when `loaded` is `true` the full `State` payload is included.
8
+ *
9
+ * @typeParam State - Plugin-specific state shape.
10
+ **/
3
11
  export type IPluginState<State extends Record<keyof State, unknown> = {}> = {
4
12
  version: number;
5
13
  } & ({
@@ -7,77 +15,99 @@ export type IPluginState<State extends Record<keyof State, unknown> = {}> = {
7
15
  } | ({
8
16
  loaded: true;
9
17
  } & State));
18
+ /**
19
+ * @internal
20
+ * Constructor signature that the SDK uses to instantiate a plugin.
21
+ *
22
+ * @typeParam TState - Plugin-specific state shape.
23
+ * @typeParam TPlugin - Concrete plugin type produced by the constructor.
24
+ **/
10
25
  export type IGearboxSDKPluginConstructor<TState extends Record<keyof TState, unknown>, TPlugin extends IGearboxSDKPlugin<TState>> = new (sdk: GearboxSDK<any>) => TPlugin;
26
+ /**
27
+ * Public contract every SDK plugin must satisfy.
28
+ *
29
+ * Plugins extend the SDK with domain-specific data and behaviour
30
+ * (e.g. farming rewards, zapper helpers). They participate in the
31
+ * SDK lifecycle: attach, hydrate, sync, and on-demand load.
32
+ *
33
+ * @typeParam TState - Plugin-specific state shape.
34
+ **/
11
35
  export interface IGearboxSDKPlugin<TState extends Record<keyof TState, unknown> = {}> {
12
36
  /**
13
- * Plugin's SDK. Is set by SDK itself in SDK constructor
14
- */
37
+ * Reference to the parent SDK instance.
38
+ * Set automatically by the SDK constructor.
39
+ **/
15
40
  sdk: GearboxSDK<any>;
16
41
  /**
17
- * Plugin version, used to check if the plugin state is compatible with the plugin during hydration
18
- */
42
+ * Plugin version, used to verify state compatibility during hydration.
43
+ **/
19
44
  version: number;
20
45
  /**
21
- * Indicates that plugins state is ready to use
22
- * It does not matter how this state was obtained, be it via attach, hydrate or on-demand load
23
- */
46
+ * Whether the plugin's state is ready to use.
47
+ * `true` regardless of how the state was obtained (attach, hydrate, or on-demand load).
48
+ **/
24
49
  loaded: boolean;
25
50
  /**
26
- * Plugin state, can be hydarted/dehydrated
27
- */
51
+ * Plugin state, can be hydrated later.
52
+ **/
28
53
  state: TState;
29
54
  /**
30
- * Loads state on demand
31
- * If it's already loaded, does nothing and returns the same state, unless force is set to true
32
- * @param force
33
- * @returns
34
- */
55
+ * Loads state on demand.
56
+ * If already loaded, returns the existing state unless `force` is `true`.
57
+ *
58
+ * @param force - Re-fetch even if state is already loaded.
59
+ * @returns The loaded plugin state.
60
+ **/
35
61
  load?: (force?: boolean) => Promise<TState>;
36
62
  /**
37
- * Called after SDK is attached
38
- * Plugins are not required to implement this. For example plugin can be stateless, or load state on demand only
39
- * @param sdk
40
- * @returns
41
- */
63
+ * Called after SDK is attached to the chain.
64
+ * Plugins are not required to implement this a plugin can be stateless
65
+ * or load state on demand only.
66
+ **/
42
67
  attach?: () => Promise<void>;
43
68
  /**
44
- * Loads plugin state from dehydrated state
45
- * @param state
46
- * @returns
47
- */
69
+ * Restores plugin state from a previously saved snapshot.
70
+ *
71
+ * @param state - state to restore from.
72
+ **/
48
73
  hydrate?: (state: TState) => void;
49
74
  /**
50
- * Called after SDK state is already synced, meaning that block number and timestamp are accessible from SDK
51
- *
52
- * @param sdk
53
- * @returns
54
- */
75
+ * Hook to sync plugin state after sdk state is synced.
76
+ * Called after SDK state is already synced, meaning that block number
77
+ * and timestamp are accessible from the SDK.
78
+ **/
55
79
  syncState?: () => Promise<void>;
56
80
  /**
57
- * Can be called by SDK to create some auxiliary contracts, such as zappers and adapters
58
- * Otherwise they are created as BaseContract instances by sdk
59
- * @param params
60
- * @returns
61
- */
81
+ * Factory hook called by the SDK to create auxiliary contracts
82
+ * (e.g. zappers, adapters). If not implemented, the SDK falls back to
83
+ * generic {@link BaseContract} instances.
84
+ *
85
+ * @param params - On-chain identification parameters for the contract.
86
+ * @returns A contract instance, or `undefined` to let the SDK use the default.
87
+ **/
62
88
  createContract?: (params: BaseState) => IBaseContract | undefined;
63
89
  /**
64
- * Human readable state for diagnostics
65
- * @param raw (print actual values in addition to human-friendly values, e.g. 1 ETH (1000000000000000000))
66
- * @returns
67
- */
90
+ * Human-readable state snapshot for diagnostics.
91
+ *
92
+ * @param raw - When `true`, include raw numeric values alongside formatted ones
93
+ * (e.g. `1 ETH (1000000000000000000)`).
94
+ * @returns An untyped object suitable for logging or inspection.
95
+ **/
68
96
  stateHuman?: (raw?: boolean) => unknown;
69
97
  }
70
98
  /**
71
- * Helper type that extracts the state type from a plugin instance
72
- */
99
+ * Helper type that extracts the state type from a plugin instance.
100
+ **/
73
101
  export type PluginState<T> = T extends IGearboxSDKPlugin<infer TState> ? IPluginState<TState> : never;
74
102
  /**
75
- * Mapping between plugin name and plugin instance
76
- */
103
+ * @internal
104
+ * Mapping between plugin name and plugin instance.
105
+ **/
77
106
  export type PluginsMap = Record<string, IGearboxSDKPlugin<any>>;
78
107
  /**
79
- * Mapping that infers plugin states map from plugin instances map
80
- */
108
+ * @internal
109
+ * Mapping that infers plugin states from plugin instances.
110
+ **/
81
111
  export type PluginStatesMap<T extends PluginsMap> = {
82
112
  [K in keyof T]: PluginState<T[K]>;
83
113
  };
@@ -1,9 +1,21 @@
1
1
  import { SDKConstruct } from "../base/index.js";
2
2
  import type { GearboxSDK } from "../GearboxSDK.js";
3
3
  import type { AddLiquidityCall, AddLiquidityProps, RemoveLiquidityCall, RemoveLiquidityProps } from "./types.js";
4
+ /**
5
+ * @internal
6
+ * Base implementation of {@link IPoolsService}.
7
+ *
8
+ * Used to generate data for write operations on LP side (deposit to/withdraw from pool)
9
+ **/
4
10
  export declare abstract class AbstractPoolService extends SDKConstruct {
5
11
  #private;
6
12
  constructor(sdk: GearboxSDK, version: number);
13
+ /**
14
+ * {@inheritDoc IPoolsService.addLiquidity}
15
+ **/
7
16
  addLiquidity({ collateral, pool, account, zapper, permit, nativeTokenAddress, referralCode, migrate, }: AddLiquidityProps): AddLiquidityCall;
17
+ /**
18
+ * {@inheritDoc IPoolsService.removeLiquidity}
19
+ **/
8
20
  removeLiquidity({ pool, amount, account, zapper, permit, }: RemoveLiquidityProps): RemoveLiquidityCall;
9
21
  }