Skip to content

Commit

Permalink
Allow admin to pause/unpause subdao (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismellike authored Mar 25, 2024
1 parent f5a95b4 commit 8f37dc8
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 265 deletions.
14 changes: 14 additions & 0 deletions contracts/dao-dao-core/schema/dao-dao-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@
},
"additionalProperties": false
},
{
"description": "Unpauses the DAO",
"type": "object",
"required": [
"unpause"
],
"properties": {
"unpause": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Executed when the contract receives a cw20 token. Depending on the contract's configuration the contract will automatically add the token to its treasury.",
"type": "object",
Expand Down
25 changes: 23 additions & 2 deletions contracts/dao-dao-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ pub fn execute(
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
// No actions can be performed while the DAO is paused.
// Check if the DAO is paused
if let Some(expiration) = PAUSED.may_load(deps.storage)? {
if !expiration.is_expired(&env.block) {
return Err(ContractError::Paused {});
// If paused, then only allow messages from the Admin or DAO itself
if info.sender != env.contract.address
&& info.sender.clone() != ADMIN.load(deps.storage)?
{
return Err(ContractError::Paused {});
}
}
}

Expand All @@ -121,6 +126,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 @@ -174,6 +180,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 can unpause
if sender != admin {
return Err(ContractError::Unauthorized {});
}

PAUSED.remove(deps.storage);

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

0 comments on commit 8f37dc8

Please sign in to comment.