Skip to content

Commit

Permalink
Merge pull request #241 from NinoLipartiia/dao-proposals
Browse files Browse the repository at this point in the history
CronCat automatically executes passed DAO DAO proposals
  • Loading branch information
mikedotexe authored Dec 22, 2022
2 parents eb19b3e + 9b20813 commit 64af446
Show file tree
Hide file tree
Showing 31 changed files with 922 additions and 32 deletions.
4 changes: 2 additions & 2 deletions checksum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
fc76a0e370c9e947d6e33d018585137d566f32d1a1fb06b1b49e695e5984a57e cw_croncat.wasm
348ce203ce7a18c2e28f001139c1f7a215f7a569c735825dc819dc79692aaffb cw_rules.wasm
2d2b8d5bb188d7a29b24a00c5fcb87c1e2e4f7c53c0f4bf176e2dc2024bd2cc6 cw_croncat.wasm
307b8919d8fcae59dd7336319c6220fe5c477488b59bf043158fba67a292234d cw_rules.wasm
9 changes: 6 additions & 3 deletions contracts/cw-croncat/src/balancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ pub struct RoundRobinBalancer {
}

impl RoundRobinBalancer {
pub fn default() -> RoundRobinBalancer {
RoundRobinBalancer::new(BalancerMode::ActivationOrder)
}
pub fn new(mode: BalancerMode) -> RoundRobinBalancer {
RoundRobinBalancer { mode }
}
Expand Down Expand Up @@ -292,3 +289,9 @@ impl<'a> Balancer<'a> for RoundRobinBalancer {
Ok(())
}
}

impl Default for RoundRobinBalancer {
fn default() -> RoundRobinBalancer {
RoundRobinBalancer::new(BalancerMode::ActivationOrder)
}
}
6 changes: 1 addition & 5 deletions contracts/cw-croncat/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ impl<'a> CwCroncat<'a> {
// It's possible there are more "covered tasks" than total tasks,
// so use saturating subtraction to hit zero and not go below
let total_tasks_needing_agents = total_tasks.saturating_sub(num_tasks_covered);
let remainder = if total_tasks_needing_agents % max_tasks == 0 {
0
} else {
1
};
let remainder = u64::from(total_tasks_needing_agents % max_tasks != 0);
total_tasks_needing_agents / max_tasks + remainder
} else {
0
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-croncat/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'a> CwCroncat<'a> {

// Querier guarantees to returns up-to-date data, including funds sent in this handle message
// https://github.com/CosmWasm/wasmd/blob/master/x/wasm/internal/keeper/keeper.go#L185-L192
let state_balances = deps.querier.query_all_balances(&env.contract.address)?;
let state_balances = deps.querier.query_all_balances(env.contract.address)?;
let mut has_fund_err = false;

let messages: Result<Vec<SubMsg>, ContractError> = balances
Expand Down
42 changes: 40 additions & 2 deletions contracts/cw-rules/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use cw_rules_core::msg::{QueryConstruct, QueryConstructResponse};
use cw_rules_core::types::{CheckOwnerOfNft, CheckProposalStatus, CroncatQuery, HasBalanceGte};
use cw_rules_core::types::{
CheckOwnerOfNft, CheckPassedProposals, CheckProposalStatus, CroncatQuery, HasBalanceGte,
};
// use schemars::JsonSchema;
// use serde::{Deserialize, Serialize};

Expand All @@ -21,7 +23,7 @@ use cw_rules_core::msg::{ExecuteMsg, InstantiateMsg, QueryMsg, QueryResponse};

//use cosmwasm_std::from_binary;
//use crate::msg::QueryMultiResponse;
use crate::types::dao::{ProposalResponse, QueryDao, Status};
use crate::types::dao::{ProposalListResponse, ProposalResponse, QueryDao, Status};
use generic_query::GenericQuery;

// version info for migration info
Expand Down Expand Up @@ -87,6 +89,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
proposal_id,
status,
)?),
QueryMsg::CheckPassedProposals(CheckPassedProposals { dao_address }) => {
to_binary(&query_dao_proposals(deps, dao_address)?)
}
QueryMsg::GenericQuery(query) => to_binary(&generic_query(deps, query)?),
QueryMsg::SmartQuery(query) => to_binary(&smart_query(deps, query)?),
QueryMsg::QueryConstruct(QueryConstruct { queries }) => {
Expand Down Expand Up @@ -203,6 +208,36 @@ fn query_dao_proposal_status(
})
}

// Check for passed proposals
// Return the first passed proposal
fn query_dao_proposals(deps: Deps, dao_address: String) -> StdResult<QueryResponse> {
let dao_addr = deps.api.addr_validate(&dao_address)?;
// Query the amount of proposals
let proposal_count = deps
.querier
.query_wasm_smart(dao_addr.clone(), &QueryDao::ProposalCount {})?;
let res: ProposalListResponse = deps.querier.query_wasm_smart(
dao_addr,
&QueryDao::ListProposals {
start_after: None,
limit: Some(proposal_count),
},
)?;

for proposal_response in &res.proposals {
if proposal_response.proposal.status == Status::Passed {
return Ok(QueryResponse {
result: true,
data: to_binary(&proposal_response.id)?,
});
}
}
Ok(QueryResponse {
result: false,
data: to_binary(&res.proposals)?,
})
}

// // // GOAL:
// // // Parse a generic query response, and inject input for the next query
// // fn query_chain(deps: Deps, env: Env) -> StdResult<QueryMultiResponse> {
Expand Down Expand Up @@ -256,6 +291,9 @@ fn query_construct(deps: Deps, queries: Vec<CroncatQuery>) -> StdResult<QueryCon
proposal_id,
status,
}) => query_dao_proposal_status(deps, dao_address, proposal_id, status),
CroncatQuery::CheckPassedProposals(CheckPassedProposals { dao_address }) => {
query_dao_proposals(deps, dao_address)
}
CroncatQuery::GenericQuery(query) => generic_query(deps, query),
CroncatQuery::SmartQuery(query) => smart_query(deps, query),
}?;
Expand Down
Loading

0 comments on commit 64af446

Please sign in to comment.