1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Decimal as StdDecimal, Uint64};
5use tg4::{Member, MemberChangedHookMsg};
6
7use crate::error::ContractError;
8use crate::functions::{AlgebraicSigmoid, GeometricMean, PoEFunction, Sigmoid, SigmoidSqrt};
9
10#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
11pub struct InstantiateMsg {
12 pub left_group: String,
14 pub right_group: String,
16 #[serde(default)]
18 pub preauths_hooks: u64,
19 #[serde(default)]
21 pub preauths_slashing: u64,
22 pub function_type: PoEFunctionType,
24}
25
26#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
27#[serde(rename_all = "snake_case")]
28pub enum PoEFunctionType {
29 GeometricMean {},
31 Sigmoid {
34 max_points: Uint64,
35 p: StdDecimal,
36 s: StdDecimal,
37 },
38 SigmoidSqrt { max_points: Uint64, s: StdDecimal },
43 AlgebraicSigmoid {
46 max_points: Uint64,
47 a: StdDecimal,
48 p: StdDecimal,
49 s: StdDecimal,
50 },
51}
52
53impl PoEFunctionType {
54 pub fn to_poe_fn(&self) -> Result<Box<dyn PoEFunction>, ContractError> {
55 match self.clone() {
56 PoEFunctionType::GeometricMean {} => Ok(Box::new(GeometricMean::new())),
57 PoEFunctionType::Sigmoid { max_points, p, s } => {
58 Ok(Box::new(Sigmoid::new(max_points, p, s)?))
59 }
60 PoEFunctionType::SigmoidSqrt { max_points, s } => {
61 Ok(Box::new(SigmoidSqrt::new(max_points, s)?))
62 }
63 PoEFunctionType::AlgebraicSigmoid {
64 max_points,
65 a,
66 p,
67 s,
68 } => Ok(Box::new(AlgebraicSigmoid::new(max_points, a, p, s)?)),
69 }
70 }
71}
72
73#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
74#[serde(rename_all = "snake_case")]
75pub enum ExecuteMsg {
76 MemberChangedHook(MemberChangedHookMsg),
78 AddHook { addr: String },
80 RemoveHook { addr: String },
82 AddSlasher { addr: String },
84 RemoveSlasher { addr: String },
86 Slash { addr: String, portion: StdDecimal },
88}
89
90#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
91#[serde(rename_all = "snake_case")]
92pub enum QueryMsg {
93 TotalPoints {},
95 ListMembers {
97 start_after: Option<String>,
98 limit: Option<u32>,
99 },
100 ListMembersByPoints {
102 start_after: Option<Member>,
103 limit: Option<u32>,
104 },
105 Member {
107 addr: String,
108 at_height: Option<u64>,
109 },
110 Hooks {},
112 Groups {},
114 Preauths {},
116 MixerFunction {
119 stake: Uint64,
120 engagement: Uint64,
121 poe_function: Option<PoEFunctionType>,
122 },
123 IsSlasher { addr: String },
125 ListSlashers {},
127}
128
129#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
131pub struct GroupsResponse {
132 pub left: String,
133 pub right: String,
134}
135
136#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
137pub struct PreauthResponse {
138 pub preauths_hooks: u64,
139}
140
141#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
142pub struct MixerFunctionResponse {
143 pub points: u64,
144}