Skip to content

Commit

Permalink
refactor(proxy): revert d3bfc6c and redefine ProxyType for mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
al3mart committed Jan 29, 2025
1 parent d4c936e commit 0716b86
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
8 changes: 8 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down
77 changes: 76 additions & 1 deletion runtime/mainnet/src/config/proxy.rs
Original file line number Diff line number Diff line change
@@ -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<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
Expand Down Expand Up @@ -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));

// Proxy 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!(
Expand Down

0 comments on commit 0716b86

Please sign in to comment.