From b1d9afedca8e70185695b1741cabdaf12aed15a5 Mon Sep 17 00:00:00 2001 From: magiodev <31893902+magiodev@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:58:30 +0200 Subject: [PATCH] fix position id not found --- .../contracts/cl-vault/src/vault/deposit.rs | 3 ++- .../contracts/cl-vault/src/vault/range.rs | 16 +++++++++------- .../contracts/cl-vault/src/vault/swap.rs | 17 +++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/vault/deposit.rs b/smart-contracts/osmosis/contracts/cl-vault/src/vault/deposit.rs index 9bf727363..092cdb9c3 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/vault/deposit.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/vault/deposit.rs @@ -81,8 +81,9 @@ pub(crate) fn execute_any_deposit( let (token_in, swap_direction, left_over_amount) = calculate_token_in_direction( &pool_config, pool_details, - position, (deposit_info.base_refund, deposit_info.quote_refund), + position.lower_tick, + position.upper_tick, )?; CURRENT_SWAP_ANY_DEPOSIT.save( diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs b/smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs index 72648525b..6b0b191fe 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs @@ -294,14 +294,14 @@ pub fn do_swap_deposit_merge( let pool_config = POOL_CONFIG.load(deps.storage)?; let pool_details = get_cl_pool_info(&deps.querier, pool_config.pool_id)?; - let position = get_position(deps.storage, &deps.querier)? - .position - .ok_or(ContractError::MissingPosition {})?; - - let mrs = MODIFY_RANGE_STATE.load(deps.storage)?.unwrap(); - let (token_in, swap_direction, _left_over_amount) = - calculate_token_in_direction(&pool_config, pool_details, position, tokens_provided)?; + let (token_in, swap_direction, _left_over_amount) = calculate_token_in_direction( + &pool_config, + pool_details, + tokens_provided, + target_lower_tick, + target_upper_tick, + )?; let twap_price = get_twap_price( &deps.querier, @@ -312,6 +312,8 @@ pub fn do_swap_deposit_merge( pool_config.clone().token1, )?; + // Calculate the swap amount using the modify_range_state + let mrs = MODIFY_RANGE_STATE.load(deps.storage)?.unwrap(); let calculate_swap_amount = calculate_swap_amount( &deps, &env, diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs b/smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs index 2da51032f..8f55ea685 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{Coin, CosmosMsg, Decimal, DepsMut, Env, Fraction, Response, Uint128}; -use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::{Pool, Position as OsmoPosition}; +use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::Pool; use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute; use crate::helpers::getters::{ @@ -145,12 +145,13 @@ pub fn execute_swap_non_vault_funds( pub fn calculate_token_in_direction( pool_config: &PoolConfig, pool_details: Pool, - position: OsmoPosition, tokens_provided: (Uint128, Uint128), + lower_tick: i64, + upper_tick: i64, ) -> Result<(Coin, SwapDirection, Uint128), ContractError> { if !tokens_provided.0.is_zero() { // range is above current tick - let token_in = if pool_details.current_tick > position.upper_tick { + let token_in = if pool_details.current_tick > upper_tick { Coin { denom: pool_config.token0.clone(), amount: tokens_provided.0, @@ -160,9 +161,9 @@ pub fn calculate_token_in_direction( denom: pool_config.token0.clone(), amount: get_single_sided_deposit_0_to_1_swap_amount( tokens_provided.0, - position.lower_tick, + lower_tick, pool_details.current_tick, - position.upper_tick, + upper_tick, )?, } }; @@ -170,7 +171,7 @@ pub fn calculate_token_in_direction( Ok((token_in, SwapDirection::ZeroToOne, left_over_amount)) } else { // current tick is above range - let token_in = if pool_details.current_tick < position.lower_tick { + let token_in = if pool_details.current_tick < lower_tick { Coin { denom: pool_config.token1.clone(), amount: tokens_provided.1, @@ -180,9 +181,9 @@ pub fn calculate_token_in_direction( denom: pool_config.token1.clone(), amount: get_single_sided_deposit_1_to_0_swap_amount( tokens_provided.1, - position.lower_tick, + lower_tick, pool_details.current_tick, - position.upper_tick, + upper_tick, )?, } };