diff --git a/pallets/loans/src/entities/loans.rs b/pallets/loans/src/entities/loans.rs index 74209b01a7..5a32d34473 100644 --- a/pallets/loans/src/entities/loans.rs +++ b/pallets/loans/src/entities/loans.rs @@ -580,62 +580,3 @@ impl TryFrom<(T::PoolId, ActiveLoan)> for ActiveLoanInfo { }) } } - -/// Migration module that contains old loans types. -/// Can be removed once chains contains pallet-loans version v3 -pub(crate) mod v2 { - use cfg_traits::Seconds; - use parity_scale_codec::Decode; - - use crate::{ - entities::pricing::{external::v2::ExternalActivePricing, internal::InternalActivePricing}, - types::{LoanRestrictions, RepaidAmount, RepaymentSchedule}, - AssetOf, Config, - }; - - #[derive(Decode)] - pub enum ActivePricing { - Internal(InternalActivePricing), - External(ExternalActivePricing), - } - - #[derive(Decode)] - pub struct ActiveLoan { - schedule: RepaymentSchedule, - collateral: AssetOf, - restrictions: LoanRestrictions, - borrower: T::AccountId, - write_off_percentage: T::Rate, - origination_date: Seconds, - pricing: ActivePricing, - total_borrowed: T::Balance, - total_repaid: RepaidAmount, - repayments_on_schedule_until: Seconds, - } - - impl ActiveLoan { - pub fn migrate(self) -> crate::entities::loans::ActiveLoan { - crate::entities::loans::ActiveLoan { - schedule: self.schedule, - collateral: self.collateral, - restrictions: self.restrictions, - borrower: self.borrower, - write_off_percentage: self.write_off_percentage, - origination_date: self.origination_date, - pricing: match self.pricing { - ActivePricing::Internal(inner) => { - crate::entities::pricing::ActivePricing::Internal(inner) - } - ActivePricing::External(inner) => { - crate::entities::pricing::ActivePricing::External( - inner.migrate(self.origination_date), - ) - } - }, - total_borrowed: self.total_borrowed, - total_repaid: self.total_repaid, - repayments_on_schedule_until: self.repayments_on_schedule_until, - } - } - } -} diff --git a/pallets/loans/src/entities/pricing/external.rs b/pallets/loans/src/entities/pricing/external.rs index 0bc614cf31..9718e8b860 100644 --- a/pallets/loans/src/entities/pricing/external.rs +++ b/pallets/loans/src/entities/pricing/external.rs @@ -288,38 +288,3 @@ impl ExternalActivePricing { Ok(()) } } - -/// Migration module that contains old loans types. -/// Can be removed once chains contains pallet-loans version v3 -pub(crate) mod v2 { - use cfg_traits::Seconds; - use parity_scale_codec::Decode; - - use crate::{ - entities::{interest::ActiveInterestRate, pricing::external::ExternalPricing}, - Config, - }; - - #[derive(Decode)] - pub struct ExternalActivePricing { - info: ExternalPricing, - outstanding_quantity: T::Quantity, - interest: ActiveInterestRate, - latest_settlement_price: T::Balance, - } - - impl ExternalActivePricing { - pub fn migrate( - self, - settlement_price_updated: Seconds, - ) -> crate::entities::pricing::external::ExternalActivePricing { - crate::entities::pricing::external::ExternalActivePricing { - info: self.info, - outstanding_quantity: self.outstanding_quantity, - interest: self.interest, - latest_settlement_price: self.latest_settlement_price, - settlement_price_updated, - } - } - } -} diff --git a/pallets/loans/src/lib.rs b/pallets/loans/src/lib.rs index 44bc9e25e8..73844a4f63 100644 --- a/pallets/loans/src/lib.rs +++ b/pallets/loans/src/lib.rs @@ -65,8 +65,6 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; -mod migrations; - pub use pallet::*; pub use weights::WeightInfo; @@ -438,13 +436,6 @@ pub mod pallet { } } - #[pallet::hooks] - impl Hooks> for Pallet { - fn on_runtime_upgrade() -> frame_support::weights::Weight { - migrations::migrate_from_v2_to_v3::() - } - } - #[pallet::call] impl Pallet { /// Creates a new loan against the collateral provided diff --git a/pallets/loans/src/migrations.rs b/pallets/loans/src/migrations.rs deleted file mode 100644 index ace3393389..0000000000 --- a/pallets/loans/src/migrations.rs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2024 Centrifuge Foundation (centrifuge.io). -// -// This file is part of the Centrifuge chain project. -// Centrifuge is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version (see http://www.gnu.org/licenses). -// Centrifuge is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -use cfg_traits::PoolNAV; -use frame_support::{ - dispatch::GetStorageVersion, inherent::Vec, log, pallet_prelude::StorageVersion, traits::Get, - weights::Weight, -}; - -use crate::{ActiveLoans, Config, Pallet}; - -mod v2 { - use frame_support::{pallet_prelude::*, storage_alias}; - - use crate::{entities::loans::v2, Config, Pallet}; - - pub type ActiveLoansVec = BoundedVec< - (::LoanId, v2::ActiveLoan), - ::MaxActiveLoansPerPool, - >; - - #[storage_alias] - pub type ActiveLoans = StorageMap< - Pallet, - Blake2_128Concat, - ::PoolId, - ActiveLoansVec, - ValueQuery, - >; -} - -pub fn migrate_from_v2_to_v3() -> Weight { - if Pallet::::on_chain_storage_version() == StorageVersion::new(2) { - log::info!("Loans: Starting migration v2 -> v3"); - - let mut changed_pools = Vec::new(); - ActiveLoans::::translate::, _>(|pool_id, active_loans| { - changed_pools.push(pool_id); - Some( - active_loans - .into_iter() - .map(|(loan_id, active_loan)| (loan_id, active_loan.migrate())) - .collect::>() - .try_into() - .expect("size doest not change, qed"), - ) - }); - - for pool_id in &changed_pools { - match Pallet::::update_nav(*pool_id) { - Ok(_) => log::info!("Loans: updated portfolio for pool_id: {pool_id:?}"), - Err(e) => log::error!("Loans: error updating the portfolio for {pool_id:?}: {e:?}"), - } - } - - Pallet::::current_storage_version().put::>(); - - let count = changed_pools.len() as u64; - log::info!("Loans: Migrated {} pools", count); - T::DbWeight::get().reads_writes(count + 1, count + 1) - } else { - // wrong storage version - log::warn!("Loans: Migration did not execute. This probably should be removed"); - T::DbWeight::get().reads_writes(1, 0) - } -}