diff --git a/bridges/snowbridge/pallets/system/src/lib.rs b/bridges/snowbridge/pallets/system/src/lib.rs index d935bb78579e..3dda000e03f3 100644 --- a/bridges/snowbridge/pallets/system/src/lib.rs +++ b/bridges/snowbridge/pallets/system/src/lib.rs @@ -58,6 +58,7 @@ pub mod weights; pub use weights::*; use frame_support::{ + dispatch::RawOrigin, pallet_prelude::*, traits::{ fungible::{Inspect, Mutate}, @@ -83,7 +84,6 @@ use sp_std::prelude::*; use xcm::prelude::*; use xcm_executor::traits::ConvertLocation; -#[cfg(feature = "runtime-benchmarks")] use frame_support::traits::OriginTrait; pub use pallet::*; @@ -182,6 +182,8 @@ pub mod pallet { #[cfg(feature = "runtime-benchmarks")] type Helper: BenchmarkHelper; + + type RegisterTokenOrigin: EnsureOrigin; } #[pallet::event] @@ -623,18 +625,23 @@ pub mod pallet { location: Box, metadata: AssetMetadata, ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; + T::RegisterTokenOrigin::ensure_origin_or_root(origin.clone())?; + + let pays_fee = match origin.as_system_ref() { + Some(&RawOrigin::Root) => Ok((PaysFee::::No, Pays::No)), + Some(&RawOrigin::Signed(ref who)) => + Ok((PaysFee::::Yes(who.clone()), Pays::Yes)), + _ => Err(BadOrigin), + }?; let location: Location = (*location).try_into().map_err(|_| Error::::UnsupportedLocationVersion)?; - let pays_fee = PaysFee::::No; - - Self::do_register_token(&location, metadata, pays_fee)?; + Self::do_register_token(&location, metadata, pays_fee.0)?; Ok(PostDispatchInfo { actual_weight: Some(T::WeightInfo::register_token()), - pays_fee: Pays::No, + pays_fee: pays_fee.1, }) } } diff --git a/bridges/snowbridge/pallets/system/src/mock.rs b/bridges/snowbridge/pallets/system/src/mock.rs index d8c905449d9a..217b7efda4ee 100644 --- a/bridges/snowbridge/pallets/system/src/mock.rs +++ b/bridges/snowbridge/pallets/system/src/mock.rs @@ -7,6 +7,7 @@ use frame_support::{ weights::IdentityFee, PalletId, }; +use frame_system::EnsureRoot; use sp_core::H256; use xcm_executor::traits::ConvertLocation; @@ -212,6 +213,7 @@ impl crate::Config for Test { type EthereumNetwork = EthereumNetwork; #[cfg(feature = "runtime-benchmarks")] type Helper = (); + type RegisterTokenOrigin = EnsureRoot; } // Build genesis storage according to the mock runtime. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_ethereum_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_ethereum_config.rs index 1e096f19ef80..8422bd83d587 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_ethereum_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_ethereum_config.rs @@ -36,6 +36,7 @@ use crate::xcm_config::RelayNetwork; #[cfg(feature = "runtime-benchmarks")] use benchmark_helpers::DoNothingRouter; use frame_support::{parameter_types, weights::ConstantMultiplier}; +use frame_system::EnsureRoot; use pallet_xcm::EnsureXcm; use sp_runtime::{ traits::{ConstU32, ConstU8, Keccak256}, @@ -190,6 +191,7 @@ impl snowbridge_pallet_system::Config for Runtime { type InboundDeliveryCost = EthereumInboundQueue; type UniversalLocation = UniversalLocation; type EthereumNetwork = EthereumNetwork; + type RegisterTokenOrigin = EnsureRoot; } #[cfg(feature = "runtime-benchmarks")] diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs index fee9f9a2f610..63b5ba8febf4 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs @@ -37,6 +37,7 @@ use crate::xcm_config::RelayNetwork; #[cfg(feature = "runtime-benchmarks")] use benchmark_helpers::DoNothingRouter; use frame_support::{parameter_types, weights::ConstantMultiplier}; +use frame_system::EnsureRoot; use pallet_xcm::EnsureXcm; use sp_runtime::{ traits::{ConstU32, ConstU8, Keccak256}, @@ -190,6 +191,7 @@ impl snowbridge_pallet_system::Config for Runtime { type InboundDeliveryCost = EthereumInboundQueue; type UniversalLocation = UniversalLocation; type EthereumNetwork = EthereumNetwork; + type RegisterTokenOrigin = EnsureRoot; } #[cfg(feature = "runtime-benchmarks")]