@jpool/bond-sdk 0.5.0 → 0.6.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,86 +1,6 @@
1
- import { BN, Program, AnchorProvider, Wallet } from '@coral-xyz/anchor';
2
- import { PublicKey, Connection, Keypair, TransactionInstruction } from '@solana/web3.js';
3
-
4
- type Config = {
5
- rpcUrl: string;
6
- };
7
- type ValidatorBondAccount = {
8
- identity: PublicKey;
9
- voteAccount: PublicKey;
10
- withdrawalAuthority?: string;
11
- totalWithdrawn: number;
12
- lastWithdrawalEpoch: number;
13
- isActive: boolean;
14
- createdAt: number;
15
- bump: number;
16
- };
17
- type InitializeProps = {
18
- authority: PublicKey;
19
- reserveAddress: PublicKey;
20
- };
21
- type RegisterValidatorProps = {
22
- creator: PublicKey;
23
- identity: PublicKey;
24
- voteAccount: PublicKey;
25
- initialCollateral: number;
26
- withdrawalAuthority?: PublicKey;
27
- };
28
- type TopUpCollateralProps = {
29
- user: PublicKey;
30
- voteAccount: PublicKey;
31
- amount: number;
32
- };
33
- type WithdrawCollateralProps = {
34
- withdrawalAuthority: PublicKey;
35
- voteAccount: PublicKey;
36
- destination: PublicKey;
37
- amount: number;
38
- };
39
- type WithdrawCompensationProps = {
40
- authority: PublicKey;
41
- voteAccount: PublicKey;
42
- amount: number;
43
- };
44
- type GetHistoryProps = {
45
- voteAccount: PublicKey;
46
- options?: {
47
- limit?: number;
48
- before?: string;
49
- until?: string;
50
- };
51
- };
52
- type GetHistoryGroupedProps = {
53
- voteAccount: PublicKey;
54
- epochsCount?: number;
55
- };
56
- type GlobalState = {
57
- authority: PublicKey;
58
- totalValidators: number;
59
- totalCollateral: BN;
60
- totalWithdrawn: BN;
61
- bump: number;
62
- };
63
- type EpochHistoryItem = {
64
- epoch: number;
65
- deposits: number;
66
- withdrawals: number;
67
- balanceChange: number;
68
- signatures: string[];
69
- };
70
- type TransactionHistoryItem = {
71
- signature: string;
72
- slot: number;
73
- epoch: number;
74
- type: BondTransactionType;
75
- amount: number;
76
- beforeBalance?: number;
77
- afterBalance?: number;
78
- };
79
- declare enum BondTransactionType {
80
- Deposit = "deposit",
81
- Withdrawal = "withdrawal",
82
- Compensation = "compensation"
83
- }
1
+ import * as _solana_web3_js from '@solana/web3.js';
2
+ import { PublicKey, Connection, Keypair, PublicKeyInitData, Transaction, VersionedTransaction } from '@solana/web3.js';
3
+ import { BN, AnchorProvider, Program, Wallet as Wallet$1 } from '@coral-xyz/anchor';
84
4
 
85
5
  /**
86
6
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -89,38 +9,46 @@ declare enum BondTransactionType {
89
9
  * IDL can be found at `target/idl/jbond.json`.
90
10
  */
