Skip to content

Commit

Permalink
Remove duplicate dex_router state (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll authored Aug 30, 2024
1 parent 159db8b commit d75209f
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 230 deletions.
23 changes: 0 additions & 23 deletions smart-contracts/osmosis/contracts/cl-vault/schema/cl-vault.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,29 +338,6 @@
},
"additionalProperties": false
},
{
"description": "Update the dex router address.",
"type": "object",
"required": [
"update_dex_router"
],
"properties": {
"update_dex_router": {
"type": "object",
"properties": {
"address": {
"description": "The new dex router address.",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Build tick exponent cache",
"type": "object",
Expand Down
23 changes: 0 additions & 23 deletions smart-contracts/osmosis/contracts/cl-vault/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,6 @@
},
"additionalProperties": false
},
{
"description": "Update the dex router address.",
"type": "object",
"required": [
"update_dex_router"
],
"properties": {
"update_dex_router": {
"type": "object",
"properties": {
"address": {
"description": "The new dex router address.",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Build tick exponent cache",
"type": "object",
Expand Down
2 changes: 2 additions & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
let dex_router_item: Item<Addr> = Item::new("dex_router");
dex_router_item.remove(deps.storage);
// VaultConfig
#[cw_serde]
struct OldVaultConfig {
Expand Down
4 changes: 4 additions & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cosmwasm_std::{
};
use cw_utils::PaymentError;
use prost::DecodeError;
use quasar_types::pool_pair::PoolPairError;
use std::num::{ParseIntError, TryFromIntError};
use thiserror::Error;

Expand Down Expand Up @@ -158,6 +159,9 @@ pub enum ContractError {

#[error("{0}")]
TryFromIntError(#[from] TryFromIntError),

#[error("{0}")]
PoolPair(#[from] PoolPairError),
}

pub fn assert_deposits(funds: &[Coin], config: &PoolConfig) -> Result<(), ContractError> {
Expand Down
5 changes: 0 additions & 5 deletions smart-contracts/osmosis/contracts/cl-vault/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ pub enum AdminExtensionExecuteMsg {
/// The metadata updates.
updates: Metadata,
},
/// Update the dex router address.
UpdateDexRouter {
/// The new dex router address.
address: Option<String>,
},
/// Build tick exponent cache
BuildTickCache {},
}
Expand Down
7 changes: 3 additions & 4 deletions smart-contracts/osmosis/contracts/cl-vault/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::helpers::coinlist::CoinList;
use crate::helpers::getters::get_unused_balances;
use crate::math::tick::verify_tick_exp_cache;
use crate::state::DEX_ROUTER;
use crate::state::{
PoolConfig, ADMIN_ADDRESS, METADATA, POOL_CONFIG, POSITION, SHARES, VAULT_DENOM,
PoolConfig, ADMIN_ADDRESS, METADATA, POOL_CONFIG, POSITION, SHARES, VAULT_CONFIG, VAULT_DENOM,
};
use crate::vault::concentrated_liquidity::get_position;
use crate::ContractError;
Expand Down Expand Up @@ -106,10 +105,10 @@ pub fn query_metadata(deps: Deps) -> Result<MetadataResponse, ContractError> {
}

pub fn query_dex_router(deps: Deps) -> Result<DexRouterResponse, ContractError> {
let dex_router = DEX_ROUTER.load(deps.storage)?;
let config = VAULT_CONFIG.load(deps.storage)?;

Ok(DexRouterResponse {
dex_router: dex_router.to_string(),
dex_router: config.dex_router.to_string(),
})
}

Expand Down
10 changes: 8 additions & 2 deletions smart-contracts/osmosis/contracts/cl-vault/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Coin, Decimal, Decimal256, Uint128};
use cw_storage_plus::{Deque, Item, Map};
use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute;
use quasar_types::pool_pair::PoolPair;

#[cw_serde]
pub struct Metadata {
Expand Down Expand Up @@ -72,8 +73,13 @@ pub struct CurrentDeposit {
pub sender: Addr,
}

pub const CURRENT_SWAP_ANY_DEPOSIT: Item<(Coin, Addr, (Uint128, Uint128))> =
Item::new("current_swap_any_deposit");
#[cw_serde]
pub struct CurrentSwap {
pub recipient: Addr,
pub vault_balance: PoolPair<Coin, Coin>,
}

pub const CURRENT_SWAP_INFO: Item<CurrentSwap> = Item::new("current_swap_recipient");

pub const DEX_ROUTER: Item<Addr> = Item::new("dex_router");

Expand Down
17 changes: 13 additions & 4 deletions smart-contracts/osmosis/contracts/cl-vault/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub const POSITION_ID: u64 = 101;
pub const BASE_DENOM: &str = "base";
pub const QUOTE_DENOM: &str = "quote";
pub const TEST_VAULT_DENOM: &str = "uqsr";
pub const INSTANTIATE_BASE_DEPOSIT_AMOUNT: u128 = 100;
pub const INSTANTIATE_QUOTE_DEPOSIT_AMOUNT: u128 = 100;
pub const TEST_VAULT_TOKEN_SUPPLY: u128 = 100_000;

pub struct QuasarQuerier {
position: FullPositionBreakdown,
Expand Down Expand Up @@ -89,7 +92,7 @@ impl Querier for QuasarQuerier {
to_json_binary(&QuerySupplyOfResponse {
amount: Some(OsmoCoin {
denom,
amount: 100000.to_string(),
amount: TEST_VAULT_TOKEN_SUPPLY.to_string(),
}),
})
.unwrap(),
Expand Down Expand Up @@ -268,16 +271,22 @@ pub fn get_init_msg(admin: &str) -> InstantiateMsg {
},
vault_token_subdenom: "utestvault".to_string(),
range_admin: admin.to_string(),
initial_lower_tick: 1,
initial_upper_tick: 100,
initial_lower_tick: 100,
initial_upper_tick: 1000,
thesis: "Test thesis".to_string(),
name: "Contract".to_string(),
}
}

pub fn instantiate_contract(mut deps: DepsMut, env: Env, admin: &str) {
let msg = get_init_msg(admin);
let info = mock_info(admin, &[coin(100, BASE_DENOM), coin(100, QUOTE_DENOM)]);
let info = mock_info(
admin,
&[
coin(INSTANTIATE_BASE_DEPOSIT_AMOUNT, BASE_DENOM),
coin(INSTANTIATE_QUOTE_DEPOSIT_AMOUNT, QUOTE_DENOM),
],
);
assert!(instantiate(deps.branch(), env, info, msg).is_ok());
VAULT_DENOM
.save(deps.storage, &TEST_VAULT_DENOM.to_string())
Expand Down
32 changes: 1 addition & 31 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/admin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::error::assert_admin;
use crate::math::tick::build_tick_exp_cache;
use crate::state::{
Metadata, VaultConfig, ADMIN_ADDRESS, DEX_ROUTER, METADATA, RANGE_ADMIN, VAULT_CONFIG,
};
use crate::state::{Metadata, VaultConfig, ADMIN_ADDRESS, METADATA, RANGE_ADMIN, VAULT_CONFIG};
use crate::{msg::AdminExtensionExecuteMsg, ContractError};
use cosmwasm_std::{Decimal, DepsMut, MessageInfo, Response, StdError};
use cw_utils::nonpayable;
Expand All @@ -25,9 +23,6 @@ pub(crate) fn execute_admin(
AdminExtensionExecuteMsg::UpdateRangeAdmin { address } => {
execute_update_range_admin(deps, info, address)
}
AdminExtensionExecuteMsg::UpdateDexRouter { address } => {
execute_update_dex_router(deps, info, address)
}
AdminExtensionExecuteMsg::BuildTickCache {} => execute_build_tick_exp_cache(deps, info),
}
}
Expand Down Expand Up @@ -80,31 +75,6 @@ pub fn execute_update_range_admin(
.add_attribute("new_admin", &new_admin))
}

/// Updates the dex router address
pub fn execute_update_dex_router(
deps: DepsMut,
info: MessageInfo,
address: Option<String>,
) -> Result<Response, ContractError> {
nonpayable(&info).map_err(|_| ContractError::NonPayable {})?;
assert_admin(deps.storage, &info.sender)?;

match address.clone() {
Some(address) => {
let new_router = deps.api.addr_validate(&address)?;
DEX_ROUTER.save(deps.storage, &new_router.clone())?;
}
None => {
DEX_ROUTER.remove(deps.storage);
}
}

Ok(Response::new()
.add_attribute("method", "execute")
.add_attribute("action", "update_dex_router")
.add_attribute("new_router", address.unwrap_or_default().to_string()))
}

/// Updates the configuration of the contract.
///
/// This function first checks if the message sender is nonpayable. If the sender sent funds, a `ContractError::NonPayable` error is returned.
Expand Down
Loading

0 comments on commit d75209f

Please sign in to comment.