diff --git a/pallets/liquidity-mining/src/lib.rs b/pallets/liquidity-mining/src/lib.rs index 06accfcbf9..2da0af8695 100644 --- a/pallets/liquidity-mining/src/lib.rs +++ b/pallets/liquidity-mining/src/lib.rs @@ -480,6 +480,11 @@ pub mod pallet { #[pallet::getter(fn pool_id)] pub(crate) type NextPoolId = 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 = StorageValue<_, BTreeSet, ValueQuery>; @@ -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::::mutate(|pids| pids.remove(&pid)); + } + match pool.state { PoolState::Charged if pool.deposit == Zero::zero() => { pool.try_withdraw_remain()?; diff --git a/pallets/liquidity-mining/src/tests.rs b/pallets/liquidity-mining/src/tests.rs index 85922d62a7..9ffd9b8dda 100644 --- a/pallets/liquidity-mining/src/tests.rs +++ b/pallets/liquidity-mining/src/tests.rs @@ -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)); @@ -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); @@ -1806,6 +1810,8 @@ 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( @@ -1813,6 +1819,8 @@ fn force_retire_pool_charged_without_deposit_should_work() { 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); @@ -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); @@ -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