Skip to content

Commit 3990e13

Browse files
hard-nettJake Hartnell
authored andcommitted
dao cw-orch interface
1 parent 0cc80ce commit 3990e13

17 files changed

+165
-547
lines changed

scripts/src/dao.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
use cw_orch::prelude::*;
2-
use dao_cw_orch::{DaoDaoCore, DaoProposalSingle, DaoProposalSudo};
2+
use dao_cw_orch::DaoDaoCore;
33

4-
// minimal dao
4+
use crate::{
5+
DaoDistributionSuite, DaoExternalSuite, DaoProposalSuite, DaoStakingSuite, DaoVotingSuite,
6+
};
7+
8+
// full dao suite
59
pub struct DaoDao<Chain> {
610
pub dao_core: DaoDaoCore<Chain>,
7-
pub dao_proposal_single: DaoProposalSingle<Chain>,
8-
pub dao_proposal_sudo: DaoProposalSudo<Chain>,
11+
pub proposal_suite: DaoProposalSuite<Chain>,
12+
pub voting_suite: DaoVotingSuite<Chain>,
13+
pub staking_suite: DaoStakingSuite<Chain>,
14+
pub distribution_suite: DaoDistributionSuite<Chain>,
15+
pub external_suite: DaoExternalSuite<Chain>,
916
}
1017

1118
impl<Chain: CwEnv> DaoDao<Chain> {
1219
pub fn new(chain: Chain) -> DaoDao<Chain> {
1320
DaoDao::<Chain> {
1421
dao_core: DaoDaoCore::new("dao_dao_core", chain.clone()),
15-
dao_proposal_single: DaoProposalSingle::new("dao_proposal_single", chain.clone()),
16-
dao_proposal_sudo: DaoProposalSudo::new("dao_proposal_sudo", chain.clone()),
22+
proposal_suite: DaoProposalSuite::new(chain.clone()),
23+
voting_suite: DaoVotingSuite::new(chain.clone()),
24+
staking_suite: DaoStakingSuite::new(chain.clone()),
25+
distribution_suite: DaoDistributionSuite::new(chain.clone()),
26+
external_suite: DaoExternalSuite::new(chain.clone()),
1727
}
1828
}
1929

2030
pub fn upload(&self) -> Result<(), CwOrchError> {
2131
self.dao_core.upload()?;
22-
self.dao_proposal_single.upload()?;
23-
self.dao_proposal_sudo.upload()?;
24-
32+
self.proposal_suite.upload()?;
33+
self.voting_suite.upload()?;
34+
self.staking_suite.upload()?;
35+
self.distribution_suite.upload()?;
36+
self.external_suite.upload()?;
2537
Ok(())
2638
}
2739
}

scripts/src/external.rs

Lines changed: 30 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,45 @@
11
use cw_orch::prelude::*;
22
use dao_cw_orch::*;
33

