[10] add proxy pallet

This commit is contained in:
Nikita Khateev
2023-11-20 17:39:12 +04:00
parent 999808e9d6
commit 5e4cef4117
8 changed files with 115 additions and 13 deletions
+70 -10
View File
@@ -11,6 +11,8 @@ use constants::currency::*;
mod weights;
pub mod xcm_config;
use codec::{Decode, Encode, MaxEncodedLen};
use common::{deposit, EXISTENTIAL_DEPOSIT, MICROUNIT, MILLIUNIT};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_primitives_core::ParaId;
use frame_support::{
@@ -18,7 +20,7 @@ use frame_support::{
dispatch::DispatchClass,
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything},
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, InstanceFilter},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
@@ -36,6 +38,7 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
// Polkadot imports
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use scale_info::TypeInfo;
use smallvec::smallvec;
use sp_api::impl_runtime_apis;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
@@ -46,7 +49,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
ApplyExtrinsicResult, MultiSignature, RuntimeDebug,
};
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use sp_std::prelude::*;
@@ -207,14 +210,6 @@ pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
// Unit = the base number of indivisible units for balances
pub const UNIT: Balance = 1_000_000_000_000;
pub const MILLIUNIT: Balance = 1_000_000_000;
pub const MICROUNIT: Balance = 1_000_000;
/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
/// We assume that ~5% of the block weight is consumed by `on_initialize`
/// handlers. This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
@@ -341,6 +336,70 @@ impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
}
parameter_types! {
pub const MaxProxies: u32 = 32;
pub const MaxPending: u32 = 32;
pub const ProxyDepositBase: Balance = deposit(1, 40);
pub const AnnouncementDepositBase: Balance = deposit(1, 48);
pub const ProxyDepositFactor: Balance = deposit(0, 33);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
}
/// The type used to represent the kinds of proxying allowed.
/// If you are adding new pallets, consider adding new proxy type
#[derive(
Copy,
Clone,
Decode,
Default,
Encode,
Eq,
MaxEncodedLen,
Ord,
PartialEq,
PartialOrd,
RuntimeDebug,
TypeInfo,
)]
pub enum ProxyType {
/// Allows to proxy all calls
#[default]
Any,
/// Allows all non-transfer calls
NonTransfer,
/// Allows to finish the proxy
CancelProxy,
/// Allows to operate with collators list (invulnerables, candidates, etc.)
Collator,
}
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances { .. }),
ProxyType::CancelProxy =>
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })),
ProxyType::Collator => matches!(c, RuntimeCall::CollatorSelection { .. }),
}
}
}
impl pallet_proxy::Config for Runtime {
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type CallHasher = BlakeTwo256;
type Currency = Balances;
type MaxPending = MaxPending;
type MaxProxies = MaxProxies;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type ProxyType = ProxyType;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Runtime>;
}
parameter_types! {
pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
}
@@ -520,6 +579,7 @@ construct_runtime!(
ParachainSystem: cumulus_pallet_parachain_system = 1,
Timestamp: pallet_timestamp = 2,
ParachainInfo: parachain_info = 3,
Proxy: pallet_proxy = 4,
// Monetary stuff.
Balances: pallet_balances = 10,