Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 25ed2d9

Browse files
add foreign assets pallet
1 parent 52bcb07 commit 25ed2d9

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/parachains/runtimes/testing/penpal/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default-
7575
pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false }
7676
parachain-info = { package = "staging-parachain-info", path = "../../../pallets/parachain-info", default-features = false }
7777
parachains-common = { path = "../../../common", default-features = false }
78+
assets-common = { path = "../../assets/common", default-features = false }
7879

7980
[features]
8081
default = [ "std" ]
8182
std = [
83+
"assets-common/std",
8284
"codec/std",
8385
"cumulus-pallet-aura-ext/std",
8486
"cumulus-pallet-dmp-queue/std",
@@ -135,6 +137,7 @@ std = [
135137
]
136138

137139
runtime-benchmarks = [
140+
"assets-common/runtime-benchmarks",
138141
"cumulus-pallet-dmp-queue/runtime-benchmarks",
139142
"cumulus-pallet-parachain-system/runtime-benchmarks",
140143
"cumulus-pallet-session-benchmarking/runtime-benchmarks",

cumulus/parachains/runtimes/testing/penpal/src/lib.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
3232
mod weights;
3333
pub mod xcm_config;
3434

35+
use assets_common::{
36+
foreign_creators::ForeignCreators,
37+
matching::FromSiblingParachain,
38+
MultiLocationForAssetId,
39+
};
3540
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
3641
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
3742
use frame_support::{
@@ -70,7 +75,7 @@ use sp_std::prelude::*;
7075
#[cfg(feature = "std")]
7176
use sp_version::NativeVersion;
7277
use sp_version::RuntimeVersion;
73-
use xcm_config::{AssetsToBlockAuthor, XcmOriginToTransactDispatchOrigin};
78+
use xcm_config::{AssetsToBlockAuthor, ForeignCreatorsSovereignAccountOf, XcmOriginToTransactDispatchOrigin};
7479

7580
#[cfg(any(feature = "std", test))]
7681
pub use sp_runtime::BuildStorage;
@@ -457,6 +462,49 @@ impl pallet_assets::Config<pallet_assets::Instance1> for Runtime {
457462
type BenchmarkHelper = ();
458463
}
459464

465+
466+
parameter_types! {
467+
// we just reuse the same deposits
468+
pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get();
469+
pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get();
470+
pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get();
471+
pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get();
472+
pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get();
473+
pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get();
474+
}
475+
476+
/// We allow root to execute privileged asset operations.
477+
pub type AssetsForceOrigin = EnsureRoot<AccountId>;
478+
479+
/// Another pallet assets instance to store foreign assets from bridgehub.
480+
pub type ForeignAssetsInstance = pallet_assets::Instance2;
481+
impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
482+
type RuntimeEvent = RuntimeEvent;
483+
type Balance = Balance;
484+
type AssetId = MultiLocationForAssetId;
485+
type AssetIdParameter = MultiLocationForAssetId;
486+
type Currency = Balances;
487+
type CreateOrigin = ForeignCreators<
488+
(FromSiblingParachain<parachain_info::Pallet<Runtime>>,),
489+
ForeignCreatorsSovereignAccountOf,
490+
AccountId,
491+
>;
492+
type ForceOrigin = AssetsForceOrigin;
493+
type AssetDeposit = ForeignAssetsAssetDeposit;
494+
type MetadataDepositBase = ForeignAssetsMetadataDepositBase;
495+
type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
496+
type ApprovalDeposit = ForeignAssetsApprovalDeposit;
497+
type StringLimit = ForeignAssetsAssetsStringLimit;
498+
type Freezer = ();
499+
type Extra = ();
500+
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
501+
type CallbackHandle = ();
502+
type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit;
503+
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
504+
#[cfg(feature = "runtime-benchmarks")]
505+
type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
506+
}
507+
460508
parameter_types! {
461509
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
462510
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
@@ -625,6 +673,7 @@ construct_runtime!(
625673

626674
// The main stage.
627675
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
676+
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>} = 51,
628677

629678
Sudo: pallet_sudo::{Pallet, Call, Storage, Event<T>, Config<T>} = 255,
630679
}

cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ pub type XcmRouter = WithUniqueTopic<(
293293
XcmpQueue,
294294
)>;
295295

296+
// TODO(alistair): Only assethub should be able to create.
297+
pub type ForeignCreatorsSovereignAccountOf = (
298+
SiblingParachainConvertsVia<Sibling, AccountId>,
299+
AccountId32Aliases<RelayNetwork, AccountId>,
300+
ParentIsPreset<AccountId>,
301+
);
302+
296303
impl pallet_xcm::Config for Runtime {
297304
type RuntimeEvent = RuntimeEvent;
298305
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;

0 commit comments

Comments
 (0)