Skip to content

Commit

Permalink
Initial dao actions on instantiate (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismellike authored Feb 25, 2025
1 parent 1249388 commit a522e33
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 6 deletions.
1 change: 1 addition & 0 deletions ci/bootstrap-env/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fn main() -> Result<()> {
label: "DAO DAO Proposal Module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

// Init dao dao dao with an initial treasury of 9000000 tokens
Expand Down
1 change: 1 addition & 0 deletions ci/integration-tests/src/helpers/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub fn create_dao(
label: "DAO DAO Proposal Module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

chain
Expand Down
20 changes: 17 additions & 3 deletions contracts/dao-dao-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use dao_interface::{
voting,
};

use crate::error::ContractError;
use crate::state::{
ACTIVE_PROPOSAL_MODULE_COUNT, ADMIN, CONFIG, CW20_LIST, CW721_LIST, ITEMS, NOMINATED_ADMIN,
PAUSED, PROPOSAL_MODULES, SUBDAO_LIST, TOTAL_PROPOSAL_MODULE_COUNT, VOTING_MODULE,
};
use crate::{error::ContractError, state::INITIAL_DAO_ACTIONS};

pub(crate) const CONTRACT_NAME: &str = "crates.io:dao-dao-core";
pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -92,11 +92,18 @@ pub fn instantiate(
TOTAL_PROPOSAL_MODULE_COUNT.save(deps.storage, &0)?;
ACTIVE_PROPOSAL_MODULE_COUNT.save(deps.storage, &0)?;

Ok(Response::new()
let res = Response::new()
.add_attribute("action", "instantiate")
.add_attribute("sender", info.sender)
.add_submessage(vote_module_msg)
.add_submessages(proposal_module_msgs))
.add_submessages(proposal_module_msgs);

if let Some(initial_dao_actions) = msg.initial_dao_actions {
INITIAL_DAO_ACTIONS.save(deps.storage, &initial_dao_actions)?;

Check warning on line 102 in contracts/dao-dao-core/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/dao-dao-core/src/contract.rs#L102

Added line #L102 was not covered by tests

return Ok(res.add_messages(initial_dao_actions));

Check warning on line 104 in contracts/dao-dao-core/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/dao-dao-core/src/contract.rs#L104

Added line #L104 was not covered by tests
}
Ok(res)
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down Expand Up @@ -595,6 +602,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
query_list_sub_daos(deps, start_after, limit)
}
QueryMsg::DaoURI {} => query_dao_uri(deps),
QueryMsg::InitialDaoActions {} => query_initial_dao_actions(deps),

Check warning on line 605 in contracts/dao-dao-core/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/dao-dao-core/src/contract.rs#L605

Added line #L605 was not covered by tests
}
}

Expand Down Expand Up @@ -868,6 +876,12 @@ pub fn query_proposal_module_count(deps: Deps) -> StdResult<Binary> {
})
}

pub fn query_initial_dao_actions(deps: Deps) -> StdResult<Binary> {
let actions = INITIAL_DAO_ACTIONS.may_load(deps.storage)?;

Check warning on line 880 in contracts/dao-dao-core/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/dao-dao-core/src/contract.rs#L879-L880

Added lines #L879 - L880 were not covered by tests

to_json_binary(&actions)
}

Check warning on line 883 in contracts/dao-dao-core/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/dao-dao-core/src/contract.rs#L882-L883

Added lines #L882 - L883 were not covered by tests

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
let ContractVersion { version, .. } = get_contract_version(deps.storage)?;
Expand Down
5 changes: 4 additions & 1 deletion contracts/dao-dao-core/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, Empty};
use cosmwasm_std::{Addr, CosmosMsg, Empty};
use cw_storage_plus::{Item, Map};
use cw_utils::Expiration;
use dao_interface::state::{Config, ProposalModule};
Expand Down Expand Up @@ -53,3 +53,6 @@ pub const CW721_LIST: Map<Addr, Empty> = Map::new("cw721s");

/// List of SubDAOs associated to this DAO. Each SubDAO has an optional charter.
pub const SUBDAO_LIST: Map<&Addr, Option<String>> = Map::new("sub_daos");

/// List of initial dao actions.
pub const INITIAL_DAO_ACTIONS: Item<Vec<CosmosMsg>> = Item::new("initial_dao_actions");
13 changes: 13 additions & 0 deletions contracts/dao-dao-core/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fn test_instantiate_with_n_gov_modules(n: usize) {
})
.collect(),
initial_items: None,
initial_dao_actions: None,
};
let gov_addr = instantiate_gov(&mut app, gov_id, instantiate);

Expand Down Expand Up @@ -180,6 +181,7 @@ makes wickedness."
},
proposal_modules_instantiate_info: governance_modules,
initial_items: None,
initial_dao_actions: None,
};
instantiate_gov(&mut app, gov_id, instantiate);
}
Expand Down Expand Up @@ -217,6 +219,7 @@ fn test_update_config() {
label: "voting module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down Expand Up @@ -316,6 +319,7 @@ fn test_swap_governance(swaps: Vec<(u32, u32)>) {
label: "governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down Expand Up @@ -495,6 +499,7 @@ fn test_removed_modules_can_not_execute() {
label: "governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down Expand Up @@ -658,6 +663,7 @@ fn test_module_already_disabled() {
label: "governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down Expand Up @@ -760,6 +766,7 @@ fn test_swap_voting_module() {
label: "governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down Expand Up @@ -866,6 +873,7 @@ fn test_permissions() {
initial_items: None,
automatically_add_cw20s: true,
automatically_add_cw721s: true,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down Expand Up @@ -966,6 +974,7 @@ fn do_standard_instantiate(auto_add: bool, admin: Option<String>) -> (Addr, App)
label: "governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down Expand Up @@ -1683,6 +1692,7 @@ fn test_list_items() {
label: "governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down Expand Up @@ -1817,6 +1827,7 @@ fn test_instantiate_with_items() {
label: "governance module".to_string(),
}],
initial_items: Some(initial_items.clone()),
initial_dao_actions: None,
};

