Skip to content

Commit befa215

Browse files
authored
remove sweep_dust (#615)
1 parent 65f1734 commit befa215

File tree

6 files changed

+3
-115
lines changed

6 files changed

+3
-115
lines changed

currencies/src/mock.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![cfg(test)]
44

55
use super::*;
6-
use frame_support::{construct_runtime, ord_parameter_types, parameter_types, PalletId};
6+
use frame_support::{construct_runtime, parameter_types, PalletId};
77
use orml_traits::parameter_type_with_key;
88
use sp_core::H256;
99
use sp_runtime::{
@@ -75,16 +75,11 @@ parameter_types! {
7575
pub MaxLocks: u32 = 100_000;
7676
}
7777

78-
ord_parameter_types! {
79-
pub const Admin: AccountId = ALICE;
80-
}
81-
8278
impl orml_tokens::Config for Runtime {
8379
type Event = Event;
8480
type Balance = Balance;
8581
type Amount = i64;
8682
type CurrencyId = CurrencyId;
87-
type SweepOrigin = frame_system::EnsureSignedBy<Admin, AccountId>;
8883
type WeightInfo = ();
8984
type ExistentialDeposits = ExistentialDeposits;
9085
type OnDust = orml_tokens::TransferDust<Runtime, DustAccount>;

tokens/src/lib.rs

-26
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ pub mod module {
189189
/// The currency ID type
190190
type CurrencyId: Parameter + Member + Copy + MaybeSerializeDeserialize + Ord;
191191

192-
/// The AccountId that can perform a sweep dust.
193-
type SweepOrigin: EnsureOrigin<Self::Origin>;
194-
195192
/// Weight information for extrinsics in this module.
196193
type WeightInfo: WeightInfo;
197194

@@ -512,29 +509,6 @@ pub mod module {
512509
Ok(())
513510
})
514511
}
515-
516-
#[pallet::weight(T::WeightInfo::sweep_dust(accounts.len() as u32))]
517-
pub fn sweep_dust(
518-
origin: OriginFor<T>,
519-
currency_id: T::CurrencyId,
520-
accounts: Vec<T::AccountId>,
521-
) -> DispatchResult {
522-
T::SweepOrigin::ensure_origin(origin)?;
523-
for account in accounts {
524-
let account_data = Accounts::<T>::get(&account, &currency_id);
525-
if account_data.free.is_zero() {
526-
continue;
527-
}
528-
if !account_data.reserved.is_zero() {
529-
continue;
530-
}
531-
if account_data.free < T::ExistentialDeposits::get(&currency_id) {
532-
T::OnDust::on_dust(&account, currency_id, account_data.free);
533-
Self::deposit_event(Event::DustLost(currency_id, account, account_data.free));
534-
}
535-
}
536-
Ok(())
537-
}
538512
}
539513
}
540514

tokens/src/mock.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use super::*;
66
use frame_support::{
7-
construct_runtime, ord_parameter_types, parameter_types,
7+
construct_runtime, parameter_types,
88
traits::{ChangeMembers, ContainsLengthBound, GenesisBuild, SaturatingCurrencyToVote, SortedMembers},
99
PalletId,
1010
};
@@ -226,16 +226,11 @@ parameter_types! {
226226
pub MaxLocks: u32 = 2;
227227
}
228228

