Skip to content

Commit

Permalink
Instantiate All Assets Pallets (#1908)
Browse files Browse the repository at this point in the history
* instantiate all assets pallets

* assets instance

* fmt

* fix merge errors

* fmt

* no default instance

* Generic AssetFeeAsExistentialDepositMultiplier

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* remove old import

* don't rename pallet in runtime

* fix merge

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
joepetrowski and ggwpez authored Jan 18, 2023
1 parent 6b241b4 commit 241d2e8
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 91 deletions.
59 changes: 35 additions & 24 deletions cumulus/parachains/runtimes/assets/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ use frame_system::{
pub use parachains_common as common;
use parachains_common::{
impls::{AssetsToBlockAuthor, DealWithFees},
opaque, AccountId, AssetId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature,
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
opaque, AccountId, AssetIdForTrustBackedAssets, AuraId, Balance, BlockNumber, Hash, Header,
Index, Signature, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT,
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
use xcm_config::{KsmLocation, XcmConfig};

Expand Down Expand Up @@ -231,11 +232,16 @@ parameter_types! {
pub type AssetsForceOrigin =
EitherOfDiverse<EnsureRoot<AccountId>, EnsureXcm<IsMajorityOfBody<KsmLocation, ExecutiveBody>>>;

impl pallet_assets::Config for Runtime {
// Called "Trust Backed" assets because these are generally registered by some account, and users of
// the asset assume it has some claimed backing. The pallet is called `Assets` in
// `construct_runtime` to avoid breaking changes on storage reads.
pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
type TrustBackedAssetsCall = pallet_assets::Call<Runtime, TrustBackedAssetsInstance>;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = AssetId;
type AssetIdParameter = codec::Compact<AssetId>;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
Expand Down Expand Up @@ -353,15 +359,15 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
},
ProxyType::AssetOwner => matches!(
c,
RuntimeCall::Assets(pallet_assets::Call::create { .. }) |
RuntimeCall::Assets(pallet_assets::Call::start_destroy { .. }) |
RuntimeCall::Assets(pallet_assets::Call::destroy_accounts { .. }) |
RuntimeCall::Assets(pallet_assets::Call::destroy_approvals { .. }) |
RuntimeCall::Assets(pallet_assets::Call::finish_destroy { .. }) |
RuntimeCall::Assets(pallet_assets::Call::transfer_ownership { .. }) |
RuntimeCall::Assets(pallet_assets::Call::set_team { .. }) |
RuntimeCall::Assets(pallet_assets::Call::set_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::clear_metadata { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) |
Expand All @@ -378,12 +384,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
),
ProxyType::AssetManager => matches!(
c,
RuntimeCall::Assets(pallet_assets::Call::mint { .. }) |
RuntimeCall::Assets(pallet_assets::Call::burn { .. }) |
RuntimeCall::Assets(pallet_assets::Call::freeze { .. }) |
RuntimeCall::Assets(pallet_assets::Call::thaw { .. }) |
RuntimeCall::Assets(pallet_assets::Call::freeze_asset { .. }) |
RuntimeCall::Assets(pallet_assets::Call::thaw_asset { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) |
Expand Down Expand Up @@ -544,8 +550,13 @@ impl pallet_asset_tx_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Fungibles = Assets;
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
AssetsToBlockAuthor<Runtime>,
pallet_assets::BalanceToAssetBalance<
Balances,
Runtime,
ConvertInto,
TrustBackedAssetsInstance,
>,
AssetsToBlockAuthor<Runtime, TrustBackedAssetsInstance>,
>;
}

Expand Down Expand Up @@ -621,7 +632,7 @@ construct_runtime!(
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 42,

// The main stage.
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 50,
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,

#[cfg(feature = "state-trie-version-1")]
Expand Down Expand Up @@ -653,7 +664,7 @@ pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;

/// Migrations to apply on runtime upgrade.
pub type Migrations = ();

/// Executive: handles dispatch to the various modules.
Expand Down
27 changes: 18 additions & 9 deletions cumulus/parachains/runtimes/assets/statemine/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// limitations under the License.

use super::{
AccountId, AllPalletsWithSystem, AssetId, Assets, Authorship, Balance, Balances, ParachainInfo,
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee,
XcmpQueue,
AccountId, AllPalletsWithSystem, AssetIdForTrustBackedAssets, Assets, Authorship, Balance,
Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
RuntimeOrigin, TrustBackedAssetsInstance, WeightToFee, XcmpQueue,
};
use frame_support::{
match_types, parameter_types,
Expand Down Expand Up @@ -53,7 +53,7 @@ parameter_types! {
pub UniversalLocation: InteriorMultiLocation =
X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into()));
pub const Local: MultiLocation = Here.into_location();
pub AssetsPalletLocation: MultiLocation =
pub TrustBackedAssetsPalletLocation: MultiLocation =
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}
Expand Down Expand Up @@ -90,9 +90,13 @@ pub type FungiblesTransactor = FungiblesAdapter<
Assets,
// Use this currency when it is a fungible asset matching the given location or name:
ConvertedConcreteId<
AssetId,
AssetIdForTrustBackedAssets,
Balance,
AsPrefixedGeneralIndex<AssetsPalletLocation, AssetId, JustTry>,
AsPrefixedGeneralIndex<
TrustBackedAssetsPalletLocation,
AssetIdForTrustBackedAssets,
JustTry,
>,
JustTry,
>,
// Convert an XCM MultiLocation into a local account id:
Expand Down Expand Up @@ -271,7 +275,8 @@ pub type Barrier = DenyThenTry<
pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentialDepositMultiplier<
Runtime,
WeightToFee,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto, TrustBackedAssetsInstance>,
TrustBackedAssetsInstance,
>;

pub struct XcmConfig;
Expand All @@ -298,9 +303,13 @@ impl xcm_executor::Config for XcmConfig {
AccountId,
AssetFeeAsExistentialDepositMultiplierFeeCharger,
ConvertedConcreteId<
AssetId,
AssetIdForTrustBackedAssets,
Balance,
AsPrefixedGeneralIndex<AssetsPalletLocation, AssetId, JustTry>,
AsPrefixedGeneralIndex<
TrustBackedAssetsPalletLocation,
AssetIdForTrustBackedAssets,
JustTry,
>,
JustTry,
>,
Assets,
Expand Down
58 changes: 34 additions & 24 deletions cumulus/parachains/runtimes/assets/statemint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ use frame_system::{
pub use parachains_common as common;
use parachains_common::{
impls::{AssetsToBlockAuthor, DealWithFees},
opaque, AccountId, AssetId, Balance, BlockNumber, Hash, Header, Index, Signature,
StatemintAuraId as AuraId, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT,
opaque, AccountId, AssetIdForTrustBackedAssets, Balance, BlockNumber, Hash, Header, Index,
Signature, StatemintAuraId as AuraId, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT,
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
use xcm_config::{DotLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};
Expand Down Expand Up @@ -247,11 +247,16 @@ parameter_types! {
pub type AssetsForceOrigin =
EitherOfDiverse<EnsureRoot<AccountId>, EnsureXcm<IsMajorityOfBody<DotLocation, ExecutiveBody>>>;

impl pallet_assets::Config for Runtime {
// Called "Trust Backed" assets because these are generally registered by some account, and users of
// the asset assume it has some claimed backing. The pallet is called `Assets` in
// `construct_runtime` to avoid breaking changes on storage reads.
pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
type TrustBackedAssetsCall = pallet_assets::Call<Runtime, TrustBackedAssetsInstance>;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = AssetId;
type AssetIdParameter = codec::Compact<AssetId>;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
Expand Down Expand Up @@ -369,15 +374,15 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
},
ProxyType::AssetOwner => matches!(
c,
RuntimeCall::Assets(pallet_assets::Call::create { .. }) |
RuntimeCall::Assets(pallet_assets::Call::start_destroy { .. }) |
RuntimeCall::Assets(pallet_assets::Call::destroy_accounts { .. }) |
RuntimeCall::Assets(pallet_assets::Call::destroy_approvals { .. }) |
RuntimeCall::Assets(pallet_assets::Call::finish_destroy { .. }) |
RuntimeCall::Assets(pallet_assets::Call::transfer_ownership { .. }) |
RuntimeCall::Assets(pallet_assets::Call::set_team { .. }) |
RuntimeCall::Assets(pallet_assets::Call::set_metadata { .. }) |
RuntimeCall::Assets(pallet_assets::Call::clear_metadata { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) |
Expand All @@ -394,12 +399,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
),
ProxyType::AssetManager => matches!(
c,
RuntimeCall::Assets(pallet_assets::Call::mint { .. }) |
RuntimeCall::Assets(pallet_assets::Call::burn { .. }) |
RuntimeCall::Assets(pallet_assets::Call::freeze { .. }) |
RuntimeCall::Assets(pallet_assets::Call::thaw { .. }) |
RuntimeCall::Assets(pallet_assets::Call::freeze_asset { .. }) |
RuntimeCall::Assets(pallet_assets::Call::thaw_asset { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) |
Expand Down Expand Up @@ -545,8 +550,13 @@ impl pallet_asset_tx_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Fungibles = Assets;
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
AssetsToBlockAuthor<Runtime>,
pallet_assets::BalanceToAssetBalance<
Balances,
Runtime,
ConvertInto,
TrustBackedAssetsInstance,
>,
AssetsToBlockAuthor<Runtime, TrustBackedAssetsInstance>,
>;
}

Expand Down Expand Up @@ -622,7 +632,7 @@ construct_runtime!(
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 42,

// The main stage.
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 50,
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
}
);
Expand Down Expand Up @@ -651,7 +661,7 @@ pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;

/// Migrations to apply on runtime upgrade.
pub type Migrations = ();

/// Executive: handles dispatch to the various modules.
Expand Down
27 changes: 18 additions & 9 deletions cumulus/parachains/runtimes/assets/statemint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// limitations under the License.

use super::{
AccountId, AllPalletsWithSystem, AssetId, Assets, Authorship, Balance, Balances, ParachainInfo,
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee,
XcmpQueue,
AccountId, AllPalletsWithSystem, AssetIdForTrustBackedAssets, Assets, Authorship, Balance,
Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
RuntimeOrigin, TrustBackedAssetsInstance, WeightToFee, XcmpQueue,
};
use frame_support::{
match_types, parameter_types,
Expand Down Expand Up @@ -53,7 +53,7 @@ parameter_types! {
pub UniversalLocation: InteriorMultiLocation =
X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into()));
pub const Local: MultiLocation = MultiLocation::here();
pub AssetsPalletLocation: MultiLocation =
pub TrustBackedAssetsPalletLocation: MultiLocation =
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}
Expand Down Expand Up @@ -90,9 +90,13 @@ pub type FungiblesTransactor = FungiblesAdapter<
Assets,
// Use this currency when it is a fungible asset matching the given location or name:
ConvertedConcreteId<
AssetId,
AssetIdForTrustBackedAssets,
Balance,
AsPrefixedGeneralIndex<AssetsPalletLocation, AssetId, JustTry>,
AsPrefixedGeneralIndex<
TrustBackedAssetsPalletLocation,
AssetIdForTrustBackedAssets,
JustTry,
>,
JustTry,
>,
// Convert an XCM MultiLocation into a local account id:
Expand Down Expand Up @@ -271,7 +275,8 @@ pub type Barrier = DenyThenTry<
pub type AssetFeeAsExistentialDepositMultiplierFeeCharger = AssetFeeAsExistentialDepositMultiplier<
Runtime,
WeightToFee,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto, TrustBackedAssetsInstance>,
TrustBackedAssetsInstance,
>;

pub struct XcmConfig;
Expand All @@ -298,9 +303,13 @@ impl xcm_executor::Config for XcmConfig {
AccountId,
AssetFeeAsExistentialDepositMultiplierFeeCharger,
ConvertedConcreteId<
AssetId,
AssetIdForTrustBackedAssets,
Balance,
AsPrefixedGeneralIndex<AssetsPalletLocation, AssetId, JustTry>,
AsPrefixedGeneralIndex<
TrustBackedAssetsPalletLocation,
AssetIdForTrustBackedAssets,
JustTry,
>,
JustTry,
>,
Assets,
Expand Down
Loading

0 comments on commit 241d2e8

Please sign in to comment.