@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.mjs
CHANGED
|
@@ -4735,7 +4735,7 @@ function slotToEpoch(slot, cluster) {
|
|
|
4735
4735
|
|
|
4736
4736
|
// src/idl/jbond.json
|
|
4737
4737
|
var jbond_default = {
|
|
4738
|
-
address: "
|
|
4738
|
+
address: "Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1",
|
|
4739
4739
|
metadata: {
|
|
4740
4740
|
name: "jbond",
|
|
4741
4741
|
version: "0.2.1",
|
|
@@ -4984,6 +4984,50 @@ var jbond_default = {
|
|
|
4984
4984
|
}
|
|
4985
4985
|
]
|
|
4986
4986
|
},
|
|
4987
|
+
{
|
|
4988
|
+
name: "bond_lock_funds",
|
|
4989
|
+
docs: [
|
|
4990
|
+
"Locks funds for both the current and upcoming epoch.",
|
|
4991
|
+
"Moves collateral from available to locked state, making it unavailable for withdrawal for the current and next epoch.",
|
|
4992
|
+
"# Errors",
|
|
4993
|
+
"Fails if the validator is not active, or if there are insufficient available funds."
|
|
4994
|
+
],
|
|
4995
|
+
discriminator: [
|
|
4996
|
+
117,
|
|
4997
|
+
166,
|
|
4998
|
+
195,
|
|
4999
|
+
99,
|
|
5000
|
+
103,
|
|
5001
|
+
45,
|
|
5002
|
+
195,
|
|
5003
|
+
2
|
|
5004
|
+
],
|
|
5005
|
+
accounts: [
|
|
5006
|
+
{
|
|
5007
|
+
name: "bond_state",
|
|
5008
|
+
writable: true
|
|
5009
|
+
},
|
|
5010
|
+
{
|
|
5011
|
+
name: "validator_bond",
|
|
5012
|
+
writable: true
|
|
5013
|
+
},
|
|
5014
|
+
{
|
|
5015
|
+
name: "bond_token_account",
|
|
5016
|
+
optional: true
|
|
5017
|
+
},
|
|
5018
|
+
{
|
|
5019
|
+
name: "payer",
|
|
5020
|
+
writable: true,
|
|
5021
|
+
signer: true
|
|
5022
|
+
}
|
|
5023
|
+
],
|
|
5024
|
+
args: [
|
|
5025
|
+
{
|
|
5026
|
+
name: "amount",
|
|
5027
|
+
type: "u64"
|
|
5028
|
+
}
|
|
5029
|
+
]
|
|
5030
|
+
},
|
|
4987
5031
|
{
|
|
4988
5032
|
name: "bond_register",
|
|
4989
5033
|
docs: [
|
|
@@ -5096,6 +5140,42 @@ var jbond_default = {
|
|
|
5096
5140
|
}
|
|
5097
5141
|
]
|
|
5098
5142
|
},
|
|
5143
|
+
{
|
|
5144
|
+
name: "bond_release_funds",
|
|
5145
|
+
docs: [
|
|
5146
|
+
"Releases locked funds after an epoch ends.",
|
|
5147
|
+
"Moves collateral from locked back to available state, allowing withdrawals.",
|
|
5148
|
+
"# Errors",
|
|
5149
|
+
"Fails if the validator is not active, or if there are insufficient locked funds."
|
|
5150
|
+
],
|
|
5151
|
+
discriminator: [
|
|
5152
|
+
184,
|
|
5153
|
+
224,
|
|
5154
|
+
14,
|
|
5155
|
+
24,
|
|
5156
|
+
76,
|
|
5157
|
+
14,
|
|
5158
|
+
226,
|
|
5159
|
+
190
|
|
5160
|
+
],
|
|
5161
|
+
accounts: [
|
|
5162
|
+
{
|
|
5163
|
+
name: "validator_bond",
|
|
5164
|
+
writable: true
|
|
5165
|
+
},
|
|
5166
|
+
{
|
|
5167
|
+
name: "payer",
|
|
5168
|
+
writable: true,
|
|
5169
|
+
signer: true
|
|
5170
|
+
}
|
|
5171
|
+
],
|
|
5172
|
+
args: [
|
|
5173
|
+
{
|
|
5174
|
+
name: "amount",
|
|
5175
|
+
type: "u64"
|
|
5176
|
+
}
|
|
5177
|
+
]
|
|
5178
|
+
},
|
|
5099
5179
|
{
|
|
5100
5180
|
name: "bond_set_withdraw_authority",
|
|
5101
5181
|
docs: [
|
|
@@ -5275,6 +5355,42 @@ var jbond_default = {
|
|
|
5275
5355
|
}
|
|
5276
5356
|
]
|
|
5277
5357
|
},
|
|
5358
|
+
{
|
|
5359
|
+
name: "bond_update",
|
|
5360
|
+
docs: [
|
|
5361
|
+
"Transitions locked funds between epochs for a validator bond.",
|
|
5362
|
+
"",
|
|
5363
|
+
"This function should be called at epoch boundaries to update the bond's",
|
|
5364
|
+
"`last_update_epoch` and move the `next_epoch_locked` amount into",
|
|
5365
|
+
"`current_epoch_locked`. It ensures that the update only occurs once per epoch.",
|
|
5366
|
+
"",
|
|
5367
|
+
"# Errors",
|
|
5368
|
+
"Returns [`BondError::InvalidEpoch`] if called more than once in the same epoch,",
|
|
5369
|
+
"or if the system clock cannot be accessed."
|
|
5370
|
+
],
|
|
5371
|
+
discriminator: [
|
|
5372
|
+
237,
|
|
5373
|
+
102,
|
|
5374
|
+
183,
|
|
5375
|
+
192,
|
|
5376
|
+
94,
|
|
5377
|
+
83,
|
|
5378
|
+
52,
|
|
5379
|
+
82
|
|
5380
|
+
],
|
|
5381
|
+
accounts: [
|
|
5382
|
+
{
|
|
5383
|
+
name: "validator_bond",
|
|
5384
|
+
writable: true
|
|
5385
|
+
},
|
|
5386
|
+
{
|
|
5387
|
+
name: "payer",
|
|
5388
|
+
writable: true,
|
|
5389
|
+
signer: true
|
|
5390
|
+
}
|
|
5391
|
+
],
|
|
5392
|
+
args: []
|
|
5393
|
+
},
|
|
5278
5394
|
{
|
|
5279
5395
|
name: "bond_withdraw",
|
|
5280
5396
|
docs: [
|
|
@@ -5492,80 +5608,6 @@ var jbond_default = {
|
|
|
5492
5608
|
],
|
|
5493
5609
|
args: []
|
|
5494
5610
|
},
|
|
5495
|
-
{
|
|
5496
|
-
name: "migrate_bond",
|
|
5497
|
-
docs: [
|
|
5498
|
-
"Migrates validator bond data from legacy structure to new structure."
|
|
5499
|
-
],
|
|
5500
|
-
discriminator: [
|
|
5501
|
-
107,
|
|
5502
|
-
119,
|
|
5503
|
-
59,
|
|
5504
|
-
110,
|
|
5505
|
-
76,
|
|
5506
|
-
18,
|
|
5507
|
-
37,
|
|
5508
|
-
163
|
|
5509
|
-
],
|
|
5510
|
-
accounts: [
|
|
5511
|
-
{
|
|
5512
|
-
name: "bond_state",
|
|
5513
|
-
writable: true
|
|
5514
|
-
},
|
|
5515
|
-
{
|
|
5516
|
-
name: "legacy_validator_bond",
|
|
5517
|
-
writable: true
|
|
5518
|
-
},
|
|
5519
|
-
{
|
|
5520
|
-
name: "legacy_vote_account"
|
|
5521
|
-
},
|
|
5522
|
-
{
|
|
5523
|
-
name: "validator_bond",
|
|
5524
|
-
writable: true,
|
|
5525
|
-
pda: {
|
|
5526
|
-
seeds: [
|
|
5527
|
-
{
|
|
5528
|
-
kind: "const",
|
|
5529
|
-
value: [
|
|
5530
|
-
118,
|
|
5531
|
-
97,
|
|
5532
|
-
108,
|
|
5533
|
-
105,
|
|
5534
|
-
100,
|
|
5535
|
-
97,
|
|
5536
|
-
116,
|
|
5537
|
-
111,
|
|
5538
|
-
114,
|
|
5539
|
-
95,
|
|
5540
|
-
98,
|
|
5541
|
-
111,
|
|
5542
|
-
110,
|
|
5543
|
-
100
|
|
5544
|
-
]
|
|
5545
|
-
},
|
|
5546
|
-
{
|
|
5547
|
-
kind: "account",
|
|
5548
|
-
path: "bond_state"
|
|
5549
|
-
},
|
|
5550
|
-
{
|
|
5551
|
-
kind: "account",
|
|
5552
|
-
path: "legacy_vote_account"
|
|
5553
|
-
}
|
|
5554
|
-
]
|
|
5555
|
-
}
|
|
5556
|
-
},
|
|
5557
|
-
{
|
|
5558
|
-
name: "creator",
|
|
5559
|
-
writable: true,
|
|
5560
|
-
signer: true
|
|
5561
|
-
},
|
|
5562
|
-
{
|
|
5563
|
-
name: "system_program",
|
|
5564
|
-
address: "11111111111111111111111111111111"
|
|
5565
|
-
}
|
|
5566
|
-
],
|
|
5567
|
-
args: []
|
|
5568
|
-
},
|
|
5569
5611
|
{
|
|
5570
5612
|
name: "session_finish",
|
|
5571
5613
|
docs: [
|
|
@@ -5632,6 +5674,41 @@ var jbond_default = {
|
|
|
5632
5674
|
type: "u64"
|
|
5633
5675
|
}
|
|
5634
5676
|
]
|
|
5677
|
+
},
|
|
5678
|
+
{
|
|
5679
|
+
name: "test_set_last_update_epoch",
|
|
5680
|
+
docs: [
|
|
5681
|
+
"NOTE!: This instruction is for testing purposes only.",
|
|
5682
|
+
"It allows direct manipulation of the validator bond's last epoch update.",
|
|
5683
|
+
"This should not be used in production environments."
|
|
5684
|
+
],
|
|
5685
|
+
discriminator: [
|
|
5686
|
+
215,
|
|
5687
|
+
125,
|
|
5688
|
+
32,
|
|
5689
|
+
8,
|
|
5690
|
+
43,
|
|
5691
|
+
106,
|
|
5692
|
+
194,
|
|
5693
|
+
221
|
|
5694
|
+
],
|
|
5695
|
+
accounts: [
|
|
5696
|
+
{
|
|
5697
|
+
name: "validator_bond",
|
|
5698
|
+
writable: true
|
|
5699
|
+
},
|
|
5700
|
+
{
|
|
5701
|
+
name: "payer",
|
|
5702
|
+
writable: true,
|
|
5703
|
+
signer: true
|
|
5704
|
+
}
|
|
5705
|
+
],
|
|
5706
|
+
args: [
|
|
5707
|
+
{
|
|
5708
|
+
name: "epoch",
|
|
5709
|
+
type: "u64"
|
|
5710
|
+
}
|
|
5711
|
+
]
|
|
5635
5712
|
}
|
|
5636
5713
|
],
|
|
5637
5714
|
accounts: [
|
|
@@ -5875,6 +5952,11 @@ var jbond_default = {
|
|
|
5875
5952
|
code: 6023,
|
|
5876
5953
|
name: "BondNotEnabled",
|
|
5877
5954
|
msg: "Bond is not enabled"
|
|
5955
|
+
},
|
|
5956
|
+
{
|
|
5957
|
+
code: 6024,
|
|
5958
|
+
name: "InvalidEpoch",
|
|
5959
|
+
msg: "Invalid epoch for this operation"
|
|
5878
5960
|
}
|
|
5879
5961
|
],
|
|
5880
5962
|
types: [
|
|
@@ -6257,33 +6339,76 @@ var jbond_default = {
|
|
|
6257
6339
|
fields: [
|
|
6258
6340
|
{
|
|
6259
6341
|
name: "state",
|
|
6342
|
+
docs: [
|
|
6343
|
+
"The bond state address"
|
|
6344
|
+
],
|
|
6260
6345
|
type: "pubkey"
|
|
6261
6346
|
},
|
|
6262
6347
|
{
|
|
6263
6348
|
name: "identity",
|
|
6349
|
+
docs: [
|
|
6350
|
+
"Validator identity pubkey"
|
|
6351
|
+
],
|
|
6264
6352
|
type: "pubkey"
|
|
6265
6353
|
},
|
|
6266
6354
|
{
|
|
6267
6355
|
name: "vote_account",
|
|
6356
|
+
docs: [
|
|
6357
|
+
"Validator vote account pubkey"
|
|
6358
|
+
],
|
|
6268
6359
|
type: "pubkey"
|
|
6269
6360
|
},
|
|
6270
6361
|
{
|
|
6271
6362
|
name: "creator",
|
|
6363
|
+
docs: [
|
|
6364
|
+
"The bond creator pubkey"
|
|
6365
|
+
],
|
|
6272
6366
|
type: "pubkey"
|
|
6273
6367
|
},
|
|
6274
6368
|
{
|
|
6275
6369
|
name: "withdrawal_authority",
|
|
6370
|
+
docs: [
|
|
6371
|
+
"Optional withdrawal authority pubkey (if set, can withdraw on behalf of the validator,",
|
|
6372
|
+
"otherwise only identity can withdraw)"
|
|
6373
|
+
],
|
|
6276
6374
|
type: {
|
|
6277
6375
|
option: "pubkey"
|
|
6278
6376
|
}
|
|
6279
6377
|
},
|
|
6280
6378
|
{
|
|
6281
6379
|
name: "created_at",
|
|
6380
|
+
docs: [
|
|
6381
|
+
"Bond creation timestamp"
|
|
6382
|
+
],
|
|
6282
6383
|
type: "i64"
|
|
6283
6384
|
},
|
|
6284
6385
|
{
|
|
6285
6386
|
name: "bump",
|
|
6387
|
+
docs: [
|
|
6388
|
+
"Bump for the PDA"
|
|
6389
|
+
],
|
|
6286
6390
|
type: "u8"
|
|
6391
|
+
},
|
|
6392
|
+
{
|
|
6393
|
+
name: "next_epoch_locked",
|
|
6394
|
+
docs: [
|
|
6395
|
+
"Amount of collateral locked for the next epoch"
|
|
6396
|
+
],
|
|
6397
|
+
type: "u64"
|
|
6398
|
+
},
|
|
6399
|
+
{
|
|
6400
|
+
name: "current_epoch_locked",
|
|
6401
|
+
docs: [
|
|
6402
|
+
"Amount of collateral locked for the current epoch"
|
|
6403
|
+
],
|
|
6404
|
+
type: "u64"
|
|
6405
|
+
},
|
|
6406
|
+
{
|
|
6407
|
+
name: "last_update_epoch",
|
|
6408
|
+
docs: [
|
|
6409
|
+
"The last epoch when the bond was updated"
|
|
6410
|
+
],
|
|
6411
|
+
type: "u64"
|
|
6287
6412
|
}
|
|
6288
6413
|
]
|
|
6289
6414
|
}
|
|
@@ -6397,6 +6522,20 @@ var NodeWallet = class {
|
|
|
6397
6522
|
}
|
|
6398
6523
|
};
|
|
6399
6524
|
var SOL_DECIMALS = Math.log10(LAMPORTS_PER_SOL);
|
|
6525
|
+
function lamportsToSol(lamports) {
|
|
6526
|
+
if (typeof lamports === "number") {
|
|
6527
|
+
return Math.abs(lamports) / LAMPORTS_PER_SOL;
|
|
6528
|
+
}
|
|
6529
|
+
let signMultiplier = 1;
|
|
6530
|
+
if (lamports.isNeg()) {
|
|
6531
|
+
signMultiplier = -1;
|
|
6532
|
+
}
|
|
6533
|
+
const absLamports = lamports.abs();
|
|
6534
|
+
const lamportsString = absLamports.toString(10).padStart(10, "0");
|
|
6535
|
+
const splitIndex = lamportsString.length - SOL_DECIMALS;
|
|
6536
|
+
const solString = `${lamportsString.slice(0, splitIndex)}.${lamportsString.slice(splitIndex)}`;
|
|
6537
|
+
return signMultiplier * Number.parseFloat(solString);
|
|
6538
|
+
}
|
|
6400
6539
|
function solToLamports(amount) {
|
|
6401
6540
|
if (Number.isNaN(amount)) {
|
|
6402
6541
|
return new BN(0);
|
|
@@ -6417,12 +6556,12 @@ function getBondTypeSeed(type) {
|
|
|
6417
6556
|
}
|
|
6418
6557
|
|
|
6419
6558
|
// src/client.ts
|
|
6420
|
-
var
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
return
|
|
6425
|
-
})(
|
|
6559
|
+
var JBondClientEnv = /* @__PURE__ */ ((JBondClientEnv2) => {
|
|
6560
|
+
JBondClientEnv2["DEV"] = "dev";
|
|
6561
|
+
JBondClientEnv2["STAGE"] = "stage";
|
|
6562
|
+
JBondClientEnv2["PROD"] = "prod";
|
|
6563
|
+
return JBondClientEnv2;
|
|
6564
|
+
})(JBondClientEnv || {});
|
|
6426
6565
|
var JBondClient = class _JBondClient {
|
|
6427
6566
|
constructor(provider, options) {
|
|
6428
6567
|
this.provider = provider;
|
|
@@ -6434,6 +6573,12 @@ var JBondClient = class _JBondClient {
|
|
|
6434
6573
|
get history() {
|
|
6435
6574
|
return new HistoryManager(this);
|
|
6436
6575
|
}
|
|
6576
|
+
/**
|
|
6577
|
+
* Creates a local instance of `JBondClient` for development and testing.
|
|
6578
|
+
*/
|
|
6579
|
+
static local(options) {
|
|
6580
|
+
return new _JBondClient(AnchorProvider.local(), options);
|
|
6581
|
+
}
|
|
6437
6582
|
/**
|
|
6438
6583
|
* Creates an instance of `JBondClient` using a provided connection and wallet.
|
|
6439
6584
|
*/
|
|
@@ -6545,7 +6690,7 @@ var JBondClient = class _JBondClient {
|
|
|
6545
6690
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6546
6691
|
}
|
|
6547
6692
|
/**
|
|
6548
|
-
* Claim compensation
|
|
6693
|
+
* Claim compensation for a validator
|
|
6549
6694
|
*/
|
|
6550
6695
|
async claimCompensation(props) {
|
|
6551
6696
|
const ix = await this.getClaimIx(props);
|
|
@@ -6806,6 +6951,35 @@ var JBondClient = class _JBondClient {
|
|
|
6806
6951
|
});
|
|
6807
6952
|
return this.program.methods.bondClaim(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
6808
6953
|
}
|
|
6954
|
+
/**
|
|
6955
|
+
* Build claim all compensations instructions
|
|
6956
|
+
*/
|
|
6957
|
+
async getClaimAllCompensationsIxs(props) {
|
|
6958
|
+
const ixs = [];
|
|
6959
|
+
const validatorBondBalances = await this.getBondStateValidatorBondBalances(
|
|
6960
|
+
props.bondType,
|
|
6961
|
+
props.name
|
|
6962
|
+
);
|
|
6963
|
+
for (const bond_balance of validatorBondBalances) {
|
|
6964
|
+
const amountToClaim = lamportsToSol(bond_balance.balance);
|
|
6965
|
+
if (amountToClaim <= 0) {
|
|
6966
|
+
this.debug("No balance to claim for validator:", bond_balance.voteAccount.toBase58());
|
|
6967
|
+
continue;
|
|
6968
|
+
}
|
|
6969
|
+
this.debug("Amount to claim:", amountToClaim);
|
|
6970
|
+
const ix = await this.getClaimIx({
|
|
6971
|
+
bondType: props.bondType,
|
|
6972
|
+
name: props.name,
|
|
6973
|
+
amount: amountToClaim,
|
|
6974
|
+
collateralType: props.collateralType,
|
|
6975
|
+
reserve: props.reserve,
|
|
6976
|
+
authority: props.authority,
|
|
6977
|
+
voteAccount: bond_balance.voteAccount
|
|
6978
|
+
});
|
|
6979
|
+
ixs.push(ix);
|
|
6980
|
+
}
|
|
6981
|
+
return ixs;
|
|
6982
|
+
}
|
|
6809
6983
|
/**
|
|
6810
6984
|
* Build set withdraw authority instruction
|
|
6811
6985
|
*/
|
|
@@ -6834,6 +7008,82 @@ var JBondClient = class _JBondClient {
|
|
|
6834
7008
|
const authority = this.provider.wallet?.publicKey;
|
|
6835
7009
|
return this.program.methods.sessionStart(new import_bn.BN(props.duration)).accountsPartial({ bondState, authority }).instruction();
|
|
6836
7010
|
}
|
|
7011
|
+
async lockFunds(props) {
|
|
7012
|
+
const ix = await this.getLockFundsIx(props);
|
|
7013
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7014
|
+
}
|
|
7015
|
+
async releaseFunds(props) {
|
|
7016
|
+
const ix = await this.getReleaseFundsIx(props);
|
|
7017
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7018
|
+
}
|
|
7019
|
+
/**
|
|
7020
|
+
* Update epoch locks
|
|
7021
|
+
*/
|
|
7022
|
+
async updateEpochLocks(props) {
|
|
7023
|
+
const { bondType, bondName, voteAccount } = props;
|
|
7024
|
+
const ix = await this.getUpdateEpochLocksIx({ bondType, bondName, voteAccount });
|
|
7025
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7026
|
+
}
|
|
7027
|
+
/**
|
|
7028
|
+
* Build update epoch locks instruction
|
|
7029
|
+
*/
|
|
7030
|
+
async getUpdateEpochLocksIx(props) {
|
|
7031
|
+
const { bondType, bondName, voteAccount } = props;
|
|
7032
|
+
const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount);
|
|
7033
|
+
return this.program.methods.bondUpdate().accountsPartial({ validatorBond }).instruction();
|
|
7034
|
+
}
|
|
7035
|
+
async getTestSetLastUpdateEpochIx(props) {
|
|
7036
|
+
const { bondType, bondName, voteAccount, epoch } = props;
|
|
7037
|
+
const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount);
|
|
7038
|
+
return this.program.methods.testSetLastUpdateEpoch(new import_bn.BN(epoch)).accountsPartial({ validatorBond }).instruction();
|
|
7039
|
+
}
|
|
7040
|
+
/**
|
|
7041
|
+
* Build lock funds instruction
|
|
7042
|
+
*/
|
|
7043
|
+
async getLockFundsIx(props) {
|
|
7044
|
+
const { bondType, name, voteAccount, amount, withdrawAuthority } = props;
|
|
7045
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7046
|
+
let collateralType = props.collateralType;
|
|
7047
|
+
if (!collateralType) {
|
|
7048
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
7049
|
+
collateralType = bondState2.collateralType;
|
|
7050
|
+
}
|
|
7051
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7052
|
+
const accounts = {
|
|
7053
|
+
bondState,
|
|
7054
|
+
validatorBond,
|
|
7055
|
+
payer: withdrawAuthority,
|
|
7056
|
+
bondTokenAccount: null
|
|
7057
|
+
};
|
|
7058
|
+
matchVariant(collateralType, {
|
|
7059
|
+
native: () => {
|
|
7060
|
+
},
|
|
7061
|
+
token: (mint) => {
|
|
7062
|
+
const bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7063
|
+
accounts.bondTokenAccount = bondTokenAccount;
|
|
7064
|
+
}
|
|
7065
|
+
});
|
|
7066
|
+
return this.program.methods.bondLockFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7067
|
+
}
|
|
7068
|
+
/**
|
|
7069
|
+
* Build release funds instruction
|
|
7070
|
+
*/
|
|
7071
|
+
async getReleaseFundsIx(props) {
|
|
7072
|
+
const { bondType, name, voteAccount, amount, withdrawAuthority } = props;
|
|
7073
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7074
|
+
const accounts = {
|
|
7075
|
+
validatorBond,
|
|
7076
|
+
payer: withdrawAuthority
|
|
7077
|
+
};
|
|
7078
|
+
return this.program.methods.bondReleaseFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7079
|
+
}
|
|
7080
|
+
/**
|
|
7081
|
+
* Get available collateral for withdrawal (taking into account locked funds)
|
|
7082
|
+
*/
|
|
7083
|
+
async getAvailableCollateral(bondType, bondName, voteAccount) {
|
|
7084
|
+
const validatorBond = await this.getValidatorBond(bondType, bondName, voteAccount);
|
|
7085
|
+
return await this.getValidatorBondBalance(bondType, bondName, voteAccount) - validatorBond.currentEpochLocked.toNumber();
|
|
7086
|
+
}
|
|
6837
7087
|
/**
|
|
6838
7088
|
* Get all bond states with total collected collateral
|
|
6839
7089
|
*/
|
|
@@ -6891,8 +7141,8 @@ var JBondClient = class _JBondClient {
|
|
|
6891
7141
|
if (!accountInfo) {
|
|
6892
7142
|
return 0;
|
|
6893
7143
|
}
|
|
6894
|
-
const {
|
|
6895
|
-
const rentExempt = await this.
|
|
7144
|
+
const { lamports } = accountInfo;
|
|
7145
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
6896
7146
|
return Math.max(0, lamports - rentExempt);
|
|
6897
7147
|
},
|
|
6898
7148
|
token: async (mint) => {
|
|
@@ -6906,12 +7156,13 @@ var JBondClient = class _JBondClient {
|
|
|
6906
7156
|
}
|
|
6907
7157
|
});
|
|
6908
7158
|
}
|
|
6909
|
-
|
|
6910
|
-
* Get total collected collateral for a bond state
|
|
6911
|
-
*/
|
|
6912
|
-
async getBondStateTotalCollected(bondType, bondName, votes) {
|
|
7159
|
+
async getBondStateValidatorBondBalances(bondType, bondName) {
|
|
6913
7160
|
const bondState = await this.getBondState(bondType, bondName);
|
|
6914
7161
|
const collateralType = bondState.collateralType;
|
|
7162
|
+
const validatorBonds = await this.getValidatorBondsForState(bondType, bondName);
|
|
7163
|
+
if (!validatorBonds.length) {
|
|
7164
|
+
return [];
|
|
7165
|
+
}
|
|
6915
7166
|
const chunk = (arr, n = 100) => {
|
|
6916
7167
|
const res = [];
|
|
6917
7168
|
for (let i = 0; i < arr.length; i += n) {
|
|
@@ -6921,54 +7172,53 @@ var JBondClient = class _JBondClient {
|
|
|
6921
7172
|
};
|
|
6922
7173
|
return await matchVariant(collateralType, {
|
|
6923
7174
|
native: async () => {
|
|
6924
|
-
const addresses =
|
|
6925
|
-
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
6926
|
-
return address;
|
|
6927
|
-
});
|
|
7175
|
+
const addresses = validatorBonds.map((vb) => vb.publicKey);
|
|
6928
7176
|
const accountInfos = await this.connection.getMultipleAccountsInfo(addresses);
|
|
6929
|
-
const
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
const { lamports } = accountInfo;
|
|
6935
|
-
return lamports;
|
|
6936
|
-
})
|
|
6937
|
-
);
|
|
6938
|
-
return balances.reduce((sum, v) => sum + v, 0);
|
|
7177
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
7178
|
+
return validatorBonds.map((vb, idx) => ({
|
|
7179
|
+
voteAccount: vb.voteAccount,
|
|
7180
|
+
balance: Math.max(0, (accountInfos[idx]?.lamports ?? 0) - rentExempt)
|
|
7181
|
+
}));
|
|
6939
7182
|
},
|
|
6940
7183
|
token: async (mint) => {
|
|
6941
|
-
const
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
});
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
for (const part of chunk(tokenAccounts, 100)) {
|
|
6950
|
-
const infos = await this.connection.getMultipleAccountsInfo(part).catch(() => []);
|
|
6951
|
-
for (let i = 0; i < infos.length; i++) {
|
|
7184
|
+
const items = validatorBonds.map((vb) => ({
|
|
7185
|
+
voteAccount: vb.voteAccount,
|
|
7186
|
+
tokenAccount: getAssociatedTokenAddressSync(mint, vb.publicKey, true)
|
|
7187
|
+
}));
|
|
7188
|
+
const balances = [];
|
|
7189
|
+
for (const part of chunk(items, 100)) {
|
|
7190
|
+
const infos = await this.connection.getMultipleAccountsInfo(part.map((i) => i.tokenAccount)).catch(() => []);
|
|
7191
|
+
for (let i = 0; i < part.length; i++) {
|
|
6952
7192
|
const info = infos[i];
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
if (info.data.length !== ACCOUNT_SIZE) {
|
|
7193
|
+
const voteAccount = part[i].voteAccount;
|
|
7194
|
+
if (!info || info.data.length !== ACCOUNT_SIZE) {
|
|
7195
|
+
balances.push({ voteAccount, balance: 0 });
|
|
6957
7196
|
continue;
|
|
6958
7197
|
}
|
|
6959
7198
|
try {
|
|
6960
7199
|
const acc = AccountLayout.decode(info.data);
|
|
6961
7200
|
const raw = BigInt(acc.amount.toString());
|
|
6962
|
-
|
|
7201
|
+
const asNumber = Number(raw);
|
|
7202
|
+
balances.push({
|
|
7203
|
+
voteAccount,
|
|
7204
|
+
balance: Number.isFinite(asNumber) ? asNumber : Number.MAX_SAFE_INTEGER
|
|
7205
|
+
});
|
|
6963
7206
|
} catch {
|
|
7207
|
+
balances.push({ voteAccount, balance: 0 });
|
|
6964
7208
|
}
|
|
6965
7209
|
}
|
|
6966
7210
|
}
|
|
6967
|
-
|
|
6968
|
-
return Number.isFinite(asNumber) ? asNumber : Number.MAX_SAFE_INTEGER;
|
|
7211
|
+
return balances;
|
|
6969
7212
|
}
|
|
6970
7213
|
});
|
|
6971
7214
|
}
|
|
7215
|
+
/**
|
|
7216
|
+
* Get total collected collateral for a bond state
|
|
7217
|
+
*/
|
|
7218
|
+
async getBondStateTotalCollected(bondType, bondName) {
|
|
7219
|
+
const allBalances = await this.getBondStateValidatorBondBalances(bondType, bondName);
|
|
7220
|
+
return allBalances.reduce((sum, vb) => sum + vb.balance, 0);
|
|
7221
|
+
}
|
|
6972
7222
|
/**
|
|
6973
7223
|
* Get bond state stats
|
|
6974
7224
|
* @param state
|
|
@@ -6976,21 +7226,25 @@ var JBondClient = class _JBondClient {
|
|
|
6976
7226
|
*/
|
|
6977
7227
|
async getBondStateStats(state) {
|
|
6978
7228
|
const bondType = anchorToBondType(state.bondType);
|
|
6979
|
-
const validatorBonds = await this.getBondValidatorStates(bondType, state.name);
|
|
6980
7229
|
const totalCollected = await this.getBondStateTotalCollected(
|
|
6981
7230
|
bondType,
|
|
6982
|
-
state.name
|
|
6983
|
-
validatorBonds.map((vb) => vb.voteAccount)
|
|
7231
|
+
state.name
|
|
6984
7232
|
);
|
|
6985
7233
|
return {
|
|
6986
7234
|
totalCollected,
|
|
6987
7235
|
status: this.getBondStateSessionStatus(state)
|
|
6988
7236
|
};
|
|
6989
7237
|
}
|
|
7238
|
+
/**
|
|
7239
|
+
* Get validator bond rent exempt amount
|
|
7240
|
+
*/
|
|
7241
|
+
validatorBondRentExempt = async () => {
|
|
7242
|
+
return this.connection.getMinimumBalanceForRentExemption(this.program.account.validatorBond.size);
|
|
7243
|
+
};
|
|
6990
7244
|
/**
|
|
6991
7245
|
* Get all validator bonds for a given bond state
|
|
6992
7246
|
*/
|
|
6993
|
-
async
|
|
7247
|
+
async getValidatorBondsForState(bondType, bondName) {
|
|
6994
7248
|
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
6995
7249
|
const accounts = await this.program.account.validatorBond.all([
|
|
6996
7250
|
{
|
|
@@ -7033,6 +7287,6 @@ buffer/index.js:
|
|
|
7033
7287
|
*)
|
|
7034
7288
|
*/
|
|
7035
7289
|
|
|
7036
|
-
export { BOND_STATE_SEED,
|
|
7290
|
+
export { BOND_STATE_SEED, BondTransactionType, BondType, CROWDFUNDING_BOND_SEED, ENV_PROGRAM_ID, GLOBAL_STATE_SEED, JBondClient, JBondClientEnv, NodeWallet, STANDARD_BOND_SEED, SessionStatus, VALIDATOR_BOND_SEED };
|
|
7037
7291
|
//# sourceMappingURL=index.mjs.map
|
|
7038
7292
|
//# sourceMappingURL=index.mjs.map
|