@cetusprotocol/aggregator-sdk 0.0.8 → 0.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/dist/index.d.mts +98 -102
- package/dist/index.d.ts +98 -102
- package/dist/index.js +1228 -1552
- package/dist/index.mjs +1215 -1539
- package/dist/src/api.d.ts +53 -0
- package/dist/src/client.d.ts +38 -65
- package/dist/src/const.d.ts +0 -9
- package/dist/src/index.d.ts +9 -5
- package/dist/src/transaction/afsui.d.ts +10 -0
- package/dist/src/transaction/aftermath.d.ts +13 -24
- package/dist/src/transaction/cetus.d.ts +9 -33
- package/dist/src/transaction/deepbook_v2.d.ts +14 -0
- package/dist/src/transaction/flowx_v2.d.ts +7 -0
- package/dist/src/transaction/haedal.d.ts +6 -0
- package/dist/src/transaction/index.d.ts +6 -1
- package/dist/src/transaction/kriya_v2.d.ts +6 -0
- package/dist/src/transaction/kriya_v3.d.ts +7 -0
- package/dist/src/transaction/swap.d.ts +1 -2
- package/dist/src/transaction/turbos.d.ts +7 -22
- package/dist/src/transaction/volo.d.ts +8 -0
- package/dist/src/utils/coin.d.ts +9 -0
- package/dist/{src → tests}/test_data.test.d.ts +1 -0
- package/package.json +2 -2
- package/src/api.ts +144 -0
- package/src/client.ts +295 -239
- package/src/const.ts +0 -13
- package/src/index.ts +10 -5
- package/src/transaction/afsui.ts +60 -0
- package/src/transaction/aftermath.ts +71 -124
- package/src/transaction/cetus.ts +87 -258
- package/src/transaction/deepbook_v2.ts +122 -0
- package/src/transaction/flowx_v2.ts +42 -0
- package/src/transaction/haedal.ts +41 -0
- package/src/transaction/index.ts +17 -1
- package/src/transaction/kriya_v2.ts +38 -0
- package/src/transaction/kriya_v3.ts +46 -0
- package/src/transaction/swap.ts +17 -24
- package/src/transaction/turbos.ts +40 -99
- package/src/transaction/volo.ts +52 -0
- package/src/utils/coin.ts +91 -6
- package/src/utils/transaction.ts +1 -1
- package/tests/router.test.ts +123 -73
- package/{src → tests}/test_data.test.ts +2 -0
- package/dist/src/config.d.ts +0 -26
- package/dist/src/transaction/common.d.ts +0 -12
- package/dist/src/transaction/deepbook.d.ts +0 -21
- package/dist/src/transaction/flowx.d.ts +0 -20
- package/dist/src/transaction/kriya.d.ts +0 -21
- package/dist/src/transaction/router.d.ts +0 -6
- package/dist/src/utils/account_cap.d.ts +0 -7
- package/src/config.ts +0 -65
- package/src/transaction/common.ts +0 -169
- package/src/transaction/deepbook.ts +0 -126
- package/src/transaction/flowx.ts +0 -97
- package/src/transaction/kriya.ts +0 -77
- package/src/transaction/router.ts +0 -339
- package/src/utils/account_cap.ts +0 -62
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SuiClient } from '@mysten/sui/client';
|
|
2
1
|
import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
|
|
3
2
|
import { Transaction } from '@mysten/sui/transactions';
|
|
4
3
|
|
|
@@ -86,8 +85,8 @@ var require_bn = __commonJS({
|
|
|
86
85
|
ctor.prototype = new TempCtor();
|
|
87
86
|
ctor.prototype.constructor = ctor;
|
|
88
87
|
}
|
|
89
|
-
function
|
|
90
|
-
if (
|
|
88
|
+
function BN6(number, base, endian) {
|
|
89
|
+
if (BN6.isBN(number)) {
|
|
91
90
|
return number;
|
|
92
91
|
}
|
|
93
92
|
this.negative = 0;
|
|
@@ -103,12 +102,12 @@ var require_bn = __commonJS({
|
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
if (typeof module2 === "object") {
|
|
106
|
-
module2.exports =
|
|
105
|
+
module2.exports = BN6;
|
|
107
106
|
} else {
|
|
108
|
-
exports2.BN =
|
|
107
|
+
exports2.BN = BN6;
|
|
109
108
|
}
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
BN6.BN = BN6;
|
|
110
|
+
BN6.wordSize = 26;
|
|
112
111
|
var Buffer2;
|
|
113
112
|
try {
|
|
114
113
|
if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
|
|
@@ -118,21 +117,21 @@ var require_bn = __commonJS({
|
|
|
118
117
|
}
|
|
119
118
|
} catch (e) {
|
|
120
119
|
}
|
|
121
|
-
|
|
122
|
-
if (num instanceof
|
|
120
|
+
BN6.isBN = function isBN(num) {
|
|
121
|
+
if (num instanceof BN6) {
|
|
123
122
|
return true;
|
|
124
123
|
}
|
|
125
|
-
return num !== null && typeof num === "object" && num.constructor.wordSize ===
|
|
124
|
+
return num !== null && typeof num === "object" && num.constructor.wordSize === BN6.wordSize && Array.isArray(num.words);
|
|
126
125
|
};
|
|
127
|
-
|
|
126
|
+
BN6.max = function max2(left, right) {
|
|
128
127
|
if (left.cmp(right) > 0) return left;
|
|
129
128
|
return right;
|
|
130
129
|
};
|
|
131
|
-
|
|
130
|
+
BN6.min = function min2(left, right) {
|
|
132
131
|
if (left.cmp(right) < 0) return left;
|
|
133
132
|
return right;
|
|
134
133
|
};
|
|
135
|
-
|
|
134
|
+
BN6.prototype._init = function init(number, base, endian) {
|
|
136
135
|
if (typeof number === "number") {
|
|
137
136
|
return this._initNumber(number, base, endian);
|
|
138
137
|
}
|
|
@@ -160,7 +159,7 @@ var require_bn = __commonJS({
|
|
|
160
159
|
}
|
|
161
160
|
}
|
|
162
161
|
};
|
|
163
|
-
|
|
162
|
+
BN6.prototype._initNumber = function _initNumber(number, base, endian) {
|
|
164
163
|
if (number < 0) {
|
|
165
164
|
this.negative = 1;
|
|
166
165
|
number = -number;
|
|
@@ -186,7 +185,7 @@ var require_bn = __commonJS({
|
|
|
186
185
|
if (endian !== "le") return;
|
|
187
186
|
this._initArray(this.toArray(), base, endian);
|
|
188
187
|
};
|
|
189
|
-
|
|
188
|
+
BN6.prototype._initArray = function _initArray(number, base, endian) {
|
|
190
189
|
assert(typeof number.length === "number");
|
|
191
190
|
if (number.length <= 0) {
|
|
192
191
|
this.words = [0];
|
|
@@ -244,7 +243,7 @@ var require_bn = __commonJS({
|
|
|
244
243
|
}
|
|
245
244
|
return r;
|
|
246
245
|
}
|
|
247
|
-
|
|
246
|
+
BN6.prototype._parseHex = function _parseHex(number, start, endian) {
|
|
248
247
|
this.length = Math.ceil((number.length - start) / 6);
|
|
249
248
|
this.words = new Array(this.length);
|
|
250
249
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -300,7 +299,7 @@ var require_bn = __commonJS({
|
|
|
300
299
|
}
|
|
301
300
|
return r;
|
|
302
301
|
}
|
|
303
|
-
|
|
302
|
+
BN6.prototype._parseBase = function _parseBase(number, base, start) {
|
|
304
303
|
this.words = [0];
|
|
305
304
|
this.length = 1;
|
|
306
305
|
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
|
|
@@ -336,7 +335,7 @@ var require_bn = __commonJS({
|
|
|
336
335
|
}
|
|
337
336
|
this._strip();
|
|
338
337
|
};
|
|
339
|
-
|
|
338
|
+
BN6.prototype.copy = function copy(dest) {
|
|
340
339
|
dest.words = new Array(this.length);
|
|
341
340
|
for (var i = 0; i < this.length; i++) {
|
|
342
341
|
dest.words[i] = this.words[i];
|
|
@@ -351,27 +350,27 @@ var require_bn = __commonJS({
|
|
|
351
350
|
dest.negative = src.negative;
|
|
352
351
|
dest.red = src.red;
|
|
353
352
|
}
|
|
354
|
-
|
|
353
|
+
BN6.prototype._move = function _move(dest) {
|
|
355
354
|
move(dest, this);
|
|
356
355
|
};
|
|
357
|
-
|
|
358
|
-
var r = new
|
|
356
|
+
BN6.prototype.clone = function clone2() {
|
|
357
|
+
var r = new BN6(null);
|
|
359
358
|
this.copy(r);
|
|
360
359
|
return r;
|
|
361
360
|
};
|
|
362
|
-
|
|
361
|
+
BN6.prototype._expand = function _expand(size) {
|
|
363
362
|
while (this.length < size) {
|
|
364
363
|
this.words[this.length++] = 0;
|
|
365
364
|
}
|
|
366
365
|
return this;
|
|
367
366
|
};
|
|
368
|
-
|
|
367
|
+
BN6.prototype._strip = function strip() {
|
|
369
368
|
while (this.length > 1 && this.words[this.length - 1] === 0) {
|
|
370
369
|
this.length--;
|
|
371
370
|
}
|
|
372
371
|
return this._normSign();
|
|
373
372
|
};
|
|
374
|
-
|
|
373
|
+
BN6.prototype._normSign = function _normSign() {
|
|
375
374
|
if (this.length === 1 && this.words[0] === 0) {
|
|
376
375
|
this.negative = 0;
|
|
377
376
|
}
|
|
@@ -379,12 +378,12 @@ var require_bn = __commonJS({
|
|
|
379
378
|
};
|
|
380
379
|
if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
|
|
381
380
|
try {
|
|
382
|
-
|
|
381
|
+
BN6.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
|
|
383
382
|
} catch (e) {
|
|
384
|
-
|
|
383
|
+
BN6.prototype.inspect = inspect;
|
|
385
384
|
}
|
|
386
385
|
} else {
|
|
387
|
-
|
|
386
|
+
BN6.prototype.inspect = inspect;
|
|
388
387
|
}
|
|
389
388
|
function inspect() {
|
|
390
389
|
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
|
|
@@ -495,7 +494,7 @@ var require_bn = __commonJS({
|
|
|
495
494
|
52521875,
|
|
496
495
|
60466176
|
|
497
496
|
];
|
|
498
|
-
|
|
497
|
+
BN6.prototype.toString = function toString(base, padding) {
|
|
499
498
|
base = base || 10;
|
|
500
499
|
padding = padding | 0 || 1;
|
|
501
500
|
var out;
|
|
@@ -557,7 +556,7 @@ var require_bn = __commonJS({
|
|
|
557
556
|
}
|
|
558
557
|
assert(false, "Base should be between 2 and 36");
|
|
559
558
|
};
|
|
560
|
-
|
|
559
|
+
BN6.prototype.toNumber = function toNumber() {
|
|
561
560
|
var ret = this.words[0];
|
|
562
561
|
if (this.length === 2) {
|
|
563
562
|
ret += this.words[1] * 67108864;
|
|
@@ -568,15 +567,15 @@ var require_bn = __commonJS({
|
|
|
568
567
|
}
|
|
569
568
|
return this.negative !== 0 ? -ret : ret;
|
|
570
569
|
};
|
|
571
|
-
|
|
570
|
+
BN6.prototype.toJSON = function toJSON() {
|
|
572
571
|
return this.toString(16, 2);
|
|
573
572
|
};
|
|
574
573
|
if (Buffer2) {
|
|
575
|
-
|
|
574
|
+
BN6.prototype.toBuffer = function toBuffer(endian, length) {
|
|
576
575
|
return this.toArrayLike(Buffer2, endian, length);
|
|
577
576
|
};
|
|
578
577
|
}
|
|
579
|
-
|
|
578
|
+
BN6.prototype.toArray = function toArray(endian, length) {
|
|
580
579
|
return this.toArrayLike(Array, endian, length);
|
|
581
580
|
};
|
|
582
581
|
var allocate = function allocate2(ArrayType, size) {
|
|
@@ -585,7 +584,7 @@ var require_bn = __commonJS({
|
|
|
585
584
|
}
|
|
586
585
|
return new ArrayType(size);
|
|
587
586
|
};
|
|
588
|
-
|
|
587
|
+
BN6.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
|
|
589
588
|
this._strip();
|
|
590
589
|
var byteLength = this.byteLength();
|
|
591
590
|
var reqLength = length || Math.max(1, byteLength);
|
|
@@ -596,7 +595,7 @@ var require_bn = __commonJS({
|
|
|
596
595
|
this["_toArrayLike" + postfix](res, byteLength);
|
|
597
596
|
return res;
|
|
598
597
|
};
|
|
599
|
-
|
|
598
|
+
BN6.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
|
|
600
599
|
var position = 0;
|
|
601
600
|
var carry = 0;
|
|
602
601
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -626,7 +625,7 @@ var require_bn = __commonJS({
|
|
|
626
625
|
}
|
|
627
626
|
}
|
|
628
627
|
};
|
|
629
|
-
|
|
628
|
+
BN6.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
|
|
630
629
|
var position = res.length - 1;
|
|
631
630
|
var carry = 0;
|
|
632
631
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -657,11 +656,11 @@ var require_bn = __commonJS({
|
|
|
657
656
|
}
|
|
658
657
|
};
|
|
659
658
|
if (Math.clz32) {
|
|
660
|
-
|
|
659
|
+
BN6.prototype._countBits = function _countBits(w) {
|
|
661
660
|
return 32 - Math.clz32(w);
|
|
662
661
|
};
|
|
663
662
|
} else {
|
|
664
|
-
|
|
663
|
+
BN6.prototype._countBits = function _countBits(w) {
|
|
665
664
|
var t = w;
|
|
666
665
|
var r = 0;
|
|
667
666
|
if (t >= 4096) {
|
|
@@ -683,7 +682,7 @@ var require_bn = __commonJS({
|
|
|
683
682
|
return r + t;
|
|
684
683
|
};
|
|
685
684
|
}
|
|
686
|
-
|
|
685
|
+
BN6.prototype._zeroBits = function _zeroBits(w) {
|
|
687
686
|
if (w === 0) return 26;
|
|
688
687
|
var t = w;
|
|
689
688
|
var r = 0;
|
|
@@ -708,7 +707,7 @@ var require_bn = __commonJS({
|
|
|
708
707
|
}
|
|
709
708
|
return r;
|
|
710
709
|
};
|
|
711
|
-
|
|
710
|
+
BN6.prototype.bitLength = function bitLength() {
|
|
712
711
|
var w = this.words[this.length - 1];
|
|
713
712
|
var hi = this._countBits(w);
|
|
714
713
|
return (this.length - 1) * 26 + hi;
|
|
@@ -722,7 +721,7 @@ var require_bn = __commonJS({
|
|
|
722
721
|
}
|
|
723
722
|
return w;
|
|
724
723
|
}
|
|
725
|
-
|
|
724
|
+
BN6.prototype.zeroBits = function zeroBits() {
|
|
726
725
|
if (this.isZero()) return 0;
|
|
727
726
|
var r = 0;
|
|
728
727
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -732,34 +731,34 @@ var require_bn = __commonJS({
|
|
|
732
731
|
}
|
|
733
732
|
return r;
|
|
734
733
|
};
|
|
735
|
-
|
|
734
|
+
BN6.prototype.byteLength = function byteLength() {
|
|
736
735
|
return Math.ceil(this.bitLength() / 8);
|
|
737
736
|
};
|
|
738
|
-
|
|
737
|
+
BN6.prototype.toTwos = function toTwos(width) {
|
|
739
738
|
if (this.negative !== 0) {
|
|
740
739
|
return this.abs().inotn(width).iaddn(1);
|
|
741
740
|
}
|
|
742
741
|
return this.clone();
|
|
743
742
|
};
|
|
744
|
-
|
|
743
|
+
BN6.prototype.fromTwos = function fromTwos(width) {
|
|
745
744
|
if (this.testn(width - 1)) {
|
|
746
745
|
return this.notn(width).iaddn(1).ineg();
|
|
747
746
|
}
|
|
748
747
|
return this.clone();
|
|
749
748
|
};
|
|
750
|
-
|
|
749
|
+
BN6.prototype.isNeg = function isNeg() {
|
|
751
750
|
return this.negative !== 0;
|
|
752
751
|
};
|
|
753
|
-
|
|
752
|
+
BN6.prototype.neg = function neg() {
|
|
754
753
|
return this.clone().ineg();
|
|
755
754
|
};
|
|
756
|
-
|
|
755
|
+
BN6.prototype.ineg = function ineg() {
|
|
757
756
|
if (!this.isZero()) {
|
|
758
757
|
this.negative ^= 1;
|
|
759
758
|
}
|
|
760
759
|
return this;
|
|
761
760
|
};
|
|
762
|
-
|
|
761
|
+
BN6.prototype.iuor = function iuor(num) {
|
|
763
762
|
while (this.length < num.length) {
|
|
764
763
|
this.words[this.length++] = 0;
|
|
765
764
|
}
|
|
@@ -768,19 +767,19 @@ var require_bn = __commonJS({
|
|
|
768
767
|
}
|
|
769
768
|
return this._strip();
|
|
770
769
|
};
|
|
771
|
-
|
|
770
|
+
BN6.prototype.ior = function ior(num) {
|
|
772
771
|
assert((this.negative | num.negative) === 0);
|
|
773
772
|
return this.iuor(num);
|
|
774
773
|
};
|
|
775
|
-
|
|
774
|
+
BN6.prototype.or = function or(num) {
|
|
776
775
|
if (this.length > num.length) return this.clone().ior(num);
|
|
777
776
|
return num.clone().ior(this);
|
|
778
777
|
};
|
|
779
|
-
|
|
778
|
+
BN6.prototype.uor = function uor(num) {
|
|
780
779
|
if (this.length > num.length) return this.clone().iuor(num);
|
|
781
780
|
return num.clone().iuor(this);
|
|
782
781
|
};
|
|
783
|
-
|
|
782
|
+
BN6.prototype.iuand = function iuand(num) {
|
|
784
783
|
var b;
|
|
785
784
|
if (this.length > num.length) {
|
|
786
785
|
b = num;
|
|
@@ -793,19 +792,19 @@ var require_bn = __commonJS({
|
|
|
793
792
|
this.length = b.length;
|
|
794
793
|
return this._strip();
|
|
795
794
|
};
|
|
796
|
-
|
|
795
|
+
BN6.prototype.iand = function iand(num) {
|
|
797
796
|
assert((this.negative | num.negative) === 0);
|
|
798
797
|
return this.iuand(num);
|
|
799
798
|
};
|
|
800
|
-
|
|
799
|
+
BN6.prototype.and = function and(num) {
|
|
801
800
|
if (this.length > num.length) return this.clone().iand(num);
|
|
802
801
|
return num.clone().iand(this);
|
|
803
802
|
};
|
|
804
|
-
|
|
803
|
+
BN6.prototype.uand = function uand(num) {
|
|
805
804
|
if (this.length > num.length) return this.clone().iuand(num);
|
|
806
805
|
return num.clone().iuand(this);
|
|
807
806
|
};
|
|
808
|
-
|
|
807
|
+
BN6.prototype.iuxor = function iuxor(num) {
|
|
809
808
|
var a;
|
|
810
809
|
var b;
|
|
811
810
|
if (this.length > num.length) {
|
|
@@ -826,19 +825,19 @@ var require_bn = __commonJS({
|
|
|
826
825
|
this.length = a.length;
|
|
827
826
|
return this._strip();
|
|
828
827
|
};
|
|
829
|
-
|
|
828
|
+
BN6.prototype.ixor = function ixor(num) {
|
|
830
829
|
assert((this.negative | num.negative) === 0);
|
|
831
830
|
return this.iuxor(num);
|
|
832
831
|
};
|
|
833
|
-
|
|
832
|
+
BN6.prototype.xor = function xor(num) {
|
|
834
833
|
if (this.length > num.length) return this.clone().ixor(num);
|
|
835
834
|
return num.clone().ixor(this);
|
|
836
835
|
};
|
|
837
|
-
|
|
836
|
+
BN6.prototype.uxor = function uxor(num) {
|
|
838
837
|
if (this.length > num.length) return this.clone().iuxor(num);
|
|
839
838
|
return num.clone().iuxor(this);
|
|
840
839
|
};
|
|
841
|
-
|
|
840
|
+
BN6.prototype.inotn = function inotn(width) {
|
|
842
841
|
assert(typeof width === "number" && width >= 0);
|
|
843
842
|
var bytesNeeded = Math.ceil(width / 26) | 0;
|
|
844
843
|
var bitsLeft = width % 26;
|
|
@@ -854,10 +853,10 @@ var require_bn = __commonJS({
|
|
|
854
853
|
}
|
|
855
854
|
return this._strip();
|
|
856
855
|
};
|
|
857
|
-
|
|
856
|
+
BN6.prototype.notn = function notn(width) {
|
|
858
857
|
return this.clone().inotn(width);
|
|
859
858
|
};
|
|
860
|
-
|
|
859
|
+
BN6.prototype.setn = function setn(bit, val) {
|
|
861
860
|
assert(typeof bit === "number" && bit >= 0);
|
|
862
861
|
var off = bit / 26 | 0;
|
|
863
862
|
var wbit = bit % 26;
|
|
@@ -869,7 +868,7 @@ var require_bn = __commonJS({
|
|
|
869
868
|
}
|
|
870
869
|
return this._strip();
|
|
871
870
|
};
|
|
872
|
-
|
|
871
|
+
BN6.prototype.iadd = function iadd(num) {
|
|
873
872
|
var r;
|
|
874
873
|
if (this.negative !== 0 && num.negative === 0) {
|
|
875
874
|
this.negative = 0;
|
|
@@ -912,7 +911,7 @@ var require_bn = __commonJS({
|
|
|
912
911
|
}
|
|
913
912
|
return this;
|
|
914
913
|
};
|
|
915
|
-
|
|
914
|
+
BN6.prototype.add = function add2(num) {
|
|
916
915
|
var res;
|
|
917
916
|
if (num.negative !== 0 && this.negative === 0) {
|
|
918
917
|
num.negative = 0;
|
|
@@ -928,7 +927,7 @@ var require_bn = __commonJS({
|
|
|
928
927
|
if (this.length > num.length) return this.clone().iadd(num);
|
|
929
928
|
return num.clone().iadd(this);
|
|
930
929
|
};
|
|
931
|
-
|
|
930
|
+
BN6.prototype.isub = function isub(num) {
|
|
932
931
|
if (num.negative !== 0) {
|
|
933
932
|
num.negative = 0;
|
|
934
933
|
var r = this.iadd(num);
|
|
@@ -977,7 +976,7 @@ var require_bn = __commonJS({
|
|
|
977
976
|
}
|
|
978
977
|
return this._strip();
|
|
979
978
|
};
|
|
980
|
-
|
|
979
|
+
BN6.prototype.sub = function sub2(num) {
|
|
981
980
|
return this.clone().isub(num);
|
|
982
981
|
};
|
|
983
982
|
function smallMulTo(self, num, out) {
|
|
@@ -1605,7 +1604,7 @@ var require_bn = __commonJS({
|
|
|
1605
1604
|
function jumboMulTo(self, num, out) {
|
|
1606
1605
|
return bigMulTo(self, num, out);
|
|
1607
1606
|
}
|
|
1608
|
-
|
|
1607
|
+
BN6.prototype.mulTo = function mulTo(num, out) {
|
|
1609
1608
|
var res;
|
|
1610
1609
|
var len = this.length + num.length;
|
|
1611
1610
|
if (this.length === 10 && num.length === 10) {
|
|
@@ -1619,20 +1618,20 @@ var require_bn = __commonJS({
|
|
|
1619
1618
|
}
|
|
1620
1619
|
return res;
|
|
1621
1620
|
};
|
|
1622
|
-
|
|
1623
|
-
var out = new
|
|
1621
|
+
BN6.prototype.mul = function mul2(num) {
|
|
1622
|
+
var out = new BN6(null);
|
|
1624
1623
|
out.words = new Array(this.length + num.length);
|
|
1625
1624
|
return this.mulTo(num, out);
|
|
1626
1625
|
};
|
|
1627
|
-
|
|
1628
|
-
var out = new
|
|
1626
|
+
BN6.prototype.mulf = function mulf(num) {
|
|
1627
|
+
var out = new BN6(null);
|
|
1629
1628
|
out.words = new Array(this.length + num.length);
|
|
1630
1629
|
return jumboMulTo(this, num, out);
|
|
1631
1630
|
};
|
|
1632
|
-
|
|
1631
|
+
BN6.prototype.imul = function imul(num) {
|
|
1633
1632
|
return this.clone().mulTo(num, this);
|
|
1634
1633
|
};
|
|
1635
|
-
|
|
1634
|
+
BN6.prototype.imuln = function imuln(num) {
|
|
1636
1635
|
var isNegNum = num < 0;
|
|
1637
1636
|
if (isNegNum) num = -num;
|
|
1638
1637
|
assert(typeof num === "number");
|
|
@@ -1652,18 +1651,18 @@ var require_bn = __commonJS({
|
|
|
1652
1651
|
}
|
|
1653
1652
|
return isNegNum ? this.ineg() : this;
|
|
1654
1653
|
};
|
|
1655
|
-
|
|
1654
|
+
BN6.prototype.muln = function muln(num) {
|
|
1656
1655
|
return this.clone().imuln(num);
|
|
1657
1656
|
};
|
|
1658
|
-
|
|
1657
|
+
BN6.prototype.sqr = function sqr() {
|
|
1659
1658
|
return this.mul(this);
|
|
1660
1659
|
};
|
|
1661
|
-
|
|
1660
|
+
BN6.prototype.isqr = function isqr() {
|
|
1662
1661
|
return this.imul(this.clone());
|
|
1663
1662
|
};
|
|
1664
|
-
|
|
1663
|
+
BN6.prototype.pow = function pow2(num) {
|
|
1665
1664
|
var w = toBitArray(num);
|
|
1666
|
-
if (w.length === 0) return new
|
|
1665
|
+
if (w.length === 0) return new BN6(1);
|
|
1667
1666
|
var res = this;
|
|
1668
1667
|
for (var i = 0; i < w.length; i++, res = res.sqr()) {
|
|
1669
1668
|
if (w[i] !== 0) break;
|
|
@@ -1676,7 +1675,7 @@ var require_bn = __commonJS({
|
|
|
1676
1675
|
}
|
|
1677
1676
|
return res;
|
|
1678
1677
|
};
|
|
1679
|
-
|
|
1678
|
+
BN6.prototype.iushln = function iushln(bits) {
|
|
1680
1679
|
assert(typeof bits === "number" && bits >= 0);
|
|
1681
1680
|
var r = bits % 26;
|
|
1682
1681
|
var s = (bits - r) / 26;
|
|
@@ -1706,11 +1705,11 @@ var require_bn = __commonJS({
|
|
|
1706
1705
|
}
|
|
1707
1706
|
return this._strip();
|
|
1708
1707
|
};
|
|
1709
|
-
|
|
1708
|
+
BN6.prototype.ishln = function ishln(bits) {
|
|
1710
1709
|
assert(this.negative === 0);
|
|
1711
1710
|
return this.iushln(bits);
|
|
1712
1711
|
};
|
|
1713
|
-
|
|
1712
|
+
BN6.prototype.iushrn = function iushrn(bits, hint, extended) {
|
|
1714
1713
|
assert(typeof bits === "number" && bits >= 0);
|
|
1715
1714
|
var h;
|
|
1716
1715
|
if (hint) {
|
|
@@ -1754,23 +1753,23 @@ var require_bn = __commonJS({
|
|
|
1754
1753
|
}
|
|
1755
1754
|
return this._strip();
|
|
1756
1755
|
};
|
|
1757
|
-
|
|
1756
|
+
BN6.prototype.ishrn = function ishrn(bits, hint, extended) {
|
|
1758
1757
|
assert(this.negative === 0);
|
|
1759
1758
|
return this.iushrn(bits, hint, extended);
|
|
1760
1759
|
};
|
|
1761
|
-
|
|
1760
|
+
BN6.prototype.shln = function shln(bits) {
|
|
1762
1761
|
return this.clone().ishln(bits);
|
|
1763
1762
|
};
|
|
1764
|
-
|
|
1763
|
+
BN6.prototype.ushln = function ushln(bits) {
|
|
1765
1764
|
return this.clone().iushln(bits);
|
|
1766
1765
|
};
|
|
1767
|
-
|
|
1766
|
+
BN6.prototype.shrn = function shrn(bits) {
|
|
1768
1767
|
return this.clone().ishrn(bits);
|
|
1769
1768
|
};
|
|
1770
|
-
|
|
1769
|
+
BN6.prototype.ushrn = function ushrn(bits) {
|
|
1771
1770
|
return this.clone().iushrn(bits);
|
|
1772
1771
|
};
|
|
1773
|
-
|
|
1772
|
+
BN6.prototype.testn = function testn(bit) {
|
|
1774
1773
|
assert(typeof bit === "number" && bit >= 0);
|
|
1775
1774
|
var r = bit % 26;
|
|
1776
1775
|
var s = (bit - r) / 26;
|
|
@@ -1779,7 +1778,7 @@ var require_bn = __commonJS({
|
|
|
1779
1778
|
var w = this.words[s];
|
|
1780
1779
|
return !!(w & q);
|
|
1781
1780
|
};
|
|
1782
|
-
|
|
1781
|
+
BN6.prototype.imaskn = function imaskn(bits) {
|
|
1783
1782
|
assert(typeof bits === "number" && bits >= 0);
|
|
1784
1783
|
var r = bits % 26;
|
|
1785
1784
|
var s = (bits - r) / 26;
|
|
@@ -1797,10 +1796,10 @@ var require_bn = __commonJS({
|
|
|
1797
1796
|
}
|
|
1798
1797
|
return this._strip();
|
|
1799
1798
|
};
|
|
1800
|
-
|
|
1799
|
+
BN6.prototype.maskn = function maskn(bits) {
|
|
1801
1800
|
return this.clone().imaskn(bits);
|
|
1802
1801
|
};
|
|
1803
|
-
|
|
1802
|
+
BN6.prototype.iaddn = function iaddn(num) {
|
|
1804
1803
|
assert(typeof num === "number");
|
|
1805
1804
|
assert(num < 67108864);
|
|
1806
1805
|
if (num < 0) return this.isubn(-num);
|
|
@@ -1817,7 +1816,7 @@ var require_bn = __commonJS({
|
|
|
1817
1816
|
}
|
|
1818
1817
|
return this._iaddn(num);
|
|
1819
1818
|
};
|
|
1820
|
-
|
|
1819
|
+
BN6.prototype._iaddn = function _iaddn(num) {
|
|
1821
1820
|
this.words[0] += num;
|
|
1822
1821
|
for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
|
|
1823
1822
|
this.words[i] -= 67108864;
|
|
@@ -1830,7 +1829,7 @@ var require_bn = __commonJS({
|
|
|
1830
1829
|
this.length = Math.max(this.length, i + 1);
|
|
1831
1830
|
return this;
|
|
1832
1831
|
};
|
|
1833
|
-
|
|
1832
|
+
BN6.prototype.isubn = function isubn(num) {
|
|
1834
1833
|
assert(typeof num === "number");
|
|
1835
1834
|
assert(num < 67108864);
|
|
1836
1835
|
if (num < 0) return this.iaddn(-num);
|
|
@@ -1852,20 +1851,20 @@ var require_bn = __commonJS({
|
|
|
1852
1851
|
}
|
|
1853
1852
|
return this._strip();
|
|
1854
1853
|
};
|
|
1855
|
-
|
|
1854
|
+
BN6.prototype.addn = function addn(num) {
|
|
1856
1855
|
return this.clone().iaddn(num);
|
|
1857
1856
|
};
|
|
1858
|
-
|
|
1857
|
+
BN6.prototype.subn = function subn(num) {
|
|
1859
1858
|
return this.clone().isubn(num);
|
|
1860
1859
|
};
|
|
1861
|
-
|
|
1860
|
+
BN6.prototype.iabs = function iabs() {
|
|
1862
1861
|
this.negative = 0;
|
|
1863
1862
|
return this;
|
|
1864
1863
|
};
|
|
1865
|
-
|
|
1864
|
+
BN6.prototype.abs = function abs2() {
|
|
1866
1865
|
return this.clone().iabs();
|
|
1867
1866
|
};
|
|
1868
|
-
|
|
1867
|
+
BN6.prototype._ishlnsubmul = function _ishlnsubmul(num, mul2, shift) {
|
|
1869
1868
|
var len = num.length + shift;
|
|
1870
1869
|
var i;
|
|
1871
1870
|
this._expand(len);
|
|
@@ -1894,7 +1893,7 @@ var require_bn = __commonJS({
|
|
|
1894
1893
|
this.negative = 1;
|
|
1895
1894
|
return this._strip();
|
|
1896
1895
|
};
|
|
1897
|
-
|
|
1896
|
+
BN6.prototype._wordDiv = function _wordDiv(num, mode) {
|
|
1898
1897
|
var shift = this.length - num.length;
|
|
1899
1898
|
var a = this.clone();
|
|
1900
1899
|
var b = num;
|
|
@@ -1909,7 +1908,7 @@ var require_bn = __commonJS({
|
|
|
1909
1908
|
var m = a.length - b.length;
|
|
1910
1909
|
var q;
|
|
1911
1910
|
if (mode !== "mod") {
|
|
1912
|
-
q = new
|
|
1911
|
+
q = new BN6(null);
|
|
1913
1912
|
q.length = m + 1;
|
|
1914
1913
|
q.words = new Array(q.length);
|
|
1915
1914
|
for (var i = 0; i < q.length; i++) {
|
|
@@ -1951,12 +1950,12 @@ var require_bn = __commonJS({
|
|
|
1951
1950
|
mod: a
|
|
1952
1951
|
};
|
|
1953
1952
|
};
|
|
1954
|
-
|
|
1953
|
+
BN6.prototype.divmod = function divmod(num, mode, positive) {
|
|
1955
1954
|
assert(!num.isZero());
|
|
1956
1955
|
if (this.isZero()) {
|
|
1957
1956
|
return {
|
|
1958
|
-
div: new
|
|
1959
|
-
mod: new
|
|
1957
|
+
div: new BN6(0),
|
|
1958
|
+
mod: new BN6(0)
|
|
1960
1959
|
};
|
|
1961
1960
|
}
|
|
1962
1961
|
var div2, mod2, res;
|
|
@@ -2001,7 +2000,7 @@ var require_bn = __commonJS({
|
|
|
2001
2000
|
}
|
|
2002
2001
|
if (num.length > this.length || this.cmp(num) < 0) {
|
|
2003
2002
|
return {
|
|
2004
|
-
div: new
|
|
2003
|
+
div: new BN6(0),
|
|
2005
2004
|
mod: this
|
|
2006
2005
|
};
|
|
2007
2006
|
}
|
|
@@ -2015,26 +2014,26 @@ var require_bn = __commonJS({
|
|
|
2015
2014
|
if (mode === "mod") {
|
|
2016
2015
|
return {
|
|
2017
2016
|
div: null,
|
|
2018
|
-
mod: new
|
|
2017
|
+
mod: new BN6(this.modrn(num.words[0]))
|
|
2019
2018
|
};
|
|
2020
2019
|
}
|
|
2021
2020
|
return {
|
|
2022
2021
|
div: this.divn(num.words[0]),
|
|
2023
|
-
mod: new
|
|
2022
|
+
mod: new BN6(this.modrn(num.words[0]))
|
|
2024
2023
|
};
|
|
2025
2024
|
}
|
|
2026
2025
|
return this._wordDiv(num, mode);
|
|
2027
2026
|
};
|
|
2028
|
-
|
|
2027
|
+
BN6.prototype.div = function div2(num) {
|
|
2029
2028
|
return this.divmod(num, "div", false).div;
|
|
2030
2029
|
};
|
|
2031
|
-
|
|
2030
|
+
BN6.prototype.mod = function mod2(num) {
|
|
2032
2031
|
return this.divmod(num, "mod", false).mod;
|
|
2033
2032
|
};
|
|
2034
|
-
|
|
2033
|
+
BN6.prototype.umod = function umod(num) {
|
|
2035
2034
|
return this.divmod(num, "mod", true).mod;
|
|
2036
2035
|
};
|
|
2037
|
-
|
|
2036
|
+
BN6.prototype.divRound = function divRound(num) {
|
|
2038
2037
|
var dm = this.divmod(num);
|
|
2039
2038
|
if (dm.mod.isZero()) return dm.div;
|
|
2040
2039
|
var mod2 = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
|
|
@@ -2044,7 +2043,7 @@ var require_bn = __commonJS({
|
|
|
2044
2043
|
if (cmp2 < 0 || r2 === 1 && cmp2 === 0) return dm.div;
|
|
2045
2044
|
return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
|
|
2046
2045
|
};
|
|
2047
|
-
|
|
2046
|
+
BN6.prototype.modrn = function modrn(num) {
|
|
2048
2047
|
var isNegNum = num < 0;
|
|
2049
2048
|
if (isNegNum) num = -num;
|
|
2050
2049
|
assert(num <= 67108863);
|
|
@@ -2055,10 +2054,10 @@ var require_bn = __commonJS({
|
|
|
2055
2054
|
}
|
|
2056
2055
|
return isNegNum ? -acc : acc;
|
|
2057
2056
|
};
|
|
2058
|
-
|
|
2057
|
+
BN6.prototype.modn = function modn(num) {
|
|
2059
2058
|
return this.modrn(num);
|
|
2060
2059
|
};
|
|
2061
|
-
|
|
2060
|
+
BN6.prototype.idivn = function idivn(num) {
|
|
2062
2061
|
var isNegNum = num < 0;
|
|
2063
2062
|
if (isNegNum) num = -num;
|
|
2064
2063
|
assert(num <= 67108863);
|
|
@@ -2071,10 +2070,10 @@ var require_bn = __commonJS({
|
|
|
2071
2070
|
this._strip();
|
|
2072
2071
|
return isNegNum ? this.ineg() : this;
|
|
2073
2072
|
};
|
|
2074
|
-
|
|
2073
|
+
BN6.prototype.divn = function divn(num) {
|
|
2075
2074
|
return this.clone().idivn(num);
|
|
2076
2075
|
};
|
|
2077
|
-
|
|
2076
|
+
BN6.prototype.egcd = function egcd(p) {
|
|
2078
2077
|
assert(p.negative === 0);
|
|
2079
2078
|
assert(!p.isZero());
|
|
2080
2079
|
var x = this;
|
|
@@ -2084,10 +2083,10 @@ var require_bn = __commonJS({
|
|
|
2084
2083
|
} else {
|
|
2085
2084
|
x = x.clone();
|
|
2086
2085
|
}
|
|
2087
|
-
var A = new
|
|
2088
|
-
var B = new
|
|
2089
|
-
var C = new
|
|
2090
|
-
var D = new
|
|
2086
|
+
var A = new BN6(1);
|
|
2087
|
+
var B = new BN6(0);
|
|
2088
|
+
var C = new BN6(0);
|
|
2089
|
+
var D = new BN6(1);
|
|
2091
2090
|
var g = 0;
|
|
2092
2091
|
while (x.isEven() && y.isEven()) {
|
|
2093
2092
|
x.iushrn(1);
|
|
@@ -2137,7 +2136,7 @@ var require_bn = __commonJS({
|
|
|
2137
2136
|
gcd: y.iushln(g)
|
|
2138
2137
|
};
|
|
2139
2138
|
};
|
|
2140
|
-
|
|
2139
|
+
BN6.prototype._invmp = function _invmp(p) {
|
|
2141
2140
|
assert(p.negative === 0);
|
|
2142
2141
|
assert(!p.isZero());
|
|
2143
2142
|
var a = this;
|
|
@@ -2147,8 +2146,8 @@ var require_bn = __commonJS({
|
|
|
2147
2146
|
} else {
|
|
2148
2147
|
a = a.clone();
|
|
2149
2148
|
}
|
|
2150
|
-
var x1 = new
|
|
2151
|
-
var x2 = new
|
|
2149
|
+
var x1 = new BN6(1);
|
|
2150
|
+
var x2 = new BN6(0);
|
|
2152
2151
|
var delta = b.clone();
|
|
2153
2152
|
while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
|
|
2154
2153
|
for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
|
|
@@ -2190,7 +2189,7 @@ var require_bn = __commonJS({
|
|
|
2190
2189
|
}
|
|
2191
2190
|
return res;
|
|
2192
2191
|
};
|
|
2193
|
-
|
|
2192
|
+
BN6.prototype.gcd = function gcd(num) {
|
|
2194
2193
|
if (this.isZero()) return num.abs();
|
|
2195
2194
|
if (num.isZero()) return this.abs();
|
|
2196
2195
|
var a = this.clone();
|
|
@@ -2220,19 +2219,19 @@ var require_bn = __commonJS({
|
|
|
2220
2219
|
} while (true);
|
|
2221
2220
|
return b.iushln(shift);
|
|
2222
2221
|
};
|
|
2223
|
-
|
|
2222
|
+
BN6.prototype.invm = function invm(num) {
|
|
2224
2223
|
return this.egcd(num).a.umod(num);
|
|
2225
2224
|
};
|
|
2226
|
-
|
|
2225
|
+
BN6.prototype.isEven = function isEven() {
|
|
2227
2226
|
return (this.words[0] & 1) === 0;
|
|
2228
2227
|
};
|
|
2229
|
-
|
|
2228
|
+
BN6.prototype.isOdd = function isOdd2() {
|
|
2230
2229
|
return (this.words[0] & 1) === 1;
|
|
2231
2230
|
};
|
|
2232
|
-
|
|
2231
|
+
BN6.prototype.andln = function andln(num) {
|
|
2233
2232
|
return this.words[0] & num;
|
|
2234
2233
|
};
|
|
2235
|
-
|
|
2234
|
+
BN6.prototype.bincn = function bincn(bit) {
|
|
2236
2235
|
assert(typeof bit === "number");
|
|
2237
2236
|
var r = bit % 26;
|
|
2238
2237
|
var s = (bit - r) / 26;
|
|
@@ -2256,10 +2255,10 @@ var require_bn = __commonJS({
|
|
|
2256
2255
|
}
|
|
2257
2256
|
return this;
|
|
2258
2257
|
};
|
|
2259
|
-
|
|
2258
|
+
BN6.prototype.isZero = function isZero() {
|
|
2260
2259
|
return this.length === 1 && this.words[0] === 0;
|
|
2261
2260
|
};
|
|
2262
|
-
|
|
2261
|
+
BN6.prototype.cmpn = function cmpn(num) {
|
|
2263
2262
|
var negative = num < 0;
|
|
2264
2263
|
if (this.negative !== 0 && !negative) return -1;
|
|
2265
2264
|
if (this.negative === 0 && negative) return 1;
|
|
@@ -2278,14 +2277,14 @@ var require_bn = __commonJS({
|
|
|
2278
2277
|
if (this.negative !== 0) return -res | 0;
|
|
2279
2278
|
return res;
|
|
2280
2279
|
};
|
|
2281
|
-
|
|
2280
|
+
BN6.prototype.cmp = function cmp2(num) {
|
|
2282
2281
|
if (this.negative !== 0 && num.negative === 0) return -1;
|
|
2283
2282
|
if (this.negative === 0 && num.negative !== 0) return 1;
|
|
2284
2283
|
var res = this.ucmp(num);
|
|
2285
2284
|
if (this.negative !== 0) return -res | 0;
|
|
2286
2285
|
return res;
|
|
2287
2286
|
};
|
|
2288
|
-
|
|
2287
|
+
BN6.prototype.ucmp = function ucmp(num) {
|
|
2289
2288
|
if (this.length > num.length) return 1;
|
|
2290
2289
|
if (this.length < num.length) return -1;
|
|
2291
2290
|
var res = 0;
|
|
@@ -2302,112 +2301,112 @@ var require_bn = __commonJS({
|
|
|
2302
2301
|
}
|
|
2303
2302
|
return res;
|
|
2304
2303
|
};
|
|
2305
|
-
|
|
2304
|
+
BN6.prototype.gtn = function gtn(num) {
|
|
2306
2305
|
return this.cmpn(num) === 1;
|
|
2307
2306
|
};
|
|
2308
|
-
|
|
2307
|
+
BN6.prototype.gt = function gt(num) {
|
|
2309
2308
|
return this.cmp(num) === 1;
|
|
2310
2309
|
};
|
|
2311
|
-
|
|
2310
|
+
BN6.prototype.gten = function gten(num) {
|
|
2312
2311
|
return this.cmpn(num) >= 0;
|
|
2313
2312
|
};
|
|
2314
|
-
|
|
2313
|
+
BN6.prototype.gte = function gte(num) {
|
|
2315
2314
|
return this.cmp(num) >= 0;
|
|
2316
2315
|
};
|
|
2317
|
-
|
|
2316
|
+
BN6.prototype.ltn = function ltn(num) {
|
|
2318
2317
|
return this.cmpn(num) === -1;
|
|
2319
2318
|
};
|
|
2320
|
-
|
|
2319
|
+
BN6.prototype.lt = function lt(num) {
|
|
2321
2320
|
return this.cmp(num) === -1;
|
|
2322
2321
|
};
|
|
2323
|
-
|
|
2322
|
+
BN6.prototype.lten = function lten(num) {
|
|
2324
2323
|
return this.cmpn(num) <= 0;
|
|
2325
2324
|
};
|
|
2326
|
-
|
|
2325
|
+
BN6.prototype.lte = function lte(num) {
|
|
2327
2326
|
return this.cmp(num) <= 0;
|
|
2328
2327
|
};
|
|
2329
|
-
|
|
2328
|
+
BN6.prototype.eqn = function eqn(num) {
|
|
2330
2329
|
return this.cmpn(num) === 0;
|
|
2331
2330
|
};
|
|
2332
|
-
|
|
2331
|
+
BN6.prototype.eq = function eq(num) {
|
|
2333
2332
|
return this.cmp(num) === 0;
|
|
2334
2333
|
};
|
|
2335
|
-
|
|
2334
|
+
BN6.red = function red(num) {
|
|
2336
2335
|
return new Red(num);
|
|
2337
2336
|
};
|
|
2338
|
-
|
|
2337
|
+
BN6.prototype.toRed = function toRed(ctx) {
|
|
2339
2338
|
assert(!this.red, "Already a number in reduction context");
|
|
2340
2339
|
assert(this.negative === 0, "red works only with positives");
|
|
2341
2340
|
return ctx.convertTo(this)._forceRed(ctx);
|
|
2342
2341
|
};
|
|
2343
|
-
|
|
2342
|
+
BN6.prototype.fromRed = function fromRed() {
|
|
2344
2343
|
assert(this.red, "fromRed works only with numbers in reduction context");
|
|
2345
2344
|
return this.red.convertFrom(this);
|
|
2346
2345
|
};
|
|
2347
|
-
|
|
2346
|
+
BN6.prototype._forceRed = function _forceRed(ctx) {
|
|
2348
2347
|
this.red = ctx;
|
|
2349
2348
|
return this;
|
|
2350
2349
|
};
|
|
2351
|
-
|
|
2350
|
+
BN6.prototype.forceRed = function forceRed(ctx) {
|
|
2352
2351
|
assert(!this.red, "Already a number in reduction context");
|
|
2353
2352
|
return this._forceRed(ctx);
|
|
2354
2353
|
};
|
|
2355
|
-
|
|
2354
|
+
BN6.prototype.redAdd = function redAdd(num) {
|
|
2356
2355
|
assert(this.red, "redAdd works only with red numbers");
|
|
2357
2356
|
return this.red.add(this, num);
|
|
2358
2357
|
};
|
|
2359
|
-
|
|
2358
|
+
BN6.prototype.redIAdd = function redIAdd(num) {
|
|
2360
2359
|
assert(this.red, "redIAdd works only with red numbers");
|
|
2361
2360
|
return this.red.iadd(this, num);
|
|
2362
2361
|
};
|
|
2363
|
-
|
|
2362
|
+
BN6.prototype.redSub = function redSub(num) {
|
|
2364
2363
|
assert(this.red, "redSub works only with red numbers");
|
|
2365
2364
|
return this.red.sub(this, num);
|
|
2366
2365
|
};
|
|
2367
|
-
|
|
2366
|
+
BN6.prototype.redISub = function redISub(num) {
|
|
2368
2367
|
assert(this.red, "redISub works only with red numbers");
|
|
2369
2368
|
return this.red.isub(this, num);
|
|
2370
2369
|
};
|
|
2371
|
-
|
|
2370
|
+
BN6.prototype.redShl = function redShl(num) {
|
|
2372
2371
|
assert(this.red, "redShl works only with red numbers");
|
|
2373
2372
|
return this.red.shl(this, num);
|
|
2374
2373
|
};
|
|
2375
|
-
|
|
2374
|
+
BN6.prototype.redMul = function redMul(num) {
|
|
2376
2375
|
assert(this.red, "redMul works only with red numbers");
|
|
2377
2376
|
this.red._verify2(this, num);
|
|
2378
2377
|
return this.red.mul(this, num);
|
|
2379
2378
|
};
|
|
2380
|
-
|
|
2379
|
+
BN6.prototype.redIMul = function redIMul(num) {
|
|
2381
2380
|
assert(this.red, "redMul works only with red numbers");
|
|
2382
2381
|
this.red._verify2(this, num);
|
|
2383
2382
|
return this.red.imul(this, num);
|
|
2384
2383
|
};
|
|
2385
|
-
|
|
2384
|
+
BN6.prototype.redSqr = function redSqr() {
|
|
2386
2385
|
assert(this.red, "redSqr works only with red numbers");
|
|
2387
2386
|
this.red._verify1(this);
|
|
2388
2387
|
return this.red.sqr(this);
|
|
2389
2388
|
};
|
|
2390
|
-
|
|
2389
|
+
BN6.prototype.redISqr = function redISqr() {
|
|
2391
2390
|
assert(this.red, "redISqr works only with red numbers");
|
|
2392
2391
|
this.red._verify1(this);
|
|
2393
2392
|
return this.red.isqr(this);
|
|
2394
2393
|
};
|
|
2395
|
-
|
|
2394
|
+
BN6.prototype.redSqrt = function redSqrt() {
|
|
2396
2395
|
assert(this.red, "redSqrt works only with red numbers");
|
|
2397
2396
|
this.red._verify1(this);
|
|
2398
2397
|
return this.red.sqrt(this);
|
|
2399
2398
|
};
|
|
2400
|
-
|
|
2399
|
+
BN6.prototype.redInvm = function redInvm() {
|
|
2401
2400
|
assert(this.red, "redInvm works only with red numbers");
|
|
2402
2401
|
this.red._verify1(this);
|
|
2403
2402
|
return this.red.invm(this);
|
|
2404
2403
|
};
|
|
2405
|
-
|
|
2404
|
+
BN6.prototype.redNeg = function redNeg() {
|
|
2406
2405
|
assert(this.red, "redNeg works only with red numbers");
|
|
2407
2406
|
this.red._verify1(this);
|
|
2408
2407
|
return this.red.neg(this);
|
|
2409
2408
|
};
|
|
2410
|
-
|
|
2409
|
+
BN6.prototype.redPow = function redPow(num) {
|
|
2411
2410
|
assert(this.red && !num.red, "redPow(normalNum)");
|
|
2412
2411
|
this.red._verify1(this);
|
|
2413
2412
|
return this.red.pow(this, num);
|
|
@@ -2420,13 +2419,13 @@ var require_bn = __commonJS({
|
|
|
2420
2419
|
};
|
|
2421
2420
|
function MPrime(name, p) {
|
|
2422
2421
|
this.name = name;
|
|
2423
|
-
this.p = new
|
|
2422
|
+
this.p = new BN6(p, 16);
|
|
2424
2423
|
this.n = this.p.bitLength();
|
|
2425
|
-
this.k = new
|
|
2424
|
+
this.k = new BN6(1).iushln(this.n).isub(this.p);
|
|
2426
2425
|
this.tmp = this._tmp();
|
|
2427
2426
|
}
|
|
2428
2427
|
MPrime.prototype._tmp = function _tmp() {
|
|
2429
|
-
var tmp = new
|
|
2428
|
+
var tmp = new BN6(null);
|
|
2430
2429
|
tmp.words = new Array(Math.ceil(this.n / 13));
|
|
2431
2430
|
return tmp;
|
|
2432
2431
|
};
|
|
@@ -2552,7 +2551,7 @@ var require_bn = __commonJS({
|
|
|
2552
2551
|
}
|
|
2553
2552
|
return num;
|
|
2554
2553
|
};
|
|
2555
|
-
|
|
2554
|
+
BN6._prime = function prime(name) {
|
|
2556
2555
|
if (primes[name]) return primes[name];
|
|
2557
2556
|
var prime2;
|
|
2558
2557
|
if (name === "k256") {
|
|
@@ -2571,7 +2570,7 @@ var require_bn = __commonJS({
|
|
|
2571
2570
|
};
|
|
2572
2571
|
function Red(m) {
|
|
2573
2572
|
if (typeof m === "string") {
|
|
2574
|
-
var prime =
|
|
2573
|
+
var prime = BN6._prime(m);
|
|
2575
2574
|
this.m = prime.p;
|
|
2576
2575
|
this.prime = prime;
|
|
2577
2576
|
} else {
|
|
@@ -2657,7 +2656,7 @@ var require_bn = __commonJS({
|
|
|
2657
2656
|
var mod3 = this.m.andln(3);
|
|
2658
2657
|
assert(mod3 % 2 === 1);
|
|
2659
2658
|
if (mod3 === 3) {
|
|
2660
|
-
var pow2 = this.m.add(new
|
|
2659
|
+
var pow2 = this.m.add(new BN6(1)).iushrn(2);
|
|
2661
2660
|
return this.pow(a, pow2);
|
|
2662
2661
|
}
|
|
2663
2662
|
var q = this.m.subn(1);
|
|
@@ -2667,11 +2666,11 @@ var require_bn = __commonJS({
|
|
|
2667
2666
|
q.iushrn(1);
|
|
2668
2667
|
}
|
|
2669
2668
|
assert(!q.isZero());
|
|
2670
|
-
var one = new
|
|
2669
|
+
var one = new BN6(1).toRed(this);
|
|
2671
2670
|
var nOne = one.redNeg();
|
|
2672
2671
|
var lpow = this.m.subn(1).iushrn(1);
|
|
2673
2672
|
var z = this.m.bitLength();
|
|
2674
|
-
z = new
|
|
2673
|
+
z = new BN6(2 * z * z).toRed(this);
|
|
2675
2674
|
while (this.pow(z, lpow).cmp(nOne) !== 0) {
|
|
2676
2675
|
z.redIAdd(nOne);
|
|
2677
2676
|
}
|
|
@@ -2685,7 +2684,7 @@ var require_bn = __commonJS({
|
|
|
2685
2684
|
tmp = tmp.redSqr();
|
|
2686
2685
|
}
|
|
2687
2686
|
assert(i < m);
|
|
2688
|
-
var b = this.pow(c, new
|
|
2687
|
+
var b = this.pow(c, new BN6(1).iushln(m - i - 1));
|
|
2689
2688
|
r = r.redMul(b);
|
|
2690
2689
|
c = b.redSqr();
|
|
2691
2690
|
t = t.redMul(c);
|
|
@@ -2703,11 +2702,11 @@ var require_bn = __commonJS({
|
|
|
2703
2702
|
}
|
|
2704
2703
|
};
|
|
2705
2704
|
Red.prototype.pow = function pow2(a, num) {
|
|
2706
|
-
if (num.isZero()) return new
|
|
2705
|
+
if (num.isZero()) return new BN6(1).toRed(this);
|
|
2707
2706
|
if (num.cmpn(1) === 0) return a.clone();
|
|
2708
2707
|
var windowSize = 4;
|
|
2709
2708
|
var wnd = new Array(1 << windowSize);
|
|
2710
|
-
wnd[0] = new
|
|
2709
|
+
wnd[0] = new BN6(1).toRed(this);
|
|
2711
2710
|
wnd[1] = a;
|
|
2712
2711
|
for (var i = 2; i < wnd.length; i++) {
|
|
2713
2712
|
wnd[i] = this.mul(wnd[i - 1], a);
|
|
@@ -2751,7 +2750,7 @@ var require_bn = __commonJS({
|
|
|
2751
2750
|
res.red = null;
|
|
2752
2751
|
return res;
|
|
2753
2752
|
};
|
|
2754
|
-
|
|
2753
|
+
BN6.mont = function mont(num) {
|
|
2755
2754
|
return new Mont(num);
|
|
2756
2755
|
};
|
|
2757
2756
|
function Mont(m) {
|
|
@@ -2760,7 +2759,7 @@ var require_bn = __commonJS({
|
|
|
2760
2759
|
if (this.shift % 26 !== 0) {
|
|
2761
2760
|
this.shift += 26 - this.shift % 26;
|
|
2762
2761
|
}
|
|
2763
|
-
this.r = new
|
|
2762
|
+
this.r = new BN6(1).iushln(this.shift);
|
|
2764
2763
|
this.r2 = this.imod(this.r.sqr());
|
|
2765
2764
|
this.rinv = this.r._invmp(this.m);
|
|
2766
2765
|
this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
|
|
@@ -2794,7 +2793,7 @@ var require_bn = __commonJS({
|
|
|
2794
2793
|
return res._forceRed(this);
|
|
2795
2794
|
};
|
|
2796
2795
|
Mont.prototype.mul = function mul2(a, b) {
|
|
2797
|
-
if (a.isZero() || b.isZero()) return new
|
|
2796
|
+
if (a.isZero() || b.isZero()) return new BN6(0)._forceRed(this);
|
|
2798
2797
|
var t = a.mul(b);
|
|
2799
2798
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
2800
2799
|
var u = t.isub(c).iushrn(this.shift);
|
|
@@ -4978,193 +4977,365 @@ LN10 = new Decimal(LN10);
|
|
|
4978
4977
|
PI = new Decimal(PI);
|
|
4979
4978
|
var decimal_default = Decimal;
|
|
4980
4979
|
|
|
4981
|
-
// src/
|
|
4982
|
-
var
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
var
|
|
4986
|
-
var
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
*/
|
|
5003
|
-
static isSUI(obj) {
|
|
5004
|
-
const arg = _CoinUtils.getCoinTypeArg(obj);
|
|
5005
|
-
return arg ? _CoinUtils.getCoinSymbol(arg) === "SUI" : false;
|
|
4980
|
+
// src/client.ts
|
|
4981
|
+
var import_bn5 = __toESM(require_bn());
|
|
4982
|
+
|
|
4983
|
+
// src/transaction/aftermath.ts
|
|
4984
|
+
var import_bn = __toESM(require_bn());
|
|
4985
|
+
var Aftermath = class {
|
|
4986
|
+
constructor(env) {
|
|
4987
|
+
if (env !== 0 /* Mainnet */) {
|
|
4988
|
+
throw new Error("Aftermath only supported on mainnet");
|
|
4989
|
+
}
|
|
4990
|
+
this.slippage = "900000000000000000";
|
|
4991
|
+
this.poolRegistry = "0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae";
|
|
4992
|
+
this.protocolFeeVault = "0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4";
|
|
4993
|
+
this.treasury = "0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce";
|
|
4994
|
+
this.insuranceFund = "0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b";
|
|
4995
|
+
this.referrealVault = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
4996
|
+
}
|
|
4997
|
+
amountLimit(exportAmountOut) {
|
|
4998
|
+
return Number(
|
|
4999
|
+
new import_bn.default(exportAmountOut).mul(new import_bn.default(this.slippage)).div(new import_bn.default("1000000000000000000")).toString()
|
|
5000
|
+
);
|
|
5006
5001
|
}
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5002
|
+
swap(client, txb, path, inputCoin) {
|
|
5003
|
+
return __async(this, null, function* () {
|
|
5004
|
+
const { direction, from, target } = path;
|
|
5005
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
5006
|
+
if (path.extendedDetails == null) {
|
|
5007
|
+
throw new Error("Extended details not supported");
|
|
5008
|
+
} else {
|
|
5009
|
+
if (path.extendedDetails.aftermathLpSupplyType == null) {
|
|
5010
|
+
throw new Error("LP supply type not supported");
|
|
5011
|
+
}
|
|
5012
|
+
}
|
|
5013
|
+
const args = [
|
|
5014
|
+
txb.object(path.id),
|
|
5015
|
+
txb.object(this.poolRegistry),
|
|
5016
|
+
txb.object(this.protocolFeeVault),
|
|
5017
|
+
txb.object(this.treasury),
|
|
5018
|
+
txb.object(this.insuranceFund),
|
|
5019
|
+
txb.object(this.referrealVault),
|
|
5020
|
+
txb.pure.u64(this.amountLimit(path.amountOut)),
|
|
5021
|
+
txb.pure.u64(this.slippage),
|
|
5022
|
+
inputCoin
|
|
5023
|
+
];
|
|
5024
|
+
const res = txb.moveCall({
|
|
5025
|
+
target: `${client.publishedAt()}::aftermath::${func}`,
|
|
5026
|
+
typeArguments: [
|
|
5027
|
+
coinAType,
|
|
5028
|
+
coinBType,
|
|
5029
|
+
path.extendedDetails.aftermathLpSupplyType
|
|
5030
|
+
],
|
|
5031
|
+
arguments: args
|
|
5032
|
+
});
|
|
5033
|
+
return res;
|
|
5034
|
+
});
|
|
5015
5035
|
}
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5036
|
+
};
|
|
5037
|
+
|
|
5038
|
+
// src/transaction/deepbook_v2.ts
|
|
5039
|
+
var DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
5040
|
+
var DeepbookV2 = class {
|
|
5041
|
+
constructor(env) {
|
|
5042
|
+
if (env !== 0 /* Mainnet */) {
|
|
5043
|
+
throw new Error("Aftermath only supported on mainnet");
|
|
5044
|
+
}
|
|
5024
5045
|
}
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5046
|
+
getAccountCap(client, owner) {
|
|
5047
|
+
return __async(this, null, function* () {
|
|
5048
|
+
let limit = 50;
|
|
5049
|
+
let cursor = null;
|
|
5050
|
+
while (true) {
|
|
5051
|
+
const ownedObjects = client.getOwnedObjects({
|
|
5052
|
+
owner,
|
|
5053
|
+
cursor,
|
|
5054
|
+
limit,
|
|
5055
|
+
filter: {
|
|
5056
|
+
MoveModule: {
|
|
5057
|
+
package: DEEPBOOK_PACKAGE_ID,
|
|
5058
|
+
module: "custodian_v2"
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
});
|
|
5062
|
+
if (ownedObjects != null && ownedObjects.data != null) {
|
|
5063
|
+
if (ownedObjects.data.length !== 0) {
|
|
5064
|
+
return ownedObjects.data[0].data.objectId;
|
|
5065
|
+
}
|
|
5066
|
+
if (ownedObjects.data.length < 50) {
|
|
5067
|
+
break;
|
|
5068
|
+
}
|
|
5069
|
+
} else {
|
|
5070
|
+
break;
|
|
5071
|
+
}
|
|
5037
5072
|
}
|
|
5073
|
+
return null;
|
|
5038
5074
|
});
|
|
5039
|
-
return balanceTotal;
|
|
5040
|
-
}
|
|
5041
|
-
/**
|
|
5042
|
-
* Get the ID of a SuiMoveObject.
|
|
5043
|
-
*
|
|
5044
|
-
* @param obj The SuiMoveObject to get the ID from.
|
|
5045
|
-
* @returns The ID of the SuiMoveObject.
|
|
5046
|
-
*/
|
|
5047
|
-
static getID(obj) {
|
|
5048
|
-
return obj.fields.id.id;
|
|
5049
5075
|
}
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5076
|
+
getOrCreateAccountCap(txb, client, owner) {
|
|
5077
|
+
return __async(this, null, function* () {
|
|
5078
|
+
let accountCapStr = yield this.getAccountCap(client, owner);
|
|
5079
|
+
if (accountCapStr !== null) {
|
|
5080
|
+
return {
|
|
5081
|
+
accountCap: txb.object(accountCapStr),
|
|
5082
|
+
isCreate: false
|
|
5083
|
+
};
|
|
5084
|
+
}
|
|
5085
|
+
const accountCap = txb.moveCall({
|
|
5086
|
+
target: `${DEEPBOOK_PACKAGE_ID}::clob_v2::create_account`,
|
|
5087
|
+
typeArguments: [],
|
|
5088
|
+
arguments: []
|
|
5089
|
+
});
|
|
5090
|
+
return {
|
|
5091
|
+
accountCap,
|
|
5092
|
+
isCreate: true
|
|
5093
|
+
};
|
|
5094
|
+
});
|
|
5058
5095
|
}
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5096
|
+
swap(client, txb, path, inputCoin) {
|
|
5097
|
+
return __async(this, null, function* () {
|
|
5098
|
+
const { direction, from, target } = path;
|
|
5099
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
5100
|
+
const accountCapRes = yield this.getOrCreateAccountCap(
|
|
5101
|
+
txb,
|
|
5102
|
+
client.client,
|
|
5103
|
+
client.signer
|
|
5104
|
+
);
|
|
5105
|
+
const args = [
|
|
5106
|
+
txb.object(path.id),
|
|
5107
|
+
inputCoin,
|
|
5108
|
+
accountCapRes.accountCap,
|
|
5109
|
+
txb.object(CLOCK_ADDRESS)
|
|
5110
|
+
];
|
|
5111
|
+
const res = txb.moveCall({
|
|
5112
|
+
target: `${client.publishedAt()}::deepbook::${func}`,
|
|
5113
|
+
typeArguments: [coinAType, coinBType],
|
|
5114
|
+
arguments: args
|
|
5115
|
+
});
|
|
5116
|
+
if (accountCapRes.isCreate) {
|
|
5117
|
+
txb.transferObjects([accountCapRes.accountCap], client.signer);
|
|
5071
5118
|
}
|
|
5119
|
+
return res;
|
|
5072
5120
|
});
|
|
5073
|
-
return coins;
|
|
5074
5121
|
}
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5122
|
+
};
|
|
5123
|
+
|
|
5124
|
+
// src/transaction/kriya_v2.ts
|
|
5125
|
+
var KriyaV2 = class {
|
|
5126
|
+
constructor(env) {
|
|
5127
|
+
if (env !== 0 /* Mainnet */) {
|
|
5128
|
+
throw new Error("Kriya amm only supported on mainnet");
|
|
5129
|
+
}
|
|
5083
5130
|
}
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
const amountArray = selectedResult.selectedCoins.map((item) => item.balance.toString());
|
|
5097
|
-
return { objectArray, remainCoins, amountArray };
|
|
5131
|
+
swap(client, txb, path, inputCoin) {
|
|
5132
|
+
return __async(this, null, function* () {
|
|
5133
|
+
const { direction, from, target } = path;
|
|
5134
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
5135
|
+
const args = [txb.object(path.id), inputCoin];
|
|
5136
|
+
const res = txb.moveCall({
|
|
5137
|
+
target: `${client.publishedAt()}::kriya_amm::${func}`,
|
|
5138
|
+
typeArguments: [coinAType, coinBType],
|
|
5139
|
+
arguments: args
|
|
5140
|
+
});
|
|
5141
|
+
return res;
|
|
5142
|
+
});
|
|
5098
5143
|
}
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
*/
|
|
5107
|
-
static selectCoinAssetGreaterThanOrEqual(coins, amount, exclude = []) {
|
|
5108
|
-
const sortedCoins = _CoinUtils.sortByBalance(coins.filter((c) => !exclude.includes(c.coinObjectId)));
|
|
5109
|
-
const total = _CoinUtils.calculateTotalBalance(sortedCoins);
|
|
5110
|
-
if (total < amount) {
|
|
5111
|
-
return { selectedCoins: [], remainingCoins: sortedCoins };
|
|
5112
|
-
}
|
|
5113
|
-
if (total === amount) {
|
|
5114
|
-
return { selectedCoins: sortedCoins, remainingCoins: [] };
|
|
5115
|
-
}
|
|
5116
|
-
let sum2 = BigInt(0);
|
|
5117
|
-
const selectedCoins = [];
|
|
5118
|
-
const remainingCoins = [...sortedCoins];
|
|
5119
|
-
while (sum2 < total) {
|
|
5120
|
-
const target = amount - sum2;
|
|
5121
|
-
const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex((c) => c.balance >= target);
|
|
5122
|
-
if (coinWithSmallestSufficientBalanceIndex !== -1) {
|
|
5123
|
-
selectedCoins.push(remainingCoins[coinWithSmallestSufficientBalanceIndex]);
|
|
5124
|
-
remainingCoins.splice(coinWithSmallestSufficientBalanceIndex, 1);
|
|
5125
|
-
break;
|
|
5126
|
-
}
|
|
5127
|
-
const coinWithLargestBalance = remainingCoins.pop();
|
|
5128
|
-
if (coinWithLargestBalance.balance > 0) {
|
|
5129
|
-
selectedCoins.push(coinWithLargestBalance);
|
|
5130
|
-
sum2 += coinWithLargestBalance.balance;
|
|
5131
|
-
}
|
|
5144
|
+
};
|
|
5145
|
+
|
|
5146
|
+
// src/transaction/flowx_v2.ts
|
|
5147
|
+
var FlowxV2 = class {
|
|
5148
|
+
constructor(env) {
|
|
5149
|
+
if (env !== 0 /* Mainnet */) {
|
|
5150
|
+
throw new Error("Flowx only supported on mainnet");
|
|
5132
5151
|
}
|
|
5133
|
-
|
|
5152
|
+
this.container = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
5134
5153
|
}
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5154
|
+
swap(client, txb, path, inputCoin) {
|
|
5155
|
+
return __async(this, null, function* () {
|
|
5156
|
+
const { direction, from, target } = path;
|
|
5157
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
5158
|
+
const args = [txb.object(this.container), inputCoin];
|
|
5159
|
+
const res = txb.moveCall({
|
|
5160
|
+
target: `${client.publishedAt()}::flowx_amm::${func}`,
|
|
5161
|
+
typeArguments: [coinAType, coinBType],
|
|
5162
|
+
arguments: args
|
|
5163
|
+
});
|
|
5164
|
+
return res;
|
|
5165
|
+
});
|
|
5143
5166
|
}
|
|
5144
|
-
|
|
5145
|
-
|
|
5167
|
+
};
|
|
5168
|
+
|
|
5169
|
+
// src/transaction/turbos.ts
|
|
5170
|
+
var Turbos = class {
|
|
5171
|
+
constructor(env) {
|
|
5172
|
+
if (env !== 0 /* Mainnet */) {
|
|
5173
|
+
throw new Error("Turbos only supported on mainnet");
|
|
5174
|
+
}
|
|
5175
|
+
this.versioned = "0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f";
|
|
5146
5176
|
}
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5177
|
+
swap(client, txb, path, inputCoin) {
|
|
5178
|
+
return __async(this, null, function* () {
|
|
5179
|
+
const { direction, from, target } = path;
|
|
5180
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
5181
|
+
if (path.extendedDetails == null) {
|
|
5182
|
+
throw new Error("Extended details not supported");
|
|
5183
|
+
} else {
|
|
5184
|
+
if (path.extendedDetails.turbosFeeType == null) {
|
|
5185
|
+
throw new Error("Turbos fee type not supported");
|
|
5186
|
+
}
|
|
5187
|
+
}
|
|
5188
|
+
const args = [
|
|
5189
|
+
txb.object(path.id),
|
|
5190
|
+
inputCoin,
|
|
5191
|
+
txb.object(CLOCK_ADDRESS),
|
|
5192
|
+
txb.object(this.versioned)
|
|
5193
|
+
];
|
|
5194
|
+
const res = txb.moveCall({
|
|
5195
|
+
target: `${client.publishedAt()}::turbos::${func}`,
|
|
5196
|
+
typeArguments: [coinAType, coinBType, path.extendedDetails.turbosFeeType],
|
|
5197
|
+
arguments: args
|
|
5198
|
+
});
|
|
5199
|
+
return res;
|
|
5200
|
+
});
|
|
5155
5201
|
}
|
|
5156
5202
|
};
|
|
5157
5203
|
|
|
5158
|
-
// src/
|
|
5159
|
-
var
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5204
|
+
// src/transaction/cetus.ts
|
|
5205
|
+
var Cetus = class {
|
|
5206
|
+
constructor(env, partner) {
|
|
5207
|
+
this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
5208
|
+
this.partner = partner != null ? partner : "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b";
|
|
5209
|
+
}
|
|
5210
|
+
flash_swap(client, txb, path, by_amount_in) {
|
|
5211
|
+
const { direction, from, target } = path;
|
|
5212
|
+
const [func, coinAType, coinBType] = direction ? ["flash_swap_a2b", from, target] : ["flash_swap_b2a", target, from];
|
|
5213
|
+
let amount = by_amount_in ? path.amountIn : path.amountOut;
|
|
5214
|
+
const args = [
|
|
5215
|
+
txb.object(this.globalConfig),
|
|
5216
|
+
txb.object(path.id),
|
|
5217
|
+
txb.object(this.partner),
|
|
5218
|
+
txb.pure.u64(amount),
|
|
5219
|
+
txb.pure.bool(by_amount_in),
|
|
5220
|
+
txb.object(CLOCK_ADDRESS)
|
|
5221
|
+
];
|
|
5222
|
+
const res = txb.moveCall({
|
|
5223
|
+
target: `${client.publishedAt()}::cetus::${func}`,
|
|
5224
|
+
typeArguments: [coinAType, coinBType],
|
|
5225
|
+
arguments: args
|
|
5226
|
+
});
|
|
5227
|
+
return {
|
|
5228
|
+
targetCoin: res[0],
|
|
5229
|
+
flashReceipt: res[1],
|
|
5230
|
+
payAmount: res[2]
|
|
5231
|
+
};
|
|
5165
5232
|
}
|
|
5166
|
-
|
|
5167
|
-
|
|
5233
|
+
repay_flash_swap(client, txb, path, inputCoin, receipt) {
|
|
5234
|
+
const { direction, from, target } = path;
|
|
5235
|
+
const [func, coinAType, coinBType] = direction ? ["repay_flash_swap_a2b", from, target] : ["repay_flash_swap_b2a", target, from];
|
|
5236
|
+
const args = [
|
|
5237
|
+
txb.object(this.globalConfig),
|
|
5238
|
+
txb.object(path.id),
|
|
5239
|
+
txb.object(this.partner),
|
|
5240
|
+
inputCoin,
|
|
5241
|
+
receipt
|
|
5242
|
+
];
|
|
5243
|
+
const res = txb.moveCall({
|
|
5244
|
+
target: `${client.publishedAt()}::cetus::${func}`,
|
|
5245
|
+
typeArguments: [coinAType, coinBType],
|
|
5246
|
+
arguments: args
|
|
5247
|
+
});
|
|
5248
|
+
return res[0];
|
|
5249
|
+
}
|
|
5250
|
+
swap(client, txb, path, inputCoin) {
|
|
5251
|
+
return __async(this, null, function* () {
|
|
5252
|
+
const { direction, from, target } = path;
|
|
5253
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
5254
|
+
const args = [
|
|
5255
|
+
txb.object(this.globalConfig),
|
|
5256
|
+
txb.object(path.id),
|
|
5257
|
+
txb.object(this.partner),
|
|
5258
|
+
inputCoin,
|
|
5259
|
+
txb.object(CLOCK_ADDRESS)
|
|
5260
|
+
];
|
|
5261
|
+
const res = txb.moveCall({
|
|
5262
|
+
target: `${client.publishedAt()}::cetus::${func}`,
|
|
5263
|
+
typeArguments: [coinAType, coinBType],
|
|
5264
|
+
arguments: args
|
|
5265
|
+
});
|
|
5266
|
+
return res;
|
|
5267
|
+
});
|
|
5268
|
+
}
|
|
5269
|
+
};
|
|
5270
|
+
|
|
5271
|
+
// src/const.ts
|
|
5272
|
+
var import_bn2 = __toESM(require_bn());
|
|
5273
|
+
var CoinInfoAddress = "0x1::coin::CoinInfo";
|
|
5274
|
+
var CoinStoreAddress = "0x1::coin::CoinStore";
|
|
5275
|
+
var SuiZeroCoinFn = "0x2::coin::zero";
|
|
5276
|
+
var CETUS_MODULE = "cetus";
|
|
5277
|
+
var DEEPBOOK_MODULE = "deepbook";
|
|
5278
|
+
var KRIYA_MODULE = "kriya";
|
|
5279
|
+
var UTILS_MODULE = "utils";
|
|
5280
|
+
var POOL_MODULT = "pool";
|
|
5281
|
+
var PAY_MODULE = "pay";
|
|
5282
|
+
var FLOWX_AMM_MODULE = "flowx_amm";
|
|
5283
|
+
var TURBOS_MODULE = "turbos";
|
|
5284
|
+
var AFTERMATH_MODULE = "aftermath";
|
|
5285
|
+
var DEEPBOOK_CUSTODIAN_V2_MODULE = "custodian_v2";
|
|
5286
|
+
var DEEPBOOK_CLOB_V2_MODULE = "clob_v2";
|
|
5287
|
+
var FlashSwapFunc = "flash_swap";
|
|
5288
|
+
var FlashSwapWithPartnerFunc = "flash_swap_with_partner";
|
|
5289
|
+
var RepayFalshSwapFunc = "repay_flash_swap";
|
|
5290
|
+
var RepayFlashSwapWithPartnerFunc = "repay_flash_swap_with_partner";
|
|
5291
|
+
var FlashSwapA2BFunc = "flash_swap_a2b";
|
|
5292
|
+
var FlashSwapB2AFunc = "flash_swap_b2a";
|
|
5293
|
+
var FlashSwapWithPartnerA2BFunc = "flash_swap_with_partner_a2b";
|
|
5294
|
+
var FlashSwapWithPartnerB2AFunc = "flash_swap_with_partner_b2a";
|
|
5295
|
+
var REPAY_FLASH_SWAP_A2B_FUNC = "repay_flash_swap_a2b";
|
|
5296
|
+
var REPAY_FLASH_SWAP_B2A_FUNC = "repay_flash_swap_b2a";
|
|
5297
|
+
var REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC = "repay_flash_swap_with_partner_a2b";
|
|
5298
|
+
var REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC = "repay_flash_swap_with_partner_b2a";
|
|
5299
|
+
var SWAP_A2B_FUNC = "swap_a2b";
|
|
5300
|
+
var SWAP_B2A_FUNC = "swap_b2a";
|
|
5301
|
+
var TRANSFER_OR_DESTORY_COIN_FUNC = "transfer_or_destroy_coin";
|
|
5302
|
+
var CHECK_COINS_THRESHOLD_FUNC = "check_coins_threshold";
|
|
5303
|
+
var JOIN_FUNC = "join_vec";
|
|
5304
|
+
var TRANSFER_ACCOUNT_CAP = "transfer_account_cap";
|
|
5305
|
+
var DEEPBOOK_PACKAGE_ID2 = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
5306
|
+
var DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
5307
|
+
var CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
|
|
5308
|
+
var MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
|
|
5309
|
+
var TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
5310
|
+
var ZERO = new import_bn2.default(0);
|
|
5311
|
+
var ONE = new import_bn2.default(1);
|
|
5312
|
+
var TWO = new import_bn2.default(2);
|
|
5313
|
+
var U128 = TWO.pow(new import_bn2.default(128));
|
|
5314
|
+
var U64_MAX_BN = new import_bn2.default("18446744073709551615");
|
|
5315
|
+
var U64_MAX = "18446744073709551615";
|
|
5316
|
+
var TEN_POW_NINE = 1e9;
|
|
5317
|
+
var MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
5318
|
+
var TESTNET_FLOWX_AMM_CONTAINER_ID = "";
|
|
5319
|
+
var TURBOS_VERSIONED = "0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f";
|
|
5320
|
+
var MAINNET_AFTERMATH_REGISTRY_ID = "0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae";
|
|
5321
|
+
var TESTNET_AFTERMATH_REGISTRY_ID = "";
|
|
5322
|
+
var MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4";
|
|
5323
|
+
var TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "";
|
|
5324
|
+
var MAINNET_AFTERMATH_TREASURY_ID = "0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce";
|
|
5325
|
+
var TESTNET_AFTERMATH_TREASURY_ID = "";
|
|
5326
|
+
var MAINNET_AFTERMATH_INSURANCE_FUND_ID = "0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b";
|
|
5327
|
+
var TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
|
|
5328
|
+
var MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
5329
|
+
var TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
|
|
5330
|
+
var EQUAL = 0;
|
|
5331
|
+
var LESS_THAN = 1;
|
|
5332
|
+
var GREATER_THAN = 2;
|
|
5333
|
+
function cmp(a, b) {
|
|
5334
|
+
if (a === b) {
|
|
5335
|
+
return EQUAL;
|
|
5336
|
+
}
|
|
5337
|
+
if (a < b) {
|
|
5338
|
+
return LESS_THAN;
|
|
5168
5339
|
}
|
|
5169
5340
|
return GREATER_THAN;
|
|
5170
5341
|
}
|
|
@@ -5262,1060 +5433,199 @@ function createTarget(packageName, moduleName, functionName) {
|
|
|
5262
5433
|
return `${packageName}::${moduleName}::${functionName}`;
|
|
5263
5434
|
}
|
|
5264
5435
|
|
|
5265
|
-
// src/
|
|
5266
|
-
var
|
|
5267
|
-
var
|
|
5268
|
-
var
|
|
5269
|
-
var
|
|
5270
|
-
var
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
var DEEPBOOK_MODULE = "deepbook";
|
|
5281
|
-
var KRIYA_MODULE = "kriya";
|
|
5282
|
-
var UTILS_MODULE = "utils";
|
|
5283
|
-
var POOL_MODULT = "pool";
|
|
5284
|
-
var PAY_MODULE = "pay";
|
|
5285
|
-
var FLOWX_AMM_MODULE = "flowx_amm";
|
|
5286
|
-
var TURBOS_MODULE = "turbos";
|
|
5287
|
-
var AFTERMATH_MODULE = "aftermath";
|
|
5288
|
-
var DEEPBOOK_CUSTODIAN_V2_MODULE = "custodian_v2";
|
|
5289
|
-
var DEEPBOOK_CLOB_V2_MODULE = "clob_v2";
|
|
5290
|
-
var FlashSwapFunc = "flash_swap";
|
|
5291
|
-
var FlashSwapWithPartnerFunc = "flash_swap_with_partner";
|
|
5292
|
-
var RepayFalshSwapFunc = "repay_flash_swap";
|
|
5293
|
-
var RepayFlashSwapWithPartnerFunc = "repay_flash_swap_with_partner";
|
|
5294
|
-
var FlashSwapA2BFunc = "flash_swap_a2b";
|
|
5295
|
-
var FlashSwapB2AFunc = "flash_swap_b2a";
|
|
5296
|
-
var FlashSwapWithPartnerA2BFunc = "flash_swap_with_partner_a2b";
|
|
5297
|
-
var FlashSwapWithPartnerB2AFunc = "flash_swap_with_partner_b2a";
|
|
5298
|
-
var REPAY_FLASH_SWAP_A2B_FUNC = "repay_flash_swap_a2b";
|
|
5299
|
-
var REPAY_FLASH_SWAP_B2A_FUNC = "repay_flash_swap_b2a";
|
|
5300
|
-
var REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC = "repay_flash_swap_with_partner_a2b";
|
|
5301
|
-
var REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC = "repay_flash_swap_with_partner_b2a";
|
|
5302
|
-
var SWAP_A2B_FUNC = "swap_a2b";
|
|
5303
|
-
var SWAP_B2A_FUNC = "swap_b2a";
|
|
5304
|
-
var TRANSFER_OR_DESTORY_COIN_FUNC = "transfer_or_destroy_coin";
|
|
5305
|
-
var CHECK_COINS_THRESHOLD_FUNC = "check_coins_threshold";
|
|
5306
|
-
var JOIN_FUNC = "join_vec";
|
|
5307
|
-
var TRANSFER_ACCOUNT_CAP = "transfer_account_cap";
|
|
5308
|
-
var DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
5309
|
-
var DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
|
|
5310
|
-
var CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
|
|
5311
|
-
var MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
|
|
5312
|
-
var TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
|
|
5313
|
-
var ZERO = new import_bn.default(0);
|
|
5314
|
-
var ONE = new import_bn.default(1);
|
|
5315
|
-
var TWO = new import_bn.default(2);
|
|
5316
|
-
var U128 = TWO.pow(new import_bn.default(128));
|
|
5317
|
-
var U64_MAX_BN = new import_bn.default("18446744073709551615");
|
|
5318
|
-
var U64_MAX = "18446744073709551615";
|
|
5319
|
-
var TEN_POW_NINE = 1e9;
|
|
5320
|
-
var MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
|
|
5321
|
-
var TESTNET_FLOWX_AMM_CONTAINER_ID = "";
|
|
5322
|
-
var TURBOS_VERSIONED = "0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f";
|
|
5323
|
-
var MAINNET_AFTERMATH_REGISTRY_ID = "0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae";
|
|
5324
|
-
var TESTNET_AFTERMATH_REGISTRY_ID = "";
|
|
5325
|
-
var MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4";
|
|
5326
|
-
var TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "";
|
|
5327
|
-
var MAINNET_AFTERMATH_TREASURY_ID = "0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce";
|
|
5328
|
-
var TESTNET_AFTERMATH_TREASURY_ID = "";
|
|
5329
|
-
var MAINNET_AFTERMATH_INSURANCE_FUND_ID = "0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b";
|
|
5330
|
-
var TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
|
|
5331
|
-
var MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
5332
|
-
var TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
|
|
5333
|
-
|
|
5334
|
-
// src/errors.ts
|
|
5335
|
-
function getAggregatorServerErrorMessage(code) {
|
|
5336
|
-
switch (code) {
|
|
5337
|
-
case 1e4 /* CalculateError */:
|
|
5338
|
-
return "Calculate error";
|
|
5339
|
-
case 10001 /* NumberTooLarge */:
|
|
5340
|
-
return "Input number too large can not fit in target type";
|
|
5341
|
-
case 10002 /* NoRouter */:
|
|
5342
|
-
return "No router";
|
|
5343
|
-
case 10003 /* InsufficientLiquidity */:
|
|
5344
|
-
return "Insufficient Liquidity";
|
|
5345
|
-
default:
|
|
5346
|
-
return "Unknown error";
|
|
5436
|
+
// src/types/CoinAssist.ts
|
|
5437
|
+
var COIN_TYPE = "0x2::coin::Coin";
|
|
5438
|
+
var COIN_TYPE_ARG_REGEX = /^0x2::coin::Coin<(.+)>$/;
|
|
5439
|
+
var GAS_TYPE_ARG = "0x2::sui::SUI";
|
|
5440
|
+
var GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
5441
|
+
var CoinUtils = class _CoinUtils {
|
|
5442
|
+
/**
|
|
5443
|
+
* Get the coin type argument from a SuiMoveObject.
|
|
5444
|
+
*
|
|
5445
|
+
* @param obj The SuiMoveObject to get the coin type argument from.
|
|
5446
|
+
* @returns The coin type argument, or null if it is not found.
|
|
5447
|
+
*/
|
|
5448
|
+
static getCoinTypeArg(obj) {
|
|
5449
|
+
const res = obj.type.match(COIN_TYPE_ARG_REGEX);
|
|
5450
|
+
return res ? res[1] : null;
|
|
5347
5451
|
}
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
if (amount === BigInt(0) && usedCoinAsests.length === 0) {
|
|
5358
|
-
const zeroCoin = mintZeroCoin(txb, coinType);
|
|
5359
|
-
return {
|
|
5360
|
-
targetCoin: zeroCoin,
|
|
5361
|
-
isMintZeroCoin: true,
|
|
5362
|
-
targetCoinAmount: 0
|
|
5363
|
-
};
|
|
5452
|
+
/**
|
|
5453
|
+
* Get whether a SuiMoveObject is a SUI coin.
|
|
5454
|
+
*
|
|
5455
|
+
* @param obj The SuiMoveObject to check.
|
|
5456
|
+
* @returns Whether the SuiMoveObject is a SUI coin.
|
|
5457
|
+
*/
|
|
5458
|
+
static isSUI(obj) {
|
|
5459
|
+
const arg = _CoinUtils.getCoinTypeArg(obj);
|
|
5460
|
+
return arg ? _CoinUtils.getCoinSymbol(arg) === "SUI" : false;
|
|
5364
5461
|
}
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5462
|
+
/**
|
|
5463
|
+
* Get the coin symbol from a coin type argument.
|
|
5464
|
+
*
|
|
5465
|
+
* @param coinTypeArg The coin type argument to get the symbol from.
|
|
5466
|
+
* @returns The coin symbol.
|
|
5467
|
+
*/
|
|
5468
|
+
static getCoinSymbol(coinTypeArg) {
|
|
5469
|
+
return coinTypeArg.substring(coinTypeArg.lastIndexOf(":") + 1);
|
|
5371
5470
|
}
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
};
|
|
5471
|
+
/**
|
|
5472
|
+
* Get the balance of a SuiMoveObject.
|
|
5473
|
+
*
|
|
5474
|
+
* @param obj The SuiMoveObject to get the balance from.
|
|
5475
|
+
* @returns The balance of the SuiMoveObject.
|
|
5476
|
+
*/
|
|
5477
|
+
static getBalance(obj) {
|
|
5478
|
+
return BigInt(obj.fields.balance);
|
|
5381
5479
|
}
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5480
|
+
/**
|
|
5481
|
+
* Get the total balance of a list of CoinAsset objects for a given coin address.
|
|
5482
|
+
*
|
|
5483
|
+
* @param objs The list of CoinAsset objects to get the total balance for.
|
|
5484
|
+
* @param coinAddress The coin address to get the total balance for.
|
|
5485
|
+
* @returns The total balance of the CoinAsset objects for the given coin address.
|
|
5486
|
+
*/
|
|
5487
|
+
static totalBalance(objs, coinAddress) {
|
|
5488
|
+
let balanceTotal = BigInt(0);
|
|
5489
|
+
objs.forEach((obj) => {
|
|
5490
|
+
if (coinAddress === obj.coinAddress) {
|
|
5491
|
+
balanceTotal += BigInt(obj.balance);
|
|
5492
|
+
}
|
|
5493
|
+
});
|
|
5494
|
+
return balanceTotal;
|
|
5386
5495
|
}
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
mergedCoin.map((coin) => txb.object(coin))
|
|
5396
|
-
);
|
|
5496
|
+
/**
|
|
5497
|
+
* Get the ID of a SuiMoveObject.
|
|
5498
|
+
*
|
|
5499
|
+
* @param obj The SuiMoveObject to get the ID from.
|
|
5500
|
+
* @returns The ID of the SuiMoveObject.
|
|
5501
|
+
*/
|
|
5502
|
+
static getID(obj) {
|
|
5503
|
+
return obj.fields.id.id;
|
|
5397
5504
|
}
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
if (aggregatorPackage == null) {
|
|
5407
|
-
throw new AggregateError(
|
|
5408
|
-
"Aggregator package not set",
|
|
5409
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
5410
|
-
);
|
|
5411
|
-
}
|
|
5412
|
-
const aggregatorPublishedAt = aggregatorPackage.publishedAt;
|
|
5413
|
-
txb.moveCall({
|
|
5414
|
-
target: createTarget(
|
|
5415
|
-
aggregatorPublishedAt,
|
|
5416
|
-
UTILS_MODULE,
|
|
5417
|
-
TRANSFER_OR_DESTORY_COIN_FUNC
|
|
5418
|
-
),
|
|
5419
|
-
typeArguments: [coinType],
|
|
5420
|
-
arguments: [coinObject]
|
|
5421
|
-
});
|
|
5422
|
-
}
|
|
5423
|
-
function checkCoinThresholdAndMergeCoin(txb, coins, coinType, amountLimit, config2) {
|
|
5424
|
-
const aggregatorPackage = config2.getPackage(AGGREGATOR);
|
|
5425
|
-
if (aggregatorPackage == null) {
|
|
5426
|
-
throw new AggregateError(
|
|
5427
|
-
"Aggregator package not set",
|
|
5428
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
5429
|
-
);
|
|
5505
|
+
/**
|
|
5506
|
+
* Get the coin type from a coin type argument.
|
|
5507
|
+
*
|
|
5508
|
+
* @param coinTypeArg The coin type argument to get the coin type from.
|
|
5509
|
+
* @returns The coin type.
|
|
5510
|
+
*/
|
|
5511
|
+
static getCoinTypeFromArg(coinTypeArg) {
|
|
5512
|
+
return `${COIN_TYPE}<${coinTypeArg}>`;
|
|
5430
5513
|
}
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
)
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
});
|
|
5444
|
-
const zeroCoin = mintZeroCoin(txb, coinType);
|
|
5445
|
-
txb.moveCall({
|
|
5446
|
-
target: createTarget(SUI_FRAMEWORK_ADDRESS, PAY_MODULE, JOIN_FUNC),
|
|
5447
|
-
typeArguments: [coinType],
|
|
5448
|
-
arguments: [zeroCoin, vec]
|
|
5449
|
-
});
|
|
5450
|
-
return zeroCoin;
|
|
5451
|
-
}
|
|
5452
|
-
|
|
5453
|
-
// src/utils/account_cap.ts
|
|
5454
|
-
function getOrCreateAccountCap(txb, client, owner) {
|
|
5455
|
-
return __async(this, null, function* () {
|
|
5456
|
-
let accountCapStr = yield getAccountCap(client, owner);
|
|
5457
|
-
if (accountCapStr !== null) {
|
|
5458
|
-
return {
|
|
5459
|
-
accountCap: txb.object(accountCapStr),
|
|
5460
|
-
isCreate: false
|
|
5461
|
-
};
|
|
5462
|
-
}
|
|
5463
|
-
const accountCap = txb.moveCall({
|
|
5464
|
-
target: `${DEEPBOOK_PUBLISHED_AT}::${DEEPBOOK_CLOB_V2_MODULE}::create_account`,
|
|
5465
|
-
typeArguments: [],
|
|
5466
|
-
arguments: []
|
|
5467
|
-
});
|
|
5468
|
-
return {
|
|
5469
|
-
accountCap,
|
|
5470
|
-
isCreate: true
|
|
5471
|
-
};
|
|
5472
|
-
});
|
|
5473
|
-
}
|
|
5474
|
-
function getAccountCap(client, owner) {
|
|
5475
|
-
return __async(this, null, function* () {
|
|
5476
|
-
let limit = 50;
|
|
5477
|
-
let cursor = null;
|
|
5478
|
-
while (true) {
|
|
5479
|
-
const ownedObjects = client.getOwnedObjects({
|
|
5480
|
-
owner,
|
|
5481
|
-
cursor,
|
|
5482
|
-
limit,
|
|
5483
|
-
filter: {
|
|
5484
|
-
MoveModule: {
|
|
5485
|
-
package: DEEPBOOK_PACKAGE_ID,
|
|
5486
|
-
module: DEEPBOOK_CUSTODIAN_V2_MODULE
|
|
5487
|
-
}
|
|
5488
|
-
}
|
|
5489
|
-
});
|
|
5490
|
-
if (ownedObjects != null && ownedObjects.data != null) {
|
|
5491
|
-
if (ownedObjects.data.length !== 0) {
|
|
5492
|
-
return ownedObjects.data[0].data.objectId;
|
|
5493
|
-
}
|
|
5494
|
-
if (ownedObjects.data.length < 50) {
|
|
5495
|
-
break;
|
|
5496
|
-
}
|
|
5497
|
-
} else {
|
|
5498
|
-
break;
|
|
5499
|
-
}
|
|
5500
|
-
}
|
|
5501
|
-
return null;
|
|
5502
|
-
});
|
|
5503
|
-
}
|
|
5504
|
-
|
|
5505
|
-
// src/transaction/deepbook.ts
|
|
5506
|
-
function deepbookSwapMovecall(swapParams, client, txb, config2) {
|
|
5507
|
-
return __async(this, null, function* () {
|
|
5508
|
-
const accountCapRes = yield getOrCreateAccountCap(
|
|
5509
|
-
txb,
|
|
5510
|
-
client,
|
|
5511
|
-
config2.getWallet()
|
|
5512
|
-
);
|
|
5513
|
-
const accountCap = accountCapRes.accountCap;
|
|
5514
|
-
const aggregatorPackage = config2.getPackage(AGGREGATOR);
|
|
5515
|
-
if (aggregatorPackage == null) {
|
|
5516
|
-
throw new AggregateError(
|
|
5517
|
-
"Aggregator package not set",
|
|
5518
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
5519
|
-
);
|
|
5520
|
-
}
|
|
5521
|
-
const aggregatorPublishedAt = aggregatorPackage.publishedAt;
|
|
5522
|
-
if (swapParams.a2b) {
|
|
5523
|
-
if (swapParams.coinA == null) {
|
|
5524
|
-
throw new AggregateError(
|
|
5525
|
-
"coinA is required",
|
|
5526
|
-
"MissCoinA" /* MissCoinA */
|
|
5527
|
-
);
|
|
5528
|
-
}
|
|
5529
|
-
} else {
|
|
5530
|
-
if (swapParams.coinB == null) {
|
|
5531
|
-
throw new AggregateError(
|
|
5532
|
-
"coinB is required",
|
|
5533
|
-
"MissCoinB" /* MissCoinB */
|
|
5534
|
-
);
|
|
5535
|
-
}
|
|
5536
|
-
}
|
|
5537
|
-
const args = swapParams.a2b ? [
|
|
5538
|
-
txb.object(swapParams.poolId),
|
|
5539
|
-
swapParams.amount,
|
|
5540
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
5541
|
-
swapParams.coinA,
|
|
5542
|
-
accountCap,
|
|
5543
|
-
txb.pure.bool(swapParams.useFullInputCoinAmount),
|
|
5544
|
-
txb.object(CLOCK_ADDRESS)
|
|
5545
|
-
] : [
|
|
5546
|
-
txb.object(swapParams.poolId),
|
|
5547
|
-
swapParams.amount,
|
|
5548
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
5549
|
-
swapParams.coinB,
|
|
5550
|
-
accountCap,
|
|
5551
|
-
txb.pure.bool(swapParams.useFullInputCoinAmount),
|
|
5552
|
-
txb.object(CLOCK_ADDRESS)
|
|
5553
|
-
];
|
|
5554
|
-
let func = swapParams.a2b ? SWAP_A2B_FUNC : SWAP_B2A_FUNC;
|
|
5555
|
-
const target = createTarget(aggregatorPublishedAt, DEEPBOOK_MODULE, func);
|
|
5556
|
-
const res = txb.moveCall({
|
|
5557
|
-
target,
|
|
5558
|
-
typeArguments: [swapParams.coinAType, swapParams.coinBType],
|
|
5559
|
-
arguments: args
|
|
5560
|
-
});
|
|
5561
|
-
if (accountCapRes.isCreate) {
|
|
5562
|
-
const target2 = createTarget(
|
|
5563
|
-
aggregatorPublishedAt,
|
|
5564
|
-
DEEPBOOK_MODULE,
|
|
5565
|
-
TRANSFER_ACCOUNT_CAP
|
|
5566
|
-
);
|
|
5567
|
-
txb.moveCall({
|
|
5568
|
-
target: target2,
|
|
5569
|
-
typeArguments: [],
|
|
5570
|
-
arguments: [accountCap]
|
|
5571
|
-
});
|
|
5572
|
-
}
|
|
5573
|
-
return {
|
|
5574
|
-
targetCoin: res[0],
|
|
5575
|
-
amountIn: res[1],
|
|
5576
|
-
amountOut: res[2],
|
|
5577
|
-
txb
|
|
5578
|
-
};
|
|
5579
|
-
});
|
|
5580
|
-
}
|
|
5581
|
-
|
|
5582
|
-
// src/transaction/kriya.ts
|
|
5583
|
-
function kriyaSwapMovecall(swapParams, txb, config2) {
|
|
5584
|
-
return __async(this, null, function* () {
|
|
5585
|
-
const aggregatorPackage = config2.getPackage(AGGREGATOR);
|
|
5586
|
-
if (aggregatorPackage == null) {
|
|
5587
|
-
throw new AggregateError("Aggregator package not set", "MissAggregatorPackage" /* MissAggregatorPackage */);
|
|
5588
|
-
}
|
|
5589
|
-
const aggregatorPublishedAt = aggregatorPackage.publishedAt;
|
|
5590
|
-
if (swapParams.a2b) {
|
|
5591
|
-
if (swapParams.coinA == null) {
|
|
5592
|
-
throw new AggregateError("coinA is required", "MissCoinA" /* MissCoinA */);
|
|
5593
|
-
}
|
|
5594
|
-
} else {
|
|
5595
|
-
if (swapParams.coinB == null) {
|
|
5596
|
-
throw new AggregateError("coinB is required", "MissCoinB" /* MissCoinB */);
|
|
5514
|
+
/**
|
|
5515
|
+
* Get the CoinAsset objects for a given coin type.
|
|
5516
|
+
*
|
|
5517
|
+
* @param coinType The coin type to get the CoinAsset objects for.
|
|
5518
|
+
* @param allSuiObjects The list of all SuiMoveObjects.
|
|
5519
|
+
* @returns The CoinAsset objects for the given coin type.
|
|
5520
|
+
*/
|
|
5521
|
+
static getCoinAssets(coinType, allSuiObjects) {
|
|
5522
|
+
const coins = [];
|
|
5523
|
+
allSuiObjects.forEach((anObj) => {
|
|
5524
|
+
if (normalizeCoinType(anObj.coinAddress) === normalizeCoinType(coinType)) {
|
|
5525
|
+
coins.push(anObj);
|
|
5597
5526
|
}
|
|
5598
|
-
}
|
|
5599
|
-
const args = swapParams.a2b ? [
|
|
5600
|
-
txb.object(swapParams.poolId),
|
|
5601
|
-
swapParams.amount,
|
|
5602
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
5603
|
-
swapParams.coinA,
|
|
5604
|
-
txb.pure.bool(swapParams.useFullInputCoinAmount)
|
|
5605
|
-
] : [
|
|
5606
|
-
txb.object(swapParams.poolId),
|
|
5607
|
-
swapParams.amount,
|
|
5608
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
5609
|
-
swapParams.coinB,
|
|
5610
|
-
txb.pure.bool(swapParams.useFullInputCoinAmount)
|
|
5611
|
-
];
|
|
5612
|
-
const func = swapParams.a2b ? SWAP_A2B_FUNC : SWAP_B2A_FUNC;
|
|
5613
|
-
const target = createTarget(aggregatorPublishedAt, KRIYA_MODULE, func);
|
|
5614
|
-
const res = txb.moveCall({
|
|
5615
|
-
target,
|
|
5616
|
-
typeArguments: [swapParams.coinAType, swapParams.coinBType],
|
|
5617
|
-
arguments: args
|
|
5618
5527
|
});
|
|
5619
|
-
return
|
|
5620
|
-
targetCoin: res[0],
|
|
5621
|
-
amountIn: res[1],
|
|
5622
|
-
amountOut: res[2],
|
|
5623
|
-
txb
|
|
5624
|
-
};
|
|
5625
|
-
});
|
|
5626
|
-
}
|
|
5627
|
-
|
|
5628
|
-
// src/config.ts
|
|
5629
|
-
var ENV = /* @__PURE__ */ ((ENV2) => {
|
|
5630
|
-
ENV2[ENV2["MAINNET"] = 0] = "MAINNET";
|
|
5631
|
-
ENV2[ENV2["TESTNET"] = 1] = "TESTNET";
|
|
5632
|
-
return ENV2;
|
|
5633
|
-
})(ENV || {});
|
|
5634
|
-
var AggregatorConfig = class {
|
|
5635
|
-
constructor(aggregatorUrl, fullNodeUrl, wallet, packages, env) {
|
|
5636
|
-
this.aggregatorUrl = aggregatorUrl;
|
|
5637
|
-
this.fullNodeUrl = fullNodeUrl;
|
|
5638
|
-
this.wallet = wallet;
|
|
5639
|
-
this.packages = packages;
|
|
5640
|
-
this.env = env;
|
|
5641
|
-
}
|
|
5642
|
-
getAggregatorUrl() {
|
|
5643
|
-
return this.aggregatorUrl;
|
|
5644
|
-
}
|
|
5645
|
-
getFullNodeUrl() {
|
|
5646
|
-
return this.fullNodeUrl;
|
|
5647
|
-
}
|
|
5648
|
-
getWallet() {
|
|
5649
|
-
return this.wallet;
|
|
5650
|
-
}
|
|
5651
|
-
getENV() {
|
|
5652
|
-
return this.env;
|
|
5653
|
-
}
|
|
5654
|
-
getPackages() {
|
|
5655
|
-
return this.packages;
|
|
5656
|
-
}
|
|
5657
|
-
getPackage(packageName) {
|
|
5658
|
-
return this.packages.find((pkg) => pkg.packageName === packageName);
|
|
5659
|
-
}
|
|
5660
|
-
addPackage(newPackage) {
|
|
5661
|
-
if (!newPackage.packageName || !newPackage.packageId || !newPackage.publishedAt) {
|
|
5662
|
-
throw new Error("Invalid package data");
|
|
5663
|
-
}
|
|
5664
|
-
this.packages.push(newPackage);
|
|
5665
|
-
}
|
|
5666
|
-
removePackageById(packageId) {
|
|
5667
|
-
this.packages = this.packages.filter((pkg) => pkg.packageId !== packageId);
|
|
5668
|
-
}
|
|
5669
|
-
findPackageById(packageId) {
|
|
5670
|
-
return this.packages.find((pkg) => pkg.packageId === packageId);
|
|
5528
|
+
return coins;
|
|
5671
5529
|
}
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
5681
|
-
);
|
|
5530
|
+
/**
|
|
5531
|
+
* Get whether a coin address is a SUI coin.
|
|
5532
|
+
*
|
|
5533
|
+
* @param coinAddress The coin address to check.
|
|
5534
|
+
* @returns Whether the coin address is a SUI coin.
|
|
5535
|
+
*/
|
|
5536
|
+
static isSuiCoin(coinAddress) {
|
|
5537
|
+
return extractStructTagFromType(coinAddress).full_address === GAS_TYPE_ARG;
|
|
5682
5538
|
}
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
txb.object(swapParams.poolId),
|
|
5698
|
-
swapParams.amount,
|
|
5699
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
5700
|
-
txb.pure.bool(swapParams.byAmountIn),
|
|
5701
|
-
txb.pure.u128(swapParams.sqrtPriceLimit.toString()),
|
|
5702
|
-
txb.object(CLOCK_ADDRESS)
|
|
5703
|
-
];
|
|
5704
|
-
let func;
|
|
5705
|
-
if (hasPartner) {
|
|
5706
|
-
if (swapParams.a2b) {
|
|
5707
|
-
func = FlashSwapWithPartnerA2BFunc;
|
|
5708
|
-
} else {
|
|
5709
|
-
func = FlashSwapWithPartnerB2AFunc;
|
|
5710
|
-
}
|
|
5711
|
-
} else {
|
|
5712
|
-
if (swapParams.a2b) {
|
|
5713
|
-
func = FlashSwapA2BFunc;
|
|
5714
|
-
} else {
|
|
5715
|
-
func = FlashSwapB2AFunc;
|
|
5716
|
-
}
|
|
5539
|
+
/**
|
|
5540
|
+
* Select the CoinAsset objects from a list of CoinAsset objects that have a balance greater than or equal to a given amount.
|
|
5541
|
+
*
|
|
5542
|
+
* @param coins The list of CoinAsset objects to select from.
|
|
5543
|
+
* @param amount The amount to select CoinAsset objects with a balance greater than or equal to.
|
|
5544
|
+
* @param exclude A list of CoinAsset objects to exclude from the selection.
|
|
5545
|
+
* @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
|
|
5546
|
+
*/
|
|
5547
|
+
static selectCoinObjectIdGreaterThanOrEqual(coins, amount, exclude = []) {
|
|
5548
|
+
const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(coins, amount, exclude);
|
|
5549
|
+
const objectArray = selectedResult.selectedCoins.map((item) => item.coinObjectId);
|
|
5550
|
+
const remainCoins = selectedResult.remainingCoins;
|
|
5551
|
+
const amountArray = selectedResult.selectedCoins.map((item) => item.balance.toString());
|
|
5552
|
+
return { objectArray, remainCoins, amountArray };
|
|
5717
5553
|
}
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
}
|
|
5732
|
-
function cetusRepayFlashSwapMovecall(repayParams, txb, config2) {
|
|
5733
|
-
return __async(this, null, function* () {
|
|
5734
|
-
const aggregatorPackage = config2.getPackage(AGGREGATOR);
|
|
5735
|
-
if (aggregatorPackage == null) {
|
|
5736
|
-
throw new AggregateError(
|
|
5737
|
-
"Aggregator package not set",
|
|
5738
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
5739
|
-
);
|
|
5740
|
-
}
|
|
5741
|
-
const aggregatorPublishedAt = aggregatorPackage.publishedAt;
|
|
5742
|
-
const globalConfigId = config2.getENV() === 0 /* MAINNET */ ? MAINNET_CETUS_GLOBAL_CONFIG_ID : TESTNET_CETUS_GLOBAL_CONFIG_ID;
|
|
5743
|
-
const hasPartner = repayParams.partner != null && repayParams.partner.length > 0;
|
|
5744
|
-
if (repayParams.a2b) {
|
|
5745
|
-
if (repayParams.coinA == null) {
|
|
5746
|
-
throw new AggregateError(
|
|
5747
|
-
"coinA is required",
|
|
5748
|
-
"MissCoinA" /* MissCoinA */
|
|
5749
|
-
);
|
|
5750
|
-
}
|
|
5751
|
-
} else {
|
|
5752
|
-
if (repayParams.coinB == null) {
|
|
5753
|
-
throw new AggregateError(
|
|
5754
|
-
"coinB is required",
|
|
5755
|
-
"MissCoinB" /* MissCoinB */
|
|
5756
|
-
);
|
|
5757
|
-
}
|
|
5554
|
+
/**
|
|
5555
|
+
* Select the CoinAsset objects from a list of CoinAsset objects that have a balance greater than or equal to a given amount.
|
|
5556
|
+
*
|
|
5557
|
+
* @param coins The list of CoinAsset objects to select from.
|
|
5558
|
+
* @param amount The amount to select CoinAsset objects with a balance greater than or equal to.
|
|
5559
|
+
* @param exclude A list of CoinAsset objects to exclude from the selection.
|
|
5560
|
+
* @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
|
|
5561
|
+
*/
|
|
5562
|
+
static selectCoinAssetGreaterThanOrEqual(coins, amount, exclude = []) {
|
|
5563
|
+
const sortedCoins = _CoinUtils.sortByBalance(coins.filter((c) => !exclude.includes(c.coinObjectId)));
|
|
5564
|
+
const total = _CoinUtils.calculateTotalBalance(sortedCoins);
|
|
5565
|
+
if (total < amount) {
|
|
5566
|
+
return { selectedCoins: [], remainingCoins: sortedCoins };
|
|
5758
5567
|
}
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
if (repayParams.a2b) {
|
|
5762
|
-
args = [
|
|
5763
|
-
txb.object(globalConfigId),
|
|
5764
|
-
txb.object(repayParams.poolId),
|
|
5765
|
-
repayParams.coinA,
|
|
5766
|
-
repayParams.receipt,
|
|
5767
|
-
txb.object(repayParams.partner)
|
|
5768
|
-
];
|
|
5769
|
-
} else {
|
|
5770
|
-
args = [
|
|
5771
|
-
txb.object(globalConfigId),
|
|
5772
|
-
txb.object(repayParams.poolId),
|
|
5773
|
-
repayParams.coinB,
|
|
5774
|
-
repayParams.receipt,
|
|
5775
|
-
txb.object(repayParams.partner)
|
|
5776
|
-
];
|
|
5777
|
-
}
|
|
5778
|
-
} else {
|
|
5779
|
-
if (repayParams.a2b) {
|
|
5780
|
-
args = [
|
|
5781
|
-
txb.object(globalConfigId),
|
|
5782
|
-
txb.object(repayParams.poolId),
|
|
5783
|
-
repayParams.coinA,
|
|
5784
|
-
repayParams.receipt
|
|
5785
|
-
];
|
|
5786
|
-
} else {
|
|
5787
|
-
args = [
|
|
5788
|
-
txb.object(globalConfigId),
|
|
5789
|
-
txb.object(repayParams.poolId),
|
|
5790
|
-
repayParams.coinB,
|
|
5791
|
-
repayParams.receipt
|
|
5792
|
-
];
|
|
5793
|
-
}
|
|
5568
|
+
if (total === amount) {
|
|
5569
|
+
return { selectedCoins: sortedCoins, remainingCoins: [] };
|
|
5794
5570
|
}
|
|
5795
|
-
let
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5571
|
+
let sum2 = BigInt(0);
|
|
5572
|
+
const selectedCoins = [];
|
|
5573
|
+
const remainingCoins = [...sortedCoins];
|
|
5574
|
+
while (sum2 < total) {
|
|
5575
|
+
const target = amount - sum2;
|
|
5576
|
+
const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex((c) => c.balance >= target);
|
|
5577
|
+
if (coinWithSmallestSufficientBalanceIndex !== -1) {
|
|
5578
|
+
selectedCoins.push(remainingCoins[coinWithSmallestSufficientBalanceIndex]);
|
|
5579
|
+
remainingCoins.splice(coinWithSmallestSufficientBalanceIndex, 1);
|
|
5580
|
+
break;
|
|
5801
5581
|
}
|
|
5802
|
-
|
|
5803
|
-
if (
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
func = REPAY_FLASH_SWAP_B2A_FUNC;
|
|
5582
|
+
const coinWithLargestBalance = remainingCoins.pop();
|
|
5583
|
+
if (coinWithLargestBalance.balance > 0) {
|
|
5584
|
+
selectedCoins.push(coinWithLargestBalance);
|
|
5585
|
+
sum2 += coinWithLargestBalance.balance;
|
|
5807
5586
|
}
|
|
5808
5587
|
}
|
|
5809
|
-
|
|
5810
|
-
const res = txb.moveCall({
|
|
5811
|
-
target,
|
|
5812
|
-
typeArguments: [repayParams.coinAType, repayParams.coinBType],
|
|
5813
|
-
arguments: args
|
|
5814
|
-
});
|
|
5815
|
-
return {
|
|
5816
|
-
repayTargetCoin: res[0]
|
|
5817
|
-
};
|
|
5818
|
-
});
|
|
5819
|
-
}
|
|
5820
|
-
function cetusSwapWithOutLimit(swapParams, fromCoin, txb, config2) {
|
|
5821
|
-
return __async(this, null, function* () {
|
|
5822
|
-
const flashResult = cetusFlashSwapMovecall(swapParams, txb, config2);
|
|
5823
|
-
const repayCoinA = swapParams.a2b ? fromCoin : void 0;
|
|
5824
|
-
const repayCoinB = swapParams.a2b ? void 0 : fromCoin;
|
|
5825
|
-
const repayParams = {
|
|
5826
|
-
poolId: swapParams.poolId,
|
|
5827
|
-
a2b: swapParams.a2b,
|
|
5828
|
-
coinA: repayCoinA,
|
|
5829
|
-
coinB: repayCoinB,
|
|
5830
|
-
receipt: flashResult.flashReceipt,
|
|
5831
|
-
coinAType: swapParams.coinAType,
|
|
5832
|
-
coinBType: swapParams.coinBType,
|
|
5833
|
-
partner: swapParams.partner
|
|
5834
|
-
};
|
|
5835
|
-
let nextInputAmount;
|
|
5836
|
-
if (swapParams.byAmountIn) {
|
|
5837
|
-
nextInputAmount = flashResult.swapedAmount;
|
|
5838
|
-
} else {
|
|
5839
|
-
nextInputAmount = flashResult.payAmount;
|
|
5840
|
-
}
|
|
5841
|
-
const repayResult = yield cetusRepayFlashSwapMovecall(
|
|
5842
|
-
repayParams,
|
|
5843
|
-
txb,
|
|
5844
|
-
config2
|
|
5845
|
-
);
|
|
5846
|
-
return {
|
|
5847
|
-
flashTargetCoin: flashResult.targetCoin,
|
|
5848
|
-
repayTargetCoin: repayResult.repayTargetCoin,
|
|
5849
|
-
nextInputAmount
|
|
5850
|
-
};
|
|
5851
|
-
});
|
|
5852
|
-
}
|
|
5853
|
-
|
|
5854
|
-
// src/math.ts
|
|
5855
|
-
var import_bn2 = __toESM(require_bn());
|
|
5856
|
-
function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
|
|
5857
|
-
let amountLimit = ZERO;
|
|
5858
|
-
if (byAmountIn) {
|
|
5859
|
-
amountLimit = expectAmount.mul(new import_bn2.default(TEN_POW_NINE - slippage * TEN_POW_NINE)).div(new import_bn2.default(TEN_POW_NINE));
|
|
5860
|
-
} else {
|
|
5861
|
-
amountLimit = expectAmount.mul(new import_bn2.default(TEN_POW_NINE + slippage * TEN_POW_NINE)).div(new import_bn2.default(TEN_POW_NINE));
|
|
5588
|
+
return { selectedCoins: _CoinUtils.sortByBalance(selectedCoins), remainingCoins: _CoinUtils.sortByBalance(remainingCoins) };
|
|
5862
5589
|
}
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
return new import_bn2.default(MAX_SQER_PRICE_X64);
|
|
5590
|
+
/**
|
|
5591
|
+
* Sort the CoinAsset objects by their balance.
|
|
5592
|
+
*
|
|
5593
|
+
* @param coins The CoinAsset objects to sort.
|
|
5594
|
+
* @returns The sorted CoinAsset objects.
|
|
5595
|
+
*/
|
|
5596
|
+
static sortByBalance(coins) {
|
|
5597
|
+
return coins.sort((a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0);
|
|
5872
5598
|
}
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
5887
|
-
);
|
|
5888
|
-
}
|
|
5889
|
-
const aggregatorPublishedAt = aggregatorPackage.publishedAt;
|
|
5890
|
-
if (swapParams.a2b) {
|
|
5891
|
-
if (swapParams.coinA == null) {
|
|
5892
|
-
throw new AggregateError(
|
|
5893
|
-
"coinA is required",
|
|
5894
|
-
"MissCoinA" /* MissCoinA */
|
|
5895
|
-
);
|
|
5896
|
-
}
|
|
5897
|
-
} else {
|
|
5898
|
-
if (swapParams.coinB == null) {
|
|
5899
|
-
throw new AggregateError(
|
|
5900
|
-
"coinB is required",
|
|
5901
|
-
"MissCoinB" /* MissCoinB */
|
|
5902
|
-
);
|
|
5903
|
-
}
|
|
5904
|
-
}
|
|
5905
|
-
const containerID = config2.getENV() === 0 /* MAINNET */ ? MAINNET_FLOWX_AMM_CONTAINER_ID : TESTNET_FLOWX_AMM_CONTAINER_ID;
|
|
5906
|
-
const swapCoin = swapParams.a2b ? swapParams.coinA : swapParams.coinB;
|
|
5907
|
-
const args = [
|
|
5908
|
-
txb.object(containerID),
|
|
5909
|
-
swapParams.amount,
|
|
5910
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
5911
|
-
swapCoin,
|
|
5912
|
-
txb.pure.bool(swapParams.useFullInputCoinAmount)
|
|
5913
|
-
];
|
|
5914
|
-
const func = swapParams.a2b ? SWAP_A2B_FUNC : SWAP_B2A_FUNC;
|
|
5915
|
-
const target = createTarget(aggregatorPublishedAt, FLOWX_AMM_MODULE, func);
|
|
5916
|
-
const res = txb.moveCall({
|
|
5917
|
-
target,
|
|
5918
|
-
typeArguments: [swapParams.coinAType, swapParams.coinBType],
|
|
5919
|
-
arguments: args
|
|
5920
|
-
});
|
|
5921
|
-
return {
|
|
5922
|
-
targetCoin: res[0],
|
|
5923
|
-
amountIn: res[1],
|
|
5924
|
-
amountOut: res[2],
|
|
5925
|
-
txb
|
|
5926
|
-
};
|
|
5927
|
-
});
|
|
5928
|
-
}
|
|
5929
|
-
|
|
5930
|
-
// src/transaction/turbos.ts
|
|
5931
|
-
function turbosClmmSwapMovecall(swapParams, txb, config2) {
|
|
5932
|
-
return __async(this, null, function* () {
|
|
5933
|
-
const aggregatorPackage = config2.getPackage(AGGREGATOR);
|
|
5934
|
-
if (aggregatorPackage == null) {
|
|
5935
|
-
throw new AggregateError(
|
|
5936
|
-
"Aggregator package not set",
|
|
5937
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
5938
|
-
);
|
|
5939
|
-
}
|
|
5940
|
-
const aggregatorPublishedAt = aggregatorPackage.publishedAt;
|
|
5941
|
-
if (swapParams.a2b) {
|
|
5942
|
-
if (swapParams.coinA == null) {
|
|
5943
|
-
throw new AggregateError(
|
|
5944
|
-
"coinA is required",
|
|
5945
|
-
"MissCoinA" /* MissCoinA */
|
|
5946
|
-
);
|
|
5947
|
-
}
|
|
5948
|
-
} else {
|
|
5949
|
-
if (swapParams.coinB == null) {
|
|
5950
|
-
throw new AggregateError(
|
|
5951
|
-
"coinB is required",
|
|
5952
|
-
"MissCoinB" /* MissCoinB */
|
|
5953
|
-
);
|
|
5954
|
-
}
|
|
5955
|
-
}
|
|
5956
|
-
const sqrtPriceLimit = swapParams.a2b ? "4295048016" : "79226673515401279992447579055";
|
|
5957
|
-
const args = swapParams.a2b ? [
|
|
5958
|
-
txb.object(swapParams.poolId),
|
|
5959
|
-
swapParams.amount,
|
|
5960
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
5961
|
-
swapParams.coinA,
|
|
5962
|
-
txb.pure.bool(swapParams.useFullInputCoinAmount),
|
|
5963
|
-
txb.pure.u128(sqrtPriceLimit),
|
|
5964
|
-
txb.object(CLOCK_ADDRESS),
|
|
5965
|
-
txb.object(TURBOS_VERSIONED)
|
|
5966
|
-
] : [
|
|
5967
|
-
txb.object(swapParams.poolId),
|
|
5968
|
-
swapParams.amount,
|
|
5969
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
5970
|
-
swapParams.coinB,
|
|
5971
|
-
txb.pure.bool(swapParams.useFullInputCoinAmount),
|
|
5972
|
-
txb.pure.u128(sqrtPriceLimit),
|
|
5973
|
-
txb.object(CLOCK_ADDRESS),
|
|
5974
|
-
txb.object(TURBOS_VERSIONED)
|
|
5975
|
-
];
|
|
5976
|
-
const func = swapParams.a2b ? SWAP_A2B_FUNC : SWAP_B2A_FUNC;
|
|
5977
|
-
const target = createTarget(aggregatorPublishedAt, TURBOS_MODULE, func);
|
|
5978
|
-
const res = txb.moveCall({
|
|
5979
|
-
target,
|
|
5980
|
-
typeArguments: [
|
|
5981
|
-
swapParams.coinAType,
|
|
5982
|
-
swapParams.coinBType,
|
|
5983
|
-
swapParams.feeType
|
|
5984
|
-
],
|
|
5985
|
-
arguments: args
|
|
5986
|
-
});
|
|
5987
|
-
return {
|
|
5988
|
-
targetCoin: res[0],
|
|
5989
|
-
amountIn: res[1],
|
|
5990
|
-
amountOut: res[2],
|
|
5991
|
-
txb
|
|
5992
|
-
};
|
|
5993
|
-
});
|
|
5994
|
-
}
|
|
5995
|
-
|
|
5996
|
-
// src/transaction/aftermath.ts
|
|
5997
|
-
function AftermathAmmSwapMovecall(swapParams, txb, config2) {
|
|
5998
|
-
return __async(this, null, function* () {
|
|
5999
|
-
const aggregatorPackage = config2.getPackage(AGGREGATOR);
|
|
6000
|
-
if (aggregatorPackage == null) {
|
|
6001
|
-
throw new AggregateError(
|
|
6002
|
-
"Aggregator package not set",
|
|
6003
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
6004
|
-
);
|
|
6005
|
-
}
|
|
6006
|
-
const aggregatorPublishedAt = aggregatorPackage.publishedAt;
|
|
6007
|
-
if (swapParams.a2b) {
|
|
6008
|
-
if (swapParams.coinA == null) {
|
|
6009
|
-
throw new AggregateError(
|
|
6010
|
-
"coinA is required",
|
|
6011
|
-
"MissCoinA" /* MissCoinA */
|
|
6012
|
-
);
|
|
6013
|
-
}
|
|
6014
|
-
} else {
|
|
6015
|
-
if (swapParams.coinB == null) {
|
|
6016
|
-
throw new AggregateError(
|
|
6017
|
-
"coinB is required",
|
|
6018
|
-
"MissCoinB" /* MissCoinB */
|
|
6019
|
-
);
|
|
6020
|
-
}
|
|
6021
|
-
}
|
|
6022
|
-
const poolRegistryID = config2.getENV() === 0 /* MAINNET */ ? MAINNET_AFTERMATH_REGISTRY_ID : TESTNET_AFTERMATH_REGISTRY_ID;
|
|
6023
|
-
const vaultID = config2.getENV() === 0 /* MAINNET */ ? MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID : TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID;
|
|
6024
|
-
const treasuryID = config2.getENV() === 0 /* MAINNET */ ? MAINNET_AFTERMATH_TREASURY_ID : TESTNET_AFTERMATH_TREASURY_ID;
|
|
6025
|
-
const insuranceFundID = config2.getENV() === 0 /* MAINNET */ ? MAINNET_AFTERMATH_INSURANCE_FUND_ID : TESTNET_AFTERMATH_INSURANCE_FUND_ID;
|
|
6026
|
-
const referrealVaultID = config2.getENV() === 0 /* MAINNET */ ? MAINNET_AFTERMATH_REFERRAL_VAULT_ID : TESTNET_AFTERMATH_REFERRAL_VAULT_ID;
|
|
6027
|
-
const swapCoin = swapParams.a2b ? swapParams.coinA : swapParams.coinB;
|
|
6028
|
-
const slippageArg = (1 - swapParams.slippage) * 1e18;
|
|
6029
|
-
const args = [
|
|
6030
|
-
txb.object(swapParams.poolId),
|
|
6031
|
-
txb.object(poolRegistryID),
|
|
6032
|
-
txb.object(vaultID),
|
|
6033
|
-
txb.object(treasuryID),
|
|
6034
|
-
txb.object(insuranceFundID),
|
|
6035
|
-
txb.object(referrealVaultID),
|
|
6036
|
-
swapParams.amount,
|
|
6037
|
-
txb.pure.u64(swapParams.amountLimit),
|
|
6038
|
-
txb.pure.u64(swapParams.amountOut),
|
|
6039
|
-
txb.pure.u64(slippageArg),
|
|
6040
|
-
swapCoin,
|
|
6041
|
-
txb.pure.bool(swapParams.useFullInputCoinAmount)
|
|
6042
|
-
];
|
|
6043
|
-
const func = swapParams.a2b ? SWAP_A2B_FUNC : SWAP_B2A_FUNC;
|
|
6044
|
-
const target = createTarget(aggregatorPublishedAt, AFTERMATH_MODULE, func);
|
|
6045
|
-
const res = txb.moveCall({
|
|
6046
|
-
target,
|
|
6047
|
-
typeArguments: [
|
|
6048
|
-
swapParams.coinAType,
|
|
6049
|
-
swapParams.coinBType,
|
|
6050
|
-
swapParams.lpSupplyType
|
|
6051
|
-
],
|
|
6052
|
-
arguments: args
|
|
6053
|
-
});
|
|
6054
|
-
return {
|
|
6055
|
-
targetCoin: res[0],
|
|
6056
|
-
amountIn: res[1],
|
|
6057
|
-
amountOut: res[2],
|
|
6058
|
-
txb
|
|
6059
|
-
};
|
|
6060
|
-
});
|
|
6061
|
-
}
|
|
5599
|
+
static sortByBalanceDes(coins) {
|
|
5600
|
+
return coins.sort((a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1);
|
|
5601
|
+
}
|
|
5602
|
+
/**
|
|
5603
|
+
* Calculate the total balance of a list of CoinAsset objects.
|
|
5604
|
+
*
|
|
5605
|
+
* @param coins The list of CoinAsset objects to calculate the total balance for.
|
|
5606
|
+
* @returns The total balance of the CoinAsset objects.
|
|
5607
|
+
*/
|
|
5608
|
+
static calculateTotalBalance(coins) {
|
|
5609
|
+
return coins.reduce((partialSum, c) => partialSum + c.balance, BigInt(0));
|
|
5610
|
+
}
|
|
5611
|
+
};
|
|
6062
5612
|
|
|
6063
|
-
// src/
|
|
6064
|
-
function
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
const firstPathPool = j === 0;
|
|
6078
|
-
const path = router.path[j];
|
|
6079
|
-
if (path.provider === CETUS_DEX) {
|
|
6080
|
-
const swapParams = {
|
|
6081
|
-
poolId: path.id,
|
|
6082
|
-
amount: nextFlashAmount,
|
|
6083
|
-
amountLimit: "0",
|
|
6084
|
-
a2b: path.a2b,
|
|
6085
|
-
byAmountIn: true,
|
|
6086
|
-
sqrtPriceLimit: GetDefaultSqrtPriceLimit(path.a2b),
|
|
6087
|
-
partner,
|
|
6088
|
-
coinAType: path.a2b ? path.from : path.target,
|
|
6089
|
-
coinBType: path.a2b ? path.target : path.from
|
|
6090
|
-
};
|
|
6091
|
-
const swapResult = yield cetusSwapWithOutLimit(
|
|
6092
|
-
swapParams,
|
|
6093
|
-
nextFromCoin,
|
|
6094
|
-
txb,
|
|
6095
|
-
config2
|
|
6096
|
-
);
|
|
6097
|
-
transferOrDestoryCoin(
|
|
6098
|
-
txb,
|
|
6099
|
-
swapResult.repayTargetCoin,
|
|
6100
|
-
path.from,
|
|
6101
|
-
config2
|
|
6102
|
-
);
|
|
6103
|
-
intermediateTargetCoin = swapResult.flashTargetCoin;
|
|
6104
|
-
nextFromCoin = intermediateTargetCoin;
|
|
6105
|
-
nextFlashAmount = swapResult.nextInputAmount;
|
|
6106
|
-
}
|
|
6107
|
-
if (path.provider === DEEPBOOK_DEX) {
|
|
6108
|
-
const coinA = path.a2b ? nextFromCoin : void 0;
|
|
6109
|
-
const coinB = path.a2b ? void 0 : nextFromCoin;
|
|
6110
|
-
const swapParams = {
|
|
6111
|
-
poolId: path.id,
|
|
6112
|
-
a2b: path.a2b,
|
|
6113
|
-
amount: nextFlashAmount,
|
|
6114
|
-
amountLimit: 0,
|
|
6115
|
-
coinA,
|
|
6116
|
-
coinB,
|
|
6117
|
-
useFullInputCoinAmount: !firstPathPool,
|
|
6118
|
-
coinAType: path.a2b ? path.from : path.target,
|
|
6119
|
-
coinBType: path.a2b ? params.targetCoinType : path.from
|
|
6120
|
-
};
|
|
6121
|
-
const deepbookSwapResult = yield deepbookSwapMovecall(
|
|
6122
|
-
swapParams,
|
|
6123
|
-
client,
|
|
6124
|
-
txb,
|
|
6125
|
-
config2
|
|
6126
|
-
);
|
|
6127
|
-
intermediateTargetCoin = deepbookSwapResult.targetCoin;
|
|
6128
|
-
nextFromCoin = intermediateTargetCoin;
|
|
6129
|
-
nextFlashAmount = deepbookSwapResult.amountOut;
|
|
6130
|
-
}
|
|
6131
|
-
if (path.provider === KRIYA_DEX) {
|
|
6132
|
-
const coinA = path.a2b ? nextFromCoin : void 0;
|
|
6133
|
-
const coinB = path.a2b ? void 0 : nextFromCoin;
|
|
6134
|
-
const swapParams = {
|
|
6135
|
-
poolId: path.id,
|
|
6136
|
-
amount: nextFlashAmount,
|
|
6137
|
-
amountLimit: 0,
|
|
6138
|
-
a2b: path.a2b,
|
|
6139
|
-
byAmountIn: true,
|
|
6140
|
-
coinA,
|
|
6141
|
-
coinB,
|
|
6142
|
-
useFullInputCoinAmount: !firstPathPool,
|
|
6143
|
-
coinAType: path.a2b ? path.from : path.target,
|
|
6144
|
-
coinBType: path.a2b ? path.target : path.from
|
|
6145
|
-
};
|
|
6146
|
-
const swapResult = yield kriyaSwapMovecall(swapParams, txb, config2);
|
|
6147
|
-
intermediateTargetCoin = swapResult.targetCoin;
|
|
6148
|
-
nextFromCoin = intermediateTargetCoin;
|
|
6149
|
-
nextFlashAmount = swapResult.amountOut;
|
|
6150
|
-
}
|
|
6151
|
-
if (path.provider === FLOWX_AMM) {
|
|
6152
|
-
const coinA = path.a2b ? nextFromCoin : void 0;
|
|
6153
|
-
const coinB = path.a2b ? void 0 : nextFromCoin;
|
|
6154
|
-
const swapParams = {
|
|
6155
|
-
amount: nextFlashAmount,
|
|
6156
|
-
amountLimit: 0,
|
|
6157
|
-
a2b: path.a2b,
|
|
6158
|
-
byAmountIn: true,
|
|
6159
|
-
coinA,
|
|
6160
|
-
coinB,
|
|
6161
|
-
useFullInputCoinAmount: !firstPathPool,
|
|
6162
|
-
coinAType: path.a2b ? path.from : path.target,
|
|
6163
|
-
coinBType: path.a2b ? path.target : path.from
|
|
6164
|
-
};
|
|
6165
|
-
const swapResult = yield flowxAmmSwapMovecall(swapParams, txb, config2);
|
|
6166
|
-
intermediateTargetCoin = swapResult.targetCoin;
|
|
6167
|
-
nextFromCoin = intermediateTargetCoin;
|
|
6168
|
-
nextFlashAmount = swapResult.amountOut;
|
|
6169
|
-
}
|
|
6170
|
-
if (path.provider === TURBOS_DEX) {
|
|
6171
|
-
const coinA = path.a2b ? nextFromCoin : void 0;
|
|
6172
|
-
const coinB = path.a2b ? void 0 : nextFromCoin;
|
|
6173
|
-
let feeType = "";
|
|
6174
|
-
if (path.extendedDetails != null && path.extendedDetails.turbosFeeType != null) {
|
|
6175
|
-
feeType = path.extendedDetails.turbosFeeType;
|
|
6176
|
-
} else {
|
|
6177
|
-
throw new AggregateError(
|
|
6178
|
-
"Build turbos swap movecall error: ",
|
|
6179
|
-
"MissTurbosFeeType" /* MissTurbosFeeType */
|
|
6180
|
-
);
|
|
6181
|
-
}
|
|
6182
|
-
const swapParams = {
|
|
6183
|
-
poolId: path.id,
|
|
6184
|
-
amount: nextFlashAmount,
|
|
6185
|
-
amountLimit: 0,
|
|
6186
|
-
a2b: path.a2b,
|
|
6187
|
-
byAmountIn: true,
|
|
6188
|
-
coinA,
|
|
6189
|
-
coinB,
|
|
6190
|
-
useFullInputCoinAmount: !firstPathPool,
|
|
6191
|
-
coinAType: path.a2b ? path.from : path.target,
|
|
6192
|
-
coinBType: path.a2b ? path.target : path.from,
|
|
6193
|
-
feeType
|
|
6194
|
-
};
|
|
6195
|
-
const swapResult = yield turbosClmmSwapMovecall(swapParams, txb, config2);
|
|
6196
|
-
intermediateTargetCoin = swapResult.targetCoin;
|
|
6197
|
-
nextFromCoin = intermediateTargetCoin;
|
|
6198
|
-
nextFlashAmount = swapResult.amountOut;
|
|
6199
|
-
}
|
|
6200
|
-
if (path.provider === AFTERMATH_AMM) {
|
|
6201
|
-
const coinA = path.a2b ? nextFromCoin : void 0;
|
|
6202
|
-
const coinB = path.a2b ? void 0 : nextFromCoin;
|
|
6203
|
-
let lpSupplyType = "";
|
|
6204
|
-
if (path.extendedDetails != null && path.extendedDetails.aftermathLpSupplyType != null) {
|
|
6205
|
-
lpSupplyType = path.extendedDetails.aftermathLpSupplyType;
|
|
6206
|
-
} else {
|
|
6207
|
-
throw new AggregateError(
|
|
6208
|
-
"Build aftermath swap movecall error: ",
|
|
6209
|
-
"MissAftermathLpSupplyType" /* MissAftermathLpSupplyType */
|
|
6210
|
-
);
|
|
6211
|
-
}
|
|
6212
|
-
const swapParams = {
|
|
6213
|
-
poolId: path.id,
|
|
6214
|
-
amount: nextFlashAmount,
|
|
6215
|
-
amountOut: path.amountOut,
|
|
6216
|
-
amountLimit: 0,
|
|
6217
|
-
a2b: path.a2b,
|
|
6218
|
-
byAmountIn: true,
|
|
6219
|
-
coinA,
|
|
6220
|
-
coinB,
|
|
6221
|
-
useFullInputCoinAmount: !firstPathPool,
|
|
6222
|
-
coinAType: path.a2b ? path.from : path.target,
|
|
6223
|
-
coinBType: path.a2b ? path.target : path.from,
|
|
6224
|
-
slippage: params.slippage,
|
|
6225
|
-
lpSupplyType
|
|
6226
|
-
};
|
|
6227
|
-
const swapResult = yield AftermathAmmSwapMovecall(
|
|
6228
|
-
swapParams,
|
|
6229
|
-
txb,
|
|
6230
|
-
config2
|
|
6231
|
-
);
|
|
6232
|
-
intermediateTargetCoin = swapResult.targetCoin;
|
|
6233
|
-
nextFromCoin = intermediateTargetCoin;
|
|
6234
|
-
nextFlashAmount = swapResult.amountOut;
|
|
6235
|
-
}
|
|
6236
|
-
}
|
|
6237
|
-
targetCoins.push(nextFromCoin);
|
|
6238
|
-
}
|
|
6239
|
-
transferOrDestoryCoin(txb, fromCoin, params.fromCoinType, config2);
|
|
6240
|
-
return targetCoins;
|
|
6241
|
-
});
|
|
6242
|
-
}
|
|
6243
|
-
function expectOutputRouterSwap(params, txb, fromCoin, config2, partner) {
|
|
6244
|
-
return __async(this, null, function* () {
|
|
6245
|
-
const splitAmounts = params.routers.map(
|
|
6246
|
-
(router) => router.amountOut.toString()
|
|
6247
|
-
);
|
|
6248
|
-
const returnCoins = [];
|
|
6249
|
-
const receipts = [];
|
|
6250
|
-
const targetCoins = [];
|
|
6251
|
-
for (let i = 0; i < params.routers.length; i++) {
|
|
6252
|
-
const router = params.routers[i];
|
|
6253
|
-
let nextFlashAmount = txb.pure.u64(splitAmounts[i]);
|
|
6254
|
-
for (let j = router.path.length - 1; j >= 0; j--) {
|
|
6255
|
-
const path = router.path[j];
|
|
6256
|
-
const coinAType = path.a2b ? path.from : path.target;
|
|
6257
|
-
const coinBType = path.a2b ? path.target : path.from;
|
|
6258
|
-
const swapParams = {
|
|
6259
|
-
poolId: path.id,
|
|
6260
|
-
amount: nextFlashAmount,
|
|
6261
|
-
amountLimit: U64_MAX,
|
|
6262
|
-
a2b: path.a2b,
|
|
6263
|
-
byAmountIn: false,
|
|
6264
|
-
sqrtPriceLimit: GetDefaultSqrtPriceLimit(path.a2b),
|
|
6265
|
-
//
|
|
6266
|
-
partner,
|
|
6267
|
-
coinAType,
|
|
6268
|
-
coinBType
|
|
6269
|
-
};
|
|
6270
|
-
const flashSwapResult = cetusFlashSwapMovecall(swapParams, txb, config2);
|
|
6271
|
-
nextFlashAmount = flashSwapResult.payAmount;
|
|
6272
|
-
returnCoins.unshift(flashSwapResult.targetCoin);
|
|
6273
|
-
receipts.unshift(flashSwapResult.flashReceipt);
|
|
6274
|
-
}
|
|
6275
|
-
let nextRepayCoin = fromCoin;
|
|
6276
|
-
for (let j = 0; j < router.path.length; j++) {
|
|
6277
|
-
const path = router.path[j];
|
|
6278
|
-
const coinAType = path.a2b ? path.from : path.target;
|
|
6279
|
-
const coinBType = path.a2b ? path.target : path.from;
|
|
6280
|
-
const repayParams = {
|
|
6281
|
-
poolId: path.id,
|
|
6282
|
-
a2b: path.a2b,
|
|
6283
|
-
partner,
|
|
6284
|
-
coinA: path.a2b ? nextRepayCoin : void 0,
|
|
6285
|
-
coinB: path.a2b ? void 0 : nextRepayCoin,
|
|
6286
|
-
receipt: receipts[j],
|
|
6287
|
-
coinAType,
|
|
6288
|
-
coinBType
|
|
6289
|
-
};
|
|
6290
|
-
const repayResult = yield cetusRepayFlashSwapMovecall(
|
|
6291
|
-
repayParams,
|
|
6292
|
-
txb,
|
|
6293
|
-
config2
|
|
6294
|
-
);
|
|
6295
|
-
nextRepayCoin = returnCoins[j];
|
|
6296
|
-
if (j === 0) {
|
|
6297
|
-
fromCoin = repayResult.repayTargetCoin;
|
|
6298
|
-
} else {
|
|
6299
|
-
transferOrDestoryCoin(
|
|
6300
|
-
txb,
|
|
6301
|
-
repayResult.repayTargetCoin,
|
|
6302
|
-
path.from,
|
|
6303
|
-
config2
|
|
6304
|
-
);
|
|
6305
|
-
}
|
|
6306
|
-
if (j === router.path.length - 1) {
|
|
6307
|
-
targetCoins.push(nextRepayCoin);
|
|
6308
|
-
}
|
|
6309
|
-
}
|
|
6310
|
-
}
|
|
6311
|
-
transferOrDestoryCoin(txb, fromCoin, params.fromCoinType, config2);
|
|
6312
|
-
return targetCoins;
|
|
6313
|
-
});
|
|
5613
|
+
// src/errors.ts
|
|
5614
|
+
function getAggregatorServerErrorMessage(code) {
|
|
5615
|
+
switch (code) {
|
|
5616
|
+
case 1e4 /* CalculateError */:
|
|
5617
|
+
return "Calculate error";
|
|
5618
|
+
case 10001 /* NumberTooLarge */:
|
|
5619
|
+
return "Input number too large can not fit in target type";
|
|
5620
|
+
case 10002 /* NoRouter */:
|
|
5621
|
+
return "No router";
|
|
5622
|
+
case 10003 /* InsufficientLiquidity */:
|
|
5623
|
+
return "Insufficient Liquidity";
|
|
5624
|
+
default:
|
|
5625
|
+
return "Unknown error";
|
|
5626
|
+
}
|
|
6314
5627
|
}
|
|
6315
5628
|
|
|
6316
|
-
// src/client.ts
|
|
6317
|
-
var import_bn4 = __toESM(require_bn());
|
|
6318
|
-
|
|
6319
5629
|
// src/utils/coin.ts
|
|
6320
5630
|
function completionCoin(s) {
|
|
6321
5631
|
const index = s.indexOf("::");
|
|
@@ -6347,6 +5657,61 @@ function compareCoins(coinA, coinB) {
|
|
|
6347
5657
|
}
|
|
6348
5658
|
return true;
|
|
6349
5659
|
}
|
|
5660
|
+
function mintZeroCoin(txb, coinType) {
|
|
5661
|
+
return txb.moveCall({
|
|
5662
|
+
target: SuiZeroCoinFn,
|
|
5663
|
+
typeArguments: [coinType]
|
|
5664
|
+
});
|
|
5665
|
+
}
|
|
5666
|
+
function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
5667
|
+
const usedCoinAsests = CoinUtils.getCoinAssets(coinType, allCoins);
|
|
5668
|
+
if (amount === BigInt(0) && usedCoinAsests.length === 0) {
|
|
5669
|
+
const zeroCoin = mintZeroCoin(txb, coinType);
|
|
5670
|
+
return {
|
|
5671
|
+
targetCoin: zeroCoin,
|
|
5672
|
+
isMintZeroCoin: true,
|
|
5673
|
+
targetCoinAmount: 0
|
|
5674
|
+
};
|
|
5675
|
+
}
|
|
5676
|
+
let totalCoinBalance = CoinUtils.calculateTotalBalance(usedCoinAsests);
|
|
5677
|
+
if (totalCoinBalance < amount) {
|
|
5678
|
+
throw new AggregateError(
|
|
5679
|
+
"Insufficient balance when build merge coin",
|
|
5680
|
+
"InsufficientBalance" /* InsufficientBalance */
|
|
5681
|
+
);
|
|
5682
|
+
}
|
|
5683
|
+
if (CoinUtils.isSuiCoin(coinType)) {
|
|
5684
|
+
const resultCoin = txb.splitCoins(txb.gas, [
|
|
5685
|
+
txb.pure.u64(amount.toString())
|
|
5686
|
+
]);
|
|
5687
|
+
return {
|
|
5688
|
+
targetCoin: resultCoin,
|
|
5689
|
+
isMintZeroCoin: true,
|
|
5690
|
+
targetCoinAmount: Number(amount.toString())
|
|
5691
|
+
};
|
|
5692
|
+
}
|
|
5693
|
+
let sortCoinAssets = CoinUtils.sortByBalance(usedCoinAsests);
|
|
5694
|
+
let totalThreeCoinBalance = sortCoinAssets.slice(0, 3).reduce((acc, coin) => acc + coin.balance, BigInt(0));
|
|
5695
|
+
if (totalThreeCoinBalance < BigInt(amount)) {
|
|
5696
|
+
sortCoinAssets = CoinUtils.sortByBalanceDes(usedCoinAsests);
|
|
5697
|
+
}
|
|
5698
|
+
let selectedCoinResult = CoinUtils.selectCoinObjectIdGreaterThanOrEqual(
|
|
5699
|
+
sortCoinAssets,
|
|
5700
|
+
amount
|
|
5701
|
+
);
|
|
5702
|
+
const [masterCoin, ...mergedCoin] = selectedCoinResult.objectArray;
|
|
5703
|
+
if (mergedCoin.length > 0) {
|
|
5704
|
+
txb.mergeCoins(
|
|
5705
|
+
masterCoin,
|
|
5706
|
+
mergedCoin.map((coin) => txb.object(coin))
|
|
5707
|
+
);
|
|
5708
|
+
}
|
|
5709
|
+
return {
|
|
5710
|
+
targetCoin: txb.object(masterCoin),
|
|
5711
|
+
isMintZeroCoin: false,
|
|
5712
|
+
targetCoinAmount: Number(amount.toString())
|
|
5713
|
+
};
|
|
5714
|
+
}
|
|
6350
5715
|
|
|
6351
5716
|
// src/utils/transaction.ts
|
|
6352
5717
|
function checkInvalidSuiAddress(address) {
|
|
@@ -6357,30 +5722,41 @@ function checkInvalidSuiAddress(address) {
|
|
|
6357
5722
|
}
|
|
6358
5723
|
|
|
6359
5724
|
// src/transaction/swap.ts
|
|
5725
|
+
var import_bn4 = __toESM(require_bn());
|
|
5726
|
+
|
|
5727
|
+
// src/math.ts
|
|
6360
5728
|
var import_bn3 = __toESM(require_bn());
|
|
6361
|
-
function
|
|
5729
|
+
function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
|
|
5730
|
+
let amountLimit = ZERO;
|
|
5731
|
+
if (byAmountIn) {
|
|
5732
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE - slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5733
|
+
} else {
|
|
5734
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE + slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5735
|
+
}
|
|
5736
|
+
return Number(amountLimit.toString());
|
|
5737
|
+
}
|
|
5738
|
+
function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
|
|
5739
|
+
const sqrtPriceX64 = new decimal_default(sqrtPriceStr).mul(decimal_default.pow(2, -64));
|
|
5740
|
+
return sqrtPriceX64.pow(2).mul(decimal_default.pow(10, decimalsA - decimalsB));
|
|
5741
|
+
}
|
|
5742
|
+
|
|
5743
|
+
// src/transaction/swap.ts
|
|
5744
|
+
function swapInPools(client, params, sender) {
|
|
6362
5745
|
return __async(this, null, function* () {
|
|
6363
5746
|
var _a, _b, _c, _d, _e;
|
|
6364
5747
|
const { from, target, amount, byAmountIn, pools } = params;
|
|
6365
5748
|
const fromCoin = completionCoin(from);
|
|
6366
5749
|
const targetCoin = completionCoin(target);
|
|
6367
5750
|
const tx = new Transaction();
|
|
6368
|
-
const
|
|
6369
|
-
const
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
"Aggregator package not set",
|
|
6373
|
-
"MissAggregatorPackage" /* MissAggregatorPackage */
|
|
6374
|
-
);
|
|
6375
|
-
}
|
|
6376
|
-
const integratePublishedAt = integratePackage.publishedAt;
|
|
6377
|
-
const coinA = a2b ? fromCoin : targetCoin;
|
|
6378
|
-
const coinB = a2b ? targetCoin : fromCoin;
|
|
5751
|
+
const direction = compareCoins(fromCoin, targetCoin);
|
|
5752
|
+
const integratePublishedAt = "0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee";
|
|
5753
|
+
const coinA = direction ? fromCoin : targetCoin;
|
|
5754
|
+
const coinB = direction ? targetCoin : fromCoin;
|
|
6379
5755
|
const typeArguments = [coinA, coinB];
|
|
6380
5756
|
for (let i = 0; i < pools.length; i++) {
|
|
6381
5757
|
const args = [
|
|
6382
5758
|
tx.object(pools[i]),
|
|
6383
|
-
tx.pure.bool(
|
|
5759
|
+
tx.pure.bool(direction),
|
|
6384
5760
|
tx.pure.bool(byAmountIn),
|
|
6385
5761
|
tx.pure.u64(amount.toString())
|
|
6386
5762
|
];
|
|
@@ -6390,7 +5766,7 @@ function swapInPools(client, params, config2) {
|
|
|
6390
5766
|
typeArguments
|
|
6391
5767
|
});
|
|
6392
5768
|
}
|
|
6393
|
-
if (!checkInvalidSuiAddress(
|
|
5769
|
+
if (!checkInvalidSuiAddress(sender)) {
|
|
6394
5770
|
throw new AggregateError(
|
|
6395
5771
|
"Aggregator package not set",
|
|
6396
5772
|
"InvalidWallet" /* InvalidWallet */
|
|
@@ -6398,7 +5774,7 @@ function swapInPools(client, params, config2) {
|
|
|
6398
5774
|
}
|
|
6399
5775
|
const simulateRes = yield client.devInspectTransactionBlock({
|
|
6400
5776
|
transactionBlock: tx,
|
|
6401
|
-
sender
|
|
5777
|
+
sender
|
|
6402
5778
|
});
|
|
6403
5779
|
if (simulateRes.error != null) {
|
|
6404
5780
|
throw new AggregateError(
|
|
@@ -6422,13 +5798,13 @@ function swapInPools(client, params, config2) {
|
|
|
6422
5798
|
continue;
|
|
6423
5799
|
}
|
|
6424
5800
|
if (params.byAmountIn) {
|
|
6425
|
-
const amount2 = new
|
|
5801
|
+
const amount2 = new import_bn4.BN(valueData[i].parsedJson.data.amount_out);
|
|
6426
5802
|
if (amount2.gt(tempMaxAmount)) {
|
|
6427
5803
|
tempIndex = i;
|
|
6428
5804
|
tempMaxAmount = amount2;
|
|
6429
5805
|
}
|
|
6430
5806
|
} else {
|
|
6431
|
-
const amount2 = new
|
|
5807
|
+
const amount2 = new import_bn4.BN(valueData[i].parsedJson.data.amount_out);
|
|
6432
5808
|
if (amount2.lt(tempMaxAmount)) {
|
|
6433
5809
|
tempIndex = i;
|
|
6434
5810
|
tempMaxAmount = amount2;
|
|
@@ -6436,6 +5812,7 @@ function swapInPools(client, params, config2) {
|
|
|
6436
5812
|
}
|
|
6437
5813
|
}
|
|
6438
5814
|
const event = valueData[tempIndex].parsedJson.data;
|
|
5815
|
+
console.log("event", JSON.stringify(event, null, 2));
|
|
6439
5816
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price;
|
|
6440
5817
|
const [decimalA, decimalB] = yield Promise.all([
|
|
6441
5818
|
client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
|
|
@@ -6453,24 +5830,24 @@ function swapInPools(client, params, config2) {
|
|
|
6453
5830
|
decimalB
|
|
6454
5831
|
);
|
|
6455
5832
|
const routeData = {
|
|
6456
|
-
amountIn: new
|
|
6457
|
-
amountOut: new
|
|
5833
|
+
amountIn: new import_bn4.BN((_b = event.amount_in) != null ? _b : 0),
|
|
5834
|
+
amountOut: new import_bn4.BN((_c = event.amount_out) != null ? _c : 0),
|
|
6458
5835
|
routes: [
|
|
6459
5836
|
{
|
|
6460
5837
|
path: [
|
|
6461
5838
|
{
|
|
6462
5839
|
id: pools[tempIndex],
|
|
6463
|
-
|
|
6464
|
-
provider:
|
|
5840
|
+
direction,
|
|
5841
|
+
provider: "CETUS",
|
|
6465
5842
|
from: fromCoin,
|
|
6466
5843
|
target: targetCoin,
|
|
6467
|
-
feeRate:
|
|
6468
|
-
amountIn:
|
|
6469
|
-
amountOut:
|
|
5844
|
+
feeRate: event.fee_rate,
|
|
5845
|
+
amountIn: event.amount_in,
|
|
5846
|
+
amountOut: event.amount_out
|
|
6470
5847
|
}
|
|
6471
5848
|
],
|
|
6472
|
-
amountIn: new
|
|
6473
|
-
amountOut: new
|
|
5849
|
+
amountIn: new import_bn4.BN((_d = event.amount_in) != null ? _d : 0),
|
|
5850
|
+
amountOut: new import_bn4.BN((_e = event.amount_out) != null ? _e : 0),
|
|
6474
5851
|
initialPrice
|
|
6475
5852
|
}
|
|
6476
5853
|
],
|
|
@@ -6483,11 +5860,146 @@ function swapInPools(client, params, config2) {
|
|
|
6483
5860
|
return result;
|
|
6484
5861
|
});
|
|
6485
5862
|
}
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
5863
|
+
|
|
5864
|
+
// src/transaction/kriya_v3.ts
|
|
5865
|
+
var KriyaV3 = class {
|
|
5866
|
+
constructor(env) {
|
|
5867
|
+
if (env !== 0 /* Mainnet */) {
|
|
5868
|
+
throw new Error("Kriya clmm only supported on mainnet");
|
|
5869
|
+
}
|
|
5870
|
+
this.version = "0xf5145a7ac345ca8736cf8c76047d00d6d378f30e81be6f6eb557184d9de93c78";
|
|
5871
|
+
}
|
|
5872
|
+
swap(client, txb, path, inputCoin) {
|
|
5873
|
+
return __async(this, null, function* () {
|
|
5874
|
+
const { direction, from, target } = path;
|
|
5875
|
+
const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
|
|
5876
|
+
const args = [
|
|
5877
|
+
txb.object(path.id),
|
|
5878
|
+
inputCoin,
|
|
5879
|
+
txb.object(this.version),
|
|
5880
|
+
txb.object(CLOCK_ADDRESS)
|
|
5881
|
+
];
|
|
5882
|
+
const res = txb.moveCall({
|
|
5883
|
+
target: `${client.publishedAt()}::kriya_clmm::${func}`,
|
|
5884
|
+
typeArguments: [coinAType, coinBType],
|
|
5885
|
+
arguments: args
|
|
5886
|
+
});
|
|
5887
|
+
return res;
|
|
5888
|
+
});
|
|
5889
|
+
}
|
|
5890
|
+
};
|
|
5891
|
+
|
|
5892
|
+
// src/transaction/haedal.ts
|
|
5893
|
+
var Haedal = class {
|
|
5894
|
+
constructor(env) {
|
|
5895
|
+
if (env !== 0 /* Mainnet */) {
|
|
5896
|
+
throw new Error("Haedal only supported on mainnet");
|
|
5897
|
+
}
|
|
5898
|
+
}
|
|
5899
|
+
swap(client, txb, path, inputCoin) {
|
|
5900
|
+
return __async(this, null, function* () {
|
|
5901
|
+
const { direction } = path;
|
|
5902
|
+
if (!direction) {
|
|
5903
|
+
throw new Error("Haedal not support b2a swap");
|
|
5904
|
+
}
|
|
5905
|
+
const func = "swap_a2b";
|
|
5906
|
+
console.log("haedal path id", path.id);
|
|
5907
|
+
const args = [txb.object(path.id), txb.object("0x5"), inputCoin];
|
|
5908
|
+
const res = txb.moveCall({
|
|
5909
|
+
target: `${client.publishedAt()}::haedal::${func}`,
|
|
5910
|
+
typeArguments: [],
|
|
5911
|
+
arguments: args
|
|
5912
|
+
});
|
|
5913
|
+
return res;
|
|
5914
|
+
});
|
|
5915
|
+
}
|
|
5916
|
+
};
|
|
5917
|
+
|
|
5918
|
+
// src/transaction/afsui.ts
|
|
5919
|
+
var Afsui = class {
|
|
5920
|
+
constructor(env) {
|
|
5921
|
+
if (env !== 0 /* Mainnet */) {
|
|
5922
|
+
throw new Error("Afsui only supported on mainnet");
|
|
5923
|
+
}
|
|
5924
|
+
this.stakedSuiVault = "0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d";
|
|
5925
|
+
this.safe = "0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610";
|
|
5926
|
+
this.referVault = "0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef";
|
|
5927
|
+
this.validator = "0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2";
|
|
5928
|
+
}
|
|
5929
|
+
swap(client, txb, path, inputCoin) {
|
|
5930
|
+
return __async(this, null, function* () {
|
|
5931
|
+
const { direction } = path;
|
|
5932
|
+
if (!direction) {
|
|
5933
|
+
throw new Error("Afsui not support b2a swap");
|
|
5934
|
+
}
|
|
5935
|
+
const func = "swap_a2b";
|
|
5936
|
+
const args = [
|
|
5937
|
+
txb.object(this.stakedSuiVault),
|
|
5938
|
+
txb.object(this.safe),
|
|
5939
|
+
txb.object("0x5"),
|
|
5940
|
+
txb.object(this.referVault),
|
|
5941
|
+
txb.object(this.validator),
|
|
5942
|
+
inputCoin
|
|
5943
|
+
];
|
|
5944
|
+
const res = txb.moveCall({
|
|
5945
|
+
target: `${client.publishedAt()}::afsui::${func}`,
|
|
5946
|
+
typeArguments: [],
|
|
5947
|
+
arguments: args
|
|
5948
|
+
});
|
|
5949
|
+
return res;
|
|
5950
|
+
});
|
|
5951
|
+
}
|
|
5952
|
+
};
|
|
5953
|
+
|
|
5954
|
+
// src/transaction/volo.ts
|
|
5955
|
+
var Volo = class {
|
|
5956
|
+
constructor(env) {
|
|
5957
|
+
if (env !== 0 /* Mainnet */) {
|
|
5958
|
+
throw new Error("Volo only supported on mainnet");
|
|
5959
|
+
}
|
|
5960
|
+
this.nativePool = "0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf";
|
|
5961
|
+
this.metadata = "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60";
|
|
5962
|
+
}
|
|
5963
|
+
swap(client, txb, path, inputCoin) {
|
|
5964
|
+
return __async(this, null, function* () {
|
|
5965
|
+
const { direction } = path;
|
|
5966
|
+
if (!direction) {
|
|
5967
|
+
throw new Error("Volo not support b2a swap");
|
|
5968
|
+
}
|
|
5969
|
+
const func = "swap_a2b";
|
|
5970
|
+
const args = [
|
|
5971
|
+
txb.object(this.nativePool),
|
|
5972
|
+
txb.object(this.metadata),
|
|
5973
|
+
txb.object("0x5"),
|
|
5974
|
+
inputCoin
|
|
5975
|
+
];
|
|
5976
|
+
const res = txb.moveCall({
|
|
5977
|
+
target: `${client.publishedAt()}::volo::${func}`,
|
|
5978
|
+
typeArguments: [],
|
|
5979
|
+
arguments: args
|
|
5980
|
+
});
|
|
5981
|
+
return res;
|
|
5982
|
+
});
|
|
5983
|
+
}
|
|
5984
|
+
};
|
|
5985
|
+
|
|
5986
|
+
// src/client.ts
|
|
5987
|
+
var CETUS = "CETUS";
|
|
5988
|
+
var DEEPBOOKV2 = "DEEPBOOK";
|
|
5989
|
+
var KRIYA = "KRIYA";
|
|
5990
|
+
var FLOWXV2 = "FLOWX";
|
|
5991
|
+
var KRIYAV3 = "KRIYAV3";
|
|
5992
|
+
var TURBOS = "TURBOS";
|
|
5993
|
+
var AFTERMATH = "AFTERMATH";
|
|
5994
|
+
var HAEDAL = "HAEDAL";
|
|
5995
|
+
var VOLO = "VOLO";
|
|
5996
|
+
var AFSUI = "AFSUI";
|
|
5997
|
+
var AggregatorClient5 = class {
|
|
5998
|
+
constructor(endpoint, signer, client, env) {
|
|
5999
|
+
this.endpoint = endpoint;
|
|
6000
|
+
this.client = client;
|
|
6001
|
+
this.signer = signer;
|
|
6002
|
+
this.env = env;
|
|
6491
6003
|
this.allCoins = [];
|
|
6492
6004
|
}
|
|
6493
6005
|
getAllCoins() {
|
|
@@ -6497,7 +6009,7 @@ var AggregatorClient = class {
|
|
|
6497
6009
|
const allCoins = [];
|
|
6498
6010
|
while (true) {
|
|
6499
6011
|
const gotAllCoins = yield this.client.getAllCoins({
|
|
6500
|
-
owner: this.
|
|
6012
|
+
owner: this.signer,
|
|
6501
6013
|
cursor,
|
|
6502
6014
|
limit
|
|
6503
6015
|
});
|
|
@@ -6516,79 +6028,95 @@ var AggregatorClient = class {
|
|
|
6516
6028
|
return allCoins;
|
|
6517
6029
|
});
|
|
6518
6030
|
}
|
|
6519
|
-
|
|
6031
|
+
findRouters(params) {
|
|
6520
6032
|
return __async(this, null, function* () {
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
splitFactor,
|
|
6529
|
-
splitCount,
|
|
6530
|
-
providers
|
|
6531
|
-
} = fromRouterParams;
|
|
6532
|
-
const fromCoin = completionCoin(from);
|
|
6533
|
-
const targetCoin = completionCoin(target);
|
|
6534
|
-
let url = this.config.getAggregatorUrl() + `/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6535
|
-
if (depth) {
|
|
6536
|
-
url += `&depth=${depth}`;
|
|
6537
|
-
}
|
|
6538
|
-
if (splitAlgorithm) {
|
|
6539
|
-
url += `&split_algorithm=${splitAlgorithm}`;
|
|
6540
|
-
}
|
|
6541
|
-
if (splitFactor) {
|
|
6542
|
-
url += `&split_factor=${splitFactor}`;
|
|
6543
|
-
}
|
|
6544
|
-
if (splitCount) {
|
|
6545
|
-
url += `&split_count=${splitCount}`;
|
|
6033
|
+
return getRouterResult(this.endpoint, params);
|
|
6034
|
+
});
|
|
6035
|
+
}
|
|
6036
|
+
expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
|
|
6037
|
+
return __async(this, null, function* () {
|
|
6038
|
+
if (routers.length === 0) {
|
|
6039
|
+
throw new Error("No router found");
|
|
6546
6040
|
}
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6041
|
+
const splitAmounts = routers.map((router) => router.amountIn.toString());
|
|
6042
|
+
const inputCoinType = routers[0].path[0].from;
|
|
6043
|
+
const outputCoinType = routers[0].path[routers[0].path.length - 1].target;
|
|
6044
|
+
const inputCoins = txb.splitCoins(inputCoin, splitAmounts);
|
|
6045
|
+
const outputCoins = [];
|
|
6046
|
+
for (let i = 0; i < routers.length; i++) {
|
|
6047
|
+
if (routers[i].path.length === 0) {
|
|
6048
|
+
throw new Error("Empty path");
|
|
6049
|
+
}
|
|
6050
|
+
let nextCoin = inputCoins[i];
|
|
6051
|
+
for (const path of routers[i].path) {
|
|
6052
|
+
const dex = this.newDex(path.provider, partner);
|
|
6053
|
+
nextCoin = yield dex.swap(this, txb, path, nextCoin);
|
|
6054
|
+
}
|
|
6055
|
+
outputCoins.push(nextCoin);
|
|
6551
6056
|
}
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6057
|
+
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
|
|
6058
|
+
const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
|
|
6059
|
+
txb,
|
|
6060
|
+
outputCoins,
|
|
6061
|
+
outputCoinType,
|
|
6062
|
+
amountOutLimit
|
|
6063
|
+
);
|
|
6064
|
+
return mergedTargetCointhis;
|
|
6065
|
+
});
|
|
6066
|
+
}
|
|
6067
|
+
expectOutputSwap(txb, inputCoin, routers, partner) {
|
|
6068
|
+
return __async(this, null, function* () {
|
|
6069
|
+
const returnCoins = [];
|
|
6070
|
+
const receipts = [];
|
|
6071
|
+
const targetCoins = [];
|
|
6072
|
+
const dex = new Cetus(this.env, partner);
|
|
6073
|
+
for (let i = 0; i < routers.length; i++) {
|
|
6074
|
+
const router = routers[i];
|
|
6075
|
+
for (let j = router.path.length - 1; j >= 0; j--) {
|
|
6076
|
+
const path = router.path[j];
|
|
6077
|
+
const flashSwapResult = dex.flash_swap(this, txb, path, false);
|
|
6078
|
+
returnCoins.unshift(flashSwapResult.targetCoin);
|
|
6079
|
+
receipts.unshift(flashSwapResult.flashReceipt);
|
|
6080
|
+
}
|
|
6081
|
+
let nextRepayCoin = inputCoin;
|
|
6082
|
+
for (let j = 0; j < router.path.length; j++) {
|
|
6083
|
+
const path = router.path[j];
|
|
6084
|
+
const repayResult = dex.repay_flash_swap(
|
|
6085
|
+
this,
|
|
6086
|
+
txb,
|
|
6087
|
+
path,
|
|
6088
|
+
nextRepayCoin,
|
|
6089
|
+
receipts[j]
|
|
6090
|
+
);
|
|
6091
|
+
nextRepayCoin = returnCoins[j];
|
|
6092
|
+
if (j === 0) {
|
|
6093
|
+
inputCoin = repayResult;
|
|
6094
|
+
} else {
|
|
6095
|
+
this.transferOrDestoryCoin(txb, repayResult, path.from);
|
|
6564
6096
|
}
|
|
6565
|
-
|
|
6097
|
+
if (j === router.path.length - 1) {
|
|
6098
|
+
targetCoins.push(nextRepayCoin);
|
|
6099
|
+
}
|
|
6100
|
+
}
|
|
6566
6101
|
}
|
|
6567
|
-
const
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6102
|
+
const inputCoinType = routers[0].path[0].from;
|
|
6103
|
+
this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
|
|
6104
|
+
if (targetCoins.length > 1) {
|
|
6105
|
+
const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
|
|
6106
|
+
txb.moveCall({
|
|
6107
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6108
|
+
typeArguments: [routers[0].path[routers[0].path.length - 1].target],
|
|
6109
|
+
arguments: [targetCoins[0], vec]
|
|
6110
|
+
});
|
|
6571
6111
|
}
|
|
6572
|
-
|
|
6573
|
-
return {
|
|
6574
|
-
amountIn: ZERO,
|
|
6575
|
-
amountOut: ZERO,
|
|
6576
|
-
routes: [],
|
|
6577
|
-
insufficientLiquidity,
|
|
6578
|
-
error: {
|
|
6579
|
-
code: 10003 /* InsufficientLiquidity */,
|
|
6580
|
-
msg: getAggregatorServerErrorMessage(
|
|
6581
|
-
10003 /* InsufficientLiquidity */
|
|
6582
|
-
)
|
|
6583
|
-
}
|
|
6584
|
-
};
|
|
6112
|
+
return targetCoins[0];
|
|
6585
6113
|
});
|
|
6586
6114
|
}
|
|
6587
6115
|
swapInPools(params) {
|
|
6588
6116
|
return __async(this, null, function* () {
|
|
6589
6117
|
let result;
|
|
6590
6118
|
try {
|
|
6591
|
-
result = yield swapInPools(this.client, params, this.
|
|
6119
|
+
result = yield swapInPools(this.client, params, this.signer);
|
|
6592
6120
|
} catch (e) {
|
|
6593
6121
|
console.error("swapInPools error:", e);
|
|
6594
6122
|
return null;
|
|
@@ -6597,100 +6125,168 @@ var AggregatorClient = class {
|
|
|
6597
6125
|
});
|
|
6598
6126
|
}
|
|
6599
6127
|
routerSwap(params) {
|
|
6128
|
+
return __async(this, null, function* () {
|
|
6129
|
+
const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
|
|
6130
|
+
const amountIn = routers.reduce(
|
|
6131
|
+
(acc, router) => acc.add(router.amountIn),
|
|
6132
|
+
new import_bn5.default(0)
|
|
6133
|
+
);
|
|
6134
|
+
const amountOut = routers.reduce(
|
|
6135
|
+
(acc, router) => acc.add(router.amountOut),
|
|
6136
|
+
new import_bn5.default(0)
|
|
6137
|
+
);
|
|
6138
|
+
const amountLimit = CalculateAmountLimit(
|
|
6139
|
+
byAmountIn ? amountOut : amountIn,
|
|
6140
|
+
byAmountIn,
|
|
6141
|
+
slippage
|
|
6142
|
+
);
|
|
6143
|
+
if (byAmountIn) {
|
|
6144
|
+
const targetCoin2 = yield this.expectInputSwap(
|
|
6145
|
+
txb,
|
|
6146
|
+
inputCoin,
|
|
6147
|
+
routers,
|
|
6148
|
+
new import_bn5.default(amountLimit),
|
|
6149
|
+
partner
|
|
6150
|
+
);
|
|
6151
|
+
return targetCoin2;
|
|
6152
|
+
}
|
|
6153
|
+
const splitedInputCoins = txb.splitCoins(inputCoin, [
|
|
6154
|
+
amountLimit.toString()
|
|
6155
|
+
]);
|
|
6156
|
+
this.transferOrDestoryCoin(txb, inputCoin, routers[0].path[0].from);
|
|
6157
|
+
const targetCoin = yield this.expectOutputSwap(
|
|
6158
|
+
txb,
|
|
6159
|
+
splitedInputCoins[0],
|
|
6160
|
+
routers,
|
|
6161
|
+
partner
|
|
6162
|
+
);
|
|
6163
|
+
return targetCoin;
|
|
6164
|
+
});
|
|
6165
|
+
}
|
|
6166
|
+
// auto build input coin
|
|
6167
|
+
// auto merge, transfer or destory target coin.
|
|
6168
|
+
fastRouterSwap(params) {
|
|
6600
6169
|
return __async(this, null, function* () {
|
|
6601
6170
|
const {
|
|
6602
|
-
routers
|
|
6603
|
-
amountIn,
|
|
6604
|
-
amountOut,
|
|
6171
|
+
routers,
|
|
6605
6172
|
byAmountIn,
|
|
6606
6173
|
slippage,
|
|
6607
|
-
|
|
6608
|
-
targetCoinType,
|
|
6174
|
+
txb,
|
|
6609
6175
|
partner,
|
|
6610
6176
|
isMergeTragetCoin,
|
|
6611
6177
|
refreshAllCoins
|
|
6612
6178
|
} = params;
|
|
6179
|
+
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
6180
|
+
this.allCoins = yield this.getAllCoins();
|
|
6181
|
+
}
|
|
6182
|
+
const fromCoinType = routers[0].path[0].from;
|
|
6183
|
+
const targetCoinType = routers[0].path[routers[0].path.length - 1].target;
|
|
6184
|
+
const amountIn = routers.reduce(
|
|
6185
|
+
(acc, router) => acc.add(router.amountIn),
|
|
6186
|
+
new import_bn5.default(0)
|
|
6187
|
+
);
|
|
6188
|
+
const amountOut = routers.reduce(
|
|
6189
|
+
(acc, router) => acc.add(router.amountOut),
|
|
6190
|
+
new import_bn5.default(0)
|
|
6191
|
+
);
|
|
6613
6192
|
const amountLimit = CalculateAmountLimit(
|
|
6614
6193
|
byAmountIn ? amountOut : amountIn,
|
|
6615
6194
|
byAmountIn,
|
|
6616
6195
|
slippage
|
|
6617
6196
|
);
|
|
6618
|
-
const
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
this.client,
|
|
6634
|
-
params,
|
|
6635
|
-
txb,
|
|
6636
|
-
fromCoin,
|
|
6637
|
-
this.config,
|
|
6638
|
-
partner
|
|
6639
|
-
);
|
|
6640
|
-
const mergedCoin = checkCoinThresholdAndMergeCoin(
|
|
6641
|
-
txb,
|
|
6642
|
-
swapedCoins,
|
|
6643
|
-
targetCoinType,
|
|
6644
|
-
amountLimit,
|
|
6645
|
-
this.config
|
|
6646
|
-
);
|
|
6647
|
-
targetCoins.push(mergedCoin);
|
|
6648
|
-
} else {
|
|
6649
|
-
const fromCoin = buildInputCoin(
|
|
6650
|
-
txb,
|
|
6651
|
-
allCoins,
|
|
6652
|
-
BigInt(amountLimit),
|
|
6653
|
-
fromCoinType
|
|
6654
|
-
).targetCoin;
|
|
6655
|
-
const swapedCoins = yield expectOutputRouterSwap(
|
|
6656
|
-
params,
|
|
6657
|
-
txb,
|
|
6658
|
-
fromCoin,
|
|
6659
|
-
this.config,
|
|
6660
|
-
partner
|
|
6661
|
-
);
|
|
6662
|
-
targetCoins.push(...swapedCoins);
|
|
6663
|
-
}
|
|
6197
|
+
const amount = byAmountIn ? amountIn : amountLimit;
|
|
6198
|
+
const buildFromCoinRes = buildInputCoin(
|
|
6199
|
+
txb,
|
|
6200
|
+
this.allCoins,
|
|
6201
|
+
BigInt(amount.toString()),
|
|
6202
|
+
fromCoinType
|
|
6203
|
+
);
|
|
6204
|
+
const targetCoin = yield this.routerSwap({
|
|
6205
|
+
routers,
|
|
6206
|
+
inputCoin: buildFromCoinRes.targetCoin,
|
|
6207
|
+
slippage,
|
|
6208
|
+
byAmountIn,
|
|
6209
|
+
txb,
|
|
6210
|
+
partner
|
|
6211
|
+
});
|
|
6664
6212
|
if (isMergeTragetCoin) {
|
|
6665
6213
|
const targetCoinRes = buildInputCoin(
|
|
6666
6214
|
txb,
|
|
6667
|
-
allCoins,
|
|
6215
|
+
this.allCoins,
|
|
6668
6216
|
BigInt(0),
|
|
6669
6217
|
targetCoinType
|
|
6670
6218
|
);
|
|
6671
|
-
txb.mergeCoins(targetCoinRes.targetCoin,
|
|
6219
|
+
txb.mergeCoins(targetCoinRes.targetCoin, [targetCoin]);
|
|
6672
6220
|
if (targetCoinRes.isMintZeroCoin) {
|
|
6673
|
-
transferOrDestoryCoin(
|
|
6221
|
+
this.transferOrDestoryCoin(
|
|
6674
6222
|
txb,
|
|
6675
6223
|
targetCoinRes.targetCoin,
|
|
6676
|
-
targetCoinType
|
|
6677
|
-
this.config
|
|
6224
|
+
targetCoinType
|
|
6678
6225
|
);
|
|
6679
6226
|
}
|
|
6680
6227
|
} else {
|
|
6681
|
-
|
|
6682
|
-
const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
|
|
6683
|
-
txb.moveCall({
|
|
6684
|
-
target: createTarget(SUI_FRAMEWORK_ADDRESS, PAY_MODULE, JOIN_FUNC),
|
|
6685
|
-
typeArguments: [targetCoinType],
|
|
6686
|
-
arguments: [targetCoins[0], vec]
|
|
6687
|
-
});
|
|
6688
|
-
}
|
|
6689
|
-
transferOrDestoryCoin(txb, targetCoins[0], targetCoinType, this.config);
|
|
6228
|
+
this.transferOrDestoryCoin(txb, targetCoin, targetCoinType);
|
|
6690
6229
|
}
|
|
6691
|
-
return txb;
|
|
6692
6230
|
});
|
|
6693
6231
|
}
|
|
6232
|
+
publishedAt() {
|
|
6233
|
+
if (this.env === 0 /* Mainnet */) {
|
|
6234
|
+
return "0x9fd702cf1a8db5a2e99be20be6750d22ec75c30d57e3d9ccbc37c9b4ad7bef21";
|
|
6235
|
+
} else {
|
|
6236
|
+
return "0x0";
|
|
6237
|
+
}
|
|
6238
|
+
}
|
|
6239
|
+
transferOrDestoryCoin(txb, coin, coinType) {
|
|
6240
|
+
txb.moveCall({
|
|
6241
|
+
target: `${this.publishedAt()}::utils::transfer_or_destroy_coin`,
|
|
6242
|
+
typeArguments: [coinType],
|
|
6243
|
+
arguments: [coin]
|
|
6244
|
+
});
|
|
6245
|
+
}
|
|
6246
|
+
checkCoinThresholdAndMergeCoin(txb, coins, coinType, amountLimit) {
|
|
6247
|
+
let targetCoin = coins[0];
|
|
6248
|
+
if (coins.length > 1) {
|
|
6249
|
+
let vec = txb.makeMoveVec({ elements: coins.slice(1) });
|
|
6250
|
+
txb.moveCall({
|
|
6251
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6252
|
+
typeArguments: [coinType],
|
|
6253
|
+
arguments: [coins[0], vec]
|
|
6254
|
+
});
|
|
6255
|
+
targetCoin = coins[0];
|
|
6256
|
+
}
|
|
6257
|
+
txb.moveCall({
|
|
6258
|
+
target: `${this.publishedAt()}::utils::check_coin_threshold`,
|
|
6259
|
+
typeArguments: [coinType],
|
|
6260
|
+
arguments: [targetCoin, txb.pure.u64(amountLimit.toString())]
|
|
6261
|
+
});
|
|
6262
|
+
return targetCoin;
|
|
6263
|
+
}
|
|
6264
|
+
newDex(provider, partner) {
|
|
6265
|
+
switch (provider) {
|
|
6266
|
+
case CETUS:
|
|
6267
|
+
return new Cetus(this.env, partner);
|
|
6268
|
+
case DEEPBOOKV2:
|
|
6269
|
+
return new DeepbookV2(this.env);
|
|
6270
|
+
case KRIYA:
|
|
6271
|
+
return new KriyaV2(this.env);
|
|
6272
|
+
case KRIYAV3:
|
|
6273
|
+
return new KriyaV3(this.env);
|
|
6274
|
+
case FLOWXV2:
|
|
6275
|
+
return new FlowxV2(this.env);
|
|
6276
|
+
case TURBOS:
|
|
6277
|
+
return new Turbos(this.env);
|
|
6278
|
+
case AFTERMATH:
|
|
6279
|
+
return new Aftermath(this.env);
|
|
6280
|
+
case HAEDAL:
|
|
6281
|
+
return new Haedal(this.env);
|
|
6282
|
+
case AFSUI:
|
|
6283
|
+
return new Afsui(this.env);
|
|
6284
|
+
case VOLO:
|
|
6285
|
+
return new Volo(this.env);
|
|
6286
|
+
default:
|
|
6287
|
+
throw new Error(`Unsupported dex ${provider}`);
|
|
6288
|
+
}
|
|
6289
|
+
}
|
|
6694
6290
|
signAndExecuteTransaction(txb, signer) {
|
|
6695
6291
|
return __async(this, null, function* () {
|
|
6696
6292
|
const res = yield this.client.signAndExecuteTransaction({
|
|
@@ -6710,7 +6306,7 @@ var AggregatorClient = class {
|
|
|
6710
6306
|
return __async(this, null, function* () {
|
|
6711
6307
|
const res = yield this.client.devInspectTransactionBlock({
|
|
6712
6308
|
transactionBlock: txb,
|
|
6713
|
-
sender: this.
|
|
6309
|
+
sender: this.signer
|
|
6714
6310
|
});
|
|
6715
6311
|
return res;
|
|
6716
6312
|
});
|
|
@@ -6727,19 +6323,19 @@ var AggregatorClient = class {
|
|
|
6727
6323
|
};
|
|
6728
6324
|
function parseRouterResponse(data) {
|
|
6729
6325
|
return {
|
|
6730
|
-
amountIn: new
|
|
6731
|
-
amountOut: new
|
|
6326
|
+
amountIn: new import_bn5.default(data.amount_in.toString()),
|
|
6327
|
+
amountOut: new import_bn5.default(data.amount_out.toString()),
|
|
6732
6328
|
insufficientLiquidity: false,
|
|
6733
6329
|
routes: data.routes.map((route) => {
|
|
6734
6330
|
return {
|
|
6735
6331
|
path: route.path.map((path) => {
|
|
6736
6332
|
var _a, _b;
|
|
6737
6333
|
let version;
|
|
6738
|
-
if (path.provider ===
|
|
6334
|
+
if (path.provider === AFTERMATH) {
|
|
6739
6335
|
version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
|
|
6740
6336
|
}
|
|
6741
6337
|
let extendedDetails;
|
|
6742
|
-
if (path.provider ===
|
|
6338
|
+
if (path.provider === TURBOS || path.provider === AFTERMATH) {
|
|
6743
6339
|
extendedDetails = {
|
|
6744
6340
|
aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
|
|
6745
6341
|
turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type
|
|
@@ -6747,7 +6343,7 @@ function parseRouterResponse(data) {
|
|
|
6747
6343
|
}
|
|
6748
6344
|
return {
|
|
6749
6345
|
id: path.id,
|
|
6750
|
-
|
|
6346
|
+
direction: path.direction,
|
|
6751
6347
|
provider: path.provider,
|
|
6752
6348
|
from: path.from,
|
|
6753
6349
|
target: path.target,
|
|
@@ -6758,13 +6354,93 @@ function parseRouterResponse(data) {
|
|
|
6758
6354
|
version
|
|
6759
6355
|
};
|
|
6760
6356
|
}),
|
|
6761
|
-
amountIn: new
|
|
6762
|
-
amountOut: new
|
|
6357
|
+
amountIn: new import_bn5.default(route.amount_in.toString()),
|
|
6358
|
+
amountOut: new import_bn5.default(route.amount_out.toString()),
|
|
6763
6359
|
initialPrice: new decimal_default(route.initial_price.toString())
|
|
6764
6360
|
};
|
|
6765
6361
|
})
|
|
6766
6362
|
};
|
|
6767
6363
|
}
|
|
6364
|
+
|
|
6365
|
+
// src/transaction/index.ts
|
|
6366
|
+
var CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
|
6367
|
+
|
|
6368
|
+
// src/api.ts
|
|
6369
|
+
function getRouterResult(endpoint, params) {
|
|
6370
|
+
return __async(this, null, function* () {
|
|
6371
|
+
const {
|
|
6372
|
+
from,
|
|
6373
|
+
target,
|
|
6374
|
+
amount,
|
|
6375
|
+
byAmountIn,
|
|
6376
|
+
depth,
|
|
6377
|
+
splitAlgorithm,
|
|
6378
|
+
splitFactor,
|
|
6379
|
+
splitCount,
|
|
6380
|
+
providers
|
|
6381
|
+
} = params;
|
|
6382
|
+
const fromCoin = completionCoin(from);
|
|
6383
|
+
const targetCoin = completionCoin(target);
|
|
6384
|
+
let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
|
|
6385
|
+
if (depth) {
|
|
6386
|
+
url += `&depth=${depth}`;
|
|
6387
|
+
}
|
|
6388
|
+
if (splitAlgorithm) {
|
|
6389
|
+
url += `&split_algorithm=${splitAlgorithm}`;
|
|
6390
|
+
}
|
|
6391
|
+
if (splitFactor) {
|
|
6392
|
+
url += `&split_factor=${splitFactor}`;
|
|
6393
|
+
}
|
|
6394
|
+
if (splitCount) {
|
|
6395
|
+
url += `&split_count=${splitCount}`;
|
|
6396
|
+
}
|
|
6397
|
+
if (providers) {
|
|
6398
|
+
if (providers.length > 0) {
|
|
6399
|
+
url += `&providers=${providers.join(",")}`;
|
|
6400
|
+
}
|
|
6401
|
+
}
|
|
6402
|
+
const response = yield fetch(url);
|
|
6403
|
+
if (!response.ok) {
|
|
6404
|
+
return {
|
|
6405
|
+
amountIn: ZERO,
|
|
6406
|
+
amountOut: ZERO,
|
|
6407
|
+
routes: [],
|
|
6408
|
+
insufficientLiquidity: false,
|
|
6409
|
+
error: {
|
|
6410
|
+
code: 10001 /* NumberTooLarge */,
|
|
6411
|
+
msg: getAggregatorServerErrorMessage(
|
|
6412
|
+
10001 /* NumberTooLarge */
|
|
6413
|
+
)
|
|
6414
|
+
}
|
|
6415
|
+
};
|
|
6416
|
+
}
|
|
6417
|
+
const data = yield response.json();
|
|
6418
|
+
if (data.data != null) {
|
|
6419
|
+
const res = parseRouterResponse(data.data);
|
|
6420
|
+
return res;
|
|
6421
|
+
}
|
|
6422
|
+
const insufficientLiquidity = data.msg === "liquidity is not enough";
|
|
6423
|
+
return {
|
|
6424
|
+
amountIn: ZERO,
|
|
6425
|
+
amountOut: ZERO,
|
|
6426
|
+
routes: [],
|
|
6427
|
+
insufficientLiquidity,
|
|
6428
|
+
error: {
|
|
6429
|
+
code: 10003 /* InsufficientLiquidity */,
|
|
6430
|
+
msg: getAggregatorServerErrorMessage(
|
|
6431
|
+
10003 /* InsufficientLiquidity */
|
|
6432
|
+
)
|
|
6433
|
+
}
|
|
6434
|
+
};
|
|
6435
|
+
});
|
|
6436
|
+
}
|
|
6437
|
+
|
|
6438
|
+
// src/index.ts
|
|
6439
|
+
var Env = /* @__PURE__ */ ((Env2) => {
|
|
6440
|
+
Env2[Env2["Mainnet"] = 0] = "Mainnet";
|
|
6441
|
+
Env2[Env2["Testnet"] = 1] = "Testnet";
|
|
6442
|
+
return Env2;
|
|
6443
|
+
})(Env || {});
|
|
6768
6444
|
/*! Bundled license information:
|
|
6769
6445
|
|
|
6770
6446
|
decimal.js/decimal.mjs:
|
|
@@ -6777,4 +6453,4 @@ decimal.js/decimal.mjs:
|
|
|
6777
6453
|
*)
|
|
6778
6454
|
*/
|
|
6779
6455
|
|
|
6780
|
-
export {
|
|
6456
|
+
export { AFSUI, AFTERMATH, AFTERMATH_MODULE, AggregatorClient5 as AggregatorClient, CETUS, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOKV2, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID2 as DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, Env, FLOWXV2, FLOWX_AMM_MODULE, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, HAEDAL, JOIN_FUNC, KRIYA, KRIYAV3, KRIYA_MODULE, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, ONE, PAY_MODULE, POOL_MODULT, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, composeType, createTarget, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|