@jpool/bond-sdk 0.10.4 → 0.10.5

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