Skip to content

Commit

Permalink
Remove redundant check
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll committed Aug 9, 2024
1 parent 68ccd8f commit 5fd840c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 49 deletions.
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

0 comments on commit 5fd840c

Please sign in to comment.