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