add second instance

This commit is contained in:
joepetrowski
2022-11-17 08:41:37 +01:00
parent aa67a43c97
commit 9ab1739304
2 changed files with 64 additions and 4 deletions
+31 -3
View File
@@ -63,7 +63,9 @@ use parachains_common::{
opaque, AccountId, AssetId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature,
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};
use xcm_config::{
ForeignCreators, MultiLocationForAssetId, XcmConfig, XcmOriginToTransactDispatchOrigin,
};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
@@ -244,6 +246,27 @@ impl pallet_assets::Config<TrustBackedAssetClasses> for Runtime {
type AssetAccountDeposit = AssetAccountDeposit;
}
/// Assets managed by some foreign location.
type ForeignAssetClasses = pallet_assets::Instance2;
impl pallet_assets::Config<ForeignAssetClasses> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = MultiLocationForAssetId;
type Currency = Balances;
type CreateOrigin = ForeignCreators;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Freezer = ();
type Extra = ();
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
type AssetAccountDeposit = AssetAccountDeposit;
type RemoveItemsLimit = frame_support::traits::ConstU32<1000>;
}
parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = deposit(1, 88);
@@ -514,9 +537,12 @@ impl pallet_asset_tx_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// TODO
// This should be able to take assets from any pallet instance.
type Fungibles = TrustBackedAssets;
type Fungibles = (ForeignAssets, TrustBackedAssets);
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
(
ForeignAssets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
TrustBackedAssets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
),
AssetsToBlockAuthor<Runtime>,
>;
}
@@ -595,6 +621,7 @@ construct_runtime!(
// The main stage.
TrustBackedAssets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>} = 52,
}
);
@@ -644,6 +671,7 @@ mod benches {
define_benchmarks!(
[frame_system, SystemBench::<Runtime>]
[pallet_assets, TrustBackedAssets]
[pallet_assets, ForeignAssets]
[pallet_balances, Balances]
[pallet_multisig, Multisig]
[pallet_proxy, Proxy]
@@ -23,6 +23,7 @@ use super::{
use frame_support::{
match_types, parameter_types,
traits::{ConstU32, Everything, Nothing, PalletInfoAccess},
traits::{EnsureOriginWithArg, Everything, PalletInfoAccess},
};
use pallet_xcm::XcmPassthrough;
use parachains_common::{
@@ -31,7 +32,7 @@ use parachains_common::{
AssetFeeAsExistentialDepositMultiplier, DenyReserveTransferToRelayChain, DenyThenTry,
},
};
use polkadot_parachain::primitives::Sibling;
use polkadot_parachain::primitives::{Id as ParaId, Sibling};
use sp_runtime::traits::ConvertInto;
use xcm::latest::prelude::*;
use xcm_builder::{
@@ -253,3 +254,34 @@ impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}
pub type MultiLocationForAssetId = MultiLocation;
pub type SovereignAccountOf = (
SiblingParachainConvertsVia<ParaId, AccountId>,
AccountId32Aliases<RelayNetwork, AccountId>,
ParentIsPreset<AccountId>,
);
// `EnsureOriginWithArg` impl for `CreateOrigin` which allows only XCM origins that are locations
// containing the class location.
pub struct ForeignCreators;
impl EnsureOriginWithArg<RuntimeOrigin, MultiLocation> for ForeignCreators {
type Success = AccountId;
fn try_origin(
o: RuntimeOrigin,
a: &MultiLocation,
) -> sp_std::result::Result<Self::Success, RuntimeOrigin> {
let origin_location = pallet_xcm::EnsureXcm::<Everything>::try_origin(o.clone())?;
if !a.starts_with(&origin_location) {
return Err(o)
}
SovereignAccountOf::convert(origin_location).map_err(|_| o)
}
#[cfg(feature = "runtime-benchmarks")]
fn successful_origin(a: &MultiLocation) -> RuntimeOrigin {
pallet_xcm::Origin::Xcm(a.clone()).into()
}
}