@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 +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +35 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7003,14 +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
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7006
|
+
/**
|
|
7007
|
+
* Get all bond states with total collected collateral
|
|
7008
|
+
*/
|
|
7009
|
+
async getAllBondStates(_bondType) {
|
|
7010
|
+
const bondStates = [];
|
|
7011
|
+
const bondStateAccounts = await this.program.account.bondState.all();
|
|
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]);
|
|
7024
|
+
}
|
|
7025
|
+
return bondStates;
|
|
7026
|
+
}
|
|
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);
|
|
7013
7040
|
}
|
|
7041
|
+
return validatorBonds;
|
|
7014
7042
|
}
|
|
7015
7043
|
/**
|
|
7016
7044
|
* Fetch validator bond data or null if not found
|
|
@@ -7020,7 +7048,6 @@ var JBondClient = class _JBondClient {
|
|
|
7020
7048
|
*/
|
|
7021
7049
|
async getValidatorBond(bondType, bondName, vote) {
|
|
7022
7050
|
const [address] = this.pda.validatorBond(bondType, bondName, new PublicKey(vote));
|
|
7023
|
-
console.log("Fetching validator bond at address:", address.toString());
|
|
7024
7051
|
return await this.program.account.validatorBond.fetchNullable(address);
|
|
7025
7052
|
}
|
|
7026
7053
|
/**
|