@jpool/bond-sdk 0.10.3 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import { utils, Program, AnchorProvider, BN } from '@coral-xyz/anchor';
2
- import { TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, ACCOUNT_SIZE, AccountLayout } from '@solana/spl-token';
3
- import { PublicKey, Transaction, SystemProgram, LAMPORTS_PER_SOL } from '@solana/web3.js';
4
- import bs58 from 'bs58';
2
+ import { getAssociatedTokenAddressSync, ACCOUNT_SIZE, AccountLayout } from '@solana/spl-token';
3
+ import { PublicKey, Transaction, LAMPORTS_PER_SOL } from '@solana/web3.js';
5
4
 
6
5
  var __create = Object.create;
7
6
  var __defProp = Object.defineProperty;
@@ -1816,8 +1815,8 @@ var require_bn = __commonJS({
1816
1815
  ctor.prototype = new TempCtor();
1817
1816
  ctor.prototype.constructor = ctor;
1818
1817
  }
1819
- function BN3(number, base, endian) {
1820
- if (BN3.isBN(number)) {
1818
+ function BN4(number, base, endian) {
1819
+ if (BN4.isBN(number)) {
1821
1820
  return number;
1822
1821
  }
1823
1822
  this.negative = 0;
@@ -1833,12 +1832,12 @@ var require_bn = __commonJS({
1833
1832
  }
1834
1833
  }
1835
1834
  if (typeof module2 === "object") {
1836
- module2.exports = BN3;
1835
+ module2.exports = BN4;
1837
1836
  } else {
1838
- exports2.BN = BN3;
1837
+ exports2.BN = BN4;
1839
1838
  }
1840
- BN3.BN = BN3;
1841
- BN3.wordSize = 26;
1839
+ BN4.BN = BN4;
1840
+ BN4.wordSize = 26;
1842
1841
  var Buffer2;
1843
1842
  try {
1844
1843
  if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
@@ -1848,21 +1847,21 @@ var require_bn = __commonJS({
1848
1847
  }
1849
1848
  } catch (e) {
1850
1849
  }
1851
- BN3.isBN = function isBN(num) {
1852
- if (num instanceof BN3) {
1850
+ BN4.isBN = function isBN(num) {
1851
+ if (num instanceof BN4) {
1853
1852
  return true;
1854
1853
  }
1855
- return num !== null && typeof num === "object" && num.constructor.wordSize === BN3.wordSize && Array.isArray(num.words);
1854
+ return num !== null && typeof num === "object" && num.constructor.wordSize === BN4.wordSize && Array.isArray(num.words);
1856
1855
  };
1857
- BN3.max = function max(left, right) {
1856
+ BN4.max = function max(left, right) {
1858
1857
  if (left.cmp(right) > 0) return left;
1859
1858
  return right;
1860
1859
  };
1861
- BN3.min = function min(left, right) {
1860
+ BN4.min = function min(left, right) {
1862
1861
  if (left.cmp(right) < 0) return left;
1863
1862
  return right;
1864
1863
  };
1865
- BN3.prototype._init = function init(number, base, endian) {
1864
+ BN4.prototype._init = function init(number, base, endian) {
1866
1865
  if (typeof number === "number") {
1867
1866
  return this._initNumber(number, base, endian);
1868
1867
  }
@@ -1890,7 +1889,7 @@ var require_bn = __commonJS({
1890
1889
  }
1891
1890
  }
1892
1891
  };
1893
- BN3.prototype._initNumber = function _initNumber(number, base, endian) {
1892
+ BN4.prototype._initNumber = function _initNumber(number, base, endian) {
1894
1893
  if (number < 0) {
1895
1894
  this.negative = 1;
1896
1895
  number = -number;
@@ -1916,7 +1915,7 @@ var require_bn = __commonJS({
1916
1915
  if (endian !== "le") return;
1917
1916
  this._initArray(this.toArray(), base, endian);
1918
1917
  };
1919
- BN3.prototype._initArray = function _initArray(number, base, endian) {
1918
+ BN4.prototype._initArray = function _initArray(number, base, endian) {
1920
1919
  assert(typeof number.length === "number");
1921
1920
  if (number.length <= 0) {
1922
1921
  this.words = [0];
@@ -1974,7 +1973,7 @@ var require_bn = __commonJS({
1974
1973
  }
1975
1974
  return r;
1976
1975
  }
1977
- BN3.prototype._parseHex = function _parseHex(number, start, endian) {
1976
+ BN4.prototype._parseHex = function _parseHex(number, start, endian) {
1978
1977
  this.length = Math.ceil((number.length - start) / 6);
1979
1978
  this.words = new Array(this.length);
1980
1979
  for (var i = 0; i < this.length; i++) {
@@ -2030,7 +2029,7 @@ var require_bn = __commonJS({
2030
2029
  }
2031
2030
  return r;
2032
2031
  }
2033
- BN3.prototype._parseBase = function _parseBase(number, base, start) {
2032
+ BN4.prototype._parseBase = function _parseBase(number, base, start) {
2034
2033
  this.words = [0];
2035
2034
  this.length = 1;
2036
2035
  for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
@@ -2066,7 +2065,7 @@ var require_bn = __commonJS({
2066
2065
  }
2067
2066
  this._strip();
2068
2067
  };
2069
- BN3.prototype.copy = function copy(dest) {
2068
+ BN4.prototype.copy = function copy(dest) {
2070
2069
  dest.words = new Array(this.length);
2071
2070
  for (var i = 0; i < this.length; i++) {
2072
2071
  dest.words[i] = this.words[i];
@@ -2081,27 +2080,27 @@ var require_bn = __commonJS({
2081
2080
  dest.negative = src.negative;
2082
2081
  dest.red = src.red;
2083
2082
  }
2084
- BN3.prototype._move = function _move(dest) {
2083
+ BN4.prototype._move = function _move(dest) {
2085
2084
  move(dest, this);
2086
2085
  };
2087
- BN3.prototype.clone = function clone() {
2088
- var r = new BN3(null);
2086
+ BN4.prototype.clone = function clone() {
2087
+ var r = new BN4(null);
2089
2088
  this.copy(r);
2090
2089
  return r;
2091
2090
  };
2092
- BN3.prototype._expand = function _expand(size) {
2091
+ BN4.prototype._expand = function _expand(size) {
2093
2092
  while (this.length < size) {
2094
2093
  this.words[this.length++] = 0;
2095
2094
  }
2096
2095
  return this;
2097
2096
  };
2098
- BN3.prototype._strip = function strip() {
2097
+ BN4.prototype._strip = function strip() {
2099
2098
  while (this.length > 1 && this.words[this.length - 1] === 0) {
2100
2099
  this.length--;
2101
2100
  }
2102
2101
  return this._normSign();
2103
2102
  };
2104
- BN3.prototype._normSign = function _normSign() {
2103
+ BN4.prototype._normSign = function _normSign() {
2105
2104
  if (this.length === 1 && this.words[0] === 0) {
2106
2105
  this.negative = 0;
2107
2106
  }
@@ -2109,12 +2108,12 @@ var require_bn = __commonJS({
2109
2108
  };
2110
2109
  if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
2111
2110
  try {
2112
- BN3.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
2111
+ BN4.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
2113
2112
  } catch (e) {
2114
- BN3.prototype.inspect = inspect;
2113
+ BN4.prototype.inspect = inspect;
2115
2114
  }
2116
2115
  } else {
2117
- BN3.prototype.inspect = inspect;
2116
+ BN4.prototype.inspect = inspect;
2118
2117
  }
2119
2118
  function inspect() {
2120
2119
  return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
@@ -2225,7 +2224,7 @@ var require_bn = __commonJS({
2225
2224
  52521875,
2226
2225
  60466176
2227
2226
  ];
2228
- BN3.prototype.toString = function toString(base, padding) {
2227
+ BN4.prototype.toString = function toString(base, padding) {
2229
2228
  base = base || 10;
2230
2229
  padding = padding | 0 || 1;
2231
2230
  var out;
@@ -2287,7 +2286,7 @@ var require_bn = __commonJS({
2287
2286
  }
2288
2287
  assert(false, "Base should be between 2 and 36");
2289
2288
  };
2290
- BN3.prototype.toNumber = function toNumber() {
2289
+ BN4.prototype.toNumber = function toNumber() {
2291
2290
  var ret = this.words[0];
2292
2291
  if (this.length === 2) {
2293
2292
  ret += this.words[1] * 67108864;
@@ -2298,15 +2297,15 @@ var require_bn = __commonJS({
2298
2297
  }
2299
2298
  return this.negative !== 0 ? -ret : ret;
2300
2299
  };
2301
- BN3.prototype.toJSON = function toJSON() {
2300
+ BN4.prototype.toJSON = function toJSON() {
2302
2301
  return this.toString(16, 2);
2303
2302
  };
2304
2303
  if (Buffer2) {
2305
- BN3.prototype.toBuffer = function toBuffer(endian, length) {
2304
+ BN4.prototype.toBuffer = function toBuffer(endian, length) {
2306
2305
  return this.toArrayLike(Buffer2, endian, length);
2307
2306
  };
2308
2307
  }
2309
- BN3.prototype.toArray = function toArray(endian, length) {
2308
+ BN4.prototype.toArray = function toArray(endian, length) {
2310
2309
  return this.toArrayLike(Array, endian, length);
2311
2310
  };
2312
2311
  var allocate = function allocate2(ArrayType, size) {
@@ -2315,7 +2314,7 @@ var require_bn = __commonJS({
2315
2314
  }
2316
2315
  return new ArrayType(size);
2317
2316
  };
2318
- BN3.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
2317
+ BN4.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
2319
2318
  this._strip();
2320
2319
  var byteLength = this.byteLength();
2321
2320
  var reqLength = length || Math.max(1, byteLength);
@@ -2326,7 +2325,7 @@ var require_bn = __commonJS({
2326
2325
  this["_toArrayLike" + postfix](res, byteLength);
2327
2326
  return res;
2328
2327
  };
2329
- BN3.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
2328
+ BN4.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
2330
2329
  var position = 0;
2331
2330
  var carry = 0;
2332
2331
  for (var i = 0, shift = 0; i < this.length; i++) {
@@ -2356,7 +2355,7 @@ var require_bn = __commonJS({
2356
2355
  }
2357
2356
  }
2358
2357
  };
2359
- BN3.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
2358
+ BN4.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
2360
2359
  var position = res.length - 1;
2361
2360
  var carry = 0;
2362
2361
  for (var i = 0, shift = 0; i < this.length; i++) {
@@ -2387,11 +2386,11 @@ var require_bn = __commonJS({
2387
2386
  }
2388
2387
  };
2389
2388
  if (Math.clz32) {
2390
- BN3.prototype._countBits = function _countBits(w) {
2389
+ BN4.prototype._countBits = function _countBits(w) {
2391
2390
  return 32 - Math.clz32(w);
2392
2391
  };
2393
2392
  } else {
2394
- BN3.prototype._countBits = function _countBits(w) {
2393
+ BN4.prototype._countBits = function _countBits(w) {
2395
2394
  var t = w;
2396
2395
  var r = 0;
2397
2396
  if (t >= 4096) {
@@ -2413,7 +2412,7 @@ var require_bn = __commonJS({
2413
2412
  return r + t;
2414
2413
  };
2415
2414
  }
2416
- BN3.prototype._zeroBits = function _zeroBits(w) {
2415
+ BN4.prototype._zeroBits = function _zeroBits(w) {
2417
2416
  if (w === 0) return 26;
2418
2417
  var t = w;
2419
2418
  var r = 0;
@@ -2438,7 +2437,7 @@ var require_bn = __commonJS({
2438
2437
  }
2439
2438
  return r;
2440
2439
  };
2441
- BN3.prototype.bitLength = function bitLength() {
2440
+ BN4.prototype.bitLength = function bitLength() {
2442
2441
  var w = this.words[this.length - 1];
2443
2442
  var hi = this._countBits(w);
2444
2443
  return (this.length - 1) * 26 + hi;
@@ -2452,7 +2451,7 @@ var require_bn = __commonJS({
2452
2451
  }
2453
2452
  return w;
2454
2453
  }
2455
- BN3.prototype.zeroBits = function zeroBits() {
2454
+ BN4.prototype.zeroBits = function zeroBits() {
2456
2455
  if (this.isZero()) return 0;
2457
2456
  var r = 0;
2458
2457
  for (var i = 0; i < this.length; i++) {
@@ -2462,34 +2461,34 @@ var require_bn = __commonJS({
2462
2461
  }
2463
2462
  return r;
2464
2463
  };
2465
- BN3.prototype.byteLength = function byteLength() {
2464
+ BN4.prototype.byteLength = function byteLength() {
2466
2465
  return Math.ceil(this.bitLength() / 8);
2467
2466
  };
2468
- BN3.prototype.toTwos = function toTwos(width) {
2467
+ BN4.prototype.toTwos = function toTwos(width) {
2469
2468
  if (this.negative !== 0) {
2470
2469
  return this.abs().inotn(width).iaddn(1);
2471
2470
  }
2472
2471
  return this.clone();
2473
2472
  };
2474
- BN3.prototype.fromTwos = function fromTwos(width) {
2473
+ BN4.prototype.fromTwos = function fromTwos(width) {
2475
2474
  if (this.testn(width - 1)) {
2476
2475
  return this.notn(width).iaddn(1).ineg();
2477
2476
  }
2478
2477
  return this.clone();
2479
2478
  };
2480
- BN3.prototype.isNeg = function isNeg() {
2479
+ BN4.prototype.isNeg = function isNeg() {
2481
2480
  return this.negative !== 0;
2482
2481
  };
2483
- BN3.prototype.neg = function neg() {
2482
+ BN4.prototype.neg = function neg() {
2484
2483
  return this.clone().ineg();
2485
2484
  };
2486
- BN3.prototype.ineg = function ineg() {
2485
+ BN4.prototype.ineg = function ineg() {
2487
2486
  if (!this.isZero()) {
2488
2487
  this.negative ^= 1;
2489
2488
  }
2490
2489
  return this;
2491
2490
  };
2492
- BN3.prototype.iuor = function iuor(num) {
2491
+ BN4.prototype.iuor = function iuor(num) {
2493
2492
  while (this.length < num.length) {
2494
2493
  this.words[this.length++] = 0;
2495
2494
  }
@@ -2498,19 +2497,19 @@ var require_bn = __commonJS({
2498
2497
  }
2499
2498
  return this._strip();
2500
2499
  };
2501
- BN3.prototype.ior = function ior(num) {
2500
+ BN4.prototype.ior = function ior(num) {
2502
2501
  assert((this.negative | num.negative) === 0);
2503
2502
  return this.iuor(num);
2504
2503
  };
2505
- BN3.prototype.or = function or(num) {
2504
+ BN4.prototype.or = function or(num) {
2506
2505
  if (this.length > num.length) return this.clone().ior(num);
2507
2506
  return num.clone().ior(this);
2508
2507
  };
2509
- BN3.prototype.uor = function uor(num) {
2508
+ BN4.prototype.uor = function uor(num) {
2510
2509
  if (this.length > num.length) return this.clone().iuor(num);
2511
2510
  return num.clone().iuor(this);
2512
2511
  };
2513
- BN3.prototype.iuand = function iuand(num) {
2512
+ BN4.prototype.iuand = function iuand(num) {
2514
2513
  var b;
2515
2514
  if (this.length > num.length) {
2516
2515
  b = num;
@@ -2523,19 +2522,19 @@ var require_bn = __commonJS({
2523
2522
  this.length = b.length;
2524
2523
  return this._strip();
2525
2524
  };
2526
- BN3.prototype.iand = function iand(num) {
2525
+ BN4.prototype.iand = function iand(num) {
2527
2526
  assert((this.negative | num.negative) === 0);
2528
2527
  return this.iuand(num);
2529
2528
  };
2530
- BN3.prototype.and = function and(num) {
2529
+ BN4.prototype.and = function and(num) {
2531
2530
  if (this.length > num.length) return this.clone().iand(num);
2532
2531
  return num.clone().iand(this);
2533
2532
  };
2534
- BN3.prototype.uand = function uand(num) {
2533
+ BN4.prototype.uand = function uand(num) {
2535
2534
  if (this.length > num.length) return this.clone().iuand(num);
2536
2535
  return num.clone().iuand(this);
2537
2536
  };
2538
- BN3.prototype.iuxor = function iuxor(num) {
2537
+ BN4.prototype.iuxor = function iuxor(num) {
2539
2538
  var a;
2540
2539
  var b;
2541
2540
  if (this.length > num.length) {
@@ -2556,19 +2555,19 @@ var require_bn = __commonJS({
2556
2555
  this.length = a.length;
2557
2556
  return this._strip();
2558
2557
  };
2559
- BN3.prototype.ixor = function ixor(num) {
2558
+ BN4.prototype.ixor = function ixor(num) {
2560
2559
  assert((this.negative | num.negative) === 0);
2561
2560
  return this.iuxor(num);
2562
2561
  };
2563
- BN3.prototype.xor = function xor(num) {
2562
+ BN4.prototype.xor = function xor(num) {
2564
2563
  if (this.length > num.length) return this.clone().ixor(num);
2565
2564
  return num.clone().ixor(this);
2566
2565
  };
2567
- BN3.prototype.uxor = function uxor(num) {
2566
+ BN4.prototype.uxor = function uxor(num) {
2568
2567
  if (this.length > num.length) return this.clone().iuxor(num);
2569
2568
  return num.clone().iuxor(this);
2570
2569
  };
2571
- BN3.prototype.inotn = function inotn(width) {
2570
+ BN4.prototype.inotn = function inotn(width) {
2572
2571
  assert(typeof width === "number" && width >= 0);
2573
2572
  var bytesNeeded = Math.ceil(width / 26) | 0;
2574
2573
  var bitsLeft = width % 26;
@@ -2584,10 +2583,10 @@ var require_bn = __commonJS({
2584
2583
  }
2585
2584
  return this._strip();
2586
2585
  };
2587
- BN3.prototype.notn = function notn(width) {
2586
+ BN4.prototype.notn = function notn(width) {
2588
2587
  return this.clone().inotn(width);
2589
2588
  };
2590
- BN3.prototype.setn = function setn(bit, val) {
2589
+ BN4.prototype.setn = function setn(bit, val) {
2591
2590
  assert(typeof bit === "number" && bit >= 0);
2592
2591
  var off = bit / 26 | 0;
2593
2592
  var wbit = bit % 26;
@@ -2599,7 +2598,7 @@ var require_bn = __commonJS({
2599
2598
  }
2600
2599
  return this._strip();
2601
2600
  };
2602
- BN3.prototype.iadd = function iadd(num) {
2601
+ BN4.prototype.iadd = function iadd(num) {
2603
2602
  var r;
2604
2603
  if (this.negative !== 0 && num.negative === 0) {
2605
2604
  this.negative = 0;
@@ -2642,7 +2641,7 @@ var require_bn = __commonJS({
2642
2641
  }
2643
2642
  return this;
2644
2643
  };
2645
- BN3.prototype.add = function add(num) {
2644
+ BN4.prototype.add = function add(num) {
2646
2645
  var res;
2647
2646
  if (num.negative !== 0 && this.negative === 0) {
2648
2647
  num.negative = 0;
@@ -2658,7 +2657,7 @@ var require_bn = __commonJS({
2658
2657
  if (this.length > num.length) return this.clone().iadd(num);
2659
2658
  return num.clone().iadd(this);
2660
2659
  };
2661
- BN3.prototype.isub = function isub(num) {
2660
+ BN4.prototype.isub = function isub(num) {
2662
2661
  if (num.negative !== 0) {
2663
2662
  num.negative = 0;
2664
2663
  var r = this.iadd(num);
@@ -2707,7 +2706,7 @@ var require_bn = __commonJS({
2707
2706
  }
2708
2707
  return this._strip();
2709
2708
  };
2710
- BN3.prototype.sub = function sub(num) {
2709
+ BN4.prototype.sub = function sub(num) {
2711
2710
  return this.clone().isub(num);
2712
2711
  };
2713
2712
  function smallMulTo(self, num, out) {
@@ -3335,7 +3334,7 @@ var require_bn = __commonJS({
3335
3334
  function jumboMulTo(self, num, out) {
3336
3335
  return bigMulTo(self, num, out);
3337
3336
  }
3338
- BN3.prototype.mulTo = function mulTo(num, out) {
3337
+ BN4.prototype.mulTo = function mulTo(num, out) {
3339
3338
  var res;
3340
3339
  var len = this.length + num.length;
3341
3340
  if (this.length === 10 && num.length === 10) {
@@ -3349,20 +3348,20 @@ var require_bn = __commonJS({
3349
3348
  }
3350
3349
  return res;
3351
3350
  };
3352
- BN3.prototype.mul = function mul(num) {
3353
- var out = new BN3(null);
3351
+ BN4.prototype.mul = function mul(num) {
3352
+ var out = new BN4(null);
3354
3353
  out.words = new Array(this.length + num.length);
3355
3354
  return this.mulTo(num, out);
3356
3355
  };
3357
- BN3.prototype.mulf = function mulf(num) {
3358
- var out = new BN3(null);
3356
+ BN4.prototype.mulf = function mulf(num) {
3357
+ var out = new BN4(null);
3359
3358
  out.words = new Array(this.length + num.length);
3360
3359
  return jumboMulTo(this, num, out);
3361
3360
  };
3362
- BN3.prototype.imul = function imul(num) {
3361
+ BN4.prototype.imul = function imul(num) {
3363
3362
  return this.clone().mulTo(num, this);
3364
3363
  };
3365
- BN3.prototype.imuln = function imuln(num) {
3364
+ BN4.prototype.imuln = function imuln(num) {
3366
3365
  var isNegNum = num < 0;
3367
3366
  if (isNegNum) num = -num;
3368
3367
  assert(typeof num === "number");
@@ -3383,18 +3382,18 @@ var require_bn = __commonJS({
3383
3382
  this.length = num === 0 ? 1 : this.length;
3384
3383
  return isNegNum ? this.ineg() : this;
3385
3384
  };
3386
- BN3.prototype.muln = function muln(num) {
3385
+ BN4.prototype.muln = function muln(num) {
3387
3386
  return this.clone().imuln(num);
3388
3387
  };
3389
- BN3.prototype.sqr = function sqr() {
3388
+ BN4.prototype.sqr = function sqr() {
3390
3389
  return this.mul(this);
3391
3390
  };
3392
- BN3.prototype.isqr = function isqr() {
3391
+ BN4.prototype.isqr = function isqr() {
3393
3392
  return this.imul(this.clone());
3394
3393
  };
3395
- BN3.prototype.pow = function pow(num) {
3394
+ BN4.prototype.pow = function pow(num) {
3396
3395
  var w = toBitArray(num);
3397
- if (w.length === 0) return new BN3(1);
3396
+ if (w.length === 0) return new BN4(1);
3398
3397
  var res = this;
3399
3398
  for (var i = 0; i < w.length; i++, res = res.sqr()) {
3400
3399
  if (w[i] !== 0) break;
@@ -3407,7 +3406,7 @@ var require_bn = __commonJS({
3407
3406
  }
3408
3407
  return res;
3409
3408
  };
3410
- BN3.prototype.iushln = function iushln(bits) {
3409
+ BN4.prototype.iushln = function iushln(bits) {
3411
3410
  assert(typeof bits === "number" && bits >= 0);
3412
3411
  var r = bits % 26;
3413
3412
  var s = (bits - r) / 26;
@@ -3437,11 +3436,11 @@ var require_bn = __commonJS({
3437
3436
  }
3438
3437
  return this._strip();
3439
3438
  };
3440
- BN3.prototype.ishln = function ishln(bits) {
3439
+ BN4.prototype.ishln = function ishln(bits) {
3441
3440
  assert(this.negative === 0);
3442
3441
  return this.iushln(bits);
3443
3442
  };
3444
- BN3.prototype.iushrn = function iushrn(bits, hint, extended) {
3443
+ BN4.prototype.iushrn = function iushrn(bits, hint, extended) {
3445
3444
  assert(typeof bits === "number" && bits >= 0);
3446
3445
  var h;
3447
3446
  if (hint) {
@@ -3485,23 +3484,23 @@ var require_bn = __commonJS({
3485
3484
  }
3486
3485
  return this._strip();
3487
3486
  };
3488
- BN3.prototype.ishrn = function ishrn(bits, hint, extended) {
3487
+ BN4.prototype.ishrn = function ishrn(bits, hint, extended) {
3489
3488
  assert(this.negative === 0);
3490
3489
  return this.iushrn(bits, hint, extended);
3491
3490
  };
3492
- BN3.prototype.shln = function shln(bits) {
3491
+ BN4.prototype.shln = function shln(bits) {
3493
3492
  return this.clone().ishln(bits);
3494
3493
  };
3495
- BN3.prototype.ushln = function ushln(bits) {
3494
+ BN4.prototype.ushln = function ushln(bits) {
3496
3495
  return this.clone().iushln(bits);
3497
3496
  };
3498
- BN3.prototype.shrn = function shrn(bits) {
3497
+ BN4.prototype.shrn = function shrn(bits) {
3499
3498
  return this.clone().ishrn(bits);
3500
3499
  };
3501
- BN3.prototype.ushrn = function ushrn(bits) {
3500
+ BN4.prototype.ushrn = function ushrn(bits) {
3502
3501
  return this.clone().iushrn(bits);
3503
3502
  };
3504
- BN3.prototype.testn = function testn(bit) {
3503
+ BN4.prototype.testn = function testn(bit) {
3505
3504
  assert(typeof bit === "number" && bit >= 0);
3506
3505
  var r = bit % 26;
3507
3506
  var s = (bit - r) / 26;
@@ -3510,7 +3509,7 @@ var require_bn = __commonJS({
3510
3509
  var w = this.words[s];
3511
3510
  return !!(w & q);
3512
3511
  };
3513
- BN3.prototype.imaskn = function imaskn(bits) {
3512
+ BN4.prototype.imaskn = function imaskn(bits) {
3514
3513
  assert(typeof bits === "number" && bits >= 0);
3515
3514
  var r = bits % 26;
3516
3515
  var s = (bits - r) / 26;
@@ -3528,10 +3527,10 @@ var require_bn = __commonJS({
3528
3527
  }
3529
3528
  return this._strip();
3530
3529
  };
3531
- BN3.prototype.maskn = function maskn(bits) {
3530
+ BN4.prototype.maskn = function maskn(bits) {
3532
3531
  return this.clone().imaskn(bits);
3533
3532
  };
3534
- BN3.prototype.iaddn = function iaddn(num) {
3533
+ BN4.prototype.iaddn = function iaddn(num) {
3535
3534
  assert(typeof num === "number");
3536
3535
  assert(num < 67108864);
3537
3536
  if (num < 0) return this.isubn(-num);
@@ -3548,7 +3547,7 @@ var require_bn = __commonJS({
3548
3547
  }
3549
3548
  return this._iaddn(num);
3550
3549
  };
3551
- BN3.prototype._iaddn = function _iaddn(num) {
3550
+ BN4.prototype._iaddn = function _iaddn(num) {
3552
3551
  this.words[0] += num;
3553
3552
  for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
3554
3553
  this.words[i] -= 67108864;
@@ -3561,7 +3560,7 @@ var require_bn = __commonJS({
3561
3560
  this.length = Math.max(this.length, i + 1);
3562
3561
  return this;
3563
3562
  };
3564
- BN3.prototype.isubn = function isubn(num) {
3563
+ BN4.prototype.isubn = function isubn(num) {
3565
3564
  assert(typeof num === "number");
3566
3565
  assert(num < 67108864);
3567
3566
  if (num < 0) return this.iaddn(-num);
@@ -3583,20 +3582,20 @@ var require_bn = __commonJS({
3583
3582
  }
3584
3583
  return this._strip();
3585
3584
  };
3586
- BN3.prototype.addn = function addn(num) {
3585
+ BN4.prototype.addn = function addn(num) {
3587
3586
  return this.clone().iaddn(num);
3588
3587
  };
3589
- BN3.prototype.subn = function subn(num) {
3588
+ BN4.prototype.subn = function subn(num) {
3590
3589
  return this.clone().isubn(num);
3591
3590
  };
3592
- BN3.prototype.iabs = function iabs() {
3591
+ BN4.prototype.iabs = function iabs() {
3593
3592
  this.negative = 0;
3594
3593
  return this;
3595
3594
  };
3596
- BN3.prototype.abs = function abs() {
3595
+ BN4.prototype.abs = function abs() {
3597
3596
  return this.clone().iabs();
3598
3597
  };
3599
- BN3.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
3598
+ BN4.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
3600
3599
  var len = num.length + shift;
3601
3600
  var i;
3602
3601
  this._expand(len);
@@ -3625,7 +3624,7 @@ var require_bn = __commonJS({
3625
3624
  this.negative = 1;
3626
3625
  return this._strip();
3627
3626
  };
3628
- BN3.prototype._wordDiv = function _wordDiv(num, mode) {
3627
+ BN4.prototype._wordDiv = function _wordDiv(num, mode) {
3629
3628
  var shift = this.length - num.length;
3630
3629
  var a = this.clone();
3631
3630
  var b = num;
@@ -3640,7 +3639,7 @@ var require_bn = __commonJS({
3640
3639
  var m = a.length - b.length;
3641
3640
  var q;
3642
3641
  if (mode !== "mod") {
3643
- q = new BN3(null);
3642
+ q = new BN4(null);
3644
3643
  q.length = m + 1;
3645
3644
  q.words = new Array(q.length);
3646
3645
  for (var i = 0; i < q.length; i++) {
@@ -3682,12 +3681,12 @@ var require_bn = __commonJS({
3682
3681
  mod: a
3683
3682
  };
3684
3683
  };
3685
- BN3.prototype.divmod = function divmod(num, mode, positive) {
3684
+ BN4.prototype.divmod = function divmod(num, mode, positive) {
3686
3685
  assert(!num.isZero());
3687
3686
  if (this.isZero()) {
3688
3687
  return {
3689
- div: new BN3(0),
3690
- mod: new BN3(0)
3688
+ div: new BN4(0),
3689
+ mod: new BN4(0)
3691
3690
  };
3692
3691
  }
3693
3692
  var div, mod, res;
@@ -3732,7 +3731,7 @@ var require_bn = __commonJS({
3732
3731
  }
3733
3732
  if (num.length > this.length || this.cmp(num) < 0) {
3734
3733
  return {
3735
- div: new BN3(0),
3734
+ div: new BN4(0),
3736
3735
  mod: this
3737
3736
  };
3738
3737
  }
@@ -3746,26 +3745,26 @@ var require_bn = __commonJS({
3746
3745
  if (mode === "mod") {
3747
3746
  return {
3748
3747
  div: null,
3749
- mod: new BN3(this.modrn(num.words[0]))
3748
+ mod: new BN4(this.modrn(num.words[0]))
3750
3749
  };
3751
3750
  }
3752
3751
  return {
3753
3752
  div: this.divn(num.words[0]),
3754
- mod: new BN3(this.modrn(num.words[0]))
3753
+ mod: new BN4(this.modrn(num.words[0]))
3755
3754
  };
3756
3755
  }
3757
3756
  return this._wordDiv(num, mode);
3758
3757
  };
3759
- BN3.prototype.div = function div(num) {
3758
+ BN4.prototype.div = function div(num) {
3760
3759
  return this.divmod(num, "div", false).div;
3761
3760
  };
3762
- BN3.prototype.mod = function mod(num) {
3761
+ BN4.prototype.mod = function mod(num) {
3763
3762
  return this.divmod(num, "mod", false).mod;
3764
3763
  };
3765
- BN3.prototype.umod = function umod(num) {
3764
+ BN4.prototype.umod = function umod(num) {
3766
3765
  return this.divmod(num, "mod", true).mod;
3767
3766
  };
3768
- BN3.prototype.divRound = function divRound(num) {
3767
+ BN4.prototype.divRound = function divRound(num) {
3769
3768
  var dm = this.divmod(num);
3770
3769
  if (dm.mod.isZero()) return dm.div;
3771
3770
  var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
@@ -3775,7 +3774,7 @@ var require_bn = __commonJS({
3775
3774
  if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
3776
3775
  return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
3777
3776
  };
3778
- BN3.prototype.modrn = function modrn(num) {
3777
+ BN4.prototype.modrn = function modrn(num) {
3779
3778
  var isNegNum = num < 0;
3780
3779
  if (isNegNum) num = -num;
3781
3780
  assert(num <= 67108863);
@@ -3786,10 +3785,10 @@ var require_bn = __commonJS({
3786
3785
  }
3787
3786
  return isNegNum ? -acc : acc;
3788
3787
  };
3789
- BN3.prototype.modn = function modn(num) {
3788
+ BN4.prototype.modn = function modn(num) {
3790
3789
  return this.modrn(num);
3791
3790
  };
3792
- BN3.prototype.idivn = function idivn(num) {
3791
+ BN4.prototype.idivn = function idivn(num) {
3793
3792
  var isNegNum = num < 0;
3794
3793
  if (isNegNum) num = -num;
3795
3794
  assert(num <= 67108863);
@@ -3802,10 +3801,10 @@ var require_bn = __commonJS({
3802
3801
  this._strip();
3803
3802
  return isNegNum ? this.ineg() : this;
3804
3803
  };
3805
- BN3.prototype.divn = function divn(num) {
3804
+ BN4.prototype.divn = function divn(num) {
3806
3805
  return this.clone().idivn(num);
3807
3806
  };
3808
- BN3.prototype.egcd = function egcd(p) {
3807
+ BN4.prototype.egcd = function egcd(p) {
3809
3808
  assert(p.negative === 0);
3810
3809
  assert(!p.isZero());
3811
3810
  var x = this;
@@ -3815,10 +3814,10 @@ var require_bn = __commonJS({
3815
3814
  } else {
3816
3815
  x = x.clone();
3817
3816
  }
3818
- var A = new BN3(1);
3819
- var B = new BN3(0);
3820
- var C = new BN3(0);
3821
- var D = new BN3(1);
3817
+ var A = new BN4(1);
3818
+ var B = new BN4(0);
3819
+ var C = new BN4(0);
3820
+ var D = new BN4(1);
3822
3821
  var g = 0;
3823
3822
  while (x.isEven() && y.isEven()) {
3824
3823
  x.iushrn(1);
@@ -3868,7 +3867,7 @@ var require_bn = __commonJS({
3868
3867
  gcd: y.iushln(g)
3869
3868
  };
3870
3869
  };
3871
- BN3.prototype._invmp = function _invmp(p) {
3870
+ BN4.prototype._invmp = function _invmp(p) {
3872
3871
  assert(p.negative === 0);
3873
3872
  assert(!p.isZero());
3874
3873
  var a = this;
@@ -3878,8 +3877,8 @@ var require_bn = __commonJS({
3878
3877
  } else {
3879
3878
  a = a.clone();
3880
3879
  }
3881
- var x1 = new BN3(1);
3882
- var x2 = new BN3(0);
3880
+ var x1 = new BN4(1);
3881
+ var x2 = new BN4(0);
3883
3882
  var delta = b.clone();
3884
3883
  while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
3885
3884
  for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
@@ -3921,7 +3920,7 @@ var require_bn = __commonJS({
3921
3920
  }
3922
3921
  return res;
3923
3922
  };
3924
- BN3.prototype.gcd = function gcd(num) {
3923
+ BN4.prototype.gcd = function gcd(num) {
3925
3924
  if (this.isZero()) return num.abs();
3926
3925
  if (num.isZero()) return this.abs();
3927
3926
  var a = this.clone();
@@ -3951,19 +3950,19 @@ var require_bn = __commonJS({
3951
3950
  } while (true);
3952
3951
  return b.iushln(shift);
3953
3952
  };
3954
- BN3.prototype.invm = function invm(num) {
3953
+ BN4.prototype.invm = function invm(num) {
3955
3954
  return this.egcd(num).a.umod(num);
3956
3955
  };
3957
- BN3.prototype.isEven = function isEven() {
3956
+ BN4.prototype.isEven = function isEven() {
3958
3957
  return (this.words[0] & 1) === 0;
3959
3958
  };
3960
- BN3.prototype.isOdd = function isOdd() {
3959
+ BN4.prototype.isOdd = function isOdd() {
3961
3960
  return (this.words[0] & 1) === 1;
3962
3961
  };
3963
- BN3.prototype.andln = function andln(num) {
3962
+ BN4.prototype.andln = function andln(num) {
3964
3963
  return this.words[0] & num;
3965
3964
  };
3966
- BN3.prototype.bincn = function bincn(bit) {
3965
+ BN4.prototype.bincn = function bincn(bit) {
3967
3966
  assert(typeof bit === "number");
3968
3967
  var r = bit % 26;
3969
3968
  var s = (bit - r) / 26;
@@ -3987,10 +3986,10 @@ var require_bn = __commonJS({
3987
3986
  }
3988
3987
  return this;
3989
3988
  };
3990
- BN3.prototype.isZero = function isZero() {
3989
+ BN4.prototype.isZero = function isZero() {
3991
3990
  return this.length === 1 && this.words[0] === 0;
3992
3991
  };
3993
- BN3.prototype.cmpn = function cmpn(num) {
3992
+ BN4.prototype.cmpn = function cmpn(num) {
3994
3993
  var negative = num < 0;
3995
3994
  if (this.negative !== 0 && !negative) return -1;
3996
3995
  if (this.negative === 0 && negative) return 1;
@@ -4009,14 +4008,14 @@ var require_bn = __commonJS({
4009
4008
  if (this.negative !== 0) return -res | 0;
4010
4009
  return res;
4011
4010
  };
4012
- BN3.prototype.cmp = function cmp(num) {
4011
+ BN4.prototype.cmp = function cmp(num) {
4013
4012
  if (this.negative !== 0 && num.negative === 0) return -1;
4014
4013
  if (this.negative === 0 && num.negative !== 0) return 1;
4015
4014
  var res = this.ucmp(num);
4016
4015
  if (this.negative !== 0) return -res | 0;
4017
4016
  return res;
4018
4017
  };
4019
- BN3.prototype.ucmp = function ucmp(num) {
4018
+ BN4.prototype.ucmp = function ucmp(num) {
4020
4019
  if (this.length > num.length) return 1;
4021
4020
  if (this.length < num.length) return -1;
4022
4021
  var res = 0;
@@ -4033,112 +4032,112 @@ var require_bn = __commonJS({
4033
4032
  }
4034
4033
  return res;
4035
4034
  };
4036
- BN3.prototype.gtn = function gtn(num) {
4035
+ BN4.prototype.gtn = function gtn(num) {
4037
4036
  return this.cmpn(num) === 1;
4038
4037
  };
4039
- BN3.prototype.gt = function gt(num) {
4038
+ BN4.prototype.gt = function gt(num) {
4040
4039
  return this.cmp(num) === 1;
4041
4040
  };
4042
- BN3.prototype.gten = function gten(num) {
4041
+ BN4.prototype.gten = function gten(num) {
4043
4042
  return this.cmpn(num) >= 0;
4044
4043
  };
4045
- BN3.prototype.gte = function gte(num) {
4044
+ BN4.prototype.gte = function gte(num) {
4046
4045
  return this.cmp(num) >= 0;
4047
4046
  };
4048
- BN3.prototype.ltn = function ltn(num) {
4047
+ BN4.prototype.ltn = function ltn(num) {
4049
4048
  return this.cmpn(num) === -1;
4050
4049
  };
4051
- BN3.prototype.lt = function lt(num) {
4050
+ BN4.prototype.lt = function lt(num) {
4052
4051
  return this.cmp(num) === -1;
4053
4052
  };
4054
- BN3.prototype.lten = function lten(num) {
4053
+ BN4.prototype.lten = function lten(num) {
4055
4054
  return this.cmpn(num) <= 0;
4056
4055
  };
4057
- BN3.prototype.lte = function lte(num) {
4056
+ BN4.prototype.lte = function lte(num) {
4058
4057
  return this.cmp(num) <= 0;
4059
4058
  };
4060
- BN3.prototype.eqn = function eqn(num) {
4059
+ BN4.prototype.eqn = function eqn(num) {
4061
4060
  return this.cmpn(num) === 0;
4062
4061
  };
4063
- BN3.prototype.eq = function eq(num) {
4062
+ BN4.prototype.eq = function eq(num) {
4064
4063
  return this.cmp(num) === 0;
4065
4064
  };
4066
- BN3.red = function red(num) {
4065
+ BN4.red = function red(num) {
4067
4066
  return new Red(num);
4068
4067
  };
4069
- BN3.prototype.toRed = function toRed(ctx) {
4068
+ BN4.prototype.toRed = function toRed(ctx) {
4070
4069
  assert(!this.red, "Already a number in reduction context");
4071
4070
  assert(this.negative === 0, "red works only with positives");
4072
4071
  return ctx.convertTo(this)._forceRed(ctx);
4073
4072
  };
4074
- BN3.prototype.fromRed = function fromRed() {
4073
+ BN4.prototype.fromRed = function fromRed() {
4075
4074
  assert(this.red, "fromRed works only with numbers in reduction context");
4076
4075
  return this.red.convertFrom(this);
4077
4076
  };
4078
- BN3.prototype._forceRed = function _forceRed(ctx) {
4077
+ BN4.prototype._forceRed = function _forceRed(ctx) {
4079
4078
  this.red = ctx;
4080
4079
  return this;
4081
4080
  };
4082
- BN3.prototype.forceRed = function forceRed(ctx) {
4081
+ BN4.prototype.forceRed = function forceRed(ctx) {
4083
4082
  assert(!this.red, "Already a number in reduction context");
4084
4083
  return this._forceRed(ctx);
4085
4084
  };
4086
- BN3.prototype.redAdd = function redAdd(num) {
4085
+ BN4.prototype.redAdd = function redAdd(num) {
4087
4086
  assert(this.red, "redAdd works only with red numbers");
4088
4087
  return this.red.add(this, num);
4089
4088
  };
4090
- BN3.prototype.redIAdd = function redIAdd(num) {
4089
+ BN4.prototype.redIAdd = function redIAdd(num) {
4091
4090
  assert(this.red, "redIAdd works only with red numbers");
4092
4091
  return this.red.iadd(this, num);
4093
4092
  };
4094
- BN3.prototype.redSub = function redSub(num) {
4093
+ BN4.prototype.redSub = function redSub(num) {
4095
4094
  assert(this.red, "redSub works only with red numbers");
4096
4095
  return this.red.sub(this, num);
4097
4096
  };
4098
- BN3.prototype.redISub = function redISub(num) {
4097
+ BN4.prototype.redISub = function redISub(num) {
4099
4098
  assert(this.red, "redISub works only with red numbers");
4100
4099
  return this.red.isub(this, num);
4101
4100
  };
4102
- BN3.prototype.redShl = function redShl(num) {
4101
+ BN4.prototype.redShl = function redShl(num) {
4103
4102
  assert(this.red, "redShl works only with red numbers");
4104
4103
  return this.red.shl(this, num);
4105
4104
  };
4106
- BN3.prototype.redMul = function redMul(num) {
4105
+ BN4.prototype.redMul = function redMul(num) {
4107
4106
  assert(this.red, "redMul works only with red numbers");
4108
4107
  this.red._verify2(this, num);
4109
4108
  return this.red.mul(this, num);
4110
4109
  };
4111
- BN3.prototype.redIMul = function redIMul(num) {
4110
+ BN4.prototype.redIMul = function redIMul(num) {
4112
4111
  assert(this.red, "redMul works only with red numbers");
4113
4112
  this.red._verify2(this, num);
4114
4113
  return this.red.imul(this, num);
4115
4114
  };
4116
- BN3.prototype.redSqr = function redSqr() {
4115
+ BN4.prototype.redSqr = function redSqr() {
4117
4116
  assert(this.red, "redSqr works only with red numbers");
4118
4117
  this.red._verify1(this);
4119
4118
  return this.red.sqr(this);
4120
4119
  };
4121
- BN3.prototype.redISqr = function redISqr() {
4120
+ BN4.prototype.redISqr = function redISqr() {
4122
4121
  assert(this.red, "redISqr works only with red numbers");
4123
4122
  this.red._verify1(this);
4124
4123
  return this.red.isqr(this);
4125
4124
  };
4126
- BN3.prototype.redSqrt = function redSqrt() {
4125
+ BN4.prototype.redSqrt = function redSqrt() {
4127
4126
  assert(this.red, "redSqrt works only with red numbers");
4128
4127
  this.red._verify1(this);
4129
4128
  return this.red.sqrt(this);
4130
4129
  };
4131
- BN3.prototype.redInvm = function redInvm() {
4130
+ BN4.prototype.redInvm = function redInvm() {
4132
4131
  assert(this.red, "redInvm works only with red numbers");
4133
4132
  this.red._verify1(this);
4134
4133
  return this.red.invm(this);
4135
4134
  };
4136
- BN3.prototype.redNeg = function redNeg() {
4135
+ BN4.prototype.redNeg = function redNeg() {
4137
4136
  assert(this.red, "redNeg works only with red numbers");
4138
4137
  this.red._verify1(this);
4139
4138
  return this.red.neg(this);
4140
4139
  };
4141
- BN3.prototype.redPow = function redPow(num) {
4140
+ BN4.prototype.redPow = function redPow(num) {
4142
4141
  assert(this.red && !num.red, "redPow(normalNum)");
4143
4142
  this.red._verify1(this);
4144
4143
  return this.red.pow(this, num);
@@ -4151,13 +4150,13 @@ var require_bn = __commonJS({
4151
4150
  };
4152
4151
  function MPrime(name, p) {
4153
4152
  this.name = name;
4154
- this.p = new BN3(p, 16);
4153
+ this.p = new BN4(p, 16);
4155
4154
  this.n = this.p.bitLength();
4156
- this.k = new BN3(1).iushln(this.n).isub(this.p);
4155
+ this.k = new BN4(1).iushln(this.n).isub(this.p);
4157
4156
  this.tmp = this._tmp();
4158
4157
  }
4159
4158
  MPrime.prototype._tmp = function _tmp() {
4160
- var tmp = new BN3(null);
4159
+ var tmp = new BN4(null);
4161
4160
  tmp.words = new Array(Math.ceil(this.n / 13));
4162
4161
  return tmp;
4163
4162
  };
@@ -4283,7 +4282,7 @@ var require_bn = __commonJS({
4283
4282
  }
4284
4283
  return num;
4285
4284
  };
4286
- BN3._prime = function prime(name) {
4285
+ BN4._prime = function prime(name) {
4287
4286
  if (primes[name]) return primes[name];
4288
4287
  var prime2;
4289
4288
  if (name === "k256") {
@@ -4302,7 +4301,7 @@ var require_bn = __commonJS({
4302
4301
  };
4303
4302
  function Red(m) {
4304
4303
  if (typeof m === "string") {
4305
- var prime = BN3._prime(m);
4304
+ var prime = BN4._prime(m);
4306
4305
  this.m = prime.p;
4307
4306
  this.prime = prime;
4308
4307
  } else {
@@ -4388,7 +4387,7 @@ var require_bn = __commonJS({
4388
4387
  var mod3 = this.m.andln(3);
4389
4388
  assert(mod3 % 2 === 1);
4390
4389
  if (mod3 === 3) {
4391
- var pow = this.m.add(new BN3(1)).iushrn(2);
4390
+ var pow = this.m.add(new BN4(1)).iushrn(2);
4392
4391
  return this.pow(a, pow);
4393
4392
  }
4394
4393
  var q = this.m.subn(1);
@@ -4398,11 +4397,11 @@ var require_bn = __commonJS({
4398
4397
  q.iushrn(1);
4399
4398
  }
4400
4399
  assert(!q.isZero());
4401
- var one = new BN3(1).toRed(this);
4400
+ var one = new BN4(1).toRed(this);
4402
4401
  var nOne = one.redNeg();
4403
4402
  var lpow = this.m.subn(1).iushrn(1);
4404
4403
  var z = this.m.bitLength();
4405
- z = new BN3(2 * z * z).toRed(this);
4404
+ z = new BN4(2 * z * z).toRed(this);
4406
4405
  while (this.pow(z, lpow).cmp(nOne) !== 0) {
4407
4406
  z.redIAdd(nOne);
4408
4407
  }
@@ -4416,7 +4415,7 @@ var require_bn = __commonJS({
4416
4415
  tmp = tmp.redSqr();
4417
4416
  }
4418
4417
  assert(i < m);
4419
- var b = this.pow(c, new BN3(1).iushln(m - i - 1));
4418
+ var b = this.pow(c, new BN4(1).iushln(m - i - 1));
4420
4419
  r = r.redMul(b);
4421
4420
  c = b.redSqr();
4422
4421
  t = t.redMul(c);
@@ -4434,11 +4433,11 @@ var require_bn = __commonJS({
4434
4433
  }
4435
4434
  };
4436
4435
  Red.prototype.pow = function pow(a, num) {
4437
- if (num.isZero()) return new BN3(1).toRed(this);
4436
+ if (num.isZero()) return new BN4(1).toRed(this);
4438
4437
  if (num.cmpn(1) === 0) return a.clone();
4439
4438
  var windowSize = 4;
4440
4439
  var wnd = new Array(1 << windowSize);
4441
- wnd[0] = new BN3(1).toRed(this);
4440
+ wnd[0] = new BN4(1).toRed(this);
4442
4441
  wnd[1] = a;
4443
4442
  for (var i = 2; i < wnd.length; i++) {
4444
4443
  wnd[i] = this.mul(wnd[i - 1], a);
@@ -4482,7 +4481,7 @@ var require_bn = __commonJS({
4482
4481
  res.red = null;
4483
4482
  return res;
4484
4483
  };
4485
- BN3.mont = function mont(num) {
4484
+ BN4.mont = function mont(num) {
4486
4485
  return new Mont(num);
4487
4486
  };
4488
4487
  function Mont(m) {
@@ -4491,7 +4490,7 @@ var require_bn = __commonJS({
4491
4490
  if (this.shift % 26 !== 0) {
4492
4491
  this.shift += 26 - this.shift % 26;
4493
4492
  }
4494
- this.r = new BN3(1).iushln(this.shift);
4493
+ this.r = new BN4(1).iushln(this.shift);
4495
4494
  this.r2 = this.imod(this.r.sqr());
4496
4495
  this.rinv = this.r._invmp(this.m);
4497
4496
  this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
@@ -4525,7 +4524,7 @@ var require_bn = __commonJS({
4525
4524
  return res._forceRed(this);
4526
4525
  };
4527
4526
  Mont.prototype.mul = function mul(a, b) {
4528
- if (a.isZero() || b.isZero()) return new BN3(0)._forceRed(this);
4527
+ if (a.isZero() || b.isZero()) return new BN4(0)._forceRed(this);
4529
4528
  var t = a.mul(b);
4530
4529
  var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
4531
4530
  var u = t.isub(c).iushrn(this.shift);
@@ -4547,141 +4546,71 @@ var require_bn = __commonJS({
4547
4546
 
4548
4547
  // src/client.ts
4549
4548
  var import_bn = __toESM(require_bn());
4550
- var JPOOL_STAKE_POOL = new PublicKey("CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1");
4551
- var Seeds = /* @__PURE__ */ ((Seeds2) => {
4552
- Seeds2["GlobalState"] = "global_state";
4553
- Seeds2["BondState"] = "bond_state";
4554
- Seeds2["ValidatorBond"] = "validator_bond";
4555
- Seeds2["StandardBond"] = "standard";
4556
- Seeds2["CrowdFundingBond"] = "crowdfunding";
4557
- return Seeds2;
4558
- })(Seeds || {});
4549
+
4550
+ // src/constants.ts
4551
+ var GLOBAL_STATE_SEED = "global_state";
4552
+ var BOND_STATE_SEED = "bond_state";
4553
+ var VALIDATOR_BOND_SEED = "validator_bond";
4554
+ var STANDARD_BOND_SEED = "standard";
4555
+ var CROWDFUNDING_BOND_SEED = "crowdfunding";
4559
4556
  var ENV_PROGRAM_ID = {
4560
4557
  // [BondClientEnv.DEV]: new PublicKey('...'),
4561
4558
  };
4562
4559
 
4563
4560
  // src/types/index.ts
4564
- var bondTypeToSeed = {
4565
- standard: "standard" /* StandardBond */,
4566
- crowdfunding: "crowdfunding" /* CrowdFundingBond */
4567
- };
4568
- var BondTypeVariant = {
4569
- Standard: { standard: {} },
4570
- Crowdfunding: { crowdfunding: {} }
4571
- };
4572
- var BondStateStatusVariant = {
4573
- Active: { active: {} },
4574
- Disabled: { disabled: {} }
4575
- };
4561
+ var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
4562
+ SessionStatus2[SessionStatus2["Live"] = 0] = "Live";
4563
+ SessionStatus2[SessionStatus2["Finished"] = 1] = "Finished";
4564
+ return SessionStatus2;
4565
+ })(SessionStatus || {});
4566
+ var BondType = /* @__PURE__ */ ((BondType2) => {
4567
+ BondType2["Standard"] = "standard";
4568
+ BondType2["Crowdfunding"] = "crowdfunding";
4569
+ return BondType2;
4570
+ })(BondType || {});
4576
4571
  var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
4577
4572
  BondTransactionType2["Deposit"] = "deposit";
4578
4573
  BondTransactionType2["Withdrawal"] = "withdrawal";
4579
4574
  BondTransactionType2["Compensation"] = "compensation";
4580
4575
  return BondTransactionType2;
4581
4576
  })(BondTransactionType || {});
4582
- var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
4583
- SessionStatus2[SessionStatus2["Live"] = 0] = "Live";
4584
- SessionStatus2[SessionStatus2["Finished"] = 1] = "Finished";
4585
- return SessionStatus2;
4586
- })(SessionStatus || {});
4587
4577
 
4588
- // src/utils/enum.ts
4589
- function getVariant(v) {
4590
- const key = Object.keys(v)[0];
4591
- return [key, v[key]];
4592
- }
4593
- function variantArgs(payload) {
4594
- if (Array.isArray(payload)) {
4595
- return payload;
4596
- }
4597
- if (payload && typeof payload === "object") {
4598
- const numericKeys = Object.keys(payload).filter((k) => String(+k) === k);
4599
- if (numericKeys.length) {
4600
- return numericKeys.sort((a, b) => +a - +b).map((k) => payload[k]);
4601
- }
4602
- return [payload];
4603
- }
4604
- return [payload];
4605
- }
4606
- function matchVariant(v, handlers) {
4607
- const [k, data] = getVariant(v);
4608
- const h = handlers[k];
4609
- if (!h) {
4610
- throw new Error(`Unhandled variant: ${k}`);
4611
- }
4612
- return h(...variantArgs(data));
4613
- }
4614
- function variantKey(v) {
4615
- return Object.keys(v)[0];
4616
- }
4617
- function sameVariant(a, b) {
4618
- return variantKey(a) === variantKey(b);
4619
- }
4620
-
4621
- // src/utils/wallet.ts
4622
- function isVersionedTransaction(tx) {
4623
- return "version" in tx;
4624
- }
4625
- var NodeWallet = class {
4626
- constructor(payer) {
4627
- this.payer = payer;
4578
+ // src/history.ts
4579
+ var { bs58 } = utils.bytes;
4580
+ var HistoryManager = class {
4581
+ constructor(client) {
4582
+ this.client = client;
4628
4583
  }
4629
- async signTransaction(tx) {
4630
- if (isVersionedTransaction(tx)) {
4631
- tx.sign([this.payer]);
4632
- } else {
4633
- tx.partialSign(this.payer);
4634
- }
4635
- return tx;
4584
+ // Cache of instruction discriminators
4585
+ discCache = /* @__PURE__ */ new Map();
4586
+ get program() {
4587
+ return this.client.program;
4636
4588
  }
4637
- async signAllTransactions(txs) {
4638
- return txs.map((t) => {
4639
- if (isVersionedTransaction(t)) {
4640
- t.sign([this.payer]);
4641
- } else {
4642
- t.partialSign(this.payer);
4643
- }
4644
- return t;
4645
- });
4589
+ get programId() {
4590
+ return this.client.programId;
4646
4591
  }
4647
- get publicKey() {
4648
- return this.payer.publicKey;
4592
+ get connection() {
4593
+ return this.client.provider.connection;
4649
4594
  }
4650
- };
4651
- var SLOTS_PER_EPOCH_MAINNET = 432e3;
4652
- var SLOTS_PER_EPOCH_DEVNET = 4e5;
4653
- function slotToEpoch(slot, cluster) {
4654
- const slotsPerEpoch = cluster === "mainnet-beta" ? SLOTS_PER_EPOCH_MAINNET : SLOTS_PER_EPOCH_DEVNET;
4655
- return Math.floor(slot / slotsPerEpoch);
4656
- }
4657
-
4658
- // src/history.ts
4659
- var HistoryManager = class {
4660
- program;
4661
- connection;
4662
- programId;
4663
- discCache = /* @__PURE__ */ new Map();
4664
- constructor(program, connection, programId) {
4665
- this.program = program;
4666
- this.connection = connection;
4667
- this.programId = programId;
4595
+ debug(...args) {
4596
+ this.client.debug(...args);
4668
4597
  }
4669
- async getHistory(bondType, vote, pdaDeriver, options) {
4670
- const cluster = options?.cluster || "mainnet-beta";
4671
- const [validatorBondAccount] = pdaDeriver(bondType, vote);
4598
+ async getHistory(bondType, bondName, vote, opts) {
4599
+ const [validatorBondAccount] = this.client.pda.validatorBond(bondType, bondName, vote);
4600
+ this.debug(`Fetching history for validator bond account: ${validatorBondAccount.toBase58()}`);
4672
4601
  const signatures = await this.fetchSignaturesForAddress(validatorBondAccount, {
4673
- limit: options?.limit,
4674
- before: options?.before,
4675
- until: options?.until
4602
+ limit: opts?.limit,
4603
+ before: opts?.before,
4604
+ until: opts?.until
4676
4605
  });
4677
4606
  if (!signatures.length) {
4678
4607
  return [];
4679
4608
  }
4680
- const sigStrs = signatures.map((s) => s.signature);
4681
- const parsed = await this.fetchParsedTransactions(sigStrs);
4609
+ const sigs = signatures.map((s) => s.signature);
4610
+ const parsed = await this.fetchParsedTransactions(sigs);
4682
4611
  const txBySig = /* @__PURE__ */ new Map();
4683
- for (let i = 0; i < sigStrs.length; i++) {
4684
- const want = sigStrs[i];
4612
+ for (let i = 0; i < sigs.length; i++) {
4613
+ const want = sigs[i];
4685
4614
  const tx = parsed[i] ?? null;
4686
4615
  if (tx?.transaction?.signatures?.[0] && tx.transaction.signatures[0] !== want) {
4687
4616
  const found = parsed.find((t) => t?.transaction?.signatures?.[0] === want) ?? null;
@@ -4716,7 +4645,7 @@ var HistoryManager = class {
4716
4645
  history.push({
4717
4646
  signature: sig,
4718
4647
  slot,
4719
- epoch: slotToEpoch(slot, cluster),
4648
+ epoch: slotToEpoch(slot, opts?.cluster),
4720
4649
  type,
4721
4650
  amount
4722
4651
  });
@@ -4729,7 +4658,8 @@ var HistoryManager = class {
4729
4658
  limit: options?.limit || 1e3,
4730
4659
  before: options?.before,
4731
4660
  until: options?.until
4732
- });
4661
+ }, "confirmed");
4662
+ console.log(sigs);
4733
4663
  return sigs.filter((s) => !s.err);
4734
4664
  }
4735
4665
  async fetchParsedTransactions(sigs, batchSize = 100) {
@@ -4737,6 +4667,7 @@ var HistoryManager = class {
4737
4667
  for (let i = 0; i < sigs.length; i += batchSize) {
4738
4668
  const batch = sigs.slice(i, i + batchSize);
4739
4669
  const txs = await this.connection.getParsedTransactions(batch, {
4670
+ commitment: "confirmed",
4740
4671
  maxSupportedTransactionVersion: 0
4741
4672
  });
4742
4673
  all.push(...txs);
@@ -4796,6 +4727,11 @@ var HistoryManager = class {
4796
4727
  }
4797
4728
  }
4798
4729
  };
4730
+ function slotToEpoch(slot, cluster) {
4731
+ const isMainnet = !cluster || cluster === "mainnet-beta";
4732
+ const slotsPerEpoch = isMainnet ? 432e3 : 4e5;
4733
+ return Math.floor(slot / slotsPerEpoch);
4734
+ }
4799
4735
 
4800
4736
  // src/idl/jbond.json
4801
4737
  var jbond_default = {
@@ -6385,8 +6321,102 @@ var jbond_default = {
6385
6321
  ]
6386
6322
  };
6387
6323
 
6324
+ // src/utils/enum.ts
6325
+ function getVariant(v) {
6326
+ const key = Object.keys(v)[0];
6327
+ return [key, v[key]];
6328
+ }
6329
+ function variantArgs(payload) {
6330
+ if (Array.isArray(payload)) {
6331
+ return payload;
6332
+ }
6333
+ if (payload && typeof payload === "object") {
6334
+ const numericKeys = Object.keys(payload).filter((k) => String(+k) === k);
6335
+ if (numericKeys.length) {
6336
+ return numericKeys.sort((a, b) => +a - +b).map((k) => payload[k]);
6337
+ }
6338
+ return [payload];
6339
+ }
6340
+ return [payload];
6341
+ }
6342
+ function matchVariant(v, handlers) {
6343
+ const [k, data] = getVariant(v);
6344
+ const h = handlers[k];
6345
+ if (!h) {
6346
+ throw new Error(`Unhandled variant: ${k}`);
6347
+ }
6348
+ return h(...variantArgs(data));
6349
+ }
6350
+ function variantKey(v) {
6351
+ return Object.keys(v)[0];
6352
+ }
6353
+ function sameVariant(a, b) {
6354
+ return variantKey(a) === variantKey(b);
6355
+ }
6356
+ function toAnchor(key, payload) {
6357
+ return { [key]: {} };
6358
+ }
6359
+ function fromAnchor(variant) {
6360
+ return variantKey(variant);
6361
+ }
6362
+ function bondTypeToAnchor(type, payload) {
6363
+ return toAnchor(type);
6364
+ }
6365
+ function anchorToBondType(variant) {
6366
+ return fromAnchor(variant);
6367
+ }
6368
+
6369
+ // src/utils/wallet.ts
6370
+ function isVersionedTransaction(tx) {
6371
+ return "version" in tx;
6372
+ }
6373
+ var NodeWallet = class {
6374
+ constructor(payer) {
6375
+ this.payer = payer;
6376
+ }
6377
+ async signTransaction(tx) {
6378
+ if (isVersionedTransaction(tx)) {
6379
+ tx.sign([this.payer]);
6380
+ } else {
6381
+ tx.partialSign(this.payer);
6382
+ }
6383
+ return tx;
6384
+ }
6385
+ async signAllTransactions(txs) {
6386
+ return txs.map((t) => {
6387
+ if (isVersionedTransaction(t)) {
6388
+ t.sign([this.payer]);
6389
+ } else {
6390
+ t.partialSign(this.payer);
6391
+ }
6392
+ return t;
6393
+ });
6394
+ }
6395
+ get publicKey() {
6396
+ return this.payer.publicKey;
6397
+ }
6398
+ };
6399
+ var SOL_DECIMALS = Math.log10(LAMPORTS_PER_SOL);
6400
+ function solToLamports(amount) {
6401
+ if (Number.isNaN(amount)) {
6402
+ return new BN(0);
6403
+ }
6404
+ return new BN(Number(amount).toFixed(SOL_DECIMALS).replace(".", ""));
6405
+ }
6406
+
6407
+ // src/utils/index.ts
6408
+ function getBondTypeSeed(type) {
6409
+ switch (type) {
6410
+ case "standard" /* Standard */:
6411
+ return STANDARD_BOND_SEED;
6412
+ case "crowdfunding" /* Crowdfunding */:
6413
+ return CROWDFUNDING_BOND_SEED;
6414
+ default:
6415
+ throw new Error(`Unknown bond type: ${type}`);
6416
+ }
6417
+ }
6418
+
6388
6419
  // src/client.ts
6389
- var { bs58: bs582 } = utils.bytes;
6390
6420
  var BondClientEnv = /* @__PURE__ */ ((BondClientEnv2) => {
6391
6421
  BondClientEnv2["DEV"] = "dev";
6392
6422
  BondClientEnv2["STAGE"] = "stage";
@@ -6398,11 +6428,12 @@ var JBondClient = class _JBondClient {
6398
6428
  this.provider = provider;
6399
6429
  this.options = options ?? {};
6400
6430
  this.program = new Program(jbond_default, this.provider);
6401
- this.history = new HistoryManager(this.program, this.provider.connection, this.program.programId);
6402
6431
  }
6403
6432
  options;
6404
6433
  program;
6405
- history;
6434
+ get history() {
6435
+ return new HistoryManager(this);
6436
+ }
6406
6437
  /**
6407
6438
  * Creates an instance of `JBondClient` using a provided connection and wallet.
6408
6439
  */
@@ -6438,167 +6469,151 @@ var JBondClient = class _JBondClient {
6438
6469
  * Set the environment.
6439
6470
  */
6440
6471
  env(env) {
6441
- return this.configureEnv("programId", ENV_PROGRAM_ID[env]);
6472
+ return this.configure("programId", ENV_PROGRAM_ID[env]);
6442
6473
  }
6443
6474
  /**
6444
6475
  * Configure a specific option.
6445
6476
  */
6446
- configureEnv(key, val) {
6477
+ configure(key, val) {
6447
6478
  this.options[key] = val;
6448
6479
  return this;
6449
6480
  }
6450
- getBondTypeSeed(bondType) {
6451
- const [k] = getVariant(bondType);
6452
- return bondTypeToSeed[k];
6481
+ /**
6482
+ * Debug logging
6483
+ * @param args
6484
+ */
6485
+ debug(...args) {
6486
+ if (this.options.debug) {
6487
+ console.log(`%c[JBondClient]`, "color: #009999;", ...args);
6488
+ }
6453
6489
  }
6454
6490
  /**
6455
6491
  * Program Derived Addresses (PDAs)
6456
6492
  */
6457
6493
  pda = {
6458
- globalState: () => {
6459
- return PublicKey.findProgramAddressSync(
6460
- [Buffer.from("global_state" /* GlobalState */)],
6461
- this.programId
6462
- );
6463
- },
6494
+ globalState: () => PublicKey.findProgramAddressSync(
6495
+ [Buffer.from(GLOBAL_STATE_SEED)],
6496
+ this.programId
6497
+ ),
6464
6498
  bondState: (bondType, bondName) => {
6465
- const seed = this.getBondTypeSeed(bondType);
6466
6499
  return PublicKey.findProgramAddressSync(
6467
- [Buffer.from("bond_state" /* BondState */), Buffer.from(seed), Buffer.from(bondName)],
6500
+ [Buffer.from(BOND_STATE_SEED), Buffer.from(getBondTypeSeed(bondType)), Buffer.from(bondName)],
6468
6501
  this.programId
6469
6502
  );
6470
6503
  },
6471
- // Derives a validator bond PDA based on the bond type and vote account
6472
6504
  validatorBond: (bondType, bondName, vote) => {
6473
6505
  const [bondState] = this.pda.bondState(bondType, bondName);
6474
6506
  return PublicKey.findProgramAddressSync(
6475
- [
6476
- Buffer.from("validator_bond" /* ValidatorBond */),
6477
- bondState.toBuffer(),
6478
- new PublicKey(vote).toBuffer()
6479
- ],
6507
+ [Buffer.from(VALIDATOR_BOND_SEED), bondState.toBuffer(), new PublicKey(vote).toBuffer()],
6480
6508
  this.programId
6481
6509
  );
6482
6510
  }
6483
6511
  };
6512
+ /**
6513
+ * Initialize global state
6514
+ */
6484
6515
  async globalInitialize(props) {
6485
- const ix = await this.buildBondGlobalStateInitializeIx(props);
6516
+ const ix = await this.getGlobalInitializeIx(props);
6486
6517
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6487
6518
  }
6488
6519
  /**
6489
6520
  * Initialize the program
6490
- * Default authority is the provider's wallet
6491
6521
  */
6492
6522
  async bondInitialize(props) {
6493
- console.log("Building bond initialize instruction with props:", props);
6494
- const ix = await this.buildBondInitializeIx(props);
6523
+ const ix = await this.getBondInitializeIx(props);
6495
6524
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6496
6525
  }
6497
6526
  /**
6498
6527
  * Register a new validator
6499
- * Default creator is the provider's wallet
6500
6528
  */
6501
6529
  async registerValidator(props) {
6502
- const ix = await this.buildRegisterIx(props);
6530
+ const ix = await this.getRegisterValidatorIx(props);
6503
6531
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6504
6532
  }
6505
6533
  /**
6506
6534
  * Top up collateral
6507
- * Default payer is the provider's wallet
6508
6535
  */
6509
6536
  async topUpCollateral(props) {
6510
- const ixs = await this.buildTopUpIXs(props);
6537
+ const ixs = await this.getTopUpIxs(props);
6511
6538
  return this.provider.sendAndConfirm?.(new Transaction().add(...ixs));
6512
6539
  }
6513
6540
  /**
6514
6541
  * Withdraw collateral
6515
- * Default withdrawal authority is the provider's wallet
6516
- * Default destination is the provider's wallet
6517
- * @return Transaction signature
6518
6542
  */
6519
6543
  async withdrawCollateral(props) {
6520
- const ix = await this.buildWithdrawIx(props);
6544
+ const ix = await this.getWithdrawIx(props);
6521
6545
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6522
6546
  }
6523
6547
  /**
6524
6548
  * Claim compensation
6525
- * Default authority is the provider's wallet
6526
- * @return Transaction signature
6527
6549
  */
6528
6550
  async claimCompensation(props) {
6529
- const ix = await this.buildClaimIx(props);
6551
+ const ix = await this.getClaimIx(props);
6530
6552
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6531
6553
  }
6532
6554
  /**
6533
6555
  * Update global configuration for the program
6534
- * Default authority is the provider's wallet
6535
- * Only the current authority can call this
6536
- * @return Transaction signature
6537
6556
  */
6538
6557
  async globalConfigure(props) {
6539
- const ix = await this.buildGlobalConfigureInstruction(props);
6558
+ const ix = await this.getGlobalConfigureIx(props);
6540
6559
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6541
6560
  }
6542
6561
  /**
6543
6562
  * Update global configuration for the program
6544
- * Default authority is the provider's wallet
6545
- * Only the current authority can call this
6546
- * @return Transaction signature
6547
6563
  */
6548
6564
  async bondConfigure(props) {
6549
- const ix = await this.buildConfigureIx(props);
6565
+ const ix = await this.getBondConfigureIx(props);
6550
6566
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6551
6567
  }
6552
6568
  /**
6553
6569
  * Set withdrawal authority for validator bond
6554
- * Only the validator identity can call this
6555
- * Default identity is the provider's wallet
6556
- * @return Transaction signature
6557
6570
  */
6558
6571
  async setWithdrawAuthority(props) {
6559
- const ix = await this.buildSetWithdrawAuthorityIx(props);
6572
+ const ix = await this.getSetWithdrawAuthorityIx(props);
6560
6573
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6561
6574
  }
6575
+ /**
6576
+ * Start crowdfunding bond session
6577
+ */
6562
6578
  async bondStart(props) {
6563
- const ix = await this.buildBondStartIx(props);
6579
+ const ix = await this.getBondSessionStartIx(props);
6564
6580
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6565
6581
  }
6582
+ /**
6583
+ * Finish crowdfunding bond session
6584
+ */
6566
6585
  async bondFinish(props) {
6567
- const ix = await this.buildBondFinishIx(props);
6586
+ const ix = await this.getBondSessionFinishIx(props);
6568
6587
  return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6569
6588
  }
6570
- async buildBondGlobalStateInitializeIx(props) {
6589
+ /**
6590
+ * Build global state initialize instruction
6591
+ */
6592
+ async getGlobalInitializeIx(props) {
6571
6593
  const [globalState] = this.pda.globalState();
6572
6594
  const authority = props.authority ?? this.provider.wallet?.publicKey;
6573
- return this.program.methods.globalInitialize().accountsPartial({
6574
- globalState,
6575
- authority
6576
- }).instruction();
6595
+ return this.program.methods.globalInitialize().accountsPartial({ globalState, authority }).instruction();
6577
6596
  }
6578
6597
  /**
6579
6598
  * Build configure instruction
6580
6599
  */
6581
- async buildGlobalConfigureInstruction(props) {
6600
+ async getGlobalConfigureIx(props) {
6582
6601
  const [globalState] = this.pda.globalState();
6583
6602
  const authority = props.authority ?? this.provider.wallet?.publicKey;
6584
6603
  return this.program.methods.globalConfigure({
6585
6604
  newAuthority: props.newAuthority ?? null
6586
- }).accountsStrict({
6587
- globalState,
6588
- authority
6589
- }).instruction();
6605
+ }).accountsStrict({ globalState, authority }).instruction();
6590
6606
  }
6591
6607
  /**
6592
- * Build initialize instruction
6608
+ * Build bond initialize instruction
6593
6609
  */
6594
- async buildBondInitializeIx(props) {
6610
+ async getBondInitializeIx(props) {
6595
6611
  const [bondState] = this.pda.bondState(props.bondType, props.name);
6612
+ const authority = props.authority ?? this.provider.wallet?.publicKey;
6596
6613
  const accounts = {
6597
6614
  bondState,
6598
- authority: props.authority ?? this.program.provider.wallet?.publicKey,
6615
+ authority,
6599
6616
  reserve: props.reserve,
6600
- systemProgram: SystemProgram.programId,
6601
- tokenProgram: TOKEN_PROGRAM_ID,
6602
6617
  reserveTokenAccount: null,
6603
6618
  mint: null
6604
6619
  };
@@ -6612,42 +6627,45 @@ var JBondClient = class _JBondClient {
6612
6627
  });
6613
6628
  return this.program.methods.bondInitialize({
6614
6629
  name: props.name,
6615
- bondType: props.bondType,
6630
+ bondType: bondTypeToAnchor(props.bondType),
6616
6631
  reserve: props.reserve,
6617
6632
  collateralType: props.collateralType
6618
- }).accountsPartial(
6619
- accounts
6620
- ).instruction();
6633
+ }).accountsPartial(accounts).instruction();
6621
6634
  }
6622
- async buildConfigureIx(props) {
6635
+ /**
6636
+ * Build bond configure instruction
6637
+ */
6638
+ async getBondConfigureIx(props) {
6623
6639
  const [bondState] = this.pda.bondState(props.bondType, props.name);
6640
+ const authority = props.authority ?? this.provider.wallet?.publicKey;
6624
6641
  return this.program.methods.bondConfigure({
6625
- status: props.bondStateStatus ?? null,
6642
+ status: props.status ?? null,
6626
6643
  newReserve: props.newReserve ?? null,
6627
6644
  newAuthority: props.newAuthority ?? null
6628
- }).accountsStrict({
6629
- bondState,
6630
- authority: props.authority ?? this.program.provider.wallet?.publicKey
6631
- }).instruction();
6645
+ }).accountsStrict({ bondState, authority }).instruction();
6632
6646
  }
6633
- async buildRegisterIx(props) {
6647
+ /**
6648
+ * Build register validator instruction
6649
+ */
6650
+ async getRegisterValidatorIx(props) {
6634
6651
  const { bondType, voteAccount, identity, name } = props;
6635
6652
  const [bondState] = this.pda.bondState(bondType, name);
6636
6653
  const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
6637
- const creator = props.creator ?? this.program.provider.wallet?.publicKey;
6654
+ const creator = props.creator ?? this.provider.wallet?.publicKey;
6638
6655
  if (!creator) {
6639
6656
  throw new Error("Missing creator");
6640
6657
  }
6641
- const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
6658
+ let collateralType = props.collateralType;
6659
+ if (!collateralType) {
6660
+ const bondState2 = await this.getBondState(bondType, name);
6661
+ collateralType = bondState2.collateralType;
6662
+ }
6642
6663
  const accounts = {
6643
6664
  bondState,
6644
6665
  validatorBond,
6645
6666
  identity,
6646
6667
  voteAccount,
6647
6668
  creator,
6648
- systemProgram: SystemProgram.programId,
6649
- tokenProgram: TOKEN_PROGRAM_ID,
6650
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
6651
6669
  bondTokenAccount: null,
6652
6670
  mint: null
6653
6671
  };
@@ -6656,42 +6674,49 @@ var JBondClient = class _JBondClient {
6656
6674
  },
6657
6675
  token: (mint) => {
6658
6676
  accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
6659
- Object.assign(accounts, { mint, bondTokenAccount: accounts.bondTokenAccount });
6677
+ accounts.mint = mint;
6660
6678
  }
6661
6679
  });
6662
- return this.program.methods.bondRegister(bondType, name).accountsPartial(accounts).instruction();
6680
+ return this.program.methods.bondRegister(bondTypeToAnchor(bondType), name).accountsPartial(accounts).instruction();
6663
6681
  }
6664
- async buildTopUpIXs(props) {
6665
- const { bondType, voteAccount, collateral, name } = props;
6666
- const payer = props.payer ?? this.program.provider.wallet?.publicKey;
6682
+ /**
6683
+ * Build top up collateral instructions
6684
+ */
6685
+ async getTopUpIxs(props) {
6686
+ const { bondType, voteAccount, amount, name } = props;
6687
+ const payer = props.payer ?? this.provider.wallet?.publicKey;
6667
6688
  if (!payer) {
6668
6689
  throw new Error("Missing payer");
6669
6690
  }
6670
- const instructions = [];
6671
6691
  const [bondState] = this.pda.bondState(bondType, name);
6672
6692
  const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
6673
- console.log("Top up collateral for bond:", { bondState: bondState.toBase58(), validatorBond: validatorBond.toBase58() });
6674
- const bond = await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
6675
- if (!bond) {
6676
- instructions.push(await this.buildRegisterIx({
6677
- bondType: props.bondType,
6678
- name: props.name,
6679
- voteAccount: props.voteAccount,
6680
- identity: props.identity,
6681
- creator: props.payer
6682
- }));
6693
+ let collateralType = props.collateralType;
6694
+ if (!collateralType) {
6695
+ const bondState2 = await this.getBondState(bondType, name);
6696
+ collateralType = bondState2.collateralType;
6697
+ }
6698
+ const instructions = [];
6699
+ try {
6700
+ await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
6701
+ } catch {
6702
+ instructions.push(
6703
+ await this.getRegisterValidatorIx({
6704
+ bondType: props.bondType,
6705
+ name: props.name,
6706
+ voteAccount: props.voteAccount,
6707
+ identity: props.identity,
6708
+ creator: props.payer,
6709
+ collateralType
6710
+ })
6711
+ );
6683
6712
  }
6684
- const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
6685
6713
  const accounts = {
6686
6714
  bondState,
6687
6715
  validatorBond,
6688
6716
  payer,
6689
- systemProgram: SystemProgram.programId,
6690
6717
  payerTokenAccount: null,
6691
6718
  bondTokenAccount: null,
6692
6719
  stakeAccount: null,
6693
- tokenProgram: null,
6694
- associatedTokenProgram: null,
6695
6720
  stakeProgram: null
6696
6721
  };
6697
6722
  matchVariant(collateralType, {
@@ -6700,35 +6725,38 @@ var JBondClient = class _JBondClient {
6700
6725
  token: (mint) => {
6701
6726
  accounts.payerTokenAccount = getAssociatedTokenAddressSync(mint, payer);
6702
6727
  accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
6703
- accounts.tokenProgram = TOKEN_PROGRAM_ID;
6704
- accounts.associatedTokenProgram = ASSOCIATED_TOKEN_PROGRAM_ID;
6705
6728
  }
6706
6729
  });
6707
6730
  instructions.push(
6708
- await this.program.methods.bondTopUp(this.lamports(collateral.amount)).accountsPartial(accounts).instruction()
6731
+ await this.program.methods.bondTopUp(solToLamports(amount)).accountsPartial(accounts).instruction()
6709
6732
  );
6710
6733
  return instructions;
6711
6734
  }
6712
- async buildWithdrawIx(props) {
6713
- const { bondType, voteAccount, withdraw, name } = props;
6735
+ /**
6736
+ * Build withdraw collateral instruction
6737
+ */
6738
+ async getWithdrawIx(props) {
6739
+ const { bondType, voteAccount, amount, name } = props;
6714
6740
  const [bondState] = this.pda.bondState(bondType, name);
6715
6741
  const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
6716
- const payer = this.program.provider.wallet?.publicKey;
6742
+ const payer = this.provider.wallet?.publicKey;
6717
6743
  const destination = props.destination ?? payer;
6718
6744
  if (!payer || !destination) {
6719
6745
  throw new Error("Missing payer/destination");
6720
6746
  }
6721
- const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
6747
+ let collateralType = props.collateralType;
6748
+ if (!collateralType) {
6749
+ const bondState2 = await this.getBondState(bondType, name);
6750
+ collateralType = bondState2.collateralType;
6751
+ }
6722
6752
  const accounts = {
6723
6753
  bondState,
6724
6754
  validatorBond,
6725
- withdrawalAuthority: props.withdrawalAuthority ?? payer,
6726
6755
  destination,
6756
+ withdrawalAuthority: props.withdrawalAuthority ?? payer,
6727
6757
  destinationTokenAccount: null,
6728
6758
  bondTokenAccount: null,
6729
6759
  stakeAccount: null,
6730
- systemProgram: SystemProgram.programId,
6731
- tokenProgram: null,
6732
6760
  stakeProgram: null
6733
6761
  };
6734
6762
  matchVariant(collateralType, {
@@ -6737,31 +6765,34 @@ var JBondClient = class _JBondClient {
6737
6765
  token: (mint) => {
6738
6766
  accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, destination, true);
6739
6767
  accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
6740
- accounts.tokenProgram = TOKEN_PROGRAM_ID;
6741
6768
  }
6742
6769
  });
6743
- return this.program.methods.bondWithdraw(this.lamports(withdraw.amount)).accountsPartial(accounts).instruction();
6770
+ return this.program.methods.bondWithdraw(solToLamports(amount)).accountsPartial(accounts).instruction();
6744
6771
  }
6745
- async buildClaimIx(props) {
6746
- const { bondType, name } = props;
6772
+ /**
6773
+ * Build claim instruction
6774
+ */
6775
+ async getClaimIx(props) {
6776
+ const { bondType, name, amount } = props;
6747
6777
  const [bondState] = this.pda.bondState(bondType, name);
6748
6778
  const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
6749
- const reserve = props.reserve ?? (await this.getBondState(bondType, name)).bondState.reserve;
6750
- const authority = props.authority ?? this.program.provider.wallet?.publicKey;
6751
- if (!reserve) {
6752
- throw new Error("Reserve not set");
6779
+ const authority = props.authority ?? this.provider.wallet?.publicKey;
6780
+ let reserve = props.reserve;
6781
+ let collateralType = props.collateralType;
6782
+ if (!collateralType || !reserve) {
6783
+ const bondState2 = await this.getBondState(bondType, name);
6784
+ collateralType = collateralType ?? bondState2.collateralType;
6785
+ reserve = reserve ?? bondState2.reserve;
6753
6786
  }
6754
- const collateralType = (await this.getBondState(bondType, name)).bondState.collateralType;
6755
6787
  const accounts = {
6756
6788
  bondState,
6757
6789
  validatorBond,
6758
6790
  reserve,
6759
- reserveTokenAccount: null,
6760
6791
  authority,
6792
+ destinationTokenAccount: null,
6761
6793
  bondTokenAccount: null,
6794
+ reserveTokenAccount: null,
6762
6795
  stakeAccount: null,
6763
- systemProgram: SystemProgram.programId,
6764
- tokenProgram: null,
6765
6796
  stakeProgram: null
6766
6797
  };
6767
6798
  matchVariant(collateralType, {
@@ -6771,161 +6802,90 @@ var JBondClient = class _JBondClient {
6771
6802
  accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
6772
6803
  accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
6773
6804
  accounts.reserveTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
6774
- accounts.tokenProgram = TOKEN_PROGRAM_ID;
6775
6805
  }
6776
6806
  });
6777
- return this.program.methods.bondClaim(this.lamports(props.claim.amount)).accountsPartial(
6778
- accounts
6779
- ).instruction();
6807
+ return this.program.methods.bondClaim(solToLamports(amount)).accountsPartial(accounts).instruction();
6780
6808
  }
6781
- async buildSetWithdrawAuthorityIx(props) {
6809
+ /**
6810
+ * Build set withdraw authority instruction
6811
+ */
6812
+ async getSetWithdrawAuthorityIx(props) {
6782
6813
  const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
6814
+ const identity = props.identity ?? this.provider.wallet?.publicKey;
6783
6815
  return this.program.methods.bondSetWithdrawAuthority().accountsPartial({
6784
6816
  validatorBond,
6785
- identity: props.identity ?? this.program.provider.wallet?.publicKey,
6817
+ identity,
6786
6818
  newWithdrawAuthority: props.newWithdrawAuthority ?? null
6787
6819
  }).instruction();
6788
6820
  }
6789
- async buildBondFinishIx(props) {
6790
- const [bondState] = this.pda.bondState(props.bondType, props.name);
6791
- return this.program.methods.sessionFinish().accountsPartial({
6792
- bondState,
6793
- authority: this.program.provider.wallet?.publicKey
6794
- }).instruction();
6795
- }
6796
- async migrateBond(props) {
6797
- const ix = await this.buildBondMigrateIx(props);
6798
- return this.provider.sendAndConfirm?.(new Transaction().add(ix));
6799
- }
6800
- async buildBondMigrateIx(props) {
6801
- const [bondState] = this.pda.bondState(props.bondType, props.name);
6802
- const [legacyValidatorBond] = PublicKey.findProgramAddressSync(
6803
- [
6804
- Buffer.from("validator_bond"),
6805
- new PublicKey(props.voteAccount).toBuffer()
6806
- ],
6807
- this.programId
6808
- );
6809
- const [validatorBond] = this.pda.validatorBond(props.bondType, props.name, props.voteAccount);
6810
- return this.program.methods.migrateBond().accountsPartial({
6811
- bondState,
6812
- legacyValidatorBond,
6813
- legacyVoteAccount: new PublicKey(props.voteAccount),
6814
- validatorBond,
6815
- creator: this.program.provider.wallet?.publicKey
6816
- }).instruction();
6817
- }
6818
- async buildBondStartIx(props) {
6819
- const [bondState] = this.pda.bondState(props.bondType, props.name);
6820
- return this.program.methods.sessionStart(new import_bn.BN(props.duration_secs)).accountsPartial({
6821
- bondState,
6822
- authority: this.program.provider.wallet?.publicKey
6823
- }).instruction();
6824
- }
6825
6821
  /**
6826
- * Fetch global state or throw if not found
6822
+ * Build finish crowdfunding session instruction
6827
6823
  */
6828
- async getGlobalState() {
6829
- const [globalState] = this.pda.globalState();
6830
- return await this.program.account.globalState.fetch(globalState);
6824
+ async getBondSessionFinishIx(props) {
6825
+ const [bondState] = this.pda.bondState(props.bondType, props.name);
6826
+ const authority = this.provider.wallet?.publicKey;
6827
+ return this.program.methods.sessionFinish().accountsPartial({ bondState, authority }).instruction();
6831
6828
  }
6832
6829
  /**
6833
- * Fetch bond state with stats
6834
- * @param bondType - Type of the bond
6835
- * @param bondName - Name of the bond
6836
- * @param withStats
6830
+ * Build start crowdfunding session instruction
6837
6831
  */
6838
- async getBondState(bondType, bondName, withStats = false) {
6839
- const bondState = await this.program.account.bondState.fetch(this.pda.bondState(bondType, bondName)[0]);
6840
- return {
6841
- bondState,
6842
- stateStats: withStats ? await this.getBondStateStats(bondState) : null
6843
- };
6832
+ async getBondSessionStartIx(props) {
6833
+ const [bondState] = this.pda.bondState(props.bondType, props.name);
6834
+ const authority = this.provider.wallet?.publicKey;
6835
+ return this.program.methods.sessionStart(new import_bn.BN(props.duration)).accountsPartial({ bondState, authority }).instruction();
6844
6836
  }
6845
6837
  /**
6846
6838
  * Get all bond states with total collected collateral
6847
6839
  */
6848
6840
  async getAllBondStates(bondType, sessionStatus) {
6849
- const bondStates = [];
6850
- const bondStateAccounts = await this.program.account.bondState.all();
6851
- for (const { publicKey, account: state } of bondStateAccounts) {
6852
- if (!sameVariant(state.bondType, bondType)) {
6841
+ const result = [];
6842
+ const accounts = await this.program.account.bondState.all();
6843
+ for (const { publicKey, account } of accounts) {
6844
+ if (!sameVariant(account.bondType, bondTypeToAnchor(bondType))) {
6853
6845
  continue;
6854
6846
  }
6855
- if (sessionStatus !== void 0 && this.getBondStateSessionStatus(state) !== sessionStatus) {
6847
+ if (sessionStatus !== void 0 && this.getBondStateSessionStatus(account) !== sessionStatus) {
6856
6848
  continue;
6857
6849
  }
6858
- const bondStateStats = await this.getBondStateStats(state);
6859
- bondStates.push(
6860
- {
6861
- publicKey,
6862
- bondState: state,
6863
- stateStats: bondStateStats
6864
- }
6865
- );
6850
+ const stateStats = await this.getBondStateStats(account);
6851
+ result.push({ publicKey, bondState: account, stateStats });
6866
6852
  }
6867
- return bondStates;
6853
+ return result;
6868
6854
  }
6869
6855
  /**
6870
- * Get session status for bond state
6856
+ * Fetch global state or throw if not found
6871
6857
  */
6872
- getBondStateSessionStatus(bondState) {
6873
- const now = Math.floor(Date.now() / 1e3);
6874
- if (bondState.sessionFinishTs.toNumber() > now) {
6875
- return 0 /* Live */;
6876
- } else {
6877
- return 1 /* Finished */;
6878
- }
6858
+ async getGlobalState() {
6859
+ const [publicKey] = this.pda.globalState();
6860
+ this.debug(`Fetching global state ${publicKey}...`);
6861
+ const data = await this.program.account.globalState.fetch(publicKey);
6862
+ return { publicKey, ...data };
6879
6863
  }
6880
6864
  /**
6881
- * Get all validator bonds for a given bond state
6865
+ * Fetch bond state with stats
6882
6866
  */
6883
- async getValidatorBondsByState(bondType, bondName) {
6884
- const validatorBonds = [];
6885
- const bondStatePda = this.pda.bondState(bondType, bondName)[0];
6886
- const validatorBondAccounts = await this.program.account.validatorBond.all([
6887
- {
6888
- memcmp: {
6889
- offset: 8,
6890
- bytes: bondStatePda.toBase58()
6891
- }
6892
- }
6893
- ]);
6894
- for (const { account: vb } of validatorBondAccounts) {
6895
- validatorBonds.push(vb);
6896
- }
6897
- return validatorBonds;
6867
+ async getBondState(bondType, bondName) {
6868
+ const [publicKey] = this.pda.bondState(bondType, bondName);
6869
+ this.debug(`Fetching bond state ${publicKey}...`);
6870
+ const data = await this.program.account.bondState.fetch(publicKey);
6871
+ return { publicKey, ...data };
6898
6872
  }
6899
6873
  /**
6900
6874
  * Fetch validator bond data or null if not found
6901
6875
  */
6902
6876
  async getValidatorBond(bondType, bondName, vote) {
6903
- const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
6904
- try {
6905
- return await this.program.account.validatorBond.fetch(address);
6906
- } catch {
6907
- return null;
6908
- }
6909
- }
6910
- /**
6911
- * Get bond collateral type
6912
- */
6913
- async getBondCollateralType(bondType, bondName) {
6914
- const bondState = await this.getBondState(bondType, bondName);
6915
- return bondState.bondState.collateralType;
6877
+ const [publicKey] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
6878
+ const data = await this.program.account.validatorBond.fetch(publicKey);
6879
+ return { publicKey, ...data };
6916
6880
  }
6917
6881
  /**
6918
6882
  * Get validator bond account balance (in SOL)
6919
- * @param bondType - Type of the bond
6920
- * @param bondName - Name of the bond
6921
- * @param vote - Vote account public key
6922
- * @return Balance in lamports
6923
6883
  */
6924
6884
  async getValidatorBondBalance(bondType, bondName, vote) {
6925
6885
  const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
6926
- const bondStateData = await this.getBondState(bondType, bondName);
6927
- const bondStateCollateralType = bondStateData.bondState.collateralType;
6928
- return await matchVariant(bondStateCollateralType, {
6886
+ const bondState = await this.getBondState(bondType, bondName);
6887
+ const collateralType = bondState.collateralType;
6888
+ return await matchVariant(collateralType, {
6929
6889
  native: async () => {
6930
6890
  const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
6931
6891
  if (!accountInfo) {
@@ -6939,7 +6899,7 @@ var JBondClient = class _JBondClient {
6939
6899
  const tokenAccount = getAssociatedTokenAddressSync(mint, address, true);
6940
6900
  try {
6941
6901
  const balance = await this.connection.getTokenAccountBalance(tokenAccount);
6942
- return Number(balance.value.uiAmount ?? 0) * LAMPORTS_PER_SOL;
6902
+ return solToLamports(balance.value.amount).toNumber();
6943
6903
  } catch {
6944
6904
  return 0;
6945
6905
  }
@@ -6950,8 +6910,8 @@ var JBondClient = class _JBondClient {
6950
6910
  * Get total collected collateral for a bond state
6951
6911
  */
6952
6912
  async getBondStateTotalCollected(bondType, bondName, votes) {
6953
- const bondStateData = await this.getBondState(bondType, bondName);
6954
- const bondStateCollateralType = bondStateData.bondState.collateralType;
6913
+ const bondState = await this.getBondState(bondType, bondName);
6914
+ const collateralType = bondState.collateralType;
6955
6915
  const chunk = (arr, n = 100) => {
6956
6916
  const res = [];
6957
6917
  for (let i = 0; i < arr.length; i += n) {
@@ -6959,7 +6919,7 @@ var JBondClient = class _JBondClient {
6959
6919
  }
6960
6920
  return res;
6961
6921
  };
6962
- return await matchVariant(bondStateCollateralType, {
6922
+ return await matchVariant(collateralType, {
6963
6923
  native: async () => {
6964
6924
  const addresses = votes.map((vote) => {
6965
6925
  const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
@@ -7009,189 +6969,16 @@ var JBondClient = class _JBondClient {
7009
6969
  }
7010
6970
  });
7011
6971
  }
7012
- /**
7013
- * Get transaction history for a specific validator bond account
7014
- */
7015
- async getHistory(bondType, bondName, vote, options) {
7016
- const [legacyValidatorBondAccount] = PublicKey.findProgramAddressSync(
7017
- [
7018
- Buffer.from("validator_bond" /* ValidatorBond */),
7019
- new PublicKey(vote).toBuffer()
7020
- ],
7021
- this.programId
7022
- );
7023
- const validatorBond = this.pda.validatorBond(bondType, bondName, vote);
7024
- const legacySignatures = (await this.connection.getSignaturesForAddress(
7025
- legacyValidatorBondAccount,
7026
- {
7027
- limit: options?.limit || 1e3,
7028
- before: options?.before,
7029
- until: options?.until
7030
- },
7031
- "confirmed"
7032
- )).filter((sig) => !sig.err);
7033
- const newSignatures = (await this.connection.getSignaturesForAddress(
7034
- validatorBond[0],
7035
- {
7036
- limit: options?.limit || 1e3,
7037
- before: options?.before,
7038
- until: options?.until
7039
- },
7040
- "confirmed"
7041
- )).filter((sig) => !sig.err);
7042
- const signatureStrings = legacySignatures.map((sig) => sig.signature);
7043
- signatureStrings.push(...newSignatures.map((sig) => sig.signature));
7044
- const signatures = [...legacySignatures, ...newSignatures];
7045
- const BATCH_SIZE = 100;
7046
- const allTransactions = [];
7047
- for (let i = 0; i < signatureStrings.length; i += BATCH_SIZE) {
7048
- const batch = signatureStrings.slice(i, i + BATCH_SIZE);
7049
- const transactions = await this.connection.getParsedTransactions(
7050
- batch,
7051
- {
7052
- maxSupportedTransactionVersion: 0,
7053
- commitment: "confirmed"
7054
- }
7055
- );
7056
- allTransactions.push(...transactions);
7057
- }
7058
- const cluster = options?.cluster || "mainnet-beta";
7059
- const history = [];
7060
- for (const [idx, tx] of allTransactions.entries()) {
7061
- const sigInfo = signatures[idx];
7062
- if (!tx || !tx.meta || tx.meta.err !== null) {
7063
- continue;
7064
- }
7065
- try {
7066
- const slot = tx.slot || 0;
7067
- const instructions = tx.transaction.message.instructions;
7068
- for (const instruction of instructions) {
7069
- if ("programId" in instruction && instruction.programId.equals(this.options.programId ?? this.program.programId)) {
7070
- const ixData = instruction;
7071
- if ("parsed" in ixData && ixData.parsed) {
7072
- continue;
7073
- }
7074
- const data = ixData.data;
7075
- if (!data) {
7076
- continue;
7077
- }
7078
- let type = null;
7079
- let amount = 0;
7080
- try {
7081
- const dataBuffer = bs582.decode(data);
7082
- if (dataBuffer.length >= 8) {
7083
- const discriminator = dataBuffer.subarray(0, 8);
7084
- const legacyRegisterDiscriminator = this.getInstructionDiscriminator("register");
7085
- const legacyTopUpDiscriminator = this.getInstructionDiscriminator("topUp");
7086
- const legacyClaimDiscriminator = this.getInstructionDiscriminator("claim");
7087
- const legacyWithdrawDiscriminator = this.getInstructionDiscriminator("withdraw");
7088
- const bondRegisterDiscriminator = this.getInstructionDiscriminator("bondRegister");
7089
- const bondTopUpDiscriminator = this.getInstructionDiscriminator("bondTopUp");
7090
- const bondClaimDiscriminator = this.getInstructionDiscriminator("bondClaim");
7091
- const bondWithdrawDiscriminator = this.getInstructionDiscriminator("bondWithdraw");
7092
- console.log("Discriminator:", Buffer.from(discriminator).toString("hex"));
7093
- if (Buffer.from(discriminator).equals(Buffer.from(legacyRegisterDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondRegisterDiscriminator))) {
7094
- type = "deposit" /* Deposit */;
7095
- if (dataBuffer.length >= 16 && Buffer.from(discriminator).equals(Buffer.from(legacyRegisterDiscriminator))) {
7096
- const amountBytes = dataBuffer.subarray(8, 16);
7097
- const amountBN = new import_bn.BN(amountBytes, "le");
7098
- amount = amountBN.toNumber() / LAMPORTS_PER_SOL;
7099
- }
7100
- } else if (dataBuffer.length >= 16) {
7101
- const amountBytes = dataBuffer.subarray(8, 16);
7102
- const amountBN = new import_bn.BN(amountBytes, "le");
7103
- amount = amountBN.toNumber() / LAMPORTS_PER_SOL;
7104
- if (Buffer.from(discriminator).equals(Buffer.from(legacyTopUpDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondTopUpDiscriminator))) {
7105
- type = "deposit" /* Deposit */;
7106
- } else if (Buffer.from(discriminator).equals(Buffer.from(legacyClaimDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondClaimDiscriminator))) {
7107
- type = "compensation" /* Compensation */;
7108
- } else if (Buffer.from(discriminator).equals(Buffer.from(legacyWithdrawDiscriminator)) || Buffer.from(discriminator).equals(Buffer.from(bondWithdrawDiscriminator))) {
7109
- type = "withdrawal" /* Withdrawal */;
7110
- }
7111
- }
7112
- }
7113
- } catch (e) {
7114
- console.warn("Failed to decode instruction data:", e);
7115
- }
7116
- if (type && (amount > 0 || type === "deposit" /* Deposit */)) {
7117
- history.push({
7118
- signature: sigInfo.signature,
7119
- slot,
7120
- epoch: slotToEpoch(slot, cluster),
7121
- type,
7122
- amount
7123
- });
7124
- }
7125
- }
7126
- }
7127
- } catch (error) {
7128
- console.error(`Error processing transaction ${sigInfo.signature}:`, error);
7129
- }
7130
- }
7131
- return history.toSorted((a, b) => b.slot - a.slot);
7132
- }
7133
- /**
7134
- * Get full transaction history by paginating through results
7135
- * @param bondType
7136
- * @param bondName
7137
- * @param voteAccount
7138
- * @param pageSize
7139
- */
7140
- async getFullHistory(bondType, bondName, voteAccount, pageSize = 100) {
7141
- const allHistory = [];
7142
- let before;
7143
- while (true) {
7144
- const batch = await this.getHistory(bondType, bondName, voteAccount, {
7145
- limit: pageSize,
7146
- before
7147
- });
7148
- if (batch.length === 0) {
7149
- break;
7150
- }
7151
- allHistory.push(...batch);
7152
- before = batch.at(-1)?.signature;
7153
- if (batch.length < pageSize) {
7154
- break;
7155
- }
7156
- }
7157
- return allHistory;
7158
- }
7159
- /**
7160
- * Get instruction discriminator from IDL
7161
- * @param instructionName
7162
- * @private
7163
- */
7164
- getInstructionDiscriminator(instructionName) {
7165
- const legacyDiscriminators = {
7166
- register: [211, 124, 67, 15, 211, 194, 178, 240],
7167
- topUp: [181, 157, 89, 67, 143, 182, 52, 72],
7168
- claim: [62, 198, 214, 193, 213, 159, 108, 210],
7169
- withdraw: [183, 18, 70, 156, 148, 109, 161, 34]
7170
- };
7171
- if (legacyDiscriminators[instructionName]) {
7172
- return new Uint8Array(legacyDiscriminators[instructionName]);
7173
- }
7174
- if (instructionName.startsWith("bond")) {
7175
- const instruction = this.program.idl.instructions.find((ix) => ix.name === instructionName);
7176
- if (!instruction) {
7177
- throw new Error(`Instruction ${instructionName} not found in IDL`);
7178
- }
7179
- if (!instruction.discriminator || !Array.isArray(instruction.discriminator)) {
7180
- throw new Error(`Discriminator not found for instruction ${instructionName}`);
7181
- }
7182
- return new Uint8Array(instruction.discriminator);
7183
- }
7184
- throw new Error(`Unknown instruction: ${instructionName}`);
7185
- }
7186
6972
  /**
7187
6973
  * Get bond state stats
7188
6974
  * @param state
7189
6975
  * @private
7190
6976
  */
7191
6977
  async getBondStateStats(state) {
7192
- const validatorBonds = await this.getValidatorBondsByState(state.bondType, state.name);
6978
+ const bondType = anchorToBondType(state.bondType);
6979
+ const validatorBonds = await this.getBondValidatorStates(bondType, state.name);
7193
6980
  const totalCollected = await this.getBondStateTotalCollected(
7194
- state.bondType,
6981
+ bondType,
7195
6982
  state.name,
7196
6983
  validatorBonds.map((vb) => vb.voteAccount)
7197
6984
  );
@@ -7200,8 +6987,36 @@ var JBondClient = class _JBondClient {
7200
6987
  status: this.getBondStateSessionStatus(state)
7201
6988
  };
7202
6989
  }
7203
- lamports(n) {
7204
- return new import_bn.BN((n ?? 0) * LAMPORTS_PER_SOL);
6990
+ /**
6991
+ * Get all validator bonds for a given bond state
6992
+ */
6993
+ async getBondValidatorStates(bondType, bondName) {
6994
+ const [bondState] = this.pda.bondState(bondType, bondName);
6995
+ const accounts = await this.program.account.validatorBond.all([
6996
+ {
6997
+ memcmp: {
6998
+ offset: 8,
6999
+ // discriminator
7000
+ bytes: bondState.toBase58()
7001
+ }
7002
+ }
7003
+ ]);
7004
+ const result = [];
7005
+ for (const { publicKey, account } of accounts) {
7006
+ result.push({ publicKey, ...account });
7007
+ }
7008
+ return result;
7009
+ }
7010
+ /**
7011
+ * Get session status for bond state
7012
+ */
7013
+ getBondStateSessionStatus(bondState) {
7014
+ const now = Math.floor(Date.now() / 1e3);
7015
+ if (bondState.sessionFinishTs.toNumber() > now) {
7016
+ return 0 /* Live */;
7017
+ } else {
7018
+ return 1 /* Finished */;
7019
+ }
7205
7020
  }
7206
7021
  };
7207
7022
  /*! Bundled license information:
@@ -7218,6 +7033,6 @@ buffer/index.js:
7218
7033
  *)
7219
7034
  */
7220
7035
 
7221
- export { BondClientEnv, BondStateStatusVariant, BondTransactionType, BondTypeVariant, ENV_PROGRAM_ID, JBondClient, JPOOL_STAKE_POOL, NodeWallet, Seeds, SessionStatus, bondTypeToSeed };
7036
+ export { BOND_STATE_SEED, BondClientEnv, BondTransactionType, BondType, CROWDFUNDING_BOND_SEED, ENV_PROGRAM_ID, GLOBAL_STATE_SEED, JBondClient, NodeWallet, STANDARD_BOND_SEED, SessionStatus, VALIDATOR_BOND_SEED };
7222
7037
  //# sourceMappingURL=index.mjs.map
7223
7038
  //# sourceMappingURL=index.mjs.map