Skip to content

Commit

Permalink
Move handle_merge_reply into autocompound.rs (#785)
Browse files Browse the repository at this point in the history
.. as that is the place where the corresponding SubMsg is created
  • Loading branch information
lubkoll authored Aug 19, 2024
1 parent e8f005e commit 0e90d25
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 50 deletions.
40 changes: 20 additions & 20 deletions smart-contracts/osmosis/contracts/cl-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ use crate::query::{
use crate::reply::Replies;
#[allow(deprecated)]
use crate::state::{MigrationStatus, MIGRATION_STATUS};
use crate::vault::admin::execute_admin;
use crate::vault::autocompound::{
execute_autocompound, execute_migration_step, handle_autocompound_reply,
use crate::vault::{
admin::execute_admin,
autocompound::{
execute_autocompound, execute_migration_step, handle_autocompound_reply, handle_merge_reply,
},
deposit::{execute_any_deposit, execute_exact_deposit, handle_any_deposit_swap_reply},
distribution::{
execute_collect_rewards, handle_collect_incentives_reply,
handle_collect_spread_rewards_reply,
},
merge::{
execute_merge_position, handle_merge_create_position_reply,
handle_merge_withdraw_position_reply,
},
range::{
execute_update_range, handle_initial_create_position_reply,
handle_iteration_create_position_reply, handle_swap_reply, handle_withdraw_position_reply,
},
swap::execute_swap_non_vault_funds,
withdraw::{execute_withdraw, handle_withdraw_user_reply},
};
use crate::vault::deposit::{
execute_any_deposit, execute_exact_deposit, handle_any_deposit_swap_reply,
};
use crate::vault::distribution::{
execute_collect_rewards, handle_collect_incentives_reply, handle_collect_spread_rewards_reply,
};
use crate::vault::merge::{
execute_merge_position, handle_merge_create_position_reply,
handle_merge_withdraw_position_reply,
};
use crate::vault::range::{
execute_update_range, handle_initial_create_position_reply,
handle_iteration_create_position_reply, handle_merge_reply, handle_swap_reply,
handle_withdraw_position_reply,
};
use crate::vault::swap::execute_swap_non_vault_funds;
use crate::vault::withdraw::{execute_withdraw, handle_withdraw_user_reply};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::msg::{ExecuteMsg, MergePositionMsg};
use crate::reply::Replies;
#[allow(deprecated)]
use crate::state::USER_REWARDS;
use crate::state::{MigrationStatus, MIGRATION_STATUS, POOL_CONFIG, POSITION};
use crate::vault::concentrated_liquidity::create_position;
use crate::state::{MigrationStatus, Position, MIGRATION_STATUS, POOL_CONFIG, POSITION};
use crate::vault::{concentrated_liquidity::create_position, merge::MergeResponse};
use crate::ContractError;

pub fn execute_autocompound(
Expand Down Expand Up @@ -109,6 +109,30 @@ pub fn handle_autocompound_reply(
))
}

pub fn handle_merge_reply(
deps: DepsMut,
env: Env,
data: SubMsgResult,
) -> Result<Response, ContractError> {
let merge_response: MergeResponse = data.try_into()?;

let position = POSITION.load(deps.storage)?;
POSITION.save(
deps.storage,
&Position {
position_id: merge_response.new_position_id,
join_time: env.block.time.seconds(),
claim_after: position.claim_after,
},
)?;

Ok(Response::new()
.add_attribute("method", "reply")
.add_attribute("action", "handle_merge_reply")
.add_attribute("swap_deposit_merge_status", "success")
.add_attribute("status", "success"))
}

// Migration is a to-depreacate entrypoint useful to migrate from Distribute to Accumulate after Autocompound implementation
pub fn execute_migration_step(
deps: DepsMut,
Expand Down
28 changes: 0 additions & 28 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
},
vault::{
concentrated_liquidity::{create_position, get_cl_pool_info, get_position},
merge::MergeResponse,
swap::{estimate_swap_min_out_amount, swap_msg},
},
ContractError,
Expand Down Expand Up @@ -391,33 +390,6 @@ pub fn handle_iteration_create_position_reply(
))
}

// store new position id and exit
pub fn handle_merge_reply(
deps: DepsMut,
env: Env,
data: SubMsgResult,
) -> Result<Response, ContractError> {
let merge_response: MergeResponse = data.try_into()?;

// Load the current Position to extract join_time and claim_after which is unchangeable in this context
let position = POSITION.load(deps.storage)?;

POSITION.save(
deps.storage,
&Position {
position_id: merge_response.new_position_id,
join_time: env.block.time.seconds(),
claim_after: position.claim_after,
},
)?;

Ok(Response::new()
.add_attribute("method", "reply")
.add_attribute("action", "handle_merge_reply")
.add_attribute("swap_deposit_merge_status", "success")
.add_attribute("status", "success"))
}

#[cfg(test)]
mod tests {
use std::str::FromStr;
Expand Down

0 comments on commit 0e90d25

Please sign in to comment.