Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depolama #3919

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ members = [
"cosmwasm/ucs03-zkgm-token-minter-api",
"cosmwasm/cw20-base",
"lib/scroll-types",
"lib/depolama",
]

[workspace.package]
Expand Down Expand Up @@ -223,6 +224,8 @@ cometbft-types = { path = "lib/cometbft-types", default-features = false }
concurrent-keyring = { path = "lib/concurrent-keyring", default-features = false }
cosmos-client = { path = "lib/cosmos-client", default-features = false }

depolama = { path = "lib/depolama", default-features = false }

state-lens-light-client-types = { path = "lib/state-lens-light-client-types", default-features = false }

arbitrum-light-client-types = { path = "lib/arbitrum-light-client-types", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/cosmwasm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
ucs03_type = "cw20";
bech32_prefix = "union";
apps = {
ucs03 = ucs03-configs.cw20;
# ucs03 = ucs03-configs.cw20;
};
# lightclients = pkgs.lib.lists.remove "cometbls" (builtins.attrNames all-lightclients);
lightclients = [ ];
Expand Down
104 changes: 93 additions & 11 deletions cosmwasm/deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ use cosmos_client::{
};
use cosmwasm_std::Addr;
use hex_literal::hex;
use protos::cosmwasm::wasm::v1::{
AccessConfig, AccessType, MsgExecuteContract, MsgExecuteContractResponse,
MsgInstantiateContract2, MsgInstantiateContract2Response, MsgMigrateContract,
MsgMigrateContractResponse, MsgStoreCode, MsgStoreCodeResponse, MsgUpdateInstantiateConfig,
MsgUpdateInstantiateConfigResponse, QuerySmartContractStateRequest,
QuerySmartContractStateResponse,
use protos::{
cosmos::base::query::v1beta1::PageRequest,
cosmwasm::wasm::v1::{
AccessConfig, AccessType, MsgExecuteContract, MsgExecuteContractResponse,
MsgInstantiateContract2, MsgInstantiateContract2Response, MsgMigrateContract,
MsgMigrateContractResponse, MsgStoreCode, MsgStoreCodeResponse, MsgUpdateInstantiateConfig,
MsgUpdateInstantiateConfigResponse, QueryAllContractStateRequest,
QueryAllContractStateResponse, QuerySmartContractStateRequest,
QuerySmartContractStateResponse,
},
};
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down Expand Up @@ -85,6 +89,8 @@ enum App {
#[arg(long)]
bech32_prefix: String,
},
#[command(subcommand)]
Query(QueryCmd),
}

#[derive(Debug, Clone, PartialEq, Default, clap::Args)]
Expand All @@ -103,6 +109,18 @@ enum QueryCmd {
#[arg(long)]
code_id: u64,
},
ContractState {
#[arg(long)]
rpc_url: String,
#[arg(long)]
output: Option<PathBuf>,
#[arg(long)]
address: Bech32<H256>,
#[arg(long)]
all: bool,
#[arg(long, default_value_t = 100)]
per_page: u64,
},
}

#[tokio::main]
Expand Down Expand Up @@ -272,10 +290,7 @@ async fn do_main() -> Result<()> {
MsgStoreCode {
sender: ctx.wallet().address().to_string(),
wasm_byte_code: BYTECODE_BASE_BYTECODE.to_vec(),
instantiate_permission: Some(AccessConfig {
permission: AccessType::Everybody.into(),
addresses: vec![],
}), // ..Default::default()
instantiate_permission: None,
},
"",
)
Expand Down Expand Up @@ -320,7 +335,6 @@ async fn do_main() -> Result<()> {
ucs03: None,
},
};

for (client_type, path) in contracts.lightclient {
let address = ctx
.deploy_and_initiate(
Expand Down Expand Up @@ -667,6 +681,74 @@ async fn do_main() -> Result<()> {
"{}",
CosmosSigner::from_raw(*private_key.get(), bech32_prefix).unwrap(),
),
App::Query(query_cmd) => match query_cmd {
QueryCmd::CodeInfo { rpc_url, code_id } => todo!(),
QueryCmd::ContractState {
rpc_url,
output,
address,
all,
per_page,
} => {
let client = cometbft_rpc::Client::new(rpc_url).await?;

if all {
let mut states = BTreeMap::<Bytes, Bytes>::new();

let mut pagination = PageRequest {
key: vec![],
offset: 0,
limit: per_page,
count_total: false,
reverse: false,
};

loop {
let state = client
.grpc_abci_query::<_, QueryAllContractStateResponse>(
"/cosmwasm.wasm.v1.Query/AllContractState",
&QueryAllContractStateRequest {
address: address.to_string(),
pagination: Some(pagination.clone()),
},
None,
false,
)
.await?
.into_result()?
.context("contract state response missing")?;

let p = state.pagination.unwrap();

info!(
"fetched page {} ({} items)",
<Bytes>::from(pagination.key),
state.models.len()
);

pagination = if p.next_key.is_empty() {
break;
} else {
PageRequest {
key: p.next_key,
..pagination
}
};

states.extend(
state
.models
.into_iter()
.map(|model| (model.key.into(), model.value.into())),
);
}

write_output(output, states)?;
} else {
todo!()
}
}
},
}

Ok(())
Expand Down
9 changes: 5 additions & 4 deletions cosmwasm/ibc-union/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ library = []
[dependencies]
alloy = { workspace = true, features = ["sol-types"] }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["abort"] }
cw-storage-plus = { workspace = true }
cosmwasm-std = { workspace = true, features = ["abort", "iterator"] }
cw-storage-plus = { workspace = true, features = ["iterator"] }
depolama = { workspace = true }
ethabi = { workspace = true }
hex = { workspace = true }
ibc-union-msg = { workspace = true }
ibc-union-spec = { workspace = true, features = ["ethabi", "serde"] }
ibc-union-spec = { workspace = true, features = ["ethabi", "serde", "bincode"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
strum = { version = "0.26.3", features = ["derive"] }
thiserror = { workspace = true }
unionlabs = { workspace = true, features = ["ethabi"] }
unionlabs = { workspace = true, features = ["ethabi", "bincode"] }
unionlabs-cosmwasm-upgradable = { workspace = true }
24 changes: 23 additions & 1 deletion cosmwasm/ibc-union/core/light-client-interface/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
use cosmwasm_std::Addr;
use cosmwasm_std::{Addr, StdError, StdResult};
use cw_storage_plus::Item;
// use depolama::{Prefix, Store, ValueCodec};
use unionlabs::primitives::Bytes;

pub const IBC_HOST: Item<Addr> = Item::new("ibc_host");

// pub enum IbcHost {}
// impl Store for IbcHost {
// const PREFIX: Prefix = Prefix::new(b"ibc_host");

// type Key = ();
// type Value = Addr;
// }

// impl ValueCodec<Addr> for IbcHost {
// fn encode_value(value: &Addr) -> Bytes {
// value.as_bytes().into()
// }

// fn decode_value(raw: &Bytes) -> StdResult<Addr> {
// String::from_utf8(raw.to_vec())
// .map(Addr::unchecked)
// .map_err(|e| StdError::generic_err(format!("invalid value: {e}")))
// }
// }
Loading
Loading