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

Commit

Permalink
adds universal location check
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Nov 30, 2023
1 parent 936f08a commit 90c2783
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ pub mod bridging {
parameter_types! {
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

/// User fee for ERC20 token transfer back to Ethereum.
/// (initially was calculated by test `OutboundQueue::calculate_fees` - ETH/ROC 1/400 and fee_per_gas 20 GWEI = 2200698000000 + *25%)
/// Needs to be more than fee calculated from DefaultFeeConfig FeeConfigRecord in snowbridge:parachain/pallets/outbound-queue/src/lib.rs
Expand Down Expand Up @@ -881,7 +882,7 @@ pub mod bridging {
}

pub type IsTrustedBridgedReserveLocationForForeignAsset =
matching::IsForeignConcreteAsset<FromNetwork<EthereumNetwork>>;
matching::IsForeignConcreteAsset<FromNetwork<UniversalLocation, EthereumNetwork>>;

impl Contains<(MultiLocation, Junction)> for UniversalAliases {
fn contains(alias: &(MultiLocation, Junction)) -> bool {
Expand Down
24 changes: 17 additions & 7 deletions cumulus/parachains/runtimes/assets/common/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,31 @@ impl<SelfParaId: Get<ParaId>> ContainsPair<MultiLocation, MultiLocation>
}
}

pub struct FromNetwork<ExpectedNetworkId>(sp_std::marker::PhantomData<ExpectedNetworkId>);
impl<ExpectedNetworkId: Get<NetworkId>> ContainsPair<MultiLocation, MultiLocation>
for FromNetwork<ExpectedNetworkId>
pub struct FromNetwork<UniversalLocation, ExpectedNetworkId>(
sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId)>,
);
impl<UniversalLocation: Get<InteriorMultiLocation>, ExpectedNetworkId: Get<NetworkId>>
ContainsPair<MultiLocation, MultiLocation> for FromNetwork<UniversalLocation, ExpectedNetworkId>
{
fn contains(&a: &MultiLocation, b: &MultiLocation) -> bool {
// `a` needs to be from `b` at least
if !a.starts_with(b) {
return false
}

match a {
MultiLocation { parents: 2, interior } => {
matches!(interior.first(), Some(GlobalConsensus(network)) if *network == ExpectedNetworkId::get())
let universal_source = UniversalLocation::get();

// check remote origin
return match ensure_is_remote(universal_source, a) {
Ok((network_id, _)) => network_id == ExpectedNetworkId::get(),
Err(e) => {
log::trace!(
target: "xcm::contains",
"FromNetwork origin: {:?} is not remote to the universal_source: {:?} {:?}",
a, universal_source, e
);
false
},
_ => false,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{
xcm_config::{AgentIdOf, EthereumNetwork, UniversalLocation},
Runtime,
};
use snowbridge_router_primitives::outbound::EthereumBlobExporter;
use xcm_config::{AgentIdOf, EthereumNetwork, UniversalLocation};

pub type SnowbridgeExporter = EthereumBlobExporter<
UniversalLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
use crate::{
bridge_common_config::{BridgeParachainWestendInstance, DeliveryRewardInBalance},
weights,
AccountId, BridgeWestendMessages, ParachainInfo, Runtime, RuntimeEvent, RuntimeOrigin,
weights, AccountId, BridgeWestendMessages, ParachainInfo, Runtime, RuntimeEvent, RuntimeOrigin,
XcmRouter,
};
use bp_messages::LaneId;
Expand Down

0 comments on commit 90c2783

Please sign in to comment.