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