Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions parachains/runtimes/collectives/collectives-polkadot/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = <T as frame_system::Config>::AccountId;

type ProposalOf<T, I> = <T as pallet_collective::Config<I>>::Proposal;

type HashOf<T> = <T as frame_system::Config>::Hash;

type NegativeImbalanceOf<T, I> = <<T as pallet_alliance::Config<I>>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::NegativeImbalance;
Expand All @@ -32,6 +39,7 @@ type BalanceOf<T, I> = <<T as pallet_alliance::Config<I>>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::Balance;

/// Implements `OnUnbalanced::on_unbalanced` to teleport slashed assets to relay chain treasury account.
pub struct ToParentTreasury<TreasuryAcc, TempAcc, T, I = ()>(
PhantomData<(TreasuryAcc, TempAcc, T, I)>,
);
Expand Down Expand Up @@ -71,3 +79,59 @@ where
};
}
}

/// Proposal provider for alliance pallet.
/// Adapter from collective pallet to alliance proposal provider trait.
pub struct AllianceProposalProvider<T, I = ()>(PhantomData<(T, I)>);

impl<T, I> ProposalProvider<AccountIdOf<T>, HashOf<T>, ProposalOf<T, I>>
for AllianceProposalProvider<T, I>
where
T: pallet_collective::Config<I> + frame_system::Config,
I: 'static,
{
fn propose_proposal(
who: AccountIdOf<T>,
threshold: u32,
proposal: Box<ProposalOf<T, I>>,
length_bound: u32,
) -> Result<(u32, u32), DispatchError> {
pallet_collective::Pallet::<T, I>::do_propose_proposed(
who,
threshold,
proposal,
length_bound,
)
}

fn vote_proposal(
who: AccountIdOf<T>,
proposal: HashOf<T>,
index: ProposalIndex,
approve: bool,
) -> Result<bool, DispatchError> {
pallet_collective::Pallet::<T, I>::do_vote(who, proposal, index, approve)
}

fn veto_proposal(proposal_hash: HashOf<T>) -> u32 {
pallet_collective::Pallet::<T, I>::do_disapprove_proposal(proposal_hash)
}

fn close_proposal(
proposal_hash: HashOf<T>,
proposal_index: ProposalIndex,
proposal_weight_bound: Weight,
length_bound: u32,
) -> DispatchResultWithPostInfo {
pallet_collective::Pallet::<T, I>::do_close(
proposal_hash,
proposal_index,
proposal_weight_bound,
length_bound,
)
}

fn proposal_of(proposal_hash: HashOf<T>) -> Option<ProposalOf<T, I>> {
pallet_collective::Pallet::<T, I>::proposal_of(proposal_hash)
}
}
47 changes: 3 additions & 44 deletions parachains/runtimes/collectives/collectives-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -421,44 +418,6 @@ impl pallet_collator_selection::Config for Runtime {
type WeightInfo = weights::pallet_collator_selection::WeightInfo<Runtime>;
}

pub struct AllianceProposalProvider;
impl ProposalProvider<AccountId, Hash, Call> for AllianceProposalProvider {
fn propose_proposal(
who: AccountId,
threshold: u32,
proposal: Box<Call>,
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<bool, DispatchError> {
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<Call> {
AllianceMotion::proposal_of(proposal_hash)
}
}

parameter_types! {
pub const AllianceMotionDuration: BlockNumber = 5 * DAYS;

Expand Down Expand Up @@ -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<Runtime, AllianceCollective>;
type MaxProposals = ConstU32<ALLIANCE_MAX_MEMBERS>;
type MaxFounders = ConstU32<MAX_FOUNDERS>;
type MaxFellows = ConstU32<MAX_FELLOWS>;
Expand Down