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 fec882d
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 63 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
59 changes: 58 additions & 1 deletion contracts/proposal/dao-proposal-multiple/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,64 @@ fn test_min_duration_same_as_proposal_duration() {
/// Instantiate the contract and use the voting module's token
/// contract as the proposal deposit token.
#[test]
fn test_voting_module_token_proposal_deposit_instantiate() {
fn test_voting_module_cw20_token_proposal_deposit_instantiate() {
let mut app = App::default();
let _govmod_id = app.store_code(proposal_multiple_contract());

let quorum = PercentageThreshold::Majority {};
let voting_strategy = VotingStrategy::SingleChoice { quorum };
let max_voting_period = cw_utils::Duration::Height(6);

let instantiate = InstantiateMsg {
min_voting_period: None,
close_proposal_on_execution_failure: true,
max_voting_period,
only_members_execute: false,
allow_revoting: false,
voting_strategy,
pre_propose_info: get_pre_propose_info(
&mut app,
Some(UncheckedDepositInfo {
denom: DepositToken::VotingModuleToken {},
amount: Uint128::new(1),
refund_policy: DepositRefundPolicy::OnlyPassed,
}),
false,
),
veto: None,
};

let core_addr = instantiate_with_staked_balances_governance(&mut app, instantiate, None);

let gov_state: dao_interface::query::DumpStateResponse = app
.wrap()
.query_wasm_smart(
core_addr.clone(),
&dao_interface::msg::QueryMsg::DumpState {},
)
.unwrap();
let governance_modules = gov_state.proposal_modules;

assert_eq!(governance_modules.len(), 1);
let govmod = governance_modules.into_iter().next().unwrap().address;

let token = query_dao_token(&app, &core_addr);

let (deposit_config, _) = query_deposit_config_and_pre_propose_module(&app, &govmod);
assert_eq!(
deposit_config.deposit_info,
Some(CheckedDepositInfo {
denom: CheckedDenom::Cw20(token),
amount: Uint128::new(1),
refund_policy: DepositRefundPolicy::OnlyPassed
})
)
}

/// Instantiate the contract and use the voting module's token
/// contract as the proposal deposit token.
#[test]
fn test_voting_module_native_token_proposal_deposit_instantiate() {
let mut app = App::default();
let _govmod_id = app.store_code(proposal_multiple_contract());

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};

/// 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};

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
Loading

0 comments on commit fec882d

Please sign in to comment.