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