@jpool/bond-sdk 0.2.0 → 0.3.0-next.1

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