Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pallet-proxy to runtimes #1322

Draft
wants to merge 1 commit into
base: manta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Expand Up @@ -93,6 +93,7 @@ pallet-membership = { git = "https://github.com/paritytech/substrate.git", branc
pallet-message-queue = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false }
pallet-multisig = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.43", default-features = false }
pallet-preimage = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false }
pallet-proxy = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.43", default-features = false }
pallet-ranked-collective = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false }
pallet-referenda = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false }
pallet-scheduler = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions runtime/calamari/Cargo.toml
Expand Up @@ -51,6 +51,7 @@ pallet-democracy = { workspace = true }
pallet-membership = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-session = { workspace = true }
pallet-timestamp = { workspace = true }
Expand Down Expand Up @@ -169,6 +170,7 @@ runtime-benchmarks = [
'pallet-treasury/runtime-benchmarks',
'pallet-parachain-staking/runtime-benchmarks',
'pallet-preimage/runtime-benchmarks',
"pallet-proxy/runtime-benchmarks",
'pallet-assets/runtime-benchmarks',
'pallet-asset-manager/runtime-benchmarks',
'cumulus-pallet-xcmp-queue/runtime-benchmarks',
Expand All @@ -195,6 +197,7 @@ try-runtime = [
'pallet-balances/try-runtime',
'pallet-parachain-staking/try-runtime',
'pallet-preimage/try-runtime',
"pallet-proxy/try-runtime",
'pallet-scheduler/try-runtime',
'pallet-multisig/try-runtime',
'pallet-session/try-runtime',
Expand Down Expand Up @@ -263,6 +266,7 @@ std = [
'pallet-parachain-staking/std',
'substrate-fixed/std',
'pallet-preimage/std',
"pallet-proxy/std",
'pallet-utility/std',
'pallet-transaction-payment-rpc-runtime-api/std',
'pallet-timestamp/std',
Expand Down
90 changes: 84 additions & 6 deletions runtime/calamari/src/lib.rs
Expand Up @@ -35,21 +35,18 @@ use sp_runtime::{
};
use sp_std::{cmp::Ordering, prelude::*};

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

use codec::{Decode, Encode, MaxEncodedLen};
use cumulus_primitives_core::relay_chain::MAX_POV_SIZE;
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
traits::{
ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, IsInVec,
ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, InstanceFilter, IsInVec,
NeverEnsureOrigin, PrivilegeCmp,
},
weights::{ConstantMultiplier, Weight},
PalletId,
PalletId, RuntimeDebug,
};
use frame_system::{
limits::{BlockLength, BlockWeights},
Expand All @@ -73,6 +70,9 @@ use runtime_common::{
ExtrinsicBaseWeight,
};
use session_key_primitives::{AuraId, NimbusId, VrfId};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use zenlink_protocol::{AssetBalance, AssetId as ZenlinkAssetId, MultiAssetsHandler, PairInfo};

#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -376,6 +376,82 @@ impl frame_system::Config for Runtime {
type MaxConsumers = ConstU32<16>;
}

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,
Staking,
}

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(..)),
ProxyType::Governance => matches!(
c,
RuntimeCall::Democracy(..)
| RuntimeCall::Council(..)
| RuntimeCall::TechnicalCommittee(..)
),
ProxyType::Staking => matches!(c, RuntimeCall::ParachainStaking(..)),
}
}
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 = ();
type MaxPending = ConstU32<32>;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
}
Expand Down Expand Up @@ -1030,6 +1106,7 @@ construct_runtime!(
Utility: pallet_utility::{Pallet, Call, Event} = 40,
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 41,
// 42 was occupied by pallet-sudo, we should discuss it if another pallet takes 42 in the future.
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 43,

// Assets management
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 45,
Expand Down Expand Up @@ -1108,6 +1185,7 @@ mod benches {
[pallet_membership, CouncilMembership]
[pallet_treasury, Treasury]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_scheduler, Scheduler]
[pallet_session, SessionBench::<Runtime>]
[pallet_assets, Assets]
Expand Down
4 changes: 4 additions & 0 deletions runtime/manta/Cargo.toml
Expand Up @@ -50,6 +50,7 @@ pallet-democracy = { workspace = true }
pallet-membership = { workspace = true }
pallet-multisig = { workspace = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-session = { workspace = true }
pallet-sudo = { workspace = true }
Expand Down Expand Up @@ -150,6 +151,7 @@ runtime-benchmarks = [
'pallet-treasury/runtime-benchmarks',
'pallet-parachain-staking/runtime-benchmarks',
'pallet-preimage/runtime-benchmarks',
"pallet-proxy/runtime-benchmarks",
'pallet-assets/runtime-benchmarks',
'pallet-asset-manager/runtime-benchmarks',
'cumulus-pallet-xcmp-queue/runtime-benchmarks',
Expand All @@ -175,6 +177,7 @@ try-runtime = [
'pallet-balances/try-runtime',
'pallet-parachain-staking/try-runtime',
'pallet-preimage/try-runtime',
"pallet-proxy/try-runtime",
'pallet-multisig/try-runtime',
'pallet-session/try-runtime',
'pallet-scheduler/try-runtime',
Expand Down Expand Up @@ -244,6 +247,7 @@ std = [
'pallet-randomness/std',
'pallet-lottery/std',
'pallet-preimage/std',
"pallet-proxy/std",
'pallet-utility/std',
'pallet-transaction-payment-rpc-runtime-api/std',
'pallet-timestamp/std',
Expand Down
94 changes: 86 additions & 8 deletions runtime/manta/src/lib.rs
Expand Up @@ -35,11 +35,7 @@ use sp_runtime::{
ApplyExtrinsicResult, Perbill, Percent, Permill,
};

use sp_std::{cmp::Ordering, prelude::*};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use codec::{Decode, Encode, MaxEncodedLen};
use cumulus_pallet_parachain_system::{
register_validate_block, CheckInherents, ParachainSetCode, RelayChainStateProof,
RelaychainDataProvider,
Expand All @@ -49,12 +45,16 @@ use frame_support::{
dispatch::DispatchClass,
parameter_types,
traits::{
ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, NeverEnsureOrigin,
PrivilegeCmp,
ConstU128, ConstU32, ConstU8, Contains, Currency, EitherOfDiverse, InstanceFilter,
NeverEnsureOrigin, PrivilegeCmp,
},
weights::{ConstantMultiplier, Weight},
PalletId,
PalletId, RuntimeDebug,
};
use sp_std::{cmp::Ordering, prelude::*};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use frame_system::{
limits::{BlockLength, BlockWeights},
Expand Down Expand Up @@ -319,6 +319,82 @@ impl frame_system::Config for Runtime {
type MaxConsumers = ConstU32<16>;
}

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,
Staking,
}

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(..)),
ProxyType::Governance => matches!(
c,
RuntimeCall::Democracy(..)
| RuntimeCall::Council(..)
| RuntimeCall::TechnicalCommittee(..)
),
ProxyType::Staking => matches!(c, RuntimeCall::ParachainStaking(..)),
}
}
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 = ();
type MaxPending = ConstU32<32>;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

parameter_types! {
pub NonPausablePallets: Vec<Vec<u8>> = vec![b"Democracy".to_vec(), b"Balances".to_vec(), b"Council".to_vec(), b"CouncilMembership".to_vec(), b"TechnicalCommittee".to_vec(), b"TechnicalMembership".to_vec()];
}
Expand Down Expand Up @@ -978,6 +1054,7 @@ construct_runtime!(
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 41,
// Temporary
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 42,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 43,

// Assets management
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 45,
Expand Down Expand Up @@ -1052,6 +1129,7 @@ mod benches {
[pallet_timestamp, Timestamp]
[pallet_utility, Utility]
[pallet_preimage, Preimage]
[pallet_proxy, Proxy]
[pallet_treasury, Treasury]
[pallet_assets, Assets]
[pallet_asset_manager, AssetManager]
Expand Down