diff --git a/Cargo.lock b/Cargo.lock index c0d1afb8c56..9b34a4f6852 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3037,9 +3037,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cfg_aliases" @@ -3465,15 +3465,14 @@ dependencies = [ [[package]] name = "const-hex" -version = "1.14.1" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83e22e0ed40b96a48d3db274f72fd365bd78f67af39b6bbd47e8a15e1c6207ff" +checksum = "3bb320cac8a0750d7f25280aa97b09c26edfe161164238ecbbb31092b079e735" dependencies = [ "cfg-if", "cpufeatures", - "hex", "proptest", - "serde", + "serde_core", ] [[package]] @@ -3646,14 +3645,12 @@ dependencies = [ [[package]] name = "cosmwasm-core" version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35b6dc17e7fd89d0a0a58f12ef33f0bbdf09a6a14c3dfb383eae665e5889250e" +source = "git+https://github.com/benluelo/cosmwasm?branch=union-v2.2.2#6467e29dc410329696e9890f03982f2a971d9f0f" [[package]] name = "cosmwasm-crypto" version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa2f53285517db3e33d825b3e46301efe845135778527e1295154413b2f0469e" +source = "git+https://github.com/benluelo/cosmwasm?branch=union-v2.2.2#6467e29dc410329696e9890f03982f2a971d9f0f" dependencies = [ "ark-bls12-381 0.4.0", "ark-ec 0.4.2", @@ -3670,7 +3667,7 @@ dependencies = [ "rand_core 0.6.4", "rayon", "sha2 0.10.9", - "thiserror 1.0.69", + "thiserror 2.0.12", ] [[package]] @@ -3712,8 +3709,7 @@ dependencies = [ [[package]] name = "cosmwasm-derive" version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a782b93fae93e57ca8ad3e9e994e784583f5933aeaaa5c80a545c4b437be2047" +source = "git+https://github.com/benluelo/cosmwasm?branch=union-v2.2.2#6467e29dc410329696e9890f03982f2a971d9f0f" dependencies = [ "proc-macro2", "quote", @@ -3723,21 +3719,19 @@ dependencies = [ [[package]] name = "cosmwasm-schema" version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6984ab21b47a096e17ae4c73cea2123a704d4b6686c39421247ad67020d76f95" +source = "git+https://github.com/benluelo/cosmwasm?branch=union-v2.2.2#6467e29dc410329696e9890f03982f2a971d9f0f" dependencies = [ "cosmwasm-schema-derive", "schemars", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.12", ] [[package]] name = "cosmwasm-schema-derive" version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e01c9214319017f6ebd8e299036e1f717fa9bb6724e758f7d6fb2477599d1a29" +source = "git+https://github.com/benluelo/cosmwasm?branch=union-v2.2.2#6467e29dc410329696e9890f03982f2a971d9f0f" dependencies = [ "proc-macro2", "quote", @@ -3747,25 +3741,25 @@ dependencies = [ [[package]] name = "cosmwasm-std" version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf82335c14bd94eeb4d3c461b7aa419ecd7ea13c2efe24b97cd972bdb8044e7d" +source = "git+https://github.com/benluelo/cosmwasm?branch=union-v2.2.2#6467e29dc410329696e9890f03982f2a971d9f0f" dependencies = [ "base64 0.22.1", "bech32 0.11.0", "bnum 0.11.0", + "cfg-if", "cosmwasm-core", "cosmwasm-crypto", "cosmwasm-derive", "derive_more 1.0.0", + "ed25519-zebra", "hex", + "mini-alloc", "rand_core 0.6.4", - "rmp-serde", - "schemars", "serde", "serde-json-wasm", "sha2 0.10.9", "static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "thiserror 1.0.69", + "thiserror 2.0.12", ] [[package]] @@ -4152,12 +4146,14 @@ name = "cw-account" version = "0.0.0" dependencies = [ "bincode 2.0.1", + "cfg-if", "cosmwasm-std", "depolama", "embed-commit", "frissitheto", "hex-literal 0.4.1", "ibc-union-spec", + "mini-alloc", "schemars", "serde", "thiserror 2.0.12", @@ -4315,11 +4311,10 @@ dependencies = [ [[package]] name = "cw-storage-plus" version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f13360e9007f51998d42b1bc6b7fa0141f74feae61ed5fd1e5b0a89eec7b5de1" +source = "git+https://github.com/benluelo/cw-storage-plus?branch=union-v2.0.0#cd079e56e8e2d7e02ba2c13993494c2996efaf40" dependencies = [ "cosmwasm-std", - "schemars", + "ed25519-zebra", "serde", ] @@ -5243,16 +5238,17 @@ dependencies = [ [[package]] name = "ed25519-zebra" -version = "4.0.3" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" +checksum = "0017d969298eec91e3db7a2985a8cab4df6341d86e6f3a6f5878b13fb7846bc9" dependencies = [ "curve25519-dalek", "ed25519", - "hashbrown 0.14.5", - "hex", + "hashbrown 0.15.2", + "pkcs8 0.10.2", "rand_core 0.6.4", "sha2 0.10.9", + "subtle 2.6.1", "zeroize", ] @@ -5440,9 +5436,18 @@ dependencies = [ [[package]] name = "enumorph" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d3e2610493c0a1fc3bf33fb420650c6ebf7990c55e3d5e71a57bee374486824" +checksum = "57800a2ba81b2c7dbb6ac3db68bbc8bf2ed2b3a8d3da5515255cbc704ebe61bc" +dependencies = [ + "enumorph-derive", +] + +[[package]] +name = "enumorph-derive" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddf587caf60391b3c5fe3df755892b29dde3b5b8b64cfe848c093fbde0d6d92a" dependencies = [ "proc-macro2", "quote", @@ -7071,7 +7076,8 @@ dependencies = [ "serde-json-wasm", "strum 0.27.2", "thiserror 2.0.12", - "unionlabs", + "unionlabs-encoding", + "unionlabs-primitives", ] [[package]] @@ -7120,7 +7126,9 @@ dependencies = [ "sha3", "thiserror 2.0.12", "tracing", - "unionlabs", + "unionlabs-height", + "unionlabs-primitives", + "unionlabs-tuple", "voyager-primitives", ] @@ -7335,15 +7343,6 @@ dependencies = [ "parity-scale-codec 3.7.4", ] -[[package]] -name = "impl-rlp" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" -dependencies = [ - "rlp", -] - [[package]] name = "impl-serde" version = "0.3.2" @@ -8622,6 +8621,15 @@ dependencies = [ "unicase", ] +[[package]] +name = "mini-alloc" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b620761d4c29ede39bb1351c4360dba54d3b414d9fb460d37cba4c98b37a0b9d" +dependencies = [ + "cfg-if", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -10647,7 +10655,6 @@ checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash 0.8.0", "impl-codec 0.6.0", - "impl-rlp", "uint", ] @@ -11609,28 +11616,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "rmp" -version = "0.8.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" -dependencies = [ - "byteorder", - "num-traits", - "paste", -] - -[[package]] -name = "rmp-serde" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" -dependencies = [ - "byteorder", - "rmp", - "serde", -] - [[package]] name = "roaring" version = "0.10.12" @@ -12390,6 +12375,7 @@ dependencies = [ "chrono", "hex", "serde", + "thiserror 2.0.12", ] [[package]] @@ -14560,6 +14546,8 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "enumorph", + "schemars", + "serde", ] [[package]] @@ -15305,6 +15293,7 @@ dependencies = [ "hex-literal 0.4.1", "ibc-union-msg", "ibc-union-spec", + "mini-alloc", "schemars", "serde", "serde-json-wasm", @@ -15315,7 +15304,7 @@ dependencies = [ "ucs03-solvable", "ucs03-zkgm-token-minter-api", "ucs03-zkgmable", - "unionlabs", + "unionlabs-primitives", ] [[package]] @@ -15335,14 +15324,15 @@ dependencies = [ name = "ucs03-zkgm-token-minter-api" version = "0.0.0" dependencies = [ - "alloy", "alloy-primitives", + "alloy-sol-types", "cosmwasm-schema", "cosmwasm-std", "enumorph", "ibc-union-spec", + "serde", "token-factory-api", - "unionlabs", + "unionlabs-primitives", ] [[package]] @@ -15565,7 +15555,9 @@ dependencies = [ "thiserror 2.0.12", "typenum", "unionlabs-encoding", + "unionlabs-height", "unionlabs-primitives", + "unionlabs-tuple", ] [[package]] @@ -15582,6 +15574,19 @@ dependencies = [ "thiserror 2.0.12", ] +[[package]] +name = "unionlabs-height" +version = "0.0.0" +dependencies = [ + "bincode 2.0.1", + "prost 0.12.6", + "protos", + "schemars", + "serde", + "thiserror 2.0.12", + "unionlabs-encoding", +] + [[package]] name = "unionlabs-primitives" version = "0.0.0" @@ -15595,6 +15600,7 @@ dependencies = [ "hex", "primitive-types 0.12.2", "rlp", + "ruint", "schemars", "serde", "serde_bytes", @@ -15602,11 +15608,17 @@ dependencies = [ "subtle-encoding", "thiserror 2.0.12", "typenum", - "uint", "unionlabs", "unionlabs-primitives", ] +[[package]] +name = "unionlabs-tuple" +version = "0.0.0" +dependencies = [ + "macros", +] + [[package]] name = "unionvisor" version = "0.0.0" @@ -17176,7 +17188,8 @@ dependencies = [ "schemars", "serde", "serde_json", - "unionlabs", + "unionlabs-height", + "unionlabs-primitives", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c83703bc498..5c1ebc3caef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,8 @@ members = [ "lib/ssz-derive", "lib/unionlabs", "lib/unionlabs-primitives", + "lib/unionlabs-tuple", + "lib/unionlabs-height", "lib/unionlabs-encoding", # "lib/zktrie-rs", "lib/galois-rpc", @@ -316,9 +318,17 @@ module_name_repetitions = "allow" # dumb lint [workspace.lints.rustdoc] broken-intra-doc-links = "deny" -[profile.release] -lto = "thin" -opt-level = 3 +[profile.wasm-release] +inherits ="release" +codegen-units = 1 # prefer efficiency to compile time +panic = "abort" # use simple panics +opt-level = "z" # optimize for size ("s" may also work) +strip = "none" +lto = true # link time optimization +debug = false # no debug data +rpath = false # no run-time search path +debug-assertions = false # prune debug assertions +incremental = false # no incremental builds [workspace.dependencies] access-managed = { path = "cosmwasm/access-managed", default-features = false } @@ -424,7 +434,9 @@ ucs03-zkgmable = { path = "lib/ucs03-zkgmable", defau ucs04 = { path = "lib/ucs04", default-features = false } unionlabs = { path = "lib/unionlabs", default-features = false, features = ["proto"] } # TODO: Properly feature gate proto in unionlabs unionlabs-encoding = { path = "lib/unionlabs-encoding", default-features = false } +unionlabs-height = { path = "lib/unionlabs-height", default-features = false } unionlabs-primitives = { path = "lib/unionlabs-primitives", default-features = false } +unionlabs-tuple = { path = "lib/unionlabs-tuple", default-features = false } upgradable = { path = "cosmwasm/upgradable", default-features = false } voyager-client = { path = "lib/voyager-client", default-features = false } voyager-core = { path = "lib/voyager-core", default-features = false } @@ -453,12 +465,12 @@ wasm-client-type = { path = "lib/wasm-client-type", def alloy = { version = "1.0", default-features = false } alloy-primitives = { version = "1.1", default-features = false } -alloy-sol-types = { version = "1.1", default-features = true } +alloy-sol-types = { version = "1.1", default-features = false } anyhow = { version = "1" } axum = { version = "0.8", default-features = false } base64 = { version = "0.22", default-features = false } bcs = { version = "0.1.6", default-features = false } -bincode = { version = "2.0.1", default-features = false, features = ["std"] } # std is used by all dependants +bincode = { version = "2.0.1", default-features = false } bip32 = { version = "0.5.3", default-features = false } bitvec = { version = "1.0.1", default-features = false } borsh = { version = "1.5.7", default-features = false } @@ -467,7 +479,7 @@ chrono = { version = "0.4.41", default-features = false } clap = { version = "4.5.39", default-features = false, features = ["std"] } # clap has a fake std feature that is required to be enabled by default color-eyre = { version = "0.6.5", default-features = false } cosmwasm-schema = { version = "2.2.2", default-features = false } -cosmwasm-std = { version = "2.2.2", default-features = false, features = ["std"] } # cosmwasm-std has a fake std feature that is requried to be enabled by default +cosmwasm-std = { version = "2.2.2", default-features = false } # cosmwasm-std has a fake std feature that is requried to be enabled by default crossbeam-queue = { version = "0.3.12", default-features = false } cw-orch = { version = "0.27.0", default-features = false } cw-storage-plus = { version = "2.0.0", default-features = false } @@ -477,12 +489,12 @@ dashmap = { version = "5.5.3", default-features = false } derive_more = { version = "0.99.20", default-features = false } ed25519-dalek = { version = "2.1.1", default-features = false } either = { version = "1.15.0", default-features = false } -enumorph = { version = "0.1.2", default-features = false } +enumorph = { version = "0.1.3", default-features = false } ethabi = { version = "18.0.0", default-features = false } frame-support-procedural = { version = "30.0.6", default-features = false } futures = { version = "0.3.31", default-features = false } generic-array = { version = "0.14.7", default-features = false } -hex = { version = "0.4.3", default-features = false } +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } # alloc is used by all dependants hex-literal = { version = "0.4.1", default-features = false } itertools = { version = "0.13" } jsonrpsee = { version = "0.25.1", default-features = false } @@ -490,6 +502,7 @@ lazy_static = { version = "1.5.0", default-features = false } moka = { version = "0.12.10", default-features = false } near-sdk = { version = "5.14.0", default-features = false } num-bigint = { version = "0.4", default-features = false } +num-traits = { version = "0.2.19", default-features = false } opentelemetry = { version = "0.29.1", default-features = false } opentelemetry-otlp = { version = "0.29.0", default-features = false } opentelemetry_sdk = { version = "0.29.0", default-features = false } @@ -502,8 +515,9 @@ reqwest = { version = "0.11.27", default-features = false } reth-ipc = { git = "https://github.com/paradigmxyz/reth", default-features = false } ripemd = { version = "0.1.3", default-features = false } rlp = { version = "0.5.2", default-features = false } +ruint = { version = "1.17.0", default-features = false } schemars = { version = "0.8.22", default-features = false } -serde = { version = "1.0.219", default-features = false } +serde = { version = "1.0.219", default-features = false, features = ["alloc"] } serde-json-wasm = { version = "1.0.1", default-features = false } serde_json = { version = "1.0.140", default-features = false, features = ["alloc"] } # serde-json requires one of "std" or "alloc" serde_with = { version = "3.12.0", default-features = false, features = ["macros"] } @@ -540,3 +554,13 @@ serde-json-wasm = { git = "https://github.com/benluelo/serde-json-wasm", branch # # https://aptos.dev/en/build/sdks/rust-sdk # merlin = { git = "https://github.com/aptos-labs/merlin" } # x25519-dalek = { git = "https://github.com/aptos-labs/x25519-dalek", branch = "zeroize_v1" } + +# cosmwasm-schema = { path = "../../cosmwasm/cosmwasm/packages/schema" } +# cosmwasm-std = { path = "../../cosmwasm/cosmwasm/packages/std" } +# cw-storage-plus = { path = "../../cosmwasm/cw-storage-plus" } + +cosmwasm-schema = { git = "https://github.com/benluelo/cosmwasm", branch = "union-v2.2.2" } +cosmwasm-std = { git = "https://github.com/benluelo/cosmwasm", branch = "union-v2.2.2" } +cw-storage-plus = { git = "https://github.com/benluelo/cw-storage-plus", branch = "union-v2.0.0" } + +# enumorph = { path = "../../benluelo/enumorph" } diff --git a/cosmwasm/access-managed/Cargo.toml b/cosmwasm/access-managed/Cargo.toml index 3b2ecfd6a0d..17f6a91fc92 100644 --- a/cosmwasm/access-managed/Cargo.toml +++ b/cosmwasm/access-managed/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] access-manager-types = { workspace = true } bincode = { workspace = true, features = ["derive"] } diff --git a/cosmwasm/access-manager/Cargo.toml b/cosmwasm/access-manager/Cargo.toml index 85de7047955..f1128cead94 100644 --- a/cosmwasm/access-manager/Cargo.toml +++ b/cosmwasm/access-manager/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] access-manager-types = { workspace = true } bincode = { workspace = true, features = ["derive"] } diff --git a/cosmwasm/cw-account/Cargo.toml b/cosmwasm/cw-account/Cargo.toml index d8f16a9e050..dbc12d8511b 100644 --- a/cosmwasm/cw-account/Cargo.toml +++ b/cosmwasm/cw-account/Cargo.toml @@ -8,19 +8,18 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true [dependencies] bincode = { workspace = true, features = ["derive"] } +cfg-if = "1.0.4" cosmwasm-std = { workspace = true, features = ["cosmwasm_2_0", "staking", "stargate"] } # enable all features so that any message is dispatchable depolama = { workspace = true, features = ["iterator"] } embed-commit = { workspace = true } frissitheto = { workspace = true } ibc-union-spec = { workspace = true, features = ["bincode"] } +mini-alloc = "1.0.0" schemars = { workspace = true, optional = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } diff --git a/cosmwasm/cw-account/src/lib.rs b/cosmwasm/cw-account/src/lib.rs index 186ca0f6569..d9deb69a800 100644 --- a/cosmwasm/cw-account/src/lib.rs +++ b/cosmwasm/cw-account/src/lib.rs @@ -1,4 +1,25 @@ -use std::num::NonZeroU32; +#![no_std] + +extern crate alloc; + +cfg_if::cfg_if! { + if #[cfg(not(feature = "library"))] { + #[global_allocator] + static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT; + + #[panic_handler] + fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} + } + } +} + +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + vec::Vec, +}; +use core::{iter::Iterator, num::NonZeroU32}; use cosmwasm_std::{ Addr, Binary, CosmosMsg, Deps, DepsMut, Env, Event, MessageInfo, Order, Response, StdError, @@ -221,7 +242,7 @@ pub fn migrate( let res = init(deps, init_msg); Ok((res, None)) }, - |_, _, _| Ok((Response::default(), None)), + |_, _, _| Ok((Response::new(), None)), ) } diff --git a/cosmwasm/cw-account/src/msg.rs b/cosmwasm/cw-account/src/msg.rs index ffed42ee044..419ee381413 100644 --- a/cosmwasm/cw-account/src/msg.rs +++ b/cosmwasm/cw-account/src/msg.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use cosmwasm_std::{Addr, CosmosMsg}; use depolama::Bytes; use ibc_union_spec::ChannelId; diff --git a/cosmwasm/cw-account/src/types.rs b/cosmwasm/cw-account/src/types.rs index b138f393bfc..7f2e92e9734 100644 --- a/cosmwasm/cw-account/src/types.rs +++ b/cosmwasm/cw-account/src/types.rs @@ -1,3 +1,4 @@ +use alloc::string::String; use core::fmt; use depolama::Bytes; diff --git a/cosmwasm/cw-escrow-vault/Cargo.toml b/cosmwasm/cw-escrow-vault/Cargo.toml index d3fb034dc8e..bdb1f61e49a 100644 --- a/cosmwasm/cw-escrow-vault/Cargo.toml +++ b/cosmwasm/cw-escrow-vault/Cargo.toml @@ -8,9 +8,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/cosmwasm/cw-unionversal-token/Cargo.toml b/cosmwasm/cw-unionversal-token/Cargo.toml index 1429980d5aa..f31d28762c1 100644 --- a/cosmwasm/cw-unionversal-token/Cargo.toml +++ b/cosmwasm/cw-unionversal-token/Cargo.toml @@ -8,9 +8,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/cosmwasm/cw20-base/Cargo.toml b/cosmwasm/cw20-base/Cargo.toml index 144a660331f..278fa2c082a 100644 --- a/cosmwasm/cw20-base/Cargo.toml +++ b/cosmwasm/cw20-base/Cargo.toml @@ -9,9 +9,6 @@ name = "cw20-base" repository = "https://github.com/CosmWasm/cw-plus" version = "0.0.0" -[lib] -crate-type = ["cdylib", "rlib"] - [features] # use library feature to disable all instantiate/execute/query exports library = [] diff --git a/cosmwasm/cw20-token-minter/Cargo.toml b/cosmwasm/cw20-token-minter/Cargo.toml index 04fd83cb5bb..79ee471c842 100644 --- a/cosmwasm/cw20-token-minter/Cargo.toml +++ b/cosmwasm/cw20-token-minter/Cargo.toml @@ -8,9 +8,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/cosmwasm/cw20-wrapped-tokenfactory/Cargo.toml b/cosmwasm/cw20-wrapped-tokenfactory/Cargo.toml index 989ee47fdf1..4921523b47f 100644 --- a/cosmwasm/cw20-wrapped-tokenfactory/Cargo.toml +++ b/cosmwasm/cw20-wrapped-tokenfactory/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [features] # use library feature to disable all instantiate/execute/query exports library = [] diff --git a/cosmwasm/ibc-union/app/ucs00-pingpong/Cargo.toml b/cosmwasm/ibc-union/app/ucs00-pingpong/Cargo.toml index e25bed81eda..fc2c978efdc 100644 --- a/cosmwasm/ibc-union/app/ucs00-pingpong/Cargo.toml +++ b/cosmwasm/ibc-union/app/ucs00-pingpong/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [features] library = [] diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/Cargo.toml b/cosmwasm/ibc-union/app/ucs03-zkgm/Cargo.toml index e652898df1b..56399edca70 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/Cargo.toml +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/Cargo.toml @@ -11,20 +11,18 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] alloy-primitives = { workspace = true } alloy-sol-types = { workspace = true } -cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true, features = ["cosmwasm_1_2", "cosmwasm_1_4", "staking"] } -cw-account = { workspace = true } +cosmwasm-schema = { workspace = true, optional = true } +cosmwasm-std = { workspace = true, features = ["cosmwasm_1_2", "cosmwasm_1_4", "staking", "panic_handler", "global_allocator"] } +cw-account = { workspace = true, features = ["library"] } cw-storage-plus = { workspace = true } embed-commit = { workspace = true } frissitheto = { workspace = true } ibc-union-msg = { workspace = true } ibc-union-spec = { workspace = true, features = ["serde", "ethabi"] } +mini-alloc = "1.0.0" schemars = { workspace = true, features = ["derive"], optional = true } serde = { workspace = true, features = ["derive"] } serde-json-wasm = { workspace = true } @@ -34,7 +32,7 @@ token-factory-api = { workspace = true } ucs03-solvable = { workspace = true } ucs03-zkgm-token-minter-api = { workspace = true } ucs03-zkgmable = { workspace = true } -unionlabs = { workspace = true, features = ["ethabi", "schemars"] } +unionlabs-primitives = { workspace = true } [dev-dependencies] cw-multi-test = { version = "=2.4", features = ["cosmwasm_2_2"] } @@ -47,5 +45,7 @@ serde_json = { workspace = true } [features] default = [] + library = [] -schemars = ["dep:schemars", "ibc-union-msg/schemars"] + +schemars = ["dep:schemars", "ibc-union-msg/schemars", "dep:cosmwasm-schema"] diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/com.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/com.rs index 94f20f3d232..a30b73d6aad 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/com.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/com.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use alloy_primitives::U256; use ucs03_solvable::CwTokenOrderV2; diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs index c6bfe73e34b..504260a489a 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/contract.rs @@ -1,7 +1,15 @@ -use core::str; -use std::{slice, str::FromStr}; +use alloc::{ + format, + string::{String, ToString}, + vec, + vec::Vec, +}; +use core::{ + slice, + str::{self, FromStr}, +}; -use alloy_primitives::U256; +use alloy_primitives::{U256, keccak256}; use alloy_sol_types::SolValue; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; @@ -17,17 +25,14 @@ use ibc_union_msg::{ msg::{MsgSendPacket, MsgWriteAcknowledgement}, }; use ibc_union_spec::{ChannelId, MustBeZero, Packet, Timestamp, path::BatchPacketsPath}; +use serde::{Deserialize, Serialize}; use ucs03_solvable::Solvable; use ucs03_zkgm_token_minter_api::{ LocalTokenMsg, Metadata, MetadataResponse, WrappedTokenKind, WrappedTokenMsg, new_wrapped_token_event, }; use ucs03_zkgmable::{OnIntentZkgm, OnZkgm, Zkgmable}; -use unionlabs::{ - ethereum::keccak256, - never::Never, - primitives::{Bytes, H256, encoding::HexPrefixed}, -}; +use unionlabs_primitives::{Bytes, H256, encoding::HexPrefixed}; use crate::{ ContractError, @@ -1539,7 +1544,7 @@ fn execute_call( WasmMsg::Migrate { contract_addr: predicted_address.to_string(), new_code_id: cw_account_code_id, - msg: to_json_binary(&frissitheto::UpgradeMsg::<_, Never>::Init( + msg: to_json_binary(&frissitheto::UpgradeMsg::<_, ()>::Init( cw_account::msg::InitMsg::Zkgm { zkgm: env.contract.address.clone(), path: path.into(), @@ -2314,7 +2319,7 @@ fn protocol_fill_mint( METADATA_IMAGE_OF.save( deps.storage, wrapped_token.clone(), - &keccak256(metadata.abi_encode_params()), + &keccak256(metadata.abi_encode_params()).into(), )?; } @@ -2994,7 +2999,7 @@ pub fn send( source_channel_id: channel_id, timeout_timestamp, data: ZkgmPacket { - salt: hashed_salt.into(), + salt: hashed_salt, path: U256::ZERO, instruction, } @@ -3005,7 +3010,7 @@ pub fn send( )?)) } -#[cosmwasm_schema::cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TokenMinterMigration { // code id of the new token minter new_code_id: u64, @@ -3016,7 +3021,7 @@ pub struct TokenMinterMigration { // The current structure is expected to be backward compatible, only idempotent // fields can be currently added. -#[cosmwasm_schema::cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct MigrateMsg { // Provide `token_minter_migration` to also migrate the token minter token_minter_migration: Option, @@ -3312,12 +3317,12 @@ fn predict_wrapped_token_v2( path, channel_id, token, - metadata_image, + metadata_image.into(), ) } pub fn derive_batch_salt(index: U256, salt: H256) -> H256 { - keccak256((index, salt.get()).abi_encode()) + keccak256((index, salt.get()).abi_encode()).into() } pub fn dequeue_channel_from_path(path: U256) -> (U256, Option) { @@ -3403,7 +3408,7 @@ pub fn is_forwarded_packet(salt: H256) -> bool { } pub fn derive_forward_salt(salt: H256) -> H256 { - tint_forward_salt(keccak256(salt.abi_encode())) + tint_forward_salt(keccak256(salt.abi_encode()).into()) } fn migrate_v1_to_v2( @@ -3498,6 +3503,7 @@ pub fn proxy_account_salt( ) .abi_encode_params(), ) + .into() } #[test] diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/lib.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/lib.rs index 5022f7d93e1..c3b2f9cf4ab 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/lib.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/lib.rs @@ -1,9 +1,19 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +use alloc::{ + borrow::ToOwned, + string::{String, ToString}, +}; + use alloy_primitives::{U256, ruint::ParseError}; use cosmwasm_std::{Instantiate2AddressError, StdError}; use frissitheto::UpgradeError; use ibc_union_spec::ChannelId; use thiserror::Error; -use unionlabs::primitives::Bytes; +use unionlabs_primitives::Bytes; pub mod com; pub mod contract; diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs index 07934c8c5d4..6ec27895a63 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/msg.rs @@ -1,8 +1,10 @@ +use alloc::{string::String, vec::Vec}; + use cosmwasm_std::{Addr, CosmosMsg, Uint64, Uint256}; use ibc_union_spec::{ChannelId, Packet, Timestamp}; use serde::{Deserialize, Serialize}; use ucs03_zkgm_token_minter_api::TokenMinterInitMsg; -use unionlabs::primitives::{Bytes, H256}; +use unionlabs_primitives::{Bytes, H256}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/state.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/state.rs index dc44b19e896..bba46720a3f 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/state.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/state.rs @@ -1,8 +1,10 @@ +use alloc::{string::String, vec::Vec}; + use cosmwasm_std::{Addr, Uint256}; use cw_storage_plus::{Item, Map}; use ibc_union_spec::{ChannelId, Packet}; use serde::{Deserialize, Serialize}; -use unionlabs::primitives::{Bytes, H256, U256}; +use unionlabs_primitives::{Bytes, H256, U256}; use crate::{msg::Config, token_bucket::TokenBucket}; diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/tests.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/tests.rs index d52f72b4074..2dd65c0d081 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/tests.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/tests.rs @@ -12,10 +12,7 @@ use cw20::{Cw20Coin, Cw20QueryMsg, TokenInfoResponse}; use cw20_token_minter::contract::{Cw20TokenMinterImplementation, save_native_token}; use ibc_union_msg::module::IbcUnionMsg; use ibc_union_spec::{ChannelId, ConnectionId, MustBeZero, Packet, path::commit_packets}; -use unionlabs::{ - ethereum::keccak256, - primitives::{Bytes, H256}, -}; +use unionlabs_primitives::{Bytes, H256}; use crate::{ ContractError, diff --git a/cosmwasm/ibc-union/app/ucs03-zkgm/src/token_bucket.rs b/cosmwasm/ibc-union/app/ucs03-zkgm/src/token_bucket.rs index 6a932796ca3..046dc6e45b3 100644 --- a/cosmwasm/ibc-union/app/ucs03-zkgm/src/token_bucket.rs +++ b/cosmwasm/ibc-union/app/ucs03-zkgm/src/token_bucket.rs @@ -1,5 +1,5 @@ -use cosmwasm_schema::cw_serde; use cosmwasm_std::Uint256; +use serde::{Deserialize, Serialize}; use thiserror::Error; #[derive(Error, Debug, PartialEq)] @@ -12,7 +12,7 @@ pub enum Error { RateLimitExceeded, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TokenBucket { pub capacity: Uint256, pub available: Uint256, diff --git a/cosmwasm/ibc-union/app/ucs06-funded-dispatch/Cargo.toml b/cosmwasm/ibc-union/app/ucs06-funded-dispatch/Cargo.toml index 98662de0d9b..5f19497ad42 100644 --- a/cosmwasm/ibc-union/app/ucs06-funded-dispatch/Cargo.toml +++ b/cosmwasm/ibc-union/app/ucs06-funded-dispatch/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [features] library = [] diff --git a/cosmwasm/ibc-union/core/Cargo.toml b/cosmwasm/ibc-union/core/Cargo.toml index 81a2767ba54..f0a73aa2dd3 100644 --- a/cosmwasm/ibc-union/core/Cargo.toml +++ b/cosmwasm/ibc-union/core/Cargo.toml @@ -11,31 +11,33 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - -[features] -cw-orch-interface = ["dep:cw-orch", "ibc-union-msg/cw-orch-interface"] -library = [] - [dependencies] -alloy-primitives = { workspace = true } -alloy-sol-types = { workspace = true } -cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true, features = ["abort", "iterator"] } -cw-orch = { workspace = true, optional = true } -depolama = { workspace = true } -embed-commit = { workspace = true } -ethabi = { workspace = true } -frissitheto = { workspace = true } -hex = { workspace = true } -ibc-union-msg = { workspace = true } -ibc-union-spec = { workspace = true, features = ["ethabi", "serde", "bincode"] } -serde = { workspace = true, features = ["derive"] } -serde-json-wasm = { workspace = true } -strum = { workspace = true, features = ["derive"] } -thiserror = { workspace = true } -unionlabs = { workspace = true, features = ["ethabi", "bincode"] } +alloy-primitives = { workspace = true } +alloy-sol-types = { workspace = true } +cosmwasm-schema = { workspace = true, optional = true } +cosmwasm-std = { workspace = true, features = ["abort", "iterator", "panic_handler", "global_allocator"] } +cw-orch = { workspace = true, optional = true } +depolama = { workspace = true } +embed-commit = { workspace = true } +ethabi = { workspace = true } +frissitheto = { workspace = true } +hex = { workspace = true } +ibc-union-msg = { workspace = true } +ibc-union-spec = { workspace = true, features = ["ethabi", "serde", "bincode"] } +serde = { workspace = true, features = ["derive"] } +serde-json-wasm = { workspace = true } +strum = { workspace = true, features = ["derive"] } +thiserror = { workspace = true } +unionlabs-encoding = { workspace = true, features = ["bincode"] } +unionlabs-primitives = { workspace = true } [dev-dependencies] hex-literal = { workspace = true } + +[features] +default = [] + +library = [] + +cw-orch-interface = ["schemars", "dep:cw-orch", "ibc-union-msg/cw-orch-interface"] +schemars = ["dep:cosmwasm-schema"] diff --git a/cosmwasm/ibc-union/core/msg/Cargo.toml b/cosmwasm/ibc-union/core/msg/Cargo.toml index 2bb3a2f125f..9cd89929170 100644 --- a/cosmwasm/ibc-union/core/msg/Cargo.toml +++ b/cosmwasm/ibc-union/core/msg/Cargo.toml @@ -12,8 +12,12 @@ repository = { workspace = true } workspace = true [features] +default = [] + +std = ["cosmwasm-std/std"] + cw-orch-interface = ["schemars", "dep:cw-orch", "dep:cosmwasm-std", "dep:cosmwasm-schema"] -schemars = ["dep:schemars", "unionlabs-primitives/schemars", "ibc-union-spec/schemars"] +schemars = ["std", "dep:schemars", "unionlabs-primitives/schemars", "ibc-union-spec/schemars"] [dependencies] ibc-union-spec = { workspace = true, features = ["serde"] } diff --git a/cosmwasm/ibc-union/core/msg/src/lib.rs b/cosmwasm/ibc-union/core/msg/src/lib.rs index 3540baa5191..f123871f40c 100644 --- a/cosmwasm/ibc-union/core/msg/src/lib.rs +++ b/cosmwasm/ibc-union/core/msg/src/lib.rs @@ -1,3 +1,7 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + pub mod lightclient; pub mod module; pub mod msg; diff --git a/cosmwasm/ibc-union/core/msg/src/lightclient.rs b/cosmwasm/ibc-union/core/msg/src/lightclient.rs index 121b151bf79..82bd8180440 100644 --- a/cosmwasm/ibc-union/core/msg/src/lightclient.rs +++ b/cosmwasm/ibc-union/core/msg/src/lightclient.rs @@ -1,4 +1,4 @@ -use std::collections::BTreeMap; +use alloc::{collections::BTreeMap, string::String, vec::Vec}; use ibc_union_spec::ClientId; use unionlabs_primitives::Bytes; diff --git a/cosmwasm/ibc-union/core/msg/src/module.rs b/cosmwasm/ibc-union/core/msg/src/module.rs index 29bc71f703e..6cec325a1da 100644 --- a/cosmwasm/ibc-union/core/msg/src/module.rs +++ b/cosmwasm/ibc-union/core/msg/src/module.rs @@ -1,3 +1,5 @@ +use alloc::string::String; + use ibc_union_spec::{ChannelId, ConnectionId, Packet}; use serde::{Deserialize, Serialize}; use unionlabs_primitives::Bytes; diff --git a/cosmwasm/ibc-union/core/msg/src/msg.rs b/cosmwasm/ibc-union/core/msg/src/msg.rs index a0da95d66af..869f4981a85 100644 --- a/cosmwasm/ibc-union/core/msg/src/msg.rs +++ b/cosmwasm/ibc-union/core/msg/src/msg.rs @@ -1,3 +1,5 @@ +use alloc::{string::String, vec::Vec}; + use ibc_union_spec::{Channel, ChannelId, ClientId, ConnectionId, Packet, Timestamp}; use serde::{Deserialize, Serialize}; use unionlabs_primitives::Bytes; diff --git a/cosmwasm/ibc-union/core/msg/src/query.rs b/cosmwasm/ibc-union/core/msg/src/query.rs index 88446b6b7f2..e6caaa837ea 100644 --- a/cosmwasm/ibc-union/core/msg/src/query.rs +++ b/cosmwasm/ibc-union/core/msg/src/query.rs @@ -1,3 +1,5 @@ +use alloc::string::String; + use ibc_union_spec::{ChannelId, ClientId, ConnectionId}; use unionlabs_primitives::{Bytes, H256}; #[derive(serde::Serialize, serde::Deserialize, Debug)] diff --git a/cosmwasm/ibc-union/core/src/contract.rs b/cosmwasm/ibc-union/core/src/contract.rs index 392de87f997..4933ff27648 100644 --- a/cosmwasm/ibc-union/core/src/contract.rs +++ b/cosmwasm/ibc-union/core/src/contract.rs @@ -1,6 +1,13 @@ -use core::slice; -use std::{collections::BTreeSet, num::NonZeroU32}; +use alloc::{ + boxed::Box, + collections::BTreeSet, + string::{String, ToString}, + vec, + vec::Vec, +}; +use core::{num::NonZeroU32, slice}; +use alloy_primitives::keccak256; use alloy_sol_types::SolValue; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; @@ -37,10 +44,7 @@ use ibc_union_spec::{ }, }; use serde::{Deserialize, Serialize, de::DeserializeOwned}; -use unionlabs::{ - ethereum::keccak256, - primitives::{Bytes, H256}, -}; +use unionlabs_primitives::{Bytes, H256}; use crate::{ ContractError, @@ -652,8 +656,8 @@ fn migrate_state( mut deps: DepsMut, sender: Addr, client_id: ClientId, - client_state: unionlabs::primitives::Bytes, - consensus_state: unionlabs::primitives::Bytes, + client_state: unionlabs_primitives::Bytes, + consensus_state: unionlabs_primitives::Bytes, height: u64, ) -> Result { let client_addr = deps.storage.read::(&client_id)?; @@ -705,7 +709,7 @@ pub fn instantiate(_: DepsMut, _: Env, _: MessageInfo, _: ()) -> StdResult Result { } fn commit(bytes: impl AsRef<[u8]>) -> H256 { - keccak256(bytes) + keccak256(bytes).into() } fn commit_ack(ack: &Bytes) -> H256 { diff --git a/cosmwasm/ibc-union/core/src/lib.rs b/cosmwasm/ibc-union/core/src/lib.rs index c83747734d7..bffeec2526d 100644 --- a/cosmwasm/ibc-union/core/src/lib.rs +++ b/cosmwasm/ibc-union/core/src/lib.rs @@ -1,4 +1,6 @@ -#![cfg_attr(not(test), warn(clippy::unwrap_used))] +#![cfg_attr(not(test), no_std, warn(clippy::unwrap_used))] + +extern crate alloc; pub mod contract; #[cfg(feature = "cw-orch-interface")] @@ -8,11 +10,13 @@ pub mod state; #[cfg(test)] mod tests; +use alloc::boxed::Box; + use cosmwasm_std::{Addr, StdError}; use frissitheto::UpgradeError; use ibc_union_spec::{ChannelId, ChannelState, ClientId, ConnectionState, Status, Timestamp}; use thiserror::Error; -use unionlabs::primitives::Bytes; +use unionlabs_primitives::Bytes; #[derive(Error, Debug, PartialEq, strum::EnumDiscriminants)] #[strum_discriminants( diff --git a/cosmwasm/ibc-union/core/src/state.rs b/cosmwasm/ibc-union/core/src/state.rs index 0fe6904b404..5f358076086 100644 --- a/cosmwasm/ibc-union/core/src/state.rs +++ b/cosmwasm/ibc-union/core/src/state.rs @@ -1,4 +1,5 @@ -use std::{collections::BTreeSet, marker::PhantomData}; +use alloc::{collections::BTreeSet, format, string::String}; +use core::marker::PhantomData; use cosmwasm_std::{Addr, StdError, StdResult}; use depolama::{ @@ -6,10 +7,8 @@ use depolama::{ value::{ValueCodecViaEncoding, ValueUnitEncoding}, }; use ibc_union_spec::{Channel, ChannelId, ClientId, Connection, ConnectionId}; -use unionlabs::{ - encoding::Bincode, - primitives::{ByteArrayExt, Bytes, H256}, -}; +use unionlabs_encoding::Bincode; +use unionlabs_primitives::{ByteArrayExt, Bytes, H256}; macro_rules! id_key { ($ty:ty) => { diff --git a/cosmwasm/ibc-union/lightclient/attested/Cargo.toml b/cosmwasm/ibc-union/lightclient/attested/Cargo.toml index 9abd95e2798..68a6f44e3e8 100644 --- a/cosmwasm/ibc-union/lightclient/attested/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/attested/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] attested-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] } bincode = { workspace = true, features = ["derive"] } diff --git a/cosmwasm/ibc-union/lightclient/base/Cargo.toml b/cosmwasm/ibc-union/lightclient/base/Cargo.toml index d878ff90f88..0d08164be94 100644 --- a/cosmwasm/ibc-union/lightclient/base/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/base/Cargo.toml @@ -14,9 +14,6 @@ workspace = true [package.metadata.crane] test-include = [] -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] base-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] } base-verifier = { workspace = true } diff --git a/cosmwasm/ibc-union/lightclient/bob/Cargo.toml b/cosmwasm/ibc-union/lightclient/bob/Cargo.toml index f86bd37fc74..246b601383c 100644 --- a/cosmwasm/ibc-union/lightclient/bob/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/bob/Cargo.toml @@ -14,9 +14,6 @@ workspace = true [package.metadata.crane] test-include = [] -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] bob-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] } bob-verifier = { workspace = true } diff --git a/cosmwasm/ibc-union/lightclient/parlia/Cargo.toml b/cosmwasm/ibc-union/lightclient/parlia/Cargo.toml index a24cdaeb035..60a5f0273a9 100644 --- a/cosmwasm/ibc-union/lightclient/parlia/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/parlia/Cargo.toml @@ -14,9 +14,6 @@ workspace = true [package.metadata.crane] test-include = [] -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cosmwasm-std = { workspace = true, features = ["abort", "cosmwasm_2_1"] } depolama = { workspace = true } diff --git a/cosmwasm/ibc-union/lightclient/scroll/Cargo.toml b/cosmwasm/ibc-union/lightclient/scroll/Cargo.toml index 791377d3717..f75e85fd08e 100644 --- a/cosmwasm/ibc-union/lightclient/scroll/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/scroll/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cosmwasm-std = { workspace = true, features = ["abort"] } embed-commit = { workspace = true } diff --git a/cosmwasm/ibc-union/lightclient/state-lens-ics23-ics23/Cargo.toml b/cosmwasm/ibc-union/lightclient/state-lens-ics23-ics23/Cargo.toml index 7ef475ab374..2101f2044f2 100644 --- a/cosmwasm/ibc-union/lightclient/state-lens-ics23-ics23/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/state-lens-ics23-ics23/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cometbls-light-client = { workspace = true } cosmwasm-std = { workspace = true, features = ["abort"] } diff --git a/cosmwasm/ibc-union/lightclient/state-lens-ics23-mpt/Cargo.toml b/cosmwasm/ibc-union/lightclient/state-lens-ics23-mpt/Cargo.toml index 798cb64f9be..875698ba74e 100644 --- a/cosmwasm/ibc-union/lightclient/state-lens-ics23-mpt/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/state-lens-ics23-mpt/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cometbls-light-client = { workspace = true, features = ["library"] } cosmwasm-std = { workspace = true, features = ["abort"] } diff --git a/cosmwasm/ibc-union/lightclient/state-lens-ics23-smt/Cargo.toml b/cosmwasm/ibc-union/lightclient/state-lens-ics23-smt/Cargo.toml index 8fcb806ecc9..66d4ae09827 100644 --- a/cosmwasm/ibc-union/lightclient/state-lens-ics23-smt/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/state-lens-ics23-smt/Cargo.toml @@ -9,9 +9,6 @@ version = "0.0.0" [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] aptos-verifier = { workspace = true } bcs = { workspace = true } diff --git a/cosmwasm/ibc-union/lightclient/sui/Cargo.toml b/cosmwasm/ibc-union/lightclient/sui/Cargo.toml index f8a6475a47c..e77310dc59b 100644 --- a/cosmwasm/ibc-union/lightclient/sui/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/sui/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] bcs = { workspace = true } bincode = { workspace = true } diff --git a/cosmwasm/ibc-union/lightclient/tendermint/Cargo.toml b/cosmwasm/ibc-union/lightclient/tendermint/Cargo.toml index 821227543e2..0e25d42ae58 100644 --- a/cosmwasm/ibc-union/lightclient/tendermint/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/tendermint/Cargo.toml @@ -14,9 +14,6 @@ workspace = true [package.metadata.crane] test-include = ["cosmwasm/ibc-union/lightclient/tendermint/src/test"] -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cometbft-types = { workspace = true, features = ["hash"] } cosmwasm-std = { workspace = true, features = ["abort", "iterator"] } diff --git a/cosmwasm/ibc-union/lightclient/trusted-mpt/Cargo.toml b/cosmwasm/ibc-union/lightclient/trusted-mpt/Cargo.toml index 56877bf8a0e..379c830ba8b 100644 --- a/cosmwasm/ibc-union/lightclient/trusted-mpt/Cargo.toml +++ b/cosmwasm/ibc-union/lightclient/trusted-mpt/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cosmwasm-std = { workspace = true, features = ["abort"] } embed-commit = { workspace = true } diff --git a/cosmwasm/lst-staker/Cargo.toml b/cosmwasm/lst-staker/Cargo.toml index 2677663dc56..2882823a643 100644 --- a/cosmwasm/lst-staker/Cargo.toml +++ b/cosmwasm/lst-staker/Cargo.toml @@ -8,9 +8,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/cosmwasm/lst/Cargo.toml b/cosmwasm/lst/Cargo.toml index cfead5f8b28..8ef94b4edb5 100644 --- a/cosmwasm/lst/Cargo.toml +++ b/cosmwasm/lst/Cargo.toml @@ -4,9 +4,6 @@ license-file = "LICENSE" name = "lst" version = "0.0.0" -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/cosmwasm/multicall/Cargo.toml b/cosmwasm/multicall/Cargo.toml index 35db86142fc..c7fdae800a2 100644 --- a/cosmwasm/multicall/Cargo.toml +++ b/cosmwasm/multicall/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [features] library = [] diff --git a/cosmwasm/on-zkgm-call-proxy/Cargo.toml b/cosmwasm/on-zkgm-call-proxy/Cargo.toml index feb697a8940..4a3fda7aa24 100644 --- a/cosmwasm/on-zkgm-call-proxy/Cargo.toml +++ b/cosmwasm/on-zkgm-call-proxy/Cargo.toml @@ -8,9 +8,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/cosmwasm/osmosis-tokenfactory-token-minter/Cargo.toml b/cosmwasm/osmosis-tokenfactory-token-minter/Cargo.toml index 23a0035ee83..5452ef14724 100644 --- a/cosmwasm/osmosis-tokenfactory-token-minter/Cargo.toml +++ b/cosmwasm/osmosis-tokenfactory-token-minter/Cargo.toml @@ -8,9 +8,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] alloy = { workspace = true, features = ["sol-types"] } cosmwasm-schema = { workspace = true } diff --git a/cosmwasm/osmosis-tokenfactory-token-owner/Cargo.toml b/cosmwasm/osmosis-tokenfactory-token-owner/Cargo.toml index a727add924f..d98d4ac8bdc 100644 --- a/cosmwasm/osmosis-tokenfactory-token-owner/Cargo.toml +++ b/cosmwasm/osmosis-tokenfactory-token-owner/Cargo.toml @@ -8,9 +8,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cosmwasm-std = { workspace = true } osmosis-tokenfactory-token-minter = { workspace = true } diff --git a/cosmwasm/token-factory-api/Cargo.toml b/cosmwasm/token-factory-api/Cargo.toml index e1a158fa695..4aca216c7b9 100644 --- a/cosmwasm/token-factory-api/Cargo.toml +++ b/cosmwasm/token-factory-api/Cargo.toml @@ -12,6 +12,15 @@ repository = { workspace = true } workspace = true [dependencies] -cosmwasm-schema = { workspace = true } +cosmwasm-schema = { workspace = true, optional = true } cosmwasm-std = { workspace = true } enumorph = { workspace = true } +schemars = { workspace = true, optional = true } +serde = { workspace = true } + +[features] +default = [] + +std = [] + +schemars = ["std", "dep:schemars"] diff --git a/cosmwasm/token-factory-api/src/lib.rs b/cosmwasm/token-factory-api/src/lib.rs index 60de4d58a16..b9825eb2420 100644 --- a/cosmwasm/token-factory-api/src/lib.rs +++ b/cosmwasm/token-factory-api/src/lib.rs @@ -1,10 +1,15 @@ //! Special messages to be supported by any chain that supports osmosis tokenfactory. -// TODO: Link to the protobuf definitions on all types +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; -use cosmwasm_schema::{QueryResponses, cw_serde}; +use alloc::{string::String, vec::Vec}; + +// TODO: Link to the protobuf definitions on all types use cosmwasm_std::{Addr, Coin, CustomMsg, CustomQuery, Uint128}; use enumorph::Enumorph; +use serde::{Deserialize, Serialize}; /// Contracts can mint native tokens for an existing factory denom /// that they are the admin of. @@ -16,7 +21,8 @@ use enumorph::Enumorph; /// MintToAddress string `json:"mint_to_address"` /// } /// ``` -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct MintTokensMsg { pub denom: String, pub amount: Uint128, @@ -35,7 +41,8 @@ pub struct MintTokensMsg { /// BurnFromAddress string `json:"burn_from_address"` /// } /// ``` -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct BurnTokensMsg { pub denom: String, pub amount: Uint128, @@ -52,13 +59,15 @@ pub struct BurnTokensMsg { /// NewAdminAddress string `json:"new_admin_address"` /// } /// ``` -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct ChangeAdminMsg { pub denom: String, pub new_admin_address: Addr, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct ForceTransferMsg { pub denom: String, pub amount: Uint128, @@ -66,8 +75,8 @@ pub struct ForceTransferMsg { pub to_address: Addr, } -#[cw_serde] -#[derive(Enumorph)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Enumorph)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub enum TokenFactoryMsg { /// CreateDenom creates a new factory denom, of denomination: /// factory/{creating contract bech32 address}/{Subdenom} @@ -99,7 +108,8 @@ pub enum TokenFactoryMsg { } /// This maps to `cosmos.bank.v1beta1.Metadata`. -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Metadata { pub description: Option, /// denom_units represents the list of DenomUnit's for a given coin @@ -120,7 +130,8 @@ pub struct Metadata { } /// This maps to cosmos.bank.v1beta1.DenomUnit protobuf struct -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct DenomUnit { /// denom represents the string name of the given denom unit (e.g uatom). pub denom: String, @@ -135,7 +146,8 @@ pub struct DenomUnit { } /// This maps to `osmosis.tokenfactory.v1beta1.Params`. -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct Params { pub denom_creation_fee: Vec, } @@ -148,14 +160,17 @@ pub struct CreateDenomResponse { pub new_token_denom: String, } -#[cw_serde] -#[derive(QueryResponses)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr( + feature = "schemars", + derive(schemars::JsonSchema, cosmwasm_schema::QueryResponses) +)] pub enum TokenFactoryQuery { /// Given a subdenom created by the address `creator_addr` via `TokenFactoryMsg::CreateDenom`, /// returns the full denom as used by `BankMsg::Send`. /// You may call `FullDenom { creator_addr: env.contract.address, subdenom }` to find the denom issued /// by the current contract. - #[returns(FullDenomResponse)] + #[cfg_attr(feature = "schemars", returns(FullDenomResponse))] FullDenom { creator_addr: String, subdenom: String, @@ -163,46 +178,51 @@ pub enum TokenFactoryQuery { /// Returns the metadata set for this denom, if present. May return None. /// This will also return metadata for native tokens created outside /// of the token factory (like staking tokens) - #[returns(MetadataResponse)] + #[cfg_attr(feature = "schemars", returns(MetadataResponse))] Metadata { denom: String }, /// Returns info on admin of the denom, only if created/managed via token factory. /// Errors if denom doesn't exist or was created by another module. - #[returns(AdminResponse)] + #[cfg_attr(feature = "schemars", returns(AdminResponse))] Admin { denom: String }, /// List all denoms that were created by the given creator. /// This does not imply all tokens currently managed by the creator. /// (Admin may have changed) - #[returns(DenomsByCreatorResponse)] + #[cfg_attr(feature = "schemars", returns(DenomsByCreatorResponse))] DenomsByCreator { creator: String }, /// Returns configuration params for TokenFactory modules - #[returns(ParamsResponse)] + #[cfg_attr(feature = "schemars", returns(ParamsResponse))] Params {}, } impl CustomQuery for TokenFactoryQuery {} -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct FullDenomResponse { pub denom: String, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct MetadataResponse { /// Empty if this was never set for the given denom pub metadata: Option, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct AdminResponse { pub admin: String, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct DenomsByCreatorResponse { pub denoms: Vec, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] pub struct ParamsResponse { pub params: Params, } diff --git a/cosmwasm/ucs03-zkgm-token-minter-api/Cargo.toml b/cosmwasm/ucs03-zkgm-token-minter-api/Cargo.toml index 099b3fe9ee0..831b1bab2e7 100644 --- a/cosmwasm/ucs03-zkgm-token-minter-api/Cargo.toml +++ b/cosmwasm/ucs03-zkgm-token-minter-api/Cargo.toml @@ -12,11 +12,19 @@ repository = { workspace = true } workspace = true [dependencies] -alloy = { workspace = true, features = ["sol-types"] } -alloy-primitives = { workspace = true } -cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true, features = ["std"] } -enumorph = { workspace = true } -ibc-union-spec = { workspace = true, features = ["schemars", "serde"] } -token-factory-api = { workspace = true } -unionlabs = { workspace = true } +alloy-primitives = { workspace = true } +alloy-sol-types = { workspace = true } +cosmwasm-schema = { workspace = true, optional = true } +cosmwasm-std = { workspace = true } +enumorph = { workspace = true } +ibc-union-spec = { workspace = true, features = ["serde"] } +serde = { workspace = true, features = ["derive"] } +token-factory-api = { workspace = true } +unionlabs-primitives = { workspace = true } + +[features] +default = [] + +std = ["cosmwasm-std/std"] + +schemars = ["std", "unionlabs-primitives/schemars", "dep:cosmwasm-schema"] diff --git a/cosmwasm/ucs03-zkgm-token-minter-api/src/lib.rs b/cosmwasm/ucs03-zkgm-token-minter-api/src/lib.rs index 62765868bc5..2bfc0ca9629 100644 --- a/cosmwasm/ucs03-zkgm-token-minter-api/src/lib.rs +++ b/cosmwasm/ucs03-zkgm-token-minter-api/src/lib.rs @@ -1,10 +1,19 @@ -use alloy::sol_types::SolValue; +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +use alloc::{ + string::{String, ToString}, + vec::Vec, +}; + use alloy_primitives::U256; -use cosmwasm_schema::cw_serde; +use alloy_sol_types::SolValue; use cosmwasm_std::{Addr, Binary, Event, Uint128}; use enumorph::Enumorph; use ibc_union_spec::ChannelId; -use unionlabs::primitives::{Bytes, H256, encoding::HexPrefixed}; +use serde::{Deserialize, Serialize}; +use unionlabs_primitives::{Bytes, H256, encoding::HexPrefixed}; pub const EVENT_WRAPPED_TOKEN: &str = "create_wrapped_token"; pub const EVENT_WRAPPED_TOKEN_ATTR_CHANNEL_ID: &str = "channel_id"; @@ -50,7 +59,8 @@ pub fn encode_metadata(implementation: &[u8], initializer: &[u8]) -> Vec { (implementation, initializer).abi_encode_params() } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(deny_unknown_fields, rename_all = "snake_case")] pub enum TokenMinterInitMsg { /// Cosmwasm's [CW20] minter, will use virtualized `CW20` tokens. /// Note that the `CW20` stack is fully on CosmWasm. Similarly to Ethereum's ERC20, the tokens will be @@ -71,7 +81,7 @@ pub enum TokenMinterInitMsg { } /// Messages for the funds that are local to this chain -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum LocalTokenMsg { /// Lock the funds. /// @@ -99,7 +109,7 @@ pub enum LocalTokenMsg { }, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Metadata { /// name defines the name of the token (eg: Circle USDC) pub name: String, @@ -110,7 +120,7 @@ pub struct Metadata { } /// Messages for the funds that are originated in other chains -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum WrappedTokenMsg { /// Create a new denom /// @@ -178,14 +188,13 @@ pub enum WrappedTokenMsg { }, } -#[cw_serde] -#[derive(Enumorph)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Enumorph)] pub enum ExecuteMsg { Wrapped(WrappedTokenMsg), Local(LocalTokenMsg), } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum QueryMsg { /// Query the metadata of a token. Metadata { @@ -205,14 +214,14 @@ pub enum QueryMsg { }, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct MetadataResponse { pub name: String, pub symbol: String, pub decimals: u8, } -#[cw_serde] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PredictWrappedTokenResponse { pub wrapped_token: String, } diff --git a/cosmwasm/upgradable/Cargo.toml b/cosmwasm/upgradable/Cargo.toml index 97e6516f2eb..b4645f22147 100644 --- a/cosmwasm/upgradable/Cargo.toml +++ b/cosmwasm/upgradable/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] cosmwasm-std = { workspace = true, features = [] } embed-commit = { workspace = true } diff --git a/e2e/access-managed-example/Cargo.toml b/e2e/access-managed-example/Cargo.toml index ee29bfabc1e..58dbcdf8829 100644 --- a/e2e/access-managed-example/Cargo.toml +++ b/e2e/access-managed-example/Cargo.toml @@ -11,9 +11,6 @@ repository = { workspace = true } [lints] workspace = true -[lib] -crate-type = ["cdylib", "rlib"] - [dependencies] access-managed = { workspace = true, features = ["library"] } access-manager-types = { workspace = true } diff --git a/generated/rust/protos/src/google.protobuf.rs b/generated/rust/protos/src/google.protobuf.rs index 247360f6a35..f59c9ce4be4 100644 --- a/generated/rust/protos/src/google.protobuf.rs +++ b/generated/rust/protos/src/google.protobuf.rs @@ -2224,8 +2224,8 @@ pub struct SourceContext { #[derive(Clone, PartialEq, :: prost :: Message)] pub struct Struct { /// Unordered map of dynamically typed values. - #[prost(map = "string, message", tag = "1")] - pub fields: ::std::collections::HashMap<::prost::alloc::string::String, Value>, + #[prost(btree_map = "string, message", tag = "1")] + pub fields: ::std::collections::BTreeMap<::prost::alloc::string::String, Value>, } /// `Value` represents a dynamically typed value which can be either /// null, a number, a string, a boolean, a recursive struct value, or a diff --git a/lib/cosmos-client/Cargo.toml b/lib/cosmos-client/Cargo.toml index 8d295bbdb8e..2cf2564abd4 100644 --- a/lib/cosmos-client/Cargo.toml +++ b/lib/cosmos-client/Cargo.toml @@ -16,7 +16,7 @@ bip32 = { workspace = true } cometbft-rpc = { workspace = true } cosmos-signer = { workspace = true } num-rational = "0.4.2" -num-traits = "0.2.19" +num-traits = { workspace = true } protos = { workspace = true } serde = { workspace = true, features = ["derive"] } serde-utils = { workspace = true } diff --git a/lib/cw20-ctx/Cargo.toml b/lib/cw20-ctx/Cargo.toml index 5d5cd00d6c2..aa052433de1 100644 --- a/lib/cw20-ctx/Cargo.toml +++ b/lib/cw20-ctx/Cargo.toml @@ -8,9 +8,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/lib/depolama/Cargo.toml b/lib/depolama/Cargo.toml index 0d48a74727e..97db3467499 100644 --- a/lib/depolama/Cargo.toml +++ b/lib/depolama/Cargo.toml @@ -12,8 +12,8 @@ repository = { workspace = true } workspace = true [dependencies] -cosmwasm-std = { workspace = true, features = ["std"] } -num-traits = "0.2.19" +cosmwasm-std = { workspace = true } +num-traits = { workspace = true } unionlabs-encoding = { workspace = true } unionlabs-primitives = { workspace = true } diff --git a/lib/depolama/src/key.rs b/lib/depolama/src/key.rs index ab8c6066413..4dd7cc7500d 100644 --- a/lib/depolama/src/key.rs +++ b/lib/depolama/src/key.rs @@ -1,3 +1,5 @@ +use alloc::{format, vec, vec::Vec}; + use cosmwasm_std::{StdError, StdResult}; use unionlabs_encoding::{Decode, DecodeAs, Encode, EncodeAs, Encoding}; use unionlabs_primitives::Bytes; diff --git a/lib/depolama/src/lib.rs b/lib/depolama/src/lib.rs index c13a9a4c979..5ec181fe7ea 100644 --- a/lib/depolama/src/lib.rs +++ b/lib/depolama/src/lib.rs @@ -58,8 +58,17 @@ //! assert!(storage.maybe_read::(&3).unwrap().is_none()); //! ``` +#![no_std] #![warn(clippy::pedantic, missing_docs)] +extern crate alloc; + +use alloc::{ + format, + string::{String, ToString}, + vec::Vec, +}; + use cosmwasm_std::{ Addr, Empty, OverflowError, OverflowOperation, Querier, QueryRequest, StdError, StdResult, Storage, WasmQuery, to_json_binary, @@ -398,7 +407,7 @@ pub trait StorageExt { fn iter_range( &self, order: cosmwasm_std::Order, - bounds: impl std::ops::RangeBounds, + bounds: impl core::ops::RangeBounds, ) -> impl Iterator>; } @@ -435,7 +444,7 @@ impl StorageExt for T { fn iter_range( &self, order: cosmwasm_std::Order, - bounds: impl std::ops::RangeBounds, + bounds: impl core::ops::RangeBounds, ) -> impl Iterator> { (self as &dyn Storage).iter_range::(order, bounds) } @@ -494,9 +503,10 @@ impl StorageExt for dyn Storage + '_ { fn iter_range( &self, order: cosmwasm_std::Order, - bounds: impl std::ops::RangeBounds, + bounds: impl core::ops::RangeBounds, ) -> impl Iterator> { - use std::ops::Bound; + use alloc::vec::Vec; + use core::ops::Bound; fn key_plus_one(raw_key: impl Into>) -> Bytes { let mut raw_key = raw_key.into(); diff --git a/lib/depolama/src/value.rs b/lib/depolama/src/value.rs index 88fba441634..e96605b04f2 100644 --- a/lib/depolama/src/value.rs +++ b/lib/depolama/src/value.rs @@ -1,3 +1,5 @@ +use alloc::{format, vec, vec::Vec}; + use cosmwasm_std::{StdError, StdResult}; use unionlabs_encoding::{Decode, DecodeAs, Encode, EncodeAs, Encoding}; use unionlabs_primitives::Bytes; diff --git a/lib/embed-commit/src/lib.rs b/lib/embed-commit/src/lib.rs index 009bf421a52..0be5c296618 100644 --- a/lib/embed-commit/src/lib.rs +++ b/lib/embed-commit/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + use bytemuck::CheckedBitPattern; /// The git rev of the code, as supplied at build time. On `wasm32` targets, this is available via the `commit_hash` export. @@ -21,7 +23,7 @@ pub enum Rev { } impl core::fmt::Display for Rev { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Rev::Unknown => f.write_str("unknown"), Rev::Dirty => f.write_str("dirty"), diff --git a/lib/frissitheto/Cargo.toml b/lib/frissitheto/Cargo.toml index 7255b4c8746..0abda9e4195 100644 --- a/lib/frissitheto/Cargo.toml +++ b/lib/frissitheto/Cargo.toml @@ -10,9 +10,6 @@ license-file = { workspace = true } publish = { workspace = true } repository = { workspace = true } -[lib] -crate-type = ["cdylib", "rlib"] - [lints] workspace = true diff --git a/lib/frissitheto/src/lib.rs b/lib/frissitheto/src/lib.rs index 7a404a16590..a8985f83001 100644 --- a/lib/frissitheto/src/lib.rs +++ b/lib/frissitheto/src/lib.rs @@ -1,7 +1,10 @@ #![doc = include_str!("../README.md")] #![warn(clippy::pedantic, missing_docs)] +#![no_std] -use std::num::NonZeroU32; +extern crate alloc; + +use core::num::NonZeroU32; use cosmwasm_std::{CustomMsg, DepsMut, Response, StdError}; use serde::{Deserialize, Serialize}; @@ -156,7 +159,7 @@ pub enum InitStateVersionError { // TODO: Add tests for version changes as well #[cfg(test)] mod tests { - use std::collections::BTreeMap; + use alloc::{collections::BTreeMap, vec::Vec}; use cosmwasm_std::{Empty, MemoryStorage, Storage, testing::mock_dependencies}; diff --git a/lib/ibc-union-spec/Cargo.toml b/lib/ibc-union-spec/Cargo.toml index b48b23fa554..b179c200e6c 100644 --- a/lib/ibc-union-spec/Cargo.toml +++ b/lib/ibc-union-spec/Cargo.toml @@ -12,17 +12,19 @@ repository = { workspace = true } workspace = true [dependencies] -alloy-sol-types = { workspace = true, optional = true } -bincode = { workspace = true, optional = true, features = ["derive"] } -enumorph = { workspace = true } -num-traits = "0.2.19" -schemars = { workspace = true, optional = true, features = ["derive"] } -serde = { workspace = true, optional = true, features = ["derive"] } -sha3 = { workspace = true } -thiserror = { workspace = true } -tracing = { workspace = true, optional = true } -unionlabs = { workspace = true } -voyager-primitives = { workspace = true } +alloy-sol-types = { workspace = true, optional = true } +bincode = { workspace = true, optional = true, features = ["derive"] } +enumorph = { workspace = true } +num-traits = { workspace = true } +schemars = { workspace = true, optional = true, features = ["derive"] } +serde = { workspace = true, optional = true, features = ["derive"] } +sha3 = { workspace = true } +thiserror = { workspace = true } +tracing = { workspace = true, optional = true } +unionlabs-height = { workspace = true } +unionlabs-primitives = { workspace = true, features = ["generic-array-compat"] } +unionlabs-tuple = { workspace = true } +voyager-primitives = { workspace = true } [dev-dependencies] ibc-union-spec = { workspace = true, features = ["ethabi", "schemars", "serde"] } @@ -30,8 +32,14 @@ ibc-union-spec = { workspace = true, features = ["ethabi", "schemars", "serde"] [features] default = [] -bincode = ["dep:bincode", "voyager-primitives/bincode", "unionlabs/bincode"] -ethabi = ["dep:alloy-sol-types", "unionlabs/ethabi"] -schemars = ["dep:schemars", "voyager-primitives/schemars", "unionlabs/schemars"] -serde = ["dep:serde", "voyager-primitives/serde"] -tracing = ["dep:tracing", "ethabi"] # ethabi for the packet hash in logs +std = [] + +bincode = ["dep:bincode", "voyager-primitives/bincode", "unionlabs-primitives/bincode"] +ethabi = [ + "dep:alloy-sol-types", + "unionlabs-primitives/alloy-primitives-compat", + "unionlabs-primitives/alloy-sol-types-compat", +] +schemars = ["std", "dep:schemars", "voyager-primitives/schemars", "unionlabs-primitives/schemars"] +serde = ["dep:serde", "voyager-primitives/serde"] +tracing = ["dep:tracing", "ethabi"] # ethabi for the packet hash in logs diff --git a/lib/ibc-union-spec/src/datagram.rs b/lib/ibc-union-spec/src/datagram.rs index 423add82bc8..f968b4e6e0f 100644 --- a/lib/ibc-union-spec/src/datagram.rs +++ b/lib/ibc-union-spec/src/datagram.rs @@ -1,5 +1,8 @@ +use alloc::{string::String, vec::Vec}; + use enumorph::Enumorph; -use unionlabs::{ibc::core::client::height::Height, primitives::Bytes}; +use unionlabs_height::Height; +use unionlabs_primitives::Bytes; use voyager_primitives::ClientType; use crate::{ diff --git a/lib/ibc-union-spec/src/event.rs b/lib/ibc-union-spec/src/event.rs index a9020dba48a..74687912feb 100644 --- a/lib/ibc-union-spec/src/event.rs +++ b/lib/ibc-union-spec/src/event.rs @@ -1,5 +1,7 @@ +use alloc::string::String; + use enumorph::Enumorph; -use unionlabs::primitives::{Bytes, H256}; +use unionlabs_primitives::{Bytes, H256}; use voyager_primitives::{ClientType, Timestamp}; use crate::{ diff --git a/lib/ibc-union-spec/src/lib.rs b/lib/ibc-union-spec/src/lib.rs index b9521df05dd..6d1aec60525 100644 --- a/lib/ibc-union-spec/src/lib.rs +++ b/lib/ibc-union-spec/src/lib.rs @@ -1,4 +1,9 @@ -use unionlabs::{ibc::core::client::height::Height, primitives::Bytes}; +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +use unionlabs_height::Height; +use unionlabs_primitives::Bytes; use voyager_primitives::{IbcSpec, IbcSpecId}; pub mod datagram; diff --git a/lib/ibc-union-spec/src/path.rs b/lib/ibc-union-spec/src/path.rs index a52ec761394..03599206391 100644 --- a/lib/ibc-union-spec/src/path.rs +++ b/lib/ibc-union-spec/src/path.rs @@ -1,6 +1,6 @@ use enumorph::Enumorph; use sha3::{Digest, Keccak256}; -use unionlabs::primitives::{Bytes, H256, U256}; +use unionlabs_primitives::{Bytes, H256, U256}; use voyager_primitives::IbcStorePathKey; #[cfg(feature = "ethabi")] diff --git a/lib/ibc-union-spec/src/query.rs b/lib/ibc-union-spec/src/query.rs index 66a2b870e75..643db3c34c2 100644 --- a/lib/ibc-union-spec/src/query.rs +++ b/lib/ibc-union-spec/src/query.rs @@ -1,5 +1,7 @@ +use alloc::{string::String, vec::Vec}; + use enumorph::Enumorph; -use unionlabs::primitives::{Bytes, H256}; +use unionlabs_primitives::{Bytes, H256}; use voyager_primitives::IbcQuery; use crate::{ diff --git a/lib/ibc-union-spec/src/types.rs b/lib/ibc-union-spec/src/types.rs index 95f79dfe6cf..73c4d295bbe 100644 --- a/lib/ibc-union-spec/src/types.rs +++ b/lib/ibc-union-spec/src/types.rs @@ -1,6 +1,6 @@ use core::{fmt, num::NonZeroU32}; -use unionlabs::primitives::U256; +use unionlabs_primitives::U256; pub(crate) mod channel; pub(crate) mod connection; @@ -107,7 +107,7 @@ pub enum Status { } impl fmt::Display for Status { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str(match self { Status::Active => "active", Status::Expired => "expired", diff --git a/lib/ibc-union-spec/src/types/channel.rs b/lib/ibc-union-spec/src/types/channel.rs index 3b20b321d1f..5f8af562a78 100644 --- a/lib/ibc-union-spec/src/types/channel.rs +++ b/lib/ibc-union-spec/src/types/channel.rs @@ -1,6 +1,8 @@ +use alloc::{string::String, vec::Vec}; use core::{borrow::Borrow, fmt::Display}; -use unionlabs::{errors::UnknownEnumVariant, primitives::Bytes, tuple::AsTuple}; +use unionlabs_primitives::Bytes; +use unionlabs_tuple::AsTuple; use crate::types::{ChannelId, ConnectionId}; @@ -38,7 +40,7 @@ pub enum ChannelState { } impl Display for ChannelState { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str(match self { ChannelState::Init => "init", ChannelState::TryOpen => "try_open", @@ -49,7 +51,7 @@ impl Display for ChannelState { } impl TryFrom for ChannelState { - type Error = UnknownEnumVariant; + type Error = InvalidChannelState; fn try_from(value: u8) -> Result { match value { @@ -57,11 +59,15 @@ impl TryFrom for ChannelState { 2 => Ok(Self::TryOpen), 3 => Ok(Self::Open), 4 => Ok(Self::Closed), - _ => Err(UnknownEnumVariant(value)), + _ => Err(InvalidChannelState(value)), } } } +#[derive(Debug, Clone, PartialEq, thiserror::Error)] +#[error("invalid channel state: {0}")] +pub struct InvalidChannelState(pub u8); + impl Borrow for ChannelState { fn borrow(&self) -> &u8 { // SAFETY: Self is repr(u8) @@ -77,7 +83,7 @@ impl Borrow for &ChannelState { #[cfg(feature = "ethabi")] pub mod ethabi { - use std::borrow::Cow; + use alloc::borrow::Cow; use alloy_sol_types::{ SolStruct, SolType, SolValue, diff --git a/lib/ibc-union-spec/src/types/connection.rs b/lib/ibc-union-spec/src/types/connection.rs index 0283b25fb31..44cacc7041e 100644 --- a/lib/ibc-union-spec/src/types/connection.rs +++ b/lib/ibc-union-spec/src/types/connection.rs @@ -1,6 +1,7 @@ +use alloc::vec::Vec; use core::{borrow::Borrow, fmt}; -use unionlabs::{errors::UnknownEnumVariant, tuple::AsTuple}; +use unionlabs_tuple::AsTuple; use crate::types::{ClientId, ConnectionId}; @@ -53,7 +54,7 @@ pub enum ConnectionState { } impl fmt::Display for ConnectionState { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str(match self { Self::Init => "init", Self::TryOpen => "try_open", @@ -63,18 +64,22 @@ impl fmt::Display for ConnectionState { } impl TryFrom for ConnectionState { - type Error = UnknownEnumVariant; + type Error = InvalidConnectionState; fn try_from(value: u8) -> Result { match value { 1 => Ok(Self::Init), 2 => Ok(Self::TryOpen), 3 => Ok(Self::Open), - _ => Err(UnknownEnumVariant(value)), + _ => Err(InvalidConnectionState(value)), } } } +#[derive(Debug, Clone, PartialEq, thiserror::Error)] +#[error("invalid connection state: {0}")] +pub struct InvalidConnectionState(pub u8); + impl Borrow for ConnectionState { fn borrow(&self) -> &u8 { // SAFETY: Self is repr(u8) @@ -90,7 +95,7 @@ impl Borrow for &ConnectionState { #[cfg(feature = "ethabi")] pub mod ethabi { - use std::borrow::Cow; + use alloc::borrow::Cow; use alloy_sol_types::{SolStruct, SolType, SolValue, sol_data::Uint}; diff --git a/lib/ibc-union-spec/src/types/packet.rs b/lib/ibc-union-spec/src/types/packet.rs index 90deb968396..2ed70ac3831 100644 --- a/lib/ibc-union-spec/src/types/packet.rs +++ b/lib/ibc-union-spec/src/types/packet.rs @@ -1,6 +1,8 @@ -use std::{fmt::Display, str::FromStr}; +use alloc::{string::String, vec::Vec}; +use core::{fmt::Display, str::FromStr}; -use unionlabs::{primitives::Bytes, tuple::AsTuple}; +use unionlabs_primitives::Bytes; +use unionlabs_tuple::AsTuple; use voyager_primitives::Timestamp; use crate::types::ChannelId; @@ -69,7 +71,7 @@ impl FromStr for MustBeZero { } impl Display for MustBeZero { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "0") } } @@ -132,17 +134,22 @@ impl serde::Serialize for MustBeZero { impl Packet { /// Calculate the hash of this packet. This is the same as the commitment key for a single packet. #[cfg(feature = "ethabi")] - pub fn hash(&self) -> unionlabs::primitives::H256 { + pub fn hash(&self) -> unionlabs_primitives::H256 { use alloy_sol_types::SolValue; - use unionlabs::ethereum::keccak256; - - keccak256(vec![self].abi_encode()) + use sha3::Digest; + + sha3::Keccak256::new() + // NOTE: `[self]` is actually `[Packet; 1]`, which encodes than `[Packet]`! + // the former is fixed size, and encodes the same as `Packet`, whereas the latter is a dynamic array + .chain_update(core::slice::from_ref(self).abi_encode()) + .finalize() + .into() } } #[cfg(feature = "ethabi")] pub mod ethabi { - use std::borrow::Cow; + use alloc::borrow::Cow; use alloy_sol_types::{ SolStruct, SolType, SolValue, @@ -337,7 +344,7 @@ pub mod ethabi { #[cfg(test)] mod tests { - use unionlabs::primitives::H256; + use unionlabs_primitives::H256; use super::*; diff --git a/lib/macros/src/lib.rs b/lib/macros/src/lib.rs index aabd245d4b8..6da1abcd805 100644 --- a/lib/macros/src/lib.rs +++ b/lib/macros/src/lib.rs @@ -1150,10 +1150,10 @@ fn derive_as_tuple( Ok(quote! { const _: () = { #[automatically_derived] - impl #impl_generics ::unionlabs::tuple::AsTuple for #ident #ty_generics #where_clause { + impl #impl_generics ::unionlabs_tuple::AsTuple for #ident #ty_generics #where_clause { type Tuple = (#(#field_types,)*); - fn as_tuple(&self) -> ::Ref<'_> { + fn as_tuple(&self) -> ::Ref<'_> { ( #( &self.#as_tuple_fields, diff --git a/lib/serde-utils/Cargo.toml b/lib/serde-utils/Cargo.toml index 2ddd7ec6a96..5880eb9e1f3 100644 --- a/lib/serde-utils/Cargo.toml +++ b/lib/serde-utils/Cargo.toml @@ -12,8 +12,9 @@ repository = { workspace = true } workspace = true [dependencies] -base64 = { workspace = true, features = ["alloc"] } -bitvec = { workspace = true, features = ["alloc"] } -chrono = { workspace = true, features = ["alloc"] } -hex = { workspace = true, features = ["alloc", "std"] } -serde = { workspace = true, features = ["derive", "alloc"] } +base64 = { workspace = true, features = ["alloc"] } +bitvec = { workspace = true, features = ["alloc"] } +chrono = { workspace = true, features = ["alloc"] } +hex = { workspace = true, features = ["alloc"] } +serde = { workspace = true, features = ["derive", "alloc"] } +thiserror = { workspace = true } diff --git a/lib/serde-utils/src/lib.rs b/lib/serde-utils/src/lib.rs index 5833813fb0a..6e3a1dd434b 100644 --- a/lib/serde-utils/src/lib.rs +++ b/lib/serde-utils/src/lib.rs @@ -14,42 +14,19 @@ use hex::FromHexError; pub const HEX_ENCODING_PREFIX: &str = "0x"; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, thiserror::Error)] pub enum FromHexStringError { + #[error("{0}")] Hex(FromHexError), + #[error("missing prefix `{HEX_ENCODING_PREFIX}` when deserializing hex data '{0}'")] MissingPrefix(String), + #[error("cannot parse empty string as hex")] EmptyString, // NOTE: Contains the stringified error + #[error("unable to convert from bytes: {0:?}")] TryFromBytes(String), } -impl core::error::Error for FromHexStringError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { - match self { - FromHexStringError::Hex(hex) => Some(hex), - FromHexStringError::EmptyString => None, - FromHexStringError::MissingPrefix(_) => None, - FromHexStringError::TryFromBytes(_) => None, - } - } -} - -impl core::fmt::Display for FromHexStringError { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - FromHexStringError::Hex(e) => write!(f, "{e}"), - FromHexStringError::EmptyString => write!(f, "cannot parse empty string as hex"), - FromHexStringError::MissingPrefix(data) => write!( - f, - "missing prefix `{HEX_ENCODING_PREFIX}` when deserializing hex data '{data}'", - ), - FromHexStringError::TryFromBytes(err) => { - write!(f, "unable to convert from bytes: {err:?}") - } - } - } -} - pub fn to_hex>(data: T) -> String { let data = data.as_ref(); diff --git a/lib/ucs03-solvable/src/lib.rs b/lib/ucs03-solvable/src/lib.rs index dcd32fab78b..035347f4a96 100644 --- a/lib/ucs03-solvable/src/lib.rs +++ b/lib/ucs03-solvable/src/lib.rs @@ -1,3 +1,7 @@ +#![no_std] + +extern crate alloc; + use cosmwasm_std::Addr; use ibc_union_spec::Packet; use serde::{Deserialize, Serialize}; diff --git a/lib/ucs03-zkgmable/src/lib.rs b/lib/ucs03-zkgmable/src/lib.rs index 695b75adbe4..31174140ea5 100644 --- a/lib/ucs03-zkgmable/src/lib.rs +++ b/lib/ucs03-zkgmable/src/lib.rs @@ -1,3 +1,7 @@ +#![no_std] + +extern crate alloc; + use cosmwasm_std::Addr; use ibc_union_spec::ChannelId; use serde::{Deserialize, Serialize}; diff --git a/lib/unionlabs-encoding/src/lib.rs b/lib/unionlabs-encoding/src/lib.rs index f4104779f41..ed13405656c 100644 --- a/lib/unionlabs-encoding/src/lib.rs +++ b/lib/unionlabs-encoding/src/lib.rs @@ -428,8 +428,8 @@ pub trait TypeUrl { pub enum TryFromProtoBytesError { #[error("unable to convert from the raw prost type")] TryFromProto(#[source] E), - #[error("unable to decode from raw proto bytes")] - Decode(#[source] prost::DecodeError), + #[error("unable to decode from raw proto bytes: {0}")] + Decode(prost::DecodeError), } /// Implement [`Proto`] encoding via conversion to/from a [`prost`] generated type. See the diff --git a/lib/unionlabs-height/Cargo.toml b/lib/unionlabs-height/Cargo.toml new file mode 100644 index 00000000000..207e890ba90 --- /dev/null +++ b/lib/unionlabs-height/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "unionlabs-height" +version = "0.0.0" + +authors = { workspace = true } +edition = { workspace = true } +license-file = { workspace = true } +publish = { workspace = true } +repository = { workspace = true } + +[lints] +workspace = true + +[dependencies] +bincode = { workspace = true, optional = true, features = ["derive"] } +prost = { workspace = true, optional = true } +protos = { workspace = true, optional = true, features = ["ibc+core+client+v1"] } +schemars = { workspace = true, optional = true, features = ["derive"] } +serde = { workspace = true, optional = true, features = ["derive"] } +thiserror = { workspace = true } +unionlabs-encoding = { workspace = true, optional = true } + +[features] +default = [] + +bincode = ["dep:bincode", "dep:unionlabs-encoding", "unionlabs-encoding/bincode"] +proto = ["dep:prost", "dep:protos", "dep:unionlabs-encoding", "unionlabs-encoding/proto"] +schemars = ["dep:schemars"] +serde = ["dep:serde"] diff --git a/lib/unionlabs-height/src/lib.rs b/lib/unionlabs-height/src/lib.rs new file mode 100644 index 00000000000..fbe3bba86d1 --- /dev/null +++ b/lib/unionlabs-height/src/lib.rs @@ -0,0 +1,471 @@ +#![no_std] + +extern crate alloc; + +use core::{ + cmp::Ordering, + fmt::{self, Debug}, + num::{NonZeroU64, ParseIntError}, + str::FromStr, +}; + +#[derive(Clone, Copy, PartialEq, Eq, Hash, Default)] +#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] +// TODO: Implement Valuable via Display once https://github.com/tokio-rs/valuable/pull/133 is merged +pub struct Height { + revision: Option, + height: u64, +} + +impl fmt::Debug for Height { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + core::write!(f, "Height({self})") + } +} + +// #[cfg(feature = "valuable")] +// impl valuable::Valuable for Height { +// fn as_value(&self) -> valuable::Value<'_> { +// valuable::Value::Renderable(valuable::Renderable::Display(self)) +// } + +// fn visit(&self, visit: &mut dyn valuable::Visit) { +// visit.visit_value(self.as_value()); +// } +// } + +impl Height { + #[must_use] + pub const fn new(height: u64) -> Self { + Self { + revision: None, + height, + } + } + + #[must_use] + pub const fn new_with_revision(revision: u64, height: u64) -> Self { + Self { + revision: NonZeroU64::new(revision), + height, + } + } + + #[must_use] + pub const fn height(&self) -> u64 { + self.height + } + + #[must_use] + pub const fn height_mut(&mut self) -> &mut u64 { + &mut self.height + } + + #[must_use] + pub const fn revision(&self) -> u64 { + match self.revision { + Some(revision) => revision.get(), + None => 0, + } + } + + #[must_use] + pub const fn revision_matches(&self, other: &Self) -> bool { + match (self.revision, other.revision) { + (Some(lhs), Some(rhs)) => lhs.get() == rhs.get(), + _ => true, + } + } + + #[must_use] + pub const fn increment(self) -> Self { + Self { + revision: self.revision, + height: self.height + 1, + } + } + + #[must_use] + pub const fn increment_by(self, height: u64) -> Self { + Self { + revision: self.revision, + height: self.height + height, + } + } + + pub fn from_str_allow_zero_revision(s: &str) -> Result { + match s.split_once('-') { + Some((n, h)) => Ok(Self::new_with_revision(n.parse()?, h.parse()?)), + None => Err(HeightFromStrError::Invalid), + } + } +} + +// Implement once this is stabilized: https://github.com/rust-lang/rust/issues/42168 +// impl Step for Height { +// fn steps_between(start: &Self, end: &Self) -> Option { +// start +// .revision_matches(end) +// .then(|| ::steps_between(&start.height(), &end.height())) +// .flatten() +// } + +// fn forward_checked(start: Self, count: usize) -> Option { +// start +// .revision_matches(end) +// .then(|| ::forward_checked(&start.height(), &end.height())) +// .flatten() +// } + +// fn backward_checked(start: Self, count: usize) -> Option { +// start +// .revision_matches(end) +// .then(|| ::backward_checked(&start.height(), &end.height())) +// .flatten() +// } +// } + +impl FromStr for Height { + type Err = HeightFromStrError; + + fn from_str(s: &str) -> Result { + match s.split_once('-') { + Some((n, h)) => Ok(Self { + revision: Some(n.parse().map_err(HeightFromStrError::ParseIntError)?), + height: h.parse().map_err(HeightFromStrError::ParseIntError)?, + }), + None => Ok(Self { + revision: None, + height: s.parse().map_err(HeightFromStrError::ParseIntError)?, + }), + } + } +} + +#[derive(Debug, PartialEq, Eq, thiserror::Error)] +pub enum HeightFromStrError { + #[error("invalid numeric value in height string")] + ParseIntError(#[from] ParseIntError), + #[error("invalid height string")] + Invalid, +} + +impl PartialOrd for Height { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Height { + fn cmp(&self, other: &Self) -> Ordering { + match (self.revision, other.revision) { + (Some(this_revision), Some(other_revision)) => match this_revision.cmp(&other_revision) + { + Ordering::Less => Ordering::Less, + Ordering::Equal => self.height.cmp(&other.height), + Ordering::Greater => Ordering::Greater, + }, + _ => self.height.cmp(&other.height), + } + } +} + +impl fmt::Display for Height { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if f.alternate() { + write!(f, "{}-{}", self.revision(), self.height) + } else { + match self.revision { + Some(revision_number) => { + write!(f, "{}-{}", revision_number, self.height) + } + None => { + write!(f, "{}", self.height) + } + } + } + } +} + +#[cfg(feature = "serde")] +impl serde::Serialize for Height { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + use serde::ser::SerializeTuple; + + if serializer.is_human_readable() { + serializer.collect_str(self) + } else { + let mut ser = serializer.serialize_tuple(2)?; + ser.serialize_element(&self.revision())?; + ser.serialize_element(&self.height())?; + ser.end() + } + } +} + +#[cfg(feature = "serde")] +impl<'de> serde::Deserialize<'de> for Height { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + if deserializer.is_human_readable() { + use alloc::string::String; + + struct HeightStrVisitor; + + impl serde::de::Visitor<'_> for HeightStrVisitor { + type Value = Height; + + fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { + formatter.write_str("string representation of Height") + } + + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + v.parse().map_err(serde::de::Error::custom) + } + + fn visit_string(self, v: String) -> Result + where + E: serde::de::Error, + { + v.parse().map_err(serde::de::Error::custom) + } + } + + deserializer.deserialize_any(HeightStrVisitor) + } else { + <(u64, u64)>::deserialize(deserializer).map(|(n, h)| Height::new_with_revision(n, h)) + } + } +} + +#[cfg(feature = "schemars")] +impl ::schemars::JsonSchema for Height { + fn schema_name() -> String { + "Height".to_owned() + } + + fn schema_id() -> alloc::borrow::Cow<'static, str> { + alloc::borrow::Cow::Borrowed(concat!(module_path!(), "::Height")) + } + + fn json_schema(_: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { + use schemars::schema::{ + InstanceType, Metadata, SchemaObject, SingleOrVec, StringValidation, + }; + + SchemaObject { + metadata: Some(Box::new(Metadata { + description: Some( + "A blockchain height, optionally prefixed with a revision \ + number as per the [IBC Specification]\ + (https://ibc.cosmos.network/main/ibc/overview/#ibc-client-heights)." + .to_owned(), + ), + ..Default::default() + })), + instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))), + string: Some(Box::new(StringValidation { + // nonzero revision number - revision height + pattern: Some(r"([1-9]\d*-)?\d+".to_owned()), + ..Default::default() + })), + ..Default::default() + } + .into() + } +} + +#[cfg(feature = "proto")] +pub mod proto { + use core::num::NonZeroU64; + + use crate::Height; + + impl From for Height { + fn from(proto: protos::ibc::core::client::v1::Height) -> Self { + Self { + revision: NonZeroU64::new(proto.revision_number), + height: proto.revision_height, + } + } + } + impl From for protos::ibc::core::client::v1::Height { + fn from(value: Height) -> Self { + Self { + revision_number: value.revision.map_or_else(|| 0, NonZeroU64::get), + revision_height: value.height, + } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + macro_rules! nz { + ($n:expr) => { + const { NonZeroU64::new($n).unwrap() } + }; + } + + #[test] + fn debug() { + assert_eq!( + format!( + "{:?}", + Height { + revision: Some(nz!(1)), + height: 1, + } + ), + "Height(1-1)" + ); + + assert_eq!( + format!( + "{:?}", + Height { + revision: None, + height: 1, + } + ), + "Height(1)" + ); + } + + #[test] + fn display() { + assert_eq!( + format!( + "{}", + Height { + revision: Some(nz!(1)), + height: 1, + } + ), + "1-1" + ); + + assert_eq!( + format!( + "{}", + Height { + revision: None, + height: 1, + } + ), + "1" + ); + + assert_eq!( + format!( + "{:#}", + Height { + revision: None, + height: 1, + } + ), + "0-1" + ); + + assert_eq!( + format!( + "{:#}", + Height { + revision: Some(nz!(1)), + height: 1, + } + ), + "1-1" + ); + } + + #[test] + fn from_str() { + assert_eq!( + Height::from_str("1-1"), + Ok(Height { + revision: Some(nz!(1)), + height: 1, + }) + ); + + assert_eq!( + Height::from_str("1-0"), + Ok(Height { + revision: Some(nz!(1)), + height: 0, + }) + ); + + assert_eq!( + Height::from_str(&format!("{0}-{0}", u64::MAX)), + Ok(Height { + revision: Some(nz!(u64::MAX)), + height: u64::MAX, + }) + ); + + // will try to parse "2-0" as a u64 + assert!(matches!( + Height::from_str("4-2-0"), + Err(HeightFromStrError::ParseIntError(_)) + )); + + assert!(matches!( + Height::from_str("gibberish"), + Err(HeightFromStrError::ParseIntError(_)) + )); + } + + #[test] + fn cmp() { + let h1 = Height::new(1); + let h2 = Height::new(2); + + let h1_1 = Height::new_with_revision(1, 1); + let h1_2 = Height::new_with_revision(1, 2); + + let h2_1 = Height::new_with_revision(2, 1); + let h2_2 = Height::new_with_revision(2, 2); + + // no revision + assert_eq!(h1.cmp(&h1), Ordering::Equal); + assert_eq!(h2.cmp(&h1), Ordering::Greater); + assert_eq!(h1.cmp(&h2), Ordering::Less); + + // both same revision + assert_eq!(h1_1.cmp(&h1_1), Ordering::Equal); + assert_eq!(h1_2.cmp(&h1_1), Ordering::Greater); + assert_eq!(h1_1.cmp(&h1_2), Ordering::Less); + + // rhs revision (will be ignored) + assert_eq!(h1.cmp(&h1_1), Ordering::Equal); + assert_eq!(h2.cmp(&h1_1), Ordering::Greater); + assert_eq!(h1.cmp(&h1_2), Ordering::Less); + + // lhs revision (will be ignored) + assert_eq!(h1_1.cmp(&h1), Ordering::Equal); + assert_eq!(h1_1.cmp(&h2), Ordering::Less); + assert_eq!(h1_2.cmp(&h1), Ordering::Greater); + + // both with revision, but different + assert_eq!(h1_1.cmp(&h2_1), Ordering::Less); + assert_eq!(h2_1.cmp(&h1_1), Ordering::Greater); + + assert_eq!(h1_2.cmp(&h2_1), Ordering::Less); + assert_eq!(h2_1.cmp(&h1_2), Ordering::Greater); + + assert_eq!(h1_2.cmp(&h2_2), Ordering::Less); + assert_eq!(h2_1.cmp(&h1_1), Ordering::Greater); + } +} diff --git a/lib/unionlabs-primitives/Cargo.toml b/lib/unionlabs-primitives/Cargo.toml index deac819e58f..f481ac1cf10 100644 --- a/lib/unionlabs-primitives/Cargo.toml +++ b/lib/unionlabs-primitives/Cargo.toml @@ -18,19 +18,17 @@ base64 = { workspace = true, optional = true, features = ["std"] } bincode = { workspace = true, optional = true, features = ["alloc"] } bs58 = { workspace = true, optional = true, features = ["std"] } generic-array = { workspace = true, optional = true } -hex = { workspace = true, features = ["std"] } -primitive-types = { workspace = true } +hex = { workspace = true } +primitive-types = { workspace = true, optional = true } rlp = { workspace = true, optional = true } +ruint = { workspace = true, features = ["alloc"] } schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"], optional = true } -serde_bytes = { version = "0.11.17", optional = true } +serde_bytes = { version = "0.11.17", default-features = false, optional = true } subtle-encoding = { workspace = true, features = ["bech32-preview"] } thiserror = { workspace = true } typenum = { workspace = true, optional = true } -# TODO: This is only used for uint, replace with ruint -uint = "0.9.5" - [dev-dependencies] serde_json = { workspace = true } unionlabs = { workspace = true, features = ["test-utils"] } @@ -42,14 +40,11 @@ default = ["serde", "base64"] base58 = ["dep:bs58"] base64 = ["dep:base64"] bincode = ["dep:bincode"] -rlp = ["dep:rlp", "primitive-types/rlp"] +rlp = ["dep:rlp", "ruint/rlp"] schemars = ["dep:schemars"] serde = ["dep:serde", "dep:serde_bytes"] alloy-primitives-compat = ["dep:alloy-primitives"] -alloy-sol-types-compat = ["dep:alloy-sol-types", "dep:alloy-primitives"] -generic-array-compat = ["dep:generic-array", "dep:typenum", "typenum/const-generics"] -primitive-types-compat = [ - # TODO: Make this dep optional again once we switch to ruint - # "dep:primitive-types" -] +alloy-sol-types-compat = ["dep:alloy-sol-types", "dep:alloy-primitives"] +generic-array-compat = ["dep:generic-array", "dep:typenum", "typenum/const-generics"] +primitive-types-compat = ["dep:primitive-types"] diff --git a/lib/unionlabs-primitives/src/bech32.rs b/lib/unionlabs-primitives/src/bech32.rs index d9baa52db82..c214b8f91c1 100644 --- a/lib/unionlabs-primitives/src/bech32.rs +++ b/lib/unionlabs-primitives/src/bech32.rs @@ -1,3 +1,4 @@ +use alloc::{string::String, vec::Vec}; use core::{convert::Infallible, fmt, str::FromStr}; #[cfg(feature = "serde")] @@ -167,6 +168,8 @@ where &self, encoder: &mut E, ) -> Result<(), bincode::error::EncodeError> { + use alloc::string::ToString; + self.to_string().encode(encoder) } } @@ -181,6 +184,8 @@ where decoder: &mut D, ) -> Result { >::decode(decoder).and_then(|s| { + use alloc::string::ToString; + s.parse::() .map_err(|e| bincode::error::DecodeError::OtherString(e.to_string())) }) diff --git a/lib/unionlabs-primitives/src/bytes.rs b/lib/unionlabs-primitives/src/bytes.rs index 0449fb4c183..7a52818b83c 100644 --- a/lib/unionlabs-primitives/src/bytes.rs +++ b/lib/unionlabs-primitives/src/bytes.rs @@ -1,4 +1,9 @@ -use alloc::borrow::Cow; +use alloc::{ + borrow::{Cow, ToOwned}, + vec::Vec, +}; +#[cfg(feature = "schemars")] +use alloc::{format, string::String}; use core::{ array::TryFromSliceError, cmp::Ordering, fmt, marker::PhantomData, ops::Deref, str::FromStr, }; @@ -176,6 +181,8 @@ impl<'de, E: Encoding> serde::Deserialize<'de> for Bytes { D: serde::Deserializer<'de>, { if deserializer.is_human_readable() { + use alloc::string::String; + String::deserialize(deserializer) .and_then(|s| s.parse().map_err(::serde::de::Error::custom)) } else { @@ -377,6 +384,8 @@ impl schemars::JsonSchema for Bytes { } fn json_schema(_: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { + use alloc::boxed::Box; + use schemars::schema::{InstanceType, Metadata, SchemaObject, SingleOrVec}; SchemaObject { diff --git a/lib/unionlabs-primitives/src/compat.rs b/lib/unionlabs-primitives/src/compat.rs index fd811d55da9..c8d60811581 100644 --- a/lib/unionlabs-primitives/src/compat.rs +++ b/lib/unionlabs-primitives/src/compat.rs @@ -27,10 +27,24 @@ pub mod primitive_types_compat { Self::new(value.0) } } + + impl From for U256 { + fn from(value: primitive_types::U256) -> Self { + Self(value) + } + } + + impl From for primitive_types::U256 { + fn from(value: U256) -> Self { + value.0 + } + } } #[cfg(feature = "generic-array-compat")] pub mod generic_array_compat { + use alloc::borrow::ToOwned; + use generic_array::{ArrayLength, GenericArray}; use typenum::{Const, ToUInt, U}; @@ -134,6 +148,8 @@ pub mod alloy_primitives_compat { #[cfg(feature = "alloy-sol-types-compat")] pub mod alloy_sol_types_compat { + use alloc::vec::Vec; + use alloy_sol_types::{ SolType, SolValue, Word, abi::token::WordToken, diff --git a/lib/unionlabs-primitives/src/encoding.rs b/lib/unionlabs-primitives/src/encoding.rs index 778c6f35706..a378b3a9f2d 100644 --- a/lib/unionlabs-primitives/src/encoding.rs +++ b/lib/unionlabs-primitives/src/encoding.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use core::fmt; trait Sealed {} @@ -65,8 +66,8 @@ impl Encoding for HexPrefixed { #[derive(Debug, Clone, PartialEq, thiserror::Error)] pub enum HexPrefixedFromStrError { - #[error("invalid hex")] - InvalidHex(#[from] hex::FromHexError), + #[error("invalid hex: {0}")] + InvalidHex(hex::FromHexError), #[error("missing 0x prefix")] MissingPrefix, } @@ -76,21 +77,27 @@ impl Sealed for HexUnprefixed {} impl Encoding for HexUnprefixed { const NAME: &'static str = "HexUnprefixed"; - type Error = hex::FromHexError; + type Error = HexUnprefixedFromStrError; fn fmt(bytes: &[u8], f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&hex::encode(bytes)) } fn decode>(data: T) -> Result, Self::Error> { - hex::decode(data) + hex::decode(data).map_err(HexUnprefixedFromStrError::InvalidHex) } fn decode_to_slice>(data: T, out: &mut [u8]) -> Result<(), Self::Error> { - hex::decode_to_slice(data, out) + hex::decode_to_slice(data, out).map_err(HexUnprefixedFromStrError::InvalidHex) } } +#[derive(Debug, Clone, PartialEq, thiserror::Error)] +pub enum HexUnprefixedFromStrError { + #[error("invalid hex: {0}")] + InvalidHex(hex::FromHexError), +} + #[cfg(feature = "base64")] pub struct Base64; #[cfg(feature = "base64")] diff --git a/lib/unionlabs-primitives/src/fixed_bytes.rs b/lib/unionlabs-primitives/src/fixed_bytes.rs index 7aa469d5e52..8c91ee3a730 100644 --- a/lib/unionlabs-primitives/src/fixed_bytes.rs +++ b/lib/unionlabs-primitives/src/fixed_bytes.rs @@ -1,3 +1,6 @@ +use alloc::vec::Vec; +#[cfg(feature = "schemars")] +use alloc::{boxed::Box, format, string::String}; use core::{ borrow::Borrow, cmp::Ordering, @@ -202,6 +205,8 @@ impl<'de, const BYTES: usize, E: Encoding> serde::Deserialize<'de> for FixedByte D: serde::Deserializer<'de>, { if deserializer.is_human_readable() { + use alloc::string::String; + String::deserialize(deserializer) .and_then(|s| s.parse().map_err(::serde::de::Error::custom)) } else { diff --git a/lib/unionlabs-primitives/src/lib.rs b/lib/unionlabs-primitives/src/lib.rs index 20bd161c6d8..7574334144f 100644 --- a/lib/unionlabs-primitives/src/lib.rs +++ b/lib/unionlabs-primitives/src/lib.rs @@ -1,3 +1,4 @@ +#![no_std] #![deny( clippy::pedantic, clippy::std_instead_of_core, diff --git a/lib/unionlabs-primitives/src/uint.rs b/lib/unionlabs-primitives/src/uint.rs index 27f292aba4f..1339d2bd2b5 100644 --- a/lib/unionlabs-primitives/src/uint.rs +++ b/lib/unionlabs-primitives/src/uint.rs @@ -1,5 +1,6 @@ #![allow(clippy::disallowed_types)] // need to access the inner type to wrap it +use alloc::{borrow::ToOwned, format, string::String, vec::Vec}; use core::{ fmt::{self, Display}, iter::Sum, @@ -8,10 +9,10 @@ use core::{ str::FromStr, }; -/// [`primitive_types::U256`] can't roundtrip through string conversion since it parses from hex but displays as decimal. +/// [`ruint::aliases::U256`] can't roundtrip through string conversion since it parses from hex but displays as decimal. #[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Default)] #[repr(transparent)] -pub struct U256(pub primitive_types::U256); +pub struct U256(pub ruint::aliases::U256); impl fmt::Debug for U256 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -41,9 +42,11 @@ impl<'de> serde::Deserialize<'de> for U256 { where D: serde::Deserializer<'de>, { + use alloc::string::String; + String::deserialize(deserializer) .and_then(|s| { - primitive_types::U256::from_dec_str(&s).map_err(|err| { + ruint::aliases::U256::from_str_radix(&s, 10).map_err(|err| { serde::de::Error::custom(format!("failure to parse string data: {err}")) }) }) @@ -54,6 +57,8 @@ impl<'de> serde::Deserialize<'de> for U256 { #[cfg(feature = "serde")] #[allow(clippy::missing_errors_doc)] pub mod u256_big_endian_hex { + use alloc::string::String; + use serde::de::{self, Deserialize}; use crate::U256; @@ -139,6 +144,8 @@ impl schemars::JsonSchema for U256 { } fn json_schema(_: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { + use alloc::boxed::Box; + use schemars::schema::{ InstanceType, Metadata, SchemaObject, SingleOrVec, StringValidation, }; @@ -182,25 +189,25 @@ impl U256 { impl From for U256 { fn from(value: u32) -> Self { - Self(primitive_types::U256::from(value)) + Self(ruint::aliases::U256::from(value)) } } impl From for U256 { fn from(value: NonZeroU32) -> Self { - Self(primitive_types::U256::from(value.get())) + Self(ruint::aliases::U256::from(value.get())) } } impl From for U256 { fn from(value: u64) -> Self { - Self(primitive_types::U256::from(value)) + Self(ruint::aliases::U256::from(value)) } } impl From for U256 { fn from(value: u128) -> Self { - Self(primitive_types::U256::from(value)) + Self(ruint::aliases::U256::from(value)) } } @@ -208,11 +215,7 @@ impl TryFrom for u32 { type Error = (); fn try_from(value: U256) -> Result { - if value > U256::from(u32::MAX) { - Err(()) - } else { - Ok(value.0.as_u32()) - } + value.0.try_into().map_err(|_| ()) } } @@ -220,11 +223,7 @@ impl TryFrom for u64 { type Error = (); fn try_from(value: U256) -> Result { - if value > U256::from(u64::MAX) { - Err(()) - } else { - Ok(value.0.as_u64()) - } + value.0.try_into().map_err(|_| ()) } } @@ -232,51 +231,29 @@ impl TryFrom for u128 { type Error = (); fn try_from(value: U256) -> Result { - if value > U256::from(u128::MAX) { - Err(()) - } else { - Ok(value.0.as_u128()) - } - } -} - -impl From for U256 { - fn from(value: primitive_types::U256) -> Self { - Self(value) - } -} - -impl From for primitive_types::U256 { - fn from(value: U256) -> Self { - value.0 + value.0.try_into().map_err(|_| ()) } } impl U256 { #[must_use] - pub fn leading_zeros(&self) -> u32 { + pub fn leading_zeros(&self) -> usize { self.0.leading_zeros() } #[must_use] pub fn to_le_bytes(&self) -> [u8; 32] { - let mut buf = [0; 32]; - self.0.to_little_endian(&mut buf); - buf + self.0.to_le_bytes() } #[must_use] pub fn to_be_bytes(&self) -> [u8; 32] { - let mut buf = [0; 32]; - self.0.to_big_endian(&mut buf); - buf + self.0.to_be_bytes() } #[must_use] pub fn to_be_bytes_packed(&self) -> Vec { - let buffer = self.to_be_bytes(); - let leading_empty_bytes = (self.leading_zeros() / 8) as usize; - buffer[leading_empty_bytes..].to_vec() + self.0.to_be_bytes_trimmed_vec() } /// Attempt to convert the provided big-endian bytes into a [`U256`]. @@ -288,7 +265,7 @@ impl U256 { let len = bz.len(); if (0..=32).contains(&len) { - Ok(Self(primitive_types::U256::from_big_endian(bz))) + Ok(Self(ruint::aliases::U256::from_be_slice(bz))) } else { Err(TryFromBytesError { expected_max_len: 32, @@ -299,28 +276,28 @@ impl U256 { #[must_use] pub fn from_be_bytes(bz: [u8; 32]) -> Self { - Self(primitive_types::U256::from_big_endian(&bz)) + Self(ruint::aliases::U256::from_be_bytes(bz)) } #[must_use] pub fn from_le_bytes(bz: [u8; 32]) -> Self { - Self(primitive_types::U256::from_little_endian(&bz)) + Self(ruint::aliases::U256::from_le_bytes(bz)) } #[must_use] pub const fn from_limbs(limbs: [u64; 4]) -> Self { - Self(primitive_types::U256(limbs)) + Self(ruint::aliases::U256::from_limbs(limbs)) } #[must_use] pub const fn as_limbs(&self) -> [u64; 4] { - self.0.0 + *self.0.as_limbs() } #[must_use] pub fn to_be_hex(&self) -> String { let encoded = if self == &Self::ZERO { - "0".to_string() + "0".to_owned() } else { hex::encode(self.to_be_bytes()) }; @@ -368,14 +345,7 @@ impl U256 { #[must_use] pub fn div_ceil(self, other: Self) -> Self { - // https://doc.rust-lang.org/stable/src/core/num/uint_macros.rs.html#3247 - - let (d, r) = self.0.div_mod(other.0); - if r.is_zero() { - Self(d) - } else { - Self(d) + Self::ONE - } + Self(self.0.div_ceil(other.0)) } pub fn checked_sub(self, other: Self) -> Option { @@ -398,20 +368,18 @@ pub enum TryFromHexError { EmptyString, #[error(transparent)] TryFromBytes(#[from] TryFromBytesError), - #[error(transparent)] - Hex(#[from] hex::FromHexError), + #[error("{0}")] + Hex(hex::FromHexError), } impl FromStr for U256 { - type Err = ::uint::FromDecStrErr; + type Err = ruint::ParseError; fn from_str(s: &str) -> Result { - primitive_types::U256::from_dec_str(s).map(Self) + ruint::aliases::U256::from_str_radix(s, 10).map(Self) } } -pub use ::uint::FromDecStrErr; - #[cfg(feature = "rlp")] impl rlp::Encodable for U256 { fn rlp_append(&self, s: &mut rlp::RlpStream) { @@ -422,7 +390,7 @@ impl rlp::Encodable for U256 { #[cfg(feature = "rlp")] impl rlp::Decodable for U256 { fn decode(rlp: &rlp::Rlp) -> Result { - ::decode(rlp).map(Self) + ::decode(rlp).map(Self) } } diff --git a/lib/unionlabs-tuple/Cargo.toml b/lib/unionlabs-tuple/Cargo.toml new file mode 100644 index 00000000000..190877557ff --- /dev/null +++ b/lib/unionlabs-tuple/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "unionlabs-tuple" +version = "0.0.0" + +authors = { workspace = true } +edition = { workspace = true } +license-file = { workspace = true } +publish = { workspace = true } +repository = { workspace = true } + +[lints] +workspace = true + +[dependencies] +macros = {workspace = true} + +[features] +default = [] diff --git a/lib/unionlabs/src/tuple.rs b/lib/unionlabs-tuple/src/lib.rs similarity index 61% rename from lib/unionlabs/src/tuple.rs rename to lib/unionlabs-tuple/src/lib.rs index c2ca33ffe49..cbfcbff2bb2 100644 --- a/lib/unionlabs/src/tuple.rs +++ b/lib/unionlabs-tuple/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + pub use macros::AsTuple; pub trait Tuple { @@ -17,38 +19,38 @@ pub trait TupleFromRef: Tuple { } macro_rules! impl_is_tuple { - ($($T:ident)*) => { - impl<$($T),*> Tuple for ($($T,)*) { - type Ref<'a> = ($(&'a $T,)*) where $($T: 'a,)*; + ($($T:ident)*) => { + impl<$($T),*> Tuple for ($($T,)*) { + type Ref<'a> = ($(&'a $T,)*) where $($T: 'a,)*; - const ARITY: usize = { - $(const $T: usize = 1;)* + const ARITY: usize = { + $(const $T: usize = 1;)* - $($T + )* 0 - }; - } + $($T + )* 0 + }; + } - impl<$($T),*> TupleAsRef for ($($T,)*) { - fn as_ref(&self) -> Self::Ref<'_> { - #[allow(non_snake_case)] - let ($($T,)*) = self; + impl<$($T),*> TupleAsRef for ($($T,)*) { + fn as_ref(&self) -> Self::Ref<'_> { + #[allow(non_snake_case)] + let ($($T,)*) = self; - #[allow(clippy::unused_unit)] - ($(&$T,)*) - } + #[allow(clippy::unused_unit)] + ($(&$T,)*) } + } - impl<$($T: Clone),*> TupleFromRef for ($($T,)*) { - fn from_ref(tuple: Self::Ref<'_>) -> Self { - #[allow(non_snake_case)] - let ($($T,)*) = tuple; + impl<$($T: Clone),*> TupleFromRef for ($($T,)*) { + fn from_ref(tuple: Self::Ref<'_>) -> Self { + #[allow(non_snake_case)] + let ($($T,)*) = tuple; - #[allow(clippy::unused_unit)] - ($($T.clone(),)*) - } + #[allow(clippy::unused_unit)] + ($($T.clone(),)*) } - }; - } + } + }; +} impl_is_tuple!(); impl_is_tuple!(A); diff --git a/lib/unionlabs/Cargo.toml b/lib/unionlabs/Cargo.toml index 241b6dcd7bb..e05ffb635af 100644 --- a/lib/unionlabs/Cargo.toml +++ b/lib/unionlabs/Cargo.toml @@ -39,10 +39,12 @@ bs58 = { workspace = true } # near-primitives-core = { version = "0.21", optional = true } near-sdk = { workspace = true, optional = true } schemars = { workspace = true, features = ["derive"], optional = true } -serde_bytes = "0.11.17" +serde_bytes = { version = "0.11.17", default-features = false } solidity-slot = { workspace = true } unionlabs-encoding = { workspace = true, features = ["proto", "json"] } +unionlabs-height = { workspace = true, features = ["serde"] } # TODO: Feature gate serde correctly throughout this crate unionlabs-primitives = { workspace = true, features = ["generic-array-compat", "serde", "base64", "base58"] } +unionlabs-tuple = { workspace = true } [dev-dependencies] hex-literal = { workspace = true } @@ -64,10 +66,15 @@ std = ["sha2/std", "unionlabs-encoding/std"] fuzzing = [] test-utils = ["dep:serde_json"] -bcs = ["unionlabs-encoding/bcs"] -bincode = ["dep:bincode", "unionlabs-primitives/bincode", "unionlabs-encoding/bincode"] -proto = ["unionlabs-encoding/proto"] -rlp = ["unionlabs-primitives/rlp"] +bcs = ["unionlabs-encoding/bcs"] +bincode = [ + "dep:bincode", + "unionlabs-primitives/bincode", + "unionlabs-encoding/bincode", + "unionlabs-height/bincode", +] +proto = ["unionlabs-encoding/proto", "unionlabs-height/proto"] +rlp = ["unionlabs-primitives/rlp"] schemars = ["dep:schemars", "unionlabs-primitives/schemars"] -ssz = ["unionlabs-encoding/ssz"] +ssz = ["unionlabs-encoding/ssz"] stargate = ["cosmwasm", "cosmwasm-std/stargate"] diff --git a/lib/unionlabs/src/ibc/core/client/height.rs b/lib/unionlabs/src/ibc/core/client/height.rs index f5837e7dc41..3f2fe05a3f3 100644 --- a/lib/unionlabs/src/ibc/core/client/height.rs +++ b/lib/unionlabs/src/ibc/core/client/height.rs @@ -1,467 +1 @@ -use core::{ - cmp::Ordering, - fmt::{self, Debug}, - num::{NonZeroU64, ParseIntError}, - str::FromStr, -}; - -use macros::model; - -#[model( - proto(raw(protos::ibc::core::client::v1::Height), into, from), - no_serde -)] -#[derive(Default, Copy)] -#[debug("Height({self})")] -#[derive(Hash)] -#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] -// TODO: Implement Valuable via Display once https://github.com/tokio-rs/valuable/pull/133 is merged -pub struct Height { - revision: Option, - height: u64, -} - -// #[cfg(feature = "valuable")] -// impl valuable::Valuable for Height { -// fn as_value(&self) -> valuable::Value<'_> { -// valuable::Value::Renderable(valuable::Renderable::Display(self)) -// } - -// fn visit(&self, visit: &mut dyn valuable::Visit) { -// visit.visit_value(self.as_value()); -// } -// } - -impl Height { - #[must_use] - pub const fn new(height: u64) -> Self { - Self { - revision: None, - height, - } - } - - #[must_use] - pub const fn new_with_revision(revision: u64, height: u64) -> Self { - Self { - revision: NonZeroU64::new(revision), - height, - } - } - - #[must_use] - pub const fn height(&self) -> u64 { - self.height - } - - #[must_use] - pub const fn height_mut(&mut self) -> &mut u64 { - &mut self.height - } - - #[must_use] - pub const fn revision(&self) -> u64 { - match self.revision { - Some(revision) => revision.get(), - None => 0, - } - } - - #[must_use] - pub const fn revision_matches(&self, other: &Self) -> bool { - match (self.revision, other.revision) { - (Some(lhs), Some(rhs)) => lhs.get() == rhs.get(), - _ => true, - } - } - - #[must_use] - pub const fn increment(self) -> Self { - Self { - revision: self.revision, - height: self.height + 1, - } - } - - #[must_use] - pub const fn increment_by(self, height: u64) -> Self { - Self { - revision: self.revision, - height: self.height + height, - } - } - - pub fn from_str_allow_zero_revision(s: &str) -> Result { - match s.split_once('-') { - Some((n, h)) => Ok(Self::new_with_revision(n.parse()?, h.parse()?)), - None => Err(HeightFromStrError::Invalid), - } - } -} - -// Implement once this is stabilized: https://github.com/rust-lang/rust/issues/42168 -// impl Step for Height { -// fn steps_between(start: &Self, end: &Self) -> Option { -// start -// .revision_matches(end) -// .then(|| ::steps_between(&start.height(), &end.height())) -// .flatten() -// } - -// fn forward_checked(start: Self, count: usize) -> Option { -// start -// .revision_matches(end) -// .then(|| ::forward_checked(&start.height(), &end.height())) -// .flatten() -// } - -// fn backward_checked(start: Self, count: usize) -> Option { -// start -// .revision_matches(end) -// .then(|| ::backward_checked(&start.height(), &end.height())) -// .flatten() -// } -// } - -impl FromStr for Height { - type Err = HeightFromStrError; - - fn from_str(s: &str) -> Result { - match s.split_once('-') { - Some((n, h)) => Ok(Self { - revision: Some(n.parse().map_err(HeightFromStrError::ParseIntError)?), - height: h.parse().map_err(HeightFromStrError::ParseIntError)?, - }), - None => Ok(Self { - revision: None, - height: s.parse().map_err(HeightFromStrError::ParseIntError)?, - }), - } - } -} - -#[derive(Debug, PartialEq, Eq, thiserror::Error)] -pub enum HeightFromStrError { - #[error("invalid numeric value in height string")] - ParseIntError(#[from] ParseIntError), - #[error("invalid height string")] - Invalid, -} - -impl PartialOrd for Height { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for Height { - fn cmp(&self, other: &Self) -> Ordering { - match (self.revision, other.revision) { - (Some(this_revision), Some(other_revision)) => match this_revision.cmp(&other_revision) - { - Ordering::Less => Ordering::Less, - Ordering::Equal => self.height.cmp(&other.height), - Ordering::Greater => Ordering::Greater, - }, - _ => self.height.cmp(&other.height), - } - } -} - -impl fmt::Display for Height { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if f.alternate() { - write!(f, "{}-{}", self.revision(), self.height) - } else { - match self.revision { - Some(revision_number) => { - write!(f, "{}-{}", revision_number, self.height) - } - None => { - write!(f, "{}", self.height) - } - } - } - } -} - -// #[cfg(feature = "serde")] -impl serde::Serialize for Height { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - use serde::ser::SerializeTuple; - - if serializer.is_human_readable() { - serializer.collect_str(self) - } else { - let mut ser = serializer.serialize_tuple(2)?; - ser.serialize_element(&self.revision())?; - ser.serialize_element(&self.height())?; - ser.end() - } - } -} - -// #[cfg(feature = "serde")] -impl<'de> serde::Deserialize<'de> for Height { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - if deserializer.is_human_readable() { - struct HeightStrVisitor; - - impl serde::de::Visitor<'_> for HeightStrVisitor { - type Value = Height; - - fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { - formatter.write_str("string representation of Height") - } - - fn visit_str(self, v: &str) -> Result - where - E: serde::de::Error, - { - v.parse().map_err(serde::de::Error::custom) - } - - fn visit_string(self, v: String) -> Result - where - E: serde::de::Error, - { - v.parse().map_err(serde::de::Error::custom) - } - } - - deserializer.deserialize_any(HeightStrVisitor) - } else { - <(u64, u64)>::deserialize(deserializer).map(|(n, h)| Height::new_with_revision(n, h)) - } - } -} - -#[cfg(feature = "schemars")] -impl ::schemars::JsonSchema for Height { - fn schema_name() -> String { - "Height".to_owned() - } - - fn schema_id() -> alloc::borrow::Cow<'static, str> { - alloc::borrow::Cow::Borrowed(concat!(module_path!(), "::Height")) - } - - fn json_schema(_: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { - use schemars::schema::{ - InstanceType, Metadata, SchemaObject, SingleOrVec, StringValidation, - }; - - SchemaObject { - metadata: Some(Box::new(Metadata { - description: Some( - "A blockchain height, optionally prefixed with a revision \ - number as per the [IBC Specification]\ - (https://ibc.cosmos.network/main/ibc/overview/#ibc-client-heights)." - .to_owned(), - ), - ..Default::default() - })), - instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))), - string: Some(Box::new(StringValidation { - // nonzero revision number - revision height - pattern: Some(r"([1-9]\d*-)?\d+".to_owned()), - ..Default::default() - })), - ..Default::default() - } - .into() - } -} - -// #[cfg(feature = "proto")] -pub mod proto { - use core::num::NonZeroU64; - - use crate::ibc::core::client::height::Height; - - impl From for Height { - fn from(proto: protos::ibc::core::client::v1::Height) -> Self { - Self { - revision: NonZeroU64::new(proto.revision_number), - height: proto.revision_height, - } - } - } - impl From for protos::ibc::core::client::v1::Height { - fn from(value: Height) -> Self { - Self { - revision_number: value.revision.map_or_else(|| 0, NonZeroU64::get), - revision_height: value.height, - } - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - macro_rules! nz { - ($n:expr) => { - const { NonZeroU64::new($n).unwrap() } - }; - } - - #[test] - fn debug() { - assert_eq!( - format!( - "{:?}", - Height { - revision: Some(nz!(1)), - height: 1, - } - ), - "Height(1-1)" - ); - - assert_eq!( - format!( - "{:?}", - Height { - revision: None, - height: 1, - } - ), - "Height(1)" - ); - } - - #[test] - fn display() { - assert_eq!( - format!( - "{}", - Height { - revision: Some(nz!(1)), - height: 1, - } - ), - "1-1" - ); - - assert_eq!( - format!( - "{}", - Height { - revision: None, - height: 1, - } - ), - "1" - ); - - assert_eq!( - format!( - "{:#}", - Height { - revision: None, - height: 1, - } - ), - "0-1" - ); - - assert_eq!( - format!( - "{:#}", - Height { - revision: Some(nz!(1)), - height: 1, - } - ), - "1-1" - ); - } - - #[test] - fn from_str() { - assert_eq!( - Height::from_str("1-1"), - Ok(Height { - revision: Some(nz!(1)), - height: 1, - }) - ); - - assert_eq!( - Height::from_str("1-0"), - Ok(Height { - revision: Some(nz!(1)), - height: 0, - }) - ); - - assert_eq!( - Height::from_str(&format!("{0}-{0}", u64::MAX)), - Ok(Height { - revision: Some(nz!(u64::MAX)), - height: u64::MAX, - }) - ); - - // will try to parse "2-0" as a u64 - assert!(matches!( - Height::from_str("4-2-0"), - Err(HeightFromStrError::ParseIntError(_)) - )); - - assert!(matches!( - Height::from_str("gibberish"), - Err(HeightFromStrError::ParseIntError(_)) - )); - } - - #[test] - fn cmp() { - let h1 = Height::new(1); - let h2 = Height::new(2); - - let h1_1 = Height::new_with_revision(1, 1); - let h1_2 = Height::new_with_revision(1, 2); - - let h2_1 = Height::new_with_revision(2, 1); - let h2_2 = Height::new_with_revision(2, 2); - - // no revision - assert_eq!(h1.cmp(&h1), Ordering::Equal); - assert_eq!(h2.cmp(&h1), Ordering::Greater); - assert_eq!(h1.cmp(&h2), Ordering::Less); - - // both same revision - assert_eq!(h1_1.cmp(&h1_1), Ordering::Equal); - assert_eq!(h1_2.cmp(&h1_1), Ordering::Greater); - assert_eq!(h1_1.cmp(&h1_2), Ordering::Less); - - // rhs revision (will be ignored) - assert_eq!(h1.cmp(&h1_1), Ordering::Equal); - assert_eq!(h2.cmp(&h1_1), Ordering::Greater); - assert_eq!(h1.cmp(&h1_2), Ordering::Less); - - // lhs revision (will be ignored) - assert_eq!(h1_1.cmp(&h1), Ordering::Equal); - assert_eq!(h1_1.cmp(&h2), Ordering::Less); - assert_eq!(h1_2.cmp(&h1), Ordering::Greater); - - // both with revision, but different - assert_eq!(h1_1.cmp(&h2_1), Ordering::Less); - assert_eq!(h2_1.cmp(&h1_1), Ordering::Greater); - - assert_eq!(h1_2.cmp(&h2_1), Ordering::Less); - assert_eq!(h2_1.cmp(&h1_2), Ordering::Greater); - - assert_eq!(h1_2.cmp(&h2_2), Ordering::Less); - assert_eq!(h2_1.cmp(&h1_1), Ordering::Greater); - } -} +pub use unionlabs_height::*; diff --git a/lib/unionlabs/src/lib.rs b/lib/unionlabs/src/lib.rs index 949bb9ef213..c9799a82234 100644 --- a/lib/unionlabs/src/lib.rs +++ b/lib/unionlabs/src/lib.rs @@ -30,6 +30,7 @@ pub use unionlabs_encoding::impl_ethabi_via_try_from_into; #[cfg(feature = "proto")] pub use unionlabs_encoding::impl_proto_via_try_from_into; pub use unionlabs_primitives as primitives; +pub use unionlabs_tuple as tuple; /// Wrapper types around protos defined in , matching the proto module structure. pub mod google; @@ -69,8 +70,6 @@ pub(crate) mod macros; pub mod errors; -pub mod tuple; - #[cfg(feature = "proto")] pub use ::prost; diff --git a/lib/voyager-primitives/Cargo.toml b/lib/voyager-primitives/Cargo.toml index e9ec4cc9f84..d2f48d5d589 100644 --- a/lib/voyager-primitives/Cargo.toml +++ b/lib/voyager-primitives/Cargo.toml @@ -17,11 +17,21 @@ macros = { workspace = true } schemars = { workspace = true, optional = true, features = ["derive"] } serde = { workspace = true, optional = true, features = ["derive"] } serde_json = { workspace = true } -unionlabs = { workspace = true } +unionlabs-height = { workspace = true } +unionlabs-primitives = { workspace = true } [features] default = [] -bincode = ["consensus-primitives/bincode"] -schemars = ["dep:schemars", "consensus-primitives/schemars"] -serde = ["dep:serde", "consensus-primitives/serde"] +bincode = [ + "consensus-primitives/bincode", + "unionlabs-height/bincode", + "unionlabs-primitives/bincode", +] +schemars = ["dep:schemars", "consensus-primitives/schemars", "unionlabs-primitives/schemars"] +serde = [ + "dep:serde", + "consensus-primitives/serde", + "unionlabs-height/serde", + "unionlabs-primitives/serde", +] diff --git a/lib/voyager-primitives/src/lib.rs b/lib/voyager-primitives/src/lib.rs index df34c431e06..9b2a95e5908 100644 --- a/lib/voyager-primitives/src/lib.rs +++ b/lib/voyager-primitives/src/lib.rs @@ -1,16 +1,20 @@ +#![no_std] #![feature(trait_alias)] #![warn(clippy::pedantic)] -use core::{fmt, str::FromStr}; -use std::fmt::{Debug, Display}; +extern crate alloc; + +use core::{ + fmt, + fmt::{Debug, Display}, + str::FromStr, +}; pub use consensus_primitives::{Duration, Timestamp}; use macros::apply; use serde_json::Value; -use unionlabs::{ - ibc::core::client::height::{Height, HeightFromStrError}, - primitives::{Bytes, H256, encoding::HexUnprefixed}, -}; +use unionlabs_height::{Height, HeightFromStrError}; +use unionlabs_primitives::{Bytes, H256, encoding::HexUnprefixed}; /// Represents the IBC interface of a chain. /// @@ -519,7 +523,7 @@ macro_rules! str_newtype { )] #[cfg_attr(feature = "schemars", derive(::schemars::JsonSchema))] #[debug("{}({:?})", stringify!($Struct), self.0)] - $vis struct $Struct(#[doc(hidden)] ::std::borrow::Cow<'static, str>); + $vis struct $Struct(#[doc(hidden)] ::alloc::borrow::Cow<'static, str>); impl ::core::fmt::Display for $Struct { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { @@ -544,7 +548,7 @@ macro_rules! str_newtype { /// Construct a new [` #[doc = stringify!($Struct)] /// `]. - pub fn new(s: impl Into<::std::borrow::Cow<'static, str>>) -> Self { + pub fn new(s: impl Into<::alloc::borrow::Cow<'static, str>>) -> Self { Self(s.into()) } @@ -559,7 +563,7 @@ macro_rules! str_newtype { /// `const`-friendly version of [`Self::new`]. #[must_use = concat!("constructing a ", stringify!($Struct), " has no effect")] pub const fn new_static(ibc_interface: &'static str) -> Self { - Self(::std::borrow::Cow::Borrowed(ibc_interface)) + Self(::alloc::borrow::Cow::Borrowed(ibc_interface)) } } }; diff --git a/tools/rust/rust.nix b/tools/rust/rust.nix index 9257e9a34ab..706c4f88a5c 100644 --- a/tools/rust/rust.nix +++ b/tools/rust/rust.nix @@ -27,7 +27,8 @@ _: { clippy = "clippy"; miri = "miri"; rust-src = "rust-src"; - llvm-tools-preview = "llvm-tools-preview"; + llvm-tools = "llvm-tools"; + llvm-bitcode-linker = "llvm-bitcode-linker"; }; # rustSrc = @@ -52,9 +53,11 @@ _: { # }); rustSrc = - (mkToolchain { - components = [ availableComponents.rust-src ]; - }).passthru.availableComponents.rust-src; + (dbg + (mkToolchain { + components = [ availableComponents.rust-src ]; + }).passthru.availableComponents + ).rust-src; mkToolchain = { @@ -106,6 +109,11 @@ _: { rec { packages.rust-home = _module.args.rust.toolchains.dev; + packages.llvm-bitcode-linker = + (mkToolchain { + components = [ availableComponents.rust-src ]; + }).passthru.availableComponents.llvm-bitcode-linker; + packages.fetchRustStdCargoLock = mkCi false ( pkgs.writeShellApplication { name = "fetchRustStdCargoLock"; @@ -126,7 +134,10 @@ _: { # for use in the devShell dev = pkgs.rust-bin.nightly.${nightlyVersion}.default.override { extensions = builtins.attrValues availableComponents; - targets = [ "wasm32-unknown-unknown" ]; + targets = [ + "wasm32-unknown-unknown" + "wasm32v1-none" + ]; }; }; };