Skip to content

Commit

Permalink
refactor: remove owner from Config since it's in ownable
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Apr 15, 2024
1 parent 9986f8a commit f5d12b9
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 67 deletions.
15 changes: 0 additions & 15 deletions contracts/liquidity_hub/pool-manager/schema/pool-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
"type": "object",
"required": [
"fee_collector_addr",
"owner",
"pool_creation_fee"
],
"properties": {
"fee_collector_addr": {
"type": "string"
},
"owner": {
"type": "string"
},
"pool_creation_fee": {
"$ref": "#/definitions/Coin"
}
Expand Down Expand Up @@ -331,13 +327,6 @@
}
]
},
"owner_addr": {
"description": "The new owner address of the contract, which is allowed to update configuration.",
"type": [
"string",
"null"
]
},
"pool_creation_fee": {
"description": "The new fee that must be paid when a pool is created.",
"anyOf": [
Expand Down Expand Up @@ -891,17 +880,13 @@
"type": "object",
"required": [
"feature_toggle",
"owner",
"pool_creation_fee",
"whale_lair_addr"
],
"properties": {
"feature_toggle": {
"$ref": "#/definitions/FeatureToggle"
},
"owner": {
"$ref": "#/definitions/Addr"
},
"pool_creation_fee": {
"$ref": "#/definitions/Coin"
},
Expand Down
7 changes: 0 additions & 7 deletions contracts/liquidity_hub/pool-manager/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,6 @@
}
]
},
"owner_addr": {
"description": "The new owner address of the contract, which is allowed to update configuration.",
"type": [
"string",
"null"
]
},
"pool_creation_fee": {
"description": "The new fee that must be paid when a pool is created.",
"anyOf": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
"type": "object",
"required": [
"fee_collector_addr",
"owner",
"pool_creation_fee"
],
"properties": {
"fee_collector_addr": {
"type": "string"
},
"owner": {
"type": "string"
},
"pool_creation_fee": {
"$ref": "#/definitions/Coin"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
"type": "object",
"required": [
"feature_toggle",
"owner",
"pool_creation_fee",
"whale_lair_addr"
],
"properties": {
"feature_toggle": {
"$ref": "#/definitions/FeatureToggle"
},
"owner": {
"$ref": "#/definitions/Addr"
},
"pool_creation_fee": {
"$ref": "#/definitions/Coin"
},
Expand Down
7 changes: 2 additions & 5 deletions contracts/liquidity_hub/pool-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
let config: Config = Config {
whale_lair_addr: deps.api.addr_validate(&msg.fee_collector_addr)?,
owner: deps.api.addr_validate(&msg.owner)?,
// We must set a creation fee on instantiation to prevent spamming of pools
pool_creation_fee: msg.pool_creation_fee,
feature_toggle: FeatureToggle {
Expand All @@ -37,7 +36,7 @@ pub fn instantiate(
MANAGER_CONFIG.save(deps.storage, &config)?;
// initialize vault counter
PAIR_COUNTER.save(deps.storage, &0u64)?;
cw_ownable::initialize_owner(deps.storage, deps.api, Some(msg.owner.as_str()))?;
cw_ownable::initialize_owner(deps.storage, deps.api, Some(info.sender.as_str()))?;

Ok(Response::default())
}
Expand Down Expand Up @@ -150,13 +149,11 @@ pub fn execute(
ExecuteMsg::AddSwapRoutes { swap_routes: _ } => Ok(Response::new()),
ExecuteMsg::UpdateConfig {
whale_lair_addr,
owner_addr,
pool_creation_fee,
feature_toggle,
} => manager::update_config(
deps,
info,
owner_addr,
whale_lair_addr,
pool_creation_fee,
feature_toggle,
Expand Down
22 changes: 7 additions & 15 deletions contracts/liquidity_hub/pool-manager/src/manager/update_config.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
use cosmwasm_std::{Coin, DepsMut, MessageInfo, Response};
use cosmwasm_std::{ensure, Coin, DepsMut, MessageInfo, Response};
use white_whale_std::pool_manager::Config;
use white_whale_std::pool_network::pair::FeatureToggle;

use crate::{state::MANAGER_CONFIG, ContractError};

pub fn update_config(
deps: DepsMut,
info: MessageInfo,
owner_addr: Option<String>,
whale_lair_addr: Option<String>,
pool_creation_fee: Option<Coin>,
feature_toggle: Option<FeatureToggle>,
) -> Result<Response, ContractError> {
MANAGER_CONFIG.update(deps.storage, |mut config| {
// permission check
if info.sender != config.owner {
return Err(ContractError::Unauthorized {});
}

if let Some(owner) = owner_addr {
let owner_addr = deps.api.addr_validate(&owner)?;
config.owner = owner_addr;
}
// permission check
cw_ownable::assert_owner(deps.storage, &info.sender)?;

MANAGER_CONFIG.update(deps.storage, |mut config| {
if let Some(whale_lair_addr) = whale_lair_addr {
let whale_lair_addr = deps.api.addr_validate(&whale_lair_addr)?;
config.whale_lair_addr = whale_lair_addr;
Expand All @@ -34,9 +27,8 @@ pub fn update_config(
if let Some(feature_toggle) = feature_toggle {
config.feature_toggle = feature_toggle;
}

Ok(config)
Ok::<Config, ContractError>(config)
})?;

Ok(Response::new().add_attribute("action", "update_config"))
Ok(Response::default().add_attribute("action", "update_config"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -1850,12 +1850,15 @@ mod ownership {
None,
None,
None,
None,
|res| {
assert_eq!(
res.unwrap_err().downcast_ref::<ContractError>(),
Some(&ContractError::Unauthorized {})
)
|result| {
let err = result.unwrap_err().downcast::<ContractError>().unwrap();

match err {
ContractError::OwnershipError { .. } => {}
_ => {
panic!("Wrong error type, should return ContractError::OwnershipError")

Check warning on line 1859 in contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs

View check run for this annotation

Codecov / codecov/patch

contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs#L1859

Added line #L1859 was not covered by tests
}
}
},
);
}
Expand All @@ -1872,7 +1875,6 @@ mod ownership {

suite.update_config(
creator,
Some(other.clone()),
Some(other),
Some(coin(
current_pool_creation_fee
Expand All @@ -1893,7 +1895,6 @@ mod ownership {
);

let config = suite.query_config();
assert_ne!(config.owner, initial_config.owner);
assert_ne!(config.whale_lair_addr, initial_config.whale_lair_addr);
assert_ne!(config.pool_creation_fee, initial_config.pool_creation_fee);
assert_ne!(config.feature_toggle, initial_config.feature_toggle);
Expand Down
3 changes: 0 additions & 3 deletions contracts/liquidity_hub/pool-manager/src/tests/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ impl TestingSuite {
pub(crate) fn instantiate(&mut self, whale_lair_addr: String) -> &mut Self {
let msg = InstantiateMsg {
fee_collector_addr: whale_lair_addr,
owner: self.creator().to_string(),
pool_creation_fee: coin(1_000, "uusd"),
};

Expand Down Expand Up @@ -370,7 +369,6 @@ impl TestingSuite {
&mut self,
sender: Addr,
new_whale_lair_addr: Option<Addr>,
new_owner_addr: Option<Addr>,
new_pool_creation_fee: Option<Coin>,
new_feature_toggle: Option<FeatureToggle>,
result: impl Fn(Result<AppResponse, anyhow::Error>),
Expand All @@ -380,7 +378,6 @@ impl TestingSuite {
self.pool_manager_addr.clone(),
&white_whale_std::pool_manager::ExecuteMsg::UpdateConfig {
whale_lair_addr: new_whale_lair_addr.map(|addr| addr.to_string()),
owner_addr: new_owner_addr.map(|addr| addr.to_string()),
pool_creation_fee: new_pool_creation_fee,
feature_toggle: new_feature_toggle,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/white-whale-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ cw20-base.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
test-case.workspace = true
test-case.workspace = true
5 changes: 0 additions & 5 deletions packages/white-whale-std/src/pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ impl PairInfo {}
#[cw_serde]
pub struct Config {
pub whale_lair_addr: Addr,
pub owner: Addr,
// We must set a creation fee on instantiation to prevent spamming of pools
pub pool_creation_fee: Coin,
// Whether or not swaps, deposits, and withdrawals are enabled
Expand All @@ -125,7 +124,6 @@ pub struct Config {
#[cw_serde]
pub struct InstantiateMsg {
pub fee_collector_addr: String,
pub owner: String,
pub pool_creation_fee: Coin,
}

Expand Down Expand Up @@ -209,9 +207,6 @@ pub enum ExecuteMsg {
UpdateConfig {
/// The new whale-lair contract address.
whale_lair_addr: Option<String>,
/// The new owner address of the contract, which is allowed to update
/// configuration.
owner_addr: Option<String>,
/// The new fee that must be paid when a pool is created.
pool_creation_fee: Option<Coin>,
/// The new feature toggles of the contract, allowing fine-tuned
Expand Down

0 comments on commit f5d12b9

Please sign in to comment.