From 1af4461846c77c83600c2b56507e5f391cf3df1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCn=20=C3=96zerk?= Date: Mon, 14 Oct 2024 13:01:35 +0300 Subject: [PATCH 01/12] asset hub as reserve for generic template --- generic-template/Cargo.lock | 1 + generic-template/Cargo.toml | 12 ++- generic-template/runtime/Cargo.toml | 17 +++-- .../runtime/src/configs/xcm_config.rs | 73 +++++++++++++++++-- 4 files changed, 88 insertions(+), 15 deletions(-) diff --git a/generic-template/Cargo.lock b/generic-template/Cargo.lock index c3600a64..ca238d1a 100644 --- a/generic-template/Cargo.lock +++ b/generic-template/Cargo.lock @@ -3681,6 +3681,7 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", + "xcm-primitives", ] [[package]] diff --git a/generic-template/Cargo.toml b/generic-template/Cargo.toml index dfe8d5e4..b598dccf 100644 --- a/generic-template/Cargo.toml +++ b/generic-template/Cargo.toml @@ -1,20 +1,20 @@ [workspace] -members = [ "node", "runtime", "template-fuzzer" ] +members = ["node", "runtime", "template-fuzzer"] resolver = "2" [workspace.package] -authors = [ "OpenZeppelin" ] +authors = ["OpenZeppelin"] description = "Generic runtime template for Polkadot Para{chains, cores}" edition = "2021" license = "GPL-3.0-only" repository = "https://github.com/OpenZeppelin/polkadot-runtime-templates" [workspace.dependencies] -clap = { version = "4.5.3", features = [ "derive" ] } +clap = { version = "4.5.3", features = ["derive"] } color-print = "0.3.4" futures = "0.3.30" hex-literal = "0.4.1" -jsonrpsee = { version = "0.23.2", features = [ "server" ] } +jsonrpsee = { version = "0.23.2", features = ["server"] } log = { version = "0.4.21", default-features = false } parity-scale-codec = { version = "3.6.12", default-features = false, features = [ "derive", @@ -132,6 +132,10 @@ parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", defaul # Moonbeam pallet-asset-manager = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch = "polkadot-stable2407-1", default-features = false } +xcm-primitives = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch = "polkadot-stable2407-1", default-features = false } + +# ORML +orml-xcm-support = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } # Fuzzer ziggy = { version = "1.0.2", default-features = false } diff --git a/generic-template/runtime/Cargo.toml b/generic-template/runtime/Cargo.toml index e4bccb4d..de4a0a3e 100644 --- a/generic-template/runtime/Cargo.toml +++ b/generic-template/runtime/Cargo.toml @@ -8,13 +8,13 @@ repository = { workspace = true } version = "2.0.0" [package.metadata.docs.rs] -targets = [ "x86_64-unknown-linux-gnu" ] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] hex-literal = { workspace = true, optional = true } log = { workspace = true } -parity-scale-codec = { workspace = true, features = [ "derive" ] } -scale-info = { workspace = true, features = [ "derive" ] } +parity-scale-codec = { workspace = true, features = ["derive"] } +scale-info = { workspace = true, features = ["derive"] } smallvec = { workspace = true } # Substrate @@ -84,6 +84,10 @@ parachains-common = { workspace = true } # Moonbeam pallet-asset-manager = { workspace = true } +xcm-primitives = { workspace = true } + +# ORML +orml-xcm-support = { workspace = true } [dev-dependencies] sp-io = { workspace = true } @@ -92,7 +96,7 @@ sp-io = { workspace = true } substrate-wasm-builder = { workspace = true } [features] -default = [ "std" ] +default = ["std"] std = [ "assets-common/std", "cumulus-pallet-aura-ext/std", @@ -156,10 +160,11 @@ std = [ "sp-version/std", "xcm-builder/std", "xcm-executor/std", + "xcm-primitives/std", "xcm/std", ] async-backing = [] -metadata-hash = [ "substrate-wasm-builder/metadata-hash" ] +metadata-hash = ["substrate-wasm-builder/metadata-hash"] runtime-benchmarks = [ "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", @@ -235,4 +240,4 @@ try-runtime = [ # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = [ "sp-api/disable-logging" ] +on-chain-release-build = ["sp-api/disable-logging"] diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index 352c7e21..c0274452 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -1,24 +1,29 @@ +use core::marker::PhantomData; + use frame_support::{ parameter_types, - traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, + pallet_prelude::Get, + traits::{ConstU32, Contains, ContainsPair, Everything, Nothing, PalletInfoAccess}, weights::Weight, }; use frame_system::EnsureRoot; +use orml_xcm_support::MultiNativeAsset; use pallet_xcm::XcmPassthrough; use polkadot_parachain_primitives::primitives::{self, Sibling}; use polkadot_runtime_common::impls::ToAuthor; use xcm::latest::prelude::*; -use xcm_builder::{ +use xcm_builder::{ Case, AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsChildSystemParachain, - IsConcrete, NativeAsset, NoChecking, ParentIsPreset, RelayChainAsNative, + IsConcrete, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; use xcm_executor::XcmExecutor; +use xcm_primitives::{AbsoluteAndRelativeReserve}; use super::TreasuryAccount; use crate::{ @@ -31,7 +36,6 @@ use crate::{ }; parameter_types! { - pub const RelayLocation: Location = Location::parent(); pub const RelayNetwork: Option = None; pub PlaceholderAccount: AccountId = PolkadotXcm::check_account(); pub AssetsPalletLocation: Location = @@ -145,6 +149,46 @@ pub type Barrier = TrailingSetTopicAsId< >, >; +/// Matches foreign assets from a given origin. +/// Foreign assets are assets bridged from other consensus systems. i.e parents > 1. +pub struct IsBridgedConcreteAssetFrom(PhantomData); +impl ContainsPair for IsBridgedConcreteAssetFrom +where + Origin: Get, +{ + fn contains(asset: &Asset, origin: &Location) -> bool { + let loc = Origin::get(); + &loc == origin + && matches!( + asset, + Asset { id: AssetId(Location { parents: 2, .. }), fun: Fungibility::Fungible(_) }, + ) + } +} + +parameter_types! { + /// Location of Asset Hub + pub AssetHubLocation: Location = Location::new(1, [Parachain(1000)]); + pub const RelayLocation: Location = Location::parent(); + pub RelayLocationFilter: AssetFilter = Wild(AllOf { + fun: WildFungible, + id: xcm::prelude::AssetId(RelayLocation::get()), + }); + pub RelayChainNativeAssetFromAssetHub: (AssetFilter, Location) = ( + RelayLocationFilter::get(), + AssetHubLocation::get() + ); +} + +type Reserves = ( + // Assets bridged from different consensus systems held in reserve on Asset Hub. + IsBridgedConcreteAssetFrom, + // Relaychain (DOT) from Asset Hub + Case, + // Assets which the reserve is the same as the origin. + MultiNativeAsset>, +); + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type Aliasers = Nothing; @@ -165,7 +209,7 @@ impl xcm_executor::Config for XcmConfig { type HrmpChannelClosingHandler = (); type HrmpNewChannelOpenRequestHandler = (); /// Please, keep these two configs (`IsReserve` and `IsTeleporter`) mutually exclusive - type IsReserve = NativeAsset; + type IsReserve = Reserves; type IsTeleporter = (); type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type MessageExporter = (); @@ -240,3 +284,22 @@ impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; } + + +// We are not using all of these below atm, but we will need them when configuring `orml_xtokens` +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(200_000_000u64, 0); + pub const MaxAssetsForTransfer: usize = 2; + + // This is how we are going to detect whether the asset is a Reserve asset + // This however is the chain part only + pub SelfLocation: Location = Location::here(); + // We need this to be able to catch when someone is trying to execute a non- + // cross-chain transfer in xtokens through the absolute path way + pub SelfLocationAbsolute: Location = Location { + parents:1, + interior: [ + Parachain(ParachainInfo::parachain_id().into()) + ].into() + }; +} From 319e4fbac0b9e8f90e252aff05b7104cc8e1b4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCn=20=C3=96zerk?= Date: Mon, 14 Oct 2024 13:40:38 +0300 Subject: [PATCH 02/12] wip --- generic-template/Cargo.lock | 199 +++++++++++++++++- generic-template/Cargo.toml | 3 + generic-template/runtime/Cargo.toml | 20 +- .../runtime/src/configs/xcm_config.rs | 164 ++++++++++++++- generic-template/runtime/src/lib.rs | 8 + generic-template/runtime/src/weights/mod.rs | 1 + .../src/weights/pallet_xcm_weight_trader.rs | 104 +++++++++ 7 files changed, 486 insertions(+), 13 deletions(-) create mode 100644 generic-template/runtime/src/weights/pallet_xcm_weight_trader.rs diff --git a/generic-template/Cargo.lock b/generic-template/Cargo.lock index ca238d1a..b55888f2 100644 --- a/generic-template/Cargo.lock +++ b/generic-template/Cargo.lock @@ -675,6 +675,17 @@ dependencies = [ "url", ] +[[package]] +name = "auto_impl" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.75", +] + [[package]] name = "autocfg" version = "1.3.0" @@ -2816,6 +2827,7 @@ dependencies = [ "fixed-hash", "impl-codec", "impl-rlp", + "impl-serde", "scale-info", "tiny-keccak", ] @@ -2833,6 +2845,7 @@ dependencies = [ "parity-scale-codec", "rlp", "scale-info", + "serde", "sha3", "trie-root", ] @@ -2847,6 +2860,7 @@ dependencies = [ "fixed-hash", "impl-codec", "impl-rlp", + "impl-serde", "primitive-types", "scale-info", "uint", @@ -2890,6 +2904,64 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "evm" +version = "0.41.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "767f43e9630cc36cf8ff2777cbb0121b055f0d1fd6eaaa13b46a1808f0d0e7e9" +dependencies = [ + "auto_impl", + "environmental", + "ethereum", + "evm-core", + "evm-gasometer", + "evm-runtime", + "log", + "parity-scale-codec", + "primitive-types", + "rlp", + "scale-info", + "serde", + "sha3", +] + +[[package]] +name = "evm-core" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1da6cedc5cedb4208e59467106db0d1f50db01b920920589f8e672c02fdc04f" +dependencies = [ + "parity-scale-codec", + "primitive-types", + "scale-info", + "serde", +] + +[[package]] +name = "evm-gasometer" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dc0eb591abc5cd7b05bef6a036c2bb6c66ab6c5e0c5ce94bfe377ab670b1fd7" +dependencies = [ + "environmental", + "evm-core", + "evm-runtime", + "primitive-types", +] + +[[package]] +name = "evm-runtime" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84bbe09b64ae13a29514048c1bb6fda6374ac0b4f6a1f15a443348ab88ef42cd" +dependencies = [ + "auto_impl", + "environmental", + "evm-core", + "primitive-types", + "sha3", +] + [[package]] name = "exit-future" version = "0.2.0" @@ -3114,6 +3186,40 @@ dependencies = [ "thiserror", ] +[[package]] +name = "fp-account" +version = "1.0.0-dev" +source = "git+https://github.com/OpenZeppelin/frontier?branch=polkadot-stable2407-1#1221dba057cb78337f7a20339514841a64a54b6d" +dependencies = [ + "hex", + "impl-serde", + "libsecp256k1", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-runtime-interface", + "staging-xcm", +] + +[[package]] +name = "fp-evm" +version = "3.0.0-dev" +source = "git+https://github.com/OpenZeppelin/frontier?branch=polkadot-stable2407-1#1221dba057cb78337f7a20339514841a64a54b6d" +dependencies = [ + "evm", + "frame-support", + "num_enum", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", +] + [[package]] name = "fragile" version = "2.0.0" @@ -3641,6 +3747,7 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-conviction-voting", + "pallet-erc20-xcm-bridge", "pallet-message-queue", "pallet-multisig", "pallet-preimage", @@ -3656,6 +3763,7 @@ dependencies = [ "pallet-utility", "pallet-whitelist", "pallet-xcm", + "pallet-xcm-weight-trader", "parachains-common", "parity-scale-codec", "polkadot-parachain-primitives", @@ -6204,6 +6312,27 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" +dependencies = [ + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.75", +] + [[package]] name = "object" version = "0.30.4" @@ -6384,6 +6513,7 @@ dependencies = [ "parity-scale-codec", "paste", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -6399,6 +6529,7 @@ dependencies = [ "frame-support", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -6828,6 +6959,51 @@ dependencies = [ "sp-staking", ] +[[package]] +name = "pallet-erc20-xcm-bridge" +version = "1.0.0" +source = "git+https://github.com/OpenZeppelin/moonbeam.git?branch=polkadot-stable2407-1#fab6e72fbaaeaa065ad983556d09d4c0e8755dfa" +dependencies = [ + "environmental", + "ethereum-types", + "fp-evm", + "frame-support", + "frame-system", + "log", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", +] + +[[package]] +name = "pallet-evm" +version = "6.0.0-dev" +source = "git+https://github.com/OpenZeppelin/frontier?branch=polkadot-stable2407-1#1221dba057cb78337f7a20339514841a64a54b6d" +dependencies = [ + "environmental", + "evm", + "fp-account", + "fp-evm", + "frame-benchmarking", + "frame-support", + "frame-system", + "hash-db", + "hex-literal", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", +] + [[package]] name = "pallet-fast-unstake" version = "36.0.0" @@ -7535,6 +7711,27 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "pallet-xcm-weight-trader" +version = "0.1.0" +source = "git+https://github.com/OpenZeppelin/moonbeam.git?branch=polkadot-stable2407-1#fab6e72fbaaeaa065ad983556d09d4c0e8755dfa" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", + "xcm-runtime-apis", +] + [[package]] name = "parachains-common" version = "17.0.0" @@ -9342,7 +9539,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" dependencies = [ "bytes", - "heck 0.5.0", + "heck 0.4.1", "itertools 0.12.1", "log", "multimap 0.10.0", diff --git a/generic-template/Cargo.toml b/generic-template/Cargo.toml index b598dccf..c5191907 100644 --- a/generic-template/Cargo.toml +++ b/generic-template/Cargo.toml @@ -132,10 +132,13 @@ parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", defaul # Moonbeam pallet-asset-manager = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch = "polkadot-stable2407-1", default-features = false } +pallet-xcm-weight-trader = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch = "polkadot-stable2407-1", default-features = false } xcm-primitives = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch = "polkadot-stable2407-1", default-features = false } # ORML +orml-traits = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } orml-xcm-support = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } +orml-xtokens = { git = "https://github.com/OpenZeppelin/open-runtime-module-library", branch = "polkadot-stable2407-1", default-features = false } # Fuzzer ziggy = { version = "1.0.2", default-features = false } diff --git a/generic-template/runtime/Cargo.toml b/generic-template/runtime/Cargo.toml index de4a0a3e..ac525b1b 100644 --- a/generic-template/runtime/Cargo.toml +++ b/generic-template/runtime/Cargo.toml @@ -84,10 +84,13 @@ parachains-common = { workspace = true } # Moonbeam pallet-asset-manager = { workspace = true } +pallet-xcm-weight-trader = { workspace = true } xcm-primitives = { workspace = true } # ORML +orml-traits = { workspace = true } orml-xcm-support = { workspace = true } +orml-xtokens = { workspace = true } [dev-dependencies] sp-io = { workspace = true } @@ -96,7 +99,6 @@ sp-io = { workspace = true } substrate-wasm-builder = { workspace = true } [features] -default = ["std"] std = [ "assets-common/std", "cumulus-pallet-aura-ext/std", @@ -117,6 +119,7 @@ std = [ "frame-system/std", "frame-try-runtime?/std", "log/std", + "orml-xtokens/std", "pallet-asset-manager/std", "pallet-assets/std", "pallet-aura/std", @@ -124,6 +127,7 @@ std = [ "pallet-balances/std", "pallet-collator-selection/std", "pallet-conviction-voting/std", + "pallet-erc20-xcm-bridge/std", "pallet-message-queue/std", "pallet-multisig/std", "pallet-preimage/std", @@ -138,6 +142,7 @@ std = [ "pallet-treasury/std", "pallet-utility/std", "pallet-whitelist/std", + "pallet-xcm-weight-trader/std", "pallet-xcm/std", "parachain-info/std", "parachains-common/std", @@ -163,8 +168,7 @@ std = [ "xcm-primitives/std", "xcm/std", ] -async-backing = [] -metadata-hash = ["substrate-wasm-builder/metadata-hash"] + runtime-benchmarks = [ "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", @@ -192,6 +196,7 @@ runtime-benchmarks = [ "pallet-treasury/runtime-benchmarks", "pallet-utility/runtime-benchmarks", "pallet-whitelist/runtime-benchmarks", + "pallet-xcm-weight-trader/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", @@ -210,6 +215,7 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "frame-try-runtime/try-runtime", + "orml-xtokens/try-runtime", "pallet-asset-manager/try-runtime", "pallet-assets/try-runtime", "pallet-aura/try-runtime", @@ -217,6 +223,7 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-conviction-voting/try-runtime", + "pallet-erc20-xcm-bridge/try-runtime", "pallet-message-queue/try-runtime", "pallet-multisig/try-runtime", "pallet-preimage/try-runtime", @@ -231,6 +238,7 @@ try-runtime = [ "pallet-treasury/try-runtime", "pallet-utility/try-runtime", "pallet-whitelist/try-runtime", + "pallet-xcm-weight-trader/try-runtime", "pallet-xcm/try-runtime", "parachain-info/try-runtime", "polkadot-runtime-common/try-runtime", @@ -241,3 +249,9 @@ try-runtime = [ # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. on-chain-release-build = ["sp-api/disable-logging"] + +async-backing = [] + +default = ["std"] + +metadata-hash = ["substrate-wasm-builder/metadata-hash"] diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index c0274452..5ff24137 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -7,10 +7,14 @@ use frame_support::{ weights::Weight, }; use frame_system::EnsureRoot; +use orml_traits::parameter_type_with_key; use orml_xcm_support::MultiNativeAsset; use pallet_xcm::XcmPassthrough; +use parity_scale_codec::{Decode, Encode}; use polkadot_parachain_primitives::primitives::{self, Sibling}; use polkadot_runtime_common::impls::ToAuthor; +use scale_info::TypeInfo; +use sp_core::H160; use xcm::latest::prelude::*; use xcm_builder::{ Case, AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, @@ -19,16 +23,18 @@ use xcm_builder::{ Case, IsConcrete, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; -use xcm_executor::XcmExecutor; -use xcm_primitives::{AbsoluteAndRelativeReserve}; +use xcm_executor::{traits::{ConvertLocation}, XcmExecutor}; +use xcm_primitives::{ + AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, +}; use super::TreasuryAccount; use crate::{ configs::{ - weights, Balances, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + asset_config::AccountIdAssetIdConversion, weights, Balances, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }, types::{AccountId, Balance}, @@ -42,6 +48,16 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + // Self Reserve location, defines the multilocation identifiying the self-reserve currency + // This is used to match it also against our Balances pallet when we receive such + // a Location: (Self Balances pallet index) + // We use the RELATIVE multilocation + pub SelfReserve: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; } /// `AssetId/Balancer` converter for `TrustBackedAssets` @@ -189,6 +205,8 @@ type Reserves = ( MultiNativeAsset>, ); +pub type XcmWeigher = FixedWeightBounds; + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type Aliasers = Nothing; @@ -197,7 +215,7 @@ impl xcm_executor::Config for XcmConfig { type AssetLocker = (); // How to withdraw and deposit an asset. type AssetTransactor = AssetTransactors; - type AssetTrap = PolkadotXcm; + type AssetTrap = PolakdotXcm; type Barrier = Barrier; type CallDispatcher = RuntimeCall; /// When changing this config, keep in mind, that you should collect fees. @@ -219,13 +237,12 @@ impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; type SafeCallFilter = Everything; type SubscriptionService = PolkadotXcm; - type Trader = - UsingComponents>; + type Trader = pallet_xcm_weight_trader::Trader; type TransactionalProcessor = FrameTransactionalProcessor; type UniversalAliases = Nothing; // Teleporting is disabled. type UniversalLocation = UniversalLocation; - type Weigher = FixedWeightBounds; + type Weigher = XcmWeigher; type XcmRecorder = PolkadotXcm; type XcmSender = XcmRouter; } @@ -264,7 +281,7 @@ impl pallet_xcm::Config for Runtime { type SovereignAccountOf = LocationToAccountId; type TrustedLockers = (); type UniversalLocation = UniversalLocation; - type Weigher = FixedWeightBounds; + type Weigher = XcmWeigher; /// Rerun benchmarks if you are making changes to runtime configuration. type WeightInfo = weights::pallet_xcm::WeightInfo; #[cfg(feature = "runtime-benchmarks")] @@ -303,3 +320,132 @@ parameter_types! { ].into() }; } + +parameter_type_with_key! { + pub ParachainMinFee: |location: Location| -> Option { + match (location.parents, location.first_interior()) { + // Polkadot AssetHub fee + (1, Some(Parachain(1000u32))) => Some(50_000_000u128), + _ => None, + } + }; +} + +// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id. +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum CurrencyId { + // Our native token + SelfReserve, + // Assets representing other chains native tokens + ForeignAsset(AssetId), + // Erc20 token + Erc20 { contract_address: H160 }, +} + +impl AccountIdToCurrencyId for Runtime { + fn account_to_currency_id(account: AccountId) -> Option { + Some(match account { + // the self-reserve currency is identified by the pallet-balances address + a if a == H160::from_low_u64_be(2050).into() => CurrencyId::SelfReserve, + // the rest of the currencies, by their corresponding erc20 address + _ => match Runtime::account_to_asset_id(account) { + // We distinguish by prefix, and depending on it we create either + // Foreign or Local + Some((_prefix, asset_id)) => CurrencyId::ForeignAsset(asset_id), + // If no known prefix is identified, we consider that it's a "real" erc20 token + // (i.e. managed by a real smart contract) + None => CurrencyId::Erc20 { contract_address: account.into() }, + }, + }) + } +} +// How to convert from CurrencyId to Location +pub struct CurrencyIdToLocation(sp_std::marker::PhantomData); +impl sp_runtime::traits::Convert> + for CurrencyIdToLocation +where + AssetXConverter: sp_runtime::traits::MaybeEquivalence, +{ + fn convert(currency: CurrencyId) -> Option { + match currency { + CurrencyId::SelfReserve => { + let multi: Location = SelfReserve::get(); + Some(multi) + } + CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), + CurrencyId::Erc20 { contract_address } => { + let mut location = Erc20XcmBridgePalletLocation::get(); // TODO: if we do not have an alternative, we need to import this pallet from moonbeam + location + .push_interior(Junction::AccountKey20 { + key: contract_address.0, + network: None, + }) + .ok(); + Some(location) + } + } + } +} + +/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`. +pub struct LocationToH160; +impl ConvertLocation for LocationToH160 { + fn convert_location(location: &Location) -> Option { + >::convert_location(location) + .map(Into::into) + } +} + + +impl orml_xtokens::Config for Runtime { + type AccountIdToLocation = AccountIdToLocation; + type Balance = Balance; + type BaseXcmWeight = BaseXcmWeight; + type CurrencyId = CurrencyId; + type CurrencyIdConvert = CurrencyIdToLocation>; + type LocationsFilter = Everything; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type RateLimiter = (); + type RateLimiterId = (); + type ReserveProvider = AbsoluteAndRelativeReserve; + type RuntimeEvent = RuntimeEvent; + type SelfLocation = SelfLocation; + type UniversalLocation = UniversalLocation; + type Weigher = XcmWeigher; + type XcmExecutor = XcmExecutor; +} + +pub struct AssetFeesFilter; +impl frame_support::traits::Contains for AssetFeesFilter { + fn contains(location: &Location) -> bool { + location.parent_count() > 0 + && location.first_interior() != Erc20XcmBridgePalletLocation::get().first_interior() + } +} + +// implement your own business logic for who can add/edit/remove/resume supported assets +pub type AddSupportedAssetOrigin = EnsureRoot; +pub type EditSupportedAssetOrigin = EnsureRoot; +pub type RemoveSupportedAssetOrigin = EnsureRoot; +pub type ResumeSupportedAssetOrigin = EnsureRoot; + +impl pallet_xcm_weight_trader::Config for Runtime { + type AccountIdToLocation = AccountIdToLocation; + type AddSupportedAssetOrigin = AddSupportedAssetOrigin; + type AssetLocationFilter = AssetFeesFilter; + type AssetTransactor = AssetTransactors; + type Balance = Balance; + type EditSupportedAssetOrigin = EditSupportedAssetOrigin; + type NativeLocation = SelfReserve; + #[cfg(feature = "runtime-benchmarks")] + type NotFilteredLocation = RelayLocation; + type PauseSupportedAssetOrigin = EditSupportedAssetOrigin; + type RemoveSupportedAssetOrigin = RemoveSupportedAssetOrigin; + type ResumeSupportedAssetOrigin = ResumeSupportedAssetOrigin; + type RuntimeEvent = RuntimeEvent; + // TODO: update this when we update benchmarks + type WeightInfo = weights::pallet_xcm_weight_trader::WeightInfo; + type WeightToFee = ::WeightToFee; + type XcmFeesAccount = TreasuryAccount; +} diff --git a/generic-template/runtime/src/lib.rs b/generic-template/runtime/src/lib.rs index 4112ce40..6c6291fb 100644 --- a/generic-template/runtime/src/lib.rs +++ b/generic-template/runtime/src/lib.rs @@ -185,6 +185,14 @@ mod runtime { pub type CumulusXcm = cumulus_pallet_xcm; #[runtime::pallet_index(33)] pub type MessageQueue = pallet_message_queue; + #[runtime::pallet_index(34)] + pub type XTokens: = orml_xtokens; + #[runtime::pallet_index(35)] + pub type XcmWeightTrader = pallet_xcm_weight_trader; + + // EVM + #[runtime::pallet_index(40)] + pub type Erc20XcmBridge = pallet_erc20_xcm_bridge; } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/generic-template/runtime/src/weights/mod.rs b/generic-template/runtime/src/weights/mod.rs index deb5a8a4..22bd7d55 100644 --- a/generic-template/runtime/src/weights/mod.rs +++ b/generic-template/runtime/src/weights/mod.rs @@ -39,6 +39,7 @@ pub mod pallet_treasury; pub mod pallet_utility; pub mod pallet_whitelist; pub mod pallet_xcm; +pub mod pallet_xcm_weight_trader; pub mod paritydb_weights; pub mod rocksdb_weights; diff --git a/generic-template/runtime/src/weights/pallet_xcm_weight_trader.rs b/generic-template/runtime/src/weights/pallet_xcm_weight_trader.rs new file mode 100644 index 00000000..93d88a64 --- /dev/null +++ b/generic-template/runtime/src/weights/pallet_xcm_weight_trader.rs @@ -0,0 +1,104 @@ +// Copyright 2024 Moonbeam foundation +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +//! Autogenerated weights for `pallet_xcm_weight_trader` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-09-13, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_xcm_weight_trader +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weights for `pallet_xcm_weight_trader`. +pub struct WeightInfo(PhantomData); +impl pallet_xcm_weight_trader::WeightInfo for WeightInfo { + /// Storage: `XcmWeightTrader::SupportedAssets` (r:1 w:1) + /// Proof: `XcmWeightTrader::SupportedAssets` (`max_values`: None, `max_size`: Some(635), added: 3110, mode: `MaxEncodedLen`) + fn add_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `4100` + // Minimum execution time: 9_432_000 picoseconds. + Weight::from_parts(9_644_000, 4100) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmWeightTrader::SupportedAssets` (r:1 w:1) + /// Proof: `XcmWeightTrader::SupportedAssets` (`max_values`: None, `max_size`: Some(635), added: 3110, mode: `MaxEncodedLen`) + fn edit_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `102` + // Estimated: `4100` + // Minimum execution time: 10_261_000 picoseconds. + Weight::from_parts(10_540_000, 4100) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmWeightTrader::SupportedAssets` (r:1 w:1) + /// Proof: `XcmWeightTrader::SupportedAssets` (`max_values`: None, `max_size`: Some(635), added: 3110, mode: `MaxEncodedLen`) + fn resume_asset_support() -> Weight { + // Proof Size summary in bytes: + // Measured: `102` + // Estimated: `4100` + // Minimum execution time: 10_153_000 picoseconds. + Weight::from_parts(10_537_000, 4100) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmWeightTrader::SupportedAssets` (r:1 w:1) + /// Proof: `XcmWeightTrader::SupportedAssets` (`max_values`: None, `max_size`: Some(635), added: 3110, mode: `MaxEncodedLen`) + fn pause_asset_support() -> Weight { + // Proof Size summary in bytes: + // Measured: `102` + // Estimated: `4100` + // Minimum execution time: 10_029_000 picoseconds. + Weight::from_parts(10_456_000, 4100) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmWeightTrader::SupportedAssets` (r:1 w:1) + /// Proof: `XcmWeightTrader::SupportedAssets` (`max_values`: None, `max_size`: Some(635), added: 3110, mode: `MaxEncodedLen`) + fn remove_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `102` + // Estimated: `4100` + // Minimum execution time: 9_844_000 picoseconds. + Weight::from_parts(10_218_000, 4100) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} From bbcd3051ed46faffa1e6080f3e6fe185433cee98 Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Wed, 16 Oct 2024 09:43:41 +0300 Subject: [PATCH 03/12] wip --- generic-template/Cargo.lock | 173 ------------------ generic-template/runtime/Cargo.toml | 2 - generic-template/runtime/src/configs/mod.rs | 1 + .../runtime/src/configs/xcm_config.rs | 42 +++-- generic-template/runtime/src/lib.rs | 6 +- 5 files changed, 26 insertions(+), 198 deletions(-) diff --git a/generic-template/Cargo.lock b/generic-template/Cargo.lock index b55888f2..231516bb 100644 --- a/generic-template/Cargo.lock +++ b/generic-template/Cargo.lock @@ -675,17 +675,6 @@ dependencies = [ "url", ] -[[package]] -name = "auto_impl" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - [[package]] name = "autocfg" version = "1.3.0" @@ -2827,7 +2816,6 @@ dependencies = [ "fixed-hash", "impl-codec", "impl-rlp", - "impl-serde", "scale-info", "tiny-keccak", ] @@ -2845,7 +2833,6 @@ dependencies = [ "parity-scale-codec", "rlp", "scale-info", - "serde", "sha3", "trie-root", ] @@ -2860,7 +2847,6 @@ dependencies = [ "fixed-hash", "impl-codec", "impl-rlp", - "impl-serde", "primitive-types", "scale-info", "uint", @@ -2904,64 +2890,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "evm" -version = "0.41.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "767f43e9630cc36cf8ff2777cbb0121b055f0d1fd6eaaa13b46a1808f0d0e7e9" -dependencies = [ - "auto_impl", - "environmental", - "ethereum", - "evm-core", - "evm-gasometer", - "evm-runtime", - "log", - "parity-scale-codec", - "primitive-types", - "rlp", - "scale-info", - "serde", - "sha3", -] - -[[package]] -name = "evm-core" -version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1da6cedc5cedb4208e59467106db0d1f50db01b920920589f8e672c02fdc04f" -dependencies = [ - "parity-scale-codec", - "primitive-types", - "scale-info", - "serde", -] - -[[package]] -name = "evm-gasometer" -version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dc0eb591abc5cd7b05bef6a036c2bb6c66ab6c5e0c5ce94bfe377ab670b1fd7" -dependencies = [ - "environmental", - "evm-core", - "evm-runtime", - "primitive-types", -] - -[[package]] -name = "evm-runtime" -version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84bbe09b64ae13a29514048c1bb6fda6374ac0b4f6a1f15a443348ab88ef42cd" -dependencies = [ - "auto_impl", - "environmental", - "evm-core", - "primitive-types", - "sha3", -] - [[package]] name = "exit-future" version = "0.2.0" @@ -3186,40 +3114,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "fp-account" -version = "1.0.0-dev" -source = "git+https://github.com/OpenZeppelin/frontier?branch=polkadot-stable2407-1#1221dba057cb78337f7a20339514841a64a54b6d" -dependencies = [ - "hex", - "impl-serde", - "libsecp256k1", - "log", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "sp-runtime-interface", - "staging-xcm", -] - -[[package]] -name = "fp-evm" -version = "3.0.0-dev" -source = "git+https://github.com/OpenZeppelin/frontier?branch=polkadot-stable2407-1#1221dba057cb78337f7a20339514841a64a54b6d" -dependencies = [ - "evm", - "frame-support", - "num_enum", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-runtime", -] - [[package]] name = "fragile" version = "2.0.0" @@ -3747,7 +3641,6 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-conviction-voting", - "pallet-erc20-xcm-bridge", "pallet-message-queue", "pallet-multisig", "pallet-preimage", @@ -6312,27 +6205,6 @@ dependencies = [ "libc", ] -[[package]] -name = "num_enum" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" -dependencies = [ - "proc-macro-crate 3.1.0", - "proc-macro2", - "quote", - "syn 2.0.75", -] - [[package]] name = "object" version = "0.30.4" @@ -6959,51 +6831,6 @@ dependencies = [ "sp-staking", ] -[[package]] -name = "pallet-erc20-xcm-bridge" -version = "1.0.0" -source = "git+https://github.com/OpenZeppelin/moonbeam.git?branch=polkadot-stable2407-1#fab6e72fbaaeaa065ad983556d09d4c0e8755dfa" -dependencies = [ - "environmental", - "ethereum-types", - "fp-evm", - "frame-support", - "frame-system", - "log", - "pallet-evm", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-runtime", - "sp-std", - "staging-xcm", - "staging-xcm-executor", -] - -[[package]] -name = "pallet-evm" -version = "6.0.0-dev" -source = "git+https://github.com/OpenZeppelin/frontier?branch=polkadot-stable2407-1#1221dba057cb78337f7a20339514841a64a54b6d" -dependencies = [ - "environmental", - "evm", - "fp-account", - "fp-evm", - "frame-benchmarking", - "frame-support", - "frame-system", - "hash-db", - "hex-literal", - "impl-trait-for-tuples", - "log", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", -] - [[package]] name = "pallet-fast-unstake" version = "36.0.0" diff --git a/generic-template/runtime/Cargo.toml b/generic-template/runtime/Cargo.toml index ac525b1b..bb72a055 100644 --- a/generic-template/runtime/Cargo.toml +++ b/generic-template/runtime/Cargo.toml @@ -127,7 +127,6 @@ std = [ "pallet-balances/std", "pallet-collator-selection/std", "pallet-conviction-voting/std", - "pallet-erc20-xcm-bridge/std", "pallet-message-queue/std", "pallet-multisig/std", "pallet-preimage/std", @@ -223,7 +222,6 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-conviction-voting/try-runtime", - "pallet-erc20-xcm-bridge/try-runtime", "pallet-message-queue/try-runtime", "pallet-multisig/try-runtime", "pallet-preimage/try-runtime", diff --git a/generic-template/runtime/src/configs/mod.rs b/generic-template/runtime/src/configs/mod.rs index 8df70d2a..f94b8663 100644 --- a/generic-template/runtime/src/configs/mod.rs +++ b/generic-template/runtime/src/configs/mod.rs @@ -1,4 +1,5 @@ pub mod asset_config; +pub use asset_config::AssetType; pub mod governance; pub mod xcm_config; diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index 5ff24137..f69f3720 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -1,8 +1,8 @@ use core::marker::PhantomData; use frame_support::{ - parameter_types, pallet_prelude::Get, + parameter_types, traits::{ConstU32, Contains, ContainsPair, Everything, Nothing, PalletInfoAccess}, weights::Weight, }; @@ -16,17 +16,16 @@ use polkadot_runtime_common::impls::ToAuthor; use scale_info::TypeInfo; use sp_core::H160; use xcm::latest::prelude::*; -use xcm_builder::{ Case, - AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, +use xcm_builder::{ + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, Case, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsChildSystemParachain, - IsConcrete, NoChecking, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, - XcmFeeToAccount, + IsConcrete, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, WithComputedOrigin, + WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; -use xcm_executor::{traits::{ConvertLocation}, XcmExecutor}; +use xcm_executor::{traits::ConvertLocation, XcmExecutor}; use xcm_primitives::{ AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, }; @@ -34,11 +33,11 @@ use xcm_primitives::{ use super::TreasuryAccount; use crate::{ configs::{ - asset_config::AccountIdAssetIdConversion, weights, Balances, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - WeightToFee, XcmpQueue, + asset_config::AccountIdAssetIdConversion, weights, AssetType, Balances, ParachainSystem, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }, types::{AccountId, Balance}, - AllPalletsWithSystem, Assets, ParachainInfo, PolkadotXcm, + AllPalletsWithSystem, AssetManager, Assets, ParachainInfo, PolkadotXcm, }; parameter_types! { @@ -215,7 +214,7 @@ impl xcm_executor::Config for XcmConfig { type AssetLocker = (); // How to withdraw and deposit an asset. type AssetTransactor = AssetTransactors; - type AssetTrap = PolakdotXcm; + type AssetTrap = PolkadotXcm; type Barrier = Barrier; type CallDispatcher = RuntimeCall; /// When changing this config, keep in mind, that you should collect fees. @@ -302,8 +301,6 @@ impl cumulus_pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; } - -// We are not using all of these below atm, but we will need them when configuring `orml_xtokens` parameter_types! { pub const BaseXcmWeight: Weight = Weight::from_parts(200_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; @@ -359,6 +356,16 @@ impl AccountIdToCurrencyId for Runtime { }) } } + +parameter_types! { + pub PolkadotXcmLocation: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) // is using PolkadotXcm as the location for Erc20 assets correct? + ].into() + }; +} + // How to convert from CurrencyId to Location pub struct CurrencyIdToLocation(sp_std::marker::PhantomData); impl sp_runtime::traits::Convert> @@ -374,7 +381,7 @@ where } CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), CurrencyId::Erc20 { contract_address } => { - let mut location = Erc20XcmBridgePalletLocation::get(); // TODO: if we do not have an alternative, we need to import this pallet from moonbeam + let mut location = PolkadotXcmLocation::get(); location .push_interior(Junction::AccountKey20 { key: contract_address.0, @@ -396,7 +403,6 @@ impl ConvertLocation for LocationToH160 { } } - impl orml_xtokens::Config for Runtime { type AccountIdToLocation = AccountIdToLocation; type Balance = Balance; @@ -420,7 +426,7 @@ pub struct AssetFeesFilter; impl frame_support::traits::Contains for AssetFeesFilter { fn contains(location: &Location) -> bool { location.parent_count() > 0 - && location.first_interior() != Erc20XcmBridgePalletLocation::get().first_interior() + && location.first_interior() != PolkadotXcmLocation::get().first_interior() } } diff --git a/generic-template/runtime/src/lib.rs b/generic-template/runtime/src/lib.rs index 6c6291fb..5b9fed58 100644 --- a/generic-template/runtime/src/lib.rs +++ b/generic-template/runtime/src/lib.rs @@ -186,13 +186,9 @@ mod runtime { #[runtime::pallet_index(33)] pub type MessageQueue = pallet_message_queue; #[runtime::pallet_index(34)] - pub type XTokens: = orml_xtokens; + pub type XTokens = orml_xtokens; #[runtime::pallet_index(35)] pub type XcmWeightTrader = pallet_xcm_weight_trader; - - // EVM - #[runtime::pallet_index(40)] - pub type Erc20XcmBridge = pallet_erc20_xcm_bridge; } cumulus_pallet_parachain_system::register_validate_block! { From 60bcf4e0aea53694fac8aece16ca0a8f7fa39b32 Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Wed, 16 Oct 2024 10:20:00 +0300 Subject: [PATCH 04/12] wip --- generic-template/runtime/src/configs/xcm_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index f69f3720..0cf03b6f 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -36,7 +36,7 @@ use crate::{ asset_config::AccountIdAssetIdConversion, weights, AssetType, Balances, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }, - types::{AccountId, Balance}, + types::{AccountId, AssetId, Balance}, AllPalletsWithSystem, AssetManager, Assets, ParachainInfo, PolkadotXcm, }; From 48f043007274589c13ed6c43dfaecb6dc643c9d5 Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Wed, 16 Oct 2024 16:30:58 +0300 Subject: [PATCH 05/12] wip --- evm-template/zombienet-config/devnet.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evm-template/zombienet-config/devnet.toml b/evm-template/zombienet-config/devnet.toml index 0be2b612..4b482ac3 100644 --- a/evm-template/zombienet-config/devnet.toml +++ b/evm-template/zombienet-config/devnet.toml @@ -1,5 +1,5 @@ [relaychain] -chain = "paseo-local" +chain = "rococo-local" default_command = "./bin-stable2407-1/polkadot" [[relaychain.nodes]] From 87a1174cf07461d9d065c32d64dfb5a7d44b3db9 Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Tue, 22 Oct 2024 18:28:36 +0300 Subject: [PATCH 06/12] h160 removal from xcm config --- .../runtime/src/configs/xcm_config.rs | 42 ++----------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index 0cf03b6f..83938c4d 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -12,9 +12,7 @@ use orml_xcm_support::MultiNativeAsset; use pallet_xcm::XcmPassthrough; use parity_scale_codec::{Decode, Encode}; use polkadot_parachain_primitives::primitives::{self, Sibling}; -use polkadot_runtime_common::impls::ToAuthor; use scale_info::TypeInfo; -use sp_core::H160; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, Case, @@ -34,7 +32,7 @@ use super::TreasuryAccount; use crate::{ configs::{ asset_config::AccountIdAssetIdConversion, weights, AssetType, Balances, ParachainSystem, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue, }, types::{AccountId, AssetId, Balance}, AllPalletsWithSystem, AssetManager, Assets, ParachainInfo, PolkadotXcm, @@ -335,25 +333,12 @@ pub enum CurrencyId { SelfReserve, // Assets representing other chains native tokens ForeignAsset(AssetId), - // Erc20 token - Erc20 { contract_address: H160 }, } impl AccountIdToCurrencyId for Runtime { fn account_to_currency_id(account: AccountId) -> Option { - Some(match account { - // the self-reserve currency is identified by the pallet-balances address - a if a == H160::from_low_u64_be(2050).into() => CurrencyId::SelfReserve, - // the rest of the currencies, by their corresponding erc20 address - _ => match Runtime::account_to_asset_id(account) { - // We distinguish by prefix, and depending on it we create either - // Foreign or Local - Some((_prefix, asset_id)) => CurrencyId::ForeignAsset(asset_id), - // If no known prefix is identified, we consider that it's a "real" erc20 token - // (i.e. managed by a real smart contract) - None => CurrencyId::Erc20 { contract_address: account.into() }, - }, - }) + Runtime::account_to_asset_id(account) + .map(|(_prefix, asset_id)| CurrencyId::ForeignAsset(asset_id)) } } @@ -361,7 +346,7 @@ parameter_types! { pub PolkadotXcmLocation: Location = Location { parents:0, interior: [ - PalletInstance(::index() as u8) // is using PolkadotXcm as the location for Erc20 assets correct? + PalletInstance(::index() as u8) ].into() }; } @@ -380,29 +365,10 @@ where Some(multi) } CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), - CurrencyId::Erc20 { contract_address } => { - let mut location = PolkadotXcmLocation::get(); - location - .push_interior(Junction::AccountKey20 { - key: contract_address.0, - network: None, - }) - .ok(); - Some(location) - } } } } -/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`. -pub struct LocationToH160; -impl ConvertLocation for LocationToH160 { - fn convert_location(location: &Location) -> Option { - >::convert_location(location) - .map(Into::into) - } -} - impl orml_xtokens::Config for Runtime { type AccountIdToLocation = AccountIdToLocation; type Balance = Balance; From 90b89359581d9536a7193e5b39188402d9aab252 Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Wed, 23 Oct 2024 10:47:43 +0300 Subject: [PATCH 07/12] wip --- .../runtime/src/configs/xcm_config.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index 83938c4d..87085830 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -23,10 +23,8 @@ use xcm_builder::{ SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; -use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -use xcm_primitives::{ - AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, -}; +use xcm_executor::XcmExecutor; +use xcm_primitives::{AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AsAssetType}; use super::TreasuryAccount; use crate::{ @@ -369,8 +367,15 @@ where } } +pub struct AccountIdToLocation; +impl Convert for AccountIdToLocation { + fn convert(account: AccountId) -> Location { + AccountId32 { network: None, id: account.into() }.into() + } +} + impl orml_xtokens::Config for Runtime { - type AccountIdToLocation = AccountIdToLocation; + type AccountIdToLocation = AccountIdToLocation; type Balance = Balance; type BaseXcmWeight = BaseXcmWeight; type CurrencyId = CurrencyId; @@ -403,7 +408,7 @@ pub type RemoveSupportedAssetOrigin = EnsureRoot; pub type ResumeSupportedAssetOrigin = EnsureRoot; impl pallet_xcm_weight_trader::Config for Runtime { - type AccountIdToLocation = AccountIdToLocation; + type AccountIdToLocation = AccountIdToLocation; type AddSupportedAssetOrigin = AddSupportedAssetOrigin; type AssetLocationFilter = AssetFeesFilter; type AssetTransactor = AssetTransactors; From e5dcffe81823bcf4ccf29e17c69359dfe0ca08a4 Mon Sep 17 00:00:00 2001 From: Nikita Khateev Date: Wed, 23 Oct 2024 12:22:12 +0400 Subject: [PATCH 08/12] u32 fixed --- generic-template/runtime/src/configs/xcm_config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index 87085830..4ffe042c 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -13,6 +13,7 @@ use pallet_xcm::XcmPassthrough; use parity_scale_codec::{Decode, Encode}; use polkadot_parachain_primitives::primitives::{self, Sibling}; use scale_info::TypeInfo; +use sp_runtime::traits::Convert; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, Case, From 18f054de41417931bef40515a2dd739450d25bcb Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Wed, 23 Oct 2024 13:17:53 +0300 Subject: [PATCH 09/12] selfReserve variant handled --- generic-template/runtime/src/configs/xcm_config.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index 4ffe042c..c4cc7dd7 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -336,8 +336,12 @@ pub enum CurrencyId { impl AccountIdToCurrencyId for Runtime { fn account_to_currency_id(account: AccountId) -> Option { - Runtime::account_to_asset_id(account) - .map(|(_prefix, asset_id)| CurrencyId::ForeignAsset(asset_id)) + if pallet_balances::Account::::contains_key(&account) { + Some(CurrencyId::SelfReserve) + } else { + Runtime::account_to_asset_id(account) + .map(|(_prefix, asset_id)| CurrencyId::ForeignAsset(asset_id)) + } } } From 3e450716ed0bda9f1382fd335baf43d765c6c705 Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Thu, 24 Oct 2024 16:27:49 +0300 Subject: [PATCH 10/12] generic xtokens support --- .../runtime/src/configs/xcm_config.rs | 88 +++++++++++++++---- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/generic-template/runtime/src/configs/xcm_config.rs b/generic-template/runtime/src/configs/xcm_config.rs index c4cc7dd7..9fe19bda 100644 --- a/generic-template/runtime/src/configs/xcm_config.rs +++ b/generic-template/runtime/src/configs/xcm_config.rs @@ -7,7 +7,7 @@ use frame_support::{ weights::Weight, }; use frame_system::EnsureRoot; -use orml_traits::parameter_type_with_key; +use orml_traits::{location::Reserve, parameter_type_with_key}; use orml_xcm_support::MultiNativeAsset; use pallet_xcm::XcmPassthrough; use parity_scale_codec::{Decode, Encode}; @@ -25,12 +25,12 @@ use xcm_builder::{ WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount, }; use xcm_executor::XcmExecutor; -use xcm_primitives::{AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AsAssetType}; +use xcm_primitives::{AbsoluteAndRelativeReserve, AsAssetType}; use super::TreasuryAccount; use crate::{ configs::{ - asset_config::AccountIdAssetIdConversion, weights, AssetType, Balances, ParachainSystem, + weights, AssetType, Balances, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue, }, types::{AccountId, AssetId, Balance}, @@ -334,17 +334,6 @@ pub enum CurrencyId { ForeignAsset(AssetId), } -impl AccountIdToCurrencyId for Runtime { - fn account_to_currency_id(account: AccountId) -> Option { - if pallet_balances::Account::::contains_key(&account) { - Some(CurrencyId::SelfReserve) - } else { - Runtime::account_to_asset_id(account) - .map(|(_prefix, asset_id)| CurrencyId::ForeignAsset(asset_id)) - } - } -} - parameter_types! { pub PolkadotXcmLocation: Location = Location { parents:0, @@ -379,6 +368,75 @@ impl Convert for AccountIdToLocation { } } +/// The `DOTReserveProvider` overrides the default reserve location for DOT (Polkadot's native token). +/// +/// DOT can exist in multiple locations, and this provider ensures that the reserve is correctly set +/// to the AssetHub parachain. +/// +/// - **Default Location:** `{ parents: 1, location: Here }` +/// - **Reserve Location on AssetHub:** `{ parents: 1, location: X1(Parachain(AssetHubParaId)) }` +/// +/// This provider ensures that if the asset's ID points to the default "Here" location, +/// it will instead be mapped to the AssetHub parachain. +pub struct DOTReserveProvider; + +impl Reserve for DOTReserveProvider { + fn reserve(asset: &Asset) -> Option { + let AssetId(location) = &asset.id; + + let dot_here = Location::new(1, Here); + let dot_asset_hub = AssetHubLocation::get(); + + if location == &dot_here { + Some(dot_asset_hub) // Reserve is on AssetHub. + } else { + None + } + } +} + +/// The `BridgedAssetReserveProvider` handles assets that are bridged from external consensus systems +/// (e.g., Ethereum) and may have multiple valid reserve locations. +/// +/// Specifically, these bridged assets can have two known reserves: +/// 1. **Ethereum-based Reserve:** +/// `{ parents: 1, location: X1(GlobalConsensus(Ethereum{ chain_id: 1 })) }` +/// 2. **AssetHub Parachain Reserve:** +/// `{ parents: 1, location: X1(Parachain(AssetHubParaId)) }` +/// +/// This provider maps the reserve for bridged assets to AssetHub when the asset originates +/// from a global consensus system, such as Ethereum. +pub struct BridgedAssetReserveProvider; + +impl Reserve for BridgedAssetReserveProvider { + fn reserve(asset: &Asset) -> Option { + let AssetId(location) = &asset.id; + + let asset_hub_reserve = AssetHubLocation::get(); + + // any asset that has parents > 1 and interior that starts with GlobalConsensus(_) pattern + // can be considered a bridged asset. + // + // `split_global` will return an `Err` if the first item is not a `GlobalConsensus` + if location.parents > 1 && location.interior.clone().split_global().is_ok() { + Some(asset_hub_reserve) + } else { + None + } + } +} + +pub struct ReserveProviders; + +impl Reserve for ReserveProviders { + fn reserve(asset: &Asset) -> Option { + // Try each provider's reserve method in sequence. + DOTReserveProvider::reserve(asset) + .or_else(|| BridgedAssetReserveProvider::reserve(asset)) + .or_else(|| AbsoluteAndRelativeReserve::::reserve(asset)) + } +} + impl orml_xtokens::Config for Runtime { type AccountIdToLocation = AccountIdToLocation; type Balance = Balance; @@ -390,7 +448,7 @@ impl orml_xtokens::Config for Runtime { type MinXcmFee = ParachainMinFee; type RateLimiter = (); type RateLimiterId = (); - type ReserveProvider = AbsoluteAndRelativeReserve; + type ReserveProvider = ReserveProviders; type RuntimeEvent = RuntimeEvent; type SelfLocation = SelfLocation; type UniversalLocation = UniversalLocation; From 03179c8d251299dcb77d0cf84b18b29c04211d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCn=20=C3=96zerk?= Date: Fri, 25 Oct 2024 13:35:10 +0300 Subject: [PATCH 11/12] comments fixed --- generic-template/runtime/src/configs/asset_config.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generic-template/runtime/src/configs/asset_config.rs b/generic-template/runtime/src/configs/asset_config.rs index cb83a12a..3b8c1d2c 100644 --- a/generic-template/runtime/src/configs/asset_config.rs +++ b/generic-template/runtime/src/configs/asset_config.rs @@ -181,12 +181,12 @@ pub trait AccountIdAssetIdConversion { fn asset_id_to_account(prefix: &[u8], asset_id: AssetId) -> Account; } +// needs to be 28 bytes due to `data` is 4 bytes const FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 28]; // Instruct how to go from an H256 to an AssetID impl AccountIdAssetIdConversion for Runtime { /// The way to convert an account to assetId is by ensuring that the prefix is 0XFFFFFFFF - /// and by taking the lowest 128 bits as the assetId fn account_to_asset_id(account: AccountId) -> Option<(Vec, AssetId)> { let bytes: [u8; 32] = account.into(); let h256_account: H256 = bytes.into(); @@ -194,6 +194,7 @@ impl AccountIdAssetIdConversion for Runtime { let (prefix_part, id_part) = h256_account.as_fixed_bytes().split_at(28); if prefix_part == FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX { data.copy_from_slice(id_part); + // we use `data` to create a u32 -> data needs to be 4 bytes let asset_id: AssetId = u32::from_be_bytes(data); Some((prefix_part.to_vec(), asset_id)) } else { From a67cd7054842471262e879b48f45c6c6cfe73861 Mon Sep 17 00:00:00 2001 From: Ozgun Ozerk Date: Thu, 31 Oct 2024 09:57:39 +0300 Subject: [PATCH 12/12] toml sort --- evm-template/Cargo.lock | 53 ++++++++++++++++ generic-template/Cargo.lock | 95 ++++++++++++++++++++++++++++- generic-template/Cargo.toml | 8 +-- generic-template/runtime/Cargo.toml | 12 ++-- 4 files changed, 156 insertions(+), 12 deletions(-) diff --git a/evm-template/Cargo.lock b/evm-template/Cargo.lock index 356071a5..3b003755 100644 --- a/evm-template/Cargo.lock +++ b/evm-template/Cargo.lock @@ -3000,6 +3000,7 @@ dependencies = [ "fp-self-contained", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -6056,6 +6057,20 @@ dependencies = [ "hash-db", ] +[[package]] +name = "merkleized-metadata" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f313fcff1d2a4bcaa2deeaa00bf7530d77d5f7bd0467a117dde2e29a75a7a17a" +dependencies = [ + "array-bytes", + "blake3", + "frame-metadata", + "parity-scale-codec", + "scale-decode", + "scale-info", +] + [[package]] name = "merlin" version = "3.0.0" @@ -12153,6 +12168,29 @@ dependencies = [ "sp-arithmetic", ] +[[package]] +name = "scale-bits" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57b1e7f6b65ed1f04e79a85a57d755ad56d76fdf1e9bddcc9ae14f71fcdcf54" +dependencies = [ + "parity-scale-codec", + "scale-type-resolver", +] + +[[package]] +name = "scale-decode" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e98f3262c250d90e700bb802eb704e1f841e03331c2eb815e46516c4edbf5b27" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-bits", + "scale-type-resolver", + "smallvec", +] + [[package]] name = "scale-info" version = "2.11.3" @@ -12179,6 +12217,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scale-type-resolver" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" + [[package]] name = "schannel" version = "0.1.24" @@ -13955,13 +13999,22 @@ name = "substrate-wasm-builder" version = "24.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2407-1#16b0fd09d9e9281c20ee0c1d8b87d011e3e3454e" dependencies = [ + "array-bytes", "build-helper", "cargo_metadata", "console", "filetime", + "frame-metadata", + "merkleized-metadata", + "parity-scale-codec", "parity-wasm", "polkavm-linker", + "sc-executor", + "sp-core", + "sp-io", "sp-maybe-compressed-blob", + "sp-tracing", + "sp-version", "strum 0.26.3", "tempfile", "toml 0.8.19", diff --git a/generic-template/Cargo.lock b/generic-template/Cargo.lock index 231516bb..7065c1b8 100644 --- a/generic-template/Cargo.lock +++ b/generic-template/Cargo.lock @@ -3627,6 +3627,7 @@ dependencies = [ "cumulus-primitives-utility", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -3634,6 +3635,9 @@ dependencies = [ "frame-try-runtime", "hex-literal", "log", + "orml-traits", + "orml-xcm-support", + "orml-xtokens", "pallet-asset-manager", "pallet-assets", "pallet-aura", @@ -5629,6 +5633,20 @@ dependencies = [ "hash-db", ] +[[package]] +name = "merkleized-metadata" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f313fcff1d2a4bcaa2deeaa00bf7530d77d5f7bd0467a117dde2e29a75a7a17a" +dependencies = [ + "array-bytes", + "blake3", + "frame-metadata", + "parity-scale-codec", + "scale-decode", + "scale-info", +] + [[package]] name = "merlin" version = "3.0.0" @@ -6376,7 +6394,7 @@ dependencies = [ [[package]] name = "orml-traits" version = "0.10.0" -source = "git+https://github.com/openzeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" +source = "git+https://github.com/OpenZeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -6396,7 +6414,7 @@ dependencies = [ [[package]] name = "orml-utilities" version = "0.10.0" -source = "git+https://github.com/openzeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" +source = "git+https://github.com/OpenZeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" dependencies = [ "frame-support", "parity-scale-codec", @@ -6408,6 +6426,41 @@ dependencies = [ "sp-std", ] +[[package]] +name = "orml-xcm-support" +version = "0.10.0" +source = "git+https://github.com/OpenZeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" +dependencies = [ + "frame-support", + "orml-traits", + "parity-scale-codec", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", +] + +[[package]] +name = "orml-xtokens" +version = "0.10.0" +source = "git+https://github.com/OpenZeppelin/open-runtime-module-library?branch=polkadot-stable2407-1#aafe9077c9ec61dd8b3a42e899ef8353b2b050c0" +dependencies = [ + "frame-support", + "frame-system", + "log", + "orml-traits", + "orml-xcm-support", + "pallet-xcm", + "parity-scale-codec", + "scale-info", + "serde", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", +] + [[package]] name = "overload" version = "0.1.1" @@ -11499,6 +11552,29 @@ dependencies = [ "sp-arithmetic", ] +[[package]] +name = "scale-bits" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57b1e7f6b65ed1f04e79a85a57d755ad56d76fdf1e9bddcc9ae14f71fcdcf54" +dependencies = [ + "parity-scale-codec", + "scale-type-resolver", +] + +[[package]] +name = "scale-decode" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e98f3262c250d90e700bb802eb704e1f841e03331c2eb815e46516c4edbf5b27" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-bits", + "scale-type-resolver", + "smallvec", +] + [[package]] name = "scale-info" version = "2.11.3" @@ -11525,6 +11601,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scale-type-resolver" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" + [[package]] name = "schannel" version = "0.1.23" @@ -13178,13 +13260,22 @@ name = "substrate-wasm-builder" version = "24.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?tag=polkadot-stable2407-1#16b0fd09d9e9281c20ee0c1d8b87d011e3e3454e" dependencies = [ + "array-bytes", "build-helper", "cargo_metadata", "console", "filetime", + "frame-metadata", + "merkleized-metadata", + "parity-scale-codec", "parity-wasm", "polkavm-linker", + "sc-executor", + "sp-core", + "sp-io", "sp-maybe-compressed-blob", + "sp-tracing", + "sp-version", "strum 0.26.3", "tempfile", "toml 0.8.19", diff --git a/generic-template/Cargo.toml b/generic-template/Cargo.toml index c5191907..304b3a5f 100644 --- a/generic-template/Cargo.toml +++ b/generic-template/Cargo.toml @@ -1,20 +1,20 @@ [workspace] -members = ["node", "runtime", "template-fuzzer"] +members = [ "node", "runtime", "template-fuzzer" ] resolver = "2" [workspace.package] -authors = ["OpenZeppelin"] +authors = [ "OpenZeppelin" ] description = "Generic runtime template for Polkadot Para{chains, cores}" edition = "2021" license = "GPL-3.0-only" repository = "https://github.com/OpenZeppelin/polkadot-runtime-templates" [workspace.dependencies] -clap = { version = "4.5.3", features = ["derive"] } +clap = { version = "4.5.3", features = [ "derive" ] } color-print = "0.3.4" futures = "0.3.30" hex-literal = "0.4.1" -jsonrpsee = { version = "0.23.2", features = ["server"] } +jsonrpsee = { version = "0.23.2", features = [ "server" ] } log = { version = "0.4.21", default-features = false } parity-scale-codec = { version = "3.6.12", default-features = false, features = [ "derive", diff --git a/generic-template/runtime/Cargo.toml b/generic-template/runtime/Cargo.toml index bb72a055..9a12a301 100644 --- a/generic-template/runtime/Cargo.toml +++ b/generic-template/runtime/Cargo.toml @@ -8,13 +8,13 @@ repository = { workspace = true } version = "2.0.0" [package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] +targets = [ "x86_64-unknown-linux-gnu" ] [dependencies] hex-literal = { workspace = true, optional = true } log = { workspace = true } -parity-scale-codec = { workspace = true, features = ["derive"] } -scale-info = { workspace = true, features = ["derive"] } +parity-scale-codec = { workspace = true, features = [ "derive" ] } +scale-info = { workspace = true, features = [ "derive" ] } smallvec = { workspace = true } # Substrate @@ -246,10 +246,10 @@ try-runtime = [ # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging"] +on-chain-release-build = [ "sp-api/disable-logging" ] async-backing = [] -default = ["std"] +default = [ "std" ] -metadata-hash = ["substrate-wasm-builder/metadata-hash"] +metadata-hash = [ "substrate-wasm-builder/metadata-hash" ]