Skip to content

Commit

Permalink
Add Proxy pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
NZT48 committed Apr 22, 2024
1 parent 51d5fdd commit 42d2b82
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 8 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pallet-aura = { git = "https://github.com/paritytech/substrate", default-feature
pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-proxy = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.40" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.40" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
Expand Down Expand Up @@ -134,6 +135,7 @@ std = [
"pallet-ethereum/std",
"pallet-identity/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-multisig/std",
"pallet-scheduler/std",
"pallet-session/std",
Expand Down Expand Up @@ -179,6 +181,7 @@ runtime-benchmarks = [
"pallet-ethereum/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
Expand Down Expand Up @@ -209,6 +212,7 @@ try-runtime = [
"pallet-democracy/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
"pallet-utility/try-runtime",
Expand Down
90 changes: 84 additions & 6 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ use sp_runtime::{
transaction_validity::{
TransactionSource, TransactionValidity, TransactionValidityError
},
ApplyExtrinsicResult, MultiSignature,
ApplyExtrinsicResult, MultiSignature, RuntimeDebug,
};

use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use codec::{Encode};
pub use frame_support::traits::EqualPrivilegeOnly;
use codec::{Encode, Decode, MaxEncodedLen};
use frame_support::{
construct_runtime, parameter_types, transactional,
traits::{
AsEnsureOriginWithArg, Currency as PalletCurrency, EitherOfDiverse, Everything, FindAuthor,
ReservableCurrency, Imbalance, OnUnbalanced, ConstU128, ConstU32, ConstU64, ConstU8,
WithdrawReasons
AsEnsureOriginWithArg, Currency as PalletCurrency, EqualPrivilegeOnly, EitherOfDiverse,
Everything, FindAuthor, ReservableCurrency, Imbalance, InstanceFilter, OnUnbalanced,
ConstU128, ConstU32, ConstU64, ConstU8, WithdrawReasons,
},
dispatch::DispatchClass,
weights::{
Expand Down Expand Up @@ -1052,6 +1051,83 @@ impl pallet_identity::Config for Runtime {
type WeightInfo = pallet_identity::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
// One storage item; key size 32, value size 8; .
pub const ProxyDepositBase: Balance = deposit(1, 8);
// Additional storage item size of 33 bytes.
pub const ProxyDepositFactor: Balance = deposit(0, 33);
pub const AnnouncementDepositBase: Balance = deposit(1, 8);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
}

/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
)]
pub enum ProxyType {
Any,
NonTransfer,
Governance,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(
c,
RuntimeCall::Balances(..) |
RuntimeCall::Assets(..) |
RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. })
),
ProxyType::Governance => matches!(
c,
RuntimeCall::Democracy(..) |
RuntimeCall::Council(..) |
RuntimeCall::Treasury(..)
),
}
}
fn is_superset(&self, o: &Self) -> bool {
match (self, o) {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
(ProxyType::NonTransfer, _) => true,
_ => false,
}
}
}

impl pallet_proxy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type ProxyType = ProxyType;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = ConstU32<32>;
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Runtime>;
type MaxPending = ConstU32<32>;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
Expand All @@ -1068,6 +1144,7 @@ construct_runtime!(
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 3,
Utility: pallet_utility = 4,
Multisig: pallet_multisig = 5,
Proxy: pallet_proxy = 6,

// Monetary stuff.
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 10,
Expand Down Expand Up @@ -1118,6 +1195,7 @@ mod benches {
[pallet_democracy, Democracy]
[pallet_identity, Identity]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_session, SessionBench::<Runtime>]
[pallet_timestamp, Timestamp]
[pallet_collator_selection, CollatorSelection]
Expand Down

0 comments on commit 42d2b82

Please sign in to comment.