cosm_orc/lib.rs
1//! Cosmwasm smart contract orchestration and gas profiling tool
2//!
3//! Store, instantiate, execute, and query [Cosmwasm] smart contracts against a configured [Cosmos] based chain.
4//! Optionally, profile gas usage of the smart contract operations.
5//!
6//! Potential uses:
7//! * Integration tests
8//! * Deployments / Bootstrapping environments
9//! * Gas profiling
10//!
11//! This project is not yet intended to be used for mainnet.
12//!
13//! [cosmwasm]: https://github.com/CosmWasm/cosmwasm
14//! [Cosmos]: https://github.com/cosmos/cosmos-sdk
15//!
16//!
17//! # Quick Start
18//!
19//! ```no_run
20//! # use std::error::Error;
21//! # use cosm_orc::{
22//! # config::cfg::Config,
23//! # orchestrator::cosm_orc::CosmOrc,
24//! # };
25//! # use cosm_orc::orchestrator::{SigningKey, Key};
26//! # use cw20_base::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
27//! # use cw20::TokenInfoResponse;
28//! # fn main() -> Result<(), Box<dyn Error>> {
29//! // juno_local.yaml has the `cw20_base` code_id already stored
30//! // If the smart contract has not been stored on the chain yet use: `cosm_orc::store_contracts()`
31//! let mut cosm_orc = CosmOrc::new(Config::from_yaml("./example-configs/juno_local.yaml")?, false)?;
32//! let key = SigningKey {
33//! name: "validator".to_string(),
34//! key: Key::Mnemonic("word1 word2 ...".to_string()),
35//! derivation_path: "m/44'/118'/0'/0/0".to_string(),
36//! };
37//!
38//! cosm_orc.instantiate(
39//! "cw20_base",
40//! "meme_token_test",
41//! &InstantiateMsg {
42//! name: "Meme Token".to_string(),
43//! symbol: "MEME".to_string(),
44//! decimals: 6,
45//! initial_balances: vec![],
46//! mint: None,
47//! marketing: None,
48//! },
49//! &key,
50//! None,
51//! vec![]
52//! )?;
53//!
54//! let res = cosm_orc.query(
55//! "cw20_base",
56//! &QueryMsg::TokenInfo {},
57//! )?;
58//!
59//! let res: TokenInfoResponse = res.data()?;
60//! # Ok(())
61//! # }
62//! ```
63//!
64//! # Store Contracts
65//!
66//! If `config.yaml` doesn't have the pre-stored contract code ids, you can call `store_contracts()`:
67//!
68//! ```no_run
69//! # use std::error::Error;
70//! # use cosm_orc::{
71//! # config::cfg::Config,
72//! # orchestrator::cosm_orc::CosmOrc,
73//! # };
74//! # use cosm_orc::orchestrator::{SigningKey, Key};
75//! # use cw20_base::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
76//! # fn main() -> Result<(), Box<dyn Error>> {
77//! let mut cosm_orc = CosmOrc::new(Config::from_yaml("./example-configs/juno_local.yaml")?, false)?;
78//!
79//! let key = SigningKey {
80//! name: "validator".to_string(),
81//! key: Key::Mnemonic("word1 word2 ...".to_string()),
82//! derivation_path: "m/44'/118'/0'/0/0".to_string(),
83//! };
84//!
85//! // `./artifacts` is a directory that contains the rust optimized wasm files.
86//! //
87//! // NOTE: currently cosm-orc is expecting a wasm filed called: `cw20_base.wasm`
88//! // to be in `/artifacts`, since `cw20_base` is used as the contract name in process_msgs() call below
89//! cosm_orc.store_contracts("./artifacts", &key, None)?;
90//!
91//! cosm_orc.instantiate(
92//! "cw20_base",
93//! "meme_token_test",
94//! &InstantiateMsg {
95//! name: "Meme Token".to_string(),
96//! symbol: "MEME".to_string(),
97//! decimals: 6,
98//! initial_balances: vec![],
99//! mint: None,
100//! marketing: None,
101//! },
102//! &key,
103//! None,
104//! vec![]
105//! )?;
106//!
107//! let res = cosm_orc.query(
108//! "cw20_base",
109//! &QueryMsg::TokenInfo {},
110//! )?;
111//!
112//! # Ok(())
113//! # }
114//! ```
115//!
116//! # Gas Profiling
117//!
118//! ```no_run
119//! # use std::error::Error;
120//! # use cosm_orc::{
121//! # config::cfg::Config,
122//! # orchestrator::cosm_orc::CosmOrc,
123//! # };
124//! # use cosm_orc::orchestrator::{SigningKey, Key};
125//! # use cw20_base::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
126//! # fn main() -> Result<(), Box<dyn Error>> {
127//! let mut cosm_orc = CosmOrc::new(Config::from_yaml("config.yaml")?, true)?;
128//!
129//! let key = SigningKey {
130//! name: "validator".to_string(),
131//! key: Key::Mnemonic("word1 word2 ...".to_string()),
132//! derivation_path: "m/44'/118'/0'/0/0".to_string(),
133//! };
134//!
135//! cosm_orc.instantiate(
136//! "cw20_base",
137//! "meme_token_test",
138//! &InstantiateMsg {
139//! name: "Meme Token".to_string(),
140//! symbol: "MEME".to_string(),
141//! decimals: 6,
142//! initial_balances: vec![],
143//! mint: None,
144//! marketing: None,
145//! },
146//! &key,
147//! None,
148//! vec![]
149//! )?;
150//!
151//! let reports = cosm_orc.gas_profiler_report();
152//!
153//! # Ok(())
154//! # }
155//! ```
156//!
157
158pub mod orchestrator;
159
160pub mod config;
161
162// re-export all of cosm-tome in case people want to use arbitrary
163// cosmtome types when accessing the underlying `cosm_orc.client`
164pub use cosm_tome;