Skip to content

Commit

Permalink
Add Burn extrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauthamastro committed Dec 27, 2023
1 parent 5f0f730 commit e32d5b7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pallets/thea-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ pub mod pallet {
use frame_support::{
pallet_prelude::*,
sp_runtime::SaturatedConversion,
traits::{fungible::Mutate, fungibles::Inspect, tokens::Preservation},
traits::{
fungible::Mutate,
fungibles::Inspect,
tokens::{Fortitude, Precision, Preservation},
},
transactional,
};
use frame_system::pallet_prelude::*;
Expand Down Expand Up @@ -119,6 +123,8 @@ pub mod pallet {
type ExistentialDeposit: Get<u128>;
/// Para Id
type ParaId: Get<u32>;
/// Governance Origin
type GovernanceOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;
/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;
}
Expand Down Expand Up @@ -181,6 +187,8 @@ pub mod pallet {
TheaKeyUpdated(Network, u32),
/// Withdrawal Fee Set (NetworkId, Amount)
WithdrawalFeeSet(u8, u128),
/// Native Token Burn event
NativeTokenBurned(T::AccountId, u128),
}

// Errors inform users that something went wrong.
Expand Down Expand Up @@ -370,6 +378,30 @@ pub mod pallet {
Self::deposit_event(Event::<T>::AssetMetadataSet(metadata));
Ok(())
}

/// Burn Native tokens of an account
///
/// # Parameters
///
/// * `who`: AccountId
/// * `amount`: Amount of native tokens to burn.
#[pallet::call_index(5)]
#[pallet::weight(<T as Config>::WeightInfo::parachain_withdraw(1))] // TODO: Update the weights
pub fn burn_native_tokens(
origin: OriginFor<T>,
who: T::AccountId,
amount: u128,
) -> DispatchResult {
T::GovernanceOrigin::ensure_origin(origin)?;
let burned_amt = <T as Config>::Currency::burn_from(
&who,
amount.saturated_into(),
Precision::BestEffort,
Fortitude::Force,
)?;
Self::deposit_event(Event::<T>::NativeTokenBurned(who, burned_amt.saturated_into()));
Ok(())
}
}

impl<T: Config> Pallet<T> {
Expand Down
1 change: 1 addition & 0 deletions runtimes/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ impl thea_executor::Config for Runtime {
type Swap = AssetConversion;
type MultiAssetIdAdapter = AssetId;
type AssetBalanceAdapter = u128;
type GovernanceOrigin = EnsureRootOrHalfCouncil;
type ExistentialDeposit = ExistentialDeposit;
}

Expand Down

0 comments on commit e32d5b7

Please sign in to comment.