Skip to content

Commit

Permalink
Add ability to change versioning and factory contract refs for every DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeeKay committed Jun 10, 2024
1 parent 5a21ce1 commit da58600
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
45 changes: 42 additions & 3 deletions contracts/enterprise/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -294,6 +298,41 @@ fn get_versions_between_current_and_target(
Ok(versions)
}

fn update_config(ctx: &mut Context, msg: UpdateConfigMsg) -> DaoResult<Response> {
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<Response> {
enterprise_governance_controller_caller_only(ctx)?;

Expand Down
3 changes: 2 additions & 1 deletion packages/enterprise-governance-controller-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <v1.1.0
#[serde(skip_serializing_if = "Option::is_none")]
// this flag is here to allow the facade v2 to work with gov controller <v1.1.0
pub deposit_owner: Option<String>,
}

Expand Down
6 changes: 6 additions & 0 deletions packages/enterprise-protocol/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ pub struct ExecuteMsgsMsg {
pub msgs: Vec<String>,
}

#[cw_serde]
pub struct UpdateConfigMsg {
pub new_versioning_contract: ModifyValue<String>,
pub new_factory_contract: ModifyValue<String>,
}

#[cw_serde]
pub struct IsRestrictedUserParams {
pub user: String,
Expand Down
4 changes: 3 additions & 1 deletion packages/enterprise-protocol/src/msg.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,6 +27,8 @@ pub enum ExecuteMsg {

ExecuteMsgs(ExecuteMsgsMsg),

UpdateConfig(UpdateConfigMsg),

// called only right after instantiation
FinalizeInstantiation(FinalizeInstantiationMsg),
}
Expand Down
14 changes: 14 additions & 0 deletions packages/enterprise-protocol/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit da58600

Please sign in to comment.