referrerpolicy=no-referrer-when-downgrade

collectives_westend_runtime/secretary/
mod.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! The Westend Technical Fellowship.
18
19//! The Polkadot Secretary Collective.
20
21use crate::{xcm_config::FellowshipAdminBodyId, *};
22use frame_support::{
23	parameter_types,
24	traits::{tokens::GetSalary, EitherOf, MapSuccess, NoOpPoll, PalletInfoAccess},
25};
26use frame_system::{pallet_prelude::BlockNumberFor, EnsureRootWithSuccess};
27use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
28use sp_core::{ConstU128, ConstU32};
29use sp_runtime::traits::{ConstU16, ConvertToValue, Identity, Replace};
30use westend_runtime_constants::time::HOURS;
31
32#[cfg(feature = "runtime-benchmarks")]
33use crate::impls::benchmarks::OpenHrmpChannel;
34
35use xcm::prelude::*;
36use xcm_builder::{AliasesIntoAccountId32, PayOverXcm};
37
38use self::xcm_config::UsdtAssetHub;
39
40/// The Secretary members' ranks.
41pub mod ranks {
42	use pallet_ranked_collective::Rank;
43
44	pub const SECRETARY_CANDIDATE: Rank = 0;
45	pub const SECRETARY: Rank = 1;
46}
47
48/// Origins of:
49/// - Root;
50/// - FellowshipAdmin (i.e. token holder referendum);
51/// - Plurality vote from Fellows can promote, demote, remove and approve rank retention of members
52///   of the Secretary Collective (rank `2`).
53type ApproveOrigin = EitherOf<
54	EnsureRootWithSuccess<AccountId, ConstU16<65535>>,
55	EitherOf<
56		MapSuccess<
57			EnsureXcm<IsVoiceOfBody<GovernanceLocation, FellowshipAdminBodyId>>,
58			Replace<ConstU16<65535>>,
59		>,
60		MapSuccess<Fellows, Replace<ConstU16<65535>>>,
61	>,
62>;
63
64pub type SecretaryCollectiveInstance = pallet_ranked_collective::Instance3;
65
66impl pallet_ranked_collective::Config<SecretaryCollectiveInstance> for Runtime {
67	type WeightInfo = ();
68	type RuntimeEvent = RuntimeEvent;
69	type AddOrigin = ApproveOrigin;
70	type RemoveOrigin = ApproveOrigin;
71	type PromoteOrigin = ApproveOrigin;
72	type DemoteOrigin = ApproveOrigin;
73	type ExchangeOrigin = ApproveOrigin;
74	type Polls = NoOpPoll<BlockNumberFor<Runtime>>;
75	type MinRankOfClass = Identity;
76	type MemberSwappedHandler = crate::SecretarySalary;
77	type VoteWeight = pallet_ranked_collective::Geometric;
78	type MaxMemberCount = ();
79	#[cfg(feature = "runtime-benchmarks")]
80	type BenchmarkSetup = crate::SecretarySalary;
81}
82
83pub type SecretarySalaryInstance = pallet_salary::Instance3;
84
85parameter_types! {
86	// The interior location on AssetHub for the paying account. This is the Secretary Salary
87	// pallet instance. This sovereign account will need funding.
88	pub SecretarySalaryInteriorLocation: InteriorLocation = PalletInstance(<crate::SecretarySalary as PalletInfoAccess>::index() as u8).into();
89}
90
91const USDT_UNITS: u128 = 1_000_000;
92
93/// [`PayOverXcm`] setup to pay the Secretary salary on the AssetHub in USDT.
94pub type SecretarySalaryPaymaster = PayOverXcm<
95	SecretarySalaryInteriorLocation,
96	crate::xcm_config::XcmRouter,
97	crate::PolkadotXcm,
98	ConstU32<{ 6 * HOURS }>,
99	AccountId,
100	(),
101	ConvertToValue<UsdtAssetHub>,
102	AliasesIntoAccountId32<(), AccountId>,
103>;
104
105pub struct SalaryForRank;
106impl GetSalary<u16, AccountId, Balance> for SalaryForRank {
107	fn get_salary(rank: u16, _who: &AccountId) -> Balance {
108		if rank == 1 {
109			6666 * USDT_UNITS
110		} else {
111			0
112		}
113	}
114}
115
116impl pallet_salary::Config<SecretarySalaryInstance> for Runtime {
117	type WeightInfo = ();
118	type RuntimeEvent = RuntimeEvent;
119
120	#[cfg(not(feature = "runtime-benchmarks"))]
121	type Paymaster = SecretarySalaryPaymaster;
122	#[cfg(feature = "runtime-benchmarks")]
123	type Paymaster = crate::impls::benchmarks::PayWithEnsure<
124		SecretarySalaryPaymaster,
125		OpenHrmpChannel<ConstU32<1000>>,
126	>;
127	type Members = pallet_ranked_collective::Pallet<Runtime, SecretaryCollectiveInstance>;
128
129	#[cfg(not(feature = "runtime-benchmarks"))]
130	type Salary = SalaryForRank;
131	#[cfg(feature = "runtime-benchmarks")]
132	type Salary = frame_support::traits::tokens::ConvertRank<
133		crate::impls::benchmarks::RankToSalary<Balances>,
134	>;
135	// 15 days to register for a salary payment.
136	type RegistrationPeriod = ConstU32<{ 15 * DAYS }>;
137	// 15 days to claim the salary payment.
138	type PayoutPeriod = ConstU32<{ 15 * DAYS }>;
139	// Total monthly salary budget.
140	type Budget = ConstU128<{ 6666 * USDT_UNITS }>;
141}