Skip to content

Commit

Permalink
Merge pull request #78 from timewave-computer/art3mix/depositor-combi…
Browse files Browse the repository at this point in the history
…ne-msgs

depositor reaching completion
  • Loading branch information
bekauz authored Jul 23, 2023
2 parents da6aa15 + a4e6519 commit e6e3482
Show file tree
Hide file tree
Showing 20 changed files with 871 additions and 268 deletions.
1 change: 1 addition & 0 deletions contracts/covenant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ covenant-holder = { workspace = true, features=["library"] }
cw-multi-test = { workspace = true }
anyhow = { workspace = true }
astroport = { workspace = true }
prost = "0.11.9"
40 changes: 23 additions & 17 deletions contracts/covenant/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult,
SubMsg, WasmMsg,
SubMsg, WasmMsg, Uint128,
};

use cw2::set_contract_version;
Expand All @@ -13,21 +13,20 @@ use crate::{
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
state::{
CLOCK_CODE, COVENANT_CLOCK_ADDR, COVENANT_DEPOSITOR_ADDR, COVENANT_HOLDER_ADDR,
COVENANT_LP_ADDR, COVENANT_LS_ADDR, DEPOSITOR_CODE, HOLDER_CODE, IBC_FEE, IBC_TIMEOUT,
COVENANT_LP_ADDR, COVENANT_LS_ADDR, DEPOSITOR_CODE, HOLDER_CODE, IBC_FEE,
LP_CODE, LS_CODE, POOL_ADDRESS, PRESET_CLOCK_FIELDS, PRESET_DEPOSITOR_FIELDS,
PRESET_HOLDER_FIELDS, PRESET_LP_FIELDS, PRESET_LS_FIELDS, TIMEOUTS,
},
};

const CONTRACT_NAME: &str = "crates.io:covenant-covenant";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
const DEFAULT_TIMEOUT_SECONDS: u64 = 60 * 60 * 24 * 7 * 2;

const CLOCK_REPLY_ID: u64 = 1u64;
const HOLDER_REPLY_ID: u64 = 2u64;
const LP_REPLY_ID: u64 = 3u64;
const LS_REPLY_ID: u64 = 4u64;
const DEPOSITOR_REPLY_ID: u64 = 5u64;
pub(crate) const CLOCK_REPLY_ID: u64 = 1u64;
pub(crate) const HOLDER_REPLY_ID: u64 = 2u64;
pub(crate) const LP_REPLY_ID: u64 = 3u64;
pub(crate) const LS_REPLY_ID: u64 = 4u64;
pub(crate) const DEPOSITOR_REPLY_ID: u64 = 5u64;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
Expand Down Expand Up @@ -118,8 +117,9 @@ pub fn handle_clock_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Respons
.add_attribute("method", "handle_clock_reply")
.add_submessage(SubMsg::reply_always(holder_instantiate_tx, HOLDER_REPLY_ID)))
}
Err(_err) => Err(ContractError::ContractInstantiationError {
Err(err) => Err(ContractError::ContractInstantiationError {
contract: "clock".to_string(),
err,
}),
}
}
Expand All @@ -139,11 +139,13 @@ pub fn handle_holder_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Respon
let code_id = LP_CODE.load(deps.storage)?;
let clock_addr = COVENANT_CLOCK_ADDR.load(deps.storage)?;
let preset_lp_fields = PRESET_LP_FIELDS.load(deps.storage)?;
let preset_depositor_fields = PRESET_DEPOSITOR_FIELDS.load(deps.storage)?;

let instantiate_msg = preset_lp_fields.clone().to_instantiate_msg(
clock_addr.to_string(),
response.contract_address,
pool_address,
preset_depositor_fields.atom_receiver_amount.amount,
);

