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

Commit

Permalink
starts with ethereum router
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Nov 2, 2023
1 parent 55305d2 commit 221ca22
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 30 deletions.
32 changes: 31 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,36 @@ impl pallet_xcm_bridge_hub_router::Config<ToRococoXcmRouterInstance> for Runtime
type WeightInfo = weights::pallet_xcm_bridge_hub_router_to_rococo::WeightInfo<Runtime>;

type UniversalLocation = xcm_config::UniversalLocation;
type BridgedNetworkId = ();
type BridgedNetworkId = xcm_config::bridging::to_rococo::RococoNetwork;
type Bridges = xcm_config::bridging::NetworkExportTable;

#[cfg(not(feature = "runtime-benchmarks"))]
type BridgeHubOrigin = EnsureXcm<Equals<xcm_config::bridging::SiblingBridgeHub>>;
#[cfg(feature = "runtime-benchmarks")]
type BridgeHubOrigin = EitherOfDiverse<
// for running benchmarks
EnsureRoot<AccountId>,
// for running tests with `--feature runtime-benchmarks`
EnsureXcm<Equals<xcm_config::bridging::SiblingBridgeHub>>,
>;

type ToBridgeHubSender = XcmpQueue;
type WithBridgeHubChannel =
cumulus_pallet_xcmp_queue::bridging::InAndOutXcmpChannelStatusProvider<
xcm_config::bridging::SiblingBridgeHubParaId,
Runtime,
>;

type ByteFee = xcm_config::bridging::XcmBridgeHubRouterByteFee;
type FeeAsset = xcm_config::bridging::XcmBridgeHubRouterFeeAssetId;
}

pub type ToEthereumXcmRouterInstance = pallet_assets::Instance3;
impl pallet_xcm_bridge_hub_router::Config<ToEthereumXcmRouterInstance> for Runtime {
type WeightInfo = weights::pallet_xcm_bridge_hub_router_to_rococo::WeightInfo<Runtime>; // TODO do for ethereum

type UniversalLocation = xcm_config::UniversalLocation;
type BridgedNetworkId = xcm_config::bridging::to_ethereum::EthereumNetwork;
type Bridges = xcm_config::bridging::NetworkExportTable;

#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down Expand Up @@ -936,6 +965,7 @@ construct_runtime!(
// Bridge utilities.
ToWococoXcmRouter: pallet_xcm_bridge_hub_router::<Instance1>::{Pallet, Storage, Call} = 43,
ToRococoXcmRouter: pallet_xcm_bridge_hub_router::<Instance2>::{Pallet, Storage, Call} = 44,
ToEthereumXcmRouter: pallet_xcm_bridge_hub_router::<Instance3>::{Pallet, Storage, Call} = 45,

// The main stage.
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ pub mod bridging {
sp_std::vec::Vec::new().into_iter()
.chain(to_wococo::BridgeTable::get())
.chain(to_rococo::BridgeTable::get())
.chain(to_ethereum::BridgeTable::get())
.collect();
}

Expand Down Expand Up @@ -872,18 +873,6 @@ pub mod bridging {
pub const RococoNetwork: NetworkId = NetworkId::Rococo;
pub AssetHubRococo: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(RococoNetwork::get()), Parachain(bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID)));
pub RocLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(RococoNetwork::get())));
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); // TODO: Maybe registry address belongs here

pub const EthereumGatewayAddress: [u8; 20] = hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39");
// The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets.
pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get()
.pushed_with_interior(
AccountKey20 {
network: None,
key: EthereumGatewayAddress::get(),
}
).unwrap();

pub RocFromAssetHubRococo: (MultiAssetFilter, MultiLocation) = (
Wild(AllOf { fun: WildFungible, id: Concrete(RocLocation::get()) }),
Expand All @@ -905,15 +894,6 @@ pub mod bridging {
bp_asset_hub_wococo::BridgeHubWococoBaseFeeInWocs::get(),
).into())
),
NetworkExportTableItem::new(
EthereumNetwork::get(),
None, // TODO add Ethereum network / gateway contract
SiblingBridgeHub::get(),
Some((
XcmBridgeHubRouterFeeAssetId::get(),
BridgeHubEthereumBaseFeeInRocs::get(),
).into())
),
];

/// Allowed assets for reserve transfer to `AssetHubWococo`.
Expand All @@ -923,15 +903,10 @@ pub mod bridging {
// and nothing else
];

pub AllowedReserveTransferAssetsToEthereum: sp_std::vec::Vec<MultiAssetFilter> = sp_std::vec![
Wild(AllOf { fun: WildFungible, id: Concrete(EthereumGatewayLocation::get()) }),
];

/// Universal aliases
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
sp_std::vec![
(SiblingBridgeHubWithBridgeHubRococoInstance::get(), GlobalConsensus(RococoNetwork::get())),
(SiblingBridgeHub::get(), GlobalConsensus(EthereumNetwork::get())),
]
);
}
Expand All @@ -954,9 +929,6 @@ pub mod bridging {
),
>;

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

/// Allows to reserve transfer assets to `AssetHubRococo`.
pub type AllowedReserveTransferAssets = LocationWithAssetFilters<
Equals<AssetHubRococo>,
Expand All @@ -975,6 +947,74 @@ pub mod bridging {
}
}

pub mod to_ethereum {
use super::*;
use assets_common::matching::FromNetwork;

parameter_types! {
pub SiblingBridgeHubWithBridgeHubRococoInstance: MultiLocation = MultiLocation::new(
1,
X2(
Parachain(SiblingBridgeHubParaId::get()),
PalletInstance(bp_bridge_hub_wococo::WITH_BRIDGE_WOCOCO_TO_ROCOCO_MESSAGES_PALLET_INDEX)
)
);

pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); // TODO: Maybe registry address belongs here
pub const EthereumGatewayAddress: [u8; 20] = hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39");
// The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets.
pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get()
.pushed_with_interior(
AccountKey20 {
network: None,
key: EthereumGatewayAddress::get(),
}
).unwrap();

/// Set up exporters configuration.
/// `Option<MultiAsset>` represents static "base fee" which is used for total delivery fee calculation.
pub BridgeTable: sp_std::vec::Vec<NetworkExportTableItem> = sp_std::vec![
NetworkExportTableItem::new(
EthereumNetwork::get(),
None, // TODO add Ethereum network / gateway contract
SiblingBridgeHub::get(),
Some((
XcmBridgeHubRouterFeeAssetId::get(),
BridgeHubEthereumBaseFeeInRocs::get(),
).into())
),
];

/// Universal aliases
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
sp_std::vec![
(SiblingBridgeHub::get(), GlobalConsensus(EthereumNetwork::get())),
]
);
}

impl Contains<(MultiLocation, Junction)> for UniversalAliases {
fn contains(alias: &(MultiLocation, Junction)) -> bool {
UniversalAliases::get().contains(alias)
}
}

pub type IsTrustedBridgedReserveLocationForForeignAsset =
IsForeignConcreteAsset<FromNetwork<EthereumNetwork>>;

impl Contains<RuntimeCall> for ToRococoXcmRouter {
fn contains(call: &RuntimeCall) -> bool {
matches!(
call,
RuntimeCall::ToEthereumXcmRouter(
pallet_xcm_bridge_hub_router::Call::report_bridge_status { .. }
)
)
}
}
}

/// Benchmarks helper for bridging configuration.
#[cfg(feature = "runtime-benchmarks")]
pub struct BridgingBenchmarksHelper;
Expand Down

0 comments on commit 221ca22

Please sign in to comment.