Skip to content

Commit

Permalink
feat: pallet proxy (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: Frank Bell <frank@r0gue.io>
  • Loading branch information
al3mart and evilrobot-01 committed Apr 20, 2024
1 parent efbb2ae commit 5264ace
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pallet-nft-fractionalization = { version = "11.0.0", default-features = false }
pallet-nfts = { version = "23.0.0", default-features = false }
pallet-nfts-runtime-api = { version = "15.0.0", default-features = false }
pallet-preimage = { version = "29.0.0", default-features = false }
pallet-proxy = { version = "29.0.0", default-features = false }
pallet-scheduler = { version = "30.0.0", default-features = false }
pallet-session = { version = "29.0.0", default-features = false }
pallet-sudo = { version = "29.0.0", default-features = false }
Expand Down
71 changes: 71 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,74 @@ pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
/// How many parachain blocks are processed by the relay chain per parent. Limits the
/// number of blocks authored per slot.
pub const BLOCK_PROCESSING_VELOCITY: u32 = 1;

/// Proxy commons for Pop runtimes
pub mod proxy {

use super::{deposit, Balance};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::parameter_types;
use sp_runtime::RuntimeDebug;

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

/// 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,
/// 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,
}
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::Assets, ProxyType::AssetOwner) => true,
(ProxyType::Assets, ProxyType::AssetManager) => true,
(ProxyType::NonTransfer, ProxyType::Collator) => true,
_ => false,
}
}
}
}
4 changes: 4 additions & 0 deletions runtime/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pallet-scheduler.workspace = true
pallet-session.workspace = true
pallet-sudo.workspace = true
pallet-preimage.workspace = true
pallet-proxy.workspace = true
pallet-timestamp.workspace = true
pallet-transaction-payment.workspace = true
pallet-transaction-payment-rpc-runtime-api.workspace = true
Expand Down Expand Up @@ -126,6 +127,7 @@ std = [
"pallet-session/std",
"pallet-sudo/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
Expand Down Expand Up @@ -176,6 +178,7 @@ runtime-benchmarks = [
"pallet-scheduler/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
Expand Down Expand Up @@ -210,6 +213,7 @@ try-runtime = [
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
Expand Down
1 change: 1 addition & 0 deletions runtime/devnet/src/assets_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl pallet_nft_fractionalization::Config for Runtime {
}

pub type TrustBackedAssets = pallet_assets::Instance1;
pub type TrustBackedAssetsCall = pallet_assets::Call<Runtime, TrustBackedAssets>;
impl pallet_assets::Config<TrustBackedAssets> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
Expand Down
3 changes: 3 additions & 0 deletions runtime/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
mod assets_config;
mod contracts_config;
mod extensions;
mod proxy_config;
mod weights;
pub mod xcm_config;

Expand Down Expand Up @@ -622,6 +623,8 @@ construct_runtime!(
// Contracts
Contracts: pallet_contracts = 40,

// Proxy
Proxy: pallet_proxy = 41,
// Multisig
Multisig: pallet_multisig = 42,
// Utility
Expand Down
109 changes: 109 additions & 0 deletions runtime/devnet/src/proxy_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use crate::{assets_config::TrustBackedAssetsCall, Balances, Runtime, RuntimeCall, RuntimeEvent};
use sp_runtime::traits::BlakeTwo256;

use frame_support::traits::InstanceFilter;
use pop_runtime_common::proxy::{
AnnouncementDepositBase, AnnouncementDepositFactor, MaxPending, MaxProxies, ProxyDepositBase,
ProxyDepositFactor, ProxyType,
};

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::Nfts { .. }
),
ProxyType::CancelProxy => matches!(
c,
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
),
ProxyType::Assets => {
matches!(
c,
RuntimeCall::Assets { .. }
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
| RuntimeCall::Nfts { .. }
)
},
ProxyType::AssetOwner => matches!(
c,
RuntimeCall::Assets(TrustBackedAssetsCall::create { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::start_destroy { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::destroy_accounts { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::destroy_approvals { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::finish_destroy { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::transfer_ownership { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::set_team { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::set_metadata { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::clear_metadata { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::set_min_balance { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::create { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::destroy { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::redeposit { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::transfer_ownership { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::set_team { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::set_collection_max_supply { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::lock_collection { .. })
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
),
ProxyType::AssetManager => matches!(
c,
RuntimeCall::Assets(TrustBackedAssetsCall::mint { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::burn { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::freeze { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::block { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::thaw { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::freeze_asset { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::thaw_asset { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::touch_other { .. })
| RuntimeCall::Assets(TrustBackedAssetsCall::refund_other { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::force_mint { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::update_mint_settings { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::mint_pre_signed { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::set_attributes_pre_signed { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::lock_item_transfer { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::unlock_item_transfer { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::lock_item_properties { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::set_metadata { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::clear_metadata { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::set_collection_metadata { .. })
| RuntimeCall::Nfts(pallet_nfts::Call::clear_collection_metadata { .. })
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
),
ProxyType::Collator => matches!(
c,
RuntimeCall::CollatorSelection { .. }
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
),
}
}

fn is_superset(&self, o: &Self) -> bool {
ProxyType::is_superset(self, o)
}
}

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<Self>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}
4 changes: 4 additions & 0 deletions runtime/testnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pallet-scheduler.workspace = true
pallet-session.workspace = true
pallet-sudo.workspace = true
pallet-preimage.workspace = true
pallet-proxy.workspace = true
pallet-timestamp.workspace = true
pallet-transaction-payment.workspace = true
pallet-transaction-payment-rpc-runtime-api.workspace = true
Expand Down Expand Up @@ -126,6 +127,7 @@ std = [
"pallet-session/std",
"pallet-sudo/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
Expand Down Expand Up @@ -176,6 +178,7 @@ runtime-benchmarks = [
"pallet-scheduler/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
Expand Down Expand Up @@ -210,6 +213,7 @@ try-runtime = [
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
Expand Down
1 change: 1 addition & 0 deletions runtime/testnet/src/assets_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl pallet_nft_fractionalization::Config for Runtime {
}

pub type TrustBackedAssets = pallet_assets::Instance1;
pub type TrustBackedAssetsCall = pallet_assets::Call<Runtime, TrustBackedAssets>;
impl pallet_assets::Config<TrustBackedAssets> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
Expand Down
3 changes: 3 additions & 0 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
mod assets_config;
mod contracts_config;
mod extensions;
mod proxy_config;
mod weights;
pub mod xcm_config;

Expand Down Expand Up @@ -622,6 +623,8 @@ construct_runtime!(
// Contracts
Contracts: pallet_contracts = 40,

// Proxy
Proxy: pallet_proxy = 41,
// Multisig
Multisig: pallet_multisig = 42,
// Utility
Expand Down
Loading

0 comments on commit 5264ace

Please sign in to comment.