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

Fixes related to pr comments #51

Merged
merged 10 commits into from
Dec 2, 2023
Merged
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
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,4 @@ snowbridge-outbound-queue = { path = "../parachain/pallets/outbound-queue" }
snowbridge-outbound-queue-runtime-api = { path = "../parachain/pallets/outbound-queue/runtime-api" }
snowbridge-router-primitives = { path = "../parachain/primitives/router" }
snowbridge-runtime-common = { path = "../parachain/runtime/runtime-common" }
snowbridge-rococo-common = { path = "../parachain/runtime/rococo-common" }
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ snowbridge-router-primitives = { git = "https://github.com/Snowfork/snowbridge.g
snowbridge-system = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-inbound-queue = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-outbound-queue = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-rococo-common = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use codec::{Decode, Encode};
use frame_support::pallet_prelude::TypeInfo;
use hex_literal::hex;
use snowbridge_core::outbound::OperatingMode;
use snowbridge_rococo_common::EthereumNetwork;
use snowbridge_router_primitives::inbound::{Command, Destination, MessageV1, VersionedMessage};
use snowbridge_system;
use sp_core::H256;
Expand Down Expand Up @@ -243,8 +244,7 @@ fn send_token_to_penpal() {
]);

let weth_asset_location: MultiLocation =
(Parent, Parent, Ethereum { chain_id: 15 }, AccountKey20 { network: None, key: WETH })
.into();
(Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into();
let weth_asset_id = weth_asset_location.into();

let origin_location =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ parachain-info = { package = "staging-parachain-info", path = "../../../pallets/
parachains-common = { path = "../../../common", default-features = false }
assets-common = { path = "../common", default-features = false }
snowbridge-router-primitives = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }

snowbridge-rococo-common = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
# Bridges
pallet-xcm-bridge-hub-router = { path = "../../../../../bridges/modules/xcm-bridge-hub-router", default-features = false }
bp-asset-hub-rococo = { path = "../../../../../bridges/primitives/chain-asset-hub-rococo", default-features = false }
Expand Down Expand Up @@ -230,6 +230,7 @@ std = [
"rococo-runtime-constants/std",
"scale-info/std",
"snowbridge-router-primitives/std",
"snowbridge-rococo-common/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ impl pallet_xcm_bridge_hub_router::Config<ToEthereumXcmRouterInstance> for Runti
type WeightInfo = weights::pallet_xcm_bridge_hub_router::WeightInfo<Runtime>;

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

#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ use parachains_common::{
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use rococo_runtime_constants::system_parachain;
use snowbridge_rococo_common::EthereumNetwork;
use snowbridge_router_primitives::inbound::GlobalConsensusEthereumConvertsFor;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use sp_std::marker::PhantomData;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand All @@ -59,6 +61,7 @@ use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

#[cfg(feature = "runtime-benchmarks")]
use cumulus_primitives_core::ParaId;
use frame_support::traits::{ContainsPair, Get};

parameter_types! {
pub const TokenLocation: MultiLocation = MultiLocation::parent();
Expand Down Expand Up @@ -543,6 +546,7 @@ pub type WaivedLocations =
/// - Sibling parachains' assets from where they originate (as `ForeignCreators`).
pub type TrustedTeleporters = (
ConcreteAssetFromSystem<TokenLocation>,
ConcreteAssetFromSnowBridgeMessageQueue<TokenLocation>,
IsForeignConcreteAsset<FromSiblingParachain<parachain_info::Pallet<Runtime>>>,
);

Expand Down Expand Up @@ -726,6 +730,18 @@ where
}
}

pub struct ConcreteAssetFromSnowBridgeMessageQueue<AssetLocation>(PhantomData<AssetLocation>);
impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
for ConcreteAssetFromSnowBridgeMessageQueue<AssetLocation>
{
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::contains", "ConcreteAssetFromSystem asset: {:?}, origin: {:?}", asset, origin);
let from_snowbridge = origin
.eq(&bridging::to_ethereum::SiblingBridgeHubWithEthereumInboundQueueInstance::get());
matches!(asset.id, Concrete(id) if id == AssetLocation::get()) && from_snowbridge
}
}

