1use cosmwasm_std::{Coin, Decimal, Uint128};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use tg_utils::{Duration, Expiration};
5
6pub use crate::claim::Claim;
7use tg4::Member;
8
9const fn default_auto_return_limit() -> u64 {
10 20
11}
12
13#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
14pub struct InstantiateMsg {
15 pub denom: String,
17 pub tokens_per_point: Uint128,
18 pub min_bond: Uint128,
19 pub unbonding_period: u64,
21
22 pub admin: Option<String>,
24 #[serde(default)]
26 pub preauths_hooks: u64,
27 #[serde(default)]
29 pub preauths_slashing: u64,
30 #[serde(default = "default_auto_return_limit")]
33 pub auto_return_limit: u64,
34}
35
36#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
37#[serde(rename_all = "snake_case")]
38pub enum ExecuteMsg {
39 Bond { vesting_tokens: Option<Coin> },
42 Unbond { tokens: Coin },
48 Claim {},
51
52 UpdateAdmin { admin: Option<String> },
54 AddHook { addr: String },
56 RemoveHook { addr: String },
58 AddSlasher { addr: String },
60 RemoveSlasher { addr: String },
62 Slash {
63 addr: String,
64 portion: Decimal,
66 },
67}
68
69#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
70#[serde(rename_all = "snake_case")]
71pub enum QueryMsg {
72 Configuration {},
74 Claims {
76 address: String,
77 limit: Option<u32>,
78 start_after: Option<Expiration>,
79 },
80 Staked { address: String },
83 UnbondingPeriod {},
86
87 Admin {},
89 TotalPoints {},
92 ListMembers {
94 start_after: Option<String>,
95 limit: Option<u32>,
96 },
97 ListMembersByPoints {
99 start_after: Option<Member>,
100 limit: Option<u32>,
101 },
102 Member {
104 addr: String,
105 at_height: Option<u64>,
106 },
107 Hooks {},
109 Preauths {},
111 IsSlasher { addr: String },
113 ListSlashers {},
115}
116
117#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
118pub struct StakedResponse {
119 pub liquid: Coin,
120 pub vesting: Coin,
121}
122
123#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
124pub struct PreauthResponse {
125 pub preauths_hooks: u64,
126}
127
128#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
129pub struct UnbondingPeriodResponse {
130 pub unbonding_period: Duration,
131}
132
133#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
134pub struct ClaimsResponse {
135 pub claims: Vec<Claim>,
136}
137
138#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
139pub struct Undelegation {
140 pub addr: String,
141 pub amount: Uint128,
142}
143
144#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
145#[serde(rename_all = "snake_case")]
146pub struct MigrateMsg {
147 pub tokens_per_point: Option<Uint128>,
148 pub min_bond: Option<Uint128>,
149 pub unbonding_period: Option<u64>,
150 pub auto_return_limit: Option<u64>,
151 pub undelegations: Option<Vec<Undelegation>>,
152}
153
154#[cfg(test)]
155mod tests {
156 use super::*;
157
158 use cosmwasm_std::to_vec;
159 use tg_utils::Duration;
160
161 #[test]
162 fn unbonding_period_serializes_in_seconds() {
163 let res = UnbondingPeriodResponse {
164 unbonding_period: Duration::new(12345),
165 };
166 let json = to_vec(&res).unwrap();
167 assert_eq!(&json, br#"{"unbonding_period":12345}"#);
168 }
169}