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 };
149}
150
151#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
152parameter_types! {
153 pub const ChainForkVersions: ForkVersions = ForkVersions {
154 genesis: Fork {
155 version: hex!("90000069"),
156 epoch: 0,
157 },
158 altair: Fork {
159 version: hex!("90000070"),
160 epoch: 50,
161 },
162 bellatrix: Fork {
163 version: hex!("90000071"),
164 epoch: 100,
165 },
166 capella: Fork {
167 version: hex!("90000072"),
168 epoch: 56832,
169 },
170 deneb: Fork {
171 version: hex!("90000073"),
172 epoch: 132608,
173 },
174 electra: Fork {
175 version: hex!("90000074"),
176 epoch: 222464, },
178 };
179}
180
181pub const SLOTS_PER_EPOCH: u32 = snowbridge_pallet_ethereum_client::config::SLOTS_PER_EPOCH as u32;
182
183impl snowbridge_pallet_ethereum_client::Config for Runtime {
184 type RuntimeEvent = RuntimeEvent;
185 type ForkVersions = ChainForkVersions;
186 type FreeHeadersInterval = ConstU32<SLOTS_PER_EPOCH>;
188 type WeightInfo = crate::weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
189}
190
191impl snowbridge_pallet_system::Config for Runtime {
192 type RuntimeEvent = RuntimeEvent;
193 type OutboundQueue = EthereumOutboundQueue;
194 type SiblingOrigin = EnsureXcm<AllowSiblingsOnly>;
195 type AgentIdOf = snowbridge_core::AgentIdOf;
196 type TreasuryAccount = TreasuryAccount;
197 type Token = Balances;
198 type WeightInfo = crate::weights::snowbridge_pallet_system::WeightInfo<Runtime>;
199 #[cfg(feature = "runtime-benchmarks")]
200 type Helper = ();
201 type DefaultPricingParameters = Parameters;
202 type InboundDeliveryCost = EthereumInboundQueue;
203 type UniversalLocation = UniversalLocation;
204 type EthereumLocation = EthereumLocation;
205}
206
207#[cfg(feature = "runtime-benchmarks")]
208pub mod benchmark_helpers {
209 use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin};
210 use codec::Encode;
211 use snowbridge_beacon_primitives::BeaconHeader;
212 use snowbridge_pallet_inbound_queue::BenchmarkHelper;
213 use sp_core::H256;
214 use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};
215
216 impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
217 fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) {
218 EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
219 }
220 }
221
222 pub struct DoNothingRouter;
223 impl SendXcm for DoNothingRouter {
224 type Ticket = Xcm<()>;
225
226 fn validate(
227 _dest: &mut Option<Location>,
228 xcm: &mut Option<Xcm<()>>,
229 ) -> SendResult<Self::Ticket> {
230 Ok((xcm.clone().unwrap(), Assets::new()))
231 }
232 fn deliver(xcm: Xcm<()>) -> Result<XcmHash, SendError> {
233 let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
234 Ok(hash)
235 }
236 }
237
238 impl snowbridge_pallet_system::BenchmarkHelper<RuntimeOrigin> for () {
239 fn make_xcm_origin(location: Location) -> RuntimeOrigin {
240 RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location))
241 }
242 }
243}