cw20_stake/
msg.rs

1use cosmwasm_schema::{cw_serde, QueryResponses};
2use cosmwasm_std::Uint128;
3use cw20::Cw20ReceiveMsg;
4
5use cw_utils::Duration;
6
7use cw_ownable::cw_ownable_execute;
8
9pub use cw_controllers::ClaimsResponse;
10// so that consumers don't need a cw_ownable dependency to consume
11// this contract's queries.
12pub use cw_ownable::Ownership;
13
14#[cw_serde]
15pub struct InstantiateMsg {
16    // Owner can update all configs including changing the owner. This will generally be a DAO.
17    pub owner: Option<String>,
18    pub token_address: String,
19    pub unstaking_duration: Option<Duration>,
20}
21
22#[cw_ownable_execute]
23#[cw_serde]
24pub enum ExecuteMsg {
25    Receive(Cw20ReceiveMsg),
26    Unstake { amount: Uint128 },
27    Claim {},
28    UpdateConfig { duration: Option<Duration> },
29    AddHook { addr: String },
30    RemoveHook { addr: String },
31}
32
33#[cw_serde]
34pub enum ReceiveMsg {
35    Stake {},
36    Fund {},
37}
38
39#[cw_serde]
40#[derive(QueryResponses)]
41pub enum QueryMsg {
42    #[returns(StakedBalanceAtHeightResponse)]
43    StakedBalanceAtHeight {
44        address: String,
45        height: Option<u64>,
46    },
47    #[returns(TotalStakedAtHeightResponse)]
48    TotalStakedAtHeight { height: Option<u64> },
49    #[returns(StakedValueResponse)]
50    StakedValue { address: String },
51    #[returns(TotalValueResponse)]
52    TotalValue {},
53    #[returns(crate::state::Config)]
54    GetConfig {},
55    #[returns(ClaimsResponse)]
56    Claims { address: String },
57    #[returns(GetHooksResponse)]
58    GetHooks {},
59    #[returns(ListStakersResponse)]
60    ListStakers {
61        start_after: Option<String>,
62        limit: Option<u32>,
63    },
64    #[returns(::cw_ownable::Ownership::<::cosmwasm_std::Addr>)]
65    Ownership {},
66}
67
68#[cw_serde]
69pub enum MigrateMsg {
70    /// Migrates the contract from version one to version two. This
71    /// will remove the contract's current manager, and require a
72    /// nomination -> acceptance flow for future ownership transfers.
73    FromV1 {},
74}
75
76#[cw_serde]
77pub struct StakedBalanceAtHeightResponse {
78    pub balance: Uint128,
79    pub height: u64,
80}
81
82#[cw_serde]
83pub struct TotalStakedAtHeightResponse {
84    pub total: Uint128,
85    pub height: u64,
86}
87
88#[cw_serde]
89pub struct StakedValueResponse {
90    pub value: Uint128,
91}
92
93#[cw_serde]
94pub struct TotalValueResponse {
95    pub total: Uint128,
96}
97
98#[cw_serde]
99pub struct GetHooksResponse {
100    pub hooks: Vec<String>,
101}
102
103#[cw_serde]
104pub struct ListStakersResponse {
105    pub stakers: Vec<StakerBalanceResponse>,
106}
107
108#[cw_serde]
109pub struct StakerBalanceResponse {
110    pub address: String,
111    pub balance: Uint128,
112}