@gearbox-protocol/sdk 14.0.0-next.4 → 14.0.0-next.6

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.
@@ -28,8 +28,8 @@ __export(create2_exports, {
28
28
  handleSalt: () => handleSalt
29
29
  });
30
30
  module.exports = __toCommonJS(create2_exports);
31
- var import_abitype = require("abitype");
32
31
  var import_viem = require("viem");
32
+ var import_utils = require("viem/utils");
33
33
  const PUBLIC_CREATE2_FACTORY = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
34
34
  function handleSalt(salt) {
35
35
  if (salt.slice(0, 2) !== "0x" || salt.length !== 66) {
@@ -63,7 +63,7 @@ function createCreate2DeployRawTx(bytecode, salt) {
63
63
  type: "fallback"
64
64
  }
65
65
  ];
66
- const signature = (0, import_abitype.formatAbiItem)(deterministicDeployerAbi[0]);
66
+ const signature = (0, import_utils.formatAbiItem)(deterministicDeployerAbi[0]);
67
67
  const contractMethod = {
68
68
  name: "fallback",
69
69
  inputs: [],
@@ -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.
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var PythAccumulatorUpdateData_exports = {};
30
20
  __export(PythAccumulatorUpdateData_exports, {
@@ -35,7 +25,6 @@ __export(PythAccumulatorUpdateData_exports, {
35
25
  sliceAccumulatorUpdateData: () => sliceAccumulatorUpdateData
36
26
  });
37
27
  module.exports = __toCommonJS(PythAccumulatorUpdateData_exports);
38
- var import_bn = __toESM(require("bn.js"));
39
28
  var import_buffer = require("buffer");
40
29
  const ACCUMULATOR_MAGIC = "504e4155";
41
30
  const MAJOR_VERSION = 1;
@@ -43,6 +32,14 @@ const MINOR_VERSION = 0;
43
32
  const KECCAK160_HASH_SIZE = 20;
44
33
  const PRICE_FEED_MESSAGE_VARIANT = 0;
45
34
  const TWAP_MESSAGE_VARIANT = 1;
35
+ function bufToBigInt(buf) {
36
+ if (buf.length === 0) return 0n;
37
+ let result = 0n;
38
+ for (let i = 0; i < buf.length; i++) {
39
+ result = result << 8n | BigInt(buf[i]);
40
+ }
41
+ return result;
42
+ }
46
43
  function isAccumulatorUpdateData(updateBytes) {
47
44
  return updateBytes.toString("hex").slice(0, 8) === ACCUMULATOR_MAGIC && updateBytes[4] === MAJOR_VERSION && updateBytes[5] === MINOR_VERSION;
48
45
  }
@@ -55,19 +52,19 @@ function parsePriceFeedMessage(message) {
55
52
  cursor += 1;
56
53
  const feedId = message.subarray(cursor, cursor + 32);
57
54
  cursor += 32;
58
- const price = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
55
+ const price = bufToBigInt(message.subarray(cursor, cursor + 8));
59
56
  cursor += 8;
60
- const confidence = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
57
+ const confidence = bufToBigInt(message.subarray(cursor, cursor + 8));
61
58
  cursor += 8;
62
59
  const exponent = message.readInt32BE(cursor);
63
60
  cursor += 4;
64
- const publishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
61
+ const publishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
65
62
  cursor += 8;
66
- const prevPublishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
63
+ const prevPublishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
67
64
  cursor += 8;
68
- const emaPrice = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
65
+ const emaPrice = bufToBigInt(message.subarray(cursor, cursor + 8));
69
66
  cursor += 8;
70
- const emaConf = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
67
+ const emaConf = bufToBigInt(message.subarray(cursor, cursor + 8));
71
68
  cursor += 8;
72
69
  return {
73
70
  feedId,
@@ -89,19 +86,19 @@ function parseTwapMessage(message) {
89
86
  cursor += 1;
90
87
  const feedId = message.subarray(cursor, cursor + 32);
91
88
  cursor += 32;
92
- const cumulativePrice = new import_bn.default(message.subarray(cursor, cursor + 16), "be");
89
+ const cumulativePrice = bufToBigInt(message.subarray(cursor, cursor + 16));
93
90
  cursor += 16;
94
- const cumulativeConf = new import_bn.default(message.subarray(cursor, cursor + 16), "be");
91
+ const cumulativeConf = bufToBigInt(message.subarray(cursor, cursor + 16));
95
92
  cursor += 16;
96
- const numDownSlots = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
93
+ const numDownSlots = bufToBigInt(message.subarray(cursor, cursor + 8));
97
94
  cursor += 8;
98
95
  const exponent = message.readInt32BE(cursor);
99
96
  cursor += 4;
100
- const publishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
97
+ const publishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
101
98
  cursor += 8;
102
- const prevPublishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
99
+ const prevPublishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
103
100
  cursor += 8;
104
- const publishSlot = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
101
+ const publishSlot = bufToBigInt(message.subarray(cursor, cursor + 8));
105
102
  cursor += 8;
106
103
  return {
107
104
  feedId,
@@ -123,7 +123,7 @@ function splitAccumulatorUpdates(binary) {
123
123
  const msg = (0, import_PythAccumulatorUpdateData.parsePriceFeedMessage)(upd);
124
124
  results.push({
125
125
  dataFeedId: (0, import_viem.toHex)(msg.feedId),
126
- timestamp: msg.publishTime.toNumber(),
126
+ timestamp: Number(msg.publishTime),
127
127
  data: (0, import_viem.toHex)((0, import_PythAccumulatorUpdateData.sliceAccumulatorUpdateData)(data, i, i + 1))
128
128
  });
129
129
  }
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var formatter_exports = {};
30
20
  __export(formatter_exports, {
@@ -42,12 +32,10 @@ __export(formatter_exports, {
42
32
  shortAddress: () => shortAddress,
43
33
  shortHash: () => shortHash,
44
34
  toBN: () => toBN,
45
- toBigInt: () => toBigInt,
46
- toSignificant: () => toSignificant
35
+ toBigInt: () => toBigInt
47
36
  });
48
37
  module.exports = __toCommonJS(formatter_exports);
49
38
  var import_date_fns = require("date-fns");
50
- var import_decimal = __toESM(require("decimal.js-light"));
51
39
  var import_constants = require("../constants/index.js");
52
40
  const toBigInt = (v) => {
53
41
  const value = typeof v === "object" && v.type === "BigNumber" ? v.hex : v.toString();
@@ -151,17 +139,22 @@ function formatTimestamp(timestamp, raw = true) {
151
139
  function rayToNumber(num) {
152
140
  return Number(toBigInt(num) / 10n ** 21n) / 1e6;
153
141
  }
154
- function toSignificant(num, decimals, precision = 6) {
155
- if (num === 1n) return "0";
156
- const divider = new import_decimal.default(10).toPower(decimals);
157
- const number = new import_decimal.default(num.toString()).div(divider);
158
- return number.toSignificantDigits(precision, 4).toString();
159
- }
160
142
  function toBN(num, decimals) {
161
143
  if (num === "") return 0n;
162
- const multiplier = new import_decimal.default(10).toPower(decimals);
163
- const number = new import_decimal.default(num).mul(multiplier);
164
- return BigInt(number.toFixed(0));
144
+ const negative = num.startsWith("-");
145
+ const abs = negative ? num.slice(1) : num;
146
+ const [intPart = "0", fracPart = ""] = abs.split(".");
147
+ let frac = fracPart;
148
+ let roundUp = false;
149
+ if (frac.length > decimals) {
150
+ roundUp = frac.charCodeAt(decimals) >= 53;
151
+ frac = frac.slice(0, decimals);
152
+ } else {
153
+ frac = frac.padEnd(decimals, "0");
154
+ }
155
+ let result = BigInt(intPart + frac);
156
+ if (roundUp) result += 1n;
157
+ return negative ? -result : result;
165
158
  }
166
159
  function shortAddress(address) {
167
160
  return address === void 0 ? "" : `${address.slice(0, 6)}...${address.slice(address.length - 4)}`;
@@ -191,6 +184,5 @@ function formatLeverage(leverage, decimals = 2) {
191
184
  shortAddress,
192
185
  shortHash,
193
186
  toBN,
194
- toBigInt,
195
- toSignificant
187
+ toBigInt
196
188
  });
@@ -1,8 +1,8 @@
1
- import { formatAbiItem } from "abitype";
2
1
  import {
3
2
  getCreate2Address,
4
3
  stringToHex
5
4
  } from "viem";
5
+ import { formatAbiItem } from "viem/utils";
6
6
  const PUBLIC_CREATE2_FACTORY = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
7
7
  function handleSalt(salt) {
8
8
  if (salt.slice(0, 2) !== "0x" || salt.length !== 66) {
@@ -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.
@@ -1,4 +1,3 @@
1
- import BN from "bn.js";
2
1
  import { Buffer } from "buffer";
3
2
  const ACCUMULATOR_MAGIC = "504e4155";
4
3
  const MAJOR_VERSION = 1;
@@ -6,6 +5,14 @@ const MINOR_VERSION = 0;
6
5
  const KECCAK160_HASH_SIZE = 20;
7
6
  const PRICE_FEED_MESSAGE_VARIANT = 0;
8
7
  const TWAP_MESSAGE_VARIANT = 1;
8
+ function bufToBigInt(buf) {
9
+ if (buf.length === 0) return 0n;
10
+ let result = 0n;
11
+ for (let i = 0; i < buf.length; i++) {
12
+ result = result << 8n | BigInt(buf[i]);
13
+ }
14
+ return result;
15
+ }
9
16
  function isAccumulatorUpdateData(updateBytes) {
10
17
  return updateBytes.toString("hex").slice(0, 8) === ACCUMULATOR_MAGIC && updateBytes[4] === MAJOR_VERSION && updateBytes[5] === MINOR_VERSION;
11
18
  }
@@ -18,19 +25,19 @@ function parsePriceFeedMessage(message) {
18
25
  cursor += 1;
19
26
  const feedId = message.subarray(cursor, cursor + 32);
20
27
  cursor += 32;
21
- const price = new BN(message.subarray(cursor, cursor + 8), "be");
28
+ const price = bufToBigInt(message.subarray(cursor, cursor + 8));
22
29
  cursor += 8;
23
- const confidence = new BN(message.subarray(cursor, cursor + 8), "be");
30
+ const confidence = bufToBigInt(message.subarray(cursor, cursor + 8));
24
31
  cursor += 8;
25
32
  const exponent = message.readInt32BE(cursor);
26
33
  cursor += 4;
27
- const publishTime = new BN(message.subarray(cursor, cursor + 8), "be");
34
+ const publishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
28
35
  cursor += 8;
29
- const prevPublishTime = new BN(message.subarray(cursor, cursor + 8), "be");
36
+ const prevPublishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
30
37
  cursor += 8;
31
- const emaPrice = new BN(message.subarray(cursor, cursor + 8), "be");
38
+ const emaPrice = bufToBigInt(message.subarray(cursor, cursor + 8));
32
39
  cursor += 8;
33
- const emaConf = new BN(message.subarray(cursor, cursor + 8), "be");
40
+ const emaConf = bufToBigInt(message.subarray(cursor, cursor + 8));
34
41
  cursor += 8;
35
42
  return {
36
43
  feedId,
@@ -52,19 +59,19 @@ function parseTwapMessage(message) {
52
59
  cursor += 1;
53
60
  const feedId = message.subarray(cursor, cursor + 32);
54
61
  cursor += 32;
55
- const cumulativePrice = new BN(message.subarray(cursor, cursor + 16), "be");
62
+ const cumulativePrice = bufToBigInt(message.subarray(cursor, cursor + 16));
56
63
  cursor += 16;
57
- const cumulativeConf = new BN(message.subarray(cursor, cursor + 16), "be");
64
+ const cumulativeConf = bufToBigInt(message.subarray(cursor, cursor + 16));
58
65
  cursor += 16;
59
- const numDownSlots = new BN(message.subarray(cursor, cursor + 8), "be");
66
+ const numDownSlots = bufToBigInt(message.subarray(cursor, cursor + 8));
60
67
  cursor += 8;
61
68
  const exponent = message.readInt32BE(cursor);
62
69
  cursor += 4;
63
- const publishTime = new BN(message.subarray(cursor, cursor + 8), "be");
70
+ const publishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
64
71
  cursor += 8;
65
- const prevPublishTime = new BN(message.subarray(cursor, cursor + 8), "be");
72
+ const prevPublishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
66
73
  cursor += 8;
67
- const publishSlot = new BN(message.subarray(cursor, cursor + 8), "be");
74
+ const publishSlot = bufToBigInt(message.subarray(cursor, cursor + 8));
68
75
  cursor += 8;
69
76
  return {
70
77
  feedId,
@@ -104,7 +104,7 @@ function splitAccumulatorUpdates(binary) {
104
104
  const msg = parsePriceFeedMessage(upd);
105
105
  results.push({
106
106
  dataFeedId: toHex(msg.feedId),
107
- timestamp: msg.publishTime.toNumber(),
107
+ timestamp: Number(msg.publishTime),
108
108
  data: toHex(sliceAccumulatorUpdateData(data, i, i + 1))
109
109
  });
110
110
  }
@@ -1,5 +1,4 @@
1
1
  import { formatDuration as fmtDuration, intervalToDuration } from "date-fns";
2
- import Decimal from "decimal.js-light";
3
2
  import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR } from "../constants/index.js";
4
3
  const toBigInt = (v) => {
5
4
  const value = typeof v === "object" && v.type === "BigNumber" ? v.hex : v.toString();
@@ -103,17 +102,22 @@ function formatTimestamp(timestamp, raw = true) {
103
102
  function rayToNumber(num) {
104
103
  return Number(toBigInt(num) / 10n ** 21n) / 1e6;
105
104
  }
106
- function toSignificant(num, decimals, precision = 6) {
107
- if (num === 1n) return "0";
108
- const divider = new Decimal(10).toPower(decimals);
109
- const number = new Decimal(num.toString()).div(divider);
110
- return number.toSignificantDigits(precision, 4).toString();
111
- }
112
105
  function toBN(num, decimals) {
113
106
  if (num === "") return 0n;
114
- const multiplier = new Decimal(10).toPower(decimals);
115
- const number = new Decimal(num).mul(multiplier);
116
- return BigInt(number.toFixed(0));
107
+ const negative = num.startsWith("-");
108
+ const abs = negative ? num.slice(1) : num;
109
+ const [intPart = "0", fracPart = ""] = abs.split(".");
110
+ let frac = fracPart;
111
+ let roundUp = false;
112
+ if (frac.length > decimals) {
113
+ roundUp = frac.charCodeAt(decimals) >= 53;
114
+ frac = frac.slice(0, decimals);
115
+ } else {
116
+ frac = frac.padEnd(decimals, "0");
117
+ }
118
+ let result = BigInt(intPart + frac);
119
+ if (roundUp) result += 1n;
120
+ return negative ? -result : result;
117
121
  }
118
122
  function shortAddress(address) {
119
123
  return address === void 0 ? "" : `${address.slice(0, 6)}...${address.slice(address.length - 4)}`;
@@ -142,6 +146,5 @@ export {
142
146
  shortAddress,
143
147
  shortHash,
144
148
  toBN,
145
- toBigInt,
146
- toSignificant
149
+ toBigInt
147
150
  };
@@ -1,5 +1,4 @@
1
- import type { Abi } from "abitype";
2
- import type { Account, Address, Chain, Client, ContractConstructorArgs, GetChainParameter, Hash, Hex, SendTransactionParameters, SendTransactionReturnType, Transport, UnionEvaluate, UnionOmit, WalletClient } from "viem";
1
+ import type { Abi, Account, Address, Chain, Client, ContractConstructorArgs, GetChainParameter, Hash, Hex, SendTransactionParameters, SendTransactionReturnType, Transport, UnionEvaluate, UnionOmit, WalletClient } from "viem";
3
2
  import type { OnchainSDK } from "../sdk/index.js";
4
3
  import { Construct } from "../sdk/index.js";
5
4
  export declare const PUBLIC_CREATE2_FACTORY: Address;
@@ -1,4 +1,4 @@
1
- import type { Abi } from "abitype";
1
+ import type { Abi } from "viem";
2
2
  import { type ContractFunctionArgs, type ContractFunctionName, type ContractFunctionParameters, type ReadContractReturnType } from "viem";
3
3
  import type { AnvilClient } from "./createAnvilClient.js";
4
4
  export type ReplaceStorageParams<abi extends Abi | readonly unknown[] = Abi, functionName extends ContractFunctionName<abi, "pure" | "view"> = ContractFunctionName<abi, "pure" | "view">, args extends ContractFunctionArgs<abi, "pure" | "view", functionName> = ContractFunctionArgs<abi, "pure" | "view", functionName>> = ContractFunctionParameters<abi, "pure" | "view", functionName, args, false> & {
@@ -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.
@@ -1,4 +1,4 @@
1
- import type { Address } from "abitype";
1
+ import type { Address } from "viem";
2
2
  import type { CreditManagerState, IBaseContract } from "../../base/index.js";
3
3
  import type { CreditConfiguratorStateHuman, CreditManagerStateHuman } from "../../types/index.js";
4
4
  import type { AddressMap } from "../../utils/index.js";
@@ -2,7 +2,6 @@
2
2
  * This is https://github.com/pyth-network/pyth-crosschain/blob/main/price_service/sdk/js/src/AccumulatorUpdateData.ts
3
3
  * modified to use buffer from npm package
4
4
  */
5
- import BN from "bn.js";
6
5
  import { Buffer } from "buffer";
7
6
  export type AccumulatorUpdateData = {
8
7
  vaa: Buffer;
@@ -13,23 +12,23 @@ export type AccumulatorUpdateData = {
13
12
  };
14
13
  export type PriceFeedMessage = {
15
14
  feedId: Buffer;
16
- price: BN;
17
- confidence: BN;
15
+ price: bigint;
16
+ confidence: bigint;
18
17
  exponent: number;
19
- publishTime: BN;
20
- prevPublishTime: BN;
21
- emaPrice: BN;
22
- emaConf: BN;
18
+ publishTime: bigint;
19
+ prevPublishTime: bigint;
20
+ emaPrice: bigint;
21
+ emaConf: bigint;
23
22
  };
24
23
  export type TwapMessage = {
25
24
  feedId: Buffer;
26
- cumulativePrice: BN;
27
- cumulativeConf: BN;
28
- numDownSlots: BN;
25
+ cumulativePrice: bigint;
26
+ cumulativeConf: bigint;
27
+ numDownSlots: bigint;
29
28
  exponent: number;
30
- publishTime: BN;
31
- prevPublishTime: BN;
32
- publishSlot: BN;
29
+ publishTime: bigint;
30
+ prevPublishTime: bigint;
31
+ publishSlot: bigint;
33
32
  };
34
33
  export declare function isAccumulatorUpdateData(updateBytes: Buffer): boolean;
35
34
  export declare function parsePriceFeedMessage(message: Buffer): PriceFeedMessage;
@@ -1,5 +1,4 @@
1
- import type { Abi } from "abitype";
2
- import type { Address, ContractFunctionArgs, ContractFunctionName } from "viem";
1
+ import type { Abi, Address, ContractFunctionArgs, ContractFunctionName } from "viem";
3
2
  import type { ZapperData } from "../market/index.js";
4
3
  import type { Asset } from "../router/index.js";
5
4
  interface PermitResult {
@@ -1,4 +1,4 @@
1
- import type { Address } from "abitype";
1
+ import type { Address } from "viem";
2
2
  import { AddressMap } from "../utils/index.js";
3
3
  import type { Asset } from "./types.js";
4
4
  export declare function balancesMap(assets: Array<Asset>): AddressMap<bigint>;
@@ -12,7 +12,6 @@ export declare function formatNumberToString_(value: bigint | number): string;
12
12
  export declare function formatTimestamp(timestamp: number, raw?: boolean): string;
13
13
  type BigNumberish = bigint | number | string;
14
14
  export declare function rayToNumber(num: BigNumberish): number;
15
- export declare function toSignificant(num: bigint, decimals: number, precision?: number): string;
16
15
  export declare function toBN(num: string, decimals: number): bigint;
17
16
  export declare function shortAddress(address?: string): string;
18
17
  export declare function shortHash(address?: string): string;
@@ -1,3 +1,3 @@
1
- import type { Address } from "abitype";
1
+ import type { Address } from "viem";
2
2
  import type { BaseState, IBaseContract } from "../base/index.js";
3
3
  export declare function toAddress(value: Address | BaseState | IBaseContract): Address;
@@ -1,5 +1,4 @@
1
- import type { AbiEvent } from "abitype";
2
- import type { BlockNumber, Chain, Client, GetLogsParameters, GetLogsReturnType, MaybeAbiEventName, Transport } from "viem";
1
+ import type { AbiEvent, BlockNumber, Chain, Client, GetLogsParameters, GetLogsReturnType, MaybeAbiEventName, Transport } from "viem";
3
2
  export type GetLogsPaginatedParameters<abiEvent extends AbiEvent | undefined = undefined, abiEvents extends readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined, _eventName extends string | undefined = MaybeAbiEventName<abiEvent>> = GetLogsParameters<abiEvent, abiEvents, strict, BlockNumber, BlockNumber, _eventName> & {
4
3
  pageSize: bigint;
5
4
  };
@@ -1,3 +1,3 @@
1
- import type { AbiEvent } from "abitype";
1
+ import type { AbiEvent } from "viem";
2
2
  import { type BlockNumber, type Chain, type Client, type GetLogsParameters, type GetLogsReturnType, type Transport } from "viem";
3
3
  export declare function getLogsSafe<chain extends Chain | undefined, const abiEvent extends AbiEvent | undefined = undefined, const abiEvents extends readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined>(client: Client<Transport, chain>, params?: GetLogsParameters<abiEvent, abiEvents, strict, BlockNumber, BlockNumber>): Promise<GetLogsReturnType<abiEvent, abiEvents, strict, BlockNumber, BlockNumber>>;
@@ -1,5 +1,4 @@
1
- import type { Narrow } from "abitype";
2
- import type { CallParameters, Chain, Client, ContractFunctionParameters, MulticallContracts, MulticallReturnType, Transport } from "viem";
1
+ import type { CallParameters, Chain, Client, ContractFunctionParameters, MulticallContracts, MulticallReturnType, Narrow, Transport } from "viem";
3
2
  import { BaseError } from "viem";
4
3
  import type { IPriceUpdateTx } from "../../types/index.js";
5
4
  import type { SimulateMulticallParameters } from "./simulateMulticall.js";
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.6",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -79,21 +79,17 @@
79
79
  "@redstone-finance/protocol": "^0.9.0",
80
80
  "@redstone-finance/sdk": "^0.9.0",
81
81
  "@redstone-finance/utils": "^0.9.0",
82
- "@types/bn.js": "^5.2.0",
83
82
  "abitype": "^1.2.3",
84
- "bn.js": "^5.2.3",
85
83
  "buffer": "^6.0.3",
86
84
  "date-fns": "^4.1.0",
87
- "decimal.js-light": "^2.5.1",
88
85
  "viem": ">=2.23.15 <3.0.0",
89
- "yaml": "^2.8.3",
90
86
  "zod": "^4.3.6"
91
87
  },
92
88
  "devDependencies": {
93
- "@biomejs/biome": "^2.4.11",
89
+ "@biomejs/biome": "^2.4.12",
94
90
  "@commitlint/cli": "^20.5.0",
95
91
  "@commitlint/config-conventional": "^20.5.0",
96
- "@gearbox-protocol/biome-config": "^1.0.26",
92
+ "@gearbox-protocol/biome-config": "^1.0.27",
97
93
  "@types/cross-spawn": "^6.0.6",
98
94
  "axios": "^1.15.0",
99
95
  "cross-spawn": "^7.0.6",
@@ -106,7 +102,8 @@
106
102
  "typescript": "^6.0.2",
107
103
  "viem-deal": "^2.0.4",
108
104
  "vite": "^8.0.8",
109
- "vitest": "^4.1.4"
105
+ "vitest": "^4.1.4",
106
+ "yaml": "^2.8.3"
110
107
  },
111
108
  "peerDependencies": {
112
109
  "axios": "^1.0.0",