@jpool/bond-sdk 0.3.0-next.7 → 0.3.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.mjs CHANGED
@@ -1,46 +1,43 @@
1
- import { Program, AnchorProvider, BN } from '@coral-xyz/anchor';
2
- import { PublicKey, LAMPORTS_PER_SOL, SYSVAR_EPOCH_SCHEDULE_PUBKEY, Transaction } from '@solana/web3.js';
1
+ import { AnchorProvider, Program, BN } from '@coral-xyz/anchor';
2
+ import { PublicKey, Connection, SystemProgram, LAMPORTS_PER_SOL, SYSVAR_EPOCH_SCHEDULE_PUBKEY, Transaction } from '@solana/web3.js';
3
3
  import bs58 from 'bs58';
4
4
 
5
5
  // src/client.ts
6
+ var PROGRAM_ID = new PublicKey("8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr");
7
+ var DEV_PROGRAM_ID = new PublicKey("8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr");
6
8
 
7
- // src/constants.ts
8
- var ENV_PROGRAM_ID = {
9
- // [BondClientEnv.DEV]: new PublicKey('...'),
10
- };
9
+ // src/helpers.ts
10
+ var SLOTS_PER_EPOCH_MAINNET = 432e3;
11
+ var SLOTS_PER_EPOCH_DEVNET = 4e5;
12
+ function slotToEpoch(slot, cluster) {
13
+ const slotsPerEpoch = cluster === "mainnet-beta" ? SLOTS_PER_EPOCH_MAINNET : SLOTS_PER_EPOCH_DEVNET;
14
+ return Math.floor(slot / slotsPerEpoch);
15
+ }
11
16
 
12
17
  // src/idl/jbond.json
