aftermath-ts-sdk 1.2.63 → 1.2.64-docs.0

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 (117) hide show
  1. package/README.md +61 -27
  2. package/dist/general/dynamicGas/dynamicGas.d.ts +34 -0
  3. package/dist/general/dynamicGas/dynamicGas.d.ts.map +1 -1
  4. package/dist/general/dynamicGas/dynamicGas.js +34 -0
  5. package/dist/general/dynamicGas/dynamicGasTypes.d.ts +25 -0
  6. package/dist/general/dynamicGas/dynamicGasTypes.d.ts.map +1 -1
  7. package/dist/general/prices/prices.d.ts +73 -0
  8. package/dist/general/prices/prices.d.ts.map +1 -1
  9. package/dist/general/prices/prices.js +73 -0
  10. package/dist/general/providers/aftermath.d.ts +106 -25
  11. package/dist/general/providers/aftermath.d.ts.map +1 -1
  12. package/dist/general/providers/aftermath.js +108 -27
  13. package/dist/general/providers/aftermathApi.d.ts +127 -8
  14. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  15. package/dist/general/providers/aftermathApi.js +132 -12
  16. package/dist/general/types/castingTypes.d.ts +0 -7
  17. package/dist/general/types/castingTypes.d.ts.map +1 -1
  18. package/dist/general/types/castingTypes.js +6 -0
  19. package/dist/general/types/generalTypes.d.ts +228 -7
  20. package/dist/general/types/generalTypes.d.ts.map +1 -1
  21. package/dist/general/types/suiTypes.d.ts +0 -16
  22. package/dist/general/types/suiTypes.d.ts.map +1 -1
  23. package/dist/general/types/suiTypes.js +3 -25
  24. package/dist/general/utils/casting.d.ts +159 -3
  25. package/dist/general/utils/casting.d.ts.map +1 -1
  26. package/dist/general/utils/casting.js +162 -16
  27. package/dist/general/utils/fixedUtils.d.ts +89 -2
  28. package/dist/general/utils/fixedUtils.d.ts.map +1 -1
  29. package/dist/general/utils/fixedUtils.js +81 -4
  30. package/dist/general/utils/helpers.d.ts +320 -9
  31. package/dist/general/utils/helpers.d.ts.map +1 -1
  32. package/dist/general/utils/helpers.js +350 -89
  33. package/dist/general/utils/iFixedUtils.d.ts +64 -0
  34. package/dist/general/utils/iFixedUtils.d.ts.map +1 -1
  35. package/dist/general/utils/iFixedUtils.js +64 -0
  36. package/dist/general/wallet/wallet.d.ts +75 -0
  37. package/dist/general/wallet/wallet.d.ts.map +1 -1
  38. package/dist/general/wallet/wallet.js +75 -5
  39. package/dist/packages/auth/auth.d.ts +113 -0
  40. package/dist/packages/auth/auth.d.ts.map +1 -1
  41. package/dist/packages/auth/auth.js +129 -15
  42. package/dist/packages/auth/authTypes.d.ts +66 -0
  43. package/dist/packages/auth/authTypes.d.ts.map +1 -1
  44. package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
  45. package/dist/packages/coin/api/coinApi.js +28 -20
  46. package/dist/packages/coin/coin.d.ts +250 -0
  47. package/dist/packages/coin/coin.d.ts.map +1 -1
  48. package/dist/packages/coin/coin.js +238 -14
  49. package/dist/packages/coin/coinTypes.d.ts +93 -0
  50. package/dist/packages/coin/coinTypes.d.ts.map +1 -1
  51. package/dist/packages/dca/dca.d.ts +124 -35
  52. package/dist/packages/dca/dca.d.ts.map +1 -1
  53. package/dist/packages/dca/dca.js +127 -37
  54. package/dist/packages/dca/dcaTypes.d.ts +213 -28
  55. package/dist/packages/dca/dcaTypes.d.ts.map +1 -1
  56. package/dist/packages/farms/farms.d.ts +184 -1
  57. package/dist/packages/farms/farms.d.ts.map +1 -1
  58. package/dist/packages/farms/farms.js +185 -11
  59. package/dist/packages/farms/farmsStakedPosition.d.ts +140 -6
  60. package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
  61. package/dist/packages/farms/farmsStakedPosition.js +189 -144
  62. package/dist/packages/farms/farmsStakingPool.d.ts +161 -1
  63. package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
  64. package/dist/packages/farms/farmsStakingPool.js +176 -70
  65. package/dist/packages/farms/farmsTypes.d.ts +283 -2
  66. package/dist/packages/farms/farmsTypes.d.ts.map +1 -1
  67. package/dist/packages/farms/farmsTypes.js +18 -0
  68. package/dist/packages/limitOrders/limitOrders.d.ts +108 -21
  69. package/dist/packages/limitOrders/limitOrders.d.ts.map +1 -1
  70. package/dist/packages/limitOrders/limitOrders.js +110 -22
  71. package/dist/packages/limitOrders/limitOrdersTypes.d.ts +142 -0
  72. package/dist/packages/limitOrders/limitOrdersTypes.d.ts.map +1 -1
  73. package/dist/packages/multisig/multisig.d.ts +33 -4
  74. package/dist/packages/multisig/multisig.d.ts.map +1 -1
  75. package/dist/packages/multisig/multisig.js +33 -4
  76. package/dist/packages/multisig/multisigTypes.d.ts +17 -0
  77. package/dist/packages/multisig/multisigTypes.d.ts.map +1 -1
  78. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  79. package/dist/packages/pools/pool.d.ts +327 -85
  80. package/dist/packages/pools/pool.d.ts.map +1 -1
  81. package/dist/packages/pools/pool.js +333 -91
  82. package/dist/packages/pools/pools.d.ts +299 -37
  83. package/dist/packages/pools/pools.d.ts.map +1 -1
  84. package/dist/packages/pools/pools.js +306 -52
  85. package/dist/packages/pools/poolsTypes.d.ts +273 -8
  86. package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
  87. package/dist/packages/referralVault/referralVault.d.ts +37 -0
  88. package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
  89. package/dist/packages/referralVault/referralVault.js +37 -0
  90. package/dist/packages/router/router.d.ts +213 -17
  91. package/dist/packages/router/router.d.ts.map +1 -1
  92. package/dist/packages/router/router.js +214 -18
  93. package/dist/packages/router/routerTypes.d.ts +198 -14
  94. package/dist/packages/router/routerTypes.d.ts.map +1 -1
  95. package/dist/packages/staking/staking.d.ts +301 -43
  96. package/dist/packages/staking/staking.d.ts.map +1 -1
  97. package/dist/packages/staking/staking.js +308 -51
  98. package/dist/packages/staking/stakingTypes.d.ts +426 -6
  99. package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
  100. package/dist/packages/staking/stakingTypes.js +19 -0
  101. package/dist/packages/sui/sui.d.ts +39 -0
  102. package/dist/packages/sui/sui.d.ts.map +1 -1
  103. package/dist/packages/sui/sui.js +39 -0
  104. package/dist/packages/userData/userData.d.ts +66 -12
  105. package/dist/packages/userData/userData.d.ts.map +1 -1
  106. package/dist/packages/userData/userData.js +66 -12
  107. package/dist/packages/userData/userDataTypes.d.ts +19 -0
  108. package/dist/packages/userData/userDataTypes.d.ts.map +1 -1
  109. package/dist/types.d.ts.map +1 -1
  110. package/dist/types.js +0 -1
  111. package/package.json +1 -1
  112. package/dist/general/historicalData/historicalData.d.ts +0 -15
  113. package/dist/general/historicalData/historicalData.d.ts.map +0 -1
  114. package/dist/general/historicalData/historicalData.js +0 -45
  115. package/dist/general/historicalData/historicalDataTypes.d.ts +0 -10
  116. package/dist/general/historicalData/historicalDataTypes.d.ts.map +0 -1
  117. package/dist/general/historicalData/historicalDataTypes.js +0 -2
