Skip to content

Commit

Permalink
Merge pull request #32 from neutron-org/feat/subdao-registry
Browse files Browse the repository at this point in the history
Hardening overrule proposals with additional checks #NTRN-325
  • Loading branch information
Andrew Zavgorodny authored Apr 14, 2023
2 parents 603593a + 03421cc commit 376cd05
Show file tree
Hide file tree
Showing 41 changed files with 1,308 additions and 271 deletions.
24 changes: 17 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions contracts/dao/cwd-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::ListSubDaos { start_after, limit } => {
query_list_sub_daos(deps, start_after, limit)
}
QueryMsg::GetSubDao { address } => query_sub_dao(deps, address),
QueryMsg::DaoURI {} => query_dao_uri(deps),
}
}
Expand Down Expand Up @@ -514,6 +515,18 @@ pub fn query_list_sub_daos(
to_binary(&subdaos)
}

pub fn query_sub_dao(deps: Deps, address: String) -> StdResult<Binary> {
let addr = deps.api.addr_validate(&address)?;
let item = SUBDAO_LIST.may_load(deps.storage, &addr)?;
match item {
None => Err(StdError::generic_err("SubDao not found")),
Some(charter) => to_binary(&SubDao {
addr: address,
charter,
}),
}
}

pub fn query_dao_uri(deps: Deps) -> StdResult<Binary> {
let config = CONFIG.load(deps.storage)?;
to_binary(&config.dao_uri)
Expand Down
2 changes: 2 additions & 0 deletions contracts/dao/cwd-core/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub enum QueryMsg {
start_after: Option<String>,
limit: Option<u32>,
},
/// Returns the SubDAO for a specific address if it in the list
GetSubDao { address: String },
/// Implements the DAO Star standard: https://daostar.one/EIP
DaoURI {},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cosmwasm_std::Empty;
use std::env::current_dir;
use std::fs::create_dir_all;

Expand All @@ -14,7 +15,7 @@ fn main() {

export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg<ProposeMessage>), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(QueryMsg<Empty>), &out_dir);
export_schema(&schema_for!(DepositInfoResponse), &out_dir);

export_schema_with_title(&schema_for!(Addr), &out_dir, "ProposalModuleResponse");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"title": "QueryMsg_for_Empty",
"oneOf": [
{
"description": "Gets the proposal module that this pre propose module is associated with. Returns `Addr`.",
Expand Down Expand Up @@ -63,6 +63,33 @@
}
},
"additionalProperties": false
},
{
"description": "Extension for queries. The default implementation will do nothing if queried for will return `Binary::default()`.",
"type": "object",
"required": [
"query_extension"
],
"properties": {
"query_extension": {
"type": "object",
"required": [
"msg"
],
"properties": {
"msg": {
"$ref": "#/definitions/Empty"
}
}
}
},
"additionalProperties": false
}
],
"definitions": {
"Empty": {
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::cw_serde;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult};
use cw2::set_contract_version;

use cwd_pre_propose_base::{
Expand All @@ -25,7 +25,7 @@ pub enum ProposeMessage {

pub type InstantiateMsg = InstantiateBase;
pub type ExecuteMsg = ExecuteBase<ProposeMessage>;
pub type QueryMsg = QueryBase;
pub type QueryMsg = QueryBase<Empty>;

/// Internal version of the propose message that includes the
/// `proposer` field. The module will fill this in based on the sender
Expand All @@ -40,7 +40,7 @@ enum ProposeMessageInternal {
},
}

type PrePropose = PreProposeContract<ProposeMessageInternal>;
type PrePropose = PreProposeContract<ProposeMessageInternal, Empty>;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ cwd-voting = { path = "../../../../packages/cwd-voting" }
neutron_bindings = { package = "neutron-sdk", version = "0.4.0" }
schemars = "0.8.8"
thiserror = { version = "1.0.31" }
neutron-subdao-core = { version = "*", path = "../../../../packages/neutron-subdao-core" }
cwd-core = { version = "*", path = "../../../../contracts/dao/cwd-core", features = ["library"] }
neutron-subdao-timelock-single = { version = "*", path = "../../../../packages/neutron-subdao-timelock-single" }
neutron-subdao-proposal-single = { version = "*", path = "../../../../packages/neutron-subdao-proposal-single" }
neutron-subdao-pre-propose-single = { version = "*", path = "../../../../packages/neutron-subdao-pre-propose-single" }
neutron-dao-pre-propose-overrule = { version = "*", path = "../../../../packages/neutron-dao-pre-propose-overrule" }
cwd-proposal-single = { version = "*", path = "../../../../contracts/dao/proposal/cwd-proposal-single", features = ["library"] }

[dev-dependencies]
cosmwasm-schema = "1.0.0"
cw-multi-test = "0.13.2"
cw-utils = "0.13.2"
cwd-proposal-single = { path = "../../proposal/cwd-proposal-single" }
cwd-core = { path = "../../cwd-core" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs::create_dir_all;
use cosmwasm_schema::{export_schema, export_schema_with_title, remove_schemas, schema_for};
use cosmwasm_std::Addr;
use cwd_pre_propose_base::msg::{DepositInfoResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
use cwd_pre_propose_overrule::contract::ProposeMessage;
use neutron_dao_pre_propose_overrule::msg::{ProposeMessage, QueryExt};

fn main() {
let mut out_dir = current_dir().unwrap();
Expand All @@ -14,7 +14,7 @@ fn main() {

export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg<ProposeMessage>), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(QueryMsg<QueryExt>), &out_dir);
export_schema(&schema_for!(DepositInfoResponse), &out_dir);

export_schema_with_title(&schema_for!(Addr), &out_dir, "ProposalModuleResponse");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"title": "QueryMsg_for_QueryExt",
"oneOf": [
{
"description": "Gets the proposal module that this pre propose module is associated with. Returns `Addr`.",
Expand Down Expand Up @@ -63,6 +63,59 @@
}
},
"additionalProperties": false
},
{
"description": "Extension for queries. The default implementation will do nothing if queried for will return `Binary::default()`.",
"type": "object",
"required": [
"query_extension"
],
"properties": {
"query_extension": {
"type": "object",
"required": [
"msg"
],
"properties": {
"msg": {
"$ref": "#/definitions/QueryExt"
}
}
}
},
"additionalProperties": false
}
],
"definitions": {
"QueryExt": {
"oneOf": [
{
"type": "object",
"required": [
"overrule_proposal_id"
],
"properties": {
"overrule_proposal_id": {
"type": "object",
"required": [
"subdao_proposal_id",
"timelock_address"
],
"properties": {
"subdao_proposal_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"timelock_address": {
"type": "string"
}
}
}
},
"additionalProperties": false
}
]
}
]
}
}
Loading

0 comments on commit 376cd05

Please sign in to comment.