@jpool/bond-sdk 0.11.0-next.3 → 0.11.0-next.6

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.js CHANGED
@@ -5008,6 +5008,50 @@ var jbond_default = {
5008
5008
  }
5009
5009
  ]
5010
5010
  },
5011
+ {
5012
+ name: "bond_lock_funds",
5013
+ docs: [
5014
+ "Locks funds for the upcoming epoch.",
5015
+ "Moves collateral from available to locked state which cannot be withdrawn.",
5016
+ "# Errors",
5017
+ "Fails if the validator is not active, or if there are insufficient available funds."
5018
+ ],
5019
+ discriminator: [
5020
+ 117,
5021
+ 166,
5022
+ 195,
5023
+ 99,
5024
+ 103,
5025
+ 45,
5026
+ 195,
5027
+ 2
5028
+ ],
5029
+ accounts: [
5030
+ {
5031
+ name: "bond_state",
5032
+ writable: true
5033
+ },
5034
+ {
5035
+ name: "validator_bond",
5036
+ writable: true
5037
+ },
5038
+ {
5039
+ name: "bond_token_account",
5040
+ optional: true
5041
+ },
5042
+ {
5043
+ name: "payer",
5044
+ writable: true,
5045
+ signer: true
5046
+ }
5047
+ ],
5048
+ args: [
5049
+ {
5050
+ name: "amount",
5051
+ type: "u64"
5052
+ }
5053
+ ]
5054
+ },
5011
5055
  {
5012
5056
  name: "bond_register",
5013
5057
  docs: [
@@ -5120,6 +5164,42 @@ var jbond_default = {
5120
5164
  }
5121
5165
  ]
5122
5166
  },
5167
+ {
5168
+ name: "bond_release_funds",
5169
+ docs: [
5170
+ "Releases locked funds after an epoch ends.",
5171
+ "Moves collateral from locked back to available state, allowing withdrawals.",
5172
+ "# Errors",
5173
+ "Fails if the validator is not active, or if there are insufficient locked funds."
5174
+ ],
5175
+ discriminator: [
5176
+ 184,
5177
+ 224,
5178
+ 14,
5179
+ 24,
5180
+ 76,
5181
+ 14,
5182
+ 226,
5183
+ 190
5184
+ ],
5185
+ accounts: [
5186
+ {
5187
+ name: "validator_bond",
5188
+ writable: true
5189
+ },
5190
+ {
5191
+ name: "payer",
5192
+ writable: true,
5193
+ signer: true
5194
+ }
5195
+ ],
5196
+ args: [
5197
+ {
5198
+ name: "amount",
5199
+ type: "u64"
5200
+ }
5201
+ ]
5202
+ },
5123
5203
  {
5124
5204
  name: "bond_set_withdraw_authority",
5125
5205
  docs: [
@@ -5299,6 +5379,31 @@ var jbond_default = {
5299
5379
  }
5300
5380
  ]
5301
5381
  },
5382
+ {
5383
+ name: "bond_update",
5384
+ discriminator: [
5385
+ 237,
5386
+ 102,
5387
+ 183,
5388
+ 192,
5389
+ 94,
5390
+ 83,
5391
+ 52,
5392
+ 82
5393
+ ],
5394
+ accounts: [
5395
+ {
5396
+ name: "validator_bond",
5397
+ writable: true
5398
+ },
5399
+ {
5400
+ name: "payer",
5401
+ writable: true,
5402
+ signer: true
5403
+ }
5404
+ ],
5405
+ args: []
5406
+ },
5302
5407
  {
5303
5408
  name: "bond_withdraw",
5304
5409
  docs: [
@@ -5899,6 +6004,11 @@ var jbond_default = {
5899
6004
  code: 6023,
5900
6005
  name: "BondNotEnabled",
5901
6006
  msg: "Bond is not enabled"
6007
+ },
6008
+ {
6009
+ code: 6024,
6010
+ name: "InvalidEpoch",
6011
+ msg: "Invalid epoch for this operation"
5902
6012
  }
5903
6013
  ],
5904
6014
  types: [
@@ -6330,6 +6440,27 @@ var jbond_default = {
6330
6440
  "Bump for the PDA"
6331
6441
  ],
6332
6442
  type: "u8"
6443
+ },
6444
+ {
6445
+ name: "next_epoch_locked",
6446
+ docs: [
6447
+ "Amount of collateral locked for the next epoch"
6448
+ ],
6449
+ type: "u64"
6450
+ },
6451
+ {
6452
+ name: "current_epoch_locked",
6453
+ docs: [
6454
+ "Amount of collateral locked for the current epoch"
6455
+ ],
6456
+ type: "u64"
6457
+ },
6458
+ {
6459
+ name: "last_update_epoch",
6460
+ docs: [
6461
+ "The last epoch when the bond was updated"
6462
+ ],
6463
+ type: "u64"
6333
6464
  }
6334
6465
  ]
6335
6466
  }
