diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs index 83863c8c475..4f821802172 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/impls.rs @@ -14,14 +14,21 @@ // limitations under the License. use frame_support::{ + dispatch::{DispatchError, DispatchResultWithPostInfo}, log, traits::{Currency, Get, Imbalance, OnUnbalanced, OriginTrait}, + weights::Weight, }; +use pallet_alliance::{ProposalIndex, ProposalProvider}; use sp_std::{boxed::Box, marker::PhantomData}; use xcm::latest::{Fungibility, Junction, NetworkId, Parent}; type AccountIdOf = ::AccountId; +type ProposalOf = >::Proposal; + +type HashOf = ::Hash; + type NegativeImbalanceOf = <>::Currency as Currency< ::AccountId, >>::NegativeImbalance; @@ -32,6 +39,7 @@ type BalanceOf = <>::Currency as Currency< ::AccountId, >>::Balance; +/// Implements `OnUnbalanced::on_unbalanced` to teleport slashed assets to relay chain treasury account. pub struct ToParentTreasury( PhantomData<(TreasuryAcc, TempAcc, T, I)>, ); @@ -71,3 +79,59 @@ where }; } } + +/// Proposal provider for alliance pallet. +/// Adapter from collective pallet to alliance proposal provider trait. +pub struct AllianceProposalProvider(PhantomData<(T, I)>); + +impl ProposalProvider, HashOf, ProposalOf> + for AllianceProposalProvider +where + T: pallet_collective::Config + frame_system::Config, + I: 'static, +{ + fn propose_proposal( + who: AccountIdOf, + threshold: u32, + proposal: Box>, + length_bound: u32, + ) -> Result<(u32, u32), DispatchError> { + pallet_collective::Pallet::::do_propose_proposed( + who, + threshold, + proposal, + length_bound, + ) + } + + fn vote_proposal( + who: AccountIdOf, + proposal: HashOf, + index: ProposalIndex, + approve: bool, + ) -> Result { + pallet_collective::Pallet::::do_vote(who, proposal, index, approve) + } + + fn veto_proposal(proposal_hash: HashOf) -> u32 { + pallet_collective::Pallet::::do_disapprove_proposal(proposal_hash) + } + + fn close_proposal( + proposal_hash: HashOf, + proposal_index: ProposalIndex, + proposal_weight_bound: Weight, + length_bound: u32, + ) -> DispatchResultWithPostInfo { + pallet_collective::Pallet::::do_close( + proposal_hash, + proposal_index, + proposal_weight_bound, + length_bound, + ) + } + + fn proposal_of(proposal_hash: HashOf) -> Option> { + pallet_collective::Pallet::::proposal_of(proposal_hash) + } +} diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index 2241a7b5a1d..2307de4fd14 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -43,7 +43,7 @@ mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use impls::ToParentTreasury; +use impls::{AllianceProposalProvider, ToParentTreasury}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -61,9 +61,7 @@ use sp_version::RuntimeVersion; use codec::{Decode, Encode, MaxEncodedLen}; use constants::{currency::*, fee::WeightToFee}; use frame_support::{ - construct_runtime, - pallet_prelude::*, - parameter_types, + construct_runtime, parameter_types, traits::{ConstU16, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter}, weights::{ConstantMultiplier, DispatchClass, Weight}, PalletId, RuntimeDebug, @@ -72,7 +70,6 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, }; -use pallet_alliance::{ProposalIndex, ProposalProvider}; pub use parachains_common as common; use parachains_common::{ impls::DealWithFees, opaque, AccountId, AuraId, Balance, BlockNumber, Hash, Header, Index, @@ -421,44 +418,6 @@ impl pallet_collator_selection::Config for Runtime { type WeightInfo = weights::pallet_collator_selection::WeightInfo; } -pub struct AllianceProposalProvider; -impl ProposalProvider for AllianceProposalProvider { - fn propose_proposal( - who: AccountId, - threshold: u32, - proposal: Box, - length_bound: u32, - ) -> Result<(u32, u32), DispatchError> { - AllianceMotion::do_propose_proposed(who, threshold, proposal, length_bound) - } - - fn vote_proposal( - who: AccountId, - proposal: Hash, - index: ProposalIndex, - approve: bool, - ) -> Result { - AllianceMotion::do_vote(who, proposal, index, approve) - } - - fn veto_proposal(proposal_hash: Hash) -> u32 { - AllianceMotion::do_disapprove_proposal(proposal_hash) - } - - fn close_proposal( - proposal_hash: Hash, - proposal_index: ProposalIndex, - proposal_weight_bound: Weight, - length_bound: u32, - ) -> DispatchResultWithPostInfo { - AllianceMotion::do_close(proposal_hash, proposal_index, proposal_weight_bound, length_bound) - } - - fn proposal_of(proposal_hash: Hash) -> Option { - AllianceMotion::proposal_of(proposal_hash) - } -} - parameter_types! { pub const AllianceMotionDuration: BlockNumber = 5 * DAYS; @@ -509,7 +468,7 @@ impl pallet_alliance::Config for Runtime { type InitializeMembers = AllianceMotion; type MembershipChanged = AllianceMotion; type IdentityVerifier = (); // Don't block accounts on identity criteria - type ProposalProvider = AllianceProposalProvider; + type ProposalProvider = AllianceProposalProvider; type MaxProposals = ConstU32; type MaxFounders = ConstU32; type MaxFellows = ConstU32;