Skip to content

Commit

Permalink
Merge pull request #77 from AbstractSDK/buckram/standalone-template
Browse files Browse the repository at this point in the history
0.23 abstract + standalone template
  • Loading branch information
CyberHoward authored Jul 24, 2024
2 parents c81ac45 + 1c44d50 commit 70a955b
Show file tree
Hide file tree
Showing 34 changed files with 747 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
- name: cargo clippy
run: |
CARGO_GENERATE_TEST_CMD="cargo clippy --all-features -- -D warnings" \
cargo generate -d include_app=true -d include_adapter=true -d app_name=my_app -d adapter_name=my_adapter --test
cargo generate -d include_app=true -d include_adapter=true -d include_standalone=true -d app_name=my_app -d adapter_name=my_adapter -d standalone_name=my_standalone --test
2 changes: 1 addition & 1 deletion .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
- name: cargo test --locked
run: |
CARGO_GENERATE_TEST_CMD="cargo test --all-features --all-targets" \
cargo generate -d include_app=true -d include_adapter=true -d app_name=my_app -d adapter_name=my_adapter --test
cargo generate -d include_app=true -d include_adapter=true -d include_standalone=true -d app_name=my_app -d adapter_name=my_adapter -d standalone_name=my_standalone --test
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: cargo test
run: |
CARGO_GENERATE_TEST_CMD="cargo test --all-features --all-targets" \
cargo generate -d include_app=true -d include_adapter=true -d app_name=my_app -d adapter_name=my_adapter --test
cargo generate -d include_app=true -d include_adapter=true -d include_standalone=true -d app_name=my_app -d adapter_name=my_adapter -d standalone_name=my_standalone --test
26 changes: 15 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@ panic = 'abort'
incremental = false

[workspace.dependencies]
{% if include_app %}
{{app_name | kebab_case}} = { path = "contracts/{{app_name}}" }
{% endif %}
{% if include_adapter %}
{{adapter_name | kebab_case}} = { path = "contracts/{{adapter_name}}" }
{% endif %}
cosmwasm-std = { version = "1.5.3" }
cosmwasm-schema = { version = "1.5.3" }
cw-controllers = { version = "1.1.2" }
cw-storage-plus = "1.2.0"
thiserror = { version = "1.0.50" }
schemars = "0.8"
cw-asset = { version = "3.0.0" }
abstract-app = { version = "0.22.2" }
abstract-adapter = { version = "0.22.2" }
abstract-interface = { version = "0.22.0" }
abstract-client = { version = "0.22.0" }
abstract-app = { version = "0.23.0" }
abstract-adapter = { version = "0.23.0" }
abstract-standalone = { version = "0.23.0" }
abstract-interface = { version = "0.23.0" }
abstract-client = { version = "0.23.0" }
lazy_static = "1.4.0"
cw-orch = { version = "0.22.2" }
cw-orch = { version = "0.24.1" }
const_format = "0.2.32"
speculoos = "0.11.0"
semver = "1.0"
dotenv = "0.15.0"
env_logger = "0.11.3"
clap = { version = "4.3.7" }
{% if include_app %}
{{app_name | kebab_case}} = { path = "contracts/{{app_name}}" }
{% endif %}
{% if include_adapter %}
{{adapter_name | kebab_case}} = { path = "contracts/{{adapter_name}}" }
{% endif %}
{% if include_standalone %}
{{standalone_name | kebab_case}} = { path = "contracts/{{standalone_name}}" }
{% endif %}
7 changes: 7 additions & 0 deletions cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
[template]
ignore = [".github", "artifacts", "target"]
exclude = ["justfile"]

[hooks]
post = ["post-script.rhai"]

[placeholders]
include_app = { prompt = "Include App Module", default = true, type = "bool" }
include_adapter = { prompt = "Include Adapter Module", default = true, type = "bool" }
include_standalone = { prompt = "Include Standalone Module", default = true, type = "bool" }

[conditional.'include_app'.placeholders]
app_name = { prompt = "Enter App Name", default = "my_app", type = "string" }

[conditional.'include_adapter'.placeholders]
adapter_name = { prompt = "Enter Adapter Name", default = "my_adapter", type = "string" }

[conditional.'include_standalone'.placeholders]
standalone_name = { prompt = "Enter Standalone Name", default = "my_standalone", type = "string" }

# Ignore files if not included
[conditional.'!include_app']
ignore = ["contracts/{{app_name}}"]
[conditional.'!include_adapter']
ignore = ["contracts/{{adapter_name}}"]
[conditional.'!include_standalone']
ignore = ["contracts/{{standalone_name}}"]
7 changes: 3 additions & 4 deletions contracts/{{adapter_name}}/src/bin/local_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! # Run
//!
//! `RUST_LOG=info cargo run --bin local_daemon --features="daemon-bin" --package my-adapter`
//! `RUST_LOG=info cargo run --bin local_daemon --features="daemon-bin" --package {{adapter_name | kebab_case}}`
use {{adapter_name | snake_case}}::{contract::interface::{{adapter_name | upper_camel_case}}Interface, {{adapter_name | upper_camel_case}}ExecuteMsg, {{adapter_name | shouty_snake_case}}_ID};

