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", "frame-try-runtime",
"hex-literal", "hex-literal",
"log", "log",
"orml-xcm-support",
"pallet-asset-manager", "pallet-asset-manager",
"pallet-assets", "pallet-assets",
"pallet-aura", "pallet-aura",
@@ -6684,7 +6685,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
dependencies = [ dependencies = [
"proc-macro-crate 3.2.0", "proc-macro-crate 1.1.3",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.77", "syn 2.0.77",
@@ -6861,7 +6862,7 @@ dependencies = [
[[package]] [[package]]
name = "orml-traits" name = "orml-traits"
version = "0.10.0" 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 = [ dependencies = [
"frame-support", "frame-support",
"impl-trait-for-tuples", "impl-trait-for-tuples",
@@ -6880,7 +6881,7 @@ dependencies = [
[[package]] [[package]]
name = "orml-utilities" name = "orml-utilities"
version = "0.10.0" 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 = [ dependencies = [
"frame-support", "frame-support",
"parity-scale-codec", "parity-scale-codec",
@@ -6891,6 +6892,20 @@ dependencies = [
"sp-std", "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]] [[package]]
name = "overload" name = "overload"
version = "0.1.1" 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-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 } 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 # Moonbeam
pallet-asset-manager = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch = "polkadot-stable2407-1", default-features = false } 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 } 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-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true } pallet-evm-precompile-simple = { workspace = true }
# ORML
orml-xcm-support = { workspace = true }
# Moonbeam # Moonbeam
pallet-asset-manager = { workspace = true } pallet-asset-manager = { workspace = true }
xcm-primitives = { workspace = true } xcm-primitives = { workspace = true }
+67 -9
View File
@@ -2,27 +2,28 @@ use core::marker::PhantomData;
use frame_support::{ use frame_support::{
parameter_types, parameter_types,
traits::{ConstU32, Contains, Everything, Nothing, PalletInfoAccess}, traits::{ConstU32, Contains, ContainsPair, Everything, Nothing, PalletInfoAccess},
weights::Weight, weights::Weight,
}; };
use frame_system::EnsureRoot; use frame_system::EnsureRoot;
use orml_xcm_support::MultiNativeAsset;
use pallet_xcm::XcmPassthrough; use pallet_xcm::XcmPassthrough;
use polkadot_parachain_primitives::primitives::{self, Sibling}; use polkadot_parachain_primitives::primitives::{self, Sibling};
use xcm::latest::prelude::{Assets as XcmAssets, *}; use xcm::latest::prelude::{Assets as XcmAssets, *};
use xcm_builder::{ use xcm_builder::{
AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, Case,
ConvertedConcreteId, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, ConvertedConcreteId, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, HandleFee, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, HandleFee,
IsChildSystemParachain, IsConcrete, NativeAsset, NoChecking, ParentIsPreset, IsChildSystemParachain, IsConcrete, NoChecking, ParentIsPreset, RelayChainAsNative,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountKey20AsNative,
SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
}; };
use xcm_executor::{ use xcm_executor::{
traits::{FeeReason, JustTry, TransactAsset}, traits::{FeeReason, JustTry, TransactAsset},
XcmExecutor, XcmExecutor,
}; };
use xcm_primitives::AsAssetType; use xcm_primitives::{AbsoluteAndRelativeReserve, AsAssetType};
use crate::{ use crate::{
configs::{ configs::{
@@ -35,7 +36,6 @@ use crate::{
}; };
parameter_types! { parameter_types! {
pub const RelayLocation: Location = Location::parent();
pub const RelayNetwork: Option<NetworkId> = None; pub const RelayNetwork: Option<NetworkId> = None;
pub AssetsPalletLocation: Location = pub AssetsPalletLocation: Location =
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into(); 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! { parameter_types! {
pub TreasuryAccount: AccountId = Treasury::account_id(); 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. /// 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 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. /// 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 IsTeleporter = ();
type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type MessageExporter = (); type MessageExporter = ();
@@ -314,3 +354,21 @@ impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>; 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()
};
}