4-
// admin factory
5-
pub struct AdminFactorySuite<Chain> {
6-
pub factory: DaoExternalAdminFactory<Chain>,
7-
}
8-
impl<Chain: CwEnv> AdminFactorySuite<Chain> {
9-
pub fn new(chain: Chain) -> AdminFactorySuite<Chain> {
10-
AdminFactorySuite::<Chain> {
11-
factory: DaoExternalAdminFactory::new("cw_admin_factory", chain.clone()),
12-
}
13-
}
14-
15-
pub fn upload(&self) -> Result<(), CwOrchError> {
16-
self.factory.upload()?;
17-
18-
Ok(())
19-
}
20-
}
21-
22-
// bitsong fantoken factory
23-
pub struct FantokenFactorySuite<Chain> {
24-
pub factory: DaoExternalFantokenFactory<Chain>,
25-
}
26-
27-
impl<Chain: CwEnv> FantokenFactorySuite<Chain> {
28-
pub fn new(chain: Chain) -> FantokenFactorySuite<Chain> {
29-
FantokenFactorySuite::<Chain> {
30-
factory: DaoExternalFantokenFactory::new("btsg_ft_factory", chain.clone()),
31-
}
32-
}
33-
34-
pub fn upload(&self) -> Result<(), CwOrchError> {
35-
self.factory.upload()?;
36-
37-
Ok(())
38-
}
39-
}
40-
41-
// payroll factory
42-
pub struct PayrollSuite<Chain> {
43-
pub payroll: DaoExternalPayrollFactory<Chain>,
44-
pub vesting: DaoExternalCwVesting<Chain>,
45-
}
46-
impl<Chain: CwEnv> PayrollSuite<Chain> {
47-
pub fn new(chain: Chain) -> PayrollSuite<Chain> {
48-
PayrollSuite::<Chain> {
49-
payroll: DaoExternalPayrollFactory::new("cw_payroll", chain.clone()),
50-
vesting: DaoExternalCwVesting::new("cw_vesting", chain.clone()),
51-
}
52-
}
53-
54-
pub fn upload(&self) -> Result<(), CwOrchError> {
55-
self.payroll.upload()?;
56-
self.vesting.upload()?;
57-
Ok(())
58-
}
59-
}
60-
61-
// cw tokenswap
62-
pub struct TokenSwapSuite<Chain> {
63-
pub tokenswap: DaoExternalTokenSwap<Chain>,
64-
}
65-
impl<Chain: CwEnv> TokenSwapSuite<Chain> {
66-
pub fn new(chain: Chain) -> TokenSwapSuite<Chain> {
67-
TokenSwapSuite::<Chain> {
68-
tokenswap: DaoExternalTokenSwap::new("cw_tokenswap", chain.clone()),
69-
}
70-
}
71-
72-
pub fn upload(&self) -> Result<(), CwOrchError> {
73-
self.tokenswap.upload()?;
74-
75-
Ok(())
76-
}
77-
}
78-
79-
// cw-tokenfactory issuer
80-
pub struct TokenFactorySuite<Chain> {
81-
pub tokenfactory: DaoExternalTokenfactoryIssuer<Chain>,
82-
}
83-
impl<Chain: CwEnv> TokenFactorySuite<Chain> {
84-
pub fn new(chain: Chain) -> TokenFactorySuite<Chain> {
85-
TokenFactorySuite::<Chain> {
86-
tokenfactory: DaoExternalTokenfactoryIssuer::new("cw_tokenfactory", chain.clone()),
87-
}
88-
}
89-
90-
pub fn upload(&self) -> Result<(), CwOrchError> {
91-
self.tokenfactory.upload()?;
92-
93-
Ok(())
94-
}
95-
}
96-
97-
// cw-vesting
98-
pub struct VestingSuite<Chain> {
99-
pub vesting: DaoExternalCwVesting<Chain>,
100-
}
101-
102-
impl<Chain: CwEnv> VestingSuite<Chain> {
103-
pub fn new(chain: Chain) -> VestingSuite<Chain> {
104-
VestingSuite::<Chain> {
105-
vesting: DaoExternalCwVesting::new("dao_dao_core", chain.clone()),
106-
}
107-
}
108-
109-
pub fn upload(&self) -> Result<(), CwOrchError> {
110-
self.vesting.upload()?;
111-
112-
Ok(())
113-
}
114-
}
115-
116-
// cw721 roles
117-
pub struct Cw721RolesSuite<Chain> {
118-
pub roles: DaoExternalCw721Roles<Chain>,
119-
}
120-
121-
impl<Chain: CwEnv> Cw721RolesSuite<Chain> {
122-
pub fn new(chain: Chain) -> Cw721RolesSuite<Chain> {
123-
Cw721RolesSuite::<Chain> {
124-
roles: DaoExternalCw721Roles::new("cw721_roles", chain.clone()),
125-
}
126-
}
127-
128-
pub fn upload(&self) -> Result<(), CwOrchError> {
129-
self.roles.upload()?;
130-
131-
Ok(())
132-
}
133-
}
134-
135-
// migrator
136-
pub struct DaoMigrationSuite<Chain> {
4+
// external suite
5+
pub struct DaoExternalSuite<Chain> {
6+
pub admin_factory: DaoExternalAdminFactory<Chain>,
7+
pub btsg_ft_factory: DaoExternalFantokenFactory<Chain>,
8+
pub payroll_factory: DaoExternalPayrollFactory<Chain>,
9+
pub cw_tokenswap: DaoExternalTokenSwap<Chain>,
10+
pub cw_tokenfactory_issuer: DaoExternalTokenfactoryIssuer<Chain>,
11+
pub cw_vesting: DaoExternalCwVesting<Chain>,
12+
pub cw721_roles: DaoExternalCw721Roles<Chain>,
13713
pub migrator: DaoExternalMigrator<Chain>,
13814
}
13915

140-
impl<Chain: CwEnv> DaoMigrationSuite<Chain> {
141-
pub fn new(chain: Chain) -> DaoMigrationSuite<Chain> {
142-
DaoMigrationSuite::<Chain> {
16+
impl<Chain: CwEnv> DaoExternalSuite<Chain> {
17+
pub fn new(chain: Chain) -> DaoExternalSuite<Chain> {
18+
DaoExternalSuite::<Chain> {
19+
admin_factory: DaoExternalAdminFactory::new("cw_admin_factory", chain.clone()),
20+
btsg_ft_factory: DaoExternalFantokenFactory::new("btsg_ft_factory", chain.clone()),
21+
payroll_factory: DaoExternalPayrollFactory::new("cw_payroll", chain.clone()),
22+
cw_tokenswap: DaoExternalTokenSwap::new("cw_tokenswap", chain.clone()),
23+
cw_tokenfactory_issuer: DaoExternalTokenfactoryIssuer::new(
24+
"cw_tokenfactory",
25+
chain.clone(),
26+
),
27+
cw_vesting: DaoExternalCwVesting::new("cw_vesting", chain.clone()),
28+
cw721_roles: DaoExternalCw721Roles::new("cw721_roles", chain.clone()),
14329
migrator: DaoExternalMigrator::new("dao_migrator", chain.clone()),
14430
}
14531
}
14632

14733
pub fn upload(&self) -> Result<(), CwOrchError> {
34+
self.admin_factory.upload()?;
35+
self.btsg_ft_factory.upload()?;
36+
self.payroll_factory.upload()?;
37+
self.cw_tokenswap.upload()?;
38+
self.cw_tokenfactory_issuer.upload()?;
39+
self.cw_vesting.upload()?;
40+
self.cw721_roles.upload()?;
14841
self.migrator.upload()?;
14942

15043
Ok(())
15144
}
152-
}
45+
}

scripts/src/propose.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,19 @@ impl<Chain: CwEnv> DaoPreProposeSuite<Chain> {
3131
self.pre_prop_approval_single.upload()?;
3232
self.pre_prop_approver.upload()?;
3333
self.pre_prop_multiple.upload()?;
34+
self.pre_prop_single.upload()?;
3435

3536
Ok(())
3637
}
3738
}
3839

40+
// proposal suite
3941
pub struct DaoProposalSuite<Chain> {
4042
pub prop_single: DaoProposalSingle<Chain>,
4143
pub prop_multiple: DaoProposalMultiple<Chain>,
4244
pub prop_condocert: DaoProposalCondorcet<Chain>,
45+
pub prop_sudo: DaoProposalSudo<Chain>,
46+
pub pre_prop_suite: DaoPreProposeSuite<Chain>,
4347
}
4448

4549
impl<Chain: CwEnv> DaoProposalSuite<Chain> {
@@ -48,14 +52,17 @@ impl<Chain: CwEnv> DaoProposalSuite<Chain> {
4852
prop_single: DaoProposalSingle::new("dao_proposal_single", chain.clone()),
4953
prop_multiple: DaoProposalMultiple::new("dao_proposal_multiple", chain.clone()),
5054
prop_condocert: DaoProposalCondorcet::new("dao_proposal_condocert", chain.clone()),
55+
prop_sudo: DaoProposalSudo::new("dao_proposal_sudo", chain.clone()),
56+
pre_prop_suite: DaoPreProposeSuite::new(chain.clone()),
5157
}
5258
}
5359

5460
pub fn upload(&self) -> Result<(), CwOrchError> {
5561
self.prop_single.upload()?;
5662
self.prop_multiple.upload()?;
5763
self.prop_condocert.upload()?;
64+
self.prop_sudo.upload()?;
65+
self.pre_prop_suite.upload()?;
5866
Ok(())
5967
}
6068
}
61-

scripts/src/tests/deploy/dao.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use crate::DaoDao;
2+
use cw_orch::prelude::*;
3+
// distribution suite
4+
impl<Chain: CwEnv> cw_orch::contract::Deploy<Chain> for DaoDao<Chain> {
5+
// We don't have a custom error type
6+
type Error = CwOrchError;
7+
type DeployData = Addr;
8+
9+
fn store_on(chain: Chain) -> Result<Self, Self::Error> {
10+
let suite = DaoDao::new(chain.clone());
11+
suite.upload()?;
12+
Ok(suite)
13+
}
14+
15+
fn deployed_state_file_path() -> Option<String> {
16+
None
17+
}
18+
19+
fn get_contracts_mut(&mut self) -> Vec<Box<&mut dyn ContractInstance<Chain>>> {
20+
let mut cs: Vec<Box<&mut dyn ContractInstance<Chain>>> = vec![];
21+
let res: Vec<Box<&mut dyn ContractInstance<Chain>>> = vec![Box::new(&mut self.dao_core)];
22+
23+
cs.extend(res);
24+
cs.extend(self.distribution_suite.get_contracts_mut());
25+
cs.extend(self.proposal_suite.get_contracts_mut());
26+
cs.extend(self.staking_suite.get_contracts_mut());
27+
cs.extend(self.voting_suite.get_contracts_mut());
28+
cs.extend(self.external_suite.get_contracts_mut());
29+
cs
30+
}
31+
32+
fn load_from(chain: Chain) -> Result<Self, Self::Error> {
33+
let suite = Self::new(chain.clone());
34+
Ok(suite)
35+
}
36+
37+
fn deploy_on(chain: Chain, _data: Self::DeployData) -> Result<Self, Self::Error> {
38+
// ########### Upload ##############
39+
let suite: DaoDao<Chain> = DaoDao::store_on(chain.clone())?;
40+
Ok(suite)
41+
}
42+
}

0 commit comments

Comments
 (0)