1
// Copyright 2025 Moonbeam foundation
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam 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
// Moonbeam 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 Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
//! Chain-specific pallet and call indices for XCM Transactor
18
//!
19
//! This module defines indices structures for different chains (Relay, AssetHub)
20
//! to enable proper SCALE encoding of remote calls.
21

            
22
use parity_scale_codec::{Decode, Encode};
23
use scale_info::TypeInfo;
24
use serde::{Deserialize, Serialize};
25

            
26
/// Relay Chain pallet and call indices
27
///
28
/// These indices are used to encode calls for the Relay Chain (Polkadot/Kusama).
29
#[derive(
30
1350
	Clone, Copy, Debug, Default, Deserialize, Serialize, Encode, Decode, TypeInfo, PartialEq, Eq,
31
)]
32
pub struct RelayChainIndices {
33
	// Pallet indices
34
	pub staking: u8,
35
	pub utility: u8,
36
	pub hrmp: u8,
37
	// Staking indices
38
	pub bond: u8,
39
	pub bond_extra: u8,
40
	pub unbond: u8,
41
	pub withdraw_unbonded: u8,
42
	pub validate: u8,
43
	pub nominate: u8,
44
	pub chill: u8,
45
	pub set_payee: u8,
46
	pub set_controller: u8,
47
	pub rebond: u8,
48
	// Utility indices
49
	pub as_derivative: u8,
50
	// Hrmp indices
51
	pub init_open_channel: u8,
52
	pub accept_open_channel: u8,
53
	pub close_channel: u8,
54
	pub cancel_open_request: u8,
55
}
56

            
57
/// AssetHub pallet and call indices
58
///
59
/// These indices are used to encode calls for AssetHub system parachain.
60
/// Network-specific values are defined in the `moonbeam-assethub-encoder` crate.
61
#[derive(
62
1725
	Clone, Copy, Debug, Default, Deserialize, Serialize, Encode, Decode, TypeInfo, PartialEq, Eq,
63
)]
64
pub struct AssetHubIndices {
65
	// Pallet indices
66
	pub utility: u8,
67
	pub proxy: u8,
68
	pub staking: u8,
69
	pub nomination_pools: u8,
70
	pub delegated_staking: u8,
71
	pub assets: u8,
72
	pub nfts: u8,
73

            
74
	// Utility call indices
75
	pub as_derivative: u8,
76
	pub batch: u8,
77
	pub batch_all: u8,
78

            
79
	// Proxy call indices
80
	pub proxy_call: u8,
81
	pub add_proxy: u8,
82
	pub remove_proxy: u8,
83

            
84
	// Staking call indices
85
	pub bond: u8,
86
	pub bond_extra: u8,
87
	pub unbond: u8,
88
	pub withdraw_unbonded: u8,
89
	pub validate: u8,
90
	pub nominate: u8,
91
	pub chill: u8,
92
	pub set_payee: u8,
93
	pub set_controller: u8,
94
	pub rebond: u8,
95
}
96

            
97
/// Unified chain indices enum
98
///
99
/// Wraps either RelayChainIndices or AssetHubIndices depending on the target chain
100
150
#[derive(Clone, Debug, Deserialize, Serialize, Encode, Decode, TypeInfo, PartialEq, Eq)]
101
pub enum ChainIndices {
102
	Relay(RelayChainIndices),
103
	AssetHub(AssetHubIndices),
104
}
105

            
106
impl Default for ChainIndices {
107
	fn default() -> Self {
108
		ChainIndices::Relay(RelayChainIndices::default())
109
	}
110
}