@jpool/bond-sdk 0.9.0-next.12 → 0.9.0-next.13
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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +60 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1937,6 +1937,8 @@ declare class JBondClient {
|
|
|
1937
1937
|
* @return Balance in lamports
|
|
1938
1938
|
*/
|
|
1939
1939
|
getValidatorBondBalance(bondType: BondType, bondName: string, vote: PublicKeyInitData): Promise<number>;
|
|
1940
|
+
getBondStateTotalCollected(bondType: BondType, bondName: string, votes: PublicKeyInitData[]): Promise<number>;
|
|
1941
|
+
private getBondStateStats;
|
|
1940
1942
|
/**
|
|
1941
1943
|
* Load stake pool account and cache it if not already cached
|
|
1942
1944
|
* @private
|
package/dist/index.d.ts
CHANGED
|
@@ -1937,6 +1937,8 @@ declare class JBondClient {
|
|
|
1937
1937
|
* @return Balance in lamports
|
|
1938
1938
|
*/
|
|
1939
1939
|
getValidatorBondBalance(bondType: BondType, bondName: string, vote: PublicKeyInitData): Promise<number>;
|
|
1940
|
+
getBondStateTotalCollected(bondType: BondType, bondName: string, votes: PublicKeyInitData[]): Promise<number>;
|
|
1941
|
+
private getBondStateStats;
|
|
1940
1942
|
/**
|
|
1941
1943
|
* Load stake pool account and cache it if not already cached
|
|
1942
1944
|
* @private
|
package/dist/index.js
CHANGED
|
@@ -6689,8 +6689,6 @@ var JBondClient = class _JBondClient {
|
|
|
6689
6689
|
token: (mint) => {
|
|
6690
6690
|
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(mint, props.reserve);
|
|
6691
6691
|
accounts.mint = mint;
|
|
6692
|
-
},
|
|
6693
|
-
stakeAccount: () => {
|
|
6694
6692
|
}
|
|
6695
6693
|
});
|
|
6696
6694
|
return this.program.methods.bondInitialize({
|
|
@@ -6739,9 +6737,6 @@ var JBondClient = class _JBondClient {
|
|
|
6739
6737
|
token: (mint) => {
|
|
6740
6738
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6741
6739
|
Object.assign(accounts, { mint, bondTokenAccount: accounts.bondTokenAccount });
|
|
6742
|
-
},
|
|
6743
|
-
stakeAccount: () => {
|
|
6744
|
-
throw new Error("Stake account collateral type is not currently supported");
|
|
6745
6740
|
}
|
|
6746
6741
|
});
|
|
6747
6742
|
return this.program.methods.bondRegister(bondType, name).accountsPartial(accounts).instruction();
|
|
@@ -6787,13 +6782,6 @@ var JBondClient = class _JBondClient {
|
|
|
6787
6782
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6788
6783
|
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6789
6784
|
accounts.associatedTokenProgram = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
6790
|
-
},
|
|
6791
|
-
stakeAccount: () => {
|
|
6792
|
-
if (!collateral.stakeAccount) {
|
|
6793
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
6794
|
-
}
|
|
6795
|
-
accounts.stakeAccount = collateral.stakeAccount;
|
|
6796
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
6797
6785
|
}
|
|
6798
6786
|
});
|
|
6799
6787
|
instructions.push(
|
|
@@ -6830,19 +6818,12 @@ var JBondClient = class _JBondClient {
|
|
|
6830
6818
|
accounts.destinationTokenAccount = splToken.getAssociatedTokenAddressSync(mint, destination, true);
|
|
6831
6819
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6832
6820
|
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6833
|
-
},
|
|
6834
|
-
stakeAccount: () => {
|
|
6835
|
-
if (!withdraw.stakeAccount) {
|
|
6836
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
6837
|
-
}
|
|
6838
|
-
accounts.stakeAccount = withdraw.stakeAccount;
|
|
6839
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
6840
6821
|
}
|
|
6841
6822
|
});
|
|
6842
6823
|
return this.program.methods.bondWithdraw(this.lamports(withdraw.amount)).accountsPartial(accounts).instruction();
|
|
6843
6824
|
}
|
|
6844
6825
|
async buildClaimIx(props) {
|
|
6845
|
-
const {
|
|
6826
|
+
const { bondType, name } = props;
|
|
6846
6827
|
const [bondState] = this.pda.bondState(bondType, name);
|
|
6847
6828
|
const [validatorBond] = this.pda.validatorBond(bondType, name, props.voteAccount);
|
|
6848
6829
|
const reserve = props.reserve ?? (await this.getBondState(bondType, name)).reserve;
|
|
@@ -6871,13 +6852,6 @@ var JBondClient = class _JBondClient {
|
|
|
6871
6852
|
accounts.bondTokenAccount = splToken.getAssociatedTokenAddressSync(mint, validatorBond, true);
|
|
6872
6853
|
accounts.reserveTokenAccount = splToken.getAssociatedTokenAddressSync(mint, reserve, true);
|
|
6873
6854
|
accounts.tokenProgram = splToken.TOKEN_PROGRAM_ID;
|
|
6874
|
-
},
|
|
6875
|
-
stakeAccount: () => {
|
|
6876
|
-
if (!claim.stakeAccount) {
|
|
6877
|
-
throw new Error("Missing stakeAccount for stake collateral");
|
|
6878
|
-
}
|
|
6879
|
-
accounts.stakeAccount = claim.stakeAccount;
|
|
6880
|
-
accounts.stakeProgram = web3_js.StakeProgram.programId;
|
|
6881
6855
|
}
|
|
6882
6856
|
});
|
|
6883
6857
|
return this.program.methods.bondClaim(this.lamports(props.claim.amount)).accountsPartial(
|
|
@@ -6941,16 +6915,7 @@ var JBondClient = class _JBondClient {
|
|
|
6941
6915
|
if (!sameVariant(state.bondType, bondType)) {
|
|
6942
6916
|
continue;
|
|
6943
6917
|
}
|
|
6944
|
-
const
|
|
6945
|
-
const balances = await Promise.all(
|
|
6946
|
-
validatorBonds.map(
|
|
6947
|
-
(vb) => this.getValidatorBondBalance(state.bondType, state.name, vb.voteAccount).then((v) => v ?? 0)
|
|
6948
|
-
)
|
|
6949
|
-
);
|
|
6950
|
-
const bondStateStats = {
|
|
6951
|
-
totalCollected: balances.reduce((sum, v) => sum + v, 0),
|
|
6952
|
-
status: await this.getBondStateSessionStatus(state)
|
|
6953
|
-
};
|
|
6918
|
+
const bondStateStats = await this.getBondStateStats(state.bondType, state.name);
|
|
6954
6919
|
bondStates.push([state, bondStateStats]);
|
|
6955
6920
|
}
|
|
6956
6921
|
return bondStates;
|
|
@@ -7033,18 +6998,68 @@ var JBondClient = class _JBondClient {
|
|
|
7033
6998
|
} catch {
|
|
7034
6999
|
return 0;
|
|
7035
7000
|
}
|
|
7001
|
+
}
|
|
7002
|
+
});
|
|
7003
|
+
}
|
|
7004
|
+
// Get total collected collateral for a bond state
|
|
7005
|
+
async getBondStateTotalCollected(bondType, bondName, votes) {
|
|
7006
|
+
const bondStateData = await this.getBondState(bondType, bondName);
|
|
7007
|
+
const bondStateCollateralType = bondStateData.collateralType;
|
|
7008
|
+
return await matchVariant(bondStateCollateralType, {
|
|
7009
|
+
native: async () => {
|
|
7010
|
+
const addresses = votes.map((vote) => {
|
|
7011
|
+
const [address] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
7012
|
+
return address;
|
|
7013
|
+
});
|
|
7014
|
+
const accountInfos = await this.connection.getMultipleAccountsInfo(addresses);
|
|
7015
|
+
const balances = await Promise.all(
|
|
7016
|
+
accountInfos.map(async (accountInfo) => {
|
|
7017
|
+
if (!accountInfo) {
|
|
7018
|
+
return 0;
|
|
7019
|
+
}
|
|
7020
|
+
const { lamports } = accountInfo;
|
|
7021
|
+
return lamports;
|
|
7022
|
+
})
|
|
7023
|
+
);
|
|
7024
|
+
return balances.reduce((sum, v) => sum + v, 0);
|
|
7036
7025
|
},
|
|
7037
|
-
|
|
7038
|
-
const
|
|
7039
|
-
|
|
7040
|
-
return
|
|
7041
|
-
}
|
|
7042
|
-
const
|
|
7043
|
-
const
|
|
7044
|
-
|
|
7026
|
+
token: async (mint) => {
|
|
7027
|
+
const tokenAccounts = votes.map((vote) => {
|
|
7028
|
+
const [validatorBondAddress] = this.pda.validatorBond(bondType, bondName, new web3_js.PublicKey(vote));
|
|
7029
|
+
return splToken.getAssociatedTokenAddressSync(mint, validatorBondAddress, true);
|
|
7030
|
+
});
|
|
7031
|
+
const accountInfos = await this.connection.getMultipleAccountsInfo(tokenAccounts);
|
|
7032
|
+
const balances = await Promise.all(
|
|
7033
|
+
accountInfos.map(async (accountInfo) => {
|
|
7034
|
+
if (!accountInfo) {
|
|
7035
|
+
return 0;
|
|
7036
|
+
}
|
|
7037
|
+
try {
|
|
7038
|
+
const balance = await this.connection.getTokenAccountBalance(tokenAccounts[accountInfos.indexOf(accountInfo)]);
|
|
7039
|
+
return Number(balance.value.uiAmount ?? 0) * web3_js.LAMPORTS_PER_SOL;
|
|
7040
|
+
} catch {
|
|
7041
|
+
return 0;
|
|
7042
|
+
}
|
|
7043
|
+
})
|
|
7044
|
+
);
|
|
7045
|
+
return balances.reduce((sum, v) => sum + v, 0);
|
|
7045
7046
|
}
|
|
7046
7047
|
});
|
|
7047
7048
|
}
|
|
7049
|
+
async getBondStateStats(bondType, bondName) {
|
|
7050
|
+
const bondState = await this.getBondState(bondType, bondName);
|
|
7051
|
+
const validatorBonds = await this.getValidatorBondsByState(bondState.bondType, bondState.name);
|
|
7052
|
+
const totalCollected = await this.getBondStateTotalCollected(
|
|
7053
|
+
bondType,
|
|
7054
|
+
bondName,
|
|
7055
|
+
validatorBonds.map((vb) => vb.voteAccount)
|
|
7056
|
+
);
|
|
7057
|
+
const bondStateStats = {
|
|
7058
|
+
totalCollected,
|
|
7059
|
+
status: await this.getBondStateSessionStatus(bondState)
|
|
7060
|
+
};
|
|
7061
|
+
return bondStateStats;
|
|
7062
|
+
}
|
|
7048
7063
|
/**
|
|
7049
7064
|
* Load stake pool account and cache it if not already cached
|
|
7050
7065
|
* @private
|