From 1f3f198e56c5651b9067832eb117cf51afb0d357 Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Thu, 21 Nov 2024 14:11:55 +0100 Subject: [PATCH] enable new foreign assets system in moonriver and moonbeam --- runtime/moonbeam/src/xcm_config.rs | 27 ++++++++++++++++++++++----- runtime/moonriver/src/xcm_config.rs | 27 ++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/runtime/moonbeam/src/xcm_config.rs b/runtime/moonbeam/src/xcm_config.rs index 8719c260c3..f512c5e344 100644 --- a/runtime/moonbeam/src/xcm_config.rs +++ b/runtime/moonbeam/src/xcm_config.rs @@ -672,14 +672,31 @@ impl sp_runtime::traits::Convert for AccountIdToH160 { } } +pub struct EvmForeignAssetIdFilter; +impl frame_support::traits::Contains for EvmForeignAssetIdFilter { + fn contains(asset_id: &AssetId) -> bool { + use xcm_primitives::AssetTypeGetter as _; + // We should return true only if the AssetId doesn't exist in AssetManager + AssetManager::get_asset_type(*asset_id).is_none() + } +} + +pub type ForeignAssetManagerOrigin = EitherOfDiverse< + EnsureRoot, + EitherOfDiverse< + pallet_collective::EnsureProportionMoreThan, + governance::custom_origins::FastGeneralAdmin, + >, +>; + impl pallet_moonbeam_foreign_assets::Config for Runtime { type AccountIdToH160 = AccountIdToH160; - type AssetIdFilter = Nothing; + type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; - type ForeignAssetCreatorOrigin = frame_system::EnsureNever; - type ForeignAssetFreezerOrigin = frame_system::EnsureNever; - type ForeignAssetModifierOrigin = frame_system::EnsureNever; - type ForeignAssetUnfreezerOrigin = frame_system::EnsureNever; + type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin; + type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin; + type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin; + type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin; type OnForeignAssetCreated = (); type MaxForeignAssets = ConstU32<256>; type RuntimeEvent = RuntimeEvent; diff --git a/runtime/moonriver/src/xcm_config.rs b/runtime/moonriver/src/xcm_config.rs index 2b77d4226b..3c19e5e83e 100644 --- a/runtime/moonriver/src/xcm_config.rs +++ b/runtime/moonriver/src/xcm_config.rs @@ -685,14 +685,31 @@ impl sp_runtime::traits::Convert for AccountIdToH160 { } } +pub struct EvmForeignAssetIdFilter; +impl frame_support::traits::Contains for EvmForeignAssetIdFilter { + fn contains(asset_id: &AssetId) -> bool { + use xcm_primitives::AssetTypeGetter as _; + // We should return true only if the AssetId doesn't exist in AssetManager + AssetManager::get_asset_type(*asset_id).is_none() + } +} + +pub type ForeignAssetManagerOrigin = EitherOfDiverse< + EnsureRoot, + EitherOfDiverse< + pallet_collective::EnsureProportionMoreThan, + governance::custom_origins::FastGeneralAdmin, + >, +>; + impl pallet_moonbeam_foreign_assets::Config for Runtime { type AccountIdToH160 = AccountIdToH160; - type AssetIdFilter = Nothing; + type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; - type ForeignAssetCreatorOrigin = frame_system::EnsureNever; - type ForeignAssetFreezerOrigin = frame_system::EnsureNever; - type ForeignAssetModifierOrigin = frame_system::EnsureNever; - type ForeignAssetUnfreezerOrigin = frame_system::EnsureNever; + type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin; + type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin; + type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin; + type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin; type OnForeignAssetCreated = (); type MaxForeignAssets = ConstU32<256>; type RuntimeEvent = RuntimeEvent;