From da586005f7b09c161d23af27d818aadb8425bdea Mon Sep 17 00:00:00 2001 From: Aleksa Boskov Date: Mon, 10 Jun 2024 15:54:56 +0200 Subject: [PATCH] Add ability to change versioning and factory contract refs for every DAO --- contracts/enterprise/src/contract.rs | 45 +++++++++++++++++-- .../src/api.rs | 3 +- packages/enterprise-protocol/src/api.rs | 6 +++ packages/enterprise-protocol/src/msg.rs | 4 +- packages/enterprise-protocol/src/response.rs | 14 ++++++ 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/contracts/enterprise/src/contract.rs b/contracts/enterprise/src/contract.rs index 191b93d..53357f9 100644 --- a/contracts/enterprise/src/contract.rs +++ b/contracts/enterprise/src/contract.rs @@ -6,6 +6,7 @@ use crate::state::{ use crate::validate::enterprise_governance_controller_caller_only; use attestation_api::api::{HasUserSignedParams, HasUserSignedResponse}; use attestation_api::msg::QueryMsg::HasUserSigned; +use common::commons::ModifyValue; use common::commons::ModifyValue::Change; use common::cw::{Context, QueryContext}; use cosmwasm_std::CosmosMsg::Wasm; @@ -18,8 +19,8 @@ use cw2::set_contract_version; use cw_utils::parse_reply_instantiate_data; use enterprise_protocol::api::{ ComponentContractsResponse, DaoInfoResponse, DaoType, ExecuteMsgsMsg, FinalizeInstantiationMsg, - IsRestrictedUserParams, IsRestrictedUserResponse, SetAttestationMsg, UpdateMetadataMsg, - UpgradeDaoMsg, + IsRestrictedUserParams, IsRestrictedUserResponse, SetAttestationMsg, UpdateConfigMsg, + UpdateMetadataMsg, UpgradeDaoMsg, }; use enterprise_protocol::error::DaoError::{ AlreadyInitialized, DuplicateVersionMigrateMsgFound, MigratingToLowerVersion, Unauthorized, @@ -29,7 +30,8 @@ use enterprise_protocol::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg} use enterprise_protocol::response::{ execute_execute_msgs_response, execute_finalize_instantiation_response, execute_remove_attestation_response, execute_set_attestation_response, - execute_update_metadata_response, execute_upgrade_dao_response, instantiate_response, + execute_update_config_response, execute_update_metadata_response, execute_upgrade_dao_response, + instantiate_response, }; use enterprise_versioning_api::api::{ Version, VersionInfo, VersionParams, VersionResponse, VersionsParams, VersionsResponse, @@ -38,6 +40,7 @@ use enterprise_versioning_api::msg::QueryMsg::Versions; use std::collections::HashMap; use std::ops::Not; use DaoType::Nft; +use ModifyValue::NoChange; pub const INSTANTIATE_ATTESTATION_REPLY_ID: u64 = 1; @@ -89,6 +92,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> D ExecuteMsg::FinalizeInstantiation(msg) => finalize_instantiation(ctx, msg), ExecuteMsg::UpdateMetadata(msg) => update_metadata(ctx, msg), ExecuteMsg::UpgradeDao(msg) => upgrade_dao(ctx, msg), + ExecuteMsg::UpdateConfig(msg) => update_config(ctx, msg), ExecuteMsg::SetAttestation(msg) => set_attestation(ctx, msg), ExecuteMsg::RemoveAttestation {} => remove_attestation(ctx), ExecuteMsg::ExecuteMsgs(msg) => execute_msgs(ctx, msg), @@ -294,6 +298,41 @@ fn get_versions_between_current_and_target( Ok(versions) } +fn update_config(ctx: &mut Context, msg: UpdateConfigMsg) -> DaoResult { + enterprise_governance_controller_caller_only(ctx)?; + + let old_versioning = ENTERPRISE_VERSIONING_CONTRACT.load(ctx.deps.storage)?; + + let new_versioning_addr = match msg.new_versioning_contract { + Change(versioning) => { + let new_versioning = ctx.deps.api.addr_validate(&versioning)?; + ENTERPRISE_VERSIONING_CONTRACT.save(ctx.deps.storage, &new_versioning)?; + + new_versioning.to_string() + } + NoChange => old_versioning.to_string(), + }; + + let old_factory = ENTERPRISE_FACTORY_CONTRACT.load(ctx.deps.storage)?; + + let new_factory_addr = match msg.new_factory_contract { + Change(factory) => { + let new_factory = ctx.deps.api.addr_validate(&factory)?; + ENTERPRISE_FACTORY_CONTRACT.save(ctx.deps.storage, &new_factory)?; + + new_factory.to_string() + } + NoChange => old_factory.to_string(), + }; + + Ok(execute_update_config_response( + old_versioning.to_string(), + new_versioning_addr, + old_factory.to_string(), + new_factory_addr, + )) +} + fn set_attestation(ctx: &mut Context, msg: SetAttestationMsg) -> DaoResult { enterprise_governance_controller_caller_only(ctx)?; diff --git a/packages/enterprise-governance-controller-api/src/api.rs b/packages/enterprise-governance-controller-api/src/api.rs index d7ad151..616a86c 100644 --- a/packages/enterprise-governance-controller-api/src/api.rs +++ b/packages/enterprise-governance-controller-api/src/api.rs @@ -99,7 +99,8 @@ pub struct CreateProposalMsg { // TODO: this message is used for non-deposit proposals too, making this field meaningless in those cases /// Optionally define the owner of the proposal deposit. /// If None, will default to the proposer themselves. - #[serde(skip_serializing_if = "Option::is_none")] // this flag is here to allow the facade v2 to work with gov controller , } diff --git a/packages/enterprise-protocol/src/api.rs b/packages/enterprise-protocol/src/api.rs index 80e927c..0d4577d 100644 --- a/packages/enterprise-protocol/src/api.rs +++ b/packages/enterprise-protocol/src/api.rs @@ -112,6 +112,12 @@ pub struct ExecuteMsgsMsg { pub msgs: Vec, } +#[cw_serde] +pub struct UpdateConfigMsg { + pub new_versioning_contract: ModifyValue, + pub new_factory_contract: ModifyValue, +} + #[cw_serde] pub struct IsRestrictedUserParams { pub user: String, diff --git a/packages/enterprise-protocol/src/msg.rs b/packages/enterprise-protocol/src/msg.rs index 20da696..15d3348 100644 --- a/packages/enterprise-protocol/src/msg.rs +++ b/packages/enterprise-protocol/src/msg.rs @@ -1,7 +1,7 @@ use crate::api::{ ComponentContractsResponse, DaoInfoResponse, DaoMetadata, DaoType, ExecuteMsgsMsg, FinalizeInstantiationMsg, IsRestrictedUserParams, IsRestrictedUserResponse, SetAttestationMsg, - UpdateMetadataMsg, UpgradeDaoMsg, + UpdateConfigMsg, UpdateMetadataMsg, UpgradeDaoMsg, }; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::Timestamp; @@ -27,6 +27,8 @@ pub enum ExecuteMsg { ExecuteMsgs(ExecuteMsgsMsg), + UpdateConfig(UpdateConfigMsg), + // called only right after instantiation FinalizeInstantiation(FinalizeInstantiationMsg), } diff --git a/packages/enterprise-protocol/src/response.rs b/packages/enterprise-protocol/src/response.rs index 4e8d74d..b486e19 100644 --- a/packages/enterprise-protocol/src/response.rs +++ b/packages/enterprise-protocol/src/response.rs @@ -43,6 +43,20 @@ pub fn execute_upgrade_dao_response(new_dao_version: String) -> Response { .add_attribute("new_version", new_dao_version) } +pub fn execute_update_config_response( + old_versioning_addr: String, + new_versioning_addr: String, + old_factory_addr: String, + new_factory_addr: String, +) -> Response { + Response::new() + .add_attribute("action", "update_config") + .add_attribute("old_versioning_addr", old_versioning_addr) + .add_attribute("new_versioning_addr", new_versioning_addr) + .add_attribute("old_factory_addr", old_factory_addr) + .add_attribute("new_factory_addr", new_factory_addr) +} + pub fn execute_set_attestation_response() -> Response { Response::new().add_attribute("action", "set_attestation") }