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 pallet_xcm::EnsureXcm;
40use sp_runtime::{
41	traits::{ConstU32, ConstU8, Keccak256},
42	FixedU128,
43};
44use xcm::prelude::{GlobalConsensus, InteriorLocation, Location, Parachain};
45
46/// Exports message to the Ethereum Gateway contract.
47pub type SnowbridgeExporter = EthereumBlobExporter<
48	UniversalLocation,
49	EthereumNetwork,
50	snowbridge_pallet_outbound_queue::Pallet<Runtime>,
51	snowbridge_core::AgentIdOf,
52	EthereumSystem,
53>;
54
55// Ethereum Bridge
56parameter_types! {
57	pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
58}
59
60parameter_types! {
61	pub const CreateAssetCall: [u8;2] = [53, 0];
62	pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT;
63	pub Parameters: PricingParameters<u128> = PricingParameters {
64		exchange_rate: FixedU128::from_rational(1, 400),
65		fee_per_gas: gwei(20),
66		rewards: Rewards { local: 1 * UNITS, remote: meth(1) },
67		multiplier: FixedU128::from_rational(1, 1),
68	};
69	pub AssetHubFromEthereum: Location = Location::new(1,[GlobalConsensus(RelayNetwork::get()),Parachain(rococo_runtime_constants::system_parachain::ASSET_HUB_ID)]);
70	pub EthereumUniversalLocation: InteriorLocation = [GlobalConsensus(EthereumNetwork::get())].into();
71}
72
73impl snowbridge_pallet_inbound_queue::Config for Runtime {
74	type RuntimeEvent = RuntimeEvent;
75	type Verifier = snowbridge_pallet_ethereum_client::Pallet<Runtime>;
76	type Token = Balances;
77	#[cfg(not(feature = "runtime-benchmarks"))]
78	type XcmSender = XcmRouter;
79	#[cfg(feature = "runtime-benchmarks")]
80	type XcmSender = DoNothingRouter;
81	type ChannelLookup = EthereumSystem;
82	type GatewayAddress = EthereumGatewayAddress;
83	#[cfg(feature = "runtime-benchmarks")]
84	type Helper = Runtime;
85	type MessageConverter = MessageToXcm<
86		CreateAssetCall,
87		CreateAssetDeposit,
88		ConstU8<INBOUND_QUEUE_PALLET_INDEX>,
89		AccountId,
90		Balance,
91		EthereumSystem,
92		EthereumUniversalLocation,
93		AssetHubFromEthereum,
94	>;
95	type WeightToFee = WeightToFee;
96	type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
97	type MaxMessageSize = ConstU32<2048>;
98	type WeightInfo = crate::weights::snowbridge_pallet_inbound_queue::WeightInfo<Runtime>;
99	type PricingParameters = EthereumSystem;
100	type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
101}
102
103impl snowbridge_pallet_outbound_queue::Config for Runtime {
104	type RuntimeEvent = RuntimeEvent;
105	type Hashing = Keccak256;
106	type MessageQueue = MessageQueue;
107	type Decimals = ConstU8<12>;
108	type MaxMessagePayloadSize = ConstU32<2048>;
109	type MaxMessagesPerBlock = ConstU32<32>;
110	type GasMeter = snowbridge_core::outbound::ConstantGasMeter;
111	type Balance = Balance;
112	type WeightToFee = WeightToFee;
113	type WeightInfo = crate::weights::snowbridge_pallet_outbound_queue::WeightInfo<Runtime>;
114	type PricingParameters = EthereumSystem;
115	type Channels = EthereumSystem;
116}
117
118#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))]
119parameter_types! {
120	pub const ChainForkVersions: ForkVersions = ForkVersions {
121		genesis: Fork {
122			version: [0, 0, 0, 0], // 0x00000000
123			epoch: 0,
124		},
125		altair: Fork {
126			version: [1, 0, 0, 0], // 0x01000000
127			epoch: 0,
128		},
129		bellatrix: Fork {
130			version: [2, 0, 0, 0], // 0x02000000
131			epoch: 0,
132		},
133		capella: Fork {
134			version: [3, 0, 0, 0], // 0x03000000
135			epoch: 0,
136		},
137		deneb: Fork {
138			version: [4, 0, 0, 0], // 0x04000000
139			epoch: 0,
140		}
141	};
142}
143
144#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
145parameter_types! {
146	pub const ChainForkVersions: ForkVersions = ForkVersions {
147		genesis: Fork {
148			version: [144, 0, 0, 111], // 0x90000069
149			epoch: 0,
150		},
151		altair: Fork {
152			version: [144, 0, 0, 112], // 0x90000070
153			epoch: 50,
154		},
155		bellatrix: Fork {
156			version: [144, 0, 0, 113], // 0x90000071
157			epoch: 100,
158		},
159		capella: Fork {
160			version: [144, 0, 0, 114], // 0x90000072
161			epoch: 56832,
162		},
163		deneb: Fork {
164			version: [144, 0, 0, 115], // 0x90000073
165			epoch: 132608,
166		},
167	};
168}
169
170pub const SLOTS_PER_EPOCH: u32 = snowbridge_pallet_ethereum_client::config::SLOTS_PER_EPOCH as u32;
171
172impl snowbridge_pallet_ethereum_client::Config for Runtime {
173	type RuntimeEvent = RuntimeEvent;
174	type ForkVersions = ChainForkVersions;
175	// Free consensus update every epoch. Works out to be 225 updates per day.
176	type FreeHeadersInterval = ConstU32<SLOTS_PER_EPOCH>;
177	type WeightInfo = crate::weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
178}
179
180impl snowbridge_pallet_system::Config for Runtime {
181	type RuntimeEvent = RuntimeEvent;
182	type OutboundQueue = EthereumOutboundQueue;
183	type SiblingOrigin = EnsureXcm<AllowSiblingsOnly>;
184	type AgentIdOf = snowbridge_core::AgentIdOf;
185	type TreasuryAccount = TreasuryAccount;
186	type Token = Balances;
187	type WeightInfo = crate::weights::snowbridge_pallet_system::WeightInfo<Runtime>;
188	#[cfg(feature = "runtime-benchmarks")]
189	type Helper = ();
190	type DefaultPricingParameters = Parameters;
191	type InboundDeliveryCost = EthereumInboundQueue;
192	type UniversalLocation = UniversalLocation;
193	type EthereumLocation = EthereumLocation;
194}
195
196#[cfg(feature = "runtime-benchmarks")]
197pub mod benchmark_helpers {
198	use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin};
199	use codec::Encode;
200	use snowbridge_beacon_primitives::BeaconHeader;
201	use snowbridge_pallet_inbound_queue::BenchmarkHelper;
202	use sp_core::H256;
203	use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};
204
205	impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
206		fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) {
207			EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
208		}
209	}
210
211	pub struct DoNothingRouter;
212	impl SendXcm for DoNothingRouter {
213		type Ticket = Xcm<()>;
214
215		fn validate(
216			_dest: &mut Option<Location>,
217			xcm: &mut Option<Xcm<()>>,
218		) -> SendResult<Self::Ticket> {
219			Ok((xcm.clone().unwrap(), Assets::new()))
220		}
221		fn deliver(xcm: Xcm<()>) -> Result<XcmHash, SendError> {
222			let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
223			Ok(hash)
224		}
225	}
226
227	impl snowbridge_pallet_system::BenchmarkHelper<RuntimeOrigin> for () {
228		fn make_xcm_origin(location: Location) -> RuntimeOrigin {
229			RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location))
230		}
231	}
232}