From 790af2d4e4938a29579883f63130ab5d7e15aa90 Mon Sep 17 00:00:00 2001 From: nuno Date: Mon, 25 Sep 2023 09:54:31 +0200 Subject: [PATCH] Check pool value == 0 --- runtime/centrifuge/src/migrations.rs | 35 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index 4b1bc8dd7b..6f3bc285fd 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -18,12 +18,13 @@ pub type UpgradeCentrifuge1021 = anemoy_pool::Migration; mod anemoy_pool { use cfg_primitives::PoolId; + use cfg_traits::PoolInspect; use cfg_types::tokens::CurrencyId; #[cfg(feature = "try-runtime")] use codec::{Decode, Encode}; #[cfg(feature = "try-runtime")] use frame_support::ensure; - use frame_support::traits::OnRuntimeUpgrade; + use frame_support::traits::{fungibles::Inspect, OnRuntimeUpgrade}; #[cfg(feature = "try-runtime")] use pallet_pool_system::PoolDetailsOf; #[cfg(feature = "try-runtime")] @@ -106,9 +107,10 @@ mod anemoy_pool { fn verify_sanity_checks() -> (bool, Weight) { let res = - pallet_investments::ActiveInvestOrders::::iter_keys() - .filter(|investment| investment.pool_id == ANEMOY_POOL_ID) - .count() == 0 && pallet_investments::ActiveInvestOrders::::iter_keys() + crate::Tokens::balance(LP_ETH_USDC, &PoolSystem::account_for(ANEMOY_POOL_ID)) == 0 + && pallet_investments::ActiveInvestOrders::::iter_keys() + .filter(|investment| investment.pool_id == ANEMOY_POOL_ID) + .count() == 0 && pallet_investments::ActiveInvestOrders::::iter_keys() .filter(|investment| investment.pool_id == ANEMOY_POOL_ID) .count() == 0 && pallet_investments::InvestOrders::::iter_keys() .filter(|(_, investment)| investment.pool_id == ANEMOY_POOL_ID) @@ -117,16 +119,21 @@ mod anemoy_pool { .count() == 0; let weight = ::DbWeight::get().reads( - 0u64.saturating_add( - pallet_investments::ActiveInvestOrders::::iter_keys().count() as u64, - ) - .saturating_add( - pallet_investments::ActiveInvestOrders::::iter_keys().count() as u64, - ) - .saturating_add(pallet_investments::InvestOrders::::iter_keys().count() as u64) - .saturating_add(pallet_investments::RedeemOrders::::iter_keys().count() as u64) - // 2x, first for the sanity checks and now for calculating these weights - .saturating_mul(2), + 1u64 // Anemoy pool account balance read + .saturating_add( + pallet_investments::ActiveInvestOrders::::iter_keys().count() as u64, + ) + .saturating_add( + pallet_investments::ActiveInvestOrders::::iter_keys().count() as u64, + ) + .saturating_add( + pallet_investments::InvestOrders::::iter_keys().count() as u64, + ) + .saturating_add( + pallet_investments::RedeemOrders::::iter_keys().count() as u64, + ) + // 2x, first for the sanity checks and now for calculating these weights + .saturating_mul(2), ); (res, weight)