229-
ord_parameter_types! {
230-
pub const Admin: AccountId = ALICE;
231-
}
232-
233229
impl Config for Runtime {
234230
type Event = Event;
235231
type Balance = Balance;
236232
type Amount = i64;
237233
type CurrencyId = CurrencyId;
238-
type SweepOrigin = frame_system::EnsureSignedBy<Admin, AccountId>;
239234
type WeightInfo = ();
240235
type ExistentialDeposits = ExistentialDeposits;
241236
type OnDust = TransferDust<Runtime, DustReceiver>;

tokens/src/tests.rs

-61
Original file line numberDiff line numberDiff line change
@@ -2079,64 +2079,3 @@ fn fungibles_mutate_hold_trait_should_work() {
20792079
);
20802080
});
20812081
}
2082-
2083-
#[test]
2084-
fn sweep_dust_works() {
2085-
ExtBuilder::default().build().execute_with(|| {
2086-
Accounts::<Runtime>::insert(
2087-
BOB,
2088-
DOT,
2089-
AccountData {
2090-
free: 1,
2091-
frozen: 0,
2092-
reserved: 0,
2093-
},
2094-
);
2095-
Accounts::<Runtime>::insert(
2096-
CHARLIE,
2097-
DOT,
2098-
AccountData {
2099-
free: 2,
2100-
frozen: 0,
2101-
reserved: 0,
2102-
},
2103-
);
2104-
Accounts::<Runtime>::insert(
2105-
DAVE,
2106-
DOT,
2107-
AccountData {
2108-
free: 0,
2109-
frozen: 1,
2110-
reserved: 0,
2111-
},
2112-
);
2113-
TotalIssuance::<Runtime>::insert(DOT, 3);
2114-
2115-
let accounts = vec![BOB, CHARLIE, DAVE];
2116-
2117-
// cannot be called by root or anyone expect SweepOrigin
2118-
assert_noop!(
2119-
Tokens::sweep_dust(Origin::root(), DOT, accounts.clone()),
2120-
DispatchError::BadOrigin
2121-
);
2122-
assert_noop!(
2123-
Tokens::sweep_dust(Origin::signed(BOB), DOT, accounts.clone()),
2124-
DispatchError::BadOrigin
2125-
);
2126-
2127-
assert_ok!(Tokens::sweep_dust(Origin::signed(ALICE), DOT, accounts.clone()));
2128-
System::assert_last_event(Event::Tokens(crate::Event::DustLost(DOT, BOB, 1)));
2129-
2130-
// Bob's account is gone
2131-
assert_eq!(Accounts::<Runtime>::contains_key(BOB, DOT), false);
2132-
assert_eq!(Tokens::free_balance(DOT, &BOB), 0);
2133-
2134-
// Charlie's account remains, not below ED
2135-
assert_eq!(Tokens::free_balance(DOT, &CHARLIE), 2);
2136-
2137-
// Dust transferred to dust receiver
2138-
assert_eq!(Tokens::free_balance(DOT, &DustReceiver::get()), 1);
2139-
// Total issuance remains the same
2140-
assert_eq!(Tokens::total_issuance(DOT), 3);
2141-
});
2142-
}

tokens/src/weights.rs

-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub trait WeightInfo {
3434
fn transfer_keep_alive() -> Weight;
3535
fn force_transfer() -> Weight;
3636
fn set_balance() -> Weight;
37-
fn sweep_dust(c: u32, ) -> Weight;
3837
}
3938

4039
/// Default weights.
@@ -64,13 +63,4 @@ impl WeightInfo for () {
6463
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
6564
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
6665
}
67-
fn sweep_dust(c: u32, ) -> Weight {
68-
(3_100_000 as Weight)
69-
// Standard Error: 597_000
70-
.saturating_add((27_100_000 as Weight).saturating_mul(c as Weight))
71-
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
72-
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(c as Weight)))
73-
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
74-
.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(c as Weight)))
75-
}
7666
}

xtokens/src/mock/para.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{Amount, Balance, CurrencyId, CurrencyIdConvert, ParachainXcmRouter,
22
use crate as orml_xtokens;
33

44
use frame_support::{
5-
construct_runtime, ord_parameter_types, parameter_types,
5+
construct_runtime, parameter_types,
66
traits::{Everything, Get},
77
weights::{constants::WEIGHT_PER_SECOND, Weight},
88
};
@@ -90,16 +90,11 @@ parameter_type_with_key! {
9090
};
9191
}
9292

93-
ord_parameter_types! {
94-
pub const Admin: AccountId = ALICE;
95-
}
96-
9793
impl orml_tokens::Config for Runtime {
9894
type Event = Event;
9995
type Balance = Balance;
10096
type Amount = Amount;
10197
type CurrencyId = CurrencyId;
102-
type SweepOrigin = frame_system::EnsureSignedBy<Admin, AccountId>;
10398
type WeightInfo = ();
10499
type ExistentialDeposits = ExistentialDeposits;
105100
type OnDust = ();

0 commit comments

Comments
 (0)