diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 895c4794675d..4737fc165f17 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -97,7 +97,7 @@ use xcm::latest::prelude::*; use xcm_executor::XcmExecutor; use crate::xcm_config::{ - bridging::to_rococo::EthereumGatewayLocation, ForeignCreatorsSovereignAccountOf, + bridging::to_wococo::EthereumLocation, ForeignCreatorsSovereignAccountOf, LocalAndForeignAssetsMultiLocationMatcher, TrustBackedAssetsPalletLocation, }; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -390,9 +390,7 @@ impl pallet_assets::Config for Runtime { type CreateOrigin = ForeignCreators< ( FromSiblingParachain>, - snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus< - EthereumGatewayLocation, - >, + snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus, ), ForeignCreatorsSovereignAccountOf, AccountId, diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index c96d9e2df8e3..bc9f17b79e18 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -22,7 +22,7 @@ use super::{ }; use assets_common::{ local_and_foreign_assets::MatchesLocalAndForeignAssetsMultiLocation, - matching::{FromSiblingParachain, IsForeignConcreteAsset}, + matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset}, }; use frame_support::{ match_types, parameter_types, @@ -42,7 +42,7 @@ use parachains_common::{ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::xcm_sender::ExponentialPrice; use rococo_runtime_constants::system_parachain::SystemParachains; -use snowbridge_router_primitives::inbound::GlobalConsensusEthereumAccountConvertsFor; +use snowbridge_router_primitives::inbound::GlobalConsensusEthereumConvertsFor; use sp_runtime::traits::{AccountIdConversion, ConvertInto}; use xcm::latest::prelude::*; use xcm_builder::{ @@ -114,7 +114,7 @@ pub type LocationToAccountId = ( GlobalConsensusParachainConvertsFor, // Ethereum contract sovereign account. // (Used to get convert ethereum contract locations to sovereign account) - GlobalConsensusEthereumAccountConvertsFor, + GlobalConsensusEthereumConvertsFor, ); /// Means for transacting the native currency on this chain. @@ -563,8 +563,8 @@ impl xcm_executor::Config for XcmConfig { // Users must use teleport where allowed (e.g. ROC with the Relay Chain). type IsReserve = ( bridging::to_wococo::IsTrustedBridgedReserveLocationForConcreteAsset, + bridging::to_wococo::IsTrustedBridgedReserveLocationForForeignAsset, bridging::to_rococo::IsTrustedBridgedReserveLocationForConcreteAsset, - bridging::to_rococo::IsTrustedBridgedReserveLocationForForeignAsset, ); type IsTeleporter = TrustedTeleporters; type UniversalLocation = UniversalLocation; @@ -700,7 +700,7 @@ pub type ForeignCreatorsSovereignAccountOf = ( SiblingParachainConvertsVia, AccountId32Aliases, ParentIsPreset, - GlobalConsensusEthereumAccountConvertsFor, + GlobalConsensusEthereumConvertsFor, ); /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. @@ -782,6 +782,8 @@ pub mod bridging { pub const WococoNetwork: NetworkId = NetworkId::Wococo; pub AssetHubWococo: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(WococoNetwork::get()), Parachain(bp_asset_hub_wococo::ASSET_HUB_WOCOCO_PARACHAIN_ID))); pub WocLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(WococoNetwork::get()))); + pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 }; + pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); pub WocFromAssetHubWococo: (MultiAssetFilter, MultiLocation) = ( Wild(AllOf { fun: WildFungible, id: Concrete(WocLocation::get()) }), @@ -802,7 +804,18 @@ pub mod bridging { XcmBridgeHubRouterFeeAssetId::get(), bp_asset_hub_rococo::BridgeHubRococoBaseFeeInRocs::get(), ).into()) - ) + ), + NetworkExportTableItem::new( + EthereumNetwork::get(), + Some(sp_std::vec![ + EthereumLocation::get().interior.split_global().expect("invalid configuration for Ethereum").1, + ]), + SiblingBridgeHub::get(), + Some(( + XcmBridgeHubRouterFeeAssetId::get(), + BridgeHubEthereumBaseFeeInRocs::get(), + ).into()) + ), ]; /// Allowed assets for reserve transfer to `AssetHubWococo`. @@ -815,11 +828,15 @@ pub mod bridging { /// Universal aliases pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter( sp_std::vec![ - (SiblingBridgeHubWithBridgeHubWococoInstance::get(), GlobalConsensus(WococoNetwork::get())) + (SiblingBridgeHubWithBridgeHubWococoInstance::get(), GlobalConsensus(WococoNetwork::get())), + (SiblingBridgeHub::get(), GlobalConsensus(EthereumNetwork::get())), ] ); } + pub type IsTrustedBridgedReserveLocationForForeignAsset = + matching::IsForeignConcreteAsset>; + impl Contains<(MultiLocation, Junction)> for UniversalAliases { fn contains(alias: &(MultiLocation, Junction)) -> bool { UniversalAliases::get().contains(alias) @@ -858,7 +875,6 @@ pub mod bridging { pub mod to_rococo { use super::*; - use assets_common::matching::FromNetwork; parameter_types! { pub SiblingBridgeHubWithBridgeHubRococoInstance: MultiLocation = MultiLocation::new( @@ -872,18 +888,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()) }), @@ -905,15 +909,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`. @@ -923,15 +918,10 @@ pub mod bridging { // and nothing else ]; - pub AllowedReserveTransferAssetsToEthereum: sp_std::vec::Vec = 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())), ] ); } @@ -954,9 +944,6 @@ pub mod bridging { ), >; - pub type IsTrustedBridgedReserveLocationForForeignAsset = - matching::IsForeignConcreteAsset>; - /// Allows to reserve transfer assets to `AssetHubRococo`. pub type AllowedReserveTransferAssets = LocationWithAssetFilters< Equals, diff --git a/cumulus/parachains/runtimes/assets/common/src/matching.rs b/cumulus/parachains/runtimes/assets/common/src/matching.rs index 6b0d8b0967e1..2f61a2824b09 100644 --- a/cumulus/parachains/runtimes/assets/common/src/matching.rs +++ b/cumulus/parachains/runtimes/assets/common/src/matching.rs @@ -63,8 +63,12 @@ pub struct FromNetwork(sp_std::marker::PhantomData impl> ContainsPair for FromNetwork { - fn contains(&a: &MultiLocation, _b: &MultiLocation) -> bool { - // TODO: check that a.starts_with(b) + 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 == SelfNetworkId::get()) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index dff547e72698..b2bd5bf5731b 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -86,7 +86,7 @@ use pallet_xcm::EnsureXcm; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm::VersionedMultiLocation; -use xcm_config::{EthereumGatewayAddress, XcmConfig, XcmOriginToTransactDispatchOrigin}; +use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; use bp_runtime::HeaderId; @@ -500,7 +500,7 @@ impl pallet_message_queue::Config for Runtime { parameter_types! { pub const Reward: u128 = 10; - pub const GatewayAddress: H160 = H160(EthereumGatewayAddress::get()); + pub const GatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39")); pub const CreateAssetCall: [u8;2] = [53, 0]; pub const CreateAssetExecutionFee: u128 = 2_000_000_000; pub const SendTokenExecutionFee: u128 = 1_000_000_000; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 4ff63f9b0cfe..c009891833a0 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -59,12 +59,11 @@ use xcm_builder::{ deposit_or_burn_fee, AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, - DescribeFamily, EnsureXcmOrigin, HandleFee, HashedDescription, IsConcrete, - ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, - XcmFeeToAccount, + DescribeFamily, EnsureXcmOrigin, HandleFee, HashedDescription, IsConcrete, ParentAsSuperuser, + ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeeManagerFromComponents, XcmFeeToAccount, }; use xcm_executor::{ traits::{ExportXcm, FeeReason, TransactAsset, WithOriginFilter}, @@ -85,16 +84,6 @@ parameter_types! { // Network and location for the local Ethereum testnet. pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 }; pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); - - 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(); } /// Adapter for resolving `NetworkId` based on `pub storage Flavor: RuntimeFlavor`. @@ -428,7 +417,7 @@ pub type AgentIdOf = HashedDescription pub type SnowbridgeExporter = EthereumBlobExporter< UniversalLocation, - EthereumGatewayLocation, + EthereumLocation, snowbridge_outbound_queue::Pallet, AgentIdOf, >; @@ -472,7 +461,7 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter { destination, message, ) - .map(|result| ((Ethereum { chain_id: 15 }, result.0), result.1)) // TODO get network ID + .map(|result| ((location, result.0), result.1)) }, _ => unimplemented!("Unsupported network: {:?}", network), }