Skip to content

Commit 3536a8b

Browse files
authored
Merge pull request #723 from opentensor/feat/more-proxy-types
Add new proxy types
2 parents 5bbe575 + 0d486ba commit 3536a8b

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

runtime/src/lib.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,11 @@ pub enum ProxyType {
626626
Governance, // Both above governance
627627
Staking,
628628
Registration,
629+
Transfer,
630+
SmallTransfer,
629631
}
632+
// Transfers below SMALL_TRANSFER_LIMIT are considered small transfers
633+
pub const SMALL_TRANSFER_LIMIT: Balance = 500_000_000; // 0.5 TAO
630634
impl Default for ProxyType {
631635
fn default() -> Self {
632636
Self::Any
@@ -645,6 +649,22 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
645649
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register { .. })
646650
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register { .. })
647651
),
652+
ProxyType::Transfer => matches!(
653+
c,
654+
RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { .. })
655+
| RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. })
656+
| RuntimeCall::Balances(pallet_balances::Call::transfer_all { .. })
657+
),
658+
ProxyType::SmallTransfer => match c {
659+
RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive {
660+
value, ..
661+
}) => *value < SMALL_TRANSFER_LIMIT,
662+
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
663+
value,
664+
..
665+
}) => *value < SMALL_TRANSFER_LIMIT,
666+
_ => false,
667+
},
648668
ProxyType::Owner => matches!(c, RuntimeCall::AdminUtils(..)),
649669
ProxyType::NonCritical => !matches!(
650670
c,
@@ -681,8 +701,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
681701
(x, y) if x == y => true,
682702
(ProxyType::Any, _) => true,
683703
(_, ProxyType::Any) => false,
684-
(ProxyType::NonTransfer, _) => true,
704+
(ProxyType::NonTransfer, _) => {
705+
// NonTransfer is NOT a superset of Transfer or SmallTransfer
706+
!matches!(o, ProxyType::Transfer | ProxyType::SmallTransfer)
707+
}
685708
(ProxyType::Governance, ProxyType::Triumvirate | ProxyType::Senate) => true,
709+
(ProxyType::Transfer, ProxyType::SmallTransfer) => true,
686710
_ => false,
687711
}
688712
}

runtime/tests/pallet_proxy.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,30 @@ fn test_proxy_pallet() {
200200
}
201201
}
202202
}
203+
204+
#[test]
205+
fn test_non_transfer_cannot_transfer() {
206+
new_test_ext().execute_with(|| {
207+
assert_ok!(Proxy::add_proxy(
208+
RuntimeOrigin::signed(AccountId::from(ACCOUNT)),
209+
AccountId::from(DELEGATE).into(),
210+
ProxyType::NonTransfer,
211+
0
212+
));
213+
214+
let call = call_transfer();
215+
assert_ok!(Proxy::proxy(
216+
RuntimeOrigin::signed(AccountId::from(DELEGATE)),
217+
AccountId::from(ACCOUNT).into(),
218+
None,
219+
Box::new(call.clone()),
220+
));
221+
222+
System::assert_last_event(
223+
pallet_proxy::Event::ProxyExecuted {
224+
result: Err(SystemError::CallFiltered.into()),
225+
}
226+
.into(),
227+
);
228+
});
229+
}

0 commit comments

Comments
 (0)