make it almost compile

This commit is contained in:
joepetrowski
2022-11-18 10:51:45 +01:00
parent 94717a415b
commit 47d96e0192
3 changed files with 54 additions and 35 deletions
+12 -7
View File
@@ -82,24 +82,29 @@ pub struct AssetFeeAsExistentialDepositMultiplier<Runtime, WeightToFee, BalanceC
impl<CurrencyBalance, Runtime, WeightToFee, BalanceConverter>
cumulus_primitives_utility::ChargeWeightInFungibles<
AccountIdOf<Runtime>,
pallet_assets::Pallet<Runtime>,
// todo: I don't understand why `frame_support` is the instance here??? but it compiles...
pallet_assets::Pallet<Runtime, frame_support::instances::Instance1>,
> for AssetFeeAsExistentialDepositMultiplier<Runtime, WeightToFee, BalanceConverter>
where
Runtime: pallet_assets::Config,
Runtime: pallet_assets::Config<frame_support::instances::Instance1>,
WeightToFee: WeightToFeePolynomial<Balance = CurrencyBalance>,
BalanceConverter: BalanceConversion<
CurrencyBalance,
<Runtime as pallet_assets::Config>::AssetId,
<Runtime as pallet_assets::Config>::Balance,
<Runtime as pallet_assets::Config<frame_support::instances::Instance1>>::AssetId,
<Runtime as pallet_assets::Config<frame_support::instances::Instance1>>::Balance,
>,
AccountIdOf<Runtime>:
From<polkadot_primitives::v2::AccountId> + Into<polkadot_primitives::v2::AccountId>,
{
fn charge_weight_in_fungibles(
asset_id: <pallet_assets::Pallet<Runtime> as Inspect<AccountIdOf<Runtime>>>::AssetId,
asset_id: <pallet_assets::Pallet<Runtime, frame_support::instances::Instance1> as Inspect<AccountIdOf<Runtime>>>::AssetId,
weight: Weight,
) -> Result<<pallet_assets::Pallet<Runtime> as Inspect<AccountIdOf<Runtime>>>::Balance, XcmError>
{
) -> Result<
<pallet_assets::Pallet<Runtime, frame_support::instances::Instance1> as Inspect<
AccountIdOf<Runtime>,
>>::Balance,
XcmError,
> {
let amount = WeightToFee::weight_to_fee(&weight);
// If the amount gotten is not at least the ED, then make it be the ED of the asset
// This is to avoid burning assets and decreasing the supply
+24 -22
View File
@@ -228,8 +228,8 @@ pub type AssetsForceOrigin = EnsureRoot<AccountId>;
// We should perhaps come up with a new name. "ReserveBackedAssets" collides with XCM terminology
// and falsly implies that they are actually backed by some reserve. In reality, the user is
// _trusting_ some `CreateOrigin` (AccountId) that the asset is what they claim.
type TrustBackedAssetClasses = pallet_assets::Instance1;
impl pallet_assets::Config<TrustBackedAssetClasses> for Runtime {
pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = AssetId;
@@ -251,9 +251,11 @@ type ForeignAssetClasses = pallet_assets::Instance2;
impl pallet_assets::Config<ForeignAssetClasses> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = MultiLocationForAssetId;
// TODO: impl Copy for MultiLocation or relax AssetId to Clone?
// https://github.com/paritytech/substrate/pull/12731
type AssetId = AssetId; // MultiLocationForAssetId;
type Currency = Balances;
type CreateOrigin = ForeignCreators;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>; // ForeignCreators;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
@@ -339,6 +341,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 {
@@ -366,12 +369,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
},
ProxyType::AssetOwner => matches!(
c,
RuntimeCall::Assets(TrustBackedAssetClasses::Call::create { .. }) |
RuntimeCall::Assets(TrustBackedAssetClasses::Call::destroy { .. }) |
RuntimeCall::Assets(TrustBackedAssetClasses::Call::transfer_ownership { .. }) |
RuntimeCall::Assets(TrustBackedAssetClasses::Call::set_team { .. }) |
RuntimeCall::Assets(TrustBackedAssetClasses::Call::set_metadata { .. }) |
RuntimeCall::Assets(TrustBackedAssetClasses::Call::clear_metadata { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::create { .. }) |
RuntimeCall::Assets(TrustBackedAssetsCall::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 { .. }) |
@@ -388,15 +391,13 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
),
ProxyType::AssetManager => matches!(
c,
RuntimeCall::TrustBackedAssets(TrustBackedAssetClasses::Call::mint { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetClasses::Call::burn { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetClasses::Call::freeze { .. }) |
RuntimeCall::TrustBackedAssets(TrustBackedAssetClasses::Call::thaw { .. }) |
RuntimeCall::TrustBackedAssets(
TrustBackedAssetClasses::Call::freeze_asset { .. }
) | RuntimeCall::TrustBackedAssets(
TrustBackedAssetClasses::Call::thaw_asset { .. }
) | RuntimeCall::Uniques(pallet_uniques::Call::mint { .. }) |
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 { .. }) |
RuntimeCall::Uniques(pallet_uniques::Call::thaw { .. }) |
@@ -536,14 +537,15 @@ impl pallet_collator_selection::Config for Runtime {
impl pallet_asset_tx_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// TODO https://github.com/paritytech/substrate/issues/12724
// This should be able to take assets from any pallet instance.
// 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::Instance1,
TrustBackedAssetsInstance,
>,
AssetsToBlockAuthor<Runtime>,
>;
@@ -661,7 +663,7 @@ 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>,
(), //pallet_assets::migration::v1::MigrateToV1<Runtime>,
>;
#[cfg(feature = "runtime-benchmarks")]
@@ -18,14 +18,15 @@ use super::{
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee,
XcmpQueue,
AccountId, AssetId, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssets, WeightToFee, XcmpQueue,
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TrustBackedAssetsInstance, TrustBackedAssets,
WeightToFee, XcmpQueue,
};
use frame_support::{
match_types, parameter_types,
traits::{ConstU32, Everything, Nothing, PalletInfoAccess},
traits::{EnsureOriginWithArg, Everything, PalletInfoAccess},
};
use pallet_xcm::XcmPassthrough;
use pallet_xcm::{EnsureXcm, XcmPassthrough};
use parachains_common::{
impls::ToStakingPot,
xcm_config::{
@@ -43,7 +44,7 @@ use xcm_builder::{
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds,
};
use xcm_executor::{traits::JustTry, XcmExecutor};
use xcm_executor::{traits::{Convert, JustTry}, XcmExecutor};
parameter_types! {
pub const WestendLocation: MultiLocation = MultiLocation::parent();
@@ -183,7 +184,12 @@ impl xcm_executor::Config for XcmConfig {
AssetFeeAsExistentialDepositMultiplier<
Runtime,
WeightToFee,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
pallet_assets::BalanceToAssetBalance<
Balances,
Runtime,
ConvertInto,
TrustBackedAssetsInstance,
>,
>,
ConvertedConcreteId<
AssetId,
@@ -274,8 +280,14 @@ impl EnsureOriginWithArg<RuntimeOrigin, MultiLocation> for ForeignCreators {
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) {
let origin_location = EnsureXcm::try_origin(o.clone())?;
// dirty hack, should port vvv into master and use `starts_with`
// https://github.com/paritytech/polkadot/commit/e640d826513c45a0452138c8908a699e19ac0143
if a.parents != origin_location.parents ||
a.interior.len() != origin_location.interior.len() ||
!a.interior.iter().zip(origin_location.interior.iter()).all(|(l, r)| l == r)
{
return Err(o)
}
SovereignAccountOf::convert(origin_location).map_err(|_| o)