@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.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var anchor = require('@coral-xyz/anchor');
|
|
4
|
+
var splStakePool = require('@solana/spl-stake-pool');
|
|
4
5
|
var splToken = require('@solana/spl-token');
|
|
5
6
|
var web3_js = require('@solana/web3.js');
|
|
6
7
|
|
|
@@ -4568,20 +4569,15 @@ var import_bn = __toESM(require_bn());
|
|
|
4568
4569
|
|
|
4569
4570
|
// src/constants.ts
|
|
4570
4571
|
init_cjs_shims();
|
|
4571
|
-
var GLOBAL_STATE_SEED = "global_state";
|
|
4572
|
-
var BOND_STATE_SEED = "bond_state";
|
|
4573
|
-
var VALIDATOR_BOND_SEED = "validator_bond";
|
|
4574
|
-
var STANDARD_BOND_SEED = "standard";
|
|
4575
|
-
var CROWDFUNDING_BOND_SEED = "crowdfunding";
|
|
4576
|
-
var ENV_PROGRAM_ID = {
|
|
4577
|
-
// [BondClientEnv.DEV]: new PublicKey('...'),
|
|
4578
|
-
};
|
|
4579
|
-
|
|
4580
|
-
// src/history.ts
|
|
4581
|
-
init_cjs_shims();
|
|
4582
4572
|
|
|
4583
4573
|
// src/types/index.ts
|
|
4584
4574
|
init_cjs_shims();
|
|
4575
|
+
var JBondClientEnv = /* @__PURE__ */ ((JBondClientEnv2) => {
|
|
4576
|
+
JBondClientEnv2["DEV"] = "dev";
|
|
4577
|
+
JBondClientEnv2["STAGE"] = "stage";
|
|
4578
|
+
JBondClientEnv2["PROD"] = "prod";
|
|
4579
|
+
return JBondClientEnv2;
|
|
4580
|
+
})(JBondClientEnv || {});
|
|
4585
4581
|
var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
|
|
4586
4582
|
SessionStatus2[SessionStatus2["Live"] = 0] = "Live";
|
|
4587
4583
|
SessionStatus2[SessionStatus2["Finished"] = 1] = "Finished";
|
|
@@ -4593,14 +4589,31 @@ var BondType = /* @__PURE__ */ ((BondType2) => {
|
|
|
4593
4589
|
return BondType2;
|
|
4594
4590
|
})(BondType || {});
|
|
4595
4591
|
var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
|
|
4592
|
+
BondTransactionType2["Registered"] = "registered";
|
|
4596
4593
|
BondTransactionType2["Deposit"] = "deposit";
|
|
4597
4594
|
BondTransactionType2["Withdrawal"] = "withdrawal";
|
|
4598
4595
|
BondTransactionType2["Compensation"] = "compensation";
|
|
4599
4596
|
return BondTransactionType2;
|
|
4600
4597
|
})(BondTransactionType || {});
|
|
4601
4598
|
|
|
4599
|
+
// src/constants.ts
|
|
4600
|
+
var GLOBAL_STATE_SEED = "global_state";
|
|
4601
|
+
var BOND_STATE_SEED = "bond_state";
|
|
4602
|
+
var VALIDATOR_BOND_SEED = "validator_bond";
|
|
4603
|
+
var STANDARD_BOND_SEED = "standard";
|
|
4604
|
+
var CROWDFUNDING_BOND_SEED = "crowdfunding";
|
|
4605
|
+
var ENV_PROGRAM_ID = {
|
|
4606
|
+
["dev" /* DEV */]: "Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1",
|
|
4607
|
+
["stage" /* STAGE */]: "Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1",
|
|
4608
|
+
["prod" /* PROD */]: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU"
|
|
4609
|
+
};
|
|
4610
|
+
var JSOL_MINT = new web3_js.PublicKey("7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn");
|
|
4611
|
+
var JPOOL_POOL_ADDRESS = new web3_js.PublicKey("CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1");
|
|
4612
|
+
|
|
4602
4613
|
// src/history.ts
|
|
4614
|
+
init_cjs_shims();
|
|
4603
4615
|
var { bs58 } = anchor.utils.bytes;
|
|
4616
|
+
var DEFAULT_TX_BATCH_SIZE = 50;
|
|
4604
4617
|
var HistoryManager = class {
|
|
4605
4618
|
constructor(client) {
|
|
4606
4619
|
this.client = client;
|
|
@@ -4621,7 +4634,8 @@ var HistoryManager = class {
|
|
|
4621
4634
|
}
|
|
4622
4635
|
async getHistory(bondType, bondName, vote, opts) {
|
|
4623
4636
|
const [validatorBondAccount] = this.client.pda.validatorBond(bondType, bondName, vote);
|
|
4624
|
-
|
|
4637
|
+
const validatorBondAccount58 = validatorBondAccount.toBase58();
|
|
4638
|
+
this.debug(`Fetching history for validator bond account: ${validatorBondAccount58}`);
|
|
4625
4639
|
const signatures = await this.fetchSignaturesForAddress(validatorBondAccount, {
|
|
4626
4640
|
limit: opts?.limit,
|
|
4627
4641
|
before: opts?.before,
|
|
@@ -4631,7 +4645,7 @@ var HistoryManager = class {
|
|
|
4631
4645
|
return [];
|
|
4632
4646
|
}
|
|
4633
4647
|
const sigs = signatures.map((s) => s.signature);
|
|
4634
|
-
const parsed = await this.fetchParsedTransactions(sigs);
|
|
4648
|
+
const parsed = await this.fetchParsedTransactions(sigs, opts?.batchSize);
|
|
4635
4649
|
const txBySig = /* @__PURE__ */ new Map();
|
|
4636
4650
|
for (let i = 0; i < sigs.length; i++) {
|
|
4637
4651
|
const want = sigs[i];
|
|
@@ -4662,8 +4676,11 @@ var HistoryManager = class {
|
|
|
4662
4676
|
if (ix.parsed) {
|
|
4663
4677
|
continue;
|
|
4664
4678
|
}
|
|
4679
|
+
if (!this.instructionReferencesBondAccount(ix, validatorBondAccount, validatorBondAccount58)) {
|
|
4680
|
+
continue;
|
|
4681
|
+
}
|
|
4665
4682
|
const { type, amount } = this.decodeInstructionData(ix.data);
|
|
4666
|
-
if (!type || amount <= 0) {
|
|
4683
|
+
if (!type || amount <= 0 && type !== "registered" /* Registered */) {
|
|
4667
4684
|
continue;
|
|
4668
4685
|
}
|
|
4669
4686
|
history.push({
|
|
@@ -4677,19 +4694,34 @@ var HistoryManager = class {
|
|
|
4677
4694
|
}
|
|
4678
4695
|
return history.sort((a, b) => b.slot - a.slot);
|
|
4679
4696
|
}
|
|
4697
|
+
instructionReferencesBondAccount(ix, validatorBondAccount, validatorBondAccount58) {
|
|
4698
|
+
if (!Array.isArray(ix.accounts) || ix.accounts.length === 0) {
|
|
4699
|
+
return false;
|
|
4700
|
+
}
|
|
4701
|
+
return ix.accounts.some((account) => {
|
|
4702
|
+
if (typeof account === "string") {
|
|
4703
|
+
return account === validatorBondAccount58;
|
|
4704
|
+
}
|
|
4705
|
+
if (account instanceof web3_js.PublicKey) {
|
|
4706
|
+
return account.equals(validatorBondAccount);
|
|
4707
|
+
}
|
|
4708
|
+
const account58 = account?.toBase58?.();
|
|
4709
|
+
return typeof account58 === "string" && account58 === validatorBondAccount58;
|
|
4710
|
+
});
|
|
4711
|
+
}
|
|
4680
4712
|
async fetchSignaturesForAddress(address, options) {
|
|
4681
4713
|
const sigs = await this.connection.getSignaturesForAddress(address, {
|
|
4682
4714
|
limit: options?.limit || 1e3,
|
|
4683
4715
|
before: options?.before,
|
|
4684
4716
|
until: options?.until
|
|
4685
4717
|
}, "confirmed");
|
|
4686
|
-
console.log(sigs);
|
|
4687
4718
|
return sigs.filter((s) => !s.err);
|
|
4688
4719
|
}
|
|
4689
|
-
async fetchParsedTransactions(sigs, batchSize =
|
|
4720
|
+
async fetchParsedTransactions(sigs, batchSize = DEFAULT_TX_BATCH_SIZE) {
|
|
4721
|
+
const size = Math.max(1, Math.floor(batchSize) || DEFAULT_TX_BATCH_SIZE);
|
|
4690
4722
|
const all = [];
|
|
4691
|
-
for (let i = 0; i < sigs.length; i +=
|
|
4692
|
-
const batch = sigs.slice(i, i +
|
|
4723
|
+
for (let i = 0; i < sigs.length; i += size) {
|
|
4724
|
+
const batch = sigs.slice(i, i + size);
|
|
4693
4725
|
const txs = await this.connection.getParsedTransactions(batch, {
|
|
4694
4726
|
commitment: "confirmed",
|
|
4695
4727
|
maxSupportedTransactionVersion: 0
|
|
@@ -4705,7 +4737,7 @@ var HistoryManager = class {
|
|
|
4705
4737
|
}
|
|
4706
4738
|
const ix = this.program.idl.instructions.find((i) => i.name === name);
|
|
4707
4739
|
if (!ix || !Array.isArray(ix.discriminator)) {
|
|
4708
|
-
|
|
4740
|
+
return new Uint8Array();
|
|
4709
4741
|
}
|
|
4710
4742
|
const disc = new Uint8Array(ix.discriminator);
|
|
4711
4743
|
this.discCache.set(name, disc);
|
|
@@ -4713,47 +4745,45 @@ var HistoryManager = class {
|
|
|
4713
4745
|
}
|
|
4714
4746
|
decodeInstructionData(data) {
|
|
4715
4747
|
if (!data) {
|
|
4716
|
-
return {
|
|
4717
|
-
type: null,
|
|
4718
|
-
amount: 0
|
|
4719
|
-
};
|
|
4748
|
+
return { type: null, amount: 0 };
|
|
4720
4749
|
}
|
|
4721
4750
|
try {
|
|
4722
4751
|
const buf = bs58.decode(data);
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
const
|
|
4734
|
-
const
|
|
4735
|
-
const
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
if (
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
}
|
|
4748
|
-
return { type
|
|
4749
|
-
} catch {
|
|
4752
|
+
let type = null;
|
|
4753
|
+
const disc = buf.subarray(0, 8);
|
|
4754
|
+
const amountBytes = buf.subarray(8, 16);
|
|
4755
|
+
let amount = 0;
|
|
4756
|
+
let noAmount = false;
|
|
4757
|
+
try {
|
|
4758
|
+
amount = new anchor.BN(amountBytes, "le").toNumber() / web3_js.LAMPORTS_PER_SOL;
|
|
4759
|
+
} catch {
|
|
4760
|
+
noAmount = true;
|
|
4761
|
+
}
|
|
4762
|
+
const bondRegisterDiscriminator = this.getInstructionDiscriminator("bondRegister");
|
|
4763
|
+
const bondTopUpDiscriminator = this.getInstructionDiscriminator("bondTopUp");
|
|
4764
|
+
const bondClaimDiscriminator = this.getInstructionDiscriminator("bondClaim");
|
|
4765
|
+
const bondWithdrawDiscriminator = this.getInstructionDiscriminator("bondWithdraw");
|
|
4766
|
+
if (Buffer.from(disc).equals(Buffer.from(bondRegisterDiscriminator))) {
|
|
4767
|
+
type = "registered" /* Registered */;
|
|
4768
|
+
} else if (!noAmount) {
|
|
4769
|
+
if (Buffer.from(disc).equals(Buffer.from(bondTopUpDiscriminator))) {
|
|
4770
|
+
type = "deposit" /* Deposit */;
|
|
4771
|
+
} else if (Buffer.from(disc).equals(Buffer.from(bondClaimDiscriminator))) {
|
|
4772
|
+
type = "compensation" /* Compensation */;
|
|
4773
|
+
} else if (Buffer.from(disc).equals(Buffer.from(bondWithdrawDiscriminator))) {
|
|
4774
|
+
type = "withdrawal" /* Withdrawal */;
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4777
|
+
return { type, amount };
|
|
4778
|
+
} catch (error) {
|
|
4779
|
+
console.error("Failed to decode instruction data:", error);
|
|
4750
4780
|
return { type: null, amount: 0 };
|
|
4751
4781
|
}
|
|
4752
4782
|
}
|
|
4753
4783
|
};
|
|
4754
4784
|
function slotToEpoch(slot, cluster) {
|
|
4755
|
-
const
|
|
4756
|
-
const slotsPerEpoch =
|
|
4785
|
+
const isDevnet = cluster?.includes("devnet") || cluster?.includes("localnet");
|
|
4786
|
+
const slotsPerEpoch = isDevnet ? 4e5 : 432e3;
|
|
4757
4787
|
return Math.floor(slot / slotsPerEpoch);
|
|
4758
4788
|
}
|
|
4759
4789
|
|
|
@@ -4762,7 +4792,7 @@ var jbond_default = {
|
|
|
4762
4792
|
address: "BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU",
|
|
4763
4793
|
metadata: {
|
|
4764
4794
|
name: "jbond",
|
|
4765
|
-
version: "0.2.
|
|
4795
|
+
version: "0.2.6",
|
|
4766
4796
|
spec: "0.1.0",
|
|
4767
4797
|
description: "Jpool Bond Program"
|
|
4768
4798
|
},
|
|
@@ -4837,7 +4867,10 @@ var jbond_default = {
|
|
|
4837
4867
|
},
|
|
4838
4868
|
{
|
|
4839
4869
|
name: "authority",
|
|
4840
|
-
signer: true
|
|
4870
|
+
signer: true,
|
|
4871
|
+
relations: [
|
|
4872
|
+
"bond_state"
|
|
4873
|
+
]
|
|
4841
4874
|
},
|
|
4842
4875
|
{
|
|
4843
4876
|
name: "bond_token_account",
|
|
@@ -5008,6 +5041,84 @@ var jbond_default = {
|
|
|
5008
5041
|
}
|
|
5009
5042
|
]
|
|
5010
5043
|
},
|
|
5044
|
+
{
|
|
5045
|
+
name: "bond_lock_funds",
|
|
5046
|
+
docs: [
|
|
5047
|
+
"Locks funds immediately, making them unavailable for withdrawal.",
|
|
5048
|
+
"The locked amount takes effect immediately in the current epoch.",
|
|
5049
|
+
"",
|
|
5050
|
+
"# Errors",
|
|
5051
|
+
"Fails if the bond type is not lockable, if the amount is zero,",
|
|
5052
|
+
"or if there are insufficient available funds."
|
|
5053
|
+
],
|
|
5054
|
+
discriminator: [
|
|
5055
|
+
117,
|
|
5056
|
+
166,
|
|
5057
|
+
195,
|
|
5058
|
+
99,
|
|
5059
|
+
103,
|
|
5060
|
+
45,
|
|
5061
|
+
195,
|
|
5062
|
+
2
|
|
5063
|
+
],
|
|
5064
|
+
accounts: [
|
|
5065
|
+
{
|
|
5066
|
+
name: "bond_state",
|
|
5067
|
+
writable: true
|
|
5068
|
+
},
|
|
5069
|
+
{
|
|
5070
|
+
name: "validator_bond",
|
|
5071
|
+
writable: true,
|
|
5072
|
+
pda: {
|
|
5073
|
+
seeds: [
|
|
5074
|
+
{
|
|
5075
|
+
kind: "const",
|
|
5076
|
+
value: [
|
|
5077
|
+
118,
|
|
5078
|
+
97,
|
|
5079
|
+
108,
|
|
5080
|
+
105,
|
|
5081
|
+
100,
|
|
5082
|
+
97,
|
|
5083
|
+
116,
|
|
5084
|
+
111,
|
|
5085
|
+
114,
|
|
5086
|
+
95,
|
|
5087
|
+
98,
|
|
5088
|
+
111,
|
|
5089
|
+
110,
|
|
5090
|
+
100
|
|
5091
|
+
]
|
|
5092
|
+
},
|
|
5093
|
+
{
|
|
5094
|
+
kind: "account",
|
|
5095
|
+
path: "bond_state"
|
|
5096
|
+
},
|
|
5097
|
+
{
|
|
5098
|
+
kind: "account",
|
|
5099
|
+
path: "validator_bond.vote_account",
|
|
5100
|
+
account: "ValidatorBond"
|
|
5101
|
+
}
|
|
5102
|
+
]
|
|
5103
|
+
}
|
|
5104
|
+
},
|
|
5105
|
+
{
|
|
5106
|
+
name: "bond_token_account",
|
|
5107
|
+
optional: true
|
|
5108
|
+
},
|
|
5109
|
+
{
|
|
5110
|
+
name: "payer",
|
|
5111
|
+
writable: true,
|
|
5112
|
+
signer: true
|
|
5113
|
+
}
|
|
5114
|
+
],
|
|
5115
|
+
args: [
|
|
5116
|
+
{
|
|
5117
|
+
name: "amount",
|
|
5118
|
+
type: "u64"
|
|
5119
|
+
}
|
|
5120
|
+
]
|
|
5121
|
+
},
|
|
5011
5122
|
{
|
|
5012
5123
|
name: "bond_register",
|
|
5013
5124
|
docs: [
|
|
@@ -5035,7 +5146,34 @@ var jbond_default = {
|
|
|
5035
5146
|
accounts: [
|
|
5036
5147
|
{
|
|
5037
5148
|
name: "bond_state",
|
|
5038
|
-
writable: true
|
|
5149
|
+
writable: true,
|
|
5150
|
+
pda: {
|
|
5151
|
+
seeds: [
|
|
5152
|
+
{
|
|
5153
|
+
kind: "const",
|
|
5154
|
+
value: [
|
|
5155
|
+
98,
|
|
5156
|
+
111,
|
|
5157
|
+
110,
|
|
5158
|
+
100,
|
|
5159
|
+
95,
|
|
5160
|
+
115,
|
|
5161
|
+
116,
|
|
5162
|
+
97,
|
|
5163
|
+
116,
|
|
5164
|
+
101
|
|
5165
|
+
]
|
|
5166
|
+
},
|
|
5167
|
+
{
|
|
5168
|
+
kind: "arg",
|
|
5169
|
+
path: "bond_type"
|
|
5170
|
+
},
|
|
5171
|
+
{
|
|
5172
|
+
kind: "arg",
|
|
5173
|
+
path: "bond_name"
|
|
5174
|
+
}
|
|
5175
|
+
]
|
|
5176
|
+
}
|
|
5039
5177
|
},
|
|
5040
5178
|
{
|
|
5041
5179
|
name: "validator_bond",
|
|
@@ -5120,6 +5258,112 @@ var jbond_default = {
|
|
|
5120
5258
|
}
|
|
5121
5259
|
]
|
|
5122
5260
|
},
|
|
5261
|
+
{
|
|
5262
|
+
name: "bond_release_funds",
|
|
5263
|
+
docs: [
|
|
5264
|
+
"Queues funds for unlock in the next epoch.",
|
|
5265
|
+
"The unlock is delayed by one epoch for security - funds remain locked",
|
|
5266
|
+
"in the current epoch but will be available after epoch transition.",
|
|
5267
|
+
"",
|
|
5268
|
+
"# Errors",
|
|
5269
|
+
"Fails if the bond type is not lockable, if the amount is zero,",
|
|
5270
|
+
"or if the amount exceeds currently locked funds."
|
|
5271
|
+
],
|
|
5272
|
+
discriminator: [
|
|
5273
|
+
184,
|
|
5274
|
+
224,
|
|
5275
|
+
14,
|
|
5276
|
+
24,
|
|
5277
|
+
76,
|
|
5278
|
+
14,
|
|
5279
|
+
226,
|
|
5280
|
+
190
|
|
5281
|
+
],
|
|
5282
|
+
accounts: [
|
|
5283
|
+
{
|
|
5284
|
+
name: "bond_state",
|
|
5285
|
+
writable: true
|
|
5286
|
+
},
|
|
5287
|
+
{
|
|
5288
|
+
name: "validator_bond",
|
|
5289
|
+
writable: true,
|
|
5290
|
+
pda: {
|
|
5291
|
+
seeds: [
|
|
5292
|
+
{
|
|
5293
|
+
kind: "const",
|
|
5294
|
+
value: [
|
|
5295
|
+
118,
|
|
5296
|
+
97,
|
|
5297
|
+
108,
|
|
5298
|
+
105,
|
|
5299
|
+
100,
|
|
5300
|
+
97,
|
|
5301
|
+
116,
|
|
5302
|
+
111,
|
|
5303
|
+
114,
|
|
5304
|
+
95,
|
|
5305
|
+
98,
|
|
5306
|
+
111,
|
|
5307
|
+
110,
|
|
5308
|
+
100
|
|
5309
|
+
]
|
|
5310
|
+
},
|
|
5311
|
+
{
|
|
5312
|
+
kind: "account",
|
|
5313
|
+
path: "bond_state"
|
|
5314
|
+
},
|
|
5315
|
+
{
|
|
5316
|
+
kind: "account",
|
|
5317
|
+
path: "validator_bond.vote_account",
|
|
5318
|
+
account: "ValidatorBond"
|
|
5319
|
+
}
|
|
5320
|
+
]
|
|
5321
|
+
}
|
|
5322
|
+
},
|
|
5323
|
+
{
|
|
5324
|
+
name: "payer",
|
|
5325
|
+
writable: true,
|
|
5326
|
+
signer: true
|
|
5327
|
+
}
|
|
5328
|
+
],
|
|
5329
|
+
args: [
|
|
5330
|
+
{
|
|
5331
|
+
name: "amount",
|
|
5332
|
+
type: "u64"
|
|
5333
|
+
}
|
|
5334
|
+
]
|
|
5335
|
+
},
|
|
5336
|
+
{
|
|
5337
|
+
name: "bond_remove",
|
|
5338
|
+
docs: [
|
|
5339
|
+
"Removes bond state"
|
|
5340
|
+
],
|
|
5341
|
+
discriminator: [
|
|
5342
|
+
121,
|
|
5343
|
+
112,
|
|
5344
|
+
246,
|
|
5345
|
+
177,
|
|
5346
|
+
181,
|
|
5347
|
+
8,
|
|
5348
|
+
18,
|
|
5349
|
+
220
|
|
5350
|
+
],
|
|
5351
|
+
accounts: [
|
|
5352
|
+
{
|
|
5353
|
+
name: "bond_state",
|
|
5354
|
+
writable: true
|
|
5355
|
+
},
|
|
5356
|
+
{
|
|
5357
|
+
name: "authority",
|
|
5358
|
+
writable: true,
|
|
5359
|
+
signer: true,
|
|
5360
|
+
relations: [
|
|
5361
|
+
"bond_state"
|
|
5362
|
+
]
|
|
5363
|
+
}
|
|
5364
|
+
],
|
|
5365
|
+
args: []
|
|
5366
|
+
},
|
|
5123
5367
|
{
|
|
5124
5368
|
name: "bond_set_withdraw_authority",
|
|
5125
5369
|
docs: [
|
|
@@ -5410,20 +5654,117 @@ var jbond_default = {
|
|
|
5410
5654
|
]
|
|
5411
5655
|
},
|
|
5412
5656
|
{
|
|
5413
|
-
name: "
|
|
5657
|
+
name: "close_validator_bond",
|
|
5658
|
+
docs: [
|
|
5659
|
+
"Closes a validator bond account and transfers remaining balance to the rent receiver.",
|
|
5660
|
+
"",
|
|
5661
|
+
"# Security",
|
|
5662
|
+
"- Only the validator identity or withdrawal authority can close the bond",
|
|
5663
|
+
"- All funds must be unlocked (locked == 0 and pending_unlock == 0)",
|
|
5664
|
+
"- For token collateral, closes the associated token account as well",
|
|
5665
|
+
"- Decrements the bond state's total_members counter",
|
|
5666
|
+
"",
|
|
5667
|
+
"# Errors",
|
|
5668
|
+
"Fails if the signer is not authorized, if funds are still locked,",
|
|
5669
|
+
"or if the rent receiver is not the identity or withdrawal authority."
|
|
5670
|
+
],
|
|
5414
5671
|
discriminator: [
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5672
|
+
51,
|
|
5673
|
+
235,
|
|
5674
|
+
111,
|
|
5675
|
+
163,
|
|
5676
|
+
176,
|
|
5677
|
+
239,
|
|
5678
|
+
95,
|
|
5679
|
+
122
|
|
5423
5680
|
],
|
|
5424
5681
|
accounts: [
|
|
5425
5682
|
{
|
|
5426
|
-
name: "
|
|
5683
|
+
name: "bond_state",
|
|
5684
|
+
writable: true
|
|
5685
|
+
},
|
|
5686
|
+
{
|
|
5687
|
+
name: "validator_bond",
|
|
5688
|
+
writable: true,
|
|
5689
|
+
pda: {
|
|
5690
|
+
seeds: [
|
|
5691
|
+
{
|
|
5692
|
+
kind: "const",
|
|
5693
|
+
value: [
|
|
5694
|
+
118,
|
|
5695
|
+
97,
|
|
5696
|
+
108,
|
|
5697
|
+
105,
|
|
5698
|
+
100,
|
|
5699
|
+
97,
|
|
5700
|
+
116,
|
|
5701
|
+
111,
|
|
5702
|
+
114,
|
|
5703
|
+
95,
|
|
5704
|
+
98,
|
|
5705
|
+
111,
|
|
5706
|
+
110,
|
|
5707
|
+
100
|
|
5708
|
+
]
|
|
5709
|
+
},
|
|
5710
|
+
{
|
|
5711
|
+
kind: "account",
|
|
5712
|
+
path: "bond_state"
|
|
5713
|
+
},
|
|
5714
|
+
{
|
|
5715
|
+
kind: "account",
|
|
5716
|
+
path: "validator_bond.vote_account",
|
|
5717
|
+
account: "ValidatorBond"
|
|
5718
|
+
}
|
|
5719
|
+
]
|
|
5720
|
+
}
|
|
5721
|
+
},
|
|
5722
|
+
{
|
|
5723
|
+
name: "authority",
|
|
5724
|
+
writable: true,
|
|
5725
|
+
signer: true
|
|
5726
|
+
},
|
|
5727
|
+
{
|
|
5728
|
+
name: "rent_receiver",
|
|
5729
|
+
writable: true
|
|
5730
|
+
},
|
|
5731
|
+
{
|
|
5732
|
+
name: "bond_token_account",
|
|
5733
|
+
writable: true,
|
|
5734
|
+
optional: true
|
|
5735
|
+
},
|
|
5736
|
+
{
|
|
5737
|
+
name: "destination_token_account",
|
|
5738
|
+
writable: true,
|
|
5739
|
+
optional: true
|
|
5740
|
+
},
|
|
5741
|
+
{
|
|
5742
|
+
name: "system_program",
|
|
5743
|
+
address: "11111111111111111111111111111111"
|
|
5744
|
+
},
|
|
5745
|
+
{
|
|
5746
|
+
name: "token_program",
|
|
5747
|
+
optional: true,
|
|
5748
|
+
address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
|
5749
|
+
}
|
|
5750
|
+
],
|
|
5751
|
+
args: []
|
|
5752
|
+
},
|
|
5753
|
+
{
|
|
5754
|
+
name: "global_configure",
|
|
5755
|
+
discriminator: [
|
|
5756
|
+
67,
|
|
5757
|
+
142,
|
|
5758
|
+
164,
|
|
5759
|
+
250,
|
|
5760
|
+
90,
|
|
5761
|
+
233,
|
|
5762
|
+
144,
|
|
5763
|
+
187
|
|
5764
|
+
],
|
|
5765
|
+
accounts: [
|
|
5766
|
+
{
|
|
5767
|
+
name: "global_state",
|
|
5427
5768
|
writable: true,
|
|
5428
5769
|
pda: {
|
|
5429
5770
|
seeds: [
|
|
@@ -5516,80 +5857,6 @@ var jbond_default = {
|
|
|
5516
5857
|
],
|
|
5517
5858
|
args: []
|
|
5518
5859
|
},
|
|
5519
|
-
{
|
|
5520
|
-
name: "migrate_bond",
|
|
5521
|
-
docs: [
|
|
5522
|
-
"Migrates validator bond data from legacy structure to new structure."
|
|
5523
|
-
],
|
|
5524
|
-
discriminator: [
|
|
5525
|
-
107,
|
|
5526
|
-
119,
|
|
5527
|
-
59,
|
|
5528
|
-
110,
|
|
5529
|
-
76,
|
|
5530
|
-
18,
|
|
5531
|
-
37,
|
|
5532
|
-
163
|
|
5533
|
-
],
|
|
5534
|
-
accounts: [
|
|
5535
|
-
{
|
|
5536
|
-
name: "bond_state",
|
|
5537
|
-
writable: true
|
|
5538
|
-
},
|
|
5539
|
-
{
|
|
5540
|
-
name: "legacy_validator_bond",
|
|
5541
|
-
writable: true
|
|
5542
|
-
},
|
|
5543
|
-
{
|
|
5544
|
-
name: "legacy_vote_account"
|
|
5545
|
-
},
|
|
5546
|
-
{
|
|
5547
|
-
name: "validator_bond",
|
|
5548
|
-
writable: true,
|
|
5549
|
-
pda: {
|
|
5550
|
-
seeds: [
|
|
5551
|
-
{
|
|
5552
|
-
kind: "const",
|
|
5553
|
-
value: [
|
|
5554
|
-
118,
|
|
5555
|
-
97,
|
|
5556
|
-
108,
|
|
5557
|
-
105,
|
|
5558
|
-
100,
|
|
5559
|
-
97,
|
|
5560
|
-
116,
|
|
5561
|
-
111,
|
|
5562
|
-
114,
|
|
5563
|
-
95,
|
|
5564
|
-
98,
|
|
5565
|
-
111,
|
|
5566
|
-
110,
|
|
5567
|
-
100
|
|
5568
|
-
]
|
|
5569
|
-
},
|
|
5570
|
-
{
|
|
5571
|
-
kind: "account",
|
|
5572
|
-
path: "bond_state"
|
|
5573
|
-
},
|
|
5574
|
-
{
|
|
5575
|
-
kind: "account",
|
|
5576
|
-
path: "legacy_vote_account"
|
|
5577
|
-
}
|
|
5578
|
-
]
|
|
5579
|
-
}
|
|
5580
|
-
},
|
|
5581
|
-
{
|
|
5582
|
-
name: "creator",
|
|
5583
|
-
writable: true,
|
|
5584
|
-
signer: true
|
|
5585
|
-
},
|
|
5586
|
-
{
|
|
5587
|
-
name: "system_program",
|
|
5588
|
-
address: "11111111111111111111111111111111"
|
|
5589
|
-
}
|
|
5590
|
-
],
|
|
5591
|
-
args: []
|
|
5592
|
-
},
|
|
5593
5860
|
{
|
|
5594
5861
|
name: "session_finish",
|
|
5595
5862
|
docs: [
|
|
@@ -5700,6 +5967,19 @@ var jbond_default = {
|
|
|
5700
5967
|
}
|
|
5701
5968
|
],
|
|
5702
5969
|
events: [
|
|
5970
|
+
{
|
|
5971
|
+
name: "BondConfigured",
|
|
5972
|
+
discriminator: [
|
|
5973
|
+
141,
|
|
5974
|
+
252,
|
|
5975
|
+
43,
|
|
5976
|
+
54,
|
|
5977
|
+
45,
|
|
5978
|
+
157,
|
|
5979
|
+
81,
|
|
5980
|
+
14
|
|
5981
|
+
]
|
|
5982
|
+
},
|
|
5703
5983
|
{
|
|
5704
5984
|
name: "BondFinished",
|
|
5705
5985
|
discriminator: [
|
|
@@ -5713,6 +5993,32 @@ var jbond_default = {
|
|
|
5713
5993
|
191
|
|
5714
5994
|
]
|
|
5715
5995
|
},
|
|
5996
|
+
{
|
|
5997
|
+
name: "BondInitialized",
|
|
5998
|
+
discriminator: [
|
|
5999
|
+
73,
|
|
6000
|
+
68,
|
|
6001
|
+
161,
|
|
6002
|
+
2,
|
|
6003
|
+
214,
|
|
6004
|
+
12,
|
|
6005
|
+
169,
|
|
6006
|
+
53
|
|
6007
|
+
]
|
|
6008
|
+
},
|
|
6009
|
+
{
|
|
6010
|
+
name: "BondRemoved",
|
|
6011
|
+
discriminator: [
|
|
6012
|
+
177,
|
|
6013
|
+
200,
|
|
6014
|
+
116,
|
|
6015
|
+
123,
|
|
6016
|
+
1,
|
|
6017
|
+
244,
|
|
6018
|
+
161,
|
|
6019
|
+
240
|
|
6020
|
+
]
|
|
6021
|
+
},
|
|
5716
6022
|
{
|
|
5717
6023
|
name: "BondStarted",
|
|
5718
6024
|
discriminator: [
|
|
@@ -5727,16 +6033,16 @@ var jbond_default = {
|
|
|
5727
6033
|
]
|
|
5728
6034
|
},
|
|
5729
6035
|
{
|
|
5730
|
-
name: "
|
|
6036
|
+
name: "CollateralDeposited",
|
|
5731
6037
|
discriminator: [
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
6038
|
+
244,
|
|
6039
|
+
62,
|
|
6040
|
+
77,
|
|
6041
|
+
11,
|
|
5736
6042
|
135,
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
6043
|
+
112,
|
|
6044
|
+
61,
|
|
6045
|
+
96
|
|
5740
6046
|
]
|
|
5741
6047
|
},
|
|
5742
6048
|
{
|
|
@@ -5752,6 +6058,19 @@ var jbond_default = {
|
|
|
5752
6058
|
82
|
|
5753
6059
|
]
|
|
5754
6060
|
},
|
|
6061
|
+
{
|
|
6062
|
+
name: "CompensationBurned",
|
|
6063
|
+
discriminator: [
|
|
6064
|
+
177,
|
|
6065
|
+
198,
|
|
6066
|
+
90,
|
|
6067
|
+
188,
|
|
6068
|
+
47,
|
|
6069
|
+
95,
|
|
6070
|
+
20,
|
|
6071
|
+
174
|
|
6072
|
+
]
|
|
6073
|
+
},
|
|
5755
6074
|
{
|
|
5756
6075
|
name: "CompensationClaimed",
|
|
5757
6076
|
discriminator: [
|
|
@@ -5765,6 +6084,45 @@ var jbond_default = {
|
|
|
5765
6084
|
32
|
|
5766
6085
|
]
|
|
5767
6086
|
},
|
|
6087
|
+
{
|
|
6088
|
+
name: "FundsLocked",
|
|
6089
|
+
discriminator: [
|
|
6090
|
+
227,
|
|
6091
|
+
93,
|
|
6092
|
+
162,
|
|
6093
|
+
69,
|
|
6094
|
+
181,
|
|
6095
|
+
4,
|
|
6096
|
+
71,
|
|
6097
|
+
157
|
|
6098
|
+
]
|
|
6099
|
+
},
|
|
6100
|
+
{
|
|
6101
|
+
name: "FundsUnlocked",
|
|
6102
|
+
discriminator: [
|
|
6103
|
+
11,
|
|
6104
|
+
240,
|
|
6105
|
+
184,
|
|
6106
|
+
107,
|
|
6107
|
+
86,
|
|
6108
|
+
187,
|
|
6109
|
+
196,
|
|
6110
|
+
128
|
|
6111
|
+
]
|
|
6112
|
+
},
|
|
6113
|
+
{
|
|
6114
|
+
name: "ValidatorBondClosed",
|
|
6115
|
+
discriminator: [
|
|
6116
|
+
71,
|
|
6117
|
+
54,
|
|
6118
|
+
59,
|
|
6119
|
+
241,
|
|
6120
|
+
91,
|
|
6121
|
+
35,
|
|
6122
|
+
123,
|
|
6123
|
+
123
|
|
6124
|
+
]
|
|
6125
|
+
},
|
|
5768
6126
|
{
|
|
5769
6127
|
name: "ValidatorRegistered",
|
|
5770
6128
|
discriminator: [
|
|
@@ -5777,33 +6135,46 @@ var jbond_default = {
|
|
|
5777
6135
|
95,
|
|
5778
6136
|
72
|
|
5779
6137
|
]
|
|
6138
|
+
},
|
|
6139
|
+
{
|
|
6140
|
+
name: "WithdrawAuthorityChanged",
|
|
6141
|
+
discriminator: [
|
|
6142
|
+
91,
|
|
6143
|
+
149,
|
|
6144
|
+
224,
|
|
6145
|
+
49,
|
|
6146
|
+
187,
|
|
6147
|
+
48,
|
|
6148
|
+
190,
|
|
6149
|
+
100
|
|
6150
|
+
]
|
|
5780
6151
|
}
|
|
5781
6152
|
],
|
|
5782
6153
|
errors: [
|
|
5783
6154
|
{
|
|
5784
6155
|
code: 6e3,
|
|
5785
|
-
name: "
|
|
5786
|
-
msg: "
|
|
6156
|
+
name: "Forbidden",
|
|
6157
|
+
msg: "Forbidden"
|
|
5787
6158
|
},
|
|
5788
6159
|
{
|
|
5789
6160
|
code: 6001,
|
|
5790
|
-
name: "
|
|
5791
|
-
msg: "
|
|
6161
|
+
name: "Unauthorized",
|
|
6162
|
+
msg: "Unauthorized"
|
|
5792
6163
|
},
|
|
5793
6164
|
{
|
|
5794
6165
|
code: 6002,
|
|
5795
|
-
name: "
|
|
5796
|
-
msg: "
|
|
6166
|
+
name: "InvalidVoteAccount",
|
|
6167
|
+
msg: "Invalid vote account"
|
|
5797
6168
|
},
|
|
5798
6169
|
{
|
|
5799
6170
|
code: 6003,
|
|
5800
|
-
name: "
|
|
5801
|
-
msg: "
|
|
6171
|
+
name: "IdentityMismatch",
|
|
6172
|
+
msg: "Vote account identity mismatch"
|
|
5802
6173
|
},
|
|
5803
6174
|
{
|
|
5804
6175
|
code: 6004,
|
|
5805
|
-
name: "
|
|
5806
|
-
msg: "
|
|
6176
|
+
name: "InvalidMint",
|
|
6177
|
+
msg: "Invalid mint address"
|
|
5807
6178
|
},
|
|
5808
6179
|
{
|
|
5809
6180
|
code: 6005,
|
|
@@ -5812,93 +6183,53 @@ var jbond_default = {
|
|
|
5812
6183
|
},
|
|
5813
6184
|
{
|
|
5814
6185
|
code: 6006,
|
|
5815
|
-
name: "
|
|
5816
|
-
msg: "
|
|
6186
|
+
name: "InvalidArgument",
|
|
6187
|
+
msg: "Invalid argument"
|
|
5817
6188
|
},
|
|
5818
6189
|
{
|
|
5819
6190
|
code: 6007,
|
|
5820
|
-
name: "
|
|
5821
|
-
msg: "
|
|
6191
|
+
name: "InsufficientBalance",
|
|
6192
|
+
msg: "Insufficient balance"
|
|
5822
6193
|
},
|
|
5823
6194
|
{
|
|
5824
6195
|
code: 6008,
|
|
5825
|
-
name: "
|
|
5826
|
-
msg: "
|
|
6196
|
+
name: "MathOverflow",
|
|
6197
|
+
msg: "Math overflow"
|
|
5827
6198
|
},
|
|
5828
6199
|
{
|
|
5829
6200
|
code: 6009,
|
|
5830
|
-
name: "
|
|
5831
|
-
msg: "
|
|
6201
|
+
name: "Overflow",
|
|
6202
|
+
msg: "Arithmetic overflow"
|
|
5832
6203
|
},
|
|
5833
6204
|
{
|
|
5834
6205
|
code: 6010,
|
|
5835
|
-
name: "
|
|
5836
|
-
msg: "
|
|
6206
|
+
name: "BondNotRemovable",
|
|
6207
|
+
msg: "Bond cannot be removed"
|
|
5837
6208
|
},
|
|
5838
6209
|
{
|
|
5839
6210
|
code: 6011,
|
|
5840
|
-
name: "
|
|
5841
|
-
msg: "
|
|
6211
|
+
name: "MissingTokenAccounts",
|
|
6212
|
+
msg: "Missing token accounts"
|
|
5842
6213
|
},
|
|
5843
6214
|
{
|
|
5844
6215
|
code: 6012,
|
|
5845
|
-
name: "
|
|
5846
|
-
msg: "
|
|
6216
|
+
name: "MissingTokenProgram",
|
|
6217
|
+
msg: "Missing token program"
|
|
5847
6218
|
},
|
|
5848
6219
|
{
|
|
5849
6220
|
code: 6013,
|
|
5850
6221
|
name: "MissingStakeAccount",
|
|
5851
|
-
msg: "
|
|
6222
|
+
msg: "Missing stake account"
|
|
5852
6223
|
},
|
|
5853
6224
|
{
|
|
5854
6225
|
code: 6014,
|
|
5855
6226
|
name: "MissingStakeProgram",
|
|
5856
|
-
msg: "
|
|
6227
|
+
msg: "Missing stake program"
|
|
5857
6228
|
},
|
|
5858
6229
|
{
|
|
5859
6230
|
code: 6015,
|
|
5860
|
-
name: "BondFinished",
|
|
5861
|
-
msg: "Bond is finished (deposits/withdrawals disabled)"
|
|
5862
|
-
},
|
|
5863
|
-
{
|
|
5864
|
-
code: 6016,
|
|
5865
|
-
name: "BondNotFinished",
|
|
5866
|
-
msg: "Bond is not finished"
|
|
5867
|
-
},
|
|
5868
|
-
{
|
|
5869
|
-
code: 6017,
|
|
5870
6231
|
name: "UnsupportedCollateralType",
|
|
5871
6232
|
msg: "Unsupported collateral type"
|
|
5872
|
-
},
|
|
5873
|
-
{
|
|
5874
|
-
code: 6018,
|
|
5875
|
-
name: "Overflow",
|
|
5876
|
-
msg: "Math operation overflowed"
|
|
5877
|
-
},
|
|
5878
|
-
{
|
|
5879
|
-
code: 6019,
|
|
5880
|
-
name: "IncorrectBondType",
|
|
5881
|
-
msg: "Incorrect bond type for this operation"
|
|
5882
|
-
},
|
|
5883
|
-
{
|
|
5884
|
-
code: 6020,
|
|
5885
|
-
name: "BondNotFinishable",
|
|
5886
|
-
msg: "This bond type can't be finished"
|
|
5887
|
-
},
|
|
5888
|
-
{
|
|
5889
|
-
code: 6021,
|
|
5890
|
-
name: "InvalidArgument",
|
|
5891
|
-
msg: "Invalid argument provided"
|
|
5892
|
-
},
|
|
5893
|
-
{
|
|
5894
|
-
code: 6022,
|
|
5895
|
-
name: "BondNotDisabled",
|
|
5896
|
-
msg: "Bond is not disabled"
|
|
5897
|
-
},
|
|
5898
|
-
{
|
|
5899
|
-
code: 6023,
|
|
5900
|
-
name: "BondNotEnabled",
|
|
5901
|
-
msg: "Bond is not enabled"
|
|
5902
6233
|
}
|
|
5903
6234
|
],
|
|
5904
6235
|
types: [
|
|
@@ -5932,6 +6263,26 @@ var jbond_default = {
|
|
|
5932
6263
|
]
|
|
5933
6264
|
}
|
|
5934
6265
|
},
|
|
6266
|
+
{
|
|
6267
|
+
name: "BondConfigured",
|
|
6268
|
+
type: {
|
|
6269
|
+
kind: "struct",
|
|
6270
|
+
fields: [
|
|
6271
|
+
{
|
|
6272
|
+
name: "bond",
|
|
6273
|
+
type: "pubkey"
|
|
6274
|
+
},
|
|
6275
|
+
{
|
|
6276
|
+
name: "authority",
|
|
6277
|
+
type: "pubkey"
|
|
6278
|
+
},
|
|
6279
|
+
{
|
|
6280
|
+
name: "timestamp",
|
|
6281
|
+
type: "i64"
|
|
6282
|
+
}
|
|
6283
|
+
]
|
|
6284
|
+
}
|
|
6285
|
+
},
|
|
5935
6286
|
{
|
|
5936
6287
|
name: "BondFinished",
|
|
5937
6288
|
type: {
|
|
@@ -5987,6 +6338,46 @@ var jbond_default = {
|
|
|
5987
6338
|
]
|
|
5988
6339
|
}
|
|
5989
6340
|
},
|
|
6341
|
+
{
|
|
6342
|
+
name: "BondInitialized",
|
|
6343
|
+
type: {
|
|
6344
|
+
kind: "struct",
|
|
6345
|
+
fields: [
|
|
6346
|
+
{
|
|
6347
|
+
name: "bond",
|
|
6348
|
+
type: "pubkey"
|
|
6349
|
+
},
|
|
6350
|
+
{
|
|
6351
|
+
name: "authority",
|
|
6352
|
+
type: "pubkey"
|
|
6353
|
+
},
|
|
6354
|
+
{
|
|
6355
|
+
name: "timestamp",
|
|
6356
|
+
type: "i64"
|
|
6357
|
+
}
|
|
6358
|
+
]
|
|
6359
|
+
}
|
|
6360
|
+
},
|
|
6361
|
+
{
|
|
6362
|
+
name: "BondRemoved",
|
|
6363
|
+
type: {
|
|
6364
|
+
kind: "struct",
|
|
6365
|
+
fields: [
|
|
6366
|
+
{
|
|
6367
|
+
name: "bond",
|
|
6368
|
+
type: "pubkey"
|
|
6369
|
+
},
|
|
6370
|
+
{
|
|
6371
|
+
name: "authority",
|
|
6372
|
+
type: "pubkey"
|
|
6373
|
+
},
|
|
6374
|
+
{
|
|
6375
|
+
name: "timestamp",
|
|
6376
|
+
type: "i64"
|
|
6377
|
+
}
|
|
6378
|
+
]
|
|
6379
|
+
}
|
|
6380
|
+
},
|
|
5990
6381
|
{
|
|
5991
6382
|
name: "BondStarted",
|
|
5992
6383
|
type: {
|
|
@@ -6140,7 +6531,7 @@ var jbond_default = {
|
|
|
6140
6531
|
}
|
|
6141
6532
|
},
|
|
6142
6533
|
{
|
|
6143
|
-
name: "
|
|
6534
|
+
name: "CollateralDeposited",
|
|
6144
6535
|
type: {
|
|
6145
6536
|
kind: "struct",
|
|
6146
6537
|
fields: [
|
|
@@ -6210,6 +6601,34 @@ var jbond_default = {
|
|
|
6210
6601
|
]
|
|
6211
6602
|
}
|
|
6212
6603
|
},
|
|
6604
|
+
{
|
|
6605
|
+
name: "CompensationBurned",
|
|
6606
|
+
type: {
|
|
6607
|
+
kind: "struct",
|
|
6608
|
+
fields: [
|
|
6609
|
+
{
|
|
6610
|
+
name: "validator",
|
|
6611
|
+
type: "pubkey"
|
|
6612
|
+
},
|
|
6613
|
+
{
|
|
6614
|
+
name: "amount",
|
|
6615
|
+
type: "u64"
|
|
6616
|
+
},
|
|
6617
|
+
{
|
|
6618
|
+
name: "post_balance",
|
|
6619
|
+
type: "u64"
|
|
6620
|
+
},
|
|
6621
|
+
{
|
|
6622
|
+
name: "epoch",
|
|
6623
|
+
type: "u64"
|
|
6624
|
+
},
|
|
6625
|
+
{
|
|
6626
|
+
name: "timestamp",
|
|
6627
|
+
type: "i64"
|
|
6628
|
+
}
|
|
6629
|
+
]
|
|
6630
|
+
}
|
|
6631
|
+
},
|
|
6213
6632
|
{
|
|
6214
6633
|
name: "CompensationClaimed",
|
|
6215
6634
|
type: {
|
|
@@ -6238,6 +6657,54 @@ var jbond_default = {
|
|
|
6238
6657
|
]
|
|
6239
6658
|
}
|
|
6240
6659
|
},
|
|
6660
|
+
{
|
|
6661
|
+
name: "FundsLocked",
|
|
6662
|
+
type: {
|
|
6663
|
+
kind: "struct",
|
|
6664
|
+
fields: [
|
|
6665
|
+
{
|
|
6666
|
+
name: "validator",
|
|
6667
|
+
type: "pubkey"
|
|
6668
|
+
},
|
|
6669
|
+
{
|
|
6670
|
+
name: "amount",
|
|
6671
|
+
type: "u64"
|
|
6672
|
+
},
|
|
6673
|
+
{
|
|
6674
|
+
name: "total_locked",
|
|
6675
|
+
type: "u64"
|
|
6676
|
+
},
|
|
6677
|
+
{
|
|
6678
|
+
name: "epoch",
|
|
6679
|
+
type: "u64"
|
|
6680
|
+
}
|
|
6681
|
+
]
|
|
6682
|
+
}
|
|
6683
|
+
},
|
|
6684
|
+
{
|
|
6685
|
+
name: "FundsUnlocked",
|
|
6686
|
+
type: {
|
|
6687
|
+
kind: "struct",
|
|
6688
|
+
fields: [
|
|
6689
|
+
{
|
|
6690
|
+
name: "validator",
|
|
6691
|
+
type: "pubkey"
|
|
6692
|
+
},
|
|
6693
|
+
{
|
|
6694
|
+
name: "amount",
|
|
6695
|
+
type: "u64"
|
|
6696
|
+
},
|
|
6697
|
+
{
|
|
6698
|
+
name: "pending_unlock",
|
|
6699
|
+
type: "u64"
|
|
6700
|
+
},
|
|
6701
|
+
{
|
|
6702
|
+
name: "epoch",
|
|
6703
|
+
type: "u64"
|
|
6704
|
+
}
|
|
6705
|
+
]
|
|
6706
|
+
}
|
|
6707
|
+
},
|
|
6241
6708
|
{
|
|
6242
6709
|
name: "GlobalConfigureData",
|
|
6243
6710
|
type: {
|
|
@@ -6260,9 +6727,69 @@ var jbond_default = {
|
|
|
6260
6727
|
{
|
|
6261
6728
|
name: "authority",
|
|
6262
6729
|
docs: [
|
|
6263
|
-
"The authority allowed to manage the program"
|
|
6730
|
+
"The authority allowed to manage the program"
|
|
6731
|
+
],
|
|
6732
|
+
type: "pubkey"
|
|
6733
|
+
},
|
|
6734
|
+
{
|
|
6735
|
+
name: "bump",
|
|
6736
|
+
docs: [
|
|
6737
|
+
"Bump for the PDA"
|
|
6738
|
+
],
|
|
6739
|
+
type: "u8"
|
|
6740
|
+
}
|
|
6741
|
+
]
|
|
6742
|
+
}
|
|
6743
|
+
},
|
|
6744
|
+
{
|
|
6745
|
+
name: "ValidatorBond",
|
|
6746
|
+
type: {
|
|
6747
|
+
kind: "struct",
|
|
6748
|
+
fields: [
|
|
6749
|
+
{
|
|
6750
|
+
name: "state",
|
|
6751
|
+
docs: [
|
|
6752
|
+
"The bond state address"
|
|
6753
|
+
],
|
|
6754
|
+
type: "pubkey"
|
|
6755
|
+
},
|
|
6756
|
+
{
|
|
6757
|
+
name: "identity",
|
|
6758
|
+
docs: [
|
|
6759
|
+
"Validator identity pubkey"
|
|
6760
|
+
],
|
|
6761
|
+
type: "pubkey"
|
|
6762
|
+
},
|
|
6763
|
+
{
|
|
6764
|
+
name: "vote_account",
|
|
6765
|
+
docs: [
|
|
6766
|
+
"Validator vote account pubkey"
|
|
6767
|
+
],
|
|
6768
|
+
type: "pubkey"
|
|
6769
|
+
},
|
|
6770
|
+
{
|
|
6771
|
+
name: "creator",
|
|
6772
|
+
docs: [
|
|
6773
|
+
"The bond creator pubkey"
|
|
6774
|
+
],
|
|
6775
|
+
type: "pubkey"
|
|
6776
|
+
},
|
|
6777
|
+
{
|
|
6778
|
+
name: "withdrawal_authority",
|
|
6779
|
+
docs: [
|
|
6780
|
+
"Optional withdrawal authority pubkey (if set, can withdraw on behalf of the validator,",
|
|
6781
|
+
"otherwise only identity can withdraw)"
|
|
6782
|
+
],
|
|
6783
|
+
type: {
|
|
6784
|
+
option: "pubkey"
|
|
6785
|
+
}
|
|
6786
|
+
},
|
|
6787
|
+
{
|
|
6788
|
+
name: "created_at",
|
|
6789
|
+
docs: [
|
|
6790
|
+
"Bond creation timestamp"
|
|
6264
6791
|
],
|
|
6265
|
-
type: "
|
|
6792
|
+
type: "i64"
|
|
6266
6793
|
},
|
|
6267
6794
|
{
|
|
6268
6795
|
name: "bump",
|
|
@@ -6270,21 +6797,38 @@ var jbond_default = {
|
|
|
6270
6797
|
"Bump for the PDA"
|
|
6271
6798
|
],
|
|
6272
6799
|
type: "u8"
|
|
6800
|
+
},
|
|
6801
|
+
{
|
|
6802
|
+
name: "locked",
|
|
6803
|
+
docs: [
|
|
6804
|
+
"Amount of collateral currently locked (unavailable for withdrawal)"
|
|
6805
|
+
],
|
|
6806
|
+
type: "u64"
|
|
6807
|
+
},
|
|
6808
|
+
{
|
|
6809
|
+
name: "pending_unlock",
|
|
6810
|
+
docs: [
|
|
6811
|
+
"Pending unlock amount (will reduce `locked` next epoch)"
|
|
6812
|
+
],
|
|
6813
|
+
type: "u64"
|
|
6814
|
+
},
|
|
6815
|
+
{
|
|
6816
|
+
name: "pending_unlock_epoch",
|
|
6817
|
+
docs: [
|
|
6818
|
+
"Epoch when pending_unlock was queued"
|
|
6819
|
+
],
|
|
6820
|
+
type: "u64"
|
|
6273
6821
|
}
|
|
6274
6822
|
]
|
|
6275
6823
|
}
|
|
6276
6824
|
},
|
|
6277
6825
|
{
|
|
6278
|
-
name: "
|
|
6826
|
+
name: "ValidatorBondClosed",
|
|
6279
6827
|
type: {
|
|
6280
6828
|
kind: "struct",
|
|
6281
6829
|
fields: [
|
|
6282
6830
|
{
|
|
6283
|
-
name: "
|
|
6284
|
-
type: "pubkey"
|
|
6285
|
-
},
|
|
6286
|
-
{
|
|
6287
|
-
name: "identity",
|
|
6831
|
+
name: "validator",
|
|
6288
6832
|
type: "pubkey"
|
|
6289
6833
|
},
|
|
6290
6834
|
{
|
|
@@ -6292,22 +6836,16 @@ var jbond_default = {
|
|
|
6292
6836
|
type: "pubkey"
|
|
6293
6837
|
},
|
|
6294
6838
|
{
|
|
6295
|
-
name: "
|
|
6839
|
+
name: "rent_receiver",
|
|
6296
6840
|
type: "pubkey"
|
|
6297
6841
|
},
|
|
6298
6842
|
{
|
|
6299
|
-
name: "
|
|
6300
|
-
type:
|
|
6301
|
-
option: "pubkey"
|
|
6302
|
-
}
|
|
6843
|
+
name: "final_balance",
|
|
6844
|
+
type: "u64"
|
|
6303
6845
|
},
|
|
6304
6846
|
{
|
|
6305
|
-
name: "
|
|
6847
|
+
name: "timestamp",
|
|
6306
6848
|
type: "i64"
|
|
6307
|
-
},
|
|
6308
|
-
{
|
|
6309
|
-
name: "bump",
|
|
6310
|
-
type: "u8"
|
|
6311
6849
|
}
|
|
6312
6850
|
]
|
|
6313
6851
|
}
|
|
@@ -6318,7 +6856,7 @@ var jbond_default = {
|
|
|
6318
6856
|
kind: "struct",
|
|
6319
6857
|
fields: [
|
|
6320
6858
|
{
|
|
6321
|
-
name: "
|
|
6859
|
+
name: "validator",
|
|
6322
6860
|
type: "pubkey"
|
|
6323
6861
|
},
|
|
6324
6862
|
{
|
|
@@ -6331,6 +6869,30 @@ var jbond_default = {
|
|
|
6331
6869
|
}
|
|
6332
6870
|
]
|
|
6333
6871
|
}
|
|
6872
|
+
},
|
|
6873
|
+
{
|
|
6874
|
+
name: "WithdrawAuthorityChanged",
|
|
6875
|
+
type: {
|
|
6876
|
+
kind: "struct",
|
|
6877
|
+
fields: [
|
|
6878
|
+
{
|
|
6879
|
+
name: "validator",
|
|
6880
|
+
type: "pubkey"
|
|
6881
|
+
},
|
|
6882
|
+
{
|
|
6883
|
+
name: "old_authority",
|
|
6884
|
+
type: {
|
|
6885
|
+
option: "pubkey"
|
|
6886
|
+
}
|
|
6887
|
+
},
|
|
6888
|
+
{
|
|
6889
|
+
name: "new_authority",
|
|
6890
|
+
type: {
|
|
6891
|
+
option: "pubkey"
|
|
6892
|
+
}
|
|
6893
|
+
}
|
|
6894
|
+
]
|
|
6895
|
+
}
|
|
6334
6896
|
}
|
|
6335
6897
|
],
|
|
6336
6898
|
constants: [
|
|
@@ -6394,6 +6956,25 @@ function anchorToBondType(variant) {
|
|
|
6394
6956
|
return fromAnchor(variant);
|
|
6395
6957
|
}
|
|
6396
6958
|
|
|
6959
|
+
// src/utils/stake-pool.ts
|
|
6960
|
+
init_cjs_shims();
|
|
6961
|
+
async function getStakePoolAccountData(connection, stakePoolAddress) {
|
|
6962
|
+
const stakePoolAccount = await splStakePool.getStakePoolAccount(connection, stakePoolAddress);
|
|
6963
|
+
if (!stakePoolAccount) {
|
|
6964
|
+
throw new Error(`Stake pool account not found: ${stakePoolAddress.toBase58()}`);
|
|
6965
|
+
}
|
|
6966
|
+
return stakePoolAccount.account.data;
|
|
6967
|
+
}
|
|
6968
|
+
function lamportsToPoolTokenLamports(lamports, stakePool) {
|
|
6969
|
+
if (stakePool.totalLamports.isZero()) {
|
|
6970
|
+
throw new Error("Stake pool has zero total lamports");
|
|
6971
|
+
}
|
|
6972
|
+
if (stakePool.poolTokenSupply.isZero()) {
|
|
6973
|
+
throw new Error("Stake pool has zero pool token supply");
|
|
6974
|
+
}
|
|
6975
|
+
return lamports.mul(stakePool.poolTokenSupply).div(stakePool.totalLamports);
|
|
6976
|
+
}
|
|
6977
|
+
|
|
6397
6978
|
// src/utils/wallet.ts
|
|
6398
6979
|
init_cjs_shims();
|
|
6399
6980
|
function isVersionedTransaction(tx) {
|
|
@@ -6429,6 +7010,20 @@ var NodeWallet = class {
|
|
|
6429
7010
|
// src/utils/web3.ts
|
|
6430
7011
|
init_cjs_shims();
|
|
6431
7012
|
var SOL_DECIMALS = Math.log10(web3_js.LAMPORTS_PER_SOL);
|
|
7013
|
+
function lamportsToSol(lamports) {
|
|
7014
|
+
if (typeof lamports === "number") {
|
|
7015
|
+
return Math.abs(lamports) / web3_js.LAMPORTS_PER_SOL;
|
|
7016
|
+
}
|
|
7017
|
+
let signMultiplier = 1;
|
|
7018
|
+
if (lamports.isNeg()) {
|
|
7019
|
+
signMultiplier = -1;
|
|
7020
|
+
}
|
|
7021
|
+
const absLamports = lamports.abs();
|
|
7022
|
+
const lamportsString = absLamports.toString(10).padStart(10, "0");
|
|
7023
|
+
const splitIndex = lamportsString.length - SOL_DECIMALS;
|
|
7024
|
+
const solString = `${lamportsString.slice(0, splitIndex)}.${lamportsString.slice(splitIndex)}`;
|
|
7025
|
+
return signMultiplier * Number.parseFloat(solString);
|
|
7026
|
+
}
|
|
6432
7027
|
function solToLamports(amount) {
|
|
6433
7028
|
if (Number.isNaN(amount)) {
|
|
6434
7029
|
return new anchor.BN(0);
|
|
@@ -6449,20 +7044,13 @@ function getBondTypeSeed(type) {
|
|
|
6449
7044
|
}
|
|
6450
7045
|
|
|
6451
7046
|
// src/client.ts
|
|
6452
|
-
var JBondClientEnv = /* @__PURE__ */ ((JBondClientEnv2) => {
|
|
6453
|
-
JBondClientEnv2["DEV"] = "dev";
|
|
6454
|
-
JBondClientEnv2["STAGE"] = "stage";
|
|
6455
|
-
JBondClientEnv2["PROD"] = "prod";
|
|
6456
|
-
return JBondClientEnv2;
|
|
6457
|
-
})(JBondClientEnv || {});
|
|
6458
7047
|
var JBondClient = class _JBondClient {
|
|
6459
7048
|
constructor(provider, options) {
|
|
6460
7049
|
this.provider = provider;
|
|
6461
7050
|
this.options = options ?? {};
|
|
6462
|
-
this.program = new anchor.Program(jbond_default, this.provider);
|
|
6463
7051
|
}
|
|
6464
7052
|
options;
|
|
6465
|
-
|
|
7053
|
+
_program = null;
|
|
6466
7054
|
get history() {
|
|
6467
7055
|
return new HistoryManager(this);
|
|
6468
7056
|
}
|
|
@@ -6491,11 +7079,24 @@ var JBondClient = class _JBondClient {
|
|
|
6491
7079
|
static fromKeypair(connection, keypair, options) {
|
|
6492
7080
|
return _JBondClient.fromWallet(connection, new NodeWallet(keypair), options);
|
|
6493
7081
|
}
|
|
7082
|
+
/**
|
|
7083
|
+
* Get or create the program instance
|
|
7084
|
+
*/
|
|
7085
|
+
get program() {
|
|
7086
|
+
if (!this._program) {
|
|
7087
|
+
jbond_default.address = this.programId.toBase58();
|
|
7088
|
+
this._program = new anchor.Program(jbond_default, this.provider);
|
|
7089
|
+
}
|
|
7090
|
+
return this._program;
|
|
7091
|
+
}
|
|
6494
7092
|
/**
|
|
6495
7093
|
* Get the current program ID.
|
|
6496
7094
|
*/
|
|
6497
7095
|
get programId() {
|
|
6498
|
-
|
|
7096
|
+
if (this.options.programId) {
|
|
7097
|
+
return this.options.programId;
|
|
7098
|
+
}
|
|
7099
|
+
return new web3_js.PublicKey(ENV_PROGRAM_ID["prod" /* PROD */]);
|
|
6499
7100
|
}
|
|
6500
7101
|
/**
|
|
6501
7102
|
* Get the current connection.
|
|
@@ -6507,13 +7108,22 @@ var JBondClient = class _JBondClient {
|
|
|
6507
7108
|
* Set the environment.
|
|
6508
7109
|
*/
|
|
6509
7110
|
env(env) {
|
|
6510
|
-
|
|
7111
|
+
const envProgramId = ENV_PROGRAM_ID[env];
|
|
7112
|
+
if (!envProgramId) {
|
|
7113
|
+
throw new Error(`Invalid environment: ${env}`);
|
|
7114
|
+
}
|
|
7115
|
+
this._program = null;
|
|
7116
|
+
this.debug(`Set environment to ${env} with program ID: ${envProgramId.toString()}`);
|
|
7117
|
+
return this.configure("programId", new web3_js.PublicKey(envProgramId));
|
|
6511
7118
|
}
|
|
6512
7119
|
/**
|
|
6513
7120
|
* Configure a specific option.
|
|
6514
7121
|
*/
|
|
6515
7122
|
configure(key, val) {
|
|
6516
7123
|
this.options[key] = val;
|
|
7124
|
+
if (key === "programId") {
|
|
7125
|
+
this._program = null;
|
|
7126
|
+
}
|
|
6517
7127
|
return this;
|
|
6518
7128
|
}
|
|
6519
7129
|
/**
|
|
@@ -6572,8 +7182,8 @@ var JBondClient = class _JBondClient {
|
|
|
6572
7182
|
* Top up collateral
|
|
6573
7183
|
*/
|
|
6574
7184
|
async topUpCollateral(props) {
|
|
6575
|
-
const
|
|
6576
|
-
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(...
|
|
7185
|
+
const { instructions, signers } = await this.getTopUpIxs(props);
|
|
7186
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(...instructions), signers);
|
|
6577
7187
|
}
|
|
6578
7188
|
/**
|
|
6579
7189
|
* Withdraw collateral
|
|
@@ -6583,7 +7193,14 @@ var JBondClient = class _JBondClient {
|
|
|
6583
7193
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6584
7194
|
}
|
|
6585
7195
|
/**
|
|
6586
|
-
*
|
|
7196
|
+
* Migrate SOL collateral from one bond account to JSOL collateral in another bond account
|
|
7197
|
+
*/
|
|
7198
|
+
async migrateBond(props) {
|
|
7199
|
+
const { instructions, signers } = await this.getMigrateBondIx(props);
|
|
7200
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(...instructions), signers);
|
|
7201
|
+
}
|
|
7202
|
+
/**
|
|
7203
|
+
* Claim compensation for a validator
|
|
6587
7204
|
*/
|
|
6588
7205
|
async claimCompensation(props) {
|
|
6589
7206
|
const ix = await this.getClaimIx(props);
|
|
@@ -6624,6 +7241,14 @@ var JBondClient = class _JBondClient {
|
|
|
6624
7241
|
const ix = await this.getBondSessionFinishIx(props);
|
|
6625
7242
|
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
6626
7243
|
}
|
|
7244
|
+
async bondRemove(props) {
|
|
7245
|
+
const ix = await this.getBondRemoveIx(props);
|
|
7246
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7247
|
+
}
|
|
7248
|
+
async closeValidatorBond(props) {
|
|
7249
|
+
const ix = await this.getCloseValidatorBondIx(props);
|
|
7250
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7251
|
+
}
|
|
6627
7252
|
/**
|
|
6628
7253
|
* Build global state initialize instruction
|
|
6629
7254
|
*/
|
|
@@ -6734,6 +7359,9 @@ var JBondClient = class _JBondClient {
|
|
|
6734
7359
|
collateralType = bondState2.collateralType;
|
|
6735
7360
|
}
|
|
6736
7361
|
const instructions = [];
|
|
7362
|
+
const signers = [];
|
|
7363
|
+
const amountLamports = solToLamports(amount);
|
|
7364
|
+
let topUpAmount = amountLamports;
|
|
6737
7365
|
try {
|
|
6738
7366
|
await this.getValidatorBond(props.bondType, props.name, props.voteAccount);
|
|
6739
7367
|
} catch {
|
|
@@ -6765,10 +7393,33 @@ var JBondClient = class _JBondClient {
|
|
|
6765
7393
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6766
7394
|
}
|
|
6767
7395
|
});
|
|
7396
|
+
if (props.solUsage) {
|
|
7397
|
+
let usesJsolCollateral = false;
|
|
7398
|
+
matchVariant(collateralType, {
|
|
7399
|
+
token: (mint) => {
|
|
7400
|
+
usesJsolCollateral = mint.equals(JSOL_MINT);
|
|
7401
|
+
}
|
|
7402
|
+
});
|
|
7403
|
+
if (usesJsolCollateral) {
|
|
7404
|
+
const stakePool = await getStakePoolAccountData(this.connection, JPOOL_POOL_ADDRESS);
|
|
7405
|
+
const deposit = await splStakePool.depositSol(
|
|
7406
|
+
this.connection,
|
|
7407
|
+
JPOOL_POOL_ADDRESS,
|
|
7408
|
+
payer,
|
|
7409
|
+
amountLamports.toNumber(),
|
|
7410
|
+
void 0,
|
|
7411
|
+
void 0,
|
|
7412
|
+
void 0
|
|
7413
|
+
);
|
|
7414
|
+
instructions.push(...deposit.instructions);
|
|
7415
|
+
signers.push(...deposit.signers);
|
|
7416
|
+
topUpAmount = lamportsToPoolTokenLamports(amountLamports, stakePool);
|
|
7417
|
+
}
|
|
7418
|
+
}
|
|
6768
7419
|
instructions.push(
|
|
6769
|
-
await this.program.methods.bondTopUp(
|
|
7420
|
+
await this.program.methods.bondTopUp(topUpAmount).accountsPartial(accounts).instruction()
|
|
6770
7421
|
);
|
|
6771
|
-
return instructions;
|
|
7422
|
+
return { instructions, signers };
|
|
6772
7423
|
}
|
|
6773
7424
|
/**
|
|
6774
7425
|
* Build withdraw collateral instruction
|
|
@@ -6807,6 +7458,139 @@ var JBondClient = class _JBondClient {
|
|
|
6807
7458
|
});
|
|
6808
7459
|
return this.program.methods.bondWithdraw(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
6809
7460
|
}
|
|
7461
|
+
/**
|
|
7462
|
+
* Build instructions for migrating SOL bond collateral into JSOL bond collateral in a single transaction
|
|
7463
|
+
*/
|
|
7464
|
+
async getMigrateBondIx(props) {
|
|
7465
|
+
const {
|
|
7466
|
+
bondType,
|
|
7467
|
+
voteAccount,
|
|
7468
|
+
identity,
|
|
7469
|
+
withdrawName = "performance",
|
|
7470
|
+
topUpName = "perf",
|
|
7471
|
+
stakePoolAddress = JPOOL_POOL_ADDRESS
|
|
7472
|
+
} = props;
|
|
7473
|
+
const payer = props.payer ?? this.provider.wallet?.publicKey;
|
|
7474
|
+
const destination = props.destination ?? payer;
|
|
7475
|
+
if (!payer || !destination) {
|
|
7476
|
+
throw new Error("Missing payer/destination");
|
|
7477
|
+
}
|
|
7478
|
+
const withdrawBondState = await this.getBondState(bondType, withdrawName);
|
|
7479
|
+
await matchVariant(withdrawBondState.collateralType, {
|
|
7480
|
+
native: () => {
|
|
7481
|
+
},
|
|
7482
|
+
token: () => {
|
|
7483
|
+
throw new Error("Withdraw bond collateral type must be native SOL for migration");
|
|
7484
|
+
}
|
|
7485
|
+
});
|
|
7486
|
+
const availableLamports = await this.getAvailableCollateral(bondType, withdrawName, voteAccount);
|
|
7487
|
+
if (!availableLamports || availableLamports <= 0) {
|
|
7488
|
+
throw new Error("No available balance to migrate");
|
|
7489
|
+
}
|
|
7490
|
+
const amount = lamportsToSol(availableLamports);
|
|
7491
|
+
const amountLamports = solToLamports(amount);
|
|
7492
|
+
const withdrawIx = await this.getWithdrawIx({
|
|
7493
|
+
bondType,
|
|
7494
|
+
name: withdrawName,
|
|
7495
|
+
amount,
|
|
7496
|
+
voteAccount,
|
|
7497
|
+
destination,
|
|
7498
|
+
withdrawalAuthority: props.withdrawalAuthority
|
|
7499
|
+
});
|
|
7500
|
+
const deposit = await this.getDepositSolIxsWithoutBalanceCheck(
|
|
7501
|
+
stakePoolAddress,
|
|
7502
|
+
payer,
|
|
7503
|
+
amountLamports.toNumber()
|
|
7504
|
+
);
|
|
7505
|
+
const topUpBondState = await this.getBondState(bondType, topUpName);
|
|
7506
|
+
const topUpCollateralType = topUpBondState.collateralType;
|
|
7507
|
+
const instructions = [withdrawIx, ...deposit.instructions];
|
|
7508
|
+
const signers = [...deposit.signers];
|
|
7509
|
+
try {
|
|
7510
|
+
await this.getValidatorBond(bondType, topUpName, voteAccount);
|
|
7511
|
+
} catch {
|
|
7512
|
+
instructions.push(
|
|
7513
|
+
await this.getRegisterValidatorIx({
|
|
7514
|
+
bondType,
|
|
7515
|
+
name: topUpName,
|
|
7516
|
+
voteAccount,
|
|
7517
|
+
identity,
|
|
7518
|
+
creator: payer,
|
|
7519
|
+
collateralType: topUpCollateralType
|
|
7520
|
+
})
|
|
7521
|
+
);
|
|
7522
|
+
}
|
|
7523
|
+
const [topUpBondStateAddress] = this.pda.bondState(bondType, topUpName);
|
|
7524
|
+
const [topUpValidatorBond] = this.pda.validatorBond(bondType, topUpName, voteAccount);
|
|
7525
|
+
await matchVariant(topUpCollateralType, {
|
|
7526
|
+
native: () => {
|
|
7527
|
+
throw new Error("Top up bond collateral type must be token for migration");
|
|
7528
|
+
},
|
|
7529
|
+
token: async (mint) => {
|
|
7530
|
+
const stakePool = await getStakePoolAccountData(this.connection, stakePoolAddress);
|
|
7531
|
+
const topUpAmount = lamportsToPoolTokenLamports(amountLamports, stakePool);
|
|
7532
|
+
const topUpIx = await this.program.methods.bondTopUp(topUpAmount).accountsPartial({
|
|
7533
|
+
bondState: topUpBondStateAddress,
|
|
7534
|
+
validatorBond: topUpValidatorBond,
|
|
7535
|
+
payer,
|
|
7536
|
+
payerTokenAccount: splToken.getAssociatedTokenAddressSync(mint, payer),
|
|
7537
|
+
bondTokenAccount: splToken.getAssociatedTokenAddressSync(mint, topUpValidatorBond, true),
|
|
7538
|
+
stakeAccount: null,
|
|
7539
|
+
stakeProgram: null
|
|
7540
|
+
}).instruction();
|
|
7541
|
+
instructions.push(topUpIx);
|
|
7542
|
+
}
|
|
7543
|
+
});
|
|
7544
|
+
return { instructions, signers };
|
|
7545
|
+
}
|
|
7546
|
+
/**
|
|
7547
|
+
* Build stake-pool SOL deposit instructions without pre-checking payer balance.
|
|
7548
|
+
* This allows composing withdraw->deposit in a single transaction where SOL is obtained by the prior instruction.
|
|
7549
|
+
*/
|
|
7550
|
+
async getDepositSolIxsWithoutBalanceCheck(stakePoolAddress, payer, lamports, destinationTokenAccount, referrerTokenAccount, depositAuthority) {
|
|
7551
|
+
const stakePool = await getStakePoolAccountData(this.connection, stakePoolAddress);
|
|
7552
|
+
const transferSigner = new web3_js.Keypair();
|
|
7553
|
+
const signers = [transferSigner];
|
|
7554
|
+
const instructions = [
|
|
7555
|
+
web3_js.SystemProgram.transfer({
|
|
7556
|
+
fromPubkey: payer,
|
|
7557
|
+
toPubkey: transferSigner.publicKey,
|
|
7558
|
+
lamports
|
|
7559
|
+
})
|
|
7560
|
+
];
|
|
7561
|
+
let destinationPoolAccount = destinationTokenAccount;
|
|
7562
|
+
if (!destinationPoolAccount) {
|
|
7563
|
+
const associatedAddress = splToken.getAssociatedTokenAddressSync(stakePool.poolMint, payer);
|
|
7564
|
+
instructions.push(
|
|
7565
|
+
splToken.createAssociatedTokenAccountIdempotentInstruction(
|
|
7566
|
+
payer,
|
|
7567
|
+
associatedAddress,
|
|
7568
|
+
payer,
|
|
7569
|
+
stakePool.poolMint
|
|
7570
|
+
)
|
|
7571
|
+
);
|
|
7572
|
+
destinationPoolAccount = associatedAddress;
|
|
7573
|
+
}
|
|
7574
|
+
const [withdrawAuthority] = web3_js.PublicKey.findProgramAddressSync(
|
|
7575
|
+
[stakePoolAddress.toBuffer(), Buffer.from("withdraw")],
|
|
7576
|
+
splStakePool.STAKE_POOL_PROGRAM_ID
|
|
7577
|
+
);
|
|
7578
|
+
instructions.push(
|
|
7579
|
+
splStakePool.StakePoolInstruction.depositSol({
|
|
7580
|
+
stakePool: stakePoolAddress,
|
|
7581
|
+
reserveStake: stakePool.reserveStake,
|
|
7582
|
+
fundingAccount: transferSigner.publicKey,
|
|
7583
|
+
destinationPoolAccount,
|
|
7584
|
+
managerFeeAccount: stakePool.managerFeeAccount,
|
|
7585
|
+
referralPoolAccount: referrerTokenAccount ?? destinationPoolAccount,
|
|
7586
|
+
poolMint: stakePool.poolMint,
|
|
7587
|
+
lamports,
|
|
7588
|
+
withdrawAuthority,
|
|
7589
|
+
depositAuthority
|
|
7590
|
+
})
|
|
7591
|
+
);
|
|
7592
|
+
return { instructions, signers };
|
|
7593
|
+
}
|
|
6810
7594
|
/**
|
|
6811
7595
|
* Build claim instruction
|
|
6812
7596
|
*/
|
|
@@ -6837,13 +7621,47 @@ var JBondClient = class _JBondClient {
|
|
|
6837
7621
|
native: () => {
|
|
6838
7622
|
},
|
|
6839
7623
|
token: (mint) => {
|
|
6840
|
-
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6841
7624
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6842
|
-
|
|
7625
|
+
if (reserve.equals(mint)) {
|
|
7626
|
+
accounts.reserveTokenAccount = null;
|
|
7627
|
+
accounts.destinationTokenAccount = null;
|
|
7628
|
+
} else {
|
|
7629
|
+
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
7630
|
+
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
7631
|
+
}
|
|
6843
7632
|
}
|
|
6844
7633
|
});
|
|
6845
7634
|
return this.program.methods.bondClaim(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
6846
7635
|
}
|
|
7636
|
+
/**
|
|
7637
|
+
* Build claim all compensations instructions
|
|
7638
|
+
*/
|
|
7639
|
+
async getClaimAllCompensationsIxs(props) {
|
|
7640
|
+
const ixs = [];
|
|
7641
|
+
const validatorBondBalances = await this.getBondStateValidatorBondBalances(
|
|
7642
|
+
props.bondType,
|
|
7643
|
+
props.name
|
|
7644
|
+
);
|
|
7645
|
+
for (const bond_balance of validatorBondBalances) {
|
|
7646
|
+
const amountToClaim = lamportsToSol(bond_balance.balance);
|
|
7647
|
+
if (amountToClaim <= 0) {
|
|
7648
|
+
this.debug("No balance to claim for validator:", bond_balance.voteAccount.toBase58());
|
|
7649
|
+
continue;
|
|
7650
|
+
}
|
|
7651
|
+
this.debug("Amount to claim:", amountToClaim);
|
|
7652
|
+
const ix = await this.getClaimIx({
|
|
7653
|
+
bondType: props.bondType,
|
|
7654
|
+
name: props.name,
|
|
7655
|
+
amount: amountToClaim,
|
|
7656
|
+
collateralType: props.collateralType,
|
|
7657
|
+
reserve: props.reserve,
|
|
7658
|
+
authority: props.authority,
|
|
7659
|
+
voteAccount: bond_balance.voteAccount
|
|
7660
|
+
});
|
|
7661
|
+
ixs.push(ix);
|
|
7662
|
+
}
|
|
7663
|
+
return ixs;
|
|
7664
|
+
}
|
|
6847
7665
|
/**
|
|
6848
7666
|
* Build set withdraw authority instruction
|
|
6849
7667
|
*/
|
|
@@ -6872,23 +7690,150 @@ var JBondClient = class _JBondClient {
|
|
|
6872
7690
|
const authority = this.provider.wallet?.publicKey;
|
|
6873
7691
|
return this.program.methods.sessionStart(new import_bn.BN(props.duration)).accountsPartial({ bondState, authority }).instruction();
|
|
6874
7692
|
}
|
|
7693
|
+
async lockFunds(props) {
|
|
7694
|
+
const ix = await this.getLockFundsIx(props);
|
|
7695
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7696
|
+
}
|
|
7697
|
+
async releaseFunds(props) {
|
|
7698
|
+
const ix = await this.getReleaseFundsIx(props);
|
|
7699
|
+
return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
|
|
7700
|
+
}
|
|
7701
|
+
/**
|
|
7702
|
+
* Build bond remove instruction
|
|
7703
|
+
*/
|
|
7704
|
+
async getBondRemoveIx(props) {
|
|
7705
|
+
const { bondType, name } = props;
|
|
7706
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7707
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
7708
|
+
return this.program.methods.bondRemove().accountsPartial({ bondState, authority }).instruction();
|
|
7709
|
+
}
|
|
7710
|
+
/**
|
|
7711
|
+
* Build close validator bond instruction
|
|
7712
|
+
*/
|
|
7713
|
+
async getCloseValidatorBondIx(props) {
|
|
7714
|
+
const { bondType, name, voteAccount } = props;
|
|
7715
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7716
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7717
|
+
const authority = props.authority ?? this.provider.wallet?.publicKey;
|
|
7718
|
+
const rentReceiver = props.rentReceiver ?? authority;
|
|
7719
|
+
if (!authority || !rentReceiver) {
|
|
7720
|
+
throw new Error("Missing authority or rentReceiver");
|
|
7721
|
+
}
|
|
7722
|
+
let collateralType = props.collateralType;
|
|
7723
|
+
if (!collateralType) {
|
|
7724
|
+
const state = await this.getBondState(bondType, name);
|
|
7725
|
+
collateralType = state.collateralType;
|
|
7726
|
+
}
|
|
7727
|
+
const accounts = {
|
|
7728
|
+
bondState,
|
|
7729
|
+
validatorBond,
|
|
7730
|
+
authority,
|
|
7731
|
+
rentReceiver,
|
|
7732
|
+
bondTokenAccount: null,
|
|
7733
|
+
destinationTokenAccount: null
|
|
7734
|
+
};
|
|
7735
|
+
matchVariant(collateralType, {
|
|
7736
|
+
native: () => {
|
|
7737
|
+
},
|
|
7738
|
+
token: (mint) => {
|
|
7739
|
+
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7740
|
+
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, rentReceiver, true);
|
|
7741
|
+
}
|
|
7742
|
+
});
|
|
7743
|
+
return this.program.methods.closeValidatorBond().accountsPartial(accounts).instruction();
|
|
7744
|
+
}
|
|
7745
|
+
/**
|
|
7746
|
+
* Build test set last update epoch instruction
|
|
7747
|
+
* NOTE!: This instruction is for testing purposes only.
|
|
7748
|
+
* It allows direct manipulation of the validator bond's last epoch update.
|
|
7749
|
+
* This should not be used in production environments.
|
|
7750
|
+
*/
|
|
7751
|
+
// async getTestSetLastUpdateEpochIx(props: { bondType: BondType, bondName: string, voteAccount: PublicKeyInitData, payer: PublicKey, epoch: number }) {
|
|
7752
|
+
// const { bondType, bondName, voteAccount, payer, epoch } = props
|
|
7753
|
+
// const [validatorBond, _] = this.pda.validatorBond(bondType, bondName, voteAccount)
|
|
7754
|
+
// return this.program.methods
|
|
7755
|
+
// .testSetLastUpdateEpoch(new BN(epoch))
|
|
7756
|
+
// .accountsPartial({ validatorBond, payer })
|
|
7757
|
+
// .instruction()
|
|
7758
|
+
// }
|
|
7759
|
+
/**
|
|
7760
|
+
* Build lock funds instruction
|
|
7761
|
+
*/
|
|
7762
|
+
async getLockFundsIx(props) {
|
|
7763
|
+
const { bondType, name, voteAccount, amount, withdrawAuthority } = props;
|
|
7764
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7765
|
+
let collateralType = props.collateralType;
|
|
7766
|
+
if (!collateralType) {
|
|
7767
|
+
const bondState2 = await this.getBondState(bondType, name);
|
|
7768
|
+
collateralType = bondState2.collateralType;
|
|
7769
|
+
}
|
|
7770
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7771
|
+
const accounts = {
|
|
7772
|
+
bondState,
|
|
7773
|
+
validatorBond,
|
|
7774
|
+
payer: withdrawAuthority,
|
|
7775
|
+
bondTokenAccount: null
|
|
7776
|
+
};
|
|
7777
|
+
matchVariant(collateralType, {
|
|
7778
|
+
native: () => {
|
|
7779
|
+
},
|
|
7780
|
+
token: (mint) => {
|
|
7781
|
+
const bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
7782
|
+
accounts.bondTokenAccount = bondTokenAccount;
|
|
7783
|
+
}
|
|
7784
|
+
});
|
|
7785
|
+
return this.program.methods.bondLockFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7786
|
+
}
|
|
7787
|
+
/**
|
|
7788
|
+
* Build release funds instruction
|
|
7789
|
+
*/
|
|
7790
|
+
async getReleaseFundsIx(props) {
|
|
7791
|
+
const { bondType, name, voteAccount, amount, withdrawAuthority } = props;
|
|
7792
|
+
const [bondState] = this.pda.bondState(bondType, name);
|
|
7793
|
+
const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
|
|
7794
|
+
const accounts = {
|
|
7795
|
+
bondState,
|
|
7796
|
+
validatorBond,
|
|
7797
|
+
payer: withdrawAuthority
|
|
7798
|
+
};
|
|
7799
|
+
return this.program.methods.bondReleaseFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
|
|
7800
|
+
}
|
|
7801
|
+
/**
|
|
7802
|
+
* Get available collateral for withdrawal (taking into account locked funds)
|
|
7803
|
+
*/
|
|
7804
|
+
async getAvailableCollateral(bondType, bondName, voteAccount) {
|
|
7805
|
+
const validatorBond = await this.getValidatorBond(bondType, bondName, voteAccount);
|
|
7806
|
+
return await this.getValidatorBondBalance(bondType, bondName, voteAccount) - validatorBond.locked.toNumber();
|
|
7807
|
+
}
|
|
6875
7808
|
/**
|
|
6876
7809
|
* Get all bond states with total collected collateral
|
|
6877
7810
|
*/
|
|
6878
|
-
async getAllBondStates(bondType, sessionStatus) {
|
|
6879
|
-
const
|
|
7811
|
+
async getAllBondStates(bondType, sessionStatus, options) {
|
|
7812
|
+
const includeStats = options?.includeStats ?? true;
|
|
7813
|
+
const targetBondType = bondTypeToAnchor(bondType);
|
|
6880
7814
|
const accounts = await this.program.account.bondState.all();
|
|
6881
|
-
|
|
6882
|
-
if (!sameVariant(account.bondType,
|
|
6883
|
-
|
|
7815
|
+
const filteredAccounts = accounts.filter(({ account }) => {
|
|
7816
|
+
if (!sameVariant(account.bondType, targetBondType)) {
|
|
7817
|
+
return false;
|
|
6884
7818
|
}
|
|
6885
7819
|
if (sessionStatus !== void 0 && this.getBondStateSessionStatus(account) !== sessionStatus) {
|
|
6886
|
-
|
|
7820
|
+
return false;
|
|
6887
7821
|
}
|
|
6888
|
-
|
|
6889
|
-
|
|
7822
|
+
return true;
|
|
7823
|
+
});
|
|
7824
|
+
if (!includeStats) {
|
|
7825
|
+
return filteredAccounts.map(({ publicKey, account }) => ({
|
|
7826
|
+
publicKey,
|
|
7827
|
+
bondState: account,
|
|
7828
|
+
stateStats: null
|
|
7829
|
+
}));
|
|
6890
7830
|
}
|
|
6891
|
-
return
|
|
7831
|
+
return Promise.all(
|
|
7832
|
+
filteredAccounts.map(async ({ publicKey, account }) => {
|
|
7833
|
+
const stateStats = await this.getBondStateStats(account);
|
|
7834
|
+
return { publicKey, bondState: account, stateStats };
|
|
7835
|
+
})
|
|
7836
|
+
);
|
|
6892
7837
|
}
|
|
6893
7838
|
/**
|
|
6894
7839
|
* Fetch global state or throw if not found
|
|
@@ -6909,16 +7854,28 @@ var JBondClient = class _JBondClient {
|
|
|
6909
7854
|
return { publicKey, ...data };
|
|
6910
7855
|
}
|
|
6911
7856
|
/**
|
|
6912
|
-
* Fetch validator bond data or
|
|
7857
|
+
* Fetch validator bond data or error if not found
|
|
6913
7858
|
*/
|
|
6914
7859
|
async getValidatorBond(bondType, bondName, vote) {
|
|
6915
7860
|
const [publicKey] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
7861
|
+
this.debug(`Fetching validator bond ${publicKey}...`);
|
|
6916
7862
|
const data = await this.program.account.validatorBond.fetch(publicKey);
|
|
6917
7863
|
return { publicKey, ...data };
|
|
6918
7864
|
}
|
|
6919
7865
|
/**
|
|
6920
|
-
*
|
|
6921
|
-
|
|
7866
|
+
* Fetch validator bond data or null if not found
|
|
7867
|
+
*/
|
|
7868
|
+
async getValidatorBondNullable(bondType, bondName, vote) {
|
|
7869
|
+
const [publicKey] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
7870
|
+
this.debug(`Fetching validator bond ${publicKey}...`);
|
|
7871
|
+
const data = await this.program.account.validatorBond.fetchNullable(publicKey);
|
|
7872
|
+
if (!data) {
|
|
7873
|
+
return null;
|
|
7874
|
+
}
|
|
7875
|
+
return { publicKey, ...data };
|
|
7876
|
+
}
|
|
7877
|
+
/**
|
|
7878
|
+
* Get validator bond account balance (in SOL)
|
|
6922
7879
|
*/
|
|
6923
7880
|
async getValidatorBondBalance(bondType, bondName, vote) {
|
|
6924
7881
|
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
@@ -6930,8 +7887,8 @@ var JBondClient = class _JBondClient {
|
|
|
6930
7887
|
if (!accountInfo) {
|
|
6931
7888
|
return 0;
|
|
6932
7889
|
}
|
|
6933
|
-
const {
|
|
6934
|
-
const rentExempt = await this.
|
|
7890
|
+
const { lamports } = accountInfo;
|
|
7891
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
6935
7892
|
return Math.max(0, lamports - rentExempt);
|
|
6936
7893
|
},
|
|
6937
7894
|
token: async (mint) => {
|
|
@@ -6945,12 +7902,13 @@ var JBondClient = class _JBondClient {
|
|
|
6945
7902
|
}
|
|
6946
7903
|
});
|
|
6947
7904
|
}
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
7905
|
+
async getBondStateValidatorBondBalances(bondType, bondName, bondState) {
|
|
7906
|
+
const state = bondState ?? await this.getBondState(bondType, bondName);
|
|
7907
|
+
const collateralType = state.collateralType;
|
|
7908
|
+
const validatorBonds = await this.getValidatorBondsForState(bondType, bondName);
|
|
7909
|
+
if (!validatorBonds.length) {
|
|
7910
|
+
return [];
|
|
7911
|
+
}
|
|
6954
7912
|
const chunk = (arr, n = 100) => {
|
|
6955
7913
|
const res = [];
|
|
6956
7914
|
for (let i = 0; i < arr.length; i += n) {
|
|
@@ -6960,76 +7918,79 @@ var JBondClient = class _JBondClient {
|
|
|
6960
7918
|
};
|
|
6961
7919
|
return await matchVariant(collateralType, {
|
|
6962
7920
|
native: async () => {
|
|
6963
|
-
const addresses =
|
|
6964
|
-
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
6965
|
-
return address;
|
|
6966
|
-
});
|
|
7921
|
+
const addresses = validatorBonds.map((vb) => vb.publicKey);
|
|
6967
7922
|
const accountInfos = await this.connection.getMultipleAccountsInfo(addresses);
|
|
6968
|
-
const
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
const { lamports } = accountInfo;
|
|
6974
|
-
return lamports;
|
|
6975
|
-
})
|
|
6976
|
-
);
|
|
6977
|
-
return balances.reduce((sum, v) => sum + v, 0);
|
|
7923
|
+
const rentExempt = await this.validatorBondRentExempt();
|
|
7924
|
+
return validatorBonds.map((vb, idx) => ({
|
|
7925
|
+
voteAccount: vb.voteAccount,
|
|
7926
|
+
balance: Math.max(0, (accountInfos[idx]?.lamports ?? 0) - rentExempt)
|
|
7927
|
+
}));
|
|
6978
7928
|
},
|
|
6979
7929
|
token: async (mint) => {
|
|
6980
|
-
const
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
});
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
for (const part of chunk(tokenAccounts, 100)) {
|
|
6989
|
-
const infos = await this.connection.getMultipleAccountsInfo(part).catch(() => []);
|
|
6990
|
-
for (let i = 0; i < infos.length; i++) {
|
|
7930
|
+
const items = validatorBonds.map((vb) => ({
|
|
7931
|
+
voteAccount: vb.voteAccount,
|
|
7932
|
+
tokenAccount: splToken.getAssociatedTokenAddressSync(mint, vb.publicKey, true)
|
|
7933
|
+
}));
|
|
7934
|
+
const balances = [];
|
|
7935
|
+
for (const part of chunk(items, 100)) {
|
|
7936
|
+
const infos = await this.connection.getMultipleAccountsInfo(part.map((i) => i.tokenAccount)).catch(() => []);
|
|
7937
|
+
for (let i = 0; i < part.length; i++) {
|
|
6991
7938
|
const info = infos[i];
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
if (info.data.length !== splToken.ACCOUNT_SIZE) {
|
|
7939
|
+
const voteAccount = part[i].voteAccount;
|
|
7940
|
+
if (!info || info.data.length !== splToken.ACCOUNT_SIZE) {
|
|
7941
|
+
balances.push({ voteAccount, balance: 0 });
|
|
6996
7942
|
continue;
|
|
6997
7943
|
}
|
|
6998
7944
|
try {
|
|
6999
7945
|
const acc = splToken.AccountLayout.decode(info.data);
|
|
7000
7946
|
const raw = BigInt(acc.amount.toString());
|
|
7001
|
-
|
|
7947
|
+
const asNumber = Number(raw);
|
|
7948
|
+
balances.push({
|
|
7949
|
+
voteAccount,
|
|
7950
|
+
balance: Number.isFinite(asNumber) ? asNumber : Number.MAX_SAFE_INTEGER
|
|
7951
|
+
});
|
|
7002
7952
|
} catch {
|
|
7953
|
+
balances.push({ voteAccount, balance: 0 });
|
|
7003
7954
|
}
|
|
7004
7955
|
}
|
|
7005
7956
|
}
|
|
7006
|
-
|
|
7007
|
-
return Number.isFinite(asNumber) ? asNumber : Number.MAX_SAFE_INTEGER;
|
|
7957
|
+
return balances;
|
|
7008
7958
|
}
|
|
7009
7959
|
});
|
|
7010
7960
|
}
|
|
7961
|
+
/**
|
|
7962
|
+
* Get total collected collateral for a bond state
|
|
7963
|
+
*/
|
|
7964
|
+
async getBondStateTotalCollected(bondType, bondName, bondState) {
|
|
7965
|
+
const allBalances = await this.getBondStateValidatorBondBalances(bondType, bondName, bondState);
|
|
7966
|
+
return allBalances.reduce((sum, vb) => sum + vb.balance, 0);
|
|
7967
|
+
}
|
|
7011
7968
|
/**
|
|
7012
7969
|
* Get bond state stats
|
|
7013
7970
|
* @param state
|
|
7014
|
-
* @private
|
|
7015
7971
|
*/
|
|
7016
7972
|
async getBondStateStats(state) {
|
|
7017
7973
|
const bondType = anchorToBondType(state.bondType);
|
|
7018
|
-
const validatorBonds = await this.getBondValidatorStates(bondType, state.name);
|
|
7019
7974
|
const totalCollected = await this.getBondStateTotalCollected(
|
|
7020
7975
|
bondType,
|
|
7021
7976
|
state.name,
|
|
7022
|
-
|
|
7977
|
+
state
|
|
7023
7978
|
);
|
|
7024
7979
|
return {
|
|
7025
7980
|
totalCollected,
|
|
7026
7981
|
status: this.getBondStateSessionStatus(state)
|
|
7027
7982
|
};
|
|
7028
7983
|
}
|
|
7984
|
+
/**
|
|
7985
|
+
* Get validator bond rent exempt amount
|
|
7986
|
+
*/
|
|
7987
|
+
validatorBondRentExempt = async () => {
|
|
7988
|
+
return this.connection.getMinimumBalanceForRentExemption(this.program.account.validatorBond.size);
|
|
7989
|
+
};
|
|
7029
7990
|
/**
|
|
7030
7991
|
* Get all validator bonds for a given bond state
|
|
7031
7992
|
*/
|
|
7032
|
-
async
|
|
7993
|
+
async getValidatorBondsForState(bondType, bondName) {
|
|
7033
7994
|
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
7034
7995
|
const accounts = await this.program.account.validatorBond.all([
|
|
7035
7996
|
{
|
|
@@ -7080,9 +8041,12 @@ exports.ENV_PROGRAM_ID = ENV_PROGRAM_ID;
|
|
|
7080
8041
|
exports.GLOBAL_STATE_SEED = GLOBAL_STATE_SEED;
|
|
7081
8042
|
exports.JBondClient = JBondClient;
|
|
7082
8043
|
exports.JBondClientEnv = JBondClientEnv;
|
|
8044
|
+
exports.JPOOL_POOL_ADDRESS = JPOOL_POOL_ADDRESS;
|
|
8045
|
+
exports.JSOL_MINT = JSOL_MINT;
|
|
7083
8046
|
exports.NodeWallet = NodeWallet;
|
|
7084
8047
|
exports.STANDARD_BOND_SEED = STANDARD_BOND_SEED;
|
|
7085
8048
|
exports.SessionStatus = SessionStatus;
|
|
7086
8049
|
exports.VALIDATOR_BOND_SEED = VALIDATOR_BOND_SEED;
|
|
8050
|
+
exports.lamportsToSol = lamportsToSol;
|
|
7087
8051
|
//# sourceMappingURL=index.js.map
|
|
7088
8052
|
//# sourceMappingURL=index.js.map
|