@xchainjs/xchain-thorchain-amm 3.0.35 → 3.0.37

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.
package/README.md CHANGED
@@ -105,13 +105,13 @@ You can find examples using the THORChain AMM package in the [thorchain-amm](htt
105
105
 
106
106
  More information about how to use the Thorchain AMM package can be found on [documentation](https://xchainjs.gitbook.io/xchainjs/protocols/thorchain/xchain-thorchain-amm)
107
107
 
108
- ### Setting Headers for Nine Realms endpoints
108
+ ### Setting Headers for public endpoints
109
109
 
110
- If you plan on using the publically accessible endpoints provided by Nine Realms(listed below), ensure that you add a valid 'x-client-id' to all requests
110
+ If you plan on using the publicly accessible endpoints listed below, ensure that you add a valid 'x-client-id' to all requests
111
111
 
112
- - https://midgard.ninerealms.com
113
- - https://haskoin.ninerealms.com (BTC/BCH/LTC)
114
- - https://thornode.ninerealms.com
112
+ - https://gateway.liquify.com/chain/thorchain_midgard
113
+ - https://api.haskoin.com (BTC/BCH/LTC)
114
+ - https://gateway.liquify.com/chain/thorchain_api
115
115
 
116
116
  Example
117
117
 
package/lib/index.esm.js CHANGED
@@ -53,7 +53,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
53
53
  };
54
54
 
55
55
  /*
56
- * bignumber.js v10.0.1
56
+ * bignumber.js v11.0.0
57
57
  * A JavaScript library for arbitrary-precision arithmetic.
58
58
  * https://github.com/MikeMcl/bignumber.js
59
59
  * Copyright (c) 2026 Michael Mclaughlin <M8ch88l@gmail.com>
@@ -126,7 +126,10 @@ var
126
126
  * Create and return a BigNumber constructor.
127
127
  */
128
128
  function clone(configObject) {
129
- var div, convertBase, parseUnusualNumeric,
129
+ var div, convertBase, parseValidString, parseBaseString,
130
+ basePrefix = /^(-?)0([xbo])(?=[^.])/i,
131
+ isInfinityOrNaN = /^-?(Infinity|NaN)$/,
132
+ whitespaceOrPlus = /^\s*\+(?!-)|^\s+|\s+$/g,
130
133
  P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },
131
134
  ONE = new BigNumber(1),
132
135
 
@@ -177,6 +180,9 @@ function clone(configObject) {
177
180
  // Whether to use cryptographically-secure random number generation, if available.
178
181
  CRYPTO = false, // true or false
179
182
 
183
+ // Whether to throw or to return NaN on an invalid BigNumber string value.
184
+ STRICT = true, // true or false
185
+
180
186
  // The modulo mode used when calculating the modulus: a mod n.
181
187
  // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
182
188
  // The remainder (r) is calculated as: r = a - n * q.
@@ -228,11 +234,11 @@ function clone(configObject) {
228
234
  * The BigNumber constructor and exported function.
229
235
  * Create and return a new instance of a BigNumber object.
230
236
  *
231
- * v {number|string|BigNumber} A numeric value.
237
+ * v {BigNumber|string|number|bigint} A numeric value.
232
238
  * [b] {number} The base of v. Integer, 2 to ALPHABET.length inclusive.
233
239
  */
234
240
  function BigNumber(v, b) {
235
- var alphabet, c, caseChanged, e, i, len, str, t,
241
+ var e, i, str, t,
236
242
  x = this;
237
243
 
238
244
  // Enable constructor call without `new`.
@@ -283,141 +289,80 @@ function clone(configObject) {
283
289
  return;
284
290
  }
285
291
 
286
- str = String(v);
287
- } else {
288
- if (t == 'string') {
289
- str = v;
290
- if (!isNumeric.test(str)) {
291
- return parseUnusualNumeric(x, str);
292
- }
293
- } else if (t == 'bigint') {
294
- str = String(v);
295
- } else {
296
- throw Error
297
- (bignumberError + 'Invalid argument: ' + v);
298
- }
299
-
300
- x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
301
- }
302
-
303
- // Decimal point?
304
- if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
305
-
306
- // Exponential form?
307
- if ((i = str.search(/e/i)) > 0) {
308
-
309
- // Determine exponent.
310
- if (e < 0) e = i;
311
- e += +str.slice(i + 1);
312
- str = str.substring(0, i);
313
- } else if (e < 0) {
314
-
315
- // Integer.
316
- e = str.length;
292
+ return parseValidString(x, String(v));
317
293
  }
318
294
 
319
- // Base specified.
320
- } else {
321
-
322
- // '[BigNumber Error] String expected: {v}'
323
- if (t != 'string') {
324
- throw Error
325
- (bignumberError + 'String expected: ' + v);
295
+ if (t == 'bigint') {
296
+ x.s = v < 0 ? (v = -v, -1) : 1;
297
+ return parseValidString(x, String(v));
326
298
  }
327
299
 
328
- // '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
329
- intCheck(b, 2, ALPHABET.length, 'Base');
330
-
331
- str = v;
332
- x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
333
- alphabet = ALPHABET.slice(0, b);
334
- e = i = 0;
335
-
336
- // Check that str is a valid base b number.
337
- // Don't use RegExp, so alphabet can contain special characters.
338
- for (len = str.length; i < len; i++) {
339
- if (alphabet.indexOf(c = str.charAt(i)) < 0) {
340
- if (c == '.') {
341
-
342
- // If '.' is not the first character and it has not be found before.
343
- if (i > e) {
344
- e = len;
345
- continue;
346
- }
347
- } else if (!caseChanged) {
348
-
349
- // Allow e.g. hexadecimal 'FF' as well as 'ff'.
350
- if (str == str.toUpperCase() && (str = str.toLowerCase()) ||
351
- str == str.toLowerCase() && (str = str.toUpperCase())) {
352
- caseChanged = true;
353
- i = -1;
354
- e = 0;
355
- continue;
356
- }
357
- }
358
-
359
- return parseUnusualNumeric(x, v, b);
300
+ if (t == 'string') {
301
+ str = v;
302
+ } else {
303
+ if (STRICT) {
304
+ throw Error
305
+ (bignumberError + 'BigNumber, string, number, or BigInt expected: ' + v);
360
306
  }
361
- }
362
-
363
- str = convertBase(str, b, 10, x.s);
364
-
365
- // Decimal point?
366
- if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
367
- else e = str.length;
368
- }
369
-
370
- // Determine leading zeros.
371
- for (i = 0; str.charCodeAt(i) === 48; i++);
372
-
373
- // Determine trailing zeros.
374
- for (len = str.length; str.charCodeAt(--len) === 48;);
307
+ str = String(v);
308
+ }
375
309
 
376
- if (str = str.slice(i, ++len)) {
377
- len -= i;
378
- e = e - i - 1;
310
+ if (isNumeric.test(str)) {
311
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
312
+ return parseValidString(x, str);
313
+ }
379
314
 
380
- // Overflow?
381
- if (e > MAX_EXP) {
315
+ // Strip whitespace and leading +.
316
+ str = str.replace(whitespaceOrPlus, '');
382
317
 
383
- // Infinity.
318
+ // No exception on ±Infinity or NaN.
319
+ if (isInfinityOrNaN.test(str)) {
320
+ x.s = isNaN(str) ? null : str < 0 ? -1 : 1;
384
321
  x.c = x.e = null;
322
+ return;
323
+ }
385
324
 
386
- // Underflow?
387
- } else if (e < MIN_EXP) {
325
+ // Check for base prefix such as 0x for hexadecimal.
326
+ str = str.replace(basePrefix, function (m, p1, p2) {
327
+ b = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
328
+ return p1;
329
+ });
388
330
 
389
- // Zero.
390
- x.c = [x.e = 0];
391
- } else {
392
- x.e = e;
393
- x.c = [];
331
+ if (b) {
332
+ return parseBaseString(x, str, b, v);
333
+ }
394
334
 
395
- // Transform base
335
+ // Strip underscores.
336
+ str = str.replace(/(\d)_(?=\d)/g, '$1');
396
337
 
397
- // e is the base 10 exponent.
398
- // i is where to slice str to get the first element of the coefficient array.
399
- i = (e + 1) % LOG_BASE;
400
- if (e < 0) i += LOG_BASE; // i < 1
338
+ if (isNumeric.test(str)) {
339
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
340
+ return parseValidString(x, str);
341
+ }
401
342
 
402
- if (i < len) {
403
- if (i) x.c.push(+str.slice(0, i));
343
+ // '[BigNumber Error] Not a number: {v}'
344
+ if (STRICT) {
345
+ throw Error
346
+ (bignumberError + 'Not a number: ' + v);
347
+ }
404
348
 
405
- for (len -= LOG_BASE; i < len;) {
406
- x.c.push(+str.slice(i, i += LOG_BASE));
407
- }
349
+ // NaN.
350
+ x.s = x.c = x.e = null;
408
351
 
409
- i = LOG_BASE - (str = str.slice(i)).length;
410
- } else {
411
- i -= len;
352
+ // Base specified.
353
+ } else {
354
+ if (t != 'string') {
355
+ if (STRICT) {
356
+ throw Error
357
+ (bignumberError + 'String expected: ' + v);
412
358
  }
413
-
414
- for (; i--; str += '0');
415
- x.c.push(+str);
359
+ v = String(v);
416
360
  }
417
- } else {
418
361
 
419
- // Zero.
420
- x.c = [x.e = 0];
362
+ // '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
363
+ intCheck(b, 2, ALPHABET.length, 'Base');
364
+
365
+ parseBaseString(x, v.replace(whitespaceOrPlus, ''), b, v);
421
366
  }
422
367
  }
423
368
 
@@ -450,6 +395,7 @@ function clone(configObject) {
450
395
  * EXPONENTIAL_AT {number|number[]} -MAX to MAX or [-MAX to 0, 0 to MAX]
451
396
  * RANGE {number|number[]} -MAX to MAX (not zero) or [-MAX to -1, 1 to MAX]
452
397
  * CRYPTO {boolean} true or false
398
+ * STRICT {boolean} true or false
453
399
  * MODULO_MODE {number} 0 to 9
454
400
  * POW_PRECISION {number} 0 to MAX
455
401
  * ALPHABET {string} A string of unique characters which does not contain
@@ -558,6 +504,18 @@ function clone(configObject) {
558
504
  }
559
505
  }
560
506
 
507
+ // STRICT {boolean} true or false.
508
+ // '[BigNumber Error] STRICT not true or false: {v}'
509
+ if (obj.hasOwnProperty(p = 'STRICT')) {
510
+ v = obj[p];
511
+ if (v === !!v) {
512
+ STRICT = v;
513
+ } else {
514
+ throw Error
515
+ (bignumberError + p + ' not true or false: ' + v);
516
+ }
517
+ }
518
+
561
519
  // MODULO_MODE {number} Integer, 0 to 9 inclusive.
562
520
  // '[BigNumber Error] MODULO_MODE {not a primitive number|not an integer|out of range}: {v}'
563
521
  if (obj.hasOwnProperty(p = 'MODULO_MODE')) {
@@ -612,6 +570,7 @@ function clone(configObject) {
612
570
  EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
613
571
  RANGE: [MIN_EXP, MAX_EXP],
614
572
  CRYPTO: CRYPTO,
573
+ STRICT: STRICT,
615
574
  MODULO_MODE: MODULO_MODE,
616
575
  POW_PRECISION: POW_PRECISION,
617
576
  FORMAT: FORMAT,
@@ -636,7 +595,7 @@ function clone(configObject) {
636
595
  if ({}.toString.call(c) != '[object Array]') {
637
596
 
638
597
  // ±Infinity and NaN
639
- return c === null && e === null && (s === null || s === 1 || s === -1)
598
+ return c === null && e === null && (s === null || s === 1 || s === -1);
640
599
  }
641
600
 
642
601
  // Check sign and check that exponent is an integer within the allowed range.
@@ -850,6 +809,160 @@ function clone(configObject) {
850
809
  // PRIVATE FUNCTIONS
851
810
 
852
811
 
812
+ /*
813
+ * Parse a known-valid decimal string str into BigNumber x.
814
+ * str must already have its sign removed.
815
+ */
816
+ parseValidString = function (x, str) {
817
+ var e, i, len;
818
+
819
+ // Decimal point?
820
+ if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
821
+
822
+ // Exponential form?
823
+ if ((i = str.search(/e/i)) > 0) {
824
+
825
+ // Determine exponent.
826
+ if (e < 0) e = i;
827
+ e += +str.slice(i + 1);
828
+ str = str.substring(0, i);
829
+ } else if (e < 0) {
830
+
831
+ // Integer.
832
+ e = str.length;
833
+ }
834
+
835
+ // Determine leading zeros.
836
+ for (i = 0; str.charCodeAt(i) === 48; i++);
837
+
838
+ // Determine trailing zeros.
839
+ for (len = str.length; str.charCodeAt(--len) === 48;);
840
+
841
+ if (str = str.slice(i, ++len)) {
842
+ len -= i;
843
+ e = e - i - 1;
844
+
845
+ // Overflow?
846
+ if (e > MAX_EXP) {
847
+
848
+ // Infinity.
849
+ x.c = x.e = null;
850
+
851
+ // Underflow?
852
+ } else if (e < MIN_EXP) {
853
+
854
+ // Zero.
855
+ x.c = [x.e = 0];
856
+ } else {
857
+ x.e = e;
858
+ x.c = [];
859
+
860
+ // Transform base
861
+
862
+ // e is the base 10 exponent.
863
+ // i is where to slice str to get the first element of the coefficient array.
864
+ i = (e + 1) % LOG_BASE;
865
+ if (e < 0) i += LOG_BASE; // i < 1
866
+
867
+ if (i < len) {
868
+ if (i) x.c.push(+str.slice(0, i));
869
+
870
+ for (len -= LOG_BASE; i < len;) {
871
+ x.c.push(+str.slice(i, i += LOG_BASE));
872
+ }
873
+
874
+ i = LOG_BASE - (str = str.slice(i)).length;
875
+ } else {
876
+ i -= len;
877
+ }
878
+
879
+ for (; i--; str += '0');
880
+ x.c.push(+str);
881
+ }
882
+ } else {
883
+
884
+ // Zero.
885
+ x.c = [x.e = 0];
886
+ }
887
+ };
888
+
889
+
890
+ /*
891
+ * Parse a non-decimal base string str into BigNumber x.
892
+ * str must have whitespace/plus stripped and base prefix removed.
893
+ * b is the base, v is the original input for error messages.
894
+ *
895
+ * Handles sign extraction, underscore stripping, leading/trailing dot normalisation,
896
+ * case flipping, character validation, then converts to base 10 via convertBase
897
+ * and delegates to parseValidString.
898
+ */
899
+ parseBaseString = function (x, str, b, v) {
900
+ var c, len,
901
+ alphabet = ALPHABET.slice(0, b),
902
+ i = 0,
903
+ clean = '',
904
+ hasDot = false,
905
+ prevIsNumeral = false,
906
+ caseChanged = false;
907
+
908
+ x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
909
+
910
+ // Check that str is a valid base b number.
911
+ // Underscores as separators are only valid between two numerals.
912
+ for (len = str.length; i < len; i++) {
913
+ c = str.charAt(i);
914
+
915
+ if (alphabet.indexOf(c) >= 0) {
916
+ clean += c;
917
+ prevIsNumeral = true;
918
+ continue;
919
+ }
920
+
921
+ if (c == '_') {
922
+ if (prevIsNumeral && i + 1 < len) {
923
+ prevIsNumeral = false;
924
+ continue;
925
+ }
926
+ } else if (c == '.') {
927
+ if (i == 0 || !hasDot && prevIsNumeral) {
928
+ // Don't add trailing or lone dot.
929
+ if (i + 1 == len) break;
930
+ if (i == 0) clean = '0';
931
+ clean += c;
932
+ hasDot = true;
933
+ prevIsNumeral = false;
934
+ continue;
935
+ }
936
+ } else if (!caseChanged) {
937
+
938
+ // Allow e.g. hexadecimal 'FF' as well as 'ff'.
939
+ if (str == str.toUpperCase() && alphabet == alphabet.toLowerCase() &&
940
+ (str = str.toLowerCase()) ||
941
+ str == str.toLowerCase() && alphabet == alphabet.toUpperCase() &&
942
+ (str = str.toUpperCase())) {
943
+ i = -1;
944
+ clean = '';
945
+ caseChanged = true;
946
+ hasDot = prevIsNumeral = false;
947
+ continue;
948
+ }
949
+ }
950
+
951
+ // '[BigNumber Error] Not a base {b} number: {v}'
952
+ if (STRICT) {
953
+ throw Error
954
+ (bignumberError + 'Not a base ' + b + ' number: ' + v);
955
+ }
956
+
957
+ // NaN.
958
+ x.s = x.c = x.e = null;
959
+ return;
960
+ }
961
+
962
+ parseValidString(x, convertBase(clean, b, 10, x.s));
963
+ };
964
+
965
+
853
966
  // Called by BigNumber and BigNumber.prototype.toString.
854
967
  convertBase = (function () {
855
968
  var decimal = '0123456789';
@@ -1385,46 +1498,7 @@ function clone(configObject) {
1385
1498
  }
1386
1499
 
1387
1500
 
1388
- // Handle values that fail the validity test in BigNumber.
1389
- parseUnusualNumeric = (function () {
1390
- var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i,
1391
- dotAfter = /^([^.]+)\.$/,
1392
- dotBefore = /^\.([^.]+)$/,
1393
- isInfinityOrNaN = /^-?(Infinity|NaN)$/,
1394
- whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
1395
-
1396
- return function (x, str, b) {
1397
- var base,
1398
- s = str.replace(whitespaceOrPlus, '');
1399
-
1400
- // No exception on ±Infinity or NaN.
1401
- if (isInfinityOrNaN.test(s)) {
1402
- x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
1403
- x.c = x.e = null;
1404
- return;
1405
- }
1406
1501
 
1407
- // basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i
1408
- s = s.replace(basePrefix, function (m, p1, p2) {
1409
- base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
1410
- return !b || b == base ? p1 : m;
1411
- });
1412
-
1413
- if (b) {
1414
- base = b;
1415
-
1416
- // E.g. '1.' to '1', '.1' to '0.1'
1417
- s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');
1418
- }
1419
-
1420
- if (str != s) return new BigNumber(s, base);
1421
-
1422
- // '[BigNumber Error] Not a number: {n}'
1423
- // '[BigNumber Error] Not a base {b} number: {n}'
1424
- throw Error
1425
- (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);
1426
- }
1427
- })();
1428
1502
 
1429
1503
 
1430
1504
  /*
@@ -2645,12 +2719,12 @@ function clone(configObject) {
2645
2719
 
2646
2720
  /*
2647
2721
  * Return an array of two BigNumbers representing the value of this BigNumber as a simple
2648
- * fraction with an integer numerator and an integer denominator.
2649
- * The denominator will be a positive non-zero value less than or equal to the specified
2650
- * maximum denominator. If a maximum denominator is not specified, the denominator will be
2651
- * the lowest value necessary to represent the number exactly.
2722
+ * fraction with an integer numerator and an integer denominator. The denominator will be
2723
+ * a positive value less than or equal to the specified maximum denominator. If a maximum
2724
+ * denominator is not specified, the denominator will be the lowest value necessary to
2725
+ * represent the number exactly.
2652
2726
  *
2653
- * [md] {number|string|BigNumber} Integer >= 1, or Infinity. The maximum denominator.
2727
+ * [md] {number|string|BigNumber} Integer > 0, or Infinity. The maximum denominator.
2654
2728
  *
2655
2729
  * '[BigNumber Error] Argument {not an integer|out of range} : {md}'
2656
2730
  */
@@ -2670,7 +2744,9 @@ function clone(configObject) {
2670
2744
  }
2671
2745
  }
2672
2746
 
2673
- if (!xc) return new BigNumber(x);
2747
+ if (!xc) {
2748
+ return [new BigNumber(x.s || 0), new BigNumber(0)];
2749
+ }
2674
2750
 
2675
2751
  d = new BigNumber(ONE);
2676
2752
  n1 = d0 = new BigNumber(ONE);
package/lib/index.js CHANGED
@@ -55,7 +55,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
55
55
  };
56
56
 
57
57
  /*
58
- * bignumber.js v10.0.1
58
+ * bignumber.js v11.0.0
59
59
  * A JavaScript library for arbitrary-precision arithmetic.
60
60
  * https://github.com/MikeMcl/bignumber.js
61
61
  * Copyright (c) 2026 Michael Mclaughlin <M8ch88l@gmail.com>
@@ -128,7 +128,10 @@ var
128
128
  * Create and return a BigNumber constructor.
129
129
  */
130
130
  function clone(configObject) {
131
- var div, convertBase, parseUnusualNumeric,
131
+ var div, convertBase, parseValidString, parseBaseString,
132
+ basePrefix = /^(-?)0([xbo])(?=[^.])/i,
133
+ isInfinityOrNaN = /^-?(Infinity|NaN)$/,
134
+ whitespaceOrPlus = /^\s*\+(?!-)|^\s+|\s+$/g,
132
135
  P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },
133
136
  ONE = new BigNumber(1),
134
137
 
@@ -179,6 +182,9 @@ function clone(configObject) {
179
182
  // Whether to use cryptographically-secure random number generation, if available.
180
183
  CRYPTO = false, // true or false
181
184
 
185
+ // Whether to throw or to return NaN on an invalid BigNumber string value.
186
+ STRICT = true, // true or false
187
+
182
188
  // The modulo mode used when calculating the modulus: a mod n.
183
189
  // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
184
190
  // The remainder (r) is calculated as: r = a - n * q.
@@ -230,11 +236,11 @@ function clone(configObject) {
230
236
  * The BigNumber constructor and exported function.
231
237
  * Create and return a new instance of a BigNumber object.
232
238
  *
233
- * v {number|string|BigNumber} A numeric value.
239
+ * v {BigNumber|string|number|bigint} A numeric value.
234
240
  * [b] {number} The base of v. Integer, 2 to ALPHABET.length inclusive.
235
241
  */
236
242
  function BigNumber(v, b) {
237
- var alphabet, c, caseChanged, e, i, len, str, t,
243
+ var e, i, str, t,
238
244
  x = this;
239
245
 
240
246
  // Enable constructor call without `new`.
@@ -285,141 +291,80 @@ function clone(configObject) {
285
291
  return;
286
292
  }
287
293
 
288
- str = String(v);
289
- } else {
290
- if (t == 'string') {
291
- str = v;
292
- if (!isNumeric.test(str)) {
293
- return parseUnusualNumeric(x, str);
294
- }
295
- } else if (t == 'bigint') {
296
- str = String(v);
297
- } else {
298
- throw Error
299
- (bignumberError + 'Invalid argument: ' + v);
300
- }
301
-
302
- x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
303
- }
304
-
305
- // Decimal point?
306
- if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
307
-
308
- // Exponential form?
309
- if ((i = str.search(/e/i)) > 0) {
310
-
311
- // Determine exponent.
312
- if (e < 0) e = i;
313
- e += +str.slice(i + 1);
314
- str = str.substring(0, i);
315
- } else if (e < 0) {
316
-
317
- // Integer.
318
- e = str.length;
294
+ return parseValidString(x, String(v));
319
295
  }
320
296
 
321
- // Base specified.
322
- } else {
323
-
324
- // '[BigNumber Error] String expected: {v}'
325
- if (t != 'string') {
326
- throw Error
327
- (bignumberError + 'String expected: ' + v);
297
+ if (t == 'bigint') {
298
+ x.s = v < 0 ? (v = -v, -1) : 1;
299
+ return parseValidString(x, String(v));
328
300
  }
329
301
 
330
- // '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
331
- intCheck(b, 2, ALPHABET.length, 'Base');
332
-
333
- str = v;
334
- x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
335
- alphabet = ALPHABET.slice(0, b);
336
- e = i = 0;
337
-
338
- // Check that str is a valid base b number.
339
- // Don't use RegExp, so alphabet can contain special characters.
340
- for (len = str.length; i < len; i++) {
341
- if (alphabet.indexOf(c = str.charAt(i)) < 0) {
342
- if (c == '.') {
343
-
344
- // If '.' is not the first character and it has not be found before.
345
- if (i > e) {
346
- e = len;
347
- continue;
348
- }
349
- } else if (!caseChanged) {
350
-
351
- // Allow e.g. hexadecimal 'FF' as well as 'ff'.
352
- if (str == str.toUpperCase() && (str = str.toLowerCase()) ||
353
- str == str.toLowerCase() && (str = str.toUpperCase())) {
354
- caseChanged = true;
355
- i = -1;
356
- e = 0;
357
- continue;
358
- }
359
- }
360
-
361
- return parseUnusualNumeric(x, v, b);
302
+ if (t == 'string') {
303
+ str = v;
304
+ } else {
305
+ if (STRICT) {
306
+ throw Error
307
+ (bignumberError + 'BigNumber, string, number, or BigInt expected: ' + v);
362
308
  }
363
- }
364
-
365
- str = convertBase(str, b, 10, x.s);
366
-
367
- // Decimal point?
368
- if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
369
- else e = str.length;
370
- }
371
-
372
- // Determine leading zeros.
373
- for (i = 0; str.charCodeAt(i) === 48; i++);
374
-
375
- // Determine trailing zeros.
376
- for (len = str.length; str.charCodeAt(--len) === 48;);
309
+ str = String(v);
310
+ }
377
311
 
378
- if (str = str.slice(i, ++len)) {
379
- len -= i;
380
- e = e - i - 1;
312
+ if (isNumeric.test(str)) {
313
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
314
+ return parseValidString(x, str);
315
+ }
381
316
 
382
- // Overflow?
383
- if (e > MAX_EXP) {
317
+ // Strip whitespace and leading +.
318
+ str = str.replace(whitespaceOrPlus, '');
384
319
 
385
- // Infinity.
320
+ // No exception on ±Infinity or NaN.
321
+ if (isInfinityOrNaN.test(str)) {
322
+ x.s = isNaN(str) ? null : str < 0 ? -1 : 1;
386
323
  x.c = x.e = null;
324
+ return;
325
+ }
387
326
 
388
- // Underflow?
389
- } else if (e < MIN_EXP) {
327
+ // Check for base prefix such as 0x for hexadecimal.
328
+ str = str.replace(basePrefix, function (m, p1, p2) {
329
+ b = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
330
+ return p1;
331
+ });
390
332
 
391
- // Zero.
392
- x.c = [x.e = 0];
393
- } else {
394
- x.e = e;
395
- x.c = [];
333
+ if (b) {
334
+ return parseBaseString(x, str, b, v);
335
+ }
396
336
 
397
- // Transform base
337
+ // Strip underscores.
338
+ str = str.replace(/(\d)_(?=\d)/g, '$1');
398
339
 
399
- // e is the base 10 exponent.
400
- // i is where to slice str to get the first element of the coefficient array.
401
- i = (e + 1) % LOG_BASE;
402
- if (e < 0) i += LOG_BASE; // i < 1
340
+ if (isNumeric.test(str)) {
341
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
342
+ return parseValidString(x, str);
343
+ }
403
344
 
404
- if (i < len) {
405
- if (i) x.c.push(+str.slice(0, i));
345
+ // '[BigNumber Error] Not a number: {v}'
346
+ if (STRICT) {
347
+ throw Error
348
+ (bignumberError + 'Not a number: ' + v);
349
+ }
406
350
 
407
- for (len -= LOG_BASE; i < len;) {
408
- x.c.push(+str.slice(i, i += LOG_BASE));
409
- }
351
+ // NaN.
352
+ x.s = x.c = x.e = null;
410
353
 
411
- i = LOG_BASE - (str = str.slice(i)).length;
412
- } else {
413
- i -= len;
354
+ // Base specified.
355
+ } else {
356
+ if (t != 'string') {
357
+ if (STRICT) {
358
+ throw Error
359
+ (bignumberError + 'String expected: ' + v);
414
360
  }
415
-
416
- for (; i--; str += '0');
417
- x.c.push(+str);
361
+ v = String(v);
418
362
  }
419
- } else {
420
363
 
421
- // Zero.
422
- x.c = [x.e = 0];
364
+ // '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
365
+ intCheck(b, 2, ALPHABET.length, 'Base');
366
+
367
+ parseBaseString(x, v.replace(whitespaceOrPlus, ''), b, v);
423
368
  }
424
369
  }
425
370
 
@@ -452,6 +397,7 @@ function clone(configObject) {
452
397
  * EXPONENTIAL_AT {number|number[]} -MAX to MAX or [-MAX to 0, 0 to MAX]
453
398
  * RANGE {number|number[]} -MAX to MAX (not zero) or [-MAX to -1, 1 to MAX]
454
399
  * CRYPTO {boolean} true or false
400
+ * STRICT {boolean} true or false
455
401
  * MODULO_MODE {number} 0 to 9
456
402
  * POW_PRECISION {number} 0 to MAX
457
403
  * ALPHABET {string} A string of unique characters which does not contain
@@ -560,6 +506,18 @@ function clone(configObject) {
560
506
  }
561
507
  }
562
508
 
509
+ // STRICT {boolean} true or false.
510
+ // '[BigNumber Error] STRICT not true or false: {v}'
511
+ if (obj.hasOwnProperty(p = 'STRICT')) {
512
+ v = obj[p];
513
+ if (v === !!v) {
514
+ STRICT = v;
515
+ } else {
516
+ throw Error
517
+ (bignumberError + p + ' not true or false: ' + v);
518
+ }
519
+ }
520
+
563
521
  // MODULO_MODE {number} Integer, 0 to 9 inclusive.
564
522
  // '[BigNumber Error] MODULO_MODE {not a primitive number|not an integer|out of range}: {v}'
565
523
  if (obj.hasOwnProperty(p = 'MODULO_MODE')) {
@@ -614,6 +572,7 @@ function clone(configObject) {
614
572
  EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
615
573
  RANGE: [MIN_EXP, MAX_EXP],
616
574
  CRYPTO: CRYPTO,
575
+ STRICT: STRICT,
617
576
  MODULO_MODE: MODULO_MODE,
618
577
  POW_PRECISION: POW_PRECISION,
619
578
  FORMAT: FORMAT,
@@ -638,7 +597,7 @@ function clone(configObject) {
638
597
  if ({}.toString.call(c) != '[object Array]') {
639
598
 
640
599
  // ±Infinity and NaN
641
- return c === null && e === null && (s === null || s === 1 || s === -1)
600
+ return c === null && e === null && (s === null || s === 1 || s === -1);
642
601
  }
643
602
 
644
603
  // Check sign and check that exponent is an integer within the allowed range.
@@ -852,6 +811,160 @@ function clone(configObject) {
852
811
  // PRIVATE FUNCTIONS
853
812
 
854
813
 
814
+ /*
815
+ * Parse a known-valid decimal string str into BigNumber x.
816
+ * str must already have its sign removed.
817
+ */
818
+ parseValidString = function (x, str) {
819
+ var e, i, len;
820
+
821
+ // Decimal point?
822
+ if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
823
+
824
+ // Exponential form?
825
+ if ((i = str.search(/e/i)) > 0) {
826
+
827
+ // Determine exponent.
828
+ if (e < 0) e = i;
829
+ e += +str.slice(i + 1);
830
+ str = str.substring(0, i);
831
+ } else if (e < 0) {
832
+
833
+ // Integer.
834
+ e = str.length;
835
+ }
836
+
837
+ // Determine leading zeros.
838
+ for (i = 0; str.charCodeAt(i) === 48; i++);
839
+
840
+ // Determine trailing zeros.
841
+ for (len = str.length; str.charCodeAt(--len) === 48;);
842
+
843
+ if (str = str.slice(i, ++len)) {
844
+ len -= i;
845
+ e = e - i - 1;
846
+
847
+ // Overflow?
848
+ if (e > MAX_EXP) {
849
+
850
+ // Infinity.
851
+ x.c = x.e = null;
852
+
853
+ // Underflow?
854
+ } else if (e < MIN_EXP) {
855
+
856
+ // Zero.
857
+ x.c = [x.e = 0];
858
+ } else {
859
+ x.e = e;
860
+ x.c = [];
861
+
862
+ // Transform base
863
+
864
+ // e is the base 10 exponent.
865
+ // i is where to slice str to get the first element of the coefficient array.
866
+ i = (e + 1) % LOG_BASE;
867
+ if (e < 0) i += LOG_BASE; // i < 1
868
+
869
+ if (i < len) {
870
+ if (i) x.c.push(+str.slice(0, i));
871
+
872
+ for (len -= LOG_BASE; i < len;) {
873
+ x.c.push(+str.slice(i, i += LOG_BASE));
874
+ }
875
+
876
+ i = LOG_BASE - (str = str.slice(i)).length;
877
+ } else {
878
+ i -= len;
879
+ }
880
+
881
+ for (; i--; str += '0');
882
+ x.c.push(+str);
883
+ }
884
+ } else {
885
+
886
+ // Zero.
887
+ x.c = [x.e = 0];
888
+ }
889
+ };
890
+
891
+
892
+ /*
893
+ * Parse a non-decimal base string str into BigNumber x.
894
+ * str must have whitespace/plus stripped and base prefix removed.
895
+ * b is the base, v is the original input for error messages.
896
+ *
897
+ * Handles sign extraction, underscore stripping, leading/trailing dot normalisation,
898
+ * case flipping, character validation, then converts to base 10 via convertBase
899
+ * and delegates to parseValidString.
900
+ */
901
+ parseBaseString = function (x, str, b, v) {
902
+ var c, len,
903
+ alphabet = ALPHABET.slice(0, b),
904
+ i = 0,
905
+ clean = '',
906
+ hasDot = false,
907
+ prevIsNumeral = false,
908
+ caseChanged = false;
909
+
910
+ x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
911
+
912
+ // Check that str is a valid base b number.
913
+ // Underscores as separators are only valid between two numerals.
914
+ for (len = str.length; i < len; i++) {
915
+ c = str.charAt(i);
916
+
917
+ if (alphabet.indexOf(c) >= 0) {
918
+ clean += c;
919
+ prevIsNumeral = true;
920
+ continue;
921
+ }
922
+
923
+ if (c == '_') {
924
+ if (prevIsNumeral && i + 1 < len) {
925
+ prevIsNumeral = false;
926
+ continue;
927
+ }
928
+ } else if (c == '.') {
929
+ if (i == 0 || !hasDot && prevIsNumeral) {
930
+ // Don't add trailing or lone dot.
931
+ if (i + 1 == len) break;
932
+ if (i == 0) clean = '0';
933
+ clean += c;
934
+ hasDot = true;
935
+ prevIsNumeral = false;
936
+ continue;
937
+ }
938
+ } else if (!caseChanged) {
939
+
940
+ // Allow e.g. hexadecimal 'FF' as well as 'ff'.
941
+ if (str == str.toUpperCase() && alphabet == alphabet.toLowerCase() &&
942
+ (str = str.toLowerCase()) ||
943
+ str == str.toLowerCase() && alphabet == alphabet.toUpperCase() &&
944
+ (str = str.toUpperCase())) {
945
+ i = -1;
946
+ clean = '';
947
+ caseChanged = true;
948
+ hasDot = prevIsNumeral = false;
949
+ continue;
950
+ }
951
+ }
952
+
953
+ // '[BigNumber Error] Not a base {b} number: {v}'
954
+ if (STRICT) {
955
+ throw Error
956
+ (bignumberError + 'Not a base ' + b + ' number: ' + v);
957
+ }
958
+
959
+ // NaN.
960
+ x.s = x.c = x.e = null;
961
+ return;
962
+ }
963
+
964
+ parseValidString(x, convertBase(clean, b, 10, x.s));
965
+ };
966
+
967
+
855
968
  // Called by BigNumber and BigNumber.prototype.toString.
856
969
  convertBase = (function () {
857
970
  var decimal = '0123456789';
@@ -1387,46 +1500,7 @@ function clone(configObject) {
1387
1500
  }
1388
1501
 
1389
1502
 
1390
- // Handle values that fail the validity test in BigNumber.
1391
- parseUnusualNumeric = (function () {
1392
- var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i,
1393
- dotAfter = /^([^.]+)\.$/,
1394
- dotBefore = /^\.([^.]+)$/,
1395
- isInfinityOrNaN = /^-?(Infinity|NaN)$/,
1396
- whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
1397
-
1398
- return function (x, str, b) {
1399
- var base,
1400
- s = str.replace(whitespaceOrPlus, '');
1401
-
1402
- // No exception on ±Infinity or NaN.
1403
- if (isInfinityOrNaN.test(s)) {
1404
- x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
1405
- x.c = x.e = null;
1406
- return;
1407
- }
1408
1503
 
1409
- // basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i
1410
- s = s.replace(basePrefix, function (m, p1, p2) {
1411
- base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
1412
- return !b || b == base ? p1 : m;
1413
- });
1414
-
1415
- if (b) {
1416
- base = b;
1417
-
1418
- // E.g. '1.' to '1', '.1' to '0.1'
1419
- s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');
1420
- }
1421
-
1422
- if (str != s) return new BigNumber(s, base);
1423
-
1424
- // '[BigNumber Error] Not a number: {n}'
1425
- // '[BigNumber Error] Not a base {b} number: {n}'
1426
- throw Error
1427
- (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);
1428
- }
1429
- })();
1430
1504
 
1431
1505
 
1432
1506
  /*
@@ -2647,12 +2721,12 @@ function clone(configObject) {
2647
2721
 
2648
2722
  /*
2649
2723
  * Return an array of two BigNumbers representing the value of this BigNumber as a simple
2650
- * fraction with an integer numerator and an integer denominator.
2651
- * The denominator will be a positive non-zero value less than or equal to the specified
2652
- * maximum denominator. If a maximum denominator is not specified, the denominator will be
2653
- * the lowest value necessary to represent the number exactly.
2724
+ * fraction with an integer numerator and an integer denominator. The denominator will be
2725
+ * a positive value less than or equal to the specified maximum denominator. If a maximum
2726
+ * denominator is not specified, the denominator will be the lowest value necessary to
2727
+ * represent the number exactly.
2654
2728
  *
2655
- * [md] {number|string|BigNumber} Integer >= 1, or Infinity. The maximum denominator.
2729
+ * [md] {number|string|BigNumber} Integer > 0, or Infinity. The maximum denominator.
2656
2730
  *
2657
2731
  * '[BigNumber Error] Argument {not an integer|out of range} : {md}'
2658
2732
  */
@@ -2672,7 +2746,9 @@ function clone(configObject) {
2672
2746
  }
2673
2747
  }
2674
2748
 
2675
- if (!xc) return new BigNumber(x);
2749
+ if (!xc) {
2750
+ return [new BigNumber(x.s || 0), new BigNumber(0)];
2751
+ }
2676
2752
 
2677
2753
  d = new BigNumber(ONE);
2678
2754
  n1 = d0 = new BigNumber(ONE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain-amm",
3
- "version": "3.0.35",
3
+ "version": "3.0.37",
4
4
  "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -36,31 +36,31 @@
36
36
  "url": "https://github.com/xchainjs/xchainjs-lib/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@xchainjs/xchain-avax": "2.0.15",
40
- "@xchainjs/xchain-base": "1.0.15",
41
- "@xchainjs/xchain-bitcoin": "2.2.2",
42
- "@xchainjs/xchain-bitcoincash": "2.2.3",
43
- "@xchainjs/xchain-bsc": "2.0.16",
44
- "@xchainjs/xchain-client": "2.0.11",
45
- "@xchainjs/xchain-cosmos": "3.0.11",
46
- "@xchainjs/xchain-doge": "2.2.2",
47
- "@xchainjs/xchain-ethereum": "2.0.16",
48
- "@xchainjs/xchain-evm": "2.0.15",
49
- "@xchainjs/xchain-litecoin": "2.2.2",
50
- "@xchainjs/xchain-ripple": "1.0.13",
51
- "@xchainjs/xchain-solana": "1.1.3",
52
- "@xchainjs/xchain-sui": "0.1.0",
53
- "@xchainjs/xchain-thorchain": "3.0.15",
54
- "@xchainjs/xchain-thorchain-query": "3.0.2",
55
- "@xchainjs/xchain-tron": "3.0.4",
56
- "@xchainjs/xchain-util": "2.0.6",
57
- "@xchainjs/xchain-wallet": "2.0.25",
58
- "@xchainjs/xchain-zcash": "1.3.3",
39
+ "@xchainjs/xchain-avax": "2.0.17",
40
+ "@xchainjs/xchain-base": "1.0.17",
41
+ "@xchainjs/xchain-bitcoin": "2.2.4",
42
+ "@xchainjs/xchain-bitcoincash": "2.2.5",
43
+ "@xchainjs/xchain-bsc": "2.0.18",
44
+ "@xchainjs/xchain-client": "2.0.13",
45
+ "@xchainjs/xchain-cosmos": "3.0.13",
46
+ "@xchainjs/xchain-doge": "2.2.4",
47
+ "@xchainjs/xchain-ethereum": "2.0.18",
48
+ "@xchainjs/xchain-evm": "2.0.17",
49
+ "@xchainjs/xchain-litecoin": "2.3.1",
50
+ "@xchainjs/xchain-ripple": "1.0.15",
51
+ "@xchainjs/xchain-solana": "1.1.5",
52
+ "@xchainjs/xchain-sui": "0.1.2",
53
+ "@xchainjs/xchain-thorchain": "3.0.17",
54
+ "@xchainjs/xchain-thorchain-query": "3.0.4",
55
+ "@xchainjs/xchain-tron": "3.0.6",
56
+ "@xchainjs/xchain-util": "2.0.7",
57
+ "@xchainjs/xchain-wallet": "2.0.27",
58
+ "@xchainjs/xchain-zcash": "1.3.5",
59
59
  "ethers": "^6.14.3"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@ledgerhq/hw-transport-node-hid": "^6.28.6",
63
- "axios": "1.13.5",
63
+ "axios": "1.15.2",
64
64
  "axios-mock-adapter": "^2.1.0"
65
65
  },
66
66
  "publishConfig": {