bridge_hub_rococo_runtime/
bridge_to_ethereum_config.rs1#[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_inbound_queue_primitives::v1::MessageToXcm;
28use snowbridge_outbound_queue_primitives::v1::EthereumBlobExporter;
29
30use sp_core::H160;
31use testnet_parachains_constants::rococo::{
32 currency::*,
33 fee::WeightToFee,
34 snowbridge::{EthereumLocation, EthereumNetwork, INBOUND_QUEUE_PALLET_INDEX},
35};
36
37use crate::xcm_config::RelayNetwork;
38#[cfg(feature = "runtime-benchmarks")]
39use benchmark_helpers::DoNothingRouter;
40use bp_asset_hub_rococo::CreateForeignAssetDeposit;
41use frame_support::{parameter_types, weights::ConstantMultiplier};
42use hex_literal::hex;
43use pallet_xcm::EnsureXcm;
44use sp_runtime::{
45 traits::{ConstU32, ConstU8, Keccak256},
46 FixedU128,
47};
48use xcm::prelude::{GlobalConsensus, InteriorLocation, Location, Parachain};
49
50pub type SnowbridgeExporter = EthereumBlobExporter<
52 UniversalLocation,
53 EthereumNetwork,
54 snowbridge_pallet_outbound_queue::Pallet<Runtime>,
55 snowbridge_core::AgentIdOf,
56 EthereumSystem,
57>;
58
59parameter_types! {
61 pub storage EthereumGatewayAddress: H160 = H160(hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
62}
63
64parameter_types! {
65 pub const CreateAssetCall: [u8;2] = [53, 0];
66 pub Parameters: PricingParameters<u128> = PricingParameters {
67 exchange_rate: FixedU128::from_rational(1, 400),
68 fee_per_gas: gwei(20),
69 rewards: Rewards { local: 1 * UNITS, remote: meth(1) },
70 multiplier: FixedU128::from_rational(1, 1),
71 };
72 pub AssetHubFromEthereum: Location = Location::new(1,[GlobalConsensus(RelayNetwork::get()),Parachain(rococo_runtime_constants::system_parachain::ASSET_HUB_ID)]);
73 pub EthereumUniversalLocation: InteriorLocation = [GlobalConsensus(EthereumNetwork::get())].into();
74}
75
76impl snowbridge_pallet_inbound_queue::Config for Runtime {
77 type RuntimeEvent = RuntimeEvent;
78 type Verifier = snowbridge_pallet_ethereum_client::Pallet<Runtime>;
79 type Token = Balances;
80 #[cfg(not(feature = "runtime-benchmarks"))]
81 type XcmSender = XcmRouter;
82 #[cfg(feature = "runtime-benchmarks")]
83 type XcmSender = DoNothingRouter;
84 type ChannelLookup = EthereumSystem;
85 type GatewayAddress = EthereumGatewayAddress;
86 #[cfg(feature = "runtime-benchmarks")]
87 type Helper = Runtime;
88 type MessageConverter = MessageToXcm<
89 CreateAssetCall,
90 CreateForeignAssetDeposit,
91 ConstU8<INBOUND_QUEUE_PALLET_INDEX>,
92 AccountId,
93 Balance,
94 EthereumSystem,
95 EthereumUniversalLocation,
96 AssetHubFromEthereum,
97 >;
98 type WeightToFee = WeightToFee;
99 type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
100 type MaxMessageSize = ConstU32<2048>;
101 type WeightInfo = crate::weights::snowbridge_pallet_inbound_queue::WeightInfo<Runtime>;
102 type PricingParameters = EthereumSystem;
103 type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
104}
105
106impl snowbridge_pallet_outbound_queue::Config for Runtime {
107 type RuntimeEvent = RuntimeEvent;
108 type Hashing = Keccak256;
109 type MessageQueue = MessageQueue;
110 type Decimals = ConstU8<12>;
111 type MaxMessagePayloadSize = ConstU32<2048>;
112 type MaxMessagesPerBlock = ConstU32<32>;
113 type GasMeter = crate::ConstantGasMeter;
114 type Balance = Balance;
115 type WeightToFee = WeightToFee;
116 type WeightInfo = crate::weights::snowbridge_pallet_outbound_queue::WeightInfo<Runtime>;
117 type PricingParameters = EthereumSystem;
118 type Channels = EthereumSystem;
119}
120
121#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))]
122parameter_types! {
123 pub const ChainForkVersions: ForkVersions = ForkVersions {
124 genesis: Fork {
125 version: hex!("00000000"),
126 epoch: 0,
127 },
128 altair: Fork {
129 version: hex!("01000000"),
130 epoch: 0,
131 },
132 bellatrix: Fork {
133 version: hex!("02000000"),
134 epoch: 0,
135 },
136 capella: Fork {
137 version: hex!("03000000"),
138 epoch: 0,
139 },
140 deneb: Fork {
141 version: hex!("04000000"),
142 epoch: 0,
143 },
144 electra: Fork {
145 version: hex!("05000000"),
146 epoch: 0,
147 },
148 fulu: Fork {
149 version: hex!("06000000"),
150 epoch: 5000000,
151 }
152 };
153}
154
155#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
156parameter_types! {
157 pub const ChainForkVersions: ForkVersions = ForkVersions {
158 genesis: Fork {
159 version: hex!("90000069"),
160 epoch: 0,
161 },
162 altair: Fork {
163 version: hex!("90000070"),
164 epoch: 50,
165 },
166 bellatrix: Fork {
167 version: hex!("90000071"),
168 epoch: 100,
169 },
170 capella: Fork {
171 version: hex!("90000072"),
172 epoch: 56832,
173 },
174 deneb: Fork {
175 version: hex!("90000073"),
176 epoch: 132608,
177 },
178 electra: Fork {
179 version: hex!("90000074"),
180 epoch: 222464,
181 },
182 fulu: Fork {
183 version: hex!("90000075"),
184 epoch: 272640, },
186 };
187}
188
189pub const SLOTS_PER_EPOCH: u32 = snowbridge_pallet_ethereum_client::config::SLOTS_PER_EPOCH as u32;
190
191impl snowbridge_pallet_ethereum_client::Config for Runtime {
192 type RuntimeEvent = RuntimeEvent;
193 type ForkVersions = ChainForkVersions;
194 type FreeHeadersInterval = ConstU32<SLOTS_PER_EPOCH>;
196 type WeightInfo = crate::weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
197}
198
199impl snowbridge_pallet_system::Config for Runtime {
200 type RuntimeEvent = RuntimeEvent;
201 type OutboundQueue = EthereumOutboundQueue;
202 type SiblingOrigin = EnsureXcm<AllowSiblingsOnly>;
203 type AgentIdOf = snowbridge_core::AgentIdOf;
204 type TreasuryAccount = TreasuryAccount;
205 type Token = Balances;
206 type WeightInfo = crate::weights::snowbridge_pallet_system::WeightInfo<Runtime>;
207 #[cfg(feature = "runtime-benchmarks")]
208 type Helper = ();
209 type DefaultPricingParameters = Parameters;
210 type InboundDeliveryCost = EthereumInboundQueue;
211 type UniversalLocation = UniversalLocation;
212 type EthereumLocation = EthereumLocation;
213}
214
215#[cfg(feature = "runtime-benchmarks")]
216pub mod benchmark_helpers {
217 use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin};
218 use codec::Encode;
219 use snowbridge_inbound_queue_primitives::EventFixture;
220 use snowbridge_pallet_inbound_queue::BenchmarkHelper;
221 use snowbridge_pallet_inbound_queue_fixtures::register_token::make_register_token_message;
222 use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};
223
224 impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
225 fn initialize_storage() -> EventFixture {
226 let message = make_register_token_message();
227 EthereumBeaconClient::store_finalized_header(
228 message.finalized_header,
229 message.block_roots_root,
230 )
231 .unwrap();
232 message
233 }
234 }
235
236 pub struct DoNothingRouter;
237 impl SendXcm for DoNothingRouter {
238 type Ticket = Xcm<()>;
239
240 fn validate(
241 _dest: &mut Option<Location>,
242 xcm: &mut Option<Xcm<()>>,
243 ) -> SendResult<Self::Ticket> {
244 Ok((xcm.clone().unwrap(), Assets::new()))
245 }
246 fn deliver(xcm: Xcm<()>) -> Result<XcmHash, SendError> {
247 let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
248 Ok(hash)
249 }
250 }
251
252 impl snowbridge_pallet_system::BenchmarkHelper<RuntimeOrigin> for () {
253 fn make_xcm_origin(location: Location) -> RuntimeOrigin {
254 RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location))
255 }
256 }
257}