@jpool/bond-sdk 0.10.4 → 0.10.5
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 +878 -857
- package/dist/index.d.ts +878 -857
- package/dist/index.js +533 -716
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +524 -711
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1830,8 +1830,8 @@ var require_bn = __commonJS({
|
|
|
1830
1830
|
ctor.prototype = new TempCtor();
|
|
1831
1831
|
ctor.prototype.constructor = ctor;
|
|
1832
1832
|
}
|
|
1833
|
-
function
|
|
1834
|
-
if (
|
|
1833
|
+
function BN4(number, base, endian) {
|
|
1834
|
+
if (BN4.isBN(number)) {
|
|
1835
1835
|
return number;
|
|
1836
1836
|
}
|
|
1837
1837
|
this.negative = 0;
|
|
@@ -1847,12 +1847,12 @@ var require_bn = __commonJS({
|
|
|
1847
1847
|
}
|
|
1848
1848
|
}
|
|
1849
1849
|
if (typeof module2 === "object") {
|
|
1850
|
-
module2.exports =
|
|
1850
|
+
module2.exports = BN4;
|
|
1851
1851
|
} else {
|
|
1852
|
-
exports2.BN =
|
|
1852
|
+
exports2.BN = BN4;
|
|
1853
1853
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1854
|
+
BN4.BN = BN4;
|
|
1855
|
+
BN4.wordSize = 26;
|
|
1856
1856
|
var Buffer2;
|
|
1857
1857
|
try {
|
|
1858
1858
|
if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
|
|
@@ -1862,21 +1862,21 @@ var require_bn = __commonJS({
|
|
|
1862
1862
|
}
|
|
1863
1863
|
} catch (e) {
|
|
1864
1864
|
}
|
|
1865
|
-
|
|
1866
|
-
if (num instanceof
|
|
1865
|
+
BN4.isBN = function isBN(num) {
|
|
1866
|
+
if (num instanceof BN4) {
|
|
1867
1867
|
return true;
|
|
1868
1868
|
}
|
|
1869
|
-
return num !== null && typeof num === "object" && num.constructor.wordSize ===
|
|
1869
|
+
return num !== null && typeof num === "object" && num.constructor.wordSize === BN4.wordSize && Array.isArray(num.words);
|
|
1870
1870
|
};
|
|
1871
|
-
|
|
1871
|
+
BN4.max = function max(left, right) {
|
|
1872
1872
|
if (left.cmp(right) > 0) return left;
|
|
1873
1873
|
return right;
|
|
1874
1874
|
};
|
|
1875
|
-
|
|
1875
|
+
BN4.min = function min(left, right) {
|
|
1876
1876
|
if (left.cmp(right) < 0) return left;
|
|
1877
1877
|
return right;
|
|
1878
1878
|
};
|
|
1879
|
-
|
|
1879
|
+
BN4.prototype._init = function init(number, base, endian) {
|
|
1880
1880
|
if (typeof number === "number") {
|
|
1881
1881
|
return this._initNumber(number, base, endian);
|
|
1882
1882
|
}
|
|
@@ -1904,7 +1904,7 @@ var require_bn = __commonJS({
|
|
|
1904
1904
|
}
|
|
1905
1905
|
}
|
|
1906
1906
|
};
|
|
1907
|
-
|
|
1907
|
+
BN4.prototype._initNumber = function _initNumber(number, base, endian) {
|
|
1908
1908
|
if (number < 0) {
|
|
1909
1909
|
this.negative = 1;
|
|
1910
1910
|
number = -number;
|
|
@@ -1930,7 +1930,7 @@ var require_bn = __commonJS({
|
|
|
1930
1930
|
if (endian !== "le") return;
|
|
1931
1931
|
this._initArray(this.toArray(), base, endian);
|
|
1932
1932
|
};
|
|
1933
|
-
|
|
1933
|
+
BN4.prototype._initArray = function _initArray(number, base, endian) {
|
|
1934
1934
|
assert(typeof number.length === "number");
|
|
1935
1935
|
if (number.length <= 0) {
|
|
1936
1936
|
this.words = [0];
|
|
@@ -1988,7 +1988,7 @@ var require_bn = __commonJS({
|
|
|
1988
1988
|
}
|
|
1989
1989
|
return r;
|
|
1990
1990
|
}
|
|
1991
|
-
|
|
1991
|
+
BN4.prototype._parseHex = function _parseHex(number, start, endian) {
|
|
1992
1992
|
this.length = Math.ceil((number.length - start) / 6);
|
|
1993
1993
|
this.words = new Array(this.length);
|
|
1994
1994
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -2044,7 +2044,7 @@ var require_bn = __commonJS({
|
|
|
2044
2044
|
}
|
|
2045
2045
|
return r;
|
|
2046
2046
|
}
|
|
2047
|
-
|
|
2047
|
+
BN4.prototype._parseBase = function _parseBase(number, base, start) {
|
|
2048
2048
|
this.words = [0];
|
|
2049
2049
|
this.length = 1;
|
|
2050
2050
|
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
|
|
@@ -2080,7 +2080,7 @@ var require_bn = __commonJS({
|
|
|
2080
2080
|
}
|
|
2081
2081
|
this._strip();
|
|
2082
2082
|
};
|
|
2083
|
-
|
|
2083
|
+
BN4.prototype.copy = function copy(dest) {
|
|
2084
2084
|
dest.words = new Array(this.length);
|
|
2085
2085
|
for (var i = 0; i < this.length; i++) {
|
|
2086
2086
|
dest.words[i] = this.words[i];
|
|
@@ -2095,27 +2095,27 @@ var require_bn = __commonJS({
|
|
|
2095
2095
|
dest.negative = src.negative;
|
|
2096
2096
|
dest.red = src.red;
|
|
2097
2097
|
}
|
|
2098
|
-
|
|
2098
|
+
BN4.prototype._move = function _move(dest) {
|
|
2099
2099
|
move(dest, this);
|
|
2100
2100
|
};
|
|
2101
|
-
|
|
2102
|
-
var r = new
|
|
2101
|
+
BN4.prototype.clone = function clone() {
|
|
2102
|
+
var r = new BN4(null);
|
|
2103
2103
|
this.copy(r);
|
|
2104
2104
|
return r;
|
|
2105
2105
|
};
|
|
2106
|
-
|
|
2106
|
+
BN4.prototype._expand = function _expand(size) {
|
|
2107
2107
|
while (this.length < size) {
|
|
2108
2108
|
this.words[this.length++] = 0;
|
|
2109
2109
|
}
|
|
2110
2110
|
return this;
|
|
2111
2111
|
};
|
|
2112
|
-
|
|
2112
|
+
BN4.prototype._strip = function strip() {
|
|
2113
2113
|
while (this.length > 1 && this.words[this.length - 1] === 0) {
|
|
2114
2114
|
this.length--;
|
|
2115
2115
|
}
|
|
2116
2116
|
return this._normSign();
|
|
2117
2117
|
};
|
|
2118
|
-
|
|
2118
|
+
BN4.prototype._normSign = function _normSign() {
|
|
2119
2119
|
if (this.length === 1 && this.words[0] === 0) {
|
|
2120
2120
|
this.negative = 0;
|
|
2121
2121
|
}
|
|
@@ -2123,12 +2123,12 @@ var require_bn = __commonJS({
|
|
|
2123
2123
|
};
|
|
2124
2124
|
if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
|
|
2125
2125
|
try {
|
|
2126
|
-
|
|
2126
|
+
BN4.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
|
|
2127
2127
|
} catch (e) {
|
|
2128
|
-
|
|
2128
|
+
BN4.prototype.inspect = inspect;
|
|
2129
2129
|
}
|
|
2130
2130
|
} else {
|
|
2131
|
-
|
|
2131
|
+
BN4.prototype.inspect = inspect;
|
|
2132
2132
|
}
|
|
2133
2133
|
function inspect() {
|
|
2134
2134
|
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
|
|
@@ -2239,7 +2239,7 @@ var require_bn = __commonJS({
|
|
|
2239
2239
|
52521875,
|
|
2240
2240
|
60466176
|
|
2241
2241
|
];
|
|
2242
|
-
|
|
2242
|
+
BN4.prototype.toString = function toString(base, padding) {
|
|
2243
2243
|
base = base || 10;
|
|
2244
2244
|
padding = padding | 0 || 1;
|
|
2245
2245
|
var out;
|
|
@@ -2301,7 +2301,7 @@ var require_bn = __commonJS({
|
|
|
2301
2301
|
}
|
|
2302
2302
|
assert(false, "Base should be between 2 and 36");
|
|
2303
2303
|
};
|
|
2304
|
-
|
|
2304
|
+
BN4.prototype.toNumber = function toNumber() {
|
|
2305
2305
|
var ret = this.words[0];
|
|
2306
2306
|
if (this.length === 2) {
|
|
2307
2307
|
ret += this.words[1] * 67108864;
|
|
@@ -2312,15 +2312,15 @@ var require_bn = __commonJS({
|
|
|
2312
2312
|
}
|
|
2313
2313
|
return this.negative !== 0 ? -ret : ret;
|
|
2314
2314
|
};
|
|
2315
|
-
|
|
2315
|
+
BN4.prototype.toJSON = function toJSON() {
|
|
2316
2316
|
return this.toString(16, 2);
|
|
2317
2317
|
};
|
|
2318
2318
|
if (Buffer2) {
|
|
2319
|
-
|
|
2319
|
+
BN4.prototype.toBuffer = function toBuffer(endian, length) {
|
|
2320
2320
|
return this.toArrayLike(Buffer2, endian, length);
|
|
2321
2321
|
};
|
|
2322
2322
|
}
|
|
2323
|
-
|
|
2323
|
+
BN4.prototype.toArray = function toArray(endian, length) {
|
|
2324
2324
|
return this.toArrayLike(Array, endian, length);
|
|
2325
2325
|
};
|
|
2326
2326
|
var allocate = function allocate2(ArrayType, size) {
|
|
@@ -2329,7 +2329,7 @@ var require_bn = __commonJS({
|
|
|
2329
2329
|
}
|
|
2330
2330
|
return new ArrayType(size);
|
|
2331
2331
|
};
|
|
2332
|
-
|
|
2332
|
+
BN4.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
|
|
2333
2333
|
this._strip();
|
|
2334
2334
|
var byteLength = this.byteLength();
|
|
2335
2335
|
var reqLength = length || Math.max(1, byteLength);
|
|
@@ -2340,7 +2340,7 @@ var require_bn = __commonJS({
|
|
|
2340
2340
|
this["_toArrayLike" + postfix](res, byteLength);
|
|
2341
2341
|
return res;
|
|
2342
2342
|
};
|
|
2343
|
-
|
|
2343
|
+
BN4.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
|
|
2344
2344
|
var position = 0;
|
|
2345
2345
|
var carry = 0;
|
|
2346
2346
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -2370,7 +2370,7 @@ var require_bn = __commonJS({
|
|
|
2370
2370
|
}
|
|
2371
2371
|
}
|
|
2372
2372
|
};
|
|
2373
|
-
|
|
2373
|
+
BN4.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
|
|
2374
2374
|
var position = res.length - 1;
|
|
2375
2375
|
var carry = 0;
|
|
2376
2376
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -2401,11 +2401,11 @@ var require_bn = __commonJS({
|
|
|
2401
2401
|
}
|
|
2402
2402
|
};
|
|
2403
2403
|
if (Math.clz32) {
|
|
2404
|
-
|
|
2404
|
+
BN4.prototype._countBits = function _countBits(w) {
|
|
2405
2405
|
return 32 - Math.clz32(w);
|
|
2406
2406
|
};
|
|
2407
2407
|
} else {
|
|
2408
|
-
|
|
2408
|
+
BN4.prototype._countBits = function _countBits(w) {
|
|
2409
2409
|
var t = w;
|
|
2410
2410
|
var r = 0;
|
|
2411
2411
|
if (t >= 4096) {
|
|
@@ -2427,7 +2427,7 @@ var require_bn = __commonJS({
|
|
|
2427
2427
|
return r + t;
|
|
2428
2428
|
};
|
|
2429
2429
|
}
|
|
2430
|
-
|
|
2430
|
+
BN4.prototype._zeroBits = function _zeroBits(w) {
|
|
2431
2431
|
if (w === 0) return 26;
|
|
2432
2432
|
var t = w;
|
|
2433
2433
|
var r = 0;
|
|
@@ -2452,7 +2452,7 @@ var require_bn = __commonJS({
|
|
|
2452
2452
|
}
|
|
2453
2453
|
return r;
|
|
2454
2454
|
};
|
|
2455
|
-
|
|
2455
|
+
BN4.prototype.bitLength = function bitLength() {
|
|
2456
2456
|
var w = this.words[this.length - 1];
|
|
2457
2457
|
var hi = this._countBits(w);
|
|
2458
2458
|
return (this.length - 1) * 26 + hi;
|
|
@@ -2466,7 +2466,7 @@ var require_bn = __commonJS({
|
|
|
2466
2466
|
}
|
|
2467
2467
|
return w;
|
|
2468
2468
|
}
|
|
2469
|
-
|
|
2469
|
+
BN4.prototype.zeroBits = function zeroBits() {
|
|
2470
2470
|
if (this.isZero()) return 0;
|
|
2471
2471
|
var r = 0;
|
|
2472
2472
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -2476,34 +2476,34 @@ var require_bn = __commonJS({
|
|
|
2476
2476
|
}
|
|
2477
2477
|
return r;
|
|
2478
2478
|
};
|
|
2479
|
-
|
|
2479
|
+
BN4.prototype.byteLength = function byteLength() {
|
|
2480
2480
|
return Math.ceil(this.bitLength() / 8);
|
|
2481
2481
|
};
|
|
2482
|
-
|
|
2482
|
+
BN4.prototype.toTwos = function toTwos(width) {
|
|
2483
2483
|
if (this.negative !== 0) {
|
|
2484
2484
|
return this.abs().inotn(width).iaddn(1);
|
|
2485
2485
|
}
|
|
2486
2486
|
return this.clone();
|
|
2487
2487
|
};
|
|
2488
|
-
|
|
2488
|
+
BN4.prototype.fromTwos = function fromTwos(width) {
|
|
2489
2489
|
if (this.testn(width - 1)) {
|
|
2490
2490
|
return this.notn(width).iaddn(1).ineg();
|
|
2491
2491
|
}
|
|
2492
2492
|
return this.clone();
|
|
2493
2493
|
};
|
|
2494
|
-
|
|
2494
|
+
BN4.prototype.isNeg = function isNeg() {
|
|
2495
2495
|
return this.negative !== 0;
|
|
2496
2496
|
};
|
|
2497
|
-
|
|
2497
|
+
BN4.prototype.neg = function neg() {
|
|
2498
2498
|
return this.clone().ineg();
|
|
2499
2499
|
};
|
|
2500
|
-
|
|
2500
|
+
BN4.prototype.ineg = function ineg() {
|
|
2501
2501
|
if (!this.isZero()) {
|
|
2502
2502
|
this.negative ^= 1;
|
|
2503
2503
|
}
|
|
2504
2504
|
return this;
|
|
2505
2505
|
};
|
|
2506
|
-
|
|
2506
|
+
BN4.prototype.iuor = function iuor(num) {
|
|
2507
2507
|
while (this.length < num.length) {
|
|
2508
2508
|
this.words[this.length++] = 0;
|
|
2509
2509
|
}
|
|
@@ -2512,19 +2512,19 @@ var require_bn = __commonJS({
|
|
|
2512
2512
|
}
|
|
2513
2513
|
return this._strip();
|
|
2514
2514
|
};
|
|
2515
|
-
|
|
2515
|
+
BN4.prototype.ior = function ior(num) {
|
|
2516
2516
|
assert((this.negative | num.negative) === 0);
|
|
2517
2517
|
return this.iuor(num);
|
|
2518
2518
|
};
|
|
2519
|
-
|
|
2519
|
+
BN4.prototype.or = function or(num) {
|
|
2520
2520
|
if (this.length > num.length) return this.clone().ior(num);
|
|
2521
2521
|
return num.clone().ior(this);
|
|
2522
2522
|
};
|
|
2523
|
-
|
|
2523
|
+
BN4.prototype.uor = function uor(num) {
|
|
2524
2524
|
if (this.length > num.length) return this.clone().iuor(num);
|
|
2525
2525
|
return num.clone().iuor(this);
|
|
2526
2526
|
};
|
|
2527
|
-
|
|
2527
|
+
BN4.prototype.iuand = function iuand(num) {
|
|
2528
2528
|
var b;
|
|
2529
2529
|
if (this.length > num.length) {
|
|
2530
2530
|
b = num;
|
|
@@ -2537,19 +2537,19 @@ var require_bn = __commonJS({
|
|
|
2537
2537
|
this.length = b.length;
|
|
2538
2538
|
return this._strip();
|
|
2539
2539
|
};
|
|
2540
|
-
|
|
2540
|
+
BN4.prototype.iand = function iand(num) {
|
|
2541
2541
|
assert((this.negative | num.negative) === 0);
|
|
2542
2542
|
return this.iuand(num);
|
|
2543
2543
|
};
|
|
2544
|
-
|
|
2544
|
+
BN4.prototype.and = function and(num) {
|
|
2545
2545
|
if (this.length > num.length) return this.clone().iand(num);
|
|
2546
2546
|
return num.clone().iand(this);
|
|
2547
2547
|
};
|
|
2548
|
-
|
|
2548
|
+
BN4.prototype.uand = function uand(num) {
|
|
2549
2549
|
if (this.length > num.length) return this.clone().iuand(num);
|
|
2550
2550
|
return num.clone().iuand(this);
|
|
2551
2551
|
};
|
|
2552
|
-
|
|
2552
|
+
BN4.prototype.iuxor = function iuxor(num) {
|
|
2553
2553
|
var a;
|
|
2554
2554
|
var b;
|
|
2555
2555
|
if (this.length > num.length) {
|
|
@@ -2570,19 +2570,19 @@ var require_bn = __commonJS({
|
|
|
2570
2570
|
this.length = a.length;
|
|
2571
2571
|
return this._strip();
|
|
2572
2572
|
};
|
|
2573
|
-
|
|
2573
|
+
BN4.prototype.ixor = function ixor(num) {
|
|
2574
2574
|
assert((this.negative | num.negative) === 0);
|
|
2575
2575
|
return this.iuxor(num);
|
|
2576
2576
|
};
|
|
2577
|
-
|
|
2577
|
+
BN4.prototype.xor = function xor(num) {
|
|
2578
2578
|
if (this.length > num.length) return this.clone().ixor(num);
|
|
2579
2579
|
return num.clone().ixor(this);
|
|
2580
2580
|
};
|
|
2581
|
-
|
|
2581
|
+
BN4.prototype.uxor = function uxor(num) {
|
|
2582
2582
|
if (this.length > num.length) return this.clone().iuxor(num);
|
|
2583
2583
|
return num.clone().iuxor(this);
|
|
2584
2584
|
};
|
|
2585
|
-
|
|
2585
|
+
BN4.prototype.inotn = function inotn(width) {
|
|
2586
2586
|
assert(typeof width === "number" && width >= 0);
|
|
2587
2587
|
var bytesNeeded = Math.ceil(width / 26) | 0;
|
|
2588
2588
|
var bitsLeft = width % 26;
|
|
@@ -2598,10 +2598,10 @@ var require_bn = __commonJS({
|
|
|
2598
2598
|
}
|
|
2599
2599
|
return this._strip();
|
|
2600
2600
|
};
|
|
2601
|
-
|
|
2601
|
+
BN4.prototype.notn = function notn(width) {
|
|
2602
2602
|
return this.clone().inotn(width);
|
|
2603
2603
|
};
|
|
2604
|
-
|
|
2604
|
+
BN4.prototype.setn = function setn(bit, val) {
|
|
2605
2605
|
assert(typeof bit === "number" && bit >= 0);
|
|
2606
2606
|
var off = bit / 26 | 0;
|
|
2607
2607
|
var wbit = bit % 26;
|
|
@@ -2613,7 +2613,7 @@ var require_bn = __commonJS({
|
|
|
2613
2613
|
}
|
|
2614
2614
|
return this._strip();
|
|
2615
2615
|
};
|
|
2616
|
-
|
|
2616
|
+
BN4.prototype.iadd = function iadd(num) {
|
|
2617
2617
|
var r;
|
|
2618
2618
|
if (this.negative !== 0 && num.negative === 0) {
|
|
2619
2619
|
this.negative = 0;
|
|
@@ -2656,7 +2656,7 @@ var require_bn = __commonJS({
|
|
|
2656
2656
|
}
|
|
2657
2657
|
return this;
|
|
2658
2658
|
};
|
|
2659
|
-
|
|
2659
|
+
BN4.prototype.add = function add(num) {
|
|
2660
2660
|
var res;
|
|
2661
2661
|
if (num.negative !== 0 && this.negative === 0) {
|
|
2662
2662
|
num.negative = 0;
|
|
@@ -2672,7 +2672,7 @@ var require_bn = __commonJS({
|
|
|
2672
2672
|
if (this.length > num.length) return this.clone().iadd(num);
|
|
2673
2673
|
return num.clone().iadd(this);
|
|
2674
2674
|
};
|
|
2675
|
-
|
|
2675
|
+
BN4.prototype.isub = function isub(num) {
|
|
2676
2676
|
if (num.negative !== 0) {
|
|
2677
2677
|
num.negative = 0;
|
|
2678
2678
|
var r = this.iadd(num);
|
|
@@ -2721,7 +2721,7 @@ var require_bn = __commonJS({
|
|
|
2721
2721
|
}
|
|
2722
2722
|
return this._strip();
|
|
2723
2723
|
};
|
|
2724
|
-
|
|
2724
|
+
BN4.prototype.sub = function sub(num) {
|
|
2725
2725
|
return this.clone().isub(num);
|
|
2726
2726
|
};
|
|
2727
2727
|
function smallMulTo(self, num, out) {
|
|
@@ -3349,7 +3349,7 @@ var require_bn = __commonJS({
|
|
|
3349
3349
|
function jumboMulTo(self, num, out) {
|
|
3350
3350
|
return bigMulTo(self, num, out);
|
|
3351
3351
|
}
|
|
3352
|
-
|
|
3352
|
+
BN4.prototype.mulTo = function mulTo(num, out) {
|
|
3353
3353
|
var res;
|
|
3354
3354
|
var len = this.length + num.length;
|
|
3355
3355
|
if (this.length === 10 && num.length === 10) {
|
|
@@ -3363,20 +3363,20 @@ var require_bn = __commonJS({
|
|
|
3363
3363
|
}
|
|
3364
3364
|
return res;
|
|
3365
3365
|
};
|
|
3366
|
-
|
|
3367
|
-
var out = new
|
|
3366
|
+
BN4.prototype.mul = function mul(num) {
|
|
3367
|
+
var out = new BN4(null);
|
|
3368
3368
|
out.words = new Array(this.length + num.length);
|
|
3369
3369
|
return this.mulTo(num, out);
|
|
3370
3370
|
};
|
|
3371
|
-
|
|
3372
|
-
var out = new
|
|
3371
|
+
BN4.prototype.mulf = function mulf(num) {
|
|
3372
|
+
var out = new BN4(null);
|
|
3373
3373
|
out.words = new Array(this.length + num.length);
|
|
3374
3374
|
return jumboMulTo(this, num, out);
|
|
3375
3375
|
};
|
|
3376
|
-
|
|
3376
|
+
BN4.prototype.imul = function imul(num) {
|
|
3377
3377
|
return this.clone().mulTo(num, this);
|
|
3378
3378
|
};
|
|
3379
|
-
|
|
3379
|
+
BN4.prototype.imuln = function imuln(num) {
|
|
3380
3380
|
var isNegNum = num < 0;
|
|
3381
3381
|
if (isNegNum) num = -num;
|
|
3382
3382
|
assert(typeof num === "number");
|
|
@@ -3397,18 +3397,18 @@ var require_bn = __commonJS({
|
|
|
3397
3397
|
this.length = num === 0 ? 1 : this.length;
|
|
3398
3398
|
return isNegNum ? this.ineg() : this;
|
|
3399
3399
|
};
|
|
3400
|
-
|
|
3400
|
+
BN4.prototype.muln = function muln(num) {
|
|
3401
3401
|
return this.clone().imuln(num);
|
|
3402
3402
|
};
|
|
3403
|
-
|
|
3403
|
+
BN4.prototype.sqr = function sqr() {
|
|
3404
3404
|
return this.mul(this);
|
|
3405
3405
|
};
|
|
3406
|
-
|
|
3406
|
+
BN4.prototype.isqr = function isqr() {
|
|
3407
3407
|
return this.imul(this.clone());
|
|
3408
3408
|
};
|
|
3409
|
-
|
|
3409
|
+
BN4.prototype.pow = function pow(num) {
|
|
3410
3410
|
var w = toBitArray(num);
|
|
3411
|
-
if (w.length === 0) return new
|
|
3411
|
+
if (w.length === 0) return new BN4(1);
|
|
3412
3412
|
var res = this;
|
|
3413
3413
|
for (var i = 0; i < w.length; i++, res = res.sqr()) {
|
|
3414
3414
|
if (w[i] !== 0) break;
|
|
@@ -3421,7 +3421,7 @@ var require_bn = __commonJS({
|
|
|
3421
3421
|
}
|
|
3422
3422
|
return res;
|
|
3423
3423
|
};
|
|
3424
|
-
|
|
3424
|
+
BN4.prototype.iushln = function iushln(bits) {
|
|
3425
3425
|
assert(typeof bits === "number" && bits >= 0);
|
|
3426
3426
|
var r = bits % 26;
|
|
3427
3427
|
var s = (bits - r) / 26;
|
|
@@ -3451,11 +3451,11 @@ var require_bn = __commonJS({
|
|
|
3451
3451
|
}
|
|
3452
3452
|
return this._strip();
|
|
3453
3453
|
};
|
|
3454
|
-
|
|
3454
|
+
BN4.prototype.ishln = function ishln(bits) {
|
|
3455
3455
|
assert(this.negative === 0);
|
|
3456
3456
|
return this.iushln(bits);
|
|
3457
3457
|
};
|
|
3458
|
-
|
|
3458
|
+
BN4.prototype.iushrn = function iushrn(bits, hint, extended) {
|
|
3459
3459
|
assert(typeof bits === "number" && bits >= 0);
|
|
3460
3460
|
var h;
|
|
3461
3461
|
if (hint) {
|
|
@@ -3499,23 +3499,23 @@ var require_bn = __commonJS({
|
|
|
3499
3499
|
}
|
|
3500
3500
|
return this._strip();
|
|
3501
3501
|
};
|
|
3502
|
-
|
|
3502
|
+
BN4.prototype.ishrn = function ishrn(bits, hint, extended) {
|
|
3503
3503
|
assert(this.negative === 0);
|
|
3504
3504
|
return this.iushrn(bits, hint, extended);
|
|
3505
3505
|
};
|
|
3506
|
-
|
|
3506
|
+
BN4.prototype.shln = function shln(bits) {
|
|
3507
3507
|
return this.clone().ishln(bits);
|
|
3508
3508
|
};
|
|
3509
|
-
|
|
3509
|
+
BN4.prototype.ushln = function ushln(bits) {
|
|
3510
3510
|
return this.clone().iushln(bits);
|
|
3511
3511
|
};
|
|
3512
|
-
|
|
3512
|
+
BN4.prototype.shrn = function shrn(bits) {
|
|
3513
3513
|
return this.clone().ishrn(bits);
|
|
3514
3514
|
};
|
|
3515
|
-
|
|
3515
|
+
BN4.prototype.ushrn = function ushrn(bits) {
|
|
3516
3516
|
return this.clone().iushrn(bits);
|
|
3517
3517
|
};
|
|
3518
|
-
|
|
3518
|
+
BN4.prototype.testn = function testn(bit) {
|
|
3519
3519
|
assert(typeof bit === "number" && bit >= 0);
|
|
3520
3520
|
var r = bit % 26;
|
|
3521
3521
|
var s = (bit - r) / 26;
|
|
@@ -3524,7 +3524,7 @@ var require_bn = __commonJS({
|
|
|
3524
3524
|
var w = this.words[s];
|
|
3525
3525
|
return !!(w & q);
|
|
3526
3526
|
};
|
|
3527
|
-
|
|
3527
|
+
BN4.prototype.imaskn = function imaskn(bits) {
|
|
3528
3528
|
assert(typeof bits === "number" && bits >= 0);
|
|
3529
3529
|
var r = bits % 26;
|
|
3530
3530
|
var s = (bits - r) / 26;
|
|
@@ -3542,10 +3542,10 @@ var require_bn = __commonJS({
|
|
|
3542
3542
|
}
|
|
3543
3543
|
return this._strip();
|
|
3544
3544
|
};
|
|
3545
|
-
|
|
3545
|
+
BN4.prototype.maskn = function maskn(bits) {
|
|
3546
3546
|
return this.clone().imaskn(bits);
|
|
3547
3547
|
};
|
|
3548
|
-
|
|
3548
|
+
BN4.prototype.iaddn = function iaddn(num) {
|
|
3549
3549
|
assert(typeof num === "number");
|
|
3550
3550
|
assert(num < 67108864);
|
|
3551
3551
|
if (num < 0) return this.isubn(-num);
|
|
@@ -3562,7 +3562,7 @@ var require_bn = __commonJS({
|
|
|
3562
3562
|
}
|
|
3563
3563
|
return this._iaddn(num);
|
|
3564
3564
|
};
|
|
3565
|
-
|
|
3565
|
+
BN4.prototype._iaddn = function _iaddn(num) {
|
|
3566
3566
|
this.words[0] += num;
|
|
3567
3567
|
for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
|
|
3568
3568
|
this.words[i] -= 67108864;
|
|
@@ -3575,7 +3575,7 @@ var require_bn = __commonJS({
|
|
|
3575
3575
|
this.length = Math.max(this.length, i + 1);
|
|
3576
3576
|
return this;
|
|
3577
3577
|
};
|
|
3578
|
-
|
|
3578
|
+
BN4.prototype.isubn = function isubn(num) {
|
|
3579
3579
|
assert(typeof num === "number");
|
|
3580
3580
|
assert(num < 67108864);
|
|
3581
3581
|
if (num < 0) return this.iaddn(-num);
|
|
@@ -3597,20 +3597,20 @@ var require_bn = __commonJS({
|
|
|
3597
3597
|
}
|
|
3598
3598
|
return this._strip();
|
|
3599
3599
|
};
|
|
3600
|
-
|
|
3600
|
+
BN4.prototype.addn = function addn(num) {
|
|
3601
3601
|
return this.clone().iaddn(num);
|
|
3602
3602
|
};
|
|
3603
|
-
|
|
3603
|
+
BN4.prototype.subn = function subn(num) {
|
|
3604
3604
|
return this.clone().isubn(num);
|
|
3605
3605
|
};
|
|
3606
|
-
|
|
3606
|
+
BN4.prototype.iabs = function iabs() {
|
|
3607
3607
|
this.negative = 0;
|
|
3608
3608
|
return this;
|
|
3609
3609
|
};
|
|
3610
|
-
|
|
3610
|
+
BN4.prototype.abs = function abs() {
|
|
3611
3611
|
return this.clone().iabs();
|
|
3612
3612
|
};
|
|
3613
|
-
|
|
3613
|
+
BN4.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
|
|
3614
3614
|
var len = num.length + shift;
|
|
3615
3615
|
var i;
|
|
3616
3616
|
this._expand(len);
|
|
@@ -3639,7 +3639,7 @@ var require_bn = __commonJS({
|
|
|
3639
3639
|
this.negative = 1;
|
|
3640
3640
|
return this._strip();
|
|
3641
3641
|
};
|
|
3642
|
-
|
|
3642
|
+
BN4.prototype._wordDiv = function _wordDiv(num, mode) {
|
|
3643
3643
|
var shift = this.length - num.length;
|
|
3644
3644
|
var a = this.clone();
|
|
3645
3645
|
var b = num;
|
|
@@ -3654,7 +3654,7 @@ var require_bn = __commonJS({
|
|
|
3654
3654
|
var m = a.length - b.length;
|
|
3655
3655
|
var q;
|
|
3656
3656
|
if (mode !== "mod") {
|
|
3657
|
-
q = new
|
|
3657
|
+
q = new BN4(null);
|
|
3658
3658
|
q.length = m + 1;
|
|
3659
3659
|
q.words = new Array(q.length);
|
|
3660
3660
|
for (var i = 0; i < q.length; i++) {
|
|
@@ -3696,12 +3696,12 @@ var require_bn = __commonJS({
|
|
|
3696
3696
|
mod: a
|
|
3697
3697
|
};
|
|
3698
3698
|
};
|
|
3699
|
-
|
|
3699
|
+
BN4.prototype.divmod = function divmod(num, mode, positive) {
|
|
3700
3700
|
assert(!num.isZero());
|
|
3701
3701
|
if (this.isZero()) {
|
|
3702
3702
|
return {
|
|
3703
|
-
div: new
|
|
3704
|
-
mod: new
|
|
3703
|
+
div: new BN4(0),
|
|
3704
|
+
mod: new BN4(0)
|
|
3705
3705
|
};
|
|
3706
3706
|
}
|
|
3707
3707
|
var div, mod, res;
|
|
@@ -3746,7 +3746,7 @@ var require_bn = __commonJS({
|
|
|
3746
3746
|
}
|
|
3747
3747
|
if (num.length > this.length || this.cmp(num) < 0) {
|
|
3748
3748
|
return {
|
|
3749
|
-
div: new
|
|
3749
|
+
div: new BN4(0),
|
|
3750
3750
|
mod: this
|
|
3751
3751
|
};
|
|
3752
3752
|
}
|
|
@@ -3760,26 +3760,26 @@ var require_bn = __commonJS({
|
|
|
3760
3760
|
if (mode === "mod") {
|
|
3761
3761
|
return {
|
|
3762
3762
|
div: null,
|
|
3763
|
-
mod: new
|
|
3763
|
+
mod: new BN4(this.modrn(num.words[0]))
|
|
3764
3764
|
};
|
|
3765
3765
|
}
|
|
3766
3766
|
return {
|
|
3767
3767
|
div: this.divn(num.words[0]),
|
|
3768
|
-
mod: new
|
|
3768
|
+
mod: new BN4(this.modrn(num.words[0]))
|
|
3769
3769
|
};
|
|
3770
3770
|
}
|
|
3771
3771
|
return this._wordDiv(num, mode);
|
|
3772
3772
|
};
|
|
3773
|
-
|
|
3773
|
+
BN4.prototype.div = function div(num) {
|
|
3774
3774
|
return this.divmod(num, "div", false).div;
|
|
3775
3775
|
};
|
|
3776
|
-
|
|
3776
|
+
BN4.prototype.mod = function mod(num) {
|
|
3777
3777
|
return this.divmod(num, "mod", false).mod;
|
|
3778
3778
|
};
|
|
3779
|
-
|
|
3779
|
+
BN4.prototype.umod = function umod(num) {
|
|
3780
3780
|
return this.divmod(num, "mod", true).mod;
|
|
3781
3781
|
};
|
|
3782
|
-
|
|
3782
|
+
BN4.prototype.divRound = function divRound(num) {
|
|
3783
3783
|
var dm = this.divmod(num);
|
|
3784
3784
|
if (dm.mod.isZero()) return dm.div;
|
|
3785
3785
|
var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
|
|
@@ -3789,7 +3789,7 @@ var require_bn = __commonJS({
|
|
|
3789
3789
|
if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
|
|
3790
3790
|
return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
|
|
3791
3791
|
};
|
|
3792
|
-
|
|
3792
|
+
BN4.prototype.modrn = function modrn(num) {
|
|
3793
3793
|
var isNegNum = num < 0;
|
|
3794
3794
|
if (isNegNum) num = -num;
|
|
3795
3795
|
assert(num <= 67108863);
|
|
@@ -3800,10 +3800,10 @@ var require_bn = __commonJS({
|
|
|
3800
3800
|
}
|
|
3801
3801
|
return isNegNum ? -acc : acc;
|
|
3802
3802
|
};
|
|
3803
|
-
|
|
3803
|
+
BN4.prototype.modn = function modn(num) {
|
|
3804
3804
|
return this.modrn(num);
|
|
3805
3805
|
};
|
|
3806
|
-
|
|
3806
|
+
BN4.prototype.idivn = function idivn(num) {
|
|
3807
3807
|
var isNegNum = num < 0;
|
|
3808
3808
|
if (isNegNum) num = -num;
|
|
3809
3809
|
assert(num <= 67108863);
|
|
@@ -3816,10 +3816,10 @@ var require_bn = __commonJS({
|
|
|
3816
3816
|
this._strip();
|
|
3817
3817
|
return isNegNum ? this.ineg() : this;
|
|
3818
3818
|
};
|
|
3819
|
-
|
|
3819
|
+
BN4.prototype.divn = function divn(num) {
|
|
3820
3820
|
return this.clone().idivn(num);
|
|
3821
3821
|
};
|
|
3822
|
-
|
|
3822
|
+
BN4.prototype.egcd = function egcd(p) {
|
|
3823
3823
|
assert(p.negative === 0);
|
|
3824
3824
|
assert(!p.isZero());
|
|
3825
3825
|
var x = this;
|
|
@@ -3829,10 +3829,10 @@ var require_bn = __commonJS({
|
|
|
3829
3829
|
} else {
|
|
3830
3830
|
x = x.clone();
|
|
3831
3831
|
}
|
|
3832
|
-
var A = new
|
|
3833
|
-
var B = new
|
|
3834
|
-
var C = new
|
|
3835
|
-
var D = new
|
|
3832
|
+
var A = new BN4(1);
|
|
3833
|
+
var B = new BN4(0);
|
|
3834
|
+
var C = new BN4(0);
|
|
3835
|
+
var D = new BN4(1);
|
|
3836
3836
|
var g = 0;
|
|
3837
3837
|
while (x.isEven() && y.isEven()) {
|
|
3838
3838
|
x.iushrn(1);
|
|
@@ -3882,7 +3882,7 @@ var require_bn = __commonJS({
|
|
|
3882
3882
|
gcd: y.iushln(g)
|
|
3883
3883
|
};
|
|
3884
3884
|
};
|
|
3885
|
-
|
|
3885
|
+
BN4.prototype._invmp = function _invmp(p) {
|
|
3886
3886
|
assert(p.negative === 0);
|
|
3887
3887
|
assert(!p.isZero());
|
|
3888
3888
|
var a = this;
|
|
@@ -3892,8 +3892,8 @@ var require_bn = __commonJS({
|
|
|
3892
3892
|
} else {
|
|
3893
3893
|
a = a.clone();
|
|
3894
3894
|
}
|
|
3895
|
-
var x1 = new
|
|
3896
|
-
var x2 = new
|
|
3895
|
+
var x1 = new BN4(1);
|
|
3896
|
+
var x2 = new BN4(0);
|
|
3897
3897
|
var delta = b.clone();
|
|
3898
3898
|
while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
|
|
3899
3899
|
for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
|
|
@@ -3935,7 +3935,7 @@ var require_bn = __commonJS({
|
|
|
3935
3935
|
}
|
|
3936
3936
|
return res;
|
|
3937
3937
|
};
|
|
3938
|
-
|
|
3938
|
+
BN4.prototype.gcd = function gcd(num) {
|
|
3939
3939
|
if (this.isZero()) return num.abs();
|
|
3940
3940
|
if (num.isZero()) return this.abs();
|
|
3941
3941
|
var a = this.clone();
|
|
@@ -3965,19 +3965,19 @@ var require_bn = __commonJS({
|
|
|
3965
3965
|
} while (true);
|
|
3966
3966
|
return b.iushln(shift);
|
|
3967
3967
|
};
|
|
3968
|
-
|
|
3968
|
+
BN4.prototype.invm = function invm(num) {
|
|
3969
3969
|
return this.egcd(num).a.umod(num);
|
|
3970
3970
|
};
|
|
3971
|
-
|
|
3971
|
+
BN4.prototype.isEven = function isEven() {
|
|
3972
3972
|
return (this.words[0] & 1) === 0;
|
|
3973
3973
|
};
|
|
3974
|
-
|
|
3974
|
+
BN4.prototype.isOdd = function isOdd() {
|
|
3975
3975
|
return (this.words[0] & 1) === 1;
|
|
3976
3976
|
};
|
|
3977
|
-
|
|
3977
|
+
BN4.prototype.andln = function andln(num) {
|
|
3978
3978
|
return this.words[0] & num;
|
|
3979
3979
|
};
|
|
3980
|
-
|
|
3980
|
+
BN4.prototype.bincn = function bincn(bit) {
|
|
3981
3981
|
assert(typeof bit === "number");
|
|
3982
3982
|
var r = bit % 26;
|
|
3983
3983
|
var s = (bit - r) / 26;
|
|
@@ -4001,10 +4001,10 @@ var require_bn = __commonJS({
|
|
|
4001
4001
|
}
|
|
4002
4002
|
return this;
|
|
4003
4003
|
};
|
|
4004
|
-
|
|
4004
|
+
BN4.prototype.isZero = function isZero() {
|
|
4005
4005
|
return this.length === 1 && this.words[0] === 0;
|
|
4006
4006
|
};
|
|
4007
|
-
|
|
4007
|
+
BN4.prototype.cmpn = function cmpn(num) {
|
|
4008
4008
|
var negative = num < 0;
|
|
4009
4009
|
if (this.negative !== 0 && !negative) return -1;
|
|
4010
4010
|
if (this.negative === 0 && negative) return 1;
|
|
@@ -4023,14 +4023,14 @@ var require_bn = __commonJS({
|
|
|
4023
4023
|
if (this.negative !== 0) return -res | 0;
|
|
4024
4024
|
return res;
|
|
4025
4025
|
};
|
|
4026
|
-
|
|
4026
|
+
BN4.prototype.cmp = function cmp(num) {
|
|
4027
4027
|
if (this.negative !== 0 && num.negative === 0) return -1;
|
|
4028
4028
|
if (this.negative === 0 && num.negative !== 0) return 1;
|
|
4029
4029
|
var res = this.ucmp(num);
|
|
4030
4030
|
if (this.negative !== 0) return -res | 0;
|
|
4031
4031
|
return res;
|
|
4032
4032
|
};
|
|
4033
|
-
|
|
4033
|
+
BN4.prototype.ucmp = function ucmp(num) {
|
|
4034
4034
|
if (this.length > num.length) return 1;
|
|
4035
4035
|
if (this.length < num.length) return -1;
|
|
4036
4036
|
var res = 0;
|
|
@@ -4047,112 +4047,112 @@ var require_bn = __commonJS({
|
|
|
4047
4047
|
}
|
|
4048
4048
|
return res;
|
|
4049
4049
|
};
|
|
4050
|
-
|
|
4050
|
+
BN4.prototype.gtn = function gtn(num) {
|
|
4051
4051
|
return this.cmpn(num) === 1;
|
|
4052
4052
|
};
|
|
4053
|
-
|
|
4053
|
+
BN4.prototype.gt = function gt(num) {
|
|
4054
4054
|
return this.cmp(num) === 1;
|
|
4055
4055
|
};
|
|
4056
|
-
|
|
4056
|
+
BN4.prototype.gten = function gten(num) {
|
|
4057
4057
|
return this.cmpn(num) >= 0;
|
|
4058
4058
|
};
|
|
4059
|
-
|
|
4059
|
+
BN4.prototype.gte = function gte(num) {
|
|
4060
4060
|
return this.cmp(num) >= 0;
|
|
4061
4061
|
};
|
|
4062
|
-
|
|
4062
|
+
BN4.prototype.ltn = function ltn(num) {
|
|
4063
4063
|
return this.cmpn(num) === -1;
|
|
4064
4064
|
};
|
|
4065
|
-
|
|
4065
|
+
BN4.prototype.lt = function lt(num) {
|
|
4066
4066
|
return this.cmp(num) === -1;
|
|
4067
4067
|
};
|
|
4068
|
-
|
|
4068
|
+
BN4.prototype.lten = function lten(num) {
|
|
4069
4069
|
return this.cmpn(num) <= 0;
|
|
4070
4070
|
};
|
|
4071
|
-
|
|
4071
|
+
BN4.prototype.lte = function lte(num) {
|
|
4072
4072
|
return this.cmp(num) <= 0;
|
|
4073
4073
|
};
|
|
4074
|
-
|
|
4074
|
+
BN4.prototype.eqn = function eqn(num) {
|
|
4075
4075
|
return this.cmpn(num) === 0;
|
|
4076
4076
|
};
|
|
4077
|
-
|
|
4077
|
+
BN4.prototype.eq = function eq(num) {
|
|
4078
4078
|
return this.cmp(num) === 0;
|
|
4079
4079
|
};
|
|
4080
|
-
|
|
4080
|
+
BN4.red = function red(num) {
|
|
4081
4081
|
return new Red(num);
|
|
4082
4082
|
};
|
|
4083
|
-
|
|
4083
|
+
BN4.prototype.toRed = function toRed(ctx) {
|
|
4084
4084
|
assert(!this.red, "Already a number in reduction context");
|
|
4085
4085
|
assert(this.negative === 0, "red works only with positives");
|
|
4086
4086
|
return ctx.convertTo(this)._forceRed(ctx);
|
|
4087
4087
|
};
|
|
4088
|
-
|
|
4088
|
+
BN4.prototype.fromRed = function fromRed() {
|
|
4089
4089
|
assert(this.red, "fromRed works only with numbers in reduction context");
|
|
4090
4090
|
return this.red.convertFrom(this);
|
|
4091
4091
|
};
|
|
4092
|
-
|
|
4092
|
+
BN4.prototype._forceRed = function _forceRed(ctx) {
|
|
4093
4093
|
this.red = ctx;
|
|
4094
4094
|
return this;
|
|
4095
4095
|
};
|
|
4096
|
-
|
|
4096
|
+
BN4.prototype.forceRed = function forceRed(ctx) {
|
|
4097
4097
|
assert(!this.red, "Already a number in reduction context");
|
|
4098
4098
|
return this._forceRed(ctx);
|
|
4099
4099
|
};
|
|
4100
|
-
|
|
4100
|
+
BN4.prototype.redAdd = function redAdd(num) {
|
|
4101
4101
|
assert(this.red, "redAdd works only with red numbers");
|
|
4102
4102
|
return this.red.add(this, num);
|
|
4103
4103
|
};
|
|
4104
|
-
|
|
4104
|
+
BN4.prototype.redIAdd = function redIAdd(num) {
|
|
4105
4105
|
assert(this.red, "redIAdd works only with red numbers");
|
|
4106
4106
|
return this.red.iadd(this, num);
|
|
4107
4107
|
};
|
|
4108
|
-
|
|
4108
|
+
BN4.prototype.redSub = function redSub(num) {
|
|
4109
4109
|
assert(this.red, "redSub works only with red numbers");
|
|
4110
4110
|
return this.red.sub(this, num);
|
|
4111
4111
|
};
|
|
4112
|
-
|
|
4112
|
+
BN4.prototype.redISub = function redISub(num) {
|
|
4113
4113
|
assert(this.red, "redISub works only with red numbers");
|
|
4114
4114
|
return this.red.isub(this, num);
|
|
4115
4115
|
};
|
|
4116
|
-
|
|
4116
|
+
BN4.prototype.redShl = function redShl(num) {
|
|
4117
4117
|
assert(this.red, "redShl works only with red numbers");
|
|
4118
4118
|
return this.red.shl(this, num);
|
|
4119
4119
|
};
|
|
4120
|
-
|
|
4120
|
+
BN4.prototype.redMul = function redMul(num) {
|
|
4121
4121
|
assert(this.red, "redMul works only with red numbers");
|
|
4122
4122
|
this.red._verify2(this, num);
|
|
4123
4123
|
return this.red.mul(this, num);
|
|
4124
4124
|
};
|
|
4125
|
-
|
|
4125
|
+
BN4.prototype.redIMul = function redIMul(num) {
|
|
4126
4126
|
assert(this.red, "redMul works only with red numbers");
|
|
4127
4127
|
this.red._verify2(this, num);
|
|
4128
4128
|
return this.red.imul(this, num);
|
|
4129
4129
|
};
|
|
4130
|
-
|
|
4130
|
+
BN4.prototype.redSqr = function redSqr() {
|
|
4131
4131
|
assert(this.red, "redSqr works only with red numbers");
|
|
4132
4132
|
this.red._verify1(this);
|
|
4133
4133
|
return this.red.sqr(this);
|
|
4134
4134
|
};
|
|
4135
|
-
|
|
4135
|
+
BN4.prototype.redISqr = function redISqr() {
|
|
4136
4136
|
assert(this.red, "redISqr works only with red numbers");
|
|
4137
4137
|
this.red._verify1(this);
|
|
4138
4138
|
return this.red.isqr(this);
|
|
4139
4139
|
};
|
|
4140
|
-
|
|
4140
|
+
BN4.prototype.redSqrt = function redSqrt() {
|
|
4141
4141
|
assert(this.red, "redSqrt works only with red numbers");
|
|
4142
4142
|
this.red._verify1(this);
|
|
4143
4143
|
return this.red.sqrt(this);
|
|
4144
4144
|
};
|
|
4145
|
-
|
|
4145
|
+
BN4.prototype.redInvm = function redInvm() {
|
|
4146
4146
|
assert(this.red, "redInvm works only with red numbers");
|
|
4147
4147
|
this.red._verify1(this);
|
|
4148
4148
|
return this.red.invm(this);
|
|
4149
4149
|
};
|
|
4150
|
-
|
|
4150
|
+
BN4.prototype.redNeg = function redNeg() {
|
|
4151
4151
|
assert(this.red, "redNeg works only with red numbers");
|
|
4152
4152
|
this.red._verify1(this);
|
|
4153
4153
|
return this.red.neg(this);
|
|
4154
4154
|
};
|
|
4155
|
-
|
|
4155
|
+
BN4.prototype.redPow = function redPow(num) {
|
|
4156
4156
|
assert(this.red && !num.red, "redPow(normalNum)");
|
|
4157
4157
|
this.red._verify1(this);
|
|
4158
4158
|
return this.red.pow(this, num);
|
|
@@ -4165,13 +4165,13 @@ var require_bn = __commonJS({
|
|
|
4165
4165
|
};
|
|
4166
4166
|
function MPrime(name, p) {
|
|
4167
4167
|
this.name = name;
|
|
4168
|
-
this.p = new
|
|
4168
|
+
this.p = new BN4(p, 16);
|
|
4169
4169
|
this.n = this.p.bitLength();
|
|
4170
|
-
this.k = new
|
|
4170
|
+
this.k = new BN4(1).iushln(this.n).isub(this.p);
|
|
4171
4171
|
this.tmp = this._tmp();
|
|
4172
4172
|
}
|
|
4173
4173
|
MPrime.prototype._tmp = function _tmp() {
|
|
4174
|
-
var tmp = new
|
|
4174
|
+
var tmp = new BN4(null);
|
|
4175
4175
|
tmp.words = new Array(Math.ceil(this.n / 13));
|
|
4176
4176
|
return tmp;
|
|
4177
4177
|
};
|
|
@@ -4297,7 +4297,7 @@ var require_bn = __commonJS({
|
|
|
4297
4297
|
}
|
|
4298
4298
|
return num;
|
|
4299
4299
|
};
|
|
4300
|
-
|
|
4300
|
+
BN4._prime = function prime(name) {
|
|
4301
4301
|
if (primes[name]) return primes[name];
|
|
4302
4302
|
var prime2;
|
|
4303
4303
|
if (name === "k256") {
|
|
@@ -4316,7 +4316,7 @@ var require_bn = __commonJS({
|
|
|
4316
4316
|
};
|
|
4317
4317
|
function Red(m) {
|
|
4318
4318
|
if (typeof m === "string") {
|
|
4319
|
-
var prime =
|
|
4319
|
+
var prime = BN4._prime(m);
|
|
4320
4320
|
this.m = prime.p;
|
|
4321
4321
|
this.prime = prime;
|
|
4322
4322
|
} else {
|
|
@@ -4402,7 +4402,7 @@ var require_bn = __commonJS({
|
|
|
4402
4402
|
var mod3 = this.m.andln(3);
|
|
4403
4403
|
assert(mod3 % 2 === 1);
|
|
4404
4404
|
if (mod3 === 3) {
|
|
4405
|
-
var pow = this.m.add(new
|
|
4405
|
+
var pow = this.m.add(new BN4(1)).iushrn(2);
|
|
4406
4406
|
return this.pow(a, pow);
|
|
4407
4407
|
}
|
|
4408
4408
|
var q = this.m.subn(1);
|
|
@@ -4412,11 +4412,11 @@ var require_bn = __commonJS({
|
|
|
4412
4412
|
q.iushrn(1);
|
|
4413
4413
|
}
|
|
4414
4414
|
assert(!q.isZero());
|
|
4415
|
-
var one = new
|
|
4415
|
+
var one = new BN4(1).toRed(this);
|
|
4416
4416
|
var nOne = one.redNeg();
|
|
4417
4417
|
var lpow = this.m.subn(1).iushrn(1);
|
|
4418
4418
|
var z = this.m.bitLength();
|
|
4419
|
-
z = new
|
|
4419
|
+
z = new BN4(2 * z * z).toRed(this);
|
|
4420
4420
|
while (this.pow(z, lpow).cmp(nOne) !== 0) {
|
|
4421
4421
|
z.redIAdd(nOne);
|
|
4422
4422
|
}
|
|
@@ -4430,7 +4430,7 @@ var require_bn = __commonJS({
|
|
|
4430
4430
|
tmp = tmp.redSqr();
|
|
4431
4431
|
}
|
|
4432
4432
|
assert(i < m);
|
|
4433
|
-
var b = this.pow(c, new
|
|
4433
|
+
var b = this.pow(c, new BN4(1).iushln(m - i - 1));
|
|
4434
4434
|
r = r.redMul(b);
|
|
4435
4435
|
c = b.redSqr();
|
|
4436
4436
|
t = t.redMul(c);
|
|
@@ -4448,11 +4448,11 @@ var require_bn = __commonJS({
|
|
|
4448
4448
|
}
|
|
4449
4449
|
};
|
|
4450
4450
|
Red.prototype.pow = function pow(a, num) {
|
|
4451
|
-
if (num.isZero()) return new
|
|
4451
|
+
if (num.isZero()) return new BN4(1).toRed(this);
|
|
4452
4452
|
if (num.cmpn(1) === 0) return a.clone();
|
|
4453
4453
|
var windowSize = 4;
|
|
4454
4454
|
var wnd = new Array(1 << windowSize);
|
|
4455
|
-
wnd[0] = new
|
|
4455
|
+
wnd[0] = new BN4(1).toRed(this);
|
|
4456
4456
|
wnd[1] = a;
|
|
4457
4457
|
for (var i = 2; i < wnd.length; i++) {
|
|
4458
4458
|
wnd[i] = this.mul(wnd[i - 1], a);
|
|
@@ -4496,7 +4496,7 @@ var require_bn = __commonJS({
|
|
|
4496
4496
|
res.red = null;
|
|
4497
4497
|
return res;
|
|
4498
4498
|
};
|
|
4499
|
-
|
|
4499
|
+
BN4.mont = function mont(num) {
|
|
4500
4500
|
return new Mont(num);
|
|
4501
4501
|
};
|
|
4502
4502
|
function Mont(m) {
|
|
@@ -4505,7 +4505,7 @@ var require_bn = __commonJS({
|
|
|
4505
4505
|
if (this.shift % 26 !== 0) {
|
|
4506
4506
|
this.shift += 26 - this.shift % 26;
|
|
4507
4507
|
}
|
|
4508
|
-
this.r = new
|
|
4508
|
+
this.r = new BN4(1).iushln(this.shift);
|
|
4509
4509
|
this.r2 = this.imod(this.r.sqr());
|
|
4510
4510
|
this.rinv = this.r._invmp(this.m);
|
|
4511
4511
|
this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
|
|
@@ -4539,7 +4539,7 @@ var require_bn = __commonJS({
|
|
|
4539
4539
|
return res._forceRed(this);
|
|
4540
4540
|
};
|
|
4541
4541
|
Mont.prototype.mul = function mul(a, b) {
|
|
4542
|
-
if (a.isZero() || b.isZero()) return new
|
|
4542
|
+
if (a.isZero() || b.isZero()) return new BN4(0)._forceRed(this);
|
|
4543
4543
|
var t = a.mul(b);
|
|
4544
4544
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
4545
4545
|
var u = t.isub(c).iushrn(this.shift);
|
|
@@ -4568,15 +4568,11 @@ var import_bn = __toESM(require_bn());
|
|
|
4568
4568
|
|
|
4569
4569
|
// src/constants.ts
|
|
4570
4570
|
init_cjs_shims();
|
|
4571
|
-
var
|
|
4572
|
-
var
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
Seeds2["StandardBond"] = "standard";
|
|
4577
|
-
Seeds2["CrowdFundingBond"] = "crowdfunding";
|
|
4578
|
-
return Seeds2;
|
|
4579
|
-
})(Seeds || {});
|
|
4571
|
+
var GLOBAL_STATE_SEED = "global_state";
|
|
4572
|
+
var BOND_STATE_SEED = "bond_state";
|
|
4573
|
+
var VALIDATOR_BOND_SEED = "validator_bond";
|
|
4574
|
+
var STANDARD_BOND_SEED = "standard";
|
|
4575
|
+
var CROWDFUNDING_BOND_SEED = "crowdfunding";
|
|
4580
4576
|
var ENV_PROGRAM_ID = {
|
|
4581
4577
|
// [BondClientEnv.DEV]: new PublicKey('...'),
|
|
4582
4578
|
};
|
|
@@ -4586,133 +4582,59 @@ init_cjs_shims();
|
|
|
4586
4582
|
|
|
4587
4583
|
// src/types/index.ts
|
|
4588
4584
|
init_cjs_shims();
|
|
4589
|
-
var
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
Disabled: { disabled: {} }
|
|
4600
|
-
};
|
|
4585
|
+
var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
|
|
4586
|
+
SessionStatus2[SessionStatus2["Live"] = 0] = "Live";
|
|
4587
|
+
SessionStatus2[SessionStatus2["Finished"] = 1] = "Finished";
|
|
4588
|
+
return SessionStatus2;
|
|
4589
|
+
})(SessionStatus || {});
|
|
4590
|
+
var BondType = /* @__PURE__ */ ((BondType2) => {
|
|
4591
|
+
BondType2["Standard"] = "standard";
|
|
4592
|
+
BondType2["Crowdfunding"] = "crowdfunding";
|
|
4593
|
+
return BondType2;
|
|
4594
|
+
})(BondType || {});
|
|
4601
4595
|
var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
|
|
4602
4596
|
BondTransactionType2["Deposit"] = "deposit";
|
|
4603
4597
|
BondTransactionType2["Withdrawal"] = "withdrawal";
|
|
4604
4598
|
BondTransactionType2["Compensation"] = "compensation";
|
|
4605
4599
|
return BondTransactionType2;
|
|
4606
4600
|
})(BondTransactionType || {});
|
|
4607
|
-
var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
|
|
4608
|
-
SessionStatus2[SessionStatus2["Live"] = 0] = "Live";
|
|
4609
|
-
SessionStatus2[SessionStatus2["Finished"] = 1] = "Finished";
|
|
4610
|
-
return SessionStatus2;
|
|
4611
|
-
})(SessionStatus || {});
|
|
4612
|
-
|
|
4613
|
-
// src/utils/enum.ts
|
|
4614
|
-
init_cjs_shims();
|
|
4615
|
-
function getVariant(v) {
|
|
4616
|
-
const key = Object.keys(v)[0];
|
|
4617
|
-
return [key, v[key]];
|
|
4618
|
-
}
|
|
4619
|
-
function variantArgs(payload) {
|
|
4620
|
-
if (Array.isArray(payload)) {
|
|
4621
|
-
return payload;
|
|
4622
|
-
}
|
|
4623
|
-
if (payload && typeof payload === "object") {
|
|
4624
|
-
const numericKeys = Object.keys(payload).filter((k) => String(+k) === k);
|
|
4625
|
-
if (numericKeys.length) {
|
|
4626
|
-
return numericKeys.sort((a, b) => +a - +b).map((k) => payload[k]);
|
|
4627
|
-
}
|
|
4628
|
-
return [payload];
|
|
4629
|
-
}
|
|
4630
|
-
return [payload];
|
|
4631
|
-
}
|
|
4632
|
-
function matchVariant(v, handlers) {
|
|
4633
|
-
const [k, data] = getVariant(v);
|
|
4634
|
-
const h = handlers[k];
|
|
4635
|
-
if (!h) {
|
|
4636
|
-
throw new Error(`Unhandled variant: ${k}`);
|
|
4637
|
-
}
|
|
4638
|
-
return h(...variantArgs(data));
|
|
4639
|
-
}
|
|
4640
|
-
function variantKey(v) {
|
|
4641
|
-
return Object.keys(v)[0];
|
|
4642
|
-
}
|
|
4643
|
-
function sameVariant(a, b) {
|
|
4644
|
-
return variantKey(a) === variantKey(b);
|
|
4645
|
-
}
|
|
4646
|
-
|
|
4647
|
-
// src/utils/wallet.ts
|
|
4648
|
-
init_cjs_shims();
|
|
4649
|
-
function isVersionedTransaction(tx) {
|
|
4650
|
-
return "version" in tx;
|
|
4651
|
-
}
|
|
4652
|
-
var NodeWallet = class {
|
|
4653
|
-
constructor(payer) {
|
|
4654
|
-
this.payer = payer;
|
|
4655
|
-
}
|
|
4656
|
-
async signTransaction(tx) {
|
|
4657
|
-
if (isVersionedTransaction(tx)) {
|
|
4658
|
-
tx.sign([this.payer]);
|
|
4659
|
-
} else {
|
|
4660
|
-
tx.partialSign(this.payer);
|
|
4661
|
-
}
|
|
4662
|
-
return tx;
|
|
4663
|
-
}
|
|
4664
|
-
async signAllTransactions(txs) {
|
|
4665
|
-
return txs.map((t) => {
|
|
4666
|
-
if (isVersionedTransaction(t)) {
|
|
4667
|
-
t.sign([this.payer]);
|
|
4668
|
-
} else {
|
|
4669
|
-
t.partialSign(this.payer);
|
|
4670
|
-
}
|
|
4671
|
-
return t;
|
|
4672
|
-
});
|
|
4673
|
-
}
|
|
4674
|
-
get publicKey() {
|
|
4675
|
-
return this.payer.publicKey;
|
|
4676
|
-
}
|
|
4677
|
-
};
|
|
4678
|
-
|
|
4679
|
-
// src/utils/web3.ts
|
|
4680
|
-
init_cjs_shims();
|
|
4681
|
-
var SLOTS_PER_EPOCH_MAINNET = 432e3;
|
|
4682
|
-
var SLOTS_PER_EPOCH_DEVNET = 4e5;
|
|
4683
|
-
function slotToEpoch(slot, cluster) {
|
|
4684
|
-
const slotsPerEpoch = cluster === "mainnet-beta" ? SLOTS_PER_EPOCH_MAINNET : SLOTS_PER_EPOCH_DEVNET;
|
|
4685
|
-
return Math.floor(slot / slotsPerEpoch);
|
|
4686
|
-
}
|
|
4687
4601
|
|
|
4688
4602
|
// src/history.ts
|
|
4689
4603
|
var { bs58 } = anchor.utils.bytes;
|
|
4690
4604
|
var HistoryManager = class {
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4605
|
+
constructor(client) {
|
|
4606
|
+
this.client = client;
|
|
4607
|
+
}
|
|
4608
|
+
// Cache of instruction discriminators
|
|
4694
4609
|
discCache = /* @__PURE__ */ new Map();
|
|
4695
|
-
|
|
4696
|
-
this.program
|
|
4697
|
-
this.connection = connection;
|
|
4698
|
-
this.programId = programId;
|
|
4610
|
+
get program() {
|
|
4611
|
+
return this.client.program;
|
|
4699
4612
|
}
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4613
|
+
get programId() {
|
|
4614
|
+
return this.client.programId;
|
|
4615
|
+
}
|
|
4616
|
+
get connection() {
|
|
4617
|
+
return this.client.provider.connection;
|
|
4618
|
+
}
|
|
4619
|
+
debug(...args) {
|
|
4620
|
+
this.client.debug(...args);
|
|
4621
|
+
}
|
|
4622
|
+
async getHistory(bondType, bondName, vote, opts) {
|
|
4623
|
+
const [validatorBondAccount] = this.client.pda.validatorBond(bondType, bondName, vote);
|
|
4624
|
+
this.debug(`Fetching history for validator bond account: ${validatorBondAccount.toBase58()}`);
|
|
4703
4625
|
const signatures = await this.fetchSignaturesForAddress(validatorBondAccount, {
|
|
4704
|
-
limit:
|
|
4705
|
-
before:
|
|
4706
|
-
until:
|
|
4626
|
+
limit: opts?.limit,
|
|
4627
|
+
before: opts?.before,
|
|
4628
|
+
until: opts?.until
|
|
4707
4629
|
});
|
|
4708
4630
|
if (!signatures.length) {
|
|
4709
4631
|
return [];
|
|
4710
4632
|
}
|
|
4711
|
-
const
|
|
4712
|
-
const parsed = await this.fetchParsedTransactions(
|
|
4633
|
+
const sigs = signatures.map((s) => s.signature);
|
|
4634
|
+
const parsed = await this.fetchParsedTransactions(sigs);
|
|
4713
4635
|
const txBySig = /* @__PURE__ */ new Map();
|
|
4714
|
-
for (let i = 0; i <
|
|
4715
|
-
const want =
|
|
4636
|
+
for (let i = 0; i < sigs.length; i++) {
|
|
4637
|
+
const want = sigs[i];
|
|
4716
4638
|
const tx = parsed[i] ?? null;
|
|
4717
4639
|
if (tx?.transaction?.signatures?.[0] && tx.transaction.signatures[0] !== want) {
|
|
4718
4640
|
const found = parsed.find((t) => t?.transaction?.signatures?.[0] === want) ?? null;
|
|
@@ -4747,7 +4669,7 @@ var HistoryManager = class {
|
|
|
4747
4669
|
history.push({
|
|
4748
4670
|
signature: sig,
|
|
4749
4671
|
slot,
|
|
4750
|
-
epoch: slotToEpoch(slot, cluster),
|
|
4672
|
+
epoch: slotToEpoch(slot, opts?.cluster),
|
|
4751
4673
|
type,
|
|
4752
4674
|
amount
|
|
4753
4675
|
});
|
|
@@ -4760,7 +4682,8 @@ var HistoryManager = class {
|
|
|
4760
4682
|
limit: options?.limit || 1e3,
|
|
4761
4683
|
before: options?.before,
|
|
4762
4684
|
until: options?.until
|
|
4763
|
-
});
|
|
4685
|
+
}, "confirmed");
|
|
4686
|
+
console.log(sigs);
|
|
4764
4687
|
return sigs.filter((s) => !s.err);
|
|
4765
4688
|
}
|
|
4766
4689
|
async fetchParsedTransactions(sigs, batchSize = 100) {
|
|
@@ -4768,6 +4691,7 @@ var HistoryManager = class {
|
|
|
4768
4691
|
for (let i = 0; i < sigs.length; i += batchSize) {
|
|
4769
4692
|
const batch = sigs.slice(i, i + batchSize);
|
|
4770
4693
|
const txs = await this.connection.getParsedTransactions(batch, {
|
|
4694
|
+
commitment: "confirmed",
|
|
4771
4695
|
maxSupportedTransactionVersion: 0
|
|
4772
4696
|
});
|
|
4773
4697
|
all.push(...txs);
|
|
@@ -4827,6 +4751,11 @@ var HistoryManager = class {
|
|
|
4827
4751
|
}
|
|
4828
4752
|
}
|
|
4829
4753
|
};
|
|
4754
|
+
function slotToEpoch(slot, cluster) {
|
|
4755
|
+
const isMainnet = !cluster || cluster === "mainnet-beta";
|
|
4756
|
+
const slotsPerEpoch = isMainnet ? 432e3 : 4e5;
|
|
4757
|
+
return Math.floor(slot / slotsPerEpoch);
|
|
4758
|
+
}
|
|
4830
4759
|
|
|
4831
4760
|
// src/idl/jbond.json
|
|
4832
4761
|
var jbond_default = {
|
|
@@ -6416,8 +6345,110 @@ var jbond_default = {
|
|
|
6416
6345
|
]
|
|
6417
6346
|
};
|
|
6418
6347
|
|
|
6348
|
+
// src/utils/index.ts
|
|
6349
|
+
init_cjs_shims();
|
|
6350
|
+
|
|
6351
|
+
// src/utils/enum.ts
|
|
6352
|
+
init_cjs_shims();
|
|
6353
|
+
function getVariant(v) {
|
|
6354
|
+
const key = Object.keys(v)[0];
|
|
6355
|
+
return [key, v[key]];
|
|
6356
|
+
}
|
|
6357
|
+
function variantArgs(payload) {
|
|
6358
|
+
if (Array.isArray(payload)) {
|
|
6359
|
+
return payload;
|
|
6360
|
+
}
|
|
6361
|
+
if (payload && typeof payload === "object") {
|
|
6362
|
+
const numericKeys = Object.keys(payload).filter((k) => String(+k) === k);
|
|
6363
|
+
if (numericKeys.length) {
|
|
6364
|
+
return numericKeys.sort((a, b) => +a - +b).map((k) => payload[k]);
|
|
6365
|
+
}
|
|
6366
|
+
return [payload];
|
|
6367
|
+
}
|
|
6368
|
+
return [payload];
|
|
6369
|
+
}
|
|
6370
|
+
function matchVariant(v, handlers) {
|
|
6371
|
+
const [k, data] = getVariant(v);
|
|
6372
|
+
const h = handlers[k];
|
|
6373
|
+
if (!h) {
|
|
6374
|
+
throw new Error(`Unhandled variant: ${k}`);
|
|
6375
|
+
}
|
|
6376
|
+
return h(...variantArgs(data));
|
|
6377
|
+
}
|
|
6378
|
+
function variantKey(v) {
|
|
6379
|
+
return Object.keys(v)[0];
|
|
6380
|
+
}
|
|
6381
|
+
function sameVariant(a, b) {
|
|
6382
|
+
return variantKey(a) === variantKey(b);
|
|
6383
|
+
}
|
|
6384
|
+
function toAnchor(key, payload) {
|
|
6385
|
+
return { [key]: {} };
|
|
6386
|
+
}
|
|
6387
|
+
function fromAnchor(variant) {
|
|
6388
|
+
return variantKey(variant);
|
|
6389
|
+
}
|
|
6390
|
+
function bondTypeToAnchor(type, payload) {
|
|
6391
|
+
return toAnchor(type);
|
|
6392
|
+
}
|
|
6393
|
+
function anchorToBondType(variant) {
|
|
6394
|
+
return fromAnchor(variant);
|
|
6395
|
+
}
|
|
6396
|
+
|
|
6397
|
+
// src/utils/wallet.ts
|
|
6398
|
+
init_cjs_shims();
|
|
6399
|
+
function isVersionedTransaction(tx) {
|
|
6400
|
+
return "version" in tx;
|
|
6401
|
+
}
|
|
6402
|
+
var NodeWallet = class {
|
|
6403
|
+
constructor(payer) {
|
|
6404
|
+
this.payer = payer;
|
|
6405
|
+
}
|
|
6406
|
+
async signTransaction(tx) {
|
|
6407
|
+
if (isVersionedTransaction(tx)) {
|
|
6408
|
+
tx.sign([this.payer]);
|
|
6409
|
+
} else {
|
|
6410
|
+
tx.partialSign(this.payer);
|
|
6411
|
+
}
|
|
6412
|
+
return tx;
|
|
6413
|
+
}
|
|
6414
|
+
async signAllTransactions(txs) {
|
|
6415
|
+
return txs.map((t) => {
|
|
6416
|
+
if (isVersionedTransaction(t)) {
|
|
6417
|
+
t.sign([this.payer]);
|
|
6418
|
+
} else {
|
|
6419
|
+
t.partialSign(this.payer);
|
|
6420
|
+
}
|
|
6421
|
+
return t;
|
|
6422
|
+
});
|
|
6423
|
+
}
|
|
6424
|
+
get publicKey() {
|
|
6425
|
+
return this.payer.publicKey;
|
|
6426
|
+
}
|
|
6427
|
+
};
|
|
6428
|
+
|
|
6429
|
+
// src/utils/web3.ts
|
|
6430
|
+
init_cjs_shims();
|
|
6431
|
+
var SOL_DECIMALS = Math.log10(web3_js.LAMPORTS_PER_SOL);
|
|
6432
|
+
function solToLamports(amount) {
|
|
6433
|
+
if (Number.isNaN(amount)) {
|
|
6434
|
+
return new anchor.BN(0);
|
|
6435
|
+
}
|
|
6436
|
+
return new anchor.BN(Number(amount).toFixed(SOL_DECIMALS).replace(".", ""));
|
|
6437
|
+
}
|
|
6438
|
+
|
|
6439
|
+
// src/utils/index.ts
|
|
6440
|
+
function getBondTypeSeed(type) {
|
|
6441
|
+
switch (type) {
|
|
6442
|
+
case "standard" /* Standard */:
|
|
6443
|
+
return STANDARD_BOND_SEED;
|
|
6444
|
+
case "crowdfunding" /* Crowdfunding */:
|
|
6445
|
+
return CROWDFUNDING_BOND_SEED;
|
|
6446
|
+
default:
|
|
6447
|
+
throw new Error(`Unknown bond type: ${type}`);
|
|
6448
|
+
}
|
|
6449
|
+
}
|
|
6450
|
+
|
|
6419
6451
|
// src/client.ts
|
|
6420
|
-
var { bs58: bs582 } = anchor.utils.bytes;
|
|
6421
6452
|
var BondClientEnv = /* @__PURE__ */ ((BondClientEnv2) => {
|
|
6422
6453
|
BondClientEnv2["DEV"] = "dev";
|
|
6423
6454
|
BondClientEnv2["STAGE"] = "stage";
|
|
@@ -6429,11 +6460,12 @@ var JBondClient = class _JBondClient {
|
|
|
6429
6460
|
this.provider = provider;
|
|
6430
6461
|
this.options = options ?? {};
|
|
6431
6462
|
this.program = new anchor.Program(jbond_default, this.provider);
|
|
6432
|
-
this.history = new HistoryManager(this.program, this.provider.connection, this.program.programId);
|
|
6433
6463
|
}
|
|
6434
6464
|
options;
|
|
6435
6465
|
program;
|
|
6436
|
-
history
|
|
6466
|
+
get history() {
|
|
6467
|
+
return new HistoryManager(this);
|
|
6468
|
+
}
|
|
6437
6469
|
/**
|
|
6438
6470
|
* Creates an instance of `JBondClient` using a provided connection and wallet.
|
|
6439
6471
|
*/
|
|
@@ -6469,167 +6501,151 @@ var JBondClient = class _JBondClient {
|
|
|
6469
6501
|
* Set the environment.
|
|
6470
6502
|
*/
|
|
6471
6503
|
env(env) {
|
|
6472
|
-
return this.
|
|
6504
|
+
return this.configure("programId", ENV_PROGRAM_ID[env]);
|
|
6473
6505
|
}
|
|
6474
6506
|
/**
|
|
6475
6507
|
* Configure a specific option.
|
|
6476
6508
|
*/
|
|
6477
|
-
|
|
6509
|
+
configure(key, val) {
|
|
6478
6510
|
this.options[key] = val;
|
|
6479
6511
|
return this;
|
|
6480
6512
|
}
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6513
|
+
/**
|
|
6514
|
+
* Debug logging
|
|
6515
|
+
* @param args
|
|
6516
|
+
*/
|
|
6517
|
+
debug(...args) {
|
|
6518
|
+
if (this.options.debug) {
|
|
6519
|
+
console.log(`%c[JBondClient]`, "color: #009999;", ...args);
|
|
6520
|
+
}
|
|
6484
6521
|
}
|
|
6485
6522
|
/**
|
|
6486
6523
|
* Program Derived Addresses (PDAs)
|
|
6487
6524
|
*/
|
|
6488
6525
|
pda = {
|
|
6489
|
-
globalState: () =>
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
);
|
|
6494
|
-
},
|
|
6526
|
+
globalState: () => web3_js.PublicKey.findProgramAddressSync(
|
|
6527
|
+
[Buffer.from(GLOBAL_STATE_SEED)],
|
|
6528
|
+
this.programId
|
|
6529
|
+
),
|
|
6495
6530
|
bondState: (bondType, bondName) => {
|
|
6496
|
-
const seed = this.getBondTypeSeed(bondType);
|
|
6497
6531
|
return web3_js.PublicKey.findProgramAddressSync(
|
|
6498
|
-
[Buffer.from(
|
|
6532
|
+
[Buffer.from(BOND_STATE_SEED), Buffer.from(getBondTypeSeed(bondType)), Buffer.from(bondName)],
|
|
6499
6533
|
this.programId
|
|
6500
6534
|
);
|
|
6501
6535
|
},
|
|
6502
|
-
// Derives a validator bond PDA based on the bond type and vote account
|
|
6503
6536
|
validatorBond: (bondType, bondName, vote) => {
|
|
6504
6537
|
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
6505
6538
|
return web3_js.PublicKey.findProgramAddressSync(
|
|
6506
|
-
[
|
|
6507
|
-
Buffer.from("validator_bond" /* ValidatorBond */),
|
|
6508
|
-
bondState.toBuffer(),
|
|
6509
|
-
new web3_js.PublicKey(vote).toBuffer()
|
|
6510
|
-
],
|
|
6539
|
+
[Buffer.from(VALIDATOR_BOND_SEED), bondState.toBuffer(), new web3_js.PublicKey(vote).toBuffer()],
|
|
6511
6540
|
this.programId
|
|
6512
6541
|
);
|
|
6513
6542
|
}
|
|
6514
6543
|
};
|
|
6544
|
+
/**
|
|
6545
|
+
* Initialize global state
|
|
6546
|
+
*/
|
|
6515
6547
|
async globalInitialize(props) {
|
|
6516
|
-
const ix = await this.
|
|
6548
|
+
const ix = await this.getGlobalInitializeIx(props);
|
|
6517
6549
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6518
6550
|
}
|
|
6519
6551
|
/**
|
|
6520
6552
|
* Initialize the program
|
|
6521
|
-
* Default authority is the provider's wallet
|
|
6522
6553
|
*/
|
|
6523
6554
|
async bondInitialize(props) {
|
|
6524
|
-
|
|
6525
|
-
const ix = await this.buildBondInitializeIx(props);
|
|
6555
|
+
const ix = await this.getBondInitializeIx(props);
|
|
6526
6556
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6527
6557
|
}
|
|
6528
6558
|
/**
|
|
6529
6559
|
* Register a new validator
|
|
6530
|
-
* Default creator is the provider's wallet
|
|
6531
6560
|
*/
|
|
6532
6561
|
async registerValidator(props) {
|
|
6533
|
-
const ix = await this.
|
|
6562
|
+
const ix = await this.getRegisterValidatorIx(props);
|
|
6534
6563
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6535
6564
|
}
|
|
6536
6565
|
/**
|
|
6537
6566
|
* Top up collateral
|
|
6538
|
-
* Default payer is the provider's wallet
|
|
6539
6567
|
*/
|
|
6540
6568
|
async topUpCollateral(props) {
|
|
6541
|
-
const ixs = await this.
|
|
6569
|
+
const ixs = await this.getTopUpIxs(props);
|
|
6542
6570
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(...ixs));
|
|
6543
6571
|
}
|
|
6544
6572
|
/**
|
|
6545
6573
|
* Withdraw collateral
|
|
6546
|
-
* Default withdrawal authority is the provider's wallet
|
|
6547
|
-
* Default destination is the provider's wallet
|
|
6548
|
-
* @return Transaction signature
|
|
6549
6574
|
*/
|
|
6550
6575
|
async withdrawCollateral(props) {
|
|
6551
|
-
const ix = await this.
|
|
6576
|
+
const ix = await this.getWithdrawIx(props);
|
|
6552
6577
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6553
6578
|
}
|
|
6554
6579
|
/**
|
|
6555
6580
|
* Claim compensation
|
|
6556
|
-
* Default authority is the provider's wallet
|
|
6557
|
-
* @return Transaction signature
|
|
6558
6581
|
*/
|
|
6559
6582
|
async claimCompensation(props) {
|
|
6560
|
-
const ix = await this.
|
|
6583
|
+
const ix = await this.getClaimIx(props);
|
|
6561
6584
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6562
6585
|
}
|
|
6563
6586
|
/**
|
|
6564
6587
|
* Update global configuration for the program
|
|
6565
|
-
* Default authority is the provider's wallet
|
|
6566
|
-
* Only the current authority can call this
|
|
6567
|
-
* @return Transaction signature
|
|
6568
6588
|
*/
|
|
6569
6589
|
async globalConfigure(props) {
|
|
6570
|
-
const ix = await this.
|
|
6590
|
+
const ix = await this.getGlobalConfigureIx(props);
|
|
6571
6591
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6572
6592
|
}
|
|
6573
6593
|
/**
|
|
6574
6594
|
* Update global configuration for the program
|
|
6575
|
-
* Default authority is the provider's wallet
|
|
6576
|
-
* Only the current authority can call this
|
|
6577
|
-
* @return Transaction signature
|
|
6578
6595
|
*/
|
|
6579
6596
|
async bondConfigure(props) {
|
|
6580
|
-
const ix = await this.
|
|
6597
|
+
const ix = await this.getBondConfigureIx(props);
|
|
6581
6598
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6582
6599
|
}
|
|
6583
6600
|
/**
|
|
6584
6601
|
* Set withdrawal authority for validator bond
|
|
6585
|
-
* Only the validator identity can call this
|
|
6586
|
-
* Default identity is the provider's wallet
|
|
6587
|
-
* @return Transaction signature
|
|
6588
6602
|
*/
|
|
6589
6603
|
async setWithdrawAuthority(props) {
|
|
6590
|
-
const ix = await this.
|
|
6604
|
+
const ix = await this.getSetWithdrawAuthorityIx(props);
|
|
6591
6605
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6592
6606
|
}
|
|
6607
|
+
/**
|
|
6608
|
+
* Start crowdfunding bond session
|
|
6609
|
+
*/
|
|
6593
6610
|
async bondStart(props) {
|
|
6594
|
-
const ix = await this.
|
|
6611
|
+
const ix = await this.getBondSessionStartIx(props);
|
|
6595
6612
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6596
6613
|
}
|
|
6614
|
+
/**
|
|
6615
|
+
* Finish crowdfunding bond session
|
|
6616
|
+
*/
|
|
6597
6617
|
async bondFinish(props) {
|
|
6598
|
-
const ix = await this.
|
|
6618
|
+
const ix = await this.getBondSessionFinishIx(props);
|
|
6599
6619
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6600
6620
|
}
|
|
6601
|
-
|
|
6621
|
+
/**
|
|
6622
|
+
* Build global state initialize instruction
|
|
6623
|
+
*/
|
|
6624
|
+
async getGlobalInitializeIx(props) {
|
|
6602
6625
|
const [globalState] = this.pda.globalState();
|
|
6603
6626
|
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
6604
|
-
return this.program.methods.globalInitialize().accountsPartial({
|
|
6605
|
-
globalState,
|
|
6606
|
-
authority
|
|
6607
|
-
}).instruction();
|
|
6627
|
+
return this.program.methods.globalInitialize().accountsPartial({ globalState, authority }).instruction();
|
|
6608
6628
|
}
|
|
6609
6629
|
/**
|
|
6610
6630
|
* Build configure instruction
|
|
6611
6631
|
*/
|
|
6612
|
-
async
|
|
6632
|
+
async getGlobalConfigureIx(props) {
|
|
6613
6633
|
const [globalState] = this.pda.globalState();
|
|
6614
6634
|
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
6615
6635
|
return this.program.methods.globalConfigure({
|
|
6616
6636
|
newAuthority: props.newAuthority ?? null
|
|
6617
|
-
}).accountsStrict({
|
|
6618
|
-
globalState,
|
|
6619
|
-
authority
|
|
6620
|
-
}).instruction();
|
|
6637
|
+
}).accountsStrict({ globalState, authority }).instruction();
|
|
6621
6638
|
}
|
|
6622
6639
|
/**
|
|
6623
|
-
* Build initialize instruction
|
|
6640
|
+
* Build bond initialize instruction
|
|
6624
6641
|
*/
|
|
6625
|
-
async
|
|
6642
|
+
async getBondInitializeIx(props) {
|
|
6626
6643
|
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6644
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
6627
6645
|
const accounts = {
|
|
6628
6646
|
bondState,
|
|
6629
|
-
authority
|
|
6647
|
+
authority,
|
|
6630
6648
|
reserve: props.reserve,
|
|
6631
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
6632
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
6633
6649
|
reserveTokenAccount: null,
|
|
6634
6650
|
mint: null
|
|
6635
6651
|
};
|
|
@@ -6643,42 +6659,45 @@ var JBondClient = class _JBondClient {
|
|
|
6643
6659
|
});
|
|
6644
6660
|
return this.program.methods.bondInitialize({
|
|
6645
6661
|
name: props.name,
|
|
6646
|
-
bondType: props.bondType,
|
|
6662
|
+
bondType: bondTypeToAnchor(props.bondType),
|
|
6647
6663
|
reserve: props.reserve,
|
|
6648
6664
|
collateralType: props.collateralType
|
|
6649
|
-
}).accountsPartial(
|
|
6650
|
-
accounts
|
|
6651
|
-
).instruction();
|
|
6665
|
+
}).accountsPartial(accounts).instruction();
|
|
6652
6666
|
}
|
|
6653
|
-
|
|
6667
|
+
/**
|
|
6668
|
+
* Build bond configure instruction
|
|
6669
|
+
*/
|
|
6670
|
+
async getBondConfigureIx(props) {
|
|
6654
6671
|
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6672
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
6655
6673
|
return this.program.methods.bondConfigure({
|
|
6656
|
-
status: props.
|
|
6674
|
+
status: props.status ?? null,
|
|
6657
6675
|
newReserve: props.newReserve ?? null,
|
|
6658
6676
|
newAuthority: props.newAuthority ?? null
|
|
6659
|
-
}).accountsStrict({
|
|
6660
|
-
bondState,
|
|
6661
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey
|
|
6662
|
-
}).instruction();
|
|
6677
|
+
}).accountsStrict({ bondState, authority }).instruction();
|
|
6663
6678
|
}
|
|
6664
|
-
|
|
6679
|
+
/**
|
|
6680
|
+
* Build register validator instruction
|
|
6681
|
+
*/
|
|
6682
|
+
async getRegisterValidatorIx(props) {
|
|
6665
6683
|
const { bondType, voteAccount, identity, name } = props;
|
|
6666
6684
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6667
6685
|
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6668
|
-
const creator = props.creator ?? this.
|
|
6686
|
+
const creator = props.creator ?? this.provider.wallet?.publicKey;
|
|
6669
6687
|
if (!creator) {
|
|
6670
6688
|
throw new Error("Missing creator");
|
|
6671
6689
|
}
|
|
6672
|
-
|
|
6690
|
+
let collateralType = props.collateralType;
|
|
6691
|
+
if (!collateralType) {
|
|
6692
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
6693
|
+
collateralType = bondState2.collateralType;
|
|
6694
|
+
}
|
|
6673
6695
|
const accounts = {
|
|
6674
6696
|
bondState,
|
|
6675
6697
|
validatorBond,
|
|
6676
6698
|
identity,
|
|
6677
6699
|
voteAccount,
|
|
6678
6700
|
creator,
|
|
6679
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
6680
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
6681
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
6682
6701
|
bondTokenAccount: null,
|
|
6683
6702
|
mint: null
|
|
6684
6703
|
};
|
|
@@ -6687,42 +6706,49 @@ var JBondClient = class _JBondClient {
|
|
|
6687
6706
|
},
|
|
6688
6707
|
token: (mint) => {
|
|
6689
6708
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6690
|
-
|
|
6709
|
+
accounts.mint = mint;
|
|
6691
6710
|
}
|
|
6692
6711
|
});
|
|
6693
|
-
return this.program.methods.bondRegister(bondType, name).accountsPartial(accounts).instruction();
|
|
6712
|
+
return this.program.methods.bondRegister(bondTypeToAnchor(bondType), name).accountsPartial(accounts).instruction();
|
|
6694
6713
|
}
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6714
|
+
/**
|
|
6715
|
+
* Build top up collateral instructions
|
|
6716
|
+
*/
|
|
6717
|
+
async getTopUpIxs(props) {
|
|
6718
|
+
const { bondType, voteAccount, amount, name } = props;
|
|
6719
|
+
const payer = props.payer ?? this.provider.wallet?.publicKey;
|
|
6698
6720
|
if (!payer) {
|
|
6699
6721
|
throw new Error("Missing payer");
|
|
6700
6722
|
}
|
|
6701
|
-
const instructions = [];
|
|
6702
6723
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6703
6724
|
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6725
|
+
let collateralType = props.collateralType;
|
|
6726
|
+
if (!collateralType) {
|
|
6727
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
6728
|
+
collateralType = bondState2.collateralType;
|
|
6729
|
+
}
|
|
6730
|
+
const instructions = [];
|
|
6731
|
+
try {
|
|
6732
|
+
await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
|
|
6733
|
+
} catch {
|
|
6734
|
+
instructions.push(
|
|
6735
|
+
await this.getRegisterValidatorIx({
|
|
6736
|
+
bondType: props.bondType,
|
|
6737
|
+
name: props.name,
|
|
6738
|
+
voteAccount: props.voteAccount,
|
|
6739
|
+
identity: props.identity,
|
|
6740
|
+
creator: props.payer,
|
|
6741
|
+
collateralType
|
|
6742
|
+
})
|
|
6743
|
+
);
|
|
6714
6744
|
}
|
|
6715
|
-
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6716
6745
|
const accounts = {
|
|
6717
6746
|
bondState,
|
|
6718
6747
|
validatorBond,
|
|
6719
6748
|
payer,
|
|
6720
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
6721
6749
|
payerTokenAccount: null,
|
|
6722
6750
|
bondTokenAccount: null,
|
|
6723
6751
|
stakeAccount: null,
|
|
6724
|
-
tokenProgram: null,
|
|
6725
|
-
associatedTokenProgram: null,
|
|
6726
6752
|
stakeProgram: null
|
|
6727
6753
|
};
|
|
6728
6754
|
matchVariant(collateralType, {
|
|
@@ -6731,35 +6757,38 @@ var JBondClient = class _JBondClient {
|
|
|
6731
6757
|
token: (mint) => {
|
|
6732
6758
|
accounts.payerTokenAccount = splToken.getAssociatedTokenAddressSync(mint, payer);
|
|
6733
6759
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6734
|
-
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6735
|
-
accounts.associatedTokenProgram = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
6736
6760
|
}
|
|
6737
6761
|
});
|
|
6738
6762
|
instructions.push(
|
|
6739
|
-
await this.program.methods.bondTopUp(
|
|
6763
|
+
await this.program.methods.bondTopUp(solToLamports(amount)).accountsPartial(accounts).instruction()
|
|
6740
6764
|
);
|
|
6741
6765
|
return instructions;
|
|
6742
6766
|
}
|
|
6743
|
-
|
|
6744
|
-
|
|
6767
|
+
/**
|
|
6768
|
+
* Build withdraw collateral instruction
|
|
6769
|
+
*/
|
|
6770
|
+
async getWithdrawIx(props) {
|
|
6771
|
+
const { bondType, voteAccount, amount, name } = props;
|
|
6745
6772
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6746
6773
|
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6747
|
-
const payer = this.
|
|
6774
|
+
const payer = this.provider.wallet?.publicKey;
|
|
6748
6775
|
const destination = props.destination ?? payer;
|
|
6749
6776
|
if (!payer || !destination) {
|
|
6750
6777
|
throw new Error("Missing payer/destination");
|
|
6751
6778
|
}
|
|
6752
|
-
|
|
6779
|
+
let collateralType = props.collateralType;
|
|
6780
|
+
if (!collateralType) {
|
|
6781
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
6782
|
+
collateralType = bondState2.collateralType;
|
|
6783
|
+
}
|
|
6753
6784
|
const accounts = {
|
|
6754
6785
|
bondState,
|
|
6755
6786
|
validatorBond,
|
|
6756
|
-
withdrawalAuthority: props.withdrawalAuthority ?? payer,
|
|
6757
6787
|
destination,
|
|
6788
|
+
withdrawalAuthority: props.withdrawalAuthority ?? payer,
|
|
6758
6789
|
destinationTokenAccount: null,
|
|
6759
6790
|
bondTokenAccount: null,
|
|
6760
6791
|
stakeAccount: null,
|
|
6761
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
6762
|
-
tokenProgram: null,
|
|
6763
6792
|
stakeProgram: null
|
|
6764
6793
|
};
|
|
6765
6794
|
matchVariant(collateralType, {
|
|
@@ -6768,31 +6797,34 @@ var JBondClient = class _JBondClient {
|
|
|
6768
6797
|
token: (mint) => {
|
|
6769
6798
|
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, destination, true);
|
|
6770
6799
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6771
|
-
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6772
6800
|
}
|
|
6773
6801
|
});
|
|
6774
|
-
return this.program.methods.bondWithdraw(
|
|
6802
|
+
return this.program.methods.bondWithdraw(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
6775
6803
|
}
|
|
6776
|
-
|
|
6777
|
-
|
|
6804
|
+
/**
|
|
6805
|
+
* Build claim instruction
|
|
6806
|
+
*/
|
|
6807
|
+
async getClaimIx(props) {
|
|
6808
|
+
const { bondType, name, amount } = props;
|
|
6778
6809
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6779
6810
|
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
6780
|
-
const
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6811
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
6812
|
+
let reserve = props.reserve;
|
|
6813
|
+
let collateralType = props.collateralType;
|
|
6814
|
+
if (!collateralType || !reserve) {
|
|
6815
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
6816
|
+
collateralType = collateralType ?? bondState2.collateralType;
|
|
6817
|
+
reserve = reserve ?? bondState2.reserve;
|
|
6784
6818
|
}
|
|
6785
|
-
const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
|
|
6786
6819
|
const accounts = {
|
|
6787
6820
|
bondState,
|
|
6788
6821
|
validatorBond,
|
|
6789
6822
|
reserve,
|
|
6790
|
-
reserveTokenAccount: null,
|
|
6791
6823
|
authority,
|
|
6824
|
+
destinationTokenAccount: null,
|
|
6792
6825
|
bondTokenAccount: null,
|
|
6826
|
+
reserveTokenAccount: null,
|
|
6793
6827
|
stakeAccount: null,
|
|
6794
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
6795
|
-
tokenProgram: null,
|
|
6796
6828
|
stakeProgram: null
|
|
6797
6829
|
};
|
|
6798
6830
|
matchVariant(collateralType, {
|
|
@@ -6802,161 +6834,90 @@ var JBondClient = class _JBondClient {
|
|
|
6802
6834
|
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6803
6835
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6804
6836
|
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6805
|
-
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6806
6837
|
}
|
|
6807
6838
|
});
|
|
6808
|
-
return this.program.methods.bondClaim(
|
|
6809
|
-
accounts
|
|
6810
|
-
).instruction();
|
|
6839
|
+
return this.program.methods.bondClaim(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
6811
6840
|
}
|
|
6812
|
-
|
|
6841
|
+
/**
|
|
6842
|
+
* Build set withdraw authority instruction
|
|
6843
|
+
*/
|
|
6844
|
+
async getSetWithdrawAuthorityIx(props) {
|
|
6813
6845
|
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
6846
|
+
const identity = props.identity ?? this.provider.wallet?.publicKey;
|
|
6814
6847
|
return this.program.methods.bondSetWithdrawAuthority().accountsPartial({
|
|
6815
6848
|
validatorBond,
|
|
6816
|
-
identity
|
|
6849
|
+
identity,
|
|
6817
6850
|
newWithdrawAuthority: props.newWithdrawAuthority ?? null
|
|
6818
6851
|
}).instruction();
|
|
6819
6852
|
}
|
|
6820
|
-
async buildBondFinishIx(props) {
|
|
6821
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6822
|
-
return this.program.methods.sessionFinish().accountsPartial({
|
|
6823
|
-
bondState,
|
|
6824
|
-
authority: this.program.provider.wallet?.publicKey
|
|
6825
|
-
}).instruction();
|
|
6826
|
-
}
|
|
6827
|
-
async migrateBond(props) {
|
|
6828
|
-
const ix = await this.buildBondMigrateIx(props);
|
|
6829
|
-
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6830
|
-
}
|
|
6831
|
-
async buildBondMigrateIx(props) {
|
|
6832
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6833
|
-
const [legacyValidatorBond] = web3_js.PublicKey.findProgramAddressSync(
|
|
6834
|
-
[
|
|
6835
|
-
Buffer.from("validator_bond"),
|
|
6836
|
-
new web3_js.PublicKey(props.voteAccount).toBuffer()
|
|
6837
|
-
],
|
|
6838
|
-
this.programId
|
|
6839
|
-
);
|
|
6840
|
-
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
6841
|
-
return this.program.methods.migrateBond().accountsPartial({
|
|
6842
|
-
bondState,
|
|
6843
|
-
legacyValidatorBond,
|
|
6844
|
-
legacyVoteAccount: new web3_js.PublicKey(props.voteAccount),
|
|
6845
|
-
validatorBond,
|
|
6846
|
-
creator: this.program.provider.wallet?.publicKey
|
|
6847
|
-
}).instruction();
|
|
6848
|
-
}
|
|
6849
|
-
async buildBondStartIx(props) {
|
|
6850
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6851
|
-
return this.program.methods.sessionStart(new import_bn.BN(props.duration_secs)).accountsPartial({
|
|
6852
|
-
bondState,
|
|
6853
|
-
authority: this.program.provider.wallet?.publicKey
|
|
6854
|
-
}).instruction();
|
|
6855
|
-
}
|
|
6856
6853
|
/**
|
|
6857
|
-
*
|
|
6854
|
+
* Build finish crowdfunding session instruction
|
|
6858
6855
|
*/
|
|
6859
|
-
async
|
|
6860
|
-
const [
|
|
6861
|
-
|
|
6856
|
+
async getBondSessionFinishIx(props) {
|
|
6857
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6858
|
+
const authority = this.provider.wallet?.publicKey;
|
|
6859
|
+
return this.program.methods.sessionFinish().accountsPartial({ bondState, authority }).instruction();
|
|
6862
6860
|
}
|
|
6863
6861
|
/**
|
|
6864
|
-
*
|
|
6865
|
-
* @param bondType - Type of the bond
|
|
6866
|
-
* @param bondName - Name of the bond
|
|
6867
|
-
* @param withStats
|
|
6862
|
+
* Build start crowdfunding session instruction
|
|
6868
6863
|
*/
|
|
6869
|
-
async
|
|
6870
|
-
const bondState =
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
stateStats: withStats ? await this.getBondStateStats(bondState) : null
|
|
6874
|
-
};
|
|
6864
|
+
async getBondSessionStartIx(props) {
|
|
6865
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6866
|
+
const authority = this.provider.wallet?.publicKey;
|
|
6867
|
+
return this.program.methods.sessionStart(new import_bn.BN(props.duration)).accountsPartial({ bondState, authority }).instruction();
|
|
6875
6868
|
}
|
|
6876
6869
|
/**
|
|
6877
6870
|
* Get all bond states with total collected collateral
|
|
6878
6871
|
*/
|
|
6879
6872
|
async getAllBondStates(bondType, sessionStatus) {
|
|
6880
|
-
const
|
|
6881
|
-
const
|
|
6882
|
-
for (const { publicKey, account
|
|
6883
|
-
if (!sameVariant(
|
|
6873
|
+
const result = [];
|
|
6874
|
+
const accounts = await this.program.account.bondState.all();
|
|
6875
|
+
for (const { publicKey, account } of accounts) {
|
|
6876
|
+
if (!sameVariant(account.bondType, bondTypeToAnchor(bondType))) {
|
|
6884
6877
|
continue;
|
|
6885
6878
|
}
|
|
6886
|
-
if (sessionStatus !== void 0 && this.getBondStateSessionStatus(
|
|
6879
|
+
if (sessionStatus !== void 0 && this.getBondStateSessionStatus(account) !== sessionStatus) {
|
|
6887
6880
|
continue;
|
|
6888
6881
|
}
|
|
6889
|
-
const
|
|
6890
|
-
|
|
6891
|
-
{
|
|
6892
|
-
publicKey,
|
|
6893
|
-
bondState: state,
|
|
6894
|
-
stateStats: bondStateStats
|
|
6895
|
-
}
|
|
6896
|
-
);
|
|
6882
|
+
const stateStats = await this.getBondStateStats(account);
|
|
6883
|
+
result.push({ publicKey, bondState: account, stateStats });
|
|
6897
6884
|
}
|
|
6898
|
-
return
|
|
6885
|
+
return result;
|
|
6899
6886
|
}
|
|
6900
6887
|
/**
|
|
6901
|
-
*
|
|
6888
|
+
* Fetch global state or throw if not found
|
|
6902
6889
|
*/
|
|
6903
|
-
|
|
6904
|
-
const
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
return 1 /* Finished */;
|
|
6909
|
-
}
|
|
6890
|
+
async getGlobalState() {
|
|
6891
|
+
const [publicKey] = this.pda.globalState();
|
|
6892
|
+
this.debug(`Fetching global state ${publicKey}...`);
|
|
6893
|
+
const data = await this.program.account.globalState.fetch(publicKey);
|
|
6894
|
+
return { publicKey, ...data };
|
|
6910
6895
|
}
|
|
6911
6896
|
/**
|
|
6912
|
-
*
|
|
6897
|
+
* Fetch bond state with stats
|
|
6913
6898
|
*/
|
|
6914
|
-
async
|
|
6915
|
-
const
|
|
6916
|
-
|
|
6917
|
-
const
|
|
6918
|
-
|
|
6919
|
-
memcmp: {
|
|
6920
|
-
offset: 8,
|
|
6921
|
-
bytes: bondStatePda.toBase58()
|
|
6922
|
-
}
|
|
6923
|
-
}
|
|
6924
|
-
]);
|
|
6925
|
-
for (const { account: vb } of validatorBondAccounts) {
|
|
6926
|
-
validatorBonds.push(vb);
|
|
6927
|
-
}
|
|
6928
|
-
return validatorBonds;
|
|
6899
|
+
async getBondState(bondType, bondName) {
|
|
6900
|
+
const [publicKey] = this.pda.bondState(bondType, bondName);
|
|
6901
|
+
this.debug(`Fetching bond state ${publicKey}...`);
|
|
6902
|
+
const data = await this.program.account.bondState.fetch(publicKey);
|
|
6903
|
+
return { publicKey, ...data };
|
|
6929
6904
|
}
|
|
6930
6905
|
/**
|
|
6931
6906
|
* Fetch validator bond data or null if not found
|
|
6932
6907
|
*/
|
|
6933
6908
|
async getValidatorBond(bondType, bondName, vote) {
|
|
6934
|
-
const [
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
} catch {
|
|
6938
|
-
return null;
|
|
6939
|
-
}
|
|
6940
|
-
}
|
|
6941
|
-
/**
|
|
6942
|
-
* Get bond collateral type
|
|
6943
|
-
*/
|
|
6944
|
-
async getBondCollateralType(bondType, bondName) {
|
|
6945
|
-
const bondState = await this.getBondState(bondType, bondName);
|
|
6946
|
-
return bondState.bondState.collateralType;
|
|
6909
|
+
const [publicKey] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
6910
|
+
const data = await this.program.account.validatorBond.fetch(publicKey);
|
|
6911
|
+
return { publicKey, ...data };
|
|
6947
6912
|
}
|
|
6948
6913
|
/**
|
|
6949
6914
|
* Get validator bond account balance (in SOL)
|
|
6950
|
-
* @param bondType - Type of the bond
|
|
6951
|
-
* @param bondName - Name of the bond
|
|
6952
|
-
* @param vote - Vote account public key
|
|
6953
|
-
* @return Balance in lamports
|
|
6954
6915
|
*/
|
|
6955
6916
|
async getValidatorBondBalance(bondType, bondName, vote) {
|
|
6956
6917
|
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
6957
|
-
const
|
|
6958
|
-
const
|
|
6959
|
-
return await matchVariant(
|
|
6918
|
+
const bondState = await this.getBondState(bondType, bondName);
|
|
6919
|
+
const collateralType = bondState.collateralType;
|
|
6920
|
+
return await matchVariant(collateralType, {
|
|
6960
6921
|
native: async () => {
|
|
6961
6922
|
const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
|
|
6962
6923
|
if (!accountInfo) {
|
|
@@ -6970,7 +6931,7 @@ var JBondClient = class _JBondClient {
|
|
|
6970
6931
|
const tokenAccount = splToken.getAssociatedTokenAddressSync(mint, address, true);
|
|
6971
6932
|
try {
|
|
6972
6933
|
const balance = await this.connection.getTokenAccountBalance(tokenAccount);
|
|
6973
|
-
return
|
|
6934
|
+
return solToLamports(balance.value.amount).toNumber();
|
|
6974
6935
|
} catch {
|
|
6975
6936
|
return 0;
|
|
6976
6937
|
}
|
|
@@ -6981,8 +6942,8 @@ var JBondClient = class _JBondClient {
|
|
|
6981
6942
|
* Get total collected collateral for a bond state
|
|
6982
6943
|
*/
|
|
6983
6944
|
async getBondStateTotalCollected(bondType, bondName, votes) {
|
|
6984
|
-
const
|
|
6985
|
-
const
|
|
6945
|
+
const bondState = await this.getBondState(bondType, bondName);
|
|
6946
|
+
const collateralType = bondState.collateralType;
|
|
6986
6947
|
const chunk = (arr, n = 100) => {
|
|
6987
6948
|
const res = [];
|
|
6988
6949
|
for (let i = 0; i < arr.length; i += n) {
|
|
@@ -6990,7 +6951,7 @@ var JBondClient = class _JBondClient {
|
|
|
6990
6951
|
}
|
|
6991
6952
|
return res;
|
|
6992
6953
|
};
|
|
6993
|
-
return await matchVariant(
|
|
6954
|
+
return await matchVariant(collateralType, {
|
|
6994
6955
|
native: async () => {
|
|
6995
6956
|
const addresses = votes.map((vote) => {
|
|
6996
6957
|
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
@@ -7040,189 +7001,16 @@ var JBondClient = class _JBondClient {
|
|
|
7040
7001
|
}
|
|
7041
7002
|
});
|
|
7042
7003
|
}
|
|
7043
|
-
/**
|
|
7044
|
-
* Get transaction history for a specific validator bond account
|
|
7045
|
-
*/
|
|
7046
|
-
async getHistory(bondType, bondName, vote, options) {
|
|
7047
|
-
const [legacyValidatorBondAccount] = web3_js.PublicKey.findProgramAddressSync(
|
|
7048
|
-
[
|
|
7049
|
-
Buffer.from("validator_bond" /* ValidatorBond */),
|
|
7050
|
-
new web3_js.PublicKey(vote).toBuffer()
|
|
7051
|
-
],
|
|
7052
|
-
this.programId
|
|
7053
|
-
);
|
|
7054
|
-
const validatorBond = this.pda.validatorBond(bondType, bondName, vote);
|
|
7055
|
-
const legacySignatures = (await this.connection.getSignaturesForAddress(
|
|
7056
|
-
legacyValidatorBondAccount,
|
|
7057
|
-
{
|
|
7058
|
-
limit: options?.limit || 1e3,
|
|
7059
|
-
before: options?.before,
|
|
7060
|
-
until: options?.until
|
|
7061
|
-
},
|
|
7062
|
-
"confirmed"
|
|
7063
|
-
)).filter((sig) => !sig.err);
|
|
7064
|
-
const newSignatures = (await this.connection.getSignaturesForAddress(
|
|
7065
|
-
validatorBond[0],
|
|
7066
|
-
{
|
|
7067
|
-
limit: options?.limit || 1e3,
|
|
7068
|
-
before: options?.before,
|
|
7069
|
-
until: options?.until
|
|
7070
|
-
},
|
|
7071
|
-
"confirmed"
|
|
7072
|
-
)).filter((sig) => !sig.err);
|
|
7073
|
-
const signatureStrings = legacySignatures.map((sig) => sig.signature);
|
|
7074
|
-
signatureStrings.push(...newSignatures.map((sig) => sig.signature));
|
|
7075
|
-
const signatures = [...legacySignatures, ...newSignatures];
|
|
7076
|
-
const BATCH_SIZE = 100;
|
|
7077
|
-
const allTransactions = [];
|
|
7078
|
-
for (let i = 0; i < signatureStrings.length; i += BATCH_SIZE) {
|
|
7079
|
-
const batch = signatureStrings.slice(i, i + BATCH_SIZE);
|
|
7080
|
-
const transactions = await this.connection.getParsedTransactions(
|
|
7081
|
-
batch,
|
|
7082
|
-
{
|
|
7083
|
-
maxSupportedTransactionVersion: 0,
|
|
7084
|
-
commitment: "confirmed"
|
|
7085
|
-
}
|
|
7086
|
-
);
|
|
7087
|
-
allTransactions.push(...transactions);
|
|
7088
|
-
}
|
|
7089
|
-
const cluster = options?.cluster || "mainnet-beta";
|
|
7090
|
-
const history = [];
|
|
7091
|
-
for (const [idx, tx] of allTransactions.entries()) {
|
|
7092
|
-
const sigInfo = signatures[idx];
|
|
7093
|
-
if (!tx || !tx.meta || tx.meta.err !== null) {
|
|
7094
|
-
continue;
|
|
7095
|
-
}
|
|
7096
|
-
try {
|
|
7097
|
-
const slot = tx.slot || 0;
|
|
7098
|
-
const instructions = tx.transaction.message.instructions;
|
|
7099
|
-
for (const instruction of instructions) {
|
|
7100
|
-
if ("programId" in instruction && instruction.programId.equals(this.options.programId ?? this.program.programId)) {
|
|
7101
|
-
const ixData = instruction;
|
|
7102
|
-
if ("parsed" in ixData && ixData.parsed) {
|
|
7103
|
-
continue;
|
|
7104
|
-
}
|
|
7105
|
-
const data = ixData.data;
|
|
7106
|
-
if (!data) {
|
|
7107
|
-
continue;
|
|
7108
|
-
}
|
|
7109
|
-
let type = null;
|
|
7110
|
-
let amount = 0;
|
|
7111
|
-
try {
|
|
7112
|
-
const dataBuffer = bs582.decode(data);
|
|
7113
|
-
if (dataBuffer.length >= 8) {
|
|
7114
|
-
const discriminator = dataBuffer.subarray(0, 8);
|
|
7115
|
-
const legacyRegisterDiscriminator = this.getInstructionDiscriminator("register");
|
|
7116
|
-
const legacyTopUpDiscriminator = this.getInstructionDiscriminator("topUp");
|
|
7117
|
-
const legacyClaimDiscriminator = this.getInstructionDiscriminator("claim");
|
|
7118
|
-
const legacyWithdrawDiscriminator = this.getInstructionDiscriminator("withdraw");
|
|
7119
|
-
const bondRegisterDiscriminator = this.getInstructionDiscriminator("bondRegister");
|
|
7120
|
-
const bondTopUpDiscriminator = this.getInstructionDiscriminator("bondTopUp");
|
|
7121
|
-
const bondClaimDiscriminator = this.getInstructionDiscriminator("bondClaim");
|
|
7122
|
-
const bondWithdrawDiscriminator = this.getInstructionDiscriminator("bondWithdraw");
|
|
7123
|
-
console.log("Discriminator:", Buffer.from(discriminator).toString("hex"));
|
|
7124
|
-
if (Buffer.from(discriminator).equals(Buffer.from(legacyRegisterDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondRegisterDiscriminator))) {
|
|
7125
|
-
type = "deposit" /* Deposit */;
|
|
7126
|
-
if (dataBuffer.length >= 16 && Buffer.from(discriminator).equals(Buffer.from(legacyRegisterDiscriminator))) {
|
|
7127
|
-
const amountBytes = dataBuffer.subarray(8, 16);
|
|
7128
|
-
const amountBN = new import_bn.BN(amountBytes, "le");
|
|
7129
|
-
amount = amountBN.toNumber() / web3_js.LAMPORTS_PER_SOL;
|
|
7130
|
-
}
|
|
7131
|
-
} else if (dataBuffer.length >= 16) {
|
|
7132
|
-
const amountBytes = dataBuffer.subarray(8, 16);
|
|
7133
|
-
const amountBN = new import_bn.BN(amountBytes, "le");
|
|
7134
|
-
amount = amountBN.toNumber() / web3_js.LAMPORTS_PER_SOL;
|
|
7135
|
-
if (Buffer.from(discriminator).equals(Buffer.from(legacyTopUpDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondTopUpDiscriminator))) {
|
|
7136
|
-
type = "deposit" /* Deposit */;
|
|
7137
|
-
} else if (Buffer.from(discriminator).equals(Buffer.from(legacyClaimDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondClaimDiscriminator))) {
|
|
7138
|
-
type = "compensation" /* Compensation */;
|
|
7139
|
-
} else if (Buffer.from(discriminator).equals(Buffer.from(legacyWithdrawDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondWithdrawDiscriminator))) {
|
|
7140
|
-
type = "withdrawal" /* Withdrawal */;
|
|
7141
|
-
}
|
|
7142
|
-
}
|
|
7143
|
-
}
|
|
7144
|
-
} catch (e) {
|
|
7145
|
-
console.warn("Failed to decode instruction data:", e);
|
|
7146
|
-
}
|
|
7147
|
-
if (type && (amount > 0 || type === "deposit" /* Deposit */)) {
|
|
7148
|
-
history.push({
|
|
7149
|
-
signature: sigInfo.signature,
|
|
7150
|
-
slot,
|
|
7151
|
-
epoch: slotToEpoch(slot, cluster),
|
|
7152
|
-
type,
|
|
7153
|
-
amount
|
|
7154
|
-
});
|
|
7155
|
-
}
|
|
7156
|
-
}
|
|
7157
|
-
}
|
|
7158
|
-
} catch (error) {
|
|
7159
|
-
console.error(`Error processing transaction ${sigInfo.signature}:`, error);
|
|
7160
|
-
}
|
|
7161
|
-
}
|
|
7162
|
-
return history.toSorted((a, b) => b.slot - a.slot);
|
|
7163
|
-
}
|
|
7164
|
-
/**
|
|
7165
|
-
* Get full transaction history by paginating through results
|
|
7166
|
-
* @param bondType
|
|
7167
|
-
* @param bondName
|
|
7168
|
-
* @param voteAccount
|
|
7169
|
-
* @param pageSize
|
|
7170
|
-
*/
|
|
7171
|
-
async getFullHistory(bondType, bondName, voteAccount, pageSize = 100) {
|
|
7172
|
-
const allHistory = [];
|
|
7173
|
-
let before;
|
|
7174
|
-
while (true) {
|
|
7175
|
-
const batch = await this.getHistory(bondType, bondName, voteAccount, {
|
|
7176
|
-
limit: pageSize,
|
|
7177
|
-
before
|
|
7178
|
-
});
|
|
7179
|
-
if (batch.length === 0) {
|
|
7180
|
-
break;
|
|
7181
|
-
}
|
|
7182
|
-
allHistory.push(...batch);
|
|
7183
|
-
before = batch.at(-1)?.signature;
|
|
7184
|
-
if (batch.length < pageSize) {
|
|
7185
|
-
break;
|
|
7186
|
-
}
|
|
7187
|
-
}
|
|
7188
|
-
return allHistory;
|
|
7189
|
-
}
|
|
7190
|
-
/**
|
|
7191
|
-
* Get instruction discriminator from IDL
|
|
7192
|
-
* @param instructionName
|
|
7193
|
-
* @private
|
|
7194
|
-
*/
|
|
7195
|
-
getInstructionDiscriminator(instructionName) {
|
|
7196
|
-
const legacyDiscriminators = {
|
|
7197
|
-
register: [211, 124, 67, 15, 211, 194, 178, 240],
|
|
7198
|
-
topUp: [181, 157, 89, 67, 143, 182, 52, 72],
|
|
7199
|
-
claim: [62, 198, 214, 193, 213, 159, 108, 210],
|
|
7200
|
-
withdraw: [183, 18, 70, 156, 148, 109, 161, 34]
|
|
7201
|
-
};
|
|
7202
|
-
if (legacyDiscriminators[instructionName]) {
|
|
7203
|
-
return new Uint8Array(legacyDiscriminators[instructionName]);
|
|
7204
|
-
}
|
|
7205
|
-
if (instructionName.startsWith("bond")) {
|
|
7206
|
-
const instruction = this.program.idl.instructions.find((ix) => ix.name === instructionName);
|
|
7207
|
-
if (!instruction) {
|
|
7208
|
-
throw new Error(`Instruction ${instructionName} not found in IDL`);
|
|
7209
|
-
}
|
|
7210
|
-
if (!instruction.discriminator || !Array.isArray(instruction.discriminator)) {
|
|
7211
|
-
throw new Error(`Discriminator not found for instruction ${instructionName}`);
|
|
7212
|
-
}
|
|
7213
|
-
return new Uint8Array(instruction.discriminator);
|
|
7214
|
-
}
|
|
7215
|
-
throw new Error(`Unknown instruction: ${instructionName}`);
|
|
7216
|
-
}
|
|
7217
7004
|
/**
|
|
7218
7005
|
* Get bond state stats
|
|
7219
7006
|
* @param state
|
|
7220
7007
|
* @private
|
|
7221
7008
|
*/
|
|
7222
7009
|
async getBondStateStats(state) {
|
|
7223
|
-
const
|
|
7010
|
+
const bondType = anchorToBondType(state.bondType);
|
|
7011
|
+
const validatorBonds = await this.getBondValidatorStates(bondType, state.name);
|
|
7224
7012
|
const totalCollected = await this.getBondStateTotalCollected(
|
|
7225
|
-
|
|
7013
|
+
bondType,
|
|
7226
7014
|
state.name,
|
|
7227
7015
|
validatorBonds.map((vb) => vb.voteAccount)
|
|
7228
7016
|
);
|
|
@@ -7231,8 +7019,36 @@ var JBondClient = class _JBondClient {
|
|
|
7231
7019
|
status: this.getBondStateSessionStatus(state)
|
|
7232
7020
|
};
|
|
7233
7021
|
}
|
|
7234
|
-
|
|
7235
|
-
|
|
7022
|
+
/**
|
|
7023
|
+
* Get all validator bonds for a given bond state
|
|
7024
|
+
*/
|
|
7025
|
+
async getBondValidatorStates(bondType, bondName) {
|
|
7026
|
+
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
7027
|
+
const accounts = await this.program.account.validatorBond.all([
|
|
7028
|
+
{
|
|
7029
|
+
memcmp: {
|
|
7030
|
+
offset: 8,
|
|
7031
|
+
// discriminator
|
|
7032
|
+
bytes: bondState.toBase58()
|
|
7033
|
+
}
|
|
7034
|
+
}
|
|
7035
|
+
]);
|
|
7036
|
+
const result = [];
|
|
7037
|
+
for (const { publicKey, account } of accounts) {
|
|
7038
|
+
result.push({ publicKey, ...account });
|
|
7039
|
+
}
|
|
7040
|
+
return result;
|
|
7041
|
+
}
|
|
7042
|
+
/**
|
|
7043
|
+
* Get session status for bond state
|
|
7044
|
+
*/
|
|
7045
|
+
getBondStateSessionStatus(bondState) {
|
|
7046
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
7047
|
+
if (bondState.sessionFinishTs.toNumber() > now) {
|
|
7048
|
+
return 0 /* Live */;
|
|
7049
|
+
} else {
|
|
7050
|
+
return 1 /* Finished */;
|
|
7051
|
+
}
|
|
7236
7052
|
}
|
|
7237
7053
|
};
|
|
7238
7054
|
/*! Bundled license information:
|
|
@@ -7249,16 +7065,17 @@ buffer/index.js:
|
|
|
7249
7065
|
*)
|
|
7250
7066
|
*/
|
|
7251
7067
|
|
|
7068
|
+
exports.BOND_STATE_SEED = BOND_STATE_SEED;
|
|
7252
7069
|
exports.BondClientEnv = BondClientEnv;
|
|
7253
|
-
exports.BondStateStatusVariant = BondStateStatusVariant;
|
|
7254
7070
|
exports.BondTransactionType = BondTransactionType;
|
|
7255
|
-
exports.
|
|
7071
|
+
exports.BondType = BondType;
|
|
7072
|
+
exports.CROWDFUNDING_BOND_SEED = CROWDFUNDING_BOND_SEED;
|
|
7256
7073
|
exports.ENV_PROGRAM_ID = ENV_PROGRAM_ID;
|
|
7074
|
+
exports.GLOBAL_STATE_SEED = GLOBAL_STATE_SEED;
|
|
7257
7075
|
exports.JBondClient = JBondClient;
|
|
7258
|
-
exports.JPOOL_STAKE_POOL = JPOOL_STAKE_POOL;
|
|
7259
7076
|
exports.NodeWallet = NodeWallet;
|
|
7260
|
-
exports.
|
|
7077
|
+
exports.STANDARD_BOND_SEED = STANDARD_BOND_SEED;
|
|
7261
7078
|
exports.SessionStatus = SessionStatus;
|
|
7262
|
-
exports.
|
|
7079
|
+
exports.VALIDATOR_BOND_SEED = VALIDATOR_BOND_SEED;
|
|
7263
7080
|
//# sourceMappingURL=index.js.map
|
|
7264
7081
|
//# sourceMappingURL=index.js.map
|