Skip to content

Commit

Permalink
Config dust removal whitelist (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjj9219 authored Aug 12, 2021
1 parent bf28d84 commit 6c7f819
Show file tree
Hide file tree
Showing 30 changed files with 70 additions and 22 deletions.
1 change: 1 addition & 0 deletions ecosystem-modules/chainsafe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

ord_parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions ecosystem-modules/ren/renvm-bridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions ecosystem-modules/starport/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/auction-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

impl orml_auction::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions modules/cdp-engine/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/cdp-treasury/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/currencies/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl tokens::Config for Runtime {
type OnDust = tokens::TransferDust<Runtime, DustAccount>;
type WeightInfo = ();
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = ();
}

pub const NATIVE_CURRENCY_ID: CurrencyId = CurrencyId::Token(TokenSymbol::ACA);
Expand Down
1 change: 1 addition & 0 deletions modules/dex/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

pub struct MockDEXIncentives;
Expand Down
1 change: 1 addition & 0 deletions modules/emergency-shutdown/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/evm-accounts/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/evm-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl orml_tokens::Config for Test {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/homa-lite/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ mod benchmark_mock {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/homa-lite/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/homa-validator-list/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/honzon/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/incentives/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

pub struct MockCDPTreasury;
Expand Down
1 change: 1 addition & 0 deletions modules/loans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl<T: Config> Pallet<T> {
debit_adjustment: Amount,
) -> DispatchResult {
// mutate collateral and debit
// Note: if a new position, will inc consumer
Self::update_loan(who, currency_id, collateral_adjustment, debit_adjustment)?;

let collateral_balance_adjustment = Self::balance_try_from_amount_abs(collateral_adjustment)?;
Expand Down
1 change: 1 addition & 0 deletions modules/loans/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/nft/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

pub const NATIVE_CURRENCY_ID: CurrencyId = CurrencyId::Token(TokenSymbol::ACA);
Expand Down
1 change: 1 addition & 0 deletions modules/nominees-election/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/prices/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

ord_parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/staking-pool/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions modules/transaction-payment/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
2 changes: 1 addition & 1 deletion orml
15 changes: 12 additions & 3 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ mod weights;
pub use frame_support::{
construct_runtime, log, parameter_types,
traits::{
ContainsLengthBound, Currency as PalletCurrency, EnsureOrigin, Filter, Get, Imbalance, InstanceFilter, IsType,
KeyOwnerProofSystem, LockIdentifier, MaxEncodedLen, OnUnbalanced, Randomness, SortedMembers,
U128CurrencyToVote,
Contains, ContainsLengthBound, Currency as PalletCurrency, EnsureOrigin, Filter, Get, Imbalance,
InstanceFilter, IsType, KeyOwnerProofSystem, LockIdentifier, MaxEncodedLen, OnUnbalanced, Randomness,
SortedMembers, U128CurrencyToVote,
},
weights::{constants::RocksDbWeight, IdentityFee, Weight},
PalletId, RuntimeDebug, StorageValue,
Expand Down Expand Up @@ -174,6 +174,7 @@ pub fn get_all_module_accounts() -> Vec<AccountId> {
CollatorPotId::get().into_account(),
TreasuryReservePalletId::get().into_account(),
ZeroAccountId::get(),
UnreleasedNativeVaultAccountId::get(),
]
}

Expand Down Expand Up @@ -751,6 +752,13 @@ impl DataFeeder<CurrencyId, Price, AccountId> for AggregatedDataProvider {
}
}

pub struct DustRemovalWhitelist;
impl Contains<AccountId> for DustRemovalWhitelist {
fn contains(a: &AccountId) -> bool {
get_all_module_accounts().contains(a)
}
}

parameter_type_with_key! {
pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance {
Zero::zero()
Expand All @@ -770,6 +778,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccount>;
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = DustRemovalWhitelist;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions runtime/common/src/precompile/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl orml_tokens::Config for Test {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type MaxLocks = ();
type DustRemovalWhitelist = ();
}

parameter_types! {
Expand Down
25 changes: 16 additions & 9 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ mod weights;
pub use frame_support::{
construct_runtime, log, parameter_types,
traits::{
All, ContainsLengthBound, Currency as PalletCurrency, EnsureOrigin, Filter, Get, Imbalance, InstanceFilter,
IsSubType, IsType, KeyOwnerProofSystem, LockIdentifier, MaxEncodedLen, OnUnbalanced, Randomness, SortedMembers,
U128CurrencyToVote,
All, Contains, ContainsLengthBound, Currency as PalletCurrency, EnsureOrigin, Filter, Get, Imbalance,
InstanceFilter, IsSubType, IsType, KeyOwnerProofSystem, LockIdentifier, MaxEncodedLen, OnUnbalanced,
Randomness, SortedMembers, U128CurrencyToVote,
},
weights::{constants::RocksDbWeight, IdentityFee, Weight},
PalletId, RuntimeDebug, StorageValue,
Expand Down Expand Up @@ -157,7 +157,6 @@ parameter_types! {
pub const LoansPalletId: PalletId = PalletId(*b"aca/loan");
pub const DEXPalletId: PalletId = PalletId(*b"aca/dexm");
pub const CDPTreasuryPalletId: PalletId = PalletId(*b"aca/cdpt");
pub const StakingPoolPalletId: PalletId = PalletId(*b"aca/stkp");
pub const HonzonTreasuryPalletId: PalletId = PalletId(*b"aca/hztr");
pub const HomaTreasuryPalletId: PalletId = PalletId(*b"aca/hmtr");
pub const IncentivesPalletId: PalletId = PalletId(*b"aca/inct");
Expand All @@ -171,17 +170,17 @@ parameter_types! {

pub fn get_all_module_accounts() -> Vec<AccountId> {
vec![
TreasuryPalletId::get().into_account(),
LoansPalletId::get().into_account(),
DEXPalletId::get().into_account(),
CDPTreasuryPalletId::get().into_account(),
StakingPoolPalletId::get().into_account(),
HonzonTreasuryPalletId::get().into_account(),
CollatorPotId::get().into_account(),
DEXPalletId::get().into_account(),
HomaTreasuryPalletId::get().into_account(),
HonzonTreasuryPalletId::get().into_account(),
IncentivesPalletId::get().into_account(),
CollatorPotId::get().into_account(),
TreasuryPalletId::get().into_account(),
TreasuryReservePalletId::get().into_account(),
ZeroAccountId::get(),
UnreleasedNativeVaultAccountId::get(),
]
}

Expand Down Expand Up @@ -755,6 +754,13 @@ parameter_type_with_key! {
};
}

pub struct DustRemovalWhitelist;
impl Contains<AccountId> for DustRemovalWhitelist {
fn contains(a: &AccountId) -> bool {
get_all_module_accounts().contains(a)
}
}

parameter_types! {
pub KaruraTreasuryAccount: AccountId = TreasuryPalletId::get().into_account();
}
Expand All @@ -768,6 +774,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = orml_tokens::TransferDust<Runtime, KaruraTreasuryAccount>;
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = DustRemovalWhitelist;
}

parameter_types! {
Expand Down
21 changes: 15 additions & 6 deletions runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use codec::{Decode, Encode};
pub use frame_support::{
construct_runtime, log, parameter_types,
traits::{
All, ContainsLengthBound, Currency as PalletCurrency, EnsureOrigin, Filter, Get, Imbalance, InstanceFilter,
IsSubType, IsType, KeyOwnerProofSystem, LockIdentifier, MaxEncodedLen, OnUnbalanced, Randomness, SortedMembers,
U128CurrencyToVote, WithdrawReasons,
All, Contains, ContainsLengthBound, Currency as PalletCurrency, EnsureOrigin, Filter, Get, Imbalance,
InstanceFilter, IsSubType, IsType, KeyOwnerProofSystem, LockIdentifier, MaxEncodedLen, OnUnbalanced,
Randomness, SortedMembers, U128CurrencyToVote, WithdrawReasons,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
Expand All @@ -64,7 +64,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdConversion, BadOrigin, BlakeTwo256, Block as BlockT, Convert, SaturatedConversion, StaticLookup, Zero,
AccountIdConversion, BadOrigin, BlakeTwo256, Block as BlockT, Convert, SaturatedConversion, StaticLookup,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, DispatchResult, FixedPointNumber,
Expand Down Expand Up @@ -186,8 +186,9 @@ pub fn get_all_module_accounts() -> Vec<AccountId> {
IncentivesPalletId::get().into_account(),
TreasuryReservePalletId::get().into_account(),
CollatorPotId::get().into_account(),
ZeroAccountId::get(),
StarportPalletId::get().into_account(),
ZeroAccountId::get(),
UnreleasedNativeVaultAccountId::get(),
]
}

Expand Down Expand Up @@ -768,9 +769,16 @@ impl DataFeeder<CurrencyId, Price, AccountId> for AggregatedDataProvider {
}
}

pub struct DustRemovalWhitelist;
impl Contains<AccountId> for DustRemovalWhitelist {
fn contains(a: &AccountId) -> bool {
get_all_module_accounts().contains(a)
}
}

parameter_type_with_key! {
pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance {
Zero::zero()
1
};
}

Expand All @@ -787,6 +795,7 @@ impl orml_tokens::Config for Runtime {
type ExistentialDeposits = ExistentialDeposits;
type OnDust = orml_tokens::TransferDust<Runtime, TreasuryAccount>;
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = DustRemovalWhitelist;
}

parameter_types! {
Expand Down
4 changes: 1 addition & 3 deletions runtime/mandala/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ fn emergency_shutdown_and_cdp_treasury() {
fn liquidate_cdp() {
ExtBuilder::default()
.balances(vec![
(AccountId::from(ALICE), ACA, 1 * dollar(ACA)),
(AccountId::from(ALICE), RENBTC, 10 * dollar(RENBTC)),
(AccountId::from(BOB), AUSD, 1_000_000 * dollar(AUSD)),
(AccountId::from(BOB), RENBTC, 101 * dollar(RENBTC)),
Expand Down Expand Up @@ -1564,14 +1565,11 @@ fn should_not_kill_contract_on_transfer_all_tokens() {
2 * dollar(AUSD)
));
assert_eq!(Currencies::free_balance(AUSD, &contract_account_id), 0);

assert_eq!(Currencies::free_balance(AUSD, &alice()), 1000 * dollar(AUSD));

// assert the contract account is not purged
assert!(EVM::accounts(contract).is_some());

assert_ok!(EVM::call(Origin::signed(alice()), contract.clone(), hex_literal::hex!("41c0e1b5").to_vec(), 0, 1000000000, 1000000000));

assert!(EVM::accounts(contract).is_none());

// should be gone
Expand Down

0 comments on commit 6c7f819

Please sign in to comment.