|
19 | 19 | mod origins;
|
20 | 20 | mod tracks;
|
21 | 21 | use crate::{
|
22 |
| - impls::ToParentTreasury, weights, AccountId, Balance, Balances, FellowshipReferenda, |
23 |
| - GovernanceLocation, PolkadotTreasuryAccount, Preimage, Runtime, RuntimeCall, RuntimeEvent, |
24 |
| - RuntimeOrigin, Scheduler, DAYS, |
| 22 | + impls::ToParentTreasury, weights, xcm_config::TreasurerBodyId, AccountId, AssetRate, Balance, |
| 23 | + Balances, FellowshipReferenda, GovernanceLocation, PolkadotTreasuryAccount, Preimage, Runtime, |
| 24 | + RuntimeCall, RuntimeEvent, RuntimeOrigin, Scheduler, DAYS, |
25 | 25 | };
|
26 | 26 | use cumulus_primitives_core::Junction::GeneralIndex;
|
27 | 27 | use frame_support::{
|
28 | 28 | parameter_types,
|
29 |
| - traits::{EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, TryWithMorphedArg}, |
| 29 | + traits::{ |
| 30 | + EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, PalletInfoAccess, TryWithMorphedArg, |
| 31 | + }, |
| 32 | + PalletId, |
30 | 33 | };
|
31 |
| -use frame_system::EnsureRootWithSuccess; |
| 34 | +use frame_system::{EnsureRoot, EnsureRootWithSuccess}; |
32 | 35 | pub use origins::{
|
33 | 36 | pallet_origins as pallet_fellowship_origins, Architects, EnsureCanPromoteTo, EnsureCanRetainAt,
|
34 | 37 | EnsureFellowship, Fellows, Masters, Members, ToVoice,
|
35 | 38 | };
|
36 | 39 | use pallet_ranked_collective::EnsureOfRank;
|
37 | 40 | use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
|
38 | 41 | use parachains_common::polkadot::account;
|
39 |
| -use polkadot_runtime_constants::{time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX}; |
| 42 | +use polkadot_runtime_common::impls::{ |
| 43 | + LocatableAssetConverter, VersionedLocatableAsset, VersionedMultiLocationConverter, |
| 44 | +}; |
| 45 | +use polkadot_runtime_constants::{currency::GRAND, time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX}; |
| 46 | +use sp_arithmetic::Permill; |
40 | 47 | use sp_core::{ConstU128, ConstU32};
|
41 |
| -use sp_runtime::traits::{AccountIdConversion, ConstU16, ConvertToValue, Replace, TakeFirst}; |
| 48 | +use sp_runtime::traits::{ |
| 49 | + AccountIdConversion, ConstU16, ConvertToValue, IdentityLookup, Replace, TakeFirst, |
| 50 | +}; |
42 | 51 | use xcm::latest::BodyId;
|
43 | 52 | use xcm_builder::{AliasesIntoAccountId32, LocatableAssetId, PayOverXcm};
|
44 | 53 |
|
@@ -244,3 +253,124 @@ impl pallet_salary::Config<FellowshipSalaryInstance> for Runtime {
|
244 | 253 | // Total monthly salary budget.
|
245 | 254 | type Budget = ConstU128<{ 100_000 * USDT_UNITS }>;
|
246 | 255 | }
|
| 256 | + |
| 257 | +parameter_types! { |
| 258 | + // TODO: reference the constant value from common crate when polkadot-sdk 1.5 is released. |
| 259 | + // https://github.com/polkadot-fellows/runtimes/issues/113 |
| 260 | + pub const FellowshipTreasuryPalletId: PalletId = PalletId(*b"py/feltr"); |
| 261 | + pub const ProposalBond: Permill = Permill::from_percent(100); |
| 262 | + pub const Burn: Permill = Permill::from_percent(0); |
| 263 | + pub const MaxBalance: Balance = Balance::max_value(); |
| 264 | + // The asset's interior location for the paying account. This is the Fellowship Treasury |
| 265 | + // pallet instance (which sits at index 65). |
| 266 | + pub FellowshipTreasuryInteriorLocation: InteriorMultiLocation = |
| 267 | + PalletInstance(<crate::FellowshipTreasury as PalletInfoAccess>::index() as u8).into(); |
| 268 | +} |
| 269 | + |
| 270 | +/// [`PayOverXcm`] setup to pay the Fellowship Treasury. |
| 271 | +pub type FellowshipTreasuryPaymaster = PayOverXcm< |
| 272 | + FellowshipTreasuryInteriorLocation, |
| 273 | + crate::xcm_config::XcmRouter, |
| 274 | + crate::PolkadotXcm, |
| 275 | + ConstU32<{ 6 * HOURS }>, |
| 276 | + VersionedMultiLocation, |
| 277 | + VersionedLocatableAsset, |
| 278 | + LocatableAssetConverter, |
| 279 | + VersionedMultiLocationConverter, |
| 280 | +>; |
| 281 | + |
| 282 | +pub type FellowshipTreasuryInstance = pallet_treasury::Instance1; |
| 283 | + |
| 284 | +impl pallet_treasury::Config<FellowshipTreasuryInstance> for Runtime { |
| 285 | + // The creation of proposals via the treasury pallet is deprecated and should not be utilized. |
| 286 | + // Instead, public or fellowship referenda should be used to propose and command the treasury |
| 287 | + // spend or spend_local dispatchables. The parameters below have been configured accordingly to |
| 288 | + // discourage its use. |
| 289 | + // TODO: replace with `NeverEnsure` once polkadot-sdk 1.5 is released. |
| 290 | + // https://github.com/polkadot-fellows/runtimes/issues/113 |
| 291 | + type ApproveOrigin = EnsureRoot<AccountId>; |
| 292 | + type OnSlash = (); |
| 293 | + type ProposalBond = ProposalBond; |
| 294 | + type ProposalBondMinimum = MaxBalance; |
| 295 | + type ProposalBondMaximum = MaxBalance; |
| 296 | + // end. |
| 297 | + |
| 298 | + type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>; |
| 299 | + type RuntimeEvent = RuntimeEvent; |
| 300 | + type PalletId = FellowshipTreasuryPalletId; |
| 301 | + type Currency = Balances; |
| 302 | + type RejectOrigin = EitherOfDiverse< |
| 303 | + EnsureRoot<AccountId>, |
| 304 | + EitherOfDiverse<EnsureXcm<IsVoiceOfBody<GovernanceLocation, TreasurerBodyId>>, Fellows>, |
| 305 | + >; |
| 306 | + type SpendPeriod = ConstU32<{ 7 * DAYS }>; |
| 307 | + type Burn = Burn; |
| 308 | + type BurnDestination = (); |
| 309 | + type SpendFunds = (); |
| 310 | + type MaxApprovals = ConstU32<100>; |
| 311 | + type SpendOrigin = EitherOf< |
| 312 | + EitherOf< |
| 313 | + EnsureRootWithSuccess<AccountId, MaxBalance>, |
| 314 | + MapSuccess< |
| 315 | + EnsureXcm<IsVoiceOfBody<GovernanceLocation, TreasurerBodyId>>, |
| 316 | + Replace<ConstU128<{ 10_000 * GRAND }>>, |
| 317 | + >, |
| 318 | + >, |
| 319 | + EitherOf< |
| 320 | + MapSuccess<Architects, Replace<ConstU128<{ 10_000 * GRAND }>>>, |
| 321 | + MapSuccess<Fellows, Replace<ConstU128<{ 10 * GRAND }>>>, |
| 322 | + >, |
| 323 | + >; |
| 324 | + type AssetKind = VersionedLocatableAsset; |
| 325 | + type Beneficiary = VersionedMultiLocation; |
| 326 | + type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>; |
| 327 | + #[cfg(not(feature = "runtime-benchmarks"))] |
| 328 | + type Paymaster = FellowshipTreasuryPaymaster; |
| 329 | + #[cfg(feature = "runtime-benchmarks")] |
| 330 | + type Paymaster = PayWithEnsure<FellowshipTreasuryPaymaster, OpenHrmpChannel<ConstU32<1000>>>; |
| 331 | + type BalanceConverter = AssetRate; |
| 332 | + type PayoutPeriod = ConstU32<{ 30 * DAYS }>; |
| 333 | + #[cfg(feature = "runtime-benchmarks")] |
| 334 | + type BenchmarkHelper = benchmarks::TreasuryArguments<sp_core::ConstU8<1>, ConstU32<1000>>; |
| 335 | +} |
| 336 | + |
| 337 | +// TODO: replace by [`polkadot_runtime_common::impls::benchmarks::TreasuryArguments`] when |
| 338 | +// polkadot-sdk 1.5 is released. |
| 339 | +// https://github.com/polkadot-fellows/runtimes/issues/113 |
| 340 | +#[cfg(feature = "runtime-benchmarks")] |
| 341 | +mod benchmarks { |
| 342 | + use super::VersionedLocatableAsset; |
| 343 | + use core::marker::PhantomData; |
| 344 | + use frame_support::traits::Get; |
| 345 | + use pallet_treasury::ArgumentsFactory as TreasuryArgumentsFactory; |
| 346 | + use sp_core::{ConstU32, ConstU8}; |
| 347 | + use xcm::prelude::*; |
| 348 | + |
| 349 | + /// Provide factory methods for the [`VersionedLocatableAsset`] and the `Beneficiary` of the |
| 350 | + /// [`VersionedMultiLocation`]. The location of the asset is determined as a Parachain with an |
| 351 | + /// ID equal to the passed seed. |
| 352 | + pub struct TreasuryArguments<Parents = ConstU8<0>, ParaId = ConstU32<0>>( |
| 353 | + PhantomData<(Parents, ParaId)>, |
| 354 | + ); |
| 355 | + impl<Parents: Get<u8>, ParaId: Get<u32>> |
| 356 | + TreasuryArgumentsFactory<VersionedLocatableAsset, VersionedMultiLocation> |
| 357 | + for TreasuryArguments<Parents, ParaId> |
| 358 | + { |
| 359 | + fn create_asset_kind(seed: u32) -> VersionedLocatableAsset { |
| 360 | + VersionedLocatableAsset::V3 { |
| 361 | + location: xcm::v3::MultiLocation::new(Parents::get(), X1(Parachain(ParaId::get()))), |
| 362 | + asset_id: xcm::v3::MultiLocation::new( |
| 363 | + 0, |
| 364 | + X2(PalletInstance(seed.try_into().unwrap()), GeneralIndex(seed.into())), |
| 365 | + ) |
| 366 | + .into(), |
| 367 | + } |
| 368 | + } |
| 369 | + fn create_beneficiary(seed: [u8; 32]) -> VersionedMultiLocation { |
| 370 | + VersionedMultiLocation::V3(xcm::v3::MultiLocation::new( |
| 371 | + 0, |
| 372 | + X1(AccountId32 { network: None, id: seed }), |
| 373 | + )) |
| 374 | + } |
| 375 | + } |
| 376 | +} |
0 commit comments