Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 43 additions & 2 deletions cosmwasm/cosmwasm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ _: {
perSystem =
{
self',
crane,
mkCrane,
pkgs,
dbg,
system,
gitRev,
ensureAtRepositoryRoot,
...
}:
let
crane = mkCrane {
root = ../.;
# gitRev = "1b172ff9247e5eedcddc6665c856b0bf4427035d";
inherit gitRev;
};

getDeployment =
ucs04-chain-id:
(builtins.fromJSON (builtins.readFile ../deployments/deployments.json)).${ucs04-chain-id};
Expand Down Expand Up @@ -624,6 +631,39 @@ _: {
'';
};

deploy-manager =
{
name,
rpc_url,
gas_config,
private_key,
bech32_prefix,
...
}:
pkgs.writeShellApplication {
name = "deploy-contract-${name}";
runtimeInputs = [
cosmwasm-deployer
];
text = ''
DEPLOYER=$(
PRIVATE_KEY=${private_key} \
cosmwasm-deployer \
address-of-private-key \
--bech32-prefix ${bech32_prefix}
)
echo "deployer address: $DEPLOYER"

PRIVATE_KEY=${private_key} \
RUST_LOG=info \
cosmwasm-deployer \
deploy-manager \
--bytecode ${manager.release} \
--rpc-url ${rpc_url} \
${mk-gas-args gas_config} "$@"
'';
};

whitelist-relayers =
{
name,
Expand Down Expand Up @@ -1006,7 +1046,7 @@ _: {
];
text = ''
PRIVATE_KEY=${private_key} \
RUST_LOG=info \
RUST_LOG="info,''${RUST_LOG:-}" \
cosmwasm-deployer \
migrate-to-access-managed \
--rpc-url ${rpc_url} \
Expand Down Expand Up @@ -1216,6 +1256,7 @@ _: {
chain-contracts-config-json = chain-contracts-config-json chain;
chain-deployed-contracts-json = chain-deployed-contracts-json chain;
deploy = deploy chain;
deploy-manager = deploy-manager chain;
update-deployments-json = update-deployments-json chain;
get-git-rev = get-git-rev chain;
whitelist-relayers = whitelist-relayers chain;
Expand Down
1 change: 1 addition & 0 deletions cosmwasm/deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cw-escrow-vault = { workspace = true, features = ["library"] }
cw20 = { workspace = true }
cw20-base = { workspace = true }
embed-commit = { workspace = true }
flate2 = "1.1.5"
frissitheto = { workspace = true }
futures = { workspace = true }
hex-literal = { workspace = true }
Expand Down
107 changes: 70 additions & 37 deletions cosmwasm/deployer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt;
use std::{
collections::BTreeMap, fmt::Display, num::NonZeroU64, ops::Deref, path::PathBuf, str::FromStr,
sync::LazyLock,
collections::BTreeMap, fmt::Display, io::Write, num::NonZeroU64, ops::Deref, path::PathBuf,
str::FromStr, sync::LazyLock,
};

use access_manager_types::{RoleId, Selector, manager::msg::ExecuteMsg as AccessManagerExecuteMsg};
Expand All @@ -17,6 +17,7 @@ use cosmos_client::{
};
use cosmos_signer::CosmosSigner;
use cosmwasm_std::{Addr, Decimal, Uint256};
use flate2::{Compression, write::GzEncoder};
use futures::{TryStreamExt, future::OptionFuture, stream::FuturesOrdered};
use hex_literal::hex;
use protos::cosmwasm::wasm::v1::{QuerySmartContractStateRequest, QuerySmartContractStateResponse};
Expand Down Expand Up @@ -109,6 +110,20 @@ enum App {
#[command(flatten)]
gas_config: GasFillerArgs,
},
DeployManager {
#[arg(long)]
rpc_url: String,
#[arg(long, env)]
private_key: H256,
#[arg(long)]
bytecode: PathBuf,
#[arg(long)]
initial_admin: Bech32<Bytes>,
#[arg(long)]
output: Option<PathBuf>,
#[command(flatten)]
gas_config: GasFillerArgs,
},
Instantiate2Address {
#[arg(long)]
deployer: Bech32<Bytes>,
Expand Down Expand Up @@ -668,7 +683,11 @@ async fn do_main() -> Result<()> {
let ctx = Deployer::new(rpc_url, private_key.unwrap_or(sha2("")), &gas_config).await?;

let do_migrate = async |address, bytecode, message: Value| {
let bytecode = std::fs::read(bytecode).context("reading bytecode")?;
let raw_bytecode = std::fs::read(bytecode).context("reading bytecode")?;

let mut gz_encoder = GzEncoder::new(Vec::new(), Compression::best());
gz_encoder.write_all(&raw_bytecode)?;
let bytecode = gz_encoder.finish()?;

let contract_info = ctx
.contract_info(&address)
Expand All @@ -681,7 +700,7 @@ async fn do_main() -> Result<()> {
bail!(
"contract {address} has not yet been initiated, it must be fully deployed before it can be migrated"
)
} else if checksum == sha2(&bytecode) {
} else if checksum == sha2(&raw_bytecode) {
info!("contract {address} has already been migrated to this bytecode");
return Ok(());
}
Expand All @@ -690,30 +709,16 @@ async fn do_main() -> Result<()> {

info!("migrate message: {message}");

let msg = MsgStoreCode {
sender: ctx.wallet().address().map_data(Into::into),
wasm_byte_code: bytecode.into(),
instantiate_permission: None,
};

info!("storing code for {address}");

let (tx_hash, store_code_response) = ctx
.tx(msg, "", gas_config.simulate)
.await
.context("migrate")?;

info!(%tx_hash, code_id = store_code_response.code_id, "code stored");
info!("migrating {address}");

let msg = MsgMigrateContract {
let msg = MsgStoreAndMigrateContract {
sender: ctx.wallet().address().map_data(Into::into),
contract: address.clone(),
code_id: store_code_response.code_id,
wasm_byte_code: bytecode.into(),
instantiate_permission: None,
msg: message.to_string().into_bytes().into(),
};

info!("migrating {address}");

let (tx_hash, _) = ctx
.tx(msg, "", gas_config.simulate)
.await
Expand Down Expand Up @@ -762,17 +767,17 @@ async fn do_main() -> Result<()> {
.await?;
}

if let Some(address) = addresses.escrow_vault.clone() {
do_migrate(
address,
&contracts.escrow_vault.unwrap(),
to_value(cw_escrow_vault::msg::MigrateMsg {
access_managed_init_msg: access_managed_init_msg.clone(),
})
.unwrap(),
)
.await?;
}
// if let Some(address) = addresses.escrow_vault.clone() {
// do_migrate(
// address,
// &contracts.escrow_vault.unwrap(),
// to_value(cw_escrow_vault::msg::MigrateMsg {
// access_managed_init_msg: access_managed_init_msg.clone(),
// })
// .unwrap(),
// )
// .await?;
// }

info!("migrated contracts");
info!("roles have not been set up, use `cosmwasm-deployer setup-roles`");
Expand Down Expand Up @@ -1003,6 +1008,34 @@ async fn do_main() -> Result<()> {

write_output(output, res)?;
}
App::DeployManager {
rpc_url,
private_key,
bytecode,
initial_admin,
output,
gas_config,
} => {
let bytecode = std::fs::read(bytecode).context("reading bytecode path")?;

let deployer = Deployer::new(rpc_url.clone(), private_key, &gas_config).await?;

let bytecode_base_code_id = deployer.store_bytecode_base(&gas_config).await?;

let res = deployer
.deploy_and_initiate(
bytecode,
bytecode_base_code_id,
access_manager_types::manager::msg::InitMsg {
initial_admin: Addr::unchecked(initial_admin.to_string()),
},
&MANAGER,
true,
)
.await?;

write_output(output, res)?;
}
App::Tx(tx_cmd) => match tx_cmd {
TxCmd::WhitelistRelayers {
rpc_url,
Expand Down Expand Up @@ -1653,10 +1686,10 @@ async fn setup_roles(
"misbehaviour",
"batch_send",
"batch_acks",
"recv_packet",
"recv_intent_packet",
"acknowledge_packet",
"timeout_packet",
"packet_recv",
"intent_packet_recv",
"packet_ack",
"packet_timeout",
];

let rate_limiter_selectors = ["set_bucket_config"];
Expand Down
1 change: 1 addition & 0 deletions deployments/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@
"osmosis.osmo-test-5": {
"ibc_interface": "ibc-cosmwasm",
"deployer": "osmo10c4yqddv6w7sphruvhxs5v0es8r9fcj5ed3yx7",
"manager": "osmo1managerhl8ka4alvaewkhflcc44m6385pf94zmrh2f4d3yzc2y4q4l623x",
"core": {
"address": "osmo1hnuj8f6d3wy3fcprt55vddv7v2650t6uudnvd2hukqrteeam8wjqata4fx",
"height": 27869833,
Expand Down