diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index e0d73b910..e0890ee3f 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -116,6 +116,12 @@ pub mod proxy { NonTransfer, /// Proxy with the ability to reject time-delay proxy announcements. CancelProxy, + /// Assets proxy. Can execute any call from `assets`, **including asset transfers**. + Assets, + /// Owner proxy. Can execute calls related to asset ownership. + AssetOwner, + /// Asset manager. Can execute calls related to asset management. + AssetManager, /// Collator selection proxy. Can execute calls related to collator selection mechanism. Collator, } @@ -131,6 +137,8 @@ pub mod proxy { (x, y) if x == y => true, (ProxyType::Any, _) => true, (_, ProxyType::Any) => false, + (ProxyType::Assets, ProxyType::AssetOwner) => true, + (ProxyType::Assets, ProxyType::AssetManager) => true, (ProxyType::NonTransfer, ProxyType::Collator) => true, _ => false, } diff --git a/runtime/mainnet/src/config/proxy.rs b/runtime/mainnet/src/config/proxy.rs index 27dbb803c..607ed91e1 100644 --- a/runtime/mainnet/src/config/proxy.rs +++ b/runtime/mainnet/src/config/proxy.rs @@ -1,10 +1,54 @@ +use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::traits::InstanceFilter; -use pop_runtime_common::proxy::{MaxPending, MaxProxies, ProxyType}; +use pop_runtime_common::proxy::{MaxPending, MaxProxies}; +use sp_runtime::RuntimeDebug; use crate::{ deposit, parameter_types, Balance, Balances, BlakeTwo256, Runtime, RuntimeCall, RuntimeEvent, }; +/// 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 { + /// Fully permissioned proxy. Can execute any call on behalf of _proxied_. + Any, + /// Can execute any call that does not transfer funds or assets. + NonTransfer, + /// Proxy with the ability to reject time-delay proxy announcements. + CancelProxy, + /// Collator selection proxy. Can execute calls related to collator selection mechanism. + Collator, +} +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +impl ProxyType { + pub fn is_superset(s: &ProxyType, o: &ProxyType) -> bool { + match (s, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + (ProxyType::NonTransfer, ProxyType::Collator) => true, + _ => false, + } + } +} + impl InstanceFilter for ProxyType { fn filter(&self, c: &RuntimeCall) -> bool { match self { @@ -64,6 +108,37 @@ mod tests { use super::*; + #[test] + fn proxy_type_default_is_any() { + assert_eq!(ProxyType::default(), ProxyType::Any); + } + + #[test] + fn proxy_type_superset_as_defined() { + let all_proxies = vec![ + ProxyType::Any, + ProxyType::NonTransfer, + ProxyType::CancelProxy, + ProxyType::Collator, + ]; + for proxy in all_proxies { + // Every proxy is part of itself. + assert!(ProxyType::is_superset(&proxy, &proxy)); + + // Any contains all others, but is not contained. + if proxy != ProxyType::Any { + assert!(ProxyType::is_superset(&ProxyType::Any, &proxy)); + assert!(!ProxyType::is_superset(&proxy, &ProxyType::Any)); + } + // CancelProxy does not contain any other proxy. + if proxy != ProxyType::CancelProxy { + assert!(!ProxyType::is_superset(&ProxyType::CancelProxy, &proxy)); + } + } + assert!(ProxyType::is_superset(&ProxyType::NonTransfer, &ProxyType::Collator)); + assert!(!ProxyType::is_superset(&ProxyType::Collator, &ProxyType::NonTransfer)); + } + #[test] fn proxy_has_announcement_deposit_base() { assert_eq!(