1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
use abstract_os::manager::ManagerModuleInfo;
use abstract_os::{
manager::QueryMsgFns as ManagerQueryMsgFns, proxy::QueryMsgFns as ProxyQueryMsgFns,
};
use boot_core::{prelude::*, BootEnvironment, BootError};
use cosmwasm_std::Empty;
use semver::Version;
use serde::Serialize;
use speculoos::prelude::*;
use std::collections::HashSet;
use crate::{
get_apis, get_apps, get_native_contracts, get_os_core_contracts, AnsHost, Manager,
ModuleFactory, OSFactory, Proxy, VersionControl,
};
pub struct Deployment<'a, Chain: BootEnvironment> {
pub chain: &'a Chain,
pub version: Version,
pub ans_host: AnsHost<Chain>,
pub version_control: VersionControl<Chain>,
pub os_factory: OSFactory<Chain>,
pub module_factory: ModuleFactory<Chain>,
}
impl<'a, Chain: BootEnvironment> Deployment<'a, Chain> {
pub fn new(chain: &'a Chain, version: Version) -> Self {
let (ans_host, os_factory, version_control, module_factory, _ibc_client) =
get_native_contracts(chain);
Self {
chain,
ans_host,
version_control,
os_factory,
module_factory,
version,
}
}
pub fn deploy(&mut self, os_core: &mut OS<Chain>) -> Result<(), BootError> {
let sender = &self.chain.sender();
self.ans_host.upload()?;
self.version_control.upload()?;
self.os_factory.upload()?;
self.module_factory.upload()?;
os_core.upload()?;
self.ans_host.instantiate(
&abstract_os::ans_host::InstantiateMsg {},
Some(sender),
None,
)?;
self.version_control.instantiate(
&abstract_os::version_control::InstantiateMsg {},
Some(sender),
None,
)?;
self.module_factory.instantiate(
&abstract_os::module_factory::InstantiateMsg {
version_control_address: self.version_control.address()?.into_string(),
ans_host_address: self.ans_host.address()?.into_string(),
},
Some(sender),
None,
)?;
self.os_factory.instantiate(
&abstract_os::os_factory::InstantiateMsg {
version_control_address: self.version_control.address()?.into_string(),
ans_host_address: self.ans_host.address()?.into_string(),
module_factory_address: self.module_factory.address()?.into_string(),
},
Some(sender),
None,
)?;
self.version_control.execute(
&abstract_os::version_control::ExecuteMsg::SetFactory {
new_factory: self.os_factory.address()?.into_string(),
},
None,
)?;
self.version_control
.register_core(os_core, &self.version.to_string())?;
self.version_control.register_native(self)?;
Ok(())
}
pub fn deploy_modules(&self) -> Result<(), BootError> {
self.upload_modules()?;
self.instantiate_apis()?;
self.register_modules()?;
Ok(())
}
pub fn contracts(&self) -> Vec<&Contract<Chain>> {
vec![
self.ans_host.as_instance(),
self.version_control.as_instance(),
self.os_factory.as_instance(),
self.module_factory.as_instance(),
]
}
fn instantiate_apis(&self) -> Result<(), BootError> {
let (dex, staking) = get_apis(self.chain);
let init_msg = abstract_os::api::InstantiateMsg {
app: Empty {},
base: abstract_os::api::BaseInstantiateMsg {
ans_host_address: self.ans_host.address()?.into(),
version_control_address: self.version_control.address()?.into(),
},
};
dex.instantiate(&init_msg, None, None)?;
staking.instantiate(&init_msg, None, None)?;
Ok(())
}
fn upload_modules(&self) -> Result<(), BootError> {
let (mut dex, mut staking) = get_apis(self.chain);
let (mut etf, mut subs) = get_apps(self.chain);
let modules: Vec<&mut dyn BootUpload<Chain>> =
vec![&mut dex, &mut staking, &mut etf, &mut subs];
modules
.into_iter()
.map(BootUpload::upload)
.collect::<Result<Vec<_>, BootError>>()?;
Ok(())
}
fn register_modules(&self) -> Result<(), BootError> {
let (dex, staking) = get_apis(self.chain);
let (etf, subs) = get_apps(self.chain);
self.version_control
.register_apps(vec![etf.as_instance(), subs.as_instance()], &self.version)?;
self.version_control.register_apis(
vec![dex.as_instance(), staking.as_instance()],
&self.version,
)?;
Ok(())
}
}
impl<'a> Deployment<'a, Daemon> {
}
pub struct OS<Chain: BootEnvironment> {
pub manager: Manager<Chain>,
pub proxy: Proxy<Chain>,
}
impl<Chain: BootEnvironment> OS<Chain> {
pub fn new(chain: &Chain, os_id: Option<u32>) -> Self {
let (manager, proxy) = get_os_core_contracts(chain, os_id);
Self { manager, proxy }
}
pub fn upload(&mut self) -> Result<(), BootError> {
self.manager.upload()?;
self.proxy.upload()?;
Ok(())
}
pub fn install_module<TInitMsg: Serialize>(
&mut self,
module_id: &str,
init_msg: &TInitMsg,
) -> Result<(), BootError> {
self.manager.install_module(module_id, init_msg)
}
pub fn expect_modules(
&self,
module_addrs: Vec<String>,
) -> Result<Vec<ManagerModuleInfo>, BootError> {
let abstract_os::manager::ModuleInfosResponse {
module_infos: manager_modules,
} = self.manager.module_infos(None, None)?;
let expected_module_addrs = module_addrs
.into_iter()
.chain(std::iter::once(self.manager.address()?.into_string()))
.collect::<HashSet<_>>();
assert_that!(manager_modules).has_length(expected_module_addrs.len());
let abstract_os::proxy::ConfigResponse {
modules: proxy_whitelist,
} = self.proxy.config()?;
let actual_proxy_whitelist = HashSet::from_iter(proxy_whitelist);
assert_eq!(actual_proxy_whitelist, expected_module_addrs);
Ok(manager_modules)
}
}