diff --git a/frame/assets/src/benchmarking.rs b/frame/assets/src/benchmarking.rs index c6925df9ad88f..6aeb78abc3074 100644 --- a/frame/assets/src/benchmarking.rs +++ b/frame/assets/src/benchmarking.rs @@ -167,12 +167,12 @@ benchmarks_instance_pallet! { assert_last_event::(Event::Issued(Default::default(), caller, amount).into()); } - burn { + slash { let amount = T::Balance::from(100u32); let (caller, caller_lookup) = create_default_minted_asset::(true, amount); }: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, amount) verify { - assert_last_event::(Event::Burned(Default::default(), caller, amount).into()); + assert_last_event::(Event::Slashed(Default::default(), caller, amount).into()); } transfer { diff --git a/frame/assets/src/functions.rs b/frame/assets/src/functions.rs index c6b5391cff860..b06af467bf375 100644 --- a/frame/assets/src/functions.rs +++ b/frame/assets/src/functions.rs @@ -342,7 +342,7 @@ impl, I: 'static> Pallet { Ok(()) })?; - Self::deposit_event(Event::Burned(id, target.clone(), actual)); + Self::deposit_event(Event::Slashed(id, target.clone(), actual)); Ok(actual) } diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index e856211289b0b..eba086b44780d 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -96,7 +96,7 @@ //! ### Privileged Functions //! * `destroy`: Destroys an entire asset class; called by the asset class's Owner. //! * `mint`: Increases the asset balance of an account; called by the asset class's Issuer. -//! * `burn`: Decreases the asset balance of an account; called by the asset class's Admin. +//! * `slash`: Decreases the asset balance of an account; called by the asset class's Admin. //! * `force_transfer`: Transfers between arbitrary accounts; called by the asset class's Admin. //! * `freeze`: Disallows further `transfer`s from an account; called by the asset class's Freezer. //! * `thaw`: Allows further `transfer`s from an account; called by the asset class's Admin. @@ -273,8 +273,8 @@ pub mod pallet { Issued(T::AssetId, T::AccountId, T::Balance), /// Some assets were transferred. \[asset_id, from, to, amount\] Transferred(T::AssetId, T::AccountId, T::AccountId, T::Balance), - /// Some assets were destroyed. \[asset_id, owner, balance\] - Burned(T::AssetId, T::AccountId, T::Balance), + /// Some assets were destroyed from an account. \[asset_id, owner, balance\] + Slashed(T::AssetId, T::AccountId, T::Balance), /// The management team changed \[asset_id, issuer, admin, freezer\] TeamChanged(T::AssetId, T::AccountId, T::AccountId, T::AccountId), /// The owner changed \[asset_id, owner\] @@ -531,7 +531,6 @@ pub mod pallet { let origin = ensure_signed(origin)?; let beneficiary = T::Lookup::lookup(beneficiary)?; Self::do_mint(id, &beneficiary, amount, Some(origin))?; - Self::deposit_event(Event::Issued(id, beneficiary, amount)); Ok(()) } @@ -541,17 +540,17 @@ pub mod pallet { /// /// Bails with `BalanceZero` if the `who` is already dead. /// - /// - `id`: The identifier of the asset to have some amount burned. + /// - `id`: The identifier of the asset to have some amount slashed. /// - `who`: The account to be debited from. /// - `amount`: The maximum amount by which `who`'s balance should be reduced. /// - /// Emits `Burned` with the actual amount burned. If this takes the balance to below the + /// Emits `Slashed` with the actual amount burned. If this takes the balance to below the /// minimum for the asset, then the amount burned is increased to take it to zero. /// /// Weight: `O(1)` /// Modes: Post-existence of `who`; Pre & post Zombie-status of `who`. - #[pallet::weight(T::WeightInfo::burn())] - pub(super) fn burn( + #[pallet::weight(T::WeightInfo::slash())] + pub(super) fn slash( origin: OriginFor, #[pallet::compact] id: T::AssetId, who: ::Source, @@ -561,8 +560,7 @@ pub mod pallet { let who = T::Lookup::lookup(who)?; let f = DebitFlags { keep_alive: false, best_effort: true }; - let burned = Self::do_burn(id, &who, amount, Some(origin), f)?; - Self::deposit_event(Event::Burned(id, who, burned)); + let _ = Self::do_burn(id, &who, amount, Some(origin), f)?; Ok(()) } diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index 3ee8f9a9cfa47..d3c17f9140301 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -231,7 +231,7 @@ fn min_balance_should_work() { assert_eq!(Assets::balance(0, 1), 100); assert_eq!(Asset::::get(0).unwrap().accounts, 1); - assert_ok!(Assets::burn(Origin::signed(1), 0, 1, 91)); + assert_ok!(Assets::slash(Origin::signed(1), 0, 1, 91)); assert!(Assets::balance(0, 1).is_zero()); assert_eq!(Asset::::get(0).unwrap().accounts, 0); }); @@ -250,7 +250,7 @@ fn querying_total_supply_should_work() { assert_eq!(Assets::balance(0, 1), 50); assert_eq!(Assets::balance(0, 2), 19); assert_eq!(Assets::balance(0, 3), 31); - assert_ok!(Assets::burn(Origin::signed(1), 0, 3, u64::max_value())); + assert_ok!(Assets::slash(Origin::signed(1), 0, 3, u64::max_value())); assert_eq!(Assets::total_supply(0), 69); }); } @@ -316,7 +316,7 @@ fn origin_guards_should_work() { assert_noop!(Assets::freeze(Origin::signed(2), 0, 1), Error::::NoPermission); assert_noop!(Assets::thaw(Origin::signed(2), 0, 2), Error::::NoPermission); assert_noop!(Assets::mint(Origin::signed(2), 0, 2, 100), Error::::NoPermission); - assert_noop!(Assets::burn(Origin::signed(2), 0, 1, 100), Error::::NoPermission); + assert_noop!(Assets::slash(Origin::signed(2), 0, 1, 100), Error::::NoPermission); assert_noop!(Assets::force_transfer(Origin::signed(2), 0, 1, 2, 100), Error::::NoPermission); let w = Asset::::get(0).unwrap().destroy_witness(); assert_noop!(Assets::destroy(Origin::signed(2), 0, w), Error::::NoPermission); @@ -356,7 +356,7 @@ fn set_team_should_work() { assert_ok!(Assets::freeze(Origin::signed(4), 0, 2)); assert_ok!(Assets::thaw(Origin::signed(3), 0, 2)); assert_ok!(Assets::force_transfer(Origin::signed(3), 0, 2, 3, 100)); - assert_ok!(Assets::burn(Origin::signed(3), 0, 3, 100)); + assert_ok!(Assets::slash(Origin::signed(3), 0, 3, 100)); }); } @@ -383,7 +383,7 @@ fn transferring_amount_more_than_available_balance_should_not_work() { assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50)); assert_eq!(Assets::balance(0, 1), 50); assert_eq!(Assets::balance(0, 2), 50); - assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::max_value())); + assert_ok!(Assets::slash(Origin::signed(1), 0, 1, u64::max_value())); assert_eq!(Assets::balance(0, 1), 0); assert_noop!(Assets::transfer(Origin::signed(1), 0, 1, 50), Error::::BalanceLow); assert_noop!(Assets::transfer(Origin::signed(2), 0, 1, 51), Error::::BalanceLow); @@ -417,7 +417,7 @@ fn burning_asset_balance_with_positive_balance_should_work() { assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100)); assert_eq!(Assets::balance(0, 1), 100); - assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::max_value())); + assert_ok!(Assets::slash(Origin::signed(1), 0, 1, u64::max_value())); assert_eq!(Assets::balance(0, 1), 0); }); } @@ -428,7 +428,7 @@ fn burning_asset_balance_with_zero_balance_does_nothing() { assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1)); assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100)); assert_eq!(Assets::balance(0, 2), 0); - assert_ok!(Assets::burn(Origin::signed(1), 0, 2, u64::max_value())); + assert_ok!(Assets::slash(Origin::signed(1), 0, 2, u64::max_value())); assert_eq!(Assets::balance(0, 2), 0); assert_eq!(Assets::total_supply(0), 100); }); diff --git a/frame/assets/src/weights.rs b/frame/assets/src/weights.rs index c3c804a392dbe..bc581e3924c80 100644 --- a/frame/assets/src/weights.rs +++ b/frame/assets/src/weights.rs @@ -48,7 +48,7 @@ pub trait WeightInfo { fn force_create() -> Weight; fn destroy(c: u32, s: u32, a: u32, ) -> Weight; fn mint() -> Weight; - fn burn() -> Weight; + fn slash() -> Weight; fn transfer() -> Weight; fn transfer_keep_alive() -> Weight; fn force_transfer() -> Weight; @@ -103,7 +103,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - fn burn() -> Weight { + fn slash() -> Weight { (46_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) @@ -237,7 +237,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - fn burn() -> Weight { + fn slash() -> Weight { (46_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))