13
18
  var jbond_default = {
14
- address: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU",
19
+ address: "8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr",
15
20
  metadata: {
16
21
  name: "jbond",
17
- version: "0.2.0",
22
+ version: "0.1.0",
18
23
  spec: "0.1.0",
19
- description: "Jpool Bond Program"
24
+ description: "Validator compensation program for boosting APR"
20
25
  },
21
26
  instructions: [
22
27
  {
23
- name: "claim",
28
+ name: "bond_init",
24
29
  docs: [
25
- "Claims compensation for a validator.",
26
- "Transfers funds from the validator's bond account to reserve.",
27
- "",
28
- "# Arguments",
29
- "* `amount` - Amount of compensation to claim (must be positive).",
30
- "",
31
- "# Errors",
32
- "Fails if the authority is invalid, if the validator is not active,",
33
- "if the amount is zero, or if there are insufficient funds."
30
+ "Register validator and fund initial collateral"
34
31
  ],
35
32
  discriminator: [
36
- 62,
37
- 198,
38
- 214,
39
- 193,
40
- 213,
41
- 159,
33
+ 220,
42
34
  108,
43
- 210
35
+ 156,
36
+ 81,
37
+ 16,
38
+ 185,
39
+ 144,
40
+ 157
44
41
  ],
45
42
  accounts: [
46
43
  {
@@ -69,7 +66,7 @@ var jbond_default = {
69
66
  }
70
67
  },
71
68
  {
72
- name: "validator_bond",
69
+ name: "validator_bond_account",
73
70
  writable: true,
74
71
  pda: {
75
72
  seeds: [
@@ -94,21 +91,23 @@ var jbond_default = {
94
91
  },
95
92
  {
96
93
  kind: "account",
97
- path: "validator_bond.vote_account",
98
- account: "ValidatorBond"
94
+ path: "vote_account"
99
95
  }
100
96
  ]
101
97
  }
102
98
  },
103
99
  {
104
- name: "reserve",
105
- writable: true
100
+ name: "identity"
106
101
  },
107
102
  {
108
- name: "authority",
103
+ name: "vote_account"
104
+ },
105
+ {
106
+ name: "creator",
109
107
  docs: [
110
- "Authority that can trigger claims"
108
+ "The account creating the bond (pays for account creation and initial collateral)"
111
109
  ],
110
+ writable: true,
112
111
  signer: true
113
112
  },
114
113
  {
@@ -118,124 +117,97 @@ var jbond_default = {
118
117
  ],
119
118
  args: [
120
119
  {
121
- name: "amount",
120
+ name: "initial_collateral",
122
121
  type: "u64"
122
+ },
123
+ {
124
+ name: "withdrawal_authority",
125
+ type: {
126
+ option: "pubkey"
127
+ }
123
128
  }
124
129
  ]
125
130
  },
126
131
  {
127
- name: "initialize",
132
+ name: "bond_top_up",
128
133
  docs: [
129
- "Initializes the global state for the bonding program.",
130
- "Sets the authority and reserve account for managing validator bonds.",
131
- "",
132
- "# Errors",
133
- "Fails if the global state account is already initialized or if the payer lacks",
134
- "sufficient funds."
134
+ "Top up collateral for existing validator"
135
135
  ],
136
136
  discriminator: [
137
- 175,
138
- 175,
139
- 109,
140
- 31,
141
- 13,
137
+ 132,
138
+ 225,
139
+ 254,
140
+ 187,
142
141
  152,
143
- 155,
144
- 237
142
+ 162,
143
+ 176,
144
+ 66
145
145
  ],
146
146
  accounts: [
147
147
  {
148
- name: "global_state",
148
+ name: "validator_bond_account",
149
149
  writable: true,
150
150
  pda: {
151
151
  seeds: [
152
152
  {
153
153
  kind: "const",
154
154
  value: [
155
- 103,
156
- 108,
157
- 111,
158
- 98,
155
+ 118,
159
156
  97,
160
157
  108,
161
- 95,
162
- 115,
163
- 116,
158
+ 105,
159
+ 100,
164
160
  97,
165
161
  116,
166
- 101
162
+ 111,
163
+ 114,
164
+ 95,
165
+ 98,
166
+ 111,
167
+ 110,
168
+ 100
167
169
  ]
170
+ },
171
+ {
172
+ kind: "account",
173
+ path: "validator_bond_account.vote_account",
174
+ account: "ValidatorBondAccount"
168
175
  }
169
176
  ]
170
177
  }
171
178
  },
172
179
  {
173
- name: "authority",
180
+ name: "depositor",
174
181
  writable: true,
175
182
  signer: true
176
183
  },
177
- {
178
- name: "reserve"
179
- },
180
184
  {
181
185
  name: "system_program",
182
186
  address: "11111111111111111111111111111111"
183
187
  }
184
188
  ],
185
- args: []
189
+ args: [
190
+ {
191
+ name: "amount",
192
+ type: "u64"
193
+ }
194
+ ]
186
195
  },
187
196
  {
188
- name: "register",
189
- docs: [
190
- "Registers a new validator with the bonding program.",
191
- "Sets up the validator's bond account and deposits initial collateral.",
192
- "",
193
- "# Arguments",
194
- "* `initial_collateral` - Amount of collateral to lock (must be positive).",
195
- "* `withdrawal_authority` - Optional key that can withdraw collateral later.",
196
- "",
197
- "# Errors",
198
- "Fails if the validator is already registered, if the vote account is invalid,",
199
- "or if the initial collateral transfer fails."
200
- ],
197
+ name: "bond_withdraw",
201
198
  discriminator: [
202
- 211,
203
- 124,
204
- 67,
205
- 15,
206
- 211,
207
- 194,
199
+ 99,
200
+ 64,
201
+ 127,
208
202
  178,
209
- 240
203
+ 53,
204
+ 117,
205
+ 70,
206
+ 204
210
207
  ],
211
208
  accounts: [
212
209
  {
213
- name: "global_state",
214
- writable: true,
215
- pda: {
216
- seeds: [
217
- {
218
- kind: "const",
219
- value: [
220
- 103,
221
- 108,
222
- 111,
223
- 98,
224
- 97,
225
- 108,
226
- 95,
227
- 115,
228
- 116,
229
- 97,
230
- 116,
231
- 101
232
- ]
233
- }
234
- ]
235
- }
236
- },
237
- {
238
- name: "validator_bond",
210
+ name: "validator_bond_account",
239
211
  writable: true,
240
212
  pda: {
241
213
  seeds: [
@@ -260,24 +232,24 @@ var jbond_default = {
260
232
  },
261
233
  {
262
234
  kind: "account",
263
- path: "vote_account"
235
+ path: "validator_bond_account.vote_account",
236
+ account: "ValidatorBondAccount"
264
237
  }
265
238
  ]
266
239
  }
267
240
  },
268
241
  {
269
- name: "identity"
242
+ name: "withdrawal_authority",
243
+ writable: true,
244
+ signer: true
270
245
  },
271
246
  {
272
- name: "vote_account"
247
+ name: "destination",
248
+ writable: true
273
249
  },
274
250
  {
275
- name: "creator",
276
- docs: [
277
- "The account creating the bond (pays for account creation and initial collateral)"
278
- ],
279
- writable: true,
280
- signer: true
251
+ name: "epoch_schedule",
252
+ address: "SysvarEpochSchedu1e111111111111111111111111"
281
253
  },
282
254
  {
283
255
  name: "system_program",
@@ -286,28 +258,71 @@ var jbond_default = {
286
258
  ],
287
259
  args: [
288
260
  {
289
- name: "initial_collateral",
261
+ name: "amount",
290
262
  type: "u64"
291
- },
263
+ }
264
+ ]
265
+ },
266
+ {
267
+ name: "initialize",
268
+ docs: [
269
+ "Initialize the global state and reserve vault"
270
+ ],
271
+ discriminator: [
272
+ 175,
273
+ 175,
274
+ 109,
275
+ 31,
276
+ 13,
277
+ 152,
278
+ 155,
279
+ 237
280
+ ],
281
+ accounts: [
292
282
  {
293
- name: "withdrawal_authority",
294
- type: {
295
- option: "pubkey"
283
+ name: "global_state",
284
+ writable: true,
285
+ pda: {
286
+ seeds: [
287
+ {
288
+ kind: "const",
289
+ value: [
290
+ 103,
291
+ 108,
292
+ 111,
293
+ 98,
294
+ 97,
295
+ 108,
296
+ 95,
297
+ 115,
298
+ 116,
299
+ 97,
300
+ 116,
301
+ 101
302
+ ]
303
+ }
304
+ ]
296
305
  }
306
+ },
307
+ {
308
+ name: "authority",
309
+ writable: true,
310
+ signer: true
311
+ },
312
+ {
313
+ name: "reserve"
314
+ },
315
+ {
316
+ name: "system_program",
317
+ address: "11111111111111111111111111111111"
297
318
  }
298
- ]
319
+ ],
320
+ args: []
299
321
  },
300
322
  {
301
323
  name: "set_authority",
302
324
  docs: [
303
- "Sets a new withdrawal authority for a validator's bond account.",
304
- "Allows changing who can withdraw collateral in the future.",
305
- "",
306
- "# Arguments",
307
- "* `new_authority` - Optional new authority key (None to restrict to identity).",
308
- "",
309
- "# Errors",
310
- "Fails if the signer is not authorized to change the authority."
325
+ "Change the bond authority"
311
326
  ],
312
327
  discriminator: [
313
328
  133,
@@ -359,105 +374,48 @@ var jbond_default = {
359
374
  args: []
360
375
  },
361
376
  {
362
- name: "top_up",
377
+ name: "withdraw_compensation",
363
378
  docs: [
364
- "Adds additional collateral to an existing validator's bond.",
365
- "Increases the collateral balance, enhancing the validator's stake.",
366
- "",
367
- "# Arguments",
368
- "* `amount` - Amount to add.",
369
- "",
370
- "# Errors",
371
- "Fails if the validator is not active, if the amount is zero,",
372
- "or if the transfer of funds fails."
379
+ "Withdraw compensation from validator to reserve (oracle only)"
373
380
  ],
374
381
  discriminator: [
375
- 236,
376
- 225,
377
- 96,
378
- 9,
379
- 60,
380
- 106,
381
- 77,
382
- 208
382
+ 10,
383
+ 228,
384
+ 22,
385
+ 213,
386
+ 205,
387
+ 117,
388
+ 181,
389
+ 75
383
390
  ],
384
391
  accounts: [
385
392
  {
386
- name: "validator_bond",
393
+ name: "global_state",
387
394
  writable: true,
388
395
  pda: {
389
396
  seeds: [
390
397
  {
391
398
  kind: "const",
392
399
  value: [
393
- 118,
400
+ 103,
401
+ 108,
402
+ 111,
403
+ 98,
394
404
  97,
395
405
  108,
396
- 105,
397
- 100,
406
+ 95,
407
+ 115,
408
+ 116,
398
409
  97,
399
410
  116,
400
- 111,
401
- 114,
402
- 95,
403
- 98,
404
- 111,
405
- 110,
406
- 100
411
+ 101
407
412
  ]
408
- },
409
- {
410
- kind: "account",
411
- path: "validator_bond.vote_account",
412
- account: "ValidatorBond"
413
413
  }
414
414
  ]
415
415
  }
416
416
  },
417
417
  {
418
- name: "payer",
419
- writable: true,
420
- signer: true
421
- },
422
- {
423
- name: "system_program",
424
- address: "11111111111111111111111111111111"
425
- }
426
- ],
427
- args: [
428
- {
429
- name: "amount",
430
- type: "u64"
431
- }
432
- ]
433
- },
434
- {
435
- name: "withdraw",
436
- docs: [
437
- "Withdraws collateral from a validator's bond.",
438
- "Decreases the collateral balance, allowing the validator to reclaim funds.",
439
- "",
440
- "# Arguments",
441
- "* `amount` - Amount to withdraw (must not exceed available balance).",
442
- "",
443
- "# Errors",
444
- "Fails if the validator is not active, if the amount is zero,",
445
- "if the withdrawal authority is invalid, or if the withdrawal would",
446
- "leave insufficient collateral."
447
- ],
448
- discriminator: [
449
- 183,
450
- 18,
451
- 70,
452
- 156,
453
- 148,
454
- 109,
455
- 161,
456
- 34
457
- ],
458
- accounts: [
459
- {
460
- name: "validator_bond",
418
+ name: "validator_bond_account",
461
419
  writable: true,
462
420
  pda: {
463
421
  seeds: [
@@ -482,24 +440,22 @@ var jbond_default = {
482
440
  },
483
441
  {
484
442
  kind: "account",
485
- path: "validator_bond.vote_account",
486
- account: "ValidatorBond"
443
+ path: "validator_bond_account.vote_account",
444
+ account: "ValidatorBondAccount"
487
445
  }
488
446
  ]
489
447
  }
490
448
  },
491
449
  {
492
- name: "withdrawal_authority",
493
- writable: true,
494
- signer: true
495
- },
496
- {
497
- name: "destination",
450
+ name: "reserve",
498
451
  writable: true
499
452
  },
500
453
  {
501
- name: "epoch_schedule",
502
- address: "SysvarEpochSchedu1e111111111111111111111111"
454
+ name: "authority",
455
+ docs: [
456
+ "Authority that can trigger claims"
457
+ ],
458
+ signer: true
503
459
  },
504
460
  {
505
461
  name: "system_program",
@@ -529,16 +485,16 @@ var jbond_default = {
529
485
  ]
530
486
  },
531
487
  {
532
- name: "ValidatorBond",
488
+ name: "ValidatorBondAccount",
533
489
  discriminator: [
534
- 82,
535
- 127,
536
- 243,
537
- 208,
538
- 195,
539
- 42,
540
- 80,
541
- 35
490
+ 25,
491
+ 67,
492
+ 241,
493
+ 227,
494
+ 226,
495
+ 104,
496
+ 108,
497
+ 73
542
498
  ]
543
499
  }
544
500
  ],
@@ -663,7 +619,7 @@ var jbond_default = {
663
619
  type: "u64"
664
620
  },
665
621
  {
666
- name: "post_balance",
622
+ name: "new_total",
667
623
  type: "u64"
668
624
  },
669
625
  {
@@ -687,7 +643,7 @@ var jbond_default = {
687
643
  type: "u64"
688
644
  },
689
645
  {
690
- name: "post_balance",
646
+ name: "remaining_collateral",
691
647
  type: "u64"
692
648
  },
693
649
  {
@@ -711,7 +667,11 @@ var jbond_default = {
711
667
  type: "u64"
712
668
  },
713
669
  {
714
- name: "post_balance",
670
+ name: "remaining_collateral",
671
+ type: "u64"
672
+ },
673
+ {
674
+ name: "total_withdrawn",
715
675
  type: "u64"
716
676
  },
717
677
  {
@@ -732,117 +692,68 @@ var jbond_default = {
732
692
  fields: [
733
693
  {
734
694
  name: "authority",
735
- docs: [
736
- "The authority allowed to manage the program"
737
- ],
738
695
  type: "pubkey"
739
696
  },
740
697
  {
741
698
  name: "reserve",
742
- docs: [
743
- "The reserve vault holding SOL for bonding and compensation"
744
- ],
745
699
  type: "pubkey"
746
700
  },
747
701
  {
748
702
  name: "total_validators",
749
- docs: [
750
- "Total number of registered validators"
751
- ],
752
- type: "u16"
703
+ type: "u32"
753
704
  },
754
705
  {
755
- name: "total_compensation_amount",
756
- docs: [
757
- "Total compensation amount paid out"
758
- ],
706
+ name: "total_withdrawn",
759
707
  type: "u64"
760
708
  },
761
709
  {
762
710
  name: "bump",
763
- docs: [
764
- "Bump for the PDA"
765
- ],
766
711
  type: "u8"
767
712
  }
768
713
  ]
769
714
  }
770
715
  },
771
716
  {
772
- name: "ValidatorBond",
717
+ name: "ValidatorBondAccount",
773
718
  type: {
774
719
  kind: "struct",
775
720
  fields: [
776
721
  {
777
722
  name: "identity",
778
- docs: [
779
- "The validator identity pubkey"
780
- ],
781
723
  type: "pubkey"
782
724
  },
783
725
  {
784
726
  name: "vote_account",
785
- docs: [
786
- "The validator vote account pubkey"
787
- ],
788
727
  type: "pubkey"
789
728
  },
790
729
  {
791
730
  name: "creator",
792
- docs: [
793
- "Creator of the validator bond account"
794
- ],
795
731
  type: "pubkey"
796
732
  },
797
733
  {
798
734
  name: "withdrawal_authority",
799
- docs: [
800
- "Authority allowed to withdraw funds (if None, only identity can withdraw)"
801
- ],
802
735
  type: {
803
736
  option: "pubkey"
804
737
  }
805
738
  },
806
739
  {
807
- name: "total_compensation_amount",
808
- docs: [
809
- "Total compensation claimed for the validator"
810
- ],
740
+ name: "total_withdrawn",
811
741
  type: "u64"
812
742
  },
813
743
  {
814
- name: "last_compensation_amount",
815
- docs: [
816
- "Last compensation amount claimed"
817
- ],
744
+ name: "last_withdrawal_epoch",
818
745
  type: "u64"
819
746
  },
820
747
  {
821
- name: "last_compensation_epoch",
822
- docs: [
823
- "Last epoch when compensation was claimed"
824
- ],
825
- type: "u64"
748
+ name: "is_active",
749
+ type: "bool"
826
750
  },
827
751
  {
828
752
  name: "created_at",
829
- docs: [
830
- "Timestamp when the bond account was created"
831
- ],
832
753
  type: "i64"
833
754
  },
834
- {
835
- name: "is_active",
836
- docs: [
837
- "Whether the validator is currently active"
838
- ],
839
- type: "bool"
840
- },
841
755
  {
842
756
  name: "bump",
843
- docs: [
844
- "Bump for the PDA"
845
- ],
846
757
  type: "u8"
847
758
  }
848
759
  ]
@@ -854,7 +765,7 @@ var jbond_default = {
854
765
  kind: "struct",
855
766
  fields: [
856
767
  {
857
- name: "identity",
768
+ name: "validator",
858
769
  type: "pubkey"
859
770
  },
860
771
  {
@@ -862,7 +773,7 @@ var jbond_default = {
862
773
  type: "pubkey"
863
774
  },
864
775
  {
865
- name: "initial_collateral",
776
+ name: "collateral_amount",
866
777
  type: "u64"
867
778
  },
868
779
  {
@@ -914,66 +825,56 @@ var NodeWallet = class {
914
825
  }
915
826
  };
916
827
 
917
- // src/utils/index.ts
918
- var SLOTS_PER_EPOCH_MAINNET = 432e3;
919
- var SLOTS_PER_EPOCH_DEVNET = 4e5;
920
- function slotToEpoch(slot, cluster) {
921
- const slotsPerEpoch = cluster === "mainnet-beta" ? SLOTS_PER_EPOCH_MAINNET : SLOTS_PER_EPOCH_DEVNET;
922
- return Math.floor(slot / slotsPerEpoch);
923
- }
924
-
925
828
  // src/client.ts
926
829
  var BondClientEnv = /* @__PURE__ */ ((BondClientEnv2) => {
927
830
  BondClientEnv2["DEV"] = "dev";
928
- BondClientEnv2["STAGE"] = "stage";
929
831
  BondClientEnv2["PROD"] = "prod";
930
832
  return BondClientEnv2;
931
833
  })(BondClientEnv || {});
932
834
  var JBondClient = class _JBondClient {
933
- constructor(provider, options) {
934
- this.provider = provider;
835
+ connection;
836
+ program;
837
+ provider;
838
+ config;
839
+ options;
840
+ constructor(config, wallet, options) {
841
+ this.config = config;
842
+ this.connection = new Connection(config.rpcUrl, "confirmed");
935
843
  this.options = options ?? {};
844
+ this.provider = new AnchorProvider(
845
+ this.connection,
846
+ // @ts-expect-error support anonymous
847
+ wallet ?? { publicKey: PublicKey.default },
848
+ AnchorProvider.defaultOptions()
849
+ );
936
850
  this.program = new Program(jbond_default, this.provider);
937
851
  }
938
- options;
939
- program;
940
852
  /**
941
853
  * Creates an instance of `JBondClient` using a provided connection and wallet.
942
854
  */
943
- static fromWallet(connection, wallet, options) {
944
- return new this(
945
- new AnchorProvider(
946
- connection,
947
- // @ts-expect-error support anonymous
948
- wallet ?? { publicKey: PublicKey.default },
949
- AnchorProvider.defaultOptions()
950
- ),
951
- options
952
- );
855
+ static fromWallet(config, wallet, options) {
856
+ return new this(config, wallet, options);
953
857
  }
954
858
  /**
955
859
  * Creates an instance of `JBondClient` using the provided connection and keypair.
956
860
  */
957
- static fromKeypair(connection, keypair, options) {
958
- return _JBondClient.fromWallet(connection, new NodeWallet(keypair), options);
861
+ static fromKeypair(config, keypair, options) {
862
+ return _JBondClient.fromWallet(config, new NodeWallet(keypair), options);
959
863
  }
960
864
  /**
961
865
  * Get the current program ID.
962
866
  */
963
867
  get programId() {
964
- return this.options.programId ?? this.program.programId;
965
- }
966
- /**
967
- * Get the current connection.
968
- */
969
- get connection() {
970
- return this.provider.connection;
868
+ return this.options.programId ?? PROGRAM_ID;
971
869
  }
972
870
  /**
973
871
  * Set the environment.
974
872
  */
975
873
  env(env) {
976
- return this.configure("programId", ENV_PROGRAM_ID[env]);
874
+ if (env === "prod" /* PROD */) {
875
+ return this.configure("programId", PROGRAM_ID);
876
+ }
877
+ return this.configure("programId", DEV_PROGRAM_ID);
977
878
  }
978
879
  /**
979
880
  * Configure a specific option.
@@ -982,109 +883,95 @@ var JBondClient = class _JBondClient {
982
883
  this.options[key] = val;
983
884
  return this;
984
885
  }
985
- /**
986
- * Program Derived Addresses (PDAs)
987
- */
988
- pda = {
989
- globalState: () => {
990
- return PublicKey.findProgramAddressSync(
991
- [Buffer.from("global_state")],
992
- this.programId
993
- );
994
- },
995
- validatorBond: (voteAccount) => {
996
- return PublicKey.findProgramAddressSync(
997
- [
998
- Buffer.from("validator_bond"),
999
- voteAccount.toBuffer()
1000
- ],
1001
- this.programId
1002
- );
1003
- }
1004
- };
1005
- /**
1006
- * Build initialize instruction
1007
- * @param props
1008
- */
886
+ // Get PDA for global state
887
+ getGlobalStatePDA() {
888
+ return PublicKey.findProgramAddressSync(
889
+ [Buffer.from("global_state")],
890
+ this.options.programId ?? this.program.programId
891
+ );
892
+ }
893
+ // Get PDA for validator bond account
894
+ getValidatorBondPDA(voteAccount) {
895
+ return PublicKey.findProgramAddressSync(
896
+ [
897
+ Buffer.from("validator_bond"),
898
+ voteAccount.toBuffer()
899
+ ],
900
+ this.options.programId ?? this.program.programId
901
+ );
902
+ }
903
+ // Build initialize instruction
1009
904
  async buildInitializeInstruction(props) {
1010
- const [globalState] = this.pda.globalState();
1011
- const { authority, reserveAddress: reserve } = props;
1012
- return this.program.methods.initialize().accountsPartial({
905
+ const [globalState] = this.getGlobalStatePDA();
906
+ const { authority, reserveAddress } = props;
907
+ return this.program.methods.initialize().accountsStrict({
1013
908
  globalState,
1014
909
  authority,
1015
- reserve
910
+ reserve: reserveAddress,
911
+ systemProgram: SystemProgram.programId
1016
912
  }).instruction();
1017
913
  }
1018
- /**
1019
- * Build register validator instruction
1020
- * @param props
1021
- */
914
+ // Build register validator instruction
1022
915
  async buildRegisterValidatorInstruction(props) {
1023
916
  const { creator, identity, voteAccount, initialCollateral, withdrawalAuthority } = props;
1024
- const [validatorBondAccountAddress] = this.pda.validatorBond(voteAccount);
917
+ const [validatorBondAccountAddress] = this.getValidatorBondPDA(voteAccount);
1025
918
  const accountInfo = await this.connection.getAccountInfo(validatorBondAccountAddress);
1026
919
  if (accountInfo) {
1027
920
  throw new Error("Validator bond account already exists");
1028
921
  }
1029
- const [globalState] = this.pda.globalState();
922
+ const [globalState] = this.getGlobalStatePDA();
1030
923
  const collateralLamports = new BN(initialCollateral * LAMPORTS_PER_SOL);
1031
- return this.program.methods.register(collateralLamports, withdrawalAuthority ?? null).accountsPartial({
924
+ return this.program.methods.bondInit(collateralLamports, withdrawalAuthority ?? null).accountsStrict({
1032
925
  creator,
1033
926
  globalState,
1034
- validatorBond: validatorBondAccountAddress,
927
+ validatorBondAccount: validatorBondAccountAddress,
1035
928
  identity,
1036
- voteAccount
929
+ voteAccount,
930
+ systemProgram: SystemProgram.programId
1037
931
  }).instruction();
1038
932
  }
1039
- /**
1040
- * Build top up collateral instruction
1041
- * @param props
1042
- */
933
+ // Build top up collateral instruction
1043
934
  buildTopUpCollateralInstruction(props) {
1044
935
  const { user, voteAccount, amount } = props;
1045
- const [validatorBondAccountAddress] = this.pda.validatorBond(voteAccount);
936
+ const [validatorBondAccountAddress] = this.getValidatorBondPDA(voteAccount);
1046
937
  const amountLamports = new BN(amount * LAMPORTS_PER_SOL);
1047
- return this.program.methods.topUp(amountLamports).accountsPartial({
1048
- validatorBond: validatorBondAccountAddress,
1049
- payer: user
938
+ return this.program.methods.bondTopUp(amountLamports).accountsStrict({
939
+ validatorBondAccount: validatorBondAccountAddress,
940
+ depositor: user,
941
+ systemProgram: SystemProgram.programId
1050
942
  }).instruction();
1051
943
  }
1052
944
  async buildWithdrawCollateralInstruction(props) {
1053
945
  const { withdrawalAuthority: user, voteAccount, destination, amount } = props;
1054
- const [validatorBondAccountAddress] = this.pda.validatorBond(voteAccount);
946
+ const [validatorBondAccountAddress] = this.getValidatorBondPDA(voteAccount);
1055
947
  const amountLamports = new BN(amount * LAMPORTS_PER_SOL);
1056
- return this.program.methods.withdraw(amountLamports).accountsPartial({
1057
- validatorBond: validatorBondAccountAddress,
948
+ return this.program.methods.bondWithdraw(amountLamports).accountsStrict({
949
+ validatorBondAccount: validatorBondAccountAddress,
1058
950
  withdrawalAuthority: user,
951
+ destination,
1059
952
  epochSchedule: SYSVAR_EPOCH_SCHEDULE_PUBKEY,
1060
- destination
953
+ systemProgram: SystemProgram.programId
1061
954
  }).instruction();
1062
955
  }
1063
- /**
1064
- * Build withdraw compensation instruction
1065
- * @param props
1066
- */
956
+ // Build withdraw compensation instruction
1067
957
  async buildWithdrawCompensationInstruction(props) {
1068
958
  const { authority, voteAccount, amount } = props;
1069
- const [globalState] = this.pda.globalState();
1070
- const [validatorBondAccountAddress] = this.pda.validatorBond(voteAccount);
959
+ const [globalState] = this.getGlobalStatePDA();
960
+ const [validatorBondAccountAddress] = this.getValidatorBondPDA(voteAccount);
1071
961
  const amountLamports = new BN(amount * LAMPORTS_PER_SOL);
1072
962
  const reserveAddress = (await this.getGlobalState())?.reserveAddress;
1073
963
  if (!reserveAddress) {
1074
964
  throw new Error("Reserve address is not set in the global state. The program might not be initialized yet.");
1075
965
  }
1076
- return this.program.methods.claim(amountLamports).accountsPartial({
966
+ return this.program.methods.withdrawCompensation(amountLamports).accountsStrict({
1077
967
  globalState,
1078
- validatorBond: validatorBondAccountAddress,
968
+ validatorBondAccount: validatorBondAccountAddress,
1079
969
  reserve: reserveAddress,
1080
- authority
970
+ authority,
971
+ systemProgram: SystemProgram.programId
1081
972
  }).instruction();
1082
973
  }
1083
- /**
1084
- * Build multiple withdraw compensation instructions
1085
- * @param authority
1086
- * @param withdrawals
1087
- */
974
+ // Build multiple withdraw compensation instructions
1088
975
  buildWithdrawCompensationsInstructions(authority, withdrawals) {
1089
976
  return Promise.all(
1090
977
  withdrawals.map(
@@ -1092,33 +979,29 @@ var JBondClient = class _JBondClient {
1092
979
  )
1093
980
  );
1094
981
  }
1095
- /**
1096
- * Get validator bond account state
1097
- * @param vote
1098
- */
1099
- async getValidatorBond(vote) {
1100
- const [validatorBondAccountAddress] = this.pda.validatorBond(vote);
982
+ // Get validator bond account state
983
+ async getValidatorBondAccount(voteAccount) {
984
+ const [validatorBondAccountAddress] = this.getValidatorBondPDA(voteAccount);
1101
985
  try {
1102
- const account = await this.program.account.validatorBond.fetch(validatorBondAccountAddress);
986
+ const account = await this.program.account.validatorBondAccount.fetch(validatorBondAccountAddress);
1103
987
  return {
1104
988
  identity: account.identity.toString(),
1105
989
  voteAccount: account.voteAccount.toString(),
1106
990
  withdrawalAuthority: account.withdrawalAuthority ? account.withdrawalAuthority.toString() : null,
1107
- totalCompensationAmount: account.totalCompensationAmount.toNumber() / LAMPORTS_PER_SOL,
991
+ totalWithdrawn: account.totalWithdrawn.toNumber() / LAMPORTS_PER_SOL,
992
+ lastWithdrawalEpoch: account.lastWithdrawalEpoch.toNumber(),
1108
993
  isActive: account.isActive,
1109
994
  createdAt: account.createdAt.toNumber() * 1e3,
1110
- // Convert i64 Unix seconds (BN) to JS milliseconds
995
+ // TODO
1111
996
  bump: account.bump
1112
997
  };
1113
998
  } catch {
1114
999
  return null;
1115
1000
  }
1116
1001
  }
1117
- /**
1118
- * Build set authority instruction
1119
- */
1002
+ // Build set authority instruction
1120
1003
  async buildSetAuthorityInstruction(props) {
1121
- const [globalState] = this.pda.globalState();
1004
+ const [globalState] = this.getGlobalStatePDA();
1122
1005
  return this.program.methods.setAuthority().accountsStrict({
1123
1006
  globalState,
1124
1007
  authority: props.authority,
@@ -1127,11 +1010,11 @@ var JBondClient = class _JBondClient {
1127
1010
  }
1128
1011
  /**
1129
1012
  * Get the collateral balance of a validator bond account
1130
- * @param vote - The vote account public key
1013
+ * @param voteAccount - The vote account public key
1131
1014
  * @returns The available collateral balance in SOL (excluding rent-exempt amount)
1132
1015
  */
1133
- async getValidatorCollateralBalance(vote) {
1134
- const [validatorBondAccountAddress] = this.pda.validatorBond(vote);
1016
+ async getValidatorCollateralBalance(voteAccount) {
1017
+ const [validatorBondAccountAddress] = this.getValidatorBondPDA(voteAccount);
1135
1018
  const accountInfo = await this.connection.getAccountInfo(validatorBondAccountAddress);
1136
1019
  if (!accountInfo) {
1137
1020
  return 0;
@@ -1142,38 +1025,35 @@ var JBondClient = class _JBondClient {
1142
1025
  const availableBalance = Math.max(0, accountInfo.lamports - rentExempt);
1143
1026
  return availableBalance / LAMPORTS_PER_SOL;
1144
1027
  }
1145
- /**
1146
- * Get global state
1147
- */
1028
+ // Get global state state
1148
1029
  async getGlobalState() {
1149
- const [globalState] = this.pda.globalState();
1150
- const account = await this.program.account.globalState.fetch(globalState);
1151
- return {
1152
- authority: account.authority.toString(),
1153
- totalValidators: account.totalValidators,
1154
- totalCompensationAmount: account.totalCompensationAmount.toNumber() / LAMPORTS_PER_SOL,
1155
- reserveAddress: account.reserve.toString()
1156
- };
1030
+ const [globalState] = this.getGlobalStatePDA();
1031
+ try {
1032
+ const account = await this.program.account.globalState.fetch(globalState);
1033
+ return {
1034
+ authority: account.authority.toString(),
1035
+ totalValidators: account.totalValidators,
1036
+ totalWithdrawn: account.totalWithdrawn.toNumber() / LAMPORTS_PER_SOL,
1037
+ reserveAddress: account.reserve.toString()
1038
+ };
1039
+ } catch {
1040
+ return null;
1041
+ }
1157
1042
  }
1158
- /**
1159
- * Get current epoch
1160
- */
1043
+ // Get current epoch
1161
1044
  async getCurrentEpoch() {
1162
1045
  const epochInfo = await this.connection.getEpochInfo();
1163
1046
  return epochInfo.epoch;
1164
1047
  }
1165
- /**
1166
- * Helper methods for backward compatibility (can be removed if not needed)
1167
- * @param props
1168
- */
1169
- async initialize(props) {
1170
- const { reserveAddress } = props;
1171
- const authority = props.authority ?? this.provider.wallet.publicKey;
1172
- const ix = await this.buildInitializeInstruction({ reserveAddress, authority });
1173
- return await this.provider.sendAndConfirm(
1048
+ // Helper methods for backward compatibility (can be removed if not needed)
1049
+ async initialize(reserveAddress, authority) {
1050
+ const authorityPubkey = authority || this.provider.wallet.publicKey;
1051
+ const ix = await this.buildInitializeInstruction({ authority: authorityPubkey, reserveAddress });
1052
+ const tx = await this.provider.sendAndConfirm(
1174
1053
  new Transaction().add(ix),
1175
1054
  []
1176
1055
  );
1056
+ return tx;
1177
1057
  }
1178
1058
  // Note: this method will be removed or changed in the future (CLI only)
1179
1059
  async registerValidator(voteAccount, initialCollateral, withdrawalAuthority, identity) {
@@ -1181,40 +1061,44 @@ var JBondClient = class _JBondClient {
1181
1061
  const ix = await this.buildRegisterValidatorInstruction(
1182
1062
  { creator: identityPubkey, identity: identityPubkey, voteAccount, initialCollateral, withdrawalAuthority }
1183
1063
  );
1184
- return await this.provider.sendAndConfirm(
1064
+ const tx = await this.provider.sendAndConfirm(
1185
1065
  new Transaction().add(ix),
1186
1066
  []
1187
1067
  );
1068
+ return tx;
1188
1069
  }
1189
1070
  async topUpCollateral(voteAccount, amount, validator) {
1190
1071
  const userPubkey = validator ?? this.provider.wallet.publicKey;
1191
1072
  const ix = await this.buildTopUpCollateralInstruction(
1192
1073
  { user: userPubkey, voteAccount, amount }
1193
1074
  );
1194
- return await this.provider.sendAndConfirm(
1075
+ const tx = await this.provider.sendAndConfirm(
1195
1076
  new Transaction().add(ix),
1196
1077
  []
1197
1078
  );
1079
+ return tx;
1198
1080
  }
1199
1081
  async withdrawCollateral(voteAccount, destination, amount, withdrawalAuthority) {
1200
1082
  const authorityPubkey = withdrawalAuthority ?? this.provider.wallet.publicKey;
1201
1083
  const ix = await this.buildWithdrawCollateralInstruction(
1202
1084
  { withdrawalAuthority: authorityPubkey, voteAccount, destination, amount }
1203
1085
  );
1204
- return await this.provider.sendAndConfirm(
1086
+ const tx = await this.provider.sendAndConfirm(
1205
1087
  new Transaction().add(ix),
1206
1088
  []
1207
1089
  );
1090
+ return tx;
1208
1091
  }
1209
1092
  async claimCompensation(voteAccount, amount, authority) {
1210
1093
  const authorityPubkey = authority ?? this.provider.wallet.publicKey;
1211
1094
  const ix = await this.buildWithdrawCompensationInstruction(
1212
1095
  { authority: authorityPubkey, voteAccount, amount }
1213
1096
  );
1214
- return await this.provider.sendAndConfirm(
1097
+ const tx = await this.provider.sendAndConfirm(
1215
1098
  new Transaction().add(ix),
1216
1099
  []
1217
1100
  );
1101
+ return tx;
1218
1102
  }
1219
1103
  /**
1220
1104
  * Get transaction history grouped by epochs
@@ -1252,18 +1136,19 @@ var JBondClient = class _JBondClient {
1252
1136
  for (const epochData of epochMap.values()) {
1253
1137
  epochData.balanceChange = epochData.deposits - epochData.withdrawals;
1254
1138
  }
1255
- return [...epochMap.values()].toSorted((a, b) => b.epoch - a.epoch);
1139
+ const result = [...epochMap.values()].toSorted((a, b) => b.epoch - a.epoch);
1140
+ return result;
1256
1141
  }
1257
1142
  async getHistory(voteAccount, options) {
1258
- const [ValidatorBondAccount] = this.pda.validatorBond(voteAccount);
1259
- const signatures = (await this.connection.getSignaturesForAddress(
1143
+ const [ValidatorBondAccount] = this.getValidatorBondPDA(voteAccount);
1144
+ const signatures = await this.connection.getSignaturesForAddress(
1260
1145
  ValidatorBondAccount,
1261
1146
  {
1262
1147
  limit: options?.limit || 1e3,
1263
1148
  before: options?.before,
1264
1149
  until: options?.until
1265
1150
  }
1266
- )).filter((sig) => !sig.err);
1151
+ );
1267
1152
  const signatureStrings = signatures.map((sig) => sig.signature);
1268
1153
  const BATCH_SIZE = 100;
1269
1154
  const allTransactions = [];
@@ -1281,7 +1166,7 @@ var JBondClient = class _JBondClient {
1281
1166
  const history = [];
1282
1167
  for (const [idx, tx] of allTransactions.entries()) {
1283
1168
  const sigInfo = signatures[idx];
1284
- if (!tx || !tx.meta || tx.meta.err !== null) {
1169
+ if (!tx || !tx.meta) {
1285
1170
  continue;
1286
1171
  }
1287
1172
  try {
@@ -1303,10 +1188,10 @@ var JBondClient = class _JBondClient {
1303
1188
  const dataBuffer = bs58.decode(data);
1304
1189
  if (dataBuffer.length >= 16) {
1305
1190
  const discriminator = dataBuffer.slice(0, 8);
1306
- const bondInitDiscriminator = this.getInstructionDiscriminator("register");
1307
- const bondTopUpDiscriminator = this.getInstructionDiscriminator("topUp");
1308
- const withdrawCompensationDiscriminator = this.getInstructionDiscriminator("claim");
1309
- const bondWithdrawDiscriminator = this.getInstructionDiscriminator("withdraw");
1191
+ const bondInitDiscriminator = this.getInstructionDiscriminator("bondInit");
1192
+ const bondTopUpDiscriminator = this.getInstructionDiscriminator("bondTopUp");
1193
+ const withdrawCompensationDiscriminator = this.getInstructionDiscriminator("withdrawCompensation");
1194
+ const bondWithdrawDiscriminator = this.getInstructionDiscriminator("bondWithdraw");
1310
1195
  const amountBytes = dataBuffer.slice(8, 16);
1311
1196
  const amountBN = new BN(amountBytes, "le");
1312
1197
  amount = amountBN.toNumber() / LAMPORTS_PER_SOL;
@@ -1351,11 +1236,7 @@ var JBondClient = class _JBondClient {
1351
1236
  }
1352
1237
  return history.toSorted((a, b) => b.slot - a.slot);
1353
1238
  }
1354
- /**
1355
- * Get full transaction history by paginating through results
1356
- * @param voteAccount
1357
- * @param pageSize
1358
- */
1239
+ // Helper method to get paginated history
1359
1240
  async getFullHistory(voteAccount, pageSize = 100) {
1360
1241
  const allHistory = [];
1361
1242
  let before;
@@ -1375,11 +1256,6 @@ var JBondClient = class _JBondClient {
1375
1256
  }
1376
1257
  return allHistory;
1377
1258
  }
1378
- /**
1379
- * Get instruction discriminator from IDL
1380
- * @param instructionName
1381
- * @private
1382
- */
1383
1259
  getInstructionDiscriminator(instructionName) {
1384
1260
  const instruction = this.program.idl.instructions.find((ix) => ix.name === instructionName);
1385
1261
  if (!instruction) {
@@ -1392,6 +1268,6 @@ var JBondClient = class _JBondClient {
1392
1268
  }
1393
1269
  };
1394
1270
 
1395
- export { BondClientEnv, BondTransactionType, ENV_PROGRAM_ID, JBondClient, NodeWallet };
1271
+ export { BondClientEnv, BondTransactionType, DEV_PROGRAM_ID, JBondClient, PROGRAM_ID };
1396
1272
  //# sourceMappingURL=index.mjs.map
1397
1273
  //# sourceMappingURL=index.mjs.map