hak-saucerswap-plugin 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -3
- package/dist/index.cjs +987 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +986 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -117,6 +117,30 @@ var createSaucerSwapClient = (options) => {
|
|
|
117
117
|
return new SaucerSwapClient(options);
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
+
// src/networks.ts
|
|
121
|
+
var SAUCERSWAP_MAINNET = {
|
|
122
|
+
routerContractId: "0.0.3045981",
|
|
123
|
+
routerV2ContractId: "0.0.3949434",
|
|
124
|
+
wrappedHbarTokenId: "0.0.1456986",
|
|
125
|
+
tokenAliases: {
|
|
126
|
+
SAUCE: "0.0.731861",
|
|
127
|
+
XSAUCE: "0.0.1460200"
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var SAUCERSWAP_TESTNET = {
|
|
131
|
+
routerContractId: "0.0.19264",
|
|
132
|
+
routerV2ContractId: "0.0.1414040",
|
|
133
|
+
wrappedHbarTokenId: "0.0.15058",
|
|
134
|
+
tokenAliases: {
|
|
135
|
+
SAUCE: "0.0.1183558",
|
|
136
|
+
XSAUCE: "0.0.1418651"
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var NETWORK_DEFAULTS = {
|
|
140
|
+
mainnet: SAUCERSWAP_MAINNET,
|
|
141
|
+
testnet: SAUCERSWAP_TESTNET
|
|
142
|
+
};
|
|
143
|
+
|
|
120
144
|
// src/config.ts
|
|
121
145
|
var DEFAULT_CONFIG = {
|
|
122
146
|
baseUrl: "https://api.saucerswap.finance",
|
|
@@ -157,6 +181,12 @@ var readPoolVersion = (value) => {
|
|
|
157
181
|
}
|
|
158
182
|
return void 0;
|
|
159
183
|
};
|
|
184
|
+
var readNetwork = (value) => {
|
|
185
|
+
if (value === "mainnet" || value === "testnet") {
|
|
186
|
+
return value;
|
|
187
|
+
}
|
|
188
|
+
return void 0;
|
|
189
|
+
};
|
|
160
190
|
var readContextConfig = (context) => {
|
|
161
191
|
if (!context || typeof context !== "object") {
|
|
162
192
|
return {};
|
|
@@ -169,6 +199,8 @@ var readContextConfig = (context) => {
|
|
|
169
199
|
};
|
|
170
200
|
var resolveSaucerSwapConfig = (context) => {
|
|
171
201
|
const ctxConfig = readContextConfig(context);
|
|
202
|
+
const network = ctxConfig.network ?? readNetwork(process.env.SAUCERSWAP_NETWORK);
|
|
203
|
+
const networkDefaults = network ? NETWORK_DEFAULTS[network] ?? {} : {};
|
|
172
204
|
const envAliases = readTokenAliases(process.env.SAUCERSWAP_TOKEN_ALIASES);
|
|
173
205
|
const envDefaultVersion = readPoolVersion(process.env.SAUCERSWAP_DEFAULT_POOL_VERSION);
|
|
174
206
|
return {
|
|
@@ -178,10 +210,12 @@ var resolveSaucerSwapConfig = (context) => {
|
|
|
178
210
|
timeoutMs: ctxConfig.timeoutMs ?? toNumber(process.env.SAUCERSWAP_TIMEOUT_MS, DEFAULT_CONFIG.timeoutMs),
|
|
179
211
|
retries: ctxConfig.retries ?? toNumber(process.env.SAUCERSWAP_RETRIES, DEFAULT_CONFIG.retries),
|
|
180
212
|
apiKey: ctxConfig.apiKey ?? process.env.SAUCERSWAP_API_KEY,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
213
|
+
network,
|
|
214
|
+
routerContractId: ctxConfig.routerContractId ?? process.env.SAUCERSWAP_ROUTER_CONTRACT_ID ?? networkDefaults.routerContractId,
|
|
215
|
+
routerV2ContractId: ctxConfig.routerV2ContractId ?? process.env.SAUCERSWAP_ROUTER_V2_CONTRACT_ID ?? networkDefaults.routerV2ContractId,
|
|
216
|
+
wrappedHbarTokenId: ctxConfig.wrappedHbarTokenId ?? process.env.SAUCERSWAP_WRAPPED_HBAR_TOKEN_ID ?? networkDefaults.wrappedHbarTokenId,
|
|
184
217
|
tokenAliases: {
|
|
218
|
+
...networkDefaults.tokenAliases ?? {},
|
|
185
219
|
...envAliases,
|
|
186
220
|
...ctxConfig.tokenAliases ?? {}
|
|
187
221
|
},
|
|
@@ -281,7 +315,929 @@ var contractIdFromString = (contractId) => {
|
|
|
281
315
|
return ContractId.fromString(contractId);
|
|
282
316
|
};
|
|
283
317
|
|
|
318
|
+
// node_modules/long/index.js
|
|
319
|
+
var wasm = null;
|
|
320
|
+
try {
|
|
321
|
+
wasm = new WebAssembly.Instance(
|
|
322
|
+
new WebAssembly.Module(
|
|
323
|
+
new Uint8Array([
|
|
324
|
+
// \0asm
|
|
325
|
+
0,
|
|
326
|
+
97,
|
|
327
|
+
115,
|
|
328
|
+
109,
|
|
329
|
+
// version 1
|
|
330
|
+
1,
|
|
331
|
+
0,
|
|
332
|
+
0,
|
|
333
|
+
0,
|
|
334
|
+
// section "type"
|
|
335
|
+
1,
|
|
336
|
+
13,
|
|
337
|
+
2,
|
|
338
|
+
// 0, () => i32
|
|
339
|
+
96,
|
|
340
|
+
0,
|
|
341
|
+
1,
|
|
342
|
+
127,
|
|
343
|
+
// 1, (i32, i32, i32, i32) => i32
|
|
344
|
+
96,
|
|
345
|
+
4,
|
|
346
|
+
127,
|
|
347
|
+
127,
|
|
348
|
+
127,
|
|
349
|
+
127,
|
|
350
|
+
1,
|
|
351
|
+
127,
|
|
352
|
+
// section "function"
|
|
353
|
+
3,
|
|
354
|
+
7,
|
|
355
|
+
6,
|
|
356
|
+
// 0, type 0
|
|
357
|
+
0,
|
|
358
|
+
// 1, type 1
|
|
359
|
+
1,
|
|
360
|
+
// 2, type 1
|
|
361
|
+
1,
|
|
362
|
+
// 3, type 1
|
|
363
|
+
1,
|
|
364
|
+
// 4, type 1
|
|
365
|
+
1,
|
|
366
|
+
// 5, type 1
|
|
367
|
+
1,
|
|
368
|
+
// section "global"
|
|
369
|
+
6,
|
|
370
|
+
6,
|
|
371
|
+
1,
|
|
372
|
+
// 0, "high", mutable i32
|
|
373
|
+
127,
|
|
374
|
+
1,
|
|
375
|
+
65,
|
|
376
|
+
0,
|
|
377
|
+
11,
|
|
378
|
+
// section "export"
|
|
379
|
+
7,
|
|
380
|
+
50,
|
|
381
|
+
6,
|
|
382
|
+
// 0, "mul"
|
|
383
|
+
3,
|
|
384
|
+
109,
|
|
385
|
+
117,
|
|
386
|
+
108,
|
|
387
|
+
0,
|
|
388
|
+
1,
|
|
389
|
+
// 1, "div_s"
|
|
390
|
+
5,
|
|
391
|
+
100,
|
|
392
|
+
105,
|
|
393
|
+
118,
|
|
394
|
+
95,
|
|
395
|
+
115,
|
|
396
|
+
0,
|
|
397
|
+
2,
|
|
398
|
+
// 2, "div_u"
|
|
399
|
+
5,
|
|
400
|
+
100,
|
|
401
|
+
105,
|
|
402
|
+
118,
|
|
403
|
+
95,
|
|
404
|
+
117,
|
|
405
|
+
0,
|
|
406
|
+
3,
|
|
407
|
+
// 3, "rem_s"
|
|
408
|
+
5,
|
|
409
|
+
114,
|
|
410
|
+
101,
|
|
411
|
+
109,
|
|
412
|
+
95,
|
|
413
|
+
115,
|
|
414
|
+
0,
|
|
415
|
+
4,
|
|
416
|
+
// 4, "rem_u"
|
|
417
|
+
5,
|
|
418
|
+
114,
|
|
419
|
+
101,
|
|
420
|
+
109,
|
|
421
|
+
95,
|
|
422
|
+
117,
|
|
423
|
+
0,
|
|
424
|
+
5,
|
|
425
|
+
// 5, "get_high"
|
|
426
|
+
8,
|
|
427
|
+
103,
|
|
428
|
+
101,
|
|
429
|
+
116,
|
|
430
|
+
95,
|
|
431
|
+
104,
|
|
432
|
+
105,
|
|
433
|
+
103,
|
|
434
|
+
104,
|
|
435
|
+
0,
|
|
436
|
+
0,
|
|
437
|
+
// section "code"
|
|
438
|
+
10,
|
|
439
|
+
191,
|
|
440
|
+
1,
|
|
441
|
+
6,
|
|
442
|
+
// 0, "get_high"
|
|
443
|
+
4,
|
|
444
|
+
0,
|
|
445
|
+
35,
|
|
446
|
+
0,
|
|
447
|
+
11,
|
|
448
|
+
// 1, "mul"
|
|
449
|
+
36,
|
|
450
|
+
1,
|
|
451
|
+
1,
|
|
452
|
+
126,
|
|
453
|
+
32,
|
|
454
|
+
0,
|
|
455
|
+
173,
|
|
456
|
+
32,
|
|
457
|
+
1,
|
|
458
|
+
173,
|
|
459
|
+
66,
|
|
460
|
+
32,
|
|
461
|
+
134,
|
|
462
|
+
132,
|
|
463
|
+
32,
|
|
464
|
+
2,
|
|
465
|
+
173,
|
|
466
|
+
32,
|
|
467
|
+
3,
|
|
468
|
+
173,
|
|
469
|
+
66,
|
|
470
|
+
32,
|
|
471
|
+
134,
|
|
472
|
+
132,
|
|
473
|
+
126,
|
|
474
|
+
34,
|
|
475
|
+
4,
|
|
476
|
+
66,
|
|
477
|
+
32,
|
|
478
|
+
135,
|
|
479
|
+
167,
|
|
480
|
+
36,
|
|
481
|
+
0,
|
|
482
|
+
32,
|
|
483
|
+
4,
|
|
484
|
+
167,
|
|
485
|
+
11,
|
|
486
|
+
// 2, "div_s"
|
|
487
|
+
36,
|
|
488
|
+
1,
|
|
489
|
+
1,
|
|
490
|
+
126,
|
|
491
|
+
32,
|
|
492
|
+
0,
|
|
493
|
+
173,
|
|
494
|
+
32,
|
|
495
|
+
1,
|
|
496
|
+
173,
|
|
497
|
+
66,
|
|
498
|
+
32,
|
|
499
|
+
134,
|
|
500
|
+
132,
|
|
501
|
+
32,
|
|
502
|
+
2,
|
|
503
|
+
173,
|
|
504
|
+
32,
|
|
505
|
+
3,
|
|
506
|
+
173,
|
|
507
|
+
66,
|
|
508
|
+
32,
|
|
509
|
+
134,
|
|
510
|
+
132,
|
|
511
|
+
127,
|
|
512
|
+
34,
|
|
513
|
+
4,
|
|
514
|
+
66,
|
|
515
|
+
32,
|
|
516
|
+
135,
|
|
517
|
+
167,
|
|
518
|
+
36,
|
|
519
|
+
0,
|
|
520
|
+
32,
|
|
521
|
+
4,
|
|
522
|
+
167,
|
|
523
|
+
11,
|
|
524
|
+
// 3, "div_u"
|
|
525
|
+
36,
|
|
526
|
+
1,
|
|
527
|
+
1,
|
|
528
|
+
126,
|
|
529
|
+
32,
|
|
530
|
+
0,
|
|
531
|
+
173,
|
|
532
|
+
32,
|
|
533
|
+
1,
|
|
534
|
+
173,
|
|
535
|
+
66,
|
|
536
|
+
32,
|
|
537
|
+
134,
|
|
538
|
+
132,
|
|
539
|
+
32,
|
|
540
|
+
2,
|
|
541
|
+
173,
|
|
542
|
+
32,
|
|
543
|
+
3,
|
|
544
|
+
173,
|
|
545
|
+
66,
|
|
546
|
+
32,
|
|
547
|
+
134,
|
|
548
|
+
132,
|
|
549
|
+
128,
|
|
550
|
+
34,
|
|
551
|
+
4,
|
|
552
|
+
66,
|
|
553
|
+
32,
|
|
554
|
+
135,
|
|
555
|
+
167,
|
|
556
|
+
36,
|
|
557
|
+
0,
|
|
558
|
+
32,
|
|
559
|
+
4,
|
|
560
|
+
167,
|
|
561
|
+
11,
|
|
562
|
+
// 4, "rem_s"
|
|
563
|
+
36,
|
|
564
|
+
1,
|
|
565
|
+
1,
|
|
566
|
+
126,
|
|
567
|
+
32,
|
|
568
|
+
0,
|
|
569
|
+
173,
|
|
570
|
+
32,
|
|
571
|
+
1,
|
|
572
|
+
173,
|
|
573
|
+
66,
|
|
574
|
+
32,
|
|
575
|
+
134,
|
|
576
|
+
132,
|
|
577
|
+
32,
|
|
578
|
+
2,
|
|
579
|
+
173,
|
|
580
|
+
32,
|
|
581
|
+
3,
|
|
582
|
+
173,
|
|
583
|
+
66,
|
|
584
|
+
32,
|
|
585
|
+
134,
|
|
586
|
+
132,
|
|
587
|
+
129,
|
|
588
|
+
34,
|
|
589
|
+
4,
|
|
590
|
+
66,
|
|
591
|
+
32,
|
|
592
|
+
135,
|
|
593
|
+
167,
|
|
594
|
+
36,
|
|
595
|
+
0,
|
|
596
|
+
32,
|
|
597
|
+
4,
|
|
598
|
+
167,
|
|
599
|
+
11,
|
|
600
|
+
// 5, "rem_u"
|
|
601
|
+
36,
|
|
602
|
+
1,
|
|
603
|
+
1,
|
|
604
|
+
126,
|
|
605
|
+
32,
|
|
606
|
+
0,
|
|
607
|
+
173,
|
|
608
|
+
32,
|
|
609
|
+
1,
|
|
610
|
+
173,
|
|
611
|
+
66,
|
|
612
|
+
32,
|
|
613
|
+
134,
|
|
614
|
+
132,
|
|
615
|
+
32,
|
|
616
|
+
2,
|
|
617
|
+
173,
|
|
618
|
+
32,
|
|
619
|
+
3,
|
|
620
|
+
173,
|
|
621
|
+
66,
|
|
622
|
+
32,
|
|
623
|
+
134,
|
|
624
|
+
132,
|
|
625
|
+
130,
|
|
626
|
+
34,
|
|
627
|
+
4,
|
|
628
|
+
66,
|
|
629
|
+
32,
|
|
630
|
+
135,
|
|
631
|
+
167,
|
|
632
|
+
36,
|
|
633
|
+
0,
|
|
634
|
+
32,
|
|
635
|
+
4,
|
|
636
|
+
167,
|
|
637
|
+
11
|
|
638
|
+
])
|
|
639
|
+
),
|
|
640
|
+
{}
|
|
641
|
+
).exports;
|
|
642
|
+
} catch {
|
|
643
|
+
}
|
|
644
|
+
function Long(low, high, unsigned) {
|
|
645
|
+
this.low = low | 0;
|
|
646
|
+
this.high = high | 0;
|
|
647
|
+
this.unsigned = !!unsigned;
|
|
648
|
+
}
|
|
649
|
+
Long.prototype.__isLong__;
|
|
650
|
+
Object.defineProperty(Long.prototype, "__isLong__", { value: true });
|
|
651
|
+
function isLong(obj) {
|
|
652
|
+
return (obj && obj["__isLong__"]) === true;
|
|
653
|
+
}
|
|
654
|
+
function ctz32(value) {
|
|
655
|
+
var c = Math.clz32(value & -value);
|
|
656
|
+
return value ? 31 - c : c;
|
|
657
|
+
}
|
|
658
|
+
Long.isLong = isLong;
|
|
659
|
+
var INT_CACHE = {};
|
|
660
|
+
var UINT_CACHE = {};
|
|
661
|
+
function fromInt(value, unsigned) {
|
|
662
|
+
var obj, cachedObj, cache;
|
|
663
|
+
if (unsigned) {
|
|
664
|
+
value >>>= 0;
|
|
665
|
+
if (cache = 0 <= value && value < 256) {
|
|
666
|
+
cachedObj = UINT_CACHE[value];
|
|
667
|
+
if (cachedObj) return cachedObj;
|
|
668
|
+
}
|
|
669
|
+
obj = fromBits(value, 0, true);
|
|
670
|
+
if (cache) UINT_CACHE[value] = obj;
|
|
671
|
+
return obj;
|
|
672
|
+
} else {
|
|
673
|
+
value |= 0;
|
|
674
|
+
if (cache = -128 <= value && value < 128) {
|
|
675
|
+
cachedObj = INT_CACHE[value];
|
|
676
|
+
if (cachedObj) return cachedObj;
|
|
677
|
+
}
|
|
678
|
+
obj = fromBits(value, value < 0 ? -1 : 0, false);
|
|
679
|
+
if (cache) INT_CACHE[value] = obj;
|
|
680
|
+
return obj;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
Long.fromInt = fromInt;
|
|
684
|
+
function fromNumber(value, unsigned) {
|
|
685
|
+
if (isNaN(value)) return unsigned ? UZERO : ZERO;
|
|
686
|
+
if (unsigned) {
|
|
687
|
+
if (value < 0) return UZERO;
|
|
688
|
+
if (value >= TWO_PWR_64_DBL) return MAX_UNSIGNED_VALUE;
|
|
689
|
+
} else {
|
|
690
|
+
if (value <= -TWO_PWR_63_DBL) return MIN_VALUE;
|
|
691
|
+
if (value + 1 >= TWO_PWR_63_DBL) return MAX_VALUE;
|
|
692
|
+
}
|
|
693
|
+
if (value < 0) return fromNumber(-value, unsigned).neg();
|
|
694
|
+
return fromBits(
|
|
695
|
+
value % TWO_PWR_32_DBL | 0,
|
|
696
|
+
value / TWO_PWR_32_DBL | 0,
|
|
697
|
+
unsigned
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
Long.fromNumber = fromNumber;
|
|
701
|
+
function fromBits(lowBits, highBits, unsigned) {
|
|
702
|
+
return new Long(lowBits, highBits, unsigned);
|
|
703
|
+
}
|
|
704
|
+
Long.fromBits = fromBits;
|
|
705
|
+
var pow_dbl = Math.pow;
|
|
706
|
+
function fromString(str, unsigned, radix) {
|
|
707
|
+
if (str.length === 0) throw Error("empty string");
|
|
708
|
+
if (typeof unsigned === "number") {
|
|
709
|
+
radix = unsigned;
|
|
710
|
+
unsigned = false;
|
|
711
|
+
} else {
|
|
712
|
+
unsigned = !!unsigned;
|
|
713
|
+
}
|
|
714
|
+
if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
|
|
715
|
+
return unsigned ? UZERO : ZERO;
|
|
716
|
+
radix = radix || 10;
|
|
717
|
+
if (radix < 2 || 36 < radix) throw RangeError("radix");
|
|
718
|
+
var p;
|
|
719
|
+
if ((p = str.indexOf("-")) > 0) throw Error("interior hyphen");
|
|
720
|
+
else if (p === 0) {
|
|
721
|
+
return fromString(str.substring(1), unsigned, radix).neg();
|
|
722
|
+
}
|
|
723
|
+
var radixToPower = fromNumber(pow_dbl(radix, 8));
|
|
724
|
+
var result = ZERO;
|
|
725
|
+
for (var i = 0; i < str.length; i += 8) {
|
|
726
|
+
var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
|
|
727
|
+
if (size < 8) {
|
|
728
|
+
var power = fromNumber(pow_dbl(radix, size));
|
|
729
|
+
result = result.mul(power).add(fromNumber(value));
|
|
730
|
+
} else {
|
|
731
|
+
result = result.mul(radixToPower);
|
|
732
|
+
result = result.add(fromNumber(value));
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
result.unsigned = unsigned;
|
|
736
|
+
return result;
|
|
737
|
+
}
|
|
738
|
+
Long.fromString = fromString;
|
|
739
|
+
function fromValue(val, unsigned) {
|
|
740
|
+
if (typeof val === "number") return fromNumber(val, unsigned);
|
|
741
|
+
if (typeof val === "string") return fromString(val, unsigned);
|
|
742
|
+
return fromBits(
|
|
743
|
+
val.low,
|
|
744
|
+
val.high,
|
|
745
|
+
typeof unsigned === "boolean" ? unsigned : val.unsigned
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
Long.fromValue = fromValue;
|
|
749
|
+
var TWO_PWR_16_DBL = 1 << 16;
|
|
750
|
+
var TWO_PWR_24_DBL = 1 << 24;
|
|
751
|
+
var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
|
|
752
|
+
var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
|
|
753
|
+
var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
|
|
754
|
+
var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
|
|
755
|
+
var ZERO = fromInt(0);
|
|
756
|
+
Long.ZERO = ZERO;
|
|
757
|
+
var UZERO = fromInt(0, true);
|
|
758
|
+
Long.UZERO = UZERO;
|
|
759
|
+
var ONE = fromInt(1);
|
|
760
|
+
Long.ONE = ONE;
|
|
761
|
+
var UONE = fromInt(1, true);
|
|
762
|
+
Long.UONE = UONE;
|
|
763
|
+
var NEG_ONE = fromInt(-1);
|
|
764
|
+
Long.NEG_ONE = NEG_ONE;
|
|
765
|
+
var MAX_VALUE = fromBits(4294967295 | 0, 2147483647 | 0, false);
|
|
766
|
+
Long.MAX_VALUE = MAX_VALUE;
|
|
767
|
+
var MAX_UNSIGNED_VALUE = fromBits(4294967295 | 0, 4294967295 | 0, true);
|
|
768
|
+
Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
|
|
769
|
+
var MIN_VALUE = fromBits(0, 2147483648 | 0, false);
|
|
770
|
+
Long.MIN_VALUE = MIN_VALUE;
|
|
771
|
+
var LongPrototype = Long.prototype;
|
|
772
|
+
LongPrototype.toInt = function toInt() {
|
|
773
|
+
return this.unsigned ? this.low >>> 0 : this.low;
|
|
774
|
+
};
|
|
775
|
+
LongPrototype.toNumber = function toNumber2() {
|
|
776
|
+
if (this.unsigned)
|
|
777
|
+
return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
|
|
778
|
+
return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
|
|
779
|
+
};
|
|
780
|
+
LongPrototype.toString = function toString(radix) {
|
|
781
|
+
radix = radix || 10;
|
|
782
|
+
if (radix < 2 || 36 < radix) throw RangeError("radix");
|
|
783
|
+
if (this.isZero()) return "0";
|
|
784
|
+
if (this.isNegative()) {
|
|
785
|
+
if (this.eq(MIN_VALUE)) {
|
|
786
|
+
var radixLong = fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
|
|
787
|
+
return div.toString(radix) + rem1.toInt().toString(radix);
|
|
788
|
+
} else return "-" + this.neg().toString(radix);
|
|
789
|
+
}
|
|
790
|
+
var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), rem = this;
|
|
791
|
+
var result = "";
|
|
792
|
+
while (true) {
|
|
793
|
+
var remDiv = rem.div(radixToPower), intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, digits = intval.toString(radix);
|
|
794
|
+
rem = remDiv;
|
|
795
|
+
if (rem.isZero()) return digits + result;
|
|
796
|
+
else {
|
|
797
|
+
while (digits.length < 6) digits = "0" + digits;
|
|
798
|
+
result = "" + digits + result;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
LongPrototype.getHighBits = function getHighBits() {
|
|
803
|
+
return this.high;
|
|
804
|
+
};
|
|
805
|
+
LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
|
|
806
|
+
return this.high >>> 0;
|
|
807
|
+
};
|
|
808
|
+
LongPrototype.getLowBits = function getLowBits() {
|
|
809
|
+
return this.low;
|
|
810
|
+
};
|
|
811
|
+
LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
|
|
812
|
+
return this.low >>> 0;
|
|
813
|
+
};
|
|
814
|
+
LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
|
|
815
|
+
if (this.isNegative())
|
|
816
|
+
return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
|
|
817
|
+
var val = this.high != 0 ? this.high : this.low;
|
|
818
|
+
for (var bit = 31; bit > 0; bit--) if ((val & 1 << bit) != 0) break;
|
|
819
|
+
return this.high != 0 ? bit + 33 : bit + 1;
|
|
820
|
+
};
|
|
821
|
+
LongPrototype.isSafeInteger = function isSafeInteger() {
|
|
822
|
+
var top11Bits = this.high >> 21;
|
|
823
|
+
if (!top11Bits) return true;
|
|
824
|
+
if (this.unsigned) return false;
|
|
825
|
+
return top11Bits === -1 && !(this.low === 0 && this.high === -2097152);
|
|
826
|
+
};
|
|
827
|
+
LongPrototype.isZero = function isZero() {
|
|
828
|
+
return this.high === 0 && this.low === 0;
|
|
829
|
+
};
|
|
830
|
+
LongPrototype.eqz = LongPrototype.isZero;
|
|
831
|
+
LongPrototype.isNegative = function isNegative() {
|
|
832
|
+
return !this.unsigned && this.high < 0;
|
|
833
|
+
};
|
|
834
|
+
LongPrototype.isPositive = function isPositive() {
|
|
835
|
+
return this.unsigned || this.high >= 0;
|
|
836
|
+
};
|
|
837
|
+
LongPrototype.isOdd = function isOdd() {
|
|
838
|
+
return (this.low & 1) === 1;
|
|
839
|
+
};
|
|
840
|
+
LongPrototype.isEven = function isEven() {
|
|
841
|
+
return (this.low & 1) === 0;
|
|
842
|
+
};
|
|
843
|
+
LongPrototype.equals = function equals(other) {
|
|
844
|
+
if (!isLong(other)) other = fromValue(other);
|
|
845
|
+
if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
|
|
846
|
+
return false;
|
|
847
|
+
return this.high === other.high && this.low === other.low;
|
|
848
|
+
};
|
|
849
|
+
LongPrototype.eq = LongPrototype.equals;
|
|
850
|
+
LongPrototype.notEquals = function notEquals(other) {
|
|
851
|
+
return !this.eq(
|
|
852
|
+
/* validates */
|
|
853
|
+
other
|
|
854
|
+
);
|
|
855
|
+
};
|
|
856
|
+
LongPrototype.neq = LongPrototype.notEquals;
|
|
857
|
+
LongPrototype.ne = LongPrototype.notEquals;
|
|
858
|
+
LongPrototype.lessThan = function lessThan(other) {
|
|
859
|
+
return this.comp(
|
|
860
|
+
/* validates */
|
|
861
|
+
other
|
|
862
|
+
) < 0;
|
|
863
|
+
};
|
|
864
|
+
LongPrototype.lt = LongPrototype.lessThan;
|
|
865
|
+
LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
|
|
866
|
+
return this.comp(
|
|
867
|
+
/* validates */
|
|
868
|
+
other
|
|
869
|
+
) <= 0;
|
|
870
|
+
};
|
|
871
|
+
LongPrototype.lte = LongPrototype.lessThanOrEqual;
|
|
872
|
+
LongPrototype.le = LongPrototype.lessThanOrEqual;
|
|
873
|
+
LongPrototype.greaterThan = function greaterThan(other) {
|
|
874
|
+
return this.comp(
|
|
875
|
+
/* validates */
|
|
876
|
+
other
|
|
877
|
+
) > 0;
|
|
878
|
+
};
|
|
879
|
+
LongPrototype.gt = LongPrototype.greaterThan;
|
|
880
|
+
LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
|
|
881
|
+
return this.comp(
|
|
882
|
+
/* validates */
|
|
883
|
+
other
|
|
884
|
+
) >= 0;
|
|
885
|
+
};
|
|
886
|
+
LongPrototype.gte = LongPrototype.greaterThanOrEqual;
|
|
887
|
+
LongPrototype.ge = LongPrototype.greaterThanOrEqual;
|
|
888
|
+
LongPrototype.compare = function compare(other) {
|
|
889
|
+
if (!isLong(other)) other = fromValue(other);
|
|
890
|
+
if (this.eq(other)) return 0;
|
|
891
|
+
var thisNeg = this.isNegative(), otherNeg = other.isNegative();
|
|
892
|
+
if (thisNeg && !otherNeg) return -1;
|
|
893
|
+
if (!thisNeg && otherNeg) return 1;
|
|
894
|
+
if (!this.unsigned) return this.sub(other).isNegative() ? -1 : 1;
|
|
895
|
+
return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
|
|
896
|
+
};
|
|
897
|
+
LongPrototype.comp = LongPrototype.compare;
|
|
898
|
+
LongPrototype.negate = function negate() {
|
|
899
|
+
if (!this.unsigned && this.eq(MIN_VALUE)) return MIN_VALUE;
|
|
900
|
+
return this.not().add(ONE);
|
|
901
|
+
};
|
|
902
|
+
LongPrototype.neg = LongPrototype.negate;
|
|
903
|
+
LongPrototype.add = function add(addend) {
|
|
904
|
+
if (!isLong(addend)) addend = fromValue(addend);
|
|
905
|
+
var a48 = this.high >>> 16;
|
|
906
|
+
var a32 = this.high & 65535;
|
|
907
|
+
var a16 = this.low >>> 16;
|
|
908
|
+
var a00 = this.low & 65535;
|
|
909
|
+
var b48 = addend.high >>> 16;
|
|
910
|
+
var b32 = addend.high & 65535;
|
|
911
|
+
var b16 = addend.low >>> 16;
|
|
912
|
+
var b00 = addend.low & 65535;
|
|
913
|
+
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
|
914
|
+
c00 += a00 + b00;
|
|
915
|
+
c16 += c00 >>> 16;
|
|
916
|
+
c00 &= 65535;
|
|
917
|
+
c16 += a16 + b16;
|
|
918
|
+
c32 += c16 >>> 16;
|
|
919
|
+
c16 &= 65535;
|
|
920
|
+
c32 += a32 + b32;
|
|
921
|
+
c48 += c32 >>> 16;
|
|
922
|
+
c32 &= 65535;
|
|
923
|
+
c48 += a48 + b48;
|
|
924
|
+
c48 &= 65535;
|
|
925
|
+
return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
|
|
926
|
+
};
|
|
927
|
+
LongPrototype.subtract = function subtract(subtrahend) {
|
|
928
|
+
if (!isLong(subtrahend)) subtrahend = fromValue(subtrahend);
|
|
929
|
+
return this.add(subtrahend.neg());
|
|
930
|
+
};
|
|
931
|
+
LongPrototype.sub = LongPrototype.subtract;
|
|
932
|
+
LongPrototype.multiply = function multiply(multiplier) {
|
|
933
|
+
if (this.isZero()) return this;
|
|
934
|
+
if (!isLong(multiplier)) multiplier = fromValue(multiplier);
|
|
935
|
+
if (wasm) {
|
|
936
|
+
var low = wasm["mul"](this.low, this.high, multiplier.low, multiplier.high);
|
|
937
|
+
return fromBits(low, wasm["get_high"](), this.unsigned);
|
|
938
|
+
}
|
|
939
|
+
if (multiplier.isZero()) return this.unsigned ? UZERO : ZERO;
|
|
940
|
+
if (this.eq(MIN_VALUE)) return multiplier.isOdd() ? MIN_VALUE : ZERO;
|
|
941
|
+
if (multiplier.eq(MIN_VALUE)) return this.isOdd() ? MIN_VALUE : ZERO;
|
|
942
|
+
if (this.isNegative()) {
|
|
943
|
+
if (multiplier.isNegative()) return this.neg().mul(multiplier.neg());
|
|
944
|
+
else return this.neg().mul(multiplier).neg();
|
|
945
|
+
} else if (multiplier.isNegative()) return this.mul(multiplier.neg()).neg();
|
|
946
|
+
if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
|
|
947
|
+
return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
|
|
948
|
+
var a48 = this.high >>> 16;
|
|
949
|
+
var a32 = this.high & 65535;
|
|
950
|
+
var a16 = this.low >>> 16;
|
|
951
|
+
var a00 = this.low & 65535;
|
|
952
|
+
var b48 = multiplier.high >>> 16;
|
|
953
|
+
var b32 = multiplier.high & 65535;
|
|
954
|
+
var b16 = multiplier.low >>> 16;
|
|
955
|
+
var b00 = multiplier.low & 65535;
|
|
956
|
+
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
|
957
|
+
c00 += a00 * b00;
|
|
958
|
+
c16 += c00 >>> 16;
|
|
959
|
+
c00 &= 65535;
|
|
960
|
+
c16 += a16 * b00;
|
|
961
|
+
c32 += c16 >>> 16;
|
|
962
|
+
c16 &= 65535;
|
|
963
|
+
c16 += a00 * b16;
|
|
964
|
+
c32 += c16 >>> 16;
|
|
965
|
+
c16 &= 65535;
|
|
966
|
+
c32 += a32 * b00;
|
|
967
|
+
c48 += c32 >>> 16;
|
|
968
|
+
c32 &= 65535;
|
|
969
|
+
c32 += a16 * b16;
|
|
970
|
+
c48 += c32 >>> 16;
|
|
971
|
+
c32 &= 65535;
|
|
972
|
+
c32 += a00 * b32;
|
|
973
|
+
c48 += c32 >>> 16;
|
|
974
|
+
c32 &= 65535;
|
|
975
|
+
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
|
976
|
+
c48 &= 65535;
|
|
977
|
+
return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
|
|
978
|
+
};
|
|
979
|
+
LongPrototype.mul = LongPrototype.multiply;
|
|
980
|
+
LongPrototype.divide = function divide(divisor) {
|
|
981
|
+
if (!isLong(divisor)) divisor = fromValue(divisor);
|
|
982
|
+
if (divisor.isZero()) throw Error("division by zero");
|
|
983
|
+
if (wasm) {
|
|
984
|
+
if (!this.unsigned && this.high === -2147483648 && divisor.low === -1 && divisor.high === -1) {
|
|
985
|
+
return this;
|
|
986
|
+
}
|
|
987
|
+
var low = (this.unsigned ? wasm["div_u"] : wasm["div_s"])(
|
|
988
|
+
this.low,
|
|
989
|
+
this.high,
|
|
990
|
+
divisor.low,
|
|
991
|
+
divisor.high
|
|
992
|
+
);
|
|
993
|
+
return fromBits(low, wasm["get_high"](), this.unsigned);
|
|
994
|
+
}
|
|
995
|
+
if (this.isZero()) return this.unsigned ? UZERO : ZERO;
|
|
996
|
+
var approx, rem, res;
|
|
997
|
+
if (!this.unsigned) {
|
|
998
|
+
if (this.eq(MIN_VALUE)) {
|
|
999
|
+
if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
|
|
1000
|
+
return MIN_VALUE;
|
|
1001
|
+
else if (divisor.eq(MIN_VALUE)) return ONE;
|
|
1002
|
+
else {
|
|
1003
|
+
var halfThis = this.shr(1);
|
|
1004
|
+
approx = halfThis.div(divisor).shl(1);
|
|
1005
|
+
if (approx.eq(ZERO)) {
|
|
1006
|
+
return divisor.isNegative() ? ONE : NEG_ONE;
|
|
1007
|
+
} else {
|
|
1008
|
+
rem = this.sub(divisor.mul(approx));
|
|
1009
|
+
res = approx.add(rem.div(divisor));
|
|
1010
|
+
return res;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
} else if (divisor.eq(MIN_VALUE)) return this.unsigned ? UZERO : ZERO;
|
|
1014
|
+
if (this.isNegative()) {
|
|
1015
|
+
if (divisor.isNegative()) return this.neg().div(divisor.neg());
|
|
1016
|
+
return this.neg().div(divisor).neg();
|
|
1017
|
+
} else if (divisor.isNegative()) return this.div(divisor.neg()).neg();
|
|
1018
|
+
res = ZERO;
|
|
1019
|
+
} else {
|
|
1020
|
+
if (!divisor.unsigned) divisor = divisor.toUnsigned();
|
|
1021
|
+
if (divisor.gt(this)) return UZERO;
|
|
1022
|
+
if (divisor.gt(this.shru(1)))
|
|
1023
|
+
return UONE;
|
|
1024
|
+
res = UZERO;
|
|
1025
|
+
}
|
|
1026
|
+
rem = this;
|
|
1027
|
+
while (rem.gte(divisor)) {
|
|
1028
|
+
approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
|
|
1029
|
+
var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48), approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor);
|
|
1030
|
+
while (approxRem.isNegative() || approxRem.gt(rem)) {
|
|
1031
|
+
approx -= delta;
|
|
1032
|
+
approxRes = fromNumber(approx, this.unsigned);
|
|
1033
|
+
approxRem = approxRes.mul(divisor);
|
|
1034
|
+
}
|
|
1035
|
+
if (approxRes.isZero()) approxRes = ONE;
|
|
1036
|
+
res = res.add(approxRes);
|
|
1037
|
+
rem = rem.sub(approxRem);
|
|
1038
|
+
}
|
|
1039
|
+
return res;
|
|
1040
|
+
};
|
|
1041
|
+
LongPrototype.div = LongPrototype.divide;
|
|
1042
|
+
LongPrototype.modulo = function modulo(divisor) {
|
|
1043
|
+
if (!isLong(divisor)) divisor = fromValue(divisor);
|
|
1044
|
+
if (wasm) {
|
|
1045
|
+
var low = (this.unsigned ? wasm["rem_u"] : wasm["rem_s"])(
|
|
1046
|
+
this.low,
|
|
1047
|
+
this.high,
|
|
1048
|
+
divisor.low,
|
|
1049
|
+
divisor.high
|
|
1050
|
+
);
|
|
1051
|
+
return fromBits(low, wasm["get_high"](), this.unsigned);
|
|
1052
|
+
}
|
|
1053
|
+
return this.sub(this.div(divisor).mul(divisor));
|
|
1054
|
+
};
|
|
1055
|
+
LongPrototype.mod = LongPrototype.modulo;
|
|
1056
|
+
LongPrototype.rem = LongPrototype.modulo;
|
|
1057
|
+
LongPrototype.not = function not() {
|
|
1058
|
+
return fromBits(~this.low, ~this.high, this.unsigned);
|
|
1059
|
+
};
|
|
1060
|
+
LongPrototype.countLeadingZeros = function countLeadingZeros() {
|
|
1061
|
+
return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32;
|
|
1062
|
+
};
|
|
1063
|
+
LongPrototype.clz = LongPrototype.countLeadingZeros;
|
|
1064
|
+
LongPrototype.countTrailingZeros = function countTrailingZeros() {
|
|
1065
|
+
return this.low ? ctz32(this.low) : ctz32(this.high) + 32;
|
|
1066
|
+
};
|
|
1067
|
+
LongPrototype.ctz = LongPrototype.countTrailingZeros;
|
|
1068
|
+
LongPrototype.and = function and(other) {
|
|
1069
|
+
if (!isLong(other)) other = fromValue(other);
|
|
1070
|
+
return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
|
|
1071
|
+
};
|
|
1072
|
+
LongPrototype.or = function or(other) {
|
|
1073
|
+
if (!isLong(other)) other = fromValue(other);
|
|
1074
|
+
return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
|
|
1075
|
+
};
|
|
1076
|
+
LongPrototype.xor = function xor(other) {
|
|
1077
|
+
if (!isLong(other)) other = fromValue(other);
|
|
1078
|
+
return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
|
|
1079
|
+
};
|
|
1080
|
+
LongPrototype.shiftLeft = function shiftLeft(numBits) {
|
|
1081
|
+
if (isLong(numBits)) numBits = numBits.toInt();
|
|
1082
|
+
if ((numBits &= 63) === 0) return this;
|
|
1083
|
+
else if (numBits < 32)
|
|
1084
|
+
return fromBits(
|
|
1085
|
+
this.low << numBits,
|
|
1086
|
+
this.high << numBits | this.low >>> 32 - numBits,
|
|
1087
|
+
this.unsigned
|
|
1088
|
+
);
|
|
1089
|
+
else return fromBits(0, this.low << numBits - 32, this.unsigned);
|
|
1090
|
+
};
|
|
1091
|
+
LongPrototype.shl = LongPrototype.shiftLeft;
|
|
1092
|
+
LongPrototype.shiftRight = function shiftRight(numBits) {
|
|
1093
|
+
if (isLong(numBits)) numBits = numBits.toInt();
|
|
1094
|
+
if ((numBits &= 63) === 0) return this;
|
|
1095
|
+
else if (numBits < 32)
|
|
1096
|
+
return fromBits(
|
|
1097
|
+
this.low >>> numBits | this.high << 32 - numBits,
|
|
1098
|
+
this.high >> numBits,
|
|
1099
|
+
this.unsigned
|
|
1100
|
+
);
|
|
1101
|
+
else
|
|
1102
|
+
return fromBits(
|
|
1103
|
+
this.high >> numBits - 32,
|
|
1104
|
+
this.high >= 0 ? 0 : -1,
|
|
1105
|
+
this.unsigned
|
|
1106
|
+
);
|
|
1107
|
+
};
|
|
1108
|
+
LongPrototype.shr = LongPrototype.shiftRight;
|
|
1109
|
+
LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
|
|
1110
|
+
if (isLong(numBits)) numBits = numBits.toInt();
|
|
1111
|
+
if ((numBits &= 63) === 0) return this;
|
|
1112
|
+
if (numBits < 32)
|
|
1113
|
+
return fromBits(
|
|
1114
|
+
this.low >>> numBits | this.high << 32 - numBits,
|
|
1115
|
+
this.high >>> numBits,
|
|
1116
|
+
this.unsigned
|
|
1117
|
+
);
|
|
1118
|
+
if (numBits === 32) return fromBits(this.high, 0, this.unsigned);
|
|
1119
|
+
return fromBits(this.high >>> numBits - 32, 0, this.unsigned);
|
|
1120
|
+
};
|
|
1121
|
+
LongPrototype.shru = LongPrototype.shiftRightUnsigned;
|
|
1122
|
+
LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
|
|
1123
|
+
LongPrototype.rotateLeft = function rotateLeft(numBits) {
|
|
1124
|
+
var b;
|
|
1125
|
+
if (isLong(numBits)) numBits = numBits.toInt();
|
|
1126
|
+
if ((numBits &= 63) === 0) return this;
|
|
1127
|
+
if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
|
|
1128
|
+
if (numBits < 32) {
|
|
1129
|
+
b = 32 - numBits;
|
|
1130
|
+
return fromBits(
|
|
1131
|
+
this.low << numBits | this.high >>> b,
|
|
1132
|
+
this.high << numBits | this.low >>> b,
|
|
1133
|
+
this.unsigned
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
numBits -= 32;
|
|
1137
|
+
b = 32 - numBits;
|
|
1138
|
+
return fromBits(
|
|
1139
|
+
this.high << numBits | this.low >>> b,
|
|
1140
|
+
this.low << numBits | this.high >>> b,
|
|
1141
|
+
this.unsigned
|
|
1142
|
+
);
|
|
1143
|
+
};
|
|
1144
|
+
LongPrototype.rotl = LongPrototype.rotateLeft;
|
|
1145
|
+
LongPrototype.rotateRight = function rotateRight(numBits) {
|
|
1146
|
+
var b;
|
|
1147
|
+
if (isLong(numBits)) numBits = numBits.toInt();
|
|
1148
|
+
if ((numBits &= 63) === 0) return this;
|
|
1149
|
+
if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
|
|
1150
|
+
if (numBits < 32) {
|
|
1151
|
+
b = 32 - numBits;
|
|
1152
|
+
return fromBits(
|
|
1153
|
+
this.high << b | this.low >>> numBits,
|
|
1154
|
+
this.low << b | this.high >>> numBits,
|
|
1155
|
+
this.unsigned
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
numBits -= 32;
|
|
1159
|
+
b = 32 - numBits;
|
|
1160
|
+
return fromBits(
|
|
1161
|
+
this.low << b | this.high >>> numBits,
|
|
1162
|
+
this.high << b | this.low >>> numBits,
|
|
1163
|
+
this.unsigned
|
|
1164
|
+
);
|
|
1165
|
+
};
|
|
1166
|
+
LongPrototype.rotr = LongPrototype.rotateRight;
|
|
1167
|
+
LongPrototype.toSigned = function toSigned() {
|
|
1168
|
+
if (!this.unsigned) return this;
|
|
1169
|
+
return fromBits(this.low, this.high, false);
|
|
1170
|
+
};
|
|
1171
|
+
LongPrototype.toUnsigned = function toUnsigned() {
|
|
1172
|
+
if (this.unsigned) return this;
|
|
1173
|
+
return fromBits(this.low, this.high, true);
|
|
1174
|
+
};
|
|
1175
|
+
LongPrototype.toBytes = function toBytes(le) {
|
|
1176
|
+
return le ? this.toBytesLE() : this.toBytesBE();
|
|
1177
|
+
};
|
|
1178
|
+
LongPrototype.toBytesLE = function toBytesLE() {
|
|
1179
|
+
var hi = this.high, lo = this.low;
|
|
1180
|
+
return [
|
|
1181
|
+
lo & 255,
|
|
1182
|
+
lo >>> 8 & 255,
|
|
1183
|
+
lo >>> 16 & 255,
|
|
1184
|
+
lo >>> 24,
|
|
1185
|
+
hi & 255,
|
|
1186
|
+
hi >>> 8 & 255,
|
|
1187
|
+
hi >>> 16 & 255,
|
|
1188
|
+
hi >>> 24
|
|
1189
|
+
];
|
|
1190
|
+
};
|
|
1191
|
+
LongPrototype.toBytesBE = function toBytesBE() {
|
|
1192
|
+
var hi = this.high, lo = this.low;
|
|
1193
|
+
return [
|
|
1194
|
+
hi >>> 24,
|
|
1195
|
+
hi >>> 16 & 255,
|
|
1196
|
+
hi >>> 8 & 255,
|
|
1197
|
+
hi & 255,
|
|
1198
|
+
lo >>> 24,
|
|
1199
|
+
lo >>> 16 & 255,
|
|
1200
|
+
lo >>> 8 & 255,
|
|
1201
|
+
lo & 255
|
|
1202
|
+
];
|
|
1203
|
+
};
|
|
1204
|
+
Long.fromBytes = function fromBytes(bytes, unsigned, le) {
|
|
1205
|
+
return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
|
|
1206
|
+
};
|
|
1207
|
+
Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
|
|
1208
|
+
return new Long(
|
|
1209
|
+
bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24,
|
|
1210
|
+
bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24,
|
|
1211
|
+
unsigned
|
|
1212
|
+
);
|
|
1213
|
+
};
|
|
1214
|
+
Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
|
|
1215
|
+
return new Long(
|
|
1216
|
+
bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7],
|
|
1217
|
+
bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3],
|
|
1218
|
+
unsigned
|
|
1219
|
+
);
|
|
1220
|
+
};
|
|
1221
|
+
if (typeof BigInt === "function") {
|
|
1222
|
+
Long.fromBigInt = function fromBigInt2(value, unsigned) {
|
|
1223
|
+
var lowBits = Number(BigInt.asIntN(32, value));
|
|
1224
|
+
var highBits = Number(BigInt.asIntN(32, value >> BigInt(32)));
|
|
1225
|
+
return fromBits(lowBits, highBits, unsigned);
|
|
1226
|
+
};
|
|
1227
|
+
Long.fromValue = function fromValueWithBigInt(value, unsigned) {
|
|
1228
|
+
if (typeof value === "bigint") return fromBigInt(value, unsigned);
|
|
1229
|
+
return fromValue(value, unsigned);
|
|
1230
|
+
};
|
|
1231
|
+
LongPrototype.toBigInt = function toBigInt() {
|
|
1232
|
+
var lowBigInt = BigInt(this.low >>> 0);
|
|
1233
|
+
var highBigInt = BigInt(this.unsigned ? this.high >>> 0 : this.high);
|
|
1234
|
+
return highBigInt << BigInt(32) | lowBigInt;
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
var long_default = Long;
|
|
1238
|
+
|
|
284
1239
|
// src/utils/units.ts
|
|
1240
|
+
var toUint256 = (value) => typeof value === "string" ? long_default.fromString(value) : long_default.fromNumber(value);
|
|
285
1241
|
var parseUnits = (amount, decimals) => {
|
|
286
1242
|
if (!amount || typeof amount !== "string") {
|
|
287
1243
|
throw new Error("Amount must be a non-empty string.");
|
|
@@ -373,7 +1329,7 @@ var AddLiquidityTool = class extends BaseTool {
|
|
|
373
1329
|
const routerContractId = resolveRouterContract(config);
|
|
374
1330
|
const deadline = resolveDeadline(config.deadlineMinutes);
|
|
375
1331
|
const toAddress = accountIdToSolidityAddress(operatorAccountId);
|
|
376
|
-
const params = new ContractFunctionParameters().addAddress(tokenIdToSolidityAddress(requireTokenId(tokenAId))).addAddress(tokenIdToSolidityAddress(requireTokenId(tokenBId))).addUint256(amountADesired).addUint256(amountBDesired).addUint256(amountAMin).addUint256(amountBMin).addAddress(toAddress).addUint256(deadline);
|
|
1332
|
+
const params = new ContractFunctionParameters().addAddress(tokenIdToSolidityAddress(requireTokenId(tokenAId))).addAddress(tokenIdToSolidityAddress(requireTokenId(tokenBId))).addUint256(toUint256(amountADesired)).addUint256(toUint256(amountBDesired)).addUint256(toUint256(amountAMin)).addUint256(toUint256(amountBMin)).addAddress(toAddress).addUint256(toUint256(deadline));
|
|
377
1333
|
const transaction = new ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("addLiquidity", params);
|
|
378
1334
|
const payload = {
|
|
379
1335
|
transaction,
|
|
@@ -447,7 +1403,7 @@ var RemoveLiquidityTool = class extends BaseTool {
|
|
|
447
1403
|
const routerContractId = resolveRouterContract(config);
|
|
448
1404
|
const deadline = resolveDeadline(config.deadlineMinutes);
|
|
449
1405
|
const toAddress = accountIdToSolidityAddress(operatorAccountId);
|
|
450
|
-
const params = new ContractFunctionParameters().addAddress(tokenIdToSolidityAddress(requireTokenId(tokenAId))).addAddress(tokenIdToSolidityAddress(requireTokenId(tokenBId))).addUint256(lpAmount).addUint256(minAmountA).addUint256(minAmountB).addAddress(toAddress).addUint256(deadline);
|
|
1406
|
+
const params = new ContractFunctionParameters().addAddress(tokenIdToSolidityAddress(requireTokenId(tokenAId))).addAddress(tokenIdToSolidityAddress(requireTokenId(tokenBId))).addUint256(toUint256(lpAmount)).addUint256(toUint256(minAmountA)).addUint256(toUint256(minAmountB)).addAddress(toAddress).addUint256(toUint256(deadline));
|
|
451
1407
|
const transaction = new ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("removeLiquidity", params);
|
|
452
1408
|
const payload = {
|
|
453
1409
|
transaction,
|
|
@@ -719,7 +1675,7 @@ var SwapTool = class extends BaseTool {
|
|
|
719
1675
|
tokenIdToSolidityAddress(requireTokenId(fromTokenId)),
|
|
720
1676
|
tokenIdToSolidityAddress(requireTokenId(toTokenId))
|
|
721
1677
|
];
|
|
722
|
-
const params = new ContractFunctionParameters().addUint256(amountInSmallest).addUint256(minOutSmallest).addAddressArray(path).addAddress(toAddress).addUint256(deadline);
|
|
1678
|
+
const params = new ContractFunctionParameters().addUint256(toUint256(amountInSmallest)).addUint256(toUint256(minOutSmallest)).addAddressArray(path).addAddress(toAddress).addUint256(toUint256(deadline));
|
|
723
1679
|
const transaction = new ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("swapExactTokensForTokens", params);
|
|
724
1680
|
const payload = {
|
|
725
1681
|
transaction,
|
|
@@ -767,7 +1723,30 @@ var saucerswapPlugin = {
|
|
|
767
1723
|
description: "Integration with SaucerSwap DEX for token swaps, liquidity provision, and yield farming",
|
|
768
1724
|
tools: () => [swapTool, quoteTool, poolsTool, addLiquidityTool, removeLiquidityTool, farmsTool]
|
|
769
1725
|
};
|
|
1726
|
+
/*! Bundled license information:
|
|
1727
|
+
|
|
1728
|
+
long/index.js:
|
|
1729
|
+
(**
|
|
1730
|
+
* @license
|
|
1731
|
+
* Copyright 2009 The Closure Library Authors
|
|
1732
|
+
* Copyright 2020 Daniel Wirtz / The long.js Authors.
|
|
1733
|
+
*
|
|
1734
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1735
|
+
* you may not use this file except in compliance with the License.
|
|
1736
|
+
* You may obtain a copy of the License at
|
|
1737
|
+
*
|
|
1738
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1739
|
+
*
|
|
1740
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1741
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1742
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1743
|
+
* See the License for the specific language governing permissions and
|
|
1744
|
+
* limitations under the License.
|
|
1745
|
+
*
|
|
1746
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
1747
|
+
*)
|
|
1748
|
+
*/
|
|
770
1749
|
|
|
771
|
-
export { saucerswapPlugin as default, saucerswapPlugin, saucerswapPluginToolNames };
|
|
1750
|
+
export { SAUCERSWAP_MAINNET, SAUCERSWAP_TESTNET, saucerswapPlugin as default, saucerswapPlugin, saucerswapPluginToolNames };
|
|
772
1751
|
//# sourceMappingURL=index.js.map
|
|
773
1752
|
//# sourceMappingURL=index.js.map
|