Skip to content
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
11 changes: 11 additions & 0 deletions tokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ pub mod module {
/// Some balance was unreserved (moved from reserved to free).
/// \[currency_id, who, value\]
Unreserved(T::CurrencyId, T::AccountId, T::Balance),
/// Some reserved balance was repatriated (moved from reserved to
/// another account).
/// \[currency_id, from, to, amount_actually_moved, status\]
RepatriatedReserve(T::CurrencyId, T::AccountId, T::AccountId, T::Balance, BalanceStatus),
/// A balance was set by root. \[who, free, reserved\]
BalanceSet(T::CurrencyId, T::AccountId, T::Balance, T::Balance),
}
Expand Down Expand Up @@ -1196,6 +1200,13 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
}
}
Self::set_reserved_balance(currency_id, slashed, from_account.reserved - actual);
Self::deposit_event(Event::<T>::RepatriatedReserve(
currency_id,
slashed.clone(),
beneficiary.clone(),
actual,
status,
));
Ok(value - actual)
}
}
Expand Down
22 changes: 22 additions & 0 deletions tokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,9 @@ fn multi_reservable_currency_repatriate_reserved_work() {
Tokens::repatriate_reserved(DOT, &ALICE, &ALICE, 50, BalanceStatus::Free),
Ok(50)
);
// Repatriating from and to the same account, fund is `unreserved`.
System::assert_last_event(Event::Tokens(crate::Event::Unreserved(DOT, ALICE, 0)));

assert_eq!(Tokens::free_balance(DOT, &ALICE), 100);
assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 0);

Expand All @@ -1333,13 +1336,22 @@ fn multi_reservable_currency_repatriate_reserved_work() {
Tokens::repatriate_reserved(DOT, &BOB, &BOB, 60, BalanceStatus::Reserved),
Ok(10)
);

assert_eq!(Tokens::free_balance(DOT, &BOB), 50);
assert_eq!(Tokens::reserved_balance(DOT, &BOB), 50);

assert_eq!(
Tokens::repatriate_reserved(DOT, &BOB, &ALICE, 30, BalanceStatus::Reserved),
Ok(0)
);
System::assert_last_event(Event::Tokens(crate::Event::RepatriatedReserve(
DOT,
BOB,
ALICE,
30,
BalanceStatus::Reserved,
)));

assert_eq!(Tokens::free_balance(DOT, &ALICE), 100);
assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 30);
assert_eq!(Tokens::free_balance(DOT, &BOB), 50);
Expand All @@ -1349,6 +1361,16 @@ fn multi_reservable_currency_repatriate_reserved_work() {
Tokens::repatriate_reserved(DOT, &BOB, &ALICE, 30, BalanceStatus::Free),
Ok(10)
);

// Actual amount repatriated is 20.
System::assert_last_event(Event::Tokens(crate::Event::RepatriatedReserve(
DOT,
BOB,
ALICE,
20,
BalanceStatus::Free,
)));

assert_eq!(Tokens::free_balance(DOT, &ALICE), 120);
assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 30);
assert_eq!(Tokens::free_balance(DOT, &BOB), 50);
Expand Down