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 the proxy pallet to the runtime #223

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pallet-membership = {version = "4.0.0-dev", default-features = false, git = "htt

# Multisig
pallet-multisig = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
pallet-proxy = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39"}

# Scheduler pallet
pallet-scheduler = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
Expand Down Expand Up @@ -106,6 +107,8 @@ std = [
"pallet-scheduler/std",
"pallet-preimage/std",
"pallet-commitments/std",
"pallet-proxy/std",
"subtensor-custom-rpc-runtime-api/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
Expand Down Expand Up @@ -138,7 +141,8 @@ runtime-benchmarks = [
"pallet-membership/runtime-benchmarks",
"pallet-registry/runtime-benchmarks",
"pallet-commitments/runtime-benchmarks",
"pallet-admin-utils/runtime-benchmarks"
"pallet-admin-utils/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
]
try-runtime = [
"frame-try-runtime/try-runtime",
Expand All @@ -159,4 +163,5 @@ try-runtime = [
"pallet-multisig/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
]
83 changes: 80 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use codec::Encode;
use codec::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;

use pallet_commitments::CanCommit;
use pallet_grandpa::{
Expand All @@ -27,7 +28,7 @@ use sp_runtime::{
AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, One, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
ApplyExtrinsicResult, MultiSignature, RuntimeDebug,
};

use sp_std::cmp::Ordering;
Expand Down Expand Up @@ -1008,6 +1009,81 @@ impl pallet_admin_utils::Config for Runtime {
type WeightInfo = pallet_admin_utils::weights::SubstrateWeight<Runtime>;

}
#[derive(
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
)]
pub enum ProxyType {
Any,
Staking,
}

impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}

impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::Staking => {
matches!(
c,
RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake {..}) |
RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake {..})
)
}
}
}

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; Balance is 4 Bytes.
pub const ProxyDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (8 as Balance) * 100 * 10_000;
// Additional storage item size of 33 bytes (`AccountId` + `ProxyType`).
pub const ProxyDepositFactor: Balance = (33 as Balance) * 100 * 10_000;
// One storage item; Balance is 4 Bytes.
pub const AnnouncementDepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (8 as Balance) * 100 * 10_000;
// Additional storage item size of 64 bytes (`AccountId`, `Hash` and `BlockNumber`).
pub const AnnouncementDepositFactor: Balance = (64 as Balance) * 100 * 10_000;
pub const MaxPending: u32 = 32;
pub const MaxProxies: u32 = 32;
}

impl pallet_proxy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type CallHasher = BlakeTwo256;
type Currency = Balances;
type MaxPending = MaxPending;
type MaxProxies = MaxProxies;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type ProxyType = ProxyType;
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Runtime>;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
Expand Down Expand Up @@ -1035,7 +1111,8 @@ construct_runtime!(
Scheduler: pallet_scheduler,
Registry: pallet_registry,
Commitments: pallet_commitments,
AdminUtils: pallet_admin_utils
AdminUtils: pallet_admin_utils,
Proxy: pallet_proxy,
}
);

Expand Down