@jpool/bond-sdk 0.9.0-next.4 → 0.9.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.d.mts CHANGED
@@ -1533,6 +1533,10 @@ type BondState = IdlAccounts<Jbond>['bondState'];
1533
1533
  type ValidatorBond = IdlAccounts<Jbond>['validatorBond'];
1534
1534
  type BondType = IdlTypes<Jbond>['bondType'];
1535
1535
  type CollateralType = IdlTypes<Jbond>['collateralType'];
1536
+ type BondStateStats = {
1537
+ totalCollected: number;
1538
+ totalMembers: number;
1539
+ };
1536
1540
  declare const bondTypeToSeed: {
1537
1541
  performance: Seeds;
1538
1542
  crowdfunding: Seeds;
@@ -1835,7 +1839,11 @@ declare class JBondClient {
1835
1839
  */
1836
1840
  getGlobalState(): Promise<GlobalState>;
1837
1841
  getBondState(bondType: BondType, bondName: string): Promise<BondState>;
1838
- getBondStateSessionStatus(bondType: BondType, bondName: string): Promise<SessionStatus>;
1842
+ /**
1843
+ * Get all bond states with total collected collateral
1844
+ */
1845
+ getAllBondStates(_bondType: BondType): Promise<Array<[BondState, number]>>;
1846
+ private getValidatorBondsByState;
1839
1847
  /**
1840
1848
  * Fetch validator bond data or null if not found
1841
1849
  * @param bondType
@@ -1874,4 +1882,4 @@ declare class JBondClient {
1874
1882
  private ensureUser;
1875
1883
  }
1876
1884
 
1877
- export { BondClientEnv, type BondCollateral, type BondConfigureProps, type BondInitializeProps, type BondState, BondTransactionType, type BondType, BondTypeVariant, type ClaimProps, type ClientOptions, type CollateralType, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalConfigureProps, type GlobalInitializeProps, type GlobalState, JBondClient, JPOOL_STAKE_POOL, type Jbond, NodeWallet, type RegisterValidatorProps, Seeds, SessionStatus, type SetWithdrawAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps, bondTypeToSeed };
1885
+ export { BondClientEnv, type BondCollateral, type BondConfigureProps, type BondInitializeProps, type BondState, type BondStateStats, BondTransactionType, type BondType, BondTypeVariant, type ClaimProps, type ClientOptions, type CollateralType, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalConfigureProps, type GlobalInitializeProps, type GlobalState, JBondClient, JPOOL_STAKE_POOL, type Jbond, NodeWallet, type RegisterValidatorProps, Seeds, SessionStatus, type SetWithdrawAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps, bondTypeToSeed };
package/dist/index.d.ts CHANGED
@@ -1533,6 +1533,10 @@ type BondState = IdlAccounts<Jbond>['bondState'];
1533
1533
  type ValidatorBond = IdlAccounts<Jbond>['validatorBond'];
1534
1534
  type BondType = IdlTypes<Jbond>['bondType'];
1535
1535
  type CollateralType = IdlTypes<Jbond>['collateralType'];
1536
+ type BondStateStats = {
1537
+ totalCollected: number;
1538
+ totalMembers: number;
1539
+ };
1536
1540
  declare const bondTypeToSeed: {
1537
1541
  performance: Seeds;
1538
1542
  crowdfunding: Seeds;
@@ -1835,7 +1839,11 @@ declare class JBondClient {
1835
1839
  */
1836
1840
  getGlobalState(): Promise<GlobalState>;
1837
1841
  getBondState(bondType: BondType, bondName: string): Promise<BondState>;
1838
- getBondStateSessionStatus(bondType: BondType, bondName: string): Promise<SessionStatus>;
1842
+ /**
1843
+ * Get all bond states with total collected collateral
1844
+ */
1845
+ getAllBondStates(_bondType: BondType): Promise<Array<[BondState, number]>>;
1846
+ private getValidatorBondsByState;
1839
1847
  /**
1840
1848
  * Fetch validator bond data or null if not found
1841
1849
  * @param bondType
@@ -1874,4 +1882,4 @@ declare class JBondClient {
1874
1882
  private ensureUser;
1875
1883
  }
1876
1884
 
1877
- export { BondClientEnv, type BondCollateral, type BondConfigureProps, type BondInitializeProps, type BondState, BondTransactionType, type BondType, BondTypeVariant, type ClaimProps, type ClientOptions, type CollateralType, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalConfigureProps, type GlobalInitializeProps, type GlobalState, JBondClient, JPOOL_STAKE_POOL, type Jbond, NodeWallet, type RegisterValidatorProps, Seeds, SessionStatus, type SetWithdrawAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps, bondTypeToSeed };
1885
+ export { BondClientEnv, type BondCollateral, type BondConfigureProps, type BondInitializeProps, type BondState, type BondStateStats, BondTransactionType, type BondType, BondTypeVariant, type ClaimProps, type ClientOptions, type CollateralType, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalConfigureProps, type GlobalInitializeProps, type GlobalState, JBondClient, JPOOL_STAKE_POOL, type Jbond, NodeWallet, type RegisterValidatorProps, Seeds, SessionStatus, type SetWithdrawAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps, bondTypeToSeed };
package/dist/index.js CHANGED
@@ -7047,14 +7047,42 @@ var JBondClient = class _JBondClient {
7047
7047
  const [bondState] = this.pda.bondState(bondType, bondName);
7048
7048
  return await this.program.account.bondState.fetch(bondState);
7049
7049
  }
7050
- async getBondStateSessionStatus(bondType, bondName) {
7051
- const bondState = await this.getBondState(bondType, bondName);
7052
- const now = Math.floor(Date.now() / 1e3);
7053
- if (bondState.sessionFinishTs.toNumber() > now) {
7054
- return 0 /* Live */;
7055
- } else {
7056
- return 1 /* Finished */;
7050
+ /**
7051
+ * Get all bond states with total collected collateral
7052
+ */
7053
+ async getAllBondStates(_bondType) {
7054
+ const bondStates = [];
7055
+ const bondStateAccounts = await this.program.account.bondState.all();
7056
+ for (const { account: state } of bondStateAccounts) {
7057
+ if (!("crowdfunding" in state.bondType)) {
7058
+ continue;
7059
+ }
7060
+ const validatorBonds = await this.getValidatorBondsByState(state.bondType, state.name);
7061
+ const balances = await Promise.all(
7062
+ validatorBonds.map(
7063
+ (vb) => this.getValidatorBondBalance(state.bondType, state.name, vb.voteAccount).then((v) => v ?? 0)
7064
+ )
7065
+ );
7066
+ const totalCollected = balances.reduce((sum, v) => sum + v, 0);
7067
+ bondStates.push([state, totalCollected]);
7068
+ }
7069
+ return bondStates;
7070
+ }
7071
+ async getValidatorBondsByState(bondType, bondName) {
7072
+ const validatorBonds = [];
7073
+ const bondStatePda = this.pda.bondState(bondType, bondName)[0];
7074
+ const validatorBondAccounts = await this.program.account.validatorBond.all([
7075
+ {
7076
+ memcmp: {
7077
+ offset: 8,
7078
+ bytes: bondStatePda.toBase58()
7079
+ }
7080
+ }
7081
+ ]);
7082
+ for (const { account: vb } of validatorBondAccounts) {
7083
+ validatorBonds.push(vb);
7057
7084
  }
7085
+ return validatorBonds;
7058
7086
  }
7059
7087
  /**
7060
7088
  * Fetch validator bond data or null if not found
@@ -7064,7 +7092,6 @@ var JBondClient = class _JBondClient {
7064
7092
  */
7065
7093
  async getValidatorBond(bondType, bondName, vote) {
7066
7094
  const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
7067
- console.log("Fetching validator bond at address:", address.toString());
7068
7095
  return await this.program.account.validatorBond.fetchNullable(address);
7069
7096
  }
7070
7097
  /**