Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[teerdays] explicitly add burned teerdays to event #265

Merged
merged 5 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion primitives/xcm-transactor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions teerdays/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub mod pallet {
/// An account's bond has been increased by an amount
Bonded { account: T::AccountId, amount: BalanceOf<T> },
/// An account's bond has been decreased by an amount
Unbonded { account: T::AccountId, amount: BalanceOf<T> },
Unbonded { account: T::AccountId, amount: BalanceOf<T>, burned_tokentime: BalanceOf<T> },
/// An account's accumulated tokentime has been updated
TokenTimeUpdated { account: T::AccountId, bond: TeerDayBondOf<T> },
/// An account has successfully withdrawn a previously unbonded amount after unlock period has passed
Expand Down Expand Up @@ -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
Expand All @@ -261,6 +262,7 @@ pub mod pallet {
Self::deposit_event(Event::<T>::Unbonded {
account: signer.clone(),
amount: unbonded_amount,
burned_tokentime: pre_tokentime.saturating_sub(new_tokentime),
});
Ok(())
}
Expand Down Expand Up @@ -312,7 +314,7 @@ impl<T: Config> Pallet<T> {
let (due, amount) = Self::pending_unlock(account).ok_or(Error::<T>::NotUnlocking)?;
let now = pallet_timestamp::Pallet::<T>::get();
if now < due {
return Err(Error::<T>::PendingUnlock.into())
return Err(Error::<T>::PendingUnlock.into());
}
let locked = T::Currency::balance_locked(TEERDAYS_ID, account);
let amount = amount.min(locked);
Expand Down
14 changes: 10 additions & 4 deletions teerdays/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test> = 15_000_000_000_000;
<Test as pallet::Config>::Currency::make_free_balance_be(&alice, alice_free);
let amount: BalanceOf<Test> = 10_000_000_000_000;
assert_ok!(TeerDays::bond(RuntimeOrigin::signed(alice.clone()), amount));

Expand Down Expand Up @@ -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;
Expand All @@ -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));

Expand Down Expand Up @@ -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);
Expand Down
Loading