Skip to content

Commit

Permalink
[feature] Updated SubDao functionality to have members count and an a…
Browse files Browse the repository at this point in the history
…ctive threshold. Fixes DA0-DA0#781
  • Loading branch information
theghostmac committed Mar 12, 2024
1 parent ef21c63 commit 02377ae
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 19 deletions.
54 changes: 48 additions & 6 deletions contracts/dao-dao-core/schema/dao-dao-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -1317,19 +1317,33 @@
"SubDao": {
"type": "object",
"required": [
"addr"
"active_threshold",
"addr",
"member_count"
],
"properties": {
"active_threshold": {
"description": "The minimum number of members required for the SubDAO to be considered active.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"addr": {
"description": "The contract address of the SubDAO",
"type": "string"
},
"charter": {
"description": "The purpose/constitution for the SubDAO",
"description": "The purpose/constitution for the SubDAO. This field is optional.",
"type": [
"string",
"null"
]
},
"member_count": {
"description": "The current number of members in the SubDAO.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2250,19 +2264,33 @@
"SubDao": {
"type": "object",
"required": [
"addr"
"active_threshold",
"addr",
"member_count"
],
"properties": {
"active_threshold": {
"description": "The minimum number of members required for the SubDAO to be considered active.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"addr": {
"description": "The contract address of the SubDAO",
"type": "string"
},
"charter": {
"description": "The purpose/constitution for the SubDAO",
"description": "The purpose/constitution for the SubDAO. This field is optional.",
"type": [
"string",
"null"
]
},
"member_count": {
"description": "The current number of members in the SubDAO.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2898,19 +2926,33 @@
"SubDao": {
"type": "object",
"required": [
"addr"
"active_threshold",
"addr",
"member_count"
],
"properties": {
"active_threshold": {
"description": "The minimum number of members required for the SubDAO to be considered active.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"addr": {
"description": "The contract address of the SubDAO",
"type": "string"
},
"charter": {
"description": "The purpose/constitution for the SubDAO",
"description": "The purpose/constitution for the SubDAO. This field is optional.",
"type": [
"string",
"null"
]
},
"member_count": {
"description": "The current number of members in the SubDAO.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down
12 changes: 7 additions & 5 deletions contracts/dao-dao-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ pub fn execute_update_sub_daos_list(

for subdao in to_add {
let addr = deps.api.addr_validate(&subdao.addr)?;
SUBDAO_LIST.save(deps.storage, &addr, &subdao.charter)?;
SUBDAO_LIST.save(deps.storage, &addr, &subdao)?; // Save the entire SubDao object.
}

Ok(Response::default()
Expand Down Expand Up @@ -814,19 +814,21 @@ pub fn query_list_sub_daos(
.map(|addr| deps.api.addr_validate(&addr))
.transpose()?;

let subdaos = cw_paginate_storage::paginate_map(
let subdaos = paginate_map(
deps,
&SUBDAO_LIST,
start_at.as_ref(),
limit,
cosmwasm_std::Order::Ascending,
Order::Ascending,
)?;

let subdaos: Vec<SubDao> = subdaos
.into_iter()
.map(|(address, charter)| SubDao {
.map(|(address, subdao)| SubDao {
addr: address.into_string(),
charter,
charter: subdao.charter, // mapping correctly to the updated SubDao structure.
member_count: subdao.member_count, // Include member count.
active_threshold: subdao.active_threshold, // Include active threshold.
})
.collect();

Expand Down
3 changes: 2 additions & 1 deletion contracts/dao-dao-core/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cosmwasm_std::{Addr, Empty};
use cw_storage_plus::{Item, Map};
use cw_utils::Expiration;
use dao_interface::query::SubDao;
use dao_interface::state::{Config, ProposalModule};

/// The admin of the contract. Typically a DAO. The contract admin may
Expand Down Expand Up @@ -52,4 +53,4 @@ pub const CW20_LIST: Map<Addr, Empty> = Map::new("cw20s");
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");
pub const SUBDAO_LIST: Map<&Addr, SubDao> = Map::new("sub_daos");
20 changes: 18 additions & 2 deletions contracts/dao-dao-core/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3003,18 +3003,26 @@ fn test_add_remove_subdaos() {
SubDao {
addr: "subdao001".to_string(),
charter: None,
member_count: 10,
active_threshold: 5,
},
SubDao {
addr: "subdao002".to_string(),
charter: Some("cool charter bro".to_string()),
member_count: 20,
active_threshold: 10,
},
SubDao {
addr: "subdao005".to_string(),
charter: None,
member_count: 15,
active_threshold: 7,
},
SubDao {
addr: "subdao007".to_string(),
charter: None,
member_count: 25,
active_threshold: 12,
},
];
let to_remove: Vec<String> = vec![];
Expand All @@ -3025,7 +3033,7 @@ fn test_add_remove_subdaos() {
&ExecuteMsg::UpdateSubDaos { to_add, to_remove },
&[],
)
.unwrap();
.unwrap();

let res: Vec<SubDao> = app
.wrap()
Expand All @@ -3051,7 +3059,7 @@ fn test_add_remove_subdaos() {
},
&[],
)
.unwrap();
.unwrap();

let res: Vec<SubDao> = app
.wrap()
Expand All @@ -3069,6 +3077,8 @@ fn test_add_remove_subdaos() {
let test_res: SubDao = SubDao {
addr: "subdao002".to_string(),
charter: Some("cool charter bro".to_string()),
member_count: 20,
active_threshold: 10,
};

assert_eq!(res[1], test_res);
Expand All @@ -3077,14 +3087,20 @@ fn test_add_remove_subdaos() {
SubDao {
addr: "subdao001".to_string(),
charter: None,
member_count: 10,
active_threshold: 5,
},
SubDao {
addr: "subdao002".to_string(),
charter: Some("cool charter bro".to_string()),
member_count: 20,
active_threshold: 10,
},
SubDao {
addr: "subdao007".to_string(),
charter: None,
member_count: 25,
active_threshold: 12,
},
];

Expand Down
36 changes: 32 additions & 4 deletions contracts/external/dao-migrator/schema/dao-migrator.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,33 @@
"SubDao": {
"type": "object",
"required": [
"addr"
"active_threshold",
"addr",
"member_count"
],
"properties": {
"active_threshold": {
"description": "The minimum number of members required for the SubDAO to be considered active.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"addr": {
"description": "The contract address of the SubDAO",
"type": "string"
},
"charter": {
"description": "The purpose/constitution for the SubDAO",
"description": "The purpose/constitution for the SubDAO. This field is optional.",
"type": [
"string",
"null"
]
},
"member_count": {
"description": "The current number of members in the SubDAO.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down Expand Up @@ -671,19 +685,33 @@
"SubDao": {
"type": "object",
"required": [
"addr"
"active_threshold",
"addr",
"member_count"
],
"properties": {
"active_threshold": {
"description": "The minimum number of members required for the SubDAO to be considered active.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"addr": {
"description": "The contract address of the SubDAO",
"type": "string"
},
"charter": {
"description": "The purpose/constitution for the SubDAO",
"description": "The purpose/constitution for the SubDAO. This field is optional.",
"type": [
"string",
"null"
]
},
"member_count": {
"description": "The current number of members in the SubDAO.",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down
2 changes: 2 additions & 0 deletions contracts/external/dao-migrator/src/testing/test_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ fn test_sub_daos() {
let sub_dao = SubDao {
addr: "sub_dao_1".to_string(),
charter: None,
member_count: 0,
active_threshold: 1,
};

execute_migration(
Expand Down
6 changes: 5 additions & 1 deletion packages/dao-interface/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ pub struct AdminNominationResponse {
pub struct SubDao {
/// The contract address of the SubDAO
pub addr: String,
/// The purpose/constitution for the SubDAO
/// The purpose/constitution for the SubDAO. This field is optional.
pub charter: Option<String>,
/// The current number of members in the SubDAO.
pub member_count: u32,
/// The minimum number of members required for the SubDAO to be considered active.
pub active_threshold: u32,
}

#[cw_serde]
Expand Down

0 comments on commit 02377ae

Please sign in to comment.