Repository: CosmWasm/cosmwasm
Pull request #1971 (2023-12-14 09:10:31)

Add `std` feature
regarding #1484 

This adds the `std` feature as a default and replaces the most obvious usages of `std`.
It does not provide full `no_std` support.

Some notes for anyone tackling full `no_std` support in the future:
The next big problem is `thiserror`. It should be possible to only enable it when `std` is enabled and provide alternative Display / Debug implementations otherwise.
The `JsonSchema` derive macro also would need to be patched to use core / alloc instead of std, but that should be straightforward.
Apart from that, some of our dependencies are likely not `no_std`, so changes might be needed there.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 706ca415c..4f07ce8e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,6 +68,7 @@ and this project adheres to
 - cosmwasm-vm: Replace `MockApi` with bech32 implementation. ([#1914])
 - cosmwasm-std: Make `IbcReceiveResponse::acknowledgement` optional and add
   `IbcReceiveResponse::without_ack` constructor. ([#1892])
+- cosmwasm-std: Add `std` feature and make it a default feature. ([#1971])
 
 [#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874
 [#1876]: https://github.com/CosmWasm/cosmwasm/pull/1876
@@ -86,6 +87,7 @@ and this project adheres to
 [#1944]: https://github.com/CosmWasm/cosmwasm/pull/1944
 [#1949]: https://github.com/CosmWasm/cosmwasm/pull/1949
 [#1967]: https://github.com/CosmWasm/cosmwasm/pull/1967
+[#1971]: https://github.com/CosmWasm/cosmwasm/pull/1971
 
 ### Removed
 
diff --git a/MIGRATING.md b/MIGRATING.md
index dadb3d80d..6cea8ea3e 100644
--- a/MIGRATING.md
+++ b/MIGRATING.md
@@ -21,9 +21,19 @@ major releases of `cosmwasm`. Note that you can also view the
 
   If you were using cosmwasm-std's `ibc3` feature, you can remove it, as it is
   the default now. Depending on your usage, you might have to enable the
-  `stargate` feature instead, since it was previously implied by `ibc3`. Also
-  remove any uses of the `backtraces` feature. You can use a `RUST_BACKTRACE=1`
-  env variable for this now.
+  `stargate` feature instead, since it was previously implied by `ibc3`.
+
+  Also remove any uses of the `backtraces` feature. You can use a
+  `RUST_BACKTRACE=1` env variable for this now.
+
+  If you were using `cosmwasm-std` with `default-features = false`, you probably
+  want to enable the `std` feature now, as we might move certain existing
+  functionality to that feature in the future to support no_std environments:
+
+  ```diff
+  -cosmwasm-std = { version = "2.0.0", default-features = false, features = [...] }
+  +cosmwasm-std = { version = "2.0.0", default-features = false, features = ["std", ...] }
+  ```
 
 - `ContractInfoResponse::new` now takes all fields of the response as
   parameters:
diff --git a/docs/USING_COSMWASM_STD.md b/docs/USING_COSMWASM_STD.md
index 2c6176774..500a232a0 100644
--- a/docs/USING_COSMWASM_STD.md
+++ b/docs/USING_COSMWASM_STD.md
@@ -74,7 +74,8 @@ there it becomes impossible to use the contract in chains with lower CosmWasm
 versions. If you add `abort`, it becomes impossible for the contract developer
 to opt out of the abort feature due to your library. Since this affects the
 default features `abort` and `iterator`, you should always disable default
-features.
+features. However, you should make sure to keep the `std` feature enabled, as we
+might move certain existing functionality to that feature in the future.
 
 Also libraries should define a loose version range that allows the contract
 developer to control which cosmwasm-std version they want to use in the final
@@ -85,5 +86,6 @@ A typical dependency then looks like this:
 
 ```toml
 # We really need `stargate` here as this is an IBC related library. `abort` and `iterator` are not needed.
-cosmwasm-std = { version = "1.0.1", default-features = false, features = ["stargate"] }
+# `std` should always stay enabled.
+cosmwasm-std = { version = "1.0.1", default-features = false, features = ["std", "stargate"] }
 ```
diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml
index 43461a812..7ece6bc72 100644
--- a/packages/std/Cargo.toml
+++ b/packages/std/Cargo.toml
@@ -12,8 +12,13 @@ readme = "README.md"
 features = ["abort", "stargate", "staking", "cosmwasm_1_4"]
 
 [features]
-default = ["iterator", "abort"]
+default = ["iterator", "abort", "std"]
 abort = []
+# This feature can be used in the future to provide support for no_std environments,
+# but disabling it will not provide any benefit at the moment. Even with this feature disabled,
+# we currently require an std environment.
+# You probably want to keep this enabled for now to avoid possible breaking changes later.
+std = ["serde/std", "serde-json-wasm/std"]
 # iterator allows us to iterate over all DB items in a given range
 # optional as some merkle stores (like tries) don't support this
 # given Ethereum 1.0, 2.0, Substrate, and other major projects use Tries
@@ -45,13 +50,13 @@ cosmwasm_1_4 = ["cosmwasm_1_3"]
 [dependencies]
 base64 = "0.21.0"
 cosmwasm-derive = { path = "../derive", version = "1.5.0" }
-derivative = "2"
+derivative = { version = "2", features = ["use_core"] }
 forward_ref = "1"
 hex = "0.4"
 schemars = "0.8.3"
 sha2 = "0.10.3"
 serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
-serde-json-wasm = { version = "1.0.0" }
+serde-json-wasm = { version = "1.0.0", default-features = false }
 thiserror = "1.0.26"
 bnum = "0.8.0"
 static_assertions = "1.1.0"
diff --git a/packages/std/src/addresses.rs b/packages/std/src/addresses.rs
index c41ab4c8a..659fe8653 100644
--- a/packages/std/src/addresses.rs
+++ b/packages/std/src/addresses.rs
@@ -9,6 +9,7 @@ use sha2::{
 };
 use thiserror::Error;
 
+use crate::prelude::*;
 use crate::{binary::Binary, forward_ref_partial_eq, HexBinary};
 
 /// A human readable address.
diff --git a/packages/std/src/binary.rs b/packages/std/src/binary.rs
index f5f39afec..823798066 100644
--- a/packages/std/src/binary.rs
+++ b/packages/std/src/binary.rs
@@ -6,6 +6,7 @@ use schemars::JsonSchema;
 use serde::{de, ser, Deserialize, Deserializer, Serialize};
 
 use crate::errors::{StdError, StdResult};
+use crate::prelude::*;
 
 /// Binary is a wrapper around Vec<u8> to add base64 de/serialization
 /// with serde. It also adds some helper methods to help encode inline.
diff --git a/packages/std/src/checksum.rs b/packages/std/src/checksum.rs
index 1a6cfff04..e56735640 100644
--- a/packages/std/src/checksum.rs
+++ b/packages/std/src/checksum.rs
@@ -5,6 +5,7 @@ use serde::{de, ser, Deserialize, Deserializer, Serialize};
 use sha2::{Digest, Sha256};
 use thiserror::Error;
 
+use crate::prelude::*;
 use crate::{StdError, StdResult};
 
 /// A SHA-256 checksum of a Wasm blob, used to identify a Wasm code.
diff --git a/packages/std/src/coin.rs b/packages/std/src/coin.rs
index 9e02786b7..daf1df173 100644
--- a/packages/std/src/coin.rs
+++ b/packages/std/src/coin.rs
@@ -2,6 +2,7 @@ use core::{fmt, str::FromStr};
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 use crate::{errors::CoinFromStrError, math::Uint128};
 
 #[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema)]
diff --git a/packages/std/src/coins.rs b/packages/std/src/coins.rs
index ea589fc16..967ab7067 100644
--- a/packages/std/src/coins.rs
+++ b/packages/std/src/coins.rs
@@ -2,6 +2,7 @@ use alloc::collections::BTreeMap;
 use core::fmt;
 use core::str::FromStr;
 
+use crate::prelude::*;
 use crate::{
     errors::CoinsError, Coin, OverflowError, OverflowOperation, StdError, StdResult, Uint128,
 };
diff --git a/packages/std/src/errors/backtrace.rs b/packages/std/src/errors/backtrace.rs
index 8446243c1..eef9ceb75 100644
--- a/packages/std/src/errors/backtrace.rs
+++ b/packages/std/src/errors/backtrace.rs
@@ -1,5 +1,7 @@
 use core::fmt::{Debug, Display, Formatter, Result};
 
+use crate::prelude::*;
+
 /// This wraps an actual backtrace to achieve two things:
 /// - being able to fill this with a stub implementation in `no_std` environments
 /// - being able to use this in conjunction with [`thiserror::Error`]
@@ -9,10 +11,17 @@ impl BT {
     #[track_caller]
     pub fn capture() -> Self {
         // in case of no_std, we can fill with a stub here
-        #[cfg(target_arch = "wasm32")]
-        return BT(Box::new(std::backtrace::Backtrace::disabled()));
-        #[cfg(not(target_arch = "wasm32"))]
-        return BT(Box::new(std::backtrace::Backtrace::capture()));
+        #[cfg(feature = "std")]
+        {
+            #[cfg(target_arch = "wasm32")]
+            return BT(Box::new(std::backtrace::Backtrace::disabled()));
+            #[cfg(not(target_arch = "wasm32"))]
+            return BT(Box::new(std::backtrace::Backtrace::capture()));
+        }
+        #[cfg(not(feature = "std"))]
+        {
+            BT(Box::new(Stub))
+        }
     }
 }
 
@@ -31,6 +40,21 @@ impl Display for BT {
     }
 }
 
+#[allow(unused)]
+struct Stub;
+
+impl Debug for Stub {
+    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+        write!(f, "<disabled>")
+    }
+}
+
+impl Display for Stub {
+    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+        write!(f, "<disabled>")
+    }
+}
+
 /// This macro implements `From` for a given error type to a given error type where
 /// the target error has a `backtrace` field.
 /// This is meant as a replacement for `thiserror`'s `#[from]` attribute, which does not
diff --git a/packages/std/src/errors/std_error.rs b/packages/std/src/errors/std_error.rs
index 22bbe71f2..31cd692ae 100644
--- a/packages/std/src/errors/std_error.rs
+++ b/packages/std/src/errors/std_error.rs
@@ -4,6 +4,7 @@ use super::{impl_from_err, BT};
 use thiserror::Error;
 
 use crate::errors::{RecoverPubkeyError, VerificationError};
+use crate::prelude::*;
 
 /// Structured error type for init, execute and query.
 ///
diff --git a/packages/std/src/errors/system_error.rs b/packages/std/src/errors/system_error.rs
index 8d560c413..e7a0b5a86 100644
--- a/packages/std/src/errors/system_error.rs
+++ b/packages/std/src/errors/system_error.rs
@@ -1,6 +1,7 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 use crate::Binary;
 
 /// SystemError is used for errors inside the VM and is API friendly (i.e. serializable).
@@ -39,6 +40,7 @@ pub enum SystemError {
     },
 }
 
+#[cfg(feature = "std")]
 impl std::error::Error for SystemError {}
 
 impl core::fmt::Display for SystemError {
diff --git a/packages/std/src/hex_binary.rs b/packages/std/src/hex_binary.rs
index aeb30b4c4..1b704e226 100644
--- a/packages/std/src/hex_binary.rs
+++ b/packages/std/src/hex_binary.rs
@@ -4,6 +4,7 @@ use core::ops::Deref;
 use schemars::JsonSchema;
 use serde::{de, ser, Deserialize, Deserializer, Serialize};
 
+use crate::prelude::*;
 use crate::{Binary, StdError, StdResult};
 
 /// This is a wrapper around Vec<u8> to add hex de/serialization
diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs
index d6398f8f1..8e5e635bd 100644
--- a/packages/std/src/ibc.rs
+++ b/packages/std/src/ibc.rs
@@ -9,6 +9,7 @@ use crate::addresses::Addr;
 use crate::binary::Binary;
 use crate::coin::Coin;
 use crate::errors::StdResult;
+use crate::prelude::*;
 use crate::results::{Attribute, CosmosMsg, Empty, Event, SubMsg};
 use crate::serde::to_json_binary;
 use crate::timestamp::Timestamp;
diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs
index 43111e20e..1e6194ff5 100644
--- a/packages/std/src/lib.rs
+++ b/packages/std/src/lib.rs
@@ -32,6 +32,9 @@ mod timestamp;
 mod traits;
 mod types;
 
+/// This module is to simplify no_std imports
+pub(crate) mod prelude;
+
 /// This modules is very advanced and will not be used directly by the vast majority of users.
 /// We want to offer it to ensure a stable storage key composition system but don't encourage
 /// contract devs to use it directly.
diff --git a/packages/std/src/math/decimal.rs b/packages/std/src/math/decimal.rs
index ed5aaae29..e51279866 100644
--- a/packages/std/src/math/decimal.rs
+++ b/packages/std/src/math/decimal.rs
@@ -11,6 +11,7 @@ use crate::errors::{
     CheckedFromRatioError, CheckedMultiplyRatioError, DivideByZeroError, OverflowError,
     OverflowOperation, RoundUpOverflowError, StdError,
 };
+use crate::prelude::*;
 use crate::{forward_ref_partial_eq, Decimal256, SignedDecimal, SignedDecimal256};
 
 use super::Fraction;
diff --git a/packages/std/src/math/decimal256.rs b/packages/std/src/math/decimal256.rs
index 401f72098..4117dd830 100644
--- a/packages/std/src/math/decimal256.rs
+++ b/packages/std/src/math/decimal256.rs
@@ -11,6 +11,7 @@ use crate::errors::{
     CheckedFromRatioError, CheckedMultiplyRatioError, DivideByZeroError, OverflowError,
     OverflowOperation, RoundUpOverflowError, StdError,
 };
+use crate::prelude::*;
 use crate::{forward_ref_partial_eq, Decimal, SignedDecimal, SignedDecimal256, Uint512};
 
 use super::Fraction;
diff --git a/packages/std/src/math/int128.rs b/packages/std/src/math/int128.rs
index 5fc43b602..aa86525b8 100644
--- a/packages/std/src/math/int128.rs
+++ b/packages/std/src/math/int128.rs
@@ -9,6 +9,7 @@ use schemars::JsonSchema;
 use serde::{de, ser, Deserialize, Deserializer, Serialize};
 
 use crate::errors::{DivideByZeroError, DivisionError, OverflowError, OverflowOperation, StdError};
+use crate::prelude::*;
 use crate::{
     forward_ref_partial_eq, CheckedMultiplyRatioError, Int256, Int512, Int64, Uint128, Uint256,
     Uint512, Uint64,
diff --git a/packages/std/src/math/int256.rs b/packages/std/src/math/int256.rs
index 24180c54e..64e5771f0 100644
--- a/packages/std/src/math/int256.rs
+++ b/packages/std/src/math/int256.rs
@@ -9,6 +9,7 @@ use schemars::JsonSchema;
 use serde::{de, ser, Deserialize, Deserializer, Serialize};
 
 use crate::errors::{DivideByZeroError, DivisionError, OverflowError, OverflowOperation, StdError};
+use crate::prelude::*;
 use crate::{
     forward_ref_partial_eq, CheckedMultiplyRatioError, Int128, Int512, Int64, Uint128, Uint256,
     Uint512, Uint64,
diff --git a/packages/std/src/math/int512.rs b/packages/std/src/math/int512.rs
index cc5d74fca..32499b657 100644
--- a/packages/std/src/math/int512.rs
+++ b/packages/std/src/math/int512.rs
@@ -9,6 +9,7 @@ use schemars::JsonSchema;
 use serde::{de, ser, Deserialize, Deserializer, Serialize};
 
 use crate::errors::{DivideByZeroError, DivisionError, OverflowError, OverflowOperation, StdError};
+use crate::prelude::*;
 use crate::{forward_ref_partial_eq, Int128, Int256, Int64, Uint128, Uint256, Uint512, Uint64};
 
 /// Used internally - we don't want to leak this type since we might change
diff --git a/packages/std/src/math/int64.rs b/packages/std/src/math/int64.rs
index 096f38a39..de8802281 100644
--- a/packages/std/src/math/int64.rs
+++ b/packages/std/src/math/int64.rs
@@ -9,6 +9,7 @@ use schemars::JsonSchema;
 use serde::{de, ser, Deserialize, Deserializer, Serialize};
 
 use crate::errors::{DivideByZeroError, DivisionError, OverflowError, OverflowOperation, StdError};
+use crate::prelude::*;
 use crate::{
     forward_ref_partial_eq, CheckedMultiplyRatioError, Int128, Int256, Int512, Uint128, Uint256,
     Uint512, Uint64,
diff --git a/packages/std/src/math/signed_decimal.rs b/packages/std/src/math/signed_decimal.rs
index 911e30293..2c9dddf96 100644
--- a/packages/std/src/math/signed_decimal.rs
+++ b/packages/std/src/math/signed_decimal.rs
@@ -13,6 +13,7 @@ use crate::errors::{
     CheckedFromRatioError, CheckedMultiplyRatioError, DivideByZeroError, OverflowError,
     OverflowOperation, RoundDownOverflowError, RoundUpOverflowError, StdError,
 };
+use crate::prelude::*;
 use crate::{forward_ref_partial_eq, Decimal, Decimal256, Int256, SignedDecimal256};
 
 use super::Fraction;
diff --git a/packages/std/src/math/signed_decimal_256.rs b/packages/std/src/math/signed_decimal_256.rs
index 464346547..175366208 100644
--- a/packages/std/src/math/signed_decimal_256.rs
+++ b/packages/std/src/math/signed_decimal_256.rs
@@ -13,6 +13,7 @@ use crate::errors::{
     CheckedFromRatioError, CheckedMultiplyRatioError, DivideByZeroError, OverflowError,
     OverflowOperation, RoundDownOverflowError, RoundUpOverflowError, StdError,
 };
+use crate::prelude::*;
 use crate::{forward_ref_partial_eq, Decimal, Decimal256, Int512, SignedDecimal};
 
 use super::Fraction;
diff --git a/packages/std/src/math/uint128.rs b/packages/std/src/math/uint128.rs
index 1d4202228..70005efbf 100644
--- a/packages/std/src/math/uint128.rs
+++ b/packages/std/src/math/uint128.rs
@@ -1,10 +1,9 @@
-use core::fmt::{self};
+use core::fmt;
 use core::ops::{
-    Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign,
-    Sub, SubAssign,
+    Add, AddAssign, Div, DivAssign, Mul, MulAssign, Not, Rem, RemAssign, Shl, ShlAssign, Shr,
+    ShrAssign, Sub, SubAssign,
 };
 use core::str::FromStr;
-use std::ops::Not;
 
 use forward_ref::{forward_ref_binop, forward_ref_op_assign};
 use schemars::JsonSchema;
@@ -14,6 +13,7 @@ use crate::errors::{
     CheckedMultiplyFractionError, CheckedMultiplyRatioError, DivideByZeroError, OverflowError,
     OverflowOperation, StdError,
 };
+use crate::prelude::*;
 use crate::{
     forward_ref_partial_eq, impl_mul_fraction, Fraction, Int128, Int256, Int512, Int64, Uint256,
     Uint64,
diff --git a/packages/std/src/math/uint256.rs b/packages/std/src/math/uint256.rs
index 2492cc46b..06dbcb933 100644
--- a/packages/std/src/math/uint256.rs
+++ b/packages/std/src/math/uint256.rs
@@ -1,18 +1,18 @@
 use core::fmt;
 use core::ops::{
-    Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign,
-    Sub, SubAssign,
+    Add, AddAssign, Div, DivAssign, Mul, MulAssign, Not, Rem, RemAssign, Shl, ShlAssign, Shr,
+    ShrAssign, Sub, SubAssign,
 };
 use core::str::FromStr;
 use forward_ref::{forward_ref_binop, forward_ref_op_assign};
 use schemars::JsonSchema;
 use serde::{de, ser, Deserialize, Deserializer, Serialize};
-use std::ops::Not;
 
 use crate::errors::{
     CheckedMultiplyFractionError, CheckedMultiplyRatioError, ConversionOverflowError,
     DivideByZeroError, OverflowError, OverflowOperation, StdError,
 };
+use crate::prelude::*;
 use crate::{
     forward_ref_partial_eq, impl_mul_fraction, Fraction, Int128, Int256, Int512, Int64, Uint128,
     Uint512, Uint64,
diff --git a/packages/std/src/math/uint512.rs b/packages/std/src/math/uint512.rs
index 49f9beeeb..2d4d05217 100644
--- a/packages/std/src/math/uint512.rs
+++ b/packages/std/src/math/uint512.rs
@@ -11,6 +11,7 @@ use serde::{de, ser, Deserialize, Deserializer, Serialize};
 use crate::errors::{
     ConversionOverflowError, DivideByZeroError, OverflowError, OverflowOperation, StdError,
 };
+use crate::prelude::*;
 use crate::{forward_ref_partial_eq, Int128, Int256, Int512, Int64, Uint128, Uint256, Uint64};
 
 /// Used internally - we don't want to leak this type since we might change
diff --git a/packages/std/src/math/uint64.rs b/packages/std/src/math/uint64.rs
index 8a3738bdf..b663855d8 100644
--- a/packages/std/src/math/uint64.rs
+++ b/packages/std/src/math/uint64.rs
@@ -1,17 +1,17 @@
-use core::fmt::{self};
+use core::fmt;
 use core::ops::{
-    Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign,
-    Sub, SubAssign,
+    Add, AddAssign, Div, DivAssign, Mul, MulAssign, Not, Rem, RemAssign, Shl, ShlAssign, Shr,
+    ShrAssign, Sub, SubAssign,
 };
 use forward_ref::{forward_ref_binop, forward_ref_op_assign};
 use schemars::JsonSchema;
 use serde::{de, ser, Deserialize, Deserializer, Serialize};
-use std::ops::Not;
 
 use crate::errors::{
     CheckedMultiplyFractionError, CheckedMultiplyRatioError, DivideByZeroError, OverflowError,
     OverflowOperation, StdError,
 };
+use crate::prelude::*;
 use crate::{
     forward_ref_partial_eq, impl_mul_fraction, Fraction, Int128, Int256, Int512, Int64, Uint128,
 };
diff --git a/packages/std/src/metadata.rs b/packages/std/src/metadata.rs
index c0827ce72..b741f3209 100644
--- a/packages/std/src/metadata.rs
+++ b/packages/std/src/metadata.rs
@@ -1,6 +1,8 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
+
 /// Replicates the cosmos-sdk bank module Metadata type
 #[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
 pub struct DenomMetadata {
diff --git a/packages/std/src/pagination.rs b/packages/std/src/pagination.rs
index d9d1d8ef9..d5e979f9f 100644
--- a/packages/std/src/pagination.rs
+++ b/packages/std/src/pagination.rs
@@ -1,6 +1,7 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 use crate::Binary;
 
 /// Simplified version of the PageRequest type for pagination from the cosmos-sdk
diff --git a/packages/std/src/prelude.rs b/packages/std/src/prelude.rs
new file mode 100644
index 000000000..ad2d30b85
--- /dev/null
+++ b/packages/std/src/prelude.rs
@@ -0,0 +1,6 @@
+pub use alloc::boxed::Box;
+pub use alloc::format;
+pub use alloc::string::{String, ToString};
+pub use alloc::vec;
+pub use alloc::vec::Vec;
+pub use core::option::Option::{self, None, Some};
diff --git a/packages/std/src/query/bank.rs b/packages/std/src/query/bank.rs
index d8ecb3bae..4ae51883e 100644
--- a/packages/std/src/query/bank.rs
+++ b/packages/std/src/query/bank.rs
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
 
 use crate::Coin;
 
+use crate::prelude::*;
 #[cfg(feature = "cosmwasm_1_3")]
 use crate::PageRequest;
 use crate::{Binary, DenomMetadata};
diff --git a/packages/std/src/query/distribution.rs b/packages/std/src/query/distribution.rs
index 5dbdfec2e..0abc33f19 100644
--- a/packages/std/src/query/distribution.rs
+++ b/packages/std/src/query/distribution.rs
@@ -1,6 +1,7 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 use crate::{Addr, Decimal256};
 
 use super::query_response::QueryResponseType;
diff --git a/packages/std/src/query/ibc.rs b/packages/std/src/query/ibc.rs
index 511c61274..739e9ac35 100644
--- a/packages/std/src/query/ibc.rs
+++ b/packages/std/src/query/ibc.rs
@@ -2,6 +2,7 @@ use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
 use crate::ibc::IbcChannel;
+use crate::prelude::*;
 
 /// These are queries to the various IBC modules to see the state of the contract's
 /// IBC connection. These will return errors if the contract is not "ibc enabled"
diff --git a/packages/std/src/query/mod.rs b/packages/std/src/query/mod.rs
index a957574a8..a6e0219c1 100644
--- a/packages/std/src/query/mod.rs
+++ b/packages/std/src/query/mod.rs
@@ -1,6 +1,7 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 #[cfg(feature = "stargate")]
 use crate::Binary;
 use crate::Empty;
diff --git a/packages/std/src/query/query_response.rs b/packages/std/src/query/query_response.rs
index 4aa4559e4..00dae078c 100644
--- a/packages/std/src/query/query_response.rs
+++ b/packages/std/src/query/query_response.rs
@@ -1,4 +1,4 @@
-use std::fmt::Debug;
+use core::fmt::Debug;
 
 use serde::de::DeserializeOwned;
 
diff --git a/packages/std/src/query/staking.rs b/packages/std/src/query/staking.rs
index b8104b8f1..3c5fd0ec2 100644
--- a/packages/std/src/query/staking.rs
+++ b/packages/std/src/query/staking.rs
@@ -1,6 +1,7 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 use crate::{Addr, Coin, Decimal};
 
 use super::query_response::QueryResponseType;
diff --git a/packages/std/src/query/wasm.rs b/packages/std/src/query/wasm.rs
index 7c01040ee..b05ba32d4 100644
--- a/packages/std/src/query/wasm.rs
+++ b/packages/std/src/query/wasm.rs
@@ -1,6 +1,7 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 use crate::{Addr, Binary, Checksum};
 
 use super::query_response::QueryResponseType;
diff --git a/packages/std/src/results/contract_result.rs b/packages/std/src/results/contract_result.rs
index a55c32e3c..e887c7450 100644
--- a/packages/std/src/results/contract_result.rs
+++ b/packages/std/src/results/contract_result.rs
@@ -2,6 +2,8 @@ use core::fmt;
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
+
 /// This is the final result type that is created and serialized in a contract for
 /// every init/execute/migrate call. The VM then deserializes this type to distinguish
 /// between successful and failed executions.
diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs
index 9c60c25bb..1336c35a5 100644
--- a/packages/std/src/results/cosmos_msg.rs
+++ b/packages/std/src/results/cosmos_msg.rs
@@ -8,6 +8,7 @@ use crate::coin::Coin;
 use crate::errors::StdResult;
 #[cfg(feature = "stargate")]
 use crate::ibc::IbcMsg;
+use crate::prelude::*;
 use crate::serde::to_json_binary;
 #[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
 use crate::Decimal;
diff --git a/packages/std/src/results/empty.rs b/packages/std/src/results/empty.rs
index 91e3b581b..9efd96d90 100644
--- a/packages/std/src/results/empty.rs
+++ b/packages/std/src/results/empty.rs
@@ -1,6 +1,8 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
+
 /// An empty struct that serves as a placeholder in different places,
 /// such as contracts that don't set a custom message.
 ///
diff --git a/packages/std/src/results/events.rs b/packages/std/src/results/events.rs
index 51eb7ace0..2ed593ae6 100644
--- a/packages/std/src/results/events.rs
+++ b/packages/std/src/results/events.rs
@@ -2,6 +2,7 @@ use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
 use crate::forward_ref_partial_eq;
+use crate::prelude::*;
 
 /// A full [*Cosmos SDK* event].
 ///
diff --git a/packages/std/src/results/response.rs b/packages/std/src/results/response.rs
index 80f687c75..921dea515 100644
--- a/packages/std/src/results/response.rs
+++ b/packages/std/src/results/response.rs
@@ -1,6 +1,7 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 use crate::Binary;
 
 use super::{Attribute, CosmosMsg, Empty, Event, SubMsg};
diff --git a/packages/std/src/results/submessages.rs b/packages/std/src/results/submessages.rs
index 5d58e87d2..ebc0efa17 100644
--- a/packages/std/src/results/submessages.rs
+++ b/packages/std/src/results/submessages.rs
@@ -1,6 +1,7 @@
 use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
+use crate::prelude::*;
 use crate::Binary;
 
 use super::{CosmosMsg, Empty, Event};
diff --git a/packages/std/src/results/system_result.rs b/packages/std/src/results/system_result.rs
index 6ad224d94..624fe0bc3 100644
--- a/packages/std/src/results/system_result.rs
+++ b/packages/std/src/results/system_result.rs
@@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
 
 use super::super::errors::SystemError;
 
+use crate::prelude::*;
+
 /// This is the outer result type returned by a querier to the contract.
 ///
 /// We use a custom type here instead of Rust's Result because we want to be able to
diff --git a/packages/std/src/sections.rs b/packages/std/src/sections.rs
index 89433f553..3a8bc9ee9 100644
--- a/packages/std/src/sections.rs
+++ b/packages/std/src/sections.rs
@@ -1,4 +1,5 @@
 use crate::conversion::force_to_u32;
+use crate::prelude::*;
 
 /// A sections decoder for the special case of two elements
 #[allow(dead_code)] // used in Wasm and tests only
diff --git a/packages/std/src/serde.rs b/packages/std/src/serde.rs
index 294881328..5adaf2456 100644
--- a/packages/std/src/serde.rs
+++ b/packages/std/src/serde.rs
@@ -7,6 +7,7 @@ use serde::{de::DeserializeOwned, Serialize};
 
 use crate::binary::Binary;
 use crate::errors::{StdError, StdResult};
+use crate::prelude::*;
 
 #[deprecated = "use from_json instead"]
 pub fn from_slice<T: DeserializeOwned>(value: &[u8]) -> StdResult<T> {
diff --git a/packages/std/src/stdack.rs b/packages/std/src/stdack.rs
index 170317fa3..1d65a7d8f 100644
--- a/packages/std/src/stdack.rs
+++ b/packages/std/src/stdack.rs
@@ -2,6 +2,7 @@ use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
 use crate::binary::Binary;
+use crate::prelude::*;
 use crate::to_json_binary;
 
 /// This is a standard IBC acknowledgement type. IBC application are free
diff --git a/packages/std/src/storage.rs b/packages/std/src/storage.rs
index 26d7f710d..bcfcb76e7 100644
--- a/packages/std/src/storage.rs
+++ b/packages/std/src/storage.rs
@@ -7,6 +7,7 @@ use core::ops::{Bound, RangeBounds};
 
 #[cfg(feature = "iterator")]
 use crate::iterator::{Order, Record};
+use crate::prelude::*;
 use crate::traits::Storage;
 
 #[derive(Default)]
diff --git a/packages/std/src/storage_keys/length_prefixed.rs b/packages/std/src/storage_keys/length_prefixed.rs
index 9e95f17f0..e033ed79f 100644
--- a/packages/std/src/storage_keys/length_prefixed.rs
+++ b/packages/std/src/storage_keys/length_prefixed.rs
@@ -4,6 +4,8 @@
 //! Everything in this file is only responsible for building such keys
 //! and is in no way specific to any kind of storage.
 
+use crate::prelude::*;
+
 /// Calculates the raw key prefix for a given namespace as documented
 /// in https://github.com/webmaster128/key-namespacing#length-prefixed-keys
 pub fn to_length_prefixed(namespace_component: &[u8]) -> Vec<u8> {
diff --git a/packages/std/src/timestamp.rs b/packages/std/src/timestamp.rs
index 6a10f060d..8421e3b1b 100644
--- a/packages/std/src/timestamp.rs
+++ b/packages/std/src/timestamp.rs
@@ -3,6 +3,7 @@ use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 
 use crate::math::Uint64;
+use crate::prelude::*;
 
 /// A point in time in nanosecond precision.
 ///
diff --git a/packages/std/src/traits.rs b/packages/std/src/traits.rs
index 0d966bd2d..4dea2819d 100644
--- a/packages/std/src/traits.rs
+++ b/packages/std/src/traits.rs
@@ -8,6 +8,7 @@ use crate::coin::Coin;
 use crate::errors::{RecoverPubkeyError, StdError, StdResult, VerificationError};
 #[cfg(feature = "iterator")]
 use crate::iterator::{Order, Record};
+use crate::prelude::*;
 #[cfg(feature = "cosmwasm_1_2")]
 use crate::query::CodeInfoResponse;
 #[cfg(feature = "cosmwasm_1_1")]
diff --git a/packages/std/src/types.rs b/packages/std/src/types.rs
index 782ad1e72..6a77eccd8 100644
--- a/packages/std/src/types.rs
+++ b/packages/std/src/types.rs
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
 
 use crate::addresses::Addr;
 use crate::coin::Coin;
+use crate::prelude::*;
 use crate::timestamp::Timestamp;
 
 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]


Test patch:
diff --git a/packages/std/src/testing/assertions.rs b/packages/std/src/testing/assertions.rs
index fa3ab6c7f..c87ba28b5 100644
--- a/packages/std/src/testing/assertions.rs
+++ b/packages/std/src/testing/assertions.rs
@@ -1,3 +1,4 @@
+use crate::prelude::*;
 use crate::{Decimal, Uint128};
 #[cfg(test)]
 use core::hash::{Hash, Hasher};
diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs
index f339fae8a..dd3395daf 100644
--- a/packages/std/src/testing/mock.rs
+++ b/packages/std/src/testing/mock.rs
@@ -1,4 +1,7 @@
+use crate::prelude::*;
 use alloc::collections::BTreeMap;
+#[cfg(feature = "cosmwasm_1_3")]
+use alloc::collections::BTreeSet;
 use bech32::{decode, encode, FromBase32, ToBase32, Variant};
 use core::marker::PhantomData;
 #[cfg(feature = "cosmwasm_1_3")]
@@ -7,9 +10,6 @@ use serde::de::DeserializeOwned;
 #[cfg(feature = "stargate")]
 use serde::Serialize;
 use sha2::{Digest, Sha256};
-#[cfg(feature = "cosmwasm_1_3")]
-use std::collections::BTreeSet;
-use std::collections::HashMap;
 
 use crate::addresses::{Addr, CanonicalAddr};
 use crate::binary::Binary;
@@ -202,7 +202,8 @@ impl Api for MockApi {
         )?)
     }
 
-    fn debug(&self, message: &str) {
+    fn debug(&self, #[allow(unused)] message: &str) {
+        #[cfg(feature = "std")]
         println!("{message}");
     }
 }
@@ -662,17 +663,17 @@ impl Default for WasmQuerier {
 #[derive(Clone, Default)]
 pub struct BankQuerier {
     #[allow(dead_code)]
-    /// HashMap<denom, amount>
-    supplies: HashMap<String, Uint128>,
-    /// HashMap<address, coins>
-    balances: HashMap<String, Vec<Coin>>,
+    /// BTreeMap<denom, amount>
+    supplies: BTreeMap<String, Uint128>,
+    /// BTreeMap<address, coins>
+    balances: BTreeMap<String, Vec<Coin>>,
     /// Vec<Metadata>
     denom_metadata: BTreeMap<Vec<u8>, DenomMetadata>,
 }
 
 impl BankQuerier {
     pub fn new(balances: &[(&str, &[Coin])]) -> Self {
-        let balances: HashMap<_, _> = balances
+        let balances: BTreeMap<_, _> = balances
             .iter()
             .map(|(s, c)| (s.to_string(), c.to_vec()))
             .collect();
@@ -702,8 +703,8 @@ impl BankQuerier {
             .collect();
     }
 
-    fn calculate_supplies(balances: &HashMap<String, Vec<Coin>>) -> HashMap<String, Uint128> {
-        let mut supplies = HashMap::new();
+    fn calculate_supplies(balances: &BTreeMap<String, Vec<Coin>>) -> BTreeMap<String, Uint128> {
+        let mut supplies = BTreeMap::new();
 
         let all_coins = balances.iter().flat_map(|(_, coins)| coins);
 
@@ -2148,7 +2149,7 @@ mod tests {
         querier.update_handler(|request| {
             let api = MockApi::default();
             let contract1 = api.addr_make("contract1");
-            let mut storage1 = HashMap::<Binary, Binary>::default();
+            let mut storage1 = BTreeMap::<Binary, Binary>::default();
             storage1.insert(b"the key".into(), b"the value".into());
 
             match request {
@@ -2347,7 +2348,7 @@ mod tests {
     }
 
     #[test]
-    #[cfg(feature = "cosmwasm_1_3")]
+    #[cfg(all(feature = "cosmwasm_1_3", feature = "std"))]
     fn distribution_querier_new_works() {
         let addresses = [
             ("addr0000".to_string(), "addr0001".to_string()),
@@ -2356,7 +2357,7 @@ mod tests {
         let btree_map = BTreeMap::from(addresses.clone());
 
         // should still work with HashMap
-        let hashmap = HashMap::from(addresses.clone());
+        let hashmap = std::collections::HashMap::from(addresses.clone());
         let querier = DistributionQuerier::new(hashmap);
         assert_eq!(querier.withdraw_addresses, btree_map);