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

task 126 add the proxy pallet #325

Merged
merged 4 commits into from
Nov 13, 2023
Merged
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions runtime/amplitude/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pallet-democracy = { git = "https://github.com/paritytech/substrate", default-fe
pallet-identity = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-insecure-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
Expand Down Expand Up @@ -172,6 +173,7 @@ std = [
"pallet-identity/std",
"pallet-multisig/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-scheduler/std",
"pallet-session/std",
Expand Down
54 changes: 51 additions & 3 deletions runtime/amplitude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use frame_support::{
parameter_types,
traits::{
ConstBool, ConstU32, Contains, Currency as FrameCurrency, EitherOfDiverse,
EqualPrivilegeOnly, Imbalance, OnUnbalanced, WithdrawReasons,
EqualPrivilegeOnly, Imbalance, InstanceFilter, OnUnbalanced, WithdrawReasons,
},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
Expand All @@ -61,7 +61,7 @@ pub use sp_runtime::{MultiAddress, Perbill, Permill, Perquintill};

use runtime_common::{
asset_registry, opaque, AccountId, Amount, AuraId, Balance, BlockNumber, Hash, Index, PoolId,
ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT,
ProxyType, ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT,
};

use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
Expand Down Expand Up @@ -360,7 +360,8 @@ impl Contains<RuntimeCall> for BaseFilter {
RuntimeCall::VaultRegistry(_) |
RuntimeCall::VaultRewards(_) |
RuntimeCall::Farming(_) |
RuntimeCall::AssetRegistry(_) => true,
RuntimeCall::AssetRegistry(_) |
RuntimeCall::Proxy(_) => true,
// All pallets are allowed, but exhaustive match is defensive
// in the case of adding new pallets.
}
Expand Down Expand Up @@ -1218,6 +1219,52 @@ impl farming::Config for Runtime {
type RewardIssuer = FarmingRewardIssuerPalletId;
}

impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
// Always allowed RuntimeCall::Utility no matter type.
// Only transactions allowed by Proxy.filter can be executed
_ if matches!(c, RuntimeCall::Utility(..)) => true,
ProxyType::Any => true,
}
}

// Determines whether self matches at least everything that o does.
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; 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 MaxProxies: u16 = 32;
pub const MaxPending: u16 = 32;
pub const AnnouncementDepositBase: Balance = deposit(1, 8);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
}

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<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}
// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
Expand Down Expand Up @@ -1247,6 +1294,7 @@ construct_runtime!(
Treasury: pallet_treasury::{Pallet, Call, Storage, Event<T>} = 19,
Bounties: pallet_bounties::{Pallet, Call, Storage, Event<T>} = 20,
ChildBounties: pallet_child_bounties::{Pallet, Call, Storage, Event<T>} = 21,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 22,

// Consensus support.
// The following order MUST NOT be changed: Aura -> Session -> Staking -> Authorship -> AuraExt
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use sp_runtime::{

pub mod asset_registry;
pub mod chain_ext;
mod proxy_type;
pub mod stellar;
pub mod zenlink;

Expand All @@ -23,6 +24,7 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
/// Type for IDs of farming pools
pub type PoolId = u32;

pub use proxy_type::*;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;

/// Balance of an account.
Expand Down
26 changes: 26 additions & 0 deletions runtime/common/src/proxy_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_runtime::RuntimeDebug;
/// 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 {
/// Allows all runtime calls for proxy account
Any,
}

impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
2 changes: 2 additions & 0 deletions runtime/foucoco/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pallet-democracy = { git = "https://github.com/paritytech/substrate", default-fe
pallet-identity = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-insecure-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
Expand Down Expand Up @@ -174,6 +175,7 @@ std = [
"pallet-identity/std",
"pallet-multisig/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-scheduler/std",
"pallet-session/std",
Expand Down
55 changes: 53 additions & 2 deletions runtime/foucoco/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ use orml_currencies_allowance_extension::{
use frame_support::{
log::{error, warn},
pallet_prelude::*,
traits::InstanceFilter,
};
use sp_std::vec::Vec;

Expand Down Expand Up @@ -371,7 +372,8 @@ impl Contains<RuntimeCall> for BaseFilter {
RuntimeCall::VaultRewards(_) |
RuntimeCall::Farming(_) |
RuntimeCall::TokenAllowance(_) |
RuntimeCall::AssetRegistry(_) => true,
RuntimeCall::AssetRegistry(_) |
RuntimeCall::Proxy(_) => true,
// All pallets are allowed, but exhaustive match is defensive
// in the case of adding new pallets.
}
Expand Down Expand Up @@ -953,7 +955,8 @@ parameter_types! {
#[derive(Default)]
pub struct Psp22Extension;

use runtime_common::chain_ext::*;
use runtime_common::{chain_ext::*, ProxyType};

pub(crate) type BalanceOfForChainExt<T> =
<<T as orml_currencies::Config>::MultiCurrency as orml_traits::MultiCurrency<
<T as frame_system::Config>::AccountId,
Expand Down Expand Up @@ -1510,6 +1513,53 @@ impl clients_info::Config for Runtime {
type MaxUriLength = ConstU32<255>;
}

impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
// Always allowed RuntimeCall::Utility no matter type.
// Only transactions allowed by Proxy.filter can be executed
_ if matches!(c, RuntimeCall::Utility(..)) => true,
ProxyType::Any => true
}
}

// Determines whether self matches at least everything that o does.
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; 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 MaxProxies: u16 = 32;
pub const MaxPending: u16 = 32;
pub const AnnouncementDepositBase: Balance = deposit(1, 8);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
}

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<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
where
RuntimeCall: From<C>,
Expand Down Expand Up @@ -1548,6 +1598,7 @@ construct_runtime!(
Treasury: pallet_treasury::{Pallet, Call, Storage, Event<T>} = 19,
Bounties: pallet_bounties::{Pallet, Call, Storage, Event<T>} = 20,
ChildBounties: pallet_child_bounties::{Pallet, Call, Storage, Event<T>} = 21,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 22,

// Consensus support.
// The following order MUST NOT be changed: Aura -> Session -> Staking -> Authorship -> AuraExt
Expand Down
2 changes: 2 additions & 0 deletions runtime/pendulum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pallet-democracy = {git = "https://github.com/paritytech/substrate", default-fea
pallet-identity = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"}
pallet-multisig = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"}
pallet-preimage = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"}
pallet-proxy = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"}
pallet-insecure-randomness-collective-flip = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"}
pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"}
pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"}
Expand Down Expand Up @@ -152,6 +153,7 @@ std = [
"pallet-identity/std",
"pallet-multisig/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-scheduler/std",
"pallet-session/std",
Expand Down
55 changes: 52 additions & 3 deletions runtime/pendulum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use frame_support::{
parameter_types,
traits::{
ConstBool, ConstU32, Contains, Currency, EitherOfDiverse, EqualPrivilegeOnly, Imbalance,
OnUnbalanced, WithdrawReasons,
InstanceFilter, OnUnbalanced, WithdrawReasons,
},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
Expand All @@ -56,7 +56,7 @@ pub use sp_runtime::{traits::AccountIdConversion, MultiAddress, Perbill, Permill

use runtime_common::{
asset_registry, opaque, AccountId, Amount, AuraId, Balance, BlockNumber, Hash, Index,
ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT,
ProxyType, ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT,
};

use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
Expand Down Expand Up @@ -269,7 +269,8 @@ impl Contains<RuntimeCall> for BaseFilter {
RuntimeCall::ZenlinkProtocol(_) |
RuntimeCall::DiaOracleModule(_) |
RuntimeCall::VestingManager(_) |
RuntimeCall::AssetRegistry(_) => true,
RuntimeCall::AssetRegistry(_) |
RuntimeCall::Proxy(_) => true,
// All pallets are allowed, but exhaustive match is defensive
// in the case of adding new pallets.
}
Expand Down Expand Up @@ -953,6 +954,53 @@ where
}
}

impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
// Always allowed RuntimeCall::Utility no matter type.
// Only transactions allowed by Proxy.filter can be executed
_ if matches!(c, RuntimeCall::Utility(..)) => true,
ProxyType::Any => true,
}
}

// Determines whether self matches at least everything that o does.
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; 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 MaxProxies: u16 = 32;
pub const MaxPending: u16 = 32;
pub const AnnouncementDepositBase: Balance = deposit(1, 8);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
}

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<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
Expand Down Expand Up @@ -982,6 +1030,7 @@ construct_runtime!(
Treasury: pallet_treasury::{Pallet, Call, Storage, Event<T>} = 19,
Bounties: pallet_bounties::{Pallet, Call, Storage, Event<T>} = 20,
ChildBounties: pallet_child_bounties::{Pallet, Call, Storage, Event<T>} = 21,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 22,

// Consensus support.
// The following order MUST NOT be changed: Aura -> Session -> Staking -> Authorship -> AuraExt
Expand Down
Loading