hufi-cli 0.4.0 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -4
- package/dist/cli.js +1538 -141
- package/package.json +5 -2
package/dist/cli.js
CHANGED
|
@@ -2629,7 +2629,7 @@ var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
|
2629
2629
|
|
|
2630
2630
|
// node_modules/@noble/hashes/esm/cryptoNode.js
|
|
2631
2631
|
import * as nc from "node:crypto";
|
|
2632
|
-
var
|
|
2632
|
+
var crypto2 = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : undefined;
|
|
2633
2633
|
|
|
2634
2634
|
// node_modules/@noble/hashes/esm/utils.js
|
|
2635
2635
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -2705,8 +2705,8 @@ function wrapXOFConstructorWithOpts(hashCons) {
|
|
|
2705
2705
|
return hashC;
|
|
2706
2706
|
}
|
|
2707
2707
|
function randomBytes2(bytesLength = 32) {
|
|
2708
|
-
if (
|
|
2709
|
-
return
|
|
2708
|
+
if (crypto2 && typeof crypto2.getRandomValues === "function") {
|
|
2709
|
+
return crypto2.getRandomValues(new Uint8Array(bytesLength));
|
|
2710
2710
|
}
|
|
2711
2711
|
throw new Error("crypto.getRandomValues must be defined");
|
|
2712
2712
|
}
|
|
@@ -9339,7 +9339,22 @@ import { homedir } from "node:os";
|
|
|
9339
9339
|
import { join } from "node:path";
|
|
9340
9340
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
9341
9341
|
var CONFIG_DIR = join(homedir(), ".hufi-cli");
|
|
9342
|
-
var
|
|
9342
|
+
var DEFAULT_CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
9343
|
+
var DEFAULT_KEY_FILE = join(CONFIG_DIR, "key.json");
|
|
9344
|
+
var customConfigFile = null;
|
|
9345
|
+
var customKeyFile = null;
|
|
9346
|
+
function setConfigFile(path) {
|
|
9347
|
+
customConfigFile = path;
|
|
9348
|
+
}
|
|
9349
|
+
function setKeyFile(path) {
|
|
9350
|
+
customKeyFile = path;
|
|
9351
|
+
}
|
|
9352
|
+
function configFile() {
|
|
9353
|
+
return customConfigFile ?? DEFAULT_CONFIG_FILE;
|
|
9354
|
+
}
|
|
9355
|
+
function keyFile() {
|
|
9356
|
+
return customKeyFile ?? DEFAULT_KEY_FILE;
|
|
9357
|
+
}
|
|
9343
9358
|
var DEFAULT_CONFIG = {
|
|
9344
9359
|
recordingApiUrl: "https://ro.hu.finance",
|
|
9345
9360
|
launcherApiUrl: "https://cl.hu.finance"
|
|
@@ -9351,11 +9366,11 @@ function ensureConfigDir() {
|
|
|
9351
9366
|
}
|
|
9352
9367
|
function loadConfig() {
|
|
9353
9368
|
ensureConfigDir();
|
|
9354
|
-
if (!existsSync(
|
|
9369
|
+
if (!existsSync(configFile())) {
|
|
9355
9370
|
return { ...DEFAULT_CONFIG };
|
|
9356
9371
|
}
|
|
9357
9372
|
try {
|
|
9358
|
-
const raw = readFileSync(
|
|
9373
|
+
const raw = readFileSync(configFile(), "utf-8");
|
|
9359
9374
|
const parsed = JSON.parse(raw);
|
|
9360
9375
|
return { ...DEFAULT_CONFIG, ...parsed };
|
|
9361
9376
|
} catch {
|
|
@@ -9364,7 +9379,7 @@ function loadConfig() {
|
|
|
9364
9379
|
}
|
|
9365
9380
|
function saveConfig(config) {
|
|
9366
9381
|
ensureConfigDir();
|
|
9367
|
-
writeFileSync(
|
|
9382
|
+
writeFileSync(configFile(), JSON.stringify(config, null, 2) + `
|
|
9368
9383
|
`);
|
|
9369
9384
|
}
|
|
9370
9385
|
function updateConfig(partial) {
|
|
@@ -9373,6 +9388,30 @@ function updateConfig(partial) {
|
|
|
9373
9388
|
saveConfig(merged);
|
|
9374
9389
|
return merged;
|
|
9375
9390
|
}
|
|
9391
|
+
function getConfigPath() {
|
|
9392
|
+
return configFile();
|
|
9393
|
+
}
|
|
9394
|
+
function getKeyPath() {
|
|
9395
|
+
return keyFile();
|
|
9396
|
+
}
|
|
9397
|
+
function keyExists() {
|
|
9398
|
+
return existsSync(keyFile());
|
|
9399
|
+
}
|
|
9400
|
+
function saveKey(key, address) {
|
|
9401
|
+
ensureConfigDir();
|
|
9402
|
+
writeFileSync(keyFile(), JSON.stringify({ address, privateKey: key }, null, 2) + `
|
|
9403
|
+
`);
|
|
9404
|
+
}
|
|
9405
|
+
function loadKey() {
|
|
9406
|
+
if (!existsSync(keyFile()))
|
|
9407
|
+
return null;
|
|
9408
|
+
try {
|
|
9409
|
+
const raw = readFileSync(keyFile(), "utf-8");
|
|
9410
|
+
return JSON.parse(raw).privateKey ?? null;
|
|
9411
|
+
} catch {
|
|
9412
|
+
return null;
|
|
9413
|
+
}
|
|
9414
|
+
}
|
|
9376
9415
|
|
|
9377
9416
|
// src/lib/output.ts
|
|
9378
9417
|
function printJson(data) {
|
|
@@ -9392,11 +9431,16 @@ function maskSecret(value) {
|
|
|
9392
9431
|
// src/commands/auth.ts
|
|
9393
9432
|
function createAuthCommand() {
|
|
9394
9433
|
const auth = new Command("auth").description("Authentication commands");
|
|
9395
|
-
auth.command("login").description("Authenticate with Recording Oracle using a private key").
|
|
9434
|
+
auth.command("login").description("Authenticate with Recording Oracle using a private key").option("-k, --private-key <key>", "EVM private key (uses saved key if not provided)").option("-u, --api-url <url>", "Recording Oracle API URL").option("--json", "Output as JSON").action(async (opts) => {
|
|
9435
|
+
const privateKey = opts.privateKey ?? loadKey();
|
|
9436
|
+
if (!privateKey) {
|
|
9437
|
+
printText("No private key provided. Run: hufi auth login -k <key> or hufi auth generate");
|
|
9438
|
+
process.exit(1);
|
|
9439
|
+
}
|
|
9396
9440
|
const config = loadConfig();
|
|
9397
9441
|
const baseUrl = (opts.apiUrl ?? config.recordingApiUrl).replace(/\/+$/, "");
|
|
9398
9442
|
try {
|
|
9399
|
-
const result = await authenticate(baseUrl,
|
|
9443
|
+
const result = await authenticate(baseUrl, privateKey);
|
|
9400
9444
|
updateConfig({
|
|
9401
9445
|
recordingApiUrl: baseUrl,
|
|
9402
9446
|
address: result.address,
|
|
@@ -9407,7 +9451,7 @@ function createAuthCommand() {
|
|
|
9407
9451
|
printJson({ address: result.address, accessToken: result.accessToken });
|
|
9408
9452
|
} else {
|
|
9409
9453
|
printText(`Authenticated as ${result.address}`);
|
|
9410
|
-
printText(`Token saved to
|
|
9454
|
+
printText(`Token saved to ${getConfigPath()}`);
|
|
9411
9455
|
}
|
|
9412
9456
|
} catch (err) {
|
|
9413
9457
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -9415,13 +9459,31 @@ function createAuthCommand() {
|
|
|
9415
9459
|
process.exitCode = 1;
|
|
9416
9460
|
}
|
|
9417
9461
|
});
|
|
9418
|
-
auth.command("generate").description("Generate a new EVM wallet").option("--json", "Output as JSON").action((opts) => {
|
|
9462
|
+
auth.command("generate").description("Generate a new EVM wallet").option("--json", "Output as JSON").action(async (opts) => {
|
|
9463
|
+
if (keyExists()) {
|
|
9464
|
+
if (!opts.json) {
|
|
9465
|
+
printText(`Key already exists at ${getKeyPath()}. Overwrite? (y/N)`);
|
|
9466
|
+
const answer = await new Promise((resolve) => {
|
|
9467
|
+
process.stdin.resume();
|
|
9468
|
+
process.stdin.once("data", (data) => {
|
|
9469
|
+
process.stdin.pause();
|
|
9470
|
+
resolve(data.toString().trim().toLowerCase());
|
|
9471
|
+
});
|
|
9472
|
+
});
|
|
9473
|
+
if (answer !== "y") {
|
|
9474
|
+
printText("Cancelled.");
|
|
9475
|
+
return;
|
|
9476
|
+
}
|
|
9477
|
+
}
|
|
9478
|
+
}
|
|
9419
9479
|
const wallet = createWallet();
|
|
9480
|
+
saveKey(wallet.privateKey, wallet.address);
|
|
9481
|
+
const keyPath = getKeyPath();
|
|
9420
9482
|
if (opts.json) {
|
|
9421
|
-
printJson(wallet);
|
|
9483
|
+
printJson({ address: wallet.address, keyPath });
|
|
9422
9484
|
} else {
|
|
9423
9485
|
printText(`Address: ${wallet.address}`);
|
|
9424
|
-
printText(`Private key
|
|
9486
|
+
printText(`Private key saved to ${keyPath}`);
|
|
9425
9487
|
}
|
|
9426
9488
|
});
|
|
9427
9489
|
auth.command("status").description("Show current authentication status").option("--json", "Output as JSON").action((opts) => {
|
|
@@ -9526,6 +9588,1450 @@ function createExchangeCommand() {
|
|
|
9526
9588
|
return exchange;
|
|
9527
9589
|
}
|
|
9528
9590
|
|
|
9591
|
+
// node_modules/bignumber.js/dist/bignumber.mjs
|
|
9592
|
+
var BigNumber = clone();
|
|
9593
|
+
var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
9594
|
+
var mathceil = Math.ceil;
|
|
9595
|
+
var mathfloor = Math.floor;
|
|
9596
|
+
var bignumberError = "[BigNumber Error] ";
|
|
9597
|
+
var BASE = 100000000000000;
|
|
9598
|
+
var LOG_BASE = 14;
|
|
9599
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
9600
|
+
var POWS_TEN = [1, 10, 100, 1000, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 10000000000, 100000000000, 1000000000000, 10000000000000];
|
|
9601
|
+
var SQRT_BASE = 1e7;
|
|
9602
|
+
var MAX = 1e9;
|
|
9603
|
+
function clone(configObject) {
|
|
9604
|
+
var div, convertBase, parseUnusualNumeric, 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 = {
|
|
9605
|
+
prefix: "",
|
|
9606
|
+
groupSize: 3,
|
|
9607
|
+
secondaryGroupSize: 0,
|
|
9608
|
+
groupSeparator: ",",
|
|
9609
|
+
decimalSeparator: ".",
|
|
9610
|
+
fractionGroupSize: 0,
|
|
9611
|
+
fractionGroupSeparator: " ",
|
|
9612
|
+
suffix: ""
|
|
9613
|
+
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
9614
|
+
function BigNumber2(v, b) {
|
|
9615
|
+
var alphabet, c, caseChanged, e, i, len, str, t, x = this;
|
|
9616
|
+
if (!(x instanceof BigNumber2))
|
|
9617
|
+
return new BigNumber2(v, b);
|
|
9618
|
+
t = typeof v;
|
|
9619
|
+
if (b == null) {
|
|
9620
|
+
if (isBigNumber(v)) {
|
|
9621
|
+
x.s = v.s;
|
|
9622
|
+
if (!v.c || v.e > MAX_EXP) {
|
|
9623
|
+
x.c = x.e = null;
|
|
9624
|
+
} else if (v.e < MIN_EXP) {
|
|
9625
|
+
x.c = [x.e = 0];
|
|
9626
|
+
} else {
|
|
9627
|
+
x.e = v.e;
|
|
9628
|
+
x.c = v.c.slice();
|
|
9629
|
+
}
|
|
9630
|
+
return;
|
|
9631
|
+
}
|
|
9632
|
+
if (t == "number") {
|
|
9633
|
+
if (v * 0 != 0) {
|
|
9634
|
+
x.s = isNaN(v) ? null : v < 0 ? -1 : 1;
|
|
9635
|
+
x.c = x.e = null;
|
|
9636
|
+
return;
|
|
9637
|
+
}
|
|
9638
|
+
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
9639
|
+
if (v === ~~v) {
|
|
9640
|
+
for (e = 0, i = v;i >= 10; i /= 10, e++)
|
|
9641
|
+
;
|
|
9642
|
+
if (e > MAX_EXP) {
|
|
9643
|
+
x.c = x.e = null;
|
|
9644
|
+
} else {
|
|
9645
|
+
x.e = e;
|
|
9646
|
+
x.c = [v];
|
|
9647
|
+
}
|
|
9648
|
+
return;
|
|
9649
|
+
}
|
|
9650
|
+
str = String(v);
|
|
9651
|
+
} else {
|
|
9652
|
+
if (t == "string") {
|
|
9653
|
+
str = v;
|
|
9654
|
+
if (!isNumeric.test(str)) {
|
|
9655
|
+
return parseUnusualNumeric(x, str);
|
|
9656
|
+
}
|
|
9657
|
+
} else if (t == "bigint") {
|
|
9658
|
+
str = String(v);
|
|
9659
|
+
} else {
|
|
9660
|
+
throw Error(bignumberError + "Invalid argument: " + v);
|
|
9661
|
+
}
|
|
9662
|
+
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
9663
|
+
}
|
|
9664
|
+
if ((e = str.indexOf(".")) > -1)
|
|
9665
|
+
str = str.replace(".", "");
|
|
9666
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
9667
|
+
if (e < 0)
|
|
9668
|
+
e = i;
|
|
9669
|
+
e += +str.slice(i + 1);
|
|
9670
|
+
str = str.substring(0, i);
|
|
9671
|
+
} else if (e < 0) {
|
|
9672
|
+
e = str.length;
|
|
9673
|
+
}
|
|
9674
|
+
} else {
|
|
9675
|
+
if (t != "string") {
|
|
9676
|
+
throw Error(bignumberError + "String expected: " + v);
|
|
9677
|
+
}
|
|
9678
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
9679
|
+
str = v;
|
|
9680
|
+
x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
9681
|
+
alphabet = ALPHABET.slice(0, b);
|
|
9682
|
+
e = i = 0;
|
|
9683
|
+
for (len = str.length;i < len; i++) {
|
|
9684
|
+
if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
9685
|
+
if (c == ".") {
|
|
9686
|
+
if (i > e) {
|
|
9687
|
+
e = len;
|
|
9688
|
+
continue;
|
|
9689
|
+
}
|
|
9690
|
+
} else if (!caseChanged) {
|
|
9691
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
9692
|
+
caseChanged = true;
|
|
9693
|
+
i = -1;
|
|
9694
|
+
e = 0;
|
|
9695
|
+
continue;
|
|
9696
|
+
}
|
|
9697
|
+
}
|
|
9698
|
+
return parseUnusualNumeric(x, v, b);
|
|
9699
|
+
}
|
|
9700
|
+
}
|
|
9701
|
+
str = convertBase(str, b, 10, x.s);
|
|
9702
|
+
if ((e = str.indexOf(".")) > -1)
|
|
9703
|
+
str = str.replace(".", "");
|
|
9704
|
+
else
|
|
9705
|
+
e = str.length;
|
|
9706
|
+
}
|
|
9707
|
+
for (i = 0;str.charCodeAt(i) === 48; i++)
|
|
9708
|
+
;
|
|
9709
|
+
for (len = str.length;str.charCodeAt(--len) === 48; )
|
|
9710
|
+
;
|
|
9711
|
+
if (str = str.slice(i, ++len)) {
|
|
9712
|
+
len -= i;
|
|
9713
|
+
e = e - i - 1;
|
|
9714
|
+
if (e > MAX_EXP) {
|
|
9715
|
+
x.c = x.e = null;
|
|
9716
|
+
} else if (e < MIN_EXP) {
|
|
9717
|
+
x.c = [x.e = 0];
|
|
9718
|
+
} else {
|
|
9719
|
+
x.e = e;
|
|
9720
|
+
x.c = [];
|
|
9721
|
+
i = (e + 1) % LOG_BASE;
|
|
9722
|
+
if (e < 0)
|
|
9723
|
+
i += LOG_BASE;
|
|
9724
|
+
if (i < len) {
|
|
9725
|
+
if (i)
|
|
9726
|
+
x.c.push(+str.slice(0, i));
|
|
9727
|
+
for (len -= LOG_BASE;i < len; ) {
|
|
9728
|
+
x.c.push(+str.slice(i, i += LOG_BASE));
|
|
9729
|
+
}
|
|
9730
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
9731
|
+
} else {
|
|
9732
|
+
i -= len;
|
|
9733
|
+
}
|
|
9734
|
+
for (;i--; str += "0")
|
|
9735
|
+
;
|
|
9736
|
+
x.c.push(+str);
|
|
9737
|
+
}
|
|
9738
|
+
} else {
|
|
9739
|
+
x.c = [x.e = 0];
|
|
9740
|
+
}
|
|
9741
|
+
}
|
|
9742
|
+
BigNumber2.clone = clone;
|
|
9743
|
+
BigNumber2.ROUND_UP = 0;
|
|
9744
|
+
BigNumber2.ROUND_DOWN = 1;
|
|
9745
|
+
BigNumber2.ROUND_CEIL = 2;
|
|
9746
|
+
BigNumber2.ROUND_FLOOR = 3;
|
|
9747
|
+
BigNumber2.ROUND_HALF_UP = 4;
|
|
9748
|
+
BigNumber2.ROUND_HALF_DOWN = 5;
|
|
9749
|
+
BigNumber2.ROUND_HALF_EVEN = 6;
|
|
9750
|
+
BigNumber2.ROUND_HALF_CEIL = 7;
|
|
9751
|
+
BigNumber2.ROUND_HALF_FLOOR = 8;
|
|
9752
|
+
BigNumber2.EUCLID = 9;
|
|
9753
|
+
BigNumber2.config = BigNumber2.set = function(obj) {
|
|
9754
|
+
var p, v;
|
|
9755
|
+
if (obj != null) {
|
|
9756
|
+
if (typeof obj == "object") {
|
|
9757
|
+
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
9758
|
+
v = obj[p];
|
|
9759
|
+
intCheck(v, 0, MAX, p);
|
|
9760
|
+
DECIMAL_PLACES = v;
|
|
9761
|
+
}
|
|
9762
|
+
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
9763
|
+
v = obj[p];
|
|
9764
|
+
intCheck(v, 0, 8, p);
|
|
9765
|
+
ROUNDING_MODE = v;
|
|
9766
|
+
}
|
|
9767
|
+
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
9768
|
+
v = obj[p];
|
|
9769
|
+
if (v && v.pop) {
|
|
9770
|
+
intCheck(v[0], -MAX, 0, p);
|
|
9771
|
+
intCheck(v[1], 0, MAX, p);
|
|
9772
|
+
TO_EXP_NEG = v[0];
|
|
9773
|
+
TO_EXP_POS = v[1];
|
|
9774
|
+
} else {
|
|
9775
|
+
intCheck(v, -MAX, MAX, p);
|
|
9776
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
9777
|
+
}
|
|
9778
|
+
}
|
|
9779
|
+
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
9780
|
+
v = obj[p];
|
|
9781
|
+
if (v && v.pop) {
|
|
9782
|
+
intCheck(v[0], -MAX, -1, p);
|
|
9783
|
+
intCheck(v[1], 1, MAX, p);
|
|
9784
|
+
MIN_EXP = v[0];
|
|
9785
|
+
MAX_EXP = v[1];
|
|
9786
|
+
} else {
|
|
9787
|
+
intCheck(v, -MAX, MAX, p);
|
|
9788
|
+
if (v) {
|
|
9789
|
+
MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
9790
|
+
} else {
|
|
9791
|
+
throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
9792
|
+
}
|
|
9793
|
+
}
|
|
9794
|
+
}
|
|
9795
|
+
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
9796
|
+
v = obj[p];
|
|
9797
|
+
if (v === !!v) {
|
|
9798
|
+
if (v) {
|
|
9799
|
+
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
9800
|
+
CRYPTO = v;
|
|
9801
|
+
} else {
|
|
9802
|
+
CRYPTO = !v;
|
|
9803
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
9804
|
+
}
|
|
9805
|
+
} else {
|
|
9806
|
+
CRYPTO = v;
|
|
9807
|
+
}
|
|
9808
|
+
} else {
|
|
9809
|
+
throw Error(bignumberError + p + " not true or false: " + v);
|
|
9810
|
+
}
|
|
9811
|
+
}
|
|
9812
|
+
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
9813
|
+
v = obj[p];
|
|
9814
|
+
intCheck(v, 0, 9, p);
|
|
9815
|
+
MODULO_MODE = v;
|
|
9816
|
+
}
|
|
9817
|
+
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
9818
|
+
v = obj[p];
|
|
9819
|
+
intCheck(v, 0, MAX, p);
|
|
9820
|
+
POW_PRECISION = v;
|
|
9821
|
+
}
|
|
9822
|
+
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
9823
|
+
v = obj[p];
|
|
9824
|
+
if (typeof v == "object")
|
|
9825
|
+
FORMAT = v;
|
|
9826
|
+
else
|
|
9827
|
+
throw Error(bignumberError + p + " not an object: " + v);
|
|
9828
|
+
}
|
|
9829
|
+
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
9830
|
+
v = obj[p];
|
|
9831
|
+
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
9832
|
+
ALPHABET = v;
|
|
9833
|
+
} else {
|
|
9834
|
+
throw Error(bignumberError + p + " invalid: " + v);
|
|
9835
|
+
}
|
|
9836
|
+
}
|
|
9837
|
+
} else {
|
|
9838
|
+
throw Error(bignumberError + "Object expected: " + obj);
|
|
9839
|
+
}
|
|
9840
|
+
}
|
|
9841
|
+
return {
|
|
9842
|
+
DECIMAL_PLACES,
|
|
9843
|
+
ROUNDING_MODE,
|
|
9844
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
9845
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
9846
|
+
CRYPTO,
|
|
9847
|
+
MODULO_MODE,
|
|
9848
|
+
POW_PRECISION,
|
|
9849
|
+
FORMAT,
|
|
9850
|
+
ALPHABET
|
|
9851
|
+
};
|
|
9852
|
+
};
|
|
9853
|
+
BigNumber2.isBigNumber = function(v) {
|
|
9854
|
+
if (!isBigNumber(v))
|
|
9855
|
+
return false;
|
|
9856
|
+
var i, n, c = v.c, e = v.e, s = v.s;
|
|
9857
|
+
if ({}.toString.call(c) != "[object Array]") {
|
|
9858
|
+
return c === null && e === null && (s === null || s === 1 || s === -1);
|
|
9859
|
+
}
|
|
9860
|
+
if (s !== 1 && s !== -1 || e < -MAX || e > MAX || e !== mathfloor(e)) {
|
|
9861
|
+
return false;
|
|
9862
|
+
}
|
|
9863
|
+
if (c[0] === 0) {
|
|
9864
|
+
return e === 0 && c.length === 1;
|
|
9865
|
+
}
|
|
9866
|
+
i = (e + 1) % LOG_BASE;
|
|
9867
|
+
if (i < 1)
|
|
9868
|
+
i += LOG_BASE;
|
|
9869
|
+
if (String(c[0]).length !== i) {
|
|
9870
|
+
return false;
|
|
9871
|
+
}
|
|
9872
|
+
for (i = 0;i < c.length; i++) {
|
|
9873
|
+
n = c[i];
|
|
9874
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n))
|
|
9875
|
+
return false;
|
|
9876
|
+
}
|
|
9877
|
+
return n !== 0;
|
|
9878
|
+
};
|
|
9879
|
+
BigNumber2.maximum = BigNumber2.max = function() {
|
|
9880
|
+
return maxOrMin(arguments, -1);
|
|
9881
|
+
};
|
|
9882
|
+
BigNumber2.minimum = BigNumber2.min = function() {
|
|
9883
|
+
return maxOrMin(arguments, 1);
|
|
9884
|
+
};
|
|
9885
|
+
BigNumber2.random = function() {
|
|
9886
|
+
var pow2_53 = 9007199254740992;
|
|
9887
|
+
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
9888
|
+
return mathfloor(Math.random() * pow2_53);
|
|
9889
|
+
} : function() {
|
|
9890
|
+
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
9891
|
+
};
|
|
9892
|
+
return function(dp) {
|
|
9893
|
+
var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
|
|
9894
|
+
if (dp == null)
|
|
9895
|
+
dp = DECIMAL_PLACES;
|
|
9896
|
+
else
|
|
9897
|
+
intCheck(dp, 0, MAX);
|
|
9898
|
+
k = mathceil(dp / LOG_BASE);
|
|
9899
|
+
if (CRYPTO) {
|
|
9900
|
+
if (crypto.getRandomValues) {
|
|
9901
|
+
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
9902
|
+
for (;i < k; ) {
|
|
9903
|
+
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
9904
|
+
if (v >= 9000000000000000) {
|
|
9905
|
+
b = crypto.getRandomValues(new Uint32Array(2));
|
|
9906
|
+
a[i] = b[0];
|
|
9907
|
+
a[i + 1] = b[1];
|
|
9908
|
+
} else {
|
|
9909
|
+
c.push(v % 100000000000000);
|
|
9910
|
+
i += 2;
|
|
9911
|
+
}
|
|
9912
|
+
}
|
|
9913
|
+
i = k / 2;
|
|
9914
|
+
} else if (crypto.randomBytes) {
|
|
9915
|
+
a = crypto.randomBytes(k *= 7);
|
|
9916
|
+
for (;i < k; ) {
|
|
9917
|
+
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];
|
|
9918
|
+
if (v >= 9000000000000000) {
|
|
9919
|
+
crypto.randomBytes(7).copy(a, i);
|
|
9920
|
+
} else {
|
|
9921
|
+
c.push(v % 100000000000000);
|
|
9922
|
+
i += 7;
|
|
9923
|
+
}
|
|
9924
|
+
}
|
|
9925
|
+
i = k / 7;
|
|
9926
|
+
} else {
|
|
9927
|
+
CRYPTO = false;
|
|
9928
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
9929
|
+
}
|
|
9930
|
+
}
|
|
9931
|
+
if (!CRYPTO) {
|
|
9932
|
+
for (;i < k; ) {
|
|
9933
|
+
v = random53bitInt();
|
|
9934
|
+
if (v < 9000000000000000)
|
|
9935
|
+
c[i++] = v % 100000000000000;
|
|
9936
|
+
}
|
|
9937
|
+
}
|
|
9938
|
+
k = c[--i];
|
|
9939
|
+
dp %= LOG_BASE;
|
|
9940
|
+
if (k && dp) {
|
|
9941
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
9942
|
+
c[i] = mathfloor(k / v) * v;
|
|
9943
|
+
}
|
|
9944
|
+
for (;c[i] === 0; c.pop(), i--)
|
|
9945
|
+
;
|
|
9946
|
+
if (i < 0) {
|
|
9947
|
+
c = [e = 0];
|
|
9948
|
+
} else {
|
|
9949
|
+
for (e = -1;c[0] === 0; c.splice(0, 1), e -= LOG_BASE)
|
|
9950
|
+
;
|
|
9951
|
+
for (i = 1, v = c[0];v >= 10; v /= 10, i++)
|
|
9952
|
+
;
|
|
9953
|
+
if (i < LOG_BASE)
|
|
9954
|
+
e -= LOG_BASE - i;
|
|
9955
|
+
}
|
|
9956
|
+
rand.e = e;
|
|
9957
|
+
rand.c = c;
|
|
9958
|
+
return rand;
|
|
9959
|
+
};
|
|
9960
|
+
}();
|
|
9961
|
+
BigNumber2.sum = function() {
|
|
9962
|
+
var i = 1, args = arguments, sum = new BigNumber2(args[0]);
|
|
9963
|
+
for (;i < args.length; )
|
|
9964
|
+
sum = sum.plus(args[i++]);
|
|
9965
|
+
return sum;
|
|
9966
|
+
};
|
|
9967
|
+
convertBase = function() {
|
|
9968
|
+
var decimal = "0123456789";
|
|
9969
|
+
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
9970
|
+
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
9971
|
+
for (;i < len; ) {
|
|
9972
|
+
for (arrL = arr.length;arrL--; arr[arrL] *= baseIn)
|
|
9973
|
+
;
|
|
9974
|
+
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
9975
|
+
for (j = 0;j < arr.length; j++) {
|
|
9976
|
+
if (arr[j] > baseOut - 1) {
|
|
9977
|
+
if (arr[j + 1] == null)
|
|
9978
|
+
arr[j + 1] = 0;
|
|
9979
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
9980
|
+
arr[j] %= baseOut;
|
|
9981
|
+
}
|
|
9982
|
+
}
|
|
9983
|
+
}
|
|
9984
|
+
return arr.reverse();
|
|
9985
|
+
}
|
|
9986
|
+
return function(str, baseIn, baseOut, sign, callerIsToString) {
|
|
9987
|
+
var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
9988
|
+
if (i >= 0) {
|
|
9989
|
+
k = POW_PRECISION;
|
|
9990
|
+
POW_PRECISION = 0;
|
|
9991
|
+
str = str.replace(".", "");
|
|
9992
|
+
y = new BigNumber2(baseIn);
|
|
9993
|
+
x = y.pow(str.length - i);
|
|
9994
|
+
POW_PRECISION = k;
|
|
9995
|
+
y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, "0"), 10, baseOut, decimal);
|
|
9996
|
+
y.e = y.c.length;
|
|
9997
|
+
}
|
|
9998
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
|
|
9999
|
+
e = k = xc.length;
|
|
10000
|
+
for (;xc[--k] == 0; xc.pop())
|
|
10001
|
+
;
|
|
10002
|
+
if (!xc[0])
|
|
10003
|
+
return alphabet.charAt(0);
|
|
10004
|
+
if (i < 0) {
|
|
10005
|
+
--e;
|
|
10006
|
+
} else {
|
|
10007
|
+
x.c = xc;
|
|
10008
|
+
x.e = e;
|
|
10009
|
+
x.s = sign;
|
|
10010
|
+
x = div(x, y, dp, rm, baseOut);
|
|
10011
|
+
xc = x.c;
|
|
10012
|
+
r = x.r;
|
|
10013
|
+
e = x.e;
|
|
10014
|
+
}
|
|
10015
|
+
d = e + dp + 1;
|
|
10016
|
+
i = xc[d];
|
|
10017
|
+
k = baseOut / 2;
|
|
10018
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
10019
|
+
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));
|
|
10020
|
+
if (d < 1 || !xc[0]) {
|
|
10021
|
+
str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
10022
|
+
} else {
|
|
10023
|
+
xc.length = d;
|
|
10024
|
+
if (r) {
|
|
10025
|
+
for (--baseOut;++xc[--d] > baseOut; ) {
|
|
10026
|
+
xc[d] = 0;
|
|
10027
|
+
if (!d) {
|
|
10028
|
+
++e;
|
|
10029
|
+
xc = [1].concat(xc);
|
|
10030
|
+
}
|
|
10031
|
+
}
|
|
10032
|
+
}
|
|
10033
|
+
for (k = xc.length;!xc[--k]; )
|
|
10034
|
+
;
|
|
10035
|
+
for (i = 0, str = "";i <= k; str += alphabet.charAt(xc[i++]))
|
|
10036
|
+
;
|
|
10037
|
+
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
10038
|
+
}
|
|
10039
|
+
return str;
|
|
10040
|
+
};
|
|
10041
|
+
}();
|
|
10042
|
+
div = function() {
|
|
10043
|
+
function multiply(x, k, base) {
|
|
10044
|
+
var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
|
|
10045
|
+
for (x = x.slice();i--; ) {
|
|
10046
|
+
xlo = x[i] % SQRT_BASE;
|
|
10047
|
+
xhi = x[i] / SQRT_BASE | 0;
|
|
10048
|
+
m = khi * xlo + xhi * klo;
|
|
10049
|
+
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
10050
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
10051
|
+
x[i] = temp % base;
|
|
10052
|
+
}
|
|
10053
|
+
if (carry)
|
|
10054
|
+
x = [carry].concat(x);
|
|
10055
|
+
return x;
|
|
10056
|
+
}
|
|
10057
|
+
function compare(a, b, aL, bL) {
|
|
10058
|
+
var i, cmp;
|
|
10059
|
+
if (aL != bL) {
|
|
10060
|
+
cmp = aL > bL ? 1 : -1;
|
|
10061
|
+
} else {
|
|
10062
|
+
for (i = cmp = 0;i < aL; i++) {
|
|
10063
|
+
if (a[i] != b[i]) {
|
|
10064
|
+
cmp = a[i] > b[i] ? 1 : -1;
|
|
10065
|
+
break;
|
|
10066
|
+
}
|
|
10067
|
+
}
|
|
10068
|
+
}
|
|
10069
|
+
return cmp;
|
|
10070
|
+
}
|
|
10071
|
+
function subtract(a, b, aL, base) {
|
|
10072
|
+
var i = 0;
|
|
10073
|
+
for (;aL--; ) {
|
|
10074
|
+
a[aL] -= i;
|
|
10075
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
10076
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
10077
|
+
}
|
|
10078
|
+
for (;!a[0] && a.length > 1; a.splice(0, 1))
|
|
10079
|
+
;
|
|
10080
|
+
}
|
|
10081
|
+
return function(x, y, dp, rm, base) {
|
|
10082
|
+
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;
|
|
10083
|
+
if (!xc || !xc[0] || !yc || !yc[0]) {
|
|
10084
|
+
return new BigNumber2(!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : xc && xc[0] == 0 || !yc ? s * 0 : s / 0);
|
|
10085
|
+
}
|
|
10086
|
+
q = new BigNumber2(s);
|
|
10087
|
+
qc = q.c = [];
|
|
10088
|
+
e = x.e - y.e;
|
|
10089
|
+
s = dp + e + 1;
|
|
10090
|
+
if (!base) {
|
|
10091
|
+
base = BASE;
|
|
10092
|
+
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
10093
|
+
s = s / LOG_BASE | 0;
|
|
10094
|
+
}
|
|
10095
|
+
for (i = 0;yc[i] == (xc[i] || 0); i++)
|
|
10096
|
+
;
|
|
10097
|
+
if (yc[i] > (xc[i] || 0))
|
|
10098
|
+
e--;
|
|
10099
|
+
if (s < 0) {
|
|
10100
|
+
qc.push(1);
|
|
10101
|
+
more = true;
|
|
10102
|
+
} else {
|
|
10103
|
+
xL = xc.length;
|
|
10104
|
+
yL = yc.length;
|
|
10105
|
+
i = 0;
|
|
10106
|
+
s += 2;
|
|
10107
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
10108
|
+
if (n > 1) {
|
|
10109
|
+
yc = multiply(yc, n, base);
|
|
10110
|
+
xc = multiply(xc, n, base);
|
|
10111
|
+
yL = yc.length;
|
|
10112
|
+
xL = xc.length;
|
|
10113
|
+
}
|
|
10114
|
+
xi = yL;
|
|
10115
|
+
rem = xc.slice(0, yL);
|
|
10116
|
+
remL = rem.length;
|
|
10117
|
+
for (;remL < yL; rem[remL++] = 0)
|
|
10118
|
+
;
|
|
10119
|
+
yz = yc.slice();
|
|
10120
|
+
yz = [0].concat(yz);
|
|
10121
|
+
yc0 = yc[0];
|
|
10122
|
+
if (yc[1] >= base / 2)
|
|
10123
|
+
yc0++;
|
|
10124
|
+
do {
|
|
10125
|
+
n = 0;
|
|
10126
|
+
cmp = compare(yc, rem, yL, remL);
|
|
10127
|
+
if (cmp < 0) {
|
|
10128
|
+
rem0 = rem[0];
|
|
10129
|
+
if (yL != remL)
|
|
10130
|
+
rem0 = rem0 * base + (rem[1] || 0);
|
|
10131
|
+
n = mathfloor(rem0 / yc0);
|
|
10132
|
+
if (n > 1) {
|
|
10133
|
+
if (n >= base)
|
|
10134
|
+
n = base - 1;
|
|
10135
|
+
prod = multiply(yc, n, base);
|
|
10136
|
+
prodL = prod.length;
|
|
10137
|
+
remL = rem.length;
|
|
10138
|
+
while (compare(prod, rem, prodL, remL) == 1) {
|
|
10139
|
+
n--;
|
|
10140
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
10141
|
+
prodL = prod.length;
|
|
10142
|
+
cmp = 1;
|
|
10143
|
+
}
|
|
10144
|
+
} else {
|
|
10145
|
+
if (n == 0) {
|
|
10146
|
+
cmp = n = 1;
|
|
10147
|
+
}
|
|
10148
|
+
prod = yc.slice();
|
|
10149
|
+
prodL = prod.length;
|
|
10150
|
+
}
|
|
10151
|
+
if (prodL < remL)
|
|
10152
|
+
prod = [0].concat(prod);
|
|
10153
|
+
subtract(rem, prod, remL, base);
|
|
10154
|
+
remL = rem.length;
|
|
10155
|
+
if (cmp == -1) {
|
|
10156
|
+
while (compare(yc, rem, yL, remL) < 1) {
|
|
10157
|
+
n++;
|
|
10158
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
10159
|
+
remL = rem.length;
|
|
10160
|
+
}
|
|
10161
|
+
}
|
|
10162
|
+
} else if (cmp === 0) {
|
|
10163
|
+
n++;
|
|
10164
|
+
rem = [0];
|
|
10165
|
+
}
|
|
10166
|
+
qc[i++] = n;
|
|
10167
|
+
if (rem[0]) {
|
|
10168
|
+
rem[remL++] = xc[xi] || 0;
|
|
10169
|
+
} else {
|
|
10170
|
+
rem = [xc[xi]];
|
|
10171
|
+
remL = 1;
|
|
10172
|
+
}
|
|
10173
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
10174
|
+
more = rem[0] != null;
|
|
10175
|
+
if (!qc[0])
|
|
10176
|
+
qc.splice(0, 1);
|
|
10177
|
+
}
|
|
10178
|
+
if (base == BASE) {
|
|
10179
|
+
for (i = 1, s = qc[0];s >= 10; s /= 10, i++)
|
|
10180
|
+
;
|
|
10181
|
+
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
10182
|
+
} else {
|
|
10183
|
+
q.e = e;
|
|
10184
|
+
q.r = +more;
|
|
10185
|
+
}
|
|
10186
|
+
return q;
|
|
10187
|
+
};
|
|
10188
|
+
}();
|
|
10189
|
+
function format(n, i, rm, id2) {
|
|
10190
|
+
var c0, e, ne, len, str;
|
|
10191
|
+
if (rm == null)
|
|
10192
|
+
rm = ROUNDING_MODE;
|
|
10193
|
+
else
|
|
10194
|
+
intCheck(rm, 0, 8);
|
|
10195
|
+
if (!n.c)
|
|
10196
|
+
return n.toString();
|
|
10197
|
+
c0 = n.c[0];
|
|
10198
|
+
ne = n.e;
|
|
10199
|
+
if (i == null) {
|
|
10200
|
+
str = coeffToString(n.c);
|
|
10201
|
+
str = id2 == 1 || id2 == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
|
|
10202
|
+
} else {
|
|
10203
|
+
n = round(new BigNumber2(n), i, rm);
|
|
10204
|
+
e = n.e;
|
|
10205
|
+
str = coeffToString(n.c);
|
|
10206
|
+
len = str.length;
|
|
10207
|
+
if (id2 == 1 || id2 == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
10208
|
+
for (;len < i; str += "0", len++)
|
|
10209
|
+
;
|
|
10210
|
+
str = toExponential(str, e);
|
|
10211
|
+
} else {
|
|
10212
|
+
i -= ne + (id2 === 2 && e > ne);
|
|
10213
|
+
str = toFixedPoint(str, e, "0");
|
|
10214
|
+
if (e + 1 > len) {
|
|
10215
|
+
if (--i > 0)
|
|
10216
|
+
for (str += ".";i--; str += "0")
|
|
10217
|
+
;
|
|
10218
|
+
} else {
|
|
10219
|
+
i += e - len;
|
|
10220
|
+
if (i > 0) {
|
|
10221
|
+
if (e + 1 == len)
|
|
10222
|
+
str += ".";
|
|
10223
|
+
for (;i--; str += "0")
|
|
10224
|
+
;
|
|
10225
|
+
}
|
|
10226
|
+
}
|
|
10227
|
+
}
|
|
10228
|
+
}
|
|
10229
|
+
return n.s < 0 && c0 ? "-" + str : str;
|
|
10230
|
+
}
|
|
10231
|
+
function isBigNumber(v) {
|
|
10232
|
+
return v instanceof BigNumber2 || !!v && v._isBigNumber === true;
|
|
10233
|
+
}
|
|
10234
|
+
function maxOrMin(args, n) {
|
|
10235
|
+
var k, y, i = 1, x = new BigNumber2(args[0]);
|
|
10236
|
+
for (;i < args.length; i++) {
|
|
10237
|
+
y = new BigNumber2(args[i]);
|
|
10238
|
+
if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
|
|
10239
|
+
x = y;
|
|
10240
|
+
}
|
|
10241
|
+
}
|
|
10242
|
+
return x;
|
|
10243
|
+
}
|
|
10244
|
+
function normalise(n, c, e) {
|
|
10245
|
+
var i = 1, j = c.length;
|
|
10246
|
+
for (;!c[--j]; c.pop())
|
|
10247
|
+
;
|
|
10248
|
+
for (j = c[0];j >= 10; j /= 10, i++)
|
|
10249
|
+
;
|
|
10250
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
|
10251
|
+
n.c = n.e = null;
|
|
10252
|
+
} else if (e < MIN_EXP) {
|
|
10253
|
+
n.c = [n.e = 0];
|
|
10254
|
+
} else {
|
|
10255
|
+
n.e = e;
|
|
10256
|
+
n.c = c;
|
|
10257
|
+
}
|
|
10258
|
+
return n;
|
|
10259
|
+
}
|
|
10260
|
+
parseUnusualNumeric = function() {
|
|
10261
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
10262
|
+
return function(x, str, b) {
|
|
10263
|
+
var base, s = str.replace(whitespaceOrPlus, "");
|
|
10264
|
+
if (isInfinityOrNaN.test(s)) {
|
|
10265
|
+
x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
10266
|
+
x.c = x.e = null;
|
|
10267
|
+
return;
|
|
10268
|
+
}
|
|
10269
|
+
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
10270
|
+
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
10271
|
+
return !b || b == base ? p1 : m;
|
|
10272
|
+
});
|
|
10273
|
+
if (b) {
|
|
10274
|
+
base = b;
|
|
10275
|
+
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
10276
|
+
}
|
|
10277
|
+
if (str != s)
|
|
10278
|
+
return new BigNumber2(s, base);
|
|
10279
|
+
throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
|
|
10280
|
+
};
|
|
10281
|
+
}();
|
|
10282
|
+
function round(x, sd, rm, r) {
|
|
10283
|
+
var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
|
|
10284
|
+
if (xc) {
|
|
10285
|
+
out: {
|
|
10286
|
+
for (d = 1, k = xc[0];k >= 10; k /= 10, d++)
|
|
10287
|
+
;
|
|
10288
|
+
i = sd - d;
|
|
10289
|
+
if (i < 0) {
|
|
10290
|
+
i += LOG_BASE;
|
|
10291
|
+
j = sd;
|
|
10292
|
+
n = xc[ni = 0];
|
|
10293
|
+
rd = mathfloor(n / pows10[d - j - 1] % 10);
|
|
10294
|
+
} else {
|
|
10295
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
10296
|
+
if (ni >= xc.length) {
|
|
10297
|
+
if (r) {
|
|
10298
|
+
for (;xc.length <= ni; xc.push(0))
|
|
10299
|
+
;
|
|
10300
|
+
n = rd = 0;
|
|
10301
|
+
d = 1;
|
|
10302
|
+
i %= LOG_BASE;
|
|
10303
|
+
j = i - LOG_BASE + 1;
|
|
10304
|
+
} else {
|
|
10305
|
+
break out;
|
|
10306
|
+
}
|
|
10307
|
+
} else {
|
|
10308
|
+
n = k = xc[ni];
|
|
10309
|
+
for (d = 1;k >= 10; k /= 10, d++)
|
|
10310
|
+
;
|
|
10311
|
+
i %= LOG_BASE;
|
|
10312
|
+
j = i - LOG_BASE + d;
|
|
10313
|
+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
|
|
10314
|
+
}
|
|
10315
|
+
}
|
|
10316
|
+
r = r || sd < 0 || xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
10317
|
+
r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
10318
|
+
if (sd < 1 || !xc[0]) {
|
|
10319
|
+
xc.length = 0;
|
|
10320
|
+
if (r) {
|
|
10321
|
+
sd -= x.e + 1;
|
|
10322
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
10323
|
+
x.e = -sd || 0;
|
|
10324
|
+
} else {
|
|
10325
|
+
xc[0] = x.e = 0;
|
|
10326
|
+
}
|
|
10327
|
+
return x;
|
|
10328
|
+
}
|
|
10329
|
+
if (i == 0) {
|
|
10330
|
+
xc.length = ni;
|
|
10331
|
+
k = 1;
|
|
10332
|
+
ni--;
|
|
10333
|
+
} else {
|
|
10334
|
+
xc.length = ni + 1;
|
|
10335
|
+
k = pows10[LOG_BASE - i];
|
|
10336
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
10337
|
+
}
|
|
10338
|
+
if (r) {
|
|
10339
|
+
for (;; ) {
|
|
10340
|
+
if (ni == 0) {
|
|
10341
|
+
for (i = 1, j = xc[0];j >= 10; j /= 10, i++)
|
|
10342
|
+
;
|
|
10343
|
+
j = xc[0] += k;
|
|
10344
|
+
for (k = 1;j >= 10; j /= 10, k++)
|
|
10345
|
+
;
|
|
10346
|
+
if (i != k) {
|
|
10347
|
+
x.e++;
|
|
10348
|
+
if (xc[0] == BASE)
|
|
10349
|
+
xc[0] = 1;
|
|
10350
|
+
}
|
|
10351
|
+
break;
|
|
10352
|
+
} else {
|
|
10353
|
+
xc[ni] += k;
|
|
10354
|
+
if (xc[ni] != BASE)
|
|
10355
|
+
break;
|
|
10356
|
+
xc[ni--] = 0;
|
|
10357
|
+
k = 1;
|
|
10358
|
+
}
|
|
10359
|
+
}
|
|
10360
|
+
}
|
|
10361
|
+
for (i = xc.length;xc[--i] === 0; xc.pop())
|
|
10362
|
+
;
|
|
10363
|
+
}
|
|
10364
|
+
if (x.e > MAX_EXP) {
|
|
10365
|
+
x.c = x.e = null;
|
|
10366
|
+
} else if (x.e < MIN_EXP) {
|
|
10367
|
+
x.c = [x.e = 0];
|
|
10368
|
+
}
|
|
10369
|
+
}
|
|
10370
|
+
return x;
|
|
10371
|
+
}
|
|
10372
|
+
function valueOf(n) {
|
|
10373
|
+
var str, e = n.e;
|
|
10374
|
+
if (e === null)
|
|
10375
|
+
return n.toString();
|
|
10376
|
+
str = coeffToString(n.c);
|
|
10377
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
10378
|
+
return n.s < 0 ? "-" + str : str;
|
|
10379
|
+
}
|
|
10380
|
+
P.absoluteValue = P.abs = function() {
|
|
10381
|
+
var x = new BigNumber2(this);
|
|
10382
|
+
if (x.s < 0)
|
|
10383
|
+
x.s = 1;
|
|
10384
|
+
return x;
|
|
10385
|
+
};
|
|
10386
|
+
P.comparedTo = function(y, b) {
|
|
10387
|
+
return compare(this, new BigNumber2(y, b));
|
|
10388
|
+
};
|
|
10389
|
+
P.decimalPlaces = P.dp = function(dp, rm) {
|
|
10390
|
+
var c, n, v, x = this;
|
|
10391
|
+
if (dp != null) {
|
|
10392
|
+
intCheck(dp, 0, MAX);
|
|
10393
|
+
if (rm == null)
|
|
10394
|
+
rm = ROUNDING_MODE;
|
|
10395
|
+
else
|
|
10396
|
+
intCheck(rm, 0, 8);
|
|
10397
|
+
return round(new BigNumber2(x), dp + x.e + 1, rm);
|
|
10398
|
+
}
|
|
10399
|
+
if (!(c = x.c))
|
|
10400
|
+
return null;
|
|
10401
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
10402
|
+
if (v = c[v])
|
|
10403
|
+
for (;v % 10 == 0; v /= 10, n--)
|
|
10404
|
+
;
|
|
10405
|
+
if (n < 0)
|
|
10406
|
+
n = 0;
|
|
10407
|
+
return n;
|
|
10408
|
+
};
|
|
10409
|
+
P.dividedBy = P.div = function(y, b) {
|
|
10410
|
+
return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
10411
|
+
};
|
|
10412
|
+
P.dividedToIntegerBy = P.idiv = function(y, b) {
|
|
10413
|
+
return div(this, new BigNumber2(y, b), 0, 1);
|
|
10414
|
+
};
|
|
10415
|
+
P.exponentiatedBy = P.pow = function(n, m) {
|
|
10416
|
+
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
|
|
10417
|
+
n = new BigNumber2(n);
|
|
10418
|
+
if (n.c && !n.isInteger()) {
|
|
10419
|
+
throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
10420
|
+
}
|
|
10421
|
+
if (m != null)
|
|
10422
|
+
m = new BigNumber2(m);
|
|
10423
|
+
nIsBig = n.e > 14;
|
|
10424
|
+
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
10425
|
+
y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
10426
|
+
return m ? y.mod(m) : y;
|
|
10427
|
+
}
|
|
10428
|
+
nIsNeg = n.s < 0;
|
|
10429
|
+
if (m) {
|
|
10430
|
+
if (m.c ? !m.c[0] : !m.s)
|
|
10431
|
+
return new BigNumber2(NaN);
|
|
10432
|
+
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
10433
|
+
if (isModExp)
|
|
10434
|
+
x = x.mod(m);
|
|
10435
|
+
} else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 240000000 : x.c[0] < 80000000000000 || nIsBig && x.c[0] <= 99999750000000))) {
|
|
10436
|
+
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
10437
|
+
if (x.e > -1)
|
|
10438
|
+
k = 1 / k;
|
|
10439
|
+
return new BigNumber2(nIsNeg ? 1 / k : k);
|
|
10440
|
+
} else if (POW_PRECISION) {
|
|
10441
|
+
k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
10442
|
+
}
|
|
10443
|
+
if (nIsBig) {
|
|
10444
|
+
half = new BigNumber2(0.5);
|
|
10445
|
+
if (nIsNeg)
|
|
10446
|
+
n.s = 1;
|
|
10447
|
+
nIsOdd = isOdd(n);
|
|
10448
|
+
} else {
|
|
10449
|
+
i = Math.abs(+valueOf(n));
|
|
10450
|
+
nIsOdd = i % 2;
|
|
10451
|
+
}
|
|
10452
|
+
y = new BigNumber2(ONE);
|
|
10453
|
+
for (;; ) {
|
|
10454
|
+
if (nIsOdd) {
|
|
10455
|
+
y = y.times(x);
|
|
10456
|
+
if (!y.c)
|
|
10457
|
+
break;
|
|
10458
|
+
if (k) {
|
|
10459
|
+
if (y.c.length > k)
|
|
10460
|
+
y.c.length = k;
|
|
10461
|
+
} else if (isModExp) {
|
|
10462
|
+
y = y.mod(m);
|
|
10463
|
+
}
|
|
10464
|
+
}
|
|
10465
|
+
if (i) {
|
|
10466
|
+
i = mathfloor(i / 2);
|
|
10467
|
+
if (i === 0)
|
|
10468
|
+
break;
|
|
10469
|
+
nIsOdd = i % 2;
|
|
10470
|
+
} else {
|
|
10471
|
+
n = n.times(half);
|
|
10472
|
+
round(n, n.e + 1, 1);
|
|
10473
|
+
if (n.e > 14) {
|
|
10474
|
+
nIsOdd = isOdd(n);
|
|
10475
|
+
} else {
|
|
10476
|
+
i = +valueOf(n);
|
|
10477
|
+
if (i === 0)
|
|
10478
|
+
break;
|
|
10479
|
+
nIsOdd = i % 2;
|
|
10480
|
+
}
|
|
10481
|
+
}
|
|
10482
|
+
x = x.times(x);
|
|
10483
|
+
if (k) {
|
|
10484
|
+
if (x.c && x.c.length > k)
|
|
10485
|
+
x.c.length = k;
|
|
10486
|
+
} else if (isModExp) {
|
|
10487
|
+
x = x.mod(m);
|
|
10488
|
+
}
|
|
10489
|
+
}
|
|
10490
|
+
if (isModExp)
|
|
10491
|
+
return y;
|
|
10492
|
+
if (nIsNeg)
|
|
10493
|
+
y = ONE.div(y);
|
|
10494
|
+
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
10495
|
+
};
|
|
10496
|
+
P.integerValue = function(rm) {
|
|
10497
|
+
var n = new BigNumber2(this);
|
|
10498
|
+
if (rm == null)
|
|
10499
|
+
rm = ROUNDING_MODE;
|
|
10500
|
+
else
|
|
10501
|
+
intCheck(rm, 0, 8);
|
|
10502
|
+
return round(n, n.e + 1, rm);
|
|
10503
|
+
};
|
|
10504
|
+
P.isEqualTo = P.eq = function(y, b) {
|
|
10505
|
+
return compare(this, new BigNumber2(y, b)) === 0;
|
|
10506
|
+
};
|
|
10507
|
+
P.isFinite = function() {
|
|
10508
|
+
return !!this.c;
|
|
10509
|
+
};
|
|
10510
|
+
P.isGreaterThan = P.gt = function(y, b) {
|
|
10511
|
+
return compare(this, new BigNumber2(y, b)) > 0;
|
|
10512
|
+
};
|
|
10513
|
+
P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
|
|
10514
|
+
return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
|
|
10515
|
+
};
|
|
10516
|
+
P.isInteger = function() {
|
|
10517
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
10518
|
+
};
|
|
10519
|
+
P.isLessThan = P.lt = function(y, b) {
|
|
10520
|
+
return compare(this, new BigNumber2(y, b)) < 0;
|
|
10521
|
+
};
|
|
10522
|
+
P.isLessThanOrEqualTo = P.lte = function(y, b) {
|
|
10523
|
+
return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
|
|
10524
|
+
};
|
|
10525
|
+
P.isNaN = function() {
|
|
10526
|
+
return !this.s;
|
|
10527
|
+
};
|
|
10528
|
+
P.isNegative = function() {
|
|
10529
|
+
return this.s < 0;
|
|
10530
|
+
};
|
|
10531
|
+
P.isPositive = function() {
|
|
10532
|
+
return this.s > 0;
|
|
10533
|
+
};
|
|
10534
|
+
P.isZero = function() {
|
|
10535
|
+
return !!this.c && this.c[0] == 0;
|
|
10536
|
+
};
|
|
10537
|
+
P.minus = function(y, b) {
|
|
10538
|
+
var i, j, t, xLTy, x = this, a = x.s;
|
|
10539
|
+
y = new BigNumber2(y, b);
|
|
10540
|
+
b = y.s;
|
|
10541
|
+
if (!a || !b)
|
|
10542
|
+
return new BigNumber2(NaN);
|
|
10543
|
+
if (a != b) {
|
|
10544
|
+
y.s = -b;
|
|
10545
|
+
return x.plus(y);
|
|
10546
|
+
}
|
|
10547
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
10548
|
+
if (!xe || !ye) {
|
|
10549
|
+
if (!xc || !yc)
|
|
10550
|
+
return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
|
|
10551
|
+
if (!xc[0] || !yc[0]) {
|
|
10552
|
+
return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : ROUNDING_MODE == 3 ? -0 : 0);
|
|
10553
|
+
}
|
|
10554
|
+
}
|
|
10555
|
+
xe = bitFloor(xe);
|
|
10556
|
+
ye = bitFloor(ye);
|
|
10557
|
+
xc = xc.slice();
|
|
10558
|
+
if (a = xe - ye) {
|
|
10559
|
+
if (xLTy = a < 0) {
|
|
10560
|
+
a = -a;
|
|
10561
|
+
t = xc;
|
|
10562
|
+
} else {
|
|
10563
|
+
ye = xe;
|
|
10564
|
+
t = yc;
|
|
10565
|
+
}
|
|
10566
|
+
t.reverse();
|
|
10567
|
+
for (b = a;b--; t.push(0))
|
|
10568
|
+
;
|
|
10569
|
+
t.reverse();
|
|
10570
|
+
} else {
|
|
10571
|
+
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
10572
|
+
for (a = b = 0;b < j; b++) {
|
|
10573
|
+
if (xc[b] != yc[b]) {
|
|
10574
|
+
xLTy = xc[b] < yc[b];
|
|
10575
|
+
break;
|
|
10576
|
+
}
|
|
10577
|
+
}
|
|
10578
|
+
}
|
|
10579
|
+
if (xLTy) {
|
|
10580
|
+
t = xc;
|
|
10581
|
+
xc = yc;
|
|
10582
|
+
yc = t;
|
|
10583
|
+
y.s = -y.s;
|
|
10584
|
+
}
|
|
10585
|
+
b = (j = yc.length) - (i = xc.length);
|
|
10586
|
+
if (b > 0)
|
|
10587
|
+
for (;b--; xc[i++] = 0)
|
|
10588
|
+
;
|
|
10589
|
+
b = BASE - 1;
|
|
10590
|
+
for (;j > a; ) {
|
|
10591
|
+
if (xc[--j] < yc[j]) {
|
|
10592
|
+
for (i = j;i && !xc[--i]; xc[i] = b)
|
|
10593
|
+
;
|
|
10594
|
+
--xc[i];
|
|
10595
|
+
xc[j] += BASE;
|
|
10596
|
+
}
|
|
10597
|
+
xc[j] -= yc[j];
|
|
10598
|
+
}
|
|
10599
|
+
for (;xc[0] == 0; xc.splice(0, 1), --ye)
|
|
10600
|
+
;
|
|
10601
|
+
if (!xc[0]) {
|
|
10602
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
10603
|
+
y.c = [y.e = 0];
|
|
10604
|
+
return y;
|
|
10605
|
+
}
|
|
10606
|
+
return normalise(y, xc, ye);
|
|
10607
|
+
};
|
|
10608
|
+
P.modulo = P.mod = function(y, b) {
|
|
10609
|
+
var q, s, x = this;
|
|
10610
|
+
y = new BigNumber2(y, b);
|
|
10611
|
+
if (!x.c || !y.s || y.c && !y.c[0]) {
|
|
10612
|
+
return new BigNumber2(NaN);
|
|
10613
|
+
} else if (!y.c || x.c && !x.c[0]) {
|
|
10614
|
+
return new BigNumber2(x);
|
|
10615
|
+
}
|
|
10616
|
+
if (MODULO_MODE == 9) {
|
|
10617
|
+
s = y.s;
|
|
10618
|
+
y.s = 1;
|
|
10619
|
+
q = div(x, y, 0, 3);
|
|
10620
|
+
y.s = s;
|
|
10621
|
+
q.s *= s;
|
|
10622
|
+
} else {
|
|
10623
|
+
q = div(x, y, 0, MODULO_MODE);
|
|
10624
|
+
}
|
|
10625
|
+
y = x.minus(q.times(y));
|
|
10626
|
+
if (!y.c[0] && MODULO_MODE == 1)
|
|
10627
|
+
y.s = x.s;
|
|
10628
|
+
return y;
|
|
10629
|
+
};
|
|
10630
|
+
P.multipliedBy = P.times = function(y, b) {
|
|
10631
|
+
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;
|
|
10632
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
10633
|
+
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
|
10634
|
+
y.c = y.e = y.s = null;
|
|
10635
|
+
} else {
|
|
10636
|
+
y.s *= x.s;
|
|
10637
|
+
if (!xc || !yc) {
|
|
10638
|
+
y.c = y.e = null;
|
|
10639
|
+
} else {
|
|
10640
|
+
y.c = [0];
|
|
10641
|
+
y.e = 0;
|
|
10642
|
+
}
|
|
10643
|
+
}
|
|
10644
|
+
return y;
|
|
10645
|
+
}
|
|
10646
|
+
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
10647
|
+
y.s *= x.s;
|
|
10648
|
+
xcL = xc.length;
|
|
10649
|
+
ycL = yc.length;
|
|
10650
|
+
if (xcL < ycL) {
|
|
10651
|
+
zc = xc;
|
|
10652
|
+
xc = yc;
|
|
10653
|
+
yc = zc;
|
|
10654
|
+
i = xcL;
|
|
10655
|
+
xcL = ycL;
|
|
10656
|
+
ycL = i;
|
|
10657
|
+
}
|
|
10658
|
+
for (i = xcL + ycL, zc = [];i--; zc.push(0))
|
|
10659
|
+
;
|
|
10660
|
+
base = BASE;
|
|
10661
|
+
sqrtBase = SQRT_BASE;
|
|
10662
|
+
for (i = ycL;--i >= 0; ) {
|
|
10663
|
+
c = 0;
|
|
10664
|
+
ylo = yc[i] % sqrtBase;
|
|
10665
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
10666
|
+
for (k = xcL, j = i + k;j > i; ) {
|
|
10667
|
+
xlo = xc[--k] % sqrtBase;
|
|
10668
|
+
xhi = xc[k] / sqrtBase | 0;
|
|
10669
|
+
m = yhi * xlo + xhi * ylo;
|
|
10670
|
+
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
10671
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
10672
|
+
zc[j--] = xlo % base;
|
|
10673
|
+
}
|
|
10674
|
+
zc[j] = c;
|
|
10675
|
+
}
|
|
10676
|
+
if (c) {
|
|
10677
|
+
++e;
|
|
10678
|
+
} else {
|
|
10679
|
+
zc.splice(0, 1);
|
|
10680
|
+
}
|
|
10681
|
+
return normalise(y, zc, e);
|
|
10682
|
+
};
|
|
10683
|
+
P.negated = function() {
|
|
10684
|
+
var x = new BigNumber2(this);
|
|
10685
|
+
x.s = -x.s || null;
|
|
10686
|
+
return x;
|
|
10687
|
+
};
|
|
10688
|
+
P.plus = function(y, b) {
|
|
10689
|
+
var t, x = this, a = x.s;
|
|
10690
|
+
y = new BigNumber2(y, b);
|
|
10691
|
+
b = y.s;
|
|
10692
|
+
if (!a || !b)
|
|
10693
|
+
return new BigNumber2(NaN);
|
|
10694
|
+
if (a != b) {
|
|
10695
|
+
y.s = -b;
|
|
10696
|
+
return x.minus(y);
|
|
10697
|
+
}
|
|
10698
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
10699
|
+
if (!xe || !ye) {
|
|
10700
|
+
if (!xc || !yc)
|
|
10701
|
+
return new BigNumber2(a / 0);
|
|
10702
|
+
if (!xc[0] || !yc[0])
|
|
10703
|
+
return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
|
|
10704
|
+
}
|
|
10705
|
+
xe = bitFloor(xe);
|
|
10706
|
+
ye = bitFloor(ye);
|
|
10707
|
+
xc = xc.slice();
|
|
10708
|
+
if (a = xe - ye) {
|
|
10709
|
+
if (a > 0) {
|
|
10710
|
+
ye = xe;
|
|
10711
|
+
t = yc;
|
|
10712
|
+
} else {
|
|
10713
|
+
a = -a;
|
|
10714
|
+
t = xc;
|
|
10715
|
+
}
|
|
10716
|
+
t.reverse();
|
|
10717
|
+
for (;a--; t.push(0))
|
|
10718
|
+
;
|
|
10719
|
+
t.reverse();
|
|
10720
|
+
}
|
|
10721
|
+
a = xc.length;
|
|
10722
|
+
b = yc.length;
|
|
10723
|
+
if (a - b < 0) {
|
|
10724
|
+
t = yc;
|
|
10725
|
+
yc = xc;
|
|
10726
|
+
xc = t;
|
|
10727
|
+
b = a;
|
|
10728
|
+
}
|
|
10729
|
+
for (a = 0;b; ) {
|
|
10730
|
+
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
10731
|
+
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
10732
|
+
}
|
|
10733
|
+
if (a) {
|
|
10734
|
+
xc = [a].concat(xc);
|
|
10735
|
+
++ye;
|
|
10736
|
+
}
|
|
10737
|
+
return normalise(y, xc, ye);
|
|
10738
|
+
};
|
|
10739
|
+
P.precision = P.sd = function(sd, rm) {
|
|
10740
|
+
var c, n, v, x = this;
|
|
10741
|
+
if (sd != null && sd !== !!sd) {
|
|
10742
|
+
intCheck(sd, 1, MAX);
|
|
10743
|
+
if (rm == null)
|
|
10744
|
+
rm = ROUNDING_MODE;
|
|
10745
|
+
else
|
|
10746
|
+
intCheck(rm, 0, 8);
|
|
10747
|
+
return round(new BigNumber2(x), sd, rm);
|
|
10748
|
+
}
|
|
10749
|
+
if (!(c = x.c))
|
|
10750
|
+
return null;
|
|
10751
|
+
v = c.length - 1;
|
|
10752
|
+
n = v * LOG_BASE + 1;
|
|
10753
|
+
if (v = c[v]) {
|
|
10754
|
+
for (;v % 10 == 0; v /= 10, n--)
|
|
10755
|
+
;
|
|
10756
|
+
for (v = c[0];v >= 10; v /= 10, n++)
|
|
10757
|
+
;
|
|
10758
|
+
}
|
|
10759
|
+
if (sd && x.e + 1 > n)
|
|
10760
|
+
n = x.e + 1;
|
|
10761
|
+
return n;
|
|
10762
|
+
};
|
|
10763
|
+
P.shiftedBy = function(k) {
|
|
10764
|
+
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
10765
|
+
return this.times("1e" + k);
|
|
10766
|
+
};
|
|
10767
|
+
P.squareRoot = P.sqrt = function() {
|
|
10768
|
+
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");
|
|
10769
|
+
if (s !== 1 || !c || !c[0]) {
|
|
10770
|
+
return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
|
10771
|
+
}
|
|
10772
|
+
s = Math.sqrt(+valueOf(x));
|
|
10773
|
+
if (s == 0 || s == 1 / 0) {
|
|
10774
|
+
n = coeffToString(c);
|
|
10775
|
+
if ((n.length + e) % 2 == 0)
|
|
10776
|
+
n += "0";
|
|
10777
|
+
s = Math.sqrt(+n);
|
|
10778
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
10779
|
+
if (s == 1 / 0) {
|
|
10780
|
+
n = "5e" + e;
|
|
10781
|
+
} else {
|
|
10782
|
+
n = s.toExponential();
|
|
10783
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
10784
|
+
}
|
|
10785
|
+
r = new BigNumber2(n);
|
|
10786
|
+
} else {
|
|
10787
|
+
r = new BigNumber2(s + "");
|
|
10788
|
+
}
|
|
10789
|
+
if (r.c[0]) {
|
|
10790
|
+
e = r.e;
|
|
10791
|
+
s = e + dp;
|
|
10792
|
+
if (s < 3)
|
|
10793
|
+
s = 0;
|
|
10794
|
+
for (;; ) {
|
|
10795
|
+
t = r;
|
|
10796
|
+
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
10797
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
10798
|
+
if (r.e < e)
|
|
10799
|
+
--s;
|
|
10800
|
+
n = n.slice(s - 3, s + 1);
|
|
10801
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
10802
|
+
if (!rep) {
|
|
10803
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
10804
|
+
if (t.times(t).eq(x)) {
|
|
10805
|
+
r = t;
|
|
10806
|
+
break;
|
|
10807
|
+
}
|
|
10808
|
+
}
|
|
10809
|
+
dp += 4;
|
|
10810
|
+
s += 4;
|
|
10811
|
+
rep = 1;
|
|
10812
|
+
} else {
|
|
10813
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
10814
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
10815
|
+
m = !r.times(r).eq(x);
|
|
10816
|
+
}
|
|
10817
|
+
break;
|
|
10818
|
+
}
|
|
10819
|
+
}
|
|
10820
|
+
}
|
|
10821
|
+
}
|
|
10822
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
10823
|
+
};
|
|
10824
|
+
P.toExponential = function(dp, rm) {
|
|
10825
|
+
if (dp != null) {
|
|
10826
|
+
intCheck(dp, 0, MAX);
|
|
10827
|
+
dp++;
|
|
10828
|
+
}
|
|
10829
|
+
return format(this, dp, rm, 1);
|
|
10830
|
+
};
|
|
10831
|
+
P.toFixed = function(dp, rm) {
|
|
10832
|
+
if (dp != null) {
|
|
10833
|
+
intCheck(dp, 0, MAX);
|
|
10834
|
+
dp = dp + this.e + 1;
|
|
10835
|
+
}
|
|
10836
|
+
return format(this, dp, rm);
|
|
10837
|
+
};
|
|
10838
|
+
P.toFormat = function(dp, rm, format2) {
|
|
10839
|
+
var str, x = this;
|
|
10840
|
+
if (format2 == null) {
|
|
10841
|
+
if (dp != null && rm && typeof rm == "object") {
|
|
10842
|
+
format2 = rm;
|
|
10843
|
+
rm = null;
|
|
10844
|
+
} else if (dp && typeof dp == "object") {
|
|
10845
|
+
format2 = dp;
|
|
10846
|
+
dp = rm = null;
|
|
10847
|
+
} else {
|
|
10848
|
+
format2 = FORMAT;
|
|
10849
|
+
}
|
|
10850
|
+
} else if (typeof format2 != "object") {
|
|
10851
|
+
throw Error(bignumberError + "Argument not an object: " + format2);
|
|
10852
|
+
}
|
|
10853
|
+
str = x.toFixed(dp, rm);
|
|
10854
|
+
if (x.c) {
|
|
10855
|
+
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;
|
|
10856
|
+
if (g2) {
|
|
10857
|
+
i = g1;
|
|
10858
|
+
g1 = g2;
|
|
10859
|
+
g2 = i;
|
|
10860
|
+
len -= i;
|
|
10861
|
+
}
|
|
10862
|
+
if (g1 > 0 && len > 0) {
|
|
10863
|
+
i = len % g1 || g1;
|
|
10864
|
+
intPart = intDigits.substr(0, i);
|
|
10865
|
+
for (;i < len; i += g1)
|
|
10866
|
+
intPart += groupSeparator + intDigits.substr(i, g1);
|
|
10867
|
+
if (g2 > 0)
|
|
10868
|
+
intPart += groupSeparator + intDigits.slice(i);
|
|
10869
|
+
if (isNeg)
|
|
10870
|
+
intPart = "-" + intPart;
|
|
10871
|
+
}
|
|
10872
|
+
str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(new RegExp("\\d{" + g2 + "}\\B", "g"), "$&" + (format2.fractionGroupSeparator || "")) : fractionPart) : intPart;
|
|
10873
|
+
}
|
|
10874
|
+
return (format2.prefix || "") + str + (format2.suffix || "");
|
|
10875
|
+
};
|
|
10876
|
+
P.toFraction = function(md) {
|
|
10877
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
|
|
10878
|
+
if (md != null) {
|
|
10879
|
+
n = new BigNumber2(md);
|
|
10880
|
+
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
|
10881
|
+
throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
|
|
10882
|
+
}
|
|
10883
|
+
}
|
|
10884
|
+
if (!xc)
|
|
10885
|
+
return new BigNumber2(x);
|
|
10886
|
+
d = new BigNumber2(ONE);
|
|
10887
|
+
n1 = d0 = new BigNumber2(ONE);
|
|
10888
|
+
d1 = n0 = new BigNumber2(ONE);
|
|
10889
|
+
s = coeffToString(xc);
|
|
10890
|
+
e = d.e = s.length - x.e - 1;
|
|
10891
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
10892
|
+
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
10893
|
+
exp = MAX_EXP;
|
|
10894
|
+
MAX_EXP = 1 / 0;
|
|
10895
|
+
n = new BigNumber2(s);
|
|
10896
|
+
n0.c[0] = 0;
|
|
10897
|
+
for (;; ) {
|
|
10898
|
+
q = div(n, d, 0, 1);
|
|
10899
|
+
d2 = d0.plus(q.times(d1));
|
|
10900
|
+
if (d2.comparedTo(md) == 1)
|
|
10901
|
+
break;
|
|
10902
|
+
d0 = d1;
|
|
10903
|
+
d1 = d2;
|
|
10904
|
+
n1 = n0.plus(q.times(d2 = n1));
|
|
10905
|
+
n0 = d2;
|
|
10906
|
+
d = n.minus(q.times(d2 = d));
|
|
10907
|
+
n = d2;
|
|
10908
|
+
}
|
|
10909
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
10910
|
+
n0 = n0.plus(d2.times(n1));
|
|
10911
|
+
d0 = d0.plus(d2.times(d1));
|
|
10912
|
+
n0.s = n1.s = x.s;
|
|
10913
|
+
e = e * 2;
|
|
10914
|
+
r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
10915
|
+
MAX_EXP = exp;
|
|
10916
|
+
return r;
|
|
10917
|
+
};
|
|
10918
|
+
P.toNumber = function() {
|
|
10919
|
+
return +valueOf(this);
|
|
10920
|
+
};
|
|
10921
|
+
P.toObject = function() {
|
|
10922
|
+
var x = this;
|
|
10923
|
+
return {
|
|
10924
|
+
c: x.c ? x.c.slice() : null,
|
|
10925
|
+
e: x.e,
|
|
10926
|
+
s: x.s
|
|
10927
|
+
};
|
|
10928
|
+
};
|
|
10929
|
+
P.toPrecision = function(sd, rm) {
|
|
10930
|
+
if (sd != null)
|
|
10931
|
+
intCheck(sd, 1, MAX);
|
|
10932
|
+
return format(this, sd, rm, 2);
|
|
10933
|
+
};
|
|
10934
|
+
P.toString = function(b) {
|
|
10935
|
+
var str, n = this, s = n.s, e = n.e;
|
|
10936
|
+
if (e === null) {
|
|
10937
|
+
if (s) {
|
|
10938
|
+
str = "Infinity";
|
|
10939
|
+
if (s < 0)
|
|
10940
|
+
str = "-" + str;
|
|
10941
|
+
} else {
|
|
10942
|
+
str = "NaN";
|
|
10943
|
+
}
|
|
10944
|
+
} else {
|
|
10945
|
+
if (b == null) {
|
|
10946
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
10947
|
+
} else {
|
|
10948
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
10949
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
|
|
10950
|
+
}
|
|
10951
|
+
if (s < 0 && n.c[0])
|
|
10952
|
+
str = "-" + str;
|
|
10953
|
+
}
|
|
10954
|
+
return str;
|
|
10955
|
+
};
|
|
10956
|
+
P.valueOf = P.toJSON = function() {
|
|
10957
|
+
return valueOf(this);
|
|
10958
|
+
};
|
|
10959
|
+
P._isBigNumber = true;
|
|
10960
|
+
if (configObject != null)
|
|
10961
|
+
BigNumber2.set(configObject);
|
|
10962
|
+
return BigNumber2;
|
|
10963
|
+
}
|
|
10964
|
+
function bitFloor(n) {
|
|
10965
|
+
var i = n | 0;
|
|
10966
|
+
return n > 0 || n === i ? i : i - 1;
|
|
10967
|
+
}
|
|
10968
|
+
function coeffToString(a) {
|
|
10969
|
+
var s, z, i = 1, j = a.length, r = a[0] + "";
|
|
10970
|
+
for (;i < j; ) {
|
|
10971
|
+
s = a[i++] + "";
|
|
10972
|
+
z = LOG_BASE - s.length;
|
|
10973
|
+
for (;z--; s = "0" + s)
|
|
10974
|
+
;
|
|
10975
|
+
r += s;
|
|
10976
|
+
}
|
|
10977
|
+
for (j = r.length;r.charCodeAt(--j) === 48; )
|
|
10978
|
+
;
|
|
10979
|
+
return r.slice(0, j + 1 || 1);
|
|
10980
|
+
}
|
|
10981
|
+
function compare(x, y) {
|
|
10982
|
+
var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
10983
|
+
if (!i || !j)
|
|
10984
|
+
return null;
|
|
10985
|
+
a = xc && !xc[0];
|
|
10986
|
+
b = yc && !yc[0];
|
|
10987
|
+
if (a || b)
|
|
10988
|
+
return a ? b ? 0 : -j : i;
|
|
10989
|
+
if (i != j)
|
|
10990
|
+
return i;
|
|
10991
|
+
a = i < 0;
|
|
10992
|
+
b = k == l;
|
|
10993
|
+
if (!xc || !yc)
|
|
10994
|
+
return b ? 0 : !xc ^ a ? 1 : -1;
|
|
10995
|
+
if (!b)
|
|
10996
|
+
return k > l ^ a ? 1 : -1;
|
|
10997
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
10998
|
+
for (i = 0;i < j; i++)
|
|
10999
|
+
if (xc[i] != yc[i])
|
|
11000
|
+
return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
11001
|
+
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
11002
|
+
}
|
|
11003
|
+
function intCheck(n, min, max, name) {
|
|
11004
|
+
if (n < min || n > max || n !== mathfloor(n)) {
|
|
11005
|
+
throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
|
|
11006
|
+
}
|
|
11007
|
+
}
|
|
11008
|
+
function isOdd(n) {
|
|
11009
|
+
var k = n.c.length - 1;
|
|
11010
|
+
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
11011
|
+
}
|
|
11012
|
+
function toExponential(str, e) {
|
|
11013
|
+
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
11014
|
+
}
|
|
11015
|
+
function toFixedPoint(str, e, z) {
|
|
11016
|
+
var len, zs;
|
|
11017
|
+
if (e < 0) {
|
|
11018
|
+
for (zs = z + ".";++e; zs += z)
|
|
11019
|
+
;
|
|
11020
|
+
str = zs + str;
|
|
11021
|
+
} else {
|
|
11022
|
+
len = str.length;
|
|
11023
|
+
if (++e > len) {
|
|
11024
|
+
for (zs = z, e -= len;--e; zs += z)
|
|
11025
|
+
;
|
|
11026
|
+
str += zs;
|
|
11027
|
+
} else if (e < len) {
|
|
11028
|
+
str = str.slice(0, e) + "." + str.slice(e);
|
|
11029
|
+
}
|
|
11030
|
+
}
|
|
11031
|
+
return str;
|
|
11032
|
+
}
|
|
11033
|
+
var bignumber_default = BigNumber;
|
|
11034
|
+
|
|
9529
11035
|
// src/services/recording/campaign.ts
|
|
9530
11036
|
async function checkJoinStatus(baseUrl, accessToken, chainId, address) {
|
|
9531
11037
|
return await requestJson(`${baseUrl}/campaigns/check-join-status`, {
|
|
@@ -9615,11 +11121,13 @@ function createCampaignCommand() {
|
|
|
9615
11121
|
const joined = joinedKeys.has(key);
|
|
9616
11122
|
const tag = joined ? " [JOINED]" : "";
|
|
9617
11123
|
const decimals = c.fund_token_decimals ?? 0;
|
|
9618
|
-
const
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
const
|
|
11124
|
+
const fmt = (v) => {
|
|
11125
|
+
const bn = new bignumber_default(v).dividedBy(new bignumber_default(10).pow(decimals));
|
|
11126
|
+
return bn.toFormat();
|
|
11127
|
+
};
|
|
11128
|
+
const fundAmount = new bignumber_default(c.fund_amount);
|
|
11129
|
+
const balanceNum = new bignumber_default(c.balance);
|
|
11130
|
+
const pct = fundAmount.gt(0) ? balanceNum.dividedBy(fundAmount).times(100).toFixed(1) : "0.0";
|
|
9623
11131
|
printText(` ${c.exchange_name} ${c.symbol} (${c.type})${tag}`);
|
|
9624
11132
|
printText(` chain: ${c.chain_id}`);
|
|
9625
11133
|
printText(` address: ${c.address}`);
|
|
@@ -9649,9 +11157,11 @@ function createCampaignCommand() {
|
|
|
9649
11157
|
printText(` address: ${c.address}`);
|
|
9650
11158
|
printText(` chain: ${c.chain_id}`);
|
|
9651
11159
|
printText(` status: ${c.status}`);
|
|
9652
|
-
|
|
9653
|
-
|
|
9654
|
-
printText(`
|
|
11160
|
+
const showDecimals = c.fund_token_decimals ?? 0;
|
|
11161
|
+
const showFmt = (v) => new bignumber_default(v).dividedBy(new bignumber_default(10).pow(showDecimals)).toFormat();
|
|
11162
|
+
printText(` funded: ${showFmt(c.fund_amount)} ${c.fund_token_symbol}`);
|
|
11163
|
+
printText(` balance: ${showFmt(c.balance)} ${c.fund_token_symbol}`);
|
|
11164
|
+
printText(` paid: ${showFmt(c.amount_paid)} ${c.fund_token_symbol}`);
|
|
9655
11165
|
printText(` start: ${c.start_date}`);
|
|
9656
11166
|
printText(` end: ${c.end_date}`);
|
|
9657
11167
|
printText(` launcher: ${c.launcher}`);
|
|
@@ -9781,127 +11291,14 @@ function createCampaignCommand() {
|
|
|
9781
11291
|
}
|
|
9782
11292
|
|
|
9783
11293
|
// src/cli.ts
|
|
9784
|
-
var BASH_COMPLETION = [
|
|
9785
|
-
"_hufi_completions() {",
|
|
9786
|
-
" local cur prev commands",
|
|
9787
|
-
" COMPREPLY=()",
|
|
9788
|
-
' cur="${COMP_WORDS[COMP_CWORD]}"',
|
|
9789
|
-
' prev="${COMP_WORDS[COMP_CWORD-1]}"',
|
|
9790
|
-
"",
|
|
9791
|
-
' commands="auth exchange campaign completion help"',
|
|
9792
|
-
"",
|
|
9793
|
-
' case "$prev" in',
|
|
9794
|
-
" hufi)",
|
|
9795
|
-
' COMPREPLY=( $(compgen -W "$commands" -- "$cur") )',
|
|
9796
|
-
" return 0",
|
|
9797
|
-
" ;;",
|
|
9798
|
-
" auth)",
|
|
9799
|
-
' COMPREPLY=( $(compgen -W "login generate status help" -- "$cur") )',
|
|
9800
|
-
" return 0",
|
|
9801
|
-
" ;;",
|
|
9802
|
-
" exchange)",
|
|
9803
|
-
' COMPREPLY=( $(compgen -W "register list help" -- "$cur") )',
|
|
9804
|
-
" return 0",
|
|
9805
|
-
" ;;",
|
|
9806
|
-
" campaign)",
|
|
9807
|
-
' COMPREPLY=( $(compgen -W "list get joined status join progress leaderboard help" -- "$cur") )',
|
|
9808
|
-
" return 0",
|
|
9809
|
-
" ;;",
|
|
9810
|
-
" esac",
|
|
9811
|
-
"",
|
|
9812
|
-
' COMPREPLY=( $(compgen -W "--help --version --json" -- "$cur") )',
|
|
9813
|
-
" return 0",
|
|
9814
|
-
"}",
|
|
9815
|
-
"",
|
|
9816
|
-
"complete -F _hufi_completions hufi"
|
|
9817
|
-
].join(`
|
|
9818
|
-
`);
|
|
9819
|
-
var ZSH_COMPLETION = [
|
|
9820
|
-
"#compdef hufi",
|
|
9821
|
-
"",
|
|
9822
|
-
"_hufi() {",
|
|
9823
|
-
" local -a commands",
|
|
9824
|
-
" commands=(",
|
|
9825
|
-
" 'auth:Authentication commands'",
|
|
9826
|
-
" 'exchange:Exchange API key management'",
|
|
9827
|
-
" 'campaign:Campaign management'",
|
|
9828
|
-
" 'completion:Generate shell completion script'",
|
|
9829
|
-
" 'help:Display help'",
|
|
9830
|
-
" )",
|
|
9831
|
-
"",
|
|
9832
|
-
" _arguments -C \\",
|
|
9833
|
-
" '1:command:->command' \\",
|
|
9834
|
-
" '*::arg:->args'",
|
|
9835
|
-
"",
|
|
9836
|
-
" case $state in",
|
|
9837
|
-
" command)",
|
|
9838
|
-
" _describe 'command' commands",
|
|
9839
|
-
" ;;",
|
|
9840
|
-
" args)",
|
|
9841
|
-
" case ${words[1]} in",
|
|
9842
|
-
" auth)",
|
|
9843
|
-
" _arguments \\",
|
|
9844
|
-
" '1:subcommand:(login generate status help)'",
|
|
9845
|
-
" ;;",
|
|
9846
|
-
" exchange)",
|
|
9847
|
-
" _arguments \\",
|
|
9848
|
-
" '1:subcommand:(register list help)'",
|
|
9849
|
-
" ;;",
|
|
9850
|
-
" campaign)",
|
|
9851
|
-
" _arguments \\",
|
|
9852
|
-
" '1:subcommand:(list get joined status join progress leaderboard help)'",
|
|
9853
|
-
" ;;",
|
|
9854
|
-
" esac",
|
|
9855
|
-
" ;;",
|
|
9856
|
-
" esac",
|
|
9857
|
-
"}",
|
|
9858
|
-
"",
|
|
9859
|
-
'_hufi "$@"'
|
|
9860
|
-
].join(`
|
|
9861
|
-
`);
|
|
9862
|
-
var FISH_COMPLETION = [
|
|
9863
|
-
"# hufi completions for fish",
|
|
9864
|
-
"complete -c hufi -f",
|
|
9865
|
-
"",
|
|
9866
|
-
"# Top-level commands",
|
|
9867
|
-
"complete -c hufi -n '__fish_use_subcommand' -a auth -d 'Authentication commands'",
|
|
9868
|
-
"complete -c hufi -n '__fish_use_subcommand' -a exchange -d 'Exchange API key management'",
|
|
9869
|
-
"complete -c hufi -n '__fish_use_subcommand' -a campaign -d 'Campaign management'",
|
|
9870
|
-
"complete -c hufi -n '__fish_use_subcommand' -a completion -d 'Generate shell completion script'",
|
|
9871
|
-
"",
|
|
9872
|
-
"# auth subcommands",
|
|
9873
|
-
"complete -c hufi -n '__fish_seen_subcommand_from auth' -a login -d 'Authenticate with private key'",
|
|
9874
|
-
"complete -c hufi -n '__fish_seen_subcommand_from auth' -a generate -d 'Generate a new wallet'",
|
|
9875
|
-
"complete -c hufi -n '__fish_seen_subcommand_from auth' -a status -d 'Show auth status'",
|
|
9876
|
-
"",
|
|
9877
|
-
"# exchange subcommands",
|
|
9878
|
-
"complete -c hufi -n '__fish_seen_subcommand_from exchange' -a register -d 'Register exchange API key'",
|
|
9879
|
-
"complete -c hufi -n '__fish_seen_subcommand_from exchange' -a list -d 'List exchange API keys'",
|
|
9880
|
-
"",
|
|
9881
|
-
"# campaign subcommands",
|
|
9882
|
-
"complete -c hufi -n '__fish_seen_subcommand_from campaign' -a list -d 'List available campaigns'",
|
|
9883
|
-
"complete -c hufi -n '__fish_seen_subcommand_from campaign' -a get -d 'Get campaign details'",
|
|
9884
|
-
"complete -c hufi -n '__fish_seen_subcommand_from campaign' -a joined -d 'List joined campaigns'",
|
|
9885
|
-
"complete -c hufi -n '__fish_seen_subcommand_from campaign' -a status -d 'Check join status'",
|
|
9886
|
-
"complete -c hufi -n '__fish_seen_subcommand_from campaign' -a join -d 'Join a campaign'",
|
|
9887
|
-
"complete -c hufi -n '__fish_seen_subcommand_from campaign' -a progress -d 'Check your progress'",
|
|
9888
|
-
"complete -c hufi -n '__fish_seen_subcommand_from campaign' -a leaderboard -d 'View leaderboard'",
|
|
9889
|
-
"",
|
|
9890
|
-
"# Global options",
|
|
9891
|
-
"complete -c hufi -l help -d 'Show help'",
|
|
9892
|
-
"complete -c hufi -l version -d 'Show version'",
|
|
9893
|
-
"complete -c hufi -l json -d 'Output as JSON'"
|
|
9894
|
-
].join(`
|
|
9895
|
-
`);
|
|
9896
11294
|
var program2 = new Command;
|
|
9897
|
-
program2.name("hufi").description("CLI tool for hu.fi DeFi platform").version("0.
|
|
9898
|
-
|
|
9899
|
-
if (opts.
|
|
9900
|
-
|
|
9901
|
-
}
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
console.log(BASH_COMPLETION);
|
|
11295
|
+
program2.name("hufi").description("CLI tool for hu.fi DeFi platform").version("0.5.3").option("--config-file <path>", "Custom config file path (default: ~/.hufi-cli/config.json)").option("--key-file <path>", "Custom key file path (default: ~/.hufi-cli/key.json)").hook("preAction", (thisCommand) => {
|
|
11296
|
+
const opts = thisCommand.opts();
|
|
11297
|
+
if (opts.configFile) {
|
|
11298
|
+
setConfigFile(opts.configFile);
|
|
11299
|
+
}
|
|
11300
|
+
if (opts.keyFile) {
|
|
11301
|
+
setKeyFile(opts.keyFile);
|
|
9905
11302
|
}
|
|
9906
11303
|
});
|
|
9907
11304
|
program2.addCommand(createAuthCommand());
|