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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
// use abstract_core::ans_host::AssetsResponse;
// use abstract_core::objects::pool_id::PoolAddressBase;
// use abstract_core::objects::PoolMetadata;
// use cosmwasm_std::coins;
// use cosmwasm_std::Timestamp;
// use cosmwasm_std::Uint128;
// use cw_orch::daemon::queriers::Node;
// use cw_orch_daemon::DaemonQuerier;
// use tokio::runtime::Runtime;
// use abstract_core::adapter::AuthorizedAddressesResponse;
// use abstract_core::adapter::BaseQueryMsg;
// use cw_multi_test::wasm_emulation::storage::analyzer::StorageAnalyzer;
// use abstract_core::adapter::AdapterRequestMsg;
// use abstract_core::adapter::BaseInstantiateMsg;
// use abstract_core::objects::module::Module;
// use abstract_core::objects::module_reference::ModuleReference;
// use abstract_core::objects::AnsAsset;
// use abstract_core::objects::AssetEntry;
// use abstract_dex_adapter::msg::InstantiateMsg;
// use abstract_dex_adapter::msg::{DexAction, DexExecuteMsg, DexInstantiateMsg};
// use cosmwasm_std::Decimal;
// use cw_multi_test::wasm_emulation::contract::WasmContract;
// use cw_orch_daemon::CosmWasm;
// use std::path::Path;
// use cw_asset::AssetInfo;
// use abstract_core::version_control::{self};
// use abstract_core::objects::module::ModuleInfo;
// use abstract_core::objects::module::ModuleVersion;
// use cosmwasm_std::{to_json_binary, Addr};
// use cw_multi_test::AppBuilder;
// use cw_multi_test::BankKeeper;
// use cw_multi_test::Executor;
// use cw_multi_test::FailingModule;
// use abstract_interface::get_account_contracts;
// use abstract_interface::Abstract;
// use abstract_interface::ManagerQueryFns;
// use cosmwasm_std::Empty;
// use cw_multi_test::WasmKeeper;
// use cw_orch::daemon::Daemon;
// use cw_orch::deploy::Deploy;
// use cw_orch_daemon::prelude::ContractInstance;
// use dotenv::dotenv;
// use abstract_core::manager::ExecuteMsg;
// // Abstract patch
// #[cosmwasm_schema::cw_serde]
// pub struct ModulesResponse {
// pub modules: Vec<Module>,
// }
// fn main() {
// dotenv().ok();
// let runtime = tokio::runtime::Runtime::new().unwrap();
// let mut chain = cw_orch::daemon::networks::JUNO_1;
// chain.grpc_urls = &["http://juno-grpc.polkachu.com:12690"];
// let daemon = Daemon::builder()
// .chain(chain.clone())
// .handle(runtime.handle())
// .build()
// .unwrap();
// let abstract_ = Abstract::load_from(daemon.clone()).unwrap();
// // Query an account, its owner and install a module for
// let (manager, proxy) = get_account_contracts(&abstract_.version_control, Some(1));
// let ownership = manager.ownership().unwrap();
// let owner = ownership.owner.unwrap();
// // We use this owner to install and uninstall a module
// let owner_addr = Addr::unchecked(owner.clone());
// env_logger::init();
// let mut wasm = WasmKeeper::<Empty, Empty>::new();
// wasm.set_chain(chain.clone().into());
// let mut bank = BankKeeper::new();
// bank.set_chain(chain.clone().into());
// let node_querier = daemon.query_client::<Node>();
// let block = runtime.block_on(node_querier.latest_block()).unwrap();
// // First we instantiate a new app
// let app = AppBuilder::default()
// .with_wasm::<FailingModule<Empty, Empty, Empty>, _>(wasm)
// .with_bank(bank)
// .with_block(cosmwasm_std::BlockInfo {
// height: block.header.height.into(),
// time: Timestamp::from_seconds(block.header.time.unix_timestamp().try_into().unwrap()),
// chain_id: block.header.chain_id.to_string(),
// });
// let mut app = app.build(|_, _, _| {});
// log::info!("Built App Environment");
// // We need to register a pool pairing on the ans host
// app.execute_contract(
// Addr::unchecked(owner.clone()),
// abstract_.ans_host.address().unwrap(),
// &abstract_core::ans_host::ExecuteMsg::UpdateDexes {
// to_add: vec!["wyndex".to_string()],
// to_remove: vec![],
// },
// &[],
// )
// .unwrap();
// app.execute_contract(
// Addr::unchecked(owner.clone()),
// abstract_.ans_host.address().unwrap(),
// &abstract_core::ans_host::ExecuteMsg::UpdatePools {
// to_add: vec![(
// PoolAddressBase::contract(
// "juno1gqy6rzary8vwnslmdavqre6jdhakcd4n2z4r803ajjmdq08r66hq7zcwrj".to_string(),
// ),
// PoolMetadata {
// dex: "wyndex".to_string(),
// pool_type: abstract_core::objects::PoolType::ConstantProduct,
// assets: vec!["axelar>usdc".into(), "juno>juno".into()],
// },
// )],
// to_remove: vec![],
// },
// &[],
// )
// .unwrap();
// // End registering the pool pairing
// // test
// let rt = Runtime::new().unwrap();
// let test = rt
// .block_on(
// CosmWasm::new(daemon.channel()).contract_raw_state(
// "juno13q8rv8w9ew5cn6wecr2p4scegzu9nac0hv2dx807l4vz60h0ldns0ksvz0",
// hex::decode(
// "0008706f6f6c5f69647300096a756e6f3e6a756e6f00096a756e6f3e77796e6477796e646578",
// )
// .unwrap(),
// ),
// )
// .unwrap();
// log::info!("{:x?}", test);
// // We deploy the adapter :
// // 1. upload the code
// let code = std::fs::read(
// Path::new(env!("CARGO_MANIFEST_DIR"))
// .join("artifacts")
// .join("abstract_dex_adapter-juno.wasm"),
// )
// .unwrap();
// let dex_code = WasmContract::new_local(code, chain.clone());
// let code_id = app.store_code(dex_code);
// // 2. Instantiate the code
// let dex_addr = app
// .instantiate_contract(
// code_id,
// owner_addr.clone(),
// &InstantiateMsg {
// module: DexInstantiateMsg {
// swap_fee: Decimal::percent(1),
// recipient_account: 0,
// },
// base: BaseInstantiateMsg {
// ans_host_address: abstract_.ans_host.address().unwrap().to_string(),
// version_control_address: abstract_
// .version_control
// .address()
// .unwrap()
// .to_string(),
// },
// },
// &[],
// "Dex adapter",
// None,
// )
// .unwrap();
// log::info!("Instantiated Dex adapter");
// // 3. Register the adapter in version control
// let module =
// ModuleInfo::from_id("abstract:dex", ModuleVersion::Version("0.17.1".to_string())).unwrap();
// app.execute_contract(
// owner_addr.clone(),
// abstract_.version_control.address().unwrap(),
// &version_control::ExecuteMsg::ProposeModules {
// modules: vec![(module.clone(), ModuleReference::Adapter(dex_addr.clone()))],
// },
// &[],
// )
// .unwrap();
// log::info!("Proposed and registered Dex adapter");
// // We install the module on the account
// app.execute_contract(
// Addr::unchecked(owner.clone()),
// manager.address().unwrap(),
// &ExecuteMsg::InstallModule {
// init_msg: Some(to_json_binary(&Empty {}).unwrap()),
// module,
// },
// &[],
// )
// .unwrap();
// log::info!("Installed Dex adapter");
// // Let's see what registered in the ans as assets
// /*
// let assets = abstract_.ans_host.asset_list(None, Some(30), Some("juno>future".to_string())).unwrap();
// log::info!("{:?}", assets);
// let pools = abstract_.ans_host.pool_list(None, Some(30), None).unwrap();
// log::info!("{:?}", pools);
// */
// // We need to get the authorized addresses on the adapter
// /*
// app.execute_contract(Addr::unchecked(owner.clone()), manager.address().unwrap(),&ExecuteMsg::ExecOnModule { module_id: "abstract:dex".to_string(),
// exec_msg: to_json_binary(&abstract_dex_adapter::msg::ExecuteMsg::Base(
// abstract_core::adapter::BaseExecuteMsg::UpdateAuthorizedAddresses {
// to_add: vec![manager.address().unwrap().to_string()],
// to_remove: vec![]
// }
// )).unwrap()}, &[]).unwrap();
// */
// log::info!("Updated authorized address on the Dex adapter");
// /* Query to verify that the manager was authorized to execute on the adapter */
// let addresses: AuthorizedAddressesResponse = app
// .wrap()
// .query_wasm_smart(
// dex_addr,
// &abstract_dex_adapter::msg::QueryMsg::Base(BaseQueryMsg::AuthorizedAddresses {
// proxy_address: proxy.address().unwrap().to_string(),
// }),
// )
// .unwrap();
// log::info!("AuthorizedAddresses on dex {:?}", addresses);
// let analysis = StorageAnalyzer::new(&app).unwrap();
// analysis.compare_all_readable_contract_storage(chain.into());
// //log::info!("analysis, dex {:x?}", analysis.get_contract_storage(dex_addr));
// /* End query */
// log::info!("Some queries to check everything is alright");
// // We deposit funds on the proxy
// app.execute(
// owner_addr,
// cosmwasm_std::CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
// to_address: proxy.address().unwrap().to_string(),
// amount: coins(100_000u128, "ujuno"),
// }),
// )
// .unwrap();
// // We get the balances (for asserting)
// let usdc: AssetsResponse = app
// .wrap()
// .query_wasm_smart(
// abstract_.ans_host.address().unwrap(),
// &abstract_core::ans_host::QueryMsg::Assets {
// names: vec!["axelar>usdc".to_string()],
// },
// )
// .unwrap();
// let usdc = match &usdc.assets[0].1 {
// AssetInfo::Native(denom) => denom,
// _ => panic!("Expected native denom"),
// };
// let old_balance = app
// .wrap()
// .query_balance(proxy.address().unwrap(), "ujuno")
// .unwrap();
// let old_usdc_balance = app
// .wrap()
// .query_balance(proxy.address().unwrap(), usdc)
// .unwrap();
// // We test a swap interaction
// app.execute_contract(
// Addr::unchecked(owner),
// manager.address().unwrap(),
// &ExecuteMsg::ExecOnModule {
// module_id: "abstract:dex".to_string(),
// exec_msg: to_json_binary(&abstract_dex_adapter::msg::ExecuteMsg::Module(
// AdapterRequestMsg {
// proxy_address: None,
// request: DexExecuteMsg::Action {
// action: DexAction::Swap {
// ask_asset: AssetEntry::new("axelar>usdc"),
// offer_asset: AnsAsset::new(AssetEntry::new("juno>juno"), 100_000u128),
// belief_price: None,
// max_spread: None,
// },
// dex: "wyndex".to_string(),
// },
// },
// ))
// .unwrap(),
// },
// &[],
// )
// .unwrap();
// log::info!("Execute the swap");
// // We get the juno balance (should be lower)
// let new_balance = app
// .wrap()
// .query_balance(proxy.address().unwrap(), "ujuno")
// .unwrap();
// assert_eq!(
// old_balance.amount - new_balance.amount,
// Uint128::from(100_000u128)
// );
// let new_usdc_balance = app
// .wrap()
// .query_balance(proxy.address().unwrap(), usdc)
// .unwrap();
// assert!(old_usdc_balance.amount < new_usdc_balance.amount);
// }