Skip to content

Commit

Permalink
add proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Apr 18, 2024
1 parent a1569e4 commit 54a9482
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ pallet-aura = { version = "27.0.0", default-features = false }
pallet-authorship = { version = "28.0.0", default-features = false }
pallet-assets = { version = "29.0.0", default-features = false }
pallet-balances = { version = "28.0.0", default-features = false }
pallet-multisig = { version = "28.0.0", default-features = false }
pallet-session = { version = "28.0.0", default-features = false }
pallet-sudo = { version = "28.0.0", default-features = false }
pallet-timestamp = { version = "27.0.0", default-features = false }
pallet-transaction-payment = { version = "28.0.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { version = "28.0.0", default-features = false }
pallet-message-queue = { version = "31.0.0", default-features = false }
pallet-multisig = { version = "28.0.0", default-features = false }
pallet-proxy = { version = "28.0.0", default-features = false }
pallet-utility = { version = "28.0.0", default-features = false }
sp-api = { version = "26.0.0", default-features = false }
sp-blockchain = { version = "28.0.0", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions runtime/regionx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-multisig = { workspace = true }
pallet-proxy = { workspace = true }
pallet-session = { workspace = true }
pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
Expand Down Expand Up @@ -122,6 +123,7 @@ std = [
"pallet-message-queue/std",
"regionx-primitives/std",
"pallet-multisig/std",
"pallet-proxy/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-utility/std",
Expand Down Expand Up @@ -169,6 +171,7 @@ runtime-benchmarks = [
"pallet-collator-selection/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand Down Expand Up @@ -201,6 +204,7 @@ try-runtime = [
"pallet-collator-selection/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-multisig/try-runtime",
"pallet-proxy/try-runtime",
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-utility/try-runtime",
Expand Down
47 changes: 45 additions & 2 deletions runtime/regionx/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{AssetId, Runtime};
use crate::{AssetId, Runtime, RuntimeCall};
use orml_asset_registry::DefaultAssetMetadata;
use orml_traits::asset_registry::AssetProcessor;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::DispatchError;
use sp_runtime::{DispatchError, RuntimeDebug};
use frame_support::traits::InstanceFilter;

#[derive(
Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
Expand All @@ -28,3 +29,45 @@ impl AssetProcessor<AssetId, DefaultAssetMetadata<Runtime>> for CustomAssetProce
Ok(())
}
}

/// 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,
// TODO: add more proxies in future related to coretime trading.
}

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 { .. } | RuntimeCall::Assets { .. }),
ProxyType::CancelProxy =>
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })),
}
}
}
29 changes: 29 additions & 0 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,33 @@ impl pallet_multisig::Config for Runtime {
type WeightInfo = ();
}

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;
}

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 = ();
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
Expand Down Expand Up @@ -607,6 +634,7 @@ construct_runtime!(
// Handy utilities
Utility: pallet_utility = 40,
Multisig: pallet_multisig = 41,
Proxy: pallet_proxy = 42,

// XCM helpers.
XcmpQueue: cumulus_pallet_xcmp_queue = 50,
Expand All @@ -628,6 +656,7 @@ mod benches {
[pallet_balances, Balances]
[pallet_session, SessionBench::<Runtime>]
[pallet_multisig, Multisig]
[pallet_proxy, Proxy]
[pallet_timestamp, Utility]
[pallet_timestamp, Timestamp]
[pallet_sudo, Sudo]
Expand Down

0 comments on commit 54a9482

Please sign in to comment.