Skip to content

Commit 45ec291

Browse files
Added extrinsic to burn token
1 parent 941bd3c commit 45ec291

File tree

6 files changed

+75
-42
lines changed

6 files changed

+75
-42
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- [C] Changes is `Cere` Runtime
1111
- [D] Changes is `Cere Dev` Runtime
1212

13+
## [7.3.7]
14+
15+
- [C,D] Added extrinsic to burn tokens
16+
1317
## [7.3.6]
1418

1519
- [C,D] Added mechanism to handle Remainder of Era Rewards

Cargo.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace.package]
2-
version = "7.3.6"
2+
version = "7.3.7"
33
authors = ["Cerebellum-Network"]
44
edition = "2021"
55
homepage = "https://cere.network/"

pallets/fee-handler/src/lib.rs

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
// todo! Add Unit tests and Benchmarking
2222

2323
use codec::{Decode, Encode, MaxEncodedLen};
24-
use frame_support::{__private::RuntimeDebug, pallet_prelude::TypeInfo, traits::Currency};
24+
use frame_support::{
25+
__private::RuntimeDebug,
26+
pallet_prelude::TypeInfo,
27+
sp_runtime::SaturatedConversion,
28+
traits::{
29+
fungible::Mutate,
30+
tokens::{Fortitude, Precision, Preservation},
31+
},
32+
};
2533
pub use pallet::*;
2634
use sp_runtime::{Permill, Saturating};
2735

@@ -31,9 +39,6 @@ pub struct FeeDistributionProportion {
3139
fee_pot_proportion: Permill,
3240
}
3341

