Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant check #762

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion smart-contracts/osmosis/contracts/cl-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
Replies::RangeIterationCreatePosition => {
handle_iteration_create_position_reply(deps, env, msg.result)
}
Replies::Swap => handle_swap_reply(deps, env, msg.result),
Replies::Swap => handle_swap_reply(deps, env),
Replies::Merge => handle_merge_reply(deps, env, msg.result),
Replies::CreateDenom => handle_create_denom_reply(deps, msg.result),
Replies::WithdrawUser => handle_withdraw_user_reply(deps, msg.result),
Expand Down
87 changes: 39 additions & 48 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,54 +343,45 @@ fn do_swap_deposit_merge(
}

// do deposit
pub fn handle_swap_reply(
deps: DepsMut,
env: Env,
data: SubMsgResult,
) -> Result<Response, ContractError> {
match data.clone() {
SubMsgResult::Ok(_) => {
let swap_deposit_merge_state = SWAP_DEPOSIT_MERGE_STATE.load(deps.storage)?;

let pool_config = POOL_CONFIG.load(deps.storage)?;
let unused_pair_balances = get_unused_pair_balances(&deps, &env, &pool_config)?;

let create_position_msg = create_position(
deps,
&env,
swap_deposit_merge_state.target_lower_tick,
swap_deposit_merge_state.target_upper_tick,
unused_pair_balances.clone(),
Uint128::zero(),
Uint128::zero(),
)?;

Ok(Response::new()
.add_submessage(SubMsg::reply_on_success(
create_position_msg,
Replies::RangeIterationCreatePosition.into(),
))
.add_attribute("method", "reply")
.add_attribute("action", "handle_swap_success")
.add_attribute(
"lower_tick",
swap_deposit_merge_state.target_lower_tick.to_string(),
)
.add_attribute(
"upper_tick",
swap_deposit_merge_state.target_upper_tick.to_string(),
)
.add_attribute(
"token0",
format!("{:?}{:?}", unused_pair_balances[0], pool_config.token0),
)
.add_attribute(
"token1",
format!("{:?}{:?}", unused_pair_balances[1], pool_config.token1),
))
}
SubMsgResult::Err(msg) => Err(ContractError::SwapFailed { message: msg }),
}
pub fn handle_swap_reply(deps: DepsMut, env: Env) -> Result<Response, ContractError> {
let swap_deposit_merge_state = SWAP_DEPOSIT_MERGE_STATE.load(deps.storage)?;

let pool_config = POOL_CONFIG.load(deps.storage)?;
let unused_pair_balances = get_unused_pair_balances(&deps, &env, &pool_config)?;

let create_position_msg = create_position(
deps,
&env,
swap_deposit_merge_state.target_lower_tick,
swap_deposit_merge_state.target_upper_tick,
unused_pair_balances.clone(),
Uint128::zero(),
Uint128::zero(),
)?;

Ok(Response::new()
.add_submessage(SubMsg::reply_on_success(
create_position_msg,
Replies::RangeIterationCreatePosition.into(),
))
.add_attribute("method", "reply")
.add_attribute("action", "handle_swap_success")
.add_attribute(
"lower_tick",
swap_deposit_merge_state.target_lower_tick.to_string(),
)
.add_attribute(
"upper_tick",
swap_deposit_merge_state.target_upper_tick.to_string(),
)
.add_attribute(
"token0",
format!("{:?}{:?}", unused_pair_balances[0], pool_config.token0),
)
.add_attribute(
"token1",
format!("{:?}{:?}", unused_pair_balances[1], pool_config.token1),
))
}

// do merge position & exit
Expand Down
Loading