@@ -23,9 +23,19 @@ const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
23
23
  const secp256k1_1 = require("@mysten/sui/keypairs/secp256k1");
24
24
  const secp256r1_1 = require("@mysten/sui/keypairs/secp256r1");
25
25
  /**
26
- * A utility class containing various helper functions for general use.
26
+ * A utility class containing various helper functions for general use across
27
+ * the Aftermath TS ecosystem. This includes numeric operations, object field
28
+ * extraction, array transformations, slippage adjustments, and Move error parsing.
27
29
  */
28
30
  class Helpers {
31
+ /**
32
+ * Combines two arrays into a single array of pairs. The result length is the
33
+ * minimum of the two input arrays' lengths.
34
+ *
35
+ * @param firstCollection - The first array.
36
+ * @param lastCollection - The second array.
37
+ * @returns An array of `[firstCollection[i], lastCollection[i]]` pairs.
38
+ */
29
39
  static zip(firstCollection, lastCollection) {
30
40
  const length = Math.min(firstCollection.length, lastCollection.length);
31
41
  const zipped = [];
@@ -34,10 +44,18 @@ class Helpers {
34
44
  }
35
45
  return zipped;
36
46
  }
47
+ /**
48
+ * Removes circular references from an object or array, returning a JSON-safe structure.
49
+ * Any cyclic references are replaced with `undefined`.
50
+ *
51
+ * @param obj - The object or array to remove circular references from.
52
+ * @param seen - Internal usage to track references that have already been visited.
53
+ * @returns A structure that can be safely JSON-stringified.
54
+ */
37
55
  static removeCircularReferences(obj, seen = new WeakSet()) {
38
56
  if (obj && typeof obj === "object") {
39
57
  if (seen.has(obj)) {
40
- return undefined; // Circular reference found, skip it
58
+ return undefined;
41
59
  }
42
60
  seen.add(obj);
43
61
  if (Array.isArray(obj)) {
@@ -56,6 +74,12 @@ class Helpers {
56
74
  // =========================================================================
57
75
  // Type Checking
58
76
  // =========================================================================
77
+ /**
78
+ * Checks if an unknown value is an array of strings.
79
+ *
80
+ * @param value - The value to check.
81
+ * @returns `true` if `value` is a string array, otherwise `false`.
82
+ */
59
83
  static isArrayOfStrings(value) {
60
84
  return (Array.isArray(value) &&
61
85
  value.every((item) => typeof item === "string"));
@@ -63,14 +87,28 @@ class Helpers {
63
87
  // =========================================================================
64
88
  // Sui Object Parsing
65
89
  // =========================================================================
90
+ /**
91
+ * Extracts the fully qualified type (e.g., "0x2::coin::Coin<...>") from a `SuiObjectResponse`,
92
+ * normalizing it with leading zeroes if necessary.
93
+ *
94
+ * @param data - The object response from Sui.
95
+ * @returns The normalized object type string.
96
+ * @throws If the type is not found.
97
+ */
66
98
  static getObjectType(data) {
67
99
  var _b, _c;
68
100
  const objectType = (_b = data.data) === null || _b === void 0 ? void 0 : _b.type;
69
- // NOTE: should `Helpers.addLeadingZeroesToType` not be used here ?
70
101
  if (objectType)
71
102
  return Helpers.addLeadingZeroesToType(objectType);
72
103
  throw new Error("no object type found on " + ((_c = data.data) === null || _c === void 0 ? void 0 : _c.objectId));
73
104
  }
105
+ /**
106
+ * Extracts the object ID from a `SuiObjectResponse`, normalizing it with leading zeroes.
107
+ *
108
+ * @param data - The object response from Sui.
109
+ * @returns A zero-padded `ObjectId`.
110
+ * @throws If the objectId is not found.
111
+ */
74
112
  static getObjectId(data) {
75
113
  var _b, _c;
76
114
  const objectId = (_b = data.data) === null || _b === void 0 ? void 0 : _b.objectId;
@@ -78,6 +116,13 @@ class Helpers {
78
116
  return Helpers.addLeadingZeroesToType(objectId);
79
117
  throw new Error("no object id found on " + ((_c = data.data) === null || _c === void 0 ? void 0 : _c.type));
80
118
  }
119
+ /**
120
+ * Retrieves the fields of a Move object from a `SuiObjectResponse`.
121
+ *
122
+ * @param data - The Sui object response containing a Move object.
123
+ * @returns A record of fields for that object.
124
+ * @throws If no fields are found.
125
+ */
81
126
  static getObjectFields(data) {
82
127
  var _b, _c;
83
128
  try {
@@ -88,6 +133,13 @@ class Helpers {
88
133
  throw new Error("no object fields found on " + ((_c = data.data) === null || _c === void 0 ? void 0 : _c.objectId));
89
134
  }
90
135
  }
136
+ /**
137
+ * Retrieves display metadata from a Sui object response, if present.
138
+ *
139
+ * @param data - The Sui object response.
140
+ * @returns The display fields for that object.
141
+ * @throws If display fields are not found.
142
+ */
91
143
  static getObjectDisplay(data) {
92
144
  var _b, _c;
93
145
  const display = (_b = data.data) === null || _b === void 0 ? void 0 : _b.display;
@@ -98,13 +150,17 @@ class Helpers {
98
150
  // =========================================================================
99
151
  // Error Parsing
100
152
  // =========================================================================
153
+ /**
154
+ * Parses a MoveAbort error message from Sui into a possible `(errorCode, packageId, module)`,
155
+ * if the message follows a known pattern. Otherwise returns undefined.
156
+ *
157
+ * @param inputs - The object containing the raw `errorMessage` from Sui.
158
+ * @returns A partial structure of the error details or undefined.
159
+ */
101
160
  static parseMoveErrorMessage(inputs) {
102
161
  const { errorMessage } = inputs;
103
162
  if (!errorMessage.toLowerCase().includes("moveabort"))
104
163
  return undefined;
105
- /*
106
- MoveAbort(MoveLocation { module: ModuleId { address: 8d8946c2a433e2bf795414498d9f7b32e04aca8dbf35a20257542dc51406242b, name: Identifier("orderbook") }, function: 11, instruction: 117, function_name: Some("fill_market_order") }, 3005) in command 2
107
- */
108
164
  const moveErrorCode = (inputs) => {
109
165
  const { errorMessage } = inputs;
110
166
  const startIndex = errorMessage.lastIndexOf(",");
@@ -117,7 +173,7 @@ class Helpers {
117
173
  return undefined;
118
174
  return errorCode;
119
175
  }
120
- catch (e) {
176
+ catch (_b) {
121
177
  return undefined;
122
178
  }
123
179
  };
@@ -128,16 +184,16 @@ class Helpers {
128
184
  if (startIndex <= 0 || endIndex <= 0 || startIndex >= endIndex)
129
185
  return undefined;
130
186
  try {
131
- const packageId = Helpers.addLeadingZeroesToType("0x" +
132
- errorMessage
133
- .slice(startIndex + 8, endIndex)
134
- .trim()
135
- .replaceAll("0x", ""));
187
+ const pkgStr = errorMessage
188
+ .slice(startIndex + 8, endIndex)
189
+ .trim()
190
+ .replaceAll("0x", "");
191
+ const packageId = Helpers.addLeadingZeroesToType("0x" + pkgStr);
136
192
  if (!this.isValidHex(packageId))
137
193
  return undefined;
138
194
  return packageId;
139
195
  }
140
- catch (e) {
196
+ catch (_b) {
141
197
  return undefined;
142
198
  }
143
199
  };
@@ -152,32 +208,25 @@ class Helpers {
152
208
  try {
153
209
  return errorMessage.slice(startIndex + 12, endIndex).trim();
154
210
  }
155
- catch (e) {
211
+ catch (_b) {
156
212
  return undefined;
157
213
  }
158
214
  };
159
- try {
160
- const errorCode = moveErrorCode({
161
- errorMessage,
162
- });
163
- const packageId = moveErrorPackageId({
164
- errorMessage,
165
- });
166
- const module = moveErrorModule({
167
- errorMessage,
168
- });
169
- if (errorCode === undefined || !packageId || !module)
170
- return undefined;
171
- return {
172
- errorCode,
173
- packageId,
174
- module,
175
- };
176
- }
177
- catch (e) {
215
+ const errorCode = moveErrorCode({ errorMessage });
216
+ const packageId = moveErrorPackageId({ errorMessage });
217
+ const module = moveErrorModule({ errorMessage });
218
+ if (errorCode === undefined || !packageId || !module)
178
219
  return undefined;
179
- }
220
+ return { errorCode, packageId, module };
180
221
  }
222
+ /**
223
+ * Translates a Move abort error message into a known error string if it matches
224
+ * entries in a given `moveErrors` table. This is used to map on-chain error codes
225
+ * to user-friendly messages.
226
+ *
227
+ * @param inputs - Includes the raw `errorMessage` and a `moveErrors` object keyed by package, module, and code.
228
+ * @returns A structure with `errorCode`, `packageId`, `module`, and a human-readable `error` string, or `undefined`.
229
+ */
181
230
  static translateMoveErrorMessage(inputs) {
182
231
  const { errorMessage, moveErrors } = inputs;
183
232
  const parsed = this.parseMoveErrorMessage({ errorMessage });
@@ -192,32 +241,53 @@ class Helpers {
192
241
  exports.Helpers = Helpers;
193
242
  _a = Helpers;
194
243
  // =========================================================================
195
- // Api Helpers
244
+ // Api Helpers (Static References)
196
245
  // =========================================================================
246
+ /**
247
+ * Static reference to the `DynamicFieldsApiHelpers`, providing utility methods
248
+ * for working with dynamic fields in Sui objects.
249
+ */
197
250
  Helpers.dynamicFields = dynamicFieldsApiHelpers_1.DynamicFieldsApiHelpers;
251
+ /**
252
+ * Static reference to the `EventsApiHelpers`, providing methods for
253
+ * querying and filtering Sui events.
254
+ */
198
255
  Helpers.events = eventsApiHelpers_1.EventsApiHelpers;
256
+ /**
257
+ * Static reference to the `InspectionsApiHelpers`, used for reading
258
+ * Summaries or inspection data from objects.
259
+ */
199
260
  Helpers.inspections = inspectionsApiHelpers_1.InspectionsApiHelpers;
261
+ /**
262
+ * Static reference to the `ObjectsApiHelpers`, providing direct
263
+ * retrieval or manipulation of on-chain Sui objects.
264
+ */
200
265
  Helpers.objects = objectsApiHelpers_1.ObjectsApiHelpers;
266
+ /**
267
+ * Static reference to the `TransactionsApiHelpers`, enabling easier
268
+ * queries for transaction data by digest or other criteria.
269
+ */
201
270
  Helpers.transactions = transactionsApiHelpers_1.TransactionsApiHelpers;
202
271
  // =========================================================================
203
272
  // Type Manipulation
204
273
  // =========================================================================
205
274
  /**
206
- * Removes leading zeroes from the hexadecimal representation of a given object type.
207
- * @param type - The object type to strip leading zeroes from.
208
- * @returns The object type with leading zeroes removed from its hexadecimal representation.
275
+ * Removes all leading zeroes (after the '0x') from a string that represents
276
+ * a Sui address or object type. For instance, "0x0000123" => "0x123".
277
+ *
278
+ * @param type - The hex string to process, potentially including "::" module syntax.
279
+ * @returns The same string with unnecessary leading zeroes stripped out.
209
280
  */
210
281
  Helpers.stripLeadingZeroesFromType = (type) => type.replaceAll(/x0+/g, "x");
211
282
  /**
212
- * Adds leading zeroes to a given `AnyObjectType` until it reaches a length of 64 characters.
213
- * If the input type already has a length greater than 64, an error is thrown.
214
- * @param type - The `AnyObjectType` to add leading zeroes to.
215
- * @returns The modified `AnyObjectType` with leading zeroes added.
216
- * @throws An error if the input type has a length greater than 64.
283
+ * Ensures the given Sui address or object type is zero-padded to 64 hex digits
284
+ * after the "0x". If a "::" suffix is present, only the address portion is padded.
285
+ *
286
+ * @param type - The "0x..." string or extended type (0x..::module).
287
+ * @returns A new string normalized to a 64-hex-digit address or object ID.
288
+ * @throws If the address portion is already longer than 64 hex digits.
217
289
  */
218
290
  Helpers.addLeadingZeroesToType = (type) => {
219
- // NOTE: is this safe to add ?
220
- // if (!Helpers.isValidType(type)) return type;
221
291
  const EXPECTED_TYPE_LENGTH = 64;
222
292
  let strippedType = type.replace("0x", "");
223
293
  let typeSuffix = "";
@@ -231,12 +301,18 @@ Helpers.addLeadingZeroesToType = (type) => {
231
301
  const typeLength = strippedType.length;
232
302
  if (typeLength > EXPECTED_TYPE_LENGTH)
233
303
  throw new Error("invalid type length");
234
- const zeros = Array(EXPECTED_TYPE_LENGTH - typeLength)
235
- .fill("0")
236
- .reduce((acc, val) => acc + val, "");
237
- const newType = "0x" + zeros + strippedType;
304
+ const zerosNeeded = EXPECTED_TYPE_LENGTH - typeLength;
305
+ const zeroString = Array(zerosNeeded).fill("0").join("");
306
+ const newType = "0x" + zeroString + strippedType;
238
307
  return newType + typeSuffix;
239
308
  };
309
+ /**
310
+ * Splits a non-SUI coin type string that may be prefixed by a chain ID for external usage,
311
+ * returning the chain and the coin type. If no chain is recognized, defaults to `"sui"`.
312
+ *
313
+ * @param coin - The coin string, which may look like `"bsc:0x<...>"` or just `"0x<...>"`.
314
+ * @returns An object with the `chain` (e.g. "bsc") and the `coinType`.
315
+ */
240
316
  Helpers.splitNonSuiCoinType = (coin) => {
241
317
  const [uncastChain, coinType] = coin.split(":");
242
318
  if (!uncastChain || !coinType)
@@ -247,30 +323,132 @@ Helpers.splitNonSuiCoinType = (coin) => {
247
323
  // =========================================================================
248
324
  // Numbers
249
325
  // =========================================================================
326
+ /**
327
+ * Checks if a given string represents a valid number (integer or decimal).
328
+ *
329
+ * @param str - The string to test.
330
+ * @returns `true` if it's a valid numeric string, otherwise `false`.
331
+ */
250
332
  Helpers.isNumber = (str) => /^\d*\.?\d*$/g.test(str);
333
+ /**
334
+ * Sums an array of floating-point numbers, returning the numeric total.
335
+ *
336
+ * @param arr - The array of numbers to sum.
337
+ * @returns The total as a float.
338
+ */
251
339
  Helpers.sum = (arr) => arr.reduce((prev, cur) => prev + cur, 0);
340
+ /**
341
+ * Sums an array of bigints, returning the total as a bigint.
342
+ *
343
+ * @param arr - The array of bigints to sum.
344
+ * @returns The resulting total as a bigint.
345
+ */
252
346
  Helpers.sumBigInt = (arr) => arr.reduce((prev, cur) => prev + cur, BigInt(0));
347
+ /**
348
+ * Determines if two numbers are close within a given tolerance factor,
349
+ * i.e., `|a - b| <= tolerance * max(a, b)`.
350
+ *
351
+ * @param a - The first number.
352
+ * @param b - The second number.
353
+ * @param tolerance - A fraction representing the max allowed difference relative to max(a, b).
354
+ * @returns `true` if within tolerance, otherwise `false`.
355
+ */
253
356
  Helpers.closeEnough = (a, b, tolerance) => Math.abs(a - b) <= tolerance * Math.max(a, b);
357
+ /**
358
+ * Determines if two bigints are close within a given tolerance factor,
359
+ * by casting them to numbers internally.
360
+ *
361
+ * @param a - First bigint.
362
+ * @param b - Second bigint.
363
+ * @param tolerance - A fraction representing the max allowed difference relative to max(a, b).
364
+ * @returns `true` if within tolerance, otherwise `false`.
365
+ */
254
366
  Helpers.closeEnoughBigInt = (a, b, tolerance) => Helpers.closeEnough(Number(a), Number(b), tolerance);
367
+ /**
368
+ * Checks whether the integer divisions of `a` and `b` (by `fixedOne`) differ
369
+ * by at most 1. Typically used in fixed math scenarios to see if two scaled
370
+ * values are "very close."
371
+ *
372
+ * @param a - First number (scaled).
373
+ * @param b - Second number (scaled).
374
+ * @param fixedOne - The scaling factor representing 1.0 in the same scale as `a` and `b`.
375
+ * @returns `true` if the integer parts differ by <= 1, otherwise `false`.
376
+ */
255
377
  Helpers.veryCloseInt = (a, b, fixedOne) => Math.abs(Math.floor(a / fixedOne) - Math.floor(b / fixedOne)) <= 1;
378
+ /**
379
+ * A small object containing "blended" math operations that handle
380
+ * mixed numeric types (number vs. bigint). This is primarily for
381
+ * internal usage in advanced math scenarios.
382
+ */
256
383
  Helpers.blendedOperations = {
384
+ /**
385
+ * Multiply two floating-point numbers.
386
+ */
257
387
  mulNNN: (a, b) => a * b,
388
+ /**
389
+ * Multiply a float and a bigint, returning a bigint (floor).
390
+ */
258
391
  mulNNB: (a, b) => BigInt(Math.floor(a * b)),
392
+ /**
393
+ * Multiply a float and a bigint, returning a float.
394
+ */
259
395
  mulNBN: (a, b) => a * Number(b),
396
+ /**
397
+ * Multiply a float and a bigint, returning a bigint (floor).
398
+ */
260
399
  mulNBB: (a, b) => BigInt(Math.floor(a * Number(b))),
400
+ /**
401
+ * Multiply two bigints, returning a float.
402
+ */
261
403
  mulBBN: (a, b) => Number(a * b),
404
+ /**
405
+ * Multiply two bigints, returning a bigint.
406
+ */
262
407
  mulBBB: (a, b) => a * b,
263
408
  };
409
+ /**
410
+ * Returns the maximum of multiple bigints.
411
+ *
412
+ * @param args - The bigints to compare.
413
+ * @returns The largest bigint.
414
+ */
264
415
  Helpers.maxBigInt = (...args) => args.reduce((m, e) => (e > m ? e : m));
416
+ /**
417
+ * Returns the minimum of multiple bigints.
418
+ *
419
+ * @param args - The bigints to compare.
420
+ * @returns The smallest bigint.
421
+ */
265
422
  Helpers.minBigInt = (...args) => args.reduce((m, e) => (e < m ? e : m));
423
+ /**
424
+ * Returns the absolute value of a bigint.
425
+ *
426
+ * @param num - The input bigint.
427
+ * @returns A bigint representing the absolute value of `num`.
428
+ */
266
429
  Helpers.absBigInt = (num) => (num < BigInt(0) ? -num : num);
267
430
  // =========================================================================
268
431
  // Display
269
432
  // =========================================================================
433
+ /**
434
+ * Capitalizes only the first letter of a string, making the rest lowercase.
435
+ * E.g., "HELLO" => "Hello".
436
+ *
437
+ * @param str - The input string to transform.
438
+ * @returns The resulting string with the first character in uppercase and the rest in lowercase.
439
+ */
270
440
  Helpers.capitalizeOnlyFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
271
441
  // =========================================================================
272
442
  // JSON
273
443
  // =========================================================================
444
+ /**
445
+ * Parses a JSON string containing potential BigInt values.
446
+ * By default, it only converts strings ending in 'n' (like `"123n"`) to BigInts.
447
+ *
448
+ * @param json - The JSON string to parse.
449
+ * @param unsafeStringNumberConversion - If `true`, all numeric strings (e.g., "123") will also become BigInts.
450
+ * @returns The parsed JSON object with BigInt conversions where applicable.
451
+ */
274
452
  Helpers.parseJsonWithBigint = (json, unsafeStringNumberConversion = false) => JSON.parse(json, (key, value) => {
275
453
  // handles bigint casting
276
454
  if (typeof value === "string" && /^-?\d+n$/.test(value)) {
@@ -286,6 +464,13 @@ Helpers.parseJsonWithBigint = (json, unsafeStringNumberConversion = false) => JS
286
464
  // =========================================================================
287
465
  // General
288
466
  // =========================================================================
467
+ /**
468
+ * Creates a deep copy of the given target, handling nested arrays and objects.
469
+ * Dates are cloned by their timestamp.
470
+ *
471
+ * @param target - The data to clone deeply.
472
+ * @returns A new object/array/date structure mirroring `target`.
473
+ */
289
474
  Helpers.deepCopy = (target) => {
290
475
  if (target === null) {
291
476
  return target;
@@ -293,7 +478,7 @@ Helpers.deepCopy = (target) => {
293
478
  if (target instanceof Date) {
294
479
  return new Date(target.getTime());
295
480
  }
296
- if (target instanceof Array) {
481
+ if (Array.isArray(target)) {
297
482
  const cp = [];
298
483
  target.forEach((v) => {
299
484
  cp.push(v);
@@ -309,6 +494,12 @@ Helpers.deepCopy = (target) => {
309
494
  }
310
495
  return target;
311
496
  };
497
+ /**
498
+ * Finds the index of the maximum value in an array. Returns -1 if the array is empty.
499
+ *
500
+ * @param arr - The input array.
501
+ * @returns The index of the maximum value, or -1 if the array is empty.
502
+ */
312
503
  Helpers.indexOfMax = (arr) => {
313
504
  if (arr.length === 0)
314
505
  return -1;
@@ -322,9 +513,35 @@ Helpers.indexOfMax = (arr) => {
322
513
  }
323
514
  return maxIndex;
324
515
  };
516
+ /**
517
+ * Returns a new array with unique elements from the input array,
518
+ * preserving the order of first occurrences.
519
+ *
520
+ * @param arr - The original array.
521
+ * @returns An array of unique items.
522
+ */
325
523
  Helpers.uniqueArray = (arr) => [...new Set(arr)];
524
+ /**
525
+ * Returns a Promise that resolves after a specified number of milliseconds.
526
+ *
527
+ * @param ms - The delay time in milliseconds.
528
+ * @returns A promise that resolves after `ms` milliseconds.
529
+ */
326
530
  Helpers.sleep = (ms) => new Promise((r) => setTimeout(r, ms));
531
+ /**
532
+ * Creates a unique ID-like string by combining the current timestamp and random base36 digits.
533
+ *
534
+ * @returns A short random string (base36) that can serve as a unique identifier.
535
+ */
327
536
  Helpers.createUid = () => Date.now().toString(36) + Math.random().toString(36).substring(2);
537
+ /**
538
+ * Splits an array into two groups: those for which `func` returns `true` (or truthy),
539
+ * and those for which it returns `false`. The result is returned as a tuple `[trues, falses]`.
540
+ *
541
+ * @param array - The array to filter.
542
+ * @param func - The function used to test each element.
543
+ * @returns A tuple containing two arrays: `[elements that pass, elements that fail]`.
544
+ */
328
545
  Helpers.bifilter = (array, func) => {
329
546
  return array.reduce(([T, F], x, i, arr) => {
330
547
  if (func(x, i, arr) === false)
@@ -333,24 +550,64 @@ Helpers.bifilter = (array, func) => {
333
550
  return [[...T, x], F];
334
551
  }, [[], []]);
335
552
  };
553
+ /**
554
+ * An async version of `bifilter`, returning a tuple of `[trues, falses]`.
555
+ * Each element is tested asynchronously in parallel via `func`.
556
+ *
557
+ * @param array - The array to filter.
558
+ * @param func - An async function returning `true` or `false`.
559
+ * @returns A tuple `[trues, falses]` after asynchronous evaluation.
560
+ */
336
561
  Helpers.bifilterAsync = (array, func) => __awaiter(void 0, void 0, void 0, function* () {
337
562
  const predicates = yield Promise.all(array.map(func));
338
563
  return _a.bifilter(array, (_, index) => predicates[index]);
339
564
  });
565
+ /**
566
+ * Filters the entries of an object based on a predicate function,
567
+ * returning a new object with only those entries for which `predicate`
568
+ * returns `true`.
569
+ *
570
+ * @param obj - The original object to filter.
571
+ * @param predicate - A function taking `(key, value)` and returning a boolean.
572
+ * @returns A new object with only the entries that pass the predicate.
573
+ */
340
574
  Helpers.filterObject = (obj, predicate) => Object.keys(obj).reduce((acc, key) => {
341
575
  const val = obj[key];
342
576
  if (!predicate(key, val))
343
577
  return acc;
344
578
  return Object.assign(Object.assign({}, acc), { [key]: val });
345
579
  }, {});
580
+ /**
581
+ * Applies downward slippage to a bigint amount by subtracting `slippage * amount`.
582
+ * For instance, for 1% slippage, we reduce the amount by 1%.
583
+ *
584
+ * @param amount - The original bigint amount.
585
+ * @param slippage - An integer percent (e.g., 1 => 1%).
586
+ * @returns The adjusted bigint after subtracting the slippage portion.
587
+ */
346
588
  Helpers.applySlippageBigInt = (amount, slippage) => {
347
589
  return (amount -
348
590
  BigInt(Math.floor(casting_1.Casting.normalizeSlippageTolerance(slippage) *
349
591
  Number(amount))));
350
592
  };
593
+ /**
594
+ * Applies downward slippage to a floating-point amount. E.g., for 1% slippage,
595
+ * reduce by 1% of `amount`.
596
+ *
597
+ * @param amount - The original float value.
598
+ * @param slippage - An integer percent (e.g., 1 => 1%).
599
+ * @returns The float after applying slippage.
600
+ */
351
601
  Helpers.applySlippage = (amount, slippage) => {
352
602
  return amount - casting_1.Casting.normalizeSlippageTolerance(slippage) * amount;
353
603
  };
604
+ /**
605
+ * Roughly checks if a string is a valid Sui type (e.g., "0x2::sui::SUI").
606
+ * This is not guaranteed to be perfect, but covers common cases.
607
+ *
608
+ * @param str - The string to validate.
609
+ * @returns `true` if it meets the minimum structure, otherwise `false`.
610
+ */
354
611
  Helpers.isValidType = (str) => {
355
612
  // TODO: use regex
356
613
  const trimmedStr = str.trim();
@@ -360,6 +617,12 @@ Helpers.isValidType = (str) => {
360
617
  trimmedStr.lastIndexOf("::") >= 6 &&
361
618
  !trimmedStr.endsWith(":"));
362
619
  };
620
+ /**
621
+ * Checks if a string is a valid hex representation, optionally prefixed with "0x".
622
+ *
623
+ * @param hexString - The string to check.
624
+ * @returns `true` if `hexString` is a valid hex, otherwise `false`.
625
+ */
363
626
  Helpers.isValidHex = (hexString) => {
364
627
  const hexPattern = /^(0x)?[0-9A-F]+$/i;
365
628
  return hexPattern.test(hexString);
@@ -367,41 +630,29 @@ Helpers.isValidHex = (hexString) => {
367
630
  // =========================================================================
368
631
  // Tx Command Input Construction
369
632
  // =========================================================================
370
- // TODO: use this everywhere in api for tx command creation
633
+ /**
634
+ * Utility for building transaction commands with either a string-based
635
+ * `ObjectId` or an existing transaction object argument. If it's a string,
636
+ * it's converted via `tx.object(...)`; if already a `TransactionObjectArgument`,
637
+ * it's returned as-is.
638
+ *
639
+ * @param tx - The current `Transaction` block to add the object to.
640
+ * @param object - Either an `ObjectId` or a `TransactionObjectArgument`.
641
+ * @returns A `TransactionObjectArgument` referencing the provided object.
642
+ */
371
643
  Helpers.addTxObject = (tx, object) => {
372
644
  return typeof object === "string" ? tx.object(object) : object;
373
645
  };
374
646
  // =========================================================================
375
- // Constructors
647
+ // Sui Address / Key Checking
376
648
  // =========================================================================
377
- // public static async createScallopProviders(inputs: {
378
- // network: SuiNetwork;
379
- // }): Promise<ScallopProviders> {
380
- // const network = inputs.network.toLowerCase();
381
- // const networkType =
382
- // network === "local"
383
- // ? "localnet"
384
- // : network !== "mainnet" &&
385
- // network !== "testnet" &&
386
- // network !== "localnet"
387
- // ? undefined
388
- // : network;
389
- // if (!networkType)
390
- // throw new Error(`network \`${inputs.network}\` not found`);
391
- // const Main = new Scallop({
392
- // networkType,
393
- // });
394
- // const [Builder, Query] = await Promise.all([
395
- // Main.createScallopBuilder(),
396
- // Main.createScallopQuery(),
397
- // ]);
398
- // // await Promise.all([Builder.init(), Query.init()]);
399
- // return {
400
- // Main,
401
- // Builder,
402
- // Query,
403
- // };
404
- // }
649
+ /**
650
+ * Checks if a given string is a valid Sui address by normalizing it to a
651
+ * 64-hex-digit form and calling `isValidSuiAddress`.
652
+ *
653
+ * @param address - The Sui address to validate.
654
+ * @returns `true` if valid, `false` otherwise.
655
+ */
405
656
  Helpers.isValidSuiAddress = (address) => (0, utils_1.isValidSuiAddress)((() => {
406
657
  if (!address.startsWith("0x") || address.length < 3)
407
658
  return "";
@@ -415,15 +666,25 @@ Helpers.isValidSuiAddress = (address) => (0, utils_1.isValidSuiAddress)((() => {
415
666
  // =========================================================================
416
667
  // Keypair
417
668
  // =========================================================================
669
+ /**
670
+ * Constructs a `Keypair` instance from a private key string. The `privateKey`
671
+ * may indicate the signing scheme (ED25519, Secp256k1, or Secp256r1) via prefix,
672
+ * as recognized by `decodeSuiPrivateKey`.
673
+ *
674
+ * @param privateKey - The full private key string (e.g., "0x<64_hex_chars>").
675
+ * @returns A new `Keypair` instance for signing transactions.
676
+ * @throws If the schema is unsupported.
677
+ */
418
678
  Helpers.keypairFromPrivateKey = (privateKey) => {
419
679
  const parsedKeypair = (0, cryptography_1.decodeSuiPrivateKey)(privateKey);
420
- return parsedKeypair.schema === "ED25519"
421
- ? ed25519_1.Ed25519Keypair.fromSecretKey(parsedKeypair.secretKey)
422
- : parsedKeypair.schema === "Secp256k1"
423
- ? secp256k1_1.Secp256k1Keypair.fromSecretKey(parsedKeypair.secretKey)
424
- : parsedKeypair.schema === "Secp256r1"
425
- ? secp256r1_1.Secp256r1Keypair.fromSecretKey(parsedKeypair.secretKey)
426
- : (() => {
427
- throw new Error(`unsupported schema \`${parsedKeypair.schema}\``);
428
- })();
680
+ switch (parsedKeypair.schema) {
681
+ case "ED25519":
682
+ return ed25519_1.Ed25519Keypair.fromSecretKey(parsedKeypair.secretKey);
683
+ case "Secp256k1":
684
+ return secp256k1_1.Secp256k1Keypair.fromSecretKey(parsedKeypair.secretKey);
685
+ case "Secp256r1":
686
+ return secp256r1_1.Secp256r1Keypair.fromSecretKey(parsedKeypair.secretKey);
687
+ default:
688
+ throw new Error(`unsupported schema \`${parsedKeypair.schema}\``);
689
+ }
429
690
  };