feat(web3.js): add support for get stake minimum delegation (#26682)
This commit is contained in:
parent
b9001a947a
commit
ce337e009d
|
@ -453,6 +453,14 @@ export type GetBlockConfig = {
|
||||||
maxSupportedTransactionVersion?: number;
|
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
|
* 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
|
* Simulate a transaction
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3804,6 +3804,10 @@ describe('Connection', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.TEST_LIVE) {
|
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 () => {
|
it('simulate transaction with message', async () => {
|
||||||
connection._commitment = 'confirmed';
|
connection._commitment = 'confirmed';
|
||||||
|
|
||||||
|
|
|
@ -382,13 +382,15 @@ describe('StakeProgram', () => {
|
||||||
if (process.env.TEST_LIVE) {
|
if (process.env.TEST_LIVE) {
|
||||||
it('live staking actions', async () => {
|
it('live staking actions', async () => {
|
||||||
const connection = new Connection(url, 'confirmed');
|
const connection = new Connection(url, 'confirmed');
|
||||||
const SYSTEM_ACCOUNT_MIN_BALANCE =
|
const [
|
||||||
await connection.getMinimumBalanceForRentExemption(0);
|
SYSTEM_ACCOUNT_MIN_BALANCE,
|
||||||
const STAKE_ACCOUNT_MIN_BALANCE =
|
STAKE_ACCOUNT_MIN_BALANCE,
|
||||||
await connection.getMinimumBalanceForRentExemption(StakeProgram.space);
|
{value: MIN_STAKE_DELEGATION},
|
||||||
|
] = await Promise.all([
|
||||||
// todo: use `Connection.getMinimumStakeDelegation` when implemented
|
connection.getMinimumBalanceForRentExemption(0),
|
||||||
const MIN_STAKE_DELEGATION = LAMPORTS_PER_SOL;
|
connection.getMinimumBalanceForRentExemption(StakeProgram.space),
|
||||||
|
connection.getStakeMinimumDelegation(),
|
||||||
|
]);
|
||||||
|
|
||||||
const voteAccounts = await connection.getVoteAccounts();
|
const voteAccounts = await connection.getVoteAccounts();
|
||||||
const voteAccount = voteAccounts.current.concat(
|
const voteAccount = voteAccounts.current.concat(
|
||||||
|
|
Loading…
Reference in New Issue