diff --git a/smart-contracts/contracts/cl-vault/src/contract.rs b/smart-contracts/contracts/cl-vault/src/contract.rs index b67acfafb..cc8c743e1 100644 --- a/smart-contracts/contracts/cl-vault/src/contract.rs +++ b/smart-contracts/contracts/cl-vault/src/contract.rs @@ -8,6 +8,7 @@ use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::Concentratedliq use crate::error::ContractError; use crate::helpers::generic::sort_tokens; +use crate::helpers::getters::get_range_admin; use crate::helpers::prepend::prepend_claim_msg; use crate::instantiate::{ handle_create_denom_reply, handle_instantiate, handle_instantiate_create_position_reply, @@ -39,7 +40,7 @@ use crate::vault::merge::{ handle_merge_withdraw_position_reply, }; use crate::vault::range::{ - execute_update_range, get_range_admin, handle_initial_create_position_reply, + execute_update_range, handle_initial_create_position_reply, handle_iteration_create_position_reply, handle_merge_reply, handle_swap_reply, handle_withdraw_position_reply, }; diff --git a/smart-contracts/contracts/cl-vault/src/helpers/assert.rs b/smart-contracts/contracts/cl-vault/src/helpers/assert.rs index b6a01b5b9..f5c92932a 100644 --- a/smart-contracts/contracts/cl-vault/src/helpers/assert.rs +++ b/smart-contracts/contracts/cl-vault/src/helpers/assert.rs @@ -1,6 +1,9 @@ -use cosmwasm_std::{coin, Addr, Coin, Deps, MessageInfo}; +use cosmwasm_std::{coin, Addr, Coin, Deps, MessageInfo, Storage}; -use crate::{state::ADMIN_ADDRESS, ContractError}; +use crate::{ + state::{ADMIN_ADDRESS, RANGE_ADMIN}, + ContractError, +}; /// This function compares the address of the message sender (caller) with the current admin /// address stored in the state. This provides a convenient way to verify if the caller @@ -13,6 +16,14 @@ pub fn assert_admin(deps: Deps, caller: &Addr) -> Result { } } +pub fn assert_range_admin(storage: &mut dyn Storage, sender: &Addr) -> Result<(), ContractError> { + let admin = RANGE_ADMIN.load(storage)?; + if admin != sender { + return Err(ContractError::Unauthorized {}); + } + Ok(()) +} + /// Returns the Coin of the needed denoms in the order given in denoms pub(crate) fn must_pay_one_or_two( info: &MessageInfo, diff --git a/smart-contracts/contracts/cl-vault/src/helpers/getters.rs b/smart-contracts/contracts/cl-vault/src/helpers/getters.rs index c8cf9c37b..c860cccf9 100644 --- a/smart-contracts/contracts/cl-vault/src/helpers/getters.rs +++ b/smart-contracts/contracts/cl-vault/src/helpers/getters.rs @@ -1,4 +1,5 @@ use crate::math::tick::tick_to_price; +use crate::state::RANGE_ADMIN; use std::str::FromStr; use osmosis_std::shim::Timestamp as OsmoTimestamp; @@ -8,12 +9,17 @@ use osmosis_std::types::osmosis::twap::v1beta1::TwapQuerier; use crate::vault::concentrated_liquidity::{get_cl_pool_info, get_position}; use crate::{state::POOL_CONFIG, ContractError}; use cosmwasm_std::{ - Coin, Decimal, Decimal256, DepsMut, Env, Fraction, QuerierWrapper, Storage, Uint128, Uint256, + Addr, Coin, Decimal, Decimal256, Deps, DepsMut, Env, Fraction, QuerierWrapper, Storage, + Uint128, Uint256, }; use osmosis_std::try_proto_to_cosmwasm_coins; use super::coinlist::CoinList; +pub fn get_range_admin(deps: Deps) -> Result { + Ok(RANGE_ADMIN.load(deps.storage)?) +} + /// Calculate the total value of two assets in asset0. pub fn get_asset0_value( storage: &dyn Storage, diff --git a/smart-contracts/contracts/cl-vault/src/helpers/msgs.rs b/smart-contracts/contracts/cl-vault/src/helpers/msgs.rs index faa93ce0c..5e3484a97 100644 --- a/smart-contracts/contracts/cl-vault/src/helpers/msgs.rs +++ b/smart-contracts/contracts/cl-vault/src/helpers/msgs.rs @@ -30,15 +30,13 @@ pub fn refund_bank_msg( if let Some(refund0) = refund0 { if refund0.amount > Uint128::zero() { - attributes.push(attr("refund0_amount", refund0.amount)); - attributes.push(attr("refund0_denom", refund0.denom.as_str())); + attributes.push(attr("refund0", refund0.amount)); coins.push(refund0) } } if let Some(refund1) = refund1 { if refund1.amount > Uint128::zero() { - attributes.push(attr("refund1_amount", refund1.amount)); - attributes.push(attr("refund1_denom", refund1.denom.as_str())); + attributes.push(attr("refund1", refund1.amount)); coins.push(refund1) } } diff --git a/smart-contracts/contracts/cl-vault/src/test_tube/autocompound.rs b/smart-contracts/contracts/cl-vault/src/test_tube/autocompound.rs index 12ea40746..8a22442c7 100644 --- a/smart-contracts/contracts/cl-vault/src/test_tube/autocompound.rs +++ b/smart-contracts/contracts/cl-vault/src/test_tube/autocompound.rs @@ -138,7 +138,7 @@ mod tests { // Assert balance refunded is either the expected value or not empty for token0 let refund0_amount = - get_event_attributes_by_ty_and_key(&exact_deposit, "wasm", vec!["refund0_amount"]); + get_event_attributes_by_ty_and_key(&exact_deposit, "wasm", vec!["refund0"]); let mut refund0_amount_parsed: u128 = 0; if expected_refund0 > 0 { assert_approx_eq!( @@ -159,7 +159,7 @@ mod tests { // Assert balance refunded is either the expected value or not empty for token1 let refund1_amount = - get_event_attributes_by_ty_and_key(&exact_deposit, "wasm", vec!["refund1_amount"]); + get_event_attributes_by_ty_and_key(&exact_deposit, "wasm", vec!["refund1"]); let mut refund1_amount_parsed: u128 = 0; if expected_refund1 > 0 { assert_approx_eq!( diff --git a/smart-contracts/contracts/cl-vault/src/test_tube/deposit_withdraw.rs b/smart-contracts/contracts/cl-vault/src/test_tube/deposit_withdraw.rs index 17268ab28..4c3cec86a 100644 --- a/smart-contracts/contracts/cl-vault/src/test_tube/deposit_withdraw.rs +++ b/smart-contracts/contracts/cl-vault/src/test_tube/deposit_withdraw.rs @@ -76,16 +76,14 @@ mod tests { .unwrap(); // assert that the refund + used funds are equal to what we deposited - let refund0: u128 = - get_event_attributes_by_ty_and_key(&response, "wasm", vec!["refund0_amount"]) - .get(0) - .map(|attr| attr.value.parse().unwrap()) - .unwrap_or(0); - let refund1: u128 = - get_event_attributes_by_ty_and_key(&response, "wasm", vec!["refund1_amount"]) - .get(0) - .map(|attr| attr.value.parse().unwrap()) - .unwrap_or(0); + let refund0: u128 = get_event_attributes_by_ty_and_key(&response, "wasm", vec!["refund0"]) + .get(0) + .map(|attr| attr.value.parse().unwrap()) + .unwrap_or(0); + let refund1: u128 = get_event_attributes_by_ty_and_key(&response, "wasm", vec!["refund1"]) + .get(0) + .map(|attr| attr.value.parse().unwrap()) + .unwrap_or(0); let deposited0: u128 = get_event_attributes_by_ty_and_key(&response, "wasm", vec!["amount0"]) diff --git a/smart-contracts/contracts/cl-vault/src/vault/range.rs b/smart-contracts/contracts/cl-vault/src/vault/range.rs index 49eb7c9bb..22cc23c7f 100644 --- a/smart-contracts/contracts/cl-vault/src/vault/range.rs +++ b/smart-contracts/contracts/cl-vault/src/vault/range.rs @@ -1,5 +1,6 @@ use crate::{ helpers::{ + assert::assert_range_admin, generic::extract_attribute_value_by_ty_and_key, getters::{ get_single_sided_deposit_0_to_1_swap_amount, @@ -12,7 +13,7 @@ use crate::{ reply::Replies, state::{ ModifyRangeState, Position, SwapDepositMergeState, CURRENT_BALANCE, CURRENT_SWAP, - MODIFY_RANGE_STATE, POOL_CONFIG, POSITION, RANGE_ADMIN, SWAP_DEPOSIT_MERGE_STATE, + MODIFY_RANGE_STATE, POOL_CONFIG, POSITION, SWAP_DEPOSIT_MERGE_STATE, }, vault::{ concentrated_liquidity::{create_position, get_position}, @@ -22,8 +23,8 @@ use crate::{ }; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - attr, to_json_binary, Addr, Coin, Decimal, Decimal256, Deps, DepsMut, Env, Fraction, - MessageInfo, Response, Storage, SubMsg, SubMsgResult, Uint128, + attr, to_json_binary, Coin, Decimal, Decimal256, DepsMut, Env, Fraction, MessageInfo, Response, + SubMsg, SubMsgResult, Uint128, }; use osmosis_std::types::osmosis::{ concentratedliquidity::v1beta1::{ @@ -39,18 +40,6 @@ use super::{ swap::{SwapCalculationResult, SwapParams}, }; -pub fn assert_range_admin(storage: &mut dyn Storage, sender: &Addr) -> Result<(), ContractError> { - let admin = RANGE_ADMIN.load(storage)?; - if admin != sender { - return Err(ContractError::Unauthorized {}); - } - Ok(()) -} - -pub fn get_range_admin(deps: Deps) -> Result { - Ok(RANGE_ADMIN.load(deps.storage)?) -} - /// This function is the entrypoint into the dsm routine that will go through the following steps /// * how much liq do we have in current range /// * so how much of each asset given liq would we have at current price @@ -687,6 +676,7 @@ mod tests { use osmosis_std::types::osmosis::concentratedliquidity::v1beta1::MsgWithdrawPositionResponse; use crate::{ + helpers::getters::get_range_admin, math::tick::build_tick_exp_cache, state::{MODIFY_RANGE_STATE, RANGE_ADMIN}, test_helpers::{mock_deps_with_querier, mock_deps_with_querier_with_balance}, @@ -717,7 +707,7 @@ mod tests { RANGE_ADMIN.save(&mut deps.storage, &info.sender).unwrap(); - assert_eq!(super::get_range_admin(deps.as_ref()).unwrap(), info.sender); + assert_eq!(get_range_admin(deps.as_ref()).unwrap(), info.sender); } #[test] diff --git a/smart-contracts/contracts/cl-vault/src/vault/swap.rs b/smart-contracts/contracts/cl-vault/src/vault/swap.rs index 79156ea15..d2d5e15e3 100644 --- a/smart-contracts/contracts/cl-vault/src/vault/swap.rs +++ b/smart-contracts/contracts/cl-vault/src/vault/swap.rs @@ -1,13 +1,12 @@ use cosmwasm_std::{CosmosMsg, DepsMut, Env, Fraction, MessageInfo, Response, Uint128}; use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute; +use crate::helpers::assert::assert_range_admin; use crate::helpers::msgs::swap_msg; use crate::msg::SwapOperation; use crate::state::POOL_CONFIG; use crate::{state::VAULT_CONFIG, ContractError}; -use super::range::assert_range_admin; - /// SwapCalculationResult holds the result of a swap calculation pub struct SwapCalculationResult { pub swap_msg: CosmosMsg,