cosmwasm_std/query/
distribution.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use crate::Addr;
5
6use super::query_response::QueryResponseType;
7
8#[non_exhaustive]
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum DistributionQuery {
12    /// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L222-L230>
13    DelegatorWithdrawAddress { delegator_address: String },
14    /// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L157-L167>
15    #[cfg(feature = "cosmwasm_1_4")]
16    DelegationRewards {
17        delegator_address: String,
18        validator_address: String,
19    },
20    /// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L180-L187>
21    #[cfg(feature = "cosmwasm_1_4")]
22    DelegationTotalRewards { delegator_address: String },
23    /// See <https://github.com/cosmos/cosmos-sdk/blob/b0acf60e6c39f7ab023841841fc0b751a12c13ff/proto/cosmos/distribution/v1beta1/query.proto#L202-L210>
24    #[cfg(feature = "cosmwasm_1_4")]
25    DelegatorValidators { delegator_address: String },
26}
27
28/// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L232-L240>
29#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
30#[serde(rename_all = "snake_case")]
31#[non_exhaustive]
32pub struct DelegatorWithdrawAddressResponse {
33    pub withdraw_address: Addr,
34}
35
36impl_response_constructor!(DelegatorWithdrawAddressResponse, withdraw_address: Addr);
37impl QueryResponseType for DelegatorWithdrawAddressResponse {}
38
39/// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L169-L178>
40#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
41#[serde(rename_all = "snake_case")]
42pub struct DelegationRewardsResponse {
43    pub rewards: Vec<DecCoin>,
44}
45
46impl_response_constructor!(DelegationRewardsResponse, rewards: Vec<DecCoin>);
47impl QueryResponseType for DelegationRewardsResponse {}
48
49/// A coin type with decimal amount.
50/// Modeled after the Cosmos SDK's [DecCoin] type.
51/// However, in contrast to the Cosmos SDK the `amount` string MUST always have a dot at JSON level,
52/// see <https://github.com/cosmos/cosmos-sdk/issues/10863>.
53/// Also if Cosmos SDK choses to migrate away from fixed point decimals
54/// (as shown [here](https://github.com/cosmos/cosmos-sdk/blob/v0.47.4/x/group/internal/math/dec.go#L13-L21 and discussed [here](https://github.com/cosmos/cosmos-sdk/issues/11783)),
55/// wasmd needs to truncate the decimal places to 18.
56///
57/// [DecCoin]: (https://github.com/cosmos/cosmos-sdk/blob/v0.47.4/proto/cosmos/base/v1beta1/coin.proto#L28-L38)
58#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
59#[serde(rename_all = "snake_case")]
60pub struct DecCoin {
61    pub denom: String,
62    /// An amount in the base denom of the distributed token.
63    ///
64    /// Some chains have choosen atto (10^-18) for their token's base denomination. If we used `Decimal` here, we could only store
65    /// 340282366920938463463.374607431768211455atoken which is 340.28 TOKEN.
66    pub amount: crate::Decimal256,
67}
68
69impl DecCoin {
70    pub fn new(amount: crate::Decimal256, denom: impl Into<String>) -> Self {
71        Self {
72            denom: denom.into(),
73            amount,
74        }
75    }
76}
77
78/// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L189-L200>
79#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
80#[non_exhaustive]
81pub struct DelegationTotalRewardsResponse {
82    pub rewards: Vec<DelegatorReward>,
83    pub total: Vec<DecCoin>,
84}
85
86impl_response_constructor!(
87    DelegationTotalRewardsResponse,
88    rewards: Vec<DelegatorReward>,
89    total: Vec<DecCoin>
90);
91impl QueryResponseType for DelegationTotalRewardsResponse {}
92
93#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
94pub struct DelegatorReward {
95    pub validator_address: String,
96    pub reward: Vec<DecCoin>,
97}
98
99/// See <https://github.com/cosmos/cosmos-sdk/blob/b0acf60e6c39f7ab023841841fc0b751a12c13ff/proto/cosmos/distribution/v1beta1/query.proto#L212-L220>
100#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
101pub struct DelegatorValidatorsResponse {
102    pub validators: Vec<String>,
103}
104
105impl_response_constructor!(DelegatorValidatorsResponse, validators: Vec<String>);
106impl QueryResponseType for DelegatorValidatorsResponse {}