1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{Addr, Binary, Coin, CosmosMsg, WasmMsg};
3
4#[cw_serde]
6pub struct Config {
7 pub name: String,
9 pub description: String,
11 pub image_url: Option<String>,
13 pub automatically_add_cw20s: bool,
16 pub automatically_add_cw721s: bool,
19 pub dao_uri: Option<String>,
22}
23
24#[cw_serde]
26pub struct ProposalModule {
27 pub address: Addr,
29 pub prefix: String,
32 pub status: ProposalModuleStatus,
34}
35
36#[cw_serde]
38pub enum ProposalModuleStatus {
39 Enabled,
40 Disabled,
41}
42
43#[cw_serde]
46pub enum Admin {
47 Address { addr: String },
49 CoreModule {},
51}
52
53#[cw_serde]
55pub struct ModuleInstantiateInfo {
56 pub code_id: u64,
58 pub msg: Binary,
60 pub admin: Option<Admin>,
63 pub funds: Vec<Coin>,
65 pub label: String,
67}
68
69impl ModuleInstantiateInfo {
70 pub fn into_wasm_msg(self, dao: Addr) -> WasmMsg {
71 WasmMsg::Instantiate {
72 admin: self.admin.map(|admin| match admin {
73 Admin::Address { addr } => addr,
74 Admin::CoreModule {} => dao.into_string(),
75 }),
76 code_id: self.code_id,
77 msg: self.msg,
78 funds: self.funds,
79 label: self.label,
80 }
81 }
82}
83
84#[cw_serde]
86pub struct ModuleInstantiateCallback {
87 pub msgs: Vec<CosmosMsg>,
88}
89
90#[cfg(test)]
91mod tests {
92 use super::*;
93
94 use cosmwasm_std::{to_json_binary, Addr, WasmMsg};
95
96 #[test]
97 fn test_module_instantiate_admin_none() {
98 let no_admin = ModuleInstantiateInfo {
99 code_id: 42,
100 msg: to_json_binary("foo").unwrap(),
101 admin: None,
102 label: "bar".to_string(),
103 funds: vec![],
104 };
105 assert_eq!(
106 no_admin.into_wasm_msg(Addr::unchecked("ekez")),
107 WasmMsg::Instantiate {
108 admin: None,
109 code_id: 42,
110 msg: to_json_binary("foo").unwrap(),
111 funds: vec![],
112 label: "bar".to_string()
113 }
114 )
115 }
116
117 #[test]
118 fn test_module_instantiate_admin_addr() {
119 let no_admin = ModuleInstantiateInfo {
120 code_id: 42,
121 msg: to_json_binary("foo").unwrap(),
122 admin: Some(Admin::Address {
123 addr: "core".to_string(),
124 }),
125 label: "bar".to_string(),
126 funds: vec![],
127 };
128 assert_eq!(
129 no_admin.into_wasm_msg(Addr::unchecked("ekez")),
130 WasmMsg::Instantiate {
131 admin: Some("core".to_string()),
132 code_id: 42,
133 msg: to_json_binary("foo").unwrap(),
134 funds: vec![],
135 label: "bar".to_string()
136 }
137 )
138 }
139
140 #[test]
141 fn test_module_instantiate_instantiator_addr() {
142 let no_admin = ModuleInstantiateInfo {
143 code_id: 42,
144 msg: to_json_binary("foo").unwrap(),
145 admin: Some(Admin::CoreModule {}),
146 label: "bar".to_string(),
147 funds: vec![],
148 };
149 assert_eq!(
150 no_admin.into_wasm_msg(Addr::unchecked("ekez")),
151 WasmMsg::Instantiate {
152 admin: Some("ekez".to_string()),
153 code_id: 42,
154 msg: to_json_binary("foo").unwrap(),
155 funds: vec![],
156 label: "bar".to_string()
157 }
158 )
159 }
160}