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
9 changes: 9 additions & 0 deletions pallets/liquidity-mining/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ pub mod pallet {
#[pallet::getter(fn pool_id)]
pub(crate) type NextPoolId<T: Config> = StorageValue<_, PoolId, ValueQuery>;

/// The storage is used to store pool-ids which point to the Pools at `PoolState::Charged`.
///
/// Actually, the pools(that the storage points to) are pending to be activated by `Hook`;
/// The activation means converting the pools from `PoolState::Charged` to `PoolState::Ongoing`
/// after the conditions that are set at the pool-creation stage are met.
#[pallet::storage]
#[pallet::getter(fn charged_pids)]
pub(crate) type ChargedPoolIds<T: Config> = StorageValue<_, BTreeSet<PoolId>, ValueQuery>;
Expand Down Expand Up @@ -702,6 +707,10 @@ pub mod pallet {
let r#type = pool.r#type;
let trading_pair = pool.trading_pair;

if pool.state == PoolState::Charged {
ChargedPoolIds::<T>::mutate(|pids| pids.remove(&pid));
}

match pool.state {
PoolState::Charged if pool.deposit == Zero::zero() => {
pool.try_withdraw_remain()?;
Expand Down
12 changes: 12 additions & 0 deletions pallets/liquidity-mining/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,8 @@ fn force_retire_pool_charged_should_work() {
// It is unable to call Collective::execute(..) which is private;
assert_ok!(LM::charge(Some(INVESTOR).into(), 0));

assert_eq!(LM::charged_pids().contains(&0), true);

assert_ok!(LM::deposit(Some(USER_1).into(), 0, UNIT));
assert_ok!(LM::deposit(Some(USER_2).into(), 0, UNIT));

Expand All @@ -1755,6 +1757,8 @@ fn force_retire_pool_charged_should_work() {
assert_ok!(LM::redeem_all(Some(USER_1).into(), 0));
assert_ok!(LM::redeem_all(Some(USER_2).into(), 0));

assert_ne!(LM::charged_pids().contains(&0), true);

assert_eq!(Tokens::accounts(USER_1, REWARD_1).free, 0);
assert_eq!(Tokens::accounts(USER_1, REWARD_1).frozen, 0);
assert_eq!(Tokens::accounts(USER_1, REWARD_1).reserved, 0);
Expand Down Expand Up @@ -1806,13 +1810,17 @@ fn force_retire_pool_charged_without_deposit_should_work() {
// It is unable to call Collective::execute(..) which is private;
assert_ok!(LM::charge(Some(INVESTOR).into(), 0));

assert_eq!(LM::charged_pids().contains(&0), true);

let keeper = LM::pool(0).unwrap().keeper;

assert_ok!(LM::force_retire_pool(
pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
0
));

assert_ne!(LM::charged_pids().contains(&0), true);

assert_eq!(Tokens::accounts(keeper.clone(), REWARD_1).free, 0);
assert_eq!(Tokens::accounts(keeper.clone(), REWARD_1).frozen, 0);
assert_eq!(Tokens::accounts(keeper.clone(), REWARD_1).reserved, 0);
Expand Down Expand Up @@ -1849,6 +1857,8 @@ fn force_retire_pool_ongoing_should_work() {
// It is unable to call Collective::execute(..) which is private;
assert_ok!(LM::charge(Some(INVESTOR).into(), 0));

assert_eq!(LM::charged_pids().contains(&0), true);

assert_ok!(LM::deposit(Some(USER_1).into(), 0, UNIT));

run_to_block(100);
Expand All @@ -1857,6 +1867,8 @@ fn force_retire_pool_ongoing_should_work() {

run_to_block(200);

assert_ne!(LM::charged_pids().contains(&0), true);

assert_ok!(LM::force_retire_pool(
pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
0
Expand Down