From d074bd97e9aba635598234d576e1412b699c9b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCn=20=C3=96zerk?= Date: Mon, 21 Oct 2024 07:59:22 +0300 Subject: [PATCH] use asset hub as reserve (#327) * implemented asset hub as reserve --- evm-template/Cargo.lock | 21 ++++- evm-template/Cargo.toml | 3 + evm-template/runtime/Cargo.toml | 4 + .../runtime/src/configs/xcm_config.rs | 76 ++++++++++++++++--- 4 files changed, 92 insertions(+), 12 deletions(-) diff --git a/evm-template/Cargo.lock b/evm-template/Cargo.lock index 052376f..2480232 100644 --- a/evm-template/Cargo.lock +++ b/evm-template/Cargo.lock @@ -3007,6 +3007,7 @@ dependencies = [ "frame-try-runtime", "hex-literal", "log", + "orml-xcm-support", "pallet-asset-manager", "pallet-assets", "pallet-aura", @@ -6684,7 +6685,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 3.2.0", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 2.0.77", @@ -6861,7 +6862,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", @@ -6880,7 +6881,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", @@ -6891,6 +6892,20 @@ 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 = "overload" version = "0.1.1" diff --git a/evm-template/Cargo.toml b/evm-template/Cargo.toml index 8bb357b..5529907 100644 --- a/evm-template/Cargo.toml +++ b/evm-template/Cargo.toml @@ -159,6 +159,9 @@ pallet-evm-precompile-modexp = { git = "https://github.com/OpenZeppelin/frontier pallet-evm-precompile-sha3fips = { git = "https://github.com/OpenZeppelin/frontier", branch = "polkadot-stable2407-1", default-features = false } pallet-evm-precompile-simple = { git = "https://github.com/OpenZeppelin/frontier", 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 } + # 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 } diff --git a/evm-template/runtime/Cargo.toml b/evm-template/runtime/Cargo.toml index 81c6ec1..da024aa 100644 --- a/evm-template/runtime/Cargo.toml +++ b/evm-template/runtime/Cargo.toml @@ -94,6 +94,10 @@ pallet-evm-precompile-modexp = { workspace = true } pallet-evm-precompile-sha3fips = { workspace = true } pallet-evm-precompile-simple = { workspace = true } +# ORML +orml-xcm-support = { workspace = true } + + # Moonbeam pallet-asset-manager = { workspace = true } xcm-primitives = { workspace = true } diff --git a/evm-template/runtime/src/configs/xcm_config.rs b/evm-template/runtime/src/configs/xcm_config.rs index be9df13..d1d3009 100644 --- a/evm-template/runtime/src/configs/xcm_config.rs +++ b/evm-template/runtime/src/configs/xcm_config.rs @@ -2,27 +2,28 @@ use core::marker::PhantomData; use frame_support::{ parameter_types, - traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, + 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 xcm::latest::prelude::{Assets as XcmAssets, *}; use xcm_builder::{ - AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, Case, ConvertedConcreteId, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, HandleFee, - IsChildSystemParachain, IsConcrete, NativeAsset, NoChecking, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + IsChildSystemParachain, IsConcrete, NoChecking, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountKey20AsNative, + SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, + WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, }; use xcm_executor::{ traits::{FeeReason, JustTry, TransactAsset}, XcmExecutor, }; -use xcm_primitives::AsAssetType; +use xcm_primitives::{AbsoluteAndRelativeReserve, AsAssetType}; use crate::{ configs::{ @@ -35,7 +36,6 @@ use crate::{ }; parameter_types! { - pub const RelayLocation: Location = Location::parent(); pub const RelayNetwork: Option = None; pub AssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); @@ -188,6 +188,46 @@ pub fn deposit_or_burn_fee 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>, +); + parameter_types! { pub TreasuryAccount: AccountId = Treasury::account_id(); } @@ -214,7 +254,7 @@ impl xcm_executor::Config for XcmConfig { /// Please, keep these two configs (`IsReserve` and `IsTeleporter`) mutually exclusive. /// The IsReserve type must be set to specify which pair we trust to deposit reserve assets on our chain. We can also use the unit type () to block ReserveAssetDeposited instructions. /// The IsTeleporter type must be set to specify which pair we trust to teleport assets to our chain. We can also use the unit type () to block ReceiveTeleportedAssets instruction. - type IsReserve = NativeAsset; + type IsReserve = Reserves; type IsTeleporter = (); type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type MessageExporter = (); @@ -314,3 +354,21 @@ 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() + }; +}