Skip to content

Commit

Permalink
Revert "Add feature flag for cw20 support in dao-core. (#571)"
Browse files Browse the repository at this point in the history
This reverts commit 9afa125.
  • Loading branch information
0xekez committed Dec 16, 2022
1 parent 457dfea commit 1788eae
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 161 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ jobs:
env:
RUST_BACKTRACE: 1

- name: Run tests w/o default features
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: unit-test
args: --locked --no-default-features
env:
RUST_BACKTRACE: 1

- name: Compile WASM contract
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -76,13 +67,6 @@ jobs:
command: clippy
args: --all-targets -- -D warnings

- name: Run cargo clippy w/o default features
uses: actions-rs/cargo@v1
with:
toolchain: nightly
command: clippy
args: --all-targets --no-default-features -- -D warnings

- name: Generate Schema
run: ./scripts/schema.sh

Expand Down
3 changes: 0 additions & 3 deletions contracts/dao-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ crate-type = ["cdylib", "rlib"]
[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# enables cw20 treasury management
cw20 = []
# use library feature to disable all instantiate/execute/query exports
library = []
default = ["cw20"]

[dependencies]
cosmwasm-std = { workspace = true, features = ["ibc3"] }
Expand Down
72 changes: 0 additions & 72 deletions contracts/dao-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,3 @@ In additon to the wiki spec this contract may also pause. To do so a
`Pause` message must by executed by a proposal module. Pausing the
core module will stop all actions on the module for the duration of
the pause.

## Treasury management

For management of non-native assets this contract maintains a list of
[cw20](https://github.com/CosmWasm/cw-plus/tree/1568d9f7796ef93747e5e5e45484447fddbea80b/packages/cw20)
and
[cw721](https://github.com/CosmWasm/cw-nfts/tree/c7be7aba9fb270abefee5a3696be62f2736592a0/packages/cw721)
tokens who's balances the DAO would like to track. This allows
frontends to list these tokens in the DAO's treasury. This tracking is
needed as, for non-native tokens, there is no on-chain data source for
all of the cw20 and cw721 tokens owned by a DAO. It may also help
reduce spam as random shitcoins sent to the DAO won't be displayed in
treasury listings, unless the DAO approves them.

For native tokens we do not need this additional tracking step, as
native token balances are stored in the [bank
module](https://github.com/cosmos/cosmos-sdk/tree/main/x/bank). Thus,
for those tokens frontends can query the chain directly to discover
which tokens the DAO owns.

### Managing the treasury

There are two ways that a non-native token may be added to the DAO
treasury.

If `automatically_add_[cw20s|cw721s]` is set to true in the [DAO's
config](https://github.com/DA0-DA0/dao-contracts/blob/74bd3881fdd86829e5e8b132b9952dd64f2d0737/contracts/dao-core/src/state.rs#L16-L21),
the DAO will add the token to the treasury upon receiving the token
via cw20's `Send` method and cw721's `SendNft` method.

```
pub enum ExecuteMsg {
/// Executed when the contract receives a cw20 token. Depending on
/// the contract's configuration the contract will automatically
/// add the token to its treasury.
#[cfg(feature = "cw20")]
Receive(cw20::Cw20ReceiveMsg),
/// Executed when the contract receives a cw721 token. Depending
/// on the contract's configuration the contract will
/// automatically add the token to its treasury.
ReceiveNft(cw721::Cw721ReceiveMsg),
// ...
}
```

The DAO may always add or remove non-native tokens via the
`UpdateCw20List` and `UpdateCw721List` methods:

```rust
pub enum ExecuteMsg {
/// Updates the list of cw20 tokens this contract has registered.
#[cfg(feature = "cw20")]
UpdateCw20List {
to_add: Vec<String>,
to_remove: Vec<String>,
},
/// Updates the list of cw721 tokens this contract has registered.
UpdateCw721List {
to_add: Vec<String>,
to_remove: Vec<String>,
},
// ...
}
```

### Disabling cw20 support

There is an effort on CosmWasm chains to depreciate the cw20 standard
in favor of native tokens [generated by the TokenFactory
module](https://hackmd.io/@reecepbcups/cw20-to-tokenfactory). By
default, this contract has cw20 support. It may be disabled by
disabling default features (ex. `cargo build --no-default-features`).
20 changes: 3 additions & 17 deletions contracts/dao-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ use dao_interface::{voting, ModuleInstantiateCallback, ModuleInstantiateInfo};

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InitialItem, InstantiateMsg, MigrateMsg, QueryMsg};
#[cfg(feature = "cw20")]
use crate::query::Cw20BalanceResponse;
use crate::query::{
AdminNominationResponse, DaoURIResponse, DumpStateResponse, GetItemResponse, PauseInfoResponse,
SubDao,
AdminNominationResponse, Cw20BalanceResponse, DaoURIResponse, DumpStateResponse,
GetItemResponse, PauseInfoResponse, SubDao,
};
#[cfg(feature = "cw20")]
use crate::state::CW20_LIST;
use crate::state::{
Config, ProposalModule, ProposalModuleStatus, ACTIVE_PROPOSAL_MODULE_COUNT, ADMIN, CONFIG,
CW721_LIST, ITEMS, NOMINATED_ADMIN, PAUSED, PROPOSAL_MODULES, SUBDAO_LIST,
CW20_LIST, CW721_LIST, ITEMS, NOMINATED_ADMIN, PAUSED, PROPOSAL_MODULES, SUBDAO_LIST,
TOTAL_PROPOSAL_MODULE_COUNT, VOTING_MODULE,
};

Expand All @@ -47,7 +43,6 @@ pub fn instantiate(
name: msg.name,
description: msg.description,
image_url: msg.image_url,
#[cfg(feature = "cw20")]
automatically_add_cw20s: msg.automatically_add_cw20s,
automatically_add_cw721s: msg.automatically_add_cw721s,
dao_uri: msg.dao_uri,
Expand Down Expand Up @@ -114,15 +109,13 @@ pub fn execute(
execute_proposal_hook(deps.as_ref(), info.sender, msgs)
}
ExecuteMsg::Pause { duration } => execute_pause(deps, env, info.sender, duration),
#[cfg(feature = "cw20")]
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),
ExecuteMsg::SetItem { key, value } => execute_set_item(deps, env, info.sender, key, value),
ExecuteMsg::UpdateConfig { config } => {
execute_update_config(deps, env, info.sender, config)
}
#[cfg(feature = "cw20")]
ExecuteMsg::UpdateCw20List { to_add, to_remove } => {
execute_update_cw20_list(deps, env, info.sender, to_add, to_remove)
}
Expand Down Expand Up @@ -404,7 +397,6 @@ fn do_update_addr_list(
Ok(())
}

#[cfg(feature = "cw20")]
pub fn execute_update_cw20_list(
deps: DepsMut,
env: Env,
Expand Down Expand Up @@ -512,7 +504,6 @@ pub fn execute_update_sub_daos_list(
.add_attribute("sender", sender))
}

#[cfg(feature = "cw20")]
pub fn execute_receive_cw20(deps: DepsMut, sender: Addr) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;
if !config.automatically_add_cw20s {
Expand Down Expand Up @@ -543,9 +534,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::Admin {} => query_admin(deps),
QueryMsg::AdminNomination {} => query_admin_nomination(deps),
QueryMsg::Config {} => query_config(deps),
#[cfg(feature = "cw20")]
QueryMsg::Cw20TokenList { start_after, limit } => query_cw20_list(deps, start_after, limit),
#[cfg(feature = "cw20")]
QueryMsg::Cw20Balances { start_after, limit } => {
query_cw20_balances(deps, env, start_after, limit)
}
Expand Down Expand Up @@ -738,7 +727,6 @@ pub fn query_list_items(
)?)
}

#[cfg(feature = "cw20")]
pub fn query_cw20_list(
deps: Deps,
start_after: Option<String>,
Expand Down Expand Up @@ -771,7 +759,6 @@ pub fn query_cw721_list(
)?)
}

#[cfg(feature = "cw20")]
pub fn query_cw20_balances(
deps: Deps,
env: Env,
Expand Down Expand Up @@ -879,7 +866,6 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, Co
name: v1_config.name,
description: v1_config.description,
image_url: v1_config.image_url,
#[cfg(feature = "cw20")]
automatically_add_cw20s: v1_config.automatically_add_cw20s,
automatically_add_cw721s: v1_config.automatically_add_cw721s,
dao_uri,
Expand Down
5 changes: 0 additions & 5 deletions contracts/dao-core/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub struct InstantiateMsg {

/// If true the contract will automatically add received cw20
/// tokens to its treasury.
#[cfg(feature = "cw20")]
pub automatically_add_cw20s: bool,
/// If true the contract will automatically add received cw721
/// tokens to its treasury.
Expand Down Expand Up @@ -67,7 +66,6 @@ pub enum ExecuteMsg {
/// Executed when the contract receives a cw20 token. Depending on
/// the contract's configuration the contract will automatically
/// add the token to its treasury.
#[cfg(feature = "cw20")]
Receive(cw20::Cw20ReceiveMsg),
/// Executed when the contract receives a cw721 token. Depending
/// on the contract's configuration the contract will
Expand Down Expand Up @@ -104,7 +102,6 @@ pub enum ExecuteMsg {
/// governance contract config with the provided config.
UpdateConfig { config: Config },
/// Updates the list of cw20 tokens this contract has registered.
#[cfg(feature = "cw20")]
UpdateCw20List {
to_add: Vec<String>,
to_remove: Vec<String>,
Expand Down Expand Up @@ -148,15 +145,13 @@ pub enum QueryMsg {
Config {},
/// Gets the token balance for each cw20 registered with the
/// contract.
#[cfg(feature = "cw20")]
#[returns(crate::query::Cw20BalanceResponse)]
Cw20Balances {
start_after: Option<String>,
limit: Option<u32>,
},
/// Lists the addresses of the cw20 tokens in this contract's
/// treasury.
#[cfg(feature = "cw20")]
#[returns(Vec<cosmwasm_std::Addr>)]
Cw20TokenList {
start_after: Option<String>,
Expand Down
5 changes: 2 additions & 3 deletions contracts/dao-core/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Addr;
use cosmwasm_std::{Addr, Uint128};
use cw2::ContractVersion;
use cw_utils::Expiration;

Expand Down Expand Up @@ -45,12 +45,11 @@ pub struct GetItemResponse {

/// Returned by the `Cw20Balances` query.
#[cw_serde]
#[cfg(feature = "cw20")]
pub struct Cw20BalanceResponse {
/// The address of the token.
pub addr: Addr,
/// The contract's balance.
pub balance: cosmwasm_std::Uint128,
pub balance: Uint128,
}

/// Returned by the `AdminNomination` query.
Expand Down
6 changes: 2 additions & 4 deletions contracts/dao-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub struct Config {
pub image_url: Option<String>,
/// If true the contract will automatically add received cw20
/// tokens to its treasury.
#[cfg(feature = "cw20")]
pub automatically_add_cw20s: bool,
/// If true the contract will automatically add received cw721
/// tokens to its treasury.
Expand All @@ -25,8 +24,8 @@ pub struct Config {
pub dao_uri: Option<String>,
}

/// Top level type describing a proposal module.
#[cw_serde]
/// Top level type describing a proposal module.
pub struct ProposalModule {
/// The address of the proposal module.
pub address: Addr,
Expand All @@ -37,8 +36,8 @@ pub struct ProposalModule {
pub status: ProposalModuleStatus,
}

/// The status of a proposal module.
#[cw_serde]
/// The status of a proposal module.
pub enum ProposalModuleStatus {
Enabled,
Disabled,
Expand Down Expand Up @@ -87,7 +86,6 @@ pub const ITEMS: Map<String, String> = Map::new("items");

/// Set of cw20 tokens that have been registered with this contract's
/// treasury.
#[cfg(feature = "cw20")]
pub const CW20_LIST: Map<Addr, Empty> = Map::new("cw20s");
/// Set of cw721 tokens that have been registered with this contract's
/// treasury.
Expand Down
Loading

0 comments on commit 1788eae

Please sign in to comment.