@jpool/bond-sdk 0.9.0-next.14 → 0.9.0-next.15

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.mjs CHANGED
@@ -6682,7 +6682,7 @@ var JBondClient = class _JBondClient {
6682
6682
  if (!creator) {
6683
6683
  throw new Error("Missing creator");
6684
6684
  }
6685
- const collateralType = (await this.getBondState(bondType, name)).collateralType;
6685
+ const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
6686
6686
  const accounts = {
6687
6687
  bondState,
6688
6688
  validatorBond,
@@ -6725,7 +6725,7 @@ var JBondClient = class _JBondClient {
6725
6725
  creator: props.payer
6726
6726
  }));
6727
6727
  }
6728
- const collateralType = (await this.getBondState(bondType, name)).collateralType;
6728
+ const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
6729
6729
  const accounts = {
6730
6730
  bondState,
6731
6731
  validatorBond,
@@ -6762,7 +6762,7 @@ var JBondClient = class _JBondClient {
6762
6762
  if (!payer || !destination) {
6763
6763
  throw new Error("Missing payer/destination");
6764
6764
  }
6765
- const collateralType = (await this.getBondState(bondType, name)).collateralType;
6765
+ const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
6766
6766
  const accounts = {
6767
6767
  bondState,
6768
6768
  validatorBond,
@@ -6790,12 +6790,12 @@ var JBondClient = class _JBondClient {
6790
6790
  const { bondType, name } = props;
6791
6791
  const [bondState] = this.pda.bondState(bondType, name);
6792
6792
  const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
6793
- const reserve = props.reserve ?? (await this.getBondState(bondType, name)).reserve;
6793
+ const reserve = props.reserve ?? (await this.getBondState(bondType, name))[0].reserve;
6794
6794
  const authority = props.authority ?? this.program.provider.wallet?.publicKey;
6795
6795
  if (!reserve) {
6796
6796
  throw new Error("Reserve not set");
6797
6797
  }
6798
- const collateralType = (await this.getBondState(bondType, name)).collateralType;
6798
+ const collateralType = (await this.getBondState(bondType, name))[0].collateralType;
6799
6799
  const accounts = {
6800
6800
  bondState,
6801
6801
  validatorBond,
@@ -6865,9 +6865,14 @@ var JBondClient = class _JBondClient {
6865
6865
  const [globalState] = this.pda.globalState();
6866
6866
  return await this.program.account.globalState.fetch(globalState);
6867
6867
  }
6868
+ /**
6869
+ * Fetch bond state with stats
6870
+ * @param bondType - Type of the bond
6871
+ * @param bondName - Name of the bond
6872
+ */
6868
6873
  async getBondState(bondType, bondName) {
6869
- const [bondState] = this.pda.bondState(bondType, bondName);
6870
- return await this.program.account.bondState.fetch(bondState);
6874
+ const bondState = await this.program.account.bondState.fetch(this.pda.bondState(bondType, bondName)[0]);
6875
+ return [bondState, await this.getBondStateStats(bondState)];
6871
6876
  }
6872
6877
  /**
6873
6878
  * Get all bond states with total collected collateral
@@ -6934,7 +6939,7 @@ var JBondClient = class _JBondClient {
6934
6939
  */
6935
6940
  async getBondCollateralType(bondType, bondName) {
6936
6941
  const bondState = await this.getBondState(bondType, bondName);
6937
- return bondState.collateralType;
6942
+ return bondState[0].collateralType;
6938
6943
  }
6939
6944
  /**
6940
6945
  * Get validator bond account balance (in SOL)
@@ -6946,7 +6951,7 @@ var JBondClient = class _JBondClient {
6946
6951
  async getValidatorBondBalance(bondType, bondName, vote) {
6947
6952
  const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
6948
6953
  const bondStateData = await this.getBondState(bondType, bondName);
6949
- const bondStateCollateralType = bondStateData.collateralType;
6954
+ const bondStateCollateralType = bondStateData[0].collateralType;
6950
6955
  return await matchVariant(bondStateCollateralType, {
6951
6956
  native: async () => {
6952
6957
  const accountInfo = await this.connection.getAccountInfo(address).catch(() => null);
@@ -6961,7 +6966,7 @@ var JBondClient = class _JBondClient {
6961
6966
  const tokenAccount = getAssociatedTokenAddressSync(mint, address, true);
6962
6967
  try {
6963
6968
  const balance = await this.connection.getTokenAccountBalance(tokenAccount);
6964
- return Number(balance.value.uiAmount ?? 0);
6969
+ return Number(balance.value.uiAmount ?? 0) * LAMPORTS_PER_SOL;
6965
6970
  } catch {
6966
6971
  return 0;
6967
6972
  }
@@ -6971,7 +6976,7 @@ var JBondClient = class _JBondClient {
6971
6976
  // Get total collected collateral for a bond state
6972
6977
  async getBondStateTotalCollected(bondType, bondName, votes) {
6973
6978
  const bondStateData = await this.getBondState(bondType, bondName);
6974
- const bondStateCollateralType = bondStateData.collateralType;
6979
+ const bondStateCollateralType = bondStateData[0].collateralType;
6975
6980
  const chunk = (arr, n = 100) => {
6976
6981
  const res = [];
6977
6982
  for (let i = 0; i < arr.length; i += n) {
@@ -6997,7 +7002,6 @@ var JBondClient = class _JBondClient {
6997
7002
  );
6998
7003
  return balances.reduce((sum, v) => sum + v, 0);
6999
7004
  },
7000
- // TODO
7001
7005
  token: async (mint) => {
7002
7006
  const tokenAccounts = votes.map((vote) => {
7003
7007
  const [validatorBondAddress] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));