difftreelog
fix disallow xcm teleports completely
in: master
3 files changed
runtime/common/config/xcm/foreignassets.rsdiffbeforeafterboth--- a/runtime/common/config/xcm/foreignassets.rs
+++ b/runtime/common/config/xcm/foreignassets.rs
@@ -15,13 +15,13 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{
- traits::{Contains, Get, fungibles, ContainsPair},
+ traits::{Get, ContainsPair},
parameter_types,
};
use sp_runtime::traits::Convert;
-use xcm::latest::{MultiAsset, Junction::*, MultiLocation, Junctions::*};
-use xcm_builder::{FungiblesAdapter, NonLocalMint, ConvertedConcreteId};
-use xcm_executor::traits::{Convert as ConvertXcm, JustTry};
+use xcm::latest::{prelude::*, MultiAsset, MultiLocation};
+use xcm_builder::{FungiblesAdapter, NoChecking, ConvertedConcreteId};
+use xcm_executor::traits::{TransactAsset, Convert as ConvertXcm, JustTry};
use pallet_foreign_assets::{
AssetIds, AssetIdMapping, XcmForeignAssetIdMapping, NativeCurrency, FreeForAll, TryAsForeign,
ForeignAssetId, CurrencyId,
@@ -36,20 +36,7 @@
parameter_types! {
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}
-
-/// No teleports are allowed
-pub struct NoTeleports<AccountId, ForeignAssets>(PhantomData<(AccountId, ForeignAssets)>);
-impl<AccountId, ForeignAssets> Contains<<ForeignAssets as fungibles::Inspect<AccountId>>::AssetId>
- for NoTeleports<AccountId, ForeignAssets>
-where
- ForeignAssets: fungibles::Inspect<AccountId>,
-{
- fn contains(_id: &<ForeignAssets as fungibles::Inspect<AccountId>>::AssetId) -> bool {
- false
- }
-}
-
pub struct AsInnerId<AssetId, ConvertAssetId>(PhantomData<(AssetId, ConvertAssetId)>);
impl<AssetId: Clone + PartialEq, ConvertAssetId: ConvertXcm<AssetId, AssetId>>
ConvertXcm<MultiLocation, AssetId> for AsInnerId<AssetId, ConvertAssetId>
@@ -131,14 +118,56 @@
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
- // No teleports are allowed
- NonLocalMint<NoTeleports<AccountId, ForeignAssets>>,
+ // No Checking for teleported assets since we disallow teleports at all.
+ NoChecking,
// The account to use for tracking teleports.
CheckingAccount,
>;
/// Means for transacting assets on this chain.
-pub type AssetTransactors = FungiblesTransactor;
+pub struct AssetTransactor;
+impl TransactAsset for AssetTransactor {
+ fn can_check_in(
+ _origin: &MultiLocation,
+ _what: &MultiAsset,
+ _context: &XcmContext,
+ ) -> XcmResult {
+ Err(XcmError::Unimplemented)
+ }
+
+ fn check_in(_origin: &MultiLocation, _what: &MultiAsset, _context: &XcmContext) {}
+
+ fn can_check_out(
+ _dest: &MultiLocation,
+ _what: &MultiAsset,
+ _context: &XcmContext,
+ ) -> XcmResult {
+ Err(XcmError::Unimplemented)
+ }
+
+ fn check_out(_dest: &MultiLocation, _what: &MultiAsset, _context: &XcmContext) {}
+
+ fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult {
+ FungiblesTransactor::deposit_asset(what, who, context)
+ }
+
+ fn withdraw_asset(
+ what: &MultiAsset,
+ who: &MultiLocation,
+ maybe_context: Option<&XcmContext>,
+ ) -> Result<xcm_executor::Assets, XcmError> {
+ FungiblesTransactor::withdraw_asset(what, who, maybe_context)
+ }
+
+ fn internal_transfer_asset(
+ what: &MultiAsset,
+ from: &MultiLocation,
+ to: &MultiLocation,
+ context: &XcmContext,
+ ) -> Result<xcm_executor::Assets, XcmError> {
+ FungiblesTransactor::internal_transfer_asset(what, from, to, context)
+ }
+}
pub struct AllAsset;
impl ContainsPair<MultiAsset, MultiLocation> for AllAsset {
runtime/common/config/xcm/mod.rsdiffbeforeafterboth--- a/runtime/common/config/xcm/mod.rs
+++ b/runtime/common/config/xcm/mod.rs
@@ -49,7 +49,7 @@
#[cfg(not(feature = "foreign-assets"))]
pub use nativeassets as xcm_assets;
-use xcm_assets::{AssetTransactors, IsReserve, Trader};
+use xcm_assets::{AssetTransactor, IsReserve, Trader};
parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
@@ -213,7 +213,7 @@
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
// How to withdraw and deposit an asset.
- type AssetTransactor = AssetTransactors;
+ type AssetTransactor = AssetTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = IsReserve;
type IsTeleporter = (); // Teleportation is disabled
runtime/common/config/xcm/nativeassets.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18 traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},19 weights::WeightToFeePolynomial,20};21use sp_runtime::traits::{CheckedConversion, Zero, Convert};22use xcm::latest::{23 AssetId::{Concrete},24 Fungibility::Fungible as XcmFungible,25 MultiAsset, Error as XcmError, Weight,26 Junction::*,27 MultiLocation,28 Junctions::*,29};30use xcm_builder::{CurrencyAdapter, NativeAsset};31use xcm_executor::{32 Assets,33 traits::{MatchesFungible, WeightTrader},34};35use pallet_foreign_assets::{AssetIds, NativeCurrency};36use sp_std::marker::PhantomData;37use crate::{Balances, ParachainInfo};38use super::{LocationToAccountId, RelayLocation};3940use up_common::types::{AccountId, Balance};4142pub struct OnlySelfCurrency;43impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {44 fn matches_fungible(a: &MultiAsset) -> Option<B> {45 let paraid = Parachain(ParachainInfo::parachain_id().into());46 match (&a.id, &a.fun) {47 (48 Concrete(MultiLocation {49 parents: 1,50 interior: X1(loc),51 }),52 XcmFungible(ref amount),53 ) if paraid == *loc => CheckedConversion::checked_from(*amount),54 (55 Concrete(MultiLocation {56 parents: 0,57 interior: Here,58 }),59 XcmFungible(ref amount),60 ) => CheckedConversion::checked_from(*amount),61 _ => None,62 }63 }64}6566/// Means for transacting assets on this chain.67pub type LocalAssetTransactor = CurrencyAdapter<68 // Use this currency:69 Balances,70 // Use this currency when it is a fungible asset matching the given location or name:71 OnlySelfCurrency,72 // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:73 LocationToAccountId,74 // Our chain's account ID type (we can't get away without mentioning it explicitly):75 AccountId,76 // We don't track any teleports.77 (),78>;7980pub type AssetTransactors = LocalAssetTransactor;8182pub type IsReserve = NativeAsset;8384pub struct UsingOnlySelfCurrencyComponents<85 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,86 AssetId: Get<MultiLocation>,87 AccountId,88 Currency: CurrencyT<AccountId>,89 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,90>(91 Weight,92 Currency::Balance,93 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,94);95impl<96 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,97 AssetId: Get<MultiLocation>,98 AccountId,99 Currency: CurrencyT<AccountId>,100 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,101 > WeightTrader102 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>103{104 fn new() -> Self {105 Self(0, Zero::zero(), PhantomData)106 }107108 fn buy_weight(&mut self, _weight: Weight, payment: Assets) -> Result<Assets, XcmError> {109 Ok(payment)110 }111}112impl<113 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,114 AssetId: Get<MultiLocation>,115 AccountId,116 Currency: CurrencyT<AccountId>,117 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,118 > Drop119 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>120{121 fn drop(&mut self) {122 OnUnbalanced::on_unbalanced(Currency::issue(self.1));123 }124}125126pub type Trader<T> = UsingOnlySelfCurrencyComponents<127 pallet_configuration::WeightToFee<T, Balance>,128 RelayLocation,129 AccountId,130 Balances,131 (),132>;133134pub struct CurrencyIdConvert;135impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {136 fn convert(id: AssetIds) -> Option<MultiLocation> {137 match id {138 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(139 1,140 X1(Parachain(ParachainInfo::get().into())),141 )),142 _ => None,143 }144 }145}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18 traits::{tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get},19 weights::WeightToFeePolynomial,20};21use sp_runtime::traits::{CheckedConversion, Zero, Convert};22use xcm::latest::{23 AssetId::{Concrete},24 Fungibility::Fungible as XcmFungible,25 MultiAsset, Error as XcmError, Weight,26 Junction::*,27 MultiLocation,28 Junctions::*,29};30use xcm_builder::{CurrencyAdapter, NativeAsset};31use xcm_executor::{32 Assets,33 traits::{MatchesFungible, WeightTrader},34};35use pallet_foreign_assets::{AssetIds, NativeCurrency};36use sp_std::marker::PhantomData;37use crate::{Balances, ParachainInfo};38use super::{LocationToAccountId, RelayLocation};3940use up_common::types::{AccountId, Balance};4142pub struct OnlySelfCurrency;43impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {44 fn matches_fungible(a: &MultiAsset) -> Option<B> {45 let paraid = Parachain(ParachainInfo::parachain_id().into());46 match (&a.id, &a.fun) {47 (48 Concrete(MultiLocation {49 parents: 1,50 interior: X1(loc),51 }),52 XcmFungible(ref amount),53 ) if paraid == *loc => CheckedConversion::checked_from(*amount),54 (55 Concrete(MultiLocation {56 parents: 0,57 interior: Here,58 }),59 XcmFungible(ref amount),60 ) => CheckedConversion::checked_from(*amount),61 _ => None,62 }63 }64}6566/// Means for transacting assets on this chain.67pub type LocalAssetTransactor = CurrencyAdapter<68 // Use this currency:69 Balances,70 // Use this currency when it is a fungible asset matching the given location or name:71 OnlySelfCurrency,72 // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:73 LocationToAccountId,74 // Our chain's account ID type (we can't get away without mentioning it explicitly):75 AccountId,76 // We don't track any teleports.77 (),78>;7980pub type AssetTransactor = LocalAssetTransactor;8182pub type IsReserve = NativeAsset;8384pub struct UsingOnlySelfCurrencyComponents<85 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,86 AssetId: Get<MultiLocation>,87 AccountId,88 Currency: CurrencyT<AccountId>,89 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,90>(91 Weight,92 Currency::Balance,93 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,94);95impl<96 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,97 AssetId: Get<MultiLocation>,98 AccountId,99 Currency: CurrencyT<AccountId>,100 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,101 > WeightTrader102 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>103{104 fn new() -> Self {105 Self(0, Zero::zero(), PhantomData)106 }107108 fn buy_weight(&mut self, _weight: Weight, payment: Assets) -> Result<Assets, XcmError> {109 Ok(payment)110 }111}112impl<113 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,114 AssetId: Get<MultiLocation>,115 AccountId,116 Currency: CurrencyT<AccountId>,117 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,118 > Drop119 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>120{121 fn drop(&mut self) {122 OnUnbalanced::on_unbalanced(Currency::issue(self.1));123 }124}125126pub type Trader<T> = UsingOnlySelfCurrencyComponents<127 pallet_configuration::WeightToFee<T, Balance>,128 RelayLocation,129 AccountId,130 Balances,131 (),132>;133134pub struct CurrencyIdConvert;135impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {136 fn convert(id: AssetIds) -> Option<MultiLocation> {137 match id {138 AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(139 1,140 X1(Parachain(ParachainInfo::get().into())),141 )),142 _ => None,143 }144 }145}