From 91ad0d5c1b78664d7dfa66aaa1eb74de20e47492 Mon Sep 17 00:00:00 2001 From: cyberhoward Date: Tue, 28 May 2024 15:37:39 +0200 Subject: [PATCH] move to adapter --- Cargo.toml | 3 +- .../{my-adapter => interchain-gov}/Cargo.toml | 8 +- .../metadata.json | 0 .../{my-adapter => interchain-gov}/src/api.rs | 29 ++-- .../src/bin/local_daemon.rs | 16 +-- .../src/bin/publish.rs | 8 +- .../src/bin/schema.rs | 4 +- contracts/interchain-gov/src/contract.rs | 35 +++++ .../src/error.rs | 2 +- .../src/handlers/execute.rs | 20 +-- .../src/handlers/instantiate.rs | 8 +- .../src/handlers/mod.rs | 0 .../src/handlers/query.rs | 12 +- .../{my-adapter => interchain-gov}/src/lib.rs | 8 +- .../{intersync => interchain-gov}/src/msg.rs | 21 +-- .../src/state.rs | 35 ++--- .../tests/integration.rs | 28 ++-- contracts/intersync/Cargo.toml | 74 ---------- contracts/intersync/metadata.json | 9 -- contracts/intersync/src/bin/local_daemon.rs | 70 ---------- contracts/intersync/src/bin/publish.rs | 64 --------- contracts/intersync/src/contract.rs | 40 ------ contracts/intersync/src/data.rs | 10 -- contracts/intersync/src/error.rs | 28 ---- contracts/intersync/src/handlers/execute.rs | 44 ------ .../intersync/src/handlers/instantiate.rs | 21 --- contracts/intersync/src/handlers/migrate.rs | 18 --- contracts/intersync/src/handlers/mod.rs | 9 -- contracts/intersync/src/handlers/query.rs | 30 ----- contracts/intersync/src/lib.rs | 18 --- .../intersync/src/replies/instantiate.rs | 8 -- contracts/intersync/src/replies/mod.rs | 5 - contracts/intersync/tests/integration.rs | 127 ------------------ contracts/my-adapter/src/bin/schema.rs | 14 -- contracts/my-adapter/src/contract.rs | 35 ----- contracts/my-adapter/src/msg.rs | 39 ------ contracts/my-adapter/src/state.rs | 8 -- 37 files changed, 131 insertions(+), 777 deletions(-) rename contracts/{my-adapter => interchain-gov}/Cargo.toml (93%) rename contracts/{my-adapter => interchain-gov}/metadata.json (100%) rename contracts/{my-adapter => interchain-gov}/src/api.rs (61%) rename contracts/{my-adapter => interchain-gov}/src/bin/local_daemon.rs (85%) rename contracts/{my-adapter => interchain-gov}/src/bin/publish.rs (88%) rename contracts/{intersync => interchain-gov}/src/bin/schema.rs (76%) create mode 100644 contracts/interchain-gov/src/contract.rs rename contracts/{my-adapter => interchain-gov}/src/error.rs (95%) rename contracts/{my-adapter => interchain-gov}/src/handlers/execute.rs (72%) rename contracts/{my-adapter => interchain-gov}/src/handlers/instantiate.rs (70%) rename contracts/{my-adapter => interchain-gov}/src/handlers/mod.rs (100%) rename contracts/{my-adapter => interchain-gov}/src/handlers/query.rs (68%) rename contracts/{my-adapter => interchain-gov}/src/lib.rs (60%) rename contracts/{intersync => interchain-gov}/src/msg.rs (67%) rename contracts/{intersync => interchain-gov}/src/state.rs (53%) rename contracts/{my-adapter => interchain-gov}/tests/integration.rs (80%) delete mode 100644 contracts/intersync/Cargo.toml delete mode 100644 contracts/intersync/metadata.json delete mode 100644 contracts/intersync/src/bin/local_daemon.rs delete mode 100644 contracts/intersync/src/bin/publish.rs delete mode 100644 contracts/intersync/src/contract.rs delete mode 100644 contracts/intersync/src/data.rs delete mode 100644 contracts/intersync/src/error.rs delete mode 100644 contracts/intersync/src/handlers/execute.rs delete mode 100644 contracts/intersync/src/handlers/instantiate.rs delete mode 100644 contracts/intersync/src/handlers/migrate.rs delete mode 100644 contracts/intersync/src/handlers/mod.rs delete mode 100644 contracts/intersync/src/handlers/query.rs delete mode 100644 contracts/intersync/src/lib.rs delete mode 100644 contracts/intersync/src/replies/instantiate.rs delete mode 100644 contracts/intersync/src/replies/mod.rs delete mode 100644 contracts/intersync/tests/integration.rs delete mode 100644 contracts/my-adapter/src/bin/schema.rs delete mode 100644 contracts/my-adapter/src/contract.rs delete mode 100644 contracts/my-adapter/src/msg.rs delete mode 100644 contracts/my-adapter/src/state.rs diff --git a/Cargo.toml b/Cargo.toml index 7e1fdf3..23101f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,8 +31,7 @@ lazy_static = "1.4.0" cw-orch = { version = "0.22.2" } const_format = "0.2.32" -intersync = { path = "contracts/intersync" } -my-adapter = { path = "contracts/my-adapter" } +interchain-gov = { path = "contracts/interchain-gov" } speculoos = "0.11.0" semver = "1.0" dotenv = "0.15.0" diff --git a/contracts/my-adapter/Cargo.toml b/contracts/interchain-gov/Cargo.toml similarity index 93% rename from contracts/my-adapter/Cargo.toml rename to contracts/interchain-gov/Cargo.toml index daca6a4..d092405 100644 --- a/contracts/my-adapter/Cargo.toml +++ b/contracts/interchain-gov/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "my-adapter" +name = "interchain-gov" version = "0.0.1" authors = [ "CyberHoward ", @@ -54,6 +54,10 @@ cw-asset = { workspace = true } abstract-adapter = { workspace = true } const_format = { workspace = true } +serde = "1" +cw-utils = "1.0.3" +dao-voting = "2.3.0" + # Dependencies for interface cw-orch = { workspace = true } abstract-interface = { workspace = true } @@ -65,6 +69,6 @@ dotenv = { workspace = true, optional = true } env_logger = { workspace = true, optional = true } [dev-dependencies] -my-adapter = { workspace = true } +interchain-gov = { workspace = true } abstract-client = { workspace = true } abstract-adapter = { workspace = true, features = ["test-utils"] } diff --git a/contracts/my-adapter/metadata.json b/contracts/interchain-gov/metadata.json similarity index 100% rename from contracts/my-adapter/metadata.json rename to contracts/interchain-gov/metadata.json diff --git a/contracts/my-adapter/src/api.rs b/contracts/interchain-gov/src/api.rs similarity index 61% rename from contracts/my-adapter/src/api.rs rename to contracts/interchain-gov/src/api.rs index 1a708df..3c6456a 100644 --- a/contracts/my-adapter/src/api.rs +++ b/contracts/interchain-gov/src/api.rs @@ -1,5 +1,5 @@ use crate::{ - msg::{MyAdapterExecuteMsg, MyAdapterQueryMsg}, + msg::{InterchainGovExecuteMsg, InterchainGovQueryMsg}, MY_ADAPTER_ID, }; @@ -13,10 +13,10 @@ use cosmwasm_std::{CosmosMsg, Deps, Uint128}; // API for Abstract SDK users /// Interact with your adapter in other modules. -pub trait MyAdapterApi: AccountIdentification + Dependencies + ModuleIdentification { +pub trait InterchainGovApi: AccountIdentification + Dependencies + ModuleIdentification { /// Construct a new adapter interface. - fn my_adapter<'a>(&'a self, deps: Deps<'a>) -> MyAdapter { - MyAdapter { + fn interchain_gov<'a>(&'a self, deps: Deps<'a>) -> InterchainGov { + InterchainGov { base: self, deps, module_id: MY_ADAPTER_ID, @@ -24,16 +24,16 @@ pub trait MyAdapterApi: AccountIdentification + Dependencies + ModuleIdentificat } } -impl MyAdapterApi for T {} +impl InterchainGovApi for T {} #[derive(Clone)] -pub struct MyAdapter<'a, T: MyAdapterApi> { +pub struct InterchainGov<'a, T: InterchainGovApi> { pub base: &'a T, pub module_id: ModuleId<'a>, pub deps: Deps<'a>, } -impl<'a, T: MyAdapterApi> MyAdapter<'a, T> { +impl<'a, T: InterchainGovApi> InterchainGov<'a, T> { /// Set the module id pub fn with_module_id(self, module_id: ModuleId<'a>) -> Self { Self { module_id, ..self } @@ -44,29 +44,24 @@ impl<'a, T: MyAdapterApi> MyAdapter<'a, T> { self.module_id } - /// Executes a [MyAdapterExecuteMsg] in the adapter - fn request(&self, msg: MyAdapterExecuteMsg) -> AbstractSdkResult { + /// Executes a [InterchainGovExecuteMsg] in the adapter + fn request(&self, msg: InterchainGovExecuteMsg) -> AbstractSdkResult { let adapters = self.base.adapters(self.deps); adapters.execute(self.module_id(), msg) } - - /// Route message - pub fn update_config(&self) -> AbstractSdkResult { - self.request(MyAdapterExecuteMsg::UpdateConfig {}) - } } /// Queries -impl<'a, T: MyAdapterApi> MyAdapter<'a, T> { +impl<'a, T: InterchainGovApi> InterchainGov<'a, T> { /// Query your adapter via message type - pub fn query(&self, query_msg: MyAdapterQueryMsg) -> AbstractSdkResult { + pub fn query(&self, query_msg: InterchainGovQueryMsg) -> AbstractSdkResult { let adapters = self.base.adapters(self.deps); adapters.query(self.module_id(), query_msg) } /// Query config pub fn config(&self) -> AbstractSdkResult { - self.query(MyAdapterQueryMsg::Config {}) + self.query(InterchainGovQueryMsg::Config {}) } } diff --git a/contracts/my-adapter/src/bin/local_daemon.rs b/contracts/interchain-gov/src/bin/local_daemon.rs similarity index 85% rename from contracts/my-adapter/src/bin/local_daemon.rs rename to contracts/interchain-gov/src/bin/local_daemon.rs index 6d747ae..c9a546d 100644 --- a/contracts/my-adapter/src/bin/local_daemon.rs +++ b/contracts/interchain-gov/src/bin/local_daemon.rs @@ -6,13 +6,13 @@ //! //! # Run //! -//! `RUST_LOG=info cargo run --bin local_daemon --features="daemon-bin" --package my-adapter` -use my_adapter::{contract::interface::MyAdapterInterface, MyAdapterExecuteMsg, MY_ADAPTER_ID}; +//! `RUST_LOG=info cargo run --bin local_daemon --features="daemon-bin" --package interchain-gov` +use interchain_gov::{contract::interface::InterchainGovInterface, InterchainGovExecuteMsg, MY_ADAPTER_ID}; use abstract_adapter::{objects::namespace::Namespace, std::adapter::AdapterRequestMsg}; use abstract_client::{AbstractClient, Publisher}; use cw_orch::{anyhow, prelude::*, tokio::runtime::Runtime}; -use my_adapter::msg::MyAdapterInstantiateMsg; +use interchain_gov::msg::InterchainGovInstantiateMsg; const LOCAL_MNEMONIC: &str = "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose"; @@ -50,18 +50,18 @@ fn main() -> anyhow::Result<()> { ); // Publish the Adapter to the Abstract Platform - publisher.publish_adapter::>( - MyAdapterInstantiateMsg {}, + publisher.publish_adapter::>( + InterchainGovInstantiateMsg {}, )?; // Install the Adapter on a new account let account = abstract_client.account_builder().build()?; // Installs the adapter on the Account - let adapter = account.install_adapter::>(&[])?; + let adapter = account.install_adapter::>(&[])?; // // Import adapter's endpoint function traits for easy interactions. - use my_adapter::msg::MyAdapterQueryMsgFns; + use interchain_gov::msg::InterchainGovQueryMsgFns; let status_response = adapter.status(adapter.account().id()?)?; assert!(status_response.status.is_none()); @@ -70,7 +70,7 @@ fn main() -> anyhow::Result<()> { &AdapterRequestMsg { // Adapter need to know on which account action is performed proxy_address: Some(adapter.account().proxy()?.to_string()), - request: MyAdapterExecuteMsg::SetStatus { + request: InterchainGovExecuteMsg::SetStatus { status: "new_status".to_owned(), }, } diff --git a/contracts/my-adapter/src/bin/publish.rs b/contracts/interchain-gov/src/bin/publish.rs similarity index 88% rename from contracts/my-adapter/src/bin/publish.rs rename to contracts/interchain-gov/src/bin/publish.rs index 43640ab..4ea8fd1 100644 --- a/contracts/my-adapter/src/bin/publish.rs +++ b/contracts/interchain-gov/src/bin/publish.rs @@ -7,8 +7,8 @@ //! ```bash //! $ just publish uni-6 osmo-test-5 //! ``` -use my_adapter::{ - contract::interface::MyAdapterInterface, msg::MyAdapterInstantiateMsg, MY_ADAPTER_ID, +use interchain_gov::{ + contract::interface::InterchainGovInterface, msg::InterchainGovInstantiateMsg, MY_ADAPTER_ID, }; use abstract_adapter::objects::namespace::Namespace; @@ -41,8 +41,8 @@ fn publish(networks: Vec) -> anyhow::Result<()> { } // Publish the Adapter to the Abstract Platform - publisher.publish_adapter::>( - MyAdapterInstantiateMsg {}, + publisher.publish_adapter::>( + InterchainGovInstantiateMsg {}, )?; } Ok(()) diff --git a/contracts/intersync/src/bin/schema.rs b/contracts/interchain-gov/src/bin/schema.rs similarity index 76% rename from contracts/intersync/src/bin/schema.rs rename to contracts/interchain-gov/src/bin/schema.rs index 0dfdf25..1c24047 100644 --- a/contracts/intersync/src/bin/schema.rs +++ b/contracts/interchain-gov/src/bin/schema.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::remove_schemas; -use intersync::contract::Intersync; +use interchain_gov::contract::InterchainGov; use std::env::current_dir; use std::fs::create_dir_all; @@ -10,5 +10,5 @@ fn main() { remove_schemas(&out_dir).unwrap(); #[cfg(feature = "schema")] - Intersync::export_schema(&out_dir); + InterchainGov::export_schema(&out_dir); } diff --git a/contracts/interchain-gov/src/contract.rs b/contracts/interchain-gov/src/contract.rs new file mode 100644 index 0000000..3007056 --- /dev/null +++ b/contracts/interchain-gov/src/contract.rs @@ -0,0 +1,35 @@ +use crate::{ + error::InterchainGovError, + handlers, + msg::{InterchainGovExecuteMsg, InterchainGovInstantiateMsg, InterchainGovQueryMsg}, + ADAPTER_VERSION, MY_ADAPTER_ID, +}; + +use abstract_adapter::AdapterContract; +use cosmwasm_std::Response; + +/// The type of the adapter that is used to build your Adapter and access the Abstract SDK features. +pub type InterchainGov = AdapterContract< + InterchainGovError, + InterchainGovInstantiateMsg, + InterchainGovExecuteMsg, + InterchainGovQueryMsg, +>; +/// The type of the result returned by your Adapter's entry points. +pub type AdapterResult = Result; + +const MY_ADAPTER: InterchainGov = InterchainGov::new(MY_ADAPTER_ID, ADAPTER_VERSION, None) + .with_instantiate(handlers::instantiate_handler) + .with_execute(handlers::execute_handler) + .with_query(handlers::query_handler); + +// Export handlers +#[cfg(feature = "export")] +abstract_adapter::export_endpoints!(MY_ADAPTER, InterchainGov); + +abstract_adapter::cw_orch_interface!( + MY_ADAPTER, + InterchainGov, + InterchainGovInstantiateMsg, + InterchainGovInterface +); diff --git a/contracts/my-adapter/src/error.rs b/contracts/interchain-gov/src/error.rs similarity index 95% rename from contracts/my-adapter/src/error.rs rename to contracts/interchain-gov/src/error.rs index fb459fc..5acbf2a 100644 --- a/contracts/my-adapter/src/error.rs +++ b/contracts/interchain-gov/src/error.rs @@ -5,7 +5,7 @@ use cw_controllers::AdminError; use thiserror::Error; #[derive(Error, Debug, PartialEq)] -pub enum MyAdapterError { +pub enum InterchainGovError { #[error("{0}")] Std(#[from] StdError), diff --git a/contracts/my-adapter/src/handlers/execute.rs b/contracts/interchain-gov/src/handlers/execute.rs similarity index 72% rename from contracts/my-adapter/src/handlers/execute.rs rename to contracts/interchain-gov/src/handlers/execute.rs index e57715e..c37b4fc 100644 --- a/contracts/my-adapter/src/handlers/execute.rs +++ b/contracts/interchain-gov/src/handlers/execute.rs @@ -1,8 +1,8 @@ use crate::{ - contract::{AdapterResult, MyAdapter}, - msg::MyAdapterExecuteMsg, + contract::{AdapterResult, InterchainGov}, + msg::InterchainGovExecuteMsg, state::{CONFIG, STATUS}, - MyAdapterError, MY_NAMESPACE, + InterchainGovError, MY_NAMESPACE, }; use abstract_adapter::{ @@ -16,17 +16,17 @@ pub fn execute_handler( deps: DepsMut, _env: Env, info: MessageInfo, - adapter: MyAdapter, - msg: MyAdapterExecuteMsg, + adapter: InterchainGov, + msg: InterchainGovExecuteMsg, ) -> AdapterResult { match msg { - MyAdapterExecuteMsg::UpdateConfig {} => update_config(deps, info, adapter), - MyAdapterExecuteMsg::SetStatus { status } => set_status(deps, adapter, status), + InterchainGovExecuteMsg::UpdateConfig {} => update_config(deps, info, adapter), + InterchainGovExecuteMsg::SetStatus { status } => set_status(deps, adapter, status), } } /// Update the configuration of the adapter -fn update_config(deps: DepsMut, _msg_info: MessageInfo, adapter: MyAdapter) -> AdapterResult { +fn update_config(deps: DepsMut, _msg_info: MessageInfo, adapter: InterchainGov) -> AdapterResult { // Only admin(namespace owner) can change recipient address let namespace = adapter .module_registry(deps.as_ref())? @@ -37,14 +37,14 @@ fn update_config(deps: DepsMut, _msg_info: MessageInfo, adapter: MyAdapter) -> A ensure_eq!( namespace_info.account_base, adapter.target_account.clone().unwrap(), - MyAdapterError::Unauthorized {} + InterchainGovError::Unauthorized {} ); let mut _config = CONFIG.load(deps.storage)?; Ok(adapter.response("update_config")) } -fn set_status(deps: DepsMut, adapter: MyAdapter, status: String) -> AdapterResult { +fn set_status(deps: DepsMut, adapter: InterchainGov, status: String) -> AdapterResult { let account_registry = adapter.account_registry(deps.as_ref())?; let account_id = account_registry.account_id(adapter.target()?)?; diff --git a/contracts/my-adapter/src/handlers/instantiate.rs b/contracts/interchain-gov/src/handlers/instantiate.rs similarity index 70% rename from contracts/my-adapter/src/handlers/instantiate.rs rename to contracts/interchain-gov/src/handlers/instantiate.rs index 41c8586..307554e 100644 --- a/contracts/my-adapter/src/handlers/instantiate.rs +++ b/contracts/interchain-gov/src/handlers/instantiate.rs @@ -1,6 +1,6 @@ use crate::{ - contract::{AdapterResult, MyAdapter}, - msg::MyAdapterInstantiateMsg, + contract::{AdapterResult, InterchainGov}, + msg::InterchainGovInstantiateMsg, state::{Config, CONFIG}, }; @@ -10,8 +10,8 @@ pub fn instantiate_handler( deps: DepsMut, _env: Env, _info: MessageInfo, - _adapter: MyAdapter, - _msg: MyAdapterInstantiateMsg, + _adapter: InterchainGov, + _msg: InterchainGovInstantiateMsg, ) -> AdapterResult { let config: Config = Config {}; diff --git a/contracts/my-adapter/src/handlers/mod.rs b/contracts/interchain-gov/src/handlers/mod.rs similarity index 100% rename from contracts/my-adapter/src/handlers/mod.rs rename to contracts/interchain-gov/src/handlers/mod.rs diff --git a/contracts/my-adapter/src/handlers/query.rs b/contracts/interchain-gov/src/handlers/query.rs similarity index 68% rename from contracts/my-adapter/src/handlers/query.rs rename to contracts/interchain-gov/src/handlers/query.rs index 2bb6cb6..4e4c164 100644 --- a/contracts/my-adapter/src/handlers/query.rs +++ b/contracts/interchain-gov/src/handlers/query.rs @@ -1,6 +1,6 @@ use crate::{ - contract::{AdapterResult, MyAdapter}, - msg::{ConfigResponse, MyAdapterQueryMsg, StatusResponse}, + contract::{AdapterResult, InterchainGov}, + msg::{ConfigResponse, InterchainGovQueryMsg, StatusResponse}, state::{CONFIG, STATUS}, }; @@ -10,12 +10,12 @@ use cosmwasm_std::{to_json_binary, Binary, Deps, Env, StdResult}; pub fn query_handler( deps: Deps, _env: Env, - _adapter: &MyAdapter, - msg: MyAdapterQueryMsg, + _adapter: &InterchainGov, + msg: InterchainGovQueryMsg, ) -> AdapterResult { match msg { - MyAdapterQueryMsg::Config {} => to_json_binary(&query_config(deps)?), - MyAdapterQueryMsg::Status { account_id } => { + InterchainGovQueryMsg::Config {} => to_json_binary(&query_config(deps)?), + InterchainGovQueryMsg::Status { account_id } => { to_json_binary(&query_status(deps, account_id)?) } } diff --git a/contracts/my-adapter/src/lib.rs b/contracts/interchain-gov/src/lib.rs similarity index 60% rename from contracts/my-adapter/src/lib.rs rename to contracts/interchain-gov/src/lib.rs index d0b1e73..bf5e57b 100644 --- a/contracts/my-adapter/src/lib.rs +++ b/contracts/interchain-gov/src/lib.rs @@ -5,13 +5,13 @@ mod handlers; pub mod msg; pub mod state; -pub use contract::interface::MyAdapterInterface; -pub use error::MyAdapterError; -pub use msg::{MyAdapterExecuteMsg, MyAdapterInstantiateMsg}; +pub use contract::interface::InterchainGovInterface; +pub use error::InterchainGovError; +pub use msg::{InterchainGovExecuteMsg, InterchainGovInstantiateMsg}; /// The version of your Adapter pub const ADAPTER_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const MY_NAMESPACE: &str = "yournamespace"; -pub const MY_ADAPTER_NAME: &str = "my-adapter"; +pub const MY_ADAPTER_NAME: &str = "interchain-gov"; pub const MY_ADAPTER_ID: &str = const_format::formatcp!("{MY_NAMESPACE}:{MY_ADAPTER_NAME}"); diff --git a/contracts/intersync/src/msg.rs b/contracts/interchain-gov/src/msg.rs similarity index 67% rename from contracts/intersync/src/msg.rs rename to contracts/interchain-gov/src/msg.rs index 1210b4a..d9b3902 100644 --- a/contracts/intersync/src/msg.rs +++ b/contracts/interchain-gov/src/msg.rs @@ -1,13 +1,15 @@ -use crate::contract::Intersync; +use crate::contract::InterchainGov; +use abstract_adapter::objects::AccountId; use cosmwasm_schema::QueryResponses; // This is used for type safety and re-exporting the contract endpoint structs. -abstract_app::app_msg_types!(Intersync, IntersyncExecuteMsg, IntersyncQueryMsg); +abstract_adapter::adapter_msg_types!(InterchainGov, InterchainGovExecuteMsg, InterchainGovQueryMsg); +use crate::{state::Proposal}; /// App instantiate message #[cosmwasm_schema::cw_serde] -pub struct IntersyncInstantiateMsg { +pub struct InterchainGovInstantiateMsg { pub count: i32, } @@ -15,29 +17,30 @@ pub struct IntersyncInstantiateMsg { #[cosmwasm_schema::cw_serde] #[derive(cw_orch::ExecuteFns)] #[impl_into(ExecuteMsg)] -pub enum IntersyncExecuteMsg { +pub enum InterchainGovExecuteMsg { /// Called by gov when a chain wants to create a proposal CreateProposal { - + proposal: Proposal, }, /// Can be called by any chain to trigger tallying TallyProposal { - + prop_hash: String, }, ///Called by gov to vote on a proposal VoteProposal { - + prop_hash: String, + vote: bool, } } #[cosmwasm_schema::cw_serde] -pub struct IntersyncMigrateMsg {} +pub struct InterchainGovMigrateMsg {} /// App query messages #[cosmwasm_schema::cw_serde] #[derive(QueryResponses, cw_orch::QueryFns)] #[impl_into(QueryMsg)] -pub enum IntersyncQueryMsg { +pub enum InterchainGovQueryMsg { #[returns(ConfigResponse)] Config {}, #[returns(CountResponse)] diff --git a/contracts/intersync/src/state.rs b/contracts/interchain-gov/src/state.rs similarity index 53% rename from contracts/intersync/src/state.rs rename to contracts/interchain-gov/src/state.rs index bc9ba78..a84771b 100644 --- a/contracts/intersync/src/state.rs +++ b/contracts/interchain-gov/src/state.rs @@ -1,8 +1,9 @@ +use abstract_adapter::objects::chain_name::ChainName; use cosmwasm_schema::cw_serde; use cosmwasm_std::{Binary, CosmosMsg, Empty, Uint128}; use cw_storage_plus::{Item, Map}; use cw_utils::Expiration; -use dao_voting::{threshold::Threshold, voting::Votes}; +use dao_voting::{status::Status, threshold::Threshold, voting::Votes}; #[cosmwasm_schema::cw_serde] pub struct Config {} @@ -10,19 +11,21 @@ pub struct Config {} pub const CONFIG: Item = Item::new("config"); pub const COUNT: Item = Item::new("count"); -pub const DATA: Map = Map::new("gov_data"); -pub const ITEM: Item = Item::new("members"); +pub const PROPS: Map = Map::new("props"); +pub const MEMBERS: Item = Item::new("members"); +pub const LOCAL_VOTE: Item = Item::new("local_vote"); +/// Different statuses for a data item #[cw_serde] -pub enum Status { +pub enum DataStatus { Initiate = 0, - Stable = 1, - Locked = 2, + Proposed = 1, + Finalized = 2, } #[cw_serde] pub struct Members { - pub status: Status, + pub status: DataStatus, pub members: Vec, } @@ -35,10 +38,8 @@ pub struct Proposal { pub description: String, /// The address that created this proposal. pub proposer: String, - /// The block height at which this proposal was created. Voting - /// power queries should query for voting power at this block - /// height. - pub start_height: u64, + /// The chain that created this proposal + pub proposer_chain: ChainName, /// The minimum amount of time this proposal must remain open for /// voting. The proposal may not pass unless this is expired or /// None. @@ -46,18 +47,6 @@ pub struct Proposal { /// The the time at which this proposal will expire and close for /// additional votes. pub expiration: Expiration, - /// The threshold at which this proposal will pass. - pub threshold: Threshold, - /// The total amount of voting power at the time of this - /// proposal's creation. - pub total_power: Uint128, - /// The messages that will be executed should this proposal pass. - pub msgs: Vec>, /// The proposal status pub status: Status, - /// Votes on a particular proposal - pub votes: Votes, - /// Whether or not revoting is enabled. If revoting is enabled, a proposal - /// cannot pass until the voting period has elapsed. - pub allow_revoting: bool, } diff --git a/contracts/my-adapter/tests/integration.rs b/contracts/interchain-gov/tests/integration.rs similarity index 80% rename from contracts/my-adapter/tests/integration.rs rename to contracts/interchain-gov/tests/integration.rs index b8fe658..b513b61 100644 --- a/contracts/my-adapter/tests/integration.rs +++ b/contracts/interchain-gov/tests/integration.rs @@ -1,7 +1,7 @@ -use my_adapter::{ - contract::interface::MyAdapterInterface, - msg::{ConfigResponse, ExecuteMsg, MyAdapterInstantiateMsg, MyAdapterQueryMsgFns}, - MyAdapterExecuteMsg, MY_ADAPTER_ID, MY_NAMESPACE, +use interchain_gov::{ + contract::interface::InterchainGovInterface, + msg::{ConfigResponse, ExecuteMsg, InterchainGovInstantiateMsg, InterchainGovQueryMsgFns}, + InterchainGovExecuteMsg, MY_ADAPTER_ID, MY_NAMESPACE, }; use abstract_adapter::std::{adapter::AdapterRequestMsg, objects::namespace::Namespace}; @@ -13,7 +13,7 @@ use cw_orch::{anyhow, prelude::*}; struct TestEnv { publisher: Publisher, abs: AbstractClient, - adapter: Application>, + adapter: Application>, } impl TestEnv { @@ -32,13 +32,13 @@ impl TestEnv { // Publish the adapter let publisher = abs_client.publisher_builder(namespace).build()?; - publisher.publish_adapter::>( - MyAdapterInstantiateMsg {}, + publisher.publish_adapter::>( + InterchainGovInstantiateMsg {}, )?; let adapter = publisher .account() - .install_adapter::>(&[])?; + .install_adapter::>(&[])?; Ok(TestEnv { abs: abs_client, @@ -73,14 +73,14 @@ fn update_config() -> anyhow::Result<()> { adapter.execute( &AdapterRequestMsg { proxy_address: Some(publisher_account.account().proxy()?.to_string()), - request: MyAdapterExecuteMsg::UpdateConfig {}, + request: InterchainGovExecuteMsg::UpdateConfig {}, } .into(), None, )?; let config = adapter.config()?; - let expected_response = my_adapter::msg::ConfigResponse {}; + let expected_response = interchain_gov::msg::ConfigResponse {}; assert_eq!(config, expected_response); // Adapter installed on sub-account of the publisher so this should error @@ -88,7 +88,7 @@ fn update_config() -> anyhow::Result<()> { .execute( &AdapterRequestMsg { proxy_address: Some(adapter.account().proxy()?.to_string()), - request: MyAdapterExecuteMsg::UpdateConfig {}, + request: InterchainGovExecuteMsg::UpdateConfig {}, } .into(), None, @@ -113,7 +113,7 @@ fn set_status() -> anyhow::Result<()> { MY_ADAPTER_ID, ExecuteMsg::Module(AdapterRequestMsg { proxy_address: Some(subaccount.proxy()?.to_string()), - request: MyAdapterExecuteMsg::SetStatus { + request: InterchainGovExecuteMsg::SetStatus { status: first_status.clone(), }, }), @@ -122,14 +122,14 @@ fn set_status() -> anyhow::Result<()> { let new_account = env .abs .account_builder() - .install_adapter::>()? + .install_adapter::>()? .build()?; new_account.as_ref().manager.execute_on_module( MY_ADAPTER_ID, ExecuteMsg::Module(AdapterRequestMsg { proxy_address: Some(new_account.proxy()?.to_string()), - request: MyAdapterExecuteMsg::SetStatus { + request: InterchainGovExecuteMsg::SetStatus { status: second_status.clone(), }, }), diff --git a/contracts/intersync/Cargo.toml b/contracts/intersync/Cargo.toml deleted file mode 100644 index bce06cf..0000000 --- a/contracts/intersync/Cargo.toml +++ /dev/null @@ -1,74 +0,0 @@ -[package] -name = "intersync" -version = "0.0.1" -authors = [ - "CyberHoward ", - "Adair ", - "Abstract Money ", -] -edition = "2021" -homepage = "" -documentation = "" -repository = "" -license = "GPL-3.0-or-later" -keywords = ["cosmos", "cosmwasm", "abstractsdk"] -resolver = "2" - -exclude = ["contract.wasm", "hash.txt"] - -[lib] -crate-type = ["cdylib", "rlib"] - -[[bin]] -name = "schema" -required-features = ["schema"] - -[[bin]] -name = "publish" -required-features = ["daemon-bin"] - -[[bin]] -name = "local_daemon" -required-features = ["daemon-bin"] - -[features] -default = ["export"] -export = [] -daemon-bin = [ - "cw-orch/daemon", - "dep:clap", - "dep:abstract-client", - "dep:dotenv", - "dep:env_logger", -] -schema = ["abstract-app/schema"] - -[dependencies] -cosmwasm-std = { workspace = true } -cosmwasm-schema = { workspace = true } -cw-controllers = { workspace = true } -cw-storage-plus = { workspace = true } -thiserror = { workspace = true } -schemars = { workspace = true } -cw-asset = { workspace = true } -abstract-app = { workspace = true } -const_format = { workspace = true } -serde = "1" -cw-utils = "1.0.3" -dao-voting = "2.3.0" - - -# Dependencies for interface -cw-orch = { workspace = true } -abstract-interface = { workspace = true } - -# Dependencies for bins -clap = { workspace = true, optional = true, features = ["derive"] } -abstract-client = { workspace = true, optional = true } -dotenv = { workspace = true, optional = true } -env_logger = { workspace = true, optional = true } - -[dev-dependencies] -intersync = { workspace = true } -abstract-client = { workspace = true } -abstract-app = { workspace = true, features = ["test-utils"] } diff --git a/contracts/intersync/metadata.json b/contracts/intersync/metadata.json deleted file mode 100644 index 2c8439a..0000000 --- a/contracts/intersync/metadata.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "App", - "description": "App description.", - "website": "", - "docs": "", - "type": "app", - "icon": "GiTrade", - "enabled": true -} diff --git a/contracts/intersync/src/bin/local_daemon.rs b/contracts/intersync/src/bin/local_daemon.rs deleted file mode 100644 index 320a988..0000000 --- a/contracts/intersync/src/bin/local_daemon.rs +++ /dev/null @@ -1,70 +0,0 @@ -//! Deploys Abstract and the App module to a local Junod instance. See how to spin up a local chain here: -//! You can also start a juno container by running `just juno-local`. -//! -//! Ensure the local juno is running before executing this script. -//! Also make sure port 9090 is exposed on the local juno container. This port is used to communicate with the chain. -//! -//! # Run -//! -//! `RUST_LOG=info cargo run --bin --features="daemon-bin" local_daemon --package intersync` -use intersync::MY_APP_ID; - -use abstract_app::objects::namespace::Namespace; -use abstract_client::{AbstractClient, Publisher}; -use cw_orch::{anyhow, prelude::*, tokio::runtime::Runtime}; -use intersync::{msg::IntersyncInstantiateMsg, IntersyncInterface}; - -const LOCAL_MNEMONIC: &str = "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose"; - -fn main() -> anyhow::Result<()> { - dotenv::dotenv().ok(); - env_logger::init(); - - let runtime = Runtime::new()?; - - let daemon = Daemon::builder() - .chain(networks::LOCAL_JUNO) - .mnemonic(LOCAL_MNEMONIC) - .handle(runtime.handle()) - .build() - .unwrap(); - - let app_namespace = Namespace::from_id(MY_APP_ID)?; - - // Create an [`AbstractClient`] - // Note: AbstractClient Builder used because Abstract is not yet deployed on the chain - let abstract_client: AbstractClient = - AbstractClient::builder(daemon.clone()).build()?; - - // Get the [`Publisher`] that owns the namespace. - // If there isn't one, it creates an Account and claims the namespace. - let publisher: Publisher<_> = abstract_client.publisher_builder(app_namespace).build()?; - - // Ensure the current sender owns the namespace - if publisher.account().owner()? != daemon.sender() { - panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.") - } - - // Publish the App to the Abstract Platform - publisher.publish_app::>()?; - - // Install the App on a new account - - let account = abstract_client.account_builder().build()?; - // Installs the app on the Account - let app = account.install_app::>(&IntersyncInstantiateMsg { count: 0 }, &[])?; - - // Import app's endpoint function traits for easy interactions. - use intersync::msg::{IntersyncExecuteMsgFns, IntersyncQueryMsgFns}; - assert_eq!(app.count()?.count, 0); - // Execute the App - app.increment()?; - - // Query the App again - assert_eq!(app.count()?.count, 1); - - // Note: the App is installed on a sub-account of the main account! - assert_ne!(account.id()?, app.account().id()?); - - Ok(()) -} diff --git a/contracts/intersync/src/bin/publish.rs b/contracts/intersync/src/bin/publish.rs deleted file mode 100644 index 4e8965f..0000000 --- a/contracts/intersync/src/bin/publish.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! Publishes the module to the Abstract platform by uploading it and registering it on the app store. -//! -//! Info: The mnemonic used to register the module must be the same as the owner of the account that claimed the namespace. -//! -//! ## Example -//! -//! ```bash -//! $ just publish uni-6 osmo-test-5 -//! ``` -use intersync::MY_APP_ID; - -use abstract_app::objects::namespace::Namespace; -use abstract_client::{AbstractClient, Publisher}; -use clap::Parser; -use cw_orch::{anyhow, daemon::networks::parse_network, prelude::*, tokio::runtime::Runtime}; -use intersync::IntersyncInterface; - -fn publish(networks: Vec) -> anyhow::Result<()> { - // run for each requested network - for network in networks { - // Setup - let rt = Runtime::new()?; - let chain = DaemonBuilder::default() - .handle(rt.handle()) - .chain(network) - .build()?; - - let app_namespace = Namespace::from_id(MY_APP_ID)?; - - // Create an [`AbstractClient`] - let abstract_client: AbstractClient = AbstractClient::new(chain.clone())?; - - // Get the [`Publisher`] that owns the namespace, otherwise create a new one and claim the namespace - let publisher: Publisher<_> = abstract_client.publisher_builder(app_namespace).build()?; - - if publisher.account().owner()? != chain.sender() { - panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.") - } - - // Publish the App to the Abstract Platform - publisher.publish_app::>()?; - } - Ok(()) -} - -#[derive(Parser, Default, Debug)] -#[command(author, version, about, long_about = None)] -struct Arguments { - /// Network Id to publish on - #[arg(short, long, value_delimiter = ' ', num_args = 1..)] - network_ids: Vec, -} - -fn main() { - dotenv::dotenv().ok(); - env_logger::init(); - let args = Arguments::parse(); - let networks = args - .network_ids - .iter() - .map(|n| parse_network(n).unwrap()) - .collect(); - publish(networks).unwrap(); -} diff --git a/contracts/intersync/src/contract.rs b/contracts/intersync/src/contract.rs deleted file mode 100644 index 96dff1e..0000000 --- a/contracts/intersync/src/contract.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::{ - error::IntersyncError, - handlers, - msg::{IntersyncExecuteMsg, IntersyncInstantiateMsg, IntersyncMigrateMsg, IntersyncQueryMsg}, - replies::{self, INSTANTIATE_REPLY_ID}, - APP_VERSION, MY_APP_ID, -}; - -use abstract_app::AppContract; -use cosmwasm_std::Response; - -/// The type of the result returned by your app's entry points. -pub type IntersyncResult = Result; - -/// The type of the app that is used to build your app and access the Abstract SDK features. -pub type Intersync = - AppContract; - -const APP: Intersync = Intersync::new(MY_APP_ID, APP_VERSION, None) - .with_instantiate(handlers::instantiate_handler) - .with_execute(handlers::execute_handler) - .with_query(handlers::query_handler) - .with_migrate(handlers::migrate_handler) - .with_dependencies(&[]) - .with_replies(&[(INSTANTIATE_REPLY_ID, replies::instantiate_reply)]); - -// Export handlers -#[cfg(feature = "export")] -abstract_app::export_endpoints!(APP, Intersync); - -abstract_app::cw_orch_interface!(APP, Intersync, IntersyncInterface); - -// TODO: add to docmuentation -// https://linear.app/abstract-sdk/issue/ABS-414/add-documentation-on-dependencycreation-trait -#[cfg(not(target_arch = "wasm32"))] -impl abstract_interface::DependencyCreation - for crate::IntersyncInterface -{ - type DependenciesConfig = cosmwasm_std::Empty; -} diff --git a/contracts/intersync/src/data.rs b/contracts/intersync/src/data.rs deleted file mode 100644 index 839f645..0000000 --- a/contracts/intersync/src/data.rs +++ /dev/null @@ -1,10 +0,0 @@ -use serde::{Serialize, Deserialize}; - -#[derive(Serialize, Deserialize)] -pub struct Data { - name: String, - - age: i64, - - sex: String, -} diff --git a/contracts/intersync/src/error.rs b/contracts/intersync/src/error.rs deleted file mode 100644 index 95775e8..0000000 --- a/contracts/intersync/src/error.rs +++ /dev/null @@ -1,28 +0,0 @@ -use abstract_app::sdk::AbstractSdkError; -use abstract_app::std::AbstractError; -use abstract_app::AppError; -use cosmwasm_std::StdError; -use cw_asset::AssetError; -use cw_controllers::AdminError; -use thiserror::Error; - -#[derive(Error, Debug, PartialEq)] -pub enum IntersyncError { - #[error("{0}")] - Std(#[from] StdError), - - #[error("{0}")] - Abstract(#[from] AbstractError), - - #[error("{0}")] - AbstractSdk(#[from] AbstractSdkError), - - #[error("{0}")] - Asset(#[from] AssetError), - - #[error("{0}")] - Admin(#[from] AdminError), - - #[error("{0}")] - DappError(#[from] AppError), -} diff --git a/contracts/intersync/src/handlers/execute.rs b/contracts/intersync/src/handlers/execute.rs deleted file mode 100644 index 342f09a..0000000 --- a/contracts/intersync/src/handlers/execute.rs +++ /dev/null @@ -1,44 +0,0 @@ -use crate::{ - contract::{Intersync, IntersyncResult}, - msg::IntersyncExecuteMsg, - state::{CONFIG, COUNT}, -}; - -use abstract_app::traits::AbstractResponse; -use cosmwasm_std::{DepsMut, Env, MessageInfo}; - -pub fn execute_handler( - deps: DepsMut, - _env: Env, - info: MessageInfo, - app: Intersync, - msg: IntersyncExecuteMsg, -) -> IntersyncResult { - match msg { - IntersyncExecuteMsg::UpdateConfig {} => update_config(deps, info, app), - IntersyncExecuteMsg::Increment {} => increment(deps, app), - IntersyncExecuteMsg::Reset { count } => reset(deps, info, count, app), - } -} - -/// Update the configuration of the app -fn update_config(deps: DepsMut, msg_info: MessageInfo, app: Intersync) -> IntersyncResult { - // Only the admin should be able to call this - app.admin.assert_admin(deps.as_ref(), &msg_info.sender)?; - let mut _config = CONFIG.load(deps.storage)?; - - Ok(app.response("update_config")) -} - -fn increment(deps: DepsMut, app: Intersync) -> IntersyncResult { - COUNT.update(deps.storage, |count| IntersyncResult::Ok(count + 1))?; - - Ok(app.response("increment")) -} - -fn reset(deps: DepsMut, info: MessageInfo, count: i32, app: Intersync) -> IntersyncResult { - app.admin.assert_admin(deps.as_ref(), &info.sender)?; - COUNT.save(deps.storage, &count)?; - - Ok(app.response("reset")) -} diff --git a/contracts/intersync/src/handlers/instantiate.rs b/contracts/intersync/src/handlers/instantiate.rs deleted file mode 100644 index dbe2646..0000000 --- a/contracts/intersync/src/handlers/instantiate.rs +++ /dev/null @@ -1,21 +0,0 @@ -use crate::{ - contract::{Intersync, IntersyncResult}, - msg::IntersyncInstantiateMsg, - state::{Config, CONFIG, COUNT}, -}; - -use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; - -pub fn instantiate_handler( - deps: DepsMut, - _env: Env, - _info: MessageInfo, - _app: Intersync, - msg: IntersyncInstantiateMsg, -) -> IntersyncResult { - let config: Config = Config {}; - - CONFIG.save(deps.storage, &config)?; - COUNT.save(deps.storage, &msg.count)?; - Ok(Response::new()) -} diff --git a/contracts/intersync/src/handlers/migrate.rs b/contracts/intersync/src/handlers/migrate.rs deleted file mode 100644 index ecf9d41..0000000 --- a/contracts/intersync/src/handlers/migrate.rs +++ /dev/null @@ -1,18 +0,0 @@ -use crate::{ - contract::{Intersync, IntersyncResult}, - msg::IntersyncMigrateMsg, -}; - -use abstract_app::traits::AbstractResponse; -use cosmwasm_std::{DepsMut, Env}; - -/// Handle the app migrate msg -/// The top-level Abstract app does version checking and dispatches to this handler -pub fn migrate_handler( - _deps: DepsMut, - _env: Env, - app: Intersync, - _msg: IntersyncMigrateMsg, -) -> IntersyncResult { - Ok(app.response("migrate")) -} diff --git a/contracts/intersync/src/handlers/mod.rs b/contracts/intersync/src/handlers/mod.rs deleted file mode 100644 index 2a61823..0000000 --- a/contracts/intersync/src/handlers/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod execute; -pub mod instantiate; -pub mod migrate; -pub mod query; - -pub use self::{ - execute::execute_handler, instantiate::instantiate_handler, migrate::migrate_handler, - query::query_handler, -}; diff --git a/contracts/intersync/src/handlers/query.rs b/contracts/intersync/src/handlers/query.rs deleted file mode 100644 index 905cf3f..0000000 --- a/contracts/intersync/src/handlers/query.rs +++ /dev/null @@ -1,30 +0,0 @@ -use crate::{ - contract::{Intersync, IntersyncResult}, - msg::{ConfigResponse, CountResponse, IntersyncQueryMsg}, - state::{CONFIG, COUNT}, -}; - -use cosmwasm_std::{to_json_binary, Binary, Deps, Env, StdResult}; - -pub fn query_handler( - deps: Deps, - _env: Env, - _app: &Intersync, - msg: IntersyncQueryMsg, -) -> IntersyncResult { - match msg { - IntersyncQueryMsg::Config {} => to_json_binary(&query_config(deps)?), - IntersyncQueryMsg::Count {} => to_json_binary(&query_count(deps)?), - } - .map_err(Into::into) -} - -fn query_config(deps: Deps) -> StdResult { - let _config = CONFIG.load(deps.storage)?; - Ok(ConfigResponse {}) -} - -fn query_count(deps: Deps) -> StdResult { - let count = COUNT.load(deps.storage)?; - Ok(CountResponse { count }) -} diff --git a/contracts/intersync/src/lib.rs b/contracts/intersync/src/lib.rs deleted file mode 100644 index 23e65bd..0000000 --- a/contracts/intersync/src/lib.rs +++ /dev/null @@ -1,18 +0,0 @@ -pub mod contract; -pub mod error; -mod handlers; -pub mod msg; -mod replies; -pub mod state; -mod data; - -pub use error::IntersyncError; - -/// The version of your app -pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); - -pub use contract::interface::IntersyncInterface; - -pub const MY_NAMESPACE: &str = "yournamespace"; -pub const MY_APP_NAME: &str = "intersync"; -pub const MY_APP_ID: &str = const_format::formatcp!("{MY_NAMESPACE}:{MY_APP_NAME}"); diff --git a/contracts/intersync/src/replies/instantiate.rs b/contracts/intersync/src/replies/instantiate.rs deleted file mode 100644 index 9442c1a..0000000 --- a/contracts/intersync/src/replies/instantiate.rs +++ /dev/null @@ -1,8 +0,0 @@ -use crate::contract::{Intersync, IntersyncResult}; - -use abstract_app::traits::AbstractResponse; -use cosmwasm_std::{DepsMut, Env, Reply}; - -pub fn instantiate_reply(_deps: DepsMut, _env: Env, app: Intersync, _reply: Reply) -> IntersyncResult { - Ok(app.response("instantiate_reply")) -} diff --git a/contracts/intersync/src/replies/mod.rs b/contracts/intersync/src/replies/mod.rs deleted file mode 100644 index cb1c54f..0000000 --- a/contracts/intersync/src/replies/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod instantiate; - -pub use instantiate::instantiate_reply; - -pub const INSTANTIATE_REPLY_ID: u64 = 1u64; diff --git a/contracts/intersync/tests/integration.rs b/contracts/intersync/tests/integration.rs deleted file mode 100644 index 092d6a7..0000000 --- a/contracts/intersync/tests/integration.rs +++ /dev/null @@ -1,127 +0,0 @@ -use intersync::{ - contract::interface::IntersyncInterface, - msg::{ - ConfigResponse, CountResponse, IntersyncExecuteMsgFns, IntersyncInstantiateMsg, IntersyncQueryMsgFns, - }, - IntersyncError, MY_NAMESPACE, -}; - -use abstract_app::objects::namespace::Namespace; -use abstract_client::{AbstractClient, Application, Environment}; -use cosmwasm_std::coins; -use cw_controllers::AdminError; -// Use prelude to get all the necessary imports -use cw_orch::{anyhow, prelude::*}; - -struct TestEnv { - abs: AbstractClient, - app: Application>, -} - -impl TestEnv { - /// Set up the test environment with an Account that has the App installed - fn setup() -> anyhow::Result> { - // Create a sender and mock env - let mock = MockBech32::new("mock"); - let sender = mock.sender(); - let namespace = Namespace::new(MY_NAMESPACE)?; - - // You can set up Abstract with a builder. - let abs_client = AbstractClient::builder(mock).build()?; - // The app supports setting balances for addresses and configuring ANS. - abs_client.set_balance(sender, &coins(123, "ucosm"))?; - - // Publish the app - let publisher = abs_client.publisher_builder(namespace).build()?; - publisher.publish_app::>()?; - - let app = publisher - .account() - .install_app::>(&IntersyncInstantiateMsg { count: 0 }, &[])?; - - Ok(TestEnv { - abs: abs_client, - app, - }) - } -} - -#[test] -fn successful_install() -> anyhow::Result<()> { - let env = TestEnv::setup()?; - let app = env.app; - - let config = app.config()?; - assert_eq!(config, ConfigResponse {}); - Ok(()) -} - -#[test] -fn successful_increment() -> anyhow::Result<()> { - let env = TestEnv::setup()?; - let app = env.app; - - app.increment()?; - let count: CountResponse = app.count()?; - assert_eq!(count.count, 1); - Ok(()) -} - -#[test] -fn successful_reset() -> anyhow::Result<()> { - let env = TestEnv::setup()?; - let app = env.app; - - app.reset(42)?; - let count: CountResponse = app.count()?; - assert_eq!(count.count, 42); - Ok(()) -} - -#[test] -fn failed_reset() -> anyhow::Result<()> { - let env = TestEnv::setup()?; - let app = env.app; - - let err: IntersyncError = app - .call_as(&Addr::unchecked("NotAdmin")) - .reset(9) - .unwrap_err() - .downcast() - .unwrap(); - assert_eq!(err, IntersyncError::Admin(AdminError::NotAdmin {})); - Ok(()) -} - -#[test] -fn update_config() -> anyhow::Result<()> { - let env = TestEnv::setup()?; - let app = env.app; - - app.update_config()?; - let config = app.config()?; - let expected_response = intersync::msg::ConfigResponse {}; - assert_eq!(config, expected_response); - Ok(()) -} - -#[test] -fn balance_added() -> anyhow::Result<()> { - let env = TestEnv::setup()?; - let account = env.app.account(); - - // You can add balance to your account in test environment - let add_balance = coins(100, "ucosm"); - account.add_balance(&add_balance)?; - let balances = account.query_balances()?; - - assert_eq!(balances, add_balance); - - // Or set balance to any other address using cw_orch - let mock_env = env.abs.environment(); - mock_env.add_balance(&env.app.address()?, add_balance.clone())?; - let balances = mock_env.query_all_balances(&env.app.address()?)?; - - assert_eq!(balances, add_balance); - Ok(()) -} diff --git a/contracts/my-adapter/src/bin/schema.rs b/contracts/my-adapter/src/bin/schema.rs deleted file mode 100644 index e815a1b..0000000 --- a/contracts/my-adapter/src/bin/schema.rs +++ /dev/null @@ -1,14 +0,0 @@ -use cosmwasm_schema::remove_schemas; -use my_adapter::contract::MyAdapter; -use std::env::current_dir; -use std::fs::create_dir_all; - -fn main() { - let mut out_dir = current_dir().unwrap(); - out_dir.push("schema"); - create_dir_all(&out_dir).unwrap(); - remove_schemas(&out_dir).unwrap(); - - #[cfg(feature = "schema")] - MyAdapter::export_schema(&out_dir); -} diff --git a/contracts/my-adapter/src/contract.rs b/contracts/my-adapter/src/contract.rs deleted file mode 100644 index 208688f..0000000 --- a/contracts/my-adapter/src/contract.rs +++ /dev/null @@ -1,35 +0,0 @@ -use crate::{ - error::MyAdapterError, - handlers, - msg::{MyAdapterExecuteMsg, MyAdapterInstantiateMsg, MyAdapterQueryMsg}, - ADAPTER_VERSION, MY_ADAPTER_ID, -}; - -use abstract_adapter::AdapterContract; -use cosmwasm_std::Response; - -/// The type of the adapter that is used to build your Adapter and access the Abstract SDK features. -pub type MyAdapter = AdapterContract< - MyAdapterError, - MyAdapterInstantiateMsg, - MyAdapterExecuteMsg, - MyAdapterQueryMsg, ->; -/// The type of the result returned by your Adapter's entry points. -pub type AdapterResult = Result; - -const MY_ADAPTER: MyAdapter = MyAdapter::new(MY_ADAPTER_ID, ADAPTER_VERSION, None) - .with_instantiate(handlers::instantiate_handler) - .with_execute(handlers::execute_handler) - .with_query(handlers::query_handler); - -// Export handlers -#[cfg(feature = "export")] -abstract_adapter::export_endpoints!(MY_ADAPTER, MyAdapter); - -abstract_adapter::cw_orch_interface!( - MY_ADAPTER, - MyAdapter, - MyAdapterInstantiateMsg, - MyAdapterInterface -); diff --git a/contracts/my-adapter/src/msg.rs b/contracts/my-adapter/src/msg.rs deleted file mode 100644 index a753d3b..0000000 --- a/contracts/my-adapter/src/msg.rs +++ /dev/null @@ -1,39 +0,0 @@ -use crate::contract::MyAdapter; - -use abstract_adapter::objects::AccountId; -use cosmwasm_schema::QueryResponses; - -// This is used for type safety and re-exporting the contract endpoint structs. -abstract_adapter::adapter_msg_types!(MyAdapter, MyAdapterExecuteMsg, MyAdapterQueryMsg); - -/// Adapter instantiate message -#[cosmwasm_schema::cw_serde] -pub struct MyAdapterInstantiateMsg {} - -/// Adapter execute messages -#[cosmwasm_schema::cw_serde] -pub enum MyAdapterExecuteMsg { - /// Set status of your account - SetStatus { status: String }, - /// Admin method: Update the configuration of the adapter - UpdateConfig {}, -} - -/// Adapter query messages -#[cosmwasm_schema::cw_serde] -#[derive(QueryResponses, cw_orch::QueryFns)] -#[impl_into(QueryMsg)] -pub enum MyAdapterQueryMsg { - #[returns(StatusResponse)] - Status { account_id: AccountId }, - #[returns(ConfigResponse)] - Config {}, -} - -#[cosmwasm_schema::cw_serde] -pub struct ConfigResponse {} - -#[cosmwasm_schema::cw_serde] -pub struct StatusResponse { - pub status: Option, -} diff --git a/contracts/my-adapter/src/state.rs b/contracts/my-adapter/src/state.rs deleted file mode 100644 index d653bae..0000000 --- a/contracts/my-adapter/src/state.rs +++ /dev/null @@ -1,8 +0,0 @@ -use abstract_adapter::objects::AccountId; -use cw_storage_plus::{Item, Map}; - -#[cosmwasm_schema::cw_serde] -pub struct Config {} - -pub const CONFIG: Item = Item::new("config"); -pub const STATUS: Map<&AccountId, String> = Map::new("status");