diff --git a/artifacts/checksums.txt b/artifacts/checksums.txt index c3e9497a..800b797d 100644 --- a/artifacts/checksums.txt +++ b/artifacts/checksums.txt @@ -1,20 +1,20 @@ -e8b52fab268f7bb5538b4b81e284a89eee824e4b9f9430eb147f64601bea3363 credits_vault.wasm +e02c0faf19a093d4f304b5aae55c34a38b4dd5fcd153bf6060b4962d29fd7d49 credits_vault.wasm e1f198ec554470bd05f4081cf2309035a1369152b147bdc2ca2fad7120364641 cw4_group.wasm 187c5a1e98b14384bf2e1bbbfddde4214f7e10e00dd5369c68f4dc3363a8a7bf cw4_voting.wasm -6fc1a396d4763097b7b260a083e1c7f9de8d92b1a020c18cceee29f055d72df2 cwd_core.wasm +676a948ace3832aaca1ffcb0809525bd8545437425eb22b39a640c4731b17e3f cwd_core.wasm c7ddd8a95dc3d1912249f12e7b036d9daeaac07af1e2c77ebe92a97aaab125b8 cwd_pre_propose_multiple.wasm 047169a6e4e4b6fc5b2f7550376b2f1648554c54837f7631afa07fc3c6c34ce8 cwd_pre_propose_overrule.wasm 35be8f8ebecfd8893eded5d63148fd1f68733a525f8f7a42f8b70c11bbaf60fb cwd_pre_propose_single.wasm -77c2d5ef5199a936905920e53c8435b9bf89e919c4552a679813902ecc3b1d77 cwd_proposal_multiple.wasm +994330de9edb83f32e1364f9d65ddcc37669bd2d22071220bad2028a93b82d5e cwd_proposal_multiple.wasm 64d3e3dc1db548307654dd585f1bad1d3dc00d2758d2b71d988a71333bcea3c6 cwd_proposal_single.wasm 8f86441f544654e6012cf4e56670c0ddbd2275c80aba64c923fe349889e0ed43 cwd_subdao_core.wasm bdddd6ea8f7dc36e1b73d97c7caf20f59a3f2e3544a307098fbd02d838f260bd cwd_subdao_pre_propose_overrule.wasm e98782b00d3a36f85dfe899025848beae3b330deefb818204d6251e431417f1a cwd_subdao_pre_propose_single.wasm be0fb8de87fad3da5f4fee52b27dbcef6426af56692401945873b2b0894779cc cwd_subdao_proposal_single.wasm aed528b20c9d432414858d0a825e945365145b3d375cb174fd7a8ba4f7234693 cwd_subdao_timelock_single.wasm -a6a0f619d52fc90ab59e15358f7a5b2a34e570e31cdbf6881037198bc877c2ab lockdrop_vault.wasm -9bbd1d908adc2e3d50ae3f3d74073a4d39c437c6b389fed2163eff3bf238ee28 neutron_distribution.wasm +73c102d902e11e0eb070d53282e5e04656dc3a549defec596b36cbb3571e0f31 lockdrop_vault.wasm +543678b0a2147d095dfe9076aad23b263422d321c98d61c969745b5c393968c0 neutron_distribution.wasm 8c58519e5a278fbce1c912a5832cab7e29768b69f05c2338e2a10d584c517c5a neutron_reserve.wasm -f4be156137da8588bf7215fa62a8bddb5d9cc31415c524716ebc1b53bd0448a8 neutron_treasury.wasm -566cdb60a51e9ad83bc2bf69492f1fdd72931784dcc2648811adaa87d5565586 neutron_vault.wasm -97a95c2ddae372f8d119cb188c1066bd3baccb7b37eae8cd704fe3ef19fbfd05 neutron_voting_registry.wasm +e95ae0040e7cf295e483440715f57cf468c3b9badd0bb3ccd0103bacc5a46bdc neutron_treasury.wasm +0704e6094cc92cbd8bf08eeaa52f17df944e6f73e6c27b79b636a90987cbcbf5 neutron_vault.wasm +9d079e8b6b3032b4f1d17a0345b583fe3274dcfb293219c3305d44720e326ade neutron_voting_registry.wasm diff --git a/artifacts/checksums_intermediate.txt b/artifacts/checksums_intermediate.txt index b8f945e4..e6750bdd 100644 --- a/artifacts/checksums_intermediate.txt +++ b/artifacts/checksums_intermediate.txt @@ -2,17 +2,17 @@ d328a563a7125e5c1bd8d31004eacfea2417467efc040aac2ecc981040f566a6 target/wasm32-unknown-unknown/release/cwd_pre_propose_overrule.wasm 9045a14917b5fe2aae20e8778bdb315ddee88dcd3f38e6d86fd2e1e820e585d0 target/wasm32-unknown-unknown/release/cwd_pre_propose_single.wasm 1ae934f9b3e188a4d7096f4f9231edfad84a482a33a66e90b5d0ce124065c062 target/wasm32-unknown-unknown/release/cwd_subdao_pre_propose_single.wasm -91be9e3bbb44c0abfafc1602887348ac67c41511c6f2cbbca26e945e7125b159 target/wasm32-unknown-unknown/release/neutron_distribution.wasm -2243d1d288ebc8c8110a95ea69226ba9012ffd79cad637147c6e9aa5a27c7942 target/wasm32-unknown-unknown/release/neutron_treasury.wasm d328a563a7125e5c1bd8d31004eacfea2417467efc040aac2ecc981040f566a6 target/wasm32-unknown-unknown/release/cwd_pre_propose_overrule.wasm -98d530814928c28813685bdd634d33c6d10bde7d8d3d14054dd28c18ecc082c7 target/wasm32-unknown-unknown/release/cwd_core.wasm 182595fe1ffd93701b14c6f04d5ac40af1f43aabcfbdb7144b63d609a87154d0 target/wasm32-unknown-unknown/release/cwd_subdao_core.wasm 5f5de39421089a6edc7f6e8bbcfe90aa57115e6257d8f3e2c4ee9f026a8acf0e target/wasm32-unknown-unknown/release/cwd_subdao_proposal_single.wasm 2cbd1aeb99f73a7089fbcb94140096585c4db4611fb342a6e9843989feee1fd2 target/wasm32-unknown-unknown/release/cwd_subdao_timelock_single.wasm 958d16502995b3793d757debf31462925a83d2a7ff64a9085cb039cdc647c6a6 target/wasm32-unknown-unknown/release/neutron_reserve.wasm -78764327dccf528394eb79786bb75d8737687dfff33ea8e0497a71276a7ee926 target/wasm32-unknown-unknown/release/cwd_proposal_multiple.wasm fc79389148ad4653d8a9da2926c683d297b0c7ddce8bf2a865c70e0897cdb176 target/wasm32-unknown-unknown/release/cwd_proposal_single.wasm -d433ee1fb4e4776d6099018f1ed0fae7ac965b519a2a7cd73d13eddeba32fa19 target/wasm32-unknown-unknown/release/lockdrop_vault.wasm -1ad122156a805c1f22ea37baf521605b5bedd761b22973bf69192de331e30bd2 target/wasm32-unknown-unknown/release/neutron_vault.wasm -55eabfcd6370e5774f67dc9517fcf6361f73bb53f17f129987cf4929227edd5b target/wasm32-unknown-unknown/release/neutron_voting_registry.wasm -98389aad0f011b85b7092660c807d8a80c5a96f68321f17eb0cf12feed478106 target/wasm32-unknown-unknown/release/credits_vault.wasm +fc8b096f3c222d03feb30db06781bc48b0047ef413a578d5051652009d4b2654 target/wasm32-unknown-unknown/release/credits_vault.wasm +e77eedef6c4bccd4f5a9d01d51384438b28698c69ac62bb04e721e01a6d53e77 target/wasm32-unknown-unknown/release/cwd_core.wasm +310bcf72e4189d76ab60a95624693f4be2a413715c5d1a938b270b4e14f9813d target/wasm32-unknown-unknown/release/cwd_proposal_multiple.wasm +5ca97769fa8c3d0e39d70518725f4671b24f20e2699eeab4b26bd6b130aebce1 target/wasm32-unknown-unknown/release/lockdrop_vault.wasm +541982d8d8e00ce380fc6d48bd7c4c631ae4160bedde61c62bd84c317c2177f2 target/wasm32-unknown-unknown/release/neutron_distribution.wasm +beeaf6a9cb0c9904515fe8be03a810df9b5348d47dc5d2e04a4ad9ad4dbad17f target/wasm32-unknown-unknown/release/neutron_treasury.wasm +015b3a9c3f570ee7ce3a01f7453b6658497565c9a438091a209f391f82659a8d target/wasm32-unknown-unknown/release/neutron_vault.wasm +8a9e58c14a85c76b3ab2ad62ca5001c7cbc52a75cc7b3a80ba8d604864e5cc0c target/wasm32-unknown-unknown/release/neutron_voting_registry.wasm diff --git a/artifacts/credits_vault.wasm b/artifacts/credits_vault.wasm index db331c74..6c8c0588 100644 Binary files a/artifacts/credits_vault.wasm and b/artifacts/credits_vault.wasm differ diff --git a/artifacts/cwd_core.wasm b/artifacts/cwd_core.wasm index ec3d4272..618c498a 100644 Binary files a/artifacts/cwd_core.wasm and b/artifacts/cwd_core.wasm differ diff --git a/artifacts/cwd_proposal_multiple.wasm b/artifacts/cwd_proposal_multiple.wasm index 3addc540..68cd41ae 100644 Binary files a/artifacts/cwd_proposal_multiple.wasm and b/artifacts/cwd_proposal_multiple.wasm differ diff --git a/artifacts/lockdrop_vault.wasm b/artifacts/lockdrop_vault.wasm index b8ca3b11..9095ad2c 100644 Binary files a/artifacts/lockdrop_vault.wasm and b/artifacts/lockdrop_vault.wasm differ diff --git a/artifacts/neutron_distribution.wasm b/artifacts/neutron_distribution.wasm index fa6237a1..fcc54bbf 100644 Binary files a/artifacts/neutron_distribution.wasm and b/artifacts/neutron_distribution.wasm differ diff --git a/artifacts/neutron_treasury.wasm b/artifacts/neutron_treasury.wasm index 60f1d0d5..50b6c8a2 100644 Binary files a/artifacts/neutron_treasury.wasm and b/artifacts/neutron_treasury.wasm differ diff --git a/artifacts/neutron_vault.wasm b/artifacts/neutron_vault.wasm index 63293457..366fdb87 100644 Binary files a/artifacts/neutron_vault.wasm and b/artifacts/neutron_vault.wasm differ diff --git a/artifacts/neutron_voting_registry.wasm b/artifacts/neutron_voting_registry.wasm index c199e57c..87425a0d 100644 Binary files a/artifacts/neutron_voting_registry.wasm and b/artifacts/neutron_voting_registry.wasm differ diff --git a/contracts/dao/proposal/cwd-proposal-multiple/src/testing/instantiate.rs b/contracts/dao/proposal/cwd-proposal-multiple/src/testing/instantiate.rs index f66494fa..7159fdcb 100644 --- a/contracts/dao/proposal/cwd-proposal-multiple/src/testing/instantiate.rs +++ b/contracts/dao/proposal/cwd-proposal-multiple/src/testing/instantiate.rs @@ -74,7 +74,7 @@ pub(crate) fn instantiate_with_native_bonded_balances_governance( let vault_intantiate = neutron_vault::msg::InstantiateMsg { name: "Test vault".to_string(), description: "based neutron vault".to_string(), - owner: None, + owner: Admin::CoreModule {}, manager: None, denom: "ujuno".to_string(), }; @@ -125,7 +125,7 @@ pub(crate) fn instantiate_with_native_bonded_balances_governance( voting_registry_module_instantiate_info: ModuleInstantiateInfo { code_id: voting_registry_id, msg: to_binary(&neutron_voting_registry::msg::InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: None, voting_vaults: vec![vault_addr.to_string()], }) diff --git a/contracts/dao/proposal/cwd-proposal-single/src/testing/instantiate.rs b/contracts/dao/proposal/cwd-proposal-single/src/testing/instantiate.rs index edd00fa5..1e0c0f4d 100644 --- a/contracts/dao/proposal/cwd-proposal-single/src/testing/instantiate.rs +++ b/contracts/dao/proposal/cwd-proposal-single/src/testing/instantiate.rs @@ -77,7 +77,7 @@ pub(crate) fn instantiate_with_native_bonded_balances_governance( let vault_intantiate = neutron_vault::msg::InstantiateMsg { name: "Test vault".to_string(), description: "based neutron vault".to_string(), - owner: None, + owner: Admin::CoreModule {}, manager: None, denom: "ujuno".to_string(), }; @@ -128,7 +128,7 @@ pub(crate) fn instantiate_with_native_bonded_balances_governance( voting_registry_module_instantiate_info: ModuleInstantiateInfo { code_id: voting_registry_id, msg: to_binary(&neutron_voting_registry::msg::InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: None, voting_vaults: vec![vault_addr.to_string()], }) diff --git a/contracts/dao/voting/credits-vault/schema/execute_msg.json b/contracts/dao/voting/credits-vault/schema/execute_msg.json index 406e4037..d5c9835d 100644 --- a/contracts/dao/voting/credits-vault/schema/execute_msg.json +++ b/contracts/dao/voting/credits-vault/schema/execute_msg.json @@ -10,6 +10,9 @@ "properties": { "update_config": { "type": "object", + "required": [ + "owner" + ], "properties": { "credits_contract_address": { "type": [ @@ -30,60 +33,12 @@ ] }, "owner": { - "anyOf": [ - { - "$ref": "#/definitions/Admin" - }, - { - "type": "null" - } - ] + "type": "string" } } } }, "additionalProperties": false } - ], - "definitions": { - "Admin": { - "description": "Information about the CosmWasm level admin of a contract. Used in conjunction with `ModuleInstantiateInfo` to instantiate modules.", - "oneOf": [ - { - "description": "Set the admin to a specified address.", - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "type": "object", - "required": [ - "addr" - ], - "properties": { - "addr": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Sets the admin as the core module address.", - "type": "object", - "required": [ - "core_module" - ], - "properties": { - "core_module": { - "type": "object" - } - }, - "additionalProperties": false - } - ] - } - } + ] } diff --git a/contracts/dao/voting/credits-vault/schema/get_config_response.json b/contracts/dao/voting/credits-vault/schema/get_config_response.json index 199c63f5..71732b1a 100644 --- a/contracts/dao/voting/credits-vault/schema/get_config_response.json +++ b/contracts/dao/voting/credits-vault/schema/get_config_response.json @@ -4,7 +4,8 @@ "type": "object", "required": [ "credits_contract_address", - "description" + "description", + "owner" ], "properties": { "credits_contract_address": { @@ -24,14 +25,7 @@ ] }, "owner": { - "anyOf": [ - { - "$ref": "#/definitions/Addr" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Addr" } }, "definitions": { diff --git a/contracts/dao/voting/credits-vault/schema/instantiate_msg.json b/contracts/dao/voting/credits-vault/schema/instantiate_msg.json index 4b4e433e..1c087db0 100644 --- a/contracts/dao/voting/credits-vault/schema/instantiate_msg.json +++ b/contracts/dao/voting/credits-vault/schema/instantiate_msg.json @@ -4,7 +4,8 @@ "type": "object", "required": [ "credits_contract_address", - "description" + "description", + "owner" ], "properties": { "credits_contract_address": { @@ -20,14 +21,7 @@ ] }, "owner": { - "anyOf": [ - { - "$ref": "#/definitions/Admin" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Admin" } }, "definitions": { diff --git a/contracts/dao/voting/credits-vault/src/contract.rs b/contracts/dao/voting/credits-vault/src/contract.rs index 9ae15753..401a59ad 100644 --- a/contracts/dao/voting/credits-vault/src/contract.rs +++ b/contracts/dao/voting/credits-vault/src/contract.rs @@ -21,15 +21,10 @@ pub fn instantiate( ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - let owner = msg - .owner - .as_ref() - .map(|owner| match owner { - Admin::Address { addr } => deps.api.addr_validate(addr), - Admin::CoreModule {} => Ok(info.sender.clone()), - }) - .transpose()?; - + let owner = match msg.owner { + Admin::Address { addr } => deps.api.addr_validate(addr.as_str())?, + Admin::CoreModule {} => info.sender.clone(), + }; let manager = msg .manager .map(|manager| deps.api.addr_validate(&manager)) @@ -51,13 +46,7 @@ pub fn instantiate( .add_attribute("action", "instantiate") .add_attribute("description", config.description) .add_attribute("credits_contract_address", config.credits_contract_address) - .add_attribute( - "owner", - config - .owner - .map(|a| a.to_string()) - .unwrap_or_else(|| "None".to_string()), - ) + .add_attribute("owner", config.owner) .add_attribute( "manager", config @@ -95,12 +84,12 @@ pub fn execute_update_config( deps: DepsMut, info: MessageInfo, new_credits_contract_address: Option, - new_owner: Option, + new_owner: String, new_manager: Option, new_description: Option, ) -> Result { let mut config: Config = CONFIG.load(deps.storage)?; - if Some(info.sender.clone()) != config.owner && Some(info.sender.clone()) != config.manager { + if info.sender != config.owner && Some(info.sender.clone()) != config.manager { return Err(ContractError::Unauthorized {}); } @@ -108,19 +97,12 @@ pub fn execute_update_config( .map(|new_credits_contract_address| deps.api.addr_validate(&new_credits_contract_address)) .transpose()?; - let new_owner = new_owner - .as_ref() - .map(|owner| match owner { - Admin::Address { addr } => deps.api.addr_validate(addr), - Admin::CoreModule {} => Ok(info.sender.clone()), - }) - .transpose()?; - + let new_owner = deps.api.addr_validate(&new_owner)?; let new_manager = new_manager .map(|new_manager| deps.api.addr_validate(&new_manager)) .transpose()?; - if Some(info.sender) != config.owner && new_owner != config.owner { + if info.sender != config.owner && new_owner != config.owner { return Err(ContractError::OnlyOwnerCanChangeOwner {}); }; @@ -138,13 +120,7 @@ pub fn execute_update_config( .add_attribute("action", "update_config") .add_attribute("description", config.description) .add_attribute("credits_contract_address", config.credits_contract_address) - .add_attribute( - "owner", - config - .owner - .map(|a| a.to_string()) - .unwrap_or_else(|| "None".to_string()), - ) + .add_attribute("owner", config.owner) .add_attribute( "manager", config diff --git a/contracts/dao/voting/credits-vault/src/msg.rs b/contracts/dao/voting/credits-vault/src/msg.rs index a19b6944..a414d6ba 100644 --- a/contracts/dao/voting/credits-vault/src/msg.rs +++ b/contracts/dao/voting/credits-vault/src/msg.rs @@ -10,7 +10,7 @@ pub struct InstantiateMsg { // Description contains information that characterizes the vault. pub description: String, // Owner can update all configs including changing the owner. This will generally be a DAO. - pub owner: Option, + pub owner: Admin, // Manager can update all configs except changing the owner. This will generally be an operations multisig for a DAO. pub manager: Option, } @@ -20,7 +20,7 @@ pub struct InstantiateMsg { pub enum ExecuteMsg { UpdateConfig { credits_contract_address: Option, - owner: Option, + owner: String, manager: Option, description: Option, }, diff --git a/contracts/dao/voting/credits-vault/src/state.rs b/contracts/dao/voting/credits-vault/src/state.rs index 1847c9d2..da50f3a7 100644 --- a/contracts/dao/voting/credits-vault/src/state.rs +++ b/contracts/dao/voting/credits-vault/src/state.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; pub struct Config { pub credits_contract_address: Addr, pub description: String, - pub owner: Option, + pub owner: Addr, pub manager: Option, } diff --git a/contracts/dao/voting/credits-vault/src/tests.rs b/contracts/dao/voting/credits-vault/src/tests.rs index 385a0d08..699d897f 100644 --- a/contracts/dao/voting/credits-vault/src/tests.rs +++ b/contracts/dao/voting/credits-vault/src/tests.rs @@ -94,7 +94,7 @@ fn update_config( contract_addr: Addr, sender: &str, credits_contract_address: Option, - owner: Option, + owner: String, manager: Option, description: Option, ) -> anyhow::Result { @@ -154,9 +154,9 @@ fn test_instantiate() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::Address { + owner: Admin::Address { addr: DAO_ADDR.to_string(), - }), + }, manager: Some(ADDR1.to_string()), }, ); @@ -168,7 +168,9 @@ fn test_instantiate() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: None, + owner: Admin::Address { + addr: DAO_ADDR.to_string(), + }, manager: None, }, ); @@ -187,14 +189,14 @@ fn test_instantiate_dao_owner() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); let config = get_config(&mut app, addr); - assert_eq!(config.owner, Some(Addr::unchecked(DAO_ADDR))) + assert_eq!(config.owner, Addr::unchecked(DAO_ADDR)) } #[test] @@ -210,7 +212,7 @@ fn test_update_config_invalid_sender() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); @@ -221,9 +223,7 @@ fn test_update_config_invalid_sender() { addr, ADDR2, Some(credits_contract.to_string()), - Some(Admin::Address { - addr: ADDR1.to_string(), - }), + ADDR1.to_string(), Some(DAO_ADDR.to_string()), Some(NEW_DESCRIPTION.to_string()), ) @@ -243,7 +243,7 @@ fn test_update_config_non_owner_changes_owner() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); @@ -254,9 +254,7 @@ fn test_update_config_non_owner_changes_owner() { addr, ADDR1, Some(credits_contract.to_string()), - Some(Admin::Address { - addr: ADDR2.to_string(), - }), + ADDR2.to_string(), None, None, ) @@ -275,7 +273,7 @@ fn test_update_config_as_owner() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); @@ -286,9 +284,7 @@ fn test_update_config_as_owner() { addr.clone(), DAO_ADDR, Some(credits_contract.to_string()), - Some(Admin::Address { - addr: ADDR1.to_string(), - }), + ADDR1.to_string(), Some(DAO_ADDR.to_string()), Some(NEW_DESCRIPTION.to_string()), ) @@ -299,7 +295,7 @@ fn test_update_config_as_owner() { Config { credits_contract_address: Addr::unchecked(credits_contract), description: NEW_DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(ADDR1)), + owner: Addr::unchecked(ADDR1), manager: Some(Addr::unchecked(DAO_ADDR)), }, config @@ -318,7 +314,7 @@ fn test_update_config_as_manager() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); @@ -329,9 +325,7 @@ fn test_update_config_as_manager() { addr.clone(), ADDR1, Some(credits_contract.to_string()), - Some(Admin::Address { - addr: DAO_ADDR.to_string(), - }), + DAO_ADDR.to_string(), Some(ADDR2.to_string()), Some(NEW_DESCRIPTION.to_string()), ) @@ -342,7 +336,7 @@ fn test_update_config_as_manager() { Config { credits_contract_address: Addr::unchecked(credits_contract), description: NEW_DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR2)), }, config @@ -362,7 +356,7 @@ fn test_update_config_invalid_description() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); @@ -373,9 +367,7 @@ fn test_update_config_invalid_description() { addr, ADDR1, Some(credits_contract.to_string()), - Some(Admin::Address { - addr: DAO_ADDR.to_string(), - }), + DAO_ADDR.to_string(), Some(ADDR2.to_string()), Some(String::from("")), ) @@ -394,7 +386,7 @@ fn test_query_dao() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); @@ -416,7 +408,7 @@ fn test_query_info() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); @@ -438,7 +430,7 @@ fn test_query_get_config() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); @@ -449,7 +441,7 @@ fn test_query_get_config() { Config { credits_contract_address: Addr::unchecked(credits_contract), description: DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR1)), } ) @@ -467,7 +459,7 @@ fn test_voting_power_queries() { InstantiateMsg { credits_contract_address: credits_contract.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), }, ); diff --git a/contracts/dao/voting/lockdrop-vault/schema/execute_msg.json b/contracts/dao/voting/lockdrop-vault/schema/execute_msg.json index 2d5ba676..8a4467e0 100644 --- a/contracts/dao/voting/lockdrop-vault/schema/execute_msg.json +++ b/contracts/dao/voting/lockdrop-vault/schema/execute_msg.json @@ -13,7 +13,8 @@ "required": [ "description", "lockdrop_contract", - "name" + "name", + "owner" ], "properties": { "description": { @@ -32,10 +33,7 @@ "type": "string" }, "owner": { - "type": [ - "string", - "null" - ] + "type": "string" } } } diff --git a/contracts/dao/voting/lockdrop-vault/schema/get_config_response.json b/contracts/dao/voting/lockdrop-vault/schema/get_config_response.json index 828fac99..9b17c917 100644 --- a/contracts/dao/voting/lockdrop-vault/schema/get_config_response.json +++ b/contracts/dao/voting/lockdrop-vault/schema/get_config_response.json @@ -5,7 +5,8 @@ "required": [ "description", "lockdrop_contract", - "name" + "name", + "owner" ], "properties": { "description": { @@ -28,14 +29,7 @@ "type": "string" }, "owner": { - "anyOf": [ - { - "$ref": "#/definitions/Addr" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Addr" } }, "definitions": { diff --git a/contracts/dao/voting/lockdrop-vault/schema/instantiate_msg.json b/contracts/dao/voting/lockdrop-vault/schema/instantiate_msg.json index 00c6779d..551486ea 100644 --- a/contracts/dao/voting/lockdrop-vault/schema/instantiate_msg.json +++ b/contracts/dao/voting/lockdrop-vault/schema/instantiate_msg.json @@ -5,7 +5,8 @@ "required": [ "description", "lockdrop_contract", - "name" + "name", + "owner" ], "properties": { "description": { @@ -29,12 +30,9 @@ }, "owner": { "description": "Owner can update all configs including changing the owner. This will generally be a DAO.", - "anyOf": [ + "allOf": [ { "$ref": "#/definitions/Admin" - }, - { - "type": "null" } ] } diff --git a/contracts/dao/voting/lockdrop-vault/src/contract.rs b/contracts/dao/voting/lockdrop-vault/src/contract.rs index e27815a1..38f87826 100644 --- a/contracts/dao/voting/lockdrop-vault/src/contract.rs +++ b/contracts/dao/voting/lockdrop-vault/src/contract.rs @@ -27,14 +27,10 @@ pub fn instantiate( ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - let owner = msg - .owner - .as_ref() - .map(|owner| match owner { - Admin::Address { addr } => deps.api.addr_validate(addr), - Admin::CoreModule {} => Ok(info.sender.clone()), - }) - .transpose()?; + let owner = match msg.owner { + Admin::Address { addr } => deps.api.addr_validate(addr.as_str())?, + Admin::CoreModule {} => info.sender.clone(), + }; let manager = msg .manager .map(|manager| deps.api.addr_validate(&manager)) @@ -55,13 +51,7 @@ pub fn instantiate( .add_attribute("action", "instantiate") .add_attribute("name", config.name) .add_attribute("description", config.description) - .add_attribute( - "owner", - config - .owner - .map(|a| a.to_string()) - .unwrap_or_else(|| "None".to_string()), - ) + .add_attribute("owner", config.owner) .add_attribute("lockdrop_contract", config.lockdrop_contract) .add_attribute( "manager", @@ -120,31 +110,27 @@ pub fn execute_unbond( pub fn execute_update_config( deps: DepsMut, info: MessageInfo, - new_owner: Option, + new_owner: String, new_lockdrop_contract: String, new_manager: Option, new_name: String, new_description: String, ) -> Result { let mut config: Config = CONFIG.load(deps.storage)?; - if Some(info.sender.clone()) != config.owner && Some(info.sender.clone()) != config.manager { + if info.sender != config.owner && Some(info.sender.clone()) != config.manager { return Err(ContractError::Unauthorized {}); } - let new_owner = new_owner - .map(|new_owner| deps.api.addr_validate(&new_owner)) - .transpose()?; + let new_owner = deps.api.addr_validate(&new_owner)?; let new_lockdrop_contract = deps.api.addr_validate(&new_lockdrop_contract)?; let new_manager = new_manager .map(|new_manager| deps.api.addr_validate(&new_manager)) .transpose()?; - if Some(info.sender.clone()) != config.owner && new_owner != config.owner { + if info.sender != config.owner && new_owner != config.owner { return Err(ContractError::OnlyOwnerCanChangeOwner {}); }; - if Some(info.sender) != config.owner - && new_lockdrop_contract != config.clone().lockdrop_contract - { + if info.sender != config.owner && new_lockdrop_contract != config.clone().lockdrop_contract { return Err(ContractError::OnlyOwnerCanChangeLockdropContract {}); }; @@ -159,13 +145,7 @@ pub fn execute_update_config( Ok(Response::new() .add_attribute("action", "update_config") .add_attribute("description", config.description) - .add_attribute( - "owner", - config - .owner - .map(|a| a.to_string()) - .unwrap_or_else(|| "None".to_string()), - ) + .add_attribute("owner", config.owner) .add_attribute("lockdrop_contract", config.lockdrop_contract) .add_attribute( "manager", diff --git a/contracts/dao/voting/lockdrop-vault/src/tests.rs b/contracts/dao/voting/lockdrop-vault/src/tests.rs index 675012c6..5faa9577 100644 --- a/contracts/dao/voting/lockdrop-vault/src/tests.rs +++ b/contracts/dao/voting/lockdrop-vault/src/tests.rs @@ -106,7 +106,7 @@ fn update_config( app: &mut App, contract_addr: Addr, sender: &str, - owner: Option, + owner: String, lockdrop_contract: String, manager: Option, name: String, @@ -179,9 +179,9 @@ fn test_instantiate() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::Address { + owner: Admin::Address { addr: DAO_ADDR.to_string(), - }), + }, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -195,7 +195,9 @@ fn test_instantiate() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: None, + owner: Admin::Address { + addr: DAO_ADDR.to_string(), + }, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: None, }, @@ -214,7 +216,7 @@ fn test_instantiate_dao_owner() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -222,7 +224,7 @@ fn test_instantiate_dao_owner() { let config = get_config(&mut app, addr); - assert_eq!(config.owner, Some(Addr::unchecked(DAO_ADDR))) + assert_eq!(config.owner, Addr::unchecked(DAO_ADDR)) } #[test] @@ -236,7 +238,7 @@ fn test_bond() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -257,7 +259,7 @@ fn test_unbond() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -277,7 +279,7 @@ fn test_update_config_invalid_sender() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -288,7 +290,7 @@ fn test_update_config_invalid_sender() { &mut app, addr, ADDR2, - Some(ADDR1.to_string()), + ADDR1.to_string(), NEW_LOCKDROP_ADDR.to_string(), Some(DAO_ADDR.to_string()), NEW_NAME.to_string(), @@ -308,7 +310,7 @@ fn test_update_config_non_owner_changes_owner() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -319,7 +321,7 @@ fn test_update_config_non_owner_changes_owner() { &mut app, addr, ADDR1, - Some(ADDR2.to_string()), + ADDR2.to_string(), LOCKDROP_ADDR.to_string(), None, NAME.to_string(), @@ -339,7 +341,7 @@ fn test_update_config_non_owner_changes_lockdrop() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -350,7 +352,7 @@ fn test_update_config_non_owner_changes_lockdrop() { &mut app, addr, ADDR1, - Some(DAO_ADDR.to_string()), + DAO_ADDR.to_string(), NEW_LOCKDROP_ADDR.to_string(), None, NAME.to_string(), @@ -369,7 +371,7 @@ fn test_update_config_as_owner() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -380,7 +382,7 @@ fn test_update_config_as_owner() { &mut app, addr.clone(), DAO_ADDR, - Some(ADDR1.to_string()), + ADDR1.to_string(), NEW_LOCKDROP_ADDR.to_string(), Some(DAO_ADDR.to_string()), NEW_NAME.to_string(), @@ -393,7 +395,7 @@ fn test_update_config_as_owner() { Config { name: NEW_NAME.to_string(), description: NEW_DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(ADDR1)), + owner: Addr::unchecked(ADDR1), lockdrop_contract: Addr::unchecked(NEW_LOCKDROP_ADDR), manager: Some(Addr::unchecked(DAO_ADDR)), }, @@ -411,7 +413,7 @@ fn test_update_config_as_manager() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -424,7 +426,7 @@ fn test_update_config_as_manager() { &mut app, addr.clone(), ADDR1, - Some(DAO_ADDR.to_string()), + DAO_ADDR.to_string(), LOCKDROP_ADDR.to_string(), Some(ADDR2.to_string()), NEW_NAME.to_string(), @@ -440,7 +442,7 @@ fn test_update_config_as_manager() { Config { name: NEW_NAME.to_string(), description: NEW_DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), manager: Some(Addr::unchecked(ADDR2)), }, @@ -459,7 +461,7 @@ fn test_update_config_invalid_description() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -470,7 +472,7 @@ fn test_update_config_invalid_description() { &mut app, addr, ADDR1, - Some(DAO_ADDR.to_string()), + DAO_ADDR.to_string(), LOCKDROP_ADDR.to_string(), Some(ADDR2.to_string()), NEW_NAME.to_string(), @@ -490,7 +492,7 @@ fn test_update_config_invalid_name() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -501,7 +503,7 @@ fn test_update_config_invalid_name() { &mut app, addr, ADDR1, - Some(DAO_ADDR.to_string()), + DAO_ADDR.to_string(), LOCKDROP_ADDR.to_string(), Some(ADDR2.to_string()), String::from(""), @@ -520,7 +522,7 @@ fn test_query_dao() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -541,7 +543,7 @@ fn test_query_info() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -562,7 +564,7 @@ fn test_query_get_config() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -574,7 +576,7 @@ fn test_query_get_config() { Config { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), lockdrop_contract: Addr::unchecked(LOCKDROP_ADDR), manager: Some(Addr::unchecked(ADDR1)), } @@ -591,7 +593,7 @@ fn test_voting_power_at_height() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, @@ -612,7 +614,7 @@ fn test_total_power_at_height() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, lockdrop_contract: LOCKDROP_ADDR.to_string(), manager: Some(ADDR1.to_string()), }, diff --git a/contracts/dao/voting/neutron-vault/schema/execute_msg.json b/contracts/dao/voting/neutron-vault/schema/execute_msg.json index d738c975..206e7075 100644 --- a/contracts/dao/voting/neutron-vault/schema/execute_msg.json +++ b/contracts/dao/voting/neutron-vault/schema/execute_msg.json @@ -12,7 +12,8 @@ "type": "object", "required": [ "description", - "name" + "name", + "owner" ], "properties": { "description": { @@ -28,10 +29,7 @@ "type": "string" }, "owner": { - "type": [ - "string", - "null" - ] + "type": "string" } } } diff --git a/contracts/dao/voting/neutron-vault/schema/get_config_response.json b/contracts/dao/voting/neutron-vault/schema/get_config_response.json index 63d0ccdb..b8e505a7 100644 --- a/contracts/dao/voting/neutron-vault/schema/get_config_response.json +++ b/contracts/dao/voting/neutron-vault/schema/get_config_response.json @@ -5,7 +5,8 @@ "required": [ "denom", "description", - "name" + "name", + "owner" ], "properties": { "denom": { @@ -28,14 +29,7 @@ "type": "string" }, "owner": { - "anyOf": [ - { - "$ref": "#/definitions/Addr" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Addr" } }, "definitions": { diff --git a/contracts/dao/voting/neutron-vault/schema/instantiate_msg.json b/contracts/dao/voting/neutron-vault/schema/instantiate_msg.json index 7c3f42e6..3cc3e96b 100644 --- a/contracts/dao/voting/neutron-vault/schema/instantiate_msg.json +++ b/contracts/dao/voting/neutron-vault/schema/instantiate_msg.json @@ -5,7 +5,8 @@ "required": [ "denom", "description", - "name" + "name", + "owner" ], "properties": { "denom": { @@ -25,14 +26,7 @@ "type": "string" }, "owner": { - "anyOf": [ - { - "$ref": "#/definitions/Admin" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Admin" } }, "definitions": { diff --git a/contracts/dao/voting/neutron-vault/src/contract.rs b/contracts/dao/voting/neutron-vault/src/contract.rs index 53f3b2be..6011f353 100644 --- a/contracts/dao/voting/neutron-vault/src/contract.rs +++ b/contracts/dao/voting/neutron-vault/src/contract.rs @@ -28,14 +28,10 @@ pub fn instantiate( ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - let owner = msg - .owner - .as_ref() - .map(|owner| match owner { - Admin::Address { addr } => deps.api.addr_validate(addr), - Admin::CoreModule {} => Ok(info.sender.clone()), - }) - .transpose()?; + let owner = match msg.owner { + Admin::Address { addr } => deps.api.addr_validate(addr.as_str())?, + Admin::CoreModule {} => info.sender.clone(), + }; let manager = msg .manager .map(|manager| deps.api.addr_validate(&manager)) @@ -56,13 +52,7 @@ pub fn instantiate( .add_attribute("action", "instantiate") .add_attribute("name", config.name) .add_attribute("description", config.description) - .add_attribute( - "owner", - config - .owner - .map(|a| a.to_string()) - .unwrap_or_else(|| "None".to_string()), - ) + .add_attribute("owner", config.owner) .add_attribute( "manager", config @@ -158,24 +148,22 @@ pub fn execute_unbond( pub fn execute_update_config( deps: DepsMut, info: MessageInfo, - new_owner: Option, + new_owner: String, new_manager: Option, new_name: String, new_description: String, ) -> Result { let mut config: Config = CONFIG.load(deps.storage)?; - if Some(info.sender.clone()) != config.owner && Some(info.sender.clone()) != config.manager { + if info.sender != config.owner && Some(info.sender.clone()) != config.manager { return Err(ContractError::Unauthorized {}); } - let new_owner = new_owner - .map(|new_owner| deps.api.addr_validate(&new_owner)) - .transpose()?; + let new_owner = deps.api.addr_validate(&new_owner)?; let new_manager = new_manager .map(|new_manager| deps.api.addr_validate(&new_manager)) .transpose()?; - if Some(info.sender) != config.owner && new_owner != config.owner { + if info.sender != config.owner && new_owner != config.owner { return Err(ContractError::OnlyOwnerCanChangeOwner {}); }; @@ -189,13 +177,7 @@ pub fn execute_update_config( Ok(Response::new() .add_attribute("action", "update_config") .add_attribute("description", config.description) - .add_attribute( - "owner", - config - .owner - .map(|a| a.to_string()) - .unwrap_or_else(|| "None".to_string()), - ) + .add_attribute("owner", config.owner) .add_attribute( "manager", config diff --git a/contracts/dao/voting/neutron-vault/src/msg.rs b/contracts/dao/voting/neutron-vault/src/msg.rs index bb54dc1a..883c9430 100644 --- a/contracts/dao/voting/neutron-vault/src/msg.rs +++ b/contracts/dao/voting/neutron-vault/src/msg.rs @@ -10,7 +10,7 @@ pub struct InstantiateMsg { // Description contains information that characterizes the vault. pub description: String, // Owner can update all configs including changing the owner. This will generally be a DAO. - pub owner: Option, + pub owner: Admin, // Manager can update all configs except changing the owner. This will generally be an operations multisig for a DAO. pub manager: Option, // Token denom e.g. untrn, or some ibc denom @@ -22,10 +22,10 @@ pub struct InstantiateMsg { #[serde(rename_all = "snake_case")] pub enum ExecuteMsg { UpdateConfig { - owner: Option, - manager: Option, name: String, description: String, + owner: String, + manager: Option, }, } diff --git a/contracts/dao/voting/neutron-vault/src/state.rs b/contracts/dao/voting/neutron-vault/src/state.rs index c955f7e0..c09c0b85 100644 --- a/contracts/dao/voting/neutron-vault/src/state.rs +++ b/contracts/dao/voting/neutron-vault/src/state.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; pub struct Config { pub name: String, pub description: String, - pub owner: Option, + pub owner: Addr, pub manager: Option, pub denom: String, } @@ -56,7 +56,7 @@ mod tests { let cfg_ok = Config { name: String::from("name"), description: String::from("description"), - owner: Some(Addr::unchecked("owner")), + owner: Addr::unchecked("owner"), manager: Some(Addr::unchecked("manager")), denom: String::from("denom"), }; @@ -65,7 +65,7 @@ mod tests { let cfg_empty_name = Config { name: String::from(""), description: String::from("description"), - owner: Some(Addr::unchecked("owner")), + owner: Addr::unchecked("owner"), manager: Some(Addr::unchecked("manager")), denom: String::from("denom"), }; @@ -77,7 +77,7 @@ mod tests { let cfg_empty_description = Config { name: String::from("name"), description: String::from(""), - owner: Some(Addr::unchecked("owner")), + owner: Addr::unchecked("owner"), manager: Some(Addr::unchecked("manager")), denom: String::from("denom"), }; @@ -89,7 +89,7 @@ mod tests { let cfg_empty_denom = Config { name: String::from("name"), description: String::from("description"), - owner: Some(Addr::unchecked("owner")), + owner: Addr::unchecked("owner"), manager: Some(Addr::unchecked("manager")), denom: String::from(""), }; diff --git a/contracts/dao/voting/neutron-vault/src/tests.rs b/contracts/dao/voting/neutron-vault/src/tests.rs index 5016bae8..6c7ee83b 100644 --- a/contracts/dao/voting/neutron-vault/src/tests.rs +++ b/contracts/dao/voting/neutron-vault/src/tests.rs @@ -125,7 +125,7 @@ fn update_config( app: &mut App, contract_addr: Addr, sender: &str, - owner: Option, + owner: String, manager: Option, name: String, description: String, @@ -212,9 +212,9 @@ fn test_instantiate() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::Address { + owner: Admin::Address { addr: DAO_ADDR.to_string(), - }), + }, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -228,7 +228,9 @@ fn test_instantiate() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: None, + owner: Admin::Address { + addr: DAO_ADDR.to_string(), + }, manager: None, denom: DENOM.to_string(), }, @@ -247,7 +249,7 @@ fn test_instantiate_dao_owner() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -255,7 +257,7 @@ fn test_instantiate_dao_owner() { let config = get_config(&mut app, addr); - assert_eq!(config.owner, Some(Addr::unchecked(DAO_ADDR))) + assert_eq!(config.owner, Addr::unchecked(DAO_ADDR)) } #[test] @@ -269,7 +271,7 @@ fn test_bond_invalid_denom() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -289,7 +291,7 @@ fn test_bond_valid_denom() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -319,7 +321,7 @@ fn test_unbond_none_bonded() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -339,7 +341,7 @@ fn test_unbond_invalid_balance() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -363,7 +365,7 @@ fn test_unbond() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -409,7 +411,7 @@ fn test_update_config_invalid_sender() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -420,7 +422,7 @@ fn test_update_config_invalid_sender() { &mut app, addr, ADDR2, - Some(ADDR1.to_string()), + ADDR1.to_string(), Some(DAO_ADDR.to_string()), NEW_NAME.to_string(), NEW_DESCRIPTION.to_string(), @@ -439,7 +441,7 @@ fn test_update_config_non_owner_changes_owner() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -450,7 +452,7 @@ fn test_update_config_non_owner_changes_owner() { &mut app, addr, ADDR1, - Some(ADDR2.to_string()), + ADDR2.to_string(), None, NEW_NAME.to_string(), NEW_DESCRIPTION.to_string(), @@ -468,7 +470,7 @@ fn test_update_config_as_owner() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -479,7 +481,7 @@ fn test_update_config_as_owner() { &mut app, addr.clone(), DAO_ADDR, - Some(ADDR1.to_string()), + ADDR1.to_string(), Some(DAO_ADDR.to_string()), NEW_NAME.to_string(), NEW_DESCRIPTION.to_string(), @@ -491,7 +493,7 @@ fn test_update_config_as_owner() { Config { name: NEW_NAME.to_string(), description: NEW_DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(ADDR1)), + owner: Addr::unchecked(ADDR1), manager: Some(Addr::unchecked(DAO_ADDR)), denom: DENOM.to_string(), }, @@ -509,7 +511,7 @@ fn test_update_config_as_manager() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -522,7 +524,7 @@ fn test_update_config_as_manager() { &mut app, addr.clone(), ADDR1, - Some(DAO_ADDR.to_string()), + DAO_ADDR.to_string(), Some(ADDR2.to_string()), NEW_NAME.to_string(), NEW_DESCRIPTION.to_string(), @@ -537,7 +539,7 @@ fn test_update_config_as_manager() { Config { name: NEW_NAME.to_string(), description: NEW_DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR2)), denom: DENOM.to_string(), }, @@ -556,7 +558,7 @@ fn test_update_config_invalid_description() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -567,7 +569,7 @@ fn test_update_config_invalid_description() { &mut app, addr, ADDR1, - Some(DAO_ADDR.to_string()), + DAO_ADDR.to_string(), Some(ADDR2.to_string()), NEW_NAME.to_string(), String::from(""), @@ -586,7 +588,7 @@ fn test_update_config_invalid_name() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -597,7 +599,7 @@ fn test_update_config_invalid_name() { &mut app, addr, ADDR1, - Some(DAO_ADDR.to_string()), + DAO_ADDR.to_string(), Some(ADDR2.to_string()), String::from(""), NEW_DESCRIPTION.to_string(), @@ -615,7 +617,7 @@ fn test_query_dao() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -636,7 +638,7 @@ fn test_query_info() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -657,7 +659,7 @@ fn test_query_get_config() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -669,7 +671,7 @@ fn test_query_get_config() { Config { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR1)), denom: DENOM.to_string(), } @@ -686,7 +688,7 @@ fn test_voting_power_queries() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, @@ -793,7 +795,7 @@ fn test_query_list_bonders() { InstantiateMsg { name: NAME.to_string(), description: DESCRIPTION.to_string(), - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), denom: DENOM.to_string(), }, diff --git a/contracts/dao/voting/neutron-voting-registry/schema/execute_msg.json b/contracts/dao/voting/neutron-voting-registry/schema/execute_msg.json index 9586090f..9fbd58c0 100644 --- a/contracts/dao/voting/neutron-voting-registry/schema/execute_msg.json +++ b/contracts/dao/voting/neutron-voting-registry/schema/execute_msg.json @@ -50,6 +50,9 @@ "properties": { "update_config": { "type": "object", + "required": [ + "owner" + ], "properties": { "manager": { "type": [ @@ -58,10 +61,7 @@ ] }, "owner": { - "type": [ - "string", - "null" - ] + "type": "string" } } } diff --git a/contracts/dao/voting/neutron-voting-registry/schema/get_config_response.json b/contracts/dao/voting/neutron-voting-registry/schema/get_config_response.json index 4278fdac..993a2152 100644 --- a/contracts/dao/voting/neutron-voting-registry/schema/get_config_response.json +++ b/contracts/dao/voting/neutron-voting-registry/schema/get_config_response.json @@ -3,6 +3,7 @@ "title": "GetConfigResponse", "type": "object", "required": [ + "owner", "voting_vaults" ], "properties": { @@ -17,14 +18,7 @@ ] }, "owner": { - "anyOf": [ - { - "$ref": "#/definitions/Addr" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Addr" }, "voting_vaults": { "type": "array", diff --git a/contracts/dao/voting/neutron-voting-registry/schema/instantiate_msg.json b/contracts/dao/voting/neutron-voting-registry/schema/instantiate_msg.json index 74c9ce50..885b29cd 100644 --- a/contracts/dao/voting/neutron-voting-registry/schema/instantiate_msg.json +++ b/contracts/dao/voting/neutron-voting-registry/schema/instantiate_msg.json @@ -3,6 +3,7 @@ "title": "InstantiateMsg", "type": "object", "required": [ + "owner", "voting_vaults" ], "properties": { @@ -13,14 +14,7 @@ ] }, "owner": { - "anyOf": [ - { - "$ref": "#/definitions/Admin" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/Admin" }, "voting_vaults": { "type": "array", diff --git a/contracts/dao/voting/neutron-voting-registry/src/contract.rs b/contracts/dao/voting/neutron-voting-registry/src/contract.rs index 11a68f16..71ba7c9e 100644 --- a/contracts/dao/voting/neutron-voting-registry/src/contract.rs +++ b/contracts/dao/voting/neutron-voting-registry/src/contract.rs @@ -24,14 +24,10 @@ pub fn instantiate( ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - let owner = msg - .owner - .as_ref() - .map(|owner| match owner { - Admin::Address { addr } => deps.api.addr_validate(addr), - Admin::CoreModule {} => Ok(info.sender.clone()), - }) - .transpose()?; + let owner = match msg.owner { + Admin::Address { addr } => deps.api.addr_validate(addr.as_str())?, + Admin::CoreModule {} => info.sender.clone(), + }; let manager = msg .manager .map(|manager| deps.api.addr_validate(&manager)) @@ -53,13 +49,7 @@ pub fn instantiate( Ok(Response::new() .add_attribute("action", "instantiate") - .add_attribute( - "owner", - config - .owner - .map(|a| a.to_string()) - .unwrap_or_else(|| "None".to_string()), - ) + .add_attribute("owner", config.owner) .add_attribute( "manager", config @@ -97,7 +87,7 @@ pub fn execute_add_voting_vault( ) -> Result { let mut config: Config = CONFIG.load(deps.storage)?; - if Some(info.sender) != config.owner { + if info.sender != config.owner { return Err(ContractError::Unauthorized {}); } @@ -120,7 +110,7 @@ pub fn execute_remove_voting_vault( ) -> Result { let mut config: Config = CONFIG.load(deps.storage)?; - if Some(info.sender) != config.owner { + if info.sender != config.owner { return Err(ContractError::Unauthorized {}); } @@ -142,22 +132,20 @@ pub fn execute_remove_voting_vault( pub fn execute_update_config( deps: DepsMut, info: MessageInfo, - new_owner: Option, + new_owner: String, new_manager: Option, ) -> Result { let mut config: Config = CONFIG.load(deps.storage)?; - if Some(info.sender.clone()) != config.owner && Some(info.sender.clone()) != config.manager { + if info.sender != config.owner && Some(info.sender.clone()) != config.manager { return Err(ContractError::Unauthorized {}); } - let new_owner = new_owner - .map(|new_owner| deps.api.addr_validate(&new_owner)) - .transpose()?; + let new_owner = deps.api.addr_validate(&new_owner)?; let new_manager = new_manager .map(|new_manager| deps.api.addr_validate(&new_manager)) .transpose()?; - if Some(info.sender) != config.owner && new_owner != config.owner { + if info.sender != config.owner && new_owner != config.owner { return Err(ContractError::OnlyOwnerCanChangeOwner {}); }; @@ -167,13 +155,7 @@ pub fn execute_update_config( CONFIG.save(deps.storage, &config)?; Ok(Response::new() .add_attribute("action", "update_config") - .add_attribute( - "owner", - config - .owner - .map(|a| a.to_string()) - .unwrap_or_else(|| "None".to_string()), - ) + .add_attribute("owner", config.owner) .add_attribute( "manager", config @@ -238,7 +220,9 @@ pub fn query_voting_power_at_height( address: address.clone(), }, )?; - total_power.power += total_power_single_vault.power; + total_power.power = total_power + .power + .checked_add(total_power_single_vault.power)?; total_power.height = total_power_single_vault.height; } @@ -260,7 +244,9 @@ pub fn query_total_power_at_height( let total_power_single_vault: TotalPowerAtHeightResponse = deps .querier .query_wasm_smart(vault, &voting::Query::TotalPowerAtHeight { height })?; - total_power.power += total_power_single_vault.power; + total_power.power = total_power + .power + .checked_add(total_power_single_vault.power)?; total_power.height = total_power_single_vault.height; } diff --git a/contracts/dao/voting/neutron-voting-registry/src/msg.rs b/contracts/dao/voting/neutron-voting-registry/src/msg.rs index 46e85038..29a01081 100644 --- a/contracts/dao/voting/neutron-voting-registry/src/msg.rs +++ b/contracts/dao/voting/neutron-voting-registry/src/msg.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] pub struct InstantiateMsg { // Owner can update all configs including changing the owner. This will generally be a DAO. - pub owner: Option, + pub owner: Admin, // Manager can update all configs except changing the owner. This will generally be an operations multisig for a DAO. pub manager: Option, // A list of addresses of relative voting vault contracts. @@ -23,7 +23,7 @@ pub enum ExecuteMsg { old_voting_vault_contract: String, }, UpdateConfig { - owner: Option, + owner: String, manager: Option, }, } diff --git a/contracts/dao/voting/neutron-voting-registry/src/state.rs b/contracts/dao/voting/neutron-voting-registry/src/state.rs index 273adf6f..b7975fc2 100644 --- a/contracts/dao/voting/neutron-voting-registry/src/state.rs +++ b/contracts/dao/voting/neutron-voting-registry/src/state.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)] pub struct Config { - pub owner: Option, + pub owner: Addr, pub manager: Option, pub voting_vaults: Vec, } diff --git a/contracts/dao/voting/neutron-voting-registry/src/tests.rs b/contracts/dao/voting/neutron-voting-registry/src/tests.rs index 0dd28c7c..561d25fe 100644 --- a/contracts/dao/voting/neutron-voting-registry/src/tests.rs +++ b/contracts/dao/voting/neutron-voting-registry/src/tests.rs @@ -86,7 +86,7 @@ fn update_config( app: &mut App, contract_addr: Addr, sender: &str, - owner: Option, + owner: String, manager: Option, ) -> anyhow::Result { app.execute_contract( @@ -144,9 +144,9 @@ fn test_instantiate() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::Address { + owner: Admin::Address { addr: DAO_ADDR.to_string(), - }), + }, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -157,7 +157,9 @@ fn test_instantiate() { &mut app, vault_id, InstantiateMsg { - owner: None, + owner: Admin::Address { + addr: DAO_ADDR.to_string(), + }, manager: None, voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -173,9 +175,9 @@ fn test_instantiate_multiple_vaults() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::Address { + owner: Admin::Address { addr: DAO_ADDR.to_string(), - }), + }, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string(), String::from("another_vault")], }, @@ -196,7 +198,7 @@ fn test_instantiate_dao_owner() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -204,7 +206,7 @@ fn test_instantiate_dao_owner() { let config = get_config(&mut app, addr); - assert_eq!(config.owner, Some(Addr::unchecked(DAO_ADDR))) + assert_eq!(config.owner, Addr::unchecked(DAO_ADDR)) } #[test] @@ -216,7 +218,7 @@ fn test_update_config_invalid_sender() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -227,7 +229,7 @@ fn test_update_config_invalid_sender() { &mut app, addr, ADDR2, - Some(ADDR1.to_string()), + ADDR1.to_string(), Some(DAO_ADDR.to_string()), ) .unwrap(); @@ -242,14 +244,14 @@ fn test_update_config_non_owner_changes_owner() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, ); // ADDR1 is the manager so cannot change the owner - update_config(&mut app, addr, ADDR1, Some(ADDR2.to_string()), None).unwrap(); + update_config(&mut app, addr, ADDR1, ADDR2.to_string(), None).unwrap(); } #[test] @@ -260,7 +262,7 @@ fn test_update_config_as_owner() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -271,7 +273,7 @@ fn test_update_config_as_owner() { &mut app, addr.clone(), DAO_ADDR, - Some(ADDR1.to_string()), + ADDR1.to_string(), Some(DAO_ADDR.to_string()), ) .unwrap(); @@ -279,7 +281,7 @@ fn test_update_config_as_owner() { let config = get_config(&mut app, addr); assert_eq!( Config { - owner: Some(Addr::unchecked(ADDR1)), + owner: Addr::unchecked(ADDR1), manager: Some(Addr::unchecked(DAO_ADDR)), voting_vaults: vec![Addr::unchecked(VAULT_ADDR)] }, @@ -295,7 +297,7 @@ fn test_update_config_as_manager() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -306,7 +308,7 @@ fn test_update_config_as_manager() { &mut app, addr.clone(), ADDR1, - Some(DAO_ADDR.to_string()), + DAO_ADDR.to_string(), Some(ADDR2.to_string()), ) .unwrap(); @@ -314,7 +316,7 @@ fn test_update_config_as_manager() { let config = get_config(&mut app, addr); assert_eq!( Config { - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR2)), voting_vaults: vec![Addr::unchecked(VAULT_ADDR)] }, @@ -330,7 +332,7 @@ fn test_query_dao() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -349,7 +351,7 @@ fn test_query_info() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -368,7 +370,7 @@ fn test_query_get_config() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -378,7 +380,7 @@ fn test_query_get_config() { assert_eq!( config, Config { - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR1)), voting_vaults: vec![Addr::unchecked(VAULT_ADDR)] } @@ -393,7 +395,7 @@ fn test_add_vault_owner() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -406,7 +408,7 @@ fn test_add_vault_owner() { assert_eq!( config, Config { - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR1)), voting_vaults: vec![Addr::unchecked(VAULT_ADDR), Addr::unchecked(new_vault)] } @@ -421,7 +423,7 @@ fn test_remove_vault_owner() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -434,7 +436,7 @@ fn test_remove_vault_owner() { assert_eq!( config, Config { - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR1)), voting_vaults: vec![Addr::unchecked(VAULT_ADDR), Addr::unchecked(new_vault)] } @@ -445,7 +447,7 @@ fn test_remove_vault_owner() { assert_eq!( config, Config { - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR1)), voting_vaults: vec![Addr::unchecked(new_vault)] } @@ -461,7 +463,7 @@ fn test_add_vault_manager() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, @@ -474,7 +476,7 @@ fn test_add_vault_manager() { assert_eq!( config, Config { - owner: Some(Addr::unchecked(DAO_ADDR)), + owner: Addr::unchecked(DAO_ADDR), manager: Some(Addr::unchecked(ADDR1)), voting_vaults: vec![Addr::unchecked(VAULT_ADDR)] } @@ -490,7 +492,7 @@ fn test_remove_last_vault_owner() { &mut app, vault_id, InstantiateMsg { - owner: Some(Admin::CoreModule {}), + owner: Admin::CoreModule {}, manager: Some(ADDR1.to_string()), voting_vaults: vec![VAULT_ADDR.to_string()], }, diff --git a/contracts/subdaos/cwd-subdao-timelock-single/src/contract.rs b/contracts/subdaos/cwd-subdao-timelock-single/src/contract.rs index 6e21c1e3..343fcdcd 100644 --- a/contracts/subdaos/cwd-subdao-timelock-single/src/contract.rs +++ b/contracts/subdaos/cwd-subdao-timelock-single/src/contract.rs @@ -201,8 +201,6 @@ pub fn execute_update_config( config.timelock_duration = timelock_duration; } - // TODO(oopcode): implement updating the .sudbao parameter. - CONFIG.save(deps.storage, &config)?; Ok(Response::new() .add_attribute("action", "update_config") diff --git a/contracts/tokenomics/distribution/src/contract.rs b/contracts/tokenomics/distribution/src/contract.rs index 7108d201..fb0562de 100644 --- a/contracts/tokenomics/distribution/src/contract.rs +++ b/contracts/tokenomics/distribution/src/contract.rs @@ -5,7 +5,7 @@ use crate::state::{Config, CONFIG, FUND_COUNTER, PAUSED_UNTIL, PENDING_DISTRIBUT use cosmwasm_std::entry_point; use cosmwasm_std::{ to_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Order, - Response, StdError, StdResult, Storage, Uint128, + Response, StdResult, Storage, Uint128, }; use exec_control::pause::{ can_pause, can_unpause, validate_duration, PauseError, PauseInfoResponse, @@ -163,15 +163,17 @@ pub fn execute_fund(deps: DepsMut, info: MessageInfo) -> Result for ContractError { - fn from(o: OverflowError) -> Self { - StdError::from(o).into() - } -} diff --git a/contracts/tokenomics/distribution/src/msg.rs b/contracts/tokenomics/distribution/src/msg.rs index 9feafc46..45985cd1 100644 --- a/contracts/tokenomics/distribution/src/msg.rs +++ b/contracts/tokenomics/distribution/src/msg.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{Addr, Uint128}; +use cosmwasm_std::Uint128; use cwd_macros::{pausable, pausable_query}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -40,17 +40,3 @@ pub enum QueryMsg { Pending {}, Shares {}, } - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct StatsResponse { - pub total_distributed: Uint128, - pub last_balance: Uint128, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct ShareResponse { - address: Addr, - shares: Uint128, -} diff --git a/contracts/tokenomics/treasury/src/contract.rs b/contracts/tokenomics/treasury/src/contract.rs index 2038f592..5f911f72 100644 --- a/contracts/tokenomics/treasury/src/contract.rs +++ b/contracts/tokenomics/treasury/src/contract.rs @@ -3,8 +3,8 @@ use crate::error::ContractError; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - coins, to_binary, Addr, BankMsg, Binary, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, - Response, StdResult, Uint128, WasmMsg, + coins, to_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, + StdResult, Uint128, WasmMsg, }; use exec_control::pause::{ can_pause, can_unpause, validate_duration, PauseError, PauseInfoResponse, @@ -31,18 +31,6 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> Result { - if (msg.distribution_rate > Decimal::one()) || (msg.distribution_rate < Decimal::zero()) { - return Err(ContractError::InvalidDistributionRate( - "distribution_rate must be between 0 and 1".to_string(), - )); - } - - if msg.vesting_denominator == 0 { - return Err(ContractError::InvalidVestingDenominator( - "vesting_denominator must be more than zero".to_string(), - )); - } - let config = Config { denom: msg.denom, min_period: msg.min_period, @@ -53,6 +41,7 @@ pub fn instantiate( security_dao_address: deps.api.addr_validate(&msg.security_dao_address)?, vesting_denominator: msg.vesting_denominator, }; + config.validate()?; CONFIG.save(deps.storage, &config)?; TOTAL_DISTRIBUTED.save(deps.storage, &Uint128::zero())?; TOTAL_RESERVED.save(deps.storage, &Uint128::zero())?; @@ -231,22 +220,13 @@ pub fn execute_update_config( config.security_dao_address = deps.api.addr_validate(security_dao_address.as_str())?; } if let Some(distribution_rate) = distribution_params.distribution_rate { - if (distribution_rate > Decimal::one()) || (distribution_rate < Decimal::zero()) { - return Err(ContractError::InvalidDistributionRate( - "distribution_rate must be between 0 and 1".to_string(), - )); - } config.distribution_rate = distribution_rate; } if let Some(vesting_denominator) = distribution_params.vesting_denominator { - if vesting_denominator == 0 { - return Err(ContractError::InvalidVestingDenominator( - "vesting_denominator must be more than zero".to_string(), - )); - } config.vesting_denominator = vesting_denominator; } + config.validate()?; CONFIG.save(deps.storage, &config)?; Ok(Response::new() diff --git a/contracts/tokenomics/treasury/src/error.rs b/contracts/tokenomics/treasury/src/error.rs index 726e4fbc..2bb2f131 100644 --- a/contracts/tokenomics/treasury/src/error.rs +++ b/contracts/tokenomics/treasury/src/error.rs @@ -16,11 +16,14 @@ pub enum ContractError { #[error("No funds to distribute")] NoFundsToDistribute {}, - #[error("Invalid distribution rate")] - InvalidDistributionRate(String), + #[error("distribution_rate must be between 0 and 1")] + InvalidDistributionRate {}, - #[error("Invalid vesting denominator")] - InvalidVestingDenominator(String), + #[error("vesting_denominator must be greater than zero")] + InvalidVestingDenominator {}, + + #[error("min_period must be greater than zero")] + InvalidMinPeriod {}, #[error("Too soon to distribute")] TooSoonToDistribute {}, diff --git a/contracts/tokenomics/treasury/src/state.rs b/contracts/tokenomics/treasury/src/state.rs index 3430fd98..3178aab3 100644 --- a/contracts/tokenomics/treasury/src/state.rs +++ b/contracts/tokenomics/treasury/src/state.rs @@ -1,3 +1,4 @@ +use crate::error::ContractError; use cosmwasm_std::{Addr, Decimal, Uint128}; use cw_storage_plus::Item; use schemars::JsonSchema; @@ -21,10 +22,28 @@ pub struct Config { /// Address of the security DAO contract pub security_dao_address: Addr, - // Denomintator used int the vesting release function + // Denominator used in the vesting release function pub vesting_denominator: u128, } +impl Config { + pub fn validate(&self) -> Result<(), ContractError> { + if (self.distribution_rate > Decimal::one()) || (self.distribution_rate < Decimal::zero()) { + return Err(ContractError::InvalidDistributionRate {}); + } + + if self.vesting_denominator == 0 { + return Err(ContractError::InvalidVestingDenominator {}); + } + + if self.min_period == 0 { + return Err(ContractError::InvalidMinPeriod {}); + } + + Ok(()) + } +} + pub const TOTAL_DISTRIBUTED: Item = Item::new("total_distributed"); pub const TOTAL_RESERVED: Item = Item::new("total_reserved"); @@ -33,5 +52,74 @@ pub const LAST_DISTRIBUTION_TIME: Item = Item::new("last_grab_time"); pub const CONFIG: Item = Item::new("config"); -/// The height the subDAO is paused until. If it's None, the subDAO is not paused. +/// The height the contract is paused until. If it's None, the contract is not paused. pub const PAUSED_UNTIL: Item> = Item::new("paused_until"); + +#[cfg(test)] +mod tests { + use super::Config; + use crate::error::ContractError; + use cosmwasm_std::Addr; + use cosmwasm_std::Decimal; + use std::str::FromStr; + + #[test] + fn test_config_validate() { + let cfg_ok = Config { + distribution_rate: Decimal::from_str("0.11").unwrap(), + distribution_contract: Addr::unchecked("owner"), + reserve_contract: Addr::unchecked("owner"), + min_period: 3600, + denom: String::from("untrn"), + main_dao_address: Addr::unchecked("owner"), + security_dao_address: Addr::unchecked("owner"), + vesting_denominator: 100_000_000_000u128, + }; + assert_eq!(cfg_ok.validate(), Ok(())); + + let cfg_invalid_distr = Config { + distribution_rate: Decimal::from_str("111.11").unwrap(), + distribution_contract: Addr::unchecked("owner"), + reserve_contract: Addr::unchecked("owner"), + min_period: 3600, + denom: String::from("untrn"), + main_dao_address: Addr::unchecked("owner"), + security_dao_address: Addr::unchecked("owner"), + vesting_denominator: 100_000_000_000u128, + }; + assert_eq!( + cfg_invalid_distr.validate(), + Err(ContractError::InvalidDistributionRate {}) + ); + + let cfg_invalid_vesting_denom = Config { + distribution_rate: Decimal::from_str("0.11").unwrap(), + distribution_contract: Addr::unchecked("owner"), + reserve_contract: Addr::unchecked("owner"), + min_period: 3600, + denom: String::from("untrn"), + main_dao_address: Addr::unchecked("owner"), + security_dao_address: Addr::unchecked("owner"), + vesting_denominator: 0u128, + }; + assert_eq!( + cfg_invalid_vesting_denom.validate(), + Err(ContractError::InvalidVestingDenominator {}) + ); + + let cfg_invalid_min_period = Config { + distribution_rate: Decimal::from_str("0.11").unwrap(), + distribution_contract: Addr::unchecked("owner"), + reserve_contract: Addr::unchecked("owner"), + min_period: 0, + denom: String::from("untrn"), + main_dao_address: Addr::unchecked("owner"), + security_dao_address: Addr::unchecked("owner"), + vesting_denominator: 100_000_000_000u128, + }; + assert_eq!( + cfg_invalid_min_period.validate(), + Err(ContractError::InvalidMinPeriod {}) + ); + } +} diff --git a/packages/neutron-lockdrop-vault/src/msg.rs b/packages/neutron-lockdrop-vault/src/msg.rs index fc1edbb5..0d37cbac 100644 --- a/packages/neutron-lockdrop-vault/src/msg.rs +++ b/packages/neutron-lockdrop-vault/src/msg.rs @@ -12,7 +12,7 @@ pub struct InstantiateMsg { /// The lockdrop contract behind the vault. pub lockdrop_contract: String, /// Owner can update all configs including changing the owner. This will generally be a DAO. - pub owner: Option, + pub owner: Admin, /// Manager can update configs except changing the owner and the lockdrop contract. /// This will generally be an operations multisig for a DAO. pub manager: Option, @@ -23,7 +23,7 @@ pub struct InstantiateMsg { #[serde(rename_all = "snake_case")] pub enum ExecuteMsg { UpdateConfig { - owner: Option, + owner: String, lockdrop_contract: String, manager: Option, name: String, diff --git a/packages/neutron-lockdrop-vault/src/types.rs b/packages/neutron-lockdrop-vault/src/types.rs index 1e5c508b..84803a76 100644 --- a/packages/neutron-lockdrop-vault/src/types.rs +++ b/packages/neutron-lockdrop-vault/src/types.rs @@ -8,7 +8,7 @@ pub struct Config { pub name: String, pub description: String, pub lockdrop_contract: Addr, - pub owner: Option, + pub owner: Addr, pub manager: Option, } @@ -37,7 +37,7 @@ mod tests { name: String::from("name"), description: String::from("description"), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - owner: Some(Addr::unchecked("owner")), + owner: Addr::unchecked("owner"), manager: Some(Addr::unchecked("manager")), }; assert_eq!(cfg_ok.validate(), Ok(())); @@ -46,7 +46,7 @@ mod tests { name: String::from(""), description: String::from("description"), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - owner: Some(Addr::unchecked("owner")), + owner: Addr::unchecked("owner"), manager: Some(Addr::unchecked("manager")), }; assert_eq!( @@ -58,7 +58,7 @@ mod tests { name: String::from("name"), description: String::from(""), lockdrop_contract: Addr::unchecked("lockdrop_contract"), - owner: Some(Addr::unchecked("owner")), + owner: Addr::unchecked("owner"), manager: Some(Addr::unchecked("manager")), }; assert_eq!(