From 69fab337d12912305daf888fc8e9cbf4774f89f9 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 8 Nov 2023 20:46:17 +0200 Subject: [PATCH 01/22] re-use pallet --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 b2bd5bf5731b..cdab65a32600 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 @@ -107,7 +107,7 @@ use parachains_common::{ impls::DealWithFees, rococo::{consensus::*, currency::*, fee::WeightToFee}, AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, - HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, + HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, TREASURY_PALLET_ID }; use xcm_executor::XcmExecutor; @@ -605,7 +605,7 @@ parameter_types! { } parameter_types! { - pub TreasuryAccount: AccountId = PalletId(*b"py/trsry").into_account_truncating(); + pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); } #[cfg(feature = "runtime-benchmarks")] From f68398cd02300d4e4af71c541a92aa836fdde181 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 8 Nov 2023 21:54:50 +0200 Subject: [PATCH 02/22] added fee handler trait --- .../bridge-hub-rococo/src/xcm_config.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) 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 4dc49d8da360..246b50320114 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 @@ -317,6 +317,11 @@ impl xcm_executor::Config for XcmConfig { BridgeHubRococoChainId, BridgeHubRococoMessagesLane, >, + XcmExportFeeToSnowbridge< + EthereumNetwork, + TreasuryAccount, + Self::AssetTransactor, + >, XcmFeeToAccount, ), >; @@ -572,3 +577,42 @@ impl< fee } } + +/// A `HandleFee` implementation that takes fees from `ExportMessage` XCM instructions +/// to Snowbridge and holds it in a receiver account. Burns the fees in case of a failure. +pub struct XcmExportFeeToSnowbridge( + PhantomData<(EthereumNetwork, ReceiverAccount, AssetTransactor)>, +); + +impl< + EthereumNetwork: Get, + ReceiverAccount: Get, + AssetTransactor: TransactAsset, + > HandleFee for XcmExportFeeToSnowbridge +{ + fn handle_fee( + fees: MultiAssets, + context: Option<&XcmContext>, + reason: FeeReason, + ) -> MultiAssets { + if matches!(reason, FeeReason::Export { network: bridged_network, destination } + if bridged_network == EthereumNetwork::get() && destination == Here) + { + log::info!( + target: "xcm::fees", + "XcmExportFeeToSnowbridge fees: {fees:?}, context: {context:?}, reason: {reason:?}", + ); + + let receiver = ReceiverAccount::get(); + deposit_or_burn_fee::( + fees, + context, + receiver, + ); + + return MultiAssets::new() + } + + fees + } +} \ No newline at end of file From 3270200911cfb16c1fbd283ce02933f4bfbb35d4 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 8 Nov 2023 22:08:09 +0200 Subject: [PATCH 03/22] whitespace --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 246b50320114..41feb5cc17c5 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 @@ -615,4 +615,4 @@ impl< fees } -} \ No newline at end of file +} From 351b71aafd7b7071c0d545cb36cf108db31a9472 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 8 Nov 2023 23:02:19 +0200 Subject: [PATCH 04/22] move to treasury to snowbridge sovereign --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 ++-- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) 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 cdab65a32600..5b27fb4fd06b 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::{XcmConfig, XcmOriginToTransactDispatchOrigin}; +use xcm_config::{SnowbridgeTreasuryAccount, XcmConfig, XcmOriginToTransactDispatchOrigin}; use bp_runtime::HeaderId; @@ -622,7 +622,7 @@ impl snowbridge_control::Config for Runtime { type MessageHasher = BlakeTwo256; type SiblingOrigin = EnsureXcm; type AgentIdOf = xcm_config::AgentIdOf; - type TreasuryAccount = TreasuryAccount; + type TreasuryAccount = SnowbridgeTreasuryAccount; type Token = Balances; type WeightInfo = weights::snowbridge_control::WeightInfo; #[cfg(feature = "runtime-benchmarks")] 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 41feb5cc17c5..ffc136a30ffe 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 @@ -50,7 +50,10 @@ 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::outbound::EthereumBlobExporter; +use snowbridge_router_primitives::{ + inbound::GlobalConsensusEthereumConvertsFor, + outbound::EthereumBlobExporter, +}; use sp_core::{Get, H256}; use sp_runtime::traits::AccountIdConversion; use sp_std::marker::PhantomData; @@ -82,7 +85,9 @@ parameter_types! { pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into(); // Network and location for the local Ethereum testnet. - pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 }; + pub const EthereumChainId: u64 = 15; + pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: EthereumChainId::get() }; + pub SnowbridgeTreasuryAccount: AccountId = GlobalConsensusEthereumConvertsFor::::from_chain_id(&EthereumChainId::get()).into(); } /// Adapter for resolving `NetworkId` based on `pub storage Flavor: RuntimeFlavor`. @@ -319,7 +324,7 @@ impl xcm_executor::Config for XcmConfig { >, XcmExportFeeToSnowbridge< EthereumNetwork, - TreasuryAccount, + SnowbridgeTreasuryAccount, Self::AssetTransactor, >, XcmFeeToAccount, From e254d6a1ebee5292658e5569aa267b2b083e6da0 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 8 Nov 2023 23:04:13 +0200 Subject: [PATCH 05/22] remove treasury --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) 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 5b27fb4fd06b..415e4d7fc48b 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 @@ -604,10 +604,6 @@ parameter_types! { pub const RelayNetwork: NetworkId = Rococo; } -parameter_types! { - pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); -} - #[cfg(feature = "runtime-benchmarks")] impl snowbridge_control::BenchmarkHelper for () { fn make_xcm_origin(location: xcm::latest::MultiLocation) -> RuntimeOrigin { From 5db326e05d04b74ca796a53e4b1f3fc40e6bda69 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 8 Nov 2023 23:05:46 +0200 Subject: [PATCH 06/22] remove TREASURY_PALLET_ID --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 415e4d7fc48b..9a3f0d2c6ce0 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 @@ -107,7 +107,7 @@ use parachains_common::{ impls::DealWithFees, rococo::{consensus::*, currency::*, fee::WeightToFee}, AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, AVERAGE_ON_INITIALIZE_RATIO, - HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, TREASURY_PALLET_ID + HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; use xcm_executor::XcmExecutor; From 69d9991275efbc93c890de763017cc1760650791 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Wed, 8 Nov 2023 23:07:45 +0200 Subject: [PATCH 07/22] remove unused imports --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9a3f0d2c6ce0..9399f0ea833e 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 @@ -45,7 +45,7 @@ use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Keccak256}, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Keccak256}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, }; From d9fed1c7502ed073b67902f65b8c1126705c95a0 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 03:08:38 +0200 Subject: [PATCH 08/22] add fee trait --- .../bridge-hub-rococo/src/xcm_config.rs | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) 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 ffc136a30ffe..71ab3e870a2d 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 @@ -54,6 +54,7 @@ use snowbridge_router_primitives::{ inbound::GlobalConsensusEthereumConvertsFor, outbound::EthereumBlobExporter, }; +use snowbridge_core::outbound::OutboundQueueLocalFee; use sp_core::{Get, H256}; use sp_runtime::traits::AccountIdConversion; use sp_std::marker::PhantomData; @@ -326,6 +327,7 @@ impl xcm_executor::Config for XcmConfig { EthereumNetwork, SnowbridgeTreasuryAccount, Self::AssetTransactor, + crate::EthereumOutboundQueue, >, XcmFeeToAccount, ), @@ -585,15 +587,16 @@ impl< /// A `HandleFee` implementation that takes fees from `ExportMessage` XCM instructions /// to Snowbridge and holds it in a receiver account. Burns the fees in case of a failure. -pub struct XcmExportFeeToSnowbridge( - PhantomData<(EthereumNetwork, ReceiverAccount, AssetTransactor)>, +pub struct XcmExportFeeToSnowbridge( + PhantomData<(EthereumNetwork, ReceiverAccount, AssetTransactor, OutboundQueue)>, ); impl< EthereumNetwork: Get, ReceiverAccount: Get, AssetTransactor: TransactAsset, - > HandleFee for XcmExportFeeToSnowbridge + OutboundQueue: OutboundQueueLocalFee, + > HandleFee for XcmExportFeeToSnowbridge { fn handle_fee( fees: MultiAssets, @@ -609,13 +612,21 @@ impl< ); let receiver = ReceiverAccount::get(); - deposit_or_burn_fee::( - fees, - context, - receiver, - ); - return MultiAssets::new() + if let Some(XcmContext{ origin: Some(origin), ..}) = context { + // There is an origin so split fee into parts. + let local_fee = OutboundQueue::calculate_local_fee(); + + } else { + // There is no context so send the full fee to the receiver + deposit_or_burn_fee::( + fees, + context, + receiver, + ); + } + + return fees; } fees From 20a41aeebf09c4bed9df21e41bc2ab6a67e1e671 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 03:09:19 +0200 Subject: [PATCH 09/22] fix error --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 71ab3e870a2d..ba43dfc03124 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 @@ -616,7 +616,7 @@ impl< if let Some(XcmContext{ origin: Some(origin), ..}) = context { // There is an origin so split fee into parts. let local_fee = OutboundQueue::calculate_local_fee(); - + } else { // There is no context so send the full fee to the receiver deposit_or_burn_fee::( @@ -626,7 +626,7 @@ impl< ); } - return fees; + return MultiAssets::new(); } fees From 42c0e88608b8f84eb840c38589a522805583c7cd Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 04:17:37 +0200 Subject: [PATCH 10/22] added full logic --- .../bridge-hub-rococo/src/xcm_config.rs | 101 ++++++++++++++---- 1 file changed, 83 insertions(+), 18 deletions(-) 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 ba43dfc03124..c062790f43f4 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 @@ -70,7 +70,7 @@ use xcm_builder::{ XcmFeeManagerFromComponents, XcmFeeToAccount, }; use xcm_executor::{ - traits::{ExportXcm, FeeReason, TransactAsset, WithOriginFilter}, + traits::{ConvertLocation, ExportXcm, FeeReason, TransactAsset, WithOriginFilter}, XcmExecutor, }; @@ -324,8 +324,10 @@ impl xcm_executor::Config for XcmConfig { BridgeHubRococoMessagesLane, >, XcmExportFeeToSnowbridge< + TokenLocation, EthereumNetwork, SnowbridgeTreasuryAccount, + LocationToAccountId, Self::AssetTransactor, crate::EthereumOutboundQueue, >, @@ -587,22 +589,49 @@ impl< /// A `HandleFee` implementation that takes fees from `ExportMessage` XCM instructions /// to Snowbridge and holds it in a receiver account. Burns the fees in case of a failure. -pub struct XcmExportFeeToSnowbridge( - PhantomData<(EthereumNetwork, ReceiverAccount, AssetTransactor, OutboundQueue)>, +pub struct XcmExportFeeToSnowbridge< + TokenLocation, + EthereumNetwork, + ReceiverAccount, + SovereignAccountOf, + AssetTransactor, + OutboundQueue, +>( + PhantomData<( + TokenLocation, + EthereumNetwork, + ReceiverAccount, + SovereignAccountOf, + AssetTransactor, + OutboundQueue, + )>, ); impl< + TokenLocation: Get, EthereumNetwork: Get, ReceiverAccount: Get, + SovereignAccountOf: ConvertLocation, AssetTransactor: TransactAsset, OutboundQueue: OutboundQueueLocalFee, - > HandleFee for XcmExportFeeToSnowbridge + > HandleFee + for XcmExportFeeToSnowbridge< + TokenLocation, + EthereumNetwork, + ReceiverAccount, + SovereignAccountOf, + AssetTransactor, + OutboundQueue, + > { fn handle_fee( fees: MultiAssets, context: Option<&XcmContext>, reason: FeeReason, ) -> MultiAssets { + let token_location = TokenLocation::get(); + let mut fees = fees.into_inner(); + if matches!(reason, FeeReason::Export { network: bridged_network, destination } if bridged_network == EthereumNetwork::get() && destination == Here) { @@ -611,24 +640,60 @@ impl< "XcmExportFeeToSnowbridge fees: {fees:?}, context: {context:?}, reason: {reason:?}", ); - let receiver = ReceiverAccount::get(); - - if let Some(XcmContext{ origin: Some(origin), ..}) = context { - // There is an origin so split fee into parts. - let local_fee = OutboundQueue::calculate_local_fee(); + let fee_item_index = fees.iter().position(|asset| { + matches!( + asset, + MultiAsset { id: Concrete(location), fun: Fungible(..)} + if *location == token_location, + ) + }); + // Find the fee asset. + let fee_item = if let Some(element) = fee_item_index { + fees.remove(element) + } else { + return fees.into() + }; + let receiver = ReceiverAccount::get(); + // There is an origin so split fee into parts. + if let Some(XcmContext { origin: Some(origin), .. }) = context { + if let Some(origin) = SovereignAccountOf::convert_location(origin) { + let local_fee = OutboundQueue::calculate_local_fee(); + if let Fungible(amount) = fee_item.fun { + let remote_fee = amount.checked_sub(local_fee).unwrap_or(0); + + // Send local fee to receiver + deposit_or_burn_fee::( + MultiAsset { + id: Concrete(token_location), + fun: Fungible(amount - remote_fee), + } + .into(), + context, + receiver, + ); + // Send remote fee to origin + deposit_or_burn_fee::( + MultiAsset { id: Concrete(token_location), fun: Fungible(remote_fee) } + .into(), + context, + origin, + ); + } else { + // Push the fee item back and bail out to let other handlers run. + fees.push(fee_item); + return fees.into() + } + } else { + // Origin conversion failed so send the full fee to the receiver. + deposit_or_burn_fee::(fee_item.into(), context, receiver); + } } else { - // There is no context so send the full fee to the receiver - deposit_or_burn_fee::( - fees, - context, - receiver, - ); + // There is no context so send the full fee to the receiver. + deposit_or_burn_fee::(fee_item.into(), context, receiver); } - - return MultiAssets::new(); } - fees + fees.into() } } From f3bfe27e665b09fb5840fb5f2674ec450ba1e900 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 06:24:41 +0200 Subject: [PATCH 11/22] adds tests --- Cargo.lock | 1 + .../bridges/bridge-hub-rococo/Cargo.toml | 1 + .../bridge-hub-rococo/src/tests/snowbridge.rs | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 355cb54b6a97..6042c552ca68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2273,6 +2273,7 @@ dependencies = [ "hex-literal", "integration-tests-common", "pallet-assets", + "pallet-balances", "pallet-bridge-messages", "pallet-xcm", "parachains-common", diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml index 3c83ed80803b..354d0489dd66 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/Cargo.toml @@ -19,6 +19,7 @@ hex-literal = "0.4.1" sp-core = { path = "../../../../../../substrate/primitives/core", default-features = false} frame-support = { path = "../../../../../../substrate/frame/support", default-features = false } pallet-assets = { path = "../../../../../../substrate/frame/assets", default-features = false } +pallet-balances = { path = "../../../../../../substrate/frame/balances", default-features = false } # Polkadot polkadot-core-primitives = { path = "../../../../../../polkadot/core-primitives", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 1b1e8be64c1b..ea78df2f81d7 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -385,5 +385,24 @@ fn reserve_transfer_token() { RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, ] ); + let events = BridgeHubRococo::events(); + assert!( + events.iter().find(|&event| matches!( + event, + RuntimeEvent::Balances(pallet_balances::Event::Deposit{ who, amount }) + if *who == SNOWBRIDGE_SOVEREIGN.into() && *amount == 16903333 + )) + .is_some(), + "Snowbridge sovereign takes local fee." + ); + assert!( + events.iter().find(|&event| matches!( + event, + RuntimeEvent::Balances(pallet_balances::Event::Deposit{ who, amount }) + if *who == ASSETHUB_SOVEREIGN.into() && *amount == 2200000000000 + )) + .is_some(), + "Assethub sovereign takes remote fee." + ); }); } From 1622650bbaa1f06193a2cad1223bfa743194c06c Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 08:32:11 +0200 Subject: [PATCH 12/22] renamed trait --- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 c062790f43f4..a579e5b1fb86 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 @@ -50,11 +50,11 @@ 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_core::outbound::SendMessageFee; use snowbridge_router_primitives::{ inbound::GlobalConsensusEthereumConvertsFor, outbound::EthereumBlobExporter, }; -use snowbridge_core::outbound::OutboundQueueLocalFee; use sp_core::{Get, H256}; use sp_runtime::traits::AccountIdConversion; use sp_std::marker::PhantomData; @@ -613,7 +613,7 @@ impl< ReceiverAccount: Get, SovereignAccountOf: ConvertLocation, AssetTransactor: TransactAsset, - OutboundQueue: OutboundQueueLocalFee, + OutboundQueue: SendMessageFee, > HandleFee for XcmExportFeeToSnowbridge< TokenLocation, @@ -658,7 +658,7 @@ impl< // There is an origin so split fee into parts. if let Some(XcmContext { origin: Some(origin), .. }) = context { if let Some(origin) = SovereignAccountOf::convert_location(origin) { - let local_fee = OutboundQueue::calculate_local_fee(); + let local_fee = OutboundQueue::local_fee(); if let Fungible(amount) = fee_item.fun { let remote_fee = amount.checked_sub(local_fee).unwrap_or(0); From 0c142dbaf5bb501f69527f3650ebcce9f84b989a Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 13:33:04 +0200 Subject: [PATCH 13/22] use siblings --- .../bridge-hub-rococo/src/xcm_config.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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 a579e5b1fb86..c6fd1282803f 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 @@ -50,7 +50,10 @@ 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_core::outbound::SendMessageFee; +use snowbridge_core::{ + outbound::SendMessageFee, + sibling_sovereign_account_raw +}; use snowbridge_router_primitives::{ inbound::GlobalConsensusEthereumConvertsFor, outbound::EthereumBlobExporter, @@ -70,7 +73,7 @@ use xcm_builder::{ XcmFeeManagerFromComponents, XcmFeeToAccount, }; use xcm_executor::{ - traits::{ConvertLocation, ExportXcm, FeeReason, TransactAsset, WithOriginFilter}, + traits::{ExportXcm, FeeReason, TransactAsset, WithOriginFilter}, XcmExecutor, }; @@ -327,7 +330,6 @@ impl xcm_executor::Config for XcmConfig { TokenLocation, EthereumNetwork, SnowbridgeTreasuryAccount, - LocationToAccountId, Self::AssetTransactor, crate::EthereumOutboundQueue, >, @@ -593,7 +595,6 @@ pub struct XcmExportFeeToSnowbridge< TokenLocation, EthereumNetwork, ReceiverAccount, - SovereignAccountOf, AssetTransactor, OutboundQueue, >( @@ -601,7 +602,6 @@ pub struct XcmExportFeeToSnowbridge< TokenLocation, EthereumNetwork, ReceiverAccount, - SovereignAccountOf, AssetTransactor, OutboundQueue, )>, @@ -611,7 +611,6 @@ impl< TokenLocation: Get, EthereumNetwork: Get, ReceiverAccount: Get, - SovereignAccountOf: ConvertLocation, AssetTransactor: TransactAsset, OutboundQueue: SendMessageFee, > HandleFee @@ -619,7 +618,6 @@ impl< TokenLocation, EthereumNetwork, ReceiverAccount, - SovereignAccountOf, AssetTransactor, OutboundQueue, > @@ -656,8 +654,9 @@ impl< let receiver = ReceiverAccount::get(); // There is an origin so split fee into parts. - if let Some(XcmContext { origin: Some(origin), .. }) = context { - if let Some(origin) = SovereignAccountOf::convert_location(origin) { + if let Some(XcmContext { origin: Some(MultiLocation { parents: 1, interior }), .. }) = context { + if let Some(Parachain(sibling_para_id)) = interior.first() { + let account: AccountId = sibling_sovereign_account_raw((*sibling_para_id).into()).into(); let local_fee = OutboundQueue::local_fee(); if let Fungible(amount) = fee_item.fun { let remote_fee = amount.checked_sub(local_fee).unwrap_or(0); @@ -677,7 +676,7 @@ impl< MultiAsset { id: Concrete(token_location), fun: Fungible(remote_fee) } .into(), context, - origin, + account, ); } else { // Push the fee item back and bail out to let other handlers run. From b971a09e9bd283ab62cf504dc52605c48625dbbf Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 17:14:27 +0200 Subject: [PATCH 14/22] address feedback --- .../bridge-hub-rococo/src/tests/snowbridge.rs | 5 +++-- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 ++-- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 12 ++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index ea78df2f81d7..4e80b92d8b05 100644 --- a/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -12,7 +12,6 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - use crate::*; use hex_literal::hex; use integration_tests_common::{AssetHubRococoPallet, BridgeHubRococoPallet}; @@ -25,6 +24,8 @@ const CHAIN_ID: u64 = 15; const DEST_PARA_ID: u32 = 1000; const SNOWBRIDGE_SOVEREIGN: [u8; 32] = hex!("da4d66c3651dc151264eee5460493210338e41a7bbfca91a520e438daf180bf5"); +const TREASURY_ACCOUNT: [u8; 32] = + hex!("6d6f646c70792f74727372790000000000000000000000000000000000000000"); const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d"); const ASSETHUB_SOVEREIGN: [u8; 32] = hex!("7369626ce8030000000000000000000000000000000000000000000000000000"); @@ -390,7 +391,7 @@ fn reserve_transfer_token() { events.iter().find(|&event| matches!( event, RuntimeEvent::Balances(pallet_balances::Event::Deposit{ who, amount }) - if *who == SNOWBRIDGE_SOVEREIGN.into() && *amount == 16903333 + if *who == TREASURY_ACCOUNT.into() && *amount == 16903333 )) .is_some(), "Snowbridge sovereign takes local fee." 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 9399f0ea833e..073e44558744 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::{SnowbridgeTreasuryAccount, XcmConfig, XcmOriginToTransactDispatchOrigin}; +use xcm_config::{TreasuryAccount, XcmConfig, XcmOriginToTransactDispatchOrigin}; use bp_runtime::HeaderId; @@ -618,7 +618,7 @@ impl snowbridge_control::Config for Runtime { type MessageHasher = BlakeTwo256; type SiblingOrigin = EnsureXcm; type AgentIdOf = xcm_config::AgentIdOf; - type TreasuryAccount = SnowbridgeTreasuryAccount; + type TreasuryAccount = TreasuryAccount; type Token = Balances; type WeightInfo = weights::snowbridge_control::WeightInfo; #[cfg(feature = "runtime-benchmarks")] 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 c6fd1282803f..a201c5da019d 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 @@ -51,13 +51,10 @@ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::xcm_sender::ExponentialPrice; use rococo_runtime_constants::system_parachain::SystemParachains; use snowbridge_core::{ - outbound::SendMessageFee, + outbound::SendMessageFeeProvider, sibling_sovereign_account_raw }; -use snowbridge_router_primitives::{ - inbound::GlobalConsensusEthereumConvertsFor, - outbound::EthereumBlobExporter, -}; +use snowbridge_router_primitives:: outbound::EthereumBlobExporter; use sp_core::{Get, H256}; use sp_runtime::traits::AccountIdConversion; use sp_std::marker::PhantomData; @@ -91,7 +88,6 @@ parameter_types! { // Network and location for the local Ethereum testnet. pub const EthereumChainId: u64 = 15; pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: EthereumChainId::get() }; - pub SnowbridgeTreasuryAccount: AccountId = GlobalConsensusEthereumConvertsFor::::from_chain_id(&EthereumChainId::get()).into(); } /// Adapter for resolving `NetworkId` based on `pub storage Flavor: RuntimeFlavor`. @@ -329,7 +325,7 @@ impl xcm_executor::Config for XcmConfig { XcmExportFeeToSnowbridge< TokenLocation, EthereumNetwork, - SnowbridgeTreasuryAccount, + TreasuryAccount, Self::AssetTransactor, crate::EthereumOutboundQueue, >, @@ -612,7 +608,7 @@ impl< EthereumNetwork: Get, ReceiverAccount: Get, AssetTransactor: TransactAsset, - OutboundQueue: SendMessageFee, + OutboundQueue: SendMessageFeeProvider, > HandleFee for XcmExportFeeToSnowbridge< TokenLocation, From 8bfa0c17028f25e5dc21277741c0d537de7428d6 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 18:00:53 +0200 Subject: [PATCH 15/22] add snowbridge-runtime-common --- Cargo.lock | 14 +++ .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 25 ++-- .../bridge-hub-rococo/src/xcm_config.rs | 115 +----------------- 3 files changed, 30 insertions(+), 124 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6042c552ca68..be0cac4b7b2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2362,6 +2362,7 @@ dependencies = [ "snowbridge-outbound-queue", "snowbridge-outbound-queue-runtime-api", "snowbridge-router-primitives", + "snowbridge-runtime-common", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -17285,6 +17286,19 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "snowbridge-runtime-common" +version = "0.1.1" +dependencies = [ + "bp-rococo", + "frame-support", + "log", + "snowbridge-core", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", +] + [[package]] name = "socket2" version = "0.4.9" diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 2eb4e54bc9d6..b9ed51fa4130 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -94,15 +94,16 @@ pallet-bridge-relayers = { path = "../../../../../bridges/modules/relayers", def bridge-runtime-common = { path = "../../../../../bridges/bin/runtime-common", default-features = false } # Ethereum Bridge (Snowbridge) -snowbridge-core = { path = "../../../../../../parachain/primitives/core", default-features = false } snowbridge-beacon-primitives = { path = "../../../../../../parachain/primitives/beacon", default-features = false } -snowbridge-router-primitives = { path = "../../../../../../parachain/primitives/router", default-features = false } +snowbridge-control = { path = "../../../../../../parachain/pallets/control", default-features = false } +snowbridge-control-runtime-api = { path = "../../../../../../parachain/pallets/control/runtime-api", default-features = false } +snowbridge-core = { path = "../../../../../../parachain/primitives/core", default-features = false } snowbridge-ethereum-beacon-client = { path = "../../../../../../parachain/pallets/ethereum-beacon-client", default-features = false } snowbridge-inbound-queue = { path = "../../../../../../parachain/pallets/inbound-queue", default-features = false } snowbridge-outbound-queue = { path = "../../../../../../parachain/pallets/outbound-queue", default-features = false } snowbridge-outbound-queue-runtime-api = { path = "../../../../../../parachain/pallets/outbound-queue/runtime-api", default-features = false } -snowbridge-control = { path = "../../../../../../parachain/pallets/control", default-features = false } -snowbridge-control-runtime-api = { path = "../../../../../../parachain/pallets/control/runtime-api", default-features = false } +snowbridge-router-primitives = { path = "../../../../../../parachain/primitives/router", default-features = false } +snowbridge-runtime-common = { path = "../../../../../../parachain/primitives/runtime-common", default-features = false } [dev-dependencies] static_assertions = "1.1" @@ -186,15 +187,16 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "snowbridge-core/std", - "snowbridge-router-primitives/std", "snowbridge-beacon-primitives/std", + "snowbridge-control-runtime-api/std", + "snowbridge-control/std", + "snowbridge-core/std", "snowbridge-ethereum-beacon-client/std", "snowbridge-inbound-queue/std", - "snowbridge-outbound-queue/std", "snowbridge-outbound-queue-runtime-api/std", - "snowbridge-control/std", - "snowbridge-control-runtime-api/std", + "snowbridge-outbound-queue/std", + "snowbridge-router-primitives/std", + "snowbridge-runtime-common/std", "substrate-wasm-builder", ] @@ -225,11 +227,12 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "snowbridge-core/runtime-benchmarks", "snowbridge-control/runtime-benchmarks", + "snowbridge-core/runtime-benchmarks", + "snowbridge-ethereum-beacon-client/runtime-benchmarks", "snowbridge-inbound-queue/runtime-benchmarks", "snowbridge-outbound-queue/runtime-benchmarks", - "snowbridge-ethereum-beacon-client/runtime-benchmarks" + "snowbridge-runtime-common/runtime-benchmarks", ] try-runtime = [ 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 a201c5da019d..162610b0bd14 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 @@ -50,11 +50,8 @@ 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_core::{ - outbound::SendMessageFeeProvider, - sibling_sovereign_account_raw -}; use snowbridge_router_primitives:: outbound::EthereumBlobExporter; +use snowbridge_runtime_common::XcmExportFeeToSnowbridge; use sp_core::{Get, H256}; use sp_runtime::traits::AccountIdConversion; use sp_std::marker::PhantomData; @@ -583,112 +580,4 @@ impl< fee } -} - -/// A `HandleFee` implementation that takes fees from `ExportMessage` XCM instructions -/// to Snowbridge and holds it in a receiver account. Burns the fees in case of a failure. -pub struct XcmExportFeeToSnowbridge< - TokenLocation, - EthereumNetwork, - ReceiverAccount, - AssetTransactor, - OutboundQueue, ->( - PhantomData<( - TokenLocation, - EthereumNetwork, - ReceiverAccount, - AssetTransactor, - OutboundQueue, - )>, -); - -impl< - TokenLocation: Get, - EthereumNetwork: Get, - ReceiverAccount: Get, - AssetTransactor: TransactAsset, - OutboundQueue: SendMessageFeeProvider, - > HandleFee - for XcmExportFeeToSnowbridge< - TokenLocation, - EthereumNetwork, - ReceiverAccount, - AssetTransactor, - OutboundQueue, - > -{ - fn handle_fee( - fees: MultiAssets, - context: Option<&XcmContext>, - reason: FeeReason, - ) -> MultiAssets { - let token_location = TokenLocation::get(); - let mut fees = fees.into_inner(); - - if matches!(reason, FeeReason::Export { network: bridged_network, destination } - if bridged_network == EthereumNetwork::get() && destination == Here) - { - log::info!( - target: "xcm::fees", - "XcmExportFeeToSnowbridge fees: {fees:?}, context: {context:?}, reason: {reason:?}", - ); - - let fee_item_index = fees.iter().position(|asset| { - matches!( - asset, - MultiAsset { id: Concrete(location), fun: Fungible(..)} - if *location == token_location, - ) - }); - // Find the fee asset. - let fee_item = if let Some(element) = fee_item_index { - fees.remove(element) - } else { - return fees.into() - }; - - let receiver = ReceiverAccount::get(); - // There is an origin so split fee into parts. - if let Some(XcmContext { origin: Some(MultiLocation { parents: 1, interior }), .. }) = context { - if let Some(Parachain(sibling_para_id)) = interior.first() { - let account: AccountId = sibling_sovereign_account_raw((*sibling_para_id).into()).into(); - let local_fee = OutboundQueue::local_fee(); - if let Fungible(amount) = fee_item.fun { - let remote_fee = amount.checked_sub(local_fee).unwrap_or(0); - - // Send local fee to receiver - deposit_or_burn_fee::( - MultiAsset { - id: Concrete(token_location), - fun: Fungible(amount - remote_fee), - } - .into(), - context, - receiver, - ); - // Send remote fee to origin - deposit_or_burn_fee::( - MultiAsset { id: Concrete(token_location), fun: Fungible(remote_fee) } - .into(), - context, - account, - ); - } else { - // Push the fee item back and bail out to let other handlers run. - fees.push(fee_item); - return fees.into() - } - } else { - // Origin conversion failed so send the full fee to the receiver. - deposit_or_burn_fee::(fee_item.into(), context, receiver); - } - } else { - // There is no context so send the full fee to the receiver. - deposit_or_burn_fee::(fee_item.into(), context, receiver); - } - } - - fees.into() - } -} +} \ No newline at end of file From 114f5524c7cc990b916997d23ad2ac73c1bb5281 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 18:55:40 +0200 Subject: [PATCH 16/22] fix build --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index be0cac4b7b2e..9ebd15a6d1d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17294,6 +17294,7 @@ dependencies = [ "frame-support", "log", "snowbridge-core", + "sp-io", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", From 2afe5bb6e0c0f62d7bd3c18975028e914a0cd848 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 22:16:20 +0200 Subject: [PATCH 17/22] cleaner implementation --- Cargo.lock | 12 +++++++++++- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ebd15a6d1d9..3bacfc46776d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17291,10 +17291,20 @@ name = "snowbridge-runtime-common" version = "0.1.1" dependencies = [ "bp-rococo", + "ethabi-decode", "frame-support", + "frame-system", "log", + "parity-scale-codec", + "polkadot-parachain-primitives", + "scale-info", + "serde", "snowbridge-core", - "sp-io", + "snowbridge-ethereum", + "sp-arithmetic", + "sp-core", + "sp-runtime", + "sp-std", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", 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 162610b0bd14..19fc7f2b8a7d 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 @@ -322,7 +322,6 @@ impl xcm_executor::Config for XcmConfig { XcmExportFeeToSnowbridge< TokenLocation, EthereumNetwork, - TreasuryAccount, Self::AssetTransactor, crate::EthereumOutboundQueue, >, From 3dbb5860cae83189b841429f550fcbbf22713b1a Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 22:17:39 +0200 Subject: [PATCH 18/22] cargo lock --- Cargo.lock | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3bacfc46776d..9ebd15a6d1d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17291,20 +17291,10 @@ name = "snowbridge-runtime-common" version = "0.1.1" dependencies = [ "bp-rococo", - "ethabi-decode", "frame-support", - "frame-system", "log", - "parity-scale-codec", - "polkadot-parachain-primitives", - "scale-info", - "serde", "snowbridge-core", - "snowbridge-ethereum", - "sp-arithmetic", - "sp-core", - "sp-runtime", - "sp-std", + "sp-io", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", From f56aaf93e36117392e61e48a59e66ae764d697ff Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 9 Nov 2023 22:20:38 +0200 Subject: [PATCH 19/22] update cargo lock --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9ebd15a6d1d9..be0cac4b7b2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17294,7 +17294,6 @@ dependencies = [ "frame-support", "log", "snowbridge-core", - "sp-io", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", From d7b9a4906cfc156e86697ee18712dd168f341211 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Fri, 10 Nov 2023 18:13:20 +0200 Subject: [PATCH 20/22] fixes --- Cargo.lock | 3 ++- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be0cac4b7b2e..e88300e4e902 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17290,10 +17290,11 @@ dependencies = [ name = "snowbridge-runtime-common" version = "0.1.1" dependencies = [ - "bp-rococo", "frame-support", + "frame-system", "log", "snowbridge-core", + "sp-arithmetic", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", 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 19fc7f2b8a7d..a0fa4cf0c3e2 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 @@ -51,7 +51,7 @@ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::xcm_sender::ExponentialPrice; use rococo_runtime_constants::system_parachain::SystemParachains; use snowbridge_router_primitives:: outbound::EthereumBlobExporter; -use snowbridge_runtime_common::XcmExportFeeToSnowbridge; +use snowbridge_runtime_common::XcmExportFeeToSibling; use sp_core::{Get, H256}; use sp_runtime::traits::AccountIdConversion; use sp_std::marker::PhantomData; @@ -319,7 +319,9 @@ impl xcm_executor::Config for XcmConfig { BridgeHubRococoChainId, BridgeHubRococoMessagesLane, >, - XcmExportFeeToSnowbridge< + XcmExportFeeToSibling< + bp_rococo::Balance, + AccountId, TokenLocation, EthereumNetwork, Self::AssetTransactor, @@ -579,4 +581,4 @@ impl< fee } -} \ No newline at end of file +} From 6236cad04fb52cc8d1791faef0a5854bc9085321 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Fri, 10 Nov 2023 18:27:16 +0200 Subject: [PATCH 21/22] move to runtime folder --- .../runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index b9ed51fa4130..d1728a009244 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -103,7 +103,7 @@ snowbridge-inbound-queue = { path = "../../../../../../parachain/pallets/inbound snowbridge-outbound-queue = { path = "../../../../../../parachain/pallets/outbound-queue", default-features = false } snowbridge-outbound-queue-runtime-api = { path = "../../../../../../parachain/pallets/outbound-queue/runtime-api", default-features = false } snowbridge-router-primitives = { path = "../../../../../../parachain/primitives/router", default-features = false } -snowbridge-runtime-common = { path = "../../../../../../parachain/primitives/runtime-common", default-features = false } +snowbridge-runtime-common = { path = "../../../../../../parachain/runtime/runtime-common", default-features = false } [dev-dependencies] static_assertions = "1.1" From 53eb94efd09e853397c0dc83dc61d844c447d489 Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Fri, 10 Nov 2023 18:36:53 +0200 Subject: [PATCH 22/22] remove uneeded code --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 a0fa4cf0c3e2..36df6a06e992 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 @@ -83,8 +83,7 @@ parameter_types! { pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into(); // Network and location for the local Ethereum testnet. - pub const EthereumChainId: u64 = 15; - pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: EthereumChainId::get() }; + pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 }; } /// Adapter for resolving `NetworkId` based on `pub storage Flavor: RuntimeFlavor`.