Skip to content

Commit

Permalink
Fix token gateway flow with v2.5.0-callbacks fork
Browse files Browse the repository at this point in the history
  • Loading branch information
ismellike committed Sep 8, 2024
1 parent af85148 commit 887a40f
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 462 deletions.
657 changes: 257 additions & 400 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,33 @@ arena-token-gateway = { path = "./contracts/arena-token-gateway" }
arena-payment-registry = { path = "./contracts/arena-payment-registry" }

#dao dependencies
dao-interface = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development" }
cw-vesting = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
dao-interface = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks" }
dao-cw-orch = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks" }
cw-vesting = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
cw-payroll-factory = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
cw-payroll-factory = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
dao-proposal-multiple = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
dao-proposal-multiple = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
dao-proposal-single = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
dao-proposal-single = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
dao-pre-propose-single = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
dao-pre-propose-single = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
dao-voting = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development" }
dao-voting-cw4 = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
dao-voting = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks" }
dao-voting-cw4 = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
dao-proposal-sudo = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
dao-proposal-sudo = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
dao-pre-propose-base = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
dao-pre-propose-base = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
dao-dao-core = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "development", features = [
dao-dao-core = { git = "https://github.com/ismellike/dao-contracts", branch = "fork/v2.5.0-callbacks", features = [
"library",
] }
6 changes: 3 additions & 3 deletions contracts/arena-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cosmwasm_std::{
};
use cw2::{ensure_from_older_version, set_contract_version};
use cw_utils::parse_reply_instantiate_data;
use dao_interface::{msg::ExecuteMsg as DAOCoreExecuteMsg, state::ModuleInstantiateCallback};
use dao_interface::{msg::ExecuteMsg as DAOCoreExecuteMsg, state::CallbackMessages};

pub(crate) const CONTRACT_NAME: &str = "crates.io:arena-core";
pub(crate) const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -133,7 +133,7 @@ pub fn instantiate_extension(

Ok(prepropose_response
.add_messages(msgs)
.set_data(to_json_binary(&ModuleInstantiateCallback {
.set_data(to_json_binary(&CallbackMessages {
msgs: vec![CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: dao.to_string(),
msg: to_json_binary(&DAOCoreExecuteMsg::SetItem {
Expand Down Expand Up @@ -231,7 +231,7 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr

// Check for module instantiation callbacks
let callback_msgs = match res.data {
Some(data) => from_json::<ModuleInstantiateCallback>(&data)
Some(data) => from_json::<CallbackMessages>(&data)
.map(|m| m.msgs)
.unwrap_or_else(|_| vec![]),
None => vec![],
Expand Down
2 changes: 1 addition & 1 deletion contracts/arena-token-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ cw-address-like = { workspace = true }
cw-vesting = { workspace = true }
cw-payroll-factory = { workspace = true }
dao-interface = { workspace = true }
serde_json = { workspace = true }
serde_json = { workspace = true }
4 changes: 2 additions & 2 deletions contracts/arena-token-gateway/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm_std::{
use cw_ownable::assert_owner;
use cw_utils::one_coin;
use cw_vesting::vesting::Schedule;
use dao_interface::state::ModuleInstantiateCallback;
use dao_interface::state::CallbackMessages;

use crate::{
helpers::get_payroll_address,
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn accept_application(
let payroll_factory = get_payroll_address(deps.as_ref(), &env.block.chain_id)?;

// Prepare the instantiate message for the vesting contract
let vesting_data = to_json_binary(&ModuleInstantiateCallback {
let vesting_data = to_json_binary(&CallbackMessages {
msgs: vec![CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: payroll_factory.to_string(),
msg: to_json_binary(
Expand Down
2 changes: 1 addition & 1 deletion contracts/arena-wager-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw-competition-base = { workspace = true }
arena-interface = { workspace = true }
cw-orch = { workspace = true }
cw-orch = { workspace = true }
3 changes: 2 additions & 1 deletion packages/orch-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ doctest = false

[dependencies]
cw-orch = { workspace = true }
dao-dao-core = { workspace = true }
dao-interface = { workspace = true }
arena-wager-module = { workspace = true }
arena-league-module = { workspace = true }
arena-tournament-module = { workspace = true }
Expand All @@ -22,5 +24,4 @@ arena-payment-registry = { workspace = true }
cosmwasm-std = { workspace = true }

cw4-group = { package = "abstract-cw4-group", git = "https://github.com/AbstractSDK/cw-plus", branch = "abstract_versions" }
# cw20-base = { package = "abstract-cw20-base", git = "https://github.com/AbstractSDK/cw-plus", branch = "abstract_versions" }
cw721-base = { git = "https://github.com/AbstractSDK/cw-nfts", branch = "main" }
29 changes: 29 additions & 0 deletions packages/orch-interface/src/dao_dao_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use cw_orch::interface;
#[cfg(not(target_arch = "wasm32"))]
use cw_orch::prelude::*;

#[allow(unused_imports)]
use dao_interface::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

pub const CONTRACT_ID: &str = "dao_dao_core";

#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg, id = CONTRACT_ID)]
pub struct DaoDaoCoreContract;

#[cfg(not(target_arch = "wasm32"))]
impl<Chain> Uploadable for DaoDaoCoreContract<Chain> {
/// Return the path to the wasm file corresponding to the contract
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
artifacts_dir_from_workspace!()
.find_wasm_path(CONTRACT_ID)
.unwrap()
}
/// Returns a CosmWasm contract wrapper
fn wrapper() -> Box<dyn MockContract<Empty>> {
Box::new(ContractWrapper::new_with_empty(
arena_token_gateway::contract::execute,
arena_token_gateway::contract::instantiate,
arena_token_gateway::contract::query,
))
}
}
1 change: 1 addition & 0 deletions packages/orch-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pub mod arena_tournament_module;
pub mod arena_wager_module;
pub mod cw4_group;
pub mod cw721_base;
pub mod dao_dao_core;
29 changes: 11 additions & 18 deletions scripts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,25 @@ cosmwasm-std = { workspace = true }
orch-interface = { workspace = true }
cw-utils = { workspace = true }
cw-balance = { workspace = true }
dao-cw-orch = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "feature/cw-orch-interface" }
dao-cw-orch = { workspace = true }
itertools = { workspace = true }
arena-competition-enrollment = { workspace = true }
arena-token-gateway = { workspace = true }
arena-payment-registry = { workspace = true }
cosmwasm-schema = { workspace = true }
serde_json = { workspace = true }

# DA0 DA0
dao-interface = { workspace = true }
dao-voting = { workspace = true }
dao-proposal-sudo = { workspace = true }
dao-proposal-single = { workspace = true }
cw-vesting = { workspace = true }
cw-payroll-factory = { workspace = true }
dao-voting-cw4 = { workspace = true }
cw4 = { workspace = true }

# scripts specific
dotenv = { version = "0.15.0" }
pretty_env_logger = { version = "0.5.0" }
cw-orch-clone-testing = "0.6.4"

# cw-orch enabled DAO DAO deps
[dev-dependencies]
dao-interface-master = { package = "dao-interface", git = "https://github.com/DA0-DA0/dao-contracts", branch = "development" }
dao-voting-master = { package = "dao-voting", git = "https://github.com/DA0-DA0/dao-contracts", branch = "development" }
dao-interface = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "feature/cw-orch-interface" }
dao-proposal-sudo = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "feature/cw-orch-interface", features = [
"library",
] }
dao-proposal-single = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "feature/cw-orch-interface", features = [
"library",
] }
dao-voting = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "feature/cw-orch-interface" }
cw-vesting = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "feature/cw-orch-interface" }
cw-payroll-factory = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "feature/cw-orch-interface" }
dao-voting-cw4 = { git = "https://github.com/DA0-DA0/dao-contracts", branch = "feature/cw-orch-interface" }
cw4 = { workspace = true }
11 changes: 10 additions & 1 deletion scripts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use orch_interface::{
arena_core::ArenaCoreContract, arena_league_module::ArenaLeagueModuleContract,
arena_token_gateway::ArenaTokenGatewayContract,
arena_tournament_module::ArenaTournamentModuleContract,
arena_wager_module::ArenaWagerModuleContract,
arena_wager_module::ArenaWagerModuleContract, dao_dao_core::DaoDaoCoreContract,
};
use std::env;

Expand Down Expand Up @@ -45,6 +45,7 @@ enum DeployComponent {
Enrollment,
TokenGateway,
CompetitionModules,
DaoCore,
}

fn parse_command(args: &[String]) -> Command {
Expand All @@ -65,6 +66,7 @@ fn parse_command(args: &[String]) -> Command {
"enrollment" => DeployComponent::Enrollment,
"token_gateway" => DeployComponent::TokenGateway,
"competition_modules" => DeployComponent::CompetitionModules,
"dao_core" => DeployComponent::DaoCore,
_ => return Command::Unknown,
};

Expand All @@ -84,6 +86,7 @@ fn deploy(network: Network, component: DeployComponent) -> anyhow::Result<()> {
DeployComponent::Enrollment => deploy_enrollment(daemon)?,
DeployComponent::TokenGateway => deploy_token_gateway(daemon)?,
DeployComponent::CompetitionModules => deploy_competition_modules(daemon)?,
DeployComponent::DaoCore => deploy_dao_core(daemon)?,
}

Ok(())
Expand Down Expand Up @@ -129,6 +132,12 @@ fn deploy_competition_modules(daemon: Daemon) -> anyhow::Result<()> {
Ok(())
}

fn deploy_dao_core(daemon: Daemon) -> anyhow::Result<()> {
let dao_core = DaoDaoCoreContract::new(daemon);
dao_core.upload()?;
Ok(())
}

mod arena;
mod dao_dao;
#[cfg(test)]
Expand Down
53 changes: 41 additions & 12 deletions scripts/src/tests/arena_token_gateway.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::tests::helpers::{setup_arena, setup_vesting};
use arena_token_gateway::msg::{ApplyMsg, ExecuteMsgFns as _, QueryMsgFns as _};
use cosmwasm_std::{coins, Decimal, Uint128};
use crate::tests::helpers::{setup_arena, setup_vesting, setup_voting_module};
use arena_token_gateway::msg::{ApplyMsg, ExecuteMsg, ExecuteMsgFns as _, QueryMsgFns as _};
use cosmwasm_std::{coins, to_json_binary, CosmosMsg, Decimal, Uint128, WasmMsg};
use cw4::Member;
use cw_orch::{anyhow, prelude::*};
use cw_payroll_factory::msg::QueryMsgFns as _;
use dao_voting::{proposal::SingleChoiceProposeMsg, voting::SingleChoiceAutoVote};

use super::{DENOM, PREFIX};

Expand Down Expand Up @@ -41,6 +43,14 @@ fn test_apply_and_accept_application() -> anyhow::Result<()> {
let mock = MockBech32::new(PREFIX);
let (mut arena, admin) = setup_arena(&mock)?;
setup_vesting(&arena, mock.block_info()?.chain_id, &admin)?;
setup_voting_module(
&mock,
&arena,
vec![Member {
addr: admin.to_string(),
weight: 1,
}],
)?;

mock.add_balance(
&arena.dao_dao.dao_core.address()?,
Expand Down Expand Up @@ -85,12 +95,32 @@ fn test_apply_and_accept_application() -> anyhow::Result<()> {
);

// Accept the application with the upfront amount attached
arena
.arena_token_gateway
.set_sender(&arena.dao_dao.dao_core.address()?);
arena
.arena_token_gateway
.accept_application(1u128, &coins(100000, DENOM))?;
arena.dao_dao.dao_proposal_single.call_as(&admin).execute(
&dao_proposal_single::msg::ExecuteMsg::Propose(SingleChoiceProposeMsg {
title: "Accept token gateway application".to_owned(),
description: "Testing the token gateway application process with callback messages"
.to_owned(),
msgs: vec![CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: arena.arena_token_gateway.addr_str()?,
msg: to_json_binary(&ExecuteMsg::AcceptApplication {
application_id: Uint128::one(),
})?,
funds: coins(100000, DENOM),
})],
proposer: None,
vote: Some(SingleChoiceAutoVote {
vote: dao_voting::voting::Vote::Yes,
rationale: None,
}),
}),
None,
)?;
let res = arena.dao_dao.dao_proposal_single.execute(
&dao_proposal_single::msg::ExecuteMsg::Execute { proposal_id: 1 },
None,
)?;
dbg!(res.events);
dbg!(arena.dao_dao.cw_payroll_factory.address()?);

// Query the application again
let updated_application = arena.arena_token_gateway.application(1u128)?;
Expand All @@ -112,13 +142,12 @@ fn test_apply_and_accept_application() -> anyhow::Result<()> {
.cw_payroll_factory
.set_address(&payroll_address);

let _vesting_contracts = arena
let vesting_contracts = arena
.dao_dao
.cw_payroll_factory
.list_vesting_contracts(None, None)?;

// TODO: proposal execute data does not get picked up by the DAO atm
// assert!(!vesting_contracts.is_empty());
assert!(!vesting_contracts.is_empty());

// Ensure token gateway balance is empty
let gateway_balance = mock.query_balance(&arena.arena_token_gateway.address()?, DENOM)?;
Expand Down
3 changes: 2 additions & 1 deletion scripts/src/tests/arena_wager_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use cw_balance::{
use cw_orch::{anyhow, prelude::*};
use cw_orch_clone_testing::CloneTesting;
use cw_utils::Expiration;
use dao_interface::CoreQueryMsgFns;
use networks::PION_1;

use crate::arena::Arena;
Expand Down Expand Up @@ -782,7 +783,7 @@ fn test_jailed_wager_resolved_by_dao() -> anyhow::Result<()> {
let res = mock.call_as(&admin).execute(
&dao_proposal_single::msg::ExecuteMsg::Execute { proposal_id: 1 },
&[],
&arena.dao_dao.dao_proposal_single.address()?,
&arena.dao_dao.dao_core.proposal_modules(None, None)?[1].address,
)?;
dbg!(res);

Expand Down
Loading

0 comments on commit 887a40f

Please sign in to comment.