Skip to content

Commit 296d35c

Browse files
committed
yep
1 parent 1253358 commit 296d35c

File tree

9 files changed

+100
-16
lines changed

9 files changed

+100
-16
lines changed

wasm-deploy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ wasm_cli = []
1818
[dependencies]
1919
wasm-deploy-derive = { version = "0.6.0", path = "../wasm-deploy-derive" }
2020
cosm-utils = { path = "../../cosm-utils", features = ["keyring"] }
21-
tendermint-rpc = "0.38"
21+
# tendermint-rpc = "0.38"
2222
wasm-opt = { version = "=0.110.2", optional = true }
2323
serde = { version = "1", default-features = false, features = ["derive"] }
2424
serde_json = "1"

wasm-deploy/src/cli.rs

+19
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ where
156156
#[arg(short, long, required = false)]
157157
interactive: bool,
158158

159+
/// Will prompt for coins for each message
160+
#[arg(long, required = false)]
161+
coins: bool,
162+
159163
/// Does not execute transactions, prints txs to console
160164
#[arg(short, long, required = false)]
161165
dry_run: bool,
@@ -238,6 +242,21 @@ where
238242
dry_run: bool,
239243
},
240244

245+
/// Sends a token amount to a given address
246+
Cw20Transfer {
247+
/// Address to receive the tokens
248+
#[arg(long)]
249+
recipient: String,
250+
251+
/// The amount and denom to send
252+
#[arg(short, long)]
253+
contract_addr: String,
254+
255+
/// The amount and denom to send
256+
#[arg(long)]
257+
amount: u128,
258+
},
259+
241260
/// Executes a contract with a custom payload
242261
ExecutePayload {
243262
#[arg(short, long)]

wasm-deploy/src/commands.rs

+26-7
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@ use clap_complete::{
1111
use colored::Colorize;
1212
use colored_json::to_colored_json_auto;
1313
use cosm_utils::chain::coin::Denom;
14+
use cosm_utils::cosmrs;
1415
use cosm_utils::modules::bank::model::SendRequest;
1516
use cosm_utils::prelude::*;
1617
use cosm_utils::{
1718
chain::{coin::Coin, request::TxOptions},
1819
modules::{auth::model::Address, cosmwasm::model::ExecRequest},
1920
};
21+
use cosmrs::rpc::client::CompatMode;
22+
use cosmrs::rpc::{HttpClient, HttpClientUrl};
2023
#[cfg(feature = "wasm_opt")]
2124
use futures::future::join_all;
2225
use inquire::{MultiSelect, Select};
2326
use interactive_parse::InteractiveParseObj;
2427
use log::info;
25-
use tendermint_rpc::client::CompatMode;
26-
use tendermint_rpc::{HttpClient, HttpClientUrl};
2728
#[cfg(feature = "wasm_opt")]
2829
use tokio::task::spawn_blocking;
2930
#[cfg(feature = "wasm_opt")]
3031
use wasm_opt::integration::run_from_command_args;
3132

3233
use crate::config::WorkspaceSettings;
34+
use crate::cw20::cw20_transfer;
3335
use crate::query::query;
3436
use crate::utils::print_res;
3537
#[cfg(wasm_cli)]
@@ -90,8 +92,9 @@ where
9092
Commands::Instantiate {
9193
contracts,
9294
interactive,
95+
coins,
9396
dry_run,
94-
} => instantiate(settings, contracts, *interactive, *dry_run).await?,
97+
} => instantiate(settings, contracts, *interactive, *coins, *dry_run).await?,
9598
Commands::Migrate {
9699
contracts,
97100
interactive,
@@ -116,6 +119,11 @@ where
116119
cw20_query(*dry_run).await?;
117120
}
118121
Commands::Cw20Instantiate { dry_run } => cw20_instantiate(*dry_run).await?,
122+
Commands::Cw20Transfer {
123+
recipient,
124+
contract_addr,
125+
amount,
126+
} => cw20_transfer(recipient.clone(), contract_addr.clone(), *amount).await?,
119127
Commands::ExecutePayload { address, payload } => custom_execute(address, payload).await?,
120128
Commands::QueryPayload { address, payload } => custom_query(address, payload).await?,
121129
Commands::SetConfig { contracts, dry_run } => {
@@ -261,7 +269,7 @@ pub async fn deploy(
261269
build(settings, contracts, cargo_args).await?;
262270
}
263271
store_code(settings, contracts, dry_run).await?;
264-
instantiate(settings, contracts, dry_run, false).await?;
272+
instantiate(settings, contracts, false, false, dry_run).await?;
265273
set_config(settings, contracts, dry_run).await?;
266274
set_up(settings, contracts, dry_run).await?;
267275
Ok(())
@@ -582,7 +590,7 @@ pub async fn store_code(
582590
let chunk_size = CONFIG.read().await.settings.store_code_chunk_size;
583591
let chunks = contracts.chunks(chunk_size);
584592
for chunk in chunks {
585-
execute_deployment(settings, chunk, dry_run, DeploymentStage::StoreCode).await?;
593+
execute_deployment(settings, chunk, false, dry_run, DeploymentStage::StoreCode).await?;
586594
}
587595
Ok(())
588596
}
@@ -591,18 +599,21 @@ pub async fn instantiate(
591599
settings: &WorkspaceSettings,
592600
contracts: &[impl Deploy],
593601
interactive: bool,
602+
coins: bool,
594603
dry_run: bool,
595604
) -> anyhow::Result<()> {
596605
execute_deployment(
597606
settings,
598607
contracts,
608+
coins,
599609
dry_run,
600610
DeploymentStage::Instantiate { interactive },
601611
)
602612
.await?;
603613
execute_deployment(
604614
settings,
605615
contracts,
616+
coins,
606617
dry_run,
607618
DeploymentStage::ExternalInstantiate,
608619
)
@@ -627,6 +638,7 @@ pub async fn migrate(
627638
execute_deployment(
628639
settings,
629640
contracts,
641+
false,
630642
dry_run,
631643
DeploymentStage::Migrate { interactive },
632644
)
@@ -640,7 +652,14 @@ pub async fn set_config(
640652
contracts: &[impl Deploy],
641653
dry_run: bool,
642654
) -> anyhow::Result<()> {
643-
execute_deployment(settings, contracts, dry_run, DeploymentStage::SetConfig).await?;
655+
execute_deployment(
656+
settings,
657+
contracts,
658+
false,
659+
dry_run,
660+
DeploymentStage::SetConfig,
661+
)
662+
.await?;
644663
Ok(())
645664
}
646665

@@ -649,7 +668,7 @@ pub async fn set_up(
649668
contracts: &[impl Deploy],
650669
dry_run: bool,
651670
) -> anyhow::Result<()> {
652-
execute_deployment(settings, contracts, dry_run, DeploymentStage::SetUp).await?;
671+
execute_deployment(settings, contracts, false, dry_run, DeploymentStage::SetUp).await?;
653672
Ok(())
654673
}
655674

wasm-deploy/src/config/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ use crate::config::{WorkspaceSettings, WORKSPACE_SETTINGS};
33
use crate::error::DeployError;
44
#[cfg(feature = "ledger")]
55
use crate::ledger::get_ledger_info;
6+
use cosm_utils::cosmrs;
67
use cosm_utils::prelude::*;
78
use cosm_utils::{
89
config::cfg::ChainConfig,
910
signing_key::key::{Key, KeyringParams, UserKey},
1011
};
12+
use cosmrs::rpc::HttpClient;
1113
use futures::executor::block_on;
1214
use ibc_chain_registry::{chain::ChainData, constants::ALL_CHAINS, fetchable::Fetchable};
1315
use inquire::{Confirm, CustomType, Select, Text};
@@ -24,7 +26,6 @@ use std::{
2426
path::PathBuf,
2527
sync::Arc,
2628
};
27-
use tendermint_rpc::HttpClient;
2829
use tokio::sync::RwLock;
2930

3031
use super::{ContractInfo, Env, UserSettings};

wasm-deploy/src/cw20.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::str::FromStr;
33
use crate::{config::CONFIG, contract::Deploy};
44
use colored::Colorize;
55
use colored_json::to_colored_json_auto;
6+
use cosm_utils::cosmrs;
67
use cosm_utils::prelude::*;
78
use cosm_utils::{
89
chain::{coin::Coin, request::TxOptions},
@@ -11,10 +12,10 @@ use cosm_utils::{
1112
cosmwasm::model::{ExecRequest, InstantiateRequest},
1213
},
1314
};
15+
use cosmrs::rpc::HttpClient;
1416
use cw20::Cw20ExecuteMsg;
1517
use inquire::{CustomType, Text};
1618
use interactive_parse::InteractiveParseObj;
17-
use tendermint_rpc::HttpClient;
1819

1920
pub async fn cw20_send(contract: &impl Deploy, dry_run: bool) -> anyhow::Result<()> {
2021
println!("Executing cw20 send");
@@ -138,3 +139,36 @@ pub async fn cw20_instantiate(dry_run: bool) -> anyhow::Result<()> {
138139
}
139140
Ok(())
140141
}
142+
143+
pub async fn cw20_transfer(
144+
recipient: String,
145+
contract_addr: String,
146+
amount: u128,
147+
) -> anyhow::Result<()> {
148+
println!("Executing cw20 transfer");
149+
let config = CONFIG.read().await;
150+
let key = config.get_active_key().await?;
151+
let msg = Cw20ExecuteMsg::Transfer {
152+
recipient,
153+
amount: amount.into(),
154+
};
155+
let chain_info = config.get_active_chain_info()?.clone();
156+
let client = HttpClient::get_persistent_compat(chain_info.rpc_endpoint.as_str()).await?;
157+
let funds = Vec::<Coin>::parse_to_obj()?;
158+
let req = ExecRequest {
159+
msg,
160+
funds,
161+
address: Address::from_str(&contract_addr)?,
162+
};
163+
164+
let response = client
165+
.wasm_execute_commit(&chain_info.cfg, req, &key, &TxOptions::default())
166+
.await?;
167+
println!(
168+
"gas wanted: {}, gas used: {}",
169+
response.tx_result.gas_wanted.to_string().green(),
170+
response.tx_result.gas_used.to_string().green()
171+
);
172+
println!("tx hash: {}", response.hash.to_string().purple());
173+
Ok(())
174+
}

wasm-deploy/src/deployment.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::str::FromStr;
2-
31
use colored::Colorize;
42
use colored_json::to_colored_json_auto;
3+
use cosm_utils::chain::coin::Coin;
4+
use cosm_utils::cosmrs;
55
use cosm_utils::{
66
chain::request::TxOptions,
77
modules::{
@@ -11,8 +11,10 @@ use cosm_utils::{
1111
prelude::*,
1212
signing_key::key::UserKey,
1313
};
14+
use cosmrs::rpc::{endpoint::broadcast::tx_commit, HttpClient};
15+
use interactive_parse::InteractiveParseObj;
1416
use log::debug;
15-
use tendermint_rpc::{endpoint::broadcast::tx_commit, HttpClient};
17+
use std::str::FromStr;
1618

1719
use crate::{
1820
config::{ChainInfo, ContractInfo, WorkspaceSettings, CONFIG},
@@ -33,6 +35,7 @@ pub enum DeploymentStage {
3335
pub async fn execute_deployment(
3436
settings: &WorkspaceSettings,
3537
contracts: &[impl Deploy],
38+
coins: bool,
3639
dry_run: bool,
3740
deployment_stage: DeploymentStage,
3841
) -> anyhow::Result<()> {
@@ -51,6 +54,7 @@ pub async fn execute_deployment(
5154
execute_instantiate(
5255
contracts,
5356
interactive,
57+
coins,
5458
dry_run,
5559
&client,
5660
&chain_info,
@@ -286,6 +290,7 @@ async fn execute_external_instantiate(
286290
async fn execute_instantiate(
287291
contracts: &[impl Deploy],
288292
interactive: bool,
293+
coins: bool,
289294
dry_run: bool,
290295
client: &HttpClient,
291296
chain_info: &ChainInfo,
@@ -318,6 +323,9 @@ async fn execute_instantiate(
318323
);
319324
let contract_info = config.get_contract(&contract.to_string())?;
320325
let code_id = contract_info.code_id.ok_or(DeployError::CodeIdNotFound)?;
326+
if coins {
327+
Coin::parse_to_obj()?;
328+
}
321329
reqs.push(InstantiateRequest {
322330
code_id,
323331
msg,

wasm-deploy/src/execute.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ use crate::{
44
};
55
use colored::Colorize;
66
use colored_json::to_colored_json_auto;
7+
use cosm_utils::cosmrs;
78
use cosm_utils::{
89
chain::{coin::Coin, request::TxOptions},
910
modules::{auth::model::Address, cosmwasm::model::ExecRequest},
1011
prelude::*,
1112
};
13+
use cosmrs::rpc::HttpClient;
1214
use interactive_parse::InteractiveParseObj;
1315
use log::debug;
1416
use serde::Serialize;
1517
use std::{fmt::Debug, str::FromStr};
16-
use tendermint_rpc::HttpClient;
1718

1819
pub async fn execute_contract(contract: &impl Deploy, dry_run: bool) -> anyhow::Result<()> {
1920
println!("Executing");

wasm-deploy/src/query.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::{fmt::Debug, str::FromStr};
22

33
use colored_json::to_colored_json_auto;
4+
use cosm_utils::cosmrs;
45
use cosm_utils::{modules::auth::model::Address, prelude::*};
6+
use cosmrs::rpc::HttpClient;
57
use cw20::Cw20QueryMsg;
68
use inquire::Text;
79
use interactive_parse::InteractiveParseObj;
810
use log::debug;
911
use serde::{de::DeserializeOwned, Serialize};
1012
use serde_json::Value;
11-
use tendermint_rpc::HttpClient;
1213

1314
use crate::{
1415
config::{Config, CONFIG},

wasm-deploy/src/utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use crate::{
33
error::DeployError,
44
};
55
use colored::Colorize;
6+
use cosm_utils::cosmrs;
7+
use cosmrs::rpc::endpoint::broadcast::tx_commit;
68
use futures::executor::block_on;
79
use lazy_static::lazy_static;
810
use serde::{de::DeserializeOwned, Serialize};
911
use serde_json::Value;
1012
use std::sync::Arc;
11-
use tendermint_rpc::endpoint::broadcast::tx_commit;
1213

1314
lazy_static! {
1415
pub static ref BIN_NAME: String = std::env::current_exe()

0 commit comments

Comments
 (0)