@jpool/bond-sdk 0.9.0-next.16 → 0.9.0-next.18

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
@@ -4600,6 +4600,10 @@ var BondTypeVariant = {
4600
4600
  Performance: { performance: {} },
4601
4601
  Crowdfunding: { crowdfunding: {} }
4602
4602
  };
4603
+ var BondStateStatusVariant = {
4604
+ Active: { active: {} },
4605
+ Disabled: { disabled: {} }
4606
+ };
4603
4607
  var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
4604
4608
  BondTransactionType2["Deposit"] = "deposit";
4605
4609
  BondTransactionType2["Withdrawal"] = "withdrawal";
@@ -4994,68 +4998,6 @@ var jbond_default = {
4994
4998
  }
4995
4999
  ]
4996
5000
  },
4997
- {
4998
- name: "bond_disable",
4999
- docs: [
5000
- "Disables a validator's bond, preventing it from participating further."
5001
- ],
5002
- discriminator: [
5003
- 159,
5004
- 156,
5005
- 97,
5006
- 253,
5007
- 70,
5008
- 122,
5009
- 117,
5010
- 129
5011
- ],
5012
- accounts: [
5013
- {
5014
- name: "bond_state",
5015
- writable: true
5016
- },
5017
- {
5018
- name: "authority",
5019
- writable: true,
5020
- signer: true,
5021
- relations: [
5022
- "bond_state"
5023
- ]
5024
- }
5025
- ],
5026
- args: []
5027
- },
5028
- {
5029
- name: "bond_enable",
5030
- docs: [
5031
- "Enables a previously disabled validator's bond."
5032
- ],
5033
- discriminator: [
5034
- 133,
5035
- 48,
5036
- 84,
5037
- 9,
5038
- 117,
5039
- 131,
5040
- 164,
5041
- 128
5042
- ],
5043
- accounts: [
5044
- {
5045
- name: "bond_state",
5046
- writable: true
5047
- },
5048
- {
5049
- name: "authority",
5050
- writable: true,
5051
- signer: true,
5052
- relations: [
5053
- "bond_state"
5054
- ]
5055
- }
5056
- ],
5057
- args: []
5058
- },
5059
5001
  {
5060
5002
  name: "bond_initialize",
5061
5003
  docs: [
@@ -5078,8 +5020,7 @@ var jbond_default = {
5078
5020
  ],
5079
5021
  accounts: [
5080
5022
  {
5081
- name: "global_state",
5082
- writable: true
5023
+ name: "global_state"
5083
5024
  },
5084
5025
  {
5085
5026
  name: "bond_state",
@@ -5115,7 +5056,10 @@ var jbond_default = {
5115
5056
  {
5116
5057
  name: "authority",
5117
5058
  writable: true,
5118
- signer: true
5059
+ signer: true,
5060
+ relations: [
5061
+ "global_state"
5062
+ ]
5119
5063
  },
5120
5064
  {
5121
5065
  name: "reserve"
@@ -5981,6 +5925,16 @@ var jbond_default = {
5981
5925
  type: {
5982
5926
  kind: "struct",
5983
5927
  fields: [
5928
+ {
5929
+ name: "status",
5930
+ type: {
5931
+ option: {
5932
+ defined: {
5933
+ name: "BondStatus"
5934
+ }
5935
+ }
5936
+ }
5937
+ },
5984
5938
  {
5985
5939
  name: "new_reserve",
5986
5940
  type: {
@@ -6153,6 +6107,9 @@ var jbond_default = {
6153
6107
  },
6154
6108
  {
6155
6109
  name: "status",
6110
+ docs: [
6111
+ "Current status of the bond"
6112
+ ],
6156
6113
  type: {
6157
6114
  defined: {
6158
6115
  name: "BondStatus"
@@ -6638,14 +6595,6 @@ var JBondClient = class _JBondClient {
6638
6595
  const ix = await this.buildBondFinishIx(props);
6639
6596
  return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
6640
6597
  }
6641
- async bondEnable(props) {
6642
- const ix = await this.buildBondEnableIx(props);
6643
- return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
6644
- }
6645
- async bondDisable(props) {
6646
- const ix = await this.buildBondDisableIx(props);
6647
- return this.provider.sendAndConfirm?.(new web3_js.Transaction().add(ix));
6648
- }
6649
6598
  async buildBondGlobalStateInitializeIx(props) {
6650
6599
  const [globalState] = this.pda.globalState();
6651
6600
  const authority = props.authority ?? this.provider.wallet?.publicKey;
@@ -6703,6 +6652,7 @@ var JBondClient = class _JBondClient {
6703
6652
  async buildConfigureIx(props) {
6704
6653
  const [bondState] = this.pda.bondState(props.bondType, props.name);
6705
6654
  return this.program.methods.bondConfigure({
6655
+ status: props.bondStateStatus ?? null,
6706
6656
  newReserve: props.newReserve ?? null,
6707
6657
  newAuthority: props.newAuthority ?? null
6708
6658
  }).accountsStrict({
@@ -6718,7 +6668,7 @@ var JBondClient = class _JBondClient {
6718
6668
  if (!creator) {
6719
6669
  throw new Error("Missing creator");
6720
6670
  }
6721
- const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
6671
+ const collateralType = (await this.getBondState(bondType, name)).bond_state.collateralType;
6722
6672
  const accounts = {
6723
6673
  bondState,
6724
6674
  validatorBond,
@@ -6761,7 +6711,7 @@ var JBondClient = class _JBondClient {
6761
6711
  creator: props.payer
6762
6712
  }));
6763
6713
  }
6764
- const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
6714
+ const collateralType = (await this.getBondState(bondType, name)).bond_state.collateralType;
6765
6715
  const accounts = {
6766
6716
  bondState,
6767
6717
  validatorBond,
@@ -6798,7 +6748,7 @@ var JBondClient = class _JBondClient {
6798
6748
  if (!payer || !destination) {
6799
6749
  throw new Error("Missing payer/destination");
6800
6750
  }
6801
- const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
6751
+ const collateralType = (await this.getBondState(bondType, name)).bond_state.collateralType;
6802
6752
  const accounts = {
6803
6753
  bondState,
6804
6754
  validatorBond,
@@ -6826,12 +6776,12 @@ var JBondClient = class _JBondClient {
6826
6776
  const { bondType, name } = props;
6827
6777
  const [bondState] = this.pda.bondState(bondType, name);
6828
6778
  const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
6829
- const reserve = props.reserve ?? (await this.getBondState(bondType, name))[0].reserve;
6779
+ const reserve = props.reserve ?? (await this.getBondState(bondType, name)).bond_state.reserve;
6830
6780
  const authority = props.authority ?? this.program.provider.wallet?.publicKey;
6831
6781
  if (!reserve) {
6832
6782
  throw new Error("Reserve not set");
6833
6783
  }
6834
- const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
6784
+ const collateralType = (await this.getBondState(bondType, name)).bond_state.collateralType;
6835
6785
  const accounts = {
6836
6786
  bondState,
6837
6787
  validatorBond,
@@ -6880,20 +6830,6 @@ var JBondClient = class _JBondClient {
6880
6830
  authority: this.program.provider.wallet?.publicKey
6881
6831
  }).instruction();
6882
6832
  }
6883
- async buildBondEnableIx(props) {
6884
- const [bondState] = this.pda.bondState(props.bondType, props.name);
6885
- return this.program.methods.bondEnable().accountsPartial({
6886
- bondState,
6887
- authority: this.program.provider.wallet?.publicKey
6888
- }).instruction();
6889
- }
6890
- async buildBondDisableIx(props) {
6891
- const [bondState] = this.pda.bondState(props.bondType, props.name);
6892
- return this.program.methods.bondDisable().accountsPartial({
6893
- bondState,
6894
- authority: this.program.provider.wallet?.publicKey
6895
- }).instruction();
6896
- }
6897
6833
  /**
6898
6834
  * Fetch global state or throw if not found
6899
6835
  */
@@ -6905,10 +6841,14 @@ var JBondClient = class _JBondClient {
6905
6841
  * Fetch bond state with stats
6906
6842
  * @param bondType - Type of the bond
6907
6843
  * @param bondName - Name of the bond
6844
+ * @param withStats
6908
6845
  */
6909
6846
  async getBondState(bondType, bondName, withStats = false) {
6910
6847
  const bondState = await this.program.account.bondState.fetch(this.pda.bondState(bondType, bondName)[0]);
6911
- return [bondState, withStats ? await this.getBondStateStats(bondState) : null];
6848
+ return {
6849
+ bond_state: bondState,
6850
+ state_stats: withStats ? await this.getBondStateStats(bondState) : null
6851
+ };
6912
6852
  }
6913
6853
  /**
6914
6854
  * Get all bond states with total collected collateral
@@ -6924,7 +6864,12 @@ var JBondClient = class _JBondClient {
6924
6864
  continue;
6925
6865
  }
6926
6866
  const bondStateStats = await this.getBondStateStats(state);
6927
- bondStates.push([state, bondStateStats]);
6867
+ bondStates.push(
6868
+ {
6869
+ bond_state: state,
6870
+ state_stats: bondStateStats
6871
+ }
6872
+ );
6928
6873
  }
6929
6874
  return bondStates;
6930
6875
  }
@@ -6939,7 +6884,9 @@ var JBondClient = class _JBondClient {
6939
6884
  return 1 /* Finished */;
6940
6885
  }
6941
6886
  }
6942
- /** Get all validator bonds for a given bond state */
6887
+ /**
6888
+ * Get all validator bonds for a given bond state
6889
+ */
6943
6890
  async getValidatorBondsByState(bondType, bondName) {
6944
6891
  const validatorBonds = [];
6945
6892
  const bondStatePda = this.pda.bondState(bondType, bondName)[0];
@@ -6958,9 +6905,6 @@ var JBondClient = class _JBondClient {
6958
6905
  }
6959
6906
  /**
6960
6907
  * Fetch validator bond data or null if not found
6961
- * @param bondType
6962
- * @param bondName
6963
- * @param vote
6964
6908
  */
6965
6909
  async getValidatorBond(bondType, bondName, vote) {
6966
6910
  const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
@@ -6975,7 +6919,7 @@ var JBondClient = class _JBondClient {
6975
6919
  */
6976
6920
  async getBondCollateralType(bondType, bondName) {
6977
6921
  const bondState = await this.getBondState(bondType, bondName);
6978
- return bondState[0].collateralType;
6922
+ return bondState.bond_state.collateralType;
6979
6923
  }
6980
6924
  /**
6981
6925
  * Get validator bond account balance (in SOL)
@@ -6987,7 +6931,7 @@ var JBondClient = class _JBondClient {
6987
6931
  async getValidatorBondBalance(bondType, bondName, vote) {
6988
6932
  const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
6989
6933
  const bondStateData = await this.getBondState(bondType, bondName);
6990
- const bondStateCollateralType = bondStateData[0].collateralType;
6934
+ const bondStateCollateralType = bondStateData.bond_state.collateralType;
6991
6935
  return await matchVariant(bondStateCollateralType, {
6992
6936
  native: async () => {
6993
6937
  const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
@@ -7009,10 +6953,12 @@ var JBondClient = class _JBondClient {
7009
6953
  }
7010
6954
  });
7011
6955
  }
7012
- // Get total collected collateral for a bond state
6956
+ /**
6957
+ * Get total collected collateral for a bond state
6958
+ */
7013
6959
  async getBondStateTotalCollected(bondType, bondName, votes) {
7014
6960
  const bondStateData = await this.getBondState(bondType, bondName);
7015
- const bondStateCollateralType = bondStateData[0].collateralType;
6961
+ const bondStateCollateralType = bondStateData.bond_state.collateralType;
7016
6962
  const chunk = (arr, n = 100) => {
7017
6963
  const res = [];
7018
6964
  for (let i = 0; i < arr.length; i += n) {
@@ -7070,6 +7016,11 @@ var JBondClient = class _JBondClient {
7070
7016
  }
7071
7017
  });
7072
7018
  }
7019
+ /**
7020
+ * Get bond state stats
7021
+ * @param state
7022
+ * @private
7023
+ */
7073
7024
  async getBondStateStats(state) {
7074
7025
  const validatorBonds = await this.getValidatorBondsByState(state.bondType, state.name);
7075
7026
  const totalCollected = await this.getBondStateTotalCollected(
@@ -7077,11 +7028,10 @@ var JBondClient = class _JBondClient {
7077
7028
  state.name,
7078
7029
  validatorBonds.map((vb) => vb.voteAccount)
7079
7030
  );
7080
- const bondStateStats = {
7031
+ return {
7081
7032
  totalCollected,
7082
- status: await this.getBondStateSessionStatus(state)
7033
+ status: this.getBondStateSessionStatus(state)
7083
7034
  };
7084
- return bondStateStats;
7085
7035
  }
7086
7036
  /**
7087
7037
  * Load stake pool account and cache it if not already cached
@@ -7129,6 +7079,7 @@ buffer/index.js:
7129
7079
  */
7130
7080
 
7131
7081
  exports.BondClientEnv = BondClientEnv;
7082
+ exports.BondStateStatusVariant = BondStateStatusVariant;
7132
7083
  exports.BondTransactionType = BondTransactionType;
7133
7084
  exports.BondTypeVariant = BondTypeVariant;
7134
7085
  exports.ENV_PROGRAM_ID = ENV_PROGRAM_ID;