Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow admin to pause/unpause subdao #744

Merged
merged 13 commits into from
Mar 25, 2024
17 changes: 9 additions & 8 deletions ci/integration-tests/src/helpers/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,16 @@ pub fn create_dao(
.unwrap();

let ProposalCreationPolicy::Module { addr: pre_propose } = chain
.orc
.query(
"dao_proposal_single",
&dao_proposal_single::msg::QueryMsg::ProposalCreationPolicy {}
).unwrap()
.data()
.unwrap()
.orc
.query(
"dao_proposal_single",
&dao_proposal_single::msg::QueryMsg::ProposalCreationPolicy {},
)
.unwrap()
.data()
.unwrap()
else {
panic!("expected pre-propose module")
panic!("expected pre-propose module")
};
chain
.orc
Expand Down
35 changes: 30 additions & 5 deletions contracts/dao-dao-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,16 @@ pub fn execute(
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
// No actions can be performed while the DAO is paused.
if let Some(expiration) = PAUSED.may_load(deps.storage)? {
if !expiration.is_expired(&env.block) {
return Err(ContractError::Paused {});
match &msg {
&ExecuteMsg::Unpause {} => {
// Allow the unpause action to pass through
}
_ => {
if let Some(expiration) = PAUSED.may_load(deps.storage)? {
if !expiration.is_expired(&env.block) {
return Err(ContractError::Paused {});
}
}
}
}

Expand All @@ -121,6 +128,7 @@ pub fn execute(
execute_proposal_hook(deps.as_ref(), info.sender, msgs)
}
ExecuteMsg::Pause { duration } => execute_pause(deps, env, info.sender, duration),
ExecuteMsg::Unpause {} => execute_unpause(deps, info.sender),
ExecuteMsg::Receive(_) => execute_receive_cw20(deps, info.sender),
ExecuteMsg::ReceiveNft(_) => execute_receive_cw721(deps, info.sender),
ExecuteMsg::RemoveItem { key } => execute_remove_item(deps, env, info.sender, key),
Expand Down Expand Up @@ -159,8 +167,10 @@ pub fn execute_pause(
sender: Addr,
pause_duration: Duration,
) -> Result<Response, ContractError> {
// Only the core contract may call this method.
bekauz marked this conversation as resolved.
Show resolved Hide resolved
if sender != env.contract.address {
let admin = ADMIN.load(deps.storage)?;

// Only the core contract or admin may call this method.
if sender != env.contract.address && sender != admin {
ismellike marked this conversation as resolved.
Show resolved Hide resolved
return Err(ContractError::Unauthorized {});
}

Expand All @@ -174,6 +184,21 @@ pub fn execute_pause(
.add_attribute("until", until.to_string()))
}

pub fn execute_unpause(deps: DepsMut, sender: Addr) -> Result<Response, ContractError> {
let admin = ADMIN.load(deps.storage)?;

// Only the admin may call this method.
if sender != admin {
return Err(ContractError::Unauthorized {});
}

PAUSED.remove(deps.storage);
NoahSaso marked this conversation as resolved.
Show resolved Hide resolved

Ok(Response::new()
.add_attribute("action", "execute_unpause")
.add_attribute("sender", sender))
}

pub fn execute_admin_msgs(
deps: Deps,
sender: Addr,
Expand Down
240 changes: 0 additions & 240 deletions contracts/dao-dao-core/src/msg.rs

This file was deleted.

Loading
Loading