@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.js CHANGED
@@ -4745,7 +4745,7 @@ var init_schemas = __esm({
4745
4745
  fillOrKillParams = z.object({
4746
4746
  retryDurationBlocks: number,
4747
4747
  refundAddress: z.string(),
4748
- minPrice: numericString
4748
+ minPriceX128: numericString
4749
4749
  });
4750
4750
  z.object({
4751
4751
  srcAsset: asset,
@@ -4830,10 +4830,10 @@ var init_broker = __esm({
4830
4830
  })).optional(),
4831
4831
  z.number().optional(),
4832
4832
  z.array(affiliateBroker).optional(),
4833
- fillOrKillParams.transform(({ retryDurationBlocks, refundAddress, minPrice }) => ({
4833
+ fillOrKillParams.transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
4834
4834
  retry_duration: retryDurationBlocks,
4835
4835
  refund_address: refundAddress,
4836
- min_price: `0x${BigInt(minPrice).toString(16)}`
4836
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`
4837
4837
  })).optional()
4838
4838
  ]).parse(params), "validateRequest");
4839
4839
  validateResponse = /* @__PURE__ */ __name((network, response) => z.object({
@@ -7027,6 +7027,1374 @@ SuperJSON.allowErrorProps;
7027
7027
 
7028
7028
  // src/swap/sdk.ts
7029
7029
  init_enums();
7030
+
7031
+ // ../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
7032
+ var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
7033
+ var mathceil = Math.ceil;
7034
+ var mathfloor = Math.floor;
7035
+ var bignumberError = "[BigNumber Error] ";
7036
+ var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
7037
+ var BASE = 1e14;
7038
+ var LOG_BASE = 14;
7039
+ var MAX_SAFE_INTEGER = 9007199254740991;
7040
+ var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
7041
+ var SQRT_BASE = 1e7;
7042
+ var MAX = 1e9;
7043
+ function clone(configObject) {
7044
+ 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 = {
7045
+ prefix: "",
7046
+ groupSize: 3,
7047
+ secondaryGroupSize: 0,
7048
+ groupSeparator: ",",
7049
+ decimalSeparator: ".",
7050
+ fractionGroupSize: 0,
7051
+ fractionGroupSeparator: "\xA0",
7052
+ // non-breaking space
7053
+ suffix: ""
7054
+ }, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
7055
+ function BigNumber2(v, b) {
7056
+ var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
7057
+ if (!(x instanceof BigNumber2)) return new BigNumber2(v, b);
7058
+ if (b == null) {
7059
+ if (v && v._isBigNumber === true) {
7060
+ x.s = v.s;
7061
+ if (!v.c || v.e > MAX_EXP) {
7062
+ x.c = x.e = null;
7063
+ } else if (v.e < MIN_EXP) {
7064
+ x.c = [x.e = 0];
7065
+ } else {
7066
+ x.e = v.e;
7067
+ x.c = v.c.slice();
7068
+ }
7069
+ return;
7070
+ }
7071
+ if ((isNum = typeof v == "number") && v * 0 == 0) {
7072
+ x.s = 1 / v < 0 ? (v = -v, -1) : 1;
7073
+ if (v === ~~v) {
7074
+ for (e = 0, i = v; i >= 10; i /= 10, e++) ;
7075
+ if (e > MAX_EXP) {
7076
+ x.c = x.e = null;
7077
+ } else {
7078
+ x.e = e;
7079
+ x.c = [v];
7080
+ }
7081
+ return;
7082
+ }
7083
+ str = String(v);
7084
+ } else {
7085
+ if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
7086
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
7087
+ }
7088
+ if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
7089
+ if ((i = str.search(/e/i)) > 0) {
7090
+ if (e < 0) e = i;
7091
+ e += +str.slice(i + 1);
7092
+ str = str.substring(0, i);
7093
+ } else if (e < 0) {
7094
+ e = str.length;
7095
+ }
7096
+ } else {
7097
+ intCheck(b, 2, ALPHABET.length, "Base");
7098
+ if (b == 10 && alphabetHasNormalDecimalDigits) {
7099
+ x = new BigNumber2(v);
7100
+ return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
7101
+ }
7102
+ str = String(v);
7103
+ if (isNum = typeof v == "number") {
7104
+ if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
7105
+ x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
7106
+ if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
7107
+ throw Error(tooManyDigits + v);
7108
+ }
7109
+ } else {
7110
+ x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
7111
+ }
7112
+ alphabet = ALPHABET.slice(0, b);
7113
+ e = i = 0;
7114
+ for (len = str.length; i < len; i++) {
7115
+ if (alphabet.indexOf(c = str.charAt(i)) < 0) {
7116
+ if (c == ".") {
7117
+ if (i > e) {
7118
+ e = len;
7119
+ continue;
7120
+ }
7121
+ } else if (!caseChanged) {
7122
+ if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
7123
+ caseChanged = true;
7124
+ i = -1;
7125
+ e = 0;
7126
+ continue;
7127
+ }
7128
+ }
7129
+ return parseNumeric(x, String(v), isNum, b);
7130
+ }
7131
+ }
7132
+ isNum = false;
7133
+ str = convertBase(str, b, 10, x.s);
7134
+ if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
7135
+ else e = str.length;
7136
+ }
7137
+ for (i = 0; str.charCodeAt(i) === 48; i++) ;
7138
+ for (len = str.length; str.charCodeAt(--len) === 48; ) ;
7139
+ if (str = str.slice(i, ++len)) {
7140
+ len -= i;
7141
+ if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
7142
+ throw Error(tooManyDigits + x.s * v);
7143
+ }
7144
+ if ((e = e - i - 1) > MAX_EXP) {
7145
+ x.c = x.e = null;
7146
+ } else if (e < MIN_EXP) {
7147
+ x.c = [x.e = 0];
7148
+ } else {
7149
+ x.e = e;
7150
+ x.c = [];
7151
+ i = (e + 1) % LOG_BASE;
7152
+ if (e < 0) i += LOG_BASE;
7153
+ if (i < len) {
7154
+ if (i) x.c.push(+str.slice(0, i));
7155
+ for (len -= LOG_BASE; i < len; ) {
7156
+ x.c.push(+str.slice(i, i += LOG_BASE));
7157
+ }
7158
+ i = LOG_BASE - (str = str.slice(i)).length;
7159
+ } else {
7160
+ i -= len;
7161
+ }
7162
+ for (; i--; str += "0") ;
7163
+ x.c.push(+str);
7164
+ }
7165
+ } else {
7166
+ x.c = [x.e = 0];
7167
+ }
7168
+ }
7169
+ __name(BigNumber2, "BigNumber");
7170
+ BigNumber2.clone = clone;
7171
+ BigNumber2.ROUND_UP = 0;
7172
+ BigNumber2.ROUND_DOWN = 1;
7173
+ BigNumber2.ROUND_CEIL = 2;
7174
+ BigNumber2.ROUND_FLOOR = 3;
7175
+ BigNumber2.ROUND_HALF_UP = 4;
7176
+ BigNumber2.ROUND_HALF_DOWN = 5;
7177
+ BigNumber2.ROUND_HALF_EVEN = 6;
7178
+ BigNumber2.ROUND_HALF_CEIL = 7;
7179
+ BigNumber2.ROUND_HALF_FLOOR = 8;
7180
+ BigNumber2.EUCLID = 9;
7181
+ BigNumber2.config = BigNumber2.set = function(obj) {
7182
+ var p, v;
7183
+ if (obj != null) {
7184
+ if (typeof obj == "object") {
7185
+ if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
7186
+ v = obj[p];
7187
+ intCheck(v, 0, MAX, p);
7188
+ DECIMAL_PLACES = v;
7189
+ }
7190
+ if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
7191
+ v = obj[p];
7192
+ intCheck(v, 0, 8, p);
7193
+ ROUNDING_MODE = v;
7194
+ }
7195
+ if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
7196
+ v = obj[p];
7197
+ if (v && v.pop) {
7198
+ intCheck(v[0], -MAX, 0, p);
7199
+ intCheck(v[1], 0, MAX, p);
7200
+ TO_EXP_NEG = v[0];
7201
+ TO_EXP_POS = v[1];
7202
+ } else {
7203
+ intCheck(v, -MAX, MAX, p);
7204
+ TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
7205
+ }
7206
+ }
7207
+ if (obj.hasOwnProperty(p = "RANGE")) {
7208
+ v = obj[p];
7209
+ if (v && v.pop) {
7210
+ intCheck(v[0], -MAX, -1, p);
7211
+ intCheck(v[1], 1, MAX, p);
7212
+ MIN_EXP = v[0];
7213
+ MAX_EXP = v[1];
7214
+ } else {
7215
+ intCheck(v, -MAX, MAX, p);
7216
+ if (v) {
7217
+ MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
7218
+ } else {
7219
+ throw Error(bignumberError + p + " cannot be zero: " + v);
7220
+ }
7221
+ }
7222
+ }
7223
+ if (obj.hasOwnProperty(p = "CRYPTO")) {
7224
+ v = obj[p];
7225
+ if (v === !!v) {
7226
+ if (v) {
7227
+ if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
7228
+ CRYPTO = v;
7229
+ } else {
7230
+ CRYPTO = !v;
7231
+ throw Error(bignumberError + "crypto unavailable");
7232
+ }
7233
+ } else {
7234
+ CRYPTO = v;
7235
+ }
7236
+ } else {
7237
+ throw Error(bignumberError + p + " not true or false: " + v);
7238
+ }
7239
+ }
7240
+ if (obj.hasOwnProperty(p = "MODULO_MODE")) {
7241
+ v = obj[p];
7242
+ intCheck(v, 0, 9, p);
7243
+ MODULO_MODE = v;
7244
+ }
7245
+ if (obj.hasOwnProperty(p = "POW_PRECISION")) {
7246
+ v = obj[p];
7247
+ intCheck(v, 0, MAX, p);
7248
+ POW_PRECISION = v;
7249
+ }
7250
+ if (obj.hasOwnProperty(p = "FORMAT")) {
7251
+ v = obj[p];
7252
+ if (typeof v == "object") FORMAT = v;
7253
+ else throw Error(bignumberError + p + " not an object: " + v);
7254
+ }
7255
+ if (obj.hasOwnProperty(p = "ALPHABET")) {
7256
+ v = obj[p];
7257
+ if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
7258
+ alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
7259
+ ALPHABET = v;
7260
+ } else {
7261
+ throw Error(bignumberError + p + " invalid: " + v);
7262
+ }
7263
+ }
7264
+ } else {
7265
+ throw Error(bignumberError + "Object expected: " + obj);
7266
+ }
7267
+ }
7268
+ return {
7269
+ DECIMAL_PLACES,
7270
+ ROUNDING_MODE,
7271
+ EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
7272
+ RANGE: [MIN_EXP, MAX_EXP],
7273
+ CRYPTO,
7274
+ MODULO_MODE,
7275
+ POW_PRECISION,
7276
+ FORMAT,
7277
+ ALPHABET
7278
+ };
7279
+ };
7280
+ BigNumber2.isBigNumber = function(v) {
7281
+ if (!v || v._isBigNumber !== true) return false;
7282
+ if (!BigNumber2.DEBUG) return true;
7283
+ var i, n, c = v.c, e = v.e, s = v.s;
7284
+ out: if ({}.toString.call(c) == "[object Array]") {
7285
+ if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
7286
+ if (c[0] === 0) {
7287
+ if (e === 0 && c.length === 1) return true;
7288
+ break out;
7289
+ }
7290
+ i = (e + 1) % LOG_BASE;
7291
+ if (i < 1) i += LOG_BASE;
7292
+ if (String(c[0]).length == i) {
7293
+ for (i = 0; i < c.length; i++) {
7294
+ n = c[i];
7295
+ if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
7296
+ }
7297
+ if (n !== 0) return true;
7298
+ }
7299
+ }
7300
+ } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
7301
+ return true;
7302
+ }
7303
+ throw Error(bignumberError + "Invalid BigNumber: " + v);
7304
+ };
7305
+ BigNumber2.maximum = BigNumber2.max = function() {
7306
+ return maxOrMin(arguments, -1);
7307
+ };
7308
+ BigNumber2.minimum = BigNumber2.min = function() {
7309
+ return maxOrMin(arguments, 1);
7310
+ };
7311
+ BigNumber2.random = function() {
7312
+ var pow2_53 = 9007199254740992;
7313
+ var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
7314
+ return mathfloor(Math.random() * pow2_53);
7315
+ } : function() {
7316
+ return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
7317
+ };
7318
+ return function(dp) {
7319
+ var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
7320
+ if (dp == null) dp = DECIMAL_PLACES;
7321
+ else intCheck(dp, 0, MAX);
7322
+ k = mathceil(dp / LOG_BASE);
7323
+ if (CRYPTO) {
7324
+ if (crypto.getRandomValues) {
7325
+ a = crypto.getRandomValues(new Uint32Array(k *= 2));
7326
+ for (; i < k; ) {
7327
+ v = a[i] * 131072 + (a[i + 1] >>> 11);
7328
+ if (v >= 9e15) {
7329
+ b = crypto.getRandomValues(new Uint32Array(2));
7330
+ a[i] = b[0];
7331
+ a[i + 1] = b[1];
7332
+ } else {
7333
+ c.push(v % 1e14);
7334
+ i += 2;
7335
+ }
7336
+ }
7337
+ i = k / 2;
7338
+ } else if (crypto.randomBytes) {
7339
+ a = crypto.randomBytes(k *= 7);
7340
+ for (; i < k; ) {
7341
+ 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];
7342
+ if (v >= 9e15) {
7343
+ crypto.randomBytes(7).copy(a, i);
7344
+ } else {
7345
+ c.push(v % 1e14);
7346
+ i += 7;
7347
+ }
7348
+ }
7349
+ i = k / 7;
7350
+ } else {
7351
+ CRYPTO = false;
7352
+ throw Error(bignumberError + "crypto unavailable");
7353
+ }
7354
+ }
7355
+ if (!CRYPTO) {
7356
+ for (; i < k; ) {
7357
+ v = random53bitInt();
7358
+ if (v < 9e15) c[i++] = v % 1e14;
7359
+ }
7360
+ }
7361
+ k = c[--i];
7362
+ dp %= LOG_BASE;
7363
+ if (k && dp) {
7364
+ v = POWS_TEN[LOG_BASE - dp];
7365
+ c[i] = mathfloor(k / v) * v;
7366
+ }
7367
+ for (; c[i] === 0; c.pop(), i--) ;
7368
+ if (i < 0) {
7369
+ c = [e = 0];
7370
+ } else {
7371
+ for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE) ;
7372
+ for (i = 1, v = c[0]; v >= 10; v /= 10, i++) ;
7373
+ if (i < LOG_BASE) e -= LOG_BASE - i;
7374
+ }
7375
+ rand.e = e;
7376
+ rand.c = c;
7377
+ return rand;
7378
+ };
7379
+ }();
7380
+ BigNumber2.sum = function() {
7381
+ var i = 1, args = arguments, sum = new BigNumber2(args[0]);
7382
+ for (; i < args.length; ) sum = sum.plus(args[i++]);
7383
+ return sum;
7384
+ };
7385
+ convertBase = /* @__PURE__ */ function() {
7386
+ var decimal = "0123456789";
7387
+ function toBaseOut(str, baseIn, baseOut, alphabet) {
7388
+ var j, arr = [0], arrL, i = 0, len = str.length;
7389
+ for (; i < len; ) {
7390
+ for (arrL = arr.length; arrL--; arr[arrL] *= baseIn) ;
7391
+ arr[0] += alphabet.indexOf(str.charAt(i++));
7392
+ for (j = 0; j < arr.length; j++) {
7393
+ if (arr[j] > baseOut - 1) {
7394
+ if (arr[j + 1] == null) arr[j + 1] = 0;
7395
+ arr[j + 1] += arr[j] / baseOut | 0;
7396
+ arr[j] %= baseOut;
7397
+ }
7398
+ }
7399
+ }
7400
+ return arr.reverse();
7401
+ }
7402
+ __name(toBaseOut, "toBaseOut");
7403
+ return function(str, baseIn, baseOut, sign, callerIsToString) {
7404
+ var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
7405
+ if (i >= 0) {
7406
+ k = POW_PRECISION;
7407
+ POW_PRECISION = 0;
7408
+ str = str.replace(".", "");
7409
+ y = new BigNumber2(baseIn);
7410
+ x = y.pow(str.length - i);
7411
+ POW_PRECISION = k;
7412
+ y.c = toBaseOut(
7413
+ toFixedPoint(coeffToString(x.c), x.e, "0"),
7414
+ 10,
7415
+ baseOut,
7416
+ decimal
7417
+ );
7418
+ y.e = y.c.length;
7419
+ }
7420
+ xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
7421
+ e = k = xc.length;
7422
+ for (; xc[--k] == 0; xc.pop()) ;
7423
+ if (!xc[0]) return alphabet.charAt(0);
7424
+ if (i < 0) {
7425
+ --e;
7426
+ } else {
7427
+ x.c = xc;
7428
+ x.e = e;
7429
+ x.s = sign;
7430
+ x = div(x, y, dp, rm, baseOut);
7431
+ xc = x.c;
7432
+ r = x.r;
7433
+ e = x.e;
7434
+ }
7435
+ d = e + dp + 1;
7436
+ i = xc[d];
7437
+ k = baseOut / 2;
7438
+ r = r || d < 0 || xc[d + 1] != null;
7439
+ 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));
7440
+ if (d < 1 || !xc[0]) {
7441
+ str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
7442
+ } else {
7443
+ xc.length = d;
7444
+ if (r) {
7445
+ for (--baseOut; ++xc[--d] > baseOut; ) {
7446
+ xc[d] = 0;
7447
+ if (!d) {
7448
+ ++e;
7449
+ xc = [1].concat(xc);
7450
+ }
7451
+ }
7452
+ }
7453
+ for (k = xc.length; !xc[--k]; ) ;
7454
+ for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++])) ;
7455
+ str = toFixedPoint(str, e, alphabet.charAt(0));
7456
+ }
7457
+ return str;
7458
+ };
7459
+ }();
7460
+ div = /* @__PURE__ */ function() {
7461
+ function multiply(x, k, base) {
7462
+ var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
7463
+ for (x = x.slice(); i--; ) {
7464
+ xlo = x[i] % SQRT_BASE;
7465
+ xhi = x[i] / SQRT_BASE | 0;
7466
+ m = khi * xlo + xhi * klo;
7467
+ temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
7468
+ carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
7469
+ x[i] = temp % base;
7470
+ }
7471
+ if (carry) x = [carry].concat(x);
7472
+ return x;
7473
+ }
7474
+ __name(multiply, "multiply");
7475
+ function compare2(a, b, aL, bL) {
7476
+ var i, cmp;
7477
+ if (aL != bL) {
7478
+ cmp = aL > bL ? 1 : -1;
7479
+ } else {
7480
+ for (i = cmp = 0; i < aL; i++) {
7481
+ if (a[i] != b[i]) {
7482
+ cmp = a[i] > b[i] ? 1 : -1;
7483
+ break;
7484
+ }
7485
+ }
7486
+ }
7487
+ return cmp;
7488
+ }
7489
+ __name(compare2, "compare");
7490
+ function subtract(a, b, aL, base) {
7491
+ var i = 0;
7492
+ for (; aL--; ) {
7493
+ a[aL] -= i;
7494
+ i = a[aL] < b[aL] ? 1 : 0;
7495
+ a[aL] = i * base + a[aL] - b[aL];
7496
+ }
7497
+ for (; !a[0] && a.length > 1; a.splice(0, 1)) ;
7498
+ }
7499
+ __name(subtract, "subtract");
7500
+ return function(x, y, dp, rm, base) {
7501
+ 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;
7502
+ if (!xc || !xc[0] || !yc || !yc[0]) {
7503
+ return new BigNumber2(
7504
+ // Return NaN if either NaN, or both Infinity or 0.
7505
+ !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
7506
+ // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
7507
+ xc && xc[0] == 0 || !yc ? s * 0 : s / 0
7508
+ )
7509
+ );
7510
+ }
7511
+ q = new BigNumber2(s);
7512
+ qc = q.c = [];
7513
+ e = x.e - y.e;
7514
+ s = dp + e + 1;
7515
+ if (!base) {
7516
+ base = BASE;
7517
+ e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
7518
+ s = s / LOG_BASE | 0;
7519
+ }
7520
+ for (i = 0; yc[i] == (xc[i] || 0); i++) ;
7521
+ if (yc[i] > (xc[i] || 0)) e--;
7522
+ if (s < 0) {
7523
+ qc.push(1);
7524
+ more = true;
7525
+ } else {
7526
+ xL = xc.length;
7527
+ yL = yc.length;
7528
+ i = 0;
7529
+ s += 2;
7530
+ n = mathfloor(base / (yc[0] + 1));
7531
+ if (n > 1) {
7532
+ yc = multiply(yc, n, base);
7533
+ xc = multiply(xc, n, base);
7534
+ yL = yc.length;
7535
+ xL = xc.length;
7536
+ }
7537
+ xi = yL;
7538
+ rem = xc.slice(0, yL);
7539
+ remL = rem.length;
7540
+ for (; remL < yL; rem[remL++] = 0) ;
7541
+ yz = yc.slice();
7542
+ yz = [0].concat(yz);
7543
+ yc0 = yc[0];
7544
+ if (yc[1] >= base / 2) yc0++;
7545
+ do {
7546
+ n = 0;
7547
+ cmp = compare2(yc, rem, yL, remL);
7548
+ if (cmp < 0) {
7549
+ rem0 = rem[0];
7550
+ if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
7551
+ n = mathfloor(rem0 / yc0);
7552
+ if (n > 1) {
7553
+ if (n >= base) n = base - 1;
7554
+ prod = multiply(yc, n, base);
7555
+ prodL = prod.length;
7556
+ remL = rem.length;
7557
+ while (compare2(prod, rem, prodL, remL) == 1) {
7558
+ n--;
7559
+ subtract(prod, yL < prodL ? yz : yc, prodL, base);
7560
+ prodL = prod.length;
7561
+ cmp = 1;
7562
+ }
7563
+ } else {
7564
+ if (n == 0) {
7565
+ cmp = n = 1;
7566
+ }
7567
+ prod = yc.slice();
7568
+ prodL = prod.length;
7569
+ }
7570
+ if (prodL < remL) prod = [0].concat(prod);
7571
+ subtract(rem, prod, remL, base);
7572
+ remL = rem.length;
7573
+ if (cmp == -1) {
7574
+ while (compare2(yc, rem, yL, remL) < 1) {
7575
+ n++;
7576
+ subtract(rem, yL < remL ? yz : yc, remL, base);
7577
+ remL = rem.length;
7578
+ }
7579
+ }
7580
+ } else if (cmp === 0) {
7581
+ n++;
7582
+ rem = [0];
7583
+ }
7584
+ qc[i++] = n;
7585
+ if (rem[0]) {
7586
+ rem[remL++] = xc[xi] || 0;
7587
+ } else {
7588
+ rem = [xc[xi]];
7589
+ remL = 1;
7590
+ }
7591
+ } while ((xi++ < xL || rem[0] != null) && s--);
7592
+ more = rem[0] != null;
7593
+ if (!qc[0]) qc.splice(0, 1);
7594
+ }
7595
+ if (base == BASE) {
7596
+ for (i = 1, s = qc[0]; s >= 10; s /= 10, i++) ;
7597
+ round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
7598
+ } else {
7599
+ q.e = e;
7600
+ q.r = +more;
7601
+ }
7602
+ return q;
7603
+ };
7604
+ }();
7605
+ function format(n, i, rm, id) {
7606
+ var c0, e, ne, len, str;
7607
+ if (rm == null) rm = ROUNDING_MODE;
7608
+ else intCheck(rm, 0, 8);
7609
+ if (!n.c) return n.toString();
7610
+ c0 = n.c[0];
7611
+ ne = n.e;
7612
+ if (i == null) {
7613
+ str = coeffToString(n.c);
7614
+ str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
7615
+ } else {
7616
+ n = round(new BigNumber2(n), i, rm);
7617
+ e = n.e;
7618
+ str = coeffToString(n.c);
7619
+ len = str.length;
7620
+ if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
7621
+ for (; len < i; str += "0", len++) ;
7622
+ str = toExponential(str, e);
7623
+ } else {
7624
+ i -= ne;
7625
+ str = toFixedPoint(str, e, "0");
7626
+ if (e + 1 > len) {
7627
+ if (--i > 0) for (str += "."; i--; str += "0") ;
7628
+ } else {
7629
+ i += e - len;
7630
+ if (i > 0) {
7631
+ if (e + 1 == len) str += ".";
7632
+ for (; i--; str += "0") ;
7633
+ }
7634
+ }
7635
+ }
7636
+ }
7637
+ return n.s < 0 && c0 ? "-" + str : str;
7638
+ }
7639
+ __name(format, "format");
7640
+ function maxOrMin(args, n) {
7641
+ var k, y, i = 1, x = new BigNumber2(args[0]);
7642
+ for (; i < args.length; i++) {
7643
+ y = new BigNumber2(args[i]);
7644
+ if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
7645
+ x = y;
7646
+ }
7647
+ }
7648
+ return x;
7649
+ }
7650
+ __name(maxOrMin, "maxOrMin");
7651
+ function normalise(n, c, e) {
7652
+ var i = 1, j = c.length;
7653
+ for (; !c[--j]; c.pop()) ;
7654
+ for (j = c[0]; j >= 10; j /= 10, i++) ;
7655
+ if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
7656
+ n.c = n.e = null;
7657
+ } else if (e < MIN_EXP) {
7658
+ n.c = [n.e = 0];
7659
+ } else {
7660
+ n.e = e;
7661
+ n.c = c;
7662
+ }
7663
+ return n;
7664
+ }
7665
+ __name(normalise, "normalise");
7666
+ parseNumeric = /* @__PURE__ */ function() {
7667
+ var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
7668
+ return function(x, str, isNum, b) {
7669
+ var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
7670
+ if (isInfinityOrNaN.test(s)) {
7671
+ x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
7672
+ } else {
7673
+ if (!isNum) {
7674
+ s = s.replace(basePrefix, function(m, p1, p2) {
7675
+ base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
7676
+ return !b || b == base ? p1 : m;
7677
+ });
7678
+ if (b) {
7679
+ base = b;
7680
+ s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
7681
+ }
7682
+ if (str != s) return new BigNumber2(s, base);
7683
+ }
7684
+ if (BigNumber2.DEBUG) {
7685
+ throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
7686
+ }
7687
+ x.s = null;
7688
+ }
7689
+ x.c = x.e = null;
7690
+ };
7691
+ }();
7692
+ function round(x, sd, rm, r) {
7693
+ var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
7694
+ if (xc) {
7695
+ out: {
7696
+ for (d = 1, k = xc[0]; k >= 10; k /= 10, d++) ;
7697
+ i = sd - d;
7698
+ if (i < 0) {
7699
+ i += LOG_BASE;
7700
+ j = sd;
7701
+ n = xc[ni = 0];
7702
+ rd = mathfloor(n / pows10[d - j - 1] % 10);
7703
+ } else {
7704
+ ni = mathceil((i + 1) / LOG_BASE);
7705
+ if (ni >= xc.length) {
7706
+ if (r) {
7707
+ for (; xc.length <= ni; xc.push(0)) ;
7708
+ n = rd = 0;
7709
+ d = 1;
7710
+ i %= LOG_BASE;
7711
+ j = i - LOG_BASE + 1;
7712
+ } else {
7713
+ break out;
7714
+ }
7715
+ } else {
7716
+ n = k = xc[ni];
7717
+ for (d = 1; k >= 10; k /= 10, d++) ;
7718
+ i %= LOG_BASE;
7719
+ j = i - LOG_BASE + d;
7720
+ rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
7721
+ }
7722
+ }
7723
+ r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
7724
+ // The expression n % pows10[d - j - 1] returns all digits of n to the right
7725
+ // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
7726
+ xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
7727
+ 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.
7728
+ (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
7729
+ if (sd < 1 || !xc[0]) {
7730
+ xc.length = 0;
7731
+ if (r) {
7732
+ sd -= x.e + 1;
7733
+ xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
7734
+ x.e = -sd || 0;
7735
+ } else {
7736
+ xc[0] = x.e = 0;
7737
+ }
7738
+ return x;
7739
+ }
7740
+ if (i == 0) {
7741
+ xc.length = ni;
7742
+ k = 1;
7743
+ ni--;
7744
+ } else {
7745
+ xc.length = ni + 1;
7746
+ k = pows10[LOG_BASE - i];
7747
+ xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
7748
+ }
7749
+ if (r) {
7750
+ for (; ; ) {
7751
+ if (ni == 0) {
7752
+ for (i = 1, j = xc[0]; j >= 10; j /= 10, i++) ;
7753
+ j = xc[0] += k;
7754
+ for (k = 1; j >= 10; j /= 10, k++) ;
7755
+ if (i != k) {
7756
+ x.e++;
7757
+ if (xc[0] == BASE) xc[0] = 1;
7758
+ }
7759
+ break;
7760
+ } else {
7761
+ xc[ni] += k;
7762
+ if (xc[ni] != BASE) break;
7763
+ xc[ni--] = 0;
7764
+ k = 1;
7765
+ }
7766
+ }
7767
+ }
7768
+ for (i = xc.length; xc[--i] === 0; xc.pop()) ;
7769
+ }
7770
+ if (x.e > MAX_EXP) {
7771
+ x.c = x.e = null;
7772
+ } else if (x.e < MIN_EXP) {
7773
+ x.c = [x.e = 0];
7774
+ }
7775
+ }
7776
+ return x;
7777
+ }
7778
+ __name(round, "round");
7779
+ function valueOf(n) {
7780
+ var str, e = n.e;
7781
+ if (e === null) return n.toString();
7782
+ str = coeffToString(n.c);
7783
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
7784
+ return n.s < 0 ? "-" + str : str;
7785
+ }
7786
+ __name(valueOf, "valueOf");
7787
+ P.absoluteValue = P.abs = function() {
7788
+ var x = new BigNumber2(this);
7789
+ if (x.s < 0) x.s = 1;
7790
+ return x;
7791
+ };
7792
+ P.comparedTo = function(y, b) {
7793
+ return compare(this, new BigNumber2(y, b));
7794
+ };
7795
+ P.decimalPlaces = P.dp = function(dp, rm) {
7796
+ var c, n, v, x = this;
7797
+ if (dp != null) {
7798
+ intCheck(dp, 0, MAX);
7799
+ if (rm == null) rm = ROUNDING_MODE;
7800
+ else intCheck(rm, 0, 8);
7801
+ return round(new BigNumber2(x), dp + x.e + 1, rm);
7802
+ }
7803
+ if (!(c = x.c)) return null;
7804
+ n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
7805
+ if (v = c[v]) for (; v % 10 == 0; v /= 10, n--) ;
7806
+ if (n < 0) n = 0;
7807
+ return n;
7808
+ };
7809
+ P.dividedBy = P.div = function(y, b) {
7810
+ return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
7811
+ };
7812
+ P.dividedToIntegerBy = P.idiv = function(y, b) {
7813
+ return div(this, new BigNumber2(y, b), 0, 1);
7814
+ };
7815
+ P.exponentiatedBy = P.pow = function(n, m) {
7816
+ var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
7817
+ n = new BigNumber2(n);
7818
+ if (n.c && !n.isInteger()) {
7819
+ throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
7820
+ }
7821
+ if (m != null) m = new BigNumber2(m);
7822
+ nIsBig = n.e > 14;
7823
+ if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
7824
+ y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
7825
+ return m ? y.mod(m) : y;
7826
+ }
7827
+ nIsNeg = n.s < 0;
7828
+ if (m) {
7829
+ if (m.c ? !m.c[0] : !m.s) return new BigNumber2(NaN);
7830
+ isModExp = !nIsNeg && x.isInteger() && m.isInteger();
7831
+ if (isModExp) x = x.mod(m);
7832
+ } 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))) {
7833
+ k = x.s < 0 && isOdd(n) ? -0 : 0;
7834
+ if (x.e > -1) k = 1 / k;
7835
+ return new BigNumber2(nIsNeg ? 1 / k : k);
7836
+ } else if (POW_PRECISION) {
7837
+ k = mathceil(POW_PRECISION / LOG_BASE + 2);
7838
+ }
7839
+ if (nIsBig) {
7840
+ half = new BigNumber2(0.5);
7841
+ if (nIsNeg) n.s = 1;
7842
+ nIsOdd = isOdd(n);
7843
+ } else {
7844
+ i = Math.abs(+valueOf(n));
7845
+ nIsOdd = i % 2;
7846
+ }
7847
+ y = new BigNumber2(ONE);
7848
+ for (; ; ) {
7849
+ if (nIsOdd) {
7850
+ y = y.times(x);
7851
+ if (!y.c) break;
7852
+ if (k) {
7853
+ if (y.c.length > k) y.c.length = k;
7854
+ } else if (isModExp) {
7855
+ y = y.mod(m);
7856
+ }
7857
+ }
7858
+ if (i) {
7859
+ i = mathfloor(i / 2);
7860
+ if (i === 0) break;
7861
+ nIsOdd = i % 2;
7862
+ } else {
7863
+ n = n.times(half);
7864
+ round(n, n.e + 1, 1);
7865
+ if (n.e > 14) {
7866
+ nIsOdd = isOdd(n);
7867
+ } else {
7868
+ i = +valueOf(n);
7869
+ if (i === 0) break;
7870
+ nIsOdd = i % 2;
7871
+ }
7872
+ }
7873
+ x = x.times(x);
7874
+ if (k) {
7875
+ if (x.c && x.c.length > k) x.c.length = k;
7876
+ } else if (isModExp) {
7877
+ x = x.mod(m);
7878
+ }
7879
+ }
7880
+ if (isModExp) return y;
7881
+ if (nIsNeg) y = ONE.div(y);
7882
+ return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
7883
+ };
7884
+ P.integerValue = function(rm) {
7885
+ var n = new BigNumber2(this);
7886
+ if (rm == null) rm = ROUNDING_MODE;
7887
+ else intCheck(rm, 0, 8);
7888
+ return round(n, n.e + 1, rm);
7889
+ };
7890
+ P.isEqualTo = P.eq = function(y, b) {
7891
+ return compare(this, new BigNumber2(y, b)) === 0;
7892
+ };
7893
+ P.isFinite = function() {
7894
+ return !!this.c;
7895
+ };
7896
+ P.isGreaterThan = P.gt = function(y, b) {
7897
+ return compare(this, new BigNumber2(y, b)) > 0;
7898
+ };
7899
+ P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
7900
+ return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
7901
+ };
7902
+ P.isInteger = function() {
7903
+ return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
7904
+ };
7905
+ P.isLessThan = P.lt = function(y, b) {
7906
+ return compare(this, new BigNumber2(y, b)) < 0;
7907
+ };
7908
+ P.isLessThanOrEqualTo = P.lte = function(y, b) {
7909
+ return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
7910
+ };
7911
+ P.isNaN = function() {
7912
+ return !this.s;
7913
+ };
7914
+ P.isNegative = function() {
7915
+ return this.s < 0;
7916
+ };
7917
+ P.isPositive = function() {
7918
+ return this.s > 0;
7919
+ };
7920
+ P.isZero = function() {
7921
+ return !!this.c && this.c[0] == 0;
7922
+ };
7923
+ P.minus = function(y, b) {
7924
+ var i, j, t, xLTy, x = this, a = x.s;
7925
+ y = new BigNumber2(y, b);
7926
+ b = y.s;
7927
+ if (!a || !b) return new BigNumber2(NaN);
7928
+ if (a != b) {
7929
+ y.s = -b;
7930
+ return x.plus(y);
7931
+ }
7932
+ var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
7933
+ if (!xe || !ye) {
7934
+ if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
7935
+ if (!xc[0] || !yc[0]) {
7936
+ return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
7937
+ // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
7938
+ ROUNDING_MODE == 3 ? -0 : 0
7939
+ ));
7940
+ }
7941
+ }
7942
+ xe = bitFloor(xe);
7943
+ ye = bitFloor(ye);
7944
+ xc = xc.slice();
7945
+ if (a = xe - ye) {
7946
+ if (xLTy = a < 0) {
7947
+ a = -a;
7948
+ t = xc;
7949
+ } else {
7950
+ ye = xe;
7951
+ t = yc;
7952
+ }
7953
+ t.reverse();
7954
+ for (b = a; b--; t.push(0)) ;
7955
+ t.reverse();
7956
+ } else {
7957
+ j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
7958
+ for (a = b = 0; b < j; b++) {
7959
+ if (xc[b] != yc[b]) {
7960
+ xLTy = xc[b] < yc[b];
7961
+ break;
7962
+ }
7963
+ }
7964
+ }
7965
+ if (xLTy) {
7966
+ t = xc;
7967
+ xc = yc;
7968
+ yc = t;
7969
+ y.s = -y.s;
7970
+ }
7971
+ b = (j = yc.length) - (i = xc.length);
7972
+ if (b > 0) for (; b--; xc[i++] = 0) ;
7973
+ b = BASE - 1;
7974
+ for (; j > a; ) {
7975
+ if (xc[--j] < yc[j]) {
7976
+ for (i = j; i && !xc[--i]; xc[i] = b) ;
7977
+ --xc[i];
7978
+ xc[j] += BASE;
7979
+ }
7980
+ xc[j] -= yc[j];
7981
+ }
7982
+ for (; xc[0] == 0; xc.splice(0, 1), --ye) ;
7983
+ if (!xc[0]) {
7984
+ y.s = ROUNDING_MODE == 3 ? -1 : 1;
7985
+ y.c = [y.e = 0];
7986
+ return y;
7987
+ }
7988
+ return normalise(y, xc, ye);
7989
+ };
7990
+ P.modulo = P.mod = function(y, b) {
7991
+ var q, s, x = this;
7992
+ y = new BigNumber2(y, b);
7993
+ if (!x.c || !y.s || y.c && !y.c[0]) {
7994
+ return new BigNumber2(NaN);
7995
+ } else if (!y.c || x.c && !x.c[0]) {
7996
+ return new BigNumber2(x);
7997
+ }
7998
+ if (MODULO_MODE == 9) {
7999
+ s = y.s;
8000
+ y.s = 1;
8001
+ q = div(x, y, 0, 3);
8002
+ y.s = s;
8003
+ q.s *= s;
8004
+ } else {
8005
+ q = div(x, y, 0, MODULO_MODE);
8006
+ }
8007
+ y = x.minus(q.times(y));
8008
+ if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
8009
+ return y;
8010
+ };
8011
+ P.multipliedBy = P.times = function(y, b) {
8012
+ 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;
8013
+ if (!xc || !yc || !xc[0] || !yc[0]) {
8014
+ if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
8015
+ y.c = y.e = y.s = null;
8016
+ } else {
8017
+ y.s *= x.s;
8018
+ if (!xc || !yc) {
8019
+ y.c = y.e = null;
8020
+ } else {
8021
+ y.c = [0];
8022
+ y.e = 0;
8023
+ }
8024
+ }
8025
+ return y;
8026
+ }
8027
+ e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
8028
+ y.s *= x.s;
8029
+ xcL = xc.length;
8030
+ ycL = yc.length;
8031
+ if (xcL < ycL) {
8032
+ zc = xc;
8033
+ xc = yc;
8034
+ yc = zc;
8035
+ i = xcL;
8036
+ xcL = ycL;
8037
+ ycL = i;
8038
+ }
8039
+ for (i = xcL + ycL, zc = []; i--; zc.push(0)) ;
8040
+ base = BASE;
8041
+ sqrtBase = SQRT_BASE;
8042
+ for (i = ycL; --i >= 0; ) {
8043
+ c = 0;
8044
+ ylo = yc[i] % sqrtBase;
8045
+ yhi = yc[i] / sqrtBase | 0;
8046
+ for (k = xcL, j = i + k; j > i; ) {
8047
+ xlo = xc[--k] % sqrtBase;
8048
+ xhi = xc[k] / sqrtBase | 0;
8049
+ m = yhi * xlo + xhi * ylo;
8050
+ xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
8051
+ c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
8052
+ zc[j--] = xlo % base;
8053
+ }
8054
+ zc[j] = c;
8055
+ }
8056
+ if (c) {
8057
+ ++e;
8058
+ } else {
8059
+ zc.splice(0, 1);
8060
+ }
8061
+ return normalise(y, zc, e);
8062
+ };
8063
+ P.negated = function() {
8064
+ var x = new BigNumber2(this);
8065
+ x.s = -x.s || null;
8066
+ return x;
8067
+ };
8068
+ P.plus = function(y, b) {
8069
+ var t, x = this, a = x.s;
8070
+ y = new BigNumber2(y, b);
8071
+ b = y.s;
8072
+ if (!a || !b) return new BigNumber2(NaN);
8073
+ if (a != b) {
8074
+ y.s = -b;
8075
+ return x.minus(y);
8076
+ }
8077
+ var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
8078
+ if (!xe || !ye) {
8079
+ if (!xc || !yc) return new BigNumber2(a / 0);
8080
+ if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
8081
+ }
8082
+ xe = bitFloor(xe);
8083
+ ye = bitFloor(ye);
8084
+ xc = xc.slice();
8085
+ if (a = xe - ye) {
8086
+ if (a > 0) {
8087
+ ye = xe;
8088
+ t = yc;
8089
+ } else {
8090
+ a = -a;
8091
+ t = xc;
8092
+ }
8093
+ t.reverse();
8094
+ for (; a--; t.push(0)) ;
8095
+ t.reverse();
8096
+ }
8097
+ a = xc.length;
8098
+ b = yc.length;
8099
+ if (a - b < 0) {
8100
+ t = yc;
8101
+ yc = xc;
8102
+ xc = t;
8103
+ b = a;
8104
+ }
8105
+ for (a = 0; b; ) {
8106
+ a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
8107
+ xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
8108
+ }
8109
+ if (a) {
8110
+ xc = [a].concat(xc);
8111
+ ++ye;
8112
+ }
8113
+ return normalise(y, xc, ye);
8114
+ };
8115
+ P.precision = P.sd = function(sd, rm) {
8116
+ var c, n, v, x = this;
8117
+ if (sd != null && sd !== !!sd) {
8118
+ intCheck(sd, 1, MAX);
8119
+ if (rm == null) rm = ROUNDING_MODE;
8120
+ else intCheck(rm, 0, 8);
8121
+ return round(new BigNumber2(x), sd, rm);
8122
+ }
8123
+ if (!(c = x.c)) return null;
8124
+ v = c.length - 1;
8125
+ n = v * LOG_BASE + 1;
8126
+ if (v = c[v]) {
8127
+ for (; v % 10 == 0; v /= 10, n--) ;
8128
+ for (v = c[0]; v >= 10; v /= 10, n++) ;
8129
+ }
8130
+ if (sd && x.e + 1 > n) n = x.e + 1;
8131
+ return n;
8132
+ };
8133
+ P.shiftedBy = function(k) {
8134
+ intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
8135
+ return this.times("1e" + k);
8136
+ };
8137
+ P.squareRoot = P.sqrt = function() {
8138
+ 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");
8139
+ if (s !== 1 || !c || !c[0]) {
8140
+ return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
8141
+ }
8142
+ s = Math.sqrt(+valueOf(x));
8143
+ if (s == 0 || s == 1 / 0) {
8144
+ n = coeffToString(c);
8145
+ if ((n.length + e) % 2 == 0) n += "0";
8146
+ s = Math.sqrt(+n);
8147
+ e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
8148
+ if (s == 1 / 0) {
8149
+ n = "5e" + e;
8150
+ } else {
8151
+ n = s.toExponential();
8152
+ n = n.slice(0, n.indexOf("e") + 1) + e;
8153
+ }
8154
+ r = new BigNumber2(n);
8155
+ } else {
8156
+ r = new BigNumber2(s + "");
8157
+ }
8158
+ if (r.c[0]) {
8159
+ e = r.e;
8160
+ s = e + dp;
8161
+ if (s < 3) s = 0;
8162
+ for (; ; ) {
8163
+ t = r;
8164
+ r = half.times(t.plus(div(x, t, dp, 1)));
8165
+ if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
8166
+ if (r.e < e) --s;
8167
+ n = n.slice(s - 3, s + 1);
8168
+ if (n == "9999" || !rep && n == "4999") {
8169
+ if (!rep) {
8170
+ round(t, t.e + DECIMAL_PLACES + 2, 0);
8171
+ if (t.times(t).eq(x)) {
8172
+ r = t;
8173
+ break;
8174
+ }
8175
+ }
8176
+ dp += 4;
8177
+ s += 4;
8178
+ rep = 1;
8179
+ } else {
8180
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
8181
+ round(r, r.e + DECIMAL_PLACES + 2, 1);
8182
+ m = !r.times(r).eq(x);
8183
+ }
8184
+ break;
8185
+ }
8186
+ }
8187
+ }
8188
+ }
8189
+ return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
8190
+ };
8191
+ P.toExponential = function(dp, rm) {
8192
+ if (dp != null) {
8193
+ intCheck(dp, 0, MAX);
8194
+ dp++;
8195
+ }
8196
+ return format(this, dp, rm, 1);
8197
+ };
8198
+ P.toFixed = function(dp, rm) {
8199
+ if (dp != null) {
8200
+ intCheck(dp, 0, MAX);
8201
+ dp = dp + this.e + 1;
8202
+ }
8203
+ return format(this, dp, rm);
8204
+ };
8205
+ P.toFormat = function(dp, rm, format2) {
8206
+ var str, x = this;
8207
+ if (format2 == null) {
8208
+ if (dp != null && rm && typeof rm == "object") {
8209
+ format2 = rm;
8210
+ rm = null;
8211
+ } else if (dp && typeof dp == "object") {
8212
+ format2 = dp;
8213
+ dp = rm = null;
8214
+ } else {
8215
+ format2 = FORMAT;
8216
+ }
8217
+ } else if (typeof format2 != "object") {
8218
+ throw Error(bignumberError + "Argument not an object: " + format2);
8219
+ }
8220
+ str = x.toFixed(dp, rm);
8221
+ if (x.c) {
8222
+ 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;
8223
+ if (g2) {
8224
+ i = g1;
8225
+ g1 = g2;
8226
+ g2 = i;
8227
+ len -= i;
8228
+ }
8229
+ if (g1 > 0 && len > 0) {
8230
+ i = len % g1 || g1;
8231
+ intPart = intDigits.substr(0, i);
8232
+ for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
8233
+ if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
8234
+ if (isNeg) intPart = "-" + intPart;
8235
+ }
8236
+ str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
8237
+ new RegExp("\\d{" + g2 + "}\\B", "g"),
8238
+ "$&" + (format2.fractionGroupSeparator || "")
8239
+ ) : fractionPart) : intPart;
8240
+ }
8241
+ return (format2.prefix || "") + str + (format2.suffix || "");
8242
+ };
8243
+ P.toFraction = function(md) {
8244
+ var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
8245
+ if (md != null) {
8246
+ n = new BigNumber2(md);
8247
+ if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
8248
+ throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
8249
+ }
8250
+ }
8251
+ if (!xc) return new BigNumber2(x);
8252
+ d = new BigNumber2(ONE);
8253
+ n1 = d0 = new BigNumber2(ONE);
8254
+ d1 = n0 = new BigNumber2(ONE);
8255
+ s = coeffToString(xc);
8256
+ e = d.e = s.length - x.e - 1;
8257
+ d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
8258
+ md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
8259
+ exp = MAX_EXP;
8260
+ MAX_EXP = 1 / 0;
8261
+ n = new BigNumber2(s);
8262
+ n0.c[0] = 0;
8263
+ for (; ; ) {
8264
+ q = div(n, d, 0, 1);
8265
+ d2 = d0.plus(q.times(d1));
8266
+ if (d2.comparedTo(md) == 1) break;
8267
+ d0 = d1;
8268
+ d1 = d2;
8269
+ n1 = n0.plus(q.times(d2 = n1));
8270
+ n0 = d2;
8271
+ d = n.minus(q.times(d2 = d));
8272
+ n = d2;
8273
+ }
8274
+ d2 = div(md.minus(d0), d1, 0, 1);
8275
+ n0 = n0.plus(d2.times(n1));
8276
+ d0 = d0.plus(d2.times(d1));
8277
+ n0.s = n1.s = x.s;
8278
+ e = e * 2;
8279
+ r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
8280
+ div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
8281
+ ) < 1 ? [n1, d1] : [n0, d0];
8282
+ MAX_EXP = exp;
8283
+ return r;
8284
+ };
8285
+ P.toNumber = function() {
8286
+ return +valueOf(this);
8287
+ };
8288
+ P.toPrecision = function(sd, rm) {
8289
+ if (sd != null) intCheck(sd, 1, MAX);
8290
+ return format(this, sd, rm, 2);
8291
+ };
8292
+ P.toString = function(b) {
8293
+ var str, n = this, s = n.s, e = n.e;
8294
+ if (e === null) {
8295
+ if (s) {
8296
+ str = "Infinity";
8297
+ if (s < 0) str = "-" + str;
8298
+ } else {
8299
+ str = "NaN";
8300
+ }
8301
+ } else {
8302
+ if (b == null) {
8303
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
8304
+ } else if (b === 10 && alphabetHasNormalDecimalDigits) {
8305
+ n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
8306
+ str = toFixedPoint(coeffToString(n.c), n.e, "0");
8307
+ } else {
8308
+ intCheck(b, 2, ALPHABET.length, "Base");
8309
+ str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
8310
+ }
8311
+ if (s < 0 && n.c[0]) str = "-" + str;
8312
+ }
8313
+ return str;
8314
+ };
8315
+ P.valueOf = P.toJSON = function() {
8316
+ return valueOf(this);
8317
+ };
8318
+ P._isBigNumber = true;
8319
+ P[Symbol.toStringTag] = "BigNumber";
8320
+ P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
8321
+ if (configObject != null) BigNumber2.set(configObject);
8322
+ return BigNumber2;
8323
+ }
8324
+ __name(clone, "clone");
8325
+ function bitFloor(n) {
8326
+ var i = n | 0;
8327
+ return n > 0 || n === i ? i : i - 1;
8328
+ }
8329
+ __name(bitFloor, "bitFloor");
8330
+ function coeffToString(a) {
8331
+ var s, z2, i = 1, j = a.length, r = a[0] + "";
8332
+ for (; i < j; ) {
8333
+ s = a[i++] + "";
8334
+ z2 = LOG_BASE - s.length;
8335
+ for (; z2--; s = "0" + s) ;
8336
+ r += s;
8337
+ }
8338
+ for (j = r.length; r.charCodeAt(--j) === 48; ) ;
8339
+ return r.slice(0, j + 1 || 1);
8340
+ }
8341
+ __name(coeffToString, "coeffToString");
8342
+ function compare(x, y) {
8343
+ var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
8344
+ if (!i || !j) return null;
8345
+ a = xc && !xc[0];
8346
+ b = yc && !yc[0];
8347
+ if (a || b) return a ? b ? 0 : -j : i;
8348
+ if (i != j) return i;
8349
+ a = i < 0;
8350
+ b = k == l;
8351
+ if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
8352
+ if (!b) return k > l ^ a ? 1 : -1;
8353
+ j = (k = xc.length) < (l = yc.length) ? k : l;
8354
+ for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
8355
+ return k == l ? 0 : k > l ^ a ? 1 : -1;
8356
+ }
8357
+ __name(compare, "compare");
8358
+ function intCheck(n, min, max, name) {
8359
+ if (n < min || n > max || n !== mathfloor(n)) {
8360
+ throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
8361
+ }
8362
+ }
8363
+ __name(intCheck, "intCheck");
8364
+ function isOdd(n) {
8365
+ var k = n.c.length - 1;
8366
+ return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
8367
+ }
8368
+ __name(isOdd, "isOdd");
8369
+ function toExponential(str, e) {
8370
+ return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
8371
+ }
8372
+ __name(toExponential, "toExponential");
8373
+ function toFixedPoint(str, e, z2) {
8374
+ var len, zs;
8375
+ if (e < 0) {
8376
+ for (zs = z2 + "."; ++e; zs += z2) ;
8377
+ str = zs + str;
8378
+ } else {
8379
+ len = str.length;
8380
+ if (++e > len) {
8381
+ for (zs = z2, e -= len; --e; zs += z2) ;
8382
+ str += zs;
8383
+ } else if (e < len) {
8384
+ str = str.slice(0, e) + "." + str.slice(e);
8385
+ }
8386
+ }
8387
+ return str;
8388
+ }
8389
+ __name(toFixedPoint, "toFixedPoint");
8390
+ var BigNumber = clone();
8391
+ var bignumber_default = BigNumber;
8392
+
8393
+ // ../shared/src/functions.ts
8394
+ init_enums();
8395
+ 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");
8396
+
8397
+ // src/swap/sdk.ts
7030
8398
  init_guards();
7031
8399
 
7032
8400
  // ../shared/src/rpc/index.ts
@@ -8661,14 +10029,15 @@ var getChainData = /* @__PURE__ */ __name((chain2, network, env) => ({
8661
10029
  name: chain2,
8662
10030
  evmChainId: getEvmChainId(chain2, network),
8663
10031
  isMainnet: !isTestnet(network),
8664
- requiredBlockConfirmations: isNotNullish(env.ingressEgress.witnessSafetyMargins[chain2]) ? Number(env.ingressEgress.witnessSafetyMargins[chain2]) + 1 : void 0
10032
+ requiredBlockConfirmations: isNotNullish(env.ingressEgress.witnessSafetyMargins[chain2]) ? Number(env.ingressEgress.witnessSafetyMargins[chain2]) + 1 : void 0,
10033
+ maxRetryDurationBlocks: env.ingressEgress.maxSwapRetryDurationBlocks[chain2]
8665
10034
  }), "getChainData");
8666
10035
 
8667
10036
  // src/swap/consts.ts
8668
10037
  init_enums();
8669
10038
 
8670
10039
  // package.json
8671
- var version = "1.5.0-alpha.0";
10040
+ var version = "1.5.0-alpha.2";
8672
10041
 
8673
10042
  // src/swap/consts.ts
8674
10043
  var CF_SDK_VERSION_HEADERS = {
@@ -8781,11 +10150,21 @@ var _SwapSDK = class _SwapSDK {
8781
10150
  }, options);
8782
10151
  }
8783
10152
  async requestDepositAddress(depositAddressRequest) {
8784
- const { srcChain, srcAsset, amount, brokerCommissionBps, affiliateBrokers } = depositAddressRequest;
10153
+ const { srcChain, srcAsset, amount, destChain, destAsset, brokerCommissionBps, affiliateBrokers } = depositAddressRequest;
8785
10154
  await this.validateSwapAmount({
8786
10155
  chain: srcChain,
8787
10156
  asset: srcAsset
8788
10157
  }, BigInt(amount));
10158
+ const fillOrKillParams2 = depositAddressRequest.fillOrKillParams ? {
10159
+ ...depositAddressRequest.fillOrKillParams,
10160
+ minPriceX128: getPriceX128FromPrice(depositAddressRequest.fillOrKillParams.minPrice, getInternalAsset({
10161
+ chain: srcChain,
10162
+ asset: srcAsset
10163
+ }), getInternalAsset({
10164
+ chain: destChain,
10165
+ asset: destAsset
10166
+ }))
10167
+ } : void 0;
8789
10168
  depositAddressRequest.ccmParams ?? (depositAddressRequest.ccmParams = depositAddressRequest.ccmMetadata);
8790
10169
  let response;
8791
10170
  if (this.options.broker !== void 0) {
@@ -8793,7 +10172,8 @@ var _SwapSDK = class _SwapSDK {
8793
10172
  const result = await requestSwapDepositAddress2({
8794
10173
  ...depositAddressRequest,
8795
10174
  commissionBps: brokerCommissionBps ?? this.options.broker.commissionBps,
8796
- affiliates: affiliateBrokers
10175
+ affiliates: affiliateBrokers,
10176
+ fillOrKillParams: fillOrKillParams2
8797
10177
  }, {
8798
10178
  url: this.options.broker.url
8799
10179
  }, this.options.network);
@@ -8808,7 +10188,10 @@ var _SwapSDK = class _SwapSDK {
8808
10188
  } else {
8809
10189
  assert(!depositAddressRequest.brokerCommissionBps, "Broker commission is only supported only when initializing the SDK with a brokerUrl");
8810
10190
  assert(!depositAddressRequest.affiliateBrokers?.length, "Affiliate brokers are supported only when initializing the SDK with a brokerUrl");
8811
- response = await this.trpc.openSwapDepositChannel.mutate(depositAddressRequest);
10191
+ response = await this.trpc.openSwapDepositChannel.mutate({
10192
+ ...depositAddressRequest,
10193
+ fillOrKillParams: fillOrKillParams2
10194
+ });
8812
10195
  }
8813
10196
  return {
8814
10197
  ...depositAddressRequest,