diff --git a/Cargo.lock b/Cargo.lock index a992270b3..2ec5f9454 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -240,6 +240,7 @@ dependencies = [ "pallet-insecure-randomness-collective-flip", "pallet-multisig", "pallet-preimage", + "pallet-proxy", "pallet-scheduler", "pallet-session", "pallet-timestamp", @@ -3050,6 +3051,7 @@ dependencies = [ "pallet-insecure-randomness-collective-flip", "pallet-multisig", "pallet-preimage", + "pallet-proxy", "pallet-scheduler", "pallet-session", "pallet-sudo", @@ -7732,6 +7734,7 @@ dependencies = [ "pallet-insecure-randomness-collective-flip", "pallet-multisig", "pallet-preimage", + "pallet-proxy", "pallet-scheduler", "pallet-session", "pallet-timestamp", diff --git a/runtime/amplitude/Cargo.toml b/runtime/amplitude/Cargo.toml index 06a498f64..885c580c5 100644 --- a/runtime/amplitude/Cargo.toml +++ b/runtime/amplitude/Cargo.toml @@ -66,6 +66,7 @@ pallet-democracy = { git = "https://github.com/paritytech/substrate", default-fe pallet-identity = { 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-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } pallet-insecure-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } @@ -172,6 +173,7 @@ std = [ "pallet-identity/std", "pallet-multisig/std", "pallet-preimage/std", + "pallet-proxy/std", "pallet-insecure-randomness-collective-flip/std", "pallet-scheduler/std", "pallet-session/std", diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index 4342d7b51..343644675 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -45,7 +45,7 @@ use frame_support::{ parameter_types, traits::{ ConstBool, ConstU32, Contains, Currency as FrameCurrency, EitherOfDiverse, - EqualPrivilegeOnly, Imbalance, OnUnbalanced, WithdrawReasons, + EqualPrivilegeOnly, Imbalance, InstanceFilter, OnUnbalanced, WithdrawReasons, }, weights::{ constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, @@ -61,7 +61,7 @@ pub use sp_runtime::{MultiAddress, Perbill, Permill, Perquintill}; use runtime_common::{ asset_registry, opaque, AccountId, Amount, AuraId, Balance, BlockNumber, Hash, Index, PoolId, - ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT, + ProxyType, ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT, }; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; @@ -360,7 +360,8 @@ impl Contains for BaseFilter { RuntimeCall::VaultRegistry(_) | RuntimeCall::VaultRewards(_) | RuntimeCall::Farming(_) | - RuntimeCall::AssetRegistry(_) => true, + RuntimeCall::AssetRegistry(_) | + RuntimeCall::Proxy(_) => true, // All pallets are allowed, but exhaustive match is defensive // in the case of adding new pallets. } @@ -1218,6 +1219,52 @@ impl farming::Config for Runtime { type RewardIssuer = FarmingRewardIssuerPalletId; } +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + // Always allowed RuntimeCall::Utility no matter type. + // Only transactions allowed by Proxy.filter can be executed + _ if matches!(c, RuntimeCall::Utility(..)) => true, + ProxyType::Any => true, + } + } + + // Determines whether self matches at least everything that o does. + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + _ => false, + } + } +} + +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 MaxProxies: u16 = 32; + pub const MaxPending: u16 = 32; + pub const AnnouncementDepositBase: Balance = deposit(1, 8); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); +} + +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 = MaxProxies; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = MaxPending; + 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 @@ -1247,6 +1294,7 @@ construct_runtime!( Treasury: pallet_treasury::{Pallet, Call, Storage, Event} = 19, Bounties: pallet_bounties::{Pallet, Call, Storage, Event} = 20, ChildBounties: pallet_child_bounties::{Pallet, Call, Storage, Event} = 21, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 22, // Consensus support. // The following order MUST NOT be changed: Aura -> Session -> Staking -> Authorship -> AuraExt diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 5ab947c1c..1f166a17e 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -7,6 +7,7 @@ use sp_runtime::{ pub mod asset_registry; pub mod chain_ext; +mod proxy_type; pub mod stellar; pub mod zenlink; @@ -23,6 +24,7 @@ pub type AccountId = <::Signer as IdentifyAccount>::Account /// Type for IDs of farming pools pub type PoolId = u32; +pub use proxy_type::*; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; /// Balance of an account. diff --git a/runtime/common/src/proxy_type.rs b/runtime/common/src/proxy_type.rs new file mode 100644 index 000000000..f7beeea23 --- /dev/null +++ b/runtime/common/src/proxy_type.rs @@ -0,0 +1,26 @@ +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use sp_runtime::RuntimeDebug; +/// 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 { + /// Allows all runtime calls for proxy account + Any, +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} diff --git a/runtime/foucoco/Cargo.toml b/runtime/foucoco/Cargo.toml index ab4b25701..405f04a9d 100644 --- a/runtime/foucoco/Cargo.toml +++ b/runtime/foucoco/Cargo.toml @@ -67,6 +67,7 @@ pallet-democracy = { git = "https://github.com/paritytech/substrate", default-fe pallet-identity = { 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-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } +pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } pallet-insecure-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" } @@ -174,6 +175,7 @@ std = [ "pallet-identity/std", "pallet-multisig/std", "pallet-preimage/std", + "pallet-proxy/std", "pallet-insecure-randomness-collective-flip/std", "pallet-scheduler/std", "pallet-session/std", diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index 32dbf8fce..89da3dec3 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -106,6 +106,7 @@ use orml_currencies_allowance_extension::{ use frame_support::{ log::{error, warn}, pallet_prelude::*, + traits::InstanceFilter, }; use sp_std::vec::Vec; @@ -371,7 +372,8 @@ impl Contains for BaseFilter { RuntimeCall::VaultRewards(_) | RuntimeCall::Farming(_) | RuntimeCall::TokenAllowance(_) | - RuntimeCall::AssetRegistry(_) => true, + RuntimeCall::AssetRegistry(_) | + RuntimeCall::Proxy(_) => true, // All pallets are allowed, but exhaustive match is defensive // in the case of adding new pallets. } @@ -953,7 +955,8 @@ parameter_types! { #[derive(Default)] pub struct Psp22Extension; -use runtime_common::chain_ext::*; +use runtime_common::{chain_ext::*, ProxyType}; + pub(crate) type BalanceOfForChainExt = <::MultiCurrency as orml_traits::MultiCurrency< ::AccountId, @@ -1510,6 +1513,53 @@ impl clients_info::Config for Runtime { type MaxUriLength = ConstU32<255>; } +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + // Always allowed RuntimeCall::Utility no matter type. + // Only transactions allowed by Proxy.filter can be executed + _ if matches!(c, RuntimeCall::Utility(..)) => true, + ProxyType::Any => true + } + } + + // Determines whether self matches at least everything that o does. + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + _ => false, + } + } +} + +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 MaxProxies: u16 = 32; + pub const MaxPending: u16 = 32; + pub const AnnouncementDepositBase: Balance = deposit(1, 8); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); +} + +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 = MaxProxies; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = MaxPending; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} + impl frame_system::offchain::SendTransactionTypes for Runtime where RuntimeCall: From, @@ -1548,6 +1598,7 @@ construct_runtime!( Treasury: pallet_treasury::{Pallet, Call, Storage, Event} = 19, Bounties: pallet_bounties::{Pallet, Call, Storage, Event} = 20, ChildBounties: pallet_child_bounties::{Pallet, Call, Storage, Event} = 21, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 22, // Consensus support. // The following order MUST NOT be changed: Aura -> Session -> Staking -> Authorship -> AuraExt diff --git a/runtime/pendulum/Cargo.toml b/runtime/pendulum/Cargo.toml index aeabc0d2a..c11c9eaee 100644 --- a/runtime/pendulum/Cargo.toml +++ b/runtime/pendulum/Cargo.toml @@ -48,6 +48,7 @@ pallet-democracy = {git = "https://github.com/paritytech/substrate", default-fea pallet-identity = {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-preimage = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} +pallet-proxy = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} pallet-insecure-randomness-collective-flip = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} @@ -152,6 +153,7 @@ std = [ "pallet-identity/std", "pallet-multisig/std", "pallet-preimage/std", + "pallet-proxy/std", "pallet-insecure-randomness-collective-flip/std", "pallet-scheduler/std", "pallet-session/std", diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index 6e9ade8f9..2b86a70f1 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -40,7 +40,7 @@ use frame_support::{ parameter_types, traits::{ ConstBool, ConstU32, Contains, Currency, EitherOfDiverse, EqualPrivilegeOnly, Imbalance, - OnUnbalanced, WithdrawReasons, + InstanceFilter, OnUnbalanced, WithdrawReasons, }, weights::{ constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, @@ -56,7 +56,7 @@ pub use sp_runtime::{traits::AccountIdConversion, MultiAddress, Perbill, Permill use runtime_common::{ asset_registry, opaque, AccountId, Amount, AuraId, Balance, BlockNumber, Hash, Index, - ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT, + ProxyType, ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT, }; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; @@ -269,7 +269,8 @@ impl Contains for BaseFilter { RuntimeCall::ZenlinkProtocol(_) | RuntimeCall::DiaOracleModule(_) | RuntimeCall::VestingManager(_) | - RuntimeCall::AssetRegistry(_) => true, + RuntimeCall::AssetRegistry(_) | + RuntimeCall::Proxy(_) => true, // All pallets are allowed, but exhaustive match is defensive // in the case of adding new pallets. } @@ -953,6 +954,53 @@ where } } +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + // Always allowed RuntimeCall::Utility no matter type. + // Only transactions allowed by Proxy.filter can be executed + _ if matches!(c, RuntimeCall::Utility(..)) => true, + ProxyType::Any => true, + } + } + + // Determines whether self matches at least everything that o does. + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + _ => false, + } + } +} + +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 MaxProxies: u16 = 32; + pub const MaxPending: u16 = 32; + pub const AnnouncementDepositBase: Balance = deposit(1, 8); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); +} + +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 = MaxProxies; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = MaxPending; + 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 @@ -982,6 +1030,7 @@ construct_runtime!( Treasury: pallet_treasury::{Pallet, Call, Storage, Event} = 19, Bounties: pallet_bounties::{Pallet, Call, Storage, Event} = 20, ChildBounties: pallet_child_bounties::{Pallet, Call, Storage, Event} = 21, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 22, // Consensus support. // The following order MUST NOT be changed: Aura -> Session -> Staking -> Authorship -> AuraExt