use asset hub as reserve (#327)

* implemented asset hub as reserve
This commit is contained in:
Özgün Özerk
2024-10-21 07:59:22 +03:00
committed by GitHub
parent 7d383119a3
commit d074bd97e9
4 changed files with 92 additions and 12 deletions
+18 -3
View File
@@ -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"
+3
View File
@@ -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 }
+4
View File
@@ -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 }
+67 -9
View File
@@ -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<NetworkId> = None;
pub AssetsPalletLocation: Location =
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
@@ -188,6 +188,46 @@ pub fn deposit_or_burn_fee<AssetTransactor: TransactAsset, AccountId: Clone + In
}
}
/// Matches foreign assets from a given origin.
/// Foreign assets are assets bridged from other consensus systems. i.e parents > 1.
pub struct IsBridgedConcreteAssetFrom<Origin>(PhantomData<Origin>);
impl<Origin> ContainsPair<Asset, Location> for IsBridgedConcreteAssetFrom<Origin>
where
Origin: Get<Location>,
{
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<AssetHubLocation>,
// Relaychain (DOT) from Asset Hub
Case<RelayChainNativeAssetFromAssetHub>,
// Assets which the reserve is the same as the origin.
MultiNativeAsset<AbsoluteAndRelativeReserve<SelfLocationAbsolute>>,
);
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 <MultiAsset, MultiLocation> 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 <MultiAsset, MultiLocation> 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<XcmConfig>;
}
// 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()
};
}