@jpool/bond-sdk 0.10.6 → 0.11.0-next.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +967 -765
- package/dist/index.d.ts +967 -765
- package/dist/index.js +379 -125
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +379 -125
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4759,7 +4759,7 @@ function slotToEpoch(slot, cluster) {
|
|
|
4759
4759
|
|
|
4760
4760
|
// src/idl/jbond.json
|
|
4761
4761
|
var jbond_default = {
|
|
4762
|
-
address: "
|
|
4762
|
+
address: "Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1",
|
|
4763
4763
|
metadata: {
|
|
4764
4764
|
name: "jbond",
|
|
4765
4765
|
version: "0.2.1",
|
|
@@ -5008,6 +5008,50 @@ var jbond_default = {
|
|
|
5008
5008
|
}
|
|
5009
5009
|
]
|
|
5010
5010
|
},
|
|
5011
|
+
{
|
|
5012
|
+
name: "bond_lock_funds",
|
|
5013
|
+
docs: [
|
|
5014
|
+
"Locks funds for both the current and upcoming epoch.",
|
|
5015
|
+
"Moves collateral from available to locked state, making it unavailable for withdrawal for the current and next epoch.",
|
|
5016
|
+
"# Errors",
|
|
5017
|
+
"Fails if the validator is not active, or if there are insufficient available funds."
|
|
5018
|
+
],
|
|
5019
|
+
discriminator: [
|
|
5020
|
+
117,
|
|
5021
|
+
166,
|
|
5022
|
+
195,
|
|
5023
|
+
99,
|
|
5024
|
+
103,
|
|
5025
|
+
45,
|
|
5026
|
+
195,
|
|
5027
|
+
2
|
|
5028
|
+
],
|
|
5029
|
+
accounts: [
|
|
5030
|
+
{
|
|
5031
|
+
name: "bond_state",
|
|
5032
|
+
writable: true
|
|
5033
|
+
},
|
|
5034
|
+
{
|
|
5035
|
+
name: "validator_bond",
|
|
5036
|
+
writable: true
|
|
5037
|
+
},
|
|
5038
|
+
{
|
|
5039
|
+
name: "bond_token_account",
|
|
5040
|
+
optional: true
|
|
5041
|
+
},
|
|
5042
|
+
{
|
|
5043
|
+
name: "payer",
|
|
5044
|
+
writable: true,
|
|
5045
|
+
signer: true
|
|
5046
|
+
}
|
|
5047
|
+
],
|
|
5048
|
+
args: [
|
|
5049
|
+
{
|
|
5050
|
+
name: "amount",
|
|
5051
|
+
type: "u64"
|
|
5052
|
+
}
|
|
5053
|
+
]
|
|
5054
|
+
},
|
|
5011
5055
|
{
|
|
5012
5056
|
name: "bond_register",
|
|
5013
5057
|
docs: [
|
|
@@ -5120,6 +5164,42 @@ var jbond_default = {
|
|
|
5120
5164
|
}
|
|
5121
5165
|
]
|
|
5122
5166
|
},
|
|
5167
|
+
{
|
|
5168
|
+
name: "bond_release_funds",
|
|
5169
|
+
docs: [
|
|
5170
|
+
"Releases locked funds after an epoch ends.",
|
|
5171
|
+
"Moves collateral from locked back to available state, allowing withdrawals.",
|
|
5172
|
+
"# Errors",
|
|
5173
|
+
"Fails if the validator is not active, or if there are insufficient locked funds."
|
|
5174
|
+
],
|
|
5175
|
+
discriminator: [
|
|
5176
|
+
184,
|
|
5177
|
+
224,
|
|
5178
|
+
14,
|
|
5179
|
+
24,
|
|
5180
|
+
76,
|
|
5181
|
+
14,
|
|
5182
|
+
226,
|
|
5183
|
+
190
|
|
5184
|
+
],
|
|
5185
|
+
accounts: [
|
|
5186
|
+
{
|
|
5187
|
+
name: "validator_bond",
|
|
5188
|
+
writable: true
|
|
5189
|
+
},
|
|
5190
|
+
{
|
|
5191
|
+
name: "payer",
|
|
5192
|
+
writable: true,
|
|
5193
|
+
signer: true
|
|
5194
|
+
}
|
|
5195
|
+
],
|
|
5196
|
+
args: [
|
|
5197
|
+
{
|
|
5198
|
+
name: "amount",
|
|
5199
|
+
type: "u64"
|
|
5200
|
+
}
|
|
5201
|
+
]
|
|
5202
|
+
},
|
|
5123
5203
|
{
|
|
5124
5204
|
name: "bond_set_withdraw_authority",
|
|
5125
5205
|
docs: [
|
|
@@ -5299,6 +5379,42 @@ var jbond_default = {
|
|
|
5299
5379
|
}
|
|
5300
5380
|
]
|
|
5301
5381
|
},
|
|
5382
|
+
{
|
|
5383
|
+
name: "bond_update",
|
|
5384
|
+
docs: [
|
|
5385
|
+
"Transitions locked funds between epochs for a validator bond.",
|
|
5386
|
+
"",
|
|
5387
|
+
"This function should be called at epoch boundaries to update the bond's",
|
|
5388
|
+
"`last_update_epoch` and move the `next_epoch_locked` amount into",
|
|
5389
|
+
"`current_epoch_locked`. It ensures that the update only occurs once per epoch.",
|
|
5390
|
+
"",
|
|
5391
|
+
"# Errors",
|
|
5392
|
+
"Returns [`BondError::InvalidEpoch`] if called more than once in the same epoch,",
|
|
5393
|
+
"or if the system clock cannot be accessed."
|
|
5394
|
+
],
|
|
5395
|
+
discriminator: [
|
|
5396
|
+
237,
|
|
5397
|
+
102,
|
|
5398
|
+
183,
|
|
5399
|
+
192,
|
|
5400
|
+
94,
|
|
5401
|
+
83,
|
|
5402
|
+
52,
|
|
5403
|
+
82
|
|
5404
|
+
],
|
|
5405
|
+
accounts: [
|
|
5406
|
+
{
|
|
5407
|
+
name: "validator_bond",
|
|
5408
|
+
writable: true
|
|
5409
|
+
},
|
|
5410
|
+
{
|
|
5411
|
+
name: "payer",
|
|
5412
|
+
writable: true,
|
|
5413
|
+
signer: true
|
|
5414
|
+
}
|
|
5415
|
+
],
|
|
5416
|
+
args: []
|
|
5417
|
+
},
|
|
5302
5418
|
{
|
|
5303
5419
|
name: "bond_withdraw",
|
|
5304
5420
|
docs: [
|
|
@@ -5516,80 +5632,6 @@ var jbond_default = {
|
|
|
5516
5632
|
],
|
|
5517
5633
|
args: []
|
|
5518
5634
|
},
|
|
5519
|
-
{
|
|
5520
|
-
name: "migrate_bond",
|
|
5521
|
-
docs: [
|
|
5522
|
-
"Migrates validator bond data from legacy structure to new structure."
|
|
5523
|
-
],
|
|
5524
|
-
discriminator: [
|
|
5525
|
-
107,
|
|
5526
|
-
119,
|
|
5527
|
-
59,
|
|
5528
|
-
110,
|
|
5529
|
-
76,
|
|
5530
|
-
18,
|
|
5531
|
-
37,
|
|
5532
|
-
163
|
|
5533
|
-
],
|
|
5534
|
-
accounts: [
|
|
5535
|
-
{
|
|
5536
|
-
name: "bond_state",
|
|
5537
|
-
writable: true
|
|
5538
|
-
},
|
|
5539
|
-
{
|
|
5540
|
-
name: "legacy_validator_bond",
|
|
5541
|
-
writable: true
|
|
5542
|
-
},
|
|
5543
|
-
{
|
|
5544
|
-
name: "legacy_vote_account"
|
|
5545
|
-
},
|
|
5546
|
-
{
|
|
5547
|
-
name: "validator_bond",
|
|
5548
|
-
writable: true,
|
|
5549
|
-
pda: {
|
|
5550
|
-
seeds: [
|
|
5551
|
-
{
|
|
5552
|
-
kind: "const",
|
|
5553
|
-
value: [
|
|
5554
|
-
118,
|
|
5555
|
-
97,
|
|
5556
|
-
108,
|
|
5557
|
-
105,
|
|
5558
|
-
100,
|
|
5559
|
-
97,
|
|
5560
|
-
116,
|
|
5561
|
-
111,
|
|
5562
|
-
114,
|
|
5563
|
-
95,
|
|
5564
|
-
98,
|
|
5565
|
-
111,
|
|
5566
|
-
110,
|
|
5567
|
-
100
|
|
5568
|
-
]
|
|
5569
|
-
},
|
|
5570
|
-
{
|
|
5571
|
-
kind: "account",
|
|
5572
|
-
path: "bond_state"
|
|
5573
|
-
},
|
|
5574
|
-
{
|
|
5575
|
-
kind: "account",
|
|
5576
|
-
path: "legacy_vote_account"
|
|
5577
|
-
}
|
|
5578
|
-
]
|
|
5579
|
-
}
|
|
5580
|
-
},
|
|
5581
|
-
{
|
|
5582
|
-
name: "creator",
|
|
5583
|
-
writable: true,
|
|
5584
|
-
signer: true
|
|
5585
|
-
},
|
|
5586
|
-
{
|
|
5587
|
-
name: "system_program",
|
|
5588
|
-
address: "11111111111111111111111111111111"
|
|
5589
|
-
}
|
|
5590
|
-
],
|
|
5591
|
-
args: []
|
|
5592
|
-
},
|
|
5593
5635
|
{
|
|
5594
5636
|
name: "session_finish",
|
|
5595
5637
|
docs: [
|
|
@@ -5656,6 +5698,41 @@ var jbond_default = {
|
|
|
5656
5698
|
type: "u64"
|
|
5657
5699
|
}
|
|
5658
5700
|
]
|
|
5701
|
+
},
|
|
5702
|
+
{
|
|
5703
|
+
name: "test_set_last_update_epoch",
|
|
5704
|
+
docs: [
|
|
5705
|
+
"NOTE!: This instruction is for testing purposes only.",
|
|
5706
|
+
"It allows direct manipulation of the validator bond's last epoch update.",
|
|
5707
|
+
"This should not be used in production environments."
|
|
5708
|
+
],
|
|
5709
|
+
discriminator: [
|
|
5710
|
+
215,
|
|
5711
|
+
125,
|
|
5712
|
+
32,
|
|
5713
|
+
8,
|
|
5714
|
+
43,
|
|
5715
|
+
106,
|
|
5716
|
+
194,
|
|
5717
|
+
221
|
|
5718
|
+
],
|
|
5719
|
+
accounts: [
|
|
5720
|
+
{
|
|
5721
|
+
name: "validator_bond",
|
|
5722
|
+
writable: true
|
|
5723
|
+
},
|
|
5724
|
+
{
|
|
5725
|
+
name: "payer",
|
|
5726
|
+
writable: true,
|
|
5727
|
+
signer: true
|
|
5728
|
+
}
|
|
5729
|
+
],
|
|
5730
|
+
args: [
|
|
5731
|
+
{
|
|
5732
|
+
name: "epoch",
|
|
5733
|
+
type: "u64"
|
|
5734
|
+
}
|
|
5735
|
+
]
|
|
5659
5736
|
}
|
|
5660
5737
|
],
|
|
5661
5738
|
accounts: [
|
|
@@ -5899,6 +5976,11 @@ var jbond_default = {
|
|
|
5899
5976
|
code: 6023,
|
|
5900
5977
|
name: "BondNotEnabled",
|
|
5901
5978
|
msg: "Bond is not enabled"
|
|
5979
|
+
},
|
|
5980
|
+
{
|
|
5981
|
+
code: 6024,
|
|
5982
|
+
name: "InvalidEpoch",
|
|
5983
|
+
msg: "Invalid epoch for this operation"
|
|
5902
5984
|
}
|
|
5903
5985
|
],
|
|
5904
5986
|
types: [
|
|
@@ -6281,33 +6363,76 @@ var jbond_default = {
|
|
|
6281
6363
|
fields: [
|
|
6282
6364
|
{
|
|
6283
6365
|
name: "state",
|
|
6366
|
+
docs: [
|
|
6367
|
+
"The bond state address"
|
|
6368
|
+
],
|
|
6284
6369
|
type: "pubkey"
|
|
6285
6370
|
},
|
|
6286
6371
|
{
|
|
6287
6372
|
name: "identity",
|
|
6373
|
+
docs: [
|
|
6374
|
+
"Validator identity pubkey"
|
|
6375
|
+
],
|
|
6288
6376
|
type: "pubkey"
|
|
6289
6377
|
},
|
|
6290
6378
|
{
|
|
6291
6379
|
name: "vote_account",
|
|
6380
|
+
docs: [
|
|
6381
|
+
"Validator vote account pubkey"
|
|
6382
|
+
],
|
|
6292
6383
|
type: "pubkey"
|
|
6293
6384
|
},
|
|
6294
6385
|
{
|
|
6295
6386
|
name: "creator",
|
|
6387
|
+
docs: [
|
|
6388
|
+
"The bond creator pubkey"
|
|
6389
|
+
],
|
|
6296
6390
|
type: "pubkey"
|
|
6297
6391
|
},
|
|
6298
6392
|
{
|
|
6299
6393
|
name: "withdrawal_authority",
|
|
6394
|
+
docs: [
|
|
6395
|
+
"Optional withdrawal authority pubkey (if set, can withdraw on behalf of the validator,",
|
|
6396
|
+
"otherwise only identity can withdraw)"
|
|
6397
|
+
],
|
|
6300
6398
|
type: {
|
|
6301
6399
|
option: "pubkey"
|
|
6302
6400
|
}
|
|
6303
6401
|
},
|
|
6304
6402
|
{
|
|
6305
6403
|
name: "created_at",
|
|
6404
|
+
docs: [
|
|
6405
|
+
"Bond creation timestamp"
|
|
6406
|
+
],
|
|
6306
6407
|
type: "i64"
|
|
6307
6408
|
},
|
|
6308
6409
|
{
|
|
6309
6410
|
name: "bump",
|
|
6411
|
+
docs: [
|
|
6412
|
+
"Bump for the PDA"
|
|
6413
|
+
],
|
|
6310
6414
|
type: "u8"
|
|
6415
|
+
},
|
|
6416
|
+
{
|
|
6417
|
+
name: "next_epoch_locked",
|
|
6418
|
+
docs: [
|
|
6419
|
+
"Amount of collateral locked for the next epoch"
|
|
6420
|
+
],
|
|
6421
|
+
type: "u64"
|
|
6422
|
+
},
|
|
6423
|
+
{
|
|
6424
|
+
name: "current_epoch_locked",
|
|
6425
|
+
docs: [
|
|
6426
|
+
"Amount of collateral locked for the current epoch"
|
|
6427
|
+
],
|
|
6428
|
+
type: "u64"
|
|
6429
|
+
},
|
|
6430
|
+
{
|
|
6431
|
+
name: "last_update_epoch",
|
|
6432
|
+
docs: [
|
|
6433
|
+
"The last epoch when the bond was updated"
|
|
6434
|
+
],
|
|
6435
|
+
type: "u64"
|
|
6311
6436
|
}
|
|
6312
6437
|
]
|
|
6313
6438
|
}
|
|
@@ -6429,6 +6554,20 @@ var NodeWallet = class {
|
|
|
6429
6554
|
// src/utils/web3.ts
|
|
6430
6555
|
init_cjs_shims();
|
|
6431
6556
|
var SOL_DECIMALS = Math.log10(web3_js.LAMPORTS_PER_SOL);
|
|
6557
|
+
function lamportsToSol(lamports) {
|
|
6558
|
+
if (typeof lamports === "number") {
|
|
6559
|
+
return Math.abs(lamports) / web3_js.LAMPORTS_PER_SOL;
|
|
6560
|
+
}
|
|
6561
|
+
let signMultiplier = 1;
|
|
6562
|
+
if (lamports.isNeg()) {
|
|
6563
|
+
signMultiplier = -1;
|
|
6564
|
+
}
|
|
6565
|
+
const absLamports = lamports.abs();
|
|
6566
|
+
const lamportsString = absLamports.toString(10).padStart(10, "0");
|
|
6567
|
+
const splitIndex = lamportsString.length - SOL_DECIMALS;
|
|
6568
|
+
const solString = `${lamportsString.slice(0, splitIndex)}.${lamportsString.slice(splitIndex)}`;
|
|
6569
|
+
return signMultiplier * Number.parseFloat(solString);
|
|
6570
|
+
}
|
|
6432
6571
|
function solToLamports(amount) {
|
|
6433
6572
|
if (Number.isNaN(amount)) {
|
|
6434
6573
|
return new anchor.BN(0);
|
|
@@ -6449,12 +6588,12 @@ function getBondTypeSeed(type) {
|
|
|
6449
6588
|
}
|
|
6450
6589
|
|
|
6451
6590
|
// src/client.ts
|
|
6452
|
-
var
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
return
|
|
6457
|
-
})(
|
|
6591
|
+
var JBondClientEnv = /* @__PURE__ */ ((JBondClientEnv2) => {
|
|
6592
|
+
JBondClientEnv2["DEV"] = "dev";
|
|
6593
|
+
JBondClientEnv2["STAGE"] = "stage";
|
|
6594
|
+
JBondClientEnv2["PROD"] = "prod";
|
|
6595
|
+
return JBondClientEnv2;
|
|
6596
|
+
})(JBondClientEnv || {});
|
|
6458
6597
|
var JBondClient = class _JBondClient {
|
|
6459
6598
|
constructor(provider, options) {
|
|
6460
6599
|
this.provider = provider;
|
|
@@ -6466,6 +6605,12 @@ var JBondClient = class _JBondClient {
|
|
|
6466
6605
|
get history() {
|
|
6467
6606
|
return new HistoryManager(this);
|
|
6468
6607
|
}
|
|
6608
|
+
/**
|
|
6609
|
+
* Creates a local instance of `JBondClient` for development and testing.
|
|
6610
|
+
*/
|
|
6611
|
+
static local(options) {
|
|
6612
|
+
return new _JBondClient(anchor.AnchorProvider.local(), options);
|
|
6613
|
+
}
|
|
6469
6614
|
/**
|
|
6470
6615
|
* Creates an instance of `JBondClient` using a provided connection and wallet.
|
|
6471
6616
|
*/
|
|
@@ -6577,7 +6722,7 @@ var JBondClient = class _JBondClient {
|
|
|
6577
6722
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6578
6723
|
}
|
|
6579
6724
|
/**
|
|
6580
|
-
* Claim compensation
|
|
6725
|
+
* Claim compensation for a validator
|
|
6581
6726
|
*/
|
|
6582
6727
|
async claimCompensation(props) {
|
|
6583
6728
|
const ix = await this.getClaimIx(props);
|
|
@@ -6838,6 +6983,35 @@ var JBondClient = class _JBondClient {
|
|
|
6838
6983
|
});
|
|
6839
6984
|
return this.program.methods.bondClaim(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
6840
6985
|
}
|
|
6986
|
+
/**
|
|
6987
|
+
* Build claim all compensations instructions
|
|
6988
|
+
*/
|
|
6989
|
+
async getClaimAllCompensationsIxs(props) {
|
|
6990
|
+
const ixs = [];
|
|
6991
|
+
const validatorBondBalances = await this.getBondStateValidatorBondBalances(
|
|
6992
|
+
props.bondType,
|
|
6993
|
+
props.name
|
|
6994
|
+
);
|
|
6995
|
+
for (const bond_balance of validatorBondBalances) {
|
|
6996
|
+
const amountToClaim = lamportsToSol(bond_balance.balance);
|
|
6997
|
+
if (amountToClaim <= 0) {
|
|
6998
|
+
this.debug("No balance to claim for validator:", bond_balance.voteAccount.toBase58());
|
|
6999
|
+
continue;
|
|
7000
|
+
}
|
|
7001
|
+
this.debug("Amount to claim:", amountToClaim);
|
|
7002
|
+
const ix = await this.getClaimIx({
|
|
7003
|
+
bondType: props.bondType,
|
|
7004
|
+
name: props.name,
|
|
7005
|
+
amount: amountToClaim,
|
|
7006
|
+
collateralType: props.collateralType,
|
|
7007
|
+
reserve: props.reserve,
|
|
7008
|
+
authority: props.authority,
|
|
7009
|
+
voteAccount: bond_balance.voteAccount
|
|
7010
|
+
});
|
|
7011
|
+
ixs.push(ix);
|
|
7012
|
+
}
|
|
7013
|
+
return ixs;
|
|
7014
|
+
}
|
|
6841
7015
|
/**
|
|
6842
7016
|
* Build set withdraw authority instruction
|
|
6843
7017
|
*/
|
|
@@ -6866,6 +7040,82 @@ var JBondClient = class _JBondClient {
|
|
|
6866
7040
|
const authority = this.provider.wallet?.publicKey;
|
|
6867
7041
|
return this.program.methods.sessionStart(new import_bn.BN(props.duration)).accountsPartial({ bondState, authority }).instruction();
|
|
6868
7042
|
}
|
|
7043
|
+
async lockFunds(props) {
|
|
7044
|
+
const ix = await this.getLockFundsIx(props);
|
|
7045
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7046
|
+
}
|
|
7047
|
+
async releaseFunds(props) {
|
|
7048
|
+
const ix = await this.getReleaseFundsIx(props);
|
|
7049
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7050
|
+
}
|
|
7051
|
+
/**
|
|
7052
|
+
* Update epoch locks
|
|
7053
|
+
*/
|
|
7054
|
+
async updateEpochLocks(props) {
|
|
7055
|
+
const { bondType, bondName, voteAccount } = props;
|
|
7056
|
+
const ix = await this.getUpdateEpochLocksIx({ bondType, bondName, voteAccount });
|
|
7057
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7058
|
+
}
|
|
7059
|
+
/**
|
|
7060
|
+
* Build update epoch locks instruction
|
|
7061
|
+
*/
|
|
7062
|
+
async getUpdateEpochLocksIx(props) {
|
|
7063
|
+
const { bondType, bondName, voteAccount } = props;
|
|
7064
|
+
const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount);
|
|
7065
|
+
return this.program.methods.bondUpdate().accountsPartial({ validatorBond }).instruction();
|
|
7066
|
+
}
|
|
7067
|
+
async getTestSetLastUpdateEpochIx(props) {
|
|
7068
|
+
const { bondType, bondName, voteAccount, epoch } = props;
|
|
7069
|
+
const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount);
|
|
7070
|
+
return this.program.methods.testSetLastUpdateEpoch(new import_bn.BN(epoch)).accountsPartial({ validatorBond }).instruction();
|
|
7071
|
+
}
|
|
7072
|
+
/**
|
|
7073
|
+
* Build lock funds instruction
|
|
7074
|
+
*/
|
|
7075
|
+
async getLockFundsIx(props) {
|
|
7076
|
+
const { bondType, name, voteAccount, amount, withdrawAuthority } = props;
|
|
7077
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7078
|
+
let collateralType = props.collateralType;
|
|
7079
|
+
if (!collateralType) {
|
|
7080
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
7081
|
+
collateralType = bondState2.collateralType;
|
|
7082
|
+
}
|
|
7083
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7084
|
+
const accounts = {
|
|
7085
|
+
bondState,
|
|
7086
|
+
validatorBond,
|
|
7087
|
+
payer: withdrawAuthority,
|
|
7088
|
+
bondTokenAccount: null
|
|
7089
|
+
};
|
|
7090
|
+
matchVariant(collateralType, {
|
|
7091
|
+
native: () => {
|
|
7092
|
+
},
|
|
7093
|
+
token: (mint) => {
|
|
7094
|
+
const bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7095
|
+
accounts.bondTokenAccount = bondTokenAccount;
|
|
7096
|
+
}
|
|
7097
|
+
});
|
|
7098
|
+
return this.program.methods.bondLockFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7099
|
+
}
|
|
7100
|
+
/**
|
|
7101
|
+
* Build release funds instruction
|
|
7102
|
+
*/
|
|
7103
|
+
async getReleaseFundsIx(props) {
|
|
7104
|
+
const { bondType, name, voteAccount, amount, withdrawAuthority } = props;
|
|
7105
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7106
|
+
const accounts = {
|
|
7107
|
+
validatorBond,
|
|
7108
|
+
payer: withdrawAuthority
|
|
7109
|
+
};
|
|
7110
|
+
return this.program.methods.bondReleaseFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7111
|
+
}
|
|
7112
|
+
/**
|
|
7113
|
+
* Get available collateral for withdrawal (taking into account locked funds)
|
|
7114
|
+
*/
|
|
7115
|
+
async getAvailableCollateral(bondType, bondName, voteAccount) {
|
|
7116
|
+
const validatorBond = await this.getValidatorBond(bondType, bondName, voteAccount);
|
|
7117
|
+
return await this.getValidatorBondBalance(bondType, bondName, voteAccount) - validatorBond.currentEpochLocked.toNumber();
|
|
7118
|
+
}
|
|
6869
7119
|
/**
|
|
6870
7120
|
* Get all bond states with total collected collateral
|
|
6871
7121
|
*/
|
|
@@ -6923,8 +7173,8 @@ var JBondClient = class _JBondClient {
|
|
|
6923
7173
|
if (!accountInfo) {
|
|
6924
7174
|
return 0;
|
|
6925
7175
|
}
|
|
6926
|
-
const {
|
|
6927
|
-
const rentExempt = await this.
|
|
7176
|
+
const { lamports } = accountInfo;
|
|
7177
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
6928
7178
|
return Math.max(0, lamports - rentExempt);
|
|
6929
7179
|
},
|
|
6930
7180
|
token: async (mint) => {
|
|
@@ -6938,12 +7188,13 @@ var JBondClient = class _JBondClient {
|
|
|
6938
7188
|
}
|
|
6939
7189
|
});
|
|
6940
7190
|
}
|
|
6941
|
-
|
|
6942
|
-
* Get total collected collateral for a bond state
|
|
6943
|
-
*/
|
|
6944
|
-
async getBondStateTotalCollected(bondType, bondName, votes) {
|
|
7191
|
+
async getBondStateValidatorBondBalances(bondType, bondName) {
|
|
6945
7192
|
const bondState = await this.getBondState(bondType, bondName);
|
|
6946
7193
|
const collateralType = bondState.collateralType;
|
|
7194
|
+
const validatorBonds = await this.getValidatorBondsForState(bondType, bondName);
|
|
7195
|
+
if (!validatorBonds.length) {
|
|
7196
|
+
return [];
|
|
7197
|
+
}
|
|
6947
7198
|
const chunk = (arr, n = 100) => {
|
|
6948
7199
|
const res = [];
|
|
6949
7200
|
for (let i = 0; i < arr.length; i += n) {
|
|
@@ -6953,54 +7204,53 @@ var JBondClient = class _JBondClient {
|
|
|
6953
7204
|
};
|
|
6954
7205
|
return await matchVariant(collateralType, {
|
|
6955
7206
|
native: async () => {
|
|
6956
|
-
const addresses =
|
|
6957
|
-
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
6958
|
-
return address;
|
|
6959
|
-
});
|
|
7207
|
+
const addresses = validatorBonds.map((vb) => vb.publicKey);
|
|
6960
7208
|
const accountInfos = await this.connection.getMultipleAccountsInfo(addresses);
|
|
6961
|
-
const
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
const { lamports } = accountInfo;
|
|
6967
|
-
return lamports;
|
|
6968
|
-
})
|
|
6969
|
-
);
|
|
6970
|
-
return balances.reduce((sum, v) => sum + v, 0);
|
|
7209
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
7210
|
+
return validatorBonds.map((vb, idx) => ({
|
|
7211
|
+
voteAccount: vb.voteAccount,
|
|
7212
|
+
balance: Math.max(0, (accountInfos[idx]?.lamports ?? 0) - rentExempt)
|
|
7213
|
+
}));
|
|
6971
7214
|
},
|
|
6972
7215
|
token: async (mint) => {
|
|
6973
|
-
const
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
});
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
for (const part of chunk(tokenAccounts, 100)) {
|
|
6982
|
-
const infos = await this.connection.getMultipleAccountsInfo(part).catch(() => []);
|
|
6983
|
-
for (let i = 0; i < infos.length; i++) {
|
|
7216
|
+
const items = validatorBonds.map((vb) => ({
|
|
7217
|
+
voteAccount: vb.voteAccount,
|
|
7218
|
+
tokenAccount: splToken.getAssociatedTokenAddressSync(mint, vb.publicKey, true)
|
|
7219
|
+
}));
|
|
7220
|
+
const balances = [];
|
|
7221
|
+
for (const part of chunk(items, 100)) {
|
|
7222
|
+
const infos = await this.connection.getMultipleAccountsInfo(part.map((i) => i.tokenAccount)).catch(() => []);
|
|
7223
|
+
for (let i = 0; i < part.length; i++) {
|
|
6984
7224
|
const info = infos[i];
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
if (info.data.length !== splToken.ACCOUNT_SIZE) {
|
|
7225
|
+
const voteAccount = part[i].voteAccount;
|
|
7226
|
+
if (!info || info.data.length !== splToken.ACCOUNT_SIZE) {
|
|
7227
|
+
balances.push({ voteAccount, balance: 0 });
|
|
6989
7228
|
continue;
|
|
6990
7229
|
}
|
|
6991
7230
|
try {
|
|
6992
7231
|
const acc = splToken.AccountLayout.decode(info.data);
|
|
6993
7232
|
const raw = BigInt(acc.amount.toString());
|
|
6994
|
-
|
|
7233
|
+
const asNumber = Number(raw);
|
|
7234
|
+
balances.push({
|
|
7235
|
+
voteAccount,
|
|
7236
|
+
balance: Number.isFinite(asNumber) ? asNumber : Number.MAX_SAFE_INTEGER
|
|
7237
|
+
});
|
|
6995
7238
|
} catch {
|
|
7239
|
+
balances.push({ voteAccount, balance: 0 });
|
|
6996
7240
|
}
|
|
6997
7241
|
}
|
|
6998
7242
|
}
|
|
6999
|
-
|
|
7000
|
-
return Number.isFinite(asNumber) ? asNumber : Number.MAX_SAFE_INTEGER;
|
|
7243
|
+
return balances;
|
|
7001
7244
|
}
|
|
7002
7245
|
});
|
|
7003
7246
|
}
|
|
7247
|
+
/**
|
|
7248
|
+
* Get total collected collateral for a bond state
|
|
7249
|
+
*/
|
|
7250
|
+
async getBondStateTotalCollected(bondType, bondName) {
|
|
7251
|
+
const allBalances = await this.getBondStateValidatorBondBalances(bondType, bondName);
|
|
7252
|
+
return allBalances.reduce((sum, vb) => sum + vb.balance, 0);
|
|
7253
|
+
}
|
|
7004
7254
|
/**
|
|
7005
7255
|
* Get bond state stats
|
|
7006
7256
|
* @param state
|
|
@@ -7008,21 +7258,25 @@ var JBondClient = class _JBondClient {
|
|
|
7008
7258
|
*/
|
|
7009
7259
|
async getBondStateStats(state) {
|
|
7010
7260
|
const bondType = anchorToBondType(state.bondType);
|
|
7011
|
-
const validatorBonds = await this.getBondValidatorStates(bondType, state.name);
|
|
7012
7261
|
const totalCollected = await this.getBondStateTotalCollected(
|
|
7013
7262
|
bondType,
|
|
7014
|
-
state.name
|
|
7015
|
-
validatorBonds.map((vb) => vb.voteAccount)
|
|
7263
|
+
state.name
|
|
7016
7264
|
);
|
|
7017
7265
|
return {
|
|
7018
7266
|
totalCollected,
|
|
7019
7267
|
status: this.getBondStateSessionStatus(state)
|
|
7020
7268
|
};
|
|
7021
7269
|
}
|
|
7270
|
+
/**
|
|
7271
|
+
* Get validator bond rent exempt amount
|
|
7272
|
+
*/
|
|
7273
|
+
validatorBondRentExempt = async () => {
|
|
7274
|
+
return this.connection.getMinimumBalanceForRentExemption(this.program.account.validatorBond.size);
|
|
7275
|
+
};
|
|
7022
7276
|
/**
|
|
7023
7277
|
* Get all validator bonds for a given bond state
|
|
7024
7278
|
*/
|
|
7025
|
-
async
|
|
7279
|
+
async getValidatorBondsForState(bondType, bondName) {
|
|
7026
7280
|
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
7027
7281
|
const accounts = await this.program.account.validatorBond.all([
|
|
7028
7282
|
{
|
|
@@ -7066,13 +7320,13 @@ buffer/index.js:
|
|
|
7066
7320
|
*/
|
|
7067
7321
|
|
|
7068
7322
|
exports.BOND_STATE_SEED = BOND_STATE_SEED;
|
|
7069
|
-
exports.BondClientEnv = BondClientEnv;
|
|
7070
7323
|
exports.BondTransactionType = BondTransactionType;
|
|
7071
7324
|
exports.BondType = BondType;
|
|
7072
7325
|
exports.CROWDFUNDING_BOND_SEED = CROWDFUNDING_BOND_SEED;
|
|
7073
7326
|
exports.ENV_PROGRAM_ID = ENV_PROGRAM_ID;
|
|
7074
7327
|
exports.GLOBAL_STATE_SEED = GLOBAL_STATE_SEED;
|
|
7075
7328
|
exports.JBondClient = JBondClient;
|
|
7329
|
+
exports.JBondClientEnv = JBondClientEnv;
|
|
7076
7330
|
exports.NodeWallet = NodeWallet;
|
|
7077
7331
|
exports.STANDARD_BOND_SEED = STANDARD_BOND_SEED;
|
|
7078
7332
|
exports.SessionStatus = SessionStatus;
|