diff --git a/Cargo.lock b/Cargo.lock index 258b14be58..1863416a25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3689,6 +3689,7 @@ dependencies = [ "cw20", "cw20-base", "embed-commit", + "flate2", "frissitheto", "futures", "hex-literal 0.4.1", @@ -5998,9 +5999,9 @@ checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" [[package]] name = "flate2" -version = "1.1.1" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb" dependencies = [ "crc32fast", "miniz_oxide", @@ -8694,6 +8695,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff70ce3e48ae43fa075863cef62e8b43b71a4f2382229920e0df362592919430" dependencies = [ "adler2", + "simd-adler32", ] [[package]] @@ -12825,6 +12827,12 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + [[package]] name = "similar" version = "2.7.0" diff --git a/cosmwasm/cosmwasm.nix b/cosmwasm/cosmwasm.nix index 5c55f79b79..1556d645a5 100644 --- a/cosmwasm/cosmwasm.nix +++ b/cosmwasm/cosmwasm.nix @@ -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}; @@ -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, @@ -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} \ @@ -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; diff --git a/cosmwasm/deployer/Cargo.toml b/cosmwasm/deployer/Cargo.toml index 7f3f574d4e..21ff7f41f6 100644 --- a/cosmwasm/deployer/Cargo.toml +++ b/cosmwasm/deployer/Cargo.toml @@ -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 } diff --git a/cosmwasm/deployer/src/main.rs b/cosmwasm/deployer/src/main.rs index 26f08cfc58..b91aa4cf88 100644 --- a/cosmwasm/deployer/src/main.rs +++ b/cosmwasm/deployer/src/main.rs @@ -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}; @@ -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}; @@ -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, + #[arg(long)] + output: Option, + #[command(flatten)] + gas_config: GasFillerArgs, + }, Instantiate2Address { #[arg(long)] deployer: Bech32, @@ -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) @@ -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(()); } @@ -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 @@ -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`"); @@ -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, @@ -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"]; diff --git a/deployments/deployments.json b/deployments/deployments.json index 2568a0dca8..36b69024c2 100644 --- a/deployments/deployments.json +++ b/deployments/deployments.json @@ -557,6 +557,7 @@ "osmosis.osmo-test-5": { "ibc_interface": "ibc-cosmwasm", "deployer": "osmo10c4yqddv6w7sphruvhxs5v0es8r9fcj5ed3yx7", + "manager": "osmo1managerhl8ka4alvaewkhflcc44m6385pf94zmrh2f4d3yzc2y4q4l623x", "core": { "address": "osmo1hnuj8f6d3wy3fcprt55vddv7v2650t6uudnvd2hukqrteeam8wjqata4fx", "height": 27869833,