21
21
// todo! Add Unit tests and Benchmarking
22
22
23
23
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
+ } ;
25
33
pub use pallet:: * ;
26
34
use sp_runtime:: { Permill , Saturating } ;
27
35
@@ -31,9 +39,6 @@ pub struct FeeDistributionProportion {
31
39
fee_pot_proportion : Permill ,
32
40
}
33
41
34
- pub type BalanceOf < T > =
35
- <<T as Config >:: Currency as Currency < <T as frame_system:: Config >:: AccountId > >:: Balance ;
36
-
37
42
impl FeeDistributionProportion {
38
43
/// Creates a new `FeeDistributionProportion` if the total proportions equal 100%.
39
44
pub fn new ( treasury_proportion : u32 , fee_pot_proportion : u32 ) -> Option < Self > {
@@ -50,7 +55,7 @@ impl FeeDistributionProportion {
50
55
51
56
pub trait FeeHandler < T : Config > {
52
57
/// 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 ;
54
59
}
55
60
56
61
// todo! Fixed clippy warnings
@@ -59,11 +64,7 @@ pub trait FeeHandler<T: Config> {
59
64
#[ allow( clippy:: manual_inspect) ]
60
65
#[ frame_support:: pallet]
61
66
pub mod pallet {
62
- use frame_support:: {
63
- pallet_prelude:: * ,
64
- traits:: { ExistenceRequirement , LockableCurrency } ,
65
- PalletId ,
66
- } ;
67
+ use frame_support:: { pallet_prelude:: * , PalletId } ;
67
68
use frame_system:: pallet_prelude:: * ;
68
69
use sp_runtime:: traits:: AccountIdConversion ;
69
70
@@ -77,7 +78,7 @@ pub mod pallet {
77
78
/// The overarching runtime event type.
78
79
type RuntimeEvent : From < Event < Self > > + IsType < <Self as frame_system:: Config >:: RuntimeEvent > ;
79
80
/// Native Currency Support.
80
- type Currency : LockableCurrency < Self :: AccountId , Moment = BlockNumberFor < Self > > ;
81
+ type Currency : Mutate < Self :: AccountId > ;
81
82
/// Governance origin for privileged calls.
82
83
type GovernanceOrigin : EnsureOrigin < Self :: RuntimeOrigin > ;
83
84
/// Pallet ID for the fee pot account.
@@ -95,9 +96,11 @@ pub mod pallet {
95
96
#[ pallet:: generate_deposit( pub ( super ) fn deposit_event) ]
96
97
pub enum Event < T : Config > {
97
98
/// Manual top-up of the fee pot account.
98
- ManualFeeAccountTopUp { source : T :: AccountId , amount : BalanceOf < T > } ,
99
+ ManualFeeAccountTopUp { source : T :: AccountId , amount : u128 } ,
99
100
/// Fee distribution configuration updated.
100
101
FeeDistributionProportionConfigSet { config : FeeDistributionProportion } ,
102
+ /// Native Token Burn event
103
+ NativeTokenBurned ( T :: AccountId , u128 ) ,
101
104
}
102
105
103
106
#[ pallet:: error]
@@ -114,13 +117,13 @@ pub mod pallet {
114
117
#[ pallet:: call_index( 0 ) ]
115
118
// todo! Add actual weights
116
119
#[ 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 {
118
121
let who = ensure_signed ( origin) ?;
119
122
T :: Currency :: transfer (
120
123
& who,
121
124
& Self :: fee_pot_account_id ( ) ,
122
- amount,
123
- ExistenceRequirement :: AllowDeath ,
125
+ amount. saturated_into ( ) ,
126
+ Preservation :: Preserve ,
124
127
) ?;
125
128
Self :: deposit_event ( Event :: ManualFeeAccountTopUp { source : who, amount } ) ;
126
129
Ok ( ( ) )
@@ -145,6 +148,32 @@ pub mod pallet {
145
148
} ) ;
146
149
Ok ( ( ) )
147
150
}
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
+ }
148
177
}
149
178
150
179
impl < T : Config > Pallet < T > {
@@ -160,7 +189,7 @@ pub mod pallet {
160
189
}
161
190
162
191
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 {
164
193
let fee_config: FeeDistributionProportion = <FeeDistributionProportionConfig < T > >:: get ( )
165
194
. ok_or ( Error :: < T > :: FeeDistributionConfigNotSet ) ?;
166
195
let fee_pot_amount = fee_config. fee_pot_proportion . mul_floor ( fee_amount) ;
@@ -172,14 +201,14 @@ pub mod pallet {
172
201
T :: Currency :: transfer (
173
202
& source,
174
203
& fee_pot_account,
175
- fee_pot_amount,
176
- ExistenceRequirement :: AllowDeath ,
204
+ fee_pot_amount. saturated_into ( ) ,
205
+ Preservation :: Preserve ,
177
206
) ?;
178
207
T :: Currency :: transfer (
179
208
& source,
180
209
& treasury_account,
181
- treasury_amount,
182
- ExistenceRequirement :: AllowDeath ,
210
+ treasury_amount. saturated_into ( ) ,
211
+ Preservation :: Preserve ,
183
212
) ?;
184
213
Ok ( ( ) )
185
214
}
0 commit comments