diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index f5e1d77e75..4566ef9d1e 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -107,7 +107,7 @@ pub enum AssetStatus { #[pallet] pub mod pallet { use super::*; - use frame_support::traits::{Currency, ReservableCurrency}; + use frame_support::traits::{Currency, EnsureOriginWithArg, ReservableCurrency}; use pallet_evm::{GasWeightMapping, Runner}; use sp_runtime::traits::{AccountIdConversion, AtLeast32BitUnsigned, Convert}; use xcm_executor::traits::ConvertLocation; @@ -133,17 +133,17 @@ pub mod pallet { type EvmRunner: Runner; /// Origin that is allowed to create a new foreign assets - type ForeignAssetCreatorOrigin: EnsureOrigin; + type ForeignAssetCreatorOrigin: EnsureOriginWithArg; /// Origin that is allowed to freeze all tokens of a foreign asset - type ForeignAssetFreezerOrigin: EnsureOrigin; + type ForeignAssetFreezerOrigin: EnsureOriginWithArg; /// Origin that is allowed to modify asset information for foreign assets - type ForeignAssetModifierOrigin: EnsureOrigin; + type ForeignAssetModifierOrigin: EnsureOriginWithArg; /// Origin that is allowed to unfreeze all tokens of a foreign asset that was previously /// frozen - type ForeignAssetUnfreezerOrigin: EnsureOrigin; + type ForeignAssetUnfreezerOrigin: EnsureOriginWithArg; /// Hook to be called when new foreign asset is registered. type OnForeignAssetCreated: ForeignAssetCreatedHook; @@ -410,7 +410,7 @@ pub mod pallet { symbol: BoundedVec>, name: BoundedVec>, ) -> DispatchResult { - T::ForeignAssetCreatorOrigin::ensure_origin(origin.clone())?; + T::ForeignAssetCreatorOrigin::ensure_origin(origin.clone(), &xcm_location)?; // Ensure such an assetId does not exist ensure!( @@ -478,7 +478,8 @@ pub mod pallet { asset_id: AssetId, new_xcm_location: Location, ) -> DispatchResult { - T::ForeignAssetModifierOrigin::ensure_origin(origin)?; + // Ensures that the origin is an XCM location that contains the asset + T::ForeignAssetModifierOrigin::ensure_origin(origin, &new_xcm_location)?; let previous_location = AssetsById::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; @@ -511,11 +512,15 @@ pub mod pallet { asset_id: AssetId, allow_xcm_deposit: bool, ) -> DispatchResult { - T::ForeignAssetFreezerOrigin::ensure_origin(origin)?; + ensure_signed(origin.clone())?; let xcm_location = AssetsById::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + // Ensures that the origin is an XCM location that owns the asset + // represented by the assets xcm location + T::ForeignAssetFreezerOrigin::ensure_origin(origin, &xcm_location)?; + let (_asset_id, asset_status) = AssetsByLocation::::get(&xcm_location) .ok_or(Error::::CorruptedStorageOrphanLocation)?; @@ -545,10 +550,12 @@ pub mod pallet { #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::unfreeze_foreign_asset())] pub fn unfreeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { - T::ForeignAssetUnfreezerOrigin::ensure_origin(origin)?; + ensure_signed(origin.clone())?; let xcm_location = AssetsById::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + // Ensures that the origin is an XCM location that contains the asset + T::ForeignAssetUnfreezerOrigin::ensure_origin(origin, &xcm_location)?; let (_asset_id, asset_status) = AssetsByLocation::::get(&xcm_location) .ok_or(Error::::CorruptedStorageOrphanLocation)?; diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 5dc0f08a5f..a6fd8dc22e 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -36,7 +36,7 @@ use frame_support::{ traits::{EitherOfDiverse, Everything, Nothing, PalletInfoAccess, TransformOrigin}, }; -use frame_system::{EnsureRoot, EnsureSigned, RawOrigin}; +use frame_system::{EnsureRoot, RawOrigin}; use sp_core::{ConstU32, H160, H256}; use sp_weights::Weight; use xcm_builder::{ @@ -67,14 +67,14 @@ use xcm_primitives::{ use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; +use crate::foreign_origin::ForeignAssetOwnerOrigin; +use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; use sp_core::Get; use sp_std::{ convert::{From, Into, TryFrom}, prelude::*, }; -use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; - parameter_types! { // The network Id of the relay pub const RelayNetwork: NetworkId = NetworkId::Westend; @@ -98,8 +98,9 @@ parameter_types! { } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used -/// when determining ownership of accounts for asset transacting and when attempting to use XCM -/// `Transact` in order to determine the dispatch Origin. +/// when determining ownership of accounts for asset transacting, when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin, and when validating foreign assets +/// creation and ownership through the moonbeam_foreign_assets pallet. pub type LocationToAccountId = ( // The parent (Relay-chain) origin converts to the default `AccountId`. ParentIsPreset, @@ -702,19 +703,14 @@ parameter_types! { runtime_params::dynamic_params::xcm_config::ForeignAssetCreationDeposit::get(); } -pub type ForeignAssetManagerOrigin = EitherOfDiverse< - EnsureRoot, - EitherOfDiverse< - pallet_collective::EnsureProportionMoreThan, - governance::custom_origins::FastGeneralAdmin, - >, ->; +pub type ForeignAssetManagerOrigin = + EitherOfDiverse, ForeignAssetOwnerOrigin>; impl pallet_moonbeam_foreign_assets::Config for Runtime { type AccountIdToH160 = AccountIdToH160; type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; - type ForeignAssetCreatorOrigin = EnsureSigned; + type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin; type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin; type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin; type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin; diff --git a/runtime/moonbeam/src/xcm_config.rs b/runtime/moonbeam/src/xcm_config.rs index eec71dfd24..b9c5641481 100644 --- a/runtime/moonbeam/src/xcm_config.rs +++ b/runtime/moonbeam/src/xcm_config.rs @@ -66,6 +66,7 @@ use xcm_primitives::{ use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; +use crate::foreign_origin::ForeignAssetOwnerOrigin; use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; use sp_core::Get; use sp_std::{ @@ -680,13 +681,8 @@ impl frame_support::traits::Contains for EvmForeignAssetIdFilter { } } -pub type ForeignAssetManagerOrigin = EitherOfDiverse< - EnsureRoot, - EitherOfDiverse< - pallet_collective::EnsureProportionMoreThan, - governance::custom_origins::FastGeneralAdmin, - >, ->; +pub type ForeignAssetManagerOrigin = + EitherOfDiverse, ForeignAssetOwnerOrigin>; parameter_types! { /// Balance in the native currency that will be reserved from the user diff --git a/runtime/moonriver/src/xcm_config.rs b/runtime/moonriver/src/xcm_config.rs index d5d3eaad7b..502799a8b2 100644 --- a/runtime/moonriver/src/xcm_config.rs +++ b/runtime/moonriver/src/xcm_config.rs @@ -36,7 +36,7 @@ use sp_runtime::{ }; use sp_weights::Weight; -use frame_system::{EnsureRoot, EnsureSigned, RawOrigin}; +use frame_system::{EnsureRoot, RawOrigin}; use sp_core::{ConstU32, H160, H256}; use xcm_builder::{ @@ -66,6 +66,7 @@ use xcm_primitives::{ use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; +use crate::foreign_origin::ForeignAssetOwnerOrigin; use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; use sp_core::Get; use sp_std::{ @@ -700,19 +701,14 @@ parameter_types! { runtime_params::dynamic_params::xcm_config::ForeignAssetCreationDeposit::get(); } -pub type ForeignAssetManagerOrigin = EitherOfDiverse< - EnsureRoot, - EitherOfDiverse< - pallet_collective::EnsureProportionMoreThan, - governance::custom_origins::FastGeneralAdmin, - >, ->; +pub type ForeignAssetManagerOrigin = + EitherOfDiverse, ForeignAssetOwnerOrigin>; impl pallet_moonbeam_foreign_assets::Config for Runtime { type AccountIdToH160 = AccountIdToH160; type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; - type ForeignAssetCreatorOrigin = EnsureSigned; + type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin; type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin; type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin; type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin;