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 a burn method to pallet-account-fix #2980

Merged
merged 3 commits into from
Aug 9, 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
36 changes: 27 additions & 9 deletions pallets/account-fix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@

use frame_support::{
pallet_prelude::*,
traits::{Currency, ReservableCurrency, StorageVersion},
traits::{
fungible::Mutate,
tokens::{Fortitude, Precision},
Currency, ReservableCurrency, StorageVersion,
},
};
use frame_system::pallet_prelude::*;
pub use pallet::*;
use sp_runtime::traits::StaticLookup;

use sp_std::vec::Vec;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
Expand All @@ -45,25 +49,22 @@ pub mod pallet {

#[pallet::config]
pub trait Config: frame_system::Config + pallet_balances::Config {
/// The currency mechanism.
type Currency: ReservableCurrency<Self::AccountId>;
type BurnOrigin: EnsureOrigin<Self::RuntimeOrigin>;
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Change the admin account
/// similar to sudo.set_key, the old account will be supplied in event
#[pallet::call_index(0)]
#[pallet::weight(Weight::from_parts(20_000_000u64 * (who.len() as u64), 0))]
pub fn upgrade_accounts(
pub fn inc_consumers(
origin: OriginFor<T>,
who: Vec<T::AccountId>,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
for i in &who {
frame_system::Pallet::<T>::inc_consumers(i)?;
}
// Do not pay a fee
Ok(Pays::No.into())
}

Expand All @@ -78,15 +79,32 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
let who = T::Lookup::lookup(who)?;

let add_total = add_free + add_reserved;

// First we try to modify the account's balance to the forced balance.
T::Currency::deposit_into_existing(&who, add_total)?;
// Then do the reservation
T::Currency::reserve(&who, add_reserved)?;

Ok(().into())
Ok(Pays::No.into())
}

// burn balance from a given account
#[pallet::call_index(2)]
#[pallet::weight({195_000_000})]
pub fn burn(
origin: OriginFor<T>,
who: T::AccountId,
amount: <T as pallet_balances::Config>::Balance,
) -> DispatchResultWithPostInfo {
let _ = T::BurnOrigin::ensure_origin(origin)?;
let _ = pallet_balances::Pallet::<T>::burn_from(
&who,
amount,
Precision::Exact,
Fortitude::Polite,
)?;
Ok(Pays::No.into())
}
}
}
8 changes: 7 additions & 1 deletion runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ impl pallet_identity::Config for Runtime {

impl pallet_account_fix::Config for Runtime {
type Currency = Balances;
type BurnOrigin = EnsureRootOrTwoThirdsTechnicalCommittee;
}

parameter_types! {
Expand Down Expand Up @@ -964,7 +965,12 @@ impl Contains<RuntimeCall> for BaseCallFilter {
RuntimeCall::ExtrinsicFilter(_) |
RuntimeCall::Multisig(_) |
RuntimeCall::Council(_) |
RuntimeCall::TechnicalCommittee(_)
RuntimeCall::CouncilMembership(_) |
RuntimeCall::TechnicalCommittee(_) |
RuntimeCall::TechnicalCommitteeMembership(_) |
RuntimeCall::Utility(_) |
// Temp: should be removed after the one-time burn
RuntimeCall::AccountFix(pallet_account_fix::Call::burn { .. })
) {
// always allow core calls
return true
Expand Down
7 changes: 6 additions & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ impl pallet_sudo::Config for Runtime {

impl pallet_account_fix::Config for Runtime {
type Currency = Balances;
type BurnOrigin = EnsureRootOrTwoThirdsTechnicalCommittee;
}

parameter_types! {
Expand Down Expand Up @@ -1325,8 +1326,12 @@ impl Contains<RuntimeCall> for BaseCallFilter {
RuntimeCall::ExtrinsicFilter(_) |
RuntimeCall::Multisig(_) |
RuntimeCall::Council(_) |
RuntimeCall::CouncilMembership(_) |
RuntimeCall::TechnicalCommittee(_) |
RuntimeCall::DeveloperCommittee(_)
RuntimeCall::TechnicalCommitteeMembership(_) |
RuntimeCall::Utility(_) |
// Temp: should be removed after the one-time burn
RuntimeCall::AccountFix(pallet_account_fix::Call::burn { .. })
) {
// always allow core calls
return true
Expand Down
1 change: 0 additions & 1 deletion runtime/rococo/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ where
let mut candidate_pool_sum: BalanceOf<T> = 0u128.into();

// Make sure the number of Order set is correct
assert_eq!(ordered_set.0.len(), 9);
for bond in ordered_set.0.iter() {
candidate_pool_sum += bond.amount;
}
Expand Down
Loading