1
// Copyright 2019-2025 PureStake Inc.
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

            
16
use cumulus_primitives_core::{
17
	relay_chain::{self, HrmpChannelId},
18
	ParaId,
19
};
20
use sp_std::vec::Vec;
21
use xcm::latest::{Error as XcmError, Location};
22

            
23
// The utility calls that need to be implemented as part of
24
// using a derivative account from a certain account
25
#[derive(Debug, PartialEq, Eq)]
26
pub enum UtilityAvailableCalls {
27
	AsDerivative(u16, Vec<u8>),
28
}
29

            
30
// The hrmp calls that need to be implemented as part of
31
// HRMP management process
32
#[derive(Debug, PartialEq, Eq)]
33
pub enum HrmpAvailableCalls {
34
	InitOpenChannel(ParaId, u32, u32),
35
	AcceptOpenChannel(ParaId),
36
	CloseChannel(HrmpChannelId),
37
	CancelOpenRequest(HrmpChannelId, u32),
38
}
39

            
40
// Trait that the ensures we can encode a call with utility functions.
41
// With this trait we ensure that the user cannot control entirely the call
42
// to be performed in the destination chain. It only can control the call inside
43
// the as_derivative extrinsic, and thus, this call can only be dispatched from the
44
// derivative account
45
pub trait UtilityEncodeCall {
46
	fn encode_call(self, call: UtilityAvailableCalls) -> Vec<u8>;
47
}
48

            
49
// Trait that the ensures we can encode a call with hrmp functions.
50
// With this trait we ensure that the user cannot control entirely the call.
51
// to be performed in the destination chain.
52
pub trait HrmpEncodeCall {
53
	fn hrmp_encode_call(call: HrmpAvailableCalls) -> Result<Vec<u8>, XcmError>;
54
}
55

            
56
impl HrmpEncodeCall for () {
57
	fn hrmp_encode_call(_call: HrmpAvailableCalls) -> Result<Vec<u8>, XcmError> {
58
		Err(XcmError::Unimplemented)
59
	}
60
}
61

            
62
// Trait to ensure we can retrieve the destination if a given type
63
// It must implement UtilityEncodeCall
64
pub trait XcmTransact: UtilityEncodeCall {
65
	/// Encode call from the relay.
66
	fn destination(self) -> Location;
67
}
68

            
69
pub enum AvailableStakeCalls {
70
	Bond(
71
		relay_chain::Balance,
72
		pallet_staking::RewardDestination<relay_chain::AccountId>,
73
	),
74
	BondExtra(relay_chain::Balance),
75
	Unbond(relay_chain::Balance),
76
	WithdrawUnbonded(u32),
77
	Validate(pallet_staking::ValidatorPrefs),
78
	Nominate(Vec<relay_chain::AccountId>),
79
	Chill,
80
	SetPayee(pallet_staking::RewardDestination<relay_chain::AccountId>),
81
	SetController,
82
	Rebond(relay_chain::Balance),
83
}
84

            
85
pub trait StakeEncodeCall {
86
	/// Encode call from the relay.
87
	fn encode_call(call: AvailableStakeCalls) -> Vec<u8>;
88
}