Skip to content

Commit

Permalink
Check deposit denoms at entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll committed Aug 26, 2024
1 parent 1b2fb57 commit 19a1157
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
18 changes: 11 additions & 7 deletions smart-contracts/osmosis/contracts/cl-vault/src/error.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(())
}
Expand Down
4 changes: 2 additions & 2 deletions smart-contracts/osmosis/contracts/cl-vault/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub struct PoolConfig {
}

impl PoolConfig {
pub fn pool_contains_token(&self, token: impl Into<String>) -> bool {
[&self.token0, &self.token1].contains(&&token.into())
pub fn pool_contains_token(&self, token: &str) -> bool {
self.token0 == token || self.token1 == token
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub(crate) fn execute_exact_deposit(
info: MessageInfo,
recipient: Option<String>,
) -> Result<Response, ContractError> {
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)
Expand All @@ -46,10 +46,10 @@ pub(crate) fn execute_any_deposit(
recipient: Option<String>,
max_slippage: Decimal,
) -> Result<Response, ContractError> {
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
Expand Down

0 comments on commit 19a1157

Please sign in to comment.