feat(web3.js): add support for get stake minimum delegation (#26682)

This commit is contained in:
Athar Mohammad 2022-07-22 13:32:49 +05:30 committed by GitHub
parent b9001a947a
commit ce337e009d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 7 deletions

View File

@ -453,6 +453,14 @@ export type GetBlockConfig = {
maxSupportedTransactionVersion?: number;
};
/**
* Configuration object for changing `getStakeMinimumDelegation` query behavior
*/
export type GetStakeMinimumDelegationConfig = {
/** The level of commitment desired */
commitment?: Commitment;
};
/**
* Configuration object for changing `getBlockHeight` query behavior
*/
@ -4317,6 +4325,25 @@ export class Connection {
}
}
/**
* get the stake minimum delegation
*/
async getStakeMinimumDelegation(
config?: GetStakeMinimumDelegationConfig,
): Promise<RpcResponseAndContext<number>> {
const {commitment, config: configArg} = extractCommitmentFromConfig(config);
const args = this._buildArgs([], commitment, 'base64', configArg);
const unsafeRes = await this._rpcRequest('getStakeMinimumDelegation', args);
const res = create(unsafeRes, jsonRpcResultAndContext(number()));
if ('error' in res) {
throw new SolanaJSONRPCError(
res.error,
`failed to get stake minimum delegation`,
);
}
return res.result;
}
/**
* Simulate a transaction
*/

View File

@ -3804,6 +3804,10 @@ describe('Connection', function () {
}
if (process.env.TEST_LIVE) {
it('getStakeMinimumDelegation', async () => {
const {value} = await connection.getStakeMinimumDelegation();
expect(value).to.be.a('number');
});
it('simulate transaction with message', async () => {
connection._commitment = 'confirmed';

View File

@ -382,13 +382,15 @@ describe('StakeProgram', () => {
if (process.env.TEST_LIVE) {
it('live staking actions', async () => {
const connection = new Connection(url, 'confirmed');
const SYSTEM_ACCOUNT_MIN_BALANCE =
await connection.getMinimumBalanceForRentExemption(0);
const STAKE_ACCOUNT_MIN_BALANCE =
await connection.getMinimumBalanceForRentExemption(StakeProgram.space);
// todo: use `Connection.getMinimumStakeDelegation` when implemented
const MIN_STAKE_DELEGATION = LAMPORTS_PER_SOL;
const [
SYSTEM_ACCOUNT_MIN_BALANCE,
STAKE_ACCOUNT_MIN_BALANCE,
{value: MIN_STAKE_DELEGATION},
] = await Promise.all([
connection.getMinimumBalanceForRentExemption(0),
connection.getMinimumBalanceForRentExemption(StakeProgram.space),
connection.getStakeMinimumDelegation(),
]);
const voteAccounts = await connection.getVoteAccounts();
const voteAccount = voteAccounts.current.concat(