@cetusprotocol/aggregator-sdk 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.lockb +0 -0
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +308 -207
- package/dist/index.mjs +307 -208
- package/dist/src/api.d.ts +8 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/msafe.d.ts +2 -0
- package/package.json +1 -1
- package/src/api.ts +124 -35
- package/src/client.ts +7 -2
- package/src/transaction/cetus.ts +3 -2
- package/src/transaction/swap.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/msafe.ts +31 -0
- package/tests/router.test.ts +93 -2
package/dist/index.js
CHANGED
|
@@ -87,8 +87,8 @@ var require_bn = __commonJS({
|
|
|
87
87
|
ctor.prototype = new TempCtor();
|
|
88
88
|
ctor.prototype.constructor = ctor;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
if (
|
|
90
|
+
function BN7(number, base, endian) {
|
|
91
|
+
if (BN7.isBN(number)) {
|
|
92
92
|
return number;
|
|
93
93
|
}
|
|
94
94
|
this.negative = 0;
|
|
@@ -104,12 +104,12 @@ var require_bn = __commonJS({
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
if (typeof module2 === "object") {
|
|
107
|
-
module2.exports =
|
|
107
|
+
module2.exports = BN7;
|
|
108
108
|
} else {
|
|
109
|
-
exports2.BN =
|
|
109
|
+
exports2.BN = BN7;
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
BN7.BN = BN7;
|
|
112
|
+
BN7.wordSize = 26;
|
|
113
113
|
var Buffer2;
|
|
114
114
|
try {
|
|
115
115
|
if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
|
|
@@ -119,21 +119,21 @@ var require_bn = __commonJS({
|
|
|
119
119
|
}
|
|
120
120
|
} catch (e) {
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
if (num instanceof
|
|
122
|
+
BN7.isBN = function isBN(num) {
|
|
123
|
+
if (num instanceof BN7) {
|
|
124
124
|
return true;
|
|
125
125
|
}
|
|
126
|
-
return num !== null && typeof num === "object" && num.constructor.wordSize ===
|
|
126
|
+
return num !== null && typeof num === "object" && num.constructor.wordSize === BN7.wordSize && Array.isArray(num.words);
|
|
127
127
|
};
|
|
128
|
-
|
|
128
|
+
BN7.max = function max2(left, right) {
|
|
129
129
|
if (left.cmp(right) > 0) return left;
|
|
130
130
|
return right;
|
|
131
131
|
};
|
|
132
|
-
|
|
132
|
+
BN7.min = function min2(left, right) {
|
|
133
133
|
if (left.cmp(right) < 0) return left;
|
|
134
134
|
return right;
|
|
135
135
|
};
|
|
136
|
-
|
|
136
|
+
BN7.prototype._init = function init(number, base, endian) {
|
|
137
137
|
if (typeof number === "number") {
|
|
138
138
|
return this._initNumber(number, base, endian);
|
|
139
139
|
}
|
|
@@ -161,7 +161,7 @@ var require_bn = __commonJS({
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
|
-
|
|
164
|
+
BN7.prototype._initNumber = function _initNumber(number, base, endian) {
|
|
165
165
|
if (number < 0) {
|
|
166
166
|
this.negative = 1;
|
|
167
167
|
number = -number;
|
|
@@ -187,7 +187,7 @@ var require_bn = __commonJS({
|
|
|
187
187
|
if (endian !== "le") return;
|
|
188
188
|
this._initArray(this.toArray(), base, endian);
|
|
189
189
|
};
|
|
190
|
-
|
|
190
|
+
BN7.prototype._initArray = function _initArray(number, base, endian) {
|
|
191
191
|
assert(typeof number.length === "number");
|
|
192
192
|
if (number.length <= 0) {
|
|
193
193
|
this.words = [0];
|
|
@@ -245,7 +245,7 @@ var require_bn = __commonJS({
|
|
|
245
245
|
}
|
|
246
246
|
return r;
|
|
247
247
|
}
|
|
248
|
-
|
|
248
|
+
BN7.prototype._parseHex = function _parseHex(number, start, endian) {
|
|
249
249
|
this.length = Math.ceil((number.length - start) / 6);
|
|
250
250
|
this.words = new Array(this.length);
|
|
251
251
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -301,7 +301,7 @@ var require_bn = __commonJS({
|
|
|
301
301
|
}
|
|
302
302
|
return r;
|
|
303
303
|
}
|
|
304
|
-
|
|
304
|
+
BN7.prototype._parseBase = function _parseBase(number, base, start) {
|
|
305
305
|
this.words = [0];
|
|
306
306
|
this.length = 1;
|
|
307
307
|
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
|
|
@@ -337,7 +337,7 @@ var require_bn = __commonJS({
|
|
|
337
337
|
}
|
|
338
338
|
this._strip();
|
|
339
339
|
};
|
|
340
|
-
|
|
340
|
+
BN7.prototype.copy = function copy(dest) {
|
|
341
341
|
dest.words = new Array(this.length);
|
|
342
342
|
for (var i = 0; i < this.length; i++) {
|
|
343
343
|
dest.words[i] = this.words[i];
|
|
@@ -352,27 +352,27 @@ var require_bn = __commonJS({
|
|
|
352
352
|
dest.negative = src.negative;
|
|
353
353
|
dest.red = src.red;
|
|
354
354
|
}
|
|
355
|
-
|
|
355
|
+
BN7.prototype._move = function _move(dest) {
|
|
356
356
|
move(dest, this);
|
|
357
357
|
};
|
|
358
|
-
|
|
359
|
-
var r = new
|
|
358
|
+
BN7.prototype.clone = function clone2() {
|
|
359
|
+
var r = new BN7(null);
|
|
360
360
|
this.copy(r);
|
|
361
361
|
return r;
|
|
362
362
|
};
|
|
363
|
-
|
|
363
|
+
BN7.prototype._expand = function _expand(size) {
|
|
364
364
|
while (this.length < size) {
|
|
365
365
|
this.words[this.length++] = 0;
|
|
366
366
|
}
|
|
367
367
|
return this;
|
|
368
368
|
};
|
|
369
|
-
|
|
369
|
+
BN7.prototype._strip = function strip() {
|
|
370
370
|
while (this.length > 1 && this.words[this.length - 1] === 0) {
|
|
371
371
|
this.length--;
|
|
372
372
|
}
|
|
373
373
|
return this._normSign();
|
|
374
374
|
};
|
|
375
|
-
|
|
375
|
+
BN7.prototype._normSign = function _normSign() {
|
|
376
376
|
if (this.length === 1 && this.words[0] === 0) {
|
|
377
377
|
this.negative = 0;
|
|
378
378
|
}
|
|
@@ -380,12 +380,12 @@ var require_bn = __commonJS({
|
|
|
380
380
|
};
|
|
381
381
|
if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
|
|
382
382
|
try {
|
|
383
|
-
|
|
383
|
+
BN7.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
|
|
384
384
|
} catch (e) {
|
|
385
|
-
|
|
385
|
+
BN7.prototype.inspect = inspect;
|
|
386
386
|
}
|
|
387
387
|
} else {
|
|
388
|
-
|
|
388
|
+
BN7.prototype.inspect = inspect;
|
|
389
389
|
}
|
|
390
390
|
function inspect() {
|
|
391
391
|
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
|
|
@@ -496,7 +496,7 @@ var require_bn = __commonJS({
|
|
|
496
496
|
52521875,
|
|
497
497
|
60466176
|
|
498
498
|
];
|
|
499
|
-
|
|
499
|
+
BN7.prototype.toString = function toString(base, padding) {
|
|
500
500
|
base = base || 10;
|
|
501
501
|
padding = padding | 0 || 1;
|
|
502
502
|
var out;
|
|
@@ -558,7 +558,7 @@ var require_bn = __commonJS({
|
|
|
558
558
|
}
|
|
559
559
|
assert(false, "Base should be between 2 and 36");
|
|
560
560
|
};
|
|
561
|
-
|
|
561
|
+
BN7.prototype.toNumber = function toNumber() {
|
|
562
562
|
var ret = this.words[0];
|
|
563
563
|
if (this.length === 2) {
|
|
564
564
|
ret += this.words[1] * 67108864;
|
|
@@ -569,15 +569,15 @@ var require_bn = __commonJS({
|
|
|
569
569
|
}
|
|
570
570
|
return this.negative !== 0 ? -ret : ret;
|
|
571
571
|
};
|
|
572
|
-
|
|
572
|
+
BN7.prototype.toJSON = function toJSON() {
|
|
573
573
|
return this.toString(16, 2);
|
|
574
574
|
};
|
|
575
575
|
if (Buffer2) {
|
|
576
|
-
|
|
576
|
+
BN7.prototype.toBuffer = function toBuffer(endian, length) {
|
|
577
577
|
return this.toArrayLike(Buffer2, endian, length);
|
|
578
578
|
};
|
|
579
579
|
}
|
|
580
|
-
|
|
580
|
+
BN7.prototype.toArray = function toArray(endian, length) {
|
|
581
581
|
return this.toArrayLike(Array, endian, length);
|
|
582
582
|
};
|
|
583
583
|
var allocate = function allocate2(ArrayType, size) {
|
|
@@ -586,7 +586,7 @@ var require_bn = __commonJS({
|
|
|
586
586
|
}
|
|
587
587
|
return new ArrayType(size);
|
|
588
588
|
};
|
|
589
|
-
|
|
589
|
+
BN7.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
|
|
590
590
|
this._strip();
|
|
591
591
|
var byteLength = this.byteLength();
|
|
592
592
|
var reqLength = length || Math.max(1, byteLength);
|
|
@@ -597,7 +597,7 @@ var require_bn = __commonJS({
|
|
|
597
597
|
this["_toArrayLike" + postfix](res, byteLength);
|
|
598
598
|
return res;
|
|
599
599
|
};
|
|
600
|
-
|
|
600
|
+
BN7.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
|
|
601
601
|
var position = 0;
|
|
602
602
|
var carry = 0;
|
|
603
603
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -627,7 +627,7 @@ var require_bn = __commonJS({
|
|
|
627
627
|
}
|
|
628
628
|
}
|
|
629
629
|
};
|
|
630
|
-
|
|
630
|
+
BN7.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
|
|
631
631
|
var position = res.length - 1;
|
|
632
632
|
var carry = 0;
|
|
633
633
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -658,11 +658,11 @@ var require_bn = __commonJS({
|
|
|
658
658
|
}
|
|
659
659
|
};
|
|
660
660
|
if (Math.clz32) {
|
|
661
|
-
|
|
661
|
+
BN7.prototype._countBits = function _countBits(w) {
|
|
662
662
|
return 32 - Math.clz32(w);
|
|
663
663
|
};
|
|
664
664
|
} else {
|
|
665
|
-
|
|
665
|
+
BN7.prototype._countBits = function _countBits(w) {
|
|
666
666
|
var t = w;
|
|
667
667
|
var r = 0;
|
|
668
668
|
if (t >= 4096) {
|
|
@@ -684,7 +684,7 @@ var require_bn = __commonJS({
|
|
|
684
684
|
return r + t;
|
|
685
685
|
};
|
|
686
686
|
}
|
|
687
|
-
|
|
687
|
+
BN7.prototype._zeroBits = function _zeroBits(w) {
|
|
688
688
|
if (w === 0) return 26;
|
|
689
689
|
var t = w;
|
|
690
690
|
var r = 0;
|
|
@@ -709,7 +709,7 @@ var require_bn = __commonJS({
|
|
|
709
709
|
}
|
|
710
710
|
return r;
|
|
711
711
|
};
|
|
712
|
-
|
|
712
|
+
BN7.prototype.bitLength = function bitLength() {
|
|
713
713
|
var w = this.words[this.length - 1];
|
|
714
714
|
var hi = this._countBits(w);
|
|
715
715
|
return (this.length - 1) * 26 + hi;
|
|
@@ -723,7 +723,7 @@ var require_bn = __commonJS({
|
|
|
723
723
|
}
|
|
724
724
|
return w;
|
|
725
725
|
}
|
|
726
|
-
|
|
726
|
+
BN7.prototype.zeroBits = function zeroBits() {
|
|
727
727
|
if (this.isZero()) return 0;
|
|
728
728
|
var r = 0;
|
|
729
729
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -733,34 +733,34 @@ var require_bn = __commonJS({
|
|
|
733
733
|
}
|
|
734
734
|
return r;
|
|
735
735
|
};
|
|
736
|
-
|
|
736
|
+
BN7.prototype.byteLength = function byteLength() {
|
|
737
737
|
return Math.ceil(this.bitLength() / 8);
|
|
738
738
|
};
|
|
739
|
-
|
|
739
|
+
BN7.prototype.toTwos = function toTwos(width) {
|
|
740
740
|
if (this.negative !== 0) {
|
|
741
741
|
return this.abs().inotn(width).iaddn(1);
|
|
742
742
|
}
|
|
743
743
|
return this.clone();
|
|
744
744
|
};
|
|
745
|
-
|
|
745
|
+
BN7.prototype.fromTwos = function fromTwos(width) {
|
|
746
746
|
if (this.testn(width - 1)) {
|
|
747
747
|
return this.notn(width).iaddn(1).ineg();
|
|
748
748
|
}
|
|
749
749
|
return this.clone();
|
|
750
750
|
};
|
|
751
|
-
|
|
751
|
+
BN7.prototype.isNeg = function isNeg() {
|
|
752
752
|
return this.negative !== 0;
|
|
753
753
|
};
|
|
754
|
-
|
|
754
|
+
BN7.prototype.neg = function neg() {
|
|
755
755
|
return this.clone().ineg();
|
|
756
756
|
};
|
|
757
|
-
|
|
757
|
+
BN7.prototype.ineg = function ineg() {
|
|
758
758
|
if (!this.isZero()) {
|
|
759
759
|
this.negative ^= 1;
|
|
760
760
|
}
|
|
761
761
|
return this;
|
|
762
762
|
};
|
|
763
|
-
|
|
763
|
+
BN7.prototype.iuor = function iuor(num) {
|
|
764
764
|
while (this.length < num.length) {
|
|
765
765
|
this.words[this.length++] = 0;
|
|
766
766
|
}
|
|
@@ -769,19 +769,19 @@ var require_bn = __commonJS({
|
|
|
769
769
|
}
|
|
770
770
|
return this._strip();
|
|
771
771
|
};
|
|
772
|
-
|
|
772
|
+
BN7.prototype.ior = function ior(num) {
|
|
773
773
|
assert((this.negative | num.negative) === 0);
|
|
774
774
|
return this.iuor(num);
|
|
775
775
|
};
|
|
776
|
-
|
|
776
|
+
BN7.prototype.or = function or(num) {
|
|
777
777
|
if (this.length > num.length) return this.clone().ior(num);
|
|
778
778
|
return num.clone().ior(this);
|
|
779
779
|
};
|
|
780
|
-
|
|
780
|
+
BN7.prototype.uor = function uor(num) {
|
|
781
781
|
if (this.length > num.length) return this.clone().iuor(num);
|
|
782
782
|
return num.clone().iuor(this);
|
|
783
783
|
};
|
|
784
|
-
|
|
784
|
+
BN7.prototype.iuand = function iuand(num) {
|
|
785
785
|
var b;
|
|
786
786
|
if (this.length > num.length) {
|
|
787
787
|
b = num;
|
|
@@ -794,19 +794,19 @@ var require_bn = __commonJS({
|
|
|
794
794
|
this.length = b.length;
|
|
795
795
|
return this._strip();
|
|
796
796
|
};
|
|
797
|
-
|
|
797
|
+
BN7.prototype.iand = function iand(num) {
|
|
798
798
|
assert((this.negative | num.negative) === 0);
|
|
799
799
|
return this.iuand(num);
|
|
800
800
|
};
|
|
801
|
-
|
|
801
|
+
BN7.prototype.and = function and(num) {
|
|
802
802
|
if (this.length > num.length) return this.clone().iand(num);
|
|
803
803
|
return num.clone().iand(this);
|
|
804
804
|
};
|
|
805
|
-
|
|
805
|
+
BN7.prototype.uand = function uand(num) {
|
|
806
806
|
if (this.length > num.length) return this.clone().iuand(num);
|
|
807
807
|
return num.clone().iuand(this);
|
|
808
808
|
};
|
|
809
|
-
|
|
809
|
+
BN7.prototype.iuxor = function iuxor(num) {
|
|
810
810
|
var a;
|
|
811
811
|
var b;
|
|
812
812
|
if (this.length > num.length) {
|
|
@@ -827,19 +827,19 @@ var require_bn = __commonJS({
|
|
|
827
827
|
this.length = a.length;
|
|
828
828
|
return this._strip();
|
|
829
829
|
};
|
|
830
|
-
|
|
830
|
+
BN7.prototype.ixor = function ixor(num) {
|
|
831
831
|
assert((this.negative | num.negative) === 0);
|
|
832
832
|
return this.iuxor(num);
|
|
833
833
|
};
|
|
834
|
-
|
|
834
|
+
BN7.prototype.xor = function xor(num) {
|
|
835
835
|
if (this.length > num.length) return this.clone().ixor(num);
|
|
836
836
|
return num.clone().ixor(this);
|
|
837
837
|
};
|
|
838
|
-
|
|
838
|
+
BN7.prototype.uxor = function uxor(num) {
|
|
839
839
|
if (this.length > num.length) return this.clone().iuxor(num);
|
|
840
840
|
return num.clone().iuxor(this);
|
|
841
841
|
};
|
|
842
|
-
|
|
842
|
+
BN7.prototype.inotn = function inotn(width) {
|
|
843
843
|
assert(typeof width === "number" && width >= 0);
|
|
844
844
|
var bytesNeeded = Math.ceil(width / 26) | 0;
|
|
845
845
|
var bitsLeft = width % 26;
|
|
@@ -855,10 +855,10 @@ var require_bn = __commonJS({
|
|
|
855
855
|
}
|
|
856
856
|
return this._strip();
|
|
857
857
|
};
|
|
858
|
-
|
|
858
|
+
BN7.prototype.notn = function notn(width) {
|
|
859
859
|
return this.clone().inotn(width);
|
|
860
860
|
};
|
|
861
|
-
|
|
861
|
+
BN7.prototype.setn = function setn(bit, val) {
|
|
862
862
|
assert(typeof bit === "number" && bit >= 0);
|
|
863
863
|
var off = bit / 26 | 0;
|
|
864
864
|
var wbit = bit % 26;
|
|
@@ -870,7 +870,7 @@ var require_bn = __commonJS({
|
|
|
870
870
|
}
|
|
871
871
|
return this._strip();
|
|
872
872
|
};
|
|
873
|
-
|
|
873
|
+
BN7.prototype.iadd = function iadd(num) {
|
|
874
874
|
var r;
|
|
875
875
|
if (this.negative !== 0 && num.negative === 0) {
|
|
876
876
|
this.negative = 0;
|
|
@@ -913,7 +913,7 @@ var require_bn = __commonJS({
|
|
|
913
913
|
}
|
|
914
914
|
return this;
|
|
915
915
|
};
|
|
916
|
-
|
|
916
|
+
BN7.prototype.add = function add2(num) {
|
|
917
917
|
var res;
|
|
918
918
|
if (num.negative !== 0 && this.negative === 0) {
|
|
919
919
|
num.negative = 0;
|
|
@@ -929,7 +929,7 @@ var require_bn = __commonJS({
|
|
|
929
929
|
if (this.length > num.length) return this.clone().iadd(num);
|
|
930
930
|
return num.clone().iadd(this);
|
|
931
931
|
};
|
|
932
|
-
|
|
932
|
+
BN7.prototype.isub = function isub(num) {
|
|
933
933
|
if (num.negative !== 0) {
|
|
934
934
|
num.negative = 0;
|
|
935
935
|
var r = this.iadd(num);
|
|
@@ -978,7 +978,7 @@ var require_bn = __commonJS({
|
|
|
978
978
|
}
|
|
979
979
|
return this._strip();
|
|
980
980
|
};
|
|
981
|
-
|
|
981
|
+
BN7.prototype.sub = function sub2(num) {
|
|
982
982
|
return this.clone().isub(num);
|
|
983
983
|
};
|
|
984
984
|
function smallMulTo(self, num, out) {
|
|
@@ -1606,7 +1606,7 @@ var require_bn = __commonJS({
|
|
|
1606
1606
|
function jumboMulTo(self, num, out) {
|
|
1607
1607
|
return bigMulTo(self, num, out);
|
|
1608
1608
|
}
|
|
1609
|
-
|
|
1609
|
+
BN7.prototype.mulTo = function mulTo(num, out) {
|
|
1610
1610
|
var res;
|
|
1611
1611
|
var len = this.length + num.length;
|
|
1612
1612
|
if (this.length === 10 && num.length === 10) {
|
|
@@ -1620,20 +1620,20 @@ var require_bn = __commonJS({
|
|
|
1620
1620
|
}
|
|
1621
1621
|
return res;
|
|
1622
1622
|
};
|
|
1623
|
-
|
|
1624
|
-
var out = new
|
|
1623
|
+
BN7.prototype.mul = function mul2(num) {
|
|
1624
|
+
var out = new BN7(null);
|
|
1625
1625
|
out.words = new Array(this.length + num.length);
|
|
1626
1626
|
return this.mulTo(num, out);
|
|
1627
1627
|
};
|
|
1628
|
-
|
|
1629
|
-
var out = new
|
|
1628
|
+
BN7.prototype.mulf = function mulf(num) {
|
|
1629
|
+
var out = new BN7(null);
|
|
1630
1630
|
out.words = new Array(this.length + num.length);
|
|
1631
1631
|
return jumboMulTo(this, num, out);
|
|
1632
1632
|
};
|
|
1633
|
-
|
|
1633
|
+
BN7.prototype.imul = function imul(num) {
|
|
1634
1634
|
return this.clone().mulTo(num, this);
|
|
1635
1635
|
};
|
|
1636
|
-
|
|
1636
|
+
BN7.prototype.imuln = function imuln(num) {
|
|
1637
1637
|
var isNegNum = num < 0;
|
|
1638
1638
|
if (isNegNum) num = -num;
|
|
1639
1639
|
assert(typeof num === "number");
|
|
@@ -1653,18 +1653,18 @@ var require_bn = __commonJS({
|
|
|
1653
1653
|
}
|
|
1654
1654
|
return isNegNum ? this.ineg() : this;
|
|
1655
1655
|
};
|
|
1656
|
-
|
|
1656
|
+
BN7.prototype.muln = function muln(num) {
|
|
1657
1657
|
return this.clone().imuln(num);
|
|
1658
1658
|
};
|
|
1659
|
-
|
|
1659
|
+
BN7.prototype.sqr = function sqr() {
|
|
1660
1660
|
return this.mul(this);
|
|
1661
1661
|
};
|
|
1662
|
-
|
|
1662
|
+
BN7.prototype.isqr = function isqr() {
|
|
1663
1663
|
return this.imul(this.clone());
|
|
1664
1664
|
};
|
|
1665
|
-
|
|
1665
|
+
BN7.prototype.pow = function pow2(num) {
|
|
1666
1666
|
var w = toBitArray(num);
|
|
1667
|
-
if (w.length === 0) return new
|
|
1667
|
+
if (w.length === 0) return new BN7(1);
|
|
1668
1668
|
var res = this;
|
|
1669
1669
|
for (var i = 0; i < w.length; i++, res = res.sqr()) {
|
|
1670
1670
|
if (w[i] !== 0) break;
|
|
@@ -1677,7 +1677,7 @@ var require_bn = __commonJS({
|
|
|
1677
1677
|
}
|
|
1678
1678
|
return res;
|
|
1679
1679
|
};
|
|
1680
|
-
|
|
1680
|
+
BN7.prototype.iushln = function iushln(bits) {
|
|
1681
1681
|
assert(typeof bits === "number" && bits >= 0);
|
|
1682
1682
|
var r = bits % 26;
|
|
1683
1683
|
var s = (bits - r) / 26;
|
|
@@ -1707,11 +1707,11 @@ var require_bn = __commonJS({
|
|
|
1707
1707
|
}
|
|
1708
1708
|
return this._strip();
|
|
1709
1709
|
};
|
|
1710
|
-
|
|
1710
|
+
BN7.prototype.ishln = function ishln(bits) {
|
|
1711
1711
|
assert(this.negative === 0);
|
|
1712
1712
|
return this.iushln(bits);
|
|
1713
1713
|
};
|
|
1714
|
-
|
|
1714
|
+
BN7.prototype.iushrn = function iushrn(bits, hint, extended) {
|
|
1715
1715
|
assert(typeof bits === "number" && bits >= 0);
|
|
1716
1716
|
var h;
|
|
1717
1717
|
if (hint) {
|
|
@@ -1755,23 +1755,23 @@ var require_bn = __commonJS({
|
|
|
1755
1755
|
}
|
|
1756
1756
|
return this._strip();
|
|
1757
1757
|
};
|
|
1758
|
-
|
|
1758
|
+
BN7.prototype.ishrn = function ishrn(bits, hint, extended) {
|
|
1759
1759
|
assert(this.negative === 0);
|
|
1760
1760
|
return this.iushrn(bits, hint, extended);
|
|
1761
1761
|
};
|
|
1762
|
-
|
|
1762
|
+
BN7.prototype.shln = function shln(bits) {
|
|
1763
1763
|
return this.clone().ishln(bits);
|
|
1764
1764
|
};
|
|
1765
|
-
|
|
1765
|
+
BN7.prototype.ushln = function ushln(bits) {
|
|
1766
1766
|
return this.clone().iushln(bits);
|
|
1767
1767
|
};
|
|
1768
|
-
|
|
1768
|
+
BN7.prototype.shrn = function shrn(bits) {
|
|
1769
1769
|
return this.clone().ishrn(bits);
|
|
1770
1770
|
};
|
|
1771
|
-
|
|
1771
|
+
BN7.prototype.ushrn = function ushrn(bits) {
|
|
1772
1772
|
return this.clone().iushrn(bits);
|
|
1773
1773
|
};
|
|
1774
|
-
|
|
1774
|
+
BN7.prototype.testn = function testn(bit) {
|
|
1775
1775
|
assert(typeof bit === "number" && bit >= 0);
|
|
1776
1776
|
var r = bit % 26;
|
|
1777
1777
|
var s = (bit - r) / 26;
|
|
@@ -1780,7 +1780,7 @@ var require_bn = __commonJS({
|
|
|
1780
1780
|
var w = this.words[s];
|
|
1781
1781
|
return !!(w & q);
|
|
1782
1782
|
};
|
|
1783
|
-
|
|
1783
|
+
BN7.prototype.imaskn = function imaskn(bits) {
|
|
1784
1784
|
assert(typeof bits === "number" && bits >= 0);
|
|
1785
1785
|
var r = bits % 26;
|
|
1786
1786
|
var s = (bits - r) / 26;
|
|
@@ -1798,10 +1798,10 @@ var require_bn = __commonJS({
|
|
|
1798
1798
|
}
|
|
1799
1799
|
return this._strip();
|
|
1800
1800
|
};
|
|
1801
|
-
|
|
1801
|
+
BN7.prototype.maskn = function maskn(bits) {
|
|
1802
1802
|
return this.clone().imaskn(bits);
|
|
1803
1803
|
};
|
|
1804
|
-
|
|
1804
|
+
BN7.prototype.iaddn = function iaddn(num) {
|
|
1805
1805
|
assert(typeof num === "number");
|
|
1806
1806
|
assert(num < 67108864);
|
|
1807
1807
|
if (num < 0) return this.isubn(-num);
|
|
@@ -1818,7 +1818,7 @@ var require_bn = __commonJS({
|
|
|
1818
1818
|
}
|
|
1819
1819
|
return this._iaddn(num);
|
|
1820
1820
|
};
|
|
1821
|
-
|
|
1821
|
+
BN7.prototype._iaddn = function _iaddn(num) {
|
|
1822
1822
|
this.words[0] += num;
|
|
1823
1823
|
for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
|
|
1824
1824
|
this.words[i] -= 67108864;
|
|
@@ -1831,7 +1831,7 @@ var require_bn = __commonJS({
|
|
|
1831
1831
|
this.length = Math.max(this.length, i + 1);
|
|
1832
1832
|
return this;
|
|
1833
1833
|
};
|
|
1834
|
-
|
|
1834
|
+
BN7.prototype.isubn = function isubn(num) {
|
|
1835
1835
|
assert(typeof num === "number");
|
|
1836
1836
|
assert(num < 67108864);
|
|
1837
1837
|
if (num < 0) return this.iaddn(-num);
|
|
@@ -1853,20 +1853,20 @@ var require_bn = __commonJS({
|
|
|
1853
1853
|
}
|
|
1854
1854
|
return this._strip();
|
|
1855
1855
|
};
|
|
1856
|
-
|
|
1856
|
+
BN7.prototype.addn = function addn(num) {
|
|
1857
1857
|
return this.clone().iaddn(num);
|
|
1858
1858
|
};
|
|
1859
|
-
|
|
1859
|
+
BN7.prototype.subn = function subn(num) {
|
|
1860
1860
|
return this.clone().isubn(num);
|
|
1861
1861
|
};
|
|
1862
|
-
|
|
1862
|
+
BN7.prototype.iabs = function iabs() {
|
|
1863
1863
|
this.negative = 0;
|
|
1864
1864
|
return this;
|
|
1865
1865
|
};
|
|
1866
|
-
|
|
1866
|
+
BN7.prototype.abs = function abs2() {
|
|
1867
1867
|
return this.clone().iabs();
|
|
1868
1868
|
};
|
|
1869
|
-
|
|
1869
|
+
BN7.prototype._ishlnsubmul = function _ishlnsubmul(num, mul2, shift) {
|
|
1870
1870
|
var len = num.length + shift;
|
|
1871
1871
|
var i;
|
|
1872
1872
|
this._expand(len);
|
|
@@ -1895,7 +1895,7 @@ var require_bn = __commonJS({
|
|
|
1895
1895
|
this.negative = 1;
|
|
1896
1896
|
return this._strip();
|
|
1897
1897
|
};
|
|
1898
|
-
|
|
1898
|
+
BN7.prototype._wordDiv = function _wordDiv(num, mode) {
|
|
1899
1899
|
var shift = this.length - num.length;
|
|
1900
1900
|
var a = this.clone();
|
|
1901
1901
|
var b = num;
|
|
@@ -1910,7 +1910,7 @@ var require_bn = __commonJS({
|
|
|
1910
1910
|
var m = a.length - b.length;
|
|
1911
1911
|
var q;
|
|
1912
1912
|
if (mode !== "mod") {
|
|
1913
|
-
q = new
|
|
1913
|
+
q = new BN7(null);
|
|
1914
1914
|
q.length = m + 1;
|
|
1915
1915
|
q.words = new Array(q.length);
|
|
1916
1916
|
for (var i = 0; i < q.length; i++) {
|
|
@@ -1952,12 +1952,12 @@ var require_bn = __commonJS({
|
|
|
1952
1952
|
mod: a
|
|
1953
1953
|
};
|
|
1954
1954
|
};
|
|
1955
|
-
|
|
1955
|
+
BN7.prototype.divmod = function divmod(num, mode, positive) {
|
|
1956
1956
|
assert(!num.isZero());
|
|
1957
1957
|
if (this.isZero()) {
|
|
1958
1958
|
return {
|
|
1959
|
-
div: new
|
|
1960
|
-
mod: new
|
|
1959
|
+
div: new BN7(0),
|
|
1960
|
+
mod: new BN7(0)
|
|
1961
1961
|
};
|
|
1962
1962
|
}
|
|
1963
1963
|
var div2, mod2, res;
|
|
@@ -2002,7 +2002,7 @@ var require_bn = __commonJS({
|
|
|
2002
2002
|
}
|
|
2003
2003
|
if (num.length > this.length || this.cmp(num) < 0) {
|
|
2004
2004
|
return {
|
|
2005
|
-
div: new
|
|
2005
|
+
div: new BN7(0),
|
|
2006
2006
|
mod: this
|
|
2007
2007
|
};
|
|
2008
2008
|
}
|
|
@@ -2016,26 +2016,26 @@ var require_bn = __commonJS({
|
|
|
2016
2016
|
if (mode === "mod") {
|
|
2017
2017
|
return {
|
|
2018
2018
|
div: null,
|
|
2019
|
-
mod: new
|
|
2019
|
+
mod: new BN7(this.modrn(num.words[0]))
|
|
2020
2020
|
};
|
|
2021
2021
|
}
|
|
2022
2022
|
return {
|
|
2023
2023
|
div: this.divn(num.words[0]),
|
|
2024
|
-
mod: new
|
|
2024
|
+
mod: new BN7(this.modrn(num.words[0]))
|
|
2025
2025
|
};
|
|
2026
2026
|
}
|
|
2027
2027
|
return this._wordDiv(num, mode);
|
|
2028
2028
|
};
|
|
2029
|
-
|
|
2029
|
+
BN7.prototype.div = function div2(num) {
|
|
2030
2030
|
return this.divmod(num, "div", false).div;
|
|
2031
2031
|
};
|
|
2032
|
-
|
|
2032
|
+
BN7.prototype.mod = function mod2(num) {
|
|
2033
2033
|
return this.divmod(num, "mod", false).mod;
|
|
2034
2034
|
};
|
|
2035
|
-
|
|
2035
|
+
BN7.prototype.umod = function umod(num) {
|
|
2036
2036
|
return this.divmod(num, "mod", true).mod;
|
|
2037
2037
|
};
|
|
2038
|
-
|
|
2038
|
+
BN7.prototype.divRound = function divRound(num) {
|
|
2039
2039
|
var dm = this.divmod(num);
|
|
2040
2040
|
if (dm.mod.isZero()) return dm.div;
|
|
2041
2041
|
var mod2 = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
|
|
@@ -2045,7 +2045,7 @@ var require_bn = __commonJS({
|
|
|
2045
2045
|
if (cmp2 < 0 || r2 === 1 && cmp2 === 0) return dm.div;
|
|
2046
2046
|
return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
|
|
2047
2047
|
};
|
|
2048
|
-
|
|
2048
|
+
BN7.prototype.modrn = function modrn(num) {
|
|
2049
2049
|
var isNegNum = num < 0;
|
|
2050
2050
|
if (isNegNum) num = -num;
|
|
2051
2051
|
assert(num <= 67108863);
|
|
@@ -2056,10 +2056,10 @@ var require_bn = __commonJS({
|
|
|
2056
2056
|
}
|
|
2057
2057
|
return isNegNum ? -acc : acc;
|
|
2058
2058
|
};
|
|
2059
|
-
|
|
2059
|
+
BN7.prototype.modn = function modn(num) {
|
|
2060
2060
|
return this.modrn(num);
|
|
2061
2061
|
};
|
|
2062
|
-
|
|
2062
|
+
BN7.prototype.idivn = function idivn(num) {
|
|
2063
2063
|
var isNegNum = num < 0;
|
|
2064
2064
|
if (isNegNum) num = -num;
|
|
2065
2065
|
assert(num <= 67108863);
|
|
@@ -2072,10 +2072,10 @@ var require_bn = __commonJS({
|
|
|
2072
2072
|
this._strip();
|
|
2073
2073
|
return isNegNum ? this.ineg() : this;
|
|
2074
2074
|
};
|
|
2075
|
-
|
|
2075
|
+
BN7.prototype.divn = function divn(num) {
|
|
2076
2076
|
return this.clone().idivn(num);
|
|
2077
2077
|
};
|
|
2078
|
-
|
|
2078
|
+
BN7.prototype.egcd = function egcd(p) {
|
|
2079
2079
|
assert(p.negative === 0);
|
|
2080
2080
|
assert(!p.isZero());
|
|
2081
2081
|
var x = this;
|
|
@@ -2085,10 +2085,10 @@ var require_bn = __commonJS({
|
|
|
2085
2085
|
} else {
|
|
2086
2086
|
x = x.clone();
|
|
2087
2087
|
}
|
|
2088
|
-
var A = new
|
|
2089
|
-
var B = new
|
|
2090
|
-
var C = new
|
|
2091
|
-
var D = new
|
|
2088
|
+
var A = new BN7(1);
|
|
2089
|
+
var B = new BN7(0);
|
|
2090
|
+
var C = new BN7(0);
|
|
2091
|
+
var D = new BN7(1);
|
|
2092
2092
|
var g = 0;
|
|
2093
2093
|
while (x.isEven() && y.isEven()) {
|
|
2094
2094
|
x.iushrn(1);
|
|
@@ -2138,7 +2138,7 @@ var require_bn = __commonJS({
|
|
|
2138
2138
|
gcd: y.iushln(g)
|
|
2139
2139
|
};
|
|
2140
2140
|
};
|
|
2141
|
-
|
|
2141
|
+
BN7.prototype._invmp = function _invmp(p) {
|
|
2142
2142
|
assert(p.negative === 0);
|
|
2143
2143
|
assert(!p.isZero());
|
|
2144
2144
|
var a = this;
|
|
@@ -2148,8 +2148,8 @@ var require_bn = __commonJS({
|
|
|
2148
2148
|
} else {
|
|
2149
2149
|
a = a.clone();
|
|
2150
2150
|
}
|
|
2151
|
-
var x1 = new
|
|
2152
|
-
var x2 = new
|
|
2151
|
+
var x1 = new BN7(1);
|
|
2152
|
+
var x2 = new BN7(0);
|
|
2153
2153
|
var delta = b.clone();
|
|
2154
2154
|
while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
|
|
2155
2155
|
for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
|
|
@@ -2191,7 +2191,7 @@ var require_bn = __commonJS({
|
|
|
2191
2191
|
}
|
|
2192
2192
|
return res;
|
|
2193
2193
|
};
|
|
2194
|
-
|
|
2194
|
+
BN7.prototype.gcd = function gcd(num) {
|
|
2195
2195
|
if (this.isZero()) return num.abs();
|
|
2196
2196
|
if (num.isZero()) return this.abs();
|
|
2197
2197
|
var a = this.clone();
|
|
@@ -2221,19 +2221,19 @@ var require_bn = __commonJS({
|
|
|
2221
2221
|
} while (true);
|
|
2222
2222
|
return b.iushln(shift);
|
|
2223
2223
|
};
|
|
2224
|
-
|
|
2224
|
+
BN7.prototype.invm = function invm(num) {
|
|
2225
2225
|
return this.egcd(num).a.umod(num);
|
|
2226
2226
|
};
|
|
2227
|
-
|
|
2227
|
+
BN7.prototype.isEven = function isEven() {
|
|
2228
2228
|
return (this.words[0] & 1) === 0;
|
|
2229
2229
|
};
|
|
2230
|
-
|
|
2230
|
+
BN7.prototype.isOdd = function isOdd2() {
|
|
2231
2231
|
return (this.words[0] & 1) === 1;
|
|
2232
2232
|
};
|
|
2233
|
-
|
|
2233
|
+
BN7.prototype.andln = function andln(num) {
|
|
2234
2234
|
return this.words[0] & num;
|
|
2235
2235
|
};
|
|
2236
|
-
|
|
2236
|
+
BN7.prototype.bincn = function bincn(bit) {
|
|
2237
2237
|
assert(typeof bit === "number");
|
|
2238
2238
|
var r = bit % 26;
|
|
2239
2239
|
var s = (bit - r) / 26;
|
|
@@ -2257,10 +2257,10 @@ var require_bn = __commonJS({
|
|
|
2257
2257
|
}
|
|
2258
2258
|
return this;
|
|
2259
2259
|
};
|
|
2260
|
-
|
|
2260
|
+
BN7.prototype.isZero = function isZero() {
|
|
2261
2261
|
return this.length === 1 && this.words[0] === 0;
|
|
2262
2262
|
};
|
|
2263
|
-
|
|
2263
|
+
BN7.prototype.cmpn = function cmpn(num) {
|
|
2264
2264
|
var negative = num < 0;
|
|
2265
2265
|
if (this.negative !== 0 && !negative) return -1;
|
|
2266
2266
|
if (this.negative === 0 && negative) return 1;
|
|
@@ -2279,14 +2279,14 @@ var require_bn = __commonJS({
|
|
|
2279
2279
|
if (this.negative !== 0) return -res | 0;
|
|
2280
2280
|
return res;
|
|
2281
2281
|
};
|
|
2282
|
-
|
|
2282
|
+
BN7.prototype.cmp = function cmp2(num) {
|
|
2283
2283
|
if (this.negative !== 0 && num.negative === 0) return -1;
|
|
2284
2284
|
if (this.negative === 0 && num.negative !== 0) return 1;
|
|
2285
2285
|
var res = this.ucmp(num);
|
|
2286
2286
|
if (this.negative !== 0) return -res | 0;
|
|
2287
2287
|
return res;
|
|
2288
2288
|
};
|
|
2289
|
-
|
|
2289
|
+
BN7.prototype.ucmp = function ucmp(num) {
|
|
2290
2290
|
if (this.length > num.length) return 1;
|
|
2291
2291
|
if (this.length < num.length) return -1;
|
|
2292
2292
|
var res = 0;
|
|
@@ -2303,112 +2303,112 @@ var require_bn = __commonJS({
|
|
|
2303
2303
|
}
|
|
2304
2304
|
return res;
|
|
2305
2305
|
};
|
|
2306
|
-
|
|
2306
|
+
BN7.prototype.gtn = function gtn(num) {
|
|
2307
2307
|
return this.cmpn(num) === 1;
|
|
2308
2308
|
};
|
|
2309
|
-
|
|
2309
|
+
BN7.prototype.gt = function gt(num) {
|
|
2310
2310
|
return this.cmp(num) === 1;
|
|
2311
2311
|
};
|
|
2312
|
-
|
|
2312
|
+
BN7.prototype.gten = function gten(num) {
|
|
2313
2313
|
return this.cmpn(num) >= 0;
|
|
2314
2314
|
};
|
|
2315
|
-
|
|
2315
|
+
BN7.prototype.gte = function gte(num) {
|
|
2316
2316
|
return this.cmp(num) >= 0;
|
|
2317
2317
|
};
|
|
2318
|
-
|
|
2318
|
+
BN7.prototype.ltn = function ltn(num) {
|
|
2319
2319
|
return this.cmpn(num) === -1;
|
|
2320
2320
|
};
|
|
2321
|
-
|
|
2321
|
+
BN7.prototype.lt = function lt(num) {
|
|
2322
2322
|
return this.cmp(num) === -1;
|
|
2323
2323
|
};
|
|
2324
|
-
|
|
2324
|
+
BN7.prototype.lten = function lten(num) {
|
|
2325
2325
|
return this.cmpn(num) <= 0;
|
|
2326
2326
|
};
|
|
2327
|
-
|
|
2327
|
+
BN7.prototype.lte = function lte(num) {
|
|
2328
2328
|
return this.cmp(num) <= 0;
|
|
2329
2329
|
};
|
|
2330
|
-
|
|
2330
|
+
BN7.prototype.eqn = function eqn(num) {
|
|
2331
2331
|
return this.cmpn(num) === 0;
|
|
2332
2332
|
};
|
|
2333
|
-
|
|
2333
|
+
BN7.prototype.eq = function eq(num) {
|
|
2334
2334
|
return this.cmp(num) === 0;
|
|
2335
2335
|
};
|
|
2336
|
-
|
|
2336
|
+
BN7.red = function red(num) {
|
|
2337
2337
|
return new Red(num);
|
|
2338
2338
|
};
|
|
2339
|
-
|
|
2339
|
+
BN7.prototype.toRed = function toRed(ctx) {
|
|
2340
2340
|
assert(!this.red, "Already a number in reduction context");
|
|
2341
2341
|
assert(this.negative === 0, "red works only with positives");
|
|
2342
2342
|
return ctx.convertTo(this)._forceRed(ctx);
|
|
2343
2343
|
};
|
|
2344
|
-
|
|
2344
|
+
BN7.prototype.fromRed = function fromRed() {
|
|
2345
2345
|
assert(this.red, "fromRed works only with numbers in reduction context");
|
|
2346
2346
|
return this.red.convertFrom(this);
|
|
2347
2347
|
};
|
|
2348
|
-
|
|
2348
|
+
BN7.prototype._forceRed = function _forceRed(ctx) {
|
|
2349
2349
|
this.red = ctx;
|
|
2350
2350
|
return this;
|
|
2351
2351
|
};
|
|
2352
|
-
|
|
2352
|
+
BN7.prototype.forceRed = function forceRed(ctx) {
|
|
2353
2353
|
assert(!this.red, "Already a number in reduction context");
|
|
2354
2354
|
return this._forceRed(ctx);
|
|
2355
2355
|
};
|
|
2356
|
-
|
|
2356
|
+
BN7.prototype.redAdd = function redAdd(num) {
|
|
2357
2357
|
assert(this.red, "redAdd works only with red numbers");
|
|
2358
2358
|
return this.red.add(this, num);
|
|
2359
2359
|
};
|
|
2360
|
-
|
|
2360
|
+
BN7.prototype.redIAdd = function redIAdd(num) {
|
|
2361
2361
|
assert(this.red, "redIAdd works only with red numbers");
|
|
2362
2362
|
return this.red.iadd(this, num);
|
|
2363
2363
|
};
|
|
2364
|
-
|
|
2364
|
+
BN7.prototype.redSub = function redSub(num) {
|
|
2365
2365
|
assert(this.red, "redSub works only with red numbers");
|
|
2366
2366
|
return this.red.sub(this, num);
|
|
2367
2367
|
};
|
|
2368
|
-
|
|
2368
|
+
BN7.prototype.redISub = function redISub(num) {
|
|
2369
2369
|
assert(this.red, "redISub works only with red numbers");
|
|
2370
2370
|
return this.red.isub(this, num);
|
|
2371
2371
|
};
|
|
2372
|
-
|
|
2372
|
+
BN7.prototype.redShl = function redShl(num) {
|
|
2373
2373
|
assert(this.red, "redShl works only with red numbers");
|
|
2374
2374
|
return this.red.shl(this, num);
|
|
2375
2375
|
};
|
|
2376
|
-
|
|
2376
|
+
BN7.prototype.redMul = function redMul(num) {
|
|
2377
2377
|
assert(this.red, "redMul works only with red numbers");
|
|
2378
2378
|
this.red._verify2(this, num);
|
|
2379
2379
|
return this.red.mul(this, num);
|
|
2380
2380
|
};
|
|
2381
|
-
|
|
2381
|
+
BN7.prototype.redIMul = function redIMul(num) {
|
|
2382
2382
|
assert(this.red, "redMul works only with red numbers");
|
|
2383
2383
|
this.red._verify2(this, num);
|
|
2384
2384
|
return this.red.imul(this, num);
|
|
2385
2385
|
};
|
|
2386
|
-
|
|
2386
|
+
BN7.prototype.redSqr = function redSqr() {
|
|
2387
2387
|
assert(this.red, "redSqr works only with red numbers");
|
|
2388
2388
|
this.red._verify1(this);
|
|
2389
2389
|
return this.red.sqr(this);
|
|
2390
2390
|
};
|
|
2391
|
-
|
|
2391
|
+
BN7.prototype.redISqr = function redISqr() {
|
|
2392
2392
|
assert(this.red, "redISqr works only with red numbers");
|
|
2393
2393
|
this.red._verify1(this);
|
|
2394
2394
|
return this.red.isqr(this);
|
|
2395
2395
|
};
|
|
2396
|
-
|
|
2396
|
+
BN7.prototype.redSqrt = function redSqrt() {
|
|
2397
2397
|
assert(this.red, "redSqrt works only with red numbers");
|
|
2398
2398
|
this.red._verify1(this);
|
|
2399
2399
|
return this.red.sqrt(this);
|
|
2400
2400
|
};
|
|
2401
|
-
|
|
2401
|
+
BN7.prototype.redInvm = function redInvm() {
|
|
2402
2402
|
assert(this.red, "redInvm works only with red numbers");
|
|
2403
2403
|
this.red._verify1(this);
|
|
2404
2404
|
return this.red.invm(this);
|
|
2405
2405
|
};
|
|
2406
|
-
|
|
2406
|
+
BN7.prototype.redNeg = function redNeg() {
|
|
2407
2407
|
assert(this.red, "redNeg works only with red numbers");
|
|
2408
2408
|
this.red._verify1(this);
|
|
2409
2409
|
return this.red.neg(this);
|
|
2410
2410
|
};
|
|
2411
|
-
|
|
2411
|
+
BN7.prototype.redPow = function redPow(num) {
|
|
2412
2412
|
assert(this.red && !num.red, "redPow(normalNum)");
|
|
2413
2413
|
this.red._verify1(this);
|
|
2414
2414
|
return this.red.pow(this, num);
|
|
@@ -2421,13 +2421,13 @@ var require_bn = __commonJS({
|
|
|
2421
2421
|
};
|
|
2422
2422
|
function MPrime(name, p) {
|
|
2423
2423
|
this.name = name;
|
|
2424
|
-
this.p = new
|
|
2424
|
+
this.p = new BN7(p, 16);
|
|
2425
2425
|
this.n = this.p.bitLength();
|
|
2426
|
-
this.k = new
|
|
2426
|
+
this.k = new BN7(1).iushln(this.n).isub(this.p);
|
|
2427
2427
|
this.tmp = this._tmp();
|
|
2428
2428
|
}
|
|
2429
2429
|
MPrime.prototype._tmp = function _tmp() {
|
|
2430
|
-
var tmp = new
|
|
2430
|
+
var tmp = new BN7(null);
|
|
2431
2431
|
tmp.words = new Array(Math.ceil(this.n / 13));
|
|
2432
2432
|
return tmp;
|
|
2433
2433
|
};
|
|
@@ -2553,7 +2553,7 @@ var require_bn = __commonJS({
|
|
|
2553
2553
|
}
|
|
2554
2554
|
return num;
|
|
2555
2555
|
};
|
|
2556
|
-
|
|
2556
|
+
BN7._prime = function prime(name) {
|
|
2557
2557
|
if (primes[name]) return primes[name];
|
|
2558
2558
|
var prime2;
|
|
2559
2559
|
if (name === "k256") {
|
|
@@ -2572,7 +2572,7 @@ var require_bn = __commonJS({
|
|
|
2572
2572
|
};
|
|
2573
2573
|
function Red(m) {
|
|
2574
2574
|
if (typeof m === "string") {
|
|
2575
|
-
var prime =
|
|
2575
|
+
var prime = BN7._prime(m);
|
|
2576
2576
|
this.m = prime.p;
|
|
2577
2577
|
this.prime = prime;
|
|
2578
2578
|
} else {
|
|
@@ -2658,7 +2658,7 @@ var require_bn = __commonJS({
|
|
|
2658
2658
|
var mod3 = this.m.andln(3);
|
|
2659
2659
|
assert(mod3 % 2 === 1);
|
|
2660
2660
|
if (mod3 === 3) {
|
|
2661
|
-
var pow2 = this.m.add(new
|
|
2661
|
+
var pow2 = this.m.add(new BN7(1)).iushrn(2);
|
|
2662
2662
|
return this.pow(a, pow2);
|
|
2663
2663
|
}
|
|
2664
2664
|
var q = this.m.subn(1);
|
|
@@ -2668,11 +2668,11 @@ var require_bn = __commonJS({
|
|
|
2668
2668
|
q.iushrn(1);
|
|
2669
2669
|
}
|
|
2670
2670
|
assert(!q.isZero());
|
|
2671
|
-
var one = new
|
|
2671
|
+
var one = new BN7(1).toRed(this);
|
|
2672
2672
|
var nOne = one.redNeg();
|
|
2673
2673
|
var lpow = this.m.subn(1).iushrn(1);
|
|
2674
2674
|
var z = this.m.bitLength();
|
|
2675
|
-
z = new
|
|
2675
|
+
z = new BN7(2 * z * z).toRed(this);
|
|
2676
2676
|
while (this.pow(z, lpow).cmp(nOne) !== 0) {
|
|
2677
2677
|
z.redIAdd(nOne);
|
|
2678
2678
|
}
|
|
@@ -2686,7 +2686,7 @@ var require_bn = __commonJS({
|
|
|
2686
2686
|
tmp = tmp.redSqr();
|
|
2687
2687
|
}
|
|
2688
2688
|
assert(i < m);
|
|
2689
|
-
var b = this.pow(c, new
|
|
2689
|
+
var b = this.pow(c, new BN7(1).iushln(m - i - 1));
|
|
2690
2690
|
r = r.redMul(b);
|
|
2691
2691
|
c = b.redSqr();
|
|
2692
2692
|
t = t.redMul(c);
|
|
@@ -2704,11 +2704,11 @@ var require_bn = __commonJS({
|
|
|
2704
2704
|
}
|
|
2705
2705
|
};
|
|
2706
2706
|
Red.prototype.pow = function pow2(a, num) {
|
|
2707
|
-
if (num.isZero()) return new
|
|
2707
|
+
if (num.isZero()) return new BN7(1).toRed(this);
|
|
2708
2708
|
if (num.cmpn(1) === 0) return a.clone();
|
|
2709
2709
|
var windowSize = 4;
|
|
2710
2710
|
var wnd = new Array(1 << windowSize);
|
|
2711
|
-
wnd[0] = new
|
|
2711
|
+
wnd[0] = new BN7(1).toRed(this);
|
|
2712
2712
|
wnd[1] = a;
|
|
2713
2713
|
for (var i = 2; i < wnd.length; i++) {
|
|
2714
2714
|
wnd[i] = this.mul(wnd[i - 1], a);
|
|
@@ -2752,7 +2752,7 @@ var require_bn = __commonJS({
|
|
|
2752
2752
|
res.red = null;
|
|
2753
2753
|
return res;
|
|
2754
2754
|
};
|
|
2755
|
-
|
|
2755
|
+
BN7.mont = function mont(num) {
|
|
2756
2756
|
return new Mont(num);
|
|
2757
2757
|
};
|
|
2758
2758
|
function Mont(m) {
|
|
@@ -2761,7 +2761,7 @@ var require_bn = __commonJS({
|
|
|
2761
2761
|
if (this.shift % 26 !== 0) {
|
|
2762
2762
|
this.shift += 26 - this.shift % 26;
|
|
2763
2763
|
}
|
|
2764
|
-
this.r = new
|
|
2764
|
+
this.r = new BN7(1).iushln(this.shift);
|
|
2765
2765
|
this.r2 = this.imod(this.r.sqr());
|
|
2766
2766
|
this.rinv = this.r._invmp(this.m);
|
|
2767
2767
|
this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
|
|
@@ -2795,7 +2795,7 @@ var require_bn = __commonJS({
|
|
|
2795
2795
|
return res._forceRed(this);
|
|
2796
2796
|
};
|
|
2797
2797
|
Mont.prototype.mul = function mul2(a, b) {
|
|
2798
|
-
if (a.isZero() || b.isZero()) return new
|
|
2798
|
+
if (a.isZero() || b.isZero()) return new BN7(0)._forceRed(this);
|
|
2799
2799
|
var t = a.mul(b);
|
|
2800
2800
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
2801
2801
|
var u = t.isub(c).iushrn(this.shift);
|
|
@@ -5207,7 +5207,7 @@ var Turbos = class {
|
|
|
5207
5207
|
var Cetus = class {
|
|
5208
5208
|
constructor(env, partner) {
|
|
5209
5209
|
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
5210
|
-
this.partner = partner != null ? partner : "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b";
|
|
5210
|
+
this.partner = (partner != null ? partner : env === 0 /* Mainnet */) ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528";
|
|
5211
5211
|
}
|
|
5212
5212
|
flash_swap(client, txb, path, by_amount_in) {
|
|
5213
5213
|
const { direction, from, target } = path;
|
|
@@ -5797,7 +5797,10 @@ function swapInPools(client, params, sender) {
|
|
|
5797
5797
|
target: targetCoin,
|
|
5798
5798
|
feeRate: event.fee_rate,
|
|
5799
5799
|
amountIn: event.amount_in,
|
|
5800
|
-
amountOut: event.amount_out
|
|
5800
|
+
amountOut: event.amount_out,
|
|
5801
|
+
extendedDetails: {
|
|
5802
|
+
afterSqrtPrice: event.after_sqrt_price
|
|
5803
|
+
}
|
|
5801
5804
|
}
|
|
5802
5805
|
],
|
|
5803
5806
|
amountIn: new import_bn4.BN((_d = event.amount_in) != null ? _d : 0),
|
|
@@ -6217,7 +6220,7 @@ var AggregatorClient6 = class {
|
|
|
6217
6220
|
if (this.env === 0 /* Mainnet */) {
|
|
6218
6221
|
return "0xeffc8ae61f439bb34c9b905ff8f29ec56873dcedf81c7123ff2f1f67c45ec302";
|
|
6219
6222
|
} else {
|
|
6220
|
-
return "
|
|
6223
|
+
return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595";
|
|
6221
6224
|
}
|
|
6222
6225
|
}
|
|
6223
6226
|
transferOrDestoryCoin(txb, coin, coinType) {
|
|
@@ -6315,16 +6318,17 @@ function parseRouterResponse(data) {
|
|
|
6315
6318
|
routes: data.routes.map((route) => {
|
|
6316
6319
|
return {
|
|
6317
6320
|
path: route.path.map((path) => {
|
|
6318
|
-
var _a, _b;
|
|
6321
|
+
var _a, _b, _c;
|
|
6319
6322
|
let version;
|
|
6320
6323
|
if (path.provider === AFTERMATH) {
|
|
6321
6324
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6322
6325
|
}
|
|
6323
6326
|
let extendedDetails;
|
|
6324
|
-
if (path.provider === TURBOS || path.provider === AFTERMATH) {
|
|
6327
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
|
|
6325
6328
|
extendedDetails = {
|
|
6326
6329
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6327
|
-
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type
|
|
6330
|
+
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
|
|
6331
|
+
afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
|
|
6328
6332
|
};
|
|
6329
6333
|
}
|
|
6330
6334
|
return {
|
|
@@ -6351,41 +6355,43 @@ function parseRouterResponse(data) {
|
|
|
6351
6355
|
// src/transaction/index.ts
|
|
6352
6356
|
var CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
|
6353
6357
|
|
|
6358
|
+
// src/utils/msafe.ts
|
|
6359
|
+
var import_bn6 = __toESM(require_bn());
|
|
6360
|
+
var dealWithFastRouterSwapParamsForMsafe = (data) => {
|
|
6361
|
+
const result = data.map((route) => {
|
|
6362
|
+
return __spreadProps(__spreadValues({}, route), {
|
|
6363
|
+
amountIn: route.amountIn.toString(),
|
|
6364
|
+
amountOut: route.amountOut.toString(),
|
|
6365
|
+
initialPrice: route.initialPrice.toString(),
|
|
6366
|
+
path: route.path
|
|
6367
|
+
});
|
|
6368
|
+
});
|
|
6369
|
+
return result;
|
|
6370
|
+
};
|
|
6371
|
+
var restituteMsafeFastRouterSwapParams = (data) => {
|
|
6372
|
+
const result = data.map((route) => {
|
|
6373
|
+
return __spreadProps(__spreadValues({}, route), {
|
|
6374
|
+
amountIn: new import_bn6.default(route.amountIn),
|
|
6375
|
+
amountOut: new import_bn6.default(route.amountOut),
|
|
6376
|
+
initialPrice: new decimal_default(route.initialPrice.toString()),
|
|
6377
|
+
path: route.path
|
|
6378
|
+
});
|
|
6379
|
+
});
|
|
6380
|
+
return result;
|
|
6381
|
+
};
|
|
6382
|
+
|
|
6354
6383
|
// src/api.ts
|
|
6355
6384
|
function getRouterResult(endpoint, params) {
|
|
6356
6385
|
return __async(this, null, function* () {
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
depth,
|
|
6363
|
-
splitAlgorithm,
|
|
6364
|
-
splitFactor,
|
|
6365
|
-
splitCount,
|
|
6366
|
-
providers
|
|
6367
|
-
} = params;
|
|
6368
|
-
const fromCoin = completionCoin(from);
|
|
6369
|
-
const targetCoin = completionCoin(target);
|
|
6370
|
-
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6371
|
-
if (depth) {
|
|
6372
|
-
url += `&depth=${depth}`;
|
|
6373
|
-
}
|
|
6374
|
-
if (splitAlgorithm) {
|
|
6375
|
-
url += `&split_algorithm=${splitAlgorithm}`;
|
|
6376
|
-
}
|
|
6377
|
-
if (splitFactor) {
|
|
6378
|
-
url += `&split_factor=${splitFactor}`;
|
|
6379
|
-
}
|
|
6380
|
-
if (splitCount) {
|
|
6381
|
-
url += `&split_count=${splitCount}`;
|
|
6386
|
+
let response;
|
|
6387
|
+
if (params.liquidityChanges && params.liquidityChanges.length > 0) {
|
|
6388
|
+
response = yield postRouterWithLiquidityChanges(endpoint, params);
|
|
6389
|
+
} else {
|
|
6390
|
+
response = yield getRouter(endpoint, params);
|
|
6382
6391
|
}
|
|
6383
|
-
if (
|
|
6384
|
-
|
|
6385
|
-
url += `&providers=${providers.join(",")}`;
|
|
6386
|
-
}
|
|
6392
|
+
if (!response) {
|
|
6393
|
+
return null;
|
|
6387
6394
|
}
|
|
6388
|
-
const response = yield fetch(url);
|
|
6389
6395
|
if (!response.ok) {
|
|
6390
6396
|
return {
|
|
6391
6397
|
amountIn: ZERO,
|
|
@@ -6420,6 +6426,99 @@ function getRouterResult(endpoint, params) {
|
|
|
6420
6426
|
};
|
|
6421
6427
|
});
|
|
6422
6428
|
}
|
|
6429
|
+
function getRouter(endpoint, params) {
|
|
6430
|
+
return __async(this, null, function* () {
|
|
6431
|
+
try {
|
|
6432
|
+
const {
|
|
6433
|
+
from,
|
|
6434
|
+
target,
|
|
6435
|
+
amount,
|
|
6436
|
+
byAmountIn,
|
|
6437
|
+
depth,
|
|
6438
|
+
splitAlgorithm,
|
|
6439
|
+
splitFactor,
|
|
6440
|
+
splitCount,
|
|
6441
|
+
providers
|
|
6442
|
+
} = params;
|
|
6443
|
+
const fromCoin = completionCoin(from);
|
|
6444
|
+
const targetCoin = completionCoin(target);
|
|
6445
|
+
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6446
|
+
if (depth) {
|
|
6447
|
+
url += `&depth=${depth}`;
|
|
6448
|
+
}
|
|
6449
|
+
if (splitAlgorithm) {
|
|
6450
|
+
url += `&split_algorithm=${splitAlgorithm}`;
|
|
6451
|
+
}
|
|
6452
|
+
if (splitFactor) {
|
|
6453
|
+
url += `&split_factor=${splitFactor}`;
|
|
6454
|
+
}
|
|
6455
|
+
if (splitCount) {
|
|
6456
|
+
url += `&split_count=${splitCount}`;
|
|
6457
|
+
}
|
|
6458
|
+
if (providers) {
|
|
6459
|
+
if (providers.length > 0) {
|
|
6460
|
+
url += `&providers=${providers.join(",")}`;
|
|
6461
|
+
}
|
|
6462
|
+
}
|
|
6463
|
+
const response = yield fetch(url);
|
|
6464
|
+
return response;
|
|
6465
|
+
} catch (error) {
|
|
6466
|
+
console.error(error);
|
|
6467
|
+
return null;
|
|
6468
|
+
}
|
|
6469
|
+
});
|
|
6470
|
+
}
|
|
6471
|
+
function postRouterWithLiquidityChanges(endpoint, params) {
|
|
6472
|
+
return __async(this, null, function* () {
|
|
6473
|
+
const {
|
|
6474
|
+
from,
|
|
6475
|
+
target,
|
|
6476
|
+
amount,
|
|
6477
|
+
byAmountIn,
|
|
6478
|
+
depth,
|
|
6479
|
+
splitAlgorithm,
|
|
6480
|
+
splitFactor,
|
|
6481
|
+
splitCount,
|
|
6482
|
+
providers,
|
|
6483
|
+
liquidityChanges
|
|
6484
|
+
} = params;
|
|
6485
|
+
const fromCoin = completionCoin(from);
|
|
6486
|
+
const targetCoin = completionCoin(target);
|
|
6487
|
+
const url = `${endpoint}`;
|
|
6488
|
+
const providersStr = providers == null ? void 0 : providers.join(",");
|
|
6489
|
+
const requestData = {
|
|
6490
|
+
from: fromCoin,
|
|
6491
|
+
target: targetCoin,
|
|
6492
|
+
amount: Number(amount.toString()),
|
|
6493
|
+
by_amount_in: byAmountIn,
|
|
6494
|
+
depth,
|
|
6495
|
+
split_algorithm: splitAlgorithm,
|
|
6496
|
+
split_factor: splitFactor,
|
|
6497
|
+
split_count: splitCount,
|
|
6498
|
+
providers: providersStr,
|
|
6499
|
+
liquidity_changes: liquidityChanges.map((change) => ({
|
|
6500
|
+
pool: change.poolID,
|
|
6501
|
+
tick_lower: change.ticklower,
|
|
6502
|
+
tick_upper: change.tickUpper,
|
|
6503
|
+
delta_liquidity: change.deltaLiquidity
|
|
6504
|
+
}))
|
|
6505
|
+
};
|
|
6506
|
+
console.log("requestData", JSON.stringify(requestData, null, 2));
|
|
6507
|
+
try {
|
|
6508
|
+
const response = yield fetch(url, {
|
|
6509
|
+
method: "POST",
|
|
6510
|
+
headers: {
|
|
6511
|
+
"Content-Type": "application/json"
|
|
6512
|
+
},
|
|
6513
|
+
body: JSON.stringify(requestData)
|
|
6514
|
+
});
|
|
6515
|
+
return response;
|
|
6516
|
+
} catch (error) {
|
|
6517
|
+
console.error("Error:", error);
|
|
6518
|
+
return null;
|
|
6519
|
+
}
|
|
6520
|
+
});
|
|
6521
|
+
}
|
|
6423
6522
|
|
|
6424
6523
|
// src/index.ts
|
|
6425
6524
|
var Env = /* @__PURE__ */ ((Env2) => {
|
|
@@ -6462,6 +6561,7 @@ exports.VOLO = VOLO;
|
|
|
6462
6561
|
exports.ZERO = ZERO;
|
|
6463
6562
|
exports.composeType = composeType;
|
|
6464
6563
|
exports.createTarget = createTarget;
|
|
6564
|
+
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
6465
6565
|
exports.extractAddressFromType = extractAddressFromType;
|
|
6466
6566
|
exports.extractStructTagFromType = extractStructTagFromType;
|
|
6467
6567
|
exports.fixSuiObjectId = fixSuiObjectId;
|
|
@@ -6470,3 +6570,4 @@ exports.isSortedSymbols = isSortedSymbols;
|
|
|
6470
6570
|
exports.normalizeCoinType = normalizeCoinType;
|
|
6471
6571
|
exports.parseRouterResponse = parseRouterResponse;
|
|
6472
6572
|
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
6573
|
+
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|