statemine progress

This commit is contained in:
joepetrowski
2022-11-22 21:24:25 +01:00
parent 633366b172
commit 5f7f8c2a01
4 changed files with 76 additions and 33 deletions
+43 -20
View File
@@ -228,11 +228,13 @@ parameter_types! {
pub type AssetsForceOrigin =
EitherOfDiverse<EnsureRoot<AccountId>, EnsureXcm<IsMajorityOfBody<KsmLocation, ExecutiveBody>>>;
impl pallet_assets::Config for Runtime {
pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = AssetId;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
@@ -243,6 +245,8 @@ impl pallet_assets::Config for Runtime {
type Extra = ();
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
type AssetAccountDeposit = AssetAccountDeposit;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
}
parameter_types! {
@@ -317,6 +321,7 @@ impl Default for ProxyType {
Self::Any
}
}
type TrustBackedAssetsCall = pallet_assets::Call<Runtime, frame_support::instances::Instance1>;
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
@@ -324,7 +329,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
ProxyType::NonTransfer => !matches!(
c,
RuntimeCall::Balances { .. } |
RuntimeCall::Assets { .. } |
RuntimeCall::TrustBackedAssets { .. } |
RuntimeCall::Uniques { .. }
),
ProxyType::CancelProxy => matches!(
@@ -336,7 +341,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
ProxyType::Assets => {
matches!(
c,
RuntimeCall::Assets { .. } |
RuntimeCall::TrustBackedAssets { .. } |
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. } |
RuntimeCall::Uniques { .. }
@@ -344,12 +349,13 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
},
ProxyType::AssetOwner => matches!(
c,
RuntimeCall::Assets(pallet_assets::Call::create { .. }) |
RuntimeCall::Assets(pallet_assets::Call::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::TrustBackedAssets(TrustBackedAssetsCall::create { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::destroy { .. }) |
RuntimeCall::TrustBackedAssets(
TrustBackedAssetsCall::transfer_ownership { .. }
) | RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_team { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::set_metadata { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::clear_metadata { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::create { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::destroy { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::transfer_ownership { .. }) |
@@ -366,12 +372,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::TrustBackedAssets(TrustBackedAssetsCall::mint { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::burn { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::freeze_asset { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetsCall::thaw_asset { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::burn { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::freeze { .. }) |
@@ -516,9 +522,17 @@ impl pallet_collator_selection::Config for Runtime {
impl pallet_asset_tx_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Fungibles = Assets;
// TODO https://github.com/paritytech/substrate/issues/12724
// This should be able to take assets from any pallet instance. For now we only allow
// sufficient, trust backed assets to pay for transaction fees.
type Fungibles = TrustBackedAssets;
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
pallet_assets::BalanceToAssetBalance<
Balances,
Runtime,
ConvertInto,
TrustBackedAssetsInstance,
>,
AssetsToBlockAuthor<Runtime>,
>;
}
@@ -595,7 +609,7 @@ construct_runtime!(
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 42,
// The main stage.
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 50,
TrustBackedAssets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
}
);
@@ -631,9 +645,18 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
MigrateAssetsPallet,
>;
pub struct MigrateAssetsPallet;
impl frame_support::traits::OnRuntimeUpgrade for MigrateAssetsPallet {
fn on_runtime_upgrade() -> Weight {
use frame_support::storage::migration;
migration::move_pallet(b"Assets", b"TrustBackedAssets");
<Runtime as frame_system::Config>::DbWeight::get().writes(1)
}
}
#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
@@ -642,7 +665,7 @@ extern crate frame_benchmarking;
mod benches {
define_benchmarks!(
[frame_system, SystemBench::<Runtime>]
[pallet_assets, Assets]
[pallet_assets, TrustBackedAssets]
[pallet_balances, Balances]
[pallet_multisig, Multisig]
[pallet_proxy, Proxy]
@@ -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, AssetId, Authorship, Balance, Balances, ParachainInfo,
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
TrustBackedAssets, TrustBackedAssetsInstance, WeightToFee, XcmpQueue,
};
use frame_support::{
match_types, parameter_types,
@@ -48,8 +48,8 @@ parameter_types! {
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorMultiLocation = X1(Parachain(ParachainInfo::parachain_id().into()));
pub const Local: MultiLocation = Here.into_location();
pub AssetsPalletLocation: MultiLocation =
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
pub TrustBackedAssetsPalletLocation: MultiLocation =
PalletInstance(<TrustBackedAssets as PalletInfoAccess>::index() as u8).into();
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}
@@ -82,12 +82,12 @@ pub type CurrencyTransactor = CurrencyAdapter<
/// Means for transacting assets besides the native currency on this chain.
pub type FungiblesTransactor = FungiblesAdapter<
// Use this fungibles implementation:
Assets,
TrustBackedAssets,
// Use this currency when it is a fungible asset matching the given location or name:
ConvertedConcreteId<
AssetId,
Balance,
AsPrefixedGeneralIndex<AssetsPalletLocation, AssetId, JustTry>,
AsPrefixedGeneralIndex<TrustBackedAssetsPalletLocation, AssetId, JustTry>,
JustTry,
>,
// Convert an XCM MultiLocation into a local account id:
@@ -96,7 +96,7 @@ pub type FungiblesTransactor = FungiblesAdapter<
AccountId,
// We only want to allow teleports of known assets. We use non-zero issuance as an indication
// that this asset is known.
parachains_common::impls::NonZeroIssuance<AccountId, Assets>,
parachains_common::impls::NonZeroIssuance<AccountId, TrustBackedAssets>,
// The account to use for tracking teleports.
CheckingAccount,
>;
@@ -183,15 +183,20 @@ impl xcm_executor::Config for XcmConfig {
AssetFeeAsExistentialDepositMultiplier<
Runtime,
WeightToFee,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
pallet_assets::BalanceToAssetBalance<
Balances,
Runtime,
ConvertInto,
TrustBackedAssetsInstance,
>,
>,
ConvertedConcreteId<
AssetId,
Balance,
AsPrefixedGeneralIndex<AssetsPalletLocation, AssetId, JustTry>,
AsPrefixedGeneralIndex<TrustBackedAssetsPalletLocation, AssetId, JustTry>,
JustTry,
>,
Assets,
TrustBackedAssets,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
FungiblesTransactor,
AccountId,
@@ -263,6 +263,7 @@ impl pallet_assets::Config for Runtime {
type Balance = Balance;
type AssetId = AssetId;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
@@ -273,6 +274,8 @@ impl pallet_assets::Config for Runtime {
type Extra = ();
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
type AssetAccountDeposit = AssetAccountDeposit;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
}
parameter_types! {
+14 -2
View File
@@ -245,6 +245,8 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type Extra = ();
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
type AssetAccountDeposit = AssetAccountDeposit;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
}
/// Assets managed by some foreign location.
@@ -252,7 +254,6 @@ type ForeignAssetsInstance = pallet_assets::Instance2;
impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
// TODO: need HasCompact for MultiLocation
type AssetId = AssetId; // MultiLocationForAssetId;
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>; // ForeignCreators;
@@ -266,6 +267,8 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type Extra = ();
type WeightInfo = weights::pallet_assets::WeightInfo<Runtime>;
type AssetAccountDeposit = AssetAccountDeposit;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
}
parameter_types! {
@@ -663,9 +666,18 @@ pub type Executive = frame_executive::Executive<
// TODO
// 1. Move this instance https://substrate.stackexchange.com/questions/4343/how-to-migrate-storage-from-a-default-pallet-instance-to-an-actual-one
// 2. Make sure this migration applies to the old instance
(), //pallet_assets::migration::v1::MigrateToV1<Runtime>,
MigrateAssetsPallet, //pallet_assets::migration::v1::MigrateToV1<Runtime>,
>;
pub struct MigrateAssetsPallet;
impl frame_support::traits::OnRuntimeUpgrade for MigrateAssetsPallet {
fn on_runtime_upgrade() -> Weight {
use frame_support::storage::migration;
migration::move_pallet(b"Assets", b"TrustBackedAssets");
<Runtime as frame_system::Config>::DbWeight::get().writes(1)
}
}
#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;