34-
pub type BalanceOf<T> =
35-
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
36-
3742
impl FeeDistributionProportion {
3843
/// Creates a new `FeeDistributionProportion` if the total proportions equal 100%.
3944
pub fn new(treasury_proportion: u32, fee_pot_proportion: u32) -> Option<Self> {
@@ -50,7 +55,7 @@ impl FeeDistributionProportion {
5055

5156
pub trait FeeHandler<T: Config> {
5257
/// Handles the distribution of fees to the treasury and fee pot accounts.
53-
fn handle_fee(source: T::AccountId, fee_amount: BalanceOf<T>) -> sp_runtime::DispatchResult;
58+
fn handle_fee(source: T::AccountId, fee_amount: u128) -> sp_runtime::DispatchResult;
5459
}
5560

5661
// todo! Fixed clippy warnings
@@ -59,11 +64,7 @@ pub trait FeeHandler<T: Config> {
5964
#[allow(clippy::manual_inspect)]
6065
#[frame_support::pallet]
6166
pub mod pallet {
62-
use frame_support::{
63-
pallet_prelude::*,
64-
traits::{ExistenceRequirement, LockableCurrency},
65-
PalletId,
66-
};
67+
use frame_support::{pallet_prelude::*, PalletId};
6768
use frame_system::pallet_prelude::*;
6869
use sp_runtime::traits::AccountIdConversion;
6970

@@ -77,7 +78,7 @@ pub mod pallet {
7778
/// The overarching runtime event type.
7879
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
7980
/// Native Currency Support.
80-
type Currency: LockableCurrency<Self::AccountId, Moment = BlockNumberFor<Self>>;
81+
type Currency: Mutate<Self::AccountId>;
8182
/// Governance origin for privileged calls.
8283
type GovernanceOrigin: EnsureOrigin<Self::RuntimeOrigin>;
8384
/// Pallet ID for the fee pot account.
@@ -95,9 +96,11 @@ pub mod pallet {
9596
#[pallet::generate_deposit(pub(super) fn deposit_event)]
9697
pub enum Event<T: Config> {
9798
/// Manual top-up of the fee pot account.
98-
ManualFeeAccountTopUp { source: T::AccountId, amount: BalanceOf<T> },
99+
ManualFeeAccountTopUp { source: T::AccountId, amount: u128 },
99100
/// Fee distribution configuration updated.
100101
FeeDistributionProportionConfigSet { config: FeeDistributionProportion },
102+
/// Native Token Burn event
103+
NativeTokenBurned(T::AccountId, u128),
101104
}
102105

103106
#[pallet::error]
@@ -114,13 +117,13 @@ pub mod pallet {
114117
#[pallet::call_index(0)]
115118
// todo! Add actual weights
116119
#[pallet::weight(10_000)]
117-
pub fn manual_topup(origin: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {
120+
pub fn manual_topup(origin: OriginFor<T>, amount: u128) -> DispatchResult {
118121
let who = ensure_signed(origin)?;
119122
T::Currency::transfer(
120123
&who,
121124
&Self::fee_pot_account_id(),
122-
amount,
123-
ExistenceRequirement::AllowDeath,
125+
amount.saturated_into(),
126+
Preservation::Preserve,
124127
)?;
125128
Self::deposit_event(Event::ManualFeeAccountTopUp { source: who, amount });
126129
Ok(())
@@ -145,6 +148,32 @@ pub mod pallet {
145148
});
146149
Ok(())
147150
}
151+
152+
/// Burn Native tokens of an account
153+
///
154+
/// # Parameters
155+
///
156+
/// * `who`: AccountId
157+
/// * `amount`: Amount of native tokens to burn.
158+
#[pallet::call_index(2)]
159+
// todo! Add actual weights
160+
#[pallet::weight(10_000)]
161+
pub fn burn_native_tokens(
162+
origin: OriginFor<T>,
163+
who: T::AccountId,
164+
amount: u128,
165+
) -> DispatchResult {
166+
T::GovernanceOrigin::ensure_origin(origin)?;
167+
let burned_amt = <T as Config>::Currency::burn_from(
168+
&who,
169+
amount.saturated_into(),
170+
Preservation::Preserve,
171+
Precision::BestEffort,
172+
Fortitude::Force,
173+
)?;
174+
Self::deposit_event(Event::<T>::NativeTokenBurned(who, burned_amt.saturated_into()));
175+
Ok(())
176+
}
148177
}
149178

150179
impl<T: Config> Pallet<T> {
@@ -160,7 +189,7 @@ pub mod pallet {
160189
}
161190

162191
impl<T: Config> FeeHandler<T> for Pallet<T> {
163-
fn handle_fee(source: T::AccountId, fee_amount: BalanceOf<T>) -> DispatchResult {
192+
fn handle_fee(source: T::AccountId, fee_amount: u128) -> DispatchResult {
164193
let fee_config: FeeDistributionProportion = <FeeDistributionProportionConfig<T>>::get()
165194
.ok_or(Error::<T>::FeeDistributionConfigNotSet)?;
166195
let fee_pot_amount = fee_config.fee_pot_proportion.mul_floor(fee_amount);
@@ -172,14 +201,14 @@ pub mod pallet {
172201
T::Currency::transfer(
173202
&source,
174203
&fee_pot_account,
175-
fee_pot_amount,
176-
ExistenceRequirement::AllowDeath,
204+
fee_pot_amount.saturated_into(),
205+
Preservation::Preserve,
177206
)?;
178207
T::Currency::transfer(
179208
&source,
180209
&treasury_account,
181-
treasury_amount,
182-
ExistenceRequirement::AllowDeath,
210+
treasury_amount.saturated_into(),
211+
Preservation::Preserve,
183212
)?;
184213
Ok(())
185214
}

runtime/cere-dev/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
164164
// and set impl_version to 0. If only runtime
165165
// implementation changes and behavior does not, then leave spec_version as
166166
// is and increment impl_version.
167-
spec_version: 73111,
167+
spec_version: 73112,
168168
impl_version: 0,
169169
apis: RUNTIME_API_VERSIONS,
170170
transaction_version: 24,

runtime/cere/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
159159
// and set impl_version to 0. If only runtime
160160
// implementation changes and behavior does not, then leave spec_version as
161161
// is and increment impl_version.
162-
spec_version: 73111,
162+
spec_version: 73112,
163163
impl_version: 0,
164164
apis: RUNTIME_API_VERSIONS,
165165
transaction_version: 24,

0 commit comments

Comments
 (0)