@jpool/bond-sdk 0.9.0-next.6 → 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 +16 -34
- package/dist/index.d.ts +16 -34
- package/dist/index.js +396 -655
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +399 -649
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Program, AnchorProvider, BN } from '@coral-xyz/anchor';
|
|
2
2
|
import { getStakePoolAccount, STAKE_POOL_PROGRAM_ID, StakePoolInstruction } from '@solana/spl-stake-pool';
|
|
3
|
-
import { getAssociatedTokenAddressSync,
|
|
4
|
-
import { PublicKey, Transaction,
|
|
5
|
-
import { TOKEN_PROGRAM_ID } from '@coral-xyz/anchor/dist/cjs/utils/token';
|
|
3
|
+
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
4
|
+
import { PublicKey, Transaction, SystemProgram, StakeProgram, LAMPORTS_PER_SOL } from '@solana/web3.js';
|
|
6
5
|
import bs58 from 'bs58';
|
|
7
6
|
|
|
8
7
|
var __create = Object.create;
|
|
@@ -1818,8 +1817,8 @@ var require_bn = __commonJS({
|
|
|
1818
1817
|
ctor.prototype = new TempCtor();
|
|
1819
1818
|
ctor.prototype.constructor = ctor;
|
|
1820
1819
|
}
|
|
1821
|
-
function
|
|
1822
|
-
if (
|
|
1820
|
+
function BN4(number, base, endian) {
|
|
1821
|
+
if (BN4.isBN(number)) {
|
|
1823
1822
|
return number;
|
|
1824
1823
|
}
|
|
1825
1824
|
this.negative = 0;
|
|
@@ -1835,12 +1834,12 @@ var require_bn = __commonJS({
|
|
|
1835
1834
|
}
|
|
1836
1835
|
}
|
|
1837
1836
|
if (typeof module2 === "object") {
|
|
1838
|
-
module2.exports =
|
|
1837
|
+
module2.exports = BN4;
|
|
1839
1838
|
} else {
|
|
1840
|
-
exports2.BN =
|
|
1839
|
+
exports2.BN = BN4;
|
|
1841
1840
|
}
|
|
1842
|
-
|
|
1843
|
-
|
|
1841
|
+
BN4.BN = BN4;
|
|
1842
|
+
BN4.wordSize = 26;
|
|
1844
1843
|
var Buffer2;
|
|
1845
1844
|
try {
|
|
1846
1845
|
if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
|
|
@@ -1850,21 +1849,21 @@ var require_bn = __commonJS({
|
|
|
1850
1849
|
}
|
|
1851
1850
|
} catch (e) {
|
|
1852
1851
|
}
|
|
1853
|
-
|
|
1854
|
-
if (num instanceof
|
|
1852
|
+
BN4.isBN = function isBN(num) {
|
|
1853
|
+
if (num instanceof BN4) {
|
|
1855
1854
|
return true;
|
|
1856
1855
|
}
|
|
1857
|
-
return num !== null && typeof num === "object" && num.constructor.wordSize ===
|
|
1856
|
+
return num !== null && typeof num === "object" && num.constructor.wordSize === BN4.wordSize && Array.isArray(num.words);
|
|
1858
1857
|
};
|
|
1859
|
-
|
|
1858
|
+
BN4.max = function max(left, right) {
|
|
1860
1859
|
if (left.cmp(right) > 0) return left;
|
|
1861
1860
|
return right;
|
|
1862
1861
|
};
|
|
1863
|
-
|
|
1862
|
+
BN4.min = function min(left, right) {
|
|
1864
1863
|
if (left.cmp(right) < 0) return left;
|
|
1865
1864
|
return right;
|
|
1866
1865
|
};
|
|
1867
|
-
|
|
1866
|
+
BN4.prototype._init = function init(number, base, endian) {
|
|
1868
1867
|
if (typeof number === "number") {
|
|
1869
1868
|
return this._initNumber(number, base, endian);
|
|
1870
1869
|
}
|
|
@@ -1892,7 +1891,7 @@ var require_bn = __commonJS({
|
|
|
1892
1891
|
}
|
|
1893
1892
|
}
|
|
1894
1893
|
};
|
|
1895
|
-
|
|
1894
|
+
BN4.prototype._initNumber = function _initNumber(number, base, endian) {
|
|
1896
1895
|
if (number < 0) {
|
|
1897
1896
|
this.negative = 1;
|
|
1898
1897
|
number = -number;
|
|
@@ -1918,7 +1917,7 @@ var require_bn = __commonJS({
|
|
|
1918
1917
|
if (endian !== "le") return;
|
|
1919
1918
|
this._initArray(this.toArray(), base, endian);
|
|
1920
1919
|
};
|
|
1921
|
-
|
|
1920
|
+
BN4.prototype._initArray = function _initArray(number, base, endian) {
|
|
1922
1921
|
assert(typeof number.length === "number");
|
|
1923
1922
|
if (number.length <= 0) {
|
|
1924
1923
|
this.words = [0];
|
|
@@ -1976,7 +1975,7 @@ var require_bn = __commonJS({
|
|
|
1976
1975
|
}
|
|
1977
1976
|
return r;
|
|
1978
1977
|
}
|
|
1979
|
-
|
|
1978
|
+
BN4.prototype._parseHex = function _parseHex(number, start, endian) {
|
|
1980
1979
|
this.length = Math.ceil((number.length - start) / 6);
|
|
1981
1980
|
this.words = new Array(this.length);
|
|
1982
1981
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -2032,7 +2031,7 @@ var require_bn = __commonJS({
|
|
|
2032
2031
|
}
|
|
2033
2032
|
return r;
|
|
2034
2033
|
}
|
|
2035
|
-
|
|
2034
|
+
BN4.prototype._parseBase = function _parseBase(number, base, start) {
|
|
2036
2035
|
this.words = [0];
|
|
2037
2036
|
this.length = 1;
|
|
2038
2037
|
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
|
|
@@ -2068,7 +2067,7 @@ var require_bn = __commonJS({
|
|
|
2068
2067
|
}
|
|
2069
2068
|
this._strip();
|
|
2070
2069
|
};
|
|
2071
|
-
|
|
2070
|
+
BN4.prototype.copy = function copy(dest) {
|
|
2072
2071
|
dest.words = new Array(this.length);
|
|
2073
2072
|
for (var i = 0; i < this.length; i++) {
|
|
2074
2073
|
dest.words[i] = this.words[i];
|
|
@@ -2083,27 +2082,27 @@ var require_bn = __commonJS({
|
|
|
2083
2082
|
dest.negative = src.negative;
|
|
2084
2083
|
dest.red = src.red;
|
|
2085
2084
|
}
|
|
2086
|
-
|
|
2085
|
+
BN4.prototype._move = function _move(dest) {
|
|
2087
2086
|
move(dest, this);
|
|
2088
2087
|
};
|
|
2089
|
-
|
|
2090
|
-
var r = new
|
|
2088
|
+
BN4.prototype.clone = function clone() {
|
|
2089
|
+
var r = new BN4(null);
|
|
2091
2090
|
this.copy(r);
|
|
2092
2091
|
return r;
|
|
2093
2092
|
};
|
|
2094
|
-
|
|
2093
|
+
BN4.prototype._expand = function _expand(size) {
|
|
2095
2094
|
while (this.length < size) {
|
|
2096
2095
|
this.words[this.length++] = 0;
|
|
2097
2096
|
}
|
|
2098
2097
|
return this;
|
|
2099
2098
|
};
|
|
2100
|
-
|
|
2099
|
+
BN4.prototype._strip = function strip() {
|
|
2101
2100
|
while (this.length > 1 && this.words[this.length - 1] === 0) {
|
|
2102
2101
|
this.length--;
|
|
2103
2102
|
}
|
|
2104
2103
|
return this._normSign();
|
|
2105
2104
|
};
|
|
2106
|
-
|
|
2105
|
+
BN4.prototype._normSign = function _normSign() {
|
|
2107
2106
|
if (this.length === 1 && this.words[0] === 0) {
|
|
2108
2107
|
this.negative = 0;
|
|
2109
2108
|
}
|
|
@@ -2111,12 +2110,12 @@ var require_bn = __commonJS({
|
|
|
2111
2110
|
};
|
|
2112
2111
|
if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
|
|
2113
2112
|
try {
|
|
2114
|
-
|
|
2113
|
+
BN4.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
|
|
2115
2114
|
} catch (e) {
|
|
2116
|
-
|
|
2115
|
+
BN4.prototype.inspect = inspect;
|
|
2117
2116
|
}
|
|
2118
2117
|
} else {
|
|
2119
|
-
|
|
2118
|
+
BN4.prototype.inspect = inspect;
|
|
2120
2119
|
}
|
|
2121
2120
|
function inspect() {
|
|
2122
2121
|
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
|
|
@@ -2227,7 +2226,7 @@ var require_bn = __commonJS({
|
|
|
2227
2226
|
52521875,
|
|
2228
2227
|
60466176
|
|
2229
2228
|
];
|
|
2230
|
-
|
|
2229
|
+
BN4.prototype.toString = function toString(base, padding) {
|
|
2231
2230
|
base = base || 10;
|
|
2232
2231
|
padding = padding | 0 || 1;
|
|
2233
2232
|
var out;
|
|
@@ -2289,7 +2288,7 @@ var require_bn = __commonJS({
|
|
|
2289
2288
|
}
|
|
2290
2289
|
assert(false, "Base should be between 2 and 36");
|
|
2291
2290
|
};
|
|
2292
|
-
|
|
2291
|
+
BN4.prototype.toNumber = function toNumber() {
|
|
2293
2292
|
var ret = this.words[0];
|
|
2294
2293
|
if (this.length === 2) {
|
|
2295
2294
|
ret += this.words[1] * 67108864;
|
|
@@ -2300,15 +2299,15 @@ var require_bn = __commonJS({
|
|
|
2300
2299
|
}
|
|
2301
2300
|
return this.negative !== 0 ? -ret : ret;
|
|
2302
2301
|
};
|
|
2303
|
-
|
|
2302
|
+
BN4.prototype.toJSON = function toJSON() {
|
|
2304
2303
|
return this.toString(16, 2);
|
|
2305
2304
|
};
|
|
2306
2305
|
if (Buffer2) {
|
|
2307
|
-
|
|
2306
|
+
BN4.prototype.toBuffer = function toBuffer(endian, length) {
|
|
2308
2307
|
return this.toArrayLike(Buffer2, endian, length);
|
|
2309
2308
|
};
|
|
2310
2309
|
}
|
|
2311
|
-
|
|
2310
|
+
BN4.prototype.toArray = function toArray(endian, length) {
|
|
2312
2311
|
return this.toArrayLike(Array, endian, length);
|
|
2313
2312
|
};
|
|
2314
2313
|
var allocate = function allocate2(ArrayType, size) {
|
|
@@ -2317,7 +2316,7 @@ var require_bn = __commonJS({
|
|
|
2317
2316
|
}
|
|
2318
2317
|
return new ArrayType(size);
|
|
2319
2318
|
};
|
|
2320
|
-
|
|
2319
|
+
BN4.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
|
|
2321
2320
|
this._strip();
|
|
2322
2321
|
var byteLength = this.byteLength();
|
|
2323
2322
|
var reqLength = length || Math.max(1, byteLength);
|
|
@@ -2328,7 +2327,7 @@ var require_bn = __commonJS({
|
|
|
2328
2327
|
this["_toArrayLike" + postfix](res, byteLength);
|
|
2329
2328
|
return res;
|
|
2330
2329
|
};
|
|
2331
|
-
|
|
2330
|
+
BN4.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
|
|
2332
2331
|
var position = 0;
|
|
2333
2332
|
var carry = 0;
|
|
2334
2333
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -2358,7 +2357,7 @@ var require_bn = __commonJS({
|
|
|
2358
2357
|
}
|
|
2359
2358
|
}
|
|
2360
2359
|
};
|
|
2361
|
-
|
|
2360
|
+
BN4.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
|
|
2362
2361
|
var position = res.length - 1;
|
|
2363
2362
|
var carry = 0;
|
|
2364
2363
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -2389,11 +2388,11 @@ var require_bn = __commonJS({
|
|
|
2389
2388
|
}
|
|
2390
2389
|
};
|
|
2391
2390
|
if (Math.clz32) {
|
|
2392
|
-
|
|
2391
|
+
BN4.prototype._countBits = function _countBits(w) {
|
|
2393
2392
|
return 32 - Math.clz32(w);
|
|
2394
2393
|
};
|
|
2395
2394
|
} else {
|
|
2396
|
-
|
|
2395
|
+
BN4.prototype._countBits = function _countBits(w) {
|
|
2397
2396
|
var t = w;
|
|
2398
2397
|
var r = 0;
|
|
2399
2398
|
if (t >= 4096) {
|
|
@@ -2415,7 +2414,7 @@ var require_bn = __commonJS({
|
|
|
2415
2414
|
return r + t;
|
|
2416
2415
|
};
|
|
2417
2416
|
}
|
|
2418
|
-
|
|
2417
|
+
BN4.prototype._zeroBits = function _zeroBits(w) {
|
|
2419
2418
|
if (w === 0) return 26;
|
|
2420
2419
|
var t = w;
|
|
2421
2420
|
var r = 0;
|
|
@@ -2440,7 +2439,7 @@ var require_bn = __commonJS({
|
|
|
2440
2439
|
}
|
|
2441
2440
|
return r;
|
|
2442
2441
|
};
|
|
2443
|
-
|
|
2442
|
+
BN4.prototype.bitLength = function bitLength() {
|
|
2444
2443
|
var w = this.words[this.length - 1];
|
|
2445
2444
|
var hi = this._countBits(w);
|
|
2446
2445
|
return (this.length - 1) * 26 + hi;
|
|
@@ -2454,7 +2453,7 @@ var require_bn = __commonJS({
|
|
|
2454
2453
|
}
|
|
2455
2454
|
return w;
|
|
2456
2455
|
}
|
|
2457
|
-
|
|
2456
|
+
BN4.prototype.zeroBits = function zeroBits() {
|
|
2458
2457
|
if (this.isZero()) return 0;
|
|
2459
2458
|
var r = 0;
|
|
2460
2459
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -2464,34 +2463,34 @@ var require_bn = __commonJS({
|
|
|
2464
2463
|
}
|
|
2465
2464
|
return r;
|
|
2466
2465
|
};
|
|
2467
|
-
|
|
2466
|
+
BN4.prototype.byteLength = function byteLength() {
|
|
2468
2467
|
return Math.ceil(this.bitLength() / 8);
|
|
2469
2468
|
};
|
|
2470
|
-
|
|
2469
|
+
BN4.prototype.toTwos = function toTwos(width) {
|
|
2471
2470
|
if (this.negative !== 0) {
|
|
2472
2471
|
return this.abs().inotn(width).iaddn(1);
|
|
2473
2472
|
}
|
|
2474
2473
|
return this.clone();
|
|
2475
2474
|
};
|
|
2476
|
-
|
|
2475
|
+
BN4.prototype.fromTwos = function fromTwos(width) {
|
|
2477
2476
|
if (this.testn(width - 1)) {
|
|
2478
2477
|
return this.notn(width).iaddn(1).ineg();
|
|
2479
2478
|
}
|
|
2480
2479
|
return this.clone();
|
|
2481
2480
|
};
|
|
2482
|
-
|
|
2481
|
+
BN4.prototype.isNeg = function isNeg() {
|
|
2483
2482
|
return this.negative !== 0;
|
|
2484
2483
|
};
|
|
2485
|
-
|
|
2484
|
+
BN4.prototype.neg = function neg() {
|
|
2486
2485
|
return this.clone().ineg();
|
|
2487
2486
|
};
|
|
2488
|
-
|
|
2487
|
+
BN4.prototype.ineg = function ineg() {
|
|
2489
2488
|
if (!this.isZero()) {
|
|
2490
2489
|
this.negative ^= 1;
|
|
2491
2490
|
}
|
|
2492
2491
|
return this;
|
|
2493
2492
|
};
|
|
2494
|
-
|
|
2493
|
+
BN4.prototype.iuor = function iuor(num) {
|
|
2495
2494
|
while (this.length < num.length) {
|
|
2496
2495
|
this.words[this.length++] = 0;
|
|
2497
2496
|
}
|
|
@@ -2500,19 +2499,19 @@ var require_bn = __commonJS({
|
|
|
2500
2499
|
}
|
|
2501
2500
|
return this._strip();
|
|
2502
2501
|
};
|
|
2503
|
-
|
|
2502
|
+
BN4.prototype.ior = function ior(num) {
|
|
2504
2503
|
assert((this.negative | num.negative) === 0);
|
|
2505
2504
|
return this.iuor(num);
|
|
2506
2505
|
};
|
|
2507
|
-
|
|
2506
|
+
BN4.prototype.or = function or(num) {
|
|
2508
2507
|
if (this.length > num.length) return this.clone().ior(num);
|
|
2509
2508
|
return num.clone().ior(this);
|
|
2510
2509
|
};
|
|
2511
|
-
|
|
2510
|
+
BN4.prototype.uor = function uor(num) {
|
|
2512
2511
|
if (this.length > num.length) return this.clone().iuor(num);
|
|
2513
2512
|
return num.clone().iuor(this);
|
|
2514
2513
|
};
|
|
2515
|
-
|
|
2514
|
+
BN4.prototype.iuand = function iuand(num) {
|
|
2516
2515
|
var b;
|
|
2517
2516
|
if (this.length > num.length) {
|
|
2518
2517
|
b = num;
|
|
@@ -2525,19 +2524,19 @@ var require_bn = __commonJS({
|
|
|
2525
2524
|
this.length = b.length;
|
|
2526
2525
|
return this._strip();
|
|
2527
2526
|
};
|
|
2528
|
-
|
|
2527
|
+
BN4.prototype.iand = function iand(num) {
|
|
2529
2528
|
assert((this.negative | num.negative) === 0);
|
|
2530
2529
|
return this.iuand(num);
|
|
2531
2530
|
};
|
|
2532
|
-
|
|
2531
|
+
BN4.prototype.and = function and(num) {
|
|
2533
2532
|
if (this.length > num.length) return this.clone().iand(num);
|
|
2534
2533
|
return num.clone().iand(this);
|
|
2535
2534
|
};
|
|
2536
|
-
|
|
2535
|
+
BN4.prototype.uand = function uand(num) {
|
|
2537
2536
|
if (this.length > num.length) return this.clone().iuand(num);
|
|
2538
2537
|
return num.clone().iuand(this);
|
|
2539
2538
|
};
|
|
2540
|
-
|
|
2539
|
+
BN4.prototype.iuxor = function iuxor(num) {
|
|
2541
2540
|
var a;
|
|
2542
2541
|
var b;
|
|
2543
2542
|
if (this.length > num.length) {
|
|
@@ -2558,19 +2557,19 @@ var require_bn = __commonJS({
|
|
|
2558
2557
|
this.length = a.length;
|
|
2559
2558
|
return this._strip();
|
|
2560
2559
|
};
|
|
2561
|
-
|
|
2560
|
+
BN4.prototype.ixor = function ixor(num) {
|
|
2562
2561
|
assert((this.negative | num.negative) === 0);
|
|
2563
2562
|
return this.iuxor(num);
|
|
2564
2563
|
};
|
|
2565
|
-
|
|
2564
|
+
BN4.prototype.xor = function xor(num) {
|
|
2566
2565
|
if (this.length > num.length) return this.clone().ixor(num);
|
|
2567
2566
|
return num.clone().ixor(this);
|
|
2568
2567
|
};
|
|
2569
|
-
|
|
2568
|
+
BN4.prototype.uxor = function uxor(num) {
|
|
2570
2569
|
if (this.length > num.length) return this.clone().iuxor(num);
|
|
2571
2570
|
return num.clone().iuxor(this);
|
|
2572
2571
|
};
|
|
2573
|
-
|
|
2572
|
+
BN4.prototype.inotn = function inotn(width) {
|
|
2574
2573
|
assert(typeof width === "number" && width >= 0);
|
|
2575
2574
|
var bytesNeeded = Math.ceil(width / 26) | 0;
|
|
2576
2575
|
var bitsLeft = width % 26;
|
|
@@ -2586,10 +2585,10 @@ var require_bn = __commonJS({
|
|
|
2586
2585
|
}
|
|
2587
2586
|
return this._strip();
|
|
2588
2587
|
};
|
|
2589
|
-
|
|
2588
|
+
BN4.prototype.notn = function notn(width) {
|
|
2590
2589
|
return this.clone().inotn(width);
|
|
2591
2590
|
};
|
|
2592
|
-
|
|
2591
|
+
BN4.prototype.setn = function setn(bit, val) {
|
|
2593
2592
|
assert(typeof bit === "number" && bit >= 0);
|
|
2594
2593
|
var off = bit / 26 | 0;
|
|
2595
2594
|
var wbit = bit % 26;
|
|
@@ -2601,7 +2600,7 @@ var require_bn = __commonJS({
|
|
|
2601
2600
|
}
|
|
2602
2601
|
return this._strip();
|
|
2603
2602
|
};
|
|
2604
|
-
|
|
2603
|
+
BN4.prototype.iadd = function iadd(num) {
|
|
2605
2604
|
var r;
|
|
2606
2605
|
if (this.negative !== 0 && num.negative === 0) {
|
|
2607
2606
|
this.negative = 0;
|
|
@@ -2644,7 +2643,7 @@ var require_bn = __commonJS({
|
|
|
2644
2643
|
}
|
|
2645
2644
|
return this;
|
|
2646
2645
|
};
|
|
2647
|
-
|
|
2646
|
+
BN4.prototype.add = function add(num) {
|
|
2648
2647
|
var res;
|
|
2649
2648
|
if (num.negative !== 0 && this.negative === 0) {
|
|
2650
2649
|
num.negative = 0;
|
|
@@ -2660,7 +2659,7 @@ var require_bn = __commonJS({
|
|
|
2660
2659
|
if (this.length > num.length) return this.clone().iadd(num);
|
|
2661
2660
|
return num.clone().iadd(this);
|
|
2662
2661
|
};
|
|
2663
|
-
|
|
2662
|
+
BN4.prototype.isub = function isub(num) {
|
|
2664
2663
|
if (num.negative !== 0) {
|
|
2665
2664
|
num.negative = 0;
|
|
2666
2665
|
var r = this.iadd(num);
|
|
@@ -2709,7 +2708,7 @@ var require_bn = __commonJS({
|
|
|
2709
2708
|
}
|
|
2710
2709
|
return this._strip();
|
|
2711
2710
|
};
|
|
2712
|
-
|
|
2711
|
+
BN4.prototype.sub = function sub(num) {
|
|
2713
2712
|
return this.clone().isub(num);
|
|
2714
2713
|
};
|
|
2715
2714
|
function smallMulTo(self, num, out) {
|
|
@@ -3337,7 +3336,7 @@ var require_bn = __commonJS({
|
|
|
3337
3336
|
function jumboMulTo(self, num, out) {
|
|
3338
3337
|
return bigMulTo(self, num, out);
|
|
3339
3338
|
}
|
|
3340
|
-
|
|
3339
|
+
BN4.prototype.mulTo = function mulTo(num, out) {
|
|
3341
3340
|
var res;
|
|
3342
3341
|
var len = this.length + num.length;
|
|
3343
3342
|
if (this.length === 10 && num.length === 10) {
|
|
@@ -3351,20 +3350,20 @@ var require_bn = __commonJS({
|
|
|
3351
3350
|
}
|
|
3352
3351
|
return res;
|
|
3353
3352
|
};
|
|
3354
|
-
|
|
3355
|
-
var out = new
|
|
3353
|
+
BN4.prototype.mul = function mul(num) {
|
|
3354
|
+
var out = new BN4(null);
|
|
3356
3355
|
out.words = new Array(this.length + num.length);
|
|
3357
3356
|
return this.mulTo(num, out);
|
|
3358
3357
|
};
|
|
3359
|
-
|
|
3360
|
-
var out = new
|
|
3358
|
+
BN4.prototype.mulf = function mulf(num) {
|
|
3359
|
+
var out = new BN4(null);
|
|
3361
3360
|
out.words = new Array(this.length + num.length);
|
|
3362
3361
|
return jumboMulTo(this, num, out);
|
|
3363
3362
|
};
|
|
3364
|
-
|
|
3363
|
+
BN4.prototype.imul = function imul(num) {
|
|
3365
3364
|
return this.clone().mulTo(num, this);
|
|
3366
3365
|
};
|
|
3367
|
-
|
|
3366
|
+
BN4.prototype.imuln = function imuln(num) {
|
|
3368
3367
|
var isNegNum = num < 0;
|
|
3369
3368
|
if (isNegNum) num = -num;
|
|
3370
3369
|
assert(typeof num === "number");
|
|
@@ -3385,18 +3384,18 @@ var require_bn = __commonJS({
|
|
|
3385
3384
|
this.length = num === 0 ? 1 : this.length;
|
|
3386
3385
|
return isNegNum ? this.ineg() : this;
|
|
3387
3386
|
};
|
|
3388
|
-
|
|
3387
|
+
BN4.prototype.muln = function muln(num) {
|
|
3389
3388
|
return this.clone().imuln(num);
|
|
3390
3389
|
};
|
|
3391
|
-
|
|
3390
|
+
BN4.prototype.sqr = function sqr() {
|
|
3392
3391
|
return this.mul(this);
|
|
3393
3392
|
};
|
|
3394
|
-
|
|
3393
|
+
BN4.prototype.isqr = function isqr() {
|
|
3395
3394
|
return this.imul(this.clone());
|
|
3396
3395
|
};
|
|
3397
|
-
|
|
3396
|
+
BN4.prototype.pow = function pow(num) {
|
|
3398
3397
|
var w = toBitArray(num);
|
|
3399
|
-
if (w.length === 0) return new
|
|
3398
|
+
if (w.length === 0) return new BN4(1);
|
|
3400
3399
|
var res = this;
|
|
3401
3400
|
for (var i = 0; i < w.length; i++, res = res.sqr()) {
|
|
3402
3401
|
if (w[i] !== 0) break;
|
|
@@ -3409,7 +3408,7 @@ var require_bn = __commonJS({
|
|
|
3409
3408
|
}
|
|
3410
3409
|
return res;
|
|
3411
3410
|
};
|
|
3412
|
-
|
|
3411
|
+
BN4.prototype.iushln = function iushln(bits) {
|
|
3413
3412
|
assert(typeof bits === "number" && bits >= 0);
|
|
3414
3413
|
var r = bits % 26;
|
|
3415
3414
|
var s = (bits - r) / 26;
|
|
@@ -3439,11 +3438,11 @@ var require_bn = __commonJS({
|
|
|
3439
3438
|
}
|
|
3440
3439
|
return this._strip();
|
|
3441
3440
|
};
|
|
3442
|
-
|
|
3441
|
+
BN4.prototype.ishln = function ishln(bits) {
|
|
3443
3442
|
assert(this.negative === 0);
|
|
3444
3443
|
return this.iushln(bits);
|
|
3445
3444
|
};
|
|
3446
|
-
|
|
3445
|
+
BN4.prototype.iushrn = function iushrn(bits, hint, extended) {
|
|
3447
3446
|
assert(typeof bits === "number" && bits >= 0);
|
|
3448
3447
|
var h;
|
|
3449
3448
|
if (hint) {
|
|
@@ -3487,23 +3486,23 @@ var require_bn = __commonJS({
|
|
|
3487
3486
|
}
|
|
3488
3487
|
return this._strip();
|
|
3489
3488
|
};
|
|
3490
|
-
|
|
3489
|
+
BN4.prototype.ishrn = function ishrn(bits, hint, extended) {
|
|
3491
3490
|
assert(this.negative === 0);
|
|
3492
3491
|
return this.iushrn(bits, hint, extended);
|
|
3493
3492
|
};
|
|
3494
|
-
|
|
3493
|
+
BN4.prototype.shln = function shln(bits) {
|
|
3495
3494
|
return this.clone().ishln(bits);
|
|
3496
3495
|
};
|
|
3497
|
-
|
|
3496
|
+
BN4.prototype.ushln = function ushln(bits) {
|
|
3498
3497
|
return this.clone().iushln(bits);
|
|
3499
3498
|
};
|
|
3500
|
-
|
|
3499
|
+
BN4.prototype.shrn = function shrn(bits) {
|
|
3501
3500
|
return this.clone().ishrn(bits);
|
|
3502
3501
|
};
|
|
3503
|
-
|
|
3502
|
+
BN4.prototype.ushrn = function ushrn(bits) {
|
|
3504
3503
|
return this.clone().iushrn(bits);
|
|
3505
3504
|
};
|
|
3506
|
-
|
|
3505
|
+
BN4.prototype.testn = function testn(bit) {
|
|
3507
3506
|
assert(typeof bit === "number" && bit >= 0);
|
|
3508
3507
|
var r = bit % 26;
|
|
3509
3508
|
var s = (bit - r) / 26;
|
|
@@ -3512,7 +3511,7 @@ var require_bn = __commonJS({
|
|
|
3512
3511
|
var w = this.words[s];
|
|
3513
3512
|
return !!(w & q);
|
|
3514
3513
|
};
|
|
3515
|
-
|
|
3514
|
+
BN4.prototype.imaskn = function imaskn(bits) {
|
|
3516
3515
|
assert(typeof bits === "number" && bits >= 0);
|
|
3517
3516
|
var r = bits % 26;
|
|
3518
3517
|
var s = (bits - r) / 26;
|
|
@@ -3530,10 +3529,10 @@ var require_bn = __commonJS({
|
|
|
3530
3529
|
}
|
|
3531
3530
|
return this._strip();
|
|
3532
3531
|
};
|
|
3533
|
-
|
|
3532
|
+
BN4.prototype.maskn = function maskn(bits) {
|
|
3534
3533
|
return this.clone().imaskn(bits);
|
|
3535
3534
|
};
|
|
3536
|
-
|
|
3535
|
+
BN4.prototype.iaddn = function iaddn(num) {
|
|
3537
3536
|
assert(typeof num === "number");
|
|
3538
3537
|
assert(num < 67108864);
|
|
3539
3538
|
if (num < 0) return this.isubn(-num);
|
|
@@ -3550,7 +3549,7 @@ var require_bn = __commonJS({
|
|
|
3550
3549
|
}
|
|
3551
3550
|
return this._iaddn(num);
|
|
3552
3551
|
};
|
|
3553
|
-
|
|
3552
|
+
BN4.prototype._iaddn = function _iaddn(num) {
|
|
3554
3553
|
this.words[0] += num;
|
|
3555
3554
|
for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
|
|
3556
3555
|
this.words[i] -= 67108864;
|
|
@@ -3563,7 +3562,7 @@ var require_bn = __commonJS({
|
|
|
3563
3562
|
this.length = Math.max(this.length, i + 1);
|
|
3564
3563
|
return this;
|
|
3565
3564
|
};
|
|
3566
|
-
|
|
3565
|
+
BN4.prototype.isubn = function isubn(num) {
|
|
3567
3566
|
assert(typeof num === "number");
|
|
3568
3567
|
assert(num < 67108864);
|
|
3569
3568
|
if (num < 0) return this.iaddn(-num);
|
|
@@ -3585,20 +3584,20 @@ var require_bn = __commonJS({
|
|
|
3585
3584
|
}
|
|
3586
3585
|
return this._strip();
|
|
3587
3586
|
};
|
|
3588
|
-
|
|
3587
|
+
BN4.prototype.addn = function addn(num) {
|
|
3589
3588
|
return this.clone().iaddn(num);
|
|
3590
3589
|
};
|
|
3591
|
-
|
|
3590
|
+
BN4.prototype.subn = function subn(num) {
|
|
3592
3591
|
return this.clone().isubn(num);
|
|
3593
3592
|
};
|
|
3594
|
-
|
|
3593
|
+
BN4.prototype.iabs = function iabs() {
|
|
3595
3594
|
this.negative = 0;
|
|
3596
3595
|
return this;
|
|
3597
3596
|
};
|
|
3598
|
-
|
|
3597
|
+
BN4.prototype.abs = function abs() {
|
|
3599
3598
|
return this.clone().iabs();
|
|
3600
3599
|
};
|
|
3601
|
-
|
|
3600
|
+
BN4.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
|
|
3602
3601
|
var len = num.length + shift;
|
|
3603
3602
|
var i;
|
|
3604
3603
|
this._expand(len);
|
|
@@ -3627,7 +3626,7 @@ var require_bn = __commonJS({
|
|
|
3627
3626
|
this.negative = 1;
|
|
3628
3627
|
return this._strip();
|
|
3629
3628
|
};
|
|
3630
|
-
|
|
3629
|
+
BN4.prototype._wordDiv = function _wordDiv(num, mode) {
|
|
3631
3630
|
var shift = this.length - num.length;
|
|
3632
3631
|
var a = this.clone();
|
|
3633
3632
|
var b = num;
|
|
@@ -3642,7 +3641,7 @@ var require_bn = __commonJS({
|
|
|
3642
3641
|
var m = a.length - b.length;
|
|
3643
3642
|
var q;
|
|
3644
3643
|
if (mode !== "mod") {
|
|
3645
|
-
q = new
|
|
3644
|
+
q = new BN4(null);
|
|
3646
3645
|
q.length = m + 1;
|
|
3647
3646
|
q.words = new Array(q.length);
|
|
3648
3647
|
for (var i = 0; i < q.length; i++) {
|
|
@@ -3684,12 +3683,12 @@ var require_bn = __commonJS({
|
|
|
3684
3683
|
mod: a
|
|
3685
3684
|
};
|
|
3686
3685
|
};
|
|
3687
|
-
|
|
3686
|
+
BN4.prototype.divmod = function divmod(num, mode, positive) {
|
|
3688
3687
|
assert(!num.isZero());
|
|
3689
3688
|
if (this.isZero()) {
|
|
3690
3689
|
return {
|
|
3691
|
-
div: new
|
|
3692
|
-
mod: new
|
|
3690
|
+
div: new BN4(0),
|
|
3691
|
+
mod: new BN4(0)
|
|
3693
3692
|
};
|
|
3694
3693
|
}
|
|
3695
3694
|
var div, mod, res;
|
|
@@ -3734,7 +3733,7 @@ var require_bn = __commonJS({
|
|
|
3734
3733
|
}
|
|
3735
3734
|
if (num.length > this.length || this.cmp(num) < 0) {
|
|
3736
3735
|
return {
|
|
3737
|
-
div: new
|
|
3736
|
+
div: new BN4(0),
|
|
3738
3737
|
mod: this
|
|
3739
3738
|
};
|
|
3740
3739
|
}
|
|
@@ -3748,26 +3747,26 @@ var require_bn = __commonJS({
|
|
|
3748
3747
|
if (mode === "mod") {
|
|
3749
3748
|
return {
|
|
3750
3749
|
div: null,
|
|
3751
|
-
mod: new
|
|
3750
|
+
mod: new BN4(this.modrn(num.words[0]))
|
|
3752
3751
|
};
|
|
3753
3752
|
}
|
|
3754
3753
|
return {
|
|
3755
3754
|
div: this.divn(num.words[0]),
|
|
3756
|
-
mod: new
|
|
3755
|
+
mod: new BN4(this.modrn(num.words[0]))
|
|
3757
3756
|
};
|
|
3758
3757
|
}
|
|
3759
3758
|
return this._wordDiv(num, mode);
|
|
3760
3759
|
};
|
|
3761
|
-
|
|
3760
|
+
BN4.prototype.div = function div(num) {
|
|
3762
3761
|
return this.divmod(num, "div", false).div;
|
|
3763
3762
|
};
|
|
3764
|
-
|
|
3763
|
+
BN4.prototype.mod = function mod(num) {
|
|
3765
3764
|
return this.divmod(num, "mod", false).mod;
|
|
3766
3765
|
};
|
|
3767
|
-
|
|
3766
|
+
BN4.prototype.umod = function umod(num) {
|
|
3768
3767
|
return this.divmod(num, "mod", true).mod;
|
|
3769
3768
|
};
|
|
3770
|
-
|
|
3769
|
+
BN4.prototype.divRound = function divRound(num) {
|
|
3771
3770
|
var dm = this.divmod(num);
|
|
3772
3771
|
if (dm.mod.isZero()) return dm.div;
|
|
3773
3772
|
var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
|
|
@@ -3777,7 +3776,7 @@ var require_bn = __commonJS({
|
|
|
3777
3776
|
if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
|
|
3778
3777
|
return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
|
|
3779
3778
|
};
|
|
3780
|
-
|
|
3779
|
+
BN4.prototype.modrn = function modrn(num) {
|
|
3781
3780
|
var isNegNum = num < 0;
|
|
3782
3781
|
if (isNegNum) num = -num;
|
|
3783
3782
|
assert(num <= 67108863);
|
|
@@ -3788,10 +3787,10 @@ var require_bn = __commonJS({
|
|
|
3788
3787
|
}
|
|
3789
3788
|
return isNegNum ? -acc : acc;
|
|
3790
3789
|
};
|
|
3791
|
-
|
|
3790
|
+
BN4.prototype.modn = function modn(num) {
|
|
3792
3791
|
return this.modrn(num);
|
|
3793
3792
|
};
|
|
3794
|
-
|
|
3793
|
+
BN4.prototype.idivn = function idivn(num) {
|
|
3795
3794
|
var isNegNum = num < 0;
|
|
3796
3795
|
if (isNegNum) num = -num;
|
|
3797
3796
|
assert(num <= 67108863);
|
|
@@ -3804,10 +3803,10 @@ var require_bn = __commonJS({
|
|
|
3804
3803
|
this._strip();
|
|
3805
3804
|
return isNegNum ? this.ineg() : this;
|
|
3806
3805
|
};
|
|
3807
|
-
|
|
3806
|
+
BN4.prototype.divn = function divn(num) {
|
|
3808
3807
|
return this.clone().idivn(num);
|
|
3809
3808
|
};
|
|
3810
|
-
|
|
3809
|
+
BN4.prototype.egcd = function egcd(p) {
|
|
3811
3810
|
assert(p.negative === 0);
|
|
3812
3811
|
assert(!p.isZero());
|
|
3813
3812
|
var x = this;
|
|
@@ -3817,10 +3816,10 @@ var require_bn = __commonJS({
|
|
|
3817
3816
|
} else {
|
|
3818
3817
|
x = x.clone();
|
|
3819
3818
|
}
|
|
3820
|
-
var A = new
|
|
3821
|
-
var B = new
|
|
3822
|
-
var C = new
|
|
3823
|
-
var D = new
|
|
3819
|
+
var A = new BN4(1);
|
|
3820
|
+
var B = new BN4(0);
|
|
3821
|
+
var C = new BN4(0);
|
|
3822
|
+
var D = new BN4(1);
|
|
3824
3823
|
var g = 0;
|
|
3825
3824
|
while (x.isEven() && y.isEven()) {
|
|
3826
3825
|
x.iushrn(1);
|
|
@@ -3870,7 +3869,7 @@ var require_bn = __commonJS({
|
|
|
3870
3869
|
gcd: y.iushln(g)
|
|
3871
3870
|
};
|
|
3872
3871
|
};
|
|
3873
|
-
|
|
3872
|
+
BN4.prototype._invmp = function _invmp(p) {
|
|
3874
3873
|
assert(p.negative === 0);
|
|
3875
3874
|
assert(!p.isZero());
|
|
3876
3875
|
var a = this;
|
|
@@ -3880,8 +3879,8 @@ var require_bn = __commonJS({
|
|
|
3880
3879
|
} else {
|
|
3881
3880
|
a = a.clone();
|
|
3882
3881
|
}
|
|
3883
|
-
var x1 = new
|
|
3884
|
-
var x2 = new
|
|
3882
|
+
var x1 = new BN4(1);
|
|
3883
|
+
var x2 = new BN4(0);
|
|
3885
3884
|
var delta = b.clone();
|
|
3886
3885
|
while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
|
|
3887
3886
|
for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
|
|
@@ -3923,7 +3922,7 @@ var require_bn = __commonJS({
|
|
|
3923
3922
|
}
|
|
3924
3923
|
return res;
|
|
3925
3924
|
};
|
|
3926
|
-
|
|
3925
|
+
BN4.prototype.gcd = function gcd(num) {
|
|
3927
3926
|
if (this.isZero()) return num.abs();
|
|
3928
3927
|
if (num.isZero()) return this.abs();
|
|
3929
3928
|
var a = this.clone();
|
|
@@ -3953,19 +3952,19 @@ var require_bn = __commonJS({
|
|
|
3953
3952
|
} while (true);
|
|
3954
3953
|
return b.iushln(shift);
|
|
3955
3954
|
};
|
|
3956
|
-
|
|
3955
|
+
BN4.prototype.invm = function invm(num) {
|
|
3957
3956
|
return this.egcd(num).a.umod(num);
|
|
3958
3957
|
};
|
|
3959
|
-
|
|
3958
|
+
BN4.prototype.isEven = function isEven() {
|
|
3960
3959
|
return (this.words[0] & 1) === 0;
|
|
3961
3960
|
};
|
|
3962
|
-
|
|
3961
|
+
BN4.prototype.isOdd = function isOdd() {
|
|
3963
3962
|
return (this.words[0] & 1) === 1;
|
|
3964
3963
|
};
|
|
3965
|
-
|
|
3964
|
+
BN4.prototype.andln = function andln(num) {
|
|
3966
3965
|
return this.words[0] & num;
|
|
3967
3966
|
};
|
|
3968
|
-
|
|
3967
|
+
BN4.prototype.bincn = function bincn(bit) {
|
|
3969
3968
|
assert(typeof bit === "number");
|
|
3970
3969
|
var r = bit % 26;
|
|
3971
3970
|
var s = (bit - r) / 26;
|
|
@@ -3989,10 +3988,10 @@ var require_bn = __commonJS({
|
|
|
3989
3988
|
}
|
|
3990
3989
|
return this;
|
|
3991
3990
|
};
|
|
3992
|
-
|
|
3991
|
+
BN4.prototype.isZero = function isZero() {
|
|
3993
3992
|
return this.length === 1 && this.words[0] === 0;
|
|
3994
3993
|
};
|
|
3995
|
-
|
|
3994
|
+
BN4.prototype.cmpn = function cmpn(num) {
|
|
3996
3995
|
var negative = num < 0;
|
|
3997
3996
|
if (this.negative !== 0 && !negative) return -1;
|
|
3998
3997
|
if (this.negative === 0 && negative) return 1;
|
|
@@ -4011,14 +4010,14 @@ var require_bn = __commonJS({
|
|
|
4011
4010
|
if (this.negative !== 0) return -res | 0;
|
|
4012
4011
|
return res;
|
|
4013
4012
|
};
|
|
4014
|
-
|
|
4013
|
+
BN4.prototype.cmp = function cmp(num) {
|
|
4015
4014
|
if (this.negative !== 0 && num.negative === 0) return -1;
|
|
4016
4015
|
if (this.negative === 0 && num.negative !== 0) return 1;
|
|
4017
4016
|
var res = this.ucmp(num);
|
|
4018
4017
|
if (this.negative !== 0) return -res | 0;
|
|
4019
4018
|
return res;
|
|
4020
4019
|
};
|
|
4021
|
-
|
|
4020
|
+
BN4.prototype.ucmp = function ucmp(num) {
|
|
4022
4021
|
if (this.length > num.length) return 1;
|
|
4023
4022
|
if (this.length < num.length) return -1;
|
|
4024
4023
|
var res = 0;
|
|
@@ -4035,112 +4034,112 @@ var require_bn = __commonJS({
|
|
|
4035
4034
|
}
|
|
4036
4035
|
return res;
|
|
4037
4036
|
};
|
|
4038
|
-
|
|
4037
|
+
BN4.prototype.gtn = function gtn(num) {
|
|
4039
4038
|
return this.cmpn(num) === 1;
|
|
4040
4039
|
};
|
|
4041
|
-
|
|
4040
|
+
BN4.prototype.gt = function gt(num) {
|
|
4042
4041
|
return this.cmp(num) === 1;
|
|
4043
4042
|
};
|
|
4044
|
-
|
|
4043
|
+
BN4.prototype.gten = function gten(num) {
|
|
4045
4044
|
return this.cmpn(num) >= 0;
|
|
4046
4045
|
};
|
|
4047
|
-
|
|
4046
|
+
BN4.prototype.gte = function gte(num) {
|
|
4048
4047
|
return this.cmp(num) >= 0;
|
|
4049
4048
|
};
|
|
4050
|
-
|
|
4049
|
+
BN4.prototype.ltn = function ltn(num) {
|
|
4051
4050
|
return this.cmpn(num) === -1;
|
|
4052
4051
|
};
|
|
4053
|
-
|
|
4052
|
+
BN4.prototype.lt = function lt(num) {
|
|
4054
4053
|
return this.cmp(num) === -1;
|
|
4055
4054
|
};
|
|
4056
|
-
|
|
4055
|
+
BN4.prototype.lten = function lten(num) {
|
|
4057
4056
|
return this.cmpn(num) <= 0;
|
|
4058
4057
|
};
|
|
4059
|
-
|
|
4058
|
+
BN4.prototype.lte = function lte(num) {
|
|
4060
4059
|
return this.cmp(num) <= 0;
|
|
4061
4060
|
};
|
|
4062
|
-
|
|
4061
|
+
BN4.prototype.eqn = function eqn(num) {
|
|
4063
4062
|
return this.cmpn(num) === 0;
|
|
4064
4063
|
};
|
|
4065
|
-
|
|
4064
|
+
BN4.prototype.eq = function eq(num) {
|
|
4066
4065
|
return this.cmp(num) === 0;
|
|
4067
4066
|
};
|
|
4068
|
-
|
|
4067
|
+
BN4.red = function red(num) {
|
|
4069
4068
|
return new Red(num);
|
|
4070
4069
|
};
|
|
4071
|
-
|
|
4070
|
+
BN4.prototype.toRed = function toRed(ctx) {
|
|
4072
4071
|
assert(!this.red, "Already a number in reduction context");
|
|
4073
4072
|
assert(this.negative === 0, "red works only with positives");
|
|
4074
4073
|
return ctx.convertTo(this)._forceRed(ctx);
|
|
4075
4074
|
};
|
|
4076
|
-
|
|
4075
|
+
BN4.prototype.fromRed = function fromRed() {
|
|
4077
4076
|
assert(this.red, "fromRed works only with numbers in reduction context");
|
|
4078
4077
|
return this.red.convertFrom(this);
|
|
4079
4078
|
};
|
|
4080
|
-
|
|
4079
|
+
BN4.prototype._forceRed = function _forceRed(ctx) {
|
|
4081
4080
|
this.red = ctx;
|
|
4082
4081
|
return this;
|
|
4083
4082
|
};
|
|
4084
|
-
|
|
4083
|
+
BN4.prototype.forceRed = function forceRed(ctx) {
|
|
4085
4084
|
assert(!this.red, "Already a number in reduction context");
|
|
4086
4085
|
return this._forceRed(ctx);
|
|
4087
4086
|
};
|
|
4088
|
-
|
|
4087
|
+
BN4.prototype.redAdd = function redAdd(num) {
|
|
4089
4088
|
assert(this.red, "redAdd works only with red numbers");
|
|
4090
4089
|
return this.red.add(this, num);
|
|
4091
4090
|
};
|
|
4092
|
-
|
|
4091
|
+
BN4.prototype.redIAdd = function redIAdd(num) {
|
|
4093
4092
|
assert(this.red, "redIAdd works only with red numbers");
|
|
4094
4093
|
return this.red.iadd(this, num);
|
|
4095
4094
|
};
|
|
4096
|
-
|
|
4095
|
+
BN4.prototype.redSub = function redSub(num) {
|
|
4097
4096
|
assert(this.red, "redSub works only with red numbers");
|
|
4098
4097
|
return this.red.sub(this, num);
|
|
4099
4098
|
};
|
|
4100
|
-
|
|
4099
|
+
BN4.prototype.redISub = function redISub(num) {
|
|
4101
4100
|
assert(this.red, "redISub works only with red numbers");
|
|
4102
4101
|
return this.red.isub(this, num);
|
|
4103
4102
|
};
|
|
4104
|
-
|
|
4103
|
+
BN4.prototype.redShl = function redShl(num) {
|
|
4105
4104
|
assert(this.red, "redShl works only with red numbers");
|
|
4106
4105
|
return this.red.shl(this, num);
|
|
4107
4106
|
};
|
|
4108
|
-
|
|
4107
|
+
BN4.prototype.redMul = function redMul(num) {
|
|
4109
4108
|
assert(this.red, "redMul works only with red numbers");
|
|
4110
4109
|
this.red._verify2(this, num);
|
|
4111
4110
|
return this.red.mul(this, num);
|
|
4112
4111
|
};
|
|
4113
|
-
|
|
4112
|
+
BN4.prototype.redIMul = function redIMul(num) {
|
|
4114
4113
|
assert(this.red, "redMul works only with red numbers");
|
|
4115
4114
|
this.red._verify2(this, num);
|
|
4116
4115
|
return this.red.imul(this, num);
|
|
4117
4116
|
};
|
|
4118
|
-
|
|
4117
|
+
BN4.prototype.redSqr = function redSqr() {
|
|
4119
4118
|
assert(this.red, "redSqr works only with red numbers");
|
|
4120
4119
|
this.red._verify1(this);
|
|
4121
4120
|
return this.red.sqr(this);
|
|
4122
4121
|
};
|
|
4123
|
-
|
|
4122
|
+
BN4.prototype.redISqr = function redISqr() {
|
|
4124
4123
|
assert(this.red, "redISqr works only with red numbers");
|
|
4125
4124
|
this.red._verify1(this);
|
|
4126
4125
|
return this.red.isqr(this);
|
|
4127
4126
|
};
|
|
4128
|
-
|
|
4127
|
+
BN4.prototype.redSqrt = function redSqrt() {
|
|
4129
4128
|
assert(this.red, "redSqrt works only with red numbers");
|
|
4130
4129
|
this.red._verify1(this);
|
|
4131
4130
|
return this.red.sqrt(this);
|
|
4132
4131
|
};
|
|
4133
|
-
|
|
4132
|
+
BN4.prototype.redInvm = function redInvm() {
|
|
4134
4133
|
assert(this.red, "redInvm works only with red numbers");
|
|
4135
4134
|
this.red._verify1(this);
|
|
4136
4135
|
return this.red.invm(this);
|
|
4137
4136
|
};
|
|
4138
|
-
|
|
4137
|
+
BN4.prototype.redNeg = function redNeg() {
|
|
4139
4138
|
assert(this.red, "redNeg works only with red numbers");
|
|
4140
4139
|
this.red._verify1(this);
|
|
4141
4140
|
return this.red.neg(this);
|
|
4142
4141
|
};
|
|
4143
|
-
|
|
4142
|
+
BN4.prototype.redPow = function redPow(num) {
|
|
4144
4143
|
assert(this.red && !num.red, "redPow(normalNum)");
|
|
4145
4144
|
this.red._verify1(this);
|
|
4146
4145
|
return this.red.pow(this, num);
|
|
@@ -4153,13 +4152,13 @@ var require_bn = __commonJS({
|
|
|
4153
4152
|
};
|
|
4154
4153
|
function MPrime(name, p) {
|
|
4155
4154
|
this.name = name;
|
|
4156
|
-
this.p = new
|
|
4155
|
+
this.p = new BN4(p, 16);
|
|
4157
4156
|
this.n = this.p.bitLength();
|
|
4158
|
-
this.k = new
|
|
4157
|
+
this.k = new BN4(1).iushln(this.n).isub(this.p);
|
|
4159
4158
|
this.tmp = this._tmp();
|
|
4160
4159
|
}
|
|
4161
4160
|
MPrime.prototype._tmp = function _tmp() {
|
|
4162
|
-
var tmp = new
|
|
4161
|
+
var tmp = new BN4(null);
|
|
4163
4162
|
tmp.words = new Array(Math.ceil(this.n / 13));
|
|
4164
4163
|
return tmp;
|
|
4165
4164
|
};
|
|
@@ -4285,7 +4284,7 @@ var require_bn = __commonJS({
|
|
|
4285
4284
|
}
|
|
4286
4285
|
return num;
|
|
4287
4286
|
};
|
|
4288
|
-
|
|
4287
|
+
BN4._prime = function prime(name) {
|
|
4289
4288
|
if (primes[name]) return primes[name];
|
|
4290
4289
|
var prime2;
|
|
4291
4290
|
if (name === "k256") {
|
|
@@ -4304,7 +4303,7 @@ var require_bn = __commonJS({
|
|
|
4304
4303
|
};
|
|
4305
4304
|
function Red(m) {
|
|
4306
4305
|
if (typeof m === "string") {
|
|
4307
|
-
var prime =
|
|
4306
|
+
var prime = BN4._prime(m);
|
|
4308
4307
|
this.m = prime.p;
|
|
4309
4308
|
this.prime = prime;
|
|
4310
4309
|
} else {
|
|
@@ -4390,7 +4389,7 @@ var require_bn = __commonJS({
|
|
|
4390
4389
|
var mod3 = this.m.andln(3);
|
|
4391
4390
|
assert(mod3 % 2 === 1);
|
|
4392
4391
|
if (mod3 === 3) {
|
|
4393
|
-
var pow = this.m.add(new
|
|
4392
|
+
var pow = this.m.add(new BN4(1)).iushrn(2);
|
|
4394
4393
|
return this.pow(a, pow);
|
|
4395
4394
|
}
|
|
4396
4395
|
var q = this.m.subn(1);
|
|
@@ -4400,11 +4399,11 @@ var require_bn = __commonJS({
|
|
|
4400
4399
|
q.iushrn(1);
|
|
4401
4400
|
}
|
|
4402
4401
|
assert(!q.isZero());
|
|
4403
|
-
var one = new
|
|
4402
|
+
var one = new BN4(1).toRed(this);
|
|
4404
4403
|
var nOne = one.redNeg();
|
|
4405
4404
|
var lpow = this.m.subn(1).iushrn(1);
|
|
4406
4405
|
var z = this.m.bitLength();
|
|
4407
|
-
z = new
|
|
4406
|
+
z = new BN4(2 * z * z).toRed(this);
|
|
4408
4407
|
while (this.pow(z, lpow).cmp(nOne) !== 0) {
|
|
4409
4408
|
z.redIAdd(nOne);
|
|
4410
4409
|
}
|
|
@@ -4418,7 +4417,7 @@ var require_bn = __commonJS({
|
|
|
4418
4417
|
tmp = tmp.redSqr();
|
|
4419
4418
|
}
|
|
4420
4419
|
assert(i < m);
|
|
4421
|
-
var b = this.pow(c, new
|
|
4420
|
+
var b = this.pow(c, new BN4(1).iushln(m - i - 1));
|
|
4422
4421
|
r = r.redMul(b);
|
|
4423
4422
|
c = b.redSqr();
|
|
4424
4423
|
t = t.redMul(c);
|
|
@@ -4436,11 +4435,11 @@ var require_bn = __commonJS({
|
|
|
4436
4435
|
}
|
|
4437
4436
|
};
|
|
4438
4437
|
Red.prototype.pow = function pow(a, num) {
|
|
4439
|
-
if (num.isZero()) return new
|
|
4438
|
+
if (num.isZero()) return new BN4(1).toRed(this);
|
|
4440
4439
|
if (num.cmpn(1) === 0) return a.clone();
|
|
4441
4440
|
var windowSize = 4;
|
|
4442
4441
|
var wnd = new Array(1 << windowSize);
|
|
4443
|
-
wnd[0] = new
|
|
4442
|
+
wnd[0] = new BN4(1).toRed(this);
|
|
4444
4443
|
wnd[1] = a;
|
|
4445
4444
|
for (var i = 2; i < wnd.length; i++) {
|
|
4446
4445
|
wnd[i] = this.mul(wnd[i - 1], a);
|
|
@@ -4484,7 +4483,7 @@ var require_bn = __commonJS({
|
|
|
4484
4483
|
res.red = null;
|
|
4485
4484
|
return res;
|
|
4486
4485
|
};
|
|
4487
|
-
|
|
4486
|
+
BN4.mont = function mont(num) {
|
|
4488
4487
|
return new Mont(num);
|
|
4489
4488
|
};
|
|
4490
4489
|
function Mont(m) {
|
|
@@ -4493,7 +4492,7 @@ var require_bn = __commonJS({
|
|
|
4493
4492
|
if (this.shift % 26 !== 0) {
|
|
4494
4493
|
this.shift += 26 - this.shift % 26;
|
|
4495
4494
|
}
|
|
4496
|
-
this.r = new
|
|
4495
|
+
this.r = new BN4(1).iushln(this.shift);
|
|
4497
4496
|
this.r2 = this.imod(this.r.sqr());
|
|
4498
4497
|
this.rinv = this.r._invmp(this.m);
|
|
4499
4498
|
this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
|
|
@@ -4527,7 +4526,7 @@ var require_bn = __commonJS({
|
|
|
4527
4526
|
return res._forceRed(this);
|
|
4528
4527
|
};
|
|
4529
4528
|
Mont.prototype.mul = function mul(a, b) {
|
|
4530
|
-
if (a.isZero() || b.isZero()) return new
|
|
4529
|
+
if (a.isZero() || b.isZero()) return new BN4(0)._forceRed(this);
|
|
4531
4530
|
var t = a.mul(b);
|
|
4532
4531
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
4533
4532
|
var u = t.isub(c).iushrn(this.shift);
|
|
@@ -4547,419 +4546,8 @@ var require_bn = __commonJS({
|
|
|
4547
4546
|
}
|
|
4548
4547
|
});
|
|
4549
4548
|
|
|
4550
|
-
// src/
|
|
4551
|
-
var
|
|
4552
|
-
var BaseBondAdapter = class {
|
|
4553
|
-
program;
|
|
4554
|
-
client;
|
|
4555
|
-
constructor(client) {
|
|
4556
|
-
this.client = client;
|
|
4557
|
-
this.program = client.program;
|
|
4558
|
-
}
|
|
4559
|
-
lamports(n) {
|
|
4560
|
-
return new BN((n ?? 0) * LAMPORTS_PER_SOL);
|
|
4561
|
-
}
|
|
4562
|
-
get pda() {
|
|
4563
|
-
return this.client.pda;
|
|
4564
|
-
}
|
|
4565
|
-
get connection() {
|
|
4566
|
-
return this.client.provider.connection;
|
|
4567
|
-
}
|
|
4568
|
-
};
|
|
4569
|
-
|
|
4570
|
-
// src/adapters/crowdfunding.ts
|
|
4571
|
-
var CrowdfundingBondAdapter = class extends BaseBondAdapter {
|
|
4572
|
-
async buildInitializeIx(props) {
|
|
4573
|
-
const [globalState] = this.pda.globalState();
|
|
4574
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4575
|
-
const accounts = {
|
|
4576
|
-
globalState,
|
|
4577
|
-
bondState,
|
|
4578
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey,
|
|
4579
|
-
reserve: props.reserve,
|
|
4580
|
-
systemProgram: SystemProgram.programId,
|
|
4581
|
-
tokenProgram: TOKEN_PROGRAM_ID$1,
|
|
4582
|
-
reserveTokenAccount: null,
|
|
4583
|
-
mint: null
|
|
4584
|
-
};
|
|
4585
|
-
if ("token" in props.collateralType) {
|
|
4586
|
-
accounts.reserveTokenAccount = getAssociatedTokenAddressSync(
|
|
4587
|
-
props.collateralType.token[0],
|
|
4588
|
-
props.reserve
|
|
4589
|
-
);
|
|
4590
|
-
accounts.mint = props.collateralType.token[0];
|
|
4591
|
-
}
|
|
4592
|
-
return this.program.methods.bondInitialize({
|
|
4593
|
-
name: props.name,
|
|
4594
|
-
bondType: props.bondType,
|
|
4595
|
-
reserve: props.reserve,
|
|
4596
|
-
collateralType: props.collateralType
|
|
4597
|
-
}).accountsPartial(
|
|
4598
|
-
accounts
|
|
4599
|
-
).instruction();
|
|
4600
|
-
}
|
|
4601
|
-
async buildConfigureIx(props) {
|
|
4602
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4603
|
-
return this.program.methods.bondConfigure({
|
|
4604
|
-
newReserve: props.newReserve ?? null,
|
|
4605
|
-
newAuthority: props.newAuthority ?? null
|
|
4606
|
-
}).accountsStrict({
|
|
4607
|
-
bondState,
|
|
4608
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey
|
|
4609
|
-
}).instruction();
|
|
4610
|
-
}
|
|
4611
|
-
async buildRegisterIx(props) {
|
|
4612
|
-
const { bondType, voteAccount, identity, name } = props;
|
|
4613
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4614
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4615
|
-
const creator = props.creator ?? this.program.provider.wallet?.publicKey;
|
|
4616
|
-
if (!creator) {
|
|
4617
|
-
throw new Error("Missing creator");
|
|
4618
|
-
}
|
|
4619
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4620
|
-
const acct = {
|
|
4621
|
-
bondState,
|
|
4622
|
-
validatorBond,
|
|
4623
|
-
identity,
|
|
4624
|
-
voteAccount,
|
|
4625
|
-
creator,
|
|
4626
|
-
systemProgram: SystemProgram.programId,
|
|
4627
|
-
tokenProgram: TOKEN_PROGRAM_ID$1,
|
|
4628
|
-
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
4629
|
-
bondTokenAccount: null,
|
|
4630
|
-
mint: null
|
|
4631
|
-
};
|
|
4632
|
-
if ("token" in collateralType) {
|
|
4633
|
-
const mint = collateralType.token[0];
|
|
4634
|
-
const bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4635
|
-
Object.assign(acct, { mint, bondTokenAccount });
|
|
4636
|
-
}
|
|
4637
|
-
return this.program.methods.bondRegister(bondType, name).accountsPartial(acct).instruction();
|
|
4638
|
-
}
|
|
4639
|
-
async buildTopUpIx(props) {
|
|
4640
|
-
const { bondType, voteAccount, collateral, name } = props;
|
|
4641
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4642
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4643
|
-
const payer = props.payer ?? this.program.provider.wallet?.publicKey;
|
|
4644
|
-
if (!payer) {
|
|
4645
|
-
throw new Error("Missing payer");
|
|
4646
|
-
}
|
|
4647
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4648
|
-
const accounts = {
|
|
4649
|
-
bondState,
|
|
4650
|
-
validatorBond,
|
|
4651
|
-
payer,
|
|
4652
|
-
systemProgram: SystemProgram.programId,
|
|
4653
|
-
payerTokenAccount: null,
|
|
4654
|
-
bondTokenAccount: null,
|
|
4655
|
-
stakeAccount: null,
|
|
4656
|
-
tokenProgram: null,
|
|
4657
|
-
associatedTokenProgram: null,
|
|
4658
|
-
stakeProgram: null
|
|
4659
|
-
};
|
|
4660
|
-
if ("token" in collateralType) {
|
|
4661
|
-
const mint = collateralType.token[0];
|
|
4662
|
-
accounts.payerTokenAccount = getAssociatedTokenAddressSync(mint, payer);
|
|
4663
|
-
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4664
|
-
accounts.tokenProgram = TOKEN_PROGRAM_ID$1;
|
|
4665
|
-
accounts.associatedTokenProgram = ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
4666
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4667
|
-
if (!collateral.stakeAccount) {
|
|
4668
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4669
|
-
}
|
|
4670
|
-
accounts.stakeAccount = collateral.stakeAccount;
|
|
4671
|
-
accounts.stakeProgram = StakeProgram.programId;
|
|
4672
|
-
}
|
|
4673
|
-
return this.program.methods.bondTopUp(this.lamports(collateral.amount)).accountsPartial(accounts).instruction();
|
|
4674
|
-
}
|
|
4675
|
-
async buildWithdrawIx(props) {
|
|
4676
|
-
const { bondType, voteAccount, withdraw, name } = props;
|
|
4677
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4678
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4679
|
-
const payer = this.program.provider.wallet?.publicKey;
|
|
4680
|
-
const destination = props.destination ?? payer;
|
|
4681
|
-
if (!payer || !destination) {
|
|
4682
|
-
throw new Error("Missing payer/destination");
|
|
4683
|
-
}
|
|
4684
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4685
|
-
const accounts = {
|
|
4686
|
-
bondState,
|
|
4687
|
-
validatorBond,
|
|
4688
|
-
withdrawalAuthority: props.withdrawalAuthority ?? payer,
|
|
4689
|
-
destination,
|
|
4690
|
-
destinationTokenAccount: null,
|
|
4691
|
-
bondTokenAccount: null,
|
|
4692
|
-
stakeAccount: null,
|
|
4693
|
-
systemProgram: SystemProgram.programId,
|
|
4694
|
-
tokenProgram: null,
|
|
4695
|
-
stakeProgram: null
|
|
4696
|
-
};
|
|
4697
|
-
if ("token" in collateralType) {
|
|
4698
|
-
const mint = collateralType.token[0];
|
|
4699
|
-
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, destination, true);
|
|
4700
|
-
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4701
|
-
accounts.tokenProgram = TOKEN_PROGRAM_ID$1;
|
|
4702
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4703
|
-
if (!withdraw.stakeAccount) {
|
|
4704
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4705
|
-
}
|
|
4706
|
-
accounts.stakeAccount = withdraw.stakeAccount;
|
|
4707
|
-
accounts.stakeProgram = StakeProgram.programId;
|
|
4708
|
-
}
|
|
4709
|
-
return this.program.methods.bondWithdraw(this.lamports(withdraw.amount)).accountsPartial(accounts).instruction();
|
|
4710
|
-
}
|
|
4711
|
-
async buildClaimIx(props) {
|
|
4712
|
-
const { claim, bondType, name } = props;
|
|
4713
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4714
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
4715
|
-
const reserve = props.reserve ?? (await this.client.getBondState(bondType, name)).reserve;
|
|
4716
|
-
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
4717
|
-
if (!reserve) {
|
|
4718
|
-
throw new Error("Reserve not set");
|
|
4719
|
-
}
|
|
4720
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4721
|
-
const accounts = {
|
|
4722
|
-
bondState,
|
|
4723
|
-
validatorBond,
|
|
4724
|
-
reserve,
|
|
4725
|
-
reserveTokenAccount: null,
|
|
4726
|
-
authority,
|
|
4727
|
-
bondTokenAccount: null,
|
|
4728
|
-
stakeAccount: null,
|
|
4729
|
-
systemProgram: SystemProgram.programId,
|
|
4730
|
-
tokenProgram: null,
|
|
4731
|
-
stakeProgram: null
|
|
4732
|
-
};
|
|
4733
|
-
if ("token" in collateralType) {
|
|
4734
|
-
const mint = collateralType.token[0];
|
|
4735
|
-
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
4736
|
-
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4737
|
-
accounts.reserveTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
4738
|
-
accounts.tokenProgram = TOKEN_PROGRAM_ID$1;
|
|
4739
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4740
|
-
if (!claim.stakeAccount) {
|
|
4741
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4742
|
-
}
|
|
4743
|
-
accounts.stakeAccount = claim.stakeAccount;
|
|
4744
|
-
accounts.stakeProgram = StakeProgram.programId;
|
|
4745
|
-
}
|
|
4746
|
-
return this.program.methods.bondClaim(this.lamports(props.claim.amount)).accountsPartial(
|
|
4747
|
-
accounts
|
|
4748
|
-
).instruction();
|
|
4749
|
-
}
|
|
4750
|
-
async buildSetWithdrawAuthorityIx(props) {
|
|
4751
|
-
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
4752
|
-
return this.program.methods.bondSetWithdrawAuthority().accountsPartial({
|
|
4753
|
-
validatorBond,
|
|
4754
|
-
identity: props.identity ?? this.program.provider.wallet?.publicKey,
|
|
4755
|
-
newWithdrawAuthority: props.newWithdrawAuthority ?? null
|
|
4756
|
-
}).instruction();
|
|
4757
|
-
}
|
|
4758
|
-
async buildBondFinishIx(_props) {
|
|
4759
|
-
throw new Error("Crowdfunding bond currently does not support finish operation");
|
|
4760
|
-
}
|
|
4761
|
-
async buildBondStartIx(props) {
|
|
4762
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4763
|
-
return this.program.methods.sessionStart(new import_bn.BN(props.duration_secs)).accountsPartial({
|
|
4764
|
-
bondState,
|
|
4765
|
-
authority: this.program.provider.wallet?.publicKey
|
|
4766
|
-
}).instruction();
|
|
4767
|
-
}
|
|
4768
|
-
};
|
|
4769
|
-
var PerformanceBondAdapter = class extends BaseBondAdapter {
|
|
4770
|
-
async buildInitializeIx(props) {
|
|
4771
|
-
const [globalState] = this.pda.globalState();
|
|
4772
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4773
|
-
const accounts = {
|
|
4774
|
-
globalState,
|
|
4775
|
-
bondState,
|
|
4776
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey,
|
|
4777
|
-
reserve: props.reserve,
|
|
4778
|
-
systemProgram: SystemProgram.programId,
|
|
4779
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
4780
|
-
reserveTokenAccount: null,
|
|
4781
|
-
mint: null
|
|
4782
|
-
};
|
|
4783
|
-
if ("token" in props.collateralType) {
|
|
4784
|
-
accounts.reserveTokenAccount = getAssociatedTokenAddressSync(
|
|
4785
|
-
props.collateralType.token[0],
|
|
4786
|
-
props.reserve
|
|
4787
|
-
);
|
|
4788
|
-
accounts.mint = props.collateralType.token[0];
|
|
4789
|
-
}
|
|
4790
|
-
return this.program.methods.bondInitialize({
|
|
4791
|
-
name: props.name,
|
|
4792
|
-
bondType: props.bondType,
|
|
4793
|
-
reserve: props.reserve,
|
|
4794
|
-
collateralType: props.collateralType
|
|
4795
|
-
}).accountsPartial(
|
|
4796
|
-
accounts
|
|
4797
|
-
).instruction();
|
|
4798
|
-
}
|
|
4799
|
-
async buildConfigureIx(props) {
|
|
4800
|
-
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
4801
|
-
return this.program.methods.bondConfigure({
|
|
4802
|
-
newReserve: props.newReserve ?? null,
|
|
4803
|
-
newAuthority: props.newAuthority ?? null
|
|
4804
|
-
}).accountsStrict({
|
|
4805
|
-
bondState,
|
|
4806
|
-
authority: props.authority ?? this.program.provider.wallet?.publicKey
|
|
4807
|
-
}).instruction();
|
|
4808
|
-
}
|
|
4809
|
-
async buildRegisterIx(props) {
|
|
4810
|
-
const { bondType, voteAccount, identity, name } = props;
|
|
4811
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4812
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4813
|
-
const creator = props.creator ?? this.program.provider.wallet?.publicKey;
|
|
4814
|
-
if (!creator) {
|
|
4815
|
-
throw new Error("Missing creator");
|
|
4816
|
-
}
|
|
4817
|
-
const bondStateData = await this.client.getBondState(bondType, name);
|
|
4818
|
-
const acct = {
|
|
4819
|
-
bondState,
|
|
4820
|
-
validatorBond,
|
|
4821
|
-
identity,
|
|
4822
|
-
voteAccount,
|
|
4823
|
-
creator,
|
|
4824
|
-
systemProgram: SystemProgram.programId,
|
|
4825
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
4826
|
-
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
4827
|
-
bondTokenAccount: null,
|
|
4828
|
-
mint: null
|
|
4829
|
-
};
|
|
4830
|
-
if ("token" in bondStateData.collateralType) {
|
|
4831
|
-
const mint = bondStateData.collateralType.token[0];
|
|
4832
|
-
const bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4833
|
-
Object.assign(acct, { mint, bondTokenAccount });
|
|
4834
|
-
}
|
|
4835
|
-
return this.program.methods.bondRegister(bondType, name).accountsPartial(acct).instruction();
|
|
4836
|
-
}
|
|
4837
|
-
async buildTopUpIx(props) {
|
|
4838
|
-
const { bondType, voteAccount, collateral, name } = props;
|
|
4839
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4840
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4841
|
-
const payer = props.payer ?? this.program.provider.wallet?.publicKey;
|
|
4842
|
-
if (!payer) {
|
|
4843
|
-
throw new Error("Missing payer");
|
|
4844
|
-
}
|
|
4845
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4846
|
-
const accounts = {
|
|
4847
|
-
bondState,
|
|
4848
|
-
validatorBond,
|
|
4849
|
-
payer,
|
|
4850
|
-
systemProgram: SystemProgram.programId,
|
|
4851
|
-
payerTokenAccount: null,
|
|
4852
|
-
bondTokenAccount: null,
|
|
4853
|
-
stakeAccount: null,
|
|
4854
|
-
tokenProgram: null,
|
|
4855
|
-
associatedTokenProgram: null,
|
|
4856
|
-
stakeProgram: null
|
|
4857
|
-
};
|
|
4858
|
-
if ("token" in collateralType) {
|
|
4859
|
-
const mint = collateralType.token[0];
|
|
4860
|
-
accounts.payerTokenAccount = getAssociatedTokenAddressSync(mint, payer);
|
|
4861
|
-
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4862
|
-
accounts.tokenProgram = TOKEN_PROGRAM_ID;
|
|
4863
|
-
accounts.associatedTokenProgram = ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
4864
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4865
|
-
if (!collateral.stakeAccount) {
|
|
4866
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4867
|
-
}
|
|
4868
|
-
accounts.stakeAccount = collateral.stakeAccount;
|
|
4869
|
-
accounts.stakeProgram = StakeProgram.programId;
|
|
4870
|
-
}
|
|
4871
|
-
return this.program.methods.bondTopUp(this.lamports(collateral.amount)).accountsPartial(accounts).instruction();
|
|
4872
|
-
}
|
|
4873
|
-
async buildWithdrawIx(props) {
|
|
4874
|
-
const { bondType, voteAccount, withdraw, name } = props;
|
|
4875
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4876
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
4877
|
-
const payer = this.program.provider.wallet?.publicKey;
|
|
4878
|
-
const destination = props.destination ?? payer;
|
|
4879
|
-
if (!payer || !destination) {
|
|
4880
|
-
throw new Error("Missing payer/destination");
|
|
4881
|
-
}
|
|
4882
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4883
|
-
const accounts = {
|
|
4884
|
-
bondState,
|
|
4885
|
-
validatorBond,
|
|
4886
|
-
withdrawalAuthority: props.withdrawalAuthority ?? payer,
|
|
4887
|
-
destination,
|
|
4888
|
-
destinationTokenAccount: null,
|
|
4889
|
-
bondTokenAccount: null,
|
|
4890
|
-
stakeAccount: null,
|
|
4891
|
-
systemProgram: SystemProgram.programId,
|
|
4892
|
-
tokenProgram: null,
|
|
4893
|
-
stakeProgram: null
|
|
4894
|
-
};
|
|
4895
|
-
if ("token" in collateralType) {
|
|
4896
|
-
const mint = collateralType.token[0];
|
|
4897
|
-
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, destination, true);
|
|
4898
|
-
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4899
|
-
accounts.tokenProgram = TOKEN_PROGRAM_ID;
|
|
4900
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4901
|
-
if (!withdraw.stakeAccount) {
|
|
4902
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4903
|
-
}
|
|
4904
|
-
accounts.stakeAccount = withdraw.stakeAccount;
|
|
4905
|
-
accounts.stakeProgram = StakeProgram.programId;
|
|
4906
|
-
}
|
|
4907
|
-
return this.program.methods.bondWithdraw(this.lamports(withdraw.amount)).accountsPartial(accounts).instruction();
|
|
4908
|
-
}
|
|
4909
|
-
async buildClaimIx(props) {
|
|
4910
|
-
const { claim, bondType, name } = props;
|
|
4911
|
-
const [bondState] = this.pda.bondState(bondType, name);
|
|
4912
|
-
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
4913
|
-
const reserve = props.reserve ?? (await this.client.getBondState(bondType, name)).reserve;
|
|
4914
|
-
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
4915
|
-
if (!reserve) {
|
|
4916
|
-
throw new Error("Reserve not set");
|
|
4917
|
-
}
|
|
4918
|
-
const collateralType = (await this.client.getBondState(bondType, name)).collateralType;
|
|
4919
|
-
const accounts = {
|
|
4920
|
-
bondState,
|
|
4921
|
-
validatorBond,
|
|
4922
|
-
reserve,
|
|
4923
|
-
reserveTokenAccount: null,
|
|
4924
|
-
authority,
|
|
4925
|
-
bondTokenAccount: null,
|
|
4926
|
-
stakeAccount: null,
|
|
4927
|
-
systemProgram: SystemProgram.programId,
|
|
4928
|
-
tokenProgram: null,
|
|
4929
|
-
stakeProgram: null
|
|
4930
|
-
};
|
|
4931
|
-
if ("token" in collateralType) {
|
|
4932
|
-
const mint = collateralType.token[0];
|
|
4933
|
-
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
4934
|
-
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
4935
|
-
accounts.reserveTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
4936
|
-
accounts.tokenProgram = TOKEN_PROGRAM_ID;
|
|
4937
|
-
} else if ("stakeAccount" in collateralType) {
|
|
4938
|
-
if (!claim.stakeAccount) {
|
|
4939
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
4940
|
-
}
|
|
4941
|
-
accounts.stakeAccount = claim.stakeAccount;
|
|
4942
|
-
accounts.stakeProgram = StakeProgram.programId;
|
|
4943
|
-
}
|
|
4944
|
-
return this.program.methods.bondClaim(this.lamports(props.claim.amount)).accountsPartial(
|
|
4945
|
-
accounts
|
|
4946
|
-
).instruction();
|
|
4947
|
-
}
|
|
4948
|
-
async buildSetWithdrawAuthorityIx(props) {
|
|
4949
|
-
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
4950
|
-
return this.program.methods.bondSetWithdrawAuthority().accountsPartial({
|
|
4951
|
-
validatorBond,
|
|
4952
|
-
identity: props.identity ?? this.program.provider.wallet?.publicKey,
|
|
4953
|
-
newWithdrawAuthority: props.newWithdrawAuthority ?? null
|
|
4954
|
-
}).instruction();
|
|
4955
|
-
}
|
|
4956
|
-
async buildBondFinishIx(_props) {
|
|
4957
|
-
throw new Error("Performance bond currently does not support finish operation");
|
|
4958
|
-
}
|
|
4959
|
-
async buildBondStartIx(_props) {
|
|
4960
|
-
throw new Error("Performance bond currently does not support start operation");
|
|
4961
|
-
}
|
|
4962
|
-
};
|
|
4549
|
+
// src/client.ts
|
|
4550
|
+
var import_bn2 = __toESM(require_bn());
|
|
4963
4551
|
var JPOOL_STAKE_POOL = new PublicKey("CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1");
|
|
4964
4552
|
var Seeds = /* @__PURE__ */ ((Seeds2) => {
|
|
4965
4553
|
Seeds2["GlobalState"] = "global_state";
|
|
@@ -6679,7 +6267,7 @@ var jbond_default = {
|
|
|
6679
6267
|
};
|
|
6680
6268
|
|
|
6681
6269
|
// src/utils/stake-pool.ts
|
|
6682
|
-
var
|
|
6270
|
+
var import_bn = __toESM(require_bn());
|
|
6683
6271
|
function createStakePoolManager(stakePoolAccount, user) {
|
|
6684
6272
|
if (!stakePoolAccount || !stakePoolAccount.account || !stakePoolAccount.account.data) {
|
|
6685
6273
|
throw new Error("Invalid stake pool account structure");
|
|
@@ -6715,8 +6303,8 @@ function createStakePoolManager(stakePoolAccount, user) {
|
|
|
6715
6303
|
poolTokens: poolTokens.toNumber()
|
|
6716
6304
|
}),
|
|
6717
6305
|
get exchangeRate() {
|
|
6718
|
-
const poolTokenSupply = new
|
|
6719
|
-
const totalLamports = new
|
|
6306
|
+
const poolTokenSupply = new import_bn.default(stakePool.poolTokenSupply);
|
|
6307
|
+
const totalLamports = new import_bn.default(stakePool.totalLamports);
|
|
6720
6308
|
if (poolTokenSupply.isZero()) {
|
|
6721
6309
|
return 0;
|
|
6722
6310
|
}
|
|
@@ -6789,15 +6377,6 @@ var JBondClient = class _JBondClient {
|
|
|
6789
6377
|
this.options[key] = val;
|
|
6790
6378
|
return this;
|
|
6791
6379
|
}
|
|
6792
|
-
getAdapter(bondType) {
|
|
6793
|
-
if ("performance" in bondType) {
|
|
6794
|
-
return new PerformanceBondAdapter(this);
|
|
6795
|
-
}
|
|
6796
|
-
if ("crowdfunding" in bondType) {
|
|
6797
|
-
return new CrowdfundingBondAdapter(this);
|
|
6798
|
-
}
|
|
6799
|
-
throw new Error(`Unsupported bond type: ${JSON.stringify(bondType)}`);
|
|
6800
|
-
}
|
|
6801
6380
|
getBondTypeSeed(bondType) {
|
|
6802
6381
|
if ("performance" in bondType) {
|
|
6803
6382
|
return "performance" /* PerformanceBond */;
|
|
@@ -6838,7 +6417,7 @@ var JBondClient = class _JBondClient {
|
|
|
6838
6417
|
}
|
|
6839
6418
|
};
|
|
6840
6419
|
async globalInitialize(props) {
|
|
6841
|
-
const ix = await this.
|
|
6420
|
+
const ix = await this.buildBondGlobalStateInitializeIx(props);
|
|
6842
6421
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6843
6422
|
}
|
|
6844
6423
|
/**
|
|
@@ -6847,7 +6426,7 @@ var JBondClient = class _JBondClient {
|
|
|
6847
6426
|
*/
|
|
6848
6427
|
async bondInitialize(props) {
|
|
6849
6428
|
console.log("Building bond initialize instruction with props:", props);
|
|
6850
|
-
const ix = await this.
|
|
6429
|
+
const ix = await this.buildBondInitializeIx(props);
|
|
6851
6430
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6852
6431
|
}
|
|
6853
6432
|
/**
|
|
@@ -6855,7 +6434,7 @@ var JBondClient = class _JBondClient {
|
|
|
6855
6434
|
* Default creator is the provider's wallet
|
|
6856
6435
|
*/
|
|
6857
6436
|
async registerValidator(props) {
|
|
6858
|
-
const ix = await this.
|
|
6437
|
+
const ix = await this.buildRegisterIx(props);
|
|
6859
6438
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6860
6439
|
}
|
|
6861
6440
|
/**
|
|
@@ -6863,8 +6442,8 @@ var JBondClient = class _JBondClient {
|
|
|
6863
6442
|
* Default payer is the provider's wallet
|
|
6864
6443
|
*/
|
|
6865
6444
|
async topUpCollateral(props) {
|
|
6866
|
-
const
|
|
6867
|
-
return this.provider.sendAndConfirm?.(new Transaction().add(
|
|
6445
|
+
const ixs = await this.buildTopUpIXs(props);
|
|
6446
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(...ixs));
|
|
6868
6447
|
}
|
|
6869
6448
|
/**
|
|
6870
6449
|
* Withdraw collateral
|
|
@@ -6873,7 +6452,7 @@ var JBondClient = class _JBondClient {
|
|
|
6873
6452
|
* @return Transaction signature
|
|
6874
6453
|
*/
|
|
6875
6454
|
async withdrawCollateral(props) {
|
|
6876
|
-
const ix = await this.
|
|
6455
|
+
const ix = await this.buildWithdrawIx(props);
|
|
6877
6456
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6878
6457
|
}
|
|
6879
6458
|
/**
|
|
@@ -6882,7 +6461,7 @@ var JBondClient = class _JBondClient {
|
|
|
6882
6461
|
* @return Transaction signature
|
|
6883
6462
|
*/
|
|
6884
6463
|
async claimCompensation(props) {
|
|
6885
|
-
const ix = await this.
|
|
6464
|
+
const ix = await this.buildClaimIx(props);
|
|
6886
6465
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6887
6466
|
}
|
|
6888
6467
|
/**
|
|
@@ -6902,7 +6481,7 @@ var JBondClient = class _JBondClient {
|
|
|
6902
6481
|
* @return Transaction signature
|
|
6903
6482
|
*/
|
|
6904
6483
|
async bondConfigure(props) {
|
|
6905
|
-
const ix = await this.
|
|
6484
|
+
const ix = await this.buildConfigureIx(props);
|
|
6906
6485
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6907
6486
|
}
|
|
6908
6487
|
/**
|
|
@@ -6912,18 +6491,18 @@ var JBondClient = class _JBondClient {
|
|
|
6912
6491
|
* @return Transaction signature
|
|
6913
6492
|
*/
|
|
6914
6493
|
async setWithdrawAuthority(props) {
|
|
6915
|
-
const ix = await this.
|
|
6494
|
+
const ix = await this.buildSetWithdrawAuthorityIx(props);
|
|
6916
6495
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6917
6496
|
}
|
|
6918
6497
|
async bondStart(props) {
|
|
6919
|
-
const ix = await this.
|
|
6498
|
+
const ix = await this.buildBondStartIx(props);
|
|
6920
6499
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6921
6500
|
}
|
|
6922
6501
|
async bondFinish(props) {
|
|
6923
|
-
const ix = await this.
|
|
6502
|
+
const ix = await this.buildBondFinishIx(props);
|
|
6924
6503
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6925
6504
|
}
|
|
6926
|
-
async
|
|
6505
|
+
async buildBondGlobalStateInitializeIx(props) {
|
|
6927
6506
|
const [globalState] = this.pda.globalState();
|
|
6928
6507
|
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
6929
6508
|
return this.program.methods.globalInitialize().accountsPartial({
|
|
@@ -6947,50 +6526,214 @@ var JBondClient = class _JBondClient {
|
|
|
6947
6526
|
/**
|
|
6948
6527
|
* Build initialize instruction
|
|
6949
6528
|
*/
|
|
6950
|
-
async
|
|
6951
|
-
|
|
6529
|
+
async buildBondInitializeIx(props) {
|
|
6530
|
+
const [globalState] = this.pda.globalState();
|
|
6531
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6532
|
+
const accounts = {
|
|
6533
|
+
globalState,
|
|
6534
|
+
bondState,
|
|
6535
|
+
authority: props.authority ?? this.program.provider.wallet?.publicKey,
|
|
6536
|
+
reserve: props.reserve,
|
|
6537
|
+
systemProgram: SystemProgram.programId,
|
|
6538
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
6539
|
+
reserveTokenAccount: null,
|
|
6540
|
+
mint: null
|
|
6541
|
+
};
|
|
6542
|
+
if ("token" in props.collateralType) {
|
|
6543
|
+
accounts.reserveTokenAccount = getAssociatedTokenAddressSync(
|
|
6544
|
+
props.collateralType.token[0],
|
|
6545
|
+
props.reserve
|
|
6546
|
+
);
|
|
6547
|
+
accounts.mint = props.collateralType.token[0];
|
|
6548
|
+
}
|
|
6549
|
+
return this.program.methods.bondInitialize({
|
|
6550
|
+
name: props.name,
|
|
6551
|
+
bondType: props.bondType,
|
|
6552
|
+
reserve: props.reserve,
|
|
6553
|
+
collateralType: props.collateralType
|
|
6554
|
+
}).accountsPartial(
|
|
6555
|
+
accounts
|
|
6556
|
+
).instruction();
|
|
6952
6557
|
}
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
|
|
6558
|
+
async buildConfigureIx(props) {
|
|
6559
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6560
|
+
return this.program.methods.bondConfigure({
|
|
6561
|
+
newReserve: props.newReserve ?? null,
|
|
6562
|
+
newAuthority: props.newAuthority ?? null
|
|
6563
|
+
}).accountsStrict({
|
|
6564
|
+
bondState,
|
|
6565
|
+
authority: props.authority ?? this.program.provider.wallet?.publicKey
|
|
6566
|
+
}).instruction();
|
|
6958
6567
|
}
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6568
|
+
async buildRegisterIx(props) {
|
|
6569
|
+
const { bondType, voteAccount, identity, name } = props;
|
|
6570
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
6571
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6572
|
+
const creator = props.creator ?? this.program.provider.wallet?.publicKey;
|
|
6573
|
+
if (!creator) {
|
|
6574
|
+
throw new Error("Missing creator");
|
|
6575
|
+
}
|
|
6576
|
+
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6577
|
+
const acct = {
|
|
6578
|
+
bondState,
|
|
6579
|
+
validatorBond,
|
|
6580
|
+
identity,
|
|
6581
|
+
voteAccount,
|
|
6582
|
+
creator,
|
|
6583
|
+
systemProgram: SystemProgram.programId,
|
|
6584
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
6585
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
6586
|
+
bondTokenAccount: null,
|
|
6587
|
+
mint: null
|
|
6588
|
+
};
|
|
6589
|
+
if ("token" in collateralType) {
|
|
6590
|
+
const mint = collateralType.token[0];
|
|
6591
|
+
const bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6592
|
+
Object.assign(acct, { mint, bondTokenAccount });
|
|
6593
|
+
}
|
|
6594
|
+
return this.program.methods.bondRegister(bondType, name).accountsPartial(acct).instruction();
|
|
6964
6595
|
}
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6596
|
+
async buildTopUpIXs(props) {
|
|
6597
|
+
const { bondType, voteAccount, collateral, name } = props;
|
|
6598
|
+
const payer = props.payer ?? this.program.provider.wallet?.publicKey;
|
|
6599
|
+
if (!payer) {
|
|
6600
|
+
throw new Error("Missing payer");
|
|
6601
|
+
}
|
|
6602
|
+
const instructions = [];
|
|
6603
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
6604
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6605
|
+
const bond = await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
|
|
6606
|
+
if (!bond) {
|
|
6607
|
+
instructions.push(await this.buildRegisterIx({
|
|
6608
|
+
bondType: props.bondType,
|
|
6609
|
+
name: props.name,
|
|
6610
|
+
voteAccount: props.voteAccount,
|
|
6611
|
+
identity: props.identity
|
|
6612
|
+
}));
|
|
6613
|
+
}
|
|
6614
|
+
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6615
|
+
const accounts = {
|
|
6616
|
+
bondState,
|
|
6617
|
+
validatorBond,
|
|
6618
|
+
payer,
|
|
6619
|
+
systemProgram: SystemProgram.programId,
|
|
6620
|
+
payerTokenAccount: null,
|
|
6621
|
+
bondTokenAccount: null,
|
|
6622
|
+
stakeAccount: null,
|
|
6623
|
+
tokenProgram: null,
|
|
6624
|
+
associatedTokenProgram: null,
|
|
6625
|
+
stakeProgram: null
|
|
6626
|
+
};
|
|
6627
|
+
if ("token" in collateralType) {
|
|
6628
|
+
const mint = collateralType.token[0];
|
|
6629
|
+
accounts.payerTokenAccount = getAssociatedTokenAddressSync(mint, payer);
|
|
6630
|
+
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6631
|
+
accounts.tokenProgram = TOKEN_PROGRAM_ID;
|
|
6632
|
+
accounts.associatedTokenProgram = ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
6633
|
+
} else if ("stakeAccount" in collateralType) {
|
|
6634
|
+
if (!collateral.stakeAccount) {
|
|
6635
|
+
throw new Error("Missing stakeAccount for stake collateral");
|
|
6636
|
+
}
|
|
6637
|
+
accounts.stakeAccount = collateral.stakeAccount;
|
|
6638
|
+
accounts.stakeProgram = StakeProgram.programId;
|
|
6639
|
+
}
|
|
6640
|
+
instructions.push(
|
|
6641
|
+
await this.program.methods.bondTopUp(this.lamports(collateral.amount)).accountsPartial(accounts).instruction()
|
|
6642
|
+
);
|
|
6643
|
+
return instructions;
|
|
6970
6644
|
}
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6645
|
+
async buildWithdrawIx(props) {
|
|
6646
|
+
const { bondType, voteAccount, withdraw, name } = props;
|
|
6647
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
6648
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
6649
|
+
const payer = this.program.provider.wallet?.publicKey;
|
|
6650
|
+
const destination = props.destination ?? payer;
|
|
6651
|
+
if (!payer || !destination) {
|
|
6652
|
+
throw new Error("Missing payer/destination");
|
|
6653
|
+
}
|
|
6654
|
+
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6655
|
+
const accounts = {
|
|
6656
|
+
bondState,
|
|
6657
|
+
validatorBond,
|
|
6658
|
+
withdrawalAuthority: props.withdrawalAuthority ?? payer,
|
|
6659
|
+
destination,
|
|
6660
|
+
destinationTokenAccount: null,
|
|
6661
|
+
bondTokenAccount: null,
|
|
6662
|
+
stakeAccount: null,
|
|
6663
|
+
systemProgram: SystemProgram.programId,
|
|
6664
|
+
tokenProgram: null,
|
|
6665
|
+
stakeProgram: null
|
|
6666
|
+
};
|
|
6667
|
+
if ("token" in collateralType) {
|
|
6668
|
+
const mint = collateralType.token[0];
|
|
6669
|
+
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, destination, true);
|
|
6670
|
+
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6671
|
+
accounts.tokenProgram = TOKEN_PROGRAM_ID;
|
|
6672
|
+
} else if ("stakeAccount" in collateralType) {
|
|
6673
|
+
if (!withdraw.stakeAccount) {
|
|
6674
|
+
throw new Error("Missing stakeAccount for stake collateral");
|
|
6675
|
+
}
|
|
6676
|
+
accounts.stakeAccount = withdraw.stakeAccount;
|
|
6677
|
+
accounts.stakeProgram = StakeProgram.programId;
|
|
6678
|
+
}
|
|
6679
|
+
return this.program.methods.bondWithdraw(this.lamports(withdraw.amount)).accountsPartial(accounts).instruction();
|
|
6976
6680
|
}
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6681
|
+
async buildClaimIx(props) {
|
|
6682
|
+
const { claim, bondType, name } = props;
|
|
6683
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
6684
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
6685
|
+
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).reserve;
|
|
6686
|
+
const authority = props.authority ?? this.program.provider.wallet?.publicKey;
|
|
6687
|
+
if (!reserve) {
|
|
6688
|
+
throw new Error("Reserve not set");
|
|
6689
|
+
}
|
|
6690
|
+
const collateralType = (await this.getBondState(bondType, name)).collateralType;
|
|
6691
|
+
const accounts = {
|
|
6692
|
+
bondState,
|
|
6693
|
+
validatorBond,
|
|
6694
|
+
reserve,
|
|
6695
|
+
reserveTokenAccount: null,
|
|
6696
|
+
authority,
|
|
6697
|
+
bondTokenAccount: null,
|
|
6698
|
+
stakeAccount: null,
|
|
6699
|
+
systemProgram: SystemProgram.programId,
|
|
6700
|
+
tokenProgram: null,
|
|
6701
|
+
stakeProgram: null
|
|
6702
|
+
};
|
|
6703
|
+
if ("token" in collateralType) {
|
|
6704
|
+
const mint = collateralType.token[0];
|
|
6705
|
+
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6706
|
+
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6707
|
+
accounts.reserveTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6708
|
+
accounts.tokenProgram = TOKEN_PROGRAM_ID;
|
|
6709
|
+
} else if ("stakeAccount" in collateralType) {
|
|
6710
|
+
if (!claim.stakeAccount) {
|
|
6711
|
+
throw new Error("Missing stakeAccount for stake collateral");
|
|
6712
|
+
}
|
|
6713
|
+
accounts.stakeAccount = claim.stakeAccount;
|
|
6714
|
+
accounts.stakeProgram = StakeProgram.programId;
|
|
6715
|
+
}
|
|
6716
|
+
return this.program.methods.bondClaim(this.lamports(props.claim.amount)).accountsPartial(
|
|
6717
|
+
accounts
|
|
6718
|
+
).instruction();
|
|
6982
6719
|
}
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6720
|
+
async buildSetWithdrawAuthorityIx(props) {
|
|
6721
|
+
const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
|
|
6722
|
+
return this.program.methods.bondSetWithdrawAuthority().accountsPartial({
|
|
6723
|
+
validatorBond,
|
|
6724
|
+
identity: props.identity ?? this.program.provider.wallet?.publicKey,
|
|
6725
|
+
newWithdrawAuthority: props.newWithdrawAuthority ?? null
|
|
6726
|
+
}).instruction();
|
|
6988
6727
|
}
|
|
6989
|
-
|
|
6990
|
-
|
|
6728
|
+
async buildBondFinishIx(_props) {
|
|
6729
|
+
throw new Error("Crowdfunding bond currently does not support finish operation");
|
|
6991
6730
|
}
|
|
6992
|
-
|
|
6993
|
-
|
|
6731
|
+
async buildBondStartIx(props) {
|
|
6732
|
+
const [bondState] = this.pda.bondState(props.bondType, props.name);
|
|
6733
|
+
return this.program.methods.sessionStart(new import_bn2.BN(props.duration_secs)).accountsPartial({
|
|
6734
|
+
bondState,
|
|
6735
|
+
authority: this.program.provider.wallet?.publicKey
|
|
6736
|
+
}).instruction();
|
|
6994
6737
|
}
|
|
6995
6738
|
/**
|
|
6996
6739
|
* Fetch global state or throw if not found
|
|
@@ -7048,7 +6791,11 @@ var JBondClient = class _JBondClient {
|
|
|
7048
6791
|
*/
|
|
7049
6792
|
async getValidatorBond(bondType, bondName, vote) {
|
|
7050
6793
|
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
7051
|
-
|
|
6794
|
+
try {
|
|
6795
|
+
return await this.program.account.validatorBond.fetch(address);
|
|
6796
|
+
} catch {
|
|
6797
|
+
return null;
|
|
6798
|
+
}
|
|
7052
6799
|
}
|
|
7053
6800
|
/**
|
|
7054
6801
|
* Get bond collateral type
|
|
@@ -7074,7 +6821,7 @@ var JBondClient = class _JBondClient {
|
|
|
7074
6821
|
const balance = await this.connection.getTokenAccountBalance(tokenAccount);
|
|
7075
6822
|
return Number(balance.value.uiAmount ?? 0);
|
|
7076
6823
|
}
|
|
7077
|
-
const accountInfo = await this.connection.getAccountInfo(address);
|
|
6824
|
+
const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
|
|
7078
6825
|
if (!accountInfo) {
|
|
7079
6826
|
return 0;
|
|
7080
6827
|
}
|
|
@@ -7110,6 +6857,9 @@ var JBondClient = class _JBondClient {
|
|
|
7110
6857
|
}
|
|
7111
6858
|
return user;
|
|
7112
6859
|
}
|
|
6860
|
+
lamports(n) {
|
|
6861
|
+
return new import_bn2.BN((n ?? 0) * LAMPORTS_PER_SOL);
|
|
6862
|
+
}
|
|
7113
6863
|
};
|
|
7114
6864
|
/*! Bundled license information:
|
|
7115
6865
|
|