diff --git a/primitives/xcm-transactor/src/lib.rs b/primitives/xcm-transactor/src/lib.rs index e1fe6e10..a7a69ce5 100644 --- a/primitives/xcm-transactor/src/lib.rs +++ b/primitives/xcm-transactor/src/lib.rs @@ -42,7 +42,7 @@ pub trait BuildRelayCall { /// - execution to be purchased via BuyExecution XCM Instruction /// - Weight required to execute this call. /// - Amount of execution to buy on the relay chain. This parameter is exposed because it varies - /// depending on the relay chain. + /// depending on the relay chain. /// /// Returns: /// - Corresponding XCM Message for Transacting on this RelayCall diff --git a/teerdays/src/lib.rs b/teerdays/src/lib.rs index 5fda660b..f76591b3 100644 --- a/teerdays/src/lib.rs +++ b/teerdays/src/lib.rs @@ -127,7 +127,7 @@ pub mod pallet { /// An account's bond has been increased by an amount Bonded { account: T::AccountId, amount: BalanceOf }, /// An account's bond has been decreased by an amount - Unbonded { account: T::AccountId, amount: BalanceOf }, + Unbonded { account: T::AccountId, amount: BalanceOf, burned_tokentime: BalanceOf }, /// An account's accumulated tokentime has been updated TokenTimeUpdated { account: T::AccountId, bond: TeerDayBondOf }, /// An account has successfully withdrawn a previously unbonded amount after unlock period has passed @@ -238,6 +238,7 @@ pub mod pallet { let new_bonded_amount = bond.value.saturating_sub(value); let unbonded_amount = bond.value.saturating_sub(new_bonded_amount); + let pre_tokentime = bond.accumulated_tokentime; // burn tokentime pro rata let new_tokentime = bond .accumulated_tokentime @@ -261,6 +262,7 @@ pub mod pallet { Self::deposit_event(Event::::Unbonded { account: signer.clone(), amount: unbonded_amount, + burned_tokentime: pre_tokentime.saturating_sub(new_tokentime), }); Ok(()) } @@ -312,7 +314,7 @@ impl Pallet { let (due, amount) = Self::pending_unlock(account).ok_or(Error::::NotUnlocking)?; let now = pallet_timestamp::Pallet::::get(); if now < due { - return Err(Error::::PendingUnlock.into()) + return Err(Error::::PendingUnlock.into()); } let locked = T::Currency::balance_locked(TEERDAYS_ID, account); let amount = amount.min(locked); diff --git a/teerdays/src/tests.rs b/teerdays/src/tests.rs index 1f8dfa7f..737cd44d 100644 --- a/teerdays/src/tests.rs +++ b/teerdays/src/tests.rs @@ -27,6 +27,8 @@ fn bond_works() { let now: Moment = 42; set_timestamp(now); let alice = AccountKeyring::Alice.to_account_id(); + let alice_free: BalanceOf = 15_000_000_000_000; + ::Currency::make_free_balance_be(&alice, alice_free); let amount: BalanceOf = 10_000_000_000_000; assert_ok!(TeerDays::bond(RuntimeOrigin::signed(alice.clone()), amount)); @@ -158,7 +160,7 @@ fn bond_extra_saturates_at_free_margin() { } #[test] -fn withrawing_unbonded_after_unlock_period_works() { +fn withdrawing_unbonded_after_unlock_period_works() { new_test_ext().execute_with(|| { run_to_block(1); let now: Moment = 42; @@ -178,12 +180,13 @@ fn withrawing_unbonded_after_unlock_period_works() { let tokentime_accumulated = amount.saturating_mul(UnlockPeriod::get() as Balance); - let unbond_amount = amount / 3; + let unbond_amount = amount / 5; assert_ok!(TeerDays::unbond(RuntimeOrigin::signed(alice.clone()), unbond_amount)); let expected_event = RuntimeEvent::TeerDays(TeerDaysEvent::Unbonded { account: alice.clone(), amount: unbond_amount, + burned_tokentime: tokentime_accumulated / 5, }); assert!(System::events().iter().any(|a| a.event == expected_event)); @@ -253,8 +256,11 @@ fn unbonding_saturates_at_bonded() { let unbond_amount = amount * 2; assert_ok!(TeerDays::unbond(RuntimeOrigin::signed(alice.clone()), unbond_amount)); - let expected_event = - RuntimeEvent::TeerDays(TeerDaysEvent::Unbonded { account: alice.clone(), amount }); + let expected_event = RuntimeEvent::TeerDays(TeerDaysEvent::Unbonded { + account: alice.clone(), + amount, + burned_tokentime: 0, //no time has elapsed + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert!(TeerDays::teerday_bonds(&alice).is_none()); assert_eq!(TeerDays::pending_unlock(&alice).unwrap().1, amount);