@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.mjs
CHANGED
|
@@ -7003,23 +7003,42 @@ var JBondClient = class _JBondClient {
|
|
|
7003
7003
|
const [bondState] = this.pda.bondState(bondType, bondName);
|
|
7004
7004
|
return await this.program.account.bondState.fetch(bondState);
|
|
7005
7005
|
}
|
|
7006
|
-
|
|
7006
|
+
/**
|
|
7007
|
+
* Get all bond states with total collected collateral
|
|
7008
|
+
*/
|
|
7007
7009
|
async getAllBondStates(_bondType) {
|
|
7008
7010
|
const bondStates = [];
|
|
7009
7011
|
const bondStateAccounts = await this.program.account.bondState.all();
|
|
7010
|
-
for (const { account } of bondStateAccounts) {
|
|
7011
|
-
|
|
7012
|
+
for (const { account: state } of bondStateAccounts) {
|
|
7013
|
+
if (!("crowdfunding" in state.bondType)) {
|
|
7014
|
+
continue;
|
|
7015
|
+
}
|
|
7016
|
+
const validatorBonds = await this.getValidatorBondsByState(state.bondType, state.name);
|
|
7017
|
+
const balances = await Promise.all(
|
|
7018
|
+
validatorBonds.map(
|
|
7019
|
+
(vb) => this.getValidatorBondBalance(state.bondType, state.name, vb.voteAccount).then((v) => v ?? 0)
|
|
7020
|
+
)
|
|
7021
|
+
);
|
|
7022
|
+
const totalCollected = balances.reduce((sum, v) => sum + v, 0);
|
|
7023
|
+
bondStates.push([state, totalCollected]);
|
|
7012
7024
|
}
|
|
7013
7025
|
return bondStates;
|
|
7014
7026
|
}
|
|
7015
|
-
async
|
|
7016
|
-
const
|
|
7017
|
-
const
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7027
|
+
async getValidatorBondsByState(bondType, bondName) {
|
|
7028
|
+
const validatorBonds = [];
|
|
7029
|
+
const bondStatePda = this.pda.bondState(bondType, bondName)[0];
|
|
7030
|
+
const validatorBondAccounts = await this.program.account.validatorBond.all([
|
|
7031
|
+
{
|
|
7032
|
+
memcmp: {
|
|
7033
|
+
offset: 8,
|
|
7034
|
+
bytes: bondStatePda.toBase58()
|
|
7035
|
+
}
|
|
7036
|
+
}
|
|
7037
|
+
]);
|
|
7038
|
+
for (const { account: vb } of validatorBondAccounts) {
|
|
7039
|
+
validatorBonds.push(vb);
|
|
7022
7040
|
}
|
|
7041
|
+
return validatorBonds;
|
|
7023
7042
|
}
|
|
7024
7043
|
/**
|
|
7025
7044
|
* Fetch validator bond data or null if not found
|
|
@@ -7029,7 +7048,6 @@ var JBondClient = class _JBondClient {
|
|
|
7029
7048
|
*/
|
|
7030
7049
|
async getValidatorBond(bondType, bondName, vote) {
|
|
7031
7050
|
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
7032
|
-
console.log("Fetching validator bond at address:", address.toString());
|
|
7033
7051
|
return await this.program.account.validatorBond.fetchNullable(address);
|
|
7034
7052
|
}
|
|
7035
7053
|
/**
|