Skip to content

Commit

Permalink
Merge pull request #58 from timewave-computer/holder-adjustments
Browse files Browse the repository at this point in the history
Holder adjustments
  • Loading branch information
bekauz authored Jul 14, 2023
2 parents 4010f99 + 519315e commit ad95e81
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 310 deletions.
2 changes: 1 addition & 1 deletion contracts/clock/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, Co
.add_attribute("method", "migrate_update_tick_max_gas")
.add_attribute("tick_max_gas", new_value))
}
MigrateMsg::UpdateCodeId { data } => {
MigrateMsg::UpdateCodeId { data: _ } => {
// This is a migrate message to update code id,
// Data is optional base64 that we can parse to any data we would like in the future
// let data: SomeStruct = from_binary(&data)?;
Expand Down
58 changes: 29 additions & 29 deletions contracts/covenant/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::{
state::{
CLOCK_CODE, COVENANT_CLOCK_ADDR, COVENANT_DEPOSITOR_ADDR, COVENANT_HOLDER_ADDR,
COVENANT_LP_ADDR, COVENANT_LS_ADDR, DEPOSITOR_CODE, HOLDER_CODE, LP_CODE, LS_CODE,
PRESET_CLOCK_FIELDS, PRESET_DEPOSITOR_FIELDS, PRESET_HOLDER_FIELDS, PRESET_LP_FIELDS,
PRESET_LS_FIELDS, POOL_ADDRESS,
POOL_ADDRESS, PRESET_CLOCK_FIELDS, PRESET_DEPOSITOR_FIELDS, PRESET_HOLDER_FIELDS,
PRESET_LP_FIELDS, PRESET_LS_FIELDS,
},
};

Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn instantiate(
PRESET_HOLDER_FIELDS.save(deps.storage, &msg.preset_holder_fields)?;

POOL_ADDRESS.save(deps.storage, &msg.pool_address)?;

let clock_instantiate_tx = CosmosMsg::Wasm(WasmMsg::Instantiate {
admin: Some(env.contract.address.to_string()),
code_id: msg.preset_clock_fields.clock_code,
Expand All @@ -63,11 +63,7 @@ pub fn instantiate(
// instantiate clock first
Ok(Response::default()
.add_attribute("method", "instantiate")
.add_submessage(SubMsg::reply_always(
clock_instantiate_tx,
CLOCK_REPLY_ID,
))
)
.add_submessage(SubMsg::reply_always(clock_instantiate_tx, CLOCK_REPLY_ID)))
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down Expand Up @@ -99,18 +95,18 @@ pub fn handle_clock_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Respons
let holder_instantiate_tx = CosmosMsg::Wasm(WasmMsg::Instantiate {
admin: Some(env.contract.address.to_string()),
code_id,
msg: to_binary(&preset_holder_fields.clone().to_instantiate_msg(pool_address))?,
msg: to_binary(
&preset_holder_fields
.clone()
.to_instantiate_msg(pool_address),
)?,
funds: vec![],
label: preset_holder_fields.label,
});

Ok(Response::default()
.add_attribute("method", "handle_clock_reply")
.add_submessage(SubMsg::reply_always(
holder_instantiate_tx,
HOLDER_REPLY_ID,
))
)
.add_submessage(SubMsg::reply_always(holder_instantiate_tx, HOLDER_REPLY_ID)))
}
Err(_err) => Err(ContractError::ContractInstantiationError {
contract: "clock".to_string(),
Expand All @@ -125,15 +121,17 @@ pub fn handle_holder_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Respon
match parsed_data {
Ok(response) => {
COVENANT_HOLDER_ADDR.save(deps.storage, &response.contract_address)?;

let pool_address = POOL_ADDRESS.load(deps.storage)?;
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 instantiate_msg = preset_lp_fields
.clone()
.to_instantiate_msg(clock_addr, response.contract_address, pool_address);
let instantiate_msg = preset_lp_fields.clone().to_instantiate_msg(
clock_addr,
response.contract_address,
pool_address,
);

let lp_instantiate_tx: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Instantiate {
admin: Some(env.contract.address.to_string()),
Expand Down Expand Up @@ -167,10 +165,9 @@ pub fn handle_lp_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response,
let code_id = LS_CODE.load(deps.storage)?;
let preset_ls_fields = PRESET_LS_FIELDS.load(deps.storage)?;

let instantiate_msg = preset_ls_fields.clone().to_instantiate_msg(
clock_address,
response.contract_address,
);
let instantiate_msg = preset_ls_fields
.clone()
.to_instantiate_msg(clock_address, response.contract_address);

let ls_instantiate_tx = CosmosMsg::Wasm(WasmMsg::Instantiate {
admin: Some(env.contract.address.to_string()),
Expand All @@ -182,8 +179,7 @@ pub fn handle_lp_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response,

Ok(Response::default()
.add_attribute("method", "handle_lp_reply")
.add_submessage(SubMsg::reply_always(ls_instantiate_tx, LS_REPLY_ID)
))
.add_submessage(SubMsg::reply_always(ls_instantiate_tx, LS_REPLY_ID)))
}
Err(_err) => Err(ContractError::ContractInstantiationError {
contract: "lp".to_string(),
Expand Down Expand Up @@ -224,17 +220,19 @@ pub fn handle_ls_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response,
.add_submessage(SubMsg::reply_always(
depositor_instantiate_tx,
DEPOSITOR_REPLY_ID,
))
)
)))
}
Err(_err) => Err(ContractError::ContractInstantiationError {
contract: "ls".to_string(),
}),
}
}


pub fn handle_depositor_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractError> {
pub fn handle_depositor_reply(
deps: DepsMut,
_env: Env,
msg: Reply,
) -> Result<Response, ContractError> {
deps.api.debug("WASMDEBUG: depositor reply");

let parsed_data = parse_reply_instantiate_data(msg);
Expand All @@ -244,7 +242,9 @@ pub fn handle_depositor_reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Res

Ok(Response::default().add_attribute("method", "handle_depositor_reply"))
}
Err(_err) => Err(ContractError::ContractInstantiationError { contract: "depositor".to_string() }),
Err(_err) => Err(ContractError::ContractInstantiationError {
contract: "depositor".to_string(),
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/covenant/src/suite_test/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Default for SuiteBuilder {
},
},
preset_holder_fields: covenant_holder::msg::PresetHolderFields {
withdrawer: Some(CREATOR_ADDR.to_string()),
withdrawer: CREATOR_ADDR.to_string(),
holder_code: 1,
label: "covenant_holder_contract".to_string(),
},
Expand Down
20 changes: 6 additions & 14 deletions contracts/depositor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ fn try_tick(deps: ExecuteDeps, env: Env, info: MessageInfo) -> NeutronResult<Res
match current_state {
ContractState::Instantiated => try_register_gaia_ica(deps, env),
ContractState::ICACreated => try_liquid_stake(deps, env, info, ica_address),
ContractState::LiquidStaked => {
try_receive_atom_from_ica(deps, env, info, ica_address)
}
ContractState::LiquidStaked => try_receive_atom_from_ica(deps, env, info, ica_address),
ContractState::Complete => try_completed(deps),
}
}
Expand All @@ -132,7 +130,7 @@ fn try_liquid_stake(
};
STRIDE_ATOM_RECEIVER.update(deps.storage, |mut val| -> StdResult<_> {
val.address = stride_ica_addr.clone();
Ok(val)
Ok(val)
})?;

let fee = IbcFee {
Expand Down Expand Up @@ -499,8 +497,7 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult<Response>
LS_ADDRESS.save(deps.storage, &ls_address)?;
}

Ok(Response::default()
.add_attribute("method", "update_config"))
Ok(Response::default().add_attribute("method", "update_config"))
}
MigrateMsg::UpdateCodeId { data: _ } => {
// This is a migrate message to update code id,
Expand Down Expand Up @@ -537,9 +534,7 @@ fn sudo_open_ack(
)?;
ICA_ADDRESS.save(deps.storage, &parsed_version.address)?;
CONTRACT_STATE.save(deps.storage, &ContractState::ICACreated)?;
return Ok(Response::default()
.add_attribute("method", "sudo_open_ack")
);
return Ok(Response::default().add_attribute("method", "sudo_open_ack"));
}
Err(StdError::generic_err("Can't parse counterparty_version"))
}
Expand Down Expand Up @@ -631,9 +626,7 @@ fn sudo_response(deps: DepsMut, request: RequestPacket, data: Binary) -> StdResu
)?;
}

Ok(Response::default()
.add_attribute("method", "sudo_response")
)
Ok(Response::default().add_attribute("method", "sudo_response"))
}

fn sudo_timeout(deps: DepsMut, _env: Env, request: RequestPacket) -> StdResult<Response> {
Expand Down Expand Up @@ -686,8 +679,7 @@ fn sudo_timeout(deps: DepsMut, _env: Env, request: RequestPacket) -> StdResult<R
add_error_to_queue(deps.storage, error_msg.to_string());
}

Ok(Response::default()
.add_attribute("method", "sudo_timeout"))
Ok(Response::default().add_attribute("method", "sudo_timeout"))
}

fn sudo_error(deps: DepsMut, request: RequestPacket, details: String) -> StdResult<Response> {
Expand Down
Loading

0 comments on commit ad95e81

Please sign in to comment.