pub struct Staking {}Expand description
Staking-related interactions with the NEAR Protocol and the staking pools.
The Staking struct provides methods to interact with NEAR staking, including querying staking pools, validators, and delegators,
as well as delegating and withdrawing from staking pools.
§Examples
use near_api::*;
let staking_pools = Staking::active_staking_pools().fetch_from_testnet().await?;
println!("Staking pools: {:?}", staking_pools);Implementations§
Source§impl Staking
impl Staking
Sourcepub fn active_staking_pools() -> RpcBuilder<ActiveStakingPoolQuery, ActiveStakingHandler>
pub fn active_staking_pools() -> RpcBuilder<ActiveStakingPoolQuery, ActiveStakingHandler>
Returns a list of active staking pools (std::collections::BTreeSet<AccountId>]) by querying the staking pools factory contract.
Please note that it might fail on the mainnet as the staking pool factory is super huge.
§Example
use near_api::*;
let staking_pools = Staking::active_staking_pools().fetch_from_testnet().await?;
println!("Staking pools: {:?}", staking_pools);Sourcepub fn epoch_validators_info() -> RequestBuilder<RpcValidatorHandler>
pub fn epoch_validators_info() -> RequestBuilder<RpcValidatorHandler>
Returns a list of validators and their stake (near_api_types::RpcValidatorResponse) for the current epoch.
§Example
use near_api::*;
let validators = Staking::epoch_validators_info().fetch_from_testnet().await?;
println!("Validators: {:?}", validators);Sourcepub fn validators_stake() -> RequestBuilder<PostprocessHandler<BTreeMap<AccountId, NearToken>, RpcValidatorHandler>>
pub fn validators_stake() -> RequestBuilder<PostprocessHandler<BTreeMap<AccountId, NearToken>, RpcValidatorHandler>>
Returns a map of validators and their stake (BTreeMap<AccountId, NearToken>) for the current epoch.
§Example
use near_api::*;
let validators = Staking::validators_stake().fetch_from_testnet().await?;
println!("Validators: {:?}", validators);Sourcepub fn staking_pool_reward_fee(
pool: AccountId,
) -> RequestBuilder<CallResultHandler<RewardFeeFraction>>
pub fn staking_pool_reward_fee( pool: AccountId, ) -> RequestBuilder<CallResultHandler<RewardFeeFraction>>
Prepares a new contract query (get_reward_fee_fraction) for fetching the reward fee fraction of the staking pool (Data<RewardFeeFraction>).
The call depends that the contract implements StakingPool
§Example
use near_api::*;
let reward_fee = Staking::staking_pool_reward_fee("pool.testnet".parse()?)
.fetch_from_testnet().await?;
println!("Reward fee: {:?}", reward_fee);Sourcepub fn staking_pool_delegators(
pool: AccountId,
) -> RequestBuilder<CallResultHandler<u64>>
pub fn staking_pool_delegators( pool: AccountId, ) -> RequestBuilder<CallResultHandler<u64>>
Prepares a new contract query (get_number_of_accounts) for fetching the number of delegators of the staking pool (Data<u64>).
The call depends that the contract implements StakingPool
§Example
use near_api::*;
let delegators = Staking::staking_pool_delegators("pool.testnet".parse()?)
.fetch_from_testnet()
.await?;
println!("Delegators: {:?}", delegators);Sourcepub fn staking_pool_total_stake(
pool: AccountId,
) -> RequestBuilder<PostprocessHandler<NearToken, CallResultHandler<u128>>>
pub fn staking_pool_total_stake( pool: AccountId, ) -> RequestBuilder<PostprocessHandler<NearToken, CallResultHandler<u128>>>
Prepares a new contract query (get_total_staked_balance) for fetching the total stake of the staking pool (NearToken).
The call depends that the contract implements StakingPool
§Example
use near_api::*;
let total_stake = Staking::staking_pool_total_stake("pool.testnet".parse()?)
.fetch_from_testnet()
.await?;
println!("Total stake: {:?}", total_stake);Sourcepub fn staking_pool_info(
pool: AccountId,
) -> MultiRequestBuilder<PostprocessHandler<StakingPoolInfo, MultiQueryHandler<(CallResultHandler<RewardFeeFraction>, CallResultHandler<u64>, CallResultHandler<u128>)>>>
pub fn staking_pool_info( pool: AccountId, ) -> MultiRequestBuilder<PostprocessHandler<StakingPoolInfo, MultiQueryHandler<(CallResultHandler<RewardFeeFraction>, CallResultHandler<u64>, CallResultHandler<u128>)>>>
Returns a full information about the staking pool (StakingPoolInfo).
This is a complex query that requires 3 calls (get_reward_fee_fraction, get_number_of_accounts, get_total_staked_balance) to the staking pool contract.
The call depends that the contract implements StakingPool
§Example
use near_api::*;
let staking_pool_info = Staking::staking_pool_info("pool.testnet".parse()?)
.fetch_from_testnet()
.await?;
println!("Staking pool info: {:?}", staking_pool_info);Sourcepub const fn delegation(account_id: AccountId) -> Delegation
pub const fn delegation(account_id: AccountId) -> Delegation
Returns a new Delegation struct for interacting with the staking pool on behalf of the account.