@@ -6885,20 +7016,17 @@ var JBondClient = class _JBondClient {
6885
7016
  */
6886
7017
  async getClaimAllCompensationsIxs(props) {
6887
7018
  const ixs = [];
6888
- const validatorBonds = await this.getBondValidatorStates(props.bondType, props.name);
6889
7019
  const validatorBondBalances = await this.getBondStateValidatorBondBalances(
6890
7020
  props.bondType,
6891
7021
  props.name
6892
7022
  );
6893
- for (const vb of validatorBonds) {
6894
- console.log("Processing claim for validator:", vb.voteAccount.toBase58());
6895
- const validatorBondBalance = lamportsToSol(validatorBondBalances.find((vbb) => vbb.voteAccount.equals(vb.voteAccount))?.balance || 0);
6896
- const amountToClaim = validatorBondBalance - (props.collateralType ? 0 : lamportsToSol(await this.validatorBondRentExempt()));
7023
+ for (const bond_balance of validatorBondBalances) {
7024
+ const amountToClaim = lamportsToSol(bond_balance.balance);
6897
7025
  if (amountToClaim <= 0) {
6898
- console.log("No balance to claim for validator:", vb.voteAccount.toBase58());
7026
+ this.debug("No balance to claim for validator:", bond_balance.voteAccount.toBase58());
6899
7027
  continue;
6900
7028
  }
6901
- console.log("Amount to claim:", amountToClaim);
7029
+ this.debug("Amount to claim:", amountToClaim);
6902
7030
  const ix = await this.getClaimIx({
6903
7031
  bondType: props.bondType,
6904
7032
  name: props.name,
@@ -6906,7 +7034,7 @@ var JBondClient = class _JBondClient {
6906
7034
  collateralType: props.collateralType,
6907
7035
  reserve: props.reserve,
6908
7036
  authority: props.authority,
6909
- voteAccount: vb.voteAccount
7037
+ voteAccount: bond_balance.voteAccount
6910
7038
  });
6911
7039
  ixs.push(ix);
6912
7040
  }
@@ -6940,6 +7068,48 @@ var JBondClient = class _JBondClient {
6940
7068
  const authority = this.provider.wallet?.publicKey;
6941
7069
  return this.program.methods.sessionStart(new import_bn.BN(props.duration)).accountsPartial({ bondState, authority }).instruction();
6942
7070
  }
7071
+ /**
7072
+ * Build lock funds instruction
7073
+ */
7074
+ async getLockFundsIx(props) {
7075
+ const { bondType, name, voteAccount, amount } = props;
7076
+ const [bondState] = this.pda.bondState(bondType, name);
7077
+ let collateralType = props.collateralType;
7078
+ if (!collateralType) {
7079
+ const bondState2 = await this.getBondState(bondType, name);
7080
+ collateralType = bondState2.collateralType;
7081
+ }
7082
+ const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
7083
+ const authority = this.provider.wallet?.publicKey;
7084
+ const accounts = {
7085
+ bondState,
7086
+ validatorBond,
7087
+ payer: authority,
7088
+ bondTokenAccount: null
7089
+ };
7090
+ matchVariant(collateralType, {
7091
+ native: () => {
7092
+ },
7093
+ token: (mint) => {
7094
+ const bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
7095
+ accounts.bondTokenAccount = bondTokenAccount;
7096
+ }
7097
+ });
7098
+ return this.program.methods.bondLockFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
7099
+ }
7100
+ /**
7101
+ * Build release funds instruction
7102
+ */
7103
+ async getReleaseFundsIx(props) {
7104
+ const { bondType, name, voteAccount, amount } = props;
7105
+ const [validatorBond] = this.pda.validatorBond(bondType, name, voteAccount);
7106
+ const authority = this.provider.wallet?.publicKey;
7107
+ const accounts = {
7108
+ validatorBond,
7109
+ payer: authority
7110
+ };
7111
+ return this.program.methods.bondReleaseFunds(solToLamports(amount)).accountsPartial(accounts).instruction();
7112
+ }
6943
7113
  /**
6944
7114
  * Get all bond states with total collected collateral
6945
7115
  */
@@ -6997,8 +7167,8 @@ var JBondClient = class _JBondClient {
6997
7167
  if (!accountInfo) {
6998
7168
  return 0;
6999
7169
  }
7000
- const { data, lamports } = accountInfo;
7001
- const rentExempt = await this.connection.getMinimumBalanceForRentExemption(data.length);
7170
+ const { lamports } = accountInfo;
7171
+ const rentExempt = await this.validatorBondRentExempt();
7002
7172
  return Math.max(0, lamports - rentExempt);
7003
7173
  },
7004
7174
  token: async (mint) => {
@@ -7015,7 +7185,7 @@ var JBondClient = class _JBondClient {
7015
7185
  async getBondStateValidatorBondBalances(bondType, bondName) {
7016
7186
  const bondState = await this.getBondState(bondType, bondName);
7017
7187
  const collateralType = bondState.collateralType;
7018
- const validatorBonds = await this.getBondValidatorStates(bondType, bondName);
7188
+ const validatorBonds = await this.getValidatorBondsForState(bondType, bondName);
7019
7189
  if (!validatorBonds.length) {
7020
7190
  return [];
7021
7191
  }
@@ -7030,9 +7200,10 @@ var JBondClient = class _JBondClient {
7030
7200
  native: async () => {
7031
7201
  const addresses = validatorBonds.map((vb) => vb.publicKey);
7032
7202
  const accountInfos = await this.connection.getMultipleAccountsInfo(addresses);
7203
+ const rentExempt = await this.validatorBondRentExempt();
7033
7204
  return validatorBonds.map((vb, idx) => ({
7034
7205
  voteAccount: vb.voteAccount,
7035
- balance: accountInfos[idx]?.lamports ?? 0
7206
+ balance: Math.max(0, (accountInfos[idx]?.lamports ?? 0) - rentExempt)
7036
7207
  }));
7037
7208
  },
7038
7209
  token: async (mint) => {
@@ -7099,7 +7270,7 @@ var JBondClient = class _JBondClient {
7099
7270
  /**
7100
7271
  * Get all validator bonds for a given bond state
7101
7272
  */
7102
- async getBondValidatorStates(bondType, bondName) {
7273
+ async getValidatorBondsForState(bondType, bondName) {
7103
7274
  const [bondState] = this.pda.bondState(bondType, bondName);
7104
7275
  const accounts = await this.program.account.validatorBond.all([
7105
7276
  {