@gearbox-protocol/sdk 14.0.0-next.4 → 14.0.0-next.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.
@@ -99,7 +99,8 @@ class MultichainSDK {
99
99
  * @param state - Multichain serialised state.
100
100
  * @param options - Shared and per-chain hydrate options.
101
101
  * @throws {@link SdkStateVersionMismatchError} if version doesn't match.
102
- * @throws {@link SdkMissingChainStateError} if a configured chain has no state.
102
+ * @throws {@link SdkMissingChainStateError} if a configured chain has no
103
+ * state and `allowMissingChains` is not set.
103
104
  */
104
105
  hydrate(state, options) {
105
106
  if (state.version !== import_OnchainSDK.STATE_VERSION) {
@@ -121,6 +122,9 @@ class MultichainSDK {
121
122
  for (const [network, sdk] of this.#chains) {
122
123
  const chainState = stateByNetwork.get(network);
123
124
  if (!chainState) {
125
+ if (options?.allowMissingChains) {
126
+ continue;
127
+ }
124
128
  throw new import_core.SdkMissingChainStateError(network);
125
129
  }
126
130
  const perChainOpts = options?.perChain?.[network] ?? {};
@@ -228,10 +228,18 @@ class OnchainSDK extends import_base.ChainContractsRegister {
228
228
  this.logger?.info("hydrated sdk state");
229
229
  this.#attached = true;
230
230
  }
231
- /** Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`). */
231
+ /**
232
+ * Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`).
233
+ **/
232
234
  get networkType() {
233
235
  return this.client.chain.network;
234
236
  }
237
+ /**
238
+ * Whether the SDK has been initialised via {@link attach} or {@link hydrate}.
239
+ **/
240
+ get attached() {
241
+ return this.#attached;
242
+ }
235
243
  /**
236
244
  * Returns a human-readable snapshot of the entire SDK state.
237
245
  * @param raw - When `true`, include raw numeric values alongside formatted ones.
@@ -85,7 +85,8 @@ class MultichainSDK {
85
85
  * @param state - Multichain serialised state.
86
86
  * @param options - Shared and per-chain hydrate options.
87
87
  * @throws {@link SdkStateVersionMismatchError} if version doesn't match.
88
- * @throws {@link SdkMissingChainStateError} if a configured chain has no state.
88
+ * @throws {@link SdkMissingChainStateError} if a configured chain has no
89
+ * state and `allowMissingChains` is not set.
89
90
  */
90
91
  hydrate(state, options) {
91
92
  if (state.version !== STATE_VERSION) {
@@ -107,6 +108,9 @@ class MultichainSDK {
107
108
  for (const [network, sdk] of this.#chains) {
108
109
  const chainState = stateByNetwork.get(network);
109
110
  if (!chainState) {
111
+ if (options?.allowMissingChains) {
112
+ continue;
113
+ }
110
114
  throw new SdkMissingChainStateError(network);
111
115
  }
112
116
  const perChainOpts = options?.perChain?.[network] ?? {};
@@ -223,10 +223,18 @@ class OnchainSDK extends ChainContractsRegister {
223
223
  this.logger?.info("hydrated sdk state");
224
224
  this.#attached = true;
225
225
  }
226
- /** Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`). */
226
+ /**
227
+ * Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`).
228
+ **/
227
229
  get networkType() {
228
230
  return this.client.chain.network;
229
231
  }
232
+ /**
233
+ * Whether the SDK has been initialised via {@link attach} or {@link hydrate}.
234
+ **/
235
+ get attached() {
236
+ return this.#attached;
237
+ }
230
238
  /**
231
239
  * Returns a human-readable snapshot of the entire SDK state.
232
240
  * @param raw - When `true`, include raw numeric values alongside formatted ones.
@@ -72,6 +72,14 @@ export interface MultichainHydrateOptions {
72
72
  * Options for Pyth price-feed updates (shared cache across chains).
73
73
  **/
74
74
  pyth?: PythOptions;
75
+ /**
76
+ * When `true`, chains missing from the serialised state are silently skipped
77
+ * instead of throwing {@link SdkMissingChainStateError}.
78
+ *
79
+ * Useful when a deprecated chain is no longer included in cached state snapshots
80
+ * but users still need it in legacy mode to exit existing positions.
81
+ **/
82
+ allowMissingChains?: boolean;
75
83
  }
76
84
  /**
77
85
  * Options for {@link MultichainSDK.syncState}.
@@ -102,7 +110,8 @@ export declare class MultichainSDK<const Plugins extends PluginsMap = {}> {
102
110
  * @param state - Multichain serialised state.
103
111
  * @param options - Shared and per-chain hydrate options.
104
112
  * @throws {@link SdkStateVersionMismatchError} if version doesn't match.
105
- * @throws {@link SdkMissingChainStateError} if a configured chain has no state.
113
+ * @throws {@link SdkMissingChainStateError} if a configured chain has no
114
+ * state and `allowMissingChains` is not set.
106
115
  */
107
116
  hydrate(state: MultichainState<Plugins>, options?: MultichainHydrateOptions): void;
108
117
  /**
@@ -196,8 +196,14 @@ export declare class OnchainSDK<const Plugins extends PluginsMap = {}> extends C
196
196
  * @throws {@link SdkChainMismatchError} if snapshot network doesn't match.
197
197
  */
198
198
  hydrate(state: GearboxState<Plugins>, options?: HydrateOptions): void;
199
- /** Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`). */
199
+ /**
200
+ * Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`).
201
+ **/
200
202
  get networkType(): NetworkType;
203
+ /**
204
+ * Whether the SDK has been initialised via {@link attach} or {@link hydrate}.
205
+ **/
206
+ get attached(): boolean;
201
207
  /**
202
208
  * Returns a human-readable snapshot of the entire SDK state.
203
209
  * @param raw - When `true`, include raw numeric values alongside formatted ones.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.0.0-next.4",
3
+ "version": "14.0.0-next.5",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",