diff --git a/.circleci/config.yml b/.circleci/config.yml index 01000ce3ac..926f083f3d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -358,15 +358,15 @@ jobs: - run: name: Build library for native target (all features) working_directory: ~/project/packages/std - command: cargo build --locked --features abort,iterator,staking,stargate,cosmwasm_1_1 + command: cargo build --locked --features abort,iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2 - run: name: Build library for wasm target (all features) working_directory: ~/project/packages/std - command: cargo wasm --locked --features abort,iterator,staking,stargate,cosmwasm_1_1 + command: cargo wasm --locked --features abort,iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2 - run: name: Run unit tests (all features) working_directory: ~/project/packages/std - command: cargo test --locked --features abort,iterator,staking,stargate,cosmwasm_1_1 + command: cargo test --locked --features abort,iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2 - save_cache: paths: - /usr/local/cargo/registry @@ -882,7 +882,7 @@ jobs: - run: name: Clippy linting on std (all feature flags) working_directory: ~/project/packages/std - command: cargo clippy --all-targets --features abort,iterator,staking,stargate -- -D warnings + command: cargo clippy --all-targets --features abort,iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2 -- -D warnings - run: name: Clippy linting on storage (no feature flags) working_directory: ~/project/packages/storage diff --git a/CHANGELOG.md b/CHANGELOG.md index d71e2f5465..a329879f66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ and this project adheres to of CosmWasm earlier than 1.2.0 ([#1481]). - cosmwasm-std: Add `instantiate2_address` which allows calculating the predictable addresses for `MsgInstantiateContract2` ([#1437]). +- cosmwasm-std: Add `WasmMsg::Instantiate2` (requires `cosmwasm_1_2`, see + `GovMsg::VoteWeighted` above) to instantiate contracts at a predictable + address ([#1436]). - cosmwasm-schema: In contracts, `cosmwasm schema` will now output a separate JSON Schema file for each entrypoint in the `raw` subdirectory ([#1478], [#1533]). @@ -21,6 +24,7 @@ and this project adheres to support to `to_vec`/`to_binary` and friends. - cosmwasm-std: Implement `AsRef<[u8]>` for `Binary` and `HexBinary` ([#1550]). +[#1436]: https://github.com/CosmWasm/cosmwasm/issues/1436 [#1437]: https://github.com/CosmWasm/cosmwasm/issues/1437 [#1481]: https://github.com/CosmWasm/cosmwasm/pull/1481 [#1478]: https://github.com/CosmWasm/cosmwasm/pull/1478 diff --git a/contracts/ibc-reflect-send/schema/ibc-reflect-send.json b/contracts/ibc-reflect-send/schema/ibc-reflect-send.json index 5f6fe80a2c..b42ac67e89 100644 --- a/contracts/ibc-reflect-send/schema/ibc-reflect-send.json +++ b/contracts/ibc-reflect-send/schema/ibc-reflect-send.json @@ -690,7 +690,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/ibc-reflect-send/schema/packet_msg.json b/contracts/ibc-reflect-send/schema/packet_msg.json index 1aeb3db835..7bc2a45e21 100644 --- a/contracts/ibc-reflect-send/schema/packet_msg.json +++ b/contracts/ibc-reflect-send/schema/packet_msg.json @@ -628,7 +628,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/ibc-reflect-send/schema/raw/execute.json b/contracts/ibc-reflect-send/schema/raw/execute.json index e08109d489..a382cb2aac 100644 --- a/contracts/ibc-reflect-send/schema/raw/execute.json +++ b/contracts/ibc-reflect-send/schema/raw/execute.json @@ -679,7 +679,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/ibc-reflect-send/schema/raw/migrate.json b/contracts/ibc-reflect-send/schema/raw/migrate.json index e08109d489..a382cb2aac 100644 --- a/contracts/ibc-reflect-send/schema/raw/migrate.json +++ b/contracts/ibc-reflect-send/schema/raw/migrate.json @@ -679,7 +679,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/ibc-reflect-send/schema/raw/sudo.json b/contracts/ibc-reflect-send/schema/raw/sudo.json index e08109d489..a382cb2aac 100644 --- a/contracts/ibc-reflect-send/schema/raw/sudo.json +++ b/contracts/ibc-reflect-send/schema/raw/sudo.json @@ -679,7 +679,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/ibc-reflect/schema/packet_msg.json b/contracts/ibc-reflect/schema/packet_msg.json index 11f1cb38eb..259c21b1bd 100644 --- a/contracts/ibc-reflect/schema/packet_msg.json +++ b/contracts/ibc-reflect/schema/packet_msg.json @@ -473,7 +473,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/reflect/schema/raw/execute.json b/contracts/reflect/schema/raw/execute.json index e0db5ae603..1ccfba3b0e 100644 --- a/contracts/reflect/schema/raw/execute.json +++ b/contracts/reflect/schema/raw/execute.json @@ -716,7 +716,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/reflect/schema/raw/migrate.json b/contracts/reflect/schema/raw/migrate.json index e0db5ae603..1ccfba3b0e 100644 --- a/contracts/reflect/schema/raw/migrate.json +++ b/contracts/reflect/schema/raw/migrate.json @@ -716,7 +716,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/reflect/schema/raw/sudo.json b/contracts/reflect/schema/raw/sudo.json index e0db5ae603..1ccfba3b0e 100644 --- a/contracts/reflect/schema/raw/sudo.json +++ b/contracts/reflect/schema/raw/sudo.json @@ -716,7 +716,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 515e97eac5..ab4e2c0cc6 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -726,7 +726,7 @@ "additionalProperties": false }, { - "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). `sender` is automatically filled with the current contract's address.", + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", "type": "object", "required": [ "instantiate" diff --git a/devtools/check_workspace.sh b/devtools/check_workspace.sh index d24813c5ed..a9969ae5f8 100755 --- a/devtools/check_workspace.sh +++ b/devtools/check_workspace.sh @@ -8,7 +8,7 @@ cargo fmt ( cd packages/std cargo check - cargo check --features iterator,staking,stargate + cargo check --features iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2 cargo wasm-debug cargo wasm-debug --features iterator,staking,stargate cargo clippy --all-targets --features iterator,staking,stargate -- -D warnings diff --git a/docs/CAPABILITIES-BUILT-IN.md b/docs/CAPABILITIES-BUILT-IN.md index f0cabc280b..8fdd679fe1 100644 --- a/docs/CAPABILITIES-BUILT-IN.md +++ b/docs/CAPABILITIES-BUILT-IN.md @@ -13,5 +13,5 @@ might define others. chains that don't use this (e.g. Tgrade). - `cosmwasm_1_1` enables the `BankQuery::Supply` query. Only chains running CosmWasm `1.1.0` or higher support this. -- `cosmwasm_1_2` enables the `GovMsg::VoteWeighted` message. Only chains running - CosmWasm `1.2.0` or higher support this. +- `cosmwasm_1_2` enables the `GovMsg::VoteWeighted` and `WasmMsg::Instantiate2` + messages. Only chains running CosmWasm `1.2.0` or higher support this. diff --git a/packages/check/src/main.rs b/packages/check/src/main.rs index 1d4e6eb67d..c1f7da1784 100644 --- a/packages/check/src/main.rs +++ b/packages/check/src/main.rs @@ -10,7 +10,7 @@ use colored::Colorize; use cosmwasm_vm::capabilities_from_csv; use cosmwasm_vm::internals::{check_wasm, compile}; -const DEFAULT_AVAILABLE_CAPABILITIES: &str = "iterator,staking,stargate,cosmwasm_1_1"; +const DEFAULT_AVAILABLE_CAPABILITIES: &str = "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2"; pub fn main() { let matches = App::new("Contract checking") diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index 2761ac280b..e7c63418f4 100644 --- a/packages/std/src/results/cosmos_msg.rs +++ b/packages/std/src/results/cosmos_msg.rs @@ -141,7 +141,12 @@ pub enum WasmMsg { }, /// Instantiates a new contracts from previously uploaded Wasm code. /// - /// This is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.16.0-alpha1/x/wasm/internal/types/tx.proto#L47-L61). + /// The contract address is non-predictable. But it is guaranteed that + /// when emitting the same Instantiate message multiple times, + /// multiple instances on different addresses will be generated. See also + /// Instantiate2. + /// + /// This is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). /// `sender` is automatically filled with the current contract's address. Instantiate { admin: Option, @@ -153,6 +158,25 @@ pub enum WasmMsg { /// A human-readbale label for the contract label: String, }, + /// Instantiates a new contracts from previously uploaded Wasm code + /// using a predictable address derivation algorithm implemented in + /// [`cosmwasm_std::instantiate2_address`]. + /// + /// This is translated to a [MsgInstantiateContract2](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L73-L96). + /// `sender` is automatically filled with the current contract's address. + #[cfg(feature = "cosmwasm_1_2")] + Instantiate2 { + admin: Option, + code_id: u64, + /// A human-readbale label for the contract + label: String, + /// msg is the JSON-encoded InstantiateMsg struct (as raw Binary) + #[derivative(Debug(format_with = "binary_to_string"))] + msg: Binary, + funds: Vec, + salt: Binary, + fix_msg: bool, + }, /// Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to /// customize behavior. /// diff --git a/packages/vm/src/testing/instance.rs b/packages/vm/src/testing/instance.rs index 6311c10a67..14b85cf7c9 100644 --- a/packages/vm/src/testing/instance.rs +++ b/packages/vm/src/testing/instance.rs @@ -98,7 +98,7 @@ pub struct MockInstanceOptions<'a> { impl MockInstanceOptions<'_> { fn default_capabilities() -> HashSet { #[allow(unused_mut)] - let mut out = capabilities_from_csv("iterator,staking,cosmwasm_1_1"); + let mut out = capabilities_from_csv("iterator,staking,cosmwasm_1_1,cosmwasm_1_2"); #[cfg(feature = "stargate")] out.insert("stargate".to_string()); out