// Ensure duplicates are dissallowed.
Expand Down Expand Up @@ -2646,6 +2657,7 @@ fn test_migrate_from_compatible() {
label: "governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let core_addr = app
Expand Down Expand Up @@ -2947,6 +2959,7 @@ fn test_module_prefixes() {
},
],
initial_items: None,
initial_dao_actions: None,
};

let gov_addr = app
Expand Down
4 changes: 4 additions & 0 deletions contracts/external/btsg-ft-factory/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fn test_issue_fantoken() -> anyhow::Result<()> {
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let dao = app
Expand Down Expand Up @@ -194,6 +195,7 @@ fn test_initial_fantoken_balances() -> anyhow::Result<()> {
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let dao = app
Expand Down Expand Up @@ -302,6 +304,7 @@ fn test_fantoken_minter_and_authority_set_to_dao() -> anyhow::Result<()> {
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let dao = app
Expand Down Expand Up @@ -460,6 +463,7 @@ fn test_fantoken_can_be_staked() -> anyhow::Result<()> {
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let dao = app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fn test_set_self_admin_instantiate2() {
label: "DAO DAO Proposal Module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let salt = Binary::from("salt".as_bytes());
Expand Down
2 changes: 2 additions & 0 deletions contracts/external/cw-admin-factory/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub fn test_set_self_admin() {
},
],
initial_items: None,
initial_dao_actions: None,
};

let res: AppResponse = app
Expand Down Expand Up @@ -174,6 +175,7 @@ pub fn test_authorized_set_self_admin() {
},
],
initial_items: None,
initial_dao_actions: None,
};

// Fails when not the admin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl SuiteBuilder {
label: "condorcet module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
dao_uri: None,
};
let core = app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub fn _instantiate_with_staked_cw721_governance(
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
initial_dao_actions: None,

Check warning on line 183 in contracts/proposal/dao-proposal-multiple/src/testing/instantiate.rs

View check run for this annotation

Codecov / codecov/patch

contracts/proposal/dao-proposal-multiple/src/testing/instantiate.rs#L183

Added line #L183 was not covered by tests
dao_uri: None,
};

Expand Down Expand Up @@ -299,6 +300,7 @@ pub fn instantiate_with_native_staked_balances_governance(
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
dao_uri: None,
};

Expand Down Expand Up @@ -416,6 +418,7 @@ pub fn instantiate_with_cw20_balances_governance(
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
dao_uri: None,
};

Expand Down Expand Up @@ -502,6 +505,7 @@ pub fn instantiate_with_staked_balances_governance(
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
dao_uri: None,
};

Expand Down Expand Up @@ -641,6 +645,7 @@ pub fn instantiate_with_multiple_staked_balances_governance(
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
dao_uri: None,
};

Expand Down Expand Up @@ -756,6 +761,7 @@ pub fn instantiate_with_staking_active_threshold(
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
dao_uri: None,
};

Expand Down Expand Up @@ -835,6 +841,7 @@ pub fn _instantiate_with_cw4_groups_governance(
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,

Check warning on line 844 in contracts/proposal/dao-proposal-multiple/src/testing/instantiate.rs

View check run for this annotation

Codecov / codecov/patch

contracts/proposal/dao-proposal-multiple/src/testing/instantiate.rs#L844

Added line #L844 was not covered by tests
dao_uri: None,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub(crate) fn instantiate_with_staked_cw721_governance(
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let core_addr = app
Expand Down Expand Up @@ -300,6 +301,7 @@ pub(crate) fn instantiate_with_native_staked_balances_governance(
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let core_addr = app
Expand Down Expand Up @@ -421,6 +423,7 @@ pub(crate) fn instantiate_with_staked_balances_governance(
label: "DAO DAO governance module.".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let core_addr = app
Expand Down Expand Up @@ -536,6 +539,7 @@ pub(crate) fn instantiate_with_staking_active_threshold(
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

app.instantiate_contract(
Expand Down Expand Up @@ -615,6 +619,7 @@ pub(crate) fn instantiate_with_cw4_groups_governance(
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

let addr = app
Expand Down
1 change: 1 addition & 0 deletions contracts/test/dao-proposal-hook-counter/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn instantiate_with_default_governance(
label: "DAO DAO governance module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

instantiate_governance(app, governance_id, governance_instantiate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ fn test_full_integration_with_factory() {
label: "DAO DAO Proposal Module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

// Instantiating without funds fails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl TestEnvBuilder {
label: "DAO DAO Proposal Module".to_string(),
}],
initial_items: None,
initial_dao_actions: None,
};

// Instantiate DAO
Expand Down
Loading

0 comments on commit a522e33

Please sign in to comment.