From a6a80d4f02d76ca67dbfa53965f0ec896bc66ba7 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 27 Aug 2024 16:50:25 +0400 Subject: [PATCH 1/2] add and remove schedule msgs can be modified in chain manager --- .../dao/neutron-chain-manager/src/contract.rs | 29 ++++++++++--------- ...le_param_types.rs => cron_module_types.rs} | 2 ++ .../dao/neutron-chain-manager/src/lib.rs | 2 +- .../src/testing/mock_querier.rs | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) rename contracts/dao/neutron-chain-manager/src/{cron_module_param_types.rs => cron_module_types.rs} (90%) diff --git a/contracts/dao/neutron-chain-manager/src/contract.rs b/contracts/dao/neutron-chain-manager/src/contract.rs index 9dbfa86e..909ba687 100644 --- a/contracts/dao/neutron-chain-manager/src/contract.rs +++ b/contracts/dao/neutron-chain-manager/src/contract.rs @@ -1,6 +1,6 @@ -use crate::cron_module_param_types::{ - MsgUpdateParamsCron, ParamsRequestCron, ParamsResponseCron, MSG_TYPE_UPDATE_PARAMS_CRON, - PARAMS_QUERY_PATH_CRON, +use crate::cron_module_types::{ + MsgUpdateParamsCron, ParamsRequestCron, ParamsResponseCron, MSG_TYPE_ADD_SCHEDULE, + MSG_TYPE_REMOVE_SCHEDULE, MSG_TYPE_UPDATE_PARAMS_CRON, PARAMS_QUERY_PATH_CRON, }; use crate::dex_module_param_types::{ MsgUpdateParamsDex, ParamsRequestDex, ParamsResponseDex, MSG_TYPE_UPDATE_PARAMS_DEX, @@ -180,16 +180,6 @@ fn check_neutron_msg( neutron_msg: NeutronMsg, ) -> Result<(), ContractError> { match neutron_msg { - NeutronMsg::AddSchedule { .. } => { - if !strategy.has_cron_add_schedule_permission() { - return Err(ContractError::Unauthorized {}); - } - } - NeutronMsg::RemoveSchedule { name: _ } => { - if !strategy.has_cron_remove_schedule_permission() { - return Err(ContractError::Unauthorized {}); - } - } NeutronMsg::SubmitAdminProposal { admin_proposal } => { check_submit_admin_proposal_message(deps, strategy, admin_proposal)?; } @@ -245,10 +235,23 @@ fn check_proposal_execute_message( } else if typed_proposal.type_field.as_str() == MSG_TYPE_UPDATE_PARAMS_DEX { check_dex_update_msg_params(deps, strategy, proposal)?; Ok(()) + } else if typed_proposal.type_field.as_str() == MSG_TYPE_ADD_SCHEDULE { + if strategy.has_cron_add_schedule_permission() { + Ok(()) + } else { + Err(ContractError::Unauthorized {}) + } + } else if typed_proposal.type_field.as_str() == MSG_TYPE_REMOVE_SCHEDULE { + if strategy.has_cron_remove_schedule_permission() { + Ok(()) + } else { + Err(ContractError::Unauthorized {}) + } } else { Err(ContractError::Unauthorized {}) } } + /// Checks that the strategy owner is authorised to change the parameters of the /// cron module. We query the current values for each parameter & compare them to /// the values in the proposal; all modifications must be allowed by the strategy. diff --git a/contracts/dao/neutron-chain-manager/src/cron_module_param_types.rs b/contracts/dao/neutron-chain-manager/src/cron_module_types.rs similarity index 90% rename from contracts/dao/neutron-chain-manager/src/cron_module_param_types.rs rename to contracts/dao/neutron-chain-manager/src/cron_module_types.rs index a79fb104..99f508e3 100644 --- a/contracts/dao/neutron-chain-manager/src/cron_module_param_types.rs +++ b/contracts/dao/neutron-chain-manager/src/cron_module_types.rs @@ -5,6 +5,8 @@ use serde::{Deserialize, Serialize}; pub const PARAMS_QUERY_PATH_CRON: &str = "/neutron.cron.Query/Params"; pub const MSG_TYPE_UPDATE_PARAMS_CRON: &str = "/neutron.cron.MsgUpdateParams"; +pub const MSG_TYPE_ADD_SCHEDULE: &str = "/neutron.cron.MsgAddSchedule"; +pub const MSG_TYPE_REMOVE_SCHEDULE: &str = "/neutron.cron.MsgRemoveSchedule"; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] diff --git a/contracts/dao/neutron-chain-manager/src/lib.rs b/contracts/dao/neutron-chain-manager/src/lib.rs index adb8b9e5..892b571a 100644 --- a/contracts/dao/neutron-chain-manager/src/lib.rs +++ b/contracts/dao/neutron-chain-manager/src/lib.rs @@ -1,5 +1,5 @@ pub mod contract; -mod cron_module_param_types; +mod cron_module_types; mod dex_module_param_types; mod error; pub mod msg; diff --git a/contracts/dao/neutron-chain-manager/src/testing/mock_querier.rs b/contracts/dao/neutron-chain-manager/src/testing/mock_querier.rs index f790a63f..ce4d2209 100644 --- a/contracts/dao/neutron-chain-manager/src/testing/mock_querier.rs +++ b/contracts/dao/neutron-chain-manager/src/testing/mock_querier.rs @@ -1,4 +1,4 @@ -use crate::cron_module_param_types::{ParamsCron, ParamsResponseCron}; +use crate::cron_module_types::{ParamsCron, ParamsResponseCron}; use crate::dex_module_param_types::{ParamsDex, ParamsResponseDex}; use crate::tokenfactory_module_param_types::{ParamsResponseTokenfactory, ParamsTokenfactory}; use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage}; From 4bf677e5b07fe4bf5b08d75f617955b50604df3e Mon Sep 17 00:00:00 2001 From: pr0n00gler Date: Fri, 6 Sep 2024 16:45:28 +0300 Subject: [PATCH 2/2] chain manager still can handle cron bindings --- Cargo.lock | 14 +++++++------- .../dao/neutron-chain-manager/src/contract.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25de8ff3..6d476495 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,7 +37,7 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "astroport" version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#cd7c02e8894b1953cc73c299c51010fe758a05f3" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#3685cd8f9a70a70eee83c8e688c306096a68c782" dependencies = [ "cosmwasm-schema 1.5.5", "cosmwasm-std 1.5.2", @@ -63,7 +63,7 @@ dependencies = [ [[package]] name = "astroport" version = "2.0.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#cd7c02e8894b1953cc73c299c51010fe758a05f3" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#3685cd8f9a70a70eee83c8e688c306096a68c782" dependencies = [ "cosmwasm-schema 1.5.5", "cosmwasm-std 1.5.2", @@ -164,7 +164,7 @@ dependencies = [ [[package]] name = "astroport-periphery" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#cd7c02e8894b1953cc73c299c51010fe758a05f3" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#3685cd8f9a70a70eee83c8e688c306096a68c782" dependencies = [ "astroport 3.11.0", "cosmwasm-schema 1.5.5", @@ -3149,7 +3149,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vesting-base" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#cd7c02e8894b1953cc73c299c51010fe758a05f3" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#3685cd8f9a70a70eee83c8e688c306096a68c782" dependencies = [ "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-schema 1.5.5", @@ -3179,7 +3179,7 @@ dependencies = [ [[package]] name = "vesting-base" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#cd7c02e8894b1953cc73c299c51010fe758a05f3" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git#3685cd8f9a70a70eee83c8e688c306096a68c782" dependencies = [ "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git)", "cosmwasm-schema 1.5.5", @@ -3206,7 +3206,7 @@ dependencies = [ [[package]] name = "vesting-lp" version = "1.2.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#cd7c02e8894b1953cc73c299c51010fe758a05f3" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#3685cd8f9a70a70eee83c8e688c306096a68c782" dependencies = [ "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-schema 1.5.5", @@ -3221,7 +3221,7 @@ dependencies = [ [[package]] name = "vesting-lp-pcl" version = "1.1.0" -source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#cd7c02e8894b1953cc73c299c51010fe758a05f3" +source = "git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main#3685cd8f9a70a70eee83c8e688c306096a68c782" dependencies = [ "astroport 2.0.0 (git+https://github.com/neutron-org/neutron-tge-contracts.git?branch=main)", "cosmwasm-schema 1.5.5", diff --git a/contracts/dao/neutron-chain-manager/src/contract.rs b/contracts/dao/neutron-chain-manager/src/contract.rs index 909ba687..85192c20 100644 --- a/contracts/dao/neutron-chain-manager/src/contract.rs +++ b/contracts/dao/neutron-chain-manager/src/contract.rs @@ -180,6 +180,16 @@ fn check_neutron_msg( neutron_msg: NeutronMsg, ) -> Result<(), ContractError> { match neutron_msg { + NeutronMsg::AddSchedule { .. } => { + if !strategy.has_cron_add_schedule_permission() { + return Err(ContractError::Unauthorized {}); + } + } + NeutronMsg::RemoveSchedule { name: _ } => { + if !strategy.has_cron_remove_schedule_permission() { + return Err(ContractError::Unauthorized {}); + } + } NeutronMsg::SubmitAdminProposal { admin_proposal } => { check_submit_admin_proposal_message(deps, strategy, admin_proposal)?; }