diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/error.rs b/smart-contracts/osmosis/contracts/cl-vault/src/error.rs index 4b85ba0a9..281a6efea 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/error.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/error.rs @@ -1,4 +1,4 @@ -use crate::state::{ADMIN_ADDRESS, RANGE_ADMIN, VAULT_CONFIG}; +use crate::state::{PoolConfig, ADMIN_ADDRESS, RANGE_ADMIN, VAULT_CONFIG}; use cosmwasm_std::{ Addr, CheckedFromRatioError, CheckedMultiplyFractionError, CheckedMultiplyRatioError, Coin, CoinFromStrError, ConversionOverflowError, Decimal, Decimal256, Decimal256RangeExceeded, @@ -21,11 +21,11 @@ pub enum ContractError { #[error("Pool-id {pool_id} not found")] PoolNotFound { pool_id: u64 }, - #[error("Position Not Found")] + #[error("Position not found")] PositionNotFound, - #[error("Sent the wrong amount of denoms")] - IncorrectAmountFunds, + #[error("Incorrect deposit funds")] + IncorrectDepositFunds, #[error("ratio_of_swappable_funds_to_use should be >0 and <=1")] InvalidRatioOfSwappableFundsToUse, @@ -160,9 +160,13 @@ pub enum ContractError { TryFromIntError(#[from] TryFromIntError), } -pub fn assert_deposits(funds: &[Coin]) -> Result<(), ContractError> { - if funds.len() != 2 && funds.len() != 1 { - return Err(ContractError::IncorrectAmountFunds); +pub fn assert_deposits(funds: &[Coin], config: &PoolConfig) -> Result<(), ContractError> { + if (funds.len() != 2 && funds.len() != 1) + || funds + .iter() + .any(|deposit| !config.pool_contains_token(&deposit.denom)) + { + return Err(ContractError::IncorrectDepositFunds); } Ok(()) } diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/state.rs b/smart-contracts/osmosis/contracts/cl-vault/src/state.rs index 1b55e6c78..1d9ec32b9 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/state.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/state.rs @@ -39,8 +39,8 @@ pub struct PoolConfig { } impl PoolConfig { - pub fn pool_contains_token(&self, token: impl Into) -> bool { - [&self.token0, &self.token1].contains(&&token.into()) + pub fn pool_contains_token(&self, token: &str) -> bool { + self.token0 == token || self.token1 == token } } diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/vault/autocompound.rs b/smart-contracts/osmosis/contracts/cl-vault/src/vault/autocompound.rs index daf80aa0e..beddf70a1 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/vault/autocompound.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/vault/autocompound.rs @@ -4,7 +4,6 @@ use cosmwasm_std::{ use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::ConcentratedliquidityQuerier; use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgCreatePositionResponse; -use crate::helpers::coinlist::CoinList; use crate::helpers::getters::get_unused_pair_balances; use crate::msg::{ExecuteMsg, MergePositionMsg}; use crate::reply::Replies; 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 e9f0d4724..d14e8e398 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/vault/deposit.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/vault/deposit.rs @@ -31,9 +31,9 @@ pub(crate) fn execute_exact_deposit( info: MessageInfo, recipient: Option, ) -> Result { - assert_deposits(&info.funds)?; - let recipient = recipient.map_or(Ok(info.sender.clone()), |x| deps.api.addr_validate(&x))?; let pool_config = POOL_CONFIG.load(deps.storage)?; + assert_deposits(&info.funds, &pool_config)?; + let recipient = recipient.map_or(Ok(info.sender.clone()), |x| deps.api.addr_validate(&x))?; let deposit_info = get_depositable_tokens(&deps, &info.funds, &pool_config)?; execute_deposit(&mut deps, env, recipient, deposit_info) @@ -46,10 +46,10 @@ pub(crate) fn execute_any_deposit( recipient: Option, max_slippage: Decimal, ) -> Result { - assert_deposits(&info.funds)?; + let pool_config = POOL_CONFIG.load(deps.storage)?; + assert_deposits(&info.funds, &pool_config)?; let recipient = recipient.map_or(Ok(info.sender.clone()), |x| deps.api.addr_validate(&x))?; - 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