Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for deposit funds length at entry_point #810

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions smart-contracts/osmosis/contracts/cl-vault/schema/cl-vault.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,28 +518,6 @@
},
"additionalProperties": false
},
{
"description": "MigrationStep",
"type": "object",
"required": [
"migration_step"
],
"properties": {
"migration_step": {
"type": "object",
"required": [
"amount_of_users"
],
"properties": {
"amount_of_users": {
"$ref": "#/definitions/Uint128"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "SwapNonVaultFunds",
"type": "object",
Expand Down
22 changes: 0 additions & 22 deletions smart-contracts/osmosis/contracts/cl-vault/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,28 +415,6 @@
},
"additionalProperties": false
},
{
"description": "MigrationStep",
"type": "object",
"required": [
"migration_step"
],
"properties": {
"migration_step": {
"type": "object",
"required": [
"amount_of_users"
],
"properties": {
"amount_of_users": {
"$ref": "#/definitions/Uint128"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "SwapNonVaultFunds",
"type": "object",
Expand Down
7 changes: 7 additions & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +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);
}
Ok(())
}

pub fn assert_admin(storage: &dyn Storage, caller: &Addr) -> Result<(), ContractError> {
if ADMIN_ADDRESS.load(storage)? != caller {
return Err(ContractError::Unauthorized {});
Expand Down
36 changes: 0 additions & 36 deletions smart-contracts/osmosis/contracts/cl-vault/src/helpers/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ pub(crate) fn must_pay_one_or_two(
funds: &[Coin],
denoms: (String, String),
) -> Result<(Coin, Coin), ContractError> {
if funds.len() != 2 && funds.len() != 1 {
return Err(ContractError::IncorrectAmountFunds);
}

let token0 = funds
.iter()
.find(|coin| coin.denom == denoms.0)
Expand All @@ -24,29 +20,6 @@ pub(crate) fn must_pay_one_or_two(
Ok((token0, token1))
}

pub(crate) fn must_pay_one_or_two_from_balance(
funds: Vec<Coin>,
denoms: (String, String),
) -> Result<(Coin, Coin), ContractError> {
if funds.len() < 2 {
return Err(ContractError::IncorrectAmountFunds);
}

let token0 = funds
.clone()
.into_iter()
.find(|coin| coin.denom == denoms.0)
.unwrap_or(coin(0, denoms.0));

let token1 = funds
.clone()
.into_iter()
.find(|coin| coin.denom == denoms.1)
.unwrap_or(coin(0, denoms.1));

Ok((token0, token1))
}

#[cfg(test)]
mod tests {

Expand Down Expand Up @@ -76,15 +49,6 @@ mod tests {
assert_eq!(expected1, token1);
}

#[test]
fn must_pay_one_or_two_rejects_three() {
let expected0 = coin(100, "uatom");
let expected1 = coin(200, "uosmo");
let funds = vec![expected0, expected1, coin(200, "uqsr")];
let _err =
must_pay_one_or_two(&funds, ("uatom".to_string(), "uosmo".to_string())).unwrap_err();
}

#[test]
fn must_pay_one_or_two_accepts_second_token() {
let funds = vec![coin(200, "uosmo")];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use cosmwasm_std::{
use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::ConcentratedliquidityQuerier;
use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgCreatePositionResponse;

use crate::helpers::assert::must_pay_one_or_two_from_balance;
use crate::helpers::getters::get_unused_balances;
use crate::helpers::getters::get_unused_pair_balances;
use crate::msg::{ExecuteMsg, MergePositionMsg};
use crate::reply::Replies;
#[allow(deprecated)]
Expand Down Expand Up @@ -34,11 +33,11 @@ pub fn execute_autocompound(
.position
.ok_or(ContractError::PositionNotFound)?;

let balance = get_unused_balances(&deps.querier, env)?;
let pool = POOL_CONFIG.load(deps.storage)?;
let balance = get_unused_pair_balances(&deps, env, &pool)?;

let (token0, token1) =
must_pay_one_or_two_from_balance(balance.coins(), (pool.token0, pool.token1))?;
let token0 = balance[0].clone();
let token1 = balance[1].clone();

// Create coins_to_send with no zero amounts
let mut coins_to_send = vec![];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
error::assert_deposits,
helpers::{
getters::{
get_depositable_tokens, get_single_sided_deposit_0_to_1_swap_amount,
Expand Down Expand Up @@ -30,6 +31,7 @@ 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)?;
let deposit_info = get_depositable_tokens(&deps, &info.funds, &pool_config)?;
Expand All @@ -44,6 +46,7 @@ pub(crate) fn execute_any_deposit(
recipient: Option<String>,
max_slippage: Decimal,
) -> 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)?;
Expand Down
Loading