@chainflip/sdk 1.5.0-alpha.0 → 1.5.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/swap.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getEnvironment, getSupportedAssets, getAllBoostPoolsDepth, getVaultContractAddress, approve, getTokenContractAddress, getEvmChainId, checkAllowance, extractOverrides, Vault__factory } from './chunk-M32JHS3U.mjs';
2
- import { assertValidAddress, ccmParamsSchema, dotAddress } from './chunk-7ENWS5RM.mjs';
2
+ import { assertValidAddress, ccmParamsSchema, dotAddress } from './chunk-HWJAHLL7.mjs';
3
3
  import { __name, ChainflipNetworks, __publicField, Chains, assetConstants, getInternalAsset, isNotNullish, assert, getAssetAndChain, readChainAssetValue, isTestnet, chainConstants, getInternalAssets } from './chunk-3V7QJANN.mjs';
4
4
  export { Assets, InternalAssets as ChainflipIds, ChainflipNetworks, Chains, getInternalAsset as getChainflipId } from './chunk-3V7QJANN.mjs';
5
5
  import { bytesToHex } from '@chainflip/utils/bytes';
@@ -2174,6 +2174,1369 @@ SuperJSON.registerCustom;
2174
2174
  SuperJSON.registerSymbol;
2175
2175
  SuperJSON.allowErrorProps;
2176
2176
 
