From 1341a73eb44018a9ba67abcf79ec9f0e3e2b87a7 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 1 Nov 2023 22:45:14 +0200 Subject: [PATCH 1/4] remove gateway contract location --- .../assets/asset-hub-rococo/src/lib.rs | 4 ++-- .../assets/asset-hub-rococo/src/xcm_config.rs | 20 +++++-------------- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 ++-- .../bridge-hub-rococo/src/xcm_config.rs | 12 +---------- 4 files changed, 10 insertions(+), 30 deletions(-) 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..a273ea375867 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_rococo::EthereumLocation, ForeignCreatorsSovereignAccountOf, LocalAndForeignAssetsMultiLocationMatcher, TrustBackedAssetsPalletLocation, }; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -391,7 +391,7 @@ impl pallet_assets::Config for Runtime { ( FromSiblingParachain>, snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus< - EthereumGatewayLocation, + EthereumLocation, >, ), ForeignCreatorsSovereignAccountOf, 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..d144467ca9e7 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 @@ -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. @@ -700,7 +700,7 @@ pub type ForeignCreatorsSovereignAccountOf = ( SiblingParachainConvertsVia, AccountId32Aliases, ParentIsPreset, - GlobalConsensusEthereumAccountConvertsFor, + GlobalConsensusEthereumConvertsFor, ); /// Simple conversion of `u32` into an `AssetId` for use in benchmarking. @@ -873,17 +873,7 @@ pub mod bridging { 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 EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); pub RocFromAssetHubRococo: (MultiAssetFilter, MultiLocation) = ( Wild(AllOf { fun: WildFungible, id: Concrete(RocLocation::get()) }), @@ -924,7 +914,7 @@ pub mod bridging { ]; pub AllowedReserveTransferAssetsToEthereum: sp_std::vec::Vec = sp_std::vec![ - Wild(AllOf { fun: WildFungible, id: Concrete(EthereumGatewayLocation::get()) }), + Wild(AllOf { fun: WildFungible, id: Concrete(EthereumLocation::get()) }), ]; /// Universal aliases 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..f95ddc3b7e81 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 @@ -85,16 +85,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 +418,7 @@ pub type AgentIdOf = HashedDescription pub type SnowbridgeExporter = EthereumBlobExporter< UniversalLocation, - EthereumGatewayLocation, + EthereumLocation, snowbridge_outbound_queue::Pallet, AgentIdOf, >; From f79073bdc08439b5871de883c1b90b746ebcef4a Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 1 Nov 2023 22:50:44 +0200 Subject: [PATCH 2/4] fmt --- .../runtimes/assets/asset-hub-rococo/src/lib.rs | 4 +--- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 11 +++++------ 2 files changed, 6 insertions(+), 9 deletions(-) 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 a273ea375867..c35d3a1df2a9 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -390,9 +390,7 @@ impl pallet_assets::Config for Runtime { type CreateOrigin = ForeignCreators< ( FromSiblingParachain>, - snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus< - EthereumLocation, - >, + snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus, ), ForeignCreatorsSovereignAccountOf, AccountId, 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 f95ddc3b7e81..da389b8bd1f1 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}, From dba7cff62bc81e0e07a3bab47951edb35776a172 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 2 Nov 2023 14:07:50 +0200 Subject: [PATCH 3/4] remove todos --- .../runtimes/assets/asset-hub-rococo/src/xcm_config.rs | 8 +++----- cumulus/parachains/runtimes/assets/common/src/matching.rs | 8 ++++++-- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) 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 d144467ca9e7..d7fd4040805b 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 @@ -897,7 +897,9 @@ pub mod bridging { ), NetworkExportTableItem::new( EthereumNetwork::get(), - None, // TODO add Ethereum network / gateway contract + Some(sp_std::vec![ + EthereumLocation::get().interior, + ]), SiblingBridgeHub::get(), Some(( XcmBridgeHubRouterFeeAssetId::get(), @@ -913,10 +915,6 @@ pub mod bridging { // and nothing else ]; - pub AllowedReserveTransferAssetsToEthereum: sp_std::vec::Vec = sp_std::vec![ - Wild(AllOf { fun: WildFungible, id: Concrete(EthereumLocation::get()) }), - ]; - /// Universal aliases pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter( sp_std::vec![ 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/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index da389b8bd1f1..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 @@ -461,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), } From 0ee181e76f58625815d7be9b6993936cbcc4c266 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Fri, 3 Nov 2023 02:53:06 +0200 Subject: [PATCH 4/4] use the correct bridge config --- .../assets/asset-hub-rococo/src/lib.rs | 2 +- .../assets/asset-hub-rococo/src/xcm_config.rs | 43 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) 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 c35d3a1df2a9..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::EthereumLocation, ForeignCreatorsSovereignAccountOf, + bridging::to_wococo::EthereumLocation, ForeignCreatorsSovereignAccountOf, LocalAndForeignAssetsMultiLocationMatcher, TrustBackedAssetsPalletLocation, }; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; 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 d7fd4040805b..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, @@ -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; @@ -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,8 +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()))); pub RocFromAssetHubRococo: (MultiAssetFilter, MultiLocation) = ( Wild(AllOf { fun: WildFungible, id: Concrete(RocLocation::get()) }), @@ -895,17 +909,6 @@ pub mod bridging { bp_asset_hub_wococo::BridgeHubWococoBaseFeeInWocs::get(), ).into()) ), - NetworkExportTableItem::new( - EthereumNetwork::get(), - Some(sp_std::vec![ - EthereumLocation::get().interior, - ]), - SiblingBridgeHub::get(), - Some(( - XcmBridgeHubRouterFeeAssetId::get(), - BridgeHubEthereumBaseFeeInRocs::get(), - ).into()) - ), ]; /// Allowed assets for reserve transfer to `AssetHubWococo`. @@ -919,7 +922,6 @@ pub mod bridging { pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter( sp_std::vec![ (SiblingBridgeHubWithBridgeHubRococoInstance::get(), GlobalConsensus(RococoNetwork::get())), - (SiblingBridgeHub::get(), GlobalConsensus(EthereumNetwork::get())), ] ); } @@ -942,9 +944,6 @@ pub mod bridging { ), >; - pub type IsTrustedBridgedReserveLocationForForeignAsset = - matching::IsForeignConcreteAsset>; - /// Allows to reserve transfer assets to `AssetHubRococo`. pub type AllowedReserveTransferAssets = LocationWithAssetFilters< Equals,