From 53d1c6a56f261ac475fefea90093f9eb75573a51 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Wed, 21 Sep 2022 01:23:19 +0200 Subject: [PATCH 1/2] Add promote / demote contract to privileged gov proposal --- contracts/tgrade-validator-voting/src/contract.rs | 14 ++++++++++++++ contracts/tgrade-validator-voting/src/msg.rs | 8 ++++++++ contracts/tgrade-validator-voting/src/validate.rs | 5 ++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/contracts/tgrade-validator-voting/src/contract.rs b/contracts/tgrade-validator-voting/src/contract.rs index b8eb1071..511e7d0e 100644 --- a/contracts/tgrade-validator-voting/src/contract.rs +++ b/contracts/tgrade-validator-voting/src/contract.rs @@ -150,6 +150,20 @@ pub fn execute_execute( proposal: GovProposal::ChangeParams(params), }) } + PromoteToPrivilegedContract { contract } => { + res = res.add_message(TgradeMsg::ExecuteGovProposal { + title: proposal.title, + description: proposal.description, + proposal: GovProposal::PromoteToPrivilegedContract { contract }, + }) + } + DemotePrivilegedContract { contract } => { + res = res.add_message(TgradeMsg::ExecuteGovProposal { + title: proposal.title, + description: proposal.description, + proposal: GovProposal::DemotePrivilegedContract { contract }, + }) + } }; Ok(res diff --git a/contracts/tgrade-validator-voting/src/msg.rs b/contracts/tgrade-validator-voting/src/msg.rs index e291c7c8..b3b5189e 100644 --- a/contracts/tgrade-validator-voting/src/msg.rs +++ b/contracts/tgrade-validator-voting/src/msg.rs @@ -83,6 +83,14 @@ pub enum ValidatorProposal { Text {}, /// Defines a proposal to change one or more parameters. ChangeParams(Vec), + PromoteToPrivilegedContract { + /// The contract address to be promoted + contract: String, + }, + DemotePrivilegedContract { + /// The contract address to be demoted + contract: String, + }, } // We can also add this as a tg3 extension diff --git a/contracts/tgrade-validator-voting/src/validate.rs b/contracts/tgrade-validator-voting/src/validate.rs index 13dcae5c..e57e62d0 100644 --- a/contracts/tgrade-validator-voting/src/validate.rs +++ b/contracts/tgrade-validator-voting/src/validate.rs @@ -83,7 +83,10 @@ impl ValidatorProposal { return Err(ContractError::InvalidConsensusParams {}); } } - ValidatorProposal::CancelUpgrade {} | ValidatorProposal::Text {} => {} + ValidatorProposal::PromoteToPrivilegedContract { .. } + | ValidatorProposal::DemotePrivilegedContract { .. } + | ValidatorProposal::CancelUpgrade {} + | ValidatorProposal::Text {} => {} } Ok(()) } From 64b454fa0d98e8fd47641adde02c51e3ff099728 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Wed, 21 Sep 2022 07:10:14 +0200 Subject: [PATCH 2/2] Add set / clear migrate admin to privileged gov proposal --- .../tgrade-validator-voting/src/contract.rs | 20 +++++++++++++++++++ .../tgrade-validator-voting/src/error.rs | 3 +++ contracts/tgrade-validator-voting/src/msg.rs | 10 ++++++++++ .../tgrade-validator-voting/src/validate.rs | 11 +++++++++- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/contracts/tgrade-validator-voting/src/contract.rs b/contracts/tgrade-validator-voting/src/contract.rs index 511e7d0e..e2cc6fe9 100644 --- a/contracts/tgrade-validator-voting/src/contract.rs +++ b/contracts/tgrade-validator-voting/src/contract.rs @@ -164,6 +164,26 @@ pub fn execute_execute( proposal: GovProposal::DemotePrivilegedContract { contract }, }) } + SetContractAdmin { + contract, + new_admin, + } => { + res = res.add_message(TgradeMsg::ExecuteGovProposal { + title: proposal.title, + description: proposal.description, + proposal: GovProposal::SetContractAdmin { + contract, + new_admin, + }, + }) + } + ClearContractAdmin { contract } => { + res = res.add_message(TgradeMsg::ExecuteGovProposal { + title: proposal.title, + description: proposal.description, + proposal: GovProposal::ClearContractAdmin { contract }, + }) + } }; Ok(res diff --git a/contracts/tgrade-validator-voting/src/error.rs b/contracts/tgrade-validator-voting/src/error.rs index 18e0cc5d..cd18760a 100644 --- a/contracts/tgrade-validator-voting/src/error.rs +++ b/contracts/tgrade-validator-voting/src/error.rs @@ -50,6 +50,9 @@ pub enum ContractError { #[error("Invalid consensus params: All cannot be none")] InvalidConsensusParams {}, + + #[error("Empty new admin")] + EmptyAdmin {}, } impl From for ContractError { diff --git a/contracts/tgrade-validator-voting/src/msg.rs b/contracts/tgrade-validator-voting/src/msg.rs index b3b5189e..9a7f9133 100644 --- a/contracts/tgrade-validator-voting/src/msg.rs +++ b/contracts/tgrade-validator-voting/src/msg.rs @@ -91,6 +91,16 @@ pub enum ValidatorProposal { /// The contract address to be demoted contract: String, }, + SetContractAdmin { + /// The contract address to be updated + contract: String, + /// The account address to become migrate admin of this contract + new_admin: String, + }, + ClearContractAdmin { + /// The contract address to be cleared + contract: String, + }, } // We can also add this as a tg3 extension diff --git a/contracts/tgrade-validator-voting/src/validate.rs b/contracts/tgrade-validator-voting/src/validate.rs index e57e62d0..c18bee1d 100644 --- a/contracts/tgrade-validator-voting/src/validate.rs +++ b/contracts/tgrade-validator-voting/src/validate.rs @@ -83,7 +83,16 @@ impl ValidatorProposal { return Err(ContractError::InvalidConsensusParams {}); } } - ValidatorProposal::PromoteToPrivilegedContract { .. } + ValidatorProposal::SetContractAdmin { + contract: _contract, + new_admin, + } => { + if new_admin.is_empty() { + return Err(ContractError::EmptyAdmin {}); + } + } + ValidatorProposal::ClearContractAdmin { .. } + | ValidatorProposal::PromoteToPrivilegedContract { .. } | ValidatorProposal::DemotePrivilegedContract { .. } | ValidatorProposal::CancelUpgrade {} | ValidatorProposal::Text {} => {}