Skip to content

Commit

Permalink
Support using newly created token factory denom as proposal deposit d…
Browse files Browse the repository at this point in the history
…uring instantiation.
  • Loading branch information
NoahSaso committed Dec 17, 2023
1 parent a3f15d7 commit 1474cd7
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"additionalProperties": false
},
{
"description": "Use the token address of the associated DAO's voting module. NOTE: in order to use the token address of the voting module the voting module must (1) use a cw20 token and (2) implement the `TokenContract {}` query type defined by `dao_dao_macros::token_query`. Failing to implement that and using this option will cause instantiation to fail.",
"description": "Use the token native denom or cw20 contract address of the associated DAO's voting module. NOTE: in order to retrieve the token automatically via this variant, the voting module must either (1) use a native token and implement the `Denom {}` query type defined by `dao_dao_macros::native_token_query` OR (2) use a cw20 token and implement the `TokenContract {}` query type defined by `dao_dao_macros::cw20_token_query`. Failing to implement correctly will cause this option to fail to instantiate.",
"type": "object",
"required": [
"voting_module_token"
Expand Down Expand Up @@ -609,7 +609,7 @@
"additionalProperties": false
},
{
"description": "Use the token address of the associated DAO's voting module. NOTE: in order to use the token address of the voting module the voting module must (1) use a cw20 token and (2) implement the `TokenContract {}` query type defined by `dao_dao_macros::token_query`. Failing to implement that and using this option will cause instantiation to fail.",
"description": "Use the token native denom or cw20 contract address of the associated DAO's voting module. NOTE: in order to retrieve the token automatically via this variant, the voting module must either (1) use a native token and implement the `Denom {}` query type defined by `dao_dao_macros::native_token_query` OR (2) use a cw20 token and implement the `TokenContract {}` query type defined by `dao_dao_macros::cw20_token_query`. Failing to implement correctly will cause this option to fail to instantiate.",
"type": "object",
"required": [
"voting_module_token"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
"additionalProperties": false
},
{
"description": "Use the token address of the associated DAO's voting module. NOTE: in order to use the token address of the voting module the voting module must (1) use a cw20 token and (2) implement the `TokenContract {}` query type defined by `dao_dao_macros::token_query`. Failing to implement that and using this option will cause instantiation to fail.",
"description": "Use the token native denom or cw20 contract address of the associated DAO's voting module. NOTE: in order to retrieve the token automatically via this variant, the voting module must either (1) use a native token and implement the `Denom {}` query type defined by `dao_dao_macros::native_token_query` OR (2) use a cw20 token and implement the `TokenContract {}` query type defined by `dao_dao_macros::cw20_token_query`. Failing to implement correctly will cause this option to fail to instantiate.",
"type": "object",
"required": [
"voting_module_token"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"additionalProperties": false
},
{
"description": "Use the token address of the associated DAO's voting module. NOTE: in order to use the token address of the voting module the voting module must (1) use a cw20 token and (2) implement the `TokenContract {}` query type defined by `dao_dao_macros::token_query`. Failing to implement that and using this option will cause instantiation to fail.",
"description": "Use the token native denom or cw20 contract address of the associated DAO's voting module. NOTE: in order to retrieve the token automatically via this variant, the voting module must either (1) use a native token and implement the `Denom {}` query type defined by `dao_dao_macros::native_token_query` OR (2) use a cw20 token and implement the `TokenContract {}` query type defined by `dao_dao_macros::cw20_token_query`. Failing to implement correctly will cause this option to fail to instantiate.",
"type": "object",
"required": [
"voting_module_token"
Expand Down Expand Up @@ -601,7 +601,7 @@
"additionalProperties": false
},
{
"description": "Use the token address of the associated DAO's voting module. NOTE: in order to use the token address of the voting module the voting module must (1) use a cw20 token and (2) implement the `TokenContract {}` query type defined by `dao_dao_macros::token_query`. Failing to implement that and using this option will cause instantiation to fail.",
"description": "Use the token native denom or cw20 contract address of the associated DAO's voting module. NOTE: in order to retrieve the token automatically via this variant, the voting module must either (1) use a native token and implement the `Denom {}` query type defined by `dao_dao_macros::native_token_query` OR (2) use a cw20 token and implement the `TokenContract {}` query type defined by `dao_dao_macros::cw20_token_query`. Failing to implement correctly will cause this option to fail to instantiate.",
"type": "object",
"required": [
"voting_module_token"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"additionalProperties": false
},
{
"description": "Use the token address of the associated DAO's voting module. NOTE: in order to use the token address of the voting module the voting module must (1) use a cw20 token and (2) implement the `TokenContract {}` query type defined by `dao_dao_macros::token_query`. Failing to implement that and using this option will cause instantiation to fail.",
"description": "Use the token native denom or cw20 contract address of the associated DAO's voting module. NOTE: in order to retrieve the token automatically via this variant, the voting module must either (1) use a native token and implement the `Denom {}` query type defined by `dao_dao_macros::native_token_query` OR (2) use a cw20 token and implement the `TokenContract {}` query type defined by `dao_dao_macros::cw20_token_query`. Failing to implement correctly will cause this option to fail to instantiate.",
"type": "object",
"required": [
"voting_module_token"
Expand Down Expand Up @@ -601,7 +601,7 @@
"additionalProperties": false
},
{
"description": "Use the token address of the associated DAO's voting module. NOTE: in order to use the token address of the voting module the voting module must (1) use a cw20 token and (2) implement the `TokenContract {}` query type defined by `dao_dao_macros::token_query`. Failing to implement that and using this option will cause instantiation to fail.",
"description": "Use the token native denom or cw20 contract address of the associated DAO's voting module. NOTE: in order to retrieve the token automatically via this variant, the voting module must either (1) use a native token and implement the `Denom {}` query type defined by `dao_dao_macros::native_token_query` OR (2) use a cw20 token and implement the `TokenContract {}` query type defined by `dao_dao_macros::cw20_token_query`. Failing to implement correctly will cause this option to fail to instantiate.",
"type": "object",
"required": [
"voting_module_token"
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/dao-voting-cw20-balance/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses};
use cw20::Cw20Coin;
use cw20_base::msg::InstantiateMarketingInfo;

use dao_dao_macros::{token_query, voting_module_query};
use dao_dao_macros::{cw20_token_query, voting_module_query};

#[cw_serde]
pub enum TokenInfo {
Expand All @@ -30,7 +30,7 @@ pub struct InstantiateMsg {
#[cw_serde]
pub enum ExecuteMsg {}

#[token_query]
#[cw20_token_query]
#[voting_module_query]
#[cw_serde]
#[derive(QueryResponses)]
Expand Down
4 changes: 2 additions & 2 deletions contracts/voting/dao-voting-cw20-staked/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cw20::Cw20Coin;
use cw20_base::msg::InstantiateMarketingInfo;
use cw_utils::Duration;

use dao_dao_macros::{active_query, token_query, voting_module_query};
use dao_dao_macros::{active_query, cw20_token_query, voting_module_query};
use dao_voting::threshold::{ActiveThreshold, ActiveThresholdResponse};

Check warning on line 8 in contracts/voting/dao-voting-cw20-staked/src/msg.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ActiveThresholdResponse`

Check warning on line 8 in contracts/voting/dao-voting-cw20-staked/src/msg.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ActiveThresholdResponse`

/// Information about the staking contract to be used with this voting
Expand Down Expand Up @@ -71,7 +71,7 @@ pub enum ExecuteMsg {
}

#[voting_module_query]
#[token_query]
#[cw20_token_query]
#[active_query]
#[cw_serde]
#[derive(QueryResponses)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,19 +587,6 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"denom"
],
"properties": {
"denom": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand Down Expand Up @@ -689,6 +676,19 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"denom"
],
"properties": {
"denom": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand Down
8 changes: 5 additions & 3 deletions contracts/voting/dao-voting-token-staked/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use dao_hooks::stake::{stake_hook_msgs, unstake_hook_msgs};
use dao_interface::{
state::ModuleInstantiateCallback,
token::{InitialBalance, NewTokenInfo, TokenFactoryCallback},
voting::{IsActiveResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse},
voting::{
DenomResponse, IsActiveResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse,
},
};
use dao_voting::{
duration::validate_duration,
Expand All @@ -30,8 +32,8 @@ use dao_voting::{

use crate::error::ContractError;
use crate::msg::{
DenomResponse, ExecuteMsg, GetHooksResponse, InstantiateMsg, ListStakersResponse, MigrateMsg,
QueryMsg, StakerBalanceResponse, TokenInfo,
ExecuteMsg, GetHooksResponse, InstantiateMsg, ListStakersResponse, MigrateMsg, QueryMsg,
StakerBalanceResponse, TokenInfo,
};
use crate::state::{
Config, ACTIVE_THRESHOLD, CLAIMS, CONFIG, DAO, DENOM, HOOKS, MAX_CLAIMS, STAKED_BALANCES,
Expand Down
10 changes: 2 additions & 8 deletions contracts/voting/dao-voting-token-staked/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Binary, Uint128};
use cw_utils::Duration;
use dao_dao_macros::{active_query, voting_module_query};
use dao_dao_macros::{active_query, native_token_query, voting_module_query};
use dao_interface::token::NewTokenInfo;
use dao_voting::threshold::{ActiveThreshold, ActiveThresholdResponse};

Check warning on line 6 in contracts/voting/dao-voting-token-staked/src/msg.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ActiveThresholdResponse`

Check warning on line 6 in contracts/voting/dao-voting-token-staked/src/msg.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ActiveThresholdResponse`

Expand Down Expand Up @@ -57,15 +57,14 @@ pub enum ExecuteMsg {
RemoveHook { addr: String },
}

#[native_token_query]
#[active_query]
#[voting_module_query]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(crate::state::Config)]
GetConfig {},
#[returns(DenomResponse)]
Denom {},
#[returns(cw_controllers::ClaimsResponse)]
Claims { address: String },
#[returns(ListStakersResponse)]
Expand Down Expand Up @@ -95,11 +94,6 @@ pub struct StakerBalanceResponse {
pub balance: Uint128,
}

#[cw_serde]
pub struct DenomResponse {
pub denom: String,
}

#[cw_serde]
pub struct GetHooksResponse {
pub hooks: Vec<String>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION};
use crate::msg::{
DenomResponse, ExecuteMsg, GetHooksResponse, InstantiateMsg, ListStakersResponse, MigrateMsg,
QueryMsg, StakerBalanceResponse, TokenInfo,
ExecuteMsg, GetHooksResponse, InstantiateMsg, ListStakersResponse, MigrateMsg, QueryMsg,
StakerBalanceResponse, TokenInfo,
};
use crate::state::Config;
use cosmwasm_std::testing::{mock_dependencies, mock_env};
Expand All @@ -12,7 +12,8 @@ use cw_multi_test::{
};
use cw_utils::Duration;
use dao_interface::voting::{
InfoResponse, IsActiveResponse, TotalPowerAtHeightResponse, VotingPowerAtHeightResponse,
DenomResponse, InfoResponse, IsActiveResponse, TotalPowerAtHeightResponse,
VotingPowerAtHeightResponse,
};
use dao_voting::threshold::{ActiveThreshold, ActiveThresholdResponse};

Expand Down
4 changes: 2 additions & 2 deletions packages/dao-dao-macros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ the voting module interface on an enum:

```rust
use cosmwasm_schema::{cw_serde, QueryResponses};
use dao_dao_macros::{token_query, voting_module_query};
use dao_dao_macros::{cw20_token_query, voting_module_query};
use dao_interface::voting::TotalPowerAtHeightResponse;
use dao_interface::voting::VotingPowerAtHeightResponse;

#[token_query]
#[cw20_token_query]
#[voting_module_query]
#[cw_serde]
#[derive(QueryResponses)]
Expand Down
71 changes: 65 additions & 6 deletions packages/dao-dao-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ pub fn voting_module_query(metadata: TokenStream, input: TokenStream) -> TokenSt
}

/// Adds the necessary fields to an enum such that it implements the
/// interface needed to be a voting module with a token.
/// interface needed to be a voting module with a cw20 token.
///
/// For example:
///
/// ```
/// use dao_dao_macros::token_query;
/// use dao_dao_macros::cw20_token_query;
/// use cosmwasm_schema::{cw_serde, QueryResponses};
/// use cosmwasm_std::Addr;
///
/// #[token_query]
/// #[cw20_token_query]
/// #[cw_serde]
/// #[derive(QueryResponses)]
/// enum QueryMsg {}
Expand All @@ -181,11 +181,11 @@ pub fn voting_module_query(metadata: TokenStream, input: TokenStream) -> TokenSt
/// occurs before the addition of the field.
///
/// ```compile_fail
/// use dao_dao_macros::token_query;
/// use dao_dao_macros::cw20_token_query;
/// use cosmwasm_schema::{cw_serde, QueryResponses};
///
/// #[derive(Clone)]
/// #[token_query]
/// #[cw20_token_query]
/// #[allow(dead_code)]
/// #[cw_serde]
/// #[derive(QueryResponses)]
Expand All @@ -196,7 +196,7 @@ pub fn voting_module_query(metadata: TokenStream, input: TokenStream) -> TokenSt
/// }
/// ```
#[proc_macro_attribute]
pub fn token_query(metadata: TokenStream, input: TokenStream) -> TokenStream {
pub fn cw20_token_query(metadata: TokenStream, input: TokenStream) -> TokenStream {
merge_variants(
metadata,
input,
Expand All @@ -210,6 +210,65 @@ pub fn token_query(metadata: TokenStream, input: TokenStream) -> TokenStream {
)
}

/// Adds the necessary fields to an enum such that it implements the
/// interface needed to be a voting module with a native token.
///
/// For example:
///
/// ```
/// use dao_dao_macros::native_token_query;
/// use cosmwasm_schema::{cw_serde, QueryResponses};
/// use cosmwasm_std::Addr;
///
/// #[native_token_query]
/// #[cw_serde]
/// #[derive(QueryResponses)]
/// enum QueryMsg {}
/// ```
///
/// Will transform the enum to:
///
/// ```
/// enum QueryMsg {
/// Denom {},
/// }
/// ```
///
/// Note that other derive macro invocations must occur after this
/// procedural macro as they may depend on the new fields. For
/// example, the following will fail becase the `Clone` derivation
/// occurs before the addition of the field.
///
/// ```compile_fail
/// use dao_dao_macros::native_token_query;
/// use cosmwasm_schema::{cw_serde, QueryResponses};
///
/// #[derive(Clone)]
/// #[native_token_query]
/// #[allow(dead_code)]
/// #[cw_serde]
/// #[derive(QueryResponses)]
/// enum Test {
/// Foo,
/// Bar(u64),
/// Baz { foo: u64 },
/// }
/// ```
#[proc_macro_attribute]
pub fn native_token_query(metadata: TokenStream, input: TokenStream) -> TokenStream {
merge_variants(
metadata,
input,
quote! {
enum Right {
#[returns(::dao_interface::voting::DenomResponse)]
Denom {}
}
}
.into(),
)
}

/// Adds the necessary fields to an enum such that it implements the
/// interface needed to be a voting module that has an
/// active check threshold.
Expand Down
8 changes: 8 additions & 0 deletions packages/dao-interface/src/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub enum Query {
/// Returns the token contract address, if set.
#[returns(::cosmwasm_std::Addr)]
TokenContract {},
/// Returns the native token denom, if used.
#[returns(DenomResponse)]
Denom {},
/// Returns the voting power for an address at a given height.
#[returns(VotingPowerAtHeightResponse)]
VotingPowerAtHeight {
Expand Down Expand Up @@ -56,3 +59,8 @@ pub struct InfoResponse {
pub struct IsActiveResponse {
pub active: bool,
}

#[cw_serde]
pub struct DenomResponse {
pub denom: String,
}
Loading

0 comments on commit 1474cd7

Please sign in to comment.