/// All configuration related to bridging
pub mod bridging {
use super::*;
Expand Down Expand Up @@ -848,13 +864,20 @@ pub mod bridging {
use super::*;

parameter_types! {
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

/// User fee for ERC20 token transfer back to Ethereum.
/// (initially was calculated by test `OutboundQueue::calculate_fees` - ETH/ROC 1/400 and fee_per_gas 20 GWEI = 2200698000000 + *25%)
/// Needs to be more than fee calculated from DefaultFeeConfig FeeConfigRecord in snowbridge:parachain/pallets/outbound-queue/src/lib.rs
/// Polkadot uses 12 decimals, Kusama and Rococo 10 decimals.
pub const BridgeHubEthereumBaseFeeInROC: u128 = 2_750_872_500_000;
pub SiblingBridgeHubWithEthereumInboundQueueInstance: MultiLocation = MultiLocation::new(
1,
X2(
Parachain(SiblingBridgeHubParaId::get()),
PalletInstance(snowbridge_rococo_common::INBOUND_QUEUE_MESSAGES_PALLET_INDEX)
)
);

/// Set up exporters configuration.
/// `Option<MultiAsset>` represents static "base fee" which is used for total delivery fee calculation.
Expand All @@ -875,13 +898,13 @@ pub mod bridging {
/// Universal aliases
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
sp_std::vec![
(SiblingBridgeHub::get(), GlobalConsensus(EthereumNetwork::get())),
(SiblingBridgeHubWithEthereumInboundQueueInstance::get(), GlobalConsensus(EthereumNetwork::get())),
]
);
}

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

impl Contains<(MultiLocation, Junction)> for UniversalAliases {
fn contains(alias: &(MultiLocation, Junction)) -> bool {
Expand Down
23 changes: 16 additions & 7 deletions cumulus/parachains/runtimes/assets/common/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,30 @@ impl<SelfParaId: Get<ParaId>> ContainsPair<MultiLocation, MultiLocation>
}
}

pub struct FromNetwork<SelfNetworkId>(sp_std::marker::PhantomData<SelfNetworkId>);
impl<SelfNetworkId: Get<NetworkId>> ContainsPair<MultiLocation, MultiLocation>
for FromNetwork<SelfNetworkId>
pub struct FromNetwork<UniversalLocation, ExpectedNetworkId>(
sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId)>,
);
impl<UniversalLocation: Get<InteriorMultiLocation>, ExpectedNetworkId: Get<NetworkId>>
ContainsPair<MultiLocation, MultiLocation> for FromNetwork<UniversalLocation, ExpectedNetworkId>
{
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())
let universal_source = UniversalLocation::get();

return match ensure_is_remote(universal_source, a) {
Ok((network_id, _)) => network_id == ExpectedNetworkId::get(),
Err(e) => {
log::trace!(
target: "xcm::contains",
"FromNetwork origin: {:?} is not remote to the universal_source: {:?} {:?}",
a, universal_source, e
);
false
},
_ => false,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ snowbridge-outbound-queue = { git = "https://github.com/Snowfork/snowbridge.git"
snowbridge-outbound-queue-runtime-api = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-router-primitives = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-runtime-common = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-rococo-common = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }

bridge-hub-common = { path = "../common", default-features = false }

Expand Down Expand Up @@ -200,6 +201,7 @@ std = [
"snowbridge-outbound-queue/std",
"snowbridge-router-primitives/std",
"snowbridge-runtime-common/std",
"snowbridge-rococo-common/std",
"substrate-wasm-builder",
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::{
xcm_config::{AgentIdOf, UniversalLocation},
Runtime,
};
use snowbridge_rococo_common::EthereumNetwork;
use snowbridge_router_primitives::outbound::EthereumBlobExporter;

pub type SnowbridgeExporter = EthereumBlobExporter<
UniversalLocation,
EthereumNetwork,
snowbridge_outbound_queue::Pallet<Runtime>,
AgentIdOf,
>;
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

use crate::{
bridge_common_config::{BridgeParachainWestendInstance, DeliveryRewardInBalance},
weights,
xcm_config::{AgentIdOf, EthereumNetwork, UniversalLocation},
AccountId, BridgeWestendMessages, ParachainInfo, Runtime, RuntimeEvent, RuntimeOrigin,
weights, AccountId, BridgeWestendMessages, ParachainInfo, Runtime, RuntimeEvent, RuntimeOrigin,
XcmRouter,
};
use bp_messages::LaneId;
Expand All @@ -40,7 +38,6 @@ use bridge_runtime_common::{
RefundableMessagesLane, RefundableParachain,
},
};
use snowbridge_router_primitives::outbound::EthereumBlobExporter;

use codec::Encode;
use frame_support::{parameter_types, traits::PalletInfoAccess};
Expand Down Expand Up @@ -119,13 +116,6 @@ pub type ToBridgeHubWestendHaulBlobExporter = HaulBlobExporter<
(),
>;

pub type SnowbridgeExporter = EthereumBlobExporter<
UniversalLocation,
EthereumNetwork,
snowbridge_outbound_queue::Pallet<Runtime>,
AgentIdOf,
>;

pub struct ToBridgeHubWestendXcmBlobHauler;
impl XcmBlobHauler for ToBridgeHubWestendXcmBlobHauler {
type Runtime = Runtime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

pub mod bridge_common_config;
pub mod bridge_to_ethereum_config;
pub mod bridge_to_westend_config;
mod weights;
pub mod xcm_config;
Expand Down Expand Up @@ -509,6 +510,7 @@ parameter_types! {
pub const GatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
pub const CreateAssetCall: [u8;2] = [53, 0];
pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT;
pub const InboundQueuePalletInstance: u8 = snowbridge_rococo_common::INBOUND_QUEUE_MESSAGES_PALLET_INDEX;
pub Parameters: PricingParameters<u128> = PricingParameters {
exchange_rate: FixedU128::from_rational(1, 400),
fee_per_gas: gwei(20),
Expand All @@ -535,7 +537,13 @@ impl snowbridge_inbound_queue::Config for Runtime {
type GatewayAddress = GatewayAddress;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
type MessageConverter = MessageToXcm<CreateAssetCall, CreateAssetDeposit, AccountId, Balance>;
type MessageConverter = MessageToXcm<
CreateAssetCall,
CreateAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
>;
type WeightToFee = WeightToFee;
type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo<Runtime>;
type PricingParameters = EthereumSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use rococo_runtime_constants::system_parachain;
use snowbridge_core::DescribeHere;
use snowbridge_rococo_common::EthereumNetwork;
use snowbridge_runtime_common::XcmExportFeeToSibling;
use sp_core::{Get, H256};
use sp_runtime::traits::AccountIdConversion;
Expand Down Expand Up @@ -70,9 +71,6 @@ parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
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 };
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -306,7 +304,7 @@ impl xcm_executor::Config for XcmConfig {
>;
type MessageExporter = (
crate::bridge_to_westend_config::ToBridgeHubWestendHaulBlobExporter,
crate::bridge_to_westend_config::SnowbridgeExporter,
crate::bridge_to_ethereum_config::SnowbridgeExporter,
);
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down Expand Up @@ -470,8 +468,8 @@ impl<WaivedLocations: Contains<MultiLocation>, FeeHandler: HandleFee> FeeManager
{
fn is_waived(origin: Option<&MultiLocation>, fee_reason: FeeReason) -> bool {
let Some(loc) = origin else { return false };
if let Export { network: Ethereum { chain_id: 15 }, destination: Here } = fee_reason {
return false
if let Export { network, destination: Here } = fee_reason {
return !(network == EthereumNetwork::get())
}
WaivedLocations::contains(loc)
}
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/testing/penpal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pallet-collator-selection = { path = "../../../../pallets/collator-selection", d
parachain-info = { package = "staging-parachain-info", path = "../../../pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../common", default-features = false }
assets-common = { path = "../../assets/common", default-features = false }
snowbridge-rococo-common = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false}

[features]
default = [ "std" ]
Expand Down Expand Up @@ -116,6 +117,7 @@ std = [
"polkadot-parachain-primitives/std",
"polkadot-primitives/std",
"polkadot-runtime-common/std",
"snowbridge-rococo-common/std",
"scale-info/std",
"sp-api/std",
"sp-block-builder/std",
Expand Down
3 changes: 2 additions & 1 deletion cumulus/parachains/runtimes/testing/penpal/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use pallet_assets::Instance1;
use pallet_xcm::XcmPassthrough;
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use snowbridge_rococo_common::EthereumNetwork;
use sp_runtime::traits::Zero;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -271,7 +272,7 @@ parameter_types! {
pub SystemAssetHubAssetsPalletLocation: MultiLocation =
MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50)));
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(Ethereum { chain_id: 15 })));
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));
}

pub type Reserves = (
Expand Down
Loading