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