Skip to content

Commit

Permalink
dao cw-orch interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hard-nett authored and Jake Hartnell committed Aug 14, 2024
1 parent 0cc80ce commit 3990e13
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 547 deletions.
30 changes: 21 additions & 9 deletions scripts/src/dao.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
use cw_orch::prelude::*;
use dao_cw_orch::{DaoDaoCore, DaoProposalSingle, DaoProposalSudo};
use dao_cw_orch::DaoDaoCore;

// minimal dao
use crate::{
DaoDistributionSuite, DaoExternalSuite, DaoProposalSuite, DaoStakingSuite, DaoVotingSuite,
};

// full dao suite
pub struct DaoDao<Chain> {
pub dao_core: DaoDaoCore<Chain>,
pub dao_proposal_single: DaoProposalSingle<Chain>,
pub dao_proposal_sudo: DaoProposalSudo<Chain>,
pub proposal_suite: DaoProposalSuite<Chain>,
pub voting_suite: DaoVotingSuite<Chain>,
pub staking_suite: DaoStakingSuite<Chain>,
pub distribution_suite: DaoDistributionSuite<Chain>,
pub external_suite: DaoExternalSuite<Chain>,
}

impl<Chain: CwEnv> DaoDao<Chain> {
pub fn new(chain: Chain) -> DaoDao<Chain> {
DaoDao::<Chain> {
dao_core: DaoDaoCore::new("dao_dao_core", chain.clone()),
dao_proposal_single: DaoProposalSingle::new("dao_proposal_single", chain.clone()),
dao_proposal_sudo: DaoProposalSudo::new("dao_proposal_sudo", chain.clone()),
proposal_suite: DaoProposalSuite::new(chain.clone()),
voting_suite: DaoVotingSuite::new(chain.clone()),
staking_suite: DaoStakingSuite::new(chain.clone()),
distribution_suite: DaoDistributionSuite::new(chain.clone()),
external_suite: DaoExternalSuite::new(chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.dao_core.upload()?;
self.dao_proposal_single.upload()?;
self.dao_proposal_sudo.upload()?;

self.proposal_suite.upload()?;
self.voting_suite.upload()?;
self.staking_suite.upload()?;
self.distribution_suite.upload()?;
self.external_suite.upload()?;
Ok(())
}
}
167 changes: 30 additions & 137 deletions scripts/src/external.rs
Original file line number Diff line number Diff line change
@@ -1,152 +1,45 @@
use cw_orch::prelude::*;
use dao_cw_orch::*;

// admin factory
pub struct AdminFactorySuite<Chain> {
pub factory: DaoExternalAdminFactory<Chain>,
}
impl<Chain: CwEnv> AdminFactorySuite<Chain> {
pub fn new(chain: Chain) -> AdminFactorySuite<Chain> {
AdminFactorySuite::<Chain> {
factory: DaoExternalAdminFactory::new("cw_admin_factory", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.factory.upload()?;

Ok(())
}
}

// bitsong fantoken factory
pub struct FantokenFactorySuite<Chain> {
pub factory: DaoExternalFantokenFactory<Chain>,
}

impl<Chain: CwEnv> FantokenFactorySuite<Chain> {
pub fn new(chain: Chain) -> FantokenFactorySuite<Chain> {
FantokenFactorySuite::<Chain> {
factory: DaoExternalFantokenFactory::new("btsg_ft_factory", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.factory.upload()?;

Ok(())
}
}

// payroll factory
pub struct PayrollSuite<Chain> {
pub payroll: DaoExternalPayrollFactory<Chain>,
pub vesting: DaoExternalCwVesting<Chain>,
}
impl<Chain: CwEnv> PayrollSuite<Chain> {
pub fn new(chain: Chain) -> PayrollSuite<Chain> {
PayrollSuite::<Chain> {
payroll: DaoExternalPayrollFactory::new("cw_payroll", chain.clone()),
vesting: DaoExternalCwVesting::new("cw_vesting", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.payroll.upload()?;
self.vesting.upload()?;
Ok(())
}
}

// cw tokenswap
pub struct TokenSwapSuite<Chain> {
pub tokenswap: DaoExternalTokenSwap<Chain>,
}
impl<Chain: CwEnv> TokenSwapSuite<Chain> {
pub fn new(chain: Chain) -> TokenSwapSuite<Chain> {
TokenSwapSuite::<Chain> {
tokenswap: DaoExternalTokenSwap::new("cw_tokenswap", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.tokenswap.upload()?;

Ok(())
}
}

// cw-tokenfactory issuer
pub struct TokenFactorySuite<Chain> {
pub tokenfactory: DaoExternalTokenfactoryIssuer<Chain>,
}
impl<Chain: CwEnv> TokenFactorySuite<Chain> {
pub fn new(chain: Chain) -> TokenFactorySuite<Chain> {
TokenFactorySuite::<Chain> {
tokenfactory: DaoExternalTokenfactoryIssuer::new("cw_tokenfactory", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.tokenfactory.upload()?;

Ok(())
}
}

// cw-vesting
pub struct VestingSuite<Chain> {
pub vesting: DaoExternalCwVesting<Chain>,
}

impl<Chain: CwEnv> VestingSuite<Chain> {
pub fn new(chain: Chain) -> VestingSuite<Chain> {
VestingSuite::<Chain> {
vesting: DaoExternalCwVesting::new("dao_dao_core", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.vesting.upload()?;

Ok(())
}
}

// cw721 roles
pub struct Cw721RolesSuite<Chain> {
pub roles: DaoExternalCw721Roles<Chain>,
}

impl<Chain: CwEnv> Cw721RolesSuite<Chain> {
pub fn new(chain: Chain) -> Cw721RolesSuite<Chain> {
Cw721RolesSuite::<Chain> {
roles: DaoExternalCw721Roles::new("cw721_roles", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.roles.upload()?;

Ok(())
}
}

// migrator
pub struct DaoMigrationSuite<Chain> {
// external suite
pub struct DaoExternalSuite<Chain> {
pub admin_factory: DaoExternalAdminFactory<Chain>,
pub btsg_ft_factory: DaoExternalFantokenFactory<Chain>,
pub payroll_factory: DaoExternalPayrollFactory<Chain>,
pub cw_tokenswap: DaoExternalTokenSwap<Chain>,
pub cw_tokenfactory_issuer: DaoExternalTokenfactoryIssuer<Chain>,
pub cw_vesting: DaoExternalCwVesting<Chain>,
pub cw721_roles: DaoExternalCw721Roles<Chain>,
pub migrator: DaoExternalMigrator<Chain>,
}

impl<Chain: CwEnv> DaoMigrationSuite<Chain> {
pub fn new(chain: Chain) -> DaoMigrationSuite<Chain> {
DaoMigrationSuite::<Chain> {
impl<Chain: CwEnv> DaoExternalSuite<Chain> {
pub fn new(chain: Chain) -> DaoExternalSuite<Chain> {
DaoExternalSuite::<Chain> {
admin_factory: DaoExternalAdminFactory::new("cw_admin_factory", chain.clone()),
btsg_ft_factory: DaoExternalFantokenFactory::new("btsg_ft_factory", chain.clone()),
payroll_factory: DaoExternalPayrollFactory::new("cw_payroll", chain.clone()),
cw_tokenswap: DaoExternalTokenSwap::new("cw_tokenswap", chain.clone()),
cw_tokenfactory_issuer: DaoExternalTokenfactoryIssuer::new(
"cw_tokenfactory",
chain.clone(),
),
cw_vesting: DaoExternalCwVesting::new("cw_vesting", chain.clone()),
cw721_roles: DaoExternalCw721Roles::new("cw721_roles", chain.clone()),
migrator: DaoExternalMigrator::new("dao_migrator", chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.admin_factory.upload()?;
self.btsg_ft_factory.upload()?;
self.payroll_factory.upload()?;
self.cw_tokenswap.upload()?;
self.cw_tokenfactory_issuer.upload()?;
self.cw_vesting.upload()?;
self.cw721_roles.upload()?;
self.migrator.upload()?;

Ok(())
}
}
}
9 changes: 8 additions & 1 deletion scripts/src/propose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ impl<Chain: CwEnv> DaoPreProposeSuite<Chain> {
self.pre_prop_approval_single.upload()?;
self.pre_prop_approver.upload()?;
self.pre_prop_multiple.upload()?;
self.pre_prop_single.upload()?;

Ok(())
}
}

// proposal suite
pub struct DaoProposalSuite<Chain> {
pub prop_single: DaoProposalSingle<Chain>,
pub prop_multiple: DaoProposalMultiple<Chain>,
pub prop_condocert: DaoProposalCondorcet<Chain>,
pub prop_sudo: DaoProposalSudo<Chain>,
pub pre_prop_suite: DaoPreProposeSuite<Chain>,
}

impl<Chain: CwEnv> DaoProposalSuite<Chain> {
Expand All @@ -48,14 +52,17 @@ impl<Chain: CwEnv> DaoProposalSuite<Chain> {
prop_single: DaoProposalSingle::new("dao_proposal_single", chain.clone()),
prop_multiple: DaoProposalMultiple::new("dao_proposal_multiple", chain.clone()),
prop_condocert: DaoProposalCondorcet::new("dao_proposal_condocert", chain.clone()),
prop_sudo: DaoProposalSudo::new("dao_proposal_sudo", chain.clone()),
pre_prop_suite: DaoPreProposeSuite::new(chain.clone()),
}
}

pub fn upload(&self) -> Result<(), CwOrchError> {
self.prop_single.upload()?;
self.prop_multiple.upload()?;
self.prop_condocert.upload()?;
self.prop_sudo.upload()?;
self.pre_prop_suite.upload()?;
Ok(())
}
}

42 changes: 42 additions & 0 deletions scripts/src/tests/deploy/dao.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::DaoDao;
use cw_orch::prelude::*;
// distribution suite
impl<Chain: CwEnv> cw_orch::contract::Deploy<Chain> for DaoDao<Chain> {
// We don't have a custom error type
type Error = CwOrchError;
type DeployData = Addr;

fn store_on(chain: Chain) -> Result<Self, Self::Error> {
let suite = DaoDao::new(chain.clone());
suite.upload()?;
Ok(suite)
}

fn deployed_state_file_path() -> Option<String> {
None
}

fn get_contracts_mut(&mut self) -> Vec<Box<&mut dyn ContractInstance<Chain>>> {
let mut cs: Vec<Box<&mut dyn ContractInstance<Chain>>> = vec![];
let res: Vec<Box<&mut dyn ContractInstance<Chain>>> = vec![Box::new(&mut self.dao_core)];

cs.extend(res);
cs.extend(self.distribution_suite.get_contracts_mut());
cs.extend(self.proposal_suite.get_contracts_mut());
cs.extend(self.staking_suite.get_contracts_mut());
cs.extend(self.voting_suite.get_contracts_mut());
cs.extend(self.external_suite.get_contracts_mut());
cs
}

fn load_from(chain: Chain) -> Result<Self, Self::Error> {
let suite = Self::new(chain.clone());
Ok(suite)
}

fn deploy_on(chain: Chain, _data: Self::DeployData) -> Result<Self, Self::Error> {
// ########### Upload ##############
let suite: DaoDao<Chain> = DaoDao::store_on(chain.clone())?;
Ok(suite)
}
}
Loading

0 comments on commit 3990e13

Please sign in to comment.