From a6a80d4f02d76ca67dbfa53965f0ec896bc66ba7 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 27 Aug 2024 16:50:25 +0400 Subject: [PATCH] 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};