Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
add Teleport Filter to allow only HOP
Browse files Browse the repository at this point in the history
  • Loading branch information
metricaez committed Aug 10, 2023
1 parent 3e0b211 commit e656356
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions runtime/trappist/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
// limitations under the License.

use frame_support::{
inherent::Vec,
match_types, parameter_types,
traits::{ContainsPair, EitherOfDiverse, Everything, Get, Nothing, PalletInfoAccess},
traits::{Contains, ContainsPair, EitherOfDiverse, Everything, Get, Nothing, PalletInfoAccess},
weights::Weight,
};
use frame_system::EnsureRoot;
Expand Down Expand Up @@ -152,6 +153,7 @@ pub type ReservedFungiblesTransactor = FungiblesAdapter<
>;

/// Means for transacting assets on this chain.
/// TODO: Is LocalFungiblesTransactor needed?
pub type AssetTransactors =
(LocalAssetTransactor, ReservedFungiblesTransactor /* , LocalFungiblesTransactor */);

Expand Down Expand Up @@ -230,7 +232,11 @@ parameter_types! {
);
/// Roc = 7 RUSD
pub RocPerSecond: (xcm::v3::AssetId, u128,u128) = (MultiLocation::parent().into(), default_fee_per_second() * 70, 0u128);
pub MockTokenPerSecond: (xcm::v3::AssetId, u128, u128) = (MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(10))).into(), default_fee_per_second() * 1, 0u128);
// TODO: How to define this ratio?
pub MockTokenPerSecond: (xcm::v3::AssetId, u128, u128) = (
MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(10))).into(),
default_fee_per_second() * 1,
0u128);
}

parameter_types! {
Expand All @@ -254,7 +260,9 @@ impl<T: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation> for ReserveA
let prefix = T::get();
log::trace!(target: "xcm::AssetsFrom", "prefix: {:?}, origin: {:?}, asset: {:?}", prefix, origin, asset);
&prefix == origin
// &&
// TODO: Check on how to fix assetId location as in foreign assets this does not apply.
// Assets being sent from AH but asset_loc is another parachain.
// &&
// match asset {
// MultiAsset { id: xcm::latest::AssetId::Concrete(asset_loc), fun: Fungible(_a) } =>
// matches_prefix(&prefix, asset_loc),
Expand All @@ -263,6 +271,22 @@ impl<T: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation> for ReserveA
}
}

pub struct OnlyTeleportNative;
impl Contains<(MultiLocation, Vec<MultiAsset>)> for OnlyTeleportNative {
fn contains(t: &(MultiLocation, Vec<MultiAsset>)) -> bool {
if t.1.len() != 1 {
return false
}
let asset = &t.1[0];
log::trace!(target: "xcm::OnlyTeleportNative", "Asset to be teleported: {:?}", asset);
match asset {
MultiAsset { id: xcm::latest::AssetId::Concrete(asset_loc), fun: Fungible(_a) } =>
matches_prefix(&SelfReserve::get(), asset_loc),
_ => false,
}
}
}

pub type Traders = (
// RUSD
FixedRateOfFungible<RUsdPerSecond, ()>,
Expand Down Expand Up @@ -341,7 +365,8 @@ impl pallet_xcm::Config for Runtime {
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Everything;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
//Only teleport of HOP is allowed
type XcmTeleportFilter = OnlyTeleportNative;
type XcmReserveTransferFilter = Everything;
type Weigher = WeightInfoBounds<
crate::weights::xcm::TrappistXcmWeight<RuntimeCall>,
Expand Down

0 comments on commit e656356

Please sign in to comment.