bp_asset_hub_westend/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
19
20extern crate alloc;
21
22pub use bp_bridge_hub_cumulus::*;
23use bp_messages::*;
24use bp_runtime::{
25 decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain,
26};
27pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;
28use codec::{Decode, Encode};
29use frame_support::{
30 dispatch::DispatchClass,
31 sp_runtime::{MultiAddress, MultiSigner, RuntimeDebug, StateVersion},
32};
33use scale_info::TypeInfo;
34use testnet_parachains_constants::westend::currency::UNITS;
35use xcm::latest::prelude::*;
36
37#[allow(clippy::large_enum_variant)]
46#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
47pub enum Call {
48 #[codec(index = 34)]
50 ToRococoXcmRouter(XcmBridgeHubRouterCall),
51}
52
53frame_support::parameter_types! {
54 pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
56
57 pub const CreateForeignAssetDeposit: u128 = UNITS / 10;
59}
60
61pub fn build_congestion_message<RuntimeCall>(
64 bridge_id: sp_core::H256,
65 is_congested: bool,
66) -> alloc::vec::Vec<Instruction<RuntimeCall>> {
67 alloc::vec![
68 UnpaidExecution { weight_limit: Unlimited, check_origin: None },
69 Transact {
70 origin_kind: OriginKind::Xcm,
71 fallback_max_weight: Some(XcmBridgeHubRouterTransactCallMaxWeight::get()),
72 call: Call::ToRococoXcmRouter(XcmBridgeHubRouterCall::report_bridge_status {
73 bridge_id,
74 is_congested,
75 })
76 .encode()
77 .into(),
78 },
79 ExpectTransactStatus(MaybeErrorCode::Success),
80 ]
81}
82
83pub const ASSET_HUB_WESTEND_PARACHAIN_ID: u32 = 1000;
85
86#[derive(RuntimeDebug)]
88pub struct AssetHubWestend;
89
90impl Chain for AssetHubWestend {
91 const ID: ChainId = *b"ahwd";
92
93 type BlockNumber = BlockNumber;
94 type Hash = Hash;
95 type Hasher = Hasher;
96 type Header = Header;
97
98 type AccountId = AccountId;
99 type Balance = Balance;
100 type Nonce = Nonce;
101 type Signature = Signature;
102
103 const STATE_VERSION: StateVersion = StateVersion::V1;
104
105 fn max_extrinsic_size() -> u32 {
106 *BlockLength::get().max.get(DispatchClass::Normal)
107 }
108
109 fn max_extrinsic_weight() -> Weight {
110 BlockWeightsForAsyncBacking::get()
111 .get(DispatchClass::Normal)
112 .max_extrinsic
113 .unwrap_or(Weight::MAX)
114 }
115}
116
117impl Parachain for AssetHubWestend {
118 const PARACHAIN_ID: u32 = ASSET_HUB_WESTEND_PARACHAIN_ID;
119 const MAX_HEADER_SIZE: u32 = MAX_ASSET_HUB_HEADER_SIZE;
120}
121
122impl ChainWithMessages for AssetHubWestend {
124 const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
125 WITH_ASSET_HUB_WESTEND_MESSAGES_PALLET_NAME;
126
127 const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
128 MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
129 const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
130 MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
131}
132
133pub type AccountSigner = MultiSigner;
135
136pub type Address = MultiAddress<AccountId, ()>;
138
139pub const WITH_ASSET_HUB_WESTEND_MESSAGES_PALLET_NAME: &str = "BridgeWestendMessages";
141
142pub const WITH_ASSET_HUB_WESTEND_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";
145
146pub const WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX: u8 = 63;
148
149decl_bridge_finality_runtime_apis!(asset_hub_westend);
150decl_bridge_messages_runtime_apis!(asset_hub_westend, HashedLaneId);