2177
+ // ../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
2178
+ var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
2179
+ var mathceil = Math.ceil;
2180
+ var mathfloor = Math.floor;
2181
+ var bignumberError = "[BigNumber Error] ";
2182
+ var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
2183
+ var BASE = 1e14;
2184
+ var LOG_BASE = 14;
2185
+ var MAX_SAFE_INTEGER = 9007199254740991;
2186
+ var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
2187
+ var SQRT_BASE = 1e7;
2188
+ var MAX = 1e9;
2189
+ function clone(configObject) {
2190
+ var div, convertBase, parseNumeric, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
2191
+ prefix: "",
2192
+ groupSize: 3,
2193
+ secondaryGroupSize: 0,
2194
+ groupSeparator: ",",
2195
+ decimalSeparator: ".",
2196
+ fractionGroupSize: 0,
2197
+ fractionGroupSeparator: "\xA0",
2198
+ // non-breaking space
2199
+ suffix: ""
2200
+ }, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
2201
+ function BigNumber2(v, b) {
2202
+ var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
2203
+ if (!(x instanceof BigNumber2)) return new BigNumber2(v, b);
2204
+ if (b == null) {
2205
+ if (v && v._isBigNumber === true) {
2206
+ x.s = v.s;
2207
+ if (!v.c || v.e > MAX_EXP) {
2208
+ x.c = x.e = null;
2209
+ } else if (v.e < MIN_EXP) {
2210
+ x.c = [x.e = 0];
2211
+ } else {
2212
+ x.e = v.e;
2213
+ x.c = v.c.slice();
2214
+ }
2215
+ return;
2216
+ }
2217
+ if ((isNum = typeof v == "number") && v * 0 == 0) {
2218
+ x.s = 1 / v < 0 ? (v = -v, -1) : 1;
2219
+ if (v === ~~v) {
2220
+ for (e = 0, i = v; i >= 10; i /= 10, e++) ;
2221
+ if (e > MAX_EXP) {
2222
+ x.c = x.e = null;
2223
+ } else {
2224
+ x.e = e;
2225
+ x.c = [v];
2226
+ }
2227
+ return;
2228
+ }
2229
+ str = String(v);
2230
+ } else {
2231
+ if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
2232
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
2233
+ }
2234
+ if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
2235
+ if ((i = str.search(/e/i)) > 0) {
2236
+ if (e < 0) e = i;
2237
+ e += +str.slice(i + 1);
2238
+ str = str.substring(0, i);
2239
+ } else if (e < 0) {
2240
+ e = str.length;
2241
+ }
2242
+ } else {
2243
+ intCheck(b, 2, ALPHABET.length, "Base");
2244
+ if (b == 10 && alphabetHasNormalDecimalDigits) {
2245
+ x = new BigNumber2(v);
2246
+ return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
2247
+ }
2248
+ str = String(v);
2249
+ if (isNum = typeof v == "number") {
2250
+ if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
2251
+ x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
2252
+ if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
2253
+ throw Error(tooManyDigits + v);
2254
+ }
2255
+ } else {
2256
+ x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
2257
+ }
2258
+ alphabet = ALPHABET.slice(0, b);
2259
+ e = i = 0;
2260
+ for (len = str.length; i < len; i++) {
2261
+ if (alphabet.indexOf(c = str.charAt(i)) < 0) {
2262
+ if (c == ".") {
2263
+ if (i > e) {
2264
+ e = len;
2265
+ continue;
2266
+ }
2267
+ } else if (!caseChanged) {
2268
+ if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
2269
+ caseChanged = true;
2270
+ i = -1;
2271
+ e = 0;
2272
+ continue;
2273
+ }
2274
+ }
2275
+ return parseNumeric(x, String(v), isNum, b);
2276
+ }
2277
+ }
2278
+ isNum = false;
2279
+ str = convertBase(str, b, 10, x.s);
2280
+ if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
2281
+ else e = str.length;
2282
+ }
2283
+ for (i = 0; str.charCodeAt(i) === 48; i++) ;
2284
+ for (len = str.length; str.charCodeAt(--len) === 48; ) ;
2285
+ if (str = str.slice(i, ++len)) {
2286
+ len -= i;
2287
+ if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
2288
+ throw Error(tooManyDigits + x.s * v);
2289
+ }
2290
+ if ((e = e - i - 1) > MAX_EXP) {
2291
+ x.c = x.e = null;
2292
+ } else if (e < MIN_EXP) {
2293
+ x.c = [x.e = 0];
2294
+ } else {
2295
+ x.e = e;
2296
+ x.c = [];
2297
+ i = (e + 1) % LOG_BASE;
2298
+ if (e < 0) i += LOG_BASE;
2299
+ if (i < len) {
2300
+ if (i) x.c.push(+str.slice(0, i));
2301
+ for (len -= LOG_BASE; i < len; ) {
2302
+ x.c.push(+str.slice(i, i += LOG_BASE));
2303
+ }
2304
+ i = LOG_BASE - (str = str.slice(i)).length;
2305
+ } else {
2306
+ i -= len;
2307
+ }
2308
+ for (; i--; str += "0") ;
2309
+ x.c.push(+str);
2310
+ }
2311
+ } else {
2312
+ x.c = [x.e = 0];
2313
+ }
2314
+ }
2315
+ __name(BigNumber2, "BigNumber");
2316
+ BigNumber2.clone = clone;
2317
+ BigNumber2.ROUND_UP = 0;
2318
+ BigNumber2.ROUND_DOWN = 1;
2319
+ BigNumber2.ROUND_CEIL = 2;
2320
+ BigNumber2.ROUND_FLOOR = 3;
2321
+ BigNumber2.ROUND_HALF_UP = 4;
2322
+ BigNumber2.ROUND_HALF_DOWN = 5;
2323
+ BigNumber2.ROUND_HALF_EVEN = 6;
2324
+ BigNumber2.ROUND_HALF_CEIL = 7;
2325
+ BigNumber2.ROUND_HALF_FLOOR = 8;
2326
+ BigNumber2.EUCLID = 9;
2327
+ BigNumber2.config = BigNumber2.set = function(obj) {
2328
+ var p, v;
2329
+ if (obj != null) {
2330
+ if (typeof obj == "object") {
2331
+ if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
2332
+ v = obj[p];
2333
+ intCheck(v, 0, MAX, p);
2334
+ DECIMAL_PLACES = v;
2335
+ }
2336
+ if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
2337
+ v = obj[p];
2338
+ intCheck(v, 0, 8, p);
2339
+ ROUNDING_MODE = v;
2340
+ }
2341
+ if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
2342
+ v = obj[p];
2343
+ if (v && v.pop) {
2344
+ intCheck(v[0], -MAX, 0, p);
2345
+ intCheck(v[1], 0, MAX, p);
2346
+ TO_EXP_NEG = v[0];
2347
+ TO_EXP_POS = v[1];
2348
+ } else {
2349
+ intCheck(v, -MAX, MAX, p);
2350
+ TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
2351
+ }
2352
+ }
2353
+ if (obj.hasOwnProperty(p = "RANGE")) {
2354
+ v = obj[p];
2355
+ if (v && v.pop) {
2356
+ intCheck(v[0], -MAX, -1, p);
2357
+ intCheck(v[1], 1, MAX, p);
2358
+ MIN_EXP = v[0];
2359
+ MAX_EXP = v[1];
2360
+ } else {
2361
+ intCheck(v, -MAX, MAX, p);
2362
+ if (v) {
2363
+ MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
2364
+ } else {
2365
+ throw Error(bignumberError + p + " cannot be zero: " + v);
2366
+ }
2367
+ }
2368
+ }
2369
+ if (obj.hasOwnProperty(p = "CRYPTO")) {
2370
+ v = obj[p];
2371
+ if (v === !!v) {
2372
+ if (v) {
2373
+ if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
2374
+ CRYPTO = v;
2375
+ } else {
2376
+ CRYPTO = !v;
2377
+ throw Error(bignumberError + "crypto unavailable");
2378
+ }
2379
+ } else {
2380
+ CRYPTO = v;
2381
+ }
2382
+ } else {
2383
+ throw Error(bignumberError + p + " not true or false: " + v);
2384
+ }
2385
+ }
2386
+ if (obj.hasOwnProperty(p = "MODULO_MODE")) {
2387
+ v = obj[p];
2388
+ intCheck(v, 0, 9, p);
2389
+ MODULO_MODE = v;
2390
+ }
2391
+ if (obj.hasOwnProperty(p = "POW_PRECISION")) {
2392
+ v = obj[p];
2393
+ intCheck(v, 0, MAX, p);
2394
+ POW_PRECISION = v;
2395
+ }
2396
+ if (obj.hasOwnProperty(p = "FORMAT")) {
2397
+ v = obj[p];
2398
+ if (typeof v == "object") FORMAT = v;
2399
+ else throw Error(bignumberError + p + " not an object: " + v);
2400
+ }
2401
+ if (obj.hasOwnProperty(p = "ALPHABET")) {
2402
+ v = obj[p];
2403
+ if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
2404
+ alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
2405
+ ALPHABET = v;
2406
+ } else {
2407
+ throw Error(bignumberError + p + " invalid: " + v);
2408
+ }
2409
+ }
2410
+ } else {
2411
+ throw Error(bignumberError + "Object expected: " + obj);
2412
+ }
2413
+ }
2414
+ return {
2415
+ DECIMAL_PLACES,
2416
+ ROUNDING_MODE,
2417
+ EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
2418
+ RANGE: [MIN_EXP, MAX_EXP],
2419
+ CRYPTO,
2420
+ MODULO_MODE,
2421
+ POW_PRECISION,
2422
+ FORMAT,
2423
+ ALPHABET
2424
+ };
2425
+ };
2426
+ BigNumber2.isBigNumber = function(v) {
2427
+ if (!v || v._isBigNumber !== true) return false;
2428
+ if (!BigNumber2.DEBUG) return true;
2429
+ var i, n, c = v.c, e = v.e, s = v.s;
2430
+ out: if ({}.toString.call(c) == "[object Array]") {
2431
+ if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
2432
+ if (c[0] === 0) {
2433
+ if (e === 0 && c.length === 1) return true;
2434
+ break out;
2435
+ }
2436
+ i = (e + 1) % LOG_BASE;
2437
+ if (i < 1) i += LOG_BASE;
2438
+ if (String(c[0]).length == i) {
2439
+ for (i = 0; i < c.length; i++) {
2440
+ n = c[i];
2441
+ if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
2442
+ }
2443
+ if (n !== 0) return true;
2444
+ }
2445
+ }
2446
+ } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
2447
+ return true;
2448
+ }
2449
+ throw Error(bignumberError + "Invalid BigNumber: " + v);
2450
+ };
2451
+ BigNumber2.maximum = BigNumber2.max = function() {
2452
+ return maxOrMin(arguments, -1);
2453
+ };
2454
+ BigNumber2.minimum = BigNumber2.min = function() {
2455
+ return maxOrMin(arguments, 1);
2456
+ };
2457
+ BigNumber2.random = function() {
2458
+ var pow2_53 = 9007199254740992;
2459
+ var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
2460
+ return mathfloor(Math.random() * pow2_53);
2461
+ } : function() {
2462
+ return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
2463
+ };
2464
+ return function(dp) {
2465
+ var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
2466
+ if (dp == null) dp = DECIMAL_PLACES;
2467
+ else intCheck(dp, 0, MAX);
2468
+ k = mathceil(dp / LOG_BASE);
2469
+ if (CRYPTO) {
2470
+ if (crypto.getRandomValues) {
2471
+ a = crypto.getRandomValues(new Uint32Array(k *= 2));
2472
+ for (; i < k; ) {
2473
+ v = a[i] * 131072 + (a[i + 1] >>> 11);
2474
+ if (v >= 9e15) {
2475
+ b = crypto.getRandomValues(new Uint32Array(2));
2476
+ a[i] = b[0];
2477
+ a[i + 1] = b[1];
2478
+ } else {
2479
+ c.push(v % 1e14);
2480
+ i += 2;
2481
+ }
2482
+ }
2483
+ i = k / 2;
2484
+ } else if (crypto.randomBytes) {
2485
+ a = crypto.randomBytes(k *= 7);
2486
+ for (; i < k; ) {
2487
+ v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
2488
+ if (v >= 9e15) {
2489
+ crypto.randomBytes(7).copy(a, i);
2490
+ } else {
2491
+ c.push(v % 1e14);
2492
+ i += 7;
2493
+ }
2494
+ }
2495
+ i = k / 7;
2496
+ } else {
2497
+ CRYPTO = false;
2498
+ throw Error(bignumberError + "crypto unavailable");
2499
+ }
2500
+ }
2501
+ if (!CRYPTO) {
2502
+ for (; i < k; ) {
2503
+ v = random53bitInt();
2504
+ if (v < 9e15) c[i++] = v % 1e14;
2505
+ }
2506
+ }
2507
+ k = c[--i];
2508
+ dp %= LOG_BASE;
2509
+ if (k && dp) {
2510
+ v = POWS_TEN[LOG_BASE - dp];
2511
+ c[i] = mathfloor(k / v) * v;
2512
+ }
2513
+ for (; c[i] === 0; c.pop(), i--) ;
2514
+ if (i < 0) {
2515
+ c = [e = 0];
2516
+ } else {
2517
+ for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE) ;
2518
+ for (i = 1, v = c[0]; v >= 10; v /= 10, i++) ;
2519
+ if (i < LOG_BASE) e -= LOG_BASE - i;
2520
+ }
2521
+ rand.e = e;
2522
+ rand.c = c;
2523
+ return rand;
2524
+ };
2525
+ }();
2526
+ BigNumber2.sum = function() {
2527
+ var i = 1, args = arguments, sum = new BigNumber2(args[0]);
2528
+ for (; i < args.length; ) sum = sum.plus(args[i++]);
2529
+ return sum;
2530
+ };
2531
+ convertBase = /* @__PURE__ */ function() {
2532
+ var decimal = "0123456789";
2533
+ function toBaseOut(str, baseIn, baseOut, alphabet) {
2534
+ var j, arr = [0], arrL, i = 0, len = str.length;
2535
+ for (; i < len; ) {
2536
+ for (arrL = arr.length; arrL--; arr[arrL] *= baseIn) ;
2537
+ arr[0] += alphabet.indexOf(str.charAt(i++));
2538
+ for (j = 0; j < arr.length; j++) {
2539
+ if (arr[j] > baseOut - 1) {
2540
+ if (arr[j + 1] == null) arr[j + 1] = 0;
2541
+ arr[j + 1] += arr[j] / baseOut | 0;
2542
+ arr[j] %= baseOut;
2543
+ }
2544
+ }
2545
+ }
2546
+ return arr.reverse();
2547
+ }
2548
+ __name(toBaseOut, "toBaseOut");
2549
+ return function(str, baseIn, baseOut, sign, callerIsToString) {
2550
+ var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
2551
+ if (i >= 0) {
2552
+ k = POW_PRECISION;
2553
+ POW_PRECISION = 0;
2554
+ str = str.replace(".", "");
2555
+ y = new BigNumber2(baseIn);
2556
+ x = y.pow(str.length - i);
2557
+ POW_PRECISION = k;
2558
+ y.c = toBaseOut(
2559
+ toFixedPoint(coeffToString(x.c), x.e, "0"),
2560
+ 10,
2561
+ baseOut,
2562
+ decimal
2563
+ );
2564
+ y.e = y.c.length;
2565
+ }
2566
+ xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
2567
+ e = k = xc.length;
2568
+ for (; xc[--k] == 0; xc.pop()) ;
2569
+ if (!xc[0]) return alphabet.charAt(0);
2570
+ if (i < 0) {
2571
+ --e;
2572
+ } else {
2573
+ x.c = xc;
2574
+ x.e = e;
2575
+ x.s = sign;
2576
+ x = div(x, y, dp, rm, baseOut);
2577
+ xc = x.c;
2578
+ r = x.r;
2579
+ e = x.e;
2580
+ }
2581
+ d = e + dp + 1;
2582
+ i = xc[d];
2583
+ k = baseOut / 2;
2584
+ r = r || d < 0 || xc[d + 1] != null;
2585
+ r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
2586
+ if (d < 1 || !xc[0]) {
2587
+ str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
2588
+ } else {
2589
+ xc.length = d;
2590
+ if (r) {
2591
+ for (--baseOut; ++xc[--d] > baseOut; ) {
2592
+ xc[d] = 0;
2593
+ if (!d) {
2594
+ ++e;
2595
+ xc = [1].concat(xc);
2596
+ }
2597
+ }
2598
+ }
2599
+ for (k = xc.length; !xc[--k]; ) ;
2600
+ for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++])) ;
2601
+ str = toFixedPoint(str, e, alphabet.charAt(0));
2602
+ }
2603
+ return str;
2604
+ };
2605
+ }();
2606
+ div = /* @__PURE__ */ function() {
2607
+ function multiply(x, k, base) {
2608
+ var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
2609
+ for (x = x.slice(); i--; ) {
2610
+ xlo = x[i] % SQRT_BASE;
2611
+ xhi = x[i] / SQRT_BASE | 0;
2612
+ m = khi * xlo + xhi * klo;
2613
+ temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
2614
+ carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
2615
+ x[i] = temp % base;
2616
+ }
2617
+ if (carry) x = [carry].concat(x);
2618
+ return x;
2619
+ }
2620
+ __name(multiply, "multiply");
2621
+ function compare2(a, b, aL, bL) {
2622
+ var i, cmp;
2623
+ if (aL != bL) {
2624
+ cmp = aL > bL ? 1 : -1;
2625
+ } else {
2626
+ for (i = cmp = 0; i < aL; i++) {
2627
+ if (a[i] != b[i]) {
2628
+ cmp = a[i] > b[i] ? 1 : -1;
2629
+ break;
2630
+ }
2631
+ }
2632
+ }
2633
+ return cmp;
2634
+ }
2635
+ __name(compare2, "compare");
2636
+ function subtract(a, b, aL, base) {
2637
+ var i = 0;
2638
+ for (; aL--; ) {
2639
+ a[aL] -= i;
2640
+ i = a[aL] < b[aL] ? 1 : 0;
2641
+ a[aL] = i * base + a[aL] - b[aL];
2642
+ }
2643
+ for (; !a[0] && a.length > 1; a.splice(0, 1)) ;
2644
+ }
2645
+ __name(subtract, "subtract");
2646
+ return function(x, y, dp, rm, base) {
2647
+ var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
2648
+ if (!xc || !xc[0] || !yc || !yc[0]) {
2649
+ return new BigNumber2(
2650
+ // Return NaN if either NaN, or both Infinity or 0.
2651
+ !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
2652
+ // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
2653
+ xc && xc[0] == 0 || !yc ? s * 0 : s / 0
2654
+ )
2655
+ );
2656
+ }
2657
+ q = new BigNumber2(s);
2658
+ qc = q.c = [];
2659
+ e = x.e - y.e;
2660
+ s = dp + e + 1;
2661
+ if (!base) {
2662
+ base = BASE;
2663
+ e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
2664
+ s = s / LOG_BASE | 0;
2665
+ }
2666
+ for (i = 0; yc[i] == (xc[i] || 0); i++) ;
2667
+ if (yc[i] > (xc[i] || 0)) e--;
2668
+ if (s < 0) {
2669
+ qc.push(1);
2670
+ more = true;
2671
+ } else {
2672
+ xL = xc.length;
2673
+ yL = yc.length;
2674
+ i = 0;
2675
+ s += 2;
2676
+ n = mathfloor(base / (yc[0] + 1));
2677
+ if (n > 1) {
2678
+ yc = multiply(yc, n, base);
2679
+ xc = multiply(xc, n, base);
2680
+ yL = yc.length;
2681
+ xL = xc.length;
2682
+ }
2683
+ xi = yL;
2684
+ rem = xc.slice(0, yL);
2685
+ remL = rem.length;
2686
+ for (; remL < yL; rem[remL++] = 0) ;
2687
+ yz = yc.slice();
2688
+ yz = [0].concat(yz);
2689
+ yc0 = yc[0];
2690
+ if (yc[1] >= base / 2) yc0++;
2691
+ do {
2692
+ n = 0;
2693
+ cmp = compare2(yc, rem, yL, remL);
2694
+ if (cmp < 0) {
2695
+ rem0 = rem[0];
2696
+ if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
2697
+ n = mathfloor(rem0 / yc0);
2698
+ if (n > 1) {
2699
+ if (n >= base) n = base - 1;
2700
+ prod = multiply(yc, n, base);
2701
+ prodL = prod.length;
2702
+ remL = rem.length;
2703
+ while (compare2(prod, rem, prodL, remL) == 1) {
2704
+ n--;
2705
+ subtract(prod, yL < prodL ? yz : yc, prodL, base);
2706
+ prodL = prod.length;
2707
+ cmp = 1;
2708
+ }
2709
+ } else {
2710
+ if (n == 0) {
2711
+ cmp = n = 1;
2712
+ }
2713
+ prod = yc.slice();
2714
+ prodL = prod.length;
2715
+ }
2716
+ if (prodL < remL) prod = [0].concat(prod);
2717
+ subtract(rem, prod, remL, base);
2718
+ remL = rem.length;
2719
+ if (cmp == -1) {
2720
+ while (compare2(yc, rem, yL, remL) < 1) {
2721
+ n++;
2722
+ subtract(rem, yL < remL ? yz : yc, remL, base);
2723
+ remL = rem.length;
2724
+ }
2725
+ }
2726
+ } else if (cmp === 0) {
2727
+ n++;
2728
+ rem = [0];
2729
+ }
2730
+ qc[i++] = n;
2731
+ if (rem[0]) {
2732
+ rem[remL++] = xc[xi] || 0;
2733
+ } else {
2734
+ rem = [xc[xi]];
2735
+ remL = 1;
2736
+ }
2737
+ } while ((xi++ < xL || rem[0] != null) && s--);
2738
+ more = rem[0] != null;
2739
+ if (!qc[0]) qc.splice(0, 1);
2740
+ }
2741
+ if (base == BASE) {
2742
+ for (i = 1, s = qc[0]; s >= 10; s /= 10, i++) ;
2743
+ round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
2744
+ } else {
2745
+ q.e = e;
2746
+ q.r = +more;
2747
+ }
2748
+ return q;
2749
+ };
2750
+ }();
2751
+ function format(n, i, rm, id) {
2752
+ var c0, e, ne, len, str;
2753
+ if (rm == null) rm = ROUNDING_MODE;
2754
+ else intCheck(rm, 0, 8);
2755
+ if (!n.c) return n.toString();
2756
+ c0 = n.c[0];
2757
+ ne = n.e;
2758
+ if (i == null) {
2759
+ str = coeffToString(n.c);
2760
+ str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
2761
+ } else {
2762
+ n = round(new BigNumber2(n), i, rm);
2763
+ e = n.e;
2764
+ str = coeffToString(n.c);
2765
+ len = str.length;
2766
+ if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
2767
+ for (; len < i; str += "0", len++) ;
2768
+ str = toExponential(str, e);
2769
+ } else {
2770
+ i -= ne;
2771
+ str = toFixedPoint(str, e, "0");
2772
+ if (e + 1 > len) {
2773
+ if (--i > 0) for (str += "."; i--; str += "0") ;
2774
+ } else {
2775
+ i += e - len;
2776
+ if (i > 0) {
2777
+ if (e + 1 == len) str += ".";
2778
+ for (; i--; str += "0") ;
2779
+ }
2780
+ }
2781
+ }
2782
+ }
2783
+ return n.s < 0 && c0 ? "-" + str : str;
2784
+ }
2785
+ __name(format, "format");
2786
+ function maxOrMin(args, n) {
2787
+ var k, y, i = 1, x = new BigNumber2(args[0]);
2788
+ for (; i < args.length; i++) {
2789
+ y = new BigNumber2(args[i]);
2790
+ if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
2791
+ x = y;
2792
+ }
2793
+ }
2794
+ return x;
2795
+ }
2796
+ __name(maxOrMin, "maxOrMin");
2797
+ function normalise(n, c, e) {
2798
+ var i = 1, j = c.length;
2799
+ for (; !c[--j]; c.pop()) ;
2800
+ for (j = c[0]; j >= 10; j /= 10, i++) ;
2801
+ if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
2802
+ n.c = n.e = null;
2803
+ } else if (e < MIN_EXP) {
2804
+ n.c = [n.e = 0];
2805
+ } else {
2806
+ n.e = e;
2807
+ n.c = c;
2808
+ }
2809
+ return n;
2810
+ }
2811
+ __name(normalise, "normalise");
2812
+ parseNumeric = /* @__PURE__ */ function() {
2813
+ var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
2814
+ return function(x, str, isNum, b) {
2815
+ var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
2816
+ if (isInfinityOrNaN.test(s)) {
2817
+ x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
2818
+ } else {
2819
+ if (!isNum) {
2820
+ s = s.replace(basePrefix, function(m, p1, p2) {
2821
+ base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
2822
+ return !b || b == base ? p1 : m;
2823
+ });
2824
+ if (b) {
2825
+ base = b;
2826
+ s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
2827
+ }
2828
+ if (str != s) return new BigNumber2(s, base);
2829
+ }
2830
+ if (BigNumber2.DEBUG) {
2831
+ throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
2832
+ }
2833
+ x.s = null;
2834
+ }
2835
+ x.c = x.e = null;
2836
+ };
2837
+ }();
2838
+ function round(x, sd, rm, r) {
2839
+ var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
2840
+ if (xc) {
2841
+ out: {
2842
+ for (d = 1, k = xc[0]; k >= 10; k /= 10, d++) ;
2843
+ i = sd - d;
2844
+ if (i < 0) {
2845
+ i += LOG_BASE;
2846
+ j = sd;
2847
+ n = xc[ni = 0];
2848
+ rd = mathfloor(n / pows10[d - j - 1] % 10);
2849
+ } else {
2850
+ ni = mathceil((i + 1) / LOG_BASE);
2851
+ if (ni >= xc.length) {
2852
+ if (r) {
2853
+ for (; xc.length <= ni; xc.push(0)) ;
2854
+ n = rd = 0;
2855
+ d = 1;
2856
+ i %= LOG_BASE;
2857
+ j = i - LOG_BASE + 1;
2858
+ } else {
2859
+ break out;
2860
+ }
2861
+ } else {
2862
+ n = k = xc[ni];
2863
+ for (d = 1; k >= 10; k /= 10, d++) ;
2864
+ i %= LOG_BASE;
2865
+ j = i - LOG_BASE + d;
2866
+ rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
2867
+ }
2868
+ }
2869
+ r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
2870
+ // The expression n % pows10[d - j - 1] returns all digits of n to the right
2871
+ // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
2872
+ xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
2873
+ r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
2874
+ (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
2875
+ if (sd < 1 || !xc[0]) {
2876
+ xc.length = 0;
2877
+ if (r) {
2878
+ sd -= x.e + 1;
2879
+ xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
2880
+ x.e = -sd || 0;
2881
+ } else {
2882
+ xc[0] = x.e = 0;
2883
+ }
2884
+ return x;
2885
+ }
2886
+ if (i == 0) {
2887
+ xc.length = ni;
2888
+ k = 1;
2889
+ ni--;
2890
+ } else {
2891
+ xc.length = ni + 1;
2892
+ k = pows10[LOG_BASE - i];
2893
+ xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
2894
+ }
2895
+ if (r) {
2896
+ for (; ; ) {
2897
+ if (ni == 0) {
2898
+ for (i = 1, j = xc[0]; j >= 10; j /= 10, i++) ;
2899
+ j = xc[0] += k;
2900
+ for (k = 1; j >= 10; j /= 10, k++) ;
2901
+ if (i != k) {
2902
+ x.e++;
2903
+ if (xc[0] == BASE) xc[0] = 1;
2904
+ }
2905
+ break;
2906
+ } else {
2907
+ xc[ni] += k;
2908
+ if (xc[ni] != BASE) break;
2909
+ xc[ni--] = 0;
2910
+ k = 1;
2911
+ }
2912
+ }
2913
+ }
2914
+ for (i = xc.length; xc[--i] === 0; xc.pop()) ;
2915
+ }
2916
+ if (x.e > MAX_EXP) {
2917
+ x.c = x.e = null;
2918
+ } else if (x.e < MIN_EXP) {
2919
+ x.c = [x.e = 0];
2920
+ }
2921
+ }
2922
+ return x;
2923
+ }
2924
+ __name(round, "round");
2925
+ function valueOf(n) {
2926
+ var str, e = n.e;
2927
+ if (e === null) return n.toString();
2928
+ str = coeffToString(n.c);
2929
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
2930
+ return n.s < 0 ? "-" + str : str;
2931
+ }
2932
+ __name(valueOf, "valueOf");
2933
+ P.absoluteValue = P.abs = function() {
2934
+ var x = new BigNumber2(this);
2935
+ if (x.s < 0) x.s = 1;
2936
+ return x;
2937
+ };
2938
+ P.comparedTo = function(y, b) {
2939
+ return compare(this, new BigNumber2(y, b));
2940
+ };
2941
+ P.decimalPlaces = P.dp = function(dp, rm) {
2942
+ var c, n, v, x = this;
2943
+ if (dp != null) {
2944
+ intCheck(dp, 0, MAX);
2945
+ if (rm == null) rm = ROUNDING_MODE;
2946
+ else intCheck(rm, 0, 8);
2947
+ return round(new BigNumber2(x), dp + x.e + 1, rm);
2948
+ }
2949
+ if (!(c = x.c)) return null;
2950
+ n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
2951
+ if (v = c[v]) for (; v % 10 == 0; v /= 10, n--) ;
2952
+ if (n < 0) n = 0;
2953
+ return n;
2954
+ };
2955
+ P.dividedBy = P.div = function(y, b) {
2956
+ return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
2957
+ };
2958
+ P.dividedToIntegerBy = P.idiv = function(y, b) {
2959
+ return div(this, new BigNumber2(y, b), 0, 1);
2960
+ };
2961
+ P.exponentiatedBy = P.pow = function(n, m) {
2962
+ var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
2963
+ n = new BigNumber2(n);
2964
+ if (n.c && !n.isInteger()) {
2965
+ throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
2966
+ }
2967
+ if (m != null) m = new BigNumber2(m);
2968
+ nIsBig = n.e > 14;
2969
+ if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
2970
+ y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
2971
+ return m ? y.mod(m) : y;
2972
+ }
2973
+ nIsNeg = n.s < 0;
2974
+ if (m) {
2975
+ if (m.c ? !m.c[0] : !m.s) return new BigNumber2(NaN);
2976
+ isModExp = !nIsNeg && x.isInteger() && m.isInteger();
2977
+ if (isModExp) x = x.mod(m);
2978
+ } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
2979
+ k = x.s < 0 && isOdd(n) ? -0 : 0;
2980
+ if (x.e > -1) k = 1 / k;
2981
+ return new BigNumber2(nIsNeg ? 1 / k : k);
2982
+ } else if (POW_PRECISION) {
2983
+ k = mathceil(POW_PRECISION / LOG_BASE + 2);
2984
+ }
2985
+ if (nIsBig) {
2986
+ half = new BigNumber2(0.5);
2987
+ if (nIsNeg) n.s = 1;
2988
+ nIsOdd = isOdd(n);
2989
+ } else {
2990
+ i = Math.abs(+valueOf(n));
2991
+ nIsOdd = i % 2;
2992
+ }
2993
+ y = new BigNumber2(ONE);
2994
+ for (; ; ) {
2995
+ if (nIsOdd) {
2996
+ y = y.times(x);
2997
+ if (!y.c) break;
2998
+ if (k) {
2999
+ if (y.c.length > k) y.c.length = k;
3000
+ } else if (isModExp) {
3001
+ y = y.mod(m);
3002
+ }
3003
+ }
3004
+ if (i) {
3005
+ i = mathfloor(i / 2);
3006
+ if (i === 0) break;
3007
+ nIsOdd = i % 2;
3008
+ } else {
3009
+ n = n.times(half);
3010
+ round(n, n.e + 1, 1);
3011
+ if (n.e > 14) {
3012
+ nIsOdd = isOdd(n);
3013
+ } else {
3014
+ i = +valueOf(n);
3015
+ if (i === 0) break;
3016
+ nIsOdd = i % 2;
3017
+ }
3018
+ }
3019
+ x = x.times(x);
3020
+ if (k) {
3021
+ if (x.c && x.c.length > k) x.c.length = k;
3022
+ } else if (isModExp) {
3023
+ x = x.mod(m);
3024
+ }
3025
+ }
3026
+ if (isModExp) return y;
3027
+ if (nIsNeg) y = ONE.div(y);
3028
+ return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
3029
+ };
3030
+ P.integerValue = function(rm) {
3031
+ var n = new BigNumber2(this);
3032
+ if (rm == null) rm = ROUNDING_MODE;
3033
+ else intCheck(rm, 0, 8);
3034
+ return round(n, n.e + 1, rm);
3035
+ };
3036
+ P.isEqualTo = P.eq = function(y, b) {
3037
+ return compare(this, new BigNumber2(y, b)) === 0;
3038
+ };
3039
+ P.isFinite = function() {
3040
+ return !!this.c;
3041
+ };
3042
+ P.isGreaterThan = P.gt = function(y, b) {
3043
+ return compare(this, new BigNumber2(y, b)) > 0;
3044
+ };
3045
+ P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
3046
+ return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
3047
+ };
3048
+ P.isInteger = function() {
3049
+ return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
3050
+ };
3051
+ P.isLessThan = P.lt = function(y, b) {
3052
+ return compare(this, new BigNumber2(y, b)) < 0;
3053
+ };
3054
+ P.isLessThanOrEqualTo = P.lte = function(y, b) {
3055
+ return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
3056
+ };
3057
+ P.isNaN = function() {
3058
+ return !this.s;
3059
+ };
3060
+ P.isNegative = function() {
3061
+ return this.s < 0;
3062
+ };
3063
+ P.isPositive = function() {
3064
+ return this.s > 0;
3065
+ };
3066
+ P.isZero = function() {
3067
+ return !!this.c && this.c[0] == 0;
3068
+ };
3069
+ P.minus = function(y, b) {
3070
+ var i, j, t, xLTy, x = this, a = x.s;
3071
+ y = new BigNumber2(y, b);
3072
+ b = y.s;
3073
+ if (!a || !b) return new BigNumber2(NaN);
3074
+ if (a != b) {
3075
+ y.s = -b;
3076
+ return x.plus(y);
3077
+ }
3078
+ var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
3079
+ if (!xe || !ye) {
3080
+ if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
3081
+ if (!xc[0] || !yc[0]) {
3082
+ return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
3083
+ // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
3084
+ ROUNDING_MODE == 3 ? -0 : 0
3085
+ ));
3086
+ }
3087
+ }
3088
+ xe = bitFloor(xe);
3089
+ ye = bitFloor(ye);
3090
+ xc = xc.slice();
3091
+ if (a = xe - ye) {
3092
+ if (xLTy = a < 0) {
3093
+ a = -a;
3094
+ t = xc;
3095
+ } else {
3096
+ ye = xe;
3097
+ t = yc;
3098
+ }
3099
+ t.reverse();
3100
+ for (b = a; b--; t.push(0)) ;
3101
+ t.reverse();
3102
+ } else {
3103
+ j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
3104
+ for (a = b = 0; b < j; b++) {
3105
+ if (xc[b] != yc[b]) {
3106
+ xLTy = xc[b] < yc[b];
3107
+ break;
3108
+ }
3109
+ }
3110
+ }
3111
+ if (xLTy) {
3112
+ t = xc;
3113
+ xc = yc;
3114
+ yc = t;
3115
+ y.s = -y.s;
3116
+ }
3117
+ b = (j = yc.length) - (i = xc.length);
3118
+ if (b > 0) for (; b--; xc[i++] = 0) ;
3119
+ b = BASE - 1;
3120
+ for (; j > a; ) {
3121
+ if (xc[--j] < yc[j]) {
3122
+ for (i = j; i && !xc[--i]; xc[i] = b) ;
3123
+ --xc[i];
3124
+ xc[j] += BASE;
3125
+ }
3126
+ xc[j] -= yc[j];
3127
+ }
3128
+ for (; xc[0] == 0; xc.splice(0, 1), --ye) ;
3129
+ if (!xc[0]) {
3130
+ y.s = ROUNDING_MODE == 3 ? -1 : 1;
3131
+ y.c = [y.e = 0];
3132
+ return y;
3133
+ }
3134
+ return normalise(y, xc, ye);
3135
+ };
3136
+ P.modulo = P.mod = function(y, b) {
3137
+ var q, s, x = this;
3138
+ y = new BigNumber2(y, b);
3139
+ if (!x.c || !y.s || y.c && !y.c[0]) {
3140
+ return new BigNumber2(NaN);
3141
+ } else if (!y.c || x.c && !x.c[0]) {
3142
+ return new BigNumber2(x);
3143
+ }
3144
+ if (MODULO_MODE == 9) {
3145
+ s = y.s;
3146
+ y.s = 1;
3147
+ q = div(x, y, 0, 3);
3148
+ y.s = s;
3149
+ q.s *= s;
3150
+ } else {
3151
+ q = div(x, y, 0, MODULO_MODE);
3152
+ }
3153
+ y = x.minus(q.times(y));
3154
+ if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
3155
+ return y;
3156
+ };
3157
+ P.multipliedBy = P.times = function(y, b) {
3158
+ var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
3159
+ if (!xc || !yc || !xc[0] || !yc[0]) {
3160
+ if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
3161
+ y.c = y.e = y.s = null;
3162
+ } else {
3163
+ y.s *= x.s;
3164
+ if (!xc || !yc) {
3165
+ y.c = y.e = null;
3166
+ } else {
3167
+ y.c = [0];
3168
+ y.e = 0;
3169
+ }
3170
+ }
3171
+ return y;
3172
+ }
3173
+ e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
3174
+ y.s *= x.s;
3175
+ xcL = xc.length;
3176
+ ycL = yc.length;
3177
+ if (xcL < ycL) {
3178
+ zc = xc;
3179
+ xc = yc;
3180
+ yc = zc;
3181
+ i = xcL;
3182
+ xcL = ycL;
3183
+ ycL = i;
3184
+ }
3185
+ for (i = xcL + ycL, zc = []; i--; zc.push(0)) ;
3186
+ base = BASE;
3187
+ sqrtBase = SQRT_BASE;
3188
+ for (i = ycL; --i >= 0; ) {
3189
+ c = 0;
3190
+ ylo = yc[i] % sqrtBase;
3191
+ yhi = yc[i] / sqrtBase | 0;
3192
+ for (k = xcL, j = i + k; j > i; ) {
3193
+ xlo = xc[--k] % sqrtBase;
3194
+ xhi = xc[k] / sqrtBase | 0;
3195
+ m = yhi * xlo + xhi * ylo;
3196
+ xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
3197
+ c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
3198
+ zc[j--] = xlo % base;
3199
+ }
3200
+ zc[j] = c;
3201
+ }
3202
+ if (c) {
3203
+ ++e;
3204
+ } else {
3205
+ zc.splice(0, 1);
3206
+ }
3207
+ return normalise(y, zc, e);
3208
+ };
3209
+ P.negated = function() {
3210
+ var x = new BigNumber2(this);
3211
+ x.s = -x.s || null;
3212
+ return x;
3213
+ };
3214
+ P.plus = function(y, b) {
3215
+ var t, x = this, a = x.s;
3216
+ y = new BigNumber2(y, b);
3217
+ b = y.s;
3218
+ if (!a || !b) return new BigNumber2(NaN);
3219
+ if (a != b) {
3220
+ y.s = -b;
3221
+ return x.minus(y);
3222
+ }
3223
+ var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
3224
+ if (!xe || !ye) {
3225
+ if (!xc || !yc) return new BigNumber2(a / 0);
3226
+ if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
3227
+ }
3228
+ xe = bitFloor(xe);
3229
+ ye = bitFloor(ye);
3230
+ xc = xc.slice();
3231
+ if (a = xe - ye) {
3232
+ if (a > 0) {
3233
+ ye = xe;
3234
+ t = yc;
3235
+ } else {
3236
+ a = -a;
3237
+ t = xc;
3238
+ }
3239
+ t.reverse();
3240
+ for (; a--; t.push(0)) ;
3241
+ t.reverse();
3242
+ }
3243
+ a = xc.length;
3244
+ b = yc.length;
3245
+ if (a - b < 0) {
3246
+ t = yc;
3247
+ yc = xc;
3248
+ xc = t;
3249
+ b = a;
3250
+ }
3251
+ for (a = 0; b; ) {
3252
+ a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
3253
+ xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
3254
+ }
3255
+ if (a) {
3256
+ xc = [a].concat(xc);
3257
+ ++ye;
3258
+ }
3259
+ return normalise(y, xc, ye);
3260
+ };
3261
+ P.precision = P.sd = function(sd, rm) {
3262
+ var c, n, v, x = this;
3263
+ if (sd != null && sd !== !!sd) {
3264
+ intCheck(sd, 1, MAX);
3265
+ if (rm == null) rm = ROUNDING_MODE;
3266
+ else intCheck(rm, 0, 8);
3267
+ return round(new BigNumber2(x), sd, rm);
3268
+ }
3269
+ if (!(c = x.c)) return null;
3270
+ v = c.length - 1;
3271
+ n = v * LOG_BASE + 1;
3272
+ if (v = c[v]) {
3273
+ for (; v % 10 == 0; v /= 10, n--) ;
3274
+ for (v = c[0]; v >= 10; v /= 10, n++) ;
3275
+ }
3276
+ if (sd && x.e + 1 > n) n = x.e + 1;
3277
+ return n;
3278
+ };
3279
+ P.shiftedBy = function(k) {
3280
+ intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
3281
+ return this.times("1e" + k);
3282
+ };
3283
+ P.squareRoot = P.sqrt = function() {
3284
+ var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
3285
+ if (s !== 1 || !c || !c[0]) {
3286
+ return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
3287
+ }
3288
+ s = Math.sqrt(+valueOf(x));
3289
+ if (s == 0 || s == 1 / 0) {
3290
+ n = coeffToString(c);
3291
+ if ((n.length + e) % 2 == 0) n += "0";
3292
+ s = Math.sqrt(+n);
3293
+ e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
3294
+ if (s == 1 / 0) {
3295
+ n = "5e" + e;
3296
+ } else {
3297
+ n = s.toExponential();
3298
+ n = n.slice(0, n.indexOf("e") + 1) + e;
3299
+ }
3300
+ r = new BigNumber2(n);
3301
+ } else {
3302
+ r = new BigNumber2(s + "");
3303
+ }
3304
+ if (r.c[0]) {
3305
+ e = r.e;
3306
+ s = e + dp;
3307
+ if (s < 3) s = 0;
3308
+ for (; ; ) {
3309
+ t = r;
3310
+ r = half.times(t.plus(div(x, t, dp, 1)));
3311
+ if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
3312
+ if (r.e < e) --s;
3313
+ n = n.slice(s - 3, s + 1);
3314
+ if (n == "9999" || !rep && n == "4999") {
3315
+ if (!rep) {
3316
+ round(t, t.e + DECIMAL_PLACES + 2, 0);
3317
+ if (t.times(t).eq(x)) {
3318
+ r = t;
3319
+ break;
3320
+ }
3321
+ }
3322
+ dp += 4;
3323
+ s += 4;
3324
+ rep = 1;
3325
+ } else {
3326
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
3327
+ round(r, r.e + DECIMAL_PLACES + 2, 1);
3328
+ m = !r.times(r).eq(x);
3329
+ }
3330
+ break;
3331
+ }
3332
+ }
3333
+ }
3334
+ }
3335
+ return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
3336
+ };
3337
+ P.toExponential = function(dp, rm) {
3338
+ if (dp != null) {
3339
+ intCheck(dp, 0, MAX);
3340
+ dp++;
3341
+ }
3342
+ return format(this, dp, rm, 1);
3343
+ };
3344
+ P.toFixed = function(dp, rm) {
3345
+ if (dp != null) {
3346
+ intCheck(dp, 0, MAX);
3347
+ dp = dp + this.e + 1;
3348
+ }
3349
+ return format(this, dp, rm);
3350
+ };
3351
+ P.toFormat = function(dp, rm, format2) {
3352
+ var str, x = this;
3353
+ if (format2 == null) {
3354
+ if (dp != null && rm && typeof rm == "object") {
3355
+ format2 = rm;
3356
+ rm = null;
3357
+ } else if (dp && typeof dp == "object") {
3358
+ format2 = dp;
3359
+ dp = rm = null;
3360
+ } else {
3361
+ format2 = FORMAT;
3362
+ }
3363
+ } else if (typeof format2 != "object") {
3364
+ throw Error(bignumberError + "Argument not an object: " + format2);
3365
+ }
3366
+ str = x.toFixed(dp, rm);
3367
+ if (x.c) {
3368
+ var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
3369
+ if (g2) {
3370
+ i = g1;
3371
+ g1 = g2;
3372
+ g2 = i;
3373
+ len -= i;
3374
+ }
3375
+ if (g1 > 0 && len > 0) {
3376
+ i = len % g1 || g1;
3377
+ intPart = intDigits.substr(0, i);
3378
+ for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
3379
+ if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
3380
+ if (isNeg) intPart = "-" + intPart;
3381
+ }
3382
+ str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
3383
+ new RegExp("\\d{" + g2 + "}\\B", "g"),
3384
+ "$&" + (format2.fractionGroupSeparator || "")
3385
+ ) : fractionPart) : intPart;
3386
+ }
3387
+ return (format2.prefix || "") + str + (format2.suffix || "");
3388
+ };
3389
+ P.toFraction = function(md) {
3390
+ var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
3391
+ if (md != null) {
3392
+ n = new BigNumber2(md);
3393
+ if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
3394
+ throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
3395
+ }
3396
+ }
3397
+ if (!xc) return new BigNumber2(x);
3398
+ d = new BigNumber2(ONE);
3399
+ n1 = d0 = new BigNumber2(ONE);
3400
+ d1 = n0 = new BigNumber2(ONE);
3401
+ s = coeffToString(xc);
3402
+ e = d.e = s.length - x.e - 1;
3403
+ d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
3404
+ md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
3405
+ exp = MAX_EXP;
3406
+ MAX_EXP = 1 / 0;
3407
+ n = new BigNumber2(s);
3408
+ n0.c[0] = 0;
3409
+ for (; ; ) {
3410
+ q = div(n, d, 0, 1);
3411
+ d2 = d0.plus(q.times(d1));
3412
+ if (d2.comparedTo(md) == 1) break;
3413
+ d0 = d1;
3414
+ d1 = d2;
3415
+ n1 = n0.plus(q.times(d2 = n1));
3416
+ n0 = d2;
3417
+ d = n.minus(q.times(d2 = d));
3418
+ n = d2;
3419
+ }
3420
+ d2 = div(md.minus(d0), d1, 0, 1);
3421
+ n0 = n0.plus(d2.times(n1));
3422
+ d0 = d0.plus(d2.times(d1));
3423
+ n0.s = n1.s = x.s;
3424
+ e = e * 2;
3425
+ r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
3426
+ div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
3427
+ ) < 1 ? [n1, d1] : [n0, d0];
3428
+ MAX_EXP = exp;
3429
+ return r;
3430
+ };
3431
+ P.toNumber = function() {
3432
+ return +valueOf(this);
3433
+ };
3434
+ P.toPrecision = function(sd, rm) {
3435
+ if (sd != null) intCheck(sd, 1, MAX);
3436
+ return format(this, sd, rm, 2);
3437
+ };
3438
+ P.toString = function(b) {
3439
+ var str, n = this, s = n.s, e = n.e;
3440
+ if (e === null) {
3441
+ if (s) {
3442
+ str = "Infinity";
3443
+ if (s < 0) str = "-" + str;
3444
+ } else {
3445
+ str = "NaN";
3446
+ }
3447
+ } else {
3448
+ if (b == null) {
3449
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
3450
+ } else if (b === 10 && alphabetHasNormalDecimalDigits) {
3451
+ n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
3452
+ str = toFixedPoint(coeffToString(n.c), n.e, "0");
3453
+ } else {
3454
+ intCheck(b, 2, ALPHABET.length, "Base");
3455
+ str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
3456
+ }
3457
+ if (s < 0 && n.c[0]) str = "-" + str;
3458
+ }
3459
+ return str;
3460
+ };
3461
+ P.valueOf = P.toJSON = function() {
3462
+ return valueOf(this);
3463
+ };
3464
+ P._isBigNumber = true;
3465
+ P[Symbol.toStringTag] = "BigNumber";
3466
+ P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
3467
+ if (configObject != null) BigNumber2.set(configObject);
3468
+ return BigNumber2;
3469
+ }
3470
+ __name(clone, "clone");
3471
+ function bitFloor(n) {
3472
+ var i = n | 0;
3473
+ return n > 0 || n === i ? i : i - 1;
3474
+ }
3475
+ __name(bitFloor, "bitFloor");
3476
+ function coeffToString(a) {
3477
+ var s, z, i = 1, j = a.length, r = a[0] + "";
3478
+ for (; i < j; ) {
3479
+ s = a[i++] + "";
3480
+ z = LOG_BASE - s.length;
3481
+ for (; z--; s = "0" + s) ;
3482
+ r += s;
3483
+ }
3484
+ for (j = r.length; r.charCodeAt(--j) === 48; ) ;
3485
+ return r.slice(0, j + 1 || 1);
3486
+ }
3487
+ __name(coeffToString, "coeffToString");
3488
+ function compare(x, y) {
3489
+ var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
3490
+ if (!i || !j) return null;
3491
+ a = xc && !xc[0];
3492
+ b = yc && !yc[0];
3493
+ if (a || b) return a ? b ? 0 : -j : i;
3494
+ if (i != j) return i;
3495
+ a = i < 0;
3496
+ b = k == l;
3497
+ if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
3498
+ if (!b) return k > l ^ a ? 1 : -1;
3499
+ j = (k = xc.length) < (l = yc.length) ? k : l;
3500
+ for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
3501
+ return k == l ? 0 : k > l ^ a ? 1 : -1;
3502
+ }
3503
+ __name(compare, "compare");
3504
+ function intCheck(n, min, max, name) {
3505
+ if (n < min || n > max || n !== mathfloor(n)) {
3506
+ throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
3507
+ }
3508
+ }
3509
+ __name(intCheck, "intCheck");
3510
+ function isOdd(n) {
3511
+ var k = n.c.length - 1;
3512
+ return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
3513
+ }
3514
+ __name(isOdd, "isOdd");
3515
+ function toExponential(str, e) {
3516
+ return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
3517
+ }
3518
+ __name(toExponential, "toExponential");
3519
+ function toFixedPoint(str, e, z) {
3520
+ var len, zs;
3521
+ if (e < 0) {
3522
+ for (zs = z + "."; ++e; zs += z) ;
3523
+ str = zs + str;
3524
+ } else {
3525
+ len = str.length;
3526
+ if (++e > len) {
3527
+ for (zs = z, e -= len; --e; zs += z) ;
3528
+ str += zs;
3529
+ } else if (e < len) {
3530
+ str = str.slice(0, e) + "." + str.slice(e);
3531
+ }
3532
+ }
3533
+ return str;
3534
+ }
3535
+ __name(toFixedPoint, "toFixedPoint");
3536
+ var BigNumber = clone();
3537
+ var bignumber_default = BigNumber;
3538
+ var getPriceX128FromPrice = /* @__PURE__ */ __name((price, srcAsset, destAsset) => bignumber_default(price).multipliedBy(new bignumber_default(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0), "getPriceX128FromPrice");
3539
+
2177
3540
  // ../shared/src/rpc/utils.ts
2178
3541
  var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
2179
3542
  var validateSwapAmount = /* @__PURE__ */ __name((env, asset, amount) => {
@@ -2345,11 +3708,12 @@ var getChainData = /* @__PURE__ */ __name((chain, network, env) => ({
2345
3708
  name: chain,
2346
3709
  evmChainId: getEvmChainId(chain, network),
2347
3710
  isMainnet: !isTestnet(network),
2348
- requiredBlockConfirmations: isNotNullish(env.ingressEgress.witnessSafetyMargins[chain]) ? Number(env.ingressEgress.witnessSafetyMargins[chain]) + 1 : void 0
3711
+ requiredBlockConfirmations: isNotNullish(env.ingressEgress.witnessSafetyMargins[chain]) ? Number(env.ingressEgress.witnessSafetyMargins[chain]) + 1 : void 0,
3712
+ maxRetryDurationBlocks: env.ingressEgress.maxSwapRetryDurationBlocks[chain]
2349
3713
  }), "getChainData");
2350
3714
 
2351
3715
  // package.json
2352
- var version = "1.5.0-alpha.0";
3716
+ var version = "1.5.0-alpha.2";
2353
3717
 
2354
3718
  // src/swap/consts.ts
2355
3719
  var CF_SDK_VERSION_HEADERS = {
@@ -2462,19 +3826,30 @@ var _SwapSDK = class _SwapSDK {
2462
3826
  }, options);
2463
3827
  }
2464
3828
  async requestDepositAddress(depositAddressRequest) {
2465
- const { srcChain, srcAsset, amount, brokerCommissionBps, affiliateBrokers } = depositAddressRequest;
3829
+ const { srcChain, srcAsset, amount, destChain, destAsset, brokerCommissionBps, affiliateBrokers } = depositAddressRequest;
2466
3830
  await this.validateSwapAmount({
2467
3831
  chain: srcChain,
2468
3832
  asset: srcAsset
2469
3833
  }, BigInt(amount));
3834
+ const fillOrKillParams = depositAddressRequest.fillOrKillParams ? {
3835
+ ...depositAddressRequest.fillOrKillParams,
3836
+ minPriceX128: getPriceX128FromPrice(depositAddressRequest.fillOrKillParams.minPrice, getInternalAsset({
3837
+ chain: srcChain,
3838
+ asset: srcAsset
3839
+ }), getInternalAsset({
3840
+ chain: destChain,
3841
+ asset: destAsset
3842
+ }))
3843
+ } : void 0;
2470
3844
  depositAddressRequest.ccmParams ?? (depositAddressRequest.ccmParams = depositAddressRequest.ccmMetadata);
2471
3845
  let response;
2472
3846
  if (this.options.broker !== void 0) {
2473
- const { requestSwapDepositAddress } = await import('./broker-QFRN2UBT.mjs');
3847
+ const { requestSwapDepositAddress } = await import('./broker-4AIV4KDP.mjs');
2474
3848
  const result = await requestSwapDepositAddress({
2475
3849
  ...depositAddressRequest,
2476
3850
  commissionBps: brokerCommissionBps ?? this.options.broker.commissionBps,
2477
- affiliates: affiliateBrokers
3851
+ affiliates: affiliateBrokers,
3852
+ fillOrKillParams
2478
3853
  }, {
2479
3854
  url: this.options.broker.url
2480
3855
  }, this.options.network);
@@ -2489,7 +3864,10 @@ var _SwapSDK = class _SwapSDK {
2489
3864
  } else {
2490
3865
  assert(!depositAddressRequest.brokerCommissionBps, "Broker commission is only supported only when initializing the SDK with a brokerUrl");
2491
3866
  assert(!depositAddressRequest.affiliateBrokers?.length, "Affiliate brokers are supported only when initializing the SDK with a brokerUrl");
2492
- response = await this.trpc.openSwapDepositChannel.mutate(depositAddressRequest);
3867
+ response = await this.trpc.openSwapDepositChannel.mutate({
3868
+ ...depositAddressRequest,
3869
+ fillOrKillParams
3870
+ });
2493
3871
  }
2494
3872
  return {
2495
3873
  ...depositAddressRequest,