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
use crate::Manager;
use abstract_os::{
api::{self, InstantiateMsg},
dex::*,
objects::{AnsAsset, AssetEntry},
EXCHANGE, MANAGER,
};
use boot_core::interface::ContractInstance;
use boot_core::{prelude::boot_contract, BootEnvironment, BootError, Contract};
use cosmwasm_std::Empty;
use log::info;
#[boot_contract(InstantiateMsg, ExecuteMsg, QueryMsg, Empty)]
pub struct DexApi<Chain>;
impl<Chain: BootEnvironment> DexApi<Chain> {
pub fn new(name: &str, chain: Chain) -> Self {
Self(
Contract::new(name, chain).with_wasm_path("dex"),
)
}
pub fn swap(
&self,
offer_asset: (&str, u128),
ask_asset: &str,
dex: String,
) -> Result<(), BootError> {
let manager = Manager::new(MANAGER, self.get_chain().clone());
let asset = AssetEntry::new(offer_asset.0);
let ask_asset = AssetEntry::new(ask_asset);
let swap_msg = api::ExecuteMsg::<_>::App(api::ApiRequestMsg {
proxy_address: None,
request: DexExecuteMsg {
dex,
action: DexAction::Swap {
offer_asset: AnsAsset::new(asset, offer_asset.1),
ask_asset,
max_spread: None,
belief_price: None,
},
},
});
info!("Swap msg: {:?}", serde_json::to_string(&swap_msg)?);
manager.execute_on_module(EXCHANGE, swap_msg)?;
Ok(())
}
}