91
11
  type Jbond = {
92
- address: '8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr';
93
- metadata: {
94
- name: 'jbond';
95
- version: '0.1.0';
96
- spec: '0.1.0';
97
- description: 'Validator compensation program for boosting APR';
12
+ "address": "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU";
13
+ "metadata": {
14
+ "name": "jbond";
15
+ "version": "0.2.0";
16
+ "spec": "0.1.0";
17
+ "description": "Jpool Bond Program";
98
18
  };
99
- instructions: [
19
+ "instructions": [
100
20
  {
101
- name: 'bondInit';
102
- docs: [
103
- 'Register validator and fund initial collateral'
21
+ "name": "claim";
22
+ "docs": [
23
+ "Claims compensation for a validator.",
24
+ "Transfers funds from the validator's bond account to reserve.",
25
+ "",
26
+ "# Arguments",
27
+ "* `amount` - Amount of compensation to claim (must be positive).",
28
+ "",
29
+ "# Errors",
30
+ "Fails if the authority is invalid, if the validator is not active,",
31
+ "if the amount is zero, or if there are insufficient funds."
104
32
  ];
105
- discriminator: [
106
- 220,
33
+ "discriminator": [
34
+ 62,
35
+ 198,
36
+ 214,
37
+ 193,
38
+ 213,
39
+ 159,
107
40
  108,
108
- 156,
109
- 81,
110
- 16,
111
- 185,
112
- 144,
113
- 157
41
+ 210
114
42
  ];
115
- accounts: [
43
+ "accounts": [
116
44
  {
117
- name: 'globalState';
118
- writable: true;
119
- pda: {
120
- seeds: [
45
+ "name": "globalState";
46
+ "writable": true;
47
+ "pda": {
48
+ "seeds": [
121
49
  {
122
- kind: 'const';
123
- value: [
50
+ "kind": "const";
51
+ "value": [
124
52
  103,
125
53
  108,
126
54
  111,
@@ -139,13 +67,13 @@ type Jbond = {
139
67
  };
140
68
  },
141
69
  {
142
- name: 'validatorBondAccount';
143
- writable: true;
144
- pda: {
145
- seeds: [
70
+ "name": "validatorBond";
71
+ "writable": true;
72
+ "pda": {
73
+ "seeds": [
146
74
  {
147
- kind: 'const';
148
- value: [
75
+ "kind": "const";
76
+ "value": [
149
77
  118,
150
78
  97,
151
79
  108,
@@ -163,130 +91,155 @@ type Jbond = {
163
91
  ];
164
92
  },
165
93
  {
166
- kind: 'account';
167
- path: 'voteAccount';
94
+ "kind": "account";
95
+ "path": "validator_bond.vote_account";
96
+ "account": "validatorBond";
168
97
  }
169
98
  ];
170
99
  };
171
100
  },
172
101
  {
173
- name: 'identity';
174
- },
175
- {
176
- name: 'voteAccount';
102
+ "name": "reserve";
103
+ "writable": true;
177
104
  },
178
105
  {
179
- name: 'creator';
180
- docs: [
181
- 'The account creating the bond (pays for account creation and initial collateral)'
106
+ "name": "authority";
107
+ "docs": [
108
+ "Authority that can trigger claims"
182
109
  ];
183
- writable: true;
184
- signer: true;
110
+ "signer": true;
185
111
  },
186
112
  {
187
- name: 'systemProgram';
188
- address: '11111111111111111111111111111111';
113
+ "name": "systemProgram";
114
+ "address": "11111111111111111111111111111111";
189
115
  }
190
116
  ];
191
- args: [
117
+ "args": [
192
118
  {
193
- name: 'initialCollateral';
194
- type: 'u64';
195
- },
196
- {
197
- name: 'withdrawalAuthority';
198
- type: {
199
- option: 'pubkey';
200
- };
119
+ "name": "amount";
120
+ "type": "u64";
201
121
  }
202
122
  ];
203
123
  },
204
124
  {
205
- name: 'bondTopUp';
206
- docs: [
207
- 'Top up collateral for existing validator'
125
+ "name": "initialize";
126
+ "docs": [
127
+ "Initializes the global state for the bonding program.",
128
+ "Sets the authority and reserve account for managing validator bonds.",
129
+ "",
130
+ "# Errors",
131
+ "Fails if the global state account is already initialized or if the payer lacks",
132
+ "sufficient funds."
208
133
  ];
209
- discriminator: [
210
- 132,
211
- 225,
212
- 254,
213
- 187,
134
+ "discriminator": [
135
+ 175,
136
+ 175,
137
+ 109,
138
+ 31,
139
+ 13,
214
140
  152,
215
- 162,
216
- 176,
217
- 66
141
+ 155,
142
+ 237
218
143
  ];
219
- accounts: [
144
+ "accounts": [
220
145
  {
221
- name: 'validatorBondAccount';
222
- writable: true;
223
- pda: {
224
- seeds: [
146
+ "name": "globalState";
147
+ "writable": true;
148
+ "pda": {
149
+ "seeds": [
225
150
  {
226
- kind: 'const';
227
- value: [
228
- 118,
151
+ "kind": "const";
152
+ "value": [
153
+ 103,
154
+ 108,
155
+ 111,
156
+ 98,
229
157
  97,
230
158
  108,
231
- 105,
232
- 100,
159
+ 95,
160
+ 115,
161
+ 116,
233
162
  97,
234
163
  116,
235
- 111,
236
- 114,
237
- 95,
238
- 98,
239
- 111,
240
- 110,
241
- 100
164
+ 101
242
165
  ];
243
- },
244
- {
245
- kind: 'account';
246
- path: 'validator_bond_account.vote_account';
247
- account: 'validatorBondAccount';
248
166
  }
249
167
  ];
250
168
  };
251
169
  },
252
170
  {
253
- name: 'depositor';
254
- writable: true;
255
- signer: true;
171
+ "name": "authority";
172
+ "writable": true;
173
+ "signer": true;
256
174
  },
257
175
  {
258
- name: 'systemProgram';
259
- address: '11111111111111111111111111111111';
260
- }
261
- ];
262
- args: [
176
+ "name": "reserve";
177
+ },
263
178
  {
264
- name: 'amount';
265
- type: 'u64';
179
+ "name": "systemProgram";
180
+ "address": "11111111111111111111111111111111";
266
181
  }
267
182
  ];
183
+ "args": [];
268
184
  },
269
185
  {
270
- name: 'bondWithdraw';
271
- discriminator: [
272
- 99,
273
- 64,
274
- 127,
186
+ "name": "register";
187
+ "docs": [
188
+ "Registers a new validator with the bonding program.",
189
+ "Sets up the validator's bond account and deposits initial collateral.",
190
+ "",
191
+ "# Arguments",
192
+ "* `initial_collateral` - Amount of collateral to lock (must be positive).",
193
+ "* `withdrawal_authority` - Optional key that can withdraw collateral later.",
194
+ "",
195
+ "# Errors",
196
+ "Fails if the validator is already registered, if the vote account is invalid,",
197
+ "or if the initial collateral transfer fails."
198
+ ];
199
+ "discriminator": [
200
+ 211,
201
+ 124,
202
+ 67,
203
+ 15,
204
+ 211,
205
+ 194,
275
206
  178,
276
- 53,
277
- 117,
278
- 70,
279
- 204
207
+ 240
280
208
  ];
281
- accounts: [
209
+ "accounts": [
282
210
  {
283
- name: 'validatorBondAccount';
284
- writable: true;
285
- pda: {
286
- seeds: [
211
+ "name": "globalState";
212
+ "writable": true;
213
+ "pda": {
214
+ "seeds": [
287
215
  {
288
- kind: 'const';
289
- value: [
216
+ "kind": "const";
217
+ "value": [
218
+ 103,
219
+ 108,
220
+ 111,
221
+ 98,
222
+ 97,
223
+ 108,
224
+ 95,
225
+ 115,
226
+ 116,
227
+ 97,
228
+ 116,
229
+ 101
230
+ ];
231
+ }
232
+ ];
233
+ };
234
+ },
235
+ {
236
+ "name": "validatorBond";
237
+ "writable": true;
238
+ "pda": {
239
+ "seeds": [
240
+ {
241
+ "kind": "const";
242
+ "value": [
290
243
  118,
291
244
  97,
292
245
  108,
@@ -304,100 +257,57 @@ type Jbond = {
304
257
  ];
305
258
  },
306
259
  {
307
- kind: 'account';
308
- path: 'validator_bond_account.vote_account';
309
- account: 'validatorBondAccount';
260
+ "kind": "account";
261
+ "path": "voteAccount";
310
262
  }
311
263
  ];
312
264
  };
313
265
  },
314
266
  {
315
- name: 'withdrawalAuthority';
316
- writable: true;
317
- signer: true;
267
+ "name": "identity";
318
268
  },
319
269
  {
320
- name: 'destination';
321
- writable: true;
270
+ "name": "voteAccount";
322
271
  },
323
272
  {
324
- name: 'epochSchedule';
325
- address: 'SysvarEpochSchedu1e111111111111111111111111';
273
+ "name": "creator";
274
+ "docs": [
275
+ "The account creating the bond (pays for account creation and initial collateral)"
276
+ ];
277
+ "writable": true;
278
+ "signer": true;
326
279
  },
327
280
  {
328
- name: 'systemProgram';
329
- address: '11111111111111111111111111111111';
330
- }
331
- ];
332
- args: [
333
- {
334
- name: 'amount';
335
- type: 'u64';
281
+ "name": "systemProgram";
282
+ "address": "11111111111111111111111111111111";
336
283
  }
337
284
  ];
338
- },
339
- {
340
- name: 'initialize';
341
- docs: [
342
- 'Initialize the global state and reserve vault'
343
- ];
344
- discriminator: [
345
- 175,
346
- 175,
347
- 109,
348
- 31,
349
- 13,
350
- 152,
351
- 155,
352
- 237
353
- ];
354
- accounts: [
355
- {
356
- name: 'globalState';
357
- writable: true;
358
- pda: {
359
- seeds: [
360
- {
361
- kind: 'const';
362
- value: [
363
- 103,
364
- 108,
365
- 111,
366
- 98,
367
- 97,
368
- 108,
369
- 95,
370
- 115,
371
- 116,
372
- 97,
373
- 116,
374
- 101
375
- ];
376
- }
377
- ];
378
- };
379
- },
380
- {
381
- name: 'authority';
382
- writable: true;
383
- signer: true;
384
- },
285
+ "args": [
385
286
  {
386
- name: 'reserve';
287
+ "name": "initialCollateral";
288
+ "type": "u64";
387
289
  },
388
290
  {
389
- name: 'systemProgram';
390
- address: '11111111111111111111111111111111';
291
+ "name": "withdrawalAuthority";
292
+ "type": {
293
+ "option": "pubkey";
294
+ };
391
295
  }
392
296
  ];
393
- args: [];
394
297
  },
395
298
  {
396
- name: 'setAuthority';
397
- docs: [
398
- 'Change the bond authority'
299
+ "name": "setAuthority";
300
+ "docs": [
301
+ "Sets a new withdrawal authority for a validator's bond account.",
302
+ "Allows changing who can withdraw collateral in the future.",
303
+ "",
304
+ "# Arguments",
305
+ "* `new_authority` - Optional new authority key (None to restrict to identity).",
306
+ "",
307
+ "# Errors",
308
+ "Fails if the signer is not authorized to change the authority."
399
309
  ];
400
- discriminator: [
310
+ "discriminator": [
401
311
  133,
402
312
  250,
403
313
  37,
@@ -407,15 +317,15 @@ type Jbond = {
407
317
  26,
408
318
  121
409
319
  ];
410
- accounts: [
320
+ "accounts": [
411
321
  {
412
- name: 'globalState';
413
- writable: true;
414
- pda: {
415
- seeds: [
322
+ "name": "globalState";
323
+ "writable": true;
324
+ "pda": {
325
+ "seeds": [
416
326
  {
417
- kind: 'const';
418
- value: [
327
+ "kind": "const";
328
+ "value": [
419
329
  103,
420
330
  108,
421
331
  111,
@@ -434,67 +344,124 @@ type Jbond = {
434
344
  };
435
345
  },
436
346
  {
437
- name: 'authority';
438
- signer: true;
439
- relations: [
440
- 'globalState'
347
+ "name": "authority";
348
+ "signer": true;
349
+ "relations": [
350
+ "globalState"
441
351
  ];
442
352
  },
443
353
  {
444
- name: 'newAuthority';
354
+ "name": "newAuthority";
445
355
  }
446
356
  ];
447
- args: [];
357
+ "args": [];
448
358
  },
449
359
  {
450
- name: 'withdrawCompensation';
451
- docs: [
452
- 'Withdraw compensation from validator to reserve (oracle only)'
360
+ "name": "topUp";
361
+ "docs": [
362
+ "Adds additional collateral to an existing validator's bond.",
363
+ "Increases the collateral balance, enhancing the validator's stake.",
364
+ "",
365
+ "# Arguments",
366
+ "* `amount` - Amount to add.",
367
+ "",
368
+ "# Errors",
369
+ "Fails if the validator is not active, if the amount is zero,",
370
+ "or if the transfer of funds fails."
453
371
  ];
454
- discriminator: [
455
- 10,
456
- 228,
457
- 22,
458
- 213,
459
- 205,
460
- 117,
461
- 181,
462
- 75
372
+ "discriminator": [
373
+ 236,
374
+ 225,
375
+ 96,
376
+ 9,
377
+ 60,
378
+ 106,
379
+ 77,
380
+ 208
463
381
  ];
464
- accounts: [
382
+ "accounts": [
465
383
  {
466
- name: 'globalState';
467
- writable: true;
468
- pda: {
469
- seeds: [
384
+ "name": "validatorBond";
385
+ "writable": true;
386
+ "pda": {
387
+ "seeds": [
470
388
  {
471
- kind: 'const';
472
- value: [
473
- 103,
474
- 108,
475
- 111,
476
- 98,
389
+ "kind": "const";
390
+ "value": [
391
+ 118,
477
392
  97,
478
393
  108,
479
- 95,
480
- 115,
481
- 116,
394
+ 105,
395
+ 100,
482
396
  97,
483
397
  116,
484
- 101
398
+ 111,
399
+ 114,
400
+ 95,
401
+ 98,
402
+ 111,
403
+ 110,
404
+ 100
485
405
  ];
406
+ },
407
+ {
408
+ "kind": "account";
409
+ "path": "validator_bond.vote_account";
410
+ "account": "validatorBond";
486
411
  }
487
412
  ];
488
413
  };
489
414
  },
490
415
  {
491
- name: 'validatorBondAccount';
492
- writable: true;
493
- pda: {
494
- seeds: [
416
+ "name": "payer";
417
+ "writable": true;
418
+ "signer": true;
419
+ },
420
+ {
421
+ "name": "systemProgram";
422
+ "address": "11111111111111111111111111111111";
423
+ }
424
+ ];
425
+ "args": [
426
+ {
427
+ "name": "amount";
428
+ "type": "u64";
429
+ }
430
+ ];
431
+ },
432
+ {
433
+ "name": "withdraw";
434
+ "docs": [
435
+ "Withdraws collateral from a validator's bond.",
436
+ "Decreases the collateral balance, allowing the validator to reclaim funds.",
437
+ "",
438
+ "# Arguments",
439
+ "* `amount` - Amount to withdraw (must not exceed available balance).",
440
+ "",
441
+ "# Errors",
442
+ "Fails if the validator is not active, if the amount is zero,",
443
+ "if the withdrawal authority is invalid, or if the withdrawal would",
444
+ "leave insufficient collateral."
445
+ ];
446
+ "discriminator": [
447
+ 183,
448
+ 18,
449
+ 70,
450
+ 156,
451
+ 148,
452
+ 109,
453
+ 161,
454
+ 34
455
+ ];
456
+ "accounts": [
457
+ {
458
+ "name": "validatorBond";
459
+ "writable": true;
460
+ "pda": {
461
+ "seeds": [
495
462
  {
496
- kind: 'const';
497
- value: [
463
+ "kind": "const";
464
+ "value": [
498
465
  118,
499
466
  97,
500
467
  108,
@@ -512,41 +479,43 @@ type Jbond = {
512
479
  ];
513
480
  },
514
481
  {
515
- kind: 'account';
516
- path: 'validator_bond_account.vote_account';
517
- account: 'validatorBondAccount';
482
+ "kind": "account";
483
+ "path": "validator_bond.vote_account";
484
+ "account": "validatorBond";
518
485
  }
519
486
  ];
520
487
  };
521
488
  },
522
489
  {
523
- name: 'reserve';
524
- writable: true;
490
+ "name": "withdrawalAuthority";
491
+ "writable": true;
492
+ "signer": true;
525
493
  },
526
494
  {
527
- name: 'authority';
528
- docs: [
529
- 'Authority that can trigger claims'
530
- ];
531
- signer: true;
495
+ "name": "destination";
496
+ "writable": true;
532
497
  },
533
498
  {
534
- name: 'systemProgram';
535
- address: '11111111111111111111111111111111';
499
+ "name": "epochSchedule";
500
+ "address": "SysvarEpochSchedu1e111111111111111111111111";
501
+ },
502
+ {
503
+ "name": "systemProgram";
504
+ "address": "11111111111111111111111111111111";
536
505
  }
537
506
  ];
538
- args: [
507
+ "args": [
539
508
  {
540
- name: 'amount';
541
- type: 'u64';
509
+ "name": "amount";
510
+ "type": "u64";
542
511
  }
543
512
  ];
544
513
  }
545
514
  ];
546
- accounts: [
515
+ "accounts": [
547
516
  {
548
- name: 'globalState';
549
- discriminator: [
517
+ "name": "globalState";
518
+ "discriminator": [
550
519
  163,
551
520
  46,
552
521
  74,
@@ -558,23 +527,23 @@ type Jbond = {
558
527
  ];
559
528
  },
560
529
  {
561
- name: 'validatorBondAccount';
562
- discriminator: [
563
- 25,
564
- 67,
565
- 241,
566
- 227,
567
- 226,
568
- 104,
569
- 108,
570
- 73
530
+ "name": "validatorBond";
531
+ "discriminator": [
532
+ 82,
533
+ 127,
534
+ 243,
535
+ 208,
536
+ 195,
537
+ 42,
538
+ 80,
539
+ 35
571
540
  ];
572
541
  }
573
542
  ];
574
- events: [
543
+ "events": [
575
544
  {
576
- name: 'collateralToppedUp';
577
- discriminator: [
545
+ "name": "collateralToppedUp";
546
+ "discriminator": [
578
547
  189,
579
548
  137,
580
549
  204,
@@ -586,8 +555,8 @@ type Jbond = {
586
555
  ];
587
556
  },
588
557
  {
589
- name: 'collateralWithdrawn';
590
- discriminator: [
558
+ "name": "collateralWithdrawn";
559
+ "discriminator": [
591
560
  51,
592
561
  224,
593
562
  133,
@@ -599,8 +568,8 @@ type Jbond = {
599
568
  ];
600
569
  },
601
570
  {
602
- name: 'compensationClaimed';
603
- discriminator: [
571
+ "name": "compensationClaimed";
572
+ "discriminator": [
604
573
  36,
605
574
  159,
606
575
  41,
@@ -612,8 +581,8 @@ type Jbond = {
612
581
  ];
613
582
  },
614
583
  {
615
- name: 'validatorRegistered';
616
- discriminator: [
584
+ "name": "validatorRegistered";
585
+ "discriminator": [
617
586
  20,
618
587
  20,
619
588
  190,
@@ -625,233 +594,278 @@ type Jbond = {
625
594
  ];
626
595
  }
627
596
  ];
628
- errors: [
597
+ "errors": [
629
598
  {
630
- code: 6000;
631
- name: 'invalidVoteAccount';
632
- msg: 'Invalid vote account';
599
+ "code": 6000;
600
+ "name": "invalidVoteAccount";
601
+ "msg": "Invalid vote account";
633
602
  },
634
603
  {
635
- code: 6001;
636
- name: 'identityMismatch';
637
- msg: 'Identity does not match vote account';
604
+ "code": 6001;
605
+ "name": "identityMismatch";
606
+ "msg": "Identity does not match vote account";
638
607
  },
639
608
  {
640
- code: 6002;
641
- name: 'insufficientCollateral';
642
- msg: 'Insufficient collateral amount';
609
+ "code": 6002;
610
+ "name": "insufficientCollateral";
611
+ "msg": "Insufficient collateral amount";
643
612
  },
644
613
  {
645
- code: 6003;
646
- name: 'targetAprTooLow';
647
- msg: 'Target APR is below minimum threshold';
614
+ "code": 6003;
615
+ "name": "targetAprTooLow";
616
+ "msg": "Target APR is below minimum threshold";
648
617
  },
649
618
  {
650
- code: 6004;
651
- name: 'mathOverflow';
652
- msg: 'Math overflow';
619
+ "code": 6004;
620
+ "name": "mathOverflow";
621
+ "msg": "Math overflow";
653
622
  },
654
623
  {
655
- code: 6005;
656
- name: 'invalidAmount';
657
- msg: 'Invalid amount';
624
+ "code": 6005;
625
+ "name": "invalidAmount";
626
+ "msg": "Invalid amount";
658
627
  },
659
628
  {
660
- code: 6006;
661
- name: 'validatorNotActive';
662
- msg: 'Validator boost account is not active';
629
+ "code": 6006;
630
+ "name": "validatorNotActive";
631
+ "msg": "Validator boost account is not active";
663
632
  },
664
633
  {
665
- code: 6007;
666
- name: 'validatorAlreadyRegistered';
667
- msg: 'Validator already registered';
634
+ "code": 6007;
635
+ "name": "validatorAlreadyRegistered";
636
+ "msg": "Validator already registered";
668
637
  },
669
638
  {
670
- code: 6008;
671
- name: 'unauthorized';
672
- msg: 'unauthorized';
639
+ "code": 6008;
640
+ "name": "unauthorized";
641
+ "msg": "unauthorized";
673
642
  },
674
643
  {
675
- code: 6009;
676
- name: 'withdrawalLockedNearEpochEnd';
677
- msg: 'Withdrawals are locked near the end of the epoch.';
644
+ "code": 6009;
645
+ "name": "withdrawalLockedNearEpochEnd";
646
+ "msg": "Withdrawals are locked near the end of the epoch.";
678
647
  }
679
648
  ];
680
- types: [
649
+ "types": [
681
650
  {
682
- name: 'collateralToppedUp';
683
- type: {
684
- kind: 'struct';
685
- fields: [
651
+ "name": "collateralToppedUp";
652
+ "type": {
653
+ "kind": "struct";
654
+ "fields": [
686
655
  {
687
- name: 'validator';
688
- type: 'pubkey';
656
+ "name": "validator";
657
+ "type": "pubkey";
689
658
  },
690
659
  {
691
- name: 'amount';
692
- type: 'u64';
660
+ "name": "amount";
661
+ "type": "u64";
693
662
  },
694
663
  {
695
- name: 'newTotal';
696
- type: 'u64';
664
+ "name": "postBalance";
665
+ "type": "u64";
697
666
  },
698
667
  {
699
- name: 'timestamp';
700
- type: 'i64';
668
+ "name": "timestamp";
669
+ "type": "i64";
701
670
  }
702
671
  ];
703
672
  };
704
673
  },
705
674
  {
706
- name: 'collateralWithdrawn';
707
- type: {
708
- kind: 'struct';
709
- fields: [
675
+ "name": "collateralWithdrawn";
676
+ "type": {
677
+ "kind": "struct";
678
+ "fields": [
710
679
  {
711
- name: 'validator';
712
- type: 'pubkey';
680
+ "name": "validator";
681
+ "type": "pubkey";
713
682
  },
714
683
  {
715
- name: 'amount';
716
- type: 'u64';
684
+ "name": "amount";
685
+ "type": "u64";
717
686
  },
718
687
  {
719
- name: 'remainingCollateral';
720
- type: 'u64';
688
+ "name": "postBalance";
689
+ "type": "u64";
721
690
  },
722
691
  {
723
- name: 'timestamp';
724
- type: 'i64';
692
+ "name": "timestamp";
693
+ "type": "i64";
725
694
  }
726
695
  ];
727
696
  };
728
697
  },
729
698
  {
730
- name: 'compensationClaimed';
731
- type: {
732
- kind: 'struct';
733
- fields: [
699
+ "name": "compensationClaimed";
700
+ "type": {
701
+ "kind": "struct";
702
+ "fields": [
734
703
  {
735
- name: 'validator';
736
- type: 'pubkey';
704
+ "name": "validator";
705
+ "type": "pubkey";
737
706
  },
738
707
  {
739
- name: 'amount';
740
- type: 'u64';
708
+ "name": "amount";
709
+ "type": "u64";
741
710
  },
742
711
  {
743
- name: 'remainingCollateral';
744
- type: 'u64';
712
+ "name": "postBalance";
713
+ "type": "u64";
745
714
  },
746
715
  {
747
- name: 'totalWithdrawn';
748
- type: 'u64';
716
+ "name": "epoch";
717
+ "type": "u64";
749
718
  },
750
719
  {
751
- name: 'epoch';
752
- type: 'u64';
753
- },
754
- {
755
- name: 'timestamp';
756
- type: 'i64';
720
+ "name": "timestamp";
721
+ "type": "i64";
757
722
  }
758
723
  ];
759
724
  };
760
725
  },
761
726
  {
762
- name: 'globalState';
763
- type: {
764
- kind: 'struct';
765
- fields: [
727
+ "name": "globalState";
728
+ "type": {
729
+ "kind": "struct";
730
+ "fields": [
766
731
  {
767
- name: 'authority';
768
- type: 'pubkey';
732
+ "name": "authority";
733
+ "docs": [
734
+ "The authority allowed to manage the program"
735
+ ];
736
+ "type": "pubkey";
769
737
  },
770
738
  {
771
- name: 'reserve';
772
- type: 'pubkey';
739
+ "name": "reserve";
740
+ "docs": [
741
+ "The reserve vault holding SOL for bonding and compensation"
742
+ ];
743
+ "type": "pubkey";
773
744
  },
774
745
  {
775
- name: 'totalValidators';
776
- type: 'u32';
746
+ "name": "totalValidators";
747
+ "docs": [
748
+ "Total number of registered validators"
749
+ ];
750
+ "type": "u16";
777
751
  },
778
752
  {
779
- name: 'totalWithdrawn';
780
- type: 'u64';
753
+ "name": "totalCompensationAmount";
754
+ "docs": [
755
+ "Total compensation amount paid out"
756
+ ];
757
+ "type": "u64";
781
758
  },
782
759
  {
783
- name: 'bump';
784
- type: 'u8';
760
+ "name": "bump";
761
+ "docs": [
762
+ "Bump for the PDA"
763
+ ];
764
+ "type": "u8";
785
765
  }
786
766
  ];
787
767
  };
788
768
  },
789
769
  {
790
- name: 'validatorBondAccount';
791
- type: {
792
- kind: 'struct';
793
- fields: [
770
+ "name": "validatorBond";
771
+ "type": {
772
+ "kind": "struct";
773
+ "fields": [
794
774
  {
795
- name: 'identity';
796
- type: 'pubkey';
775
+ "name": "identity";
776
+ "docs": [
777
+ "The validator identity pubkey"
778
+ ];
779
+ "type": "pubkey";
797
780
  },
798
781
  {
799
- name: 'voteAccount';
800
- type: 'pubkey';
782
+ "name": "voteAccount";
783
+ "docs": [
784
+ "The validator vote account pubkey"
785
+ ];
786
+ "type": "pubkey";
801
787
  },
802
788
  {
803
- name: 'creator';
804
- type: 'pubkey';
789
+ "name": "creator";
790
+ "docs": [
791
+ "Creator of the validator bond account"
792
+ ];
793
+ "type": "pubkey";
805
794
  },
806
795
  {
807
- name: 'withdrawalAuthority';
808
- type: {
809
- option: 'pubkey';
796
+ "name": "withdrawalAuthority";
797
+ "docs": [
798
+ "Authority allowed to withdraw funds (if None, only identity can withdraw)"
799
+ ];
800
+ "type": {
801
+ "option": "pubkey";
810
802
  };
811
803
  },
812
804
  {
813
- name: 'totalWithdrawn';
814
- type: 'u64';
805
+ "name": "totalCompensationAmount";
806
+ "docs": [
807
+ "Total compensation claimed for the validator"
808
+ ];
809
+ "type": "u64";
810
+ },
811
+ {
812
+ "name": "lastCompensationAmount";
813
+ "docs": [
814
+ "Last compensation amount claimed"
815
+ ];
816
+ "type": "u64";
815
817
  },
816
818
  {
817
- name: 'lastWithdrawalEpoch';
818
- type: 'u64';
819
+ "name": "lastCompensationEpoch";
820
+ "docs": [
821
+ "Last epoch when compensation was claimed"
822
+ ];
823
+ "type": "u64";
819
824
  },
820
825
  {
821
- name: 'isActive';
822
- type: 'bool';
826
+ "name": "createdAt";
827
+ "docs": [
828
+ "Timestamp when the bond account was created"
829
+ ];
830
+ "type": "i64";
823
831
  },
824
832
  {
825
- name: 'createdAt';
826
- type: 'i64';
833
+ "name": "isActive";
834
+ "docs": [
835
+ "Whether the validator is currently active"
836
+ ];
837
+ "type": "bool";
827
838
  },
828
839
  {
829
- name: 'bump';
830
- type: 'u8';
840
+ "name": "bump";
841
+ "docs": [
842
+ "Bump for the PDA"
843
+ ];
844
+ "type": "u8";
831
845
  }
832
846
  ];
833
847
  };
834
848
  },
835
849
  {
836
- name: 'validatorRegistered';
837
- type: {
838
- kind: 'struct';
839
- fields: [
850
+ "name": "validatorRegistered";
851
+ "type": {
852
+ "kind": "struct";
853
+ "fields": [
840
854
  {
841
- name: 'validator';
842
- type: 'pubkey';
855
+ "name": "identity";
856
+ "type": "pubkey";
843
857
  },
844
858
  {
845
- name: 'voteAccount';
846
- type: 'pubkey';
859
+ "name": "voteAccount";
860
+ "type": "pubkey";
847
861
  },
848
862
  {
849
- name: 'collateralAmount';
850
- type: 'u64';
863
+ "name": "initialCollateral";
864
+ "type": "u64";
851
865
  },
852
866
  {
853
- name: 'timestamp';
854
- type: 'i64';
867
+ "name": "timestamp";
868
+ "type": "i64";
855
869
  }
856
870
  ];
857
871
  };
@@ -859,28 +873,125 @@ type Jbond = {
859
873
  ];
860
874
  };
861
875
 
876
+ type ValidatorBond = {
877
+ identity: PublicKey;
878
+ voteAccount: PublicKey;
879
+ withdrawalAuthority?: string;
880
+ totalWithdrawn: number;
881
+ lastWithdrawalEpoch: number;
882
+ isActive: boolean;
883
+ createdAt: number;
884
+ bump: number;
885
+ };
886
+ type InitializeProps = {
887
+ authority?: PublicKey;
888
+ reserve: PublicKey;
889
+ };
890
+ type RegisterValidatorProps = {
891
+ identity: PublicKey;
892
+ voteAccount: PublicKey;
893
+ initialCollateral: number;
894
+ withdrawalAuthority?: PublicKey;
895
+ creator?: PublicKey;
896
+ };
897
+ type TopUpCollateralProps = {
898
+ amount: number;
899
+ voteAccount: PublicKey;
900
+ payer?: PublicKey;
901
+ };
902
+ type WithdrawCollateralProps = {
903
+ amount: number;
904
+ voteAccount: PublicKey;
905
+ destination?: PublicKey;
906
+ withdrawalAuthority?: PublicKey;
907
+ };
908
+ type ClaimProps = {
909
+ amount: number;
910
+ voteAccount: PublicKey;
911
+ reserve?: PublicKey;
912
+ authority?: PublicKey;
913
+ };
914
+ type GetHistoryProps = {
915
+ voteAccount: PublicKey;
916
+ options?: {
917
+ limit?: number;
918
+ before?: string;
919
+ until?: string;
920
+ };
921
+ };
922
+ type GetHistoryGroupedProps = {
923
+ voteAccount: PublicKey;
924
+ epochsCount?: number;
925
+ };
926
+ type SetAuthorityProps = {
927
+ newAuthority: PublicKey;
928
+ authority?: PublicKey;
929
+ };
930
+ type GlobalState = {
931
+ authority: PublicKey;
932
+ totalValidators: number;
933
+ totalCollateral: BN;
934
+ totalWithdrawn: BN;
935
+ bump: number;
936
+ };
937
+ type EpochHistoryItem = {
938
+ epoch: number;
939
+ deposits: number;
940
+ withdrawals: number;
941
+ balanceChange: number;
942
+ signatures: string[];
943
+ };
944
+ type TransactionHistoryItem = {
945
+ signature: string;
946
+ slot: number;
947
+ epoch: number;
948
+ type: BondTransactionType;
949
+ amount: number;
950
+ beforeBalance?: number;
951
+ afterBalance?: number;
952
+ };
953
+ declare enum BondTransactionType {
954
+ Deposit = "deposit",
955
+ Withdrawal = "withdrawal",
956
+ Compensation = "compensation"
957
+ }
958
+
959
+ /**
960
+ * Enum for different client environments.
961
+ */
862
962
  declare enum BondClientEnv {
863
963
  DEV = "dev",
964
+ STAGE = "stage",
864
965
  PROD = "prod"
865
966
  }
967
+ /**
968
+ * Options for configuring the JBondClient.
969
+ */
970
+ type ClientOptions = {
971
+ programId?: PublicKey;
972
+ debug?: boolean;
973
+ } & Record<string, any>;
866
974
  declare class JBondClient {
867
- connection: Connection;
868
- program: Program<Jbond>;
869
- provider: AnchorProvider;
975
+ readonly provider: AnchorProvider;
870
976
  readonly options: ClientOptions;
871
- constructor(options: ClientOptions, wallet?: Wallet);
977
+ readonly program: Program<Jbond>;
978
+ constructor(provider: AnchorProvider, options?: ClientOptions);
872
979
  /**
873
980
  * Creates an instance of `JBondClient` using a provided connection and wallet.
874
981
  */
875
- static fromWallet(options: ClientOptions, wallet?: Wallet): JBondClient;
982
+ static fromWallet(connection: Connection, wallet?: Wallet$1, options?: ClientOptions): JBondClient;
876
983
  /**
877
984
  * Creates an instance of `JBondClient` using the provided connection and keypair.
878
985
  */
879
- static fromKeypair(options: ClientOptions, keypair: Keypair): JBondClient;
986
+ static fromKeypair(connection: Connection, keypair: Keypair, options?: ClientOptions): JBondClient;
880
987
  /**
881
988
  * Get the current program ID.
882
989
  */
883
990
  get programId(): PublicKey;
991
+ /**
992
+ * Get the current connection.
993
+ */
994
+ private get connection();
884
995
  /**
885
996
  * Set the environment.
886
997
  */
@@ -889,62 +1000,150 @@ declare class JBondClient {
889
1000
  * Configure a specific option.
890
1001
  */
891
1002
  configure<K extends keyof ClientOptions>(key: K, val: ClientOptions[K]): this;
892
- getGlobalStatePDA(): [PublicKey, number];
893
- getValidatorBondPDA(voteAccount: PublicKey): [PublicKey, number];
894
- buildInitializeInstruction(props: InitializeProps): Promise<TransactionInstruction>;
895
- buildRegisterValidatorInstruction(props: RegisterValidatorProps): Promise<TransactionInstruction>;
896
- buildTopUpCollateralInstruction(props: TopUpCollateralProps): Promise<TransactionInstruction>;
897
- buildWithdrawCollateralInstruction(props: WithdrawCollateralProps): Promise<TransactionInstruction>;
898
- buildWithdrawCompensationInstruction(props: WithdrawCompensationProps): Promise<TransactionInstruction>;
899
- buildWithdrawCompensationsInstructions(authority: PublicKey, withdrawals: Array<{
900
- voteAccount: PublicKey;
901
- amount: number;
902
- }>): Promise<TransactionInstruction[]>;
903
- getValidatorBondAccount(voteAccount: PublicKey): Promise<ValidatorBondAccount | null>;
904
- buildSetAuthorityInstruction(props: {
905
- authority: PublicKey;
906
- newAuthority: PublicKey;
907
- }): Promise<TransactionInstruction>;
908
1003
  /**
909
- * Get the collateral balance of a validator bond account
910
- * @param voteAccount - The vote account public key
911
- * @returns The available collateral balance in SOL (excluding rent-exempt amount)
1004
+ * Program Derived Addresses (PDAs)
1005
+ */
1006
+ pda: {
1007
+ globalState: () => [PublicKey, number];
1008
+ validatorBond: (vote: PublicKeyInitData) => [PublicKey, number];
1009
+ };
1010
+ /**
1011
+ * Initialize the program
1012
+ * Default authority is the provider's wallet
1013
+ */
1014
+ initialize(props: InitializeProps): Promise<string>;
1015
+ /**
1016
+ * Register a new validator
1017
+ * Default creator is the provider's wallet
1018
+ */
1019
+ registerValidator(props: RegisterValidatorProps): Promise<string>;
1020
+ /**
1021
+ * Top up collateral
1022
+ * Default payer is the provider's wallet
1023
+ */
1024
+ topUpCollateral(props: TopUpCollateralProps): Promise<string>;
1025
+ /**
1026
+ * Withdraw collateral
1027
+ * Default withdrawal authority is the provider's wallet
1028
+ * Default destination is the provider's wallet
1029
+ * @return Transaction signature
1030
+ */
1031
+ withdrawCollateral(props: WithdrawCollateralProps): Promise<string>;
1032
+ /**
1033
+ * Claim compensation
1034
+ * Default authority is the provider's wallet
1035
+ * @return Transaction signature
1036
+ */
1037
+ claimCompensation(props: ClaimProps): Promise<string>;
1038
+ /**
1039
+ * Set a new authority for the program
1040
+ * Default authority is the provider's wallet
1041
+ * @return Transaction signature
1042
+ */
1043
+ setAuthority(props: SetAuthorityProps): Promise<string>;
1044
+ /**
1045
+ * Build initialize instruction
1046
+ */
1047
+ buildInitializeInstruction(props: InitializeProps): Promise<_solana_web3_js.TransactionInstruction>;
1048
+ /**
1049
+ * Build register validator instruction
1050
+ */
1051
+ buildRegisterValidatorInstruction(props: RegisterValidatorProps): Promise<_solana_web3_js.TransactionInstruction>;
1052
+ /**
1053
+ * Build top up collateral instruction
1054
+ */
1055
+ buildTopUpCollateralInstruction(props: TopUpCollateralProps): Promise<_solana_web3_js.TransactionInstruction>;
1056
+ /**
1057
+ * Build withdraw collateral instruction
1058
+ */
1059
+ buildWithdrawCollateralInstruction(props: WithdrawCollateralProps): Promise<_solana_web3_js.TransactionInstruction>;
1060
+ /**
1061
+ * Build claim compensation instruction
1062
+ */
1063
+ buildClaimInstruction(props: ClaimProps): Promise<_solana_web3_js.TransactionInstruction>;
1064
+ /**
1065
+ * Build set authority instruction
1066
+ */
1067
+ buildSetAuthorityInstruction(props: SetAuthorityProps): Promise<_solana_web3_js.TransactionInstruction>;
1068
+ /**
1069
+ * Fetch global state or throw if not found
912
1070
  */
913
- getValidatorCollateralBalance(voteAccount: PublicKey): Promise<number>;
914
1071
  getGlobalState(): Promise<{
915
- authority: string;
1072
+ authority: PublicKey;
1073
+ reserve: PublicKey;
916
1074
  totalValidators: number;
917
- totalWithdrawn: number;
918
- reserveAddress: string;
1075
+ totalCompensationAmount: BN;
1076
+ bump: number;
1077
+ }>;
1078
+ /**
1079
+ * Fetch validator bond data or null if not found
1080
+ * @param vote
1081
+ */
1082
+ getValidatorBond(vote: PublicKeyInitData): Promise<{
1083
+ identity: PublicKey;
1084
+ voteAccount: PublicKey;
1085
+ creator: PublicKey;
1086
+ withdrawalAuthority: PublicKey | null;
1087
+ totalCompensationAmount: BN;
1088
+ lastCompensationAmount: BN;
1089
+ lastCompensationEpoch: BN;
1090
+ createdAt: BN;
1091
+ isActive: boolean;
1092
+ bump: number;
919
1093
  } | null>;
920
- getCurrentEpoch(): Promise<number>;
921
- initialize(reserveAddress: PublicKey, authority?: PublicKey): Promise<string>;
922
- registerValidator(voteAccount: PublicKey, initialCollateral: number, withdrawalAuthority?: PublicKey, identity?: PublicKey): Promise<string>;
923
- topUpCollateral(voteAccount: PublicKey, amount: number, validator?: PublicKey): Promise<string>;
924
- withdrawCollateral(voteAccount: PublicKey, destination: PublicKey, amount: number, withdrawalAuthority?: PublicKey): Promise<string>;
925
- claimCompensation(voteAccount: PublicKey, amount: number, authority?: PublicKey): Promise<string>;
1094
+ /**
1095
+ * Get validator bond account balance (in SOL)
1096
+ * @param vote - Vote account public key
1097
+ * @return Balance in SOL
1098
+ */
1099
+ getValidatorBondBalance(vote: PublicKeyInitData): Promise<number>;
926
1100
  /**
927
1101
  * Get transaction history grouped by epochs
928
- * @param voteAccount - The vote account to get history for
1102
+ * @param vote - The vote account to get history for
929
1103
  * @param epochsCount - Number of recent epochs to return (default: 10)
930
1104
  * @returns Array of epoch history items sorted by epoch (descending)
931
1105
  */
932
- getHistoryGroupedByEpochs(voteAccount: PublicKey, epochsCount?: number): Promise<EpochHistoryItem[]>;
933
- getHistory(voteAccount: PublicKey, options?: {
1106
+ getHistoryGroupedByEpochs(vote: PublicKeyInitData, epochsCount?: number): Promise<EpochHistoryItem[]>;
1107
+ /**
1108
+ * Get transaction history for a specific validator bond account
1109
+ */
1110
+ getHistory(vote: PublicKey, options?: {
934
1111
  cluster?: 'mainnet-beta' | 'testnet' | 'devnet';
935
1112
  limit?: number;
936
1113
  before?: string;
937
1114
  until?: string;
938
1115
  }): Promise<TransactionHistoryItem[]>;
1116
+ /**
1117
+ * Get full transaction history by paginating through results
1118
+ * @param voteAccount
1119
+ * @param pageSize
1120
+ */
939
1121
  getFullHistory(voteAccount: PublicKey, pageSize?: number): Promise<TransactionHistoryItem[]>;
1122
+ /**
1123
+ * Get instruction discriminator from IDL
1124
+ * @param instructionName
1125
+ * @private
1126
+ */
940
1127
  private getInstructionDiscriminator;
941
1128
  }
942
- type ClientOptions = {
943
- rpcUrl: string;
944
- programId?: PublicKey;
945
- } & Record<string, any>;
946
1129
 
947
- declare const PROGRAM_ID: PublicKey;
948
- declare const DEV_PROGRAM_ID: PublicKey;
1130
+ /**
1131
+ * Program IDs for different environments
1132
+ */
1133
+ declare const ENV_PROGRAM_ID: Record<string, PublicKey>;
1134
+
1135
+ type Wallet = {
1136
+ publicKey: PublicKey;
1137
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
1138
+ signTransaction: <T extends Transaction | VersionedTransaction>(tx: T) => Promise<T>;
1139
+ signAllTransactions: <T extends Transaction | VersionedTransaction>(txs: T[]) => Promise<T[]>;
1140
+ };
1141
+ declare class NodeWallet implements Wallet {
1142
+ readonly payer: Keypair;
1143
+ constructor(payer: Keypair);
1144
+ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
1145
+ signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
1146
+ get publicKey(): PublicKey;
1147
+ }
949
1148
 
950
- export { BondClientEnv, BondTransactionType, type ClientOptions, type Config, DEV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, PROGRAM_ID, type RegisterValidatorProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBondAccount, type WithdrawCollateralProps, type WithdrawCompensationProps };
1149
+ export { BondClientEnv, BondTransactionType, type ClaimProps, type ClientOptions, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, NodeWallet, type RegisterValidatorProps, type SetAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps };