Skip to content

Commit

Permalink
fix position id not found
Browse files Browse the repository at this point in the history
  • Loading branch information
magiodev committed Jul 30, 2024
1 parent 57265ce commit b1d9afe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 9 additions & 7 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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,
Expand All @@ -160,17 +161,17 @@ 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,
)?,
}
};
let left_over_amount = tokens_provided.0.checked_sub(token_in.amount)?;
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,
Expand All @@ -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,
)?,
}
};
Expand Down

0 comments on commit b1d9afe

Please sign in to comment.