use abstract_adapter::{objects::namespace::Namespace, std::adapter::AdapterRequestMsg};
Expand All @@ -22,8 +22,7 @@ fn main() -> anyhow::Result<()> {

let runtime = Runtime::new()?;

let daemon = Daemon::builder()
.chain(networks::LOCAL_JUNO)
let daemon = Daemon::builder(networks::LOCAL_JUNO)
.mnemonic(LOCAL_MNEMONIC)
.handle(runtime.handle())
.build()
Expand All @@ -45,7 +44,7 @@ fn main() -> anyhow::Result<()> {
// Ensure the current sender owns the namespace
assert_eq!(
publisher.account().owner()?,
daemon.sender(),
daemon.sender_addr(),
"The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace."
);

Expand Down
7 changes: 3 additions & 4 deletions contracts/{{adapter_name}}/src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! ## Example
//!
//! ```bash
//! $ just publish uni-6 osmo-test-5
//! $ just publish {{adapter_name | kebab_case}} uni-6 osmo-test-5
//! ```
use {{adapter_name | snake_case}}::{
contract::interface::{{adapter_name | upper_camel_case}}Interface, msg::{{adapter_name | upper_camel_case}}InstantiateMsg, {{adapter_name | shouty_snake_case}}_ID,
Expand All @@ -21,9 +21,8 @@ fn publish(networks: Vec<ChainInfo>) -> anyhow::Result<()> {
for network in networks {
// Setup
let rt = Runtime::new()?;
let chain = DaemonBuilder::default()
let chain = DaemonBuilder::new(network)
.handle(rt.handle())
.chain(network)
.build()?;

let adapter_namespace = Namespace::from_id({{adapter_name | shouty_snake_case}}_ID)?;
Expand All @@ -36,7 +35,7 @@ fn publish(networks: Vec<ChainInfo>) -> anyhow::Result<()> {
.publisher_builder(adapter_namespace)
.build()?;

if publisher.account().owner()? != chain.sender() {
if publisher.account().owner()? != chain.sender_addr() {
panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.")
}

Expand Down
1 change: 0 additions & 1 deletion contracts/{{adapter_name}}/src/bin/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ fn main() {
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

#[cfg(feature = "schema")]
{{adapter_name | upper_camel_case}}::export_schema(&out_dir);
}
4 changes: 3 additions & 1 deletion contracts/{{adapter_name}}/src/handlers/execute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
contract::{AdapterResult, {{adapter_name | upper_camel_case}}},
contract::{
AdapterResult, {{adapter_name | upper_camel_case}}
},
msg::{{adapter_name | upper_camel_case}}ExecuteMsg,
state::{CONFIG, STATUS},
{{adapter_name | upper_camel_case}}Error, {{project-name | shouty_snake_case}}_NAMESPACE,
Expand Down
4 changes: 3 additions & 1 deletion contracts/{{adapter_name}}/src/handlers/instantiate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
contract::{AdapterResult, {{adapter_name | upper_camel_case}}},
contract::{
AdapterResult, {{adapter_name | upper_camel_case}}
},
msg::{{adapter_name | upper_camel_case}}InstantiateMsg,
state::{Config, CONFIG},
};
Expand Down
4 changes: 3 additions & 1 deletion contracts/{{adapter_name}}/src/handlers/query.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
contract::{AdapterResult, {{adapter_name | upper_camel_case}}},
contract::{
AdapterResult, {{adapter_name | upper_camel_case}}
},
msg::{ConfigResponse, {{adapter_name | upper_camel_case}}QueryMsg, StatusResponse},
state::{CONFIG, STATUS},
};
Expand Down
1 change: 0 additions & 1 deletion contracts/{{adapter_name}}/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub enum {{adapter_name | upper_camel_case}}ExecuteMsg {
/// Adapter query messages
#[cosmwasm_schema::cw_serde]
#[derive(QueryResponses, cw_orch::QueryFns)]
#[impl_into(QueryMsg)]
pub enum {{adapter_name | upper_camel_case}}QueryMsg {
#[returns(StatusResponse)]
Status { account_id: AccountId },
Expand Down
2 changes: 1 addition & 1 deletion contracts/{{adapter_name}}/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl TestEnv<MockBech32> {
fn setup() -> anyhow::Result<TestEnv<MockBech32>> {
// Create a sender and mock env
let mock = MockBech32::new("mock");
let sender = mock.sender();
let sender = mock.sender_addr();
let namespace = Namespace::new({{project-name | shouty_snake_case}}_NAMESPACE)?;

// You can set up Abstract with a builder.
Expand Down
7 changes: 3 additions & 4 deletions contracts/{{app_name}}/src/bin/local_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! # Run
//!
//! `RUST_LOG=info cargo run --bin --features="daemon-bin" local_daemon --package my-app`
//! `RUST_LOG=info cargo run --bin --features="daemon-bin" local_daemon --package {{app_name | kebab_case}}`
use {{app_name | snake_case}}::{{app_name | shouty_snake_case}}_ID;

use abstract_app::objects::namespace::Namespace;
Expand All @@ -22,8 +22,7 @@ fn main() -> anyhow::Result<()> {

let runtime = Runtime::new()?;

let daemon = Daemon::builder()
.chain(networks::LOCAL_JUNO)
let daemon = Daemon::builder(networks::LOCAL_JUNO)
.mnemonic(LOCAL_MNEMONIC)
.handle(runtime.handle())
.build()
Expand All @@ -41,7 +40,7 @@ fn main() -> anyhow::Result<()> {
let publisher: Publisher<_> = abstract_client.publisher_builder(app_namespace).build()?;

// Ensure the current sender owns the namespace
if publisher.account().owner()? != daemon.sender() {
if publisher.account().owner()? != daemon.sender_addr() {
panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.")
}

Expand Down
7 changes: 3 additions & 4 deletions contracts/{{app_name}}/src/bin/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! ## Example
//!
//! ```bash
//! $ just publish uni-6 osmo-test-5
//! $ just publish {{app_name | kebab_case}} uni-6 osmo-test-5
//! ```
use {{app_name | snake_case}}::{{app_name | shouty_snake_case}}_ID;

Expand All @@ -20,9 +20,8 @@ fn publish(networks: Vec<ChainInfo>) -> anyhow::Result<()> {
for network in networks {
// Setup
let rt = Runtime::new()?;
let chain = DaemonBuilder::default()
let chain = DaemonBuilder::new(network)
.handle(rt.handle())
.chain(network)
.build()?;

let app_namespace = Namespace::from_id({{app_name | shouty_snake_case}}_ID)?;
Expand All @@ -33,7 +32,7 @@ fn publish(networks: Vec<ChainInfo>) -> anyhow::Result<()> {
// 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() {
if publisher.account().owner()? != chain.sender_addr() {
panic!("The current sender can not publish to this namespace. Please use the wallet that owns the Account that owns the Namespace.")
}

Expand Down
1 change: 0 additions & 1 deletion contracts/{{app_name}}/src/bin/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ fn main() {
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

#[cfg(feature = "schema")]
{{app_name | upper_camel_case}}::export_schema(&out_dir);
}
2 changes: 0 additions & 2 deletions contracts/{{app_name}}/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct {{app_name | upper_camel_case}}InstantiateMsg {
/// App execute messages
#[cosmwasm_schema::cw_serde]
#[derive(cw_orch::ExecuteFns)]
#[impl_into(ExecuteMsg)]
pub enum {{app_name | upper_camel_case}}ExecuteMsg {
UpdateConfig {},
/// Increment count by 1
Expand All @@ -32,7 +31,6 @@ pub struct {{app_name | upper_camel_case}}MigrateMsg {}
/// App query messages
#[cosmwasm_schema::cw_serde]
#[derive(QueryResponses, cw_orch::QueryFns)]
#[impl_into(QueryMsg)]
pub enum {{app_name | upper_camel_case}}QueryMsg {
#[returns(ConfigResponse)]
Config {},
Expand Down
2 changes: 1 addition & 1 deletion contracts/{{app_name}}/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl TestEnv<MockBech32> {
fn setup() -> anyhow::Result<TestEnv<MockBech32>> {
// Create a sender and mock env
let mock = MockBech32::new("mock");
let sender = mock.sender();
let sender = mock.sender_addr();
let namespace = Namespace::new({{project-name | shouty_snake_case}}_NAMESPACE)?;

// You can set up Abstract with a builder.
Expand Down
66 changes: 66 additions & 0 deletions contracts/{{standalone_name}}/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[package]
name = "{{standalone_name | kebab_case}}"
version = "0.0.1"
authors = []
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 = []

[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-standalone = { workspace = true }
const_format = { version = "0.2.32" }

# 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]
{{standalone_name | kebab_case}} = { path = "." }
abstract-client = { workspace = true }
abstract-standalone = { workspace = true, features = ["test-utils"] }
9 changes: 9 additions & 0 deletions contracts/{{standalone_name}}/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "{{standalone_name | upper_camel_case}}",
"description": "Standalone description.",
"website": "",
"docs": "",
"type": "standalone",
"icon": "GiTrade",
"enabled": true
}
Loading

0 comments on commit 70a955b

Please sign in to comment.