diff --git a/evm-template/Cargo.lock b/evm-template/Cargo.lock index 1558808..356071a 100644 --- a/evm-template/Cargo.lock +++ b/evm-template/Cargo.lock @@ -3007,7 +3007,9 @@ dependencies = [ "frame-try-runtime", "hex-literal", "log", + "orml-traits", "orml-xcm-support", + "orml-xtokens", "pallet-asset-manager", "pallet-assets", "pallet-aura", @@ -3016,6 +3018,7 @@ dependencies = [ "pallet-base-fee", "pallet-collator-selection", "pallet-conviction-voting", + "pallet-erc20-xcm-bridge", "pallet-ethereum", "pallet-evm", "pallet-evm-chain-id", @@ -3037,6 +3040,7 @@ dependencies = [ "pallet-utility", "pallet-whitelist", "pallet-xcm", + "pallet-xcm-weight-trader", "parachains-common", "parity-scale-codec", "polkadot-parachain-primitives", @@ -6871,6 +6875,7 @@ dependencies = [ "parity-scale-codec", "paste", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -6886,6 +6891,7 @@ dependencies = [ "frame-support", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -6906,6 +6912,27 @@ dependencies = [ "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" @@ -6933,7 +6960,7 @@ dependencies = [ [[package]] name = "pallet-asset-manager" version = "0.1.0" -source = "git+https://github.com/OpenZeppelin/moonbeam.git?branch=polkadot-stable2407-1#3ed33a712c6968af7a33d970ec4300293c5345b9" +source = "git+https://github.com/OpenZeppelin/moonbeam.git?branch=polkadot-stable2407-1#fab6e72fbaaeaa065ad983556d09d4c0e8755dfa" dependencies = [ "frame-benchmarking", "frame-support", @@ -7343,6 +7370,28 @@ 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-ethereum" version = "4.0.0-dev" @@ -8134,6 +8183,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" @@ -9941,7 +10011,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", @@ -15781,7 +15851,7 @@ dependencies = [ [[package]] name = "xcm-primitives" version = "0.1.1" -source = "git+https://github.com/OpenZeppelin/moonbeam.git?branch=polkadot-stable2407-1#3ed33a712c6968af7a33d970ec4300293c5345b9" +source = "git+https://github.com/OpenZeppelin/moonbeam.git?branch=polkadot-stable2407-1#fab6e72fbaaeaa065ad983556d09d4c0e8755dfa" dependencies = [ "cumulus-primitives-core", "ethereum", diff --git a/evm-template/Cargo.toml b/evm-template/Cargo.toml index 4b24f95..87298d8 100644 --- a/evm-template/Cargo.toml +++ b/evm-template/Cargo.toml @@ -161,12 +161,17 @@ pallet-evm-precompile-sha3fips = { git = "https://github.com/OpenZeppelin/fronti pallet-evm-precompile-simple = { git = "https://github.com/OpenZeppelin/frontier", 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 } # Moonbeam pallet-asset-manager = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch = "polkadot-stable2407-1", default-features = false } +pallet-erc20-xcm-bridge = { 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 } + # Fuzzer substrate-runtimes-fuzzers = { git = "https://github.com/srlabs/substrate-runtime-fuzzer.git", default-features = false, tag = "polkadot-v1.12.0" } ziggy = { version = "0.8", default-features = false } diff --git a/evm-template/runtime/Cargo.toml b/evm-template/runtime/Cargo.toml index cf020d7..19a4e7a 100644 --- a/evm-template/runtime/Cargo.toml +++ b/evm-template/runtime/Cargo.toml @@ -96,13 +96,17 @@ pallet-evm-precompile-sha3fips = { workspace = true } pallet-evm-precompile-simple = { workspace = true } # ORML +orml-traits = { workspace = true } orml-xcm-support = { workspace = true } - +orml-xtokens = { workspace = true } # Moonbeam pallet-asset-manager = { workspace = true } +pallet-erc20-xcm-bridge = { workspace = true } +pallet-xcm-weight-trader = { workspace = true } xcm-primitives = { workspace = true } + [dev-dependencies] sp-io = { workspace = true } @@ -136,6 +140,7 @@ std = [ "frame-system/std", "frame-try-runtime?/std", "log/std", + "orml-xtokens/std", "pallet-asset-manager/std", "pallet-assets/std", "pallet-aura/std", @@ -144,6 +149,7 @@ std = [ "pallet-base-fee/std", "pallet-collator-selection/std", "pallet-conviction-voting/std", + "pallet-erc20-xcm-bridge/std", "pallet-ethereum/std", "pallet-evm-chain-id/std", "pallet-evm/std", @@ -161,6 +167,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", @@ -217,6 +224,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", @@ -236,6 +244,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", @@ -244,6 +253,7 @@ try-runtime = [ "pallet-base-fee/try-runtime", "pallet-collator-selection/try-runtime", "pallet-conviction-voting/try-runtime", + "pallet-erc20-xcm-bridge/try-runtime", "pallet-ethereum/try-runtime", "pallet-evm-chain-id/try-runtime", "pallet-message-queue/try-runtime", @@ -260,6 +270,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", diff --git a/evm-template/runtime/src/configs/asset_config.rs b/evm-template/runtime/src/configs/asset_config.rs index b590eff..6404bc7 100644 --- a/evm-template/runtime/src/configs/asset_config.rs +++ b/evm-template/runtime/src/configs/asset_config.rs @@ -4,7 +4,7 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSigned}; use parity_scale_codec::{Compact, Decode, Encode}; use scale_info::TypeInfo; -use sp_core::H256; +use sp_core::{H160, H256}; use sp_runtime::traits::Hash as THash; use sp_std::{ convert::{From, Into}, @@ -184,3 +184,41 @@ impl pallet_asset_manager::Config for Runtime { /// Rerun benchmarks if you are making changes to runtime configuration. type WeightInfo = weights::pallet_asset_manager::WeightInfo; } + +/// This trait ensure we can convert AccountIds to AssetIds. +pub trait AccountIdAssetIdConversion { + // Get assetId and prefix from account + fn account_to_asset_id(account: Account) -> Option<(Vec, AssetId)>; + + // Get AccountId from AssetId and prefix + fn asset_id_to_account(prefix: &[u8], asset_id: AssetId) -> Account; +} + +const FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; + +// Instruct how to go from an H160 to an AssetID +// We just take the lowest 128 bits +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 h160_account: H160 = account.into(); + let mut data = [0u8; 16]; + let (prefix_part, id_part) = h160_account.as_fixed_bytes().split_at(4); + if prefix_part == FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX { + data.copy_from_slice(id_part); + let asset_id: AssetId = u128::from_be_bytes(data); + Some((prefix_part.to_vec(), asset_id)) + } else { + None + } + } + + // The opposite conversion + fn asset_id_to_account(prefix: &[u8], asset_id: AssetId) -> AccountId { + let mut data = [0u8; 20]; + data[0..4].copy_from_slice(prefix); + data[4..20].copy_from_slice(&asset_id.to_be_bytes()); + AccountId::from(data) + } +} diff --git a/evm-template/runtime/src/configs/xcm_config.rs b/evm-template/runtime/src/configs/xcm_config.rs index d1d3009..b0866d0 100644 --- a/evm-template/runtime/src/configs/xcm_config.rs +++ b/evm-template/runtime/src/configs/xcm_config.rs @@ -6,9 +6,13 @@ use frame_support::{ weights::Weight, }; use frame_system::EnsureRoot; +use orml_traits::{location::Reserve, 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 scale_info::TypeInfo; +use sp_core::H160; use xcm::latest::prelude::{Assets as XcmAssets, *}; use xcm_builder::{ AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, Case, @@ -16,23 +20,22 @@ use xcm_builder::{ FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, HandleFee, IsChildSystemParachain, IsConcrete, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountKey20AsNative, - SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, WithComputedOrigin, + WithUniqueTopic, XcmFeeManagerFromComponents, }; use xcm_executor::{ - traits::{FeeReason, JustTry, TransactAsset}, + traits::{ConvertLocation, FeeReason, JustTry, TransactAsset}, XcmExecutor, }; -use xcm_primitives::{AbsoluteAndRelativeReserve, AsAssetType}; +use xcm_primitives::{AbsoluteAndRelativeReserve, AccountIdToLocation, AsAssetType}; use crate::{ configs::{ - AssetType, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, - XcmpQueue, + AssetType, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue, }, - types::{AccountId, AssetId, Balance, XcmFeesToAccount}, - weights, AllPalletsWithSystem, AssetManager, Assets, Balances, ParachainInfo, PolkadotXcm, - Treasury, + types::{AccountId, AssetId, Balance}, + weights, AllPalletsWithSystem, AssetManager, Assets, Balances, Erc20XcmBridge, ParachainInfo, + PolkadotXcm, Treasury, }; parameter_types! { @@ -42,6 +45,16 @@ parameter_types! { pub BalancesPalletLocation: Location = 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` @@ -232,6 +245,8 @@ parameter_types! { pub TreasuryAccount: AccountId = Treasury::account_id(); } +pub type XcmWeigher = FixedWeightBounds; + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type Aliasers = Nothing; @@ -240,7 +255,7 @@ impl xcm_executor::Config for XcmConfig { type AssetLocker = (); // How to withdraw and deposit an asset. type AssetTransactor = AssetTransactors; - type AssetTrap = PolkadotXcm; + type AssetTrap = pallet_erc20_xcm_bridge::AssetTrapWrapper; type Barrier = Barrier; type CallDispatcher = RuntimeCall; /// When changing this config, keep in mind, that you should collect fees. @@ -264,15 +279,12 @@ impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; type SafeCallFilter = Everything; type SubscriptionService = PolkadotXcm; - type Trader = ( - UsingComponents, - xcm_primitives::FirstAssetTrader, - ); + 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; } @@ -334,7 +346,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")] @@ -372,3 +384,206 @@ 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 }, +} + +// 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(); + 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) + } +} + +parameter_types! { + // This is the relative view of erc20 assets. + // Identified by this prefix + AccountKey20(contractAddress) + // We use the RELATIVE multilocation + pub Erc20XcmBridgePalletLocation: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; + + // To be able to support almost all erc20 implementations, + // we provide a sufficiently high gas limit. + pub Erc20XcmBridgeTransferGasLimit: u64 = 800_000; +} + +impl pallet_erc20_xcm_bridge::Config for Runtime { + type AccountIdConverter = LocationToH160; + type Erc20MultilocationPrefix = Erc20XcmBridgePalletLocation; + type Erc20TransferGasLimit = Erc20XcmBridgeTransferGasLimit; + type EvmRunner = pallet_evm::runner::stack::Runner; +} + +/// 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; + type BaseXcmWeight = BaseXcmWeight; + type CurrencyId = CurrencyId; + type CurrencyIdConvert = CurrencyIdToLocation>; + type LocationsFilter = Everything; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type RateLimiter = (); + type RateLimiterId = (); + type ReserveProvider = ReserveProviders; + 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/evm-template/runtime/src/lib.rs b/evm-template/runtime/src/lib.rs index 054e689..4058eb9 100644 --- a/evm-template/runtime/src/lib.rs +++ b/evm-template/runtime/src/lib.rs @@ -262,6 +262,10 @@ 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)] @@ -272,6 +276,8 @@ mod runtime { pub type BaseFee = pallet_base_fee; #[runtime::pallet_index(43)] pub type EVMChainId = pallet_evm_chain_id; + #[runtime::pallet_index(44)] + pub type Erc20XcmBridge = pallet_erc20_xcm_bridge; } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/evm-template/runtime/src/types.rs b/evm-template/runtime/src/types.rs index 1317239..5115224 100644 --- a/evm-template/runtime/src/types.rs +++ b/evm-template/runtime/src/types.rs @@ -11,19 +11,16 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentifyAccount, Verify}, }; use xcm::VersionedLocation; -use xcm_builder::{ConvertedConcreteId, PayOverXcm}; -use xcm_executor::traits::JustTry; -use xcm_primitives::AsAssetType; +use xcm_builder::PayOverXcm; use crate::{ configs::{xcm_config, TreasuryInteriorLocation}, constants::HOURS, - AssetManager, Assets, }; pub use crate::{ configs::{ - xcm_config::RelayLocation, AssetType, FeeAssetId, StakingAdminBodyId, - ToSiblingBaseDeliveryFee, TransactionByteFee, TreasuryAccount, + xcm_config::RelayLocation, FeeAssetId, StakingAdminBodyId, ToSiblingBaseDeliveryFee, + TransactionByteFee, }, constants::{ BLOCK_PROCESSING_VELOCITY, RELAY_CHAIN_SLOT_DURATION_MILLIS, UNINCLUDED_SEGMENT_CAPACITY, @@ -111,23 +108,6 @@ pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureXcm>, >; -/// This is the struct that will handle the revenue from xcm fees -/// We do not burn anything because we want to mimic exactly what -/// the sovereign account has -pub type XcmFeesToAccount = xcm_primitives::XcmFeesToAccount< - Assets, - ( - ConvertedConcreteId< - AssetId, - Balance, - AsAssetType, - JustTry, - >, - ), - AccountId, - TreasuryAccount, ->; - /// These aliases are describing the Beneficiary and AssetKind for the Treasury pallet pub type Beneficiary = VersionedLocation; pub type AssetKind = VersionedLocatableAsset; diff --git a/evm-template/runtime/src/weights/mod.rs b/evm-template/runtime/src/weights/mod.rs index eadce68..44a6f49 100644 --- a/evm-template/runtime/src/weights/mod.rs +++ b/evm-template/runtime/src/weights/mod.rs @@ -40,6 +40,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; pub use block_weights::constants::BlockExecutionWeight; diff --git a/evm-template/runtime/src/weights/pallet_asset_manager.rs b/evm-template/runtime/src/weights/pallet_asset_manager.rs index 4f1a97d..e012403 100644 --- a/evm-template/runtime/src/weights/pallet_asset_manager.rs +++ b/evm-template/runtime/src/weights/pallet_asset_manager.rs @@ -50,26 +50,6 @@ impl pallet_asset_manager::WeightInfo for WeightInfo .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(4)) } - /// Storage: `AssetManager::AssetTypeId` (r:1 w:0) - /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) - /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1) - /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `x` is `[5, 100]`. - fn set_asset_units_per_second(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `611 + x * (9 ±0)` - // Estimated: `4000 + x * (10 ±0)` - // Minimum execution time: 24_022_000 picoseconds. - Weight::from_parts(24_974_937, 0) - .saturating_add(Weight::from_parts(0, 4000)) - // Standard Error: 3_934 - .saturating_add(Weight::from_parts(658_977, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into())) - } /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `AssetManager::AssetIdType` (r:1 w:1) @@ -79,36 +59,15 @@ impl pallet_asset_manager::WeightInfo for WeightInfo /// Storage: `AssetManager::AssetTypeId` (r:0 w:2) /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `x` is `[5, 100]`. - fn change_existing_asset_type(x: u32, ) -> Weight { + fn change_existing_asset_type() -> Weight { // Proof Size summary in bytes: - // Measured: `926 + x * (13 ±0)` - // Estimated: `4309 + x * (15 ±0)` - // Minimum execution time: 37_311_000 picoseconds. - Weight::from_parts(38_598_190, 0) - .saturating_add(Weight::from_parts(0, 4309)) - // Standard Error: 3_797 - .saturating_add(Weight::from_parts(702_853, 0).saturating_mul(x.into())) + // Measured: `82` + // Estimated: `3639` + // Minimum execution time: 39_040_000 picoseconds. + Weight::from_parts(39_649_000, 0) + .saturating_add(Weight::from_parts(0, 3639)) .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(6)) - .saturating_add(Weight::from_parts(0, 15).saturating_mul(x.into())) - } - /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) - /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1) - /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `x` is `[5, 100]`. - fn remove_supported_asset(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `196 + x * (5 ±0)` - // Estimated: `1678 + x * (5 ±0)` - // Minimum execution time: 19_119_000 picoseconds. - Weight::from_parts(19_212_212, 0) - .saturating_add(Weight::from_parts(0, 1678)) - // Standard Error: 3_489 - .saturating_add(Weight::from_parts(562_250, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 5).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -119,17 +78,14 @@ impl pallet_asset_manager::WeightInfo for WeightInfo /// Storage: `AssetManager::AssetTypeId` (r:0 w:1) /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `x` is `[5, 100]`. - fn remove_existing_asset_type(x: u32, ) -> Weight { + fn remove_existing_asset_type() -> Weight { // Proof Size summary in bytes: - // Measured: `482 + x * (10 ±0)` - // Estimated: `3955 + x * (10 ±0)` - // Minimum execution time: 26_737_000 picoseconds. - Weight::from_parts(27_944_215, 0) - .saturating_add(Weight::from_parts(0, 3955)) - // Standard Error: 4_073 - .saturating_add(Weight::from_parts(587_318, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2)) + // Measured: `82` + // Estimated: `3639` + // Minimum execution time: 39_040_000 picoseconds. + Weight::from_parts(39_649_000, 0) + .saturating_add(Weight::from_parts(0, 3639)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(4)) - .saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into())) } } diff --git a/evm-template/runtime/src/weights/pallet_xcm_weight_trader.rs b/evm-template/runtime/src/weights/pallet_xcm_weight_trader.rs new file mode 100644 index 0000000..93d88a6 --- /dev/null +++ b/evm-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)) + } +}