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 new proxy types #723

Merged
merged 4 commits into from
Aug 16, 2024
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
26 changes: 25 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,11 @@ pub enum ProxyType {
Governance, // Both above governance
Staking,
Registration,
Transfer,
SmallTransfer,
}
// Transfers below SMALL_TRANSFER_LIMIT are considered small transfers
pub const SMALL_TRANSFER_LIMIT: Balance = 500_000_000; // 0.5 TAO
impl Default for ProxyType {
fn default() -> Self {
Self::Any
Expand All @@ -645,6 +649,22 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register { .. })
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register { .. })
),
ProxyType::Transfer => matches!(
c,
RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { .. })
| RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. })
| RuntimeCall::Balances(pallet_balances::Call::transfer_all { .. })
),
ProxyType::SmallTransfer => match c {
RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive {
value, ..
}) => *value < SMALL_TRANSFER_LIMIT,
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
value,
..
}) => *value < SMALL_TRANSFER_LIMIT,
_ => false,
},
ProxyType::Owner => matches!(c, RuntimeCall::AdminUtils(..)),
ProxyType::NonCritical => !matches!(
c,
Expand Down Expand Up @@ -681,8 +701,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
(ProxyType::NonTransfer, _) => true,
(ProxyType::NonTransfer, _) => {
// NonTransfer is NOT a superset of Transfer or SmallTransfer
!matches!(o, ProxyType::Transfer | ProxyType::SmallTransfer)
}
(ProxyType::Governance, ProxyType::Triumvirate | ProxyType::Senate) => true,
(ProxyType::Transfer, ProxyType::SmallTransfer) => true,
_ => false,
}
}
Expand Down
27 changes: 27 additions & 0 deletions runtime/tests/pallet_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,30 @@ fn test_proxy_pallet() {
}
}
}

#[test]
fn test_non_transfer_cannot_transfer() {
new_test_ext().execute_with(|| {
assert_ok!(Proxy::add_proxy(
RuntimeOrigin::signed(AccountId::from(ACCOUNT)),
AccountId::from(DELEGATE).into(),
ProxyType::NonTransfer,
0
));

let call = call_transfer();
assert_ok!(Proxy::proxy(
RuntimeOrigin::signed(AccountId::from(DELEGATE)),
AccountId::from(ACCOUNT).into(),
None,
Box::new(call.clone()),
));

System::assert_last_event(
pallet_proxy::Event::ProxyExecuted {
result: Err(SystemError::CallFiltered.into()),
}
.into(),
);
});
}
Loading