Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bridges/snowbridge/primitives/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sp-std = { workspace = true }

xcm = { workspace = true }
xcm-executor = { workspace = true }
xcm-builder = { workspace = true }

snowbridge-core = { workspace = true }

Expand All @@ -43,12 +44,14 @@ std = [
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
47 changes: 44 additions & 3 deletions bridges/snowbridge/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#[cfg(test)]
mod tests;

use core::slice::Iter;

use codec::{Decode, Encode};
use core::slice::Iter;
use sp_std::ops::ControlFlow;

use frame_support::{ensure, traits::Get};
use frame_support::{
ensure,
traits::{Contains, Get, ProcessMessageError},
};
use snowbridge_core::{
outbound::{AgentExecuteCommand, Command, Message, SendMessage},
AgentId, ChannelId, ParaId, TokenId, TokenIdOf,
Expand All @@ -18,6 +21,7 @@ use sp_core::{H160, H256};
use sp_runtime::traits::MaybeEquivalence;
use sp_std::{iter::Peekable, marker::PhantomData, prelude::*};
use xcm::prelude::*;
use xcm_builder::{CreateMatcher, ExporterFor, MatchXcm};
use xcm_executor::traits::{ConvertLocation, ExportXcm};

pub struct EthereumBlobExporter<
Expand Down Expand Up @@ -407,3 +411,40 @@ where
Ok((Command::MintForeignToken { token_id, recipient, amount }, *topic_id))
}
}

/// An adapter for the implementation of `ExporterFor`, which attempts to find the
/// `(bridge_location, payment)` for the requested `network` and `remote_location` and `xcm`
/// in the provided `T` table containing various exporters.
pub struct XcmFilterExporter<T, M>(core::marker::PhantomData<(T, M)>);
impl<T: ExporterFor, M: Contains<Xcm<()>>> ExporterFor for XcmFilterExporter<T, M> {
fn exporter_for(
network: &NetworkId,
remote_location: &InteriorLocation,
xcm: &Xcm<()>,
) -> Option<(Location, Option<Asset>)> {
// check the XCM
if !M::contains(xcm) {
return None
}
// check `network` and `remote_location`
T::exporter_for(network, remote_location, xcm)
}
}

/// Xcm for SnowbridgeV2 which requires XCMV5
pub struct XcmForSnowbridgeV2;
impl Contains<Xcm<()>> for XcmForSnowbridgeV2 {
fn contains(xcm: &Xcm<()>) -> bool {
let mut instructions = xcm.clone().0;
let result = instructions.matcher().match_next_inst_while(
|_| true,
|inst| {
return match inst {
AliasOrigin(..) => Err(ProcessMessageError::Yield),
_ => Ok(ControlFlow::Continue(())),
}
},
);
result.is_err()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,10 @@ pub type XcmRouter = WithUniqueTopic<(
// Router which wraps and sends xcm to BridgeHub to be delivered to the Ethereum
// GlobalConsensus
SovereignPaidRemoteExporter<
bridging::to_ethereum::EthereumNetworkExportTable,
(
bridging::to_ethereum::EthereumNetworkExportTableV2,
bridging::to_ethereum::EthereumNetworkExportTable,
),
XcmpQueue,
UniversalLocation,
>,
Expand Down Expand Up @@ -666,7 +669,9 @@ pub mod bridging {
/// Needs to be more than fee calculated from DefaultFeeConfig FeeConfigRecord in snowbridge:parachain/pallets/outbound-queue/src/lib.rs
/// Polkadot uses 10 decimals, Kusama,Rococo,Westend 12 decimals.
pub const DefaultBridgeHubEthereumBaseFee: Balance = 2_750_872_500_000;
pub const DefaultBridgeHubEthereumBaseFeeV2: Balance = 4_000_000_000;
pub storage BridgeHubEthereumBaseFee: Balance = DefaultBridgeHubEthereumBaseFee::get();
pub storage BridgeHubEthereumBaseFeeV2: Balance = DefaultBridgeHubEthereumBaseFeeV2::get();
pub SiblingBridgeHubWithEthereumInboundQueueInstance: Location = Location::new(
1,
[
Expand All @@ -689,6 +694,18 @@ pub mod bridging {
),
];

pub BridgeTableV2: sp_std::vec::Vec<NetworkExportTableItem> = sp_std::vec![
NetworkExportTableItem::new(
EthereumNetwork::get(),
Some(sp_std::vec![Junctions::Here]),
SiblingBridgeHub::get(),
Some((
XcmBridgeHubRouterFeeAssetId::get(),
BridgeHubEthereumBaseFeeV2::get(),
).into())
),
];

/// Universal aliases
pub UniversalAliases: BTreeSet<(Location, Junction)> = BTreeSet::from_iter(
sp_std::vec![
Expand All @@ -699,8 +716,18 @@ pub mod bridging {
pub EthereumBridgeTable: sp_std::vec::Vec<NetworkExportTableItem> = sp_std::vec::Vec::new().into_iter()
.chain(BridgeTable::get())
.collect();

pub EthereumBridgeTableV2: sp_std::vec::Vec<NetworkExportTableItem> = sp_std::vec::Vec::new().into_iter()
.chain(BridgeTableV2::get())
.collect();
}

pub type EthereumNetworkExportTableV2 =
snowbridge_router_primitives::outbound::XcmFilterExporter<
xcm_builder::NetworkExportTable<EthereumBridgeTableV2>,
snowbridge_router_primitives::outbound::XcmForSnowbridgeV2,
>;

pub type EthereumNetworkExportTable = xcm_builder::NetworkExportTable<EthereumBridgeTable>;

pub type IsTrustedBridgedReserveLocationForForeignAsset =
Expand Down