@jpool/bond-sdk 0.9.0-next.5 → 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 +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +29 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,8 +1839,11 @@ declare class JBondClient {
|
|
|
1835
1839
|
*/
|
|
1836
1840
|
getGlobalState(): Promise<GlobalState>;
|
|
1837
1841
|
getBondState(bondType: BondType, bondName: string): Promise<BondState>;
|
|
1838
|
-
|
|
1839
|
-
|
|
1842
|
+
/**
|
|
1843
|
+
* Get all bond states with total collected collateral
|
|
1844
|
+
*/
|
|
1845
|
+
getAllBondStates(_bondType: BondType): Promise<Array<[BondState, number]>>;
|
|
1846
|
+
private getValidatorBondsByState;
|
|
1840
1847
|
/**
|
|
1841
1848
|
* Fetch validator bond data or null if not found
|
|
1842
1849
|
* @param bondType
|
|
@@ -1875,4 +1882,4 @@ declare class JBondClient {
|
|
|
1875
1882
|
private ensureUser;
|
|
1876
1883
|
}
|
|
1877
1884
|
|
|
1878
|
-
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,8 +1839,11 @@ declare class JBondClient {
|
|
|
1835
1839
|
*/
|
|
1836
1840
|
getGlobalState(): Promise<GlobalState>;
|
|
1837
1841
|
getBondState(bondType: BondType, bondName: string): Promise<BondState>;
|
|
1838
|
-
|
|
1839
|
-
|
|
1842
|
+
/**
|
|
1843
|
+
* Get all bond states with total collected collateral
|
|
1844
|
+
*/
|
|
1845
|
+
getAllBondStates(_bondType: BondType): Promise<Array<[BondState, number]>>;
|
|
1846
|
+
private getValidatorBondsByState;
|
|
1840
1847
|
/**
|
|
1841
1848
|
* Fetch validator bond data or null if not found
|
|
1842
1849
|
* @param bondType
|
|
@@ -1875,4 +1882,4 @@ declare class JBondClient {
|
|
|
1875
1882
|
private ensureUser;
|
|
1876
1883
|
}
|
|
1877
1884
|
|
|
1878
|
-
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,23 +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
|
-
|
|
7050
|
+
/**
|
|
7051
|
+
* Get all bond states with total collected collateral
|
|
7052
|
+
*/
|
|
7051
7053
|
async getAllBondStates(_bondType) {
|
|
7052
7054
|
const bondStates = [];
|
|
7053
7055
|
const bondStateAccounts = await this.program.account.bondState.all();
|
|
7054
|
-
for (const { account } of bondStateAccounts) {
|
|
7055
|
-
|
|
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]);
|
|
7056
7068
|
}
|
|
7057
7069
|
return bondStates;
|
|
7058
7070
|
}
|
|
7059
|
-
async
|
|
7060
|
-
const
|
|
7061
|
-
const
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
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);
|
|
7066
7084
|
}
|
|
7085
|
+
return validatorBonds;
|
|
7067
7086
|
}
|
|
7068
7087
|
/**
|
|
7069
7088
|
* Fetch validator bond data or null if not found
|
|
@@ -7073,7 +7092,6 @@ var JBondClient = class _JBondClient {
|
|
|
7073
7092
|
*/
|
|
7074
7093
|
async getValidatorBond(bondType, bondName, vote) {
|
|
7075
7094
|
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
7076
|
-
console.log("Fetching validator bond at address:", address.toString());
|
|
7077
7095
|
return await this.program.account.validatorBond.fetchNullable(address);
|
|
7078
7096
|
}
|
|
7079
7097
|
/**
|