Skip to main content

dao_migrator/
types.rs

1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{Addr, Uint128};
3use dao_voting::veto::VetoConfig;
4
5use crate::ContractError;
6
7#[cw_serde]
8pub struct V1CodeIds {
9    pub proposal_single: u64,
10    pub cw4_voting: u64,
11    pub cw20_stake: u64,
12    pub cw20_staked_balances_voting: u64,
13}
14
15impl V1CodeIds {
16    pub fn to(self) -> dao_interface::migrate_msg::V1CodeIds {
17        dao_interface::migrate_msg::V1CodeIds {
18            proposal_single: self.proposal_single,
19            cw4_voting: self.cw4_voting,
20            cw20_stake: self.cw20_stake,
21            cw20_staked_balances_voting: self.cw20_staked_balances_voting,
22        }
23    }
24}
25
26#[cw_serde]
27pub struct V2CodeIds {
28    pub proposal_single: u64,
29    pub cw4_voting: u64,
30    pub cw20_stake: u64,
31    pub cw20_staked_balances_voting: u64,
32}
33
34impl V2CodeIds {
35    pub fn to(self) -> dao_interface::migrate_msg::V2CodeIds {
36        dao_interface::migrate_msg::V2CodeIds {
37            proposal_single: self.proposal_single,
38            cw4_voting: self.cw4_voting,
39            cw20_stake: self.cw20_stake,
40            cw20_staked_balances_voting: self.cw20_staked_balances_voting,
41        }
42    }
43}
44
45/// The params we need to provide for migration msgs
46#[cw_serde]
47pub struct ProposalParams {
48    pub close_proposal_on_execution_failure: bool,
49    pub pre_propose_info: dao_voting::pre_propose::PreProposeInfo,
50    pub veto: Option<VetoConfig>,
51}
52
53#[cw_serde]
54pub struct MigrationParams {
55    // General
56    /// Rather or not to migrate the stake_cw20 contract and its
57    /// manager. If this is not set to true and a stake_cw20
58    /// contract is detected in the DAO's configuration the
59    /// migration will be aborted.
60    pub migrate_stake_cw20_manager: Option<bool>,
61    /// List of (address, ProposalParams) where `address` is an
62    /// address of a proposal module currently part of the DAO.
63    pub proposal_params: Vec<(String, ProposalParams)>,
64}
65
66/// Wrapper enum that helps us to hold different types of migration msgs
67#[cw_serde]
68#[serde(untagged)]
69pub enum MigrationMsgs {
70    DaoProposalSingle(dao_proposal_single::msg::MigrateMsg),
71    DaoVotingCw4(dao_voting_cw4::msg::MigrateMsg),
72    Cw20Stake(cw20_stake::msg::MigrateMsg),
73    DaoVotingCw20Staked(dao_voting_cw20_staked::msg::MigrateMsg),
74}
75
76/// Module data we need for migrations and tests.
77#[derive(Clone)]
78pub struct CodeIdPair {
79    /// The code id used in V1 module
80    pub v1_code_id: u64,
81    /// The new code id used in V2
82    pub v2_code_id: u64,
83    /// The migration msg of the module
84    pub migrate_msg: MigrationMsgs,
85}
86
87impl CodeIdPair {
88    pub fn new(v1_code_id: u64, v2_code_id: u64, migrate_msg: MigrationMsgs) -> CodeIdPair {
89        CodeIdPair {
90            v1_code_id,
91            v2_code_id,
92            migrate_msg,
93        }
94    }
95}
96
97/// Hold module addresses to do queries on
98#[cw_serde]
99#[derive(Default)]
100pub struct ModulesAddrs {
101    pub voting: Option<Addr>,
102    pub proposals: Vec<Addr>,
103}
104
105impl ModulesAddrs {
106    pub fn verify(&self) -> Result<(), ContractError> {
107        if self.voting.is_none() {
108            return Err(ContractError::VotingModuleNotFound);
109        }
110
111        if self.proposals.is_empty() {
112            return Err(ContractError::DaoProposalSingleNotFound);
113        }
114        Ok(())
115    }
116}
117
118// Test helper types
119
120pub struct SingleProposalData {
121    pub proposer: Addr,
122    pub start_height: u64,
123}
124
125/// Data we use to test after migration (it is set before migration)
126#[cw_serde]
127pub struct TestState {
128    pub proposal_counts: Vec<u64>,
129    pub proposals: Vec<dao_proposal_single::proposal::SingleChoiceProposal>,
130    pub total_voting_power: Uint128,
131    /// This is the voting power of the proposer of the sample proposal
132    pub single_voting_power: Uint128,
133}