@jpool/bond-sdk 0.9.0-next.5 → 0.9.0-next.7
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 +26 -37
- package/dist/index.d.ts +26 -37
- package/dist/index.js +425 -666
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +428 -660
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ var anchor = require('@coral-xyz/anchor');
|
|
|
4
4
|
var splStakePool = require('@solana/spl-stake-pool');
|
|
5
5
|
var splToken = require('@solana/spl-token');
|
|
6
6
|
var web3_js = require('@solana/web3.js');
|
|
7
|
-
var token = require('@coral-xyz/anchor/dist/cjs/utils/token');
|
|
8
7
|
var bs58 = require('bs58');
|
|
9
8
|
|
|
10
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -1837,8 +1836,8 @@ var require_bn = __commonJS({
|
|
|
1837
1836
|
ctor.prototype = new TempCtor();
|
|
1838
1837
|
ctor.prototype.constructor = ctor;
|
|
1839
1838
|
}
|
|
1840
|
-
function
|
|
1841
|
-
if (
|
|
1839
|
+
function BN4(number, base, endian) {
|
|
1840
|
+
if (BN4.isBN(number)) {
|
|
1842
1841
|
return number;
|
|
1843
1842
|
}
|
|
1844
1843
|
this.negative = 0;
|
|
@@ -1854,12 +1853,12 @@ var require_bn = __commonJS({
|
|
|
1854
1853
|
}
|
|
1855
1854
|
}
|
|
1856
1855
|
if (typeof module2 === "object") {
|
|
1857
|
-
module2.exports =
|
|
1856
|
+
module2.exports = BN4;
|
|
1858
1857
|
} else {
|
|
1859
|
-
exports2.BN =
|
|
1858
|
+
exports2.BN = BN4;
|
|
1860
1859
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1860
|
+
BN4.BN = BN4;
|
|
1861
|
+
BN4.wordSize = 26;
|
|
1863
1862
|
var Buffer2;
|
|
1864
1863
|
try {
|
|
1865
1864
|
if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
|
|
@@ -1869,21 +1868,21 @@ var require_bn = __commonJS({
|
|
|
1869
1868
|
}
|
|
1870
1869
|
} catch (e) {
|
|
1871
1870
|
}
|
|
1872
|
-
|
|
1873
|
-
if (num instanceof
|
|
1871
|
+
BN4.isBN = function isBN(num) {
|
|
1872
|
+
if (num instanceof BN4) {
|
|
1874
1873
|
return true;
|
|
1875
1874
|
}
|
|
1876
|
-
return num !== null && typeof num === "object" && num.constructor.wordSize ===
|
|
1875
|
+
return num !== null && typeof num === "object" && num.constructor.wordSize === BN4.wordSize && Array.isArray(num.words);
|
|
1877
1876
|
};
|
|
1878
|
-
|
|
1877
|
+
BN4.max = function max(left, right) {
|
|
1879
1878
|
if (left.cmp(right) > 0) return left;
|
|
1880
1879
|
return right;
|
|
1881
1880
|
};
|
|
1882
|
-
|
|
1881
|
+
BN4.min = function min(left, right) {
|
|
1883
1882
|
if (left.cmp(right) < 0) return left;
|
|
1884
1883
|
return right;
|
|
1885
1884
|
};
|
|
1886
|
-
|
|
1885
|
+
BN4.prototype._init = function init(number, base, endian) {
|
|
1887
1886
|
if (typeof number === "number") {
|
|
1888
1887
|
return this._initNumber(number, base, endian);
|
|
1889
1888
|
}
|
|
@@ -1911,7 +1910,7 @@ var require_bn = __commonJS({
|
|
|
1911
1910
|
}
|
|
1912
1911
|
}
|
|
1913
1912
|
};
|
|
1914
|
-
|
|
1913
|
+
BN4.prototype._initNumber = function _initNumber(number, base, endian) {
|
|
1915
1914
|
if (number < 0) {
|
|
1916
1915
|
this.negative = 1;
|
|
1917
1916
|
number = -number;
|
|
@@ -1937,7 +1936,7 @@ var require_bn = __commonJS({
|
|
|
1937
1936
|
if (endian !== "le") return;
|
|
1938
1937
|
this._initArray(this.toArray(), base, endian);
|
|
1939
1938
|
};
|
|
1940
|
-
|
|
1939
|
+
BN4.prototype._initArray = function _initArray(number, base, endian) {
|
|
1941
1940
|
assert(typeof number.length === "number");
|
|
1942
1941
|
if (number.length <= 0) {
|
|
1943
1942
|
this.words = [0];
|
|
@@ -1995,7 +1994,7 @@ var require_bn = __commonJS({
|
|
|
1995
1994
|
}
|
|
1996
1995
|
return r;
|
|
1997
1996
|
}
|
|
1998
|
-
|
|
1997
|
+
BN4.prototype._parseHex = function _parseHex(number, start, endian) {
|
|
1999
1998
|
this.length = Math.ceil((number.length - start) / 6);
|
|
2000
1999
|
this.words = new Array(this.length);
|
|
2001
2000
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -2051,7 +2050,7 @@ var require_bn = __commonJS({
|
|
|
2051
2050
|
}
|
|
2052
2051
|
return r;
|
|
2053
2052
|
}
|
|
2054
|
-
|
|
2053
|
+
BN4.prototype._parseBase = function _parseBase(number, base, start) {
|
|
2055
2054
|
this.words = [0];
|
|
2056
2055
|
this.length = 1;
|
|
2057
2056
|
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
|
|
@@ -2087,7 +2086,7 @@ var require_bn = __commonJS({
|
|
|
2087
2086
|
}
|
|
2088
2087
|
this._strip();
|
|
2089
2088
|
};
|
|
2090
|
-
|
|
2089
|
+
BN4.prototype.copy = function copy(dest) {
|
|
2091
2090
|
dest.words = new Array(this.length);
|
|
2092
2091
|
for (var i = 0; i < this.length; i++) {
|
|
2093
2092
|
dest.words[i] = this.words[i];
|
|
@@ -2102,27 +2101,27 @@ var require_bn = __commonJS({
|
|
|
2102
2101
|
dest.negative = src.negative;
|
|
2103
2102
|
dest.red = src.red;
|
|
2104
2103
|
}
|
|
2105
|
-
|
|
2104
|
+
BN4.prototype._move = function _move(dest) {
|
|
2106
2105
|
move(dest, this);
|
|
2107
2106
|
};
|
|
2108
|
-
|
|
2109
|
-
var r = new
|
|
2107
|
+
BN4.prototype.clone = function clone() {
|
|
2108
|
+
var r = new BN4(null);
|
|
2110
2109
|
this.copy(r);
|
|
2111
2110
|
return r;
|
|
2112
2111
|
};
|
|
2113
|
-
|
|
2112
|
+
BN4.prototype._expand = function _expand(size) {
|
|
2114
2113
|
while (this.length < size) {
|
|
2115
2114
|
this.words[this.length++] = 0;
|
|
2116
2115
|
}
|
|
2117
2116
|
return this;
|
|
2118
2117
|
};
|
|
2119
|
-
|
|
2118
|
+
BN4.prototype._strip = function strip() {
|
|
2120
2119
|
while (this.length > 1 && this.words[this.length - 1] === 0) {
|
|
2121
2120
|
this.length--;
|
|
2122
2121
|
}
|
|
2123
2122
|
return this._normSign();
|
|
2124
2123
|
};
|
|
2125
|
-
|
|
2124
|
+
BN4.prototype._normSign = function _normSign() {
|
|
2126
2125
|
if (this.length === 1 && this.words[0] === 0) {
|
|
2127
2126
|
this.negative = 0;
|
|
2128
2127
|
}
|
|
@@ -2130,12 +2129,12 @@ var require_bn = __commonJS({
|
|
|
2130
2129
|
};
|
|
2131
2130
|
if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
|
|
2132
2131
|
try {
|
|
2133
|
-
|
|
2132
|
+
BN4.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
|
|
2134
2133
|
} catch (e) {
|
|
2135
|
-
|
|
2134
|
+
BN4.prototype.inspect = inspect;
|
|
2136
2135
|
}
|
|
2137
2136
|
} else {
|
|
2138
|
-
|
|
2137
|
+
BN4.prototype.inspect = inspect;
|
|
2139
2138
|
}
|
|
2140
2139
|
function inspect() {
|
|
2141
2140
|
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
|
|
@@ -2246,7 +2245,7 @@ var require_bn = __commonJS({
|
|
|
2246
2245
|
52521875,
|
|
2247
2246
|
60466176
|
|
2248
2247
|
];
|
|
2249
|
-
|
|
2248
|
+
BN4.prototype.toString = function toString(base, padding) {
|
|
2250
2249
|
base = base || 10;
|
|
2251
2250
|
padding = padding | 0 || 1;
|
|
2252
2251
|
var out;
|
|
@@ -2308,7 +2307,7 @@ var require_bn = __commonJS({
|
|
|
2308
2307
|
}
|
|
2309
2308
|
assert(false, "Base should be between 2 and 36");
|
|
2310
2309
|
};
|
|
2311
|
-
|
|
2310
|
+
BN4.prototype.toNumber = function toNumber() {
|
|
2312
2311
|
var ret = this.words[0];
|
|
2313
2312
|
if (this.length === 2) {
|
|
2314
2313
|
ret += this.words[1] * 67108864;
|
|
@@ -2319,15 +2318,15 @@ var require_bn = __commonJS({
|
|
|
2319
2318
|
}
|
|
2320
2319
|
return this.negative !== 0 ? -ret : ret;
|
|
2321
2320
|
};
|
|
2322
|
-
|
|
2321
|
+
BN4.prototype.toJSON = function toJSON() {
|
|
2323
2322
|
return this.toString(16, 2);
|
|
2324
2323
|
};
|
|
2325
2324
|
if (Buffer2) {
|
|
2326
|
-
|
|
2325
|
+
BN4.prototype.toBuffer = function toBuffer(endian, length) {
|
|
2327
2326
|
return this.toArrayLike(Buffer2, endian, length);
|
|
2328
2327
|
};
|
|
2329
2328
|
}
|
|
2330
|
-
|
|
2329
|
+
BN4.prototype.toArray = function toArray(endian, length) {
|
|
2331
2330
|
return this.toArrayLike(Array, endian, length);
|
|
2332
2331
|
};
|
|
2333
2332
|
var allocate = function allocate2(ArrayType, size) {
|
|
@@ -2336,7 +2335,7 @@ var require_bn = __commonJS({
|
|
|
2336
2335
|
}
|
|
2337
2336
|
return new ArrayType(size);
|
|
2338
2337
|
};
|
|
2339
|
-
|
|
2338
|
+
BN4.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
|
|
2340
2339
|
this._strip();
|
|
2341
2340
|
var byteLength = this.byteLength();
|
|
2342
2341
|
var reqLength = length || Math.max(1, byteLength);
|
|
@@ -2347,7 +2346,7 @@ var require_bn = __commonJS({
|
|
|
2347
2346
|
this["_toArrayLike" + postfix](res, byteLength);
|
|
2348
2347
|
return res;
|
|
2349
2348
|
};
|
|
2350
|
-
|
|
2349
|
+
BN4.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
|
|
2351
2350
|
var position = 0;
|
|
2352
2351
|
var carry = 0;
|
|
2353
2352
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -2377,7 +2376,7 @@ var require_bn = __commonJS({
|
|
|
2377
2376
|
}
|
|
2378
2377
|
}
|
|
2379
2378
|
};
|
|
2380
|
-
|
|
2379
|
+
BN4.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
|
|
2381
2380
|
var position = res.length - 1;
|
|
2382
2381
|
var carry = 0;
|
|
2383
2382
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -2408,11 +2407,11 @@ var require_bn = __commonJS({
|
|
|
2408
2407
|
}
|
|
2409
2408
|
};
|
|
2410
2409
|
if (Math.clz32) {
|
|
2411
|
-
|
|
2410
|
+
BN4.prototype._countBits = function _countBits(w) {
|
|
2412
2411
|
return 32 - Math.clz32(w);
|
|
2413
2412
|
};
|
|
2414
2413
|
} else {
|
|
2415
|
-
|
|
2414
|
+
BN4.prototype._countBits = function _countBits(w) {
|
|
2416
2415
|
var t = w;
|
|
2417
2416
|
var r = 0;
|
|
2418
2417
|
if (t >= 4096) {
|
|
@@ -2434,7 +2433,7 @@ var require_bn = __commonJS({
|
|
|
2434
2433
|
return r + t;
|
|
2435
2434
|
};
|
|
2436
2435
|
}
|
|
2437
|
-
|
|
2436
|
+
BN4.prototype._zeroBits = function _zeroBits(w) {
|
|
2438
2437
|
if (w === 0) return 26;
|
|
2439
2438
|
var t = w;
|
|
2440
2439
|
var r = 0;
|
|
@@ -2459,7 +2458,7 @@ var require_bn = __commonJS({
|
|
|
2459
2458
|
}
|
|
2460
2459
|
return r;
|
|
2461
2460
|
};
|
|
2462
|
-
|
|
2461
|
+
BN4.prototype.bitLength = function bitLength() {
|
|
2463
2462
|
var w = this.words[this.length - 1];
|
|
2464
2463
|
var hi = this._countBits(w);
|
|
2465
2464
|
return (this.length - 1) * 26 + hi;
|
|
@@ -2473,7 +2472,7 @@ var require_bn = __commonJS({
|
|
|
2473
2472
|
}
|
|
2474
2473
|
return w;
|
|
2475
2474
|
}
|
|
2476
|
-
|
|
2475
|
+
BN4.prototype.zeroBits = function zeroBits() {
|
|
2477
2476
|
if (this.isZero()) return 0;
|
|
2478
2477
|
var r = 0;
|
|
2479
2478
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -2483,34 +2482,34 @@ var require_bn = __commonJS({
|
|
|
2483
2482
|
}
|
|
2484
2483
|
return r;
|
|
2485
2484
|
};
|
|
2486
|
-
|
|
2485
|
+
BN4.prototype.byteLength = function byteLength() {
|
|
2487
2486
|
return Math.ceil(this.bitLength() / 8);
|
|
2488
2487
|
};
|
|
2489
|
-
|
|
2488
|
+
BN4.prototype.toTwos = function toTwos(width) {
|
|
2490
2489
|
if (this.negative !== 0) {
|
|
2491
2490
|
return this.abs().inotn(width).iaddn(1);
|
|
2492
2491
|
}
|
|
2493
2492
|
return this.clone();
|
|
2494
2493
|
};
|
|
2495
|
-
|
|
2494
|
+
BN4.prototype.fromTwos = function fromTwos(width) {
|
|
2496
2495
|
if (this.testn(width - 1)) {
|
|
2497
2496
|
return this.notn(width).iaddn(1).ineg();
|
|
2498
2497
|
}
|
|
2499
2498
|
return this.clone();
|
|
2500
2499
|
};
|
|
2501
|
-
|
|
2500
|
+
BN4.prototype.isNeg = function isNeg() {
|
|
2502
2501
|
return this.negative !== 0;
|
|
2503
2502
|
};
|
|
2504
|
-
|
|
2503
|
+
BN4.prototype.neg = function neg() {
|
|
2505
2504
|
return this.clone().ineg();
|
|
2506
2505
|
};
|
|
2507
|
-
|
|
2506
|
+
BN4.prototype.ineg = function ineg() {
|
|
2508
2507
|
if (!this.isZero()) {
|
|
2509
2508
|
this.negative ^= 1;
|
|
2510
2509
|
}
|
|
2511
2510
|
return this;
|
|
2512
2511
|
};
|
|
2513
|
-
|
|
2512
|
+
BN4.prototype.iuor = function iuor(num) {
|
|
2514
2513
|
while (this.length < num.length) {
|
|
2515
2514
|
this.words[this.length++] = 0;
|
|
2516
2515
|
}
|
|
@@ -2519,19 +2518,19 @@ var require_bn = __commonJS({
|
|
|
2519
2518
|
}
|
|
2520
2519
|
return this._strip();
|
|
2521
2520
|
};
|
|
2522
|
-
|
|
2521
|
+
BN4.prototype.ior = function ior(num) {
|
|
2523
2522
|
assert((this.negative | num.negative) === 0);
|
|
2524
2523
|
return this.iuor(num);
|
|
2525
2524
|
};
|
|
2526
|
-
|
|
2525
|
+
BN4.prototype.or = function or(num) {
|
|
2527
2526
|
if (this.length > num.length) return this.clone().ior(num);
|
|
2528
2527
|
return num.clone().ior(this);
|
|
2529
2528
|
};
|
|
2530
|
-
|
|
2529
|
+
BN4.prototype.uor = function uor(num) {
|
|
2531
2530
|
if (this.length > num.length) return this.clone().iuor(num);
|
|
2532
2531
|
return num.clone().iuor(this);
|
|
2533
2532
|
};
|
|
2534
|
-
|
|
2533
|
+
BN4.prototype.iuand = function iuand(num) {
|
|
2535
2534
|
var b;
|
|
2536
2535
|
if (this.length > num.length) {
|
|
2537
2536
|
b = num;
|
|
@@ -2544,19 +2543,19 @@ var require_bn = __commonJS({
|
|
|
2544
2543
|
this.length = b.length;
|
|
2545
2544
|
return this._strip();
|
|
2546
2545
|
};
|
|
2547
|
-
|
|
2546
|
+
BN4.prototype.iand = function iand(num) {
|
|
2548
2547
|
assert((this.negative | num.negative) === 0);
|
|
2549
2548
|
return this.iuand(num);
|
|
2550
2549
|
};
|
|
2551
|
-
|
|
2550
|
+
BN4.prototype.and = function and(num) {
|
|
2552
2551
|
if (this.length > num.length) return this.clone().iand(num);
|
|
2553
2552
|
return num.clone().iand(this);
|
|
2554
2553
|
};
|
|
2555
|
-
|
|
2554
|
+
BN4.prototype.uand = function uand(num) {
|
|
2556
2555
|
if (this.length > num.length) return this.clone().iuand(num);
|
|
2557
2556
|
return num.clone().iuand(this);
|
|
2558
2557
|
};
|
|
2559
|
-
|
|
2558
|
+
BN4.prototype.iuxor = function iuxor(num) {
|
|
2560
2559
|
var a;
|
|
2561
2560
|
var b;
|
|
2562
2561
|
if (this.length > num.length) {
|
|
@@ -2577,19 +2576,19 @@ var require_bn = __commonJS({
|
|
|
2577
2576
|
this.length = a.length;
|
|
2578
2577
|
return this._strip();
|
|
2579
2578
|
};
|
|
2580
|
-
|
|
2579
|
+
BN4.prototype.ixor = function ixor(num) {
|
|
2581
2580
|
assert((this.negative | num.negative) === 0);
|
|
2582
2581
|
return this.iuxor(num);
|
|
2583
2582
|
};
|
|
2584
|
-
|
|
2583
|
+
BN4.prototype.xor = function xor(num) {
|
|
2585
2584
|
if (this.length > num.length) return this.clone().ixor(num);
|
|
2586
2585
|
return num.clone().ixor(this);
|
|
2587
2586
|
};
|
|
2588
|
-
|
|
2587
|
+
BN4.prototype.uxor = function uxor(num) {
|
|
2589
2588
|
if (this.length > num.length) return this.clone().iuxor(num);
|
|
2590
2589
|
return num.clone().iuxor(this);
|
|
2591
2590
|
};
|
|
2592
|
-
|
|
2591
|
+
BN4.prototype.inotn = function inotn(width) {
|
|
2593
2592
|
assert(typeof width === "number" && width >= 0);
|
|
2594
2593
|
var bytesNeeded = Math.ceil(width / 26) | 0;
|
|
2595
2594
|
var bitsLeft = width % 26;
|
|
@@ -2605,10 +2604,10 @@ var require_bn = __commonJS({
|
|
|
2605
2604
|
}
|
|
2606
2605
|
return this._strip();
|
|
2607
2606
|
};
|
|
2608
|
-
|
|
2607
|
+
BN4.prototype.notn = function notn(width) {
|
|
2609
2608
|
return this.clone().inotn(width);
|
|
2610
2609
|
};
|
|
2611
|
-
|
|
2610
|
+
BN4.prototype.setn = function setn(bit, val) {
|
|
2612
2611
|
assert(typeof bit === "number" && bit >= 0);
|
|
2613
2612
|
var off = bit / 26 | 0;
|
|
2614
2613
|
var wbit = bit % 26;
|
|
@@ -2620,7 +2619,7 @@ var require_bn = __commonJS({
|
|
|
2620
2619
|
}
|
|
2621
2620
|
return this._strip();
|
|
2622
2621
|
};
|
|
2623
|
-
|
|
2622
|
+
BN4.prototype.iadd = function iadd(num) {
|
|
2624
2623
|
var r;
|
|
2625
2624
|
if (this.negative !== 0 && num.negative === 0) {
|
|
2626
2625
|
this.negative = 0;
|
|
@@ -2663,7 +2662,7 @@ var require_bn = __commonJS({
|
|
|
2663
2662
|
}
|
|
2664
2663
|
return this;
|
|
2665
2664
|
};
|
|
2666
|
-
|
|
2665
|
+
BN4.prototype.add = function add(num) {
|
|
2667
2666
|
var res;
|
|
2668
2667
|
if (num.negative !== 0 && this.negative === 0) {
|
|
2669
2668
|
num.negative = 0;
|
|
@@ -2679,7 +2678,7 @@ var require_bn = __commonJS({
|
|
|
2679
2678
|
if (this.length > num.length) return this.clone().iadd(num);
|
|
2680
2679
|
return num.clone().iadd(this);
|
|
2681
2680
|
};
|
|
2682
|
-
|
|
2681
|
+
BN4.prototype.isub = function isub(num) {
|
|
2683
2682
|
if (num.negative !== 0) {
|
|
2684
2683
|
num.negative = 0;
|
|
2685
2684
|
var r = this.iadd(num);
|
|
@@ -2728,7 +2727,7 @@ var require_bn = __commonJS({
|
|
|
2728
2727
|
}
|
|
2729
2728
|
return this._strip();
|
|
2730
2729
|
};
|
|
2731
|
-
|
|
2730
|
+
BN4.prototype.sub = function sub(num) {
|
|
2732
2731
|
return this.clone().isub(num);
|
|
2733
2732
|
};
|
|
2734
2733
|
function smallMulTo(self, num, out) {
|
|
@@ -3356,7 +3355,7 @@ var require_bn = __commonJS({
|
|
|
3356
3355
|
function jumboMulTo(self, num, out) {
|
|
3357
3356
|
return bigMulTo(self, num, out);
|
|
3358
3357
|
}
|
|
3359
|
-
|
|
3358
|
+
BN4.prototype.mulTo = function mulTo(num, out) {
|
|
3360
3359
|
var res;
|
|
3361
3360
|
var len = this.length + num.length;
|
|
3362
3361
|
if (this.length === 10 && num.length === 10) {
|
|
@@ -3370,20 +3369,20 @@ var require_bn = __commonJS({
|
|
|
3370
3369
|
}
|
|
3371
3370
|
return res;
|
|
3372
3371
|
};
|
|
3373
|
-
|
|
3374
|
-
var out = new
|
|
3372
|
+
BN4.prototype.mul = function mul(num) {
|
|
3373
|
+
var out = new BN4(null);
|
|
3375
3374
|
out.words = new Array(this.length + num.length);
|
|
3376
3375
|
return this.mulTo(num, out);
|
|
3377
3376
|
};
|
|
3378
|
-
|
|
3379
|
-
var out = new
|
|
3377
|
+
BN4.prototype.mulf = function mulf(num) {
|
|
3378
|
+
var out = new BN4(null);
|
|
3380
3379
|
out.words = new Array(this.length + num.length);
|
|
3381
3380
|
return jumboMulTo(this, num, out);
|
|
3382
3381
|
};
|
|
3383
|
-
|
|
3382
|
+
BN4.prototype.imul = function imul(num) {
|
|
3384
3383
|
return this.clone().mulTo(num, this);
|
|
3385
3384
|
};
|
|
3386
|
-
|
|
3385
|
+
BN4.prototype.imuln = function imuln(num) {
|
|
3387
3386
|
var isNegNum = num < 0;
|
|
3388
3387
|
if (isNegNum) num = -num;
|
|
3389
3388
|
assert(typeof num === "number");
|
|
@@ -3404,18 +3403,18 @@ var require_bn = __commonJS({
|
|
|
3404
3403
|
this.length = num === 0 ? 1 : this.length;
|
|
3405
3404
|
return isNegNum ? this.ineg() : this;
|
|
3406
3405
|
};
|
|
3407
|
-
|
|
3406
|
+
BN4.prototype.muln = function muln(num) {
|
|
3408
3407
|
return this.clone().imuln(num);
|
|
3409
3408
|
};
|
|
3410
|
-
|
|
3409
|
+
BN4.prototype.sqr = function sqr() {
|
|
3411
3410
|
return this.mul(this);
|
|
3412
3411
|
};
|
|
3413
|
-
|
|
3412
|
+
BN4.prototype.isqr = function isqr() {
|
|
3414
3413
|
return this.imul(this.clone());
|
|
3415
3414
|
};
|
|
3416
|
-
|
|
3415
|
+
BN4.prototype.pow = function pow(num) {
|
|
3417
3416
|
var w = toBitArray(num);
|
|
3418
|
-
if (w.length === 0) return new
|
|
3417
|
+
if (w.length === 0) return new BN4(1);
|
|
3419
3418
|
var res = this;
|
|
3420
3419
|
for (var i = 0; i < w.length; i++, res = res.sqr()) {
|
|
3421
3420
|
if (w[i] !== 0) break;
|
|
@@ -3428,7 +3427,7 @@ var require_bn = __commonJS({
|
|
|
3428
3427
|
}
|
|
3429
3428
|
return res;
|
|
3430
3429
|
};
|
|
3431
|
-
|
|
3430
|
+
BN4.prototype.iushln = function iushln(bits) {
|
|
3432
3431
|
assert(typeof bits === "number" && bits >= 0);
|
|
3433
3432
|
var r = bits % 26;
|
|
3434
3433
|
var s = (bits - r) / 26;
|
|
@@ -3458,11 +3457,11 @@ var require_bn = __commonJS({
|
|
|
3458
3457
|
}
|
|
3459
3458
|
return this._strip();
|
|
3460
3459
|
};
|
|
3461
|
-
|
|
3460
|
+
BN4.prototype.ishln = function ishln(bits) {
|
|
3462
3461
|
assert(this.negative === 0);
|
|
3463
3462
|
return this.iushln(bits);
|
|
3464
3463
|
};
|
|
3465
|
-
|
|
3464
|
+
BN4.prototype.iushrn = function iushrn(bits, hint, extended) {
|
|
3466
3465
|
assert(typeof bits === "number" && bits >= 0);
|
|
3467
3466
|
var h;
|
|
3468
3467
|
if (hint) {
|
|
@@ -3506,23 +3505,23 @@ var require_bn = __commonJS({
|
|
|
3506
3505
|
}
|
|
3507
3506
|
return this._strip();
|
|
3508
3507
|
};
|
|
3509
|
-
|
|
3508
|
+
BN4.prototype.ishrn = function ishrn(bits, hint, extended) {
|
|
3510
3509
|
assert(this.negative === 0);
|
|
3511
3510
|
return this.iushrn(bits, hint, extended);
|
|
3512
3511
|
};
|
|
3513
|
-
|
|
3512
|
+
BN4.prototype.shln = function shln(bits) {
|
|
3514
3513
|
return this.clone().ishln(bits);
|
|
3515
3514
|
};
|
|
3516
|
-
|
|
3515
|
+
BN4.prototype.ushln = function ushln(bits) {
|
|
3517
3516
|
return this.clone().iushln(bits);
|
|
3518
3517
|
};
|
|
3519
|
-
|
|
3518
|
+
BN4.prototype.shrn = function shrn(bits) {
|
|
3520
3519
|
return this.clone().ishrn(bits);
|
|
3521
3520
|
};
|
|
3522
|
-
|
|
3521
|
+
BN4.prototype.ushrn = function ushrn(bits) {
|
|
3523
3522
|
return this.clone().iushrn(bits);
|
|
3524
3523
|
};
|
|
3525
|
-
|
|
3524
|
+
BN4.prototype.testn = function testn(bit) {
|
|
3526
3525
|
assert(typeof bit === "number" && bit >= 0);
|
|
3527
3526
|
var r = bit % 26;
|
|
3528
3527
|
var s = (bit - r) / 26;
|
|
@@ -3531,7 +3530,7 @@ var require_bn = __commonJS({
|
|
|
3531
3530
|
var w = this.words[s];
|
|
3532
3531
|
return !!(w & q);
|
|
3533
3532
|
};
|
|
3534
|
-
|
|
3533
|
+
BN4.prototype.imaskn = function imaskn(bits) {
|
|
3535
3534
|
assert(typeof bits === "number" && bits >= 0);
|
|
3536
3535
|
var r = bits % 26;
|
|
3537
3536
|
var s = (bits - r) / 26;
|
|
@@ -3549,10 +3548,10 @@ var require_bn = __commonJS({
|
|
|
3549
3548
|
}
|
|
3550
3549
|
return this._strip();
|
|
3551
3550
|
};
|
|
3552
|
-
|
|
3551
|
+
BN4.prototype.maskn = function maskn(bits) {
|
|
3553
3552
|
return this.clone().imaskn(bits);
|
|
3554
3553
|
};
|
|
3555
|
-
|
|
3554
|
+
BN4.prototype.iaddn = function iaddn(num) {
|
|
3556
3555
|
assert(typeof num === "number");
|
|
3557
3556
|
assert(num < 67108864);
|
|
3558
3557
|
if (num < 0) return this.isubn(-num);
|
|
@@ -3569,7 +3568,7 @@ var require_bn = __commonJS({
|
|
|
3569
3568
|
}
|
|
3570
3569
|
return this._iaddn(num);
|
|
3571
3570
|
};
|
|
3572
|
-
|
|
3571
|
+
BN4.prototype._iaddn = function _iaddn(num) {
|
|
3573
3572
|
this.words[0] += num;
|
|
3574
3573
|
for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
|
|
3575
3574
|
this.words[i] -= 67108864;
|
|
@@ -3582,7 +3581,7 @@ var require_bn = __commonJS({
|
|
|
3582
3581
|
this.length = Math.max(this.length, i + 1);
|
|
3583
3582
|
return this;
|
|
3584
3583
|
};
|
|
3585
|
-
|
|
3584
|
+
BN4.prototype.isubn = function isubn(num) {
|
|
3586
3585
|
assert(typeof num === "number");
|
|
3587
3586
|
assert(num < 67108864);
|
|
3588
3587
|
if (num < 0) return this.iaddn(-num);
|
|
@@ -3604,20 +3603,20 @@ var require_bn = __commonJS({
|
|
|
3604
3603
|
}
|
|
3605
3604
|
return this._strip();
|
|
3606
3605
|
};
|
|
3607
|
-
|
|
3606
|
+
BN4.prototype.addn = function addn(num) {
|
|
3608
3607
|
return this.clone().iaddn(num);
|
|
3609
3608
|
};
|
|
3610
|
-
|
|
3609
|
+
BN4.prototype.subn = function subn(num) {
|
|
3611
3610
|
return this.clone().isubn(num);
|
|
3612
3611
|
};
|
|
3613
|
-
|
|
3612
|
+
BN4.prototype.iabs = function iabs() {
|
|
3614
3613
|
this.negative = 0;
|
|
3615
3614
|
return this;
|
|
3616
3615
|
};
|
|
3617
|
-
|
|
3616
|
+
BN4.prototype.abs = function abs() {
|
|
3618
3617
|
return this.clone().iabs();
|
|
3619
3618
|
};
|
|
3620
|
-
|
|
3619
|
+
BN4.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
|
|
3621
3620
|
var len = num.length + shift;
|
|
3622
3621
|
var i;
|
|
3623
3622
|
this._expand(len);
|
|
@@ -3646,7 +3645,7 @@ var require_bn = __commonJS({
|
|
|
3646
3645
|
this.negative = 1;
|
|
3647
3646
|
return this._strip();
|
|
3648
3647
|
};
|
|
3649
|
-
|
|
3648
|
+
BN4.prototype._wordDiv = function _wordDiv(num, mode) {
|
|
3650
3649
|
var shift = this.length - num.length;
|
|
3651
3650
|
var a = this.clone();
|
|
3652
3651
|
var b = num;
|
|
@@ -3661,7 +3660,7 @@ var require_bn = __commonJS({
|
|
|
3661
3660
|
var m = a.length - b.length;
|
|
3662
3661
|
var q;
|
|
3663
3662
|
if (mode !== "mod") {
|
|
3664
|
-
q = new
|
|
3663
|
+
q = new BN4(null);
|
|
3665
3664
|
q.length = m + 1;
|
|
3666
3665
|
q.words = new Array(q.length);
|
|
3667
3666
|
for (var i = 0; i < q.length; i++) {
|
|
@@ -3703,12 +3702,12 @@ var require_bn = __commonJS({
|
|
|
3703
3702
|
mod: a
|
|
3704
3703
|
};
|
|
3705
3704
|
};
|
|
3706
|
-
|
|
3705
|
+
BN4.prototype.divmod = function divmod(num, mode, positive) {
|
|
3707
3706
|
assert(!num.isZero());
|
|
3708
3707
|
if (this.isZero()) {
|
|
3709
3708
|
return {
|
|
3710
|
-
div: new
|
|
3711
|
-
mod: new
|
|
3709
|
+
div: new BN4(0),
|
|
3710
|
+
mod: new BN4(0)
|
|
3712
3711
|
};
|
|
3713
3712
|
}
|
|
3714
3713
|
var div, mod, res;
|
|
@@ -3753,7 +3752,7 @@ var require_bn = __commonJS({
|
|
|
3753
3752
|
}
|
|
3754
3753
|
if (num.length > this.length || this.cmp(num) < 0) {
|
|
3755
3754
|
return {
|
|
3756
|
-
div: new
|
|
3755
|
+
div: new BN4(0),
|
|
3757
3756
|
mod: this
|
|
3758
3757
|
};
|
|
3759
3758
|
}
|
|
@@ -3767,26 +3766,26 @@ var require_bn = __commonJS({
|
|
|
3767
3766
|
if (mode === "mod") {
|
|
3768
3767
|
return {
|
|
3769
3768
|
div: null,
|
|
3770
|
-
mod: new
|
|
3769
|
+
mod: new BN4(this.modrn(num.words[0]))
|
|
3771
3770
|
};
|
|
3772
3771
|
}
|
|
3773
3772
|
return {
|
|
3774
3773
|
div: this.divn(num.words[0]),
|
|
3775
|
-
mod: new
|
|
3774
|
+
mod: new BN4(this.modrn(num.words[0]))
|
|
3776
3775
|
};
|
|
3777
3776
|
}
|
|
3778
3777
|
return this._wordDiv(num, mode);
|
|
3779
3778
|
};
|
|
3780
|
-
|
|
3779
|
+
BN4.prototype.div = function div(num) {
|
|
3781
3780
|
return this.divmod(num, "div", false).div;
|
|
3782
3781
|
};
|
|
3783
|
-
|
|
3782
|
+
BN4.prototype.mod = function mod(num) {
|
|
3784
3783
|
return this.divmod(num, "mod", false).mod;
|
|
3785
3784
|
};
|
|
3786
|
-
|
|
3785
|
+
BN4.prototype.umod = function umod(num) {
|
|
3787
3786
|
return this.divmod(num, "mod", true).mod;
|
|
3788
3787
|
};
|
|
3789
|
-
|
|
3788
|
+
BN4.prototype.divRound = function divRound(num) {
|
|
3790
3789
|
var dm = this.divmod(num);
|
|
3791
3790
|
if (dm.mod.isZero()) return dm.div;
|
|
3792
3791
|
var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
|
|
@@ -3796,7 +3795,7 @@ var require_bn = __commonJS({
|
|
|
3796
3795
|
if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
|
|
3797
3796
|
return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
|
|
3798
3797
|
};
|
|
3799
|
-
|
|
3798
|
+
BN4.prototype.modrn = function modrn(num) {
|
|
3800
3799
|
var isNegNum = num < 0;
|
|
3801
3800
|
if (isNegNum) num = -num;
|
|
3802
3801
|
assert(num <= 67108863);
|
|
@@ -3807,10 +3806,10 @@ var require_bn = __commonJS({
|
|
|
3807
3806
|
}
|
|
3808
3807
|
return isNegNum ? -acc : acc;
|
|
3809
3808
|
};
|
|
3810
|
-
|
|
3809
|
+
BN4.prototype.modn = function modn(num) {
|
|
3811
3810
|
return this.modrn(num);
|
|
3812
3811
|
};
|
|
3813
|
-
|
|
3812
|
+
BN4.prototype.idivn = function idivn(num) {
|
|
3814
3813
|
var isNegNum = num < 0;
|
|
3815
3814
|
if (isNegNum) num = -num;
|
|
3816
3815
|
assert(num <= 67108863);
|
|
@@ -3823,10 +3822,10 @@ var require_bn = __commonJS({
|
|
|
3823
3822
|
this._strip();
|
|
3824
3823
|
return isNegNum ? this.ineg() : this;
|
|
3825
3824
|
};
|
|
3826
|
-
|
|
3825
|
+
BN4.prototype.divn = function divn(num) {
|
|
3827
3826
|
return this.clone().idivn(num);
|
|
3828
3827
|
};
|
|
3829
|
-
|
|
3828
|
+
BN4.prototype.egcd = function egcd(p) {
|
|
3830
3829
|
assert(p.negative === 0);
|
|
3831
3830
|
assert(!p.isZero());
|
|
3832
3831
|
var x = this;
|
|
@@ -3836,10 +3835,10 @@ var require_bn = __commonJS({
|
|
|
3836
3835
|
} else {
|
|
3837
3836
|
x = x.clone();
|
|
3838
3837
|
}
|
|
3839
|
-
var A = new
|
|
3840
|
-
var B = new
|
|
3841
|
-
var C = new
|
|
3842
|
-
var D = new
|
|
3838
|
+
var A = new BN4(1);
|
|
3839
|
+
var B = new BN4(0);
|
|
3840
|
+
var C = new BN4(0);
|
|
3841
|
+
var D = new BN4(1);
|
|
3843
3842
|
var g = 0;
|
|
3844
3843
|
while (x.isEven() && y.isEven()) {
|
|
3845
3844
|
x.iushrn(1);
|
|
@@ -3889,7 +3888,7 @@ var require_bn = __commonJS({
|
|
|
3889
3888
|
gcd: y.iushln(g)
|
|
3890
3889
|
};
|
|
3891
3890
|
};
|
|
3892
|
-
|
|
3891
|
+
BN4.prototype._invmp = function _invmp(p) {
|
|
3893
3892
|
assert(p.negative === 0);
|
|
3894
3893
|
assert(!p.isZero());
|
|
3895
3894
|
var a = this;
|
|
@@ -3899,8 +3898,8 @@ var require_bn = __commonJS({
|
|
|
3899
3898
|
} else {
|
|
3900
3899
|
a = a.clone();
|
|
3901
3900
|
}
|
|
3902
|
-
var x1 = new
|
|
3903
|
-
var x2 = new
|
|
3901
|
+
var x1 = new BN4(1);
|
|
3902
|
+
var x2 = new BN4(0);
|
|
3904
3903
|
var delta = b.clone();
|
|
3905
3904
|
while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
|
|
3906
3905
|
for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
|
|
@@ -3942,7 +3941,7 @@ var require_bn = __commonJS({
|
|
|
3942
3941
|
}
|
|
3943
3942
|
return res;
|
|
3944
3943
|
};
|
|
3945
|
-
|
|
3944
|
+
BN4.prototype.gcd = function gcd(num) {
|
|
3946
3945
|
if (this.isZero()) return num.abs();
|
|
3947
3946
|
if (num.isZero()) return this.abs();
|
|
3948
3947
|
var a = this.clone();
|
|
@@ -3972,19 +3971,19 @@ var require_bn = __commonJS({
|
|
|
3972
3971
|
} while (true);
|
|
3973
3972
|
return b.iushln(shift);
|
|
3974
3973
|
};
|
|
3975
|
-
|
|
3974
|
+
BN4.prototype.invm = function invm(num) {
|
|
3976
3975
|
return this.egcd(num).a.umod(num);
|
|
3977
3976
|
};
|
|
3978
|
-
|
|
3977
|
+
BN4.prototype.isEven = function isEven() {
|
|
3979
3978
|
return (this.words[0] & 1) === 0;
|
|
3980
3979
|
};
|
|
3981
|
-
|
|
3980
|
+
BN4.prototype.isOdd = function isOdd() {
|
|
3982
3981
|
return (this.words[0] & 1) === 1;
|
|
3983
3982
|
};
|
|
3984
|
-
|
|
3983
|
+
BN4.prototype.andln = function andln(num) {
|
|
3985
3984
|
return this.words[0] & num;
|
|
3986
3985
|
};
|
|
3987
|
-
|
|
3986
|
+
BN4.prototype.bincn = function bincn(bit) {
|
|
3988
3987
|
assert(typeof bit === "number");
|
|
3989
3988
|
var r = bit % 26;
|
|
3990
3989
|
var s = (bit - r) / 26;
|
|
@@ -4008,10 +4007,10 @@ var require_bn = __commonJS({
|
|
|
4008
4007
|
}
|
|
4009
4008
|
return this;
|
|
4010
4009
|
};
|
|
4011
|
-
|
|
4010
|
+
BN4.prototype.isZero = function isZero() {
|
|
4012
4011
|
return this.length === 1 && this.words[0] === 0;
|
|
4013
4012
|
};
|
|
4014
|
-
|
|
4013
|
+
BN4.prototype.cmpn = function cmpn(num) {
|
|
4015
4014
|
var negative = num < 0;
|
|
4016
4015
|
if (this.negative !== 0 && !negative) return -1;
|
|
4017
4016
|
if (this.negative === 0 && negative) return 1;
|
|
@@ -4030,14 +4029,14 @@ var require_bn = __commonJS({
|
|
|
4030
4029
|
if (this.negative !== 0) return -res | 0;
|
|
4031
4030
|
return res;
|
|
4032
4031
|
};
|
|
4033
|
-
|
|
4032
|
+
BN4.prototype.cmp = function cmp(num) {
|
|
4034
4033
|
if (this.negative !== 0 && num.negative === 0) return -1;
|
|
4035
4034
|
if (this.negative === 0 && num.negative !== 0) return 1;
|
|
4036
4035
|
var res = this.ucmp(num);
|
|
4037
4036
|
if (this.negative !== 0) return -res | 0;
|
|
4038
4037
|
return res;
|
|
4039
4038
|
};
|
|
4040
|
-
|
|
4039
|
+
BN4.prototype.ucmp = function ucmp(num) {
|
|
4041
4040
|
if (this.length > num.length) return 1;
|
|
4042
4041
|
if (this.length < num.length) return -1;
|
|
4043
4042
|
var res = 0;
|
|
@@ -4054,112 +4053,112 @@ var require_bn = __commonJS({
|
|
|
4054
4053
|
}
|
|
4055
4054
|
return res;
|
|
4056
4055
|
};
|
|
4057
|
-
|
|
4056
|
+
BN4.prototype.gtn = function gtn(num) {
|
|
4058
4057
|
return this.cmpn(num) === 1;
|
|
4059
4058
|
};
|
|
4060
|
-
|
|
4059
|
+
BN4.prototype.gt = function gt(num) {
|
|
4061
4060
|
return this.cmp(num) === 1;
|
|
4062
4061
|
};
|
|
4063
|
-
|
|
4062
|
+
BN4.prototype.gten = function gten(num) {
|
|
4064
4063
|
return this.cmpn(num) >= 0;
|
|
4065
4064
|
};
|
|
4066
|
-
|
|
4065
|
+
BN4.prototype.gte = function gte(num) {
|
|
4067
4066
|
return this.cmp(num) >= 0;
|
|
4068
4067
|
};
|
|
4069
|
-
|
|
4068
|
+
BN4.prototype.ltn = function ltn(num) {
|
|
4070
4069
|
return this.cmpn(num) === -1;
|
|
4071
4070
|
};
|
|
4072
|
-
|
|
4071
|
+
BN4.prototype.lt = function lt(num) {
|
|
4073
4072
|
return this.cmp(num) === -1;
|
|
4074
4073
|
};
|
|
4075
|
-
|
|
4074
|
+
BN4.prototype.lten = function lten(num) {
|
|
4076
4075
|
return this.cmpn(num) <= 0;
|
|
4077
4076
|
};
|
|
4078
|
-
|
|
4077
|
+
BN4.prototype.lte = function lte(num) {
|
|
4079
4078
|
return this.cmp(num) <= 0;
|
|
4080
4079
|
};
|
|
4081
|
-
|
|
4080
|
+
BN4.prototype.eqn = function eqn(num) {
|
|
4082
4081
|
return this.cmpn(num) === 0;
|
|
4083
4082
|
};
|
|
4084
|
-
|
|
4083
|
+
BN4.prototype.eq = function eq(num) {
|
|
4085
4084
|
return this.cmp(num) === 0;
|
|
4086
4085
|
};
|
|
4087
|
-
|
|
4086
|
+
BN4.red = function red(num) {
|
|
4088
4087
|
return new Red(num);
|
|
4089
4088
|
};
|
|
4090
|
-
|
|
4089
|
+
BN4.prototype.toRed = function toRed(ctx) {
|
|
4091
4090
|
assert(!this.red, "Already a number in reduction context");
|
|
4092
4091
|
assert(this.negative === 0, "red works only with positives");
|
|
4093
4092
|
return ctx.convertTo(this)._forceRed(ctx);
|
|
4094
4093
|
};
|
|
4095
|
-
|
|
4094
|
+
BN4.prototype.fromRed = function fromRed() {
|
|
4096
4095
|
assert(this.red, "fromRed works only with numbers in reduction context");
|
|
4097
4096
|
return this.red.convertFrom(this);
|
|
4098
4097
|
};
|
|
4099
|
-
|
|
4098
|
+
BN4.prototype._forceRed = function _forceRed(ctx) {
|
|
4100
4099
|
this.red = ctx;
|
|
4101
4100
|
return this;
|
|
4102
4101
|
};
|
|
4103
|
-
|
|
4102
|
+
BN4.prototype.forceRed = function forceRed(ctx) {
|
|
4104
4103
|
assert(!this.red, "Already a number in reduction context");
|
|
4105
4104
|
return this._forceRed(ctx);
|
|
4106
4105
|
};
|
|
4107
|
-
|
|
4106
|
+
BN4.prototype.redAdd = function redAdd(num) {
|
|
4108
4107
|
assert(this.red, "redAdd works only with red numbers");
|
|
4109
4108
|
return this.red.add(this, num);
|
|
4110
4109
|
};
|
|
4111
|
-
|
|
4110
|
+
BN4.prototype.redIAdd = function redIAdd(num) {
|
|
4112
4111
|
assert(this.red, "redIAdd works only with red numbers");
|
|
4113
4112
|
return this.red.iadd(this, num);
|
|
4114
4113
|
};
|
|
4115
|
-
|
|
4114
|
+
BN4.prototype.redSub = function redSub(num) {
|
|
4116
4115
|
assert(this.red, "redSub works only with red numbers");
|
|
4117
4116
|
return this.red.sub(this, num);
|
|
4118
4117
|
};
|
|
4119
|
-
|
|
4118
|
+
BN4.prototype.redISub = function redISub(num) {
|
|
4120
4119
|
assert(this.red, "redISub works only with red numbers");
|
|
4121
4120
|
return this.red.isub(this, num);
|
|
4122
4121
|
};
|
|
4123
|
-
|
|
4122
|
+
BN4.prototype.redShl = function redShl(num) {
|
|
4124
4123
|
assert(this.red, "redShl works only with red numbers");
|
|
4125
4124
|
return this.red.shl(this, num);
|
|
4126
4125
|
};
|
|
4127
|
-
|
|
4126
|
+
BN4.prototype.redMul = function redMul(num) {
|
|
4128
4127
|
assert(this.red, "redMul works only with red numbers");
|
|
4129
4128
|
this.red._verify2(this, num);
|
|
4130
4129
|
return this.red.mul(this, num);
|
|
4131
4130
|
};
|
|
4132
|
-
|
|
4131
|
+
BN4.prototype.redIMul = function redIMul(num) {
|
|
4133
4132
|
assert(this.red, "redMul works only with red numbers");
|
|
4134
4133
|
this.red._verify2(this, num);
|
|
4135
4134
|
return this.red.imul(this, num);
|
|
4136
4135
|
};
|
|
4137
|
-
|
|
4136
|
+
BN4.prototype.redSqr = function redSqr() {
|
|
4138
4137
|
assert(this.red, "redSqr works only with red numbers");
|
|
4139
4138
|
this.red._verify1(this);
|
|
4140
4139
|
return this.red.sqr(this);
|
|
4141
4140
|
};
|
|
4142
|
-
|
|
4141
|
+
BN4.prototype.redISqr = function redISqr() {
|
|
4143
4142
|
assert(this.red, "redISqr works only with red numbers");
|
|
4144
4143
|
this.red._verify1(this);
|
|
4145
4144
|
return this.red.isqr(this);
|
|
4146
4145
|
};
|
|
4147
|
-
|
|
4146
|
+
BN4.prototype.redSqrt = function redSqrt() {
|
|
4148
4147
|
assert(this.red, "redSqrt works only with red numbers");
|
|
4149
4148
|
this.red._verify1(this);
|
|
4150
4149
|
return this.red.sqrt(this);
|
|
4151
4150
|
};
|
|
4152
|
-
|
|
4151
|
+
BN4.prototype.redInvm = function redInvm() {
|
|
4153
4152
|
assert(this.red, "redInvm works only with red numbers");
|
|
4154
4153
|
this.red._verify1(this);
|
|
4155
4154
|
return this.red.invm(this);
|
|
4156
4155
|
};
|
|
4157
|
-
|
|
4156
|
+
BN4.prototype.redNeg = function redNeg() {
|
|
4158
4157
|
assert(this.red, "redNeg works only with red numbers");
|
|
4159
4158
|
this.red._verify1(this);
|
|
4160
4159
|
return this.red.neg(this);
|
|
4161
4160
|
};
|
|
4162
|
-
|
|
4161
|
+
BN4.prototype.redPow = function redPow(num) {
|
|
4163
4162
|
assert(this.red && !num.red, "redPow(normalNum)");
|
|
4164
4163
|
this.red._verify1(this);
|
|
4165
4164
|
return this.red.pow(this, num);
|
|
@@ -4172,13 +4171,13 @@ var require_bn = __commonJS({
|
|
|
4172
4171
|
};
|
|
4173
4172
|
function MPrime(name, p) {
|
|
4174
4173
|
this.name = name;
|
|
4175
|
-
this.p = new
|
|
4174
|
+
this.p = new BN4(p, 16);
|
|
4176
4175
|
this.n = this.p.bitLength();
|
|
4177
|
-
this.k = new
|
|
4176
|
+
this.k = new BN4(1).iushln(this.n).isub(this.p);
|
|
4178
4177
|
this.tmp = this._tmp();
|
|
4179
4178
|
}
|
|
4180
4179
|
MPrime.prototype._tmp = function _tmp() {
|
|
4181
|
-
var tmp = new
|
|
4180
|
+
var tmp = new BN4(null);
|
|
4182
4181
|
tmp.words = new Array(Math.ceil(this.n / 13));
|
|
4183
4182
|
return tmp;
|
|
4184
4183
|
};
|
|
@@ -4304,7 +4303,7 @@ var require_bn = __commonJS({
|
|
|
4304
4303
|
}
|
|
4305
4304
|
return num;
|
|
4306
4305
|
};
|
|
4307
|
-
|
|
4306
|
+
BN4._prime = function prime(name) {
|
|
4308
4307
|
if (primes[name]) return primes[name];
|
|
4309
4308
|
var prime2;
|
|
4310
4309
|
if (name === "k256") {
|
|
@@ -4323,7 +4322,7 @@ var require_bn = __commonJS({
|
|
|
4323
4322
|
};
|
|
4324
4323
|
function Red(m) {
|
|
4325
4324
|
if (typeof m === "string") {
|
|
4326
|
-
var prime =
|
|
4325
|
+
var prime = BN4._prime(m);
|
|
4327
4326
|
this.m = prime.p;
|
|
4328
4327
|
this.prime = prime;
|
|
4329
4328
|
} else {
|
|
@@ -4409,7 +4408,7 @@ var require_bn = __commonJS({
|
|
|
4409
4408
|
var mod3 = this.m.andln(3);
|
|
4410
4409
|
assert(mod3 % 2 === 1);
|
|
4411
4410
|
if (mod3 === 3) {
|
|
4412
|
-
var pow = this.m.add(new
|
|
4411
|
+
var pow = this.m.add(new BN4(1)).iushrn(2);
|
|
4413
4412
|
return this.pow(a, pow);
|
|
4414
4413
|
}
|
|
4415
4414
|
var q = this.m.subn(1);
|
|
@@ -4419,11 +4418,11 @@ var require_bn = __commonJS({
|
|
|
4419
4418
|
q.iushrn(1);
|
|
4420
4419
|
}
|
|
4421
4420
|
assert(!q.isZero());
|
|
4422
|
-
var one = new
|
|
4421
|
+
var one = new BN4(1).toRed(this);
|
|
4423
4422
|
var nOne = one.redNeg();
|
|
4424
4423
|
var lpow = this.m.subn(1).iushrn(1);
|
|
4425
4424
|
var z = this.m.bitLength();
|
|
4426
|
-
z = new
|
|
4425
|
+
z = new BN4(2 * z * z).toRed(this);
|
|
4427
4426
|
while (this.pow(z, lpow).cmp(nOne) !== 0) {
|
|
4428
4427
|
z.redIAdd(nOne);
|
|
4429
4428
|
}
|
|
@@ -4437,7 +4436,7 @@ var require_bn = __commonJS({
|
|
|
4437
4436
|
tmp = tmp.redSqr();
|
|
4438
4437
|
}
|
|
4439
4438
|
assert(i < m);
|
|
4440
|
-
var b = this.pow(c, new
|
|
4439
|
+
var b = this.pow(c, new BN4(1).iushln(m - i - 1));
|
|
4441
4440
|
r = r.redMul(b);
|
|
4442
4441
|
c = b.redSqr();
|
|
4443
4442
|
t = t.redMul(c);
|
|
@@ -4455,11 +4454,11 @@ var require_bn = __commonJS({
|
|
|
4455
4454
|
}
|
|
4456
4455
|
};
|
|
4457
4456
|
Red.prototype.pow = function pow(a, num) {
|
|
4458
|
-
if (num.isZero()) return new
|
|
4457
|
+
if (num.isZero()) return new BN4(1).toRed(this);
|
|
4459
4458
|
if (num.cmpn(1) === 0) return a.clone();
|
|
4460
4459
|
var windowSize = 4;
|
|
4461
4460
|
var wnd = new Array(1 << windowSize);
|
|
4462
|
-
wnd[0] = new
|
|
4461
|
+
wnd[0] = new BN4(1).toRed(this);
|
|
4463
4462
|
wnd[1] = a;
|
|
4464
4463
|
for (var i = 2; i < wnd.length; i++) {
|
|
4465
4464
|
wnd[i] = this.mul(wnd[i - 1], a);
|
|
@@ -4503,7 +4502,7 @@ var require_bn = __commonJS({
|
|
|
4503
4502
|
res.red = null;
|
|
4504
4503
|
return res;
|
|
4505
4504
|
};
|
|
4506
|
-
|
|
4505
|
+
BN4.mont = function mont(num) {
|
|
4507
4506
|
return new Mont(num);
|
|
4508
4507
|
};
|
|
4509
4508
|
function Mont(m) {
|
|
@@ -4512,7 +4511,7 @@ var require_bn = __commonJS({
|
|
|
4512
4511
|
if (this.shift % 26 !== 0) {
|
|
4513
4512
|
this.shift += 26 - this.shift % 26;
|
|
4514
4513
|
}
|
|
4515
|
-
this.r = new
|
|
4514
|
+
this.r = new BN4(1).iushln(this.shift);
|
|
4516
4515
|
this.r2 = this.imod(this.r.sqr());
|
|
4517
4516
|
this.rinv = this.r._invmp(this.m);
|
|
4518
4517
|
this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
|
|
@@ -4546,7 +4545,7 @@ var require_bn = __commonJS({
|
|
|
4546
4545
|
return res._forceRed(this);
|
|
4547
4546
|
};
|
|
4548
4547
|
Mont.prototype.mul = function mul(a, b) {
|
|
4549
|
-
if (a.isZero() || b.isZero()) return new
|
|
4548
|
+
if (a.isZero() || b.isZero()) return new BN4(0)._forceRed(this);
|
|
4550
4549
|
var t = a.mul(b);
|
|
4551
4550
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
4552
4551
|
var u = t.isub(c).iushrn(this.shift);
|
|
@@ -4571,427 +4570,7 @@ init_cjs_shims();
|
|
|
4571
4570
|
|
|
4572
4571
|
// src/client.ts
|
|
4573
4572
|
init_cjs_shims();
|
|
4574
|
-
|
|
4575
|
-
// src/adapters/crowdfunding.ts
|
|
4576
|
-
init_cjs_shims();
|
|
4577
|
-
var import_bn = __toESM(require_bn());
|
|
4578
|
-
|
|
4579
|
-
// src/adapters/base.ts
|
|
4580
|
-
init_cjs_shims();
|
|
4581
|
-
var BaseBondAdapter = class {
|
|
4582
|
-
program;
|
|
4583
|
-
client;
|
|
4584
|
-
constructor(client) {
|
|
4585
|
-
this.client = client;
|
|
4586
|
-
this.program = client.program;
|
|
4587
|
-
}
|
|
4588
|
-
lamports(n) {
|
|
4589
|
-
return new anchor.BN((n ?? 0) * web3_js.LAMPORTS_PER_SOL);
|
|
4590
|
-
}
|
|
4591
|
-
get pda() {
|
|
4592
|
-
return this.client.pda;
|
|
4593
|
-
}
|
|
4594
|
-
get connection() {
|
|
4595
|
-
return this.client.provider.connection;
|
|
4596
|
-
}
|
|
4597
|
-
};
|
|
4598
|
-
|
|
4599
|
-
// src/adapters/crowdfunding.ts
|
|
4600
|
-
var CrowdfundingBondAdapter = class extends BaseBondAdapter {
|
|
4601
|
-
async buildInitializeIx(props) {
|
|
4602
|
-
const [globalState] = this.pda.globalState();
|
|
4603
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4604
|
-
const accounts = {
|
|
4605
|
-
globalState,
|
|
4606
|
-
bondState,
|
|
4607
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey,
|
|
4608
|
-
reserve: props.reserve,
|
|
4609
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4610
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
4611
|
-
reserveTokenAccount: null,
|
|
4612
|
-
mint: null
|
|
4613
|
-
};
|
|
4614
|
-
if ("token" in props.collateralType) {
|
|
4615
|
-
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
4616
|
-
props.collateralType.token[0],
|
|
4617
|
-
props.reserve
|
|
4618
|
-
);
|
|
4619
|
-
accounts.mint = props.collateralType.token[0];
|
|
4620
|
-
}
|
|
4621
|
-
return this.program.methods.bondInitialize({
|
|
4622
|
-
name: props.name,
|
|
4623
|
-
bondType: props.bondType,
|
|
4624
|
-
reserve: props.reserve,
|
|
4625
|
-
collateralType: props.collateralType
|
|
4626
|
-
}).accountsPartial(
|
|
4627
|
-
accounts
|
|
4628
|
-
).instruction();
|
|
4629
|
-
}
|
|
4630
|
-
async buildConfigureIx(props) {
|
|
4631
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4632
|
-
return this.program.methods.bondConfigure({
|
|
4633
|
-
newReserve: props.newReserve ?? null,
|
|
4634
|
-
newAuthority: props.newAuthority ?? null
|
|
4635
|
-
}).accountsStrict({
|
|
4636
|
-
bondState,
|
|
4637
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey
|
|
4638
|
-
}).instruction();
|
|
4639
|
-
}
|
|
4640
|
-
async buildRegisterIx(props) {
|
|
4641
|
-
const { bondType, voteAccount, identity, name } = props;
|
|
4642
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4643
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4644
|
-
const creator = props.creator ?? this.program.provider.wallet?.publicKey;
|
|
4645
|
-
if (!creator) {
|
|
4646
|
-
throw new Error("Missing creator");
|
|
4647
|
-
}
|
|
4648
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4649
|
-
const acct = {
|
|
4650
|
-
bondState,
|
|
4651
|
-
validatorBond,
|
|
4652
|
-
identity,
|
|
4653
|
-
voteAccount,
|
|
4654
|
-
creator,
|
|
4655
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4656
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
4657
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
4658
|
-
bondTokenAccount: null,
|
|
4659
|
-
mint: null
|
|
4660
|
-
};
|
|
4661
|
-
if ("token" in collateralType) {
|
|
4662
|
-
const mint = collateralType.token[0];
|
|
4663
|
-
const bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4664
|
-
Object.assign(acct, { mint, bondTokenAccount });
|
|
4665
|
-
}
|
|
4666
|
-
return this.program.methods.bondRegister(bondType, name).accountsPartial(acct).instruction();
|
|
4667
|
-
}
|
|
4668
|
-
async buildTopUpIx(props) {
|
|
4669
|
-
const { bondType, voteAccount, collateral, name } = props;
|
|
4670
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4671
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4672
|
-
const payer = props.payer ?? this.program.provider.wallet?.publicKey;
|
|
4673
|
-
if (!payer) {
|
|
4674
|
-
throw new Error("Missing payer");
|
|
4675
|
-
}
|
|
4676
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4677
|
-
const accounts = {
|
|
4678
|
-
bondState,
|
|
4679
|
-
validatorBond,
|
|
4680
|
-
payer,
|
|
4681
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4682
|
-
payerTokenAccount: null,
|
|
4683
|
-
bondTokenAccount: null,
|
|
4684
|
-
stakeAccount: null,
|
|
4685
|
-
tokenProgram: null,
|
|
4686
|
-
associatedTokenProgram: null,
|
|
4687
|
-
stakeProgram: null
|
|
4688
|
-
};
|
|
4689
|
-
if ("token" in collateralType) {
|
|
4690
|
-
const mint = collateralType.token[0];
|
|
4691
|
-
accounts.payerTokenAccount = splToken.getAssociatedTokenAddressSync(mint, payer);
|
|
4692
|
-
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4693
|
-
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
4694
|
-
accounts.associatedTokenProgram = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
4695
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4696
|
-
if (!collateral.stakeAccount) {
|
|
4697
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4698
|
-
}
|
|
4699
|
-
accounts.stakeAccount = collateral.stakeAccount;
|
|
4700
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
4701
|
-
}
|
|
4702
|
-
return this.program.methods.bondTopUp(this.lamports(collateral.amount)).accountsPartial(accounts).instruction();
|
|
4703
|
-
}
|
|
4704
|
-
async buildWithdrawIx(props) {
|
|
4705
|
-
const { bondType, voteAccount, withdraw, name } = props;
|
|
4706
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4707
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4708
|
-
const payer = this.program.provider.wallet?.publicKey;
|
|
4709
|
-
const destination = props.destination ?? payer;
|
|
4710
|
-
if (!payer || !destination) {
|
|
4711
|
-
throw new Error("Missing payer/destination");
|
|
4712
|
-
}
|
|
4713
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4714
|
-
const accounts = {
|
|
4715
|
-
bondState,
|
|
4716
|
-
validatorBond,
|
|
4717
|
-
withdrawalAuthority: props.withdrawalAuthority ?? payer,
|
|
4718
|
-
destination,
|
|
4719
|
-
destinationTokenAccount: null,
|
|
4720
|
-
bondTokenAccount: null,
|
|
4721
|
-
stakeAccount: null,
|
|
4722
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4723
|
-
tokenProgram: null,
|
|
4724
|
-
stakeProgram: null
|
|
4725
|
-
};
|
|
4726
|
-
if ("token" in collateralType) {
|
|
4727
|
-
const mint = collateralType.token[0];
|
|
4728
|
-
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, destination, true);
|
|
4729
|
-
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4730
|
-
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
4731
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4732
|
-
if (!withdraw.stakeAccount) {
|
|
4733
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4734
|
-
}
|
|
4735
|
-
accounts.stakeAccount = withdraw.stakeAccount;
|
|
4736
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
4737
|
-
}
|
|
4738
|
-
return this.program.methods.bondWithdraw(this.lamports(withdraw.amount)).accountsPartial(accounts).instruction();
|
|
4739
|
-
}
|
|
4740
|
-
async buildClaimIx(props) {
|
|
4741
|
-
const { claim, bondType, name } = props;
|
|
4742
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4743
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
4744
|
-
const reserve = props.reserve ?? (await this.client.getBondState(bondType, name)).reserve;
|
|
4745
|
-
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
4746
|
-
if (!reserve) {
|
|
4747
|
-
throw new Error("Reserve not set");
|
|
4748
|
-
}
|
|
4749
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4750
|
-
const accounts = {
|
|
4751
|
-
bondState,
|
|
4752
|
-
validatorBond,
|
|
4753
|
-
reserve,
|
|
4754
|
-
reserveTokenAccount: null,
|
|
4755
|
-
authority,
|
|
4756
|
-
bondTokenAccount: null,
|
|
4757
|
-
stakeAccount: null,
|
|
4758
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4759
|
-
tokenProgram: null,
|
|
4760
|
-
stakeProgram: null
|
|
4761
|
-
};
|
|
4762
|
-
if ("token" in collateralType) {
|
|
4763
|
-
const mint = collateralType.token[0];
|
|
4764
|
-
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
4765
|
-
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4766
|
-
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
4767
|
-
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
4768
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4769
|
-
if (!claim.stakeAccount) {
|
|
4770
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4771
|
-
}
|
|
4772
|
-
accounts.stakeAccount = claim.stakeAccount;
|
|
4773
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
4774
|
-
}
|
|
4775
|
-
return this.program.methods.bondClaim(this.lamports(props.claim.amount)).accountsPartial(
|
|
4776
|
-
accounts
|
|
4777
|
-
).instruction();
|
|
4778
|
-
}
|
|
4779
|
-
async buildSetWithdrawAuthorityIx(props) {
|
|
4780
|
-
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
4781
|
-
return this.program.methods.bondSetWithdrawAuthority().accountsPartial({
|
|
4782
|
-
validatorBond,
|
|
4783
|
-
identity: props.identity ?? this.program.provider.wallet?.publicKey,
|
|
4784
|
-
newWithdrawAuthority: props.newWithdrawAuthority ?? null
|
|
4785
|
-
}).instruction();
|
|
4786
|
-
}
|
|
4787
|
-
async buildBondFinishIx(_props) {
|
|
4788
|
-
throw new Error("Crowdfunding bond currently does not support finish operation");
|
|
4789
|
-
}
|
|
4790
|
-
async buildBondStartIx(props) {
|
|
4791
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4792
|
-
return this.program.methods.sessionStart(new import_bn.BN(props.duration_secs)).accountsPartial({
|
|
4793
|
-
bondState,
|
|
4794
|
-
authority: this.program.provider.wallet?.publicKey
|
|
4795
|
-
}).instruction();
|
|
4796
|
-
}
|
|
4797
|
-
};
|
|
4798
|
-
|
|
4799
|
-
// src/adapters/performance.ts
|
|
4800
|
-
init_cjs_shims();
|
|
4801
|
-
var PerformanceBondAdapter = class extends BaseBondAdapter {
|
|
4802
|
-
async buildInitializeIx(props) {
|
|
4803
|
-
const [globalState] = this.pda.globalState();
|
|
4804
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4805
|
-
const accounts = {
|
|
4806
|
-
globalState,
|
|
4807
|
-
bondState,
|
|
4808
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey,
|
|
4809
|
-
reserve: props.reserve,
|
|
4810
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4811
|
-
tokenProgram: token.TOKEN_PROGRAM_ID,
|
|
4812
|
-
reserveTokenAccount: null,
|
|
4813
|
-
mint: null
|
|
4814
|
-
};
|
|
4815
|
-
if ("token" in props.collateralType) {
|
|
4816
|
-
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
4817
|
-
props.collateralType.token[0],
|
|
4818
|
-
props.reserve
|
|
4819
|
-
);
|
|
4820
|
-
accounts.mint = props.collateralType.token[0];
|
|
4821
|
-
}
|
|
4822
|
-
return this.program.methods.bondInitialize({
|
|
4823
|
-
name: props.name,
|
|
4824
|
-
bondType: props.bondType,
|
|
4825
|
-
reserve: props.reserve,
|
|
4826
|
-
collateralType: props.collateralType
|
|
4827
|
-
}).accountsPartial(
|
|
4828
|
-
accounts
|
|
4829
|
-
).instruction();
|
|
4830
|
-
}
|
|
4831
|
-
async buildConfigureIx(props) {
|
|
4832
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4833
|
-
return this.program.methods.bondConfigure({
|
|
4834
|
-
newReserve: props.newReserve ?? null,
|
|
4835
|
-
newAuthority: props.newAuthority ?? null
|
|
4836
|
-
}).accountsStrict({
|
|
4837
|
-
bondState,
|
|
4838
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey
|
|
4839
|
-
}).instruction();
|
|
4840
|
-
}
|
|
4841
|
-
async buildRegisterIx(props) {
|
|
4842
|
-
const { bondType, voteAccount, identity, name } = props;
|
|
4843
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4844
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4845
|
-
const creator = props.creator ?? this.program.provider.wallet?.publicKey;
|
|
4846
|
-
if (!creator) {
|
|
4847
|
-
throw new Error("Missing creator");
|
|
4848
|
-
}
|
|
4849
|
-
const bondStateData = await this.client.getBondState(bondType, name);
|
|
4850
|
-
const acct = {
|
|
4851
|
-
bondState,
|
|
4852
|
-
validatorBond,
|
|
4853
|
-
identity,
|
|
4854
|
-
voteAccount,
|
|
4855
|
-
creator,
|
|
4856
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4857
|
-
tokenProgram: token.TOKEN_PROGRAM_ID,
|
|
4858
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
4859
|
-
bondTokenAccount: null,
|
|
4860
|
-
mint: null
|
|
4861
|
-
};
|
|
4862
|
-
if ("token" in bondStateData.collateralType) {
|
|
4863
|
-
const mint = bondStateData.collateralType.token[0];
|
|
4864
|
-
const bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4865
|
-
Object.assign(acct, { mint, bondTokenAccount });
|
|
4866
|
-
}
|
|
4867
|
-
return this.program.methods.bondRegister(bondType, name).accountsPartial(acct).instruction();
|
|
4868
|
-
}
|
|
4869
|
-
async buildTopUpIx(props) {
|
|
4870
|
-
const { bondType, voteAccount, collateral, name } = props;
|
|
4871
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4872
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4873
|
-
const payer = props.payer ?? this.program.provider.wallet?.publicKey;
|
|
4874
|
-
if (!payer) {
|
|
4875
|
-
throw new Error("Missing payer");
|
|
4876
|
-
}
|
|
4877
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4878
|
-
const accounts = {
|
|
4879
|
-
bondState,
|
|
4880
|
-
validatorBond,
|
|
4881
|
-
payer,
|
|
4882
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4883
|
-
payerTokenAccount: null,
|
|
4884
|
-
bondTokenAccount: null,
|
|
4885
|
-
stakeAccount: null,
|
|
4886
|
-
tokenProgram: null,
|
|
4887
|
-
associatedTokenProgram: null,
|
|
4888
|
-
stakeProgram: null
|
|
4889
|
-
};
|
|
4890
|
-
if ("token" in collateralType) {
|
|
4891
|
-
const mint = collateralType.token[0];
|
|
4892
|
-
accounts.payerTokenAccount = splToken.getAssociatedTokenAddressSync(mint, payer);
|
|
4893
|
-
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4894
|
-
accounts.tokenProgram = token.TOKEN_PROGRAM_ID;
|
|
4895
|
-
accounts.associatedTokenProgram = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
4896
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4897
|
-
if (!collateral.stakeAccount) {
|
|
4898
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4899
|
-
}
|
|
4900
|
-
accounts.stakeAccount = collateral.stakeAccount;
|
|
4901
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
4902
|
-
}
|
|
4903
|
-
return this.program.methods.bondTopUp(this.lamports(collateral.amount)).accountsPartial(accounts).instruction();
|
|
4904
|
-
}
|
|
4905
|
-
async buildWithdrawIx(props) {
|
|
4906
|
-
const { bondType, voteAccount, withdraw, name } = props;
|
|
4907
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4908
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4909
|
-
const payer = this.program.provider.wallet?.publicKey;
|
|
4910
|
-
const destination = props.destination ?? payer;
|
|
4911
|
-
if (!payer || !destination) {
|
|
4912
|
-
throw new Error("Missing payer/destination");
|
|
4913
|
-
}
|
|
4914
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4915
|
-
const accounts = {
|
|
4916
|
-
bondState,
|
|
4917
|
-
validatorBond,
|
|
4918
|
-
withdrawalAuthority: props.withdrawalAuthority ?? payer,
|
|
4919
|
-
destination,
|
|
4920
|
-
destinationTokenAccount: null,
|
|
4921
|
-
bondTokenAccount: null,
|
|
4922
|
-
stakeAccount: null,
|
|
4923
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4924
|
-
tokenProgram: null,
|
|
4925
|
-
stakeProgram: null
|
|
4926
|
-
};
|
|
4927
|
-
if ("token" in collateralType) {
|
|
4928
|
-
const mint = collateralType.token[0];
|
|
4929
|
-
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, destination, true);
|
|
4930
|
-
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4931
|
-
accounts.tokenProgram = token.TOKEN_PROGRAM_ID;
|
|
4932
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4933
|
-
if (!withdraw.stakeAccount) {
|
|
4934
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4935
|
-
}
|
|
4936
|
-
accounts.stakeAccount = withdraw.stakeAccount;
|
|
4937
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
4938
|
-
}
|
|
4939
|
-
return this.program.methods.bondWithdraw(this.lamports(withdraw.amount)).accountsPartial(accounts).instruction();
|
|
4940
|
-
}
|
|
4941
|
-
async buildClaimIx(props) {
|
|
4942
|
-
const { claim, bondType, name } = props;
|
|
4943
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4944
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
4945
|
-
const reserve = props.reserve ?? (await this.client.getBondState(bondType, name)).reserve;
|
|
4946
|
-
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
4947
|
-
if (!reserve) {
|
|
4948
|
-
throw new Error("Reserve not set");
|
|
4949
|
-
}
|
|
4950
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4951
|
-
const accounts = {
|
|
4952
|
-
bondState,
|
|
4953
|
-
validatorBond,
|
|
4954
|
-
reserve,
|
|
4955
|
-
reserveTokenAccount: null,
|
|
4956
|
-
authority,
|
|
4957
|
-
bondTokenAccount: null,
|
|
4958
|
-
stakeAccount: null,
|
|
4959
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
4960
|
-
tokenProgram: null,
|
|
4961
|
-
stakeProgram: null
|
|
4962
|
-
};
|
|
4963
|
-
if ("token" in collateralType) {
|
|
4964
|
-
const mint = collateralType.token[0];
|
|
4965
|
-
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
4966
|
-
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4967
|
-
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
4968
|
-
accounts.tokenProgram = token.TOKEN_PROGRAM_ID;
|
|
4969
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4970
|
-
if (!claim.stakeAccount) {
|
|
4971
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4972
|
-
}
|
|
4973
|
-
accounts.stakeAccount = claim.stakeAccount;
|
|
4974
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
4975
|
-
}
|
|
4976
|
-
return this.program.methods.bondClaim(this.lamports(props.claim.amount)).accountsPartial(
|
|
4977
|
-
accounts
|
|
4978
|
-
).instruction();
|
|
4979
|
-
}
|
|
4980
|
-
async buildSetWithdrawAuthorityIx(props) {
|
|
4981
|
-
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
4982
|
-
return this.program.methods.bondSetWithdrawAuthority().accountsPartial({
|
|
4983
|
-
validatorBond,
|
|
4984
|
-
identity: props.identity ?? this.program.provider.wallet?.publicKey,
|
|
4985
|
-
newWithdrawAuthority: props.newWithdrawAuthority ?? null
|
|
4986
|
-
}).instruction();
|
|
4987
|
-
}
|
|
4988
|
-
async buildBondFinishIx(_props) {
|
|
4989
|
-
throw new Error("Performance bond currently does not support finish operation");
|
|
4990
|
-
}
|
|
4991
|
-
async buildBondStartIx(_props) {
|
|
4992
|
-
throw new Error("Performance bond currently does not support start operation");
|
|
4993
|
-
}
|
|
4994
|
-
};
|
|
4573
|
+
var import_bn2 = __toESM(require_bn());
|
|
4995
4574
|
|
|
4996
4575
|
// src/constants.ts
|
|
4997
4576
|
init_cjs_shims();
|
|
@@ -6723,7 +6302,7 @@ var jbond_default = {
|
|
|
6723
6302
|
|
|
6724
6303
|
// src/utils/stake-pool.ts
|
|
6725
6304
|
init_cjs_shims();
|
|
6726
|
-
var
|
|
6305
|
+
var import_bn = __toESM(require_bn());
|
|
6727
6306
|
function createStakePoolManager(stakePoolAccount, user) {
|
|
6728
6307
|
if (!stakePoolAccount || !stakePoolAccount.account || !stakePoolAccount.account.data) {
|
|
6729
6308
|
throw new Error("Invalid stake pool account structure");
|
|
@@ -6759,8 +6338,8 @@ function createStakePoolManager(stakePoolAccount, user) {
|
|
|
6759
6338
|
poolTokens: poolTokens.toNumber()
|
|
6760
6339
|
}),
|
|
6761
6340
|
get exchangeRate() {
|
|
6762
|
-
const poolTokenSupply = new
|
|
6763
|
-
const totalLamports = new
|
|
6341
|
+
const poolTokenSupply = new import_bn.default(stakePool.poolTokenSupply);
|
|
6342
|
+
const totalLamports = new import_bn.default(stakePool.totalLamports);
|
|
6764
6343
|
if (poolTokenSupply.isZero()) {
|
|
6765
6344
|
return 0;
|
|
6766
6345
|
}
|
|
@@ -6833,15 +6412,6 @@ var JBondClient = class _JBondClient {
|
|
|
6833
6412
|
this.options[key] = val;
|
|
6834
6413
|
return this;
|
|
6835
6414
|
}
|
|
6836
|
-
getAdapter(bondType) {
|
|
6837
|
-
if ("performance" in bondType) {
|
|
6838
|
-
return new PerformanceBondAdapter(this);
|
|
6839
|
-
}
|
|
6840
|
-
if ("crowdfunding" in bondType) {
|
|
6841
|
-
return new CrowdfundingBondAdapter(this);
|
|
6842
|
-
}
|
|
6843
|
-
throw new Error(`Unsupported bond type: ${JSON.stringify(bondType)}`);
|
|
6844
|
-
}
|
|
6845
6415
|
getBondTypeSeed(bondType) {
|
|
6846
6416
|
if ("performance" in bondType) {
|
|
6847
6417
|
return "performance" /* PerformanceBond */;
|
|
@@ -6882,7 +6452,7 @@ var JBondClient = class _JBondClient {
|
|
|
6882
6452
|
}
|
|
6883
6453
|
};
|
|
6884
6454
|
async globalInitialize(props) {
|
|
6885
|
-
const ix = await this.
|
|
6455
|
+
const ix = await this.buildBondGlobalStateInitializeIx(props);
|
|
6886
6456
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6887
6457
|
}
|
|
6888
6458
|
/**
|
|
@@ -6891,7 +6461,7 @@ var JBondClient = class _JBondClient {
|
|
|
6891
6461
|
*/
|
|
6892
6462
|
async bondInitialize(props) {
|
|
6893
6463
|
console.log("Building bond initialize instruction with props:", props);
|
|
6894
|
-
const ix = await this.
|
|
6464
|
+
const ix = await this.buildBondInitializeIx(props);
|
|
6895
6465
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6896
6466
|
}
|
|
6897
6467
|
/**
|
|
@@ -6899,7 +6469,7 @@ var JBondClient = class _JBondClient {
|
|
|
6899
6469
|
* Default creator is the provider's wallet
|
|
6900
6470
|
*/
|
|
6901
6471
|
async registerValidator(props) {
|
|
6902
|
-
const ix = await this.
|
|
6472
|
+
const ix = await this.buildRegisterIx(props);
|
|
6903
6473
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6904
6474
|
}
|
|
6905
6475
|
/**
|
|
@@ -6907,8 +6477,8 @@ var JBondClient = class _JBondClient {
|
|
|
6907
6477
|
* Default payer is the provider's wallet
|
|
6908
6478
|
*/
|
|
6909
6479
|
async topUpCollateral(props) {
|
|
6910
|
-
const
|
|
6911
|
-
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(
|
|
6480
|
+
const ixs = await this.buildTopUpIXs(props);
|
|
6481
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(...ixs));
|
|
6912
6482
|
}
|
|
6913
6483
|
/**
|
|
6914
6484
|
* Withdraw collateral
|
|
@@ -6917,7 +6487,7 @@ var JBondClient = class _JBondClient {
|
|
|
6917
6487
|
* @return Transaction signature
|
|
6918
6488
|
*/
|
|
6919
6489
|
async withdrawCollateral(props) {
|
|
6920
|
-
const ix = await this.
|
|
6490
|
+
const ix = await this.buildWithdrawIx(props);
|
|
6921
6491
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6922
6492
|
}
|
|
6923
6493
|
/**
|
|
@@ -6926,7 +6496,7 @@ var JBondClient = class _JBondClient {
|
|
|
6926
6496
|
* @return Transaction signature
|
|
6927
6497
|
*/
|
|
6928
6498
|
async claimCompensation(props) {
|
|
6929
|
-
const ix = await this.
|
|
6499
|
+
const ix = await this.buildClaimIx(props);
|
|
6930
6500
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6931
6501
|
}
|
|
6932
6502
|
/**
|
|
@@ -6946,7 +6516,7 @@ var JBondClient = class _JBondClient {
|
|
|
6946
6516
|
* @return Transaction signature
|
|
6947
6517
|
*/
|
|
6948
6518
|
async bondConfigure(props) {
|
|
6949
|
-
const ix = await this.
|
|
6519
|
+
const ix = await this.buildConfigureIx(props);
|
|
6950
6520
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6951
6521
|
}
|
|
6952
6522
|
/**
|
|
@@ -6956,18 +6526,18 @@ var JBondClient = class _JBondClient {
|
|
|
6956
6526
|
* @return Transaction signature
|
|
6957
6527
|
*/
|
|
6958
6528
|
async setWithdrawAuthority(props) {
|
|
6959
|
-
const ix = await this.
|
|
6529
|
+
const ix = await this.buildSetWithdrawAuthorityIx(props);
|
|
6960
6530
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6961
6531
|
}
|
|
6962
6532
|
async bondStart(props) {
|
|
6963
|
-
const ix = await this.
|
|
6533
|
+
const ix = await this.buildBondStartIx(props);
|
|
6964
6534
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6965
6535
|
}
|
|
6966
6536
|
async bondFinish(props) {
|
|
6967
|
-
const ix = await this.
|
|
6537
|
+
const ix = await this.buildBondFinishIx(props);
|
|
6968
6538
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6969
6539
|
}
|
|
6970
|
-
async
|
|
6540
|
+
async buildBondGlobalStateInitializeIx(props) {
|
|
6971
6541
|
const [globalState] = this.pda.globalState();
|
|
6972
6542
|
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
6973
6543
|
return this.program.methods.globalInitialize().accountsPartial({
|
|
@@ -6991,50 +6561,214 @@ var JBondClient = class _JBondClient {
|
|
|
6991
6561
|
/**
|
|
6992
6562
|
* Build initialize instruction
|
|
6993
6563
|
*/
|
|
6994
|
-
async
|
|
6995
|
-
|
|
6564
|
+
async buildBondInitializeIx(props) {
|
|
6565
|
+
const [globalState] = this.pda.globalState();
|
|
6566
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6567
|
+
const accounts = {
|
|
6568
|
+
globalState,
|
|
6569
|
+
bondState,
|
|
6570
|
+
authority: props.authority ?? this.program.provider.wallet?.publicKey,
|
|
6571
|
+
reserve: props.reserve,
|
|
6572
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
6573
|
+
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
6574
|
+
reserveTokenAccount: null,
|
|
6575
|
+
mint: null
|
|
6576
|
+
};
|
|
6577
|
+
if ("token" in props.collateralType) {
|
|
6578
|
+
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
6579
|
+
props.collateralType.token[0],
|
|
6580
|
+
props.reserve
|
|
6581
|
+
);
|
|
6582
|
+
accounts.mint = props.collateralType.token[0];
|
|
6583
|
+
}
|
|
6584
|
+
return this.program.methods.bondInitialize({
|
|
6585
|
+
name: props.name,
|
|
6586
|
+
bondType: props.bondType,
|
|
6587
|
+
reserve: props.reserve,
|
|
6588
|
+
collateralType: props.collateralType
|
|
6589
|
+
}).accountsPartial(
|
|
6590
|
+
accounts
|
|
6591
|
+
).instruction();
|
|
6996
6592
|
}
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
6593
|
+
async buildConfigureIx(props) {
|
|
6594
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6595
|
+
return this.program.methods.bondConfigure({
|
|
6596
|
+
newReserve: props.newReserve ?? null,
|
|
6597
|
+
newAuthority: props.newAuthority ?? null
|
|
6598
|
+
}).accountsStrict({
|
|
6599
|
+
bondState,
|
|
6600
|
+
authority: props.authority ?? this.program.provider.wallet?.publicKey
|
|
6601
|
+
}).instruction();
|
|
7002
6602
|
}
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
6603
|
+
async buildRegisterIx(props) {
|
|
6604
|
+
const { bondType, voteAccount, identity, name } = props;
|
|
6605
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
6606
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6607
|
+
const creator = props.creator ?? this.program.provider.wallet?.publicKey;
|
|
6608
|
+
if (!creator) {
|
|
6609
|
+
throw new Error("Missing creator");
|
|
6610
|
+
}
|
|
6611
|
+
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6612
|
+
const acct = {
|
|
6613
|
+
bondState,
|
|
6614
|
+
validatorBond,
|
|
6615
|
+
identity,
|
|
6616
|
+
voteAccount,
|
|
6617
|
+
creator,
|
|
6618
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
6619
|
+
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
6620
|
+
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
6621
|
+
bondTokenAccount: null,
|
|
6622
|
+
mint: null
|
|
6623
|
+
};
|
|
6624
|
+
if ("token" in collateralType) {
|
|
6625
|
+
const mint = collateralType.token[0];
|
|
6626
|
+
const bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6627
|
+
Object.assign(acct, { mint, bondTokenAccount });
|
|
6628
|
+
}
|
|
6629
|
+
return this.program.methods.bondRegister(bondType, name).accountsPartial(acct).instruction();
|
|
7008
6630
|
}
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
6631
|
+
async buildTopUpIXs(props) {
|
|
6632
|
+
const { bondType, voteAccount, collateral, name } = props;
|
|
6633
|
+
const payer = props.payer ?? this.program.provider.wallet?.publicKey;
|
|
6634
|
+
if (!payer) {
|
|
6635
|
+
throw new Error("Missing payer");
|
|
6636
|
+
}
|
|
6637
|
+
const instructions = [];
|
|
6638
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
6639
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6640
|
+
const bond = await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
|
|
6641
|
+
if (!bond) {
|
|
6642
|
+
instructions.push(await this.buildRegisterIx({
|
|
6643
|
+
bondType: props.bondType,
|
|
6644
|
+
name: props.name,
|
|
6645
|
+
voteAccount: props.voteAccount,
|
|
6646
|
+
identity: props.identity
|
|
6647
|
+
}));
|
|
6648
|
+
}
|
|
6649
|
+
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6650
|
+
const accounts = {
|
|
6651
|
+
bondState,
|
|
6652
|
+
validatorBond,
|
|
6653
|
+
payer,
|
|
6654
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
6655
|
+
payerTokenAccount: null,
|
|
6656
|
+
bondTokenAccount: null,
|
|
6657
|
+
stakeAccount: null,
|
|
6658
|
+
tokenProgram: null,
|
|
6659
|
+
associatedTokenProgram: null,
|
|
6660
|
+
stakeProgram: null
|
|
6661
|
+
};
|
|
6662
|
+
if ("token" in collateralType) {
|
|
6663
|
+
const mint = collateralType.token[0];
|
|
6664
|
+
accounts.payerTokenAccount = splToken.getAssociatedTokenAddressSync(mint, payer);
|
|
6665
|
+
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6666
|
+
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6667
|
+
accounts.associatedTokenProgram = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
6668
|
+
} else if ("stakeAccount" in collateralType) {
|
|
6669
|
+
if (!collateral.stakeAccount) {
|
|
6670
|
+
throw new Error("Missing stakeAccount for stake collateral");
|
|
6671
|
+
}
|
|
6672
|
+
accounts.stakeAccount = collateral.stakeAccount;
|
|
6673
|
+
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
6674
|
+
}
|
|
6675
|
+
instructions.push(
|
|
6676
|
+
await this.program.methods.bondTopUp(this.lamports(collateral.amount)).accountsPartial(accounts).instruction()
|
|
6677
|
+
);
|
|
6678
|
+
return instructions;
|
|
7014
6679
|
}
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
6680
|
+
async buildWithdrawIx(props) {
|
|
6681
|
+
const { bondType, voteAccount, withdraw, name } = props;
|
|
6682
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
6683
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6684
|
+
const payer = this.program.provider.wallet?.publicKey;
|
|
6685
|
+
const destination = props.destination ?? payer;
|
|
6686
|
+
if (!payer || !destination) {
|
|
6687
|
+
throw new Error("Missing payer/destination");
|
|
6688
|
+
}
|
|
6689
|
+
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6690
|
+
const accounts = {
|
|
6691
|
+
bondState,
|
|
6692
|
+
validatorBond,
|
|
6693
|
+
withdrawalAuthority: props.withdrawalAuthority ?? payer,
|
|
6694
|
+
destination,
|
|
6695
|
+
destinationTokenAccount: null,
|
|
6696
|
+
bondTokenAccount: null,
|
|
6697
|
+
stakeAccount: null,
|
|
6698
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
6699
|
+
tokenProgram: null,
|
|
6700
|
+
stakeProgram: null
|
|
6701
|
+
};
|
|
6702
|
+
if ("token" in collateralType) {
|
|
6703
|
+
const mint = collateralType.token[0];
|
|
6704
|
+
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, destination, true);
|
|
6705
|
+
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6706
|
+
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6707
|
+
} else if ("stakeAccount" in collateralType) {
|
|
6708
|
+
if (!withdraw.stakeAccount) {
|
|
6709
|
+
throw new Error("Missing stakeAccount for stake collateral");
|
|
6710
|
+
}
|
|
6711
|
+
accounts.stakeAccount = withdraw.stakeAccount;
|
|
6712
|
+
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
6713
|
+
}
|
|
6714
|
+
return this.program.methods.bondWithdraw(this.lamports(withdraw.amount)).accountsPartial(accounts).instruction();
|
|
7020
6715
|
}
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
6716
|
+
async buildClaimIx(props) {
|
|
6717
|
+
const { claim, bondType, name } = props;
|
|
6718
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
6719
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
6720
|
+
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).reserve;
|
|
6721
|
+
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
6722
|
+
if (!reserve) {
|
|
6723
|
+
throw new Error("Reserve not set");
|
|
6724
|
+
}
|
|
6725
|
+
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6726
|
+
const accounts = {
|
|
6727
|
+
bondState,
|
|
6728
|
+
validatorBond,
|
|
6729
|
+
reserve,
|
|
6730
|
+
reserveTokenAccount: null,
|
|
6731
|
+
authority,
|
|
6732
|
+
bondTokenAccount: null,
|
|
6733
|
+
stakeAccount: null,
|
|
6734
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
6735
|
+
tokenProgram: null,
|
|
6736
|
+
stakeProgram: null
|
|
6737
|
+
};
|
|
6738
|
+
if ("token" in collateralType) {
|
|
6739
|
+
const mint = collateralType.token[0];
|
|
6740
|
+
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6741
|
+
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6742
|
+
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6743
|
+
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6744
|
+
} else if ("stakeAccount" in collateralType) {
|
|
6745
|
+
if (!claim.stakeAccount) {
|
|
6746
|
+
throw new Error("Missing stakeAccount for stake collateral");
|
|
6747
|
+
}
|
|
6748
|
+
accounts.stakeAccount = claim.stakeAccount;
|
|
6749
|
+
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
6750
|
+
}
|
|
6751
|
+
return this.program.methods.bondClaim(this.lamports(props.claim.amount)).accountsPartial(
|
|
6752
|
+
accounts
|
|
6753
|
+
).instruction();
|
|
7026
6754
|
}
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
6755
|
+
async buildSetWithdrawAuthorityIx(props) {
|
|
6756
|
+
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
6757
|
+
return this.program.methods.bondSetWithdrawAuthority().accountsPartial({
|
|
6758
|
+
validatorBond,
|
|
6759
|
+
identity: props.identity ?? this.program.provider.wallet?.publicKey,
|
|
6760
|
+
newWithdrawAuthority: props.newWithdrawAuthority ?? null
|
|
6761
|
+
}).instruction();
|
|
7032
6762
|
}
|
|
7033
|
-
|
|
7034
|
-
|
|
6763
|
+
async buildBondFinishIx(_props) {
|
|
6764
|
+
throw new Error("Crowdfunding bond currently does not support finish operation");
|
|
7035
6765
|
}
|
|
7036
|
-
|
|
7037
|
-
|
|
6766
|
+
async buildBondStartIx(props) {
|
|
6767
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6768
|
+
return this.program.methods.sessionStart(new import_bn2.BN(props.duration_secs)).accountsPartial({
|
|
6769
|
+
bondState,
|
|
6770
|
+
authority: this.program.provider.wallet?.publicKey
|
|
6771
|
+
}).instruction();
|
|
7038
6772
|
}
|
|
7039
6773
|
/**
|
|
7040
6774
|
* Fetch global state or throw if not found
|
|
@@ -7047,23 +6781,42 @@ var JBondClient = class _JBondClient {
|
|
|
7047
6781
|
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
7048
6782
|
return await this.program.account.bondState.fetch(bondState);
|
|
7049
6783
|
}
|
|
7050
|
-
|
|
6784
|
+
/**
|
|
6785
|
+
* Get all bond states with total collected collateral
|
|
6786
|
+
*/
|
|
7051
6787
|
async getAllBondStates(_bondType) {
|
|
7052
6788
|
const bondStates = [];
|
|
7053
6789
|
const bondStateAccounts = await this.program.account.bondState.all();
|
|
7054
|
-
for (const { account } of bondStateAccounts) {
|
|
7055
|
-
|
|
6790
|
+
for (const { account: state } of bondStateAccounts) {
|
|
6791
|
+
if (!("crowdfunding" in state.bondType)) {
|
|
6792
|
+
continue;
|
|
6793
|
+
}
|
|
6794
|
+
const validatorBonds = await this.getValidatorBondsByState(state.bondType, state.name);
|
|
6795
|
+
const balances = await Promise.all(
|
|
6796
|
+
validatorBonds.map(
|
|
6797
|
+
(vb) => this.getValidatorBondBalance(state.bondType, state.name, vb.voteAccount).then((v) => v ?? 0)
|
|
6798
|
+
)
|
|
6799
|
+
);
|
|
6800
|
+
const totalCollected = balances.reduce((sum, v) => sum + v, 0);
|
|
6801
|
+
bondStates.push([state, totalCollected]);
|
|
7056
6802
|
}
|
|
7057
6803
|
return bondStates;
|
|
7058
6804
|
}
|
|
7059
|
-
async
|
|
7060
|
-
const
|
|
7061
|
-
const
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
6805
|
+
async getValidatorBondsByState(bondType, bondName) {
|
|
6806
|
+
const validatorBonds = [];
|
|
6807
|
+
const bondStatePda = this.pda.bondState(bondType, bondName)[0];
|
|
6808
|
+
const validatorBondAccounts = await this.program.account.validatorBond.all([
|
|
6809
|
+
{
|
|
6810
|
+
memcmp: {
|
|
6811
|
+
offset: 8,
|
|
6812
|
+
bytes: bondStatePda.toBase58()
|
|
6813
|
+
}
|
|
6814
|
+
}
|
|
6815
|
+
]);
|
|
6816
|
+
for (const { account: vb } of validatorBondAccounts) {
|
|
6817
|
+
validatorBonds.push(vb);
|
|
7066
6818
|
}
|
|
6819
|
+
return validatorBonds;
|
|
7067
6820
|
}
|
|
7068
6821
|
/**
|
|
7069
6822
|
* Fetch validator bond data or null if not found
|
|
@@ -7073,8 +6826,11 @@ var JBondClient = class _JBondClient {
|
|
|
7073
6826
|
*/
|
|
7074
6827
|
async getValidatorBond(bondType, bondName, vote) {
|
|
7075
6828
|
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
7076
|
-
|
|
7077
|
-
|
|
6829
|
+
try {
|
|
6830
|
+
return await this.program.account.validatorBond.fetch(address);
|
|
6831
|
+
} catch {
|
|
6832
|
+
return null;
|
|
6833
|
+
}
|
|
7078
6834
|
}
|
|
7079
6835
|
/**
|
|
7080
6836
|
* Get bond collateral type
|
|
@@ -7100,7 +6856,7 @@ var JBondClient = class _JBondClient {
|
|
|
7100
6856
|
const balance = await this.connection.getTokenAccountBalance(tokenAccount);
|
|
7101
6857
|
return Number(balance.value.uiAmount ?? 0);
|
|
7102
6858
|
}
|
|
7103
|
-
const accountInfo = await this.connection.getAccountInfo(address);
|
|
6859
|
+
const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
|
|
7104
6860
|
if (!accountInfo) {
|
|
7105
6861
|
return 0;
|
|
7106
6862
|
}
|
|
@@ -7136,6 +6892,9 @@ var JBondClient = class _JBondClient {
|
|
|
7136
6892
|
}
|
|
7137
6893
|
return user;
|
|
7138
6894
|
}
|
|
6895
|
+
lamports(n) {
|
|
6896
|
+
return new import_bn2.BN((n ?? 0) * web3_js.LAMPORTS_PER_SOL);
|
|
6897
|
+
}
|
|
7139
6898
|
};
|
|
7140
6899
|
/*! Bundled license information:
|
|
7141
6900
|
|