1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use cosmwasm_schema::{cw_serde, schemars::JsonSchema, QueryResponses};
use cw_denom::UncheckedDenom;
use dao_voting::{
    deposit::{CheckedDepositInfo, UncheckedDepositInfo},
    status::Status,
};

#[cw_serde]
pub struct InstantiateMsg<InstantiateExt> {
    /// Information about the deposit requirements for this
    /// module. None if no deposit.
    pub deposit_info: Option<UncheckedDepositInfo>,
    /// If false, only members (addresses with voting power) may create
    /// proposals in the DAO. Otherwise, any address may create a
    /// proposal so long as they pay the deposit.
    pub open_proposal_submission: bool,
    /// Extension for instantiation. The default implementation will
    /// do nothing with this data.
    pub extension: InstantiateExt,
}

#[cw_serde]
pub enum ExecuteMsg<ProposalMessage, ExecuteExt> {
    /// Creates a new proposal in the pre-propose module. MSG will be
    /// serialized and used as the proposal creation message.
    Propose { msg: ProposalMessage },

    /// Updates the configuration of this module. This will completely
    /// override the existing configuration. This new configuration
    /// will only apply to proposals created after the config is
    /// updated. Only the DAO may execute this message.
    UpdateConfig {
        deposit_info: Option<UncheckedDepositInfo>,
        open_proposal_submission: bool,
    },

    /// Withdraws funds inside of this contract to the message
    /// sender. The contracts entire balance for the specifed DENOM is
    /// withdrawn to the message sender. Only the DAO may call this
    /// method.
    ///
    /// This is intended only as an escape hatch in the event of a
    /// critical bug in this contract or it's proposal
    /// module. Withdrawing funds will cause future attempts to return
    /// proposal deposits to fail their transactions as the contract
    /// will have insufficent balance to return them. In the case of
    /// `cw-proposal-single` this transaction failure will cause the
    /// module to remove the pre-propose module from its proposal hook
    /// receivers.
    ///
    /// More likely than not, this should NEVER BE CALLED unless a bug
    /// in this contract or the proposal module it is associated with
    /// has caused it to stop receiving proposal hook messages, or if
    /// a critical security vulnerability has been found that allows
    /// an attacker to drain proposal deposits.
    Withdraw {
        /// The denom to withdraw funds for. If no denom is specified,
        /// the denomination currently configured for proposal
        /// deposits will be used.
        ///
        /// You may want to specify a denomination here if you are
        /// withdrawing funds that were previously accepted for
        /// proposal deposits but are not longer used due to an
        /// `UpdateConfig` message being executed on the contract.
        denom: Option<UncheckedDenom>,
    },

    /// Extension message. Contracts that extend this one should put
    /// their custom execute logic here. The default implementation
    /// will do nothing if this variant is executed.
    Extension { msg: ExecuteExt },

    /// Adds a proposal submitted hook. Fires when a new proposal is submitted
    /// to the pre-propose contract. Only the DAO may call this method.
    AddProposalSubmittedHook { address: String },

    /// Removes a proposal submitted hook. Only the DAO may call this method.
    RemoveProposalSubmittedHook { address: String },

    /// Handles proposal hook fired by the associated proposal
    /// module when a proposal is completed (ie executed or rejected).
    /// By default, the base contract will return deposits
    /// proposals, when they are closed, when proposals are executed, or,
    /// if it is refunding failed.
    ProposalCompletedHook {
        proposal_id: u64,
        new_status: Status,
    },
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg<QueryExt>
where
    QueryExt: JsonSchema,
{
    /// Gets the proposal module that this pre propose module is
    /// associated with. Returns `Addr`.
    #[returns(cosmwasm_std::Addr)]
    ProposalModule {},
    /// Gets the DAO (dao-dao) module this contract is associated
    /// with. Returns `Addr`.
    #[returns(cosmwasm_std::Addr)]
    Dao {},
    /// Gets the module's configuration.
    #[returns(crate::state::Config)]
    Config {},
    /// Gets the deposit info for the proposal identified by
    /// PROPOSAL_ID.
    #[returns(DepositInfoResponse)]
    DepositInfo { proposal_id: u64 },
    /// Returns list of proposal submitted hooks.
    #[returns(cw_hooks::HooksResponse)]
    ProposalSubmittedHooks {},
    /// Extension for queries. The default implementation will do
    /// nothing if queried for will return `Binary::default()`.
    #[returns(cosmwasm_std::Binary)]
    QueryExtension { msg: QueryExt },
}

#[cw_serde]
pub struct DepositInfoResponse {
    /// The deposit that has been paid for the specified proposal.
    pub deposit_info: Option<CheckedDepositInfo>,
    /// The address that created the proposal.
    pub proposer: cosmwasm_std::Addr,
}