Skip to content

Commit

Permalink
Restore dao-voting-native-staked, rename tf contract
Browse files Browse the repository at this point in the history
The token factory contract will not work on chains without the Token
Factory module. This restores the previous contract, and creates a new
`dao-voting-token-factory-staked` contract.
  • Loading branch information
JakeHartnell committed Aug 18, 2023
1 parent 3c7050e commit f3b6611
Show file tree
Hide file tree
Showing 33 changed files with 4,364 additions and 2,442 deletions.
443 changes: 29 additions & 414 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cw721 = "0.18"
cw721-base = "0.18"
env_logger = "0.10"
once_cell = "1.18"
osmosis-test-tube = "16.1.2"
# osmosis-test-tube = "16.1.2"
proc-macro2 = "1.0"
quote = "1.0"
rand = "0.8"
Expand Down Expand Up @@ -107,6 +107,7 @@ dao-voting-cw4 = { path = "./contracts/voting/dao-voting-cw4", version = "2.2.0"
dao-voting-cw721-roles = { path = "./contracts/voting/dao-voting-cw721-roles", version = "*" }
dao-voting-cw721-staked = { path = "./contracts/voting/dao-voting-cw721-staked", version = "2.2.0" }
dao-voting-native-staked = { path = "./contracts/voting/dao-voting-native-staked", version = "2.2.0" }
dao-voting-token-factory-staked = { path = "./contracts/voting/dao-voting-token-factory-staked", version = "2.2.0" }

# v1 dependencies. used for state migrations.
cw-core-v1 = { package = "cw-core", version = "0.1.0" }
Expand Down
1 change: 0 additions & 1 deletion contracts/proposal/dao-proposal-multiple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ cw721-base = { workspace = true }
cw4 = { workspace = true }
cw4-group = { workspace = true }
rand = { workspace = true }
token-bindings = { workspace = true }
220 changes: 109 additions & 111 deletions contracts/proposal/dao-proposal-multiple/src/testing/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dao_pre_propose_multiple as cppm;
use dao_testing::contracts::{
cw20_balances_voting_contract, cw20_base_contract, cw20_stake_contract,
cw20_staked_balances_voting_contract, cw4_group_contract, cw721_base_contract,
dao_dao_contract, pre_propose_multiple_contract,
dao_dao_contract, native_staked_balances_voting_contract, pre_propose_multiple_contract,
};
use dao_voting::{
deposit::{DepositRefundPolicy, UncheckedDepositInfo},
Expand Down Expand Up @@ -223,116 +223,114 @@ pub fn _instantiate_with_staked_cw721_governance(
core_addr
}

// pub fn _instantiate_with_native_staked_balances_governance(
// app: &mut App,
// proposal_module_instantiate: InstantiateMsg,
// initial_balances: Option<Vec<Cw20Coin>>,
// ) -> Addr {
// let proposal_module_code_id = app.store_code(proposal_multiple_contract());

// let initial_balances = initial_balances.unwrap_or_else(|| {
// vec![Cw20Coin {
// address: CREATOR_ADDR.to_string(),
// amount: Uint128::new(100_000_000),
// }]
// });

// // Collapse balances so that we can test double votes.
// let initial_balances: Vec<Cw20Coin> = {
// let mut already_seen = vec![];
// initial_balances
// .into_iter()
// .filter(|Cw20Coin { address, amount: _ }| {
// if already_seen.contains(address) {
// false
// } else {
// already_seen.push(address.clone());
// true
// }
// })
// .collect()
// };

// let native_stake_id = app.store_code(native_staked_balances_voting_contract());
// let core_contract_id = app.store_code(dao_dao_contract());

// let instantiate_core = dao_interface::msg::InstantiateMsg {
// admin: None,
// name: "DAO DAO".to_string(),
// description: "A DAO that builds DAOs".to_string(),
// image_url: None,
// automatically_add_cw20s: true,
// automatically_add_cw721s: false,
// voting_module_instantiate_info: ModuleInstantiateInfo {
// code_id: native_stake_id,
// msg: to_binary(&dao_voting_native_staked::msg::InstantiateMsg {
// owner: Some(Admin::CoreModule {}),
// manager: None,
// token_info: dao_voting_native_staked::msg::TokenInfo::Existing {
// denom: "ujuno".to_string(),
// },
// unstaking_duration: None,
// active_threshold: None,
// })
// .unwrap(),
// admin: None,
// label: "DAO DAO voting module".to_string(),
// },
// proposal_modules_instantiate_info: vec![ModuleInstantiateInfo {
// code_id: proposal_module_code_id,
// label: "DAO DAO governance module.".to_string(),
// admin: Some(Admin::CoreModule {}),
// msg: to_binary(&proposal_module_instantiate).unwrap(),
// }],
// initial_items: None,
// dao_uri: None,
// };

// let core_addr = app
// .instantiate_contract(
// core_contract_id,
// Addr::unchecked(CREATOR_ADDR),
// &instantiate_core,
// &[],
// "DAO DAO",
// None,
// )
// .unwrap();

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

// for Cw20Coin { address, amount } in initial_balances {
// app.sudo(SudoMsg::Bank(BankSudo::Mint {
// to_address: address.clone(),
// amount: vec![Coin {
// denom: "ujuno".to_string(),
// amount,
// }],
// }))
// .unwrap();
// app.execute_contract(
// Addr::unchecked(&address),
// native_staking_addr.clone(),
// &dao_voting_native_staked::msg::ExecuteMsg::Stake {},
// &[Coin {
// amount,
// denom: "ujuno".to_string(),
// }],
// )
// .unwrap();
// }

// app.update_block(next_block);

// core_addr
// }
pub fn _instantiate_with_native_staked_balances_governance(
app: &mut App,
proposal_module_instantiate: InstantiateMsg,
initial_balances: Option<Vec<Cw20Coin>>,
) -> Addr {
let proposal_module_code_id = app.store_code(proposal_multiple_contract());

let initial_balances = initial_balances.unwrap_or_else(|| {
vec![Cw20Coin {
address: CREATOR_ADDR.to_string(),
amount: Uint128::new(100_000_000),
}]
});

// Collapse balances so that we can test double votes.
let initial_balances: Vec<Cw20Coin> = {
let mut already_seen = vec![];
initial_balances
.into_iter()
.filter(|Cw20Coin { address, amount: _ }| {
if already_seen.contains(address) {
false
} else {
already_seen.push(address.clone());
true
}
})
.collect()
};

let native_stake_id = app.store_code(native_staked_balances_voting_contract());
let core_contract_id = app.store_code(dao_dao_contract());

let instantiate_core = dao_interface::msg::InstantiateMsg {
admin: None,
name: "DAO DAO".to_string(),
description: "A DAO that builds DAOs".to_string(),
image_url: None,
automatically_add_cw20s: true,
automatically_add_cw721s: false,
voting_module_instantiate_info: ModuleInstantiateInfo {
code_id: native_stake_id,
msg: to_binary(&dao_voting_native_staked::msg::InstantiateMsg {
owner: Some(Admin::CoreModule {}),
manager: None,
denom: "ujuno".to_string(),
unstaking_duration: None,
// active_threshold: None,
})
.unwrap(),
admin: None,
label: "DAO DAO voting module".to_string(),
},
proposal_modules_instantiate_info: vec![ModuleInstantiateInfo {
code_id: proposal_module_code_id,
label: "DAO DAO governance module.".to_string(),
admin: Some(Admin::CoreModule {}),
msg: to_binary(&proposal_module_instantiate).unwrap(),
}],
initial_items: None,
dao_uri: None,
};

let core_addr = app
.instantiate_contract(
core_contract_id,
Addr::unchecked(CREATOR_ADDR),
&instantiate_core,
&[],
"DAO DAO",
None,
)
.unwrap();

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

for Cw20Coin { address, amount } in initial_balances {
app.sudo(SudoMsg::Bank(BankSudo::Mint {
to_address: address.clone(),
amount: vec![Coin {
denom: "ujuno".to_string(),
amount,
}],
}))
.unwrap();
app.execute_contract(
Addr::unchecked(&address),
native_staking_addr.clone(),
&dao_voting_native_staked::msg::ExecuteMsg::Stake {},
&[Coin {
amount,
denom: "ujuno".to_string(),
}],
)
.unwrap();
}

app.update_block(next_block);

core_addr
}

pub fn instantiate_with_cw20_balances_governance(
app: &mut App,
Expand Down
1 change: 0 additions & 1 deletion contracts/proposal/dao-proposal-single/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ cw721-base = { workspace = true }
cw4 = { workspace = true }
cw4-group = { workspace = true }
cw-core-v1 = { workspace = true, features = ["library"] }
token-bindings-test = { workspace = true }
16 changes: 8 additions & 8 deletions contracts/proposal/dao-proposal-single/src/testing/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ pub(crate) fn cw20_staked_balances_voting_contract() -> Box<dyn Contract<Empty>>
Box::new(contract)
}

// pub(crate) fn native_staked_balances_voting_contract() -> Box<dyn Contract<Empty>> {
// let contract = ContractWrapper::new(
// dao_voting_native_staked::contract::execute,
// dao_voting_native_staked::contract::instantiate,
// dao_voting_native_staked::contract::query,
// );
// Box::new(contract)
// }
pub(crate) fn native_staked_balances_voting_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
dao_voting_native_staked::contract::execute,
dao_voting_native_staked::contract::instantiate,
dao_voting_native_staked::contract::query,
);
Box::new(contract)
}

pub(crate) fn cw721_stake_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
Expand Down
Loading

0 comments on commit f3b6611

Please sign in to comment.