@jpool/bond-sdk 0.11.8 → 0.11.9
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 +1527 -799
- package/dist/index.d.ts +1527 -799
- package/dist/index.js +1270 -306
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1270 -314
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { utils,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { utils, AnchorProvider, Program, BN } from '@coral-xyz/anchor';
|
|
2
|
+
import { STAKE_POOL_PROGRAM_ID, StakePoolInstruction, getStakePoolAccount, depositSol } from '@solana/spl-stake-pool';
|
|
3
|
+
import { getAssociatedTokenAddressSync, createAssociatedTokenAccountIdempotentInstruction, ACCOUNT_SIZE, AccountLayout } from '@solana/spl-token';
|
|
4
|
+
import { PublicKey, LAMPORTS_PER_SOL, Transaction, Keypair, SystemProgram } from '@solana/web3.js';
|
|
4
5
|
|
|
5
6
|
var __create = Object.create;
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
@@ -4547,17 +4548,13 @@ var require_bn = __commonJS({
|
|
|
4547
4548
|
// src/client.ts
|
|
4548
4549
|
var import_bn = __toESM(require_bn());
|
|
4549
4550
|
|
|
4550
|
-
// src/constants.ts
|
|
4551
|
-
var GLOBAL_STATE_SEED = "global_state";
|
|
4552
|
-
var BOND_STATE_SEED = "bond_state";
|
|
4553
|
-
var VALIDATOR_BOND_SEED = "validator_bond";
|
|
4554
|
-
var STANDARD_BOND_SEED = "standard";
|
|
4555
|
-
var CROWDFUNDING_BOND_SEED = "crowdfunding";
|
|
4556
|
-
var ENV_PROGRAM_ID = {
|
|
4557
|
-
// [BondClientEnv.DEV]: new PublicKey('...'),
|
|
4558
|
-
};
|
|
4559
|
-
|
|
4560
4551
|
// src/types/index.ts
|
|
4552
|
+
var JBondClientEnv = /* @__PURE__ */ ((JBondClientEnv2) => {
|
|
4553
|
+
JBondClientEnv2["DEV"] = "dev";
|
|
4554
|
+
JBondClientEnv2["STAGE"] = "stage";
|
|
4555
|
+
JBondClientEnv2["PROD"] = "prod";
|
|
4556
|
+
return JBondClientEnv2;
|
|
4557
|
+
})(JBondClientEnv || {});
|
|
4561
4558
|
var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
|
|
4562
4559
|
SessionStatus2[SessionStatus2["Live"] = 0] = "Live";
|
|
4563
4560
|
SessionStatus2[SessionStatus2["Finished"] = 1] = "Finished";
|
|
@@ -4569,14 +4566,28 @@ var BondType = /* @__PURE__ */ ((BondType2) => {
|
|
|
4569
4566
|
return BondType2;
|
|
4570
4567
|
})(BondType || {});
|
|
4571
4568
|
var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
|
|
4569
|
+
BondTransactionType2["Registered"] = "registered";
|
|
4572
4570
|
BondTransactionType2["Deposit"] = "deposit";
|
|
4573
4571
|
BondTransactionType2["Withdrawal"] = "withdrawal";
|
|
4574
4572
|
BondTransactionType2["Compensation"] = "compensation";
|
|
4575
4573
|
return BondTransactionType2;
|
|
4576
4574
|
})(BondTransactionType || {});
|
|
4577
4575
|
|
|
4578
|
-
// src/
|
|
4576
|
+
// src/constants.ts
|
|
4577
|
+
var GLOBAL_STATE_SEED = "global_state";
|
|
4578
|
+
var BOND_STATE_SEED = "bond_state";
|
|
4579
|
+
var VALIDATOR_BOND_SEED = "validator_bond";
|
|
4580
|
+
var STANDARD_BOND_SEED = "standard";
|
|
4581
|
+
var CROWDFUNDING_BOND_SEED = "crowdfunding";
|
|
4582
|
+
var ENV_PROGRAM_ID = {
|
|
4583
|
+
["dev" /* DEV */]: "Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1",
|
|
4584
|
+
["stage" /* STAGE */]: "Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1",
|
|
4585
|
+
["prod" /* PROD */]: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU"
|
|
4586
|
+
};
|
|
4587
|
+
var JSOL_MINT = new PublicKey("7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn");
|
|
4588
|
+
var JPOOL_POOL_ADDRESS = new PublicKey("CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1");
|
|
4579
4589
|
var { bs58 } = utils.bytes;
|
|
4590
|
+
var DEFAULT_TX_BATCH_SIZE = 50;
|
|
4580
4591
|
var HistoryManager = class {
|
|
4581
4592
|
constructor(client) {
|
|
4582
4593
|
this.client = client;
|
|
@@ -4597,7 +4608,8 @@ var HistoryManager = class {
|
|
|
4597
4608
|
}
|
|
4598
4609
|
async getHistory(bondType, bondName, vote, opts) {
|
|
4599
4610
|
const [validatorBondAccount] = this.client.pda.validatorBond(bondType, bondName, vote);
|
|
4600
|
-
|
|
4611
|
+
const validatorBondAccount58 = validatorBondAccount.toBase58();
|
|
4612
|
+
this.debug(`Fetching history for validator bond account: ${validatorBondAccount58}`);
|
|
4601
4613
|
const signatures = await this.fetchSignaturesForAddress(validatorBondAccount, {
|
|
4602
4614
|
limit: opts?.limit,
|
|
4603
4615
|
before: opts?.before,
|
|
@@ -4607,7 +4619,7 @@ var HistoryManager = class {
|
|
|
4607
4619
|
return [];
|
|
4608
4620
|
}
|
|
4609
4621
|
const sigs = signatures.map((s) => s.signature);
|
|
4610
|
-
const parsed = await this.fetchParsedTransactions(sigs);
|
|
4622
|
+
const parsed = await this.fetchParsedTransactions(sigs, opts?.batchSize);
|
|
4611
4623
|
const txBySig = /* @__PURE__ */ new Map();
|
|
4612
4624
|
for (let i = 0; i < sigs.length; i++) {
|
|
4613
4625
|
const want = sigs[i];
|
|
@@ -4638,8 +4650,11 @@ var HistoryManager = class {
|
|
|
4638
4650
|
if (ix.parsed) {
|
|
4639
4651
|
continue;
|
|
4640
4652
|
}
|
|
4653
|
+
if (!this.instructionReferencesBondAccount(ix, validatorBondAccount, validatorBondAccount58)) {
|
|
4654
|
+
continue;
|
|
4655
|
+
}
|
|
4641
4656
|
const { type, amount } = this.decodeInstructionData(ix.data);
|
|
4642
|
-
if (!type || amount <= 0) {
|
|
4657
|
+
if (!type || amount <= 0 && type !== "registered" /* Registered */) {
|
|
4643
4658
|
continue;
|
|
4644
4659
|
}
|
|
4645
4660
|
history.push({
|
|
@@ -4653,19 +4668,34 @@ var HistoryManager = class {
|
|
|
4653
4668
|
}
|
|
4654
4669
|
return history.sort((a, b) => b.slot - a.slot);
|
|
4655
4670
|
}
|
|
4671
|
+
instructionReferencesBondAccount(ix, validatorBondAccount, validatorBondAccount58) {
|
|
4672
|
+
if (!Array.isArray(ix.accounts) || ix.accounts.length === 0) {
|
|
4673
|
+
return false;
|
|
4674
|
+
}
|
|
4675
|
+
return ix.accounts.some((account) => {
|
|
4676
|
+
if (typeof account === "string") {
|
|
4677
|
+
return account === validatorBondAccount58;
|
|
4678
|
+
}
|
|
4679
|
+
if (account instanceof PublicKey) {
|
|
4680
|
+
return account.equals(validatorBondAccount);
|
|
4681
|
+
}
|
|
4682
|
+
const account58 = account?.toBase58?.();
|
|
4683
|
+
return typeof account58 === "string" && account58 === validatorBondAccount58;
|
|
4684
|
+
});
|
|
4685
|
+
}
|
|
4656
4686
|
async fetchSignaturesForAddress(address, options) {
|
|
4657
4687
|
const sigs = await this.connection.getSignaturesForAddress(address, {
|
|
4658
4688
|
limit: options?.limit || 1e3,
|
|
4659
4689
|
before: options?.before,
|
|
4660
4690
|
until: options?.until
|
|
4661
4691
|
}, "confirmed");
|
|
4662
|
-
console.log(sigs);
|
|
4663
4692
|
return sigs.filter((s) => !s.err);
|
|
4664
4693
|
}
|
|
4665
|
-
async fetchParsedTransactions(sigs, batchSize =
|
|
4694
|
+
async fetchParsedTransactions(sigs, batchSize = DEFAULT_TX_BATCH_SIZE) {
|
|
4695
|
+
const size = Math.max(1, Math.floor(batchSize) || DEFAULT_TX_BATCH_SIZE);
|
|
4666
4696
|
const all = [];
|
|
4667
|
-
for (let i = 0; i < sigs.length; i +=
|
|
4668
|
-
const batch = sigs.slice(i, i +
|
|
4697
|
+
for (let i = 0; i < sigs.length; i += size) {
|
|
4698
|
+
const batch = sigs.slice(i, i + size);
|
|
4669
4699
|
const txs = await this.connection.getParsedTransactions(batch, {
|
|
4670
4700
|
commitment: "confirmed",
|
|
4671
4701
|
maxSupportedTransactionVersion: 0
|
|
@@ -4681,7 +4711,7 @@ var HistoryManager = class {
|
|
|
4681
4711
|
}
|
|
4682
4712
|
const ix = this.program.idl.instructions.find((i) => i.name === name);
|
|
4683
4713
|
if (!ix || !Array.isArray(ix.discriminator)) {
|
|
4684
|
-
|
|
4714
|
+
return new Uint8Array();
|
|
4685
4715
|
}
|
|
4686
4716
|
const disc = new Uint8Array(ix.discriminator);
|
|
4687
4717
|
this.discCache.set(name, disc);
|
|
@@ -4689,47 +4719,45 @@ var HistoryManager = class {
|
|
|
4689
4719
|
}
|
|
4690
4720
|
decodeInstructionData(data) {
|
|
4691
4721
|
if (!data) {
|
|
4692
|
-
return {
|
|
4693
|
-
type: null,
|
|
4694
|
-
amount: 0
|
|
4695
|
-
};
|
|
4722
|
+
return { type: null, amount: 0 };
|
|
4696
4723
|
}
|
|
4697
4724
|
try {
|
|
4698
4725
|
const buf = bs58.decode(data);
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
const
|
|
4710
|
-
const
|
|
4711
|
-
const
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
if (
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
}
|
|
4724
|
-
return { type
|
|
4725
|
-
} catch {
|
|
4726
|
+
let type = null;
|
|
4727
|
+
const disc = buf.subarray(0, 8);
|
|
4728
|
+
const amountBytes = buf.subarray(8, 16);
|
|
4729
|
+
let amount = 0;
|
|
4730
|
+
let noAmount = false;
|
|
4731
|
+
try {
|
|
4732
|
+
amount = new BN(amountBytes, "le").toNumber() / LAMPORTS_PER_SOL;
|
|
4733
|
+
} catch {
|
|
4734
|
+
noAmount = true;
|
|
4735
|
+
}
|
|
4736
|
+
const bondRegisterDiscriminator = this.getInstructionDiscriminator("bondRegister");
|
|
4737
|
+
const bondTopUpDiscriminator = this.getInstructionDiscriminator("bondTopUp");
|
|
4738
|
+
const bondClaimDiscriminator = this.getInstructionDiscriminator("bondClaim");
|
|
4739
|
+
const bondWithdrawDiscriminator = this.getInstructionDiscriminator("bondWithdraw");
|
|
4740
|
+
if (Buffer.from(disc).equals(Buffer.from(bondRegisterDiscriminator))) {
|
|
4741
|
+
type = "registered" /* Registered */;
|
|
4742
|
+
} else if (!noAmount) {
|
|
4743
|
+
if (Buffer.from(disc).equals(Buffer.from(bondTopUpDiscriminator))) {
|
|
4744
|
+
type = "deposit" /* Deposit */;
|
|
4745
|
+
} else if (Buffer.from(disc).equals(Buffer.from(bondClaimDiscriminator))) {
|
|
4746
|
+
type = "compensation" /* Compensation */;
|
|
4747
|
+
} else if (Buffer.from(disc).equals(Buffer.from(bondWithdrawDiscriminator))) {
|
|
4748
|
+
type = "withdrawal" /* Withdrawal */;
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
return { type, amount };
|
|
4752
|
+
} catch (error) {
|
|
4753
|
+
console.error("Failed to decode instruction data:", error);
|
|
4726
4754
|
return { type: null, amount: 0 };
|
|
4727
4755
|
}
|
|
4728
4756
|
}
|
|
4729
4757
|
};
|
|
4730
4758
|
function slotToEpoch(slot, cluster) {
|
|
4731
|
-
const
|
|
4732
|
-
const slotsPerEpoch =
|
|
4759
|
+
const isDevnet = cluster?.includes("devnet") || cluster?.includes("localnet");
|
|
4760
|
+
const slotsPerEpoch = isDevnet ? 4e5 : 432e3;
|
|
4733
4761
|
return Math.floor(slot / slotsPerEpoch);
|
|
4734
4762
|
}
|
|
4735
4763
|
|
|
@@ -4738,7 +4766,7 @@ var jbond_default = {
|
|
|
4738
4766
|
address: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU",
|
|
4739
4767
|
metadata: {
|
|
4740
4768
|
name: "jbond",
|
|
4741
|
-
version: "0.2.
|
|
4769
|
+
version: "0.2.6",
|
|
4742
4770
|
spec: "0.1.0",
|
|
4743
4771
|
description: "Jpool Bond Program"
|
|
4744
4772
|
},
|
|
@@ -4813,7 +4841,10 @@ var jbond_default = {
|
|
|
4813
4841
|
},
|
|
4814
4842
|
{
|
|
4815
4843
|
name: "authority",
|
|
4816
|
-
signer: true
|
|
4844
|
+
signer: true,
|
|
4845
|
+
relations: [
|
|
4846
|
+
"bond_state"
|
|
4847
|
+
]
|
|
4817
4848
|
},
|
|
4818
4849
|
{
|
|
4819
4850
|
name: "bond_token_account",
|
|
@@ -4984,6 +5015,84 @@ var jbond_default = {
|
|
|
4984
5015
|
}
|
|
4985
5016
|
]
|
|
4986
5017
|
},
|
|
5018
|
+
{
|
|
5019
|
+
name: "bond_lock_funds",
|
|
5020
|
+
docs: [
|
|
5021
|
+
"Locks funds immediately, making them unavailable for withdrawal.",
|
|
5022
|
+
"The locked amount takes effect immediately in the current epoch.",
|
|
5023
|
+
"",
|
|
5024
|
+
"# Errors",
|
|
5025
|
+
"Fails if the bond type is not lockable, if the amount is zero,",
|
|
5026
|
+
"or if there are insufficient available funds."
|
|
5027
|
+
],
|
|
5028
|
+
discriminator: [
|
|
5029
|
+
117,
|
|
5030
|
+
166,
|
|
5031
|
+
195,
|
|
5032
|
+
99,
|
|
5033
|
+
103,
|
|
5034
|
+
45,
|
|
5035
|
+
195,
|
|
5036
|
+
2
|
|
5037
|
+
],
|
|
5038
|
+
accounts: [
|
|
5039
|
+
{
|
|
5040
|
+
name: "bond_state",
|
|
5041
|
+
writable: true
|
|
5042
|
+
},
|
|
5043
|
+
{
|
|
5044
|
+
name: "validator_bond",
|
|
5045
|
+
writable: true,
|
|
5046
|
+
pda: {
|
|
5047
|
+
seeds: [
|
|
5048
|
+
{
|
|
5049
|
+
kind: "const",
|
|
5050
|
+
value: [
|
|
5051
|
+
118,
|
|
5052
|
+
97,
|
|
5053
|
+
108,
|
|
5054
|
+
105,
|
|
5055
|
+
100,
|
|
5056
|
+
97,
|
|
5057
|
+
116,
|
|
5058
|
+
111,
|
|
5059
|
+
114,
|
|
5060
|
+
95,
|
|
5061
|
+
98,
|
|
5062
|
+
111,
|
|
5063
|
+
110,
|
|
5064
|
+
100
|
|
5065
|
+
]
|
|
5066
|
+
},
|
|
5067
|
+
{
|
|
5068
|
+
kind: "account",
|
|
5069
|
+
path: "bond_state"
|
|
5070
|
+
},
|
|
5071
|
+
{
|
|
5072
|
+
kind: "account",
|
|
5073
|
+
path: "validator_bond.vote_account",
|
|
5074
|
+
account: "ValidatorBond"
|
|
5075
|
+
}
|
|
5076
|
+
]
|
|
5077
|
+
}
|
|
5078
|
+
},
|
|
5079
|
+
{
|
|
5080
|
+
name: "bond_token_account",
|
|
5081
|
+
optional: true
|
|
5082
|
+
},
|
|
5083
|
+
{
|
|
5084
|
+
name: "payer",
|
|
5085
|
+
writable: true,
|
|
5086
|
+
signer: true
|
|
5087
|
+
}
|
|
5088
|
+
],
|
|
5089
|
+
args: [
|
|
5090
|
+
{
|
|
5091
|
+
name: "amount",
|
|
5092
|
+
type: "u64"
|
|
5093
|
+
}
|
|
5094
|
+
]
|
|
5095
|
+
},
|
|
4987
5096
|
{
|
|
4988
5097
|
name: "bond_register",
|
|
4989
5098
|
docs: [
|
|
@@ -5011,7 +5120,34 @@ var jbond_default = {
|
|
|
5011
5120
|
accounts: [
|
|
5012
5121
|
{
|
|
5013
5122
|
name: "bond_state",
|
|
5014
|
-
writable: true
|
|
5123
|
+
writable: true,
|
|
5124
|
+
pda: {
|
|
5125
|
+
seeds: [
|
|
5126
|
+
{
|
|
5127
|
+
kind: "const",
|
|
5128
|
+
value: [
|
|
5129
|
+
98,
|
|
5130
|
+
111,
|
|
5131
|
+
110,
|
|
5132
|
+
100,
|
|
5133
|
+
95,
|
|
5134
|
+
115,
|
|
5135
|
+
116,
|
|
5136
|
+
97,
|
|
5137
|
+
116,
|
|
5138
|
+
101
|
|
5139
|
+
]
|
|
5140
|
+
},
|
|
5141
|
+
{
|
|
5142
|
+
kind: "arg",
|
|
5143
|
+
path: "bond_type"
|
|
5144
|
+
},
|
|
5145
|
+
{
|
|
5146
|
+
kind: "arg",
|
|
5147
|
+
path: "bond_name"
|
|
5148
|
+
}
|
|
5149
|
+
]
|
|
5150
|
+
}
|
|
5015
5151
|
},
|
|
5016
5152
|
{
|
|
5017
5153
|
name: "validator_bond",
|
|
@@ -5096,6 +5232,112 @@ var jbond_default = {
|
|
|
5096
5232
|
}
|
|
5097
5233
|
]
|
|
5098
5234
|
},
|
|
5235
|
+
{
|
|
5236
|
+
name: "bond_release_funds",
|
|
5237
|
+
docs: [
|
|
5238
|
+
"Queues funds for unlock in the next epoch.",
|
|
5239
|
+
"The unlock is delayed by one epoch for security - funds remain locked",
|
|
5240
|
+
"in the current epoch but will be available after epoch transition.",
|
|
5241
|
+
"",
|
|
5242
|
+
"# Errors",
|
|
5243
|
+
"Fails if the bond type is not lockable, if the amount is zero,",
|
|
5244
|
+
"or if the amount exceeds currently locked funds."
|
|
5245
|
+
],
|
|
5246
|
+
discriminator: [
|
|
5247
|
+
184,
|
|
5248
|
+
224,
|
|
5249
|
+
14,
|
|
5250
|
+
24,
|
|
5251
|
+
76,
|
|
5252
|
+
14,
|
|
5253
|
+
226,
|
|
5254
|
+
190
|
|
5255
|
+
],
|
|
5256
|
+
accounts: [
|
|
5257
|
+
{
|
|
5258
|
+
name: "bond_state",
|
|
5259
|
+
writable: true
|
|
5260
|
+
},
|
|
5261
|
+
{
|
|
5262
|
+
name: "validator_bond",
|
|
5263
|
+
writable: true,
|
|
5264
|
+
pda: {
|
|
5265
|
+
seeds: [
|
|
5266
|
+
{
|
|
5267
|
+
kind: "const",
|
|
5268
|
+
value: [
|
|
5269
|
+
118,
|
|
5270
|
+
97,
|
|
5271
|
+
108,
|
|
5272
|
+
105,
|
|
5273
|
+
100,
|
|
5274
|
+
97,
|
|
5275
|
+
116,
|
|
5276
|
+
111,
|
|
5277
|
+
114,
|
|
5278
|
+
95,
|
|
5279
|
+
98,
|
|
5280
|
+
111,
|
|
5281
|
+
110,
|
|
5282
|
+
100
|
|
5283
|
+
]
|
|
5284
|
+
},
|
|
5285
|
+
{
|
|
5286
|
+
kind: "account",
|
|
5287
|
+
path: "bond_state"
|
|
5288
|
+
},
|
|
5289
|
+
{
|
|
5290
|
+
kind: "account",
|
|
5291
|
+
path: "validator_bond.vote_account",
|
|
5292
|
+
account: "ValidatorBond"
|
|
5293
|
+
}
|
|
5294
|
+
]
|
|
5295
|
+
}
|
|
5296
|
+
},
|
|
5297
|
+
{
|
|
5298
|
+
name: "payer",
|
|
5299
|
+
writable: true,
|
|
5300
|
+
signer: true
|
|
5301
|
+
}
|
|
5302
|
+
],
|
|
5303
|
+
args: [
|
|
5304
|
+
{
|
|
5305
|
+
name: "amount",
|
|
5306
|
+
type: "u64"
|
|
5307
|
+
}
|
|
5308
|
+
]
|
|
5309
|
+
},
|
|
5310
|
+
{
|
|
5311
|
+
name: "bond_remove",
|
|
5312
|
+
docs: [
|
|
5313
|
+
"Removes bond state"
|
|
5314
|
+
],
|
|
5315
|
+
discriminator: [
|
|
5316
|
+
121,
|
|
5317
|
+
112,
|
|
5318
|
+
246,
|
|
5319
|
+
177,
|
|
5320
|
+
181,
|
|
5321
|
+
8,
|
|
5322
|
+
18,
|
|
5323
|
+
220
|
|
5324
|
+
],
|
|
5325
|
+
accounts: [
|
|
5326
|
+
{
|
|
5327
|
+
name: "bond_state",
|
|
5328
|
+
writable: true
|
|
5329
|
+
},
|
|
5330
|
+
{
|
|
5331
|
+
name: "authority",
|
|
5332
|
+
writable: true,
|
|
5333
|
+
signer: true,
|
|
5334
|
+
relations: [
|
|
5335
|
+
"bond_state"
|
|
5336
|
+
]
|
|
5337
|
+
}
|
|
5338
|
+
],
|
|
5339
|
+
args: []
|
|
5340
|
+
},
|
|
5099
5341
|
{
|
|
5100
5342
|
name: "bond_set_withdraw_authority",
|
|
5101
5343
|
docs: [
|
|
@@ -5386,23 +5628,120 @@ var jbond_default = {
|
|
|
5386
5628
|
]
|
|
5387
5629
|
},
|
|
5388
5630
|
{
|
|
5389
|
-
name: "
|
|
5631
|
+
name: "close_validator_bond",
|
|
5632
|
+
docs: [
|
|
5633
|
+
"Closes a validator bond account and transfers remaining balance to the rent receiver.",
|
|
5634
|
+
"",
|
|
5635
|
+
"# Security",
|
|
5636
|
+
"- Only the validator identity or withdrawal authority can close the bond",
|
|
5637
|
+
"- All funds must be unlocked (locked == 0 and pending_unlock == 0)",
|
|
5638
|
+
"- For token collateral, closes the associated token account as well",
|
|
5639
|
+
"- Decrements the bond state's total_members counter",
|
|
5640
|
+
"",
|
|
5641
|
+
"# Errors",
|
|
5642
|
+
"Fails if the signer is not authorized, if funds are still locked,",
|
|
5643
|
+
"or if the rent receiver is not the identity or withdrawal authority."
|
|
5644
|
+
],
|
|
5390
5645
|
discriminator: [
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5646
|
+
51,
|
|
5647
|
+
235,
|
|
5648
|
+
111,
|
|
5649
|
+
163,
|
|
5650
|
+
176,
|
|
5651
|
+
239,
|
|
5652
|
+
95,
|
|
5653
|
+
122
|
|
5399
5654
|
],
|
|
5400
5655
|
accounts: [
|
|
5401
5656
|
{
|
|
5402
|
-
name: "
|
|
5403
|
-
writable: true
|
|
5404
|
-
|
|
5405
|
-
|
|
5657
|
+
name: "bond_state",
|
|
5658
|
+
writable: true
|
|
5659
|
+
},
|
|
5660
|
+
{
|
|
5661
|
+
name: "validator_bond",
|
|
5662
|
+
writable: true,
|
|
5663
|
+
pda: {
|
|
5664
|
+
seeds: [
|
|
5665
|
+
{
|
|
5666
|
+
kind: "const",
|
|
5667
|
+
value: [
|
|
5668
|
+
118,
|
|
5669
|
+
97,
|
|
5670
|
+
108,
|
|
5671
|
+
105,
|
|
5672
|
+
100,
|
|
5673
|
+
97,
|
|
5674
|
+
116,
|
|
5675
|
+
111,
|
|
5676
|
+
114,
|
|
5677
|
+
95,
|
|
5678
|
+
98,
|
|
5679
|
+
111,
|
|
5680
|
+
110,
|
|
5681
|
+
100
|
|
5682
|
+
]
|
|
5683
|
+
},
|
|
5684
|
+
{
|
|
5685
|
+
kind: "account",
|
|
5686
|
+
path: "bond_state"
|
|
5687
|
+
},
|
|
5688
|
+
{
|
|
5689
|
+
kind: "account",
|
|
5690
|
+
path: "validator_bond.vote_account",
|
|
5691
|
+
account: "ValidatorBond"
|
|
5692
|
+
}
|
|
5693
|
+
]
|
|
5694
|
+
}
|
|
5695
|
+
},
|
|
5696
|
+
{
|
|
5697
|
+
name: "authority",
|
|
5698
|
+
writable: true,
|
|
5699
|
+
signer: true
|
|
5700
|
+
},
|
|
5701
|
+
{
|
|
5702
|
+
name: "rent_receiver",
|
|
5703
|
+
writable: true
|
|
5704
|
+
},
|
|
5705
|
+
{
|
|
5706
|
+
name: "bond_token_account",
|
|
5707
|
+
writable: true,
|
|
5708
|
+
optional: true
|
|
5709
|
+
},
|
|
5710
|
+
{
|
|
5711
|
+
name: "destination_token_account",
|
|
5712
|
+
writable: true,
|
|
5713
|
+
optional: true
|
|
5714
|
+
},
|
|
5715
|
+
{
|
|
5716
|
+
name: "system_program",
|
|
5717
|
+
address: "11111111111111111111111111111111"
|
|
5718
|
+
},
|
|
5719
|
+
{
|
|
5720
|
+
name: "token_program",
|
|
5721
|
+
optional: true,
|
|
5722
|
+
address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
|
5723
|
+
}
|
|
5724
|
+
],
|
|
5725
|
+
args: []
|
|
5726
|
+
},
|
|
5727
|
+
{
|
|
5728
|
+
name: "global_configure",
|
|
5729
|
+
discriminator: [
|
|
5730
|
+
67,
|
|
5731
|
+
142,
|
|
5732
|
+
164,
|
|
5733
|
+
250,
|
|
5734
|
+
90,
|
|
5735
|
+
233,
|
|
5736
|
+
144,
|
|
5737
|
+
187
|
|
5738
|
+
],
|
|
5739
|
+
accounts: [
|
|
5740
|
+
{
|
|
5741
|
+
name: "global_state",
|
|
5742
|
+
writable: true,
|
|
5743
|
+
pda: {
|
|
5744
|
+
seeds: [
|
|
5406
5745
|
{
|
|
5407
5746
|
kind: "const",
|
|
5408
5747
|
value: [
|
|
@@ -5492,80 +5831,6 @@ var jbond_default = {
|
|
|
5492
5831
|
],
|
|
5493
5832
|
args: []
|
|
5494
5833
|
},
|
|
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
5834
|
{
|
|
5570
5835
|
name: "session_finish",
|
|
5571
5836
|
docs: [
|
|
@@ -5676,6 +5941,19 @@ var jbond_default = {
|
|
|
5676
5941
|
}
|
|
5677
5942
|
],
|
|
5678
5943
|
events: [
|
|
5944
|
+
{
|
|
5945
|
+
name: "BondConfigured",
|
|
5946
|
+
discriminator: [
|
|
5947
|
+
141,
|
|
5948
|
+
252,
|
|
5949
|
+
43,
|
|
5950
|
+
54,
|
|
5951
|
+
45,
|
|
5952
|
+
157,
|
|
5953
|
+
81,
|
|
5954
|
+
14
|
|
5955
|
+
]
|
|
5956
|
+
},
|
|
5679
5957
|
{
|
|
5680
5958
|
name: "BondFinished",
|
|
5681
5959
|
discriminator: [
|
|
@@ -5689,6 +5967,32 @@ var jbond_default = {
|
|
|
5689
5967
|
191
|
|
5690
5968
|
]
|
|
5691
5969
|
},
|
|
5970
|
+
{
|
|
5971
|
+
name: "BondInitialized",
|
|
5972
|
+
discriminator: [
|
|
5973
|
+
73,
|
|
5974
|
+
68,
|
|
5975
|
+
161,
|
|
5976
|
+
2,
|
|
5977
|
+
214,
|
|
5978
|
+
12,
|
|
5979
|
+
169,
|
|
5980
|
+
53
|
|
5981
|
+
]
|
|
5982
|
+
},
|
|
5983
|
+
{
|
|
5984
|
+
name: "BondRemoved",
|
|
5985
|
+
discriminator: [
|
|
5986
|
+
177,
|
|
5987
|
+
200,
|
|
5988
|
+
116,
|
|
5989
|
+
123,
|
|
5990
|
+
1,
|
|
5991
|
+
244,
|
|
5992
|
+
161,
|
|
5993
|
+
240
|
|
5994
|
+
]
|
|
5995
|
+
},
|
|
5692
5996
|
{
|
|
5693
5997
|
name: "BondStarted",
|
|
5694
5998
|
discriminator: [
|
|
@@ -5703,16 +6007,16 @@ var jbond_default = {
|
|
|
5703
6007
|
]
|
|
5704
6008
|
},
|
|
5705
6009
|
{
|
|
5706
|
-
name: "
|
|
6010
|
+
name: "CollateralDeposited",
|
|
5707
6011
|
discriminator: [
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
6012
|
+
244,
|
|
6013
|
+
62,
|
|
6014
|
+
77,
|
|
6015
|
+
11,
|
|
5712
6016
|
135,
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
6017
|
+
112,
|
|
6018
|
+
61,
|
|
6019
|
+
96
|
|
5716
6020
|
]
|
|
5717
6021
|
},
|
|
5718
6022
|
{
|
|
@@ -5728,6 +6032,19 @@ var jbond_default = {
|
|
|
5728
6032
|
82
|
|
5729
6033
|
]
|
|
5730
6034
|
},
|
|
6035
|
+
{
|
|
6036
|
+
name: "CompensationBurned",
|
|
6037
|
+
discriminator: [
|
|
6038
|
+
177,
|
|
6039
|
+
198,
|
|
6040
|
+
90,
|
|
6041
|
+
188,
|
|
6042
|
+
47,
|
|
6043
|
+
95,
|
|
6044
|
+
20,
|
|
6045
|
+
174
|
|
6046
|
+
]
|
|
6047
|
+
},
|
|
5731
6048
|
{
|
|
5732
6049
|
name: "CompensationClaimed",
|
|
5733
6050
|
discriminator: [
|
|
@@ -5741,6 +6058,45 @@ var jbond_default = {
|
|
|
5741
6058
|
32
|
|
5742
6059
|
]
|
|
5743
6060
|
},
|
|
6061
|
+
{
|
|
6062
|
+
name: "FundsLocked",
|
|
6063
|
+
discriminator: [
|
|
6064
|
+
227,
|
|
6065
|
+
93,
|
|
6066
|
+
162,
|
|
6067
|
+
69,
|
|
6068
|
+
181,
|
|
6069
|
+
4,
|
|
6070
|
+
71,
|
|
6071
|
+
157
|
|
6072
|
+
]
|
|
6073
|
+
},
|
|
6074
|
+
{
|
|
6075
|
+
name: "FundsUnlocked",
|
|
6076
|
+
discriminator: [
|
|
6077
|
+
11,
|
|
6078
|
+
240,
|
|
6079
|
+
184,
|
|
6080
|
+
107,
|
|
6081
|
+
86,
|
|
6082
|
+
187,
|
|
6083
|
+
196,
|
|
6084
|
+
128
|
|
6085
|
+
]
|
|
6086
|
+
},
|
|
6087
|
+
{
|
|
6088
|
+
name: "ValidatorBondClosed",
|
|
6089
|
+
discriminator: [
|
|
6090
|
+
71,
|
|
6091
|
+
54,
|
|
6092
|
+
59,
|
|
6093
|
+
241,
|
|
6094
|
+
91,
|
|
6095
|
+
35,
|
|
6096
|
+
123,
|
|
6097
|
+
123
|
|
6098
|
+
]
|
|
6099
|
+
},
|
|
5744
6100
|
{
|
|
5745
6101
|
name: "ValidatorRegistered",
|
|
5746
6102
|
discriminator: [
|
|
@@ -5753,33 +6109,46 @@ var jbond_default = {
|
|
|
5753
6109
|
95,
|
|
5754
6110
|
72
|
|
5755
6111
|
]
|
|
6112
|
+
},
|
|
6113
|
+
{
|
|
6114
|
+
name: "WithdrawAuthorityChanged",
|
|
6115
|
+
discriminator: [
|
|
6116
|
+
91,
|
|
6117
|
+
149,
|
|
6118
|
+
224,
|
|
6119
|
+
49,
|
|
6120
|
+
187,
|
|
6121
|
+
48,
|
|
6122
|
+
190,
|
|
6123
|
+
100
|
|
6124
|
+
]
|
|
5756
6125
|
}
|
|
5757
6126
|
],
|
|
5758
6127
|
errors: [
|
|
5759
6128
|
{
|
|
5760
6129
|
code: 6e3,
|
|
5761
|
-
name: "
|
|
5762
|
-
msg: "
|
|
6130
|
+
name: "Forbidden",
|
|
6131
|
+
msg: "Forbidden"
|
|
5763
6132
|
},
|
|
5764
6133
|
{
|
|
5765
6134
|
code: 6001,
|
|
5766
|
-
name: "
|
|
5767
|
-
msg: "
|
|
6135
|
+
name: "Unauthorized",
|
|
6136
|
+
msg: "Unauthorized"
|
|
5768
6137
|
},
|
|
5769
6138
|
{
|
|
5770
6139
|
code: 6002,
|
|
5771
|
-
name: "
|
|
5772
|
-
msg: "
|
|
6140
|
+
name: "InvalidVoteAccount",
|
|
6141
|
+
msg: "Invalid vote account"
|
|
5773
6142
|
},
|
|
5774
6143
|
{
|
|
5775
6144
|
code: 6003,
|
|
5776
|
-
name: "
|
|
5777
|
-
msg: "
|
|
6145
|
+
name: "IdentityMismatch",
|
|
6146
|
+
msg: "Vote account identity mismatch"
|
|
5778
6147
|
},
|
|
5779
6148
|
{
|
|
5780
6149
|
code: 6004,
|
|
5781
|
-
name: "
|
|
5782
|
-
msg: "
|
|
6150
|
+
name: "InvalidMint",
|
|
6151
|
+
msg: "Invalid mint address"
|
|
5783
6152
|
},
|
|
5784
6153
|
{
|
|
5785
6154
|
code: 6005,
|
|
@@ -5788,93 +6157,53 @@ var jbond_default = {
|
|
|
5788
6157
|
},
|
|
5789
6158
|
{
|
|
5790
6159
|
code: 6006,
|
|
5791
|
-
name: "
|
|
5792
|
-
msg: "
|
|
6160
|
+
name: "InvalidArgument",
|
|
6161
|
+
msg: "Invalid argument"
|
|
5793
6162
|
},
|
|
5794
6163
|
{
|
|
5795
6164
|
code: 6007,
|
|
5796
|
-
name: "
|
|
5797
|
-
msg: "
|
|
6165
|
+
name: "InsufficientBalance",
|
|
6166
|
+
msg: "Insufficient balance"
|
|
5798
6167
|
},
|
|
5799
6168
|
{
|
|
5800
6169
|
code: 6008,
|
|
5801
|
-
name: "
|
|
5802
|
-
msg: "
|
|
6170
|
+
name: "MathOverflow",
|
|
6171
|
+
msg: "Math overflow"
|
|
5803
6172
|
},
|
|
5804
6173
|
{
|
|
5805
6174
|
code: 6009,
|
|
5806
|
-
name: "
|
|
5807
|
-
msg: "
|
|
6175
|
+
name: "Overflow",
|
|
6176
|
+
msg: "Arithmetic overflow"
|
|
5808
6177
|
},
|
|
5809
6178
|
{
|
|
5810
6179
|
code: 6010,
|
|
5811
|
-
name: "
|
|
5812
|
-
msg: "
|
|
6180
|
+
name: "BondNotRemovable",
|
|
6181
|
+
msg: "Bond cannot be removed"
|
|
5813
6182
|
},
|
|
5814
6183
|
{
|
|
5815
6184
|
code: 6011,
|
|
5816
|
-
name: "
|
|
5817
|
-
msg: "
|
|
6185
|
+
name: "MissingTokenAccounts",
|
|
6186
|
+
msg: "Missing token accounts"
|
|
5818
6187
|
},
|
|
5819
6188
|
{
|
|
5820
6189
|
code: 6012,
|
|
5821
|
-
name: "
|
|
5822
|
-
msg: "
|
|
6190
|
+
name: "MissingTokenProgram",
|
|
6191
|
+
msg: "Missing token program"
|
|
5823
6192
|
},
|
|
5824
6193
|
{
|
|
5825
6194
|
code: 6013,
|
|
5826
6195
|
name: "MissingStakeAccount",
|
|
5827
|
-
msg: "
|
|
6196
|
+
msg: "Missing stake account"
|
|
5828
6197
|
},
|
|
5829
6198
|
{
|
|
5830
6199
|
code: 6014,
|
|
5831
6200
|
name: "MissingStakeProgram",
|
|
5832
|
-
msg: "
|
|
6201
|
+
msg: "Missing stake program"
|
|
5833
6202
|
},
|
|
5834
6203
|
{
|
|
5835
6204
|
code: 6015,
|
|
5836
|
-
name: "BondFinished",
|
|
5837
|
-
msg: "Bond is finished (deposits/withdrawals disabled)"
|
|
5838
|
-
},
|
|
5839
|
-
{
|
|
5840
|
-
code: 6016,
|
|
5841
|
-
name: "BondNotFinished",
|
|
5842
|
-
msg: "Bond is not finished"
|
|
5843
|
-
},
|
|
5844
|
-
{
|
|
5845
|
-
code: 6017,
|
|
5846
6205
|
name: "UnsupportedCollateralType",
|
|
5847
6206
|
msg: "Unsupported collateral type"
|
|
5848
|
-
},
|
|
5849
|
-
{
|
|
5850
|
-
code: 6018,
|
|
5851
|
-
name: "Overflow",
|
|
5852
|
-
msg: "Math operation overflowed"
|
|
5853
|
-
},
|
|
5854
|
-
{
|
|
5855
|
-
code: 6019,
|
|
5856
|
-
name: "IncorrectBondType",
|
|
5857
|
-
msg: "Incorrect bond type for this operation"
|
|
5858
|
-
},
|
|
5859
|
-
{
|
|
5860
|
-
code: 6020,
|
|
5861
|
-
name: "BondNotFinishable",
|
|
5862
|
-
msg: "This bond type can't be finished"
|
|
5863
|
-
},
|
|
5864
|
-
{
|
|
5865
|
-
code: 6021,
|
|
5866
|
-
name: "InvalidArgument",
|
|
5867
|
-
msg: "Invalid argument provided"
|
|
5868
|
-
},
|
|
5869
|
-
{
|
|
5870
|
-
code: 6022,
|
|
5871
|
-
name: "BondNotDisabled",
|
|
5872
|
-
msg: "Bond is not disabled"
|
|
5873
|
-
},
|
|
5874
|
-
{
|
|
5875
|
-
code: 6023,
|
|
5876
|
-
name: "BondNotEnabled",
|
|
5877
|
-
msg: "Bond is not enabled"
|
|
5878
6207
|
}
|
|
5879
6208
|
],
|
|
5880
6209
|
types: [
|
|
@@ -5908,6 +6237,26 @@ var jbond_default = {
|
|
|
5908
6237
|
]
|
|
5909
6238
|
}
|
|
5910
6239
|
},
|
|
6240
|
+
{
|
|
6241
|
+
name: "BondConfigured",
|
|
6242
|
+
type: {
|
|
6243
|
+
kind: "struct",
|
|
6244
|
+
fields: [
|
|
6245
|
+
{
|
|
6246
|
+
name: "bond",
|
|
6247
|
+
type: "pubkey"
|
|
6248
|
+
},
|
|
6249
|
+
{
|
|
6250
|
+
name: "authority",
|
|
6251
|
+
type: "pubkey"
|
|
6252
|
+
},
|
|
6253
|
+
{
|
|
6254
|
+
name: "timestamp",
|
|
6255
|
+
type: "i64"
|
|
6256
|
+
}
|
|
6257
|
+
]
|
|
6258
|
+
}
|
|
6259
|
+
},
|
|
5911
6260
|
{
|
|
5912
6261
|
name: "BondFinished",
|
|
5913
6262
|
type: {
|
|
@@ -5963,6 +6312,46 @@ var jbond_default = {
|
|
|
5963
6312
|
]
|
|
5964
6313
|
}
|
|
5965
6314
|
},
|
|
6315
|
+
{
|
|
6316
|
+
name: "BondInitialized",
|
|
6317
|
+
type: {
|
|
6318
|
+
kind: "struct",
|
|
6319
|
+
fields: [
|
|
6320
|
+
{
|
|
6321
|
+
name: "bond",
|
|
6322
|
+
type: "pubkey"
|
|
6323
|
+
},
|
|
6324
|
+
{
|
|
6325
|
+
name: "authority",
|
|
6326
|
+
type: "pubkey"
|
|
6327
|
+
},
|
|
6328
|
+
{
|
|
6329
|
+
name: "timestamp",
|
|
6330
|
+
type: "i64"
|
|
6331
|
+
}
|
|
6332
|
+
]
|
|
6333
|
+
}
|
|
6334
|
+
},
|
|
6335
|
+
{
|
|
6336
|
+
name: "BondRemoved",
|
|
6337
|
+
type: {
|
|
6338
|
+
kind: "struct",
|
|
6339
|
+
fields: [
|
|
6340
|
+
{
|
|
6341
|
+
name: "bond",
|
|
6342
|
+
type: "pubkey"
|
|
6343
|
+
},
|
|
6344
|
+
{
|
|
6345
|
+
name: "authority",
|
|
6346
|
+
type: "pubkey"
|
|
6347
|
+
},
|
|
6348
|
+
{
|
|
6349
|
+
name: "timestamp",
|
|
6350
|
+
type: "i64"
|
|
6351
|
+
}
|
|
6352
|
+
]
|
|
6353
|
+
}
|
|
6354
|
+
},
|
|
5966
6355
|
{
|
|
5967
6356
|
name: "BondStarted",
|
|
5968
6357
|
type: {
|
|
@@ -6116,7 +6505,7 @@ var jbond_default = {
|
|
|
6116
6505
|
}
|
|
6117
6506
|
},
|
|
6118
6507
|
{
|
|
6119
|
-
name: "
|
|
6508
|
+
name: "CollateralDeposited",
|
|
6120
6509
|
type: {
|
|
6121
6510
|
kind: "struct",
|
|
6122
6511
|
fields: [
|
|
@@ -6186,6 +6575,34 @@ var jbond_default = {
|
|
|
6186
6575
|
]
|
|
6187
6576
|
}
|
|
6188
6577
|
},
|
|
6578
|
+
{
|
|
6579
|
+
name: "CompensationBurned",
|
|
6580
|
+
type: {
|
|
6581
|
+
kind: "struct",
|
|
6582
|
+
fields: [
|
|
6583
|
+
{
|
|
6584
|
+
name: "validator",
|
|
6585
|
+
type: "pubkey"
|
|
6586
|
+
},
|
|
6587
|
+
{
|
|
6588
|
+
name: "amount",
|
|
6589
|
+
type: "u64"
|
|
6590
|
+
},
|
|
6591
|
+
{
|
|
6592
|
+
name: "post_balance",
|
|
6593
|
+
type: "u64"
|
|
6594
|
+
},
|
|
6595
|
+
{
|
|
6596
|
+
name: "epoch",
|
|
6597
|
+
type: "u64"
|
|
6598
|
+
},
|
|
6599
|
+
{
|
|
6600
|
+
name: "timestamp",
|
|
6601
|
+
type: "i64"
|
|
6602
|
+
}
|
|
6603
|
+
]
|
|
6604
|
+
}
|
|
6605
|
+
},
|
|
6189
6606
|
{
|
|
6190
6607
|
name: "CompensationClaimed",
|
|
6191
6608
|
type: {
|
|
@@ -6214,6 +6631,54 @@ var jbond_default = {
|
|
|
6214
6631
|
]
|
|
6215
6632
|
}
|
|
6216
6633
|
},
|
|
6634
|
+
{
|
|
6635
|
+
name: "FundsLocked",
|
|
6636
|
+
type: {
|
|
6637
|
+
kind: "struct",
|
|
6638
|
+
fields: [
|
|
6639
|
+
{
|
|
6640
|
+
name: "validator",
|
|
6641
|
+
type: "pubkey"
|
|
6642
|
+
},
|
|
6643
|
+
{
|
|
6644
|
+
name: "amount",
|
|
6645
|
+
type: "u64"
|
|
6646
|
+
},
|
|
6647
|
+
{
|
|
6648
|
+
name: "total_locked",
|
|
6649
|
+
type: "u64"
|
|
6650
|
+
},
|
|
6651
|
+
{
|
|
6652
|
+
name: "epoch",
|
|
6653
|
+
type: "u64"
|
|
6654
|
+
}
|
|
6655
|
+
]
|
|
6656
|
+
}
|
|
6657
|
+
},
|
|
6658
|
+
{
|
|
6659
|
+
name: "FundsUnlocked",
|
|
6660
|
+
type: {
|
|
6661
|
+
kind: "struct",
|
|
6662
|
+
fields: [
|
|
6663
|
+
{
|
|
6664
|
+
name: "validator",
|
|
6665
|
+
type: "pubkey"
|
|
6666
|
+
},
|
|
6667
|
+
{
|
|
6668
|
+
name: "amount",
|
|
6669
|
+
type: "u64"
|
|
6670
|
+
},
|
|
6671
|
+
{
|
|
6672
|
+
name: "pending_unlock",
|
|
6673
|
+
type: "u64"
|
|
6674
|
+
},
|
|
6675
|
+
{
|
|
6676
|
+
name: "epoch",
|
|
6677
|
+
type: "u64"
|
|
6678
|
+
}
|
|
6679
|
+
]
|
|
6680
|
+
}
|
|
6681
|
+
},
|
|
6217
6682
|
{
|
|
6218
6683
|
name: "GlobalConfigureData",
|
|
6219
6684
|
type: {
|
|
@@ -6234,11 +6699,71 @@ var jbond_default = {
|
|
|
6234
6699
|
kind: "struct",
|
|
6235
6700
|
fields: [
|
|
6236
6701
|
{
|
|
6237
|
-
name: "authority",
|
|
6702
|
+
name: "authority",
|
|
6703
|
+
docs: [
|
|
6704
|
+
"The authority allowed to manage the program"
|
|
6705
|
+
],
|
|
6706
|
+
type: "pubkey"
|
|
6707
|
+
},
|
|
6708
|
+
{
|
|
6709
|
+
name: "bump",
|
|
6710
|
+
docs: [
|
|
6711
|
+
"Bump for the PDA"
|
|
6712
|
+
],
|
|
6713
|
+
type: "u8"
|
|
6714
|
+
}
|
|
6715
|
+
]
|
|
6716
|
+
}
|
|
6717
|
+
},
|
|
6718
|
+
{
|
|
6719
|
+
name: "ValidatorBond",
|
|
6720
|
+
type: {
|
|
6721
|
+
kind: "struct",
|
|
6722
|
+
fields: [
|
|
6723
|
+
{
|
|
6724
|
+
name: "state",
|
|
6725
|
+
docs: [
|
|
6726
|
+
"The bond state address"
|
|
6727
|
+
],
|
|
6728
|
+
type: "pubkey"
|
|
6729
|
+
},
|
|
6730
|
+
{
|
|
6731
|
+
name: "identity",
|
|
6732
|
+
docs: [
|
|
6733
|
+
"Validator identity pubkey"
|
|
6734
|
+
],
|
|
6735
|
+
type: "pubkey"
|
|
6736
|
+
},
|
|
6737
|
+
{
|
|
6738
|
+
name: "vote_account",
|
|
6739
|
+
docs: [
|
|
6740
|
+
"Validator vote account pubkey"
|
|
6741
|
+
],
|
|
6742
|
+
type: "pubkey"
|
|
6743
|
+
},
|
|
6744
|
+
{
|
|
6745
|
+
name: "creator",
|
|
6746
|
+
docs: [
|
|
6747
|
+
"The bond creator pubkey"
|
|
6748
|
+
],
|
|
6749
|
+
type: "pubkey"
|
|
6750
|
+
},
|
|
6751
|
+
{
|
|
6752
|
+
name: "withdrawal_authority",
|
|
6753
|
+
docs: [
|
|
6754
|
+
"Optional withdrawal authority pubkey (if set, can withdraw on behalf of the validator,",
|
|
6755
|
+
"otherwise only identity can withdraw)"
|
|
6756
|
+
],
|
|
6757
|
+
type: {
|
|
6758
|
+
option: "pubkey"
|
|
6759
|
+
}
|
|
6760
|
+
},
|
|
6761
|
+
{
|
|
6762
|
+
name: "created_at",
|
|
6238
6763
|
docs: [
|
|
6239
|
-
"
|
|
6764
|
+
"Bond creation timestamp"
|
|
6240
6765
|
],
|
|
6241
|
-
type: "
|
|
6766
|
+
type: "i64"
|
|
6242
6767
|
},
|
|
6243
6768
|
{
|
|
6244
6769
|
name: "bump",
|
|
@@ -6246,21 +6771,38 @@ var jbond_default = {
|
|
|
6246
6771
|
"Bump for the PDA"
|
|
6247
6772
|
],
|
|
6248
6773
|
type: "u8"
|
|
6774
|
+
},
|
|
6775
|
+
{
|
|
6776
|
+
name: "locked",
|
|
6777
|
+
docs: [
|
|
6778
|
+
"Amount of collateral currently locked (unavailable for withdrawal)"
|
|
6779
|
+
],
|
|
6780
|
+
type: "u64"
|
|
6781
|
+
},
|
|
6782
|
+
{
|
|
6783
|
+
name: "pending_unlock",
|
|
6784
|
+
docs: [
|
|
6785
|
+
"Pending unlock amount (will reduce `locked` next epoch)"
|
|
6786
|
+
],
|
|
6787
|
+
type: "u64"
|
|
6788
|
+
},
|
|
6789
|
+
{
|
|
6790
|
+
name: "pending_unlock_epoch",
|
|
6791
|
+
docs: [
|
|
6792
|
+
"Epoch when pending_unlock was queued"
|
|
6793
|
+
],
|
|
6794
|
+
type: "u64"
|
|
6249
6795
|
}
|
|
6250
6796
|
]
|
|
6251
6797
|
}
|
|
6252
6798
|
},
|
|
6253
6799
|
{
|
|
6254
|
-
name: "
|
|
6800
|
+
name: "ValidatorBondClosed",
|
|
6255
6801
|
type: {
|
|
6256
6802
|
kind: "struct",
|
|
6257
6803
|
fields: [
|
|
6258
6804
|
{
|
|
6259
|
-
name: "
|
|
6260
|
-
type: "pubkey"
|
|
6261
|
-
},
|
|
6262
|
-
{
|
|
6263
|
-
name: "identity",
|
|
6805
|
+
name: "validator",
|
|
6264
6806
|
type: "pubkey"
|
|
6265
6807
|
},
|
|
6266
6808
|
{
|
|
@@ -6268,22 +6810,16 @@ var jbond_default = {
|
|
|
6268
6810
|
type: "pubkey"
|
|
6269
6811
|
},
|
|
6270
6812
|
{
|
|
6271
|
-
name: "
|
|
6813
|
+
name: "rent_receiver",
|
|
6272
6814
|
type: "pubkey"
|
|
6273
6815
|
},
|
|
6274
6816
|
{
|
|
6275
|
-
name: "
|
|
6276
|
-
type:
|
|
6277
|
-
option: "pubkey"
|
|
6278
|
-
}
|
|
6817
|
+
name: "final_balance",
|
|
6818
|
+
type: "u64"
|
|
6279
6819
|
},
|
|
6280
6820
|
{
|
|
6281
|
-
name: "
|
|
6821
|
+
name: "timestamp",
|
|
6282
6822
|
type: "i64"
|
|
6283
|
-
},
|
|
6284
|
-
{
|
|
6285
|
-
name: "bump",
|
|
6286
|
-
type: "u8"
|
|
6287
6823
|
}
|
|
6288
6824
|
]
|
|
6289
6825
|
}
|
|
@@ -6294,7 +6830,7 @@ var jbond_default = {
|
|
|
6294
6830
|
kind: "struct",
|
|
6295
6831
|
fields: [
|
|
6296
6832
|
{
|
|
6297
|
-
name: "
|
|
6833
|
+
name: "validator",
|
|
6298
6834
|
type: "pubkey"
|
|
6299
6835
|
},
|
|
6300
6836
|
{
|
|
@@ -6307,6 +6843,30 @@ var jbond_default = {
|
|
|
6307
6843
|
}
|
|
6308
6844
|
]
|
|
6309
6845
|
}
|
|
6846
|
+
},
|
|
6847
|
+
{
|
|
6848
|
+
name: "WithdrawAuthorityChanged",
|
|
6849
|
+
type: {
|
|
6850
|
+
kind: "struct",
|
|
6851
|
+
fields: [
|
|
6852
|
+
{
|
|
6853
|
+
name: "validator",
|
|
6854
|
+
type: "pubkey"
|
|
6855
|
+
},
|
|
6856
|
+
{
|
|
6857
|
+
name: "old_authority",
|
|
6858
|
+
type: {
|
|
6859
|
+
option: "pubkey"
|
|
6860
|
+
}
|
|
6861
|
+
},
|
|
6862
|
+
{
|
|
6863
|
+
name: "new_authority",
|
|
6864
|
+
type: {
|
|
6865
|
+
option: "pubkey"
|
|
6866
|
+
}
|
|
6867
|
+
}
|
|
6868
|
+
]
|
|
6869
|
+
}
|
|
6310
6870
|
}
|
|
6311
6871
|
],
|
|
6312
6872
|
constants: [
|
|
@@ -6365,6 +6925,22 @@ function bondTypeToAnchor(type, payload) {
|
|
|
6365
6925
|
function anchorToBondType(variant) {
|
|
6366
6926
|
return fromAnchor(variant);
|
|
6367
6927
|
}
|
|
6928
|
+
async function getStakePoolAccountData(connection, stakePoolAddress) {
|
|
6929
|
+
const stakePoolAccount = await getStakePoolAccount(connection, stakePoolAddress);
|
|
6930
|
+
if (!stakePoolAccount) {
|
|
6931
|
+
throw new Error(`Stake pool account not found: ${stakePoolAddress.toBase58()}`);
|
|
6932
|
+
}
|
|
6933
|
+
return stakePoolAccount.account.data;
|
|
6934
|
+
}
|
|
6935
|
+
function lamportsToPoolTokenLamports(lamports, stakePool) {
|
|
6936
|
+
if (stakePool.totalLamports.isZero()) {
|
|
6937
|
+
throw new Error("Stake pool has zero total lamports");
|
|
6938
|
+
}
|
|
6939
|
+
if (stakePool.poolTokenSupply.isZero()) {
|
|
6940
|
+
throw new Error("Stake pool has zero pool token supply");
|
|
6941
|
+
}
|
|
6942
|
+
return lamports.mul(stakePool.poolTokenSupply).div(stakePool.totalLamports);
|
|
6943
|
+
}
|
|
6368
6944
|
|
|
6369
6945
|
// src/utils/wallet.ts
|
|
6370
6946
|
function isVersionedTransaction(tx) {
|
|
@@ -6397,6 +6973,20 @@ var NodeWallet = class {
|
|
|
6397
6973
|
}
|
|
6398
6974
|
};
|
|
6399
6975
|
var SOL_DECIMALS = Math.log10(LAMPORTS_PER_SOL);
|
|
6976
|
+
function lamportsToSol(lamports) {
|
|
6977
|
+
if (typeof lamports === "number") {
|
|
6978
|
+
return Math.abs(lamports) / LAMPORTS_PER_SOL;
|
|
6979
|
+
}
|
|
6980
|
+
let signMultiplier = 1;
|
|
6981
|
+
if (lamports.isNeg()) {
|
|
6982
|
+
signMultiplier = -1;
|
|
6983
|
+
}
|
|
6984
|
+
const absLamports = lamports.abs();
|
|
6985
|
+
const lamportsString = absLamports.toString(10).padStart(10, "0");
|
|
6986
|
+
const splitIndex = lamportsString.length - SOL_DECIMALS;
|
|
6987
|
+
const solString = `${lamportsString.slice(0, splitIndex)}.${lamportsString.slice(splitIndex)}`;
|
|
6988
|
+
return signMultiplier * Number.parseFloat(solString);
|
|
6989
|
+
}
|
|
6400
6990
|
function solToLamports(amount) {
|
|
6401
6991
|
if (Number.isNaN(amount)) {
|
|
6402
6992
|
return new BN(0);
|
|
@@ -6417,20 +7007,13 @@ function getBondTypeSeed(type) {
|
|
|
6417
7007
|
}
|
|
6418
7008
|
|
|
6419
7009
|
// src/client.ts
|
|
6420
|
-
var JBondClientEnv = /* @__PURE__ */ ((JBondClientEnv2) => {
|
|
6421
|
-
JBondClientEnv2["DEV"] = "dev";
|
|
6422
|
-
JBondClientEnv2["STAGE"] = "stage";
|
|
6423
|
-
JBondClientEnv2["PROD"] = "prod";
|
|
6424
|
-
return JBondClientEnv2;
|
|
6425
|
-
})(JBondClientEnv || {});
|
|
6426
7010
|
var JBondClient = class _JBondClient {
|
|
6427
7011
|
constructor(provider, options) {
|
|
6428
7012
|
this.provider = provider;
|
|
6429
7013
|
this.options = options ?? {};
|
|
6430
|
-
this.program = new Program(jbond_default, this.provider);
|
|
6431
7014
|
}
|
|
6432
7015
|
options;
|
|
6433
|
-
|
|
7016
|
+
_program = null;
|
|
6434
7017
|
get history() {
|
|
6435
7018
|
return new HistoryManager(this);
|
|
6436
7019
|
}
|
|
@@ -6459,11 +7042,24 @@ var JBondClient = class _JBondClient {
|
|
|
6459
7042
|
static fromKeypair(connection, keypair, options) {
|
|
6460
7043
|
return _JBondClient.fromWallet(connection, new NodeWallet(keypair), options);
|
|
6461
7044
|
}
|
|
7045
|
+
/**
|
|
7046
|
+
* Get or create the program instance
|
|
7047
|
+
*/
|
|
7048
|
+
get program() {
|
|
7049
|
+
if (!this._program) {
|
|
7050
|
+
jbond_default.address = this.programId.toBase58();
|
|
7051
|
+
this._program = new Program(jbond_default, this.provider);
|
|
7052
|
+
}
|
|
7053
|
+
return this._program;
|
|
7054
|
+
}
|
|
6462
7055
|
/**
|
|
6463
7056
|
* Get the current program ID.
|
|
6464
7057
|
*/
|
|
6465
7058
|
get programId() {
|
|
6466
|
-
|
|
7059
|
+
if (this.options.programId) {
|
|
7060
|
+
return this.options.programId;
|
|
7061
|
+
}
|
|
7062
|
+
return new PublicKey(ENV_PROGRAM_ID["prod" /* PROD */]);
|
|
6467
7063
|
}
|
|
6468
7064
|
/**
|
|
6469
7065
|
* Get the current connection.
|
|
@@ -6475,13 +7071,22 @@ var JBondClient = class _JBondClient {
|
|
|
6475
7071
|
* Set the environment.
|
|
6476
7072
|
*/
|
|
6477
7073
|
env(env) {
|
|
6478
|
-
|
|
7074
|
+
const envProgramId = ENV_PROGRAM_ID[env];
|
|
7075
|
+
if (!envProgramId) {
|
|
7076
|
+
throw new Error(`Invalid environment: ${env}`);
|
|
7077
|
+
}
|
|
7078
|
+
this._program = null;
|
|
7079
|
+
this.debug(`Set environment to ${env} with program ID: ${envProgramId.toString()}`);
|
|
7080
|
+
return this.configure("programId", new PublicKey(envProgramId));
|
|
6479
7081
|
}
|
|
6480
7082
|
/**
|
|
6481
7083
|
* Configure a specific option.
|
|
6482
7084
|
*/
|
|
6483
7085
|
configure(key, val) {
|
|
6484
7086
|
this.options[key] = val;
|
|
7087
|
+
if (key === "programId") {
|
|
7088
|
+
this._program = null;
|
|
7089
|
+
}
|
|
6485
7090
|
return this;
|
|
6486
7091
|
}
|
|
6487
7092
|
/**
|
|
@@ -6540,8 +7145,8 @@ var JBondClient = class _JBondClient {
|
|
|
6540
7145
|
* Top up collateral
|
|
6541
7146
|
*/
|
|
6542
7147
|
async topUpCollateral(props) {
|
|
6543
|
-
const
|
|
6544
|
-
return this.provider.sendAndConfirm?.(new Transaction().add(...
|
|
7148
|
+
const { instructions, signers } = await this.getTopUpIxs(props);
|
|
7149
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(...instructions), signers);
|
|
6545
7150
|
}
|
|
6546
7151
|
/**
|
|
6547
7152
|
* Withdraw collateral
|
|
@@ -6551,7 +7156,14 @@ var JBondClient = class _JBondClient {
|
|
|
6551
7156
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6552
7157
|
}
|
|
6553
7158
|
/**
|
|
6554
|
-
*
|
|
7159
|
+
* Migrate SOL collateral from one bond account to JSOL collateral in another bond account
|
|
7160
|
+
*/
|
|
7161
|
+
async migrateBond(props) {
|
|
7162
|
+
const { instructions, signers } = await this.getMigrateBondIx(props);
|
|
7163
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(...instructions), signers);
|
|
7164
|
+
}
|
|
7165
|
+
/**
|
|
7166
|
+
* Claim compensation for a validator
|
|
6555
7167
|
*/
|
|
6556
7168
|
async claimCompensation(props) {
|
|
6557
7169
|
const ix = await this.getClaimIx(props);
|
|
@@ -6592,6 +7204,14 @@ var JBondClient = class _JBondClient {
|
|
|
6592
7204
|
const ix = await this.getBondSessionFinishIx(props);
|
|
6593
7205
|
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
6594
7206
|
}
|
|
7207
|
+
async bondRemove(props) {
|
|
7208
|
+
const ix = await this.getBondRemoveIx(props);
|
|
7209
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7210
|
+
}
|
|
7211
|
+
async closeValidatorBond(props) {
|
|
7212
|
+
const ix = await this.getCloseValidatorBondIx(props);
|
|
7213
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7214
|
+
}
|
|
6595
7215
|
/**
|
|
6596
7216
|
* Build global state initialize instruction
|
|
6597
7217
|
*/
|
|
@@ -6702,6 +7322,9 @@ var JBondClient = class _JBondClient {
|
|
|
6702
7322
|
collateralType = bondState2.collateralType;
|
|
6703
7323
|
}
|
|
6704
7324
|
const instructions = [];
|
|
7325
|
+
const signers = [];
|
|
7326
|
+
const amountLamports = solToLamports(amount);
|
|
7327
|
+
let topUpAmount = amountLamports;
|
|
6705
7328
|
try {
|
|
6706
7329
|
await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
|
|
6707
7330
|
} catch {
|
|
@@ -6733,10 +7356,33 @@ var JBondClient = class _JBondClient {
|
|
|
6733
7356
|
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6734
7357
|
}
|
|
6735
7358
|
});
|
|
7359
|
+
if (props.solUsage) {
|
|
7360
|
+
let usesJsolCollateral = false;
|
|
7361
|
+
matchVariant(collateralType, {
|
|
7362
|
+
token: (mint) => {
|
|
7363
|
+
usesJsolCollateral = mint.equals(JSOL_MINT);
|
|
7364
|
+
}
|
|
7365
|
+
});
|
|
7366
|
+
if (usesJsolCollateral) {
|
|
7367
|
+
const stakePool = await getStakePoolAccountData(this.connection, JPOOL_POOL_ADDRESS);
|
|
7368
|
+
const deposit = await depositSol(
|
|
7369
|
+
this.connection,
|
|
7370
|
+
JPOOL_POOL_ADDRESS,
|
|
7371
|
+
payer,
|
|
7372
|
+
amountLamports.toNumber(),
|
|
7373
|
+
void 0,
|
|
7374
|
+
void 0,
|
|
7375
|
+
void 0
|
|
7376
|
+
);
|
|
7377
|
+
instructions.push(...deposit.instructions);
|
|
7378
|
+
signers.push(...deposit.signers);
|
|
7379
|
+
topUpAmount = lamportsToPoolTokenLamports(amountLamports, stakePool);
|
|
7380
|
+
}
|
|
7381
|
+
}
|
|
6736
7382
|
instructions.push(
|
|
6737
|
-
await this.program.methods.bondTopUp(
|
|
7383
|
+
await this.program.methods.bondTopUp(topUpAmount).accountsPartial(accounts).instruction()
|
|
6738
7384
|
);
|
|
6739
|
-
return instructions;
|
|
7385
|
+
return { instructions, signers };
|
|
6740
7386
|
}
|
|
6741
7387
|
/**
|
|
6742
7388
|
* Build withdraw collateral instruction
|
|
@@ -6775,6 +7421,139 @@ var JBondClient = class _JBondClient {
|
|
|
6775
7421
|
});
|
|
6776
7422
|
return this.program.methods.bondWithdraw(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
6777
7423
|
}
|
|
7424
|
+
/**
|
|
7425
|
+
* Build instructions for migrating SOL bond collateral into JSOL bond collateral in a single transaction
|
|
7426
|
+
*/
|
|
7427
|
+
async getMigrateBondIx(props) {
|
|
7428
|
+
const {
|
|
7429
|
+
bondType,
|
|
7430
|
+
voteAccount,
|
|
7431
|
+
identity,
|
|
7432
|
+
withdrawName = "performance",
|
|
7433
|
+
topUpName = "perf",
|
|
7434
|
+
stakePoolAddress = JPOOL_POOL_ADDRESS
|
|
7435
|
+
} = props;
|
|
7436
|
+
const payer = props.payer ?? this.provider.wallet?.publicKey;
|
|
7437
|
+
const destination = props.destination ?? payer;
|
|
7438
|
+
if (!payer || !destination) {
|
|
7439
|
+
throw new Error("Missing payer/destination");
|
|
7440
|
+
}
|
|
7441
|
+
const withdrawBondState = await this.getBondState(bondType, withdrawName);
|
|
7442
|
+
await matchVariant(withdrawBondState.collateralType, {
|
|
7443
|
+
native: () => {
|
|
7444
|
+
},
|
|
7445
|
+
token: () => {
|
|
7446
|
+
throw new Error("Withdraw bond collateral type must be native SOL for migration");
|
|
7447
|
+
}
|
|
7448
|
+
});
|
|
7449
|
+
const availableLamports = await this.getAvailableCollateral(bondType, withdrawName, voteAccount);
|
|
7450
|
+
if (!availableLamports || availableLamports <= 0) {
|
|
7451
|
+
throw new Error("No available balance to migrate");
|
|
7452
|
+
}
|
|
7453
|
+
const amount = lamportsToSol(availableLamports);
|
|
7454
|
+
const amountLamports = solToLamports(amount);
|
|
7455
|
+
const withdrawIx = await this.getWithdrawIx({
|
|
7456
|
+
bondType,
|
|
7457
|
+
name: withdrawName,
|
|
7458
|
+
amount,
|
|
7459
|
+
voteAccount,
|
|
7460
|
+
destination,
|
|
7461
|
+
withdrawalAuthority: props.withdrawalAuthority
|
|
7462
|
+
});
|
|
7463
|
+
const deposit = await this.getDepositSolIxsWithoutBalanceCheck(
|
|
7464
|
+
stakePoolAddress,
|
|
7465
|
+
payer,
|
|
7466
|
+
amountLamports.toNumber()
|
|
7467
|
+
);
|
|
7468
|
+
const topUpBondState = await this.getBondState(bondType, topUpName);
|
|
7469
|
+
const topUpCollateralType = topUpBondState.collateralType;
|
|
7470
|
+
const instructions = [withdrawIx, ...deposit.instructions];
|
|
7471
|
+
const signers = [...deposit.signers];
|
|
7472
|
+
try {
|
|
7473
|
+
await this.getValidatorBond(bondType, topUpName, voteAccount);
|
|
7474
|
+
} catch {
|
|
7475
|
+
instructions.push(
|
|
7476
|
+
await this.getRegisterValidatorIx({
|
|
7477
|
+
bondType,
|
|
7478
|
+
name: topUpName,
|
|
7479
|
+
voteAccount,
|
|
7480
|
+
identity,
|
|
7481
|
+
creator: payer,
|
|
7482
|
+
collateralType: topUpCollateralType
|
|
7483
|
+
})
|
|
7484
|
+
);
|
|
7485
|
+
}
|
|
7486
|
+
const [topUpBondStateAddress] = this.pda.bondState(bondType, topUpName);
|
|
7487
|
+
const [topUpValidatorBond] = this.pda.validatorBond(bondType, topUpName, voteAccount);
|
|
7488
|
+
await matchVariant(topUpCollateralType, {
|
|
7489
|
+
native: () => {
|
|
7490
|
+
throw new Error("Top up bond collateral type must be token for migration");
|
|
7491
|
+
},
|
|
7492
|
+
token: async (mint) => {
|
|
7493
|
+
const stakePool = await getStakePoolAccountData(this.connection, stakePoolAddress);
|
|
7494
|
+
const topUpAmount = lamportsToPoolTokenLamports(amountLamports, stakePool);
|
|
7495
|
+
const topUpIx = await this.program.methods.bondTopUp(topUpAmount).accountsPartial({
|
|
7496
|
+
bondState: topUpBondStateAddress,
|
|
7497
|
+
validatorBond: topUpValidatorBond,
|
|
7498
|
+
payer,
|
|
7499
|
+
payerTokenAccount: getAssociatedTokenAddressSync(mint, payer),
|
|
7500
|
+
bondTokenAccount: getAssociatedTokenAddressSync(mint, topUpValidatorBond, true),
|
|
7501
|
+
stakeAccount: null,
|
|
7502
|
+
stakeProgram: null
|
|
7503
|
+
}).instruction();
|
|
7504
|
+
instructions.push(topUpIx);
|
|
7505
|
+
}
|
|
7506
|
+
});
|
|
7507
|
+
return { instructions, signers };
|
|
7508
|
+
}
|
|
7509
|
+
/**
|
|
7510
|
+
* Build stake-pool SOL deposit instructions without pre-checking payer balance.
|
|
7511
|
+
* This allows composing withdraw->deposit in a single transaction where SOL is obtained by the prior instruction.
|
|
7512
|
+
*/
|
|
7513
|
+
async getDepositSolIxsWithoutBalanceCheck(stakePoolAddress, payer, lamports, destinationTokenAccount, referrerTokenAccount, depositAuthority) {
|
|
7514
|
+
const stakePool = await getStakePoolAccountData(this.connection, stakePoolAddress);
|
|
7515
|
+
const transferSigner = new Keypair();
|
|
7516
|
+
const signers = [transferSigner];
|
|
7517
|
+
const instructions = [
|
|
7518
|
+
SystemProgram.transfer({
|
|
7519
|
+
fromPubkey: payer,
|
|
7520
|
+
toPubkey: transferSigner.publicKey,
|
|
7521
|
+
lamports
|
|
7522
|
+
})
|
|
7523
|
+
];
|
|
7524
|
+
let destinationPoolAccount = destinationTokenAccount;
|
|
7525
|
+
if (!destinationPoolAccount) {
|
|
7526
|
+
const associatedAddress = getAssociatedTokenAddressSync(stakePool.poolMint, payer);
|
|
7527
|
+
instructions.push(
|
|
7528
|
+
createAssociatedTokenAccountIdempotentInstruction(
|
|
7529
|
+
payer,
|
|
7530
|
+
associatedAddress,
|
|
7531
|
+
payer,
|
|
7532
|
+
stakePool.poolMint
|
|
7533
|
+
)
|
|
7534
|
+
);
|
|
7535
|
+
destinationPoolAccount = associatedAddress;
|
|
7536
|
+
}
|
|
7537
|
+
const [withdrawAuthority] = PublicKey.findProgramAddressSync(
|
|
7538
|
+
[stakePoolAddress.toBuffer(), Buffer.from("withdraw")],
|
|
7539
|
+
STAKE_POOL_PROGRAM_ID
|
|
7540
|
+
);
|
|
7541
|
+
instructions.push(
|
|
7542
|
+
StakePoolInstruction.depositSol({
|
|
7543
|
+
stakePool: stakePoolAddress,
|
|
7544
|
+
reserveStake: stakePool.reserveStake,
|
|
7545
|
+
fundingAccount: transferSigner.publicKey,
|
|
7546
|
+
destinationPoolAccount,
|
|
7547
|
+
managerFeeAccount: stakePool.managerFeeAccount,
|
|
7548
|
+
referralPoolAccount: referrerTokenAccount ?? destinationPoolAccount,
|
|
7549
|
+
poolMint: stakePool.poolMint,
|
|
7550
|
+
lamports,
|
|
7551
|
+
withdrawAuthority,
|
|
7552
|
+
depositAuthority
|
|
7553
|
+
})
|
|
7554
|
+
);
|
|
7555
|
+
return { instructions, signers };
|
|
7556
|
+
}
|
|
6778
7557
|
/**
|
|
6779
7558
|
* Build claim instruction
|
|
6780
7559
|
*/
|
|
@@ -6805,13 +7584,47 @@ var JBondClient = class _JBondClient {
|
|
|
6805
7584
|
native: () => {
|
|
6806
7585
|
},
|
|
6807
7586
|
token: (mint) => {
|
|
6808
|
-
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6809
7587
|
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6810
|
-
|
|
7588
|
+
if (reserve.equals(mint)) {
|
|
7589
|
+
accounts.reserveTokenAccount = null;
|
|
7590
|
+
accounts.destinationTokenAccount = null;
|
|
7591
|
+
} else {
|
|
7592
|
+
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
7593
|
+
accounts.reserveTokenAccount = getAssociatedTokenAddressSync(mint, reserve, true);
|
|
7594
|
+
}
|
|
6811
7595
|
}
|
|
6812
7596
|
});
|
|
6813
7597
|
return this.program.methods.bondClaim(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
6814
7598
|
}
|
|
7599
|
+
/**
|
|
7600
|
+
* Build claim all compensations instructions
|
|
7601
|
+
*/
|
|
7602
|
+
async getClaimAllCompensationsIxs(props) {
|
|
7603
|
+
const ixs = [];
|
|
7604
|
+
const validatorBondBalances = await this.getBondStateValidatorBondBalances(
|
|
7605
|
+
props.bondType,
|
|
7606
|
+
props.name
|
|
7607
|
+
);
|
|
7608
|
+
for (const bond_balance of validatorBondBalances) {
|
|
7609
|
+
const amountToClaim = lamportsToSol(bond_balance.balance);
|
|
7610
|
+
if (amountToClaim <= 0) {
|
|
7611
|
+
this.debug("No balance to claim for validator:", bond_balance.voteAccount.toBase58());
|
|
7612
|
+
continue;
|
|
7613
|
+
}
|
|
7614
|
+
this.debug("Amount to claim:", amountToClaim);
|
|
7615
|
+
const ix = await this.getClaimIx({
|
|
7616
|
+
bondType: props.bondType,
|
|
7617
|
+
name: props.name,
|
|
7618
|
+
amount: amountToClaim,
|
|
7619
|
+
collateralType: props.collateralType,
|
|
7620
|
+
reserve: props.reserve,
|
|
7621
|
+
authority: props.authority,
|
|
7622
|
+
voteAccount: bond_balance.voteAccount
|
|
7623
|
+
});
|
|
7624
|
+
ixs.push(ix);
|
|
7625
|
+
}
|
|
7626
|
+
return ixs;
|
|
7627
|
+
}
|
|
6815
7628
|
/**
|
|
6816
7629
|
* Build set withdraw authority instruction
|
|
6817
7630
|
*/
|
|
@@ -6840,23 +7653,150 @@ var JBondClient = class _JBondClient {
|
|
|
6840
7653
|
const authority = this.provider.wallet?.publicKey;
|
|
6841
7654
|
return this.program.methods.sessionStart(new import_bn.BN(props.duration)).accountsPartial({ bondState, authority }).instruction();
|
|
6842
7655
|
}
|
|
7656
|
+
async lockFunds(props) {
|
|
7657
|
+
const ix = await this.getLockFundsIx(props);
|
|
7658
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7659
|
+
}
|
|
7660
|
+
async releaseFunds(props) {
|
|
7661
|
+
const ix = await this.getReleaseFundsIx(props);
|
|
7662
|
+
return this.provider.sendAndConfirm?.(new Transaction().add(ix));
|
|
7663
|
+
}
|
|
7664
|
+
/**
|
|
7665
|
+
* Build bond remove instruction
|
|
7666
|
+
*/
|
|
7667
|
+
async getBondRemoveIx(props) {
|
|
7668
|
+
const { bondType, name } = props;
|
|
7669
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7670
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
7671
|
+
return this.program.methods.bondRemove().accountsPartial({ bondState, authority }).instruction();
|
|
7672
|
+
}
|
|
7673
|
+
/**
|
|
7674
|
+
* Build close validator bond instruction
|
|
7675
|
+
*/
|
|
7676
|
+
async getCloseValidatorBondIx(props) {
|
|
7677
|
+
const { bondType, name, voteAccount } = props;
|
|
7678
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7679
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7680
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
7681
|
+
const rentReceiver = props.rentReceiver ?? authority;
|
|
7682
|
+
if (!authority || !rentReceiver) {
|
|
7683
|
+
throw new Error("Missing authority or rentReceiver");
|
|
7684
|
+
}
|
|
7685
|
+
let collateralType = props.collateralType;
|
|
7686
|
+
if (!collateralType) {
|
|
7687
|
+
const state = await this.getBondState(bondType, name);
|
|
7688
|
+
collateralType = state.collateralType;
|
|
7689
|
+
}
|
|
7690
|
+
const accounts = {
|
|
7691
|
+
bondState,
|
|
7692
|
+
validatorBond,
|
|
7693
|
+
authority,
|
|
7694
|
+
rentReceiver,
|
|
7695
|
+
bondTokenAccount: null,
|
|
7696
|
+
destinationTokenAccount: null
|
|
7697
|
+
};
|
|
7698
|
+
matchVariant(collateralType, {
|
|
7699
|
+
native: () => {
|
|
7700
|
+
},
|
|
7701
|
+
token: (mint) => {
|
|
7702
|
+
accounts.bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7703
|
+
accounts.destinationTokenAccount = getAssociatedTokenAddressSync(mint, rentReceiver, true);
|
|
7704
|
+
}
|
|
7705
|
+
});
|
|
7706
|
+
return this.program.methods.closeValidatorBond().accountsPartial(accounts).instruction();
|
|
7707
|
+
}
|
|
7708
|
+
/**
|
|
7709
|
+
* Build test set last update epoch instruction
|
|
7710
|
+
* NOTE!: This instruction is for testing purposes only.
|
|
7711
|
+
* It allows direct manipulation of the validator bond's last epoch update.
|
|
7712
|
+
* This should not be used in production environments.
|
|
7713
|
+
*/
|
|
7714
|
+
// async getTestSetLastUpdateEpochIx(props: { bondType: BondType, bondName: string, voteAccount: PublicKeyInitData, payer: PublicKey, epoch: number }) {
|
|
7715
|
+
// const { bondType, bondName, voteAccount, payer, epoch } = props
|
|
7716
|
+
// const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount)
|
|
7717
|
+
// return this.program.methods
|
|
7718
|
+
// .testSetLastUpdateEpoch(new BN(epoch))
|
|
7719
|
+
// .accountsPartial({ validatorBond, payer })
|
|
7720
|
+
// .instruction()
|
|
7721
|
+
// }
|
|
7722
|
+
/**
|
|
7723
|
+
* Build lock funds instruction
|
|
7724
|
+
*/
|
|
7725
|
+
async getLockFundsIx(props) {
|
|
7726
|
+
const { bondType, name, voteAccount, amount, withdrawAuthority } = props;
|
|
7727
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7728
|
+
let collateralType = props.collateralType;
|
|
7729
|
+
if (!collateralType) {
|
|
7730
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
7731
|
+
collateralType = bondState2.collateralType;
|
|
7732
|
+
}
|
|
7733
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7734
|
+
const accounts = {
|
|
7735
|
+
bondState,
|
|
7736
|
+
validatorBond,
|
|
7737
|
+
payer: withdrawAuthority,
|
|
7738
|
+
bondTokenAccount: null
|
|
7739
|
+
};
|
|
7740
|
+
matchVariant(collateralType, {
|
|
7741
|
+
native: () => {
|
|
7742
|
+
},
|
|
7743
|
+
token: (mint) => {
|
|
7744
|
+
const bondTokenAccount = getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7745
|
+
accounts.bondTokenAccount = bondTokenAccount;
|
|
7746
|
+
}
|
|
7747
|
+
});
|
|
7748
|
+
return this.program.methods.bondLockFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7749
|
+
}
|
|
7750
|
+
/**
|
|
7751
|
+
* Build release funds instruction
|
|
7752
|
+
*/
|
|
7753
|
+
async getReleaseFundsIx(props) {
|
|
7754
|
+
const { bondType, name, voteAccount, amount, withdrawAuthority } = props;
|
|
7755
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7756
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7757
|
+
const accounts = {
|
|
7758
|
+
bondState,
|
|
7759
|
+
validatorBond,
|
|
7760
|
+
payer: withdrawAuthority
|
|
7761
|
+
};
|
|
7762
|
+
return this.program.methods.bondReleaseFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7763
|
+
}
|
|
7764
|
+
/**
|
|
7765
|
+
* Get available collateral for withdrawal (taking into account locked funds)
|
|
7766
|
+
*/
|
|
7767
|
+
async getAvailableCollateral(bondType, bondName, voteAccount) {
|
|
7768
|
+
const validatorBond = await this.getValidatorBond(bondType, bondName, voteAccount);
|
|
7769
|
+
return await this.getValidatorBondBalance(bondType, bondName, voteAccount) - validatorBond.locked.toNumber();
|
|
7770
|
+
}
|
|
6843
7771
|
/**
|
|
6844
7772
|
* Get all bond states with total collected collateral
|
|
6845
7773
|
*/
|
|
6846
|
-
async getAllBondStates(bondType, sessionStatus) {
|
|
6847
|
-
const
|
|
7774
|
+
async getAllBondStates(bondType, sessionStatus, options) {
|
|
7775
|
+
const includeStats = options?.includeStats ?? true;
|
|
7776
|
+
const targetBondType = bondTypeToAnchor(bondType);
|
|
6848
7777
|
const accounts = await this.program.account.bondState.all();
|
|
6849
|
-
|
|
6850
|
-
if (!sameVariant(account.bondType,
|
|
6851
|
-
|
|
7778
|
+
const filteredAccounts = accounts.filter(({ account }) => {
|
|
7779
|
+
if (!sameVariant(account.bondType, targetBondType)) {
|
|
7780
|
+
return false;
|
|
6852
7781
|
}
|
|
6853
7782
|
if (sessionStatus !== void 0 && this.getBondStateSessionStatus(account) !== sessionStatus) {
|
|
6854
|
-
|
|
7783
|
+
return false;
|
|
6855
7784
|
}
|
|
6856
|
-
|
|
6857
|
-
|
|
7785
|
+
return true;
|
|
7786
|
+
});
|
|
7787
|
+
if (!includeStats) {
|
|
7788
|
+
return filteredAccounts.map(({ publicKey, account }) => ({
|
|
7789
|
+
publicKey,
|
|
7790
|
+
bondState: account,
|
|
7791
|
+
stateStats: null
|
|
7792
|
+
}));
|
|
6858
7793
|
}
|
|
6859
|
-
return
|
|
7794
|
+
return Promise.all(
|
|
7795
|
+
filteredAccounts.map(async ({ publicKey, account }) => {
|
|
7796
|
+
const stateStats = await this.getBondStateStats(account);
|
|
7797
|
+
return { publicKey, bondState: account, stateStats };
|
|
7798
|
+
})
|
|
7799
|
+
);
|
|
6860
7800
|
}
|
|
6861
7801
|
/**
|
|
6862
7802
|
* Fetch global state or throw if not found
|
|
@@ -6877,16 +7817,28 @@ var JBondClient = class _JBondClient {
|
|
|
6877
7817
|
return { publicKey, ...data };
|
|
6878
7818
|
}
|
|
6879
7819
|
/**
|
|
6880
|
-
* Fetch validator bond data or
|
|
7820
|
+
* Fetch validator bond data or error if not found
|
|
6881
7821
|
*/
|
|
6882
7822
|
async getValidatorBond(bondType, bondName, vote) {
|
|
6883
7823
|
const [publicKey] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
7824
|
+
this.debug(`Fetching validator bond ${publicKey}...`);
|
|
6884
7825
|
const data = await this.program.account.validatorBond.fetch(publicKey);
|
|
6885
7826
|
return { publicKey, ...data };
|
|
6886
7827
|
}
|
|
6887
7828
|
/**
|
|
6888
|
-
*
|
|
6889
|
-
|
|
7829
|
+
* Fetch validator bond data or null if not found
|
|
7830
|
+
*/
|
|
7831
|
+
async getValidatorBondNullable(bondType, bondName, vote) {
|
|
7832
|
+
const [publicKey] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
7833
|
+
this.debug(`Fetching validator bond ${publicKey}...`);
|
|
7834
|
+
const data = await this.program.account.validatorBond.fetchNullable(publicKey);
|
|
7835
|
+
if (!data) {
|
|
7836
|
+
return null;
|
|
7837
|
+
}
|
|
7838
|
+
return { publicKey, ...data };
|
|
7839
|
+
}
|
|
7840
|
+
/**
|
|
7841
|
+
* Get validator bond account balance (in SOL)
|
|
6890
7842
|
*/
|
|
6891
7843
|
async getValidatorBondBalance(bondType, bondName, vote) {
|
|
6892
7844
|
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
@@ -6898,8 +7850,8 @@ var JBondClient = class _JBondClient {
|
|
|
6898
7850
|
if (!accountInfo) {
|
|
6899
7851
|
return 0;
|
|
6900
7852
|
}
|
|
6901
|
-
const {
|
|
6902
|
-
const rentExempt = await this.
|
|
7853
|
+
const { lamports } = accountInfo;
|
|
7854
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
6903
7855
|
return Math.max(0, lamports - rentExempt);
|
|
6904
7856
|
},
|
|
6905
7857
|
token: async (mint) => {
|
|
@@ -6913,12 +7865,13 @@ var JBondClient = class _JBondClient {
|
|
|
6913
7865
|
}
|
|
6914
7866
|
});
|
|
6915
7867
|
}
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
7868
|
+
async getBondStateValidatorBondBalances(bondType, bondName, bondState) {
|
|
7869
|
+
const state = bondState ?? await this.getBondState(bondType, bondName);
|
|
7870
|
+
const collateralType = state.collateralType;
|
|
7871
|
+
const validatorBonds = await this.getValidatorBondsForState(bondType, bondName);
|
|
7872
|
+
if (!validatorBonds.length) {
|
|
7873
|
+
return [];
|
|
7874
|
+
}
|
|
6922
7875
|
const chunk = (arr, n = 100) => {
|
|
6923
7876
|
const res = [];
|
|
6924
7877
|
for (let i = 0; i < arr.length; i += n) {
|
|
@@ -6928,76 +7881,79 @@ var JBondClient = class _JBondClient {
|
|
|
6928
7881
|
};
|
|
6929
7882
|
return await matchVariant(collateralType, {
|
|
6930
7883
|
native: async () => {
|
|
6931
|
-
const addresses =
|
|
6932
|
-
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
6933
|
-
return address;
|
|
6934
|
-
});
|
|
7884
|
+
const addresses = validatorBonds.map((vb) => vb.publicKey);
|
|
6935
7885
|
const accountInfos = await this.connection.getMultipleAccountsInfo(addresses);
|
|
6936
|
-
const
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
const { lamports } = accountInfo;
|
|
6942
|
-
return lamports;
|
|
6943
|
-
})
|
|
6944
|
-
);
|
|
6945
|
-
return balances.reduce((sum, v) => sum + v, 0);
|
|
7886
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
7887
|
+
return validatorBonds.map((vb, idx) => ({
|
|
7888
|
+
voteAccount: vb.voteAccount,
|
|
7889
|
+
balance: Math.max(0, (accountInfos[idx]?.lamports ?? 0) - rentExempt)
|
|
7890
|
+
}));
|
|
6946
7891
|
},
|
|
6947
7892
|
token: async (mint) => {
|
|
6948
|
-
const
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
});
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
for (const part of chunk(tokenAccounts, 100)) {
|
|
6957
|
-
const infos = await this.connection.getMultipleAccountsInfo(part).catch(() => []);
|
|
6958
|
-
for (let i = 0; i < infos.length; i++) {
|
|
7893
|
+
const items = validatorBonds.map((vb) => ({
|
|
7894
|
+
voteAccount: vb.voteAccount,
|
|
7895
|
+
tokenAccount: getAssociatedTokenAddressSync(mint, vb.publicKey, true)
|
|
7896
|
+
}));
|
|
7897
|
+
const balances = [];
|
|
7898
|
+
for (const part of chunk(items, 100)) {
|
|
7899
|
+
const infos = await this.connection.getMultipleAccountsInfo(part.map((i) => i.tokenAccount)).catch(() => []);
|
|
7900
|
+
for (let i = 0; i < part.length; i++) {
|
|
6959
7901
|
const info = infos[i];
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
if (info.data.length !== ACCOUNT_SIZE) {
|
|
7902
|
+
const voteAccount = part[i].voteAccount;
|
|
7903
|
+
if (!info || info.data.length !== ACCOUNT_SIZE) {
|
|
7904
|
+
balances.push({ voteAccount, balance: 0 });
|
|
6964
7905
|
continue;
|
|
6965
7906
|
}
|
|
6966
7907
|
try {
|
|
6967
7908
|
const acc = AccountLayout.decode(info.data);
|
|
6968
7909
|
const raw = BigInt(acc.amount.toString());
|
|
6969
|
-
|
|
7910
|
+
const asNumber = Number(raw);
|
|
7911
|
+
balances.push({
|
|
7912
|
+
voteAccount,
|
|
7913
|
+
balance: Number.isFinite(asNumber) ? asNumber : Number.MAX_SAFE_INTEGER
|
|
7914
|
+
});
|
|
6970
7915
|
} catch {
|
|
7916
|
+
balances.push({ voteAccount, balance: 0 });
|
|
6971
7917
|
}
|
|
6972
7918
|
}
|
|
6973
7919
|
}
|
|
6974
|
-
|
|
6975
|
-
return Number.isFinite(asNumber) ? asNumber : Number.MAX_SAFE_INTEGER;
|
|
7920
|
+
return balances;
|
|
6976
7921
|
}
|
|
6977
7922
|
});
|
|
6978
7923
|
}
|
|
7924
|
+
/**
|
|
7925
|
+
* Get total collected collateral for a bond state
|
|
7926
|
+
*/
|
|
7927
|
+
async getBondStateTotalCollected(bondType, bondName, bondState) {
|
|
7928
|
+
const allBalances = await this.getBondStateValidatorBondBalances(bondType, bondName, bondState);
|
|
7929
|
+
return allBalances.reduce((sum, vb) => sum + vb.balance, 0);
|
|
7930
|
+
}
|
|
6979
7931
|
/**
|
|
6980
7932
|
* Get bond state stats
|
|
6981
7933
|
* @param state
|
|
6982
|
-
* @private
|
|
6983
7934
|
*/
|
|
6984
7935
|
async getBondStateStats(state) {
|
|
6985
7936
|
const bondType = anchorToBondType(state.bondType);
|
|
6986
|
-
const validatorBonds = await this.getBondValidatorStates(bondType, state.name);
|
|
6987
7937
|
const totalCollected = await this.getBondStateTotalCollected(
|
|
6988
7938
|
bondType,
|
|
6989
7939
|
state.name,
|
|
6990
|
-
|
|
7940
|
+
state
|
|
6991
7941
|
);
|
|
6992
7942
|
return {
|
|
6993
7943
|
totalCollected,
|
|
6994
7944
|
status: this.getBondStateSessionStatus(state)
|
|
6995
7945
|
};
|
|
6996
7946
|
}
|
|
7947
|
+
/**
|
|
7948
|
+
* Get validator bond rent exempt amount
|
|
7949
|
+
*/
|
|
7950
|
+
validatorBondRentExempt = async () => {
|
|
7951
|
+
return this.connection.getMinimumBalanceForRentExemption(this.program.account.validatorBond.size);
|
|
7952
|
+
};
|
|
6997
7953
|
/**
|
|
6998
7954
|
* Get all validator bonds for a given bond state
|
|
6999
7955
|
*/
|
|
7000
|
-
async
|
|
7956
|
+
async getValidatorBondsForState(bondType, bondName) {
|
|
7001
7957
|
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
7002
7958
|
const accounts = await this.program.account.validatorBond.all([
|
|
7003
7959
|
{
|
|
@@ -7040,6 +7996,6 @@ buffer/index.js:
|
|
|
7040
7996
|
*)
|
|
7041
7997
|
*/
|
|
7042
7998
|
|
|
7043
|
-
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 };
|
|
7999
|
+
export { BOND_STATE_SEED, BondTransactionType, BondType, CROWDFUNDING_BOND_SEED, ENV_PROGRAM_ID, GLOBAL_STATE_SEED, JBondClient, JBondClientEnv, JPOOL_POOL_ADDRESS, JSOL_MINT, NodeWallet, STANDARD_BOND_SEED, SessionStatus, VALIDATOR_BOND_SEED, lamportsToSol };
|
|
7044
8000
|
//# sourceMappingURL=index.mjs.map
|
|
7045
8001
|
//# sourceMappingURL=index.mjs.map
|