Skip to content

Commit

Permalink
first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
b-yap committed Oct 18, 2023
1 parent 08b2eef commit 8a36e55
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 8 deletions.
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
49 changes: 46 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,47 @@ 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 {
true
}
}

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 All @@ -1244,6 +1286,7 @@ construct_runtime!(
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 16,
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 17,
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 18,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 92,
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,
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
37 changes: 37 additions & 0 deletions runtime/common/src/proxy_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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,
// /// Allows only NonTransfer runtime calls for proxy account
// /// To know exact calls check InstanceFilter inmplementation for ProxyTypes
// NonTransfer,
// /// All Runtime calls from Pallet Balances allowed for proxy account
// Balances,
// /// Only provide_judgement call from pallet identity allowed for proxy account
// IdentityJudgement,
// /// Only reject_announcement call from pallet proxy allowed for proxy account
// CancelProxy,
// /// Only claim_reward call from pallet staking is allowed for proxy account
// StakerRewardClaim,
}

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
98 changes: 96 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,96 @@ 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,
// ProxyType::NonTransfer => {
// matches!(
// c,
// RuntimeCall::System(..)
// | RuntimeCall::Identity(..)
// | RuntimeCall::Timestamp(..)
// | RuntimeCall::Multisig(..)
// | RuntimeCall::Proxy(..)
// | RuntimeCall::ParachainSystem(..)
// | RuntimeCall::ParachainInfo(..)
// // Skip entire Balances pallet
// | RuntimeCall::Vesting(pallet_vesting::Call::vest{..})
// | RuntimeCall::Vesting(pallet_vesting::Call::vest_other{..})
// // Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer`
// | RuntimeCall::Session(..)
// | RuntimeCall::XcmpQueue(..)
// | RuntimeCall::PolkadotXcm(..)
// | RuntimeCall::DmpQueue(..)
// )
// }
// ProxyType::Balances => {
// matches!(c, RuntimeCall::Balances(..))
// }
// ProxyType::IdentityJudgement => {
// matches!(
// c,
// RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
// )
// }
// ProxyType::CancelProxy => {
// matches!(
// c,
// RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
// )
// }
// ProxyType::StakerRewardClaim => {
// matches!(
// c,
// RuntimeCall::DappsStaking(parachain_staking::Call::claim_rewards { .. })
// )
// }
}
}

// Determines whether self matches at least everything that o does.
fn is_superset(&self, _o: &Self) -> bool {
true
// match (self, o) {
// (x, y) if x == y => true,
// (ProxyType::Any, _) => true,
// (_, ProxyType::Any) => false,
// (_, ProxyType::StakerRewardClaim) => true,
// _ => 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 @@ -1545,6 +1638,7 @@ construct_runtime!(
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 16,
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 17,
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 18,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 92,
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,
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
Loading

0 comments on commit 8a36e55

Please sign in to comment.