let lp_instantiate_tx: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Instantiate {
Expand All @@ -158,8 +160,9 @@ pub fn handle_holder_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Respon
.add_attribute("method", "handle_holder_reply")
.add_submessage(SubMsg::reply_always(lp_instantiate_tx, LP_REPLY_ID)))
}
Err(_err) => Err(ContractError::ContractInstantiationError {
Err(err) => Err(ContractError::ContractInstantiationError {
contract: "holder".to_string(),
err,
}),
}
}
Expand Down Expand Up @@ -203,8 +206,9 @@ pub fn handle_lp_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response,
.add_attribute("method", "handle_lp_reply")
.add_submessage(SubMsg::reply_always(ls_instantiate_tx, LS_REPLY_ID)))
}
Err(_err) => Err(ContractError::ContractInstantiationError {
Err(err) => Err(ContractError::ContractInstantiationError {
contract: "lp".to_string(),
err,
}),
}
}
Expand Down Expand Up @@ -252,8 +256,9 @@ pub fn handle_ls_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response,
DEPOSITOR_REPLY_ID,
)))
}
Err(_err) => Err(ContractError::ContractInstantiationError {
Err(err) => Err(ContractError::ContractInstantiationError {
contract: "ls".to_string(),
err,
}),
}
}
Expand All @@ -279,26 +284,27 @@ pub fn handle_depositor_reply(
let clock_code_id = CLOCK_CODE.load(deps.storage)?;
let lp_addr = COVENANT_LP_ADDR.load(deps.storage)?;
let ls_addr = COVENANT_LS_ADDR.load(deps.storage)?;

let migrate_msg = WasmMsg::Migrate {
let update_clock_whitelist_msg = WasmMsg::Migrate {
contract_addr: clock_addr.to_string(),
new_code_id: clock_code_id,
msg: to_binary(&covenant_clock::msg::MigrateMsg::ManageWhitelist {
add: Some(vec![
lp_addr.to_string(),
ls_addr.to_string(),
response.contract_address, //depositor
response.contract_address.clone(), //depositor
]),
remove: None,
})?,
};

Ok(Response::default()
.add_message(migrate_msg)
.add_message(update_clock_whitelist_msg)
.add_attribute("method", "handle_depositor_reply"))
}
Err(_err) => Err(ContractError::ContractInstantiationError {
Err(err) => Err(ContractError::ContractInstantiationError {
contract: "depositor".to_string(),
err,
}),
}
}
Expand Down
6 changes: 5 additions & 1 deletion contracts/covenant/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cosmwasm_std::StdError;
use cw_utils::ParseReplyError;
use thiserror::Error;

#[derive(Error, Debug)]
Expand All @@ -19,5 +20,8 @@ pub enum ContractError {
ReplyError { err: String },

#[error("Failed to instantiate {contract:?} contract")]
ContractInstantiationError { contract: String },
ContractInstantiationError {
contract: String,
err: ParseReplyError,
},
}
1 change: 0 additions & 1 deletion contracts/covenant/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub struct InstantiateMsg {
pub preset_lp_fields: PresetLpFields,
pub preset_holder_fields: PresetHolderFields,
pub pool_address: String,
pub ibc_msg_transfer_timeout_timestamp: Option<u64>,
pub preset_ibc_fee: PresetIbcFee,
pub timeouts: Timeouts,
}
Expand Down
1 change: 1 addition & 0 deletions contracts/covenant/src/suite_test/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod suite;
mod tests;
mod unit_tests;
7 changes: 3 additions & 4 deletions contracts/covenant/src/suite_test/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::msg::{InstantiateMsg, QueryMsg, PresetIbcFee, Timeouts};

pub const CREATOR_ADDR: &str = "admin";
pub const TODO: &str = "replace";
pub const NEUTRON_DENOM: &str = "untrn";

fn covenant_clock() -> Box<dyn Contract<Empty>> {
Box::new(
Expand Down Expand Up @@ -73,12 +72,13 @@ impl Default for SuiteBuilder {
depositor_code: 1,
label: "covenant_depositor_contract".to_string(),
st_atom_receiver_amount: covenant_depositor::msg::WeightedReceiverAmount {
amount: 1,
amount: Uint128::one(),
},
atom_receiver_amount: covenant_depositor::msg::WeightedReceiverAmount {
amount: 1,
amount: Uint128::one(),
},
autopilot_format: "{{\"autopilot\": {{\"receiver\": \"{st_ica}\",\"stakeibc\": {{\"stride_address\": \"{st_ica}\",\"action\": \"LiquidStake\"}}}}}}".to_string(),
neutron_atom_ibc_denom: "neutron_atom_ibc_denom".to_string(),
},
preset_lp_fields: covenant_lp::msg::PresetLpFields {
slippage_tolerance: None,
Expand All @@ -101,7 +101,6 @@ impl Default for SuiteBuilder {
},
label: "covenant_contract".to_string(),
pool_address: TODO.to_string(),
ibc_msg_transfer_timeout_timestamp: None,
preset_ibc_fee: PresetIbcFee {
ack_fee: Uint128::new(1000),
timeout_fee: Uint128::new(1000),
Expand Down
Loading

0 comments on commit e6e3482

Please sign in to comment.