bridge_hub_rococo_runtime/
bridge_to_ethereum_config.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3
4// Cumulus is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Cumulus is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
16
17#[cfg(not(feature = "runtime-benchmarks"))]
18use crate::XcmRouter;
19use crate::{
20	xcm_config, xcm_config::UniversalLocation, Balances, EthereumInboundQueue,
21	EthereumOutboundQueue, EthereumSystem, MessageQueue, Runtime, RuntimeEvent, TransactionByteFee,
22	TreasuryAccount,
23};
24use parachains_common::{AccountId, Balance};
25use snowbridge_beacon_primitives::{Fork, ForkVersions};
26use snowbridge_core::{gwei, meth, AllowSiblingsOnly, PricingParameters, Rewards};
27use snowbridge_router_primitives::{inbound::MessageToXcm, outbound::EthereumBlobExporter};
28use sp_core::H160;
29use testnet_parachains_constants::rococo::{
30	currency::*,
31	fee::WeightToFee,
32	snowbridge::{EthereumLocation, EthereumNetwork, INBOUND_QUEUE_PALLET_INDEX},
33};
34
35use crate::xcm_config::RelayNetwork;
36#[cfg(feature = "runtime-benchmarks")]
37use benchmark_helpers::DoNothingRouter;
38use frame_support::{parameter_types, weights::ConstantMultiplier};
39use hex_literal::hex;
40use pallet_xcm::EnsureXcm;
41use sp_runtime::{
42	traits::{ConstU32, ConstU8, Keccak256},
43	FixedU128,
44};
45use xcm::prelude::{GlobalConsensus, InteriorLocation, Location, Parachain};
46
47/// Exports message to the Ethereum Gateway contract.
48pub type SnowbridgeExporter = EthereumBlobExporter<
49	UniversalLocation,
50	EthereumNetwork,
51	snowbridge_pallet_outbound_queue::Pallet<Runtime>,
52	snowbridge_core::AgentIdOf,
53	EthereumSystem,
54>;
55
56// Ethereum Bridge
57parameter_types! {
58	pub storage EthereumGatewayAddress: H160 = H160(hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
59}
60
61parameter_types! {
62	pub const CreateAssetCall: [u8;2] = [53, 0];
63	pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT;
64	pub Parameters: PricingParameters<u128> = PricingParameters {
65		exchange_rate: FixedU128::from_rational(1, 400),
66		fee_per_gas: gwei(20),
67		rewards: Rewards { local: 1 * UNITS, remote: meth(1) },
68		multiplier: FixedU128::from_rational(1, 1),
69	};
70	pub AssetHubFromEthereum: Location = Location::new(1,[GlobalConsensus(RelayNetwork::get()),Parachain(rococo_runtime_constants::system_parachain::ASSET_HUB_ID)]);
71	pub EthereumUniversalLocation: InteriorLocation = [GlobalConsensus(EthereumNetwork::get())].into();
72}
73
74impl snowbridge_pallet_inbound_queue::Config for Runtime {
75	type RuntimeEvent = RuntimeEvent;
76	type Verifier = snowbridge_pallet_ethereum_client::Pallet<Runtime>;
77	type Token = Balances;
78	#[cfg(not(feature = "runtime-benchmarks"))]
79	type XcmSender = XcmRouter;
80	#[cfg(feature = "runtime-benchmarks")]
81	type XcmSender = DoNothingRouter;
82	type ChannelLookup = EthereumSystem;
83	type GatewayAddress = EthereumGatewayAddress;
84	#[cfg(feature = "runtime-benchmarks")]
85	type Helper = Runtime;
86	type MessageConverter = MessageToXcm<
87		CreateAssetCall,
88		CreateAssetDeposit,
89		ConstU8<INBOUND_QUEUE_PALLET_INDEX>,
90		AccountId,
91		Balance,
92		EthereumSystem,
93		EthereumUniversalLocation,
94		AssetHubFromEthereum,
95	>;
96	type WeightToFee = WeightToFee;
97	type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
98	type MaxMessageSize = ConstU32<2048>;
99	type WeightInfo = crate::weights::snowbridge_pallet_inbound_queue::WeightInfo<Runtime>;
100	type PricingParameters = EthereumSystem;
101	type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
102}
103
104impl snowbridge_pallet_outbound_queue::Config for Runtime {
105	type RuntimeEvent = RuntimeEvent;
106	type Hashing = Keccak256;
107	type MessageQueue = MessageQueue;
108	type Decimals = ConstU8<12>;
109	type MaxMessagePayloadSize = ConstU32<2048>;
110	type MaxMessagesPerBlock = ConstU32<32>;
111	type GasMeter = snowbridge_core::outbound::ConstantGasMeter;
112	type Balance = Balance;
113	type WeightToFee = WeightToFee;
114	type WeightInfo = crate::weights::snowbridge_pallet_outbound_queue::WeightInfo<Runtime>;
115	type PricingParameters = EthereumSystem;
116	type Channels = EthereumSystem;
117}
118
119#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))]
120parameter_types! {
121	pub const ChainForkVersions: ForkVersions = ForkVersions {
122		genesis: Fork {
123			version: hex!("00000000"),
124			epoch: 0,
125		},
126		altair: Fork {
127			version: hex!("01000000"),
128			epoch: 0,
129		},
130		bellatrix: Fork {
131			version: hex!("02000000"),
132			epoch: 0,
133		},
134		capella: Fork {
135			version: hex!("03000000"),
136			epoch: 0,
137		},
138		deneb: Fork {
139			version: hex!("04000000"),
140			epoch: 0,
141		},
142		electra: Fork {
143			version: hex!("05000000"),
144			epoch: 80000000000,
145		}
146	};
147}
148
149#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
150parameter_types! {
151	pub const ChainForkVersions: ForkVersions = ForkVersions {
152		genesis: Fork {
153			version: hex!("90000069"),
154			epoch: 0,
155		},
156		altair: Fork {
157			version: hex!("90000070"),
158			epoch: 50,
159		},
160		bellatrix: Fork {
161			version: hex!("90000071"),
162			epoch: 100,
163		},
164		capella: Fork {
165			version: hex!("90000072"),
166			epoch: 56832,
167		},
168		deneb: Fork {
169			version: hex!("90000073"),
170			epoch: 132608,
171		},
172		electra: Fork {
173			version: hex!("90000074"),
174			epoch: 222464, // https://github.com/ethereum/EIPs/pull/9322/files
175		},
176	};
177}
178
179pub const SLOTS_PER_EPOCH: u32 = snowbridge_pallet_ethereum_client::config::SLOTS_PER_EPOCH as u32;
180
181impl snowbridge_pallet_ethereum_client::Config for Runtime {
182	type RuntimeEvent = RuntimeEvent;
183	type ForkVersions = ChainForkVersions;
184	// Free consensus update every epoch. Works out to be 225 updates per day.
185	type FreeHeadersInterval = ConstU32<SLOTS_PER_EPOCH>;
186	type WeightInfo = crate::weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
187}
188
189impl snowbridge_pallet_system::Config for Runtime {
190	type RuntimeEvent = RuntimeEvent;
191	type OutboundQueue = EthereumOutboundQueue;
192	type SiblingOrigin = EnsureXcm<AllowSiblingsOnly>;
193	type AgentIdOf = snowbridge_core::AgentIdOf;
194	type TreasuryAccount = TreasuryAccount;
195	type Token = Balances;
196	type WeightInfo = crate::weights::snowbridge_pallet_system::WeightInfo<Runtime>;
197	#[cfg(feature = "runtime-benchmarks")]
198	type Helper = ();
199	type DefaultPricingParameters = Parameters;
200	type InboundDeliveryCost = EthereumInboundQueue;
201	type UniversalLocation = UniversalLocation;
202	type EthereumLocation = EthereumLocation;
203}
204
205#[cfg(feature = "runtime-benchmarks")]
206pub mod benchmark_helpers {
207	use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin};
208	use codec::Encode;
209	use snowbridge_beacon_primitives::BeaconHeader;
210	use snowbridge_pallet_inbound_queue::BenchmarkHelper;
211	use sp_core::H256;
212	use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};
213
214	impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
215		fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) {
216			EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
217		}
218	}
219
220	pub struct DoNothingRouter;
221	impl SendXcm for DoNothingRouter {
222		type Ticket = Xcm<()>;
223
224		fn validate(
225			_dest: &mut Option<Location>,
226			xcm: &mut Option<Xcm<()>>,
227		) -> SendResult<Self::Ticket> {
228			Ok((xcm.clone().unwrap(), Assets::new()))
229		}
230		fn deliver(xcm: Xcm<()>) -> Result<XcmHash, SendError> {
231			let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
232			Ok(hash)
233		}
234	}
235
236	impl snowbridge_pallet_system::BenchmarkHelper<RuntimeOrigin> for () {
237		fn make_xcm_origin(location: Location) -> RuntimeOrigin {
238			RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location))
239		}
240	}
241}