Skip to content

Commit

Permalink
feat(web3.js): add support for get stake minimum delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
atharmohammad committed Jul 20, 2022
1 parent 0402c3d commit 8602516
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
21 changes: 21 additions & 0 deletions web3.js/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4278,6 +4278,27 @@ export class Connection {
}
}

/**
* get the stake minimum delegation
*/
async getStakeMinimumDelegation(): Promise<RpcResponseAndContext<number>> {
const config: any = {
encoding: 'base64',
commitment: this.commitment,
};
const unsafeRes = await this._rpcRequest('getStakeMinimumDelegation', [
config,
]);
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
*/
Expand Down
4 changes: 4 additions & 0 deletions web3.js/test/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3804,6 +3804,10 @@ describe('Connection', function () {
}

if (process.env.TEST_LIVE) {
it('getStakeMinimumDelegation', async () => {
const {value} = await connection.getStakeMinimumDelegation();
expect(value).to.eql(1000000000);
});
it('simulate transaction with message', async () => {
connection._commitment = 'confirmed';

Expand Down
5 changes: 3 additions & 2 deletions web3.js/test/stake-program.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,9 @@ describe('StakeProgram', () => {
const STAKE_ACCOUNT_MIN_BALANCE =
await connection.getMinimumBalanceForRentExemption(StakeProgram.space);

// todo: use `Connection.getMinimumStakeDelegation` when implemented
const MIN_STAKE_DELEGATION = LAMPORTS_PER_SOL;
const MIN_STAKE_DELEGATION = (
await connection.getStakeMinimumDelegation()
).value;

const voteAccounts = await connection.getVoteAccounts();
const voteAccount = voteAccounts.current.concat(
Expand Down

0 comments on commit 8602516

Please sign in to comment.