Skip to content

Commit

Permalink
Add pre-propose-approval support for multiple choice proposals, and f…
Browse files Browse the repository at this point in the history
…reeze approver (#883)

* moved common pre-propose-approval types to dao-voting package

* added dao-pre-propose-approval-multiple contract

* added multiple choice approver tests

* lock approver in pending proposal on propose instead of using most recent approver

* updated schema
  • Loading branch information
NoahSaso authored Oct 31, 2024
1 parent ee38828 commit fe0209a
Show file tree
Hide file tree
Showing 27 changed files with 8,643 additions and 180 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ dao-dao-core = { path = "./contracts/dao-dao-core", version = "2.5.1" }
dao-dao-macros = { path = "./packages/dao-dao-macros", version = "2.5.1" }
dao-hooks = { path = "./packages/dao-hooks", version = "2.5.1" }
dao-interface = { path = "./packages/dao-interface", version = "2.5.1" }
dao-pre-propose-approval-multiple = { path = "./contracts/pre-propose/dao-pre-propose-approval-multiple", version = "2.5.1" }
dao-migrator = { path = "./contracts/external/dao-migrator", version = "2.5.1" }
dao-pre-propose-approval-single = { path = "./contracts/pre-propose/dao-pre-propose-approval-single", version = "2.5.1" }
dao-pre-propose-approver = { path = "./contracts/pre-propose/dao-pre-propose-approver", version = "2.5.1" }
Expand Down
44 changes: 44 additions & 0 deletions contracts/pre-propose/dao-pre-propose-approval-multiple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "dao-pre-propose-approval-multiple"
authors = ["ekez <[email protected]>", "Jake Hartnell <[email protected]>", "noah <[email protected]>"]
description = "A DAO DAO pre-propose module handling a proposal approval flow for for dao-proposal-multiple."
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
version = { workspace = true }

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
cw-paginate-storage = { workspace = true }
dao-pre-propose-base = { workspace = true }
dao-voting = { workspace = true }
thiserror = { workspace = true }
dao-interface = { workspace = true }

[dev-dependencies]
cw-denom = { workspace = true }
cw-multi-test = { workspace = true }
cw-utils = { workspace = true }
cw4 = { workspace = true }
cw4-group = { workspace = true }
cw20 = { workspace = true }
cw20-base = { workspace = true }
dao-dao-core = { workspace = true }
dao-hooks = { workspace = true }
dao-testing = { workspace = true }
dao-voting = { workspace = true }
dao-voting-cw4 = { workspace = true }
dao-voting-cw20-staked = { workspace = true }
dao-proposal-multiple = { workspace = true }
78 changes: 78 additions & 0 deletions contracts/pre-propose/dao-pre-propose-approval-multiple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Multi choice proposal approval contract

[![dao-pre-propose-approval-multiple on crates.io](https://img.shields.io/crates/v/dao-pre-propose-approval-multiple.svg?logo=rust)](https://crates.io/crates/dao-pre-propose-approval-multiple)
[![docs.rs](https://img.shields.io/docsrs/dao-pre-propose-approval-multiple?logo=docsdotrs)](https://docs.rs/dao-pre-propose-approval-multiple/latest/dao_pre_propose_approval_multiple/)

This contract implements an approval flow for proposals, it also handles deposit logic. It works with the `dao-proposal-multiple` proposal module.

## Approval Logic

This contract is instantatied with an `approver` address. This address is
allowed to approve or reject the proposal. An approved proposal opens for voting
immediately, whereas a rejected proposal is simply discarded.

```text
┌──────────┐
│ │
│ Account │
│ │
└─────┬────┘
│ Makes prop
┌────────────────────────┐ ┌────────────────────────┐
│ │ │ │
│ Pre-propose Approval │ ◄─────────────┤ Approver Address │
│ │ Approves │ │
└───────────┬────────────┘ or rejects └────────────────────────┘
│ Creates prop
│ on approval
┌──────────────────────────┐
│ │
│ Proposal Multiple │
│ │
└───────────┬──────────────┘
│ Normal voting
┌────────────────────────┐
│ │
│ Main DAO │
│ │
└────────────────────────┘
```

The `approver` may also register a `ProposalSubmitHook`, which fires every time a proposal is submitted to the `dao-pre-propose-approval-multiple` contract.

## Deposit Logic

It may accept either native ([bank
module](https://docs.cosmos.network/main/modules/bank/)),
[cw20](https://github.com/CosmWasm/cw-plus/tree/bc339368b1ee33c97c55a19d4cff983c7708ce36/packages/cw20)
tokens, or no tokens as a deposit. If a proposal deposit is enabled
the following refund strategies are avaliable:

1. Never refund deposits. All deposits are sent to the DAO on proposal
completion.
2. Always refund deposits. Deposits are returned to the proposer on
proposal completion and even rejection by the `approver`.
3. Only refund passed proposals. Deposits are only returned to the
proposer if the proposal is approved and passes. Otherwise, they
are sent to the DAO.

This module may also be configured to only accept proposals from
members (addresses with voting power) of the DAO.

Here is a flowchart showing the proposal creation process using this
module:

![](https://bafkreig42cxswefi2ks7vhrwyvkcnumbnwdk7ov643yaafm7loi6vh2gja.ipfs.nftstorage.link)

### Resources

More about the [pre-propose design](https://github.com/DA0-DA0/dao-contracts/wiki/Pre-propose-module-design).

More about [pre-propose modules](https://github.com/DA0-DA0/dao-contracts/wiki/DAO-DAO-Contracts-Design#pre-propose-modules).
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_schema::write_api;
use dao_pre_propose_approval_multiple::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg,
migrate: MigrateMsg,
}
}
Loading

0 comments on commit fe0209a

Please sign in to comment.