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

            
17
//! traits for parachain-staking
18

            
19
use crate::weights::WeightInfo;
20
use frame_support::{dispatch::PostDispatchInfo, pallet_prelude::Weight};
21
use sp_runtime::DispatchErrorWithPostInfo;
22

            
23
pub trait OnCollatorPayout<AccountId, Balance> {
24
	fn on_collator_payout(
25
		for_round: crate::RoundIndex,
26
		collator_id: AccountId,
27
		amount: Balance,
28
	) -> Weight;
29
}
30
impl<AccountId, Balance> OnCollatorPayout<AccountId, Balance> for () {
31
56
	fn on_collator_payout(
32
56
		_for_round: crate::RoundIndex,
33
56
		_collator_id: AccountId,
34
56
		_amount: Balance,
35
56
	) -> Weight {
36
56
		Weight::zero()
37
56
	}
38
}
39

            
40
pub trait OnNewRound {
41
	fn on_new_round(round_index: crate::RoundIndex) -> Weight;
42
}
43
impl OnNewRound for () {
44
247
	fn on_new_round(_round_index: crate::RoundIndex) -> Weight {
45
247
		Weight::zero()
46
247
	}
47
}
48

            
49
/// Defines the behavior to payout the collator's reward.
50
pub trait PayoutCollatorReward<Runtime: crate::Config> {
51
	fn payout_collator_reward(
52
		round_index: crate::RoundIndex,
53
		collator_id: Runtime::AccountId,
54
		amount: crate::BalanceOf<Runtime>,
55
	) -> Weight;
56
}
57

            
58
/// Defines the default behavior for paying out the collator's reward. The amount is directly
59
/// deposited into the collator's account.
60
impl<Runtime: crate::Config> PayoutCollatorReward<Runtime> for () {
61
50
	fn payout_collator_reward(
62
50
		for_round: crate::RoundIndex,
63
50
		collator_id: Runtime::AccountId,
64
50
		amount: crate::BalanceOf<Runtime>,
65
50
	) -> Weight {
66
50
		crate::Pallet::<Runtime>::mint_collator_reward(for_round, collator_id, amount)
67
50
	}
68
}
69

            
70
pub trait OnInactiveCollator<Runtime: crate::Config> {
71
	fn on_inactive_collator(
72
		collator_id: Runtime::AccountId,
73
		round: crate::RoundIndex,
74
	) -> Result<Weight, DispatchErrorWithPostInfo<PostDispatchInfo>>;
75
}
76

            
77
impl<Runtime: crate::Config> OnInactiveCollator<Runtime> for () {
78
2
	fn on_inactive_collator(
79
2
		collator_id: <Runtime>::AccountId,
80
2
		_round: crate::RoundIndex,
81
2
	) -> Result<Weight, DispatchErrorWithPostInfo<PostDispatchInfo>> {
82
2
		crate::Pallet::<Runtime>::go_offline_inner(collator_id)?;
83
2
		Ok(<Runtime as crate::Config>::WeightInfo::go_offline(
84
2
			crate::MAX_CANDIDATES,
85
2
		))
86
2
	}
87
}