Skip to content

Commit

Permalink
move to adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberHoward committed May 28, 2024
1 parent ee5dc2f commit 91ad0d5
Show file tree
Hide file tree
Showing 37 changed files with 131 additions and 777 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "my-adapter"
name = "interchain-gov"
version = "0.0.1"
authors = [
"CyberHoward <cyberhoward@protonmail.com>",
Expand Down Expand Up @@ -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 }
Expand All @@ -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"] }
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
msg::{MyAdapterExecuteMsg, MyAdapterQueryMsg},
msg::{InterchainGovExecuteMsg, InterchainGovQueryMsg},
MY_ADAPTER_ID,
};

Expand All @@ -13,27 +13,27 @@ 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<Self> {
MyAdapter {
fn interchain_gov<'a>(&'a self, deps: Deps<'a>) -> InterchainGov<Self> {
InterchainGov {
base: self,
deps,
module_id: MY_ADAPTER_ID,
}
}
}

impl<T: AccountIdentification + Dependencies + ModuleIdentification> MyAdapterApi for T {}
impl<T: AccountIdentification + Dependencies + ModuleIdentification> 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 }
Expand All @@ -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<CosmosMsg> {
/// Executes a [InterchainGovExecuteMsg] in the adapter
fn request(&self, msg: InterchainGovExecuteMsg) -> AbstractSdkResult<CosmosMsg> {
let adapters = self.base.adapters(self.deps);

adapters.execute(self.module_id(), msg)
}

/// Route message
pub fn update_config(&self) -> AbstractSdkResult<CosmosMsg> {
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<R: DeserializeOwned>(&self, query_msg: MyAdapterQueryMsg) -> AbstractSdkResult<R> {
pub fn query<R: DeserializeOwned>(&self, query_msg: InterchainGovQueryMsg) -> AbstractSdkResult<R> {
let adapters = self.base.adapters(self.deps);
adapters.query(self.module_id(), query_msg)
}

/// Query config
pub fn config(&self) -> AbstractSdkResult<Uint128> {
self.query(MyAdapterQueryMsg::Config {})
self.query(InterchainGovQueryMsg::Config {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -50,18 +50,18 @@ fn main() -> anyhow::Result<()> {
);

// Publish the Adapter to the Abstract Platform
publisher.publish_adapter::<MyAdapterInstantiateMsg, MyAdapterInterface<Daemon>>(
MyAdapterInstantiateMsg {},
publisher.publish_adapter::<InterchainGovInstantiateMsg, InterchainGovInterface<Daemon>>(
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::<MyAdapterInterface<_>>(&[])?;
let adapter = account.install_adapter::<InterchainGovInterface<_>>(&[])?;

// // 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());

Expand All @@ -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(),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,8 +41,8 @@ fn publish(networks: Vec<ChainInfo>) -> anyhow::Result<()> {
}

// Publish the Adapter to the Abstract Platform
publisher.publish_adapter::<MyAdapterInstantiateMsg, MyAdapterInterface<Daemon>>(
MyAdapterInstantiateMsg {},
publisher.publish_adapter::<InterchainGovInstantiateMsg, InterchainGovInterface<Daemon>>(
InterchainGovInstantiateMsg {},
)?;
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand 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);
}
35 changes: 35 additions & 0 deletions contracts/interchain-gov/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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<T = Response> = Result<T, InterchainGovError>;

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
);
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
contract::{AdapterResult, MyAdapter},
msg::MyAdapterExecuteMsg,
contract::{AdapterResult, InterchainGov},
msg::InterchainGovExecuteMsg,
state::{CONFIG, STATUS},

Check failure on line 4 in contracts/interchain-gov/src/handlers/execute.rs

View workflow job for this annotation

GitHub Actions / clippy

unresolved import `crate::state::STATUS`

error[E0432]: unresolved import `crate::state::STATUS` --> contracts/interchain-gov/src/handlers/execute.rs:4:21 | 4 | state::{CONFIG, STATUS}, | ^^^^^^ | | | no `STATUS` in `state` | help: a similar name exists in the module: `Status`
MyAdapterError, MY_NAMESPACE,
InterchainGovError, MY_NAMESPACE,
};

use abstract_adapter::{
Expand All @@ -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),

Check failure on line 23 in contracts/interchain-gov/src/handlers/execute.rs

View workflow job for this annotation

GitHub Actions / clippy

no variant named `UpdateConfig` found for enum `msg::InterchainGovExecuteMsg`

error[E0599]: no variant named `UpdateConfig` found for enum `msg::InterchainGovExecuteMsg` --> contracts/interchain-gov/src/handlers/execute.rs:23:34 | 23 | InterchainGovExecuteMsg::UpdateConfig {} => update_config(deps, info, adapter), | ^^^^^^^^^^^^ variant not found in `msg::InterchainGovExecuteMsg` | ::: contracts/interchain-gov/src/msg.rs:20:1 | 20 | pub enum InterchainGovExecuteMsg { | -------------------------------- variant `UpdateConfig` not found here
InterchainGovExecuteMsg::SetStatus { status } => set_status(deps, adapter, status),

Check failure on line 24 in contracts/interchain-gov/src/handlers/execute.rs

View workflow job for this annotation

GitHub Actions / clippy

no variant named `SetStatus` found for enum `msg::InterchainGovExecuteMsg`

error[E0599]: no variant named `SetStatus` found for enum `msg::InterchainGovExecuteMsg` --> contracts/interchain-gov/src/handlers/execute.rs:24:34 | 24 | InterchainGovExecuteMsg::SetStatus { status } => set_status(deps, adapter, status), | ^^^^^^^^^ variant not found in `msg::InterchainGovExecuteMsg` | ::: contracts/interchain-gov/src/msg.rs:20:1 | 20 | pub enum InterchainGovExecuteMsg { | -------------------------------- variant `SetStatus` not found here
}
}

/// 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())?
Expand All @@ -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()?)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
contract::{AdapterResult, MyAdapter},
msg::MyAdapterInstantiateMsg,
contract::{AdapterResult, InterchainGov},
msg::InterchainGovInstantiateMsg,
state::{Config, CONFIG},
};

Expand All @@ -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 {};

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
contract::{AdapterResult, MyAdapter},
msg::{ConfigResponse, MyAdapterQueryMsg, StatusResponse},
contract::{AdapterResult, InterchainGov},
msg::{ConfigResponse, InterchainGovQueryMsg, StatusResponse},

Check failure on line 3 in contracts/interchain-gov/src/handlers/query.rs

View workflow job for this annotation

GitHub Actions / clippy

unresolved imports `crate::msg::StatusResponse`, `crate::state::STATUS`

error[E0432]: unresolved imports `crate::msg::StatusResponse`, `crate::state::STATUS` --> contracts/interchain-gov/src/handlers/query.rs:3:50 | 3 | msg::{ConfigResponse, InterchainGovQueryMsg, StatusResponse}, | ^^^^^^^^^^^^^^ no `StatusResponse` in `msg` 4 | state::{CONFIG, STATUS}, | ^^^^^^ | | | no `STATUS` in `state` | help: a similar name exists in the module: `Status`
state::{CONFIG, STATUS},
};

Expand All @@ -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<Binary> {
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 } => {

Check failure on line 18 in contracts/interchain-gov/src/handlers/query.rs

View workflow job for this annotation

GitHub Actions / clippy

no variant named `Status` found for enum `msg::InterchainGovQueryMsg`

error[E0599]: no variant named `Status` found for enum `msg::InterchainGovQueryMsg` --> contracts/interchain-gov/src/handlers/query.rs:18:32 | 18 | InterchainGovQueryMsg::Status { account_id } => { | ^^^^^^ variant not found in `msg::InterchainGovQueryMsg` | ::: contracts/interchain-gov/src/msg.rs:43:1 | 43 | pub enum InterchainGovQueryMsg { | ------------------------------ variant `Status` not found here
to_json_binary(&query_status(deps, account_id)?)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Loading

0 comments on commit 91ad0d5

Please sign in to comment.