prov_cosmwasm_std/query/
staking.rs

1#![cfg(feature = "staking")]
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::{Addr, Coin, Decimal};
7
8#[non_exhaustive]
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum StakingQuery {
12    /// Returns the denomination that can be bonded (if there are multiple native tokens on the chain)
13    BondedDenom {},
14    /// AllDelegations will return all delegations by the delegator
15    AllDelegations { delegator: String },
16    /// Delegation will return more detailed info on a particular
17    /// delegation, defined by delegator/validator pair
18    Delegation {
19        delegator: String,
20        validator: String,
21    },
22    /// Returns all validators in the currently active validator set.
23    ///
24    /// The query response type is `AllValidatorsResponse`.
25    AllValidators {},
26    /// Returns the validator at the given address. Returns None if the validator is
27    /// not part of the currently active validator set.
28    ///
29    /// The query response type is `ValidatorResponse`.
30    Validator {
31        /// The validator's address (e.g. (e.g. cosmosvaloper1...))
32        address: String,
33    },
34}
35
36/// BondedDenomResponse is data format returned from StakingRequest::BondedDenom query
37#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
38#[serde(rename_all = "snake_case")]
39pub struct BondedDenomResponse {
40    pub denom: String,
41}
42
43/// DelegationsResponse is data format returned from StakingRequest::AllDelegations query
44#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
45#[serde(rename_all = "snake_case")]
46pub struct AllDelegationsResponse {
47    pub delegations: Vec<Delegation>,
48}
49
50/// Delegation is basic (cheap to query) data about a delegation.
51///
52/// Instances are created in the querier.
53#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
54pub struct Delegation {
55    pub delegator: Addr,
56    /// A validator address (e.g. cosmosvaloper1...)
57    pub validator: String,
58    /// How much we have locked in the delegation
59    pub amount: Coin,
60}
61
62impl From<FullDelegation> for Delegation {
63    fn from(full: FullDelegation) -> Self {
64        Delegation {
65            delegator: full.delegator,
66            validator: full.validator,
67            amount: full.amount,
68        }
69    }
70}
71
72/// DelegationResponse is data format returned from StakingRequest::Delegation query
73#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
74#[serde(rename_all = "snake_case")]
75pub struct DelegationResponse {
76    pub delegation: Option<FullDelegation>,
77}
78
79/// FullDelegation is all the info on the delegation, some (like accumulated_reward and can_redelegate)
80/// is expensive to query.
81///
82/// Instances are created in the querier.
83#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
84pub struct FullDelegation {
85    pub delegator: Addr,
86    /// A validator address (e.g. cosmosvaloper1...)
87    pub validator: String,
88    /// How much we have locked in the delegation
89    pub amount: Coin,
90    /// can_redelegate captures how much can be immediately redelegated.
91    /// 0 is no redelegation and can_redelegate == amount is redelegate all
92    /// but there are many places between the two
93    pub can_redelegate: Coin,
94    /// How much we can currently withdraw
95    pub accumulated_rewards: Vec<Coin>,
96}
97
98/// The data format returned from StakingRequest::AllValidators query
99#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
100pub struct AllValidatorsResponse {
101    pub validators: Vec<Validator>,
102}
103
104/// The data format returned from StakingRequest::Validator query
105#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
106pub struct ValidatorResponse {
107    pub validator: Option<Validator>,
108}
109
110/// Instances are created in the querier.
111#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
112pub struct Validator {
113    /// A validator address (e.g. cosmosvaloper1...)
114    pub address: String,
115    pub commission: Decimal,
116    pub max_commission: Decimal,
117    /// TODO: what units are these (in terms of time)?
118    pub max_change_rate: Decimal,
119}