diff --git a/Cargo.lock b/Cargo.lock index 1d28fc9e55..3249eada4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1007,7 +1007,7 @@ dependencies = [ "pallet-interest-accrual", "pallet-investments", "pallet-keystore", - "pallet-loans", + "pallet-loans-ref", "pallet-migration-manager", "pallet-multisig", "pallet-nft", diff --git a/runtime/centrifuge/Cargo.toml b/runtime/centrifuge/Cargo.toml index fba8dcc89c..de49f4b477 100644 --- a/runtime/centrifuge/Cargo.toml +++ b/runtime/centrifuge/Cargo.toml @@ -101,7 +101,7 @@ pallet-fees = { path = "../../pallets/fees", default-features = false } pallet-interest-accrual = { path = "../../pallets/interest-accrual", default-features = false } pallet-investments = { path = "../../pallets/investments", default-features = false } pallet-keystore = { path = "../../pallets/keystore", default-features = false } -pallet-loans = { path = "../../pallets/loans", default-features = false } +pallet-loans-ref = { path = "../../pallets/loans-ref", default-features = false } pallet-migration-manager = { path = "../../pallets/migration", default-features = false } pallet-nft = { path = "../../pallets/nft", default-features = false } pallet-permissions = { path = "../../pallets/permissions", default-features = false } @@ -162,7 +162,7 @@ std = [ "pallet-identity/std", "pallet-interest-accrual/std", "pallet-investments/std", - "pallet-loans/std", + "pallet-loans-ref/std", "pallet-keystore/std", "pallet-migration-manager/std", "pallet-multisig/std", @@ -236,7 +236,7 @@ runtime-benchmarks = [ "pallet-identity/runtime-benchmarks", "pallet-interest-accrual/runtime-benchmarks", "pallet-investments/runtime-benchmarks", - "pallet-loans/runtime-benchmarks", + "pallet-loans-ref/runtime-benchmarks", "pallet-keystore/runtime-benchmarks", "pallet-migration-manager/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", @@ -297,7 +297,7 @@ try-runtime = [ "pallet-identity/try-runtime", "pallet-interest-accrual/try-runtime", "pallet-investments/try-runtime", - "pallet-loans/try-runtime", + "pallet-loans-ref/try-runtime", "pallet-keystore/try-runtime", "pallet-migration-manager/try-runtime", "pallet-multisig/try-runtime", diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index 98f04c19fd..5c202ce053 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -20,7 +20,8 @@ pub use cfg_primitives::{constants::*, types::*}; use cfg_traits::{ - OrderManager, Permissions as PermissionsT, PoolUpdateGuard, PreConditions, TrancheCurrency as _, + OrderManager, Permissions as PermissionsT, PoolNAV, PoolUpdateGuard, PreConditions, + TrancheCurrency as _, }; use cfg_types::{ consts::pools::{MaxTrancheNameLengthBytes, MaxTrancheSymbolLengthBytes}, @@ -551,7 +552,6 @@ pub enum ProxyType { _Staking, NonProxy, Borrow, - Price, Invest, ProxyManagement, KeystoreManagement, @@ -623,21 +623,20 @@ impl InstanceFilter for ProxyType { } ProxyType::Borrow => matches!( c, - RuntimeCall::Loans(pallet_loans::Call::create{..}) | - RuntimeCall::Loans(pallet_loans::Call::borrow{..}) | - RuntimeCall::Loans(pallet_loans::Call::repay{..}) | - RuntimeCall::Loans(pallet_loans::Call::write_off{..}) | - RuntimeCall::Loans(pallet_loans::Call::close{..}) | + RuntimeCall::Loans(pallet_loans_ref::Call::create{..}) | + RuntimeCall::Loans(pallet_loans_ref::Call::borrow{..}) | + RuntimeCall::Loans(pallet_loans_ref::Call::repay{..}) | + RuntimeCall::Loans(pallet_loans_ref::Call::write_off{..}) | + RuntimeCall::Loans(pallet_loans_ref::Call::close{..}) | // Borrowers should be able to close and execute an epoch // in order to get liquidity from repayments in previous epochs. - RuntimeCall::Loans(pallet_loans::Call::update_nav{..}) | + RuntimeCall::Loans(pallet_loans_ref::Call::update_portfolio_valuation{..}) | RuntimeCall::PoolSystem(pallet_pool_system::Call::close_epoch{..}) | RuntimeCall::PoolSystem(pallet_pool_system::Call::submit_solution{..}) | RuntimeCall::PoolSystem(pallet_pool_system::Call::execute_epoch{..}) | RuntimeCall::Utility(pallet_utility::Call::batch_all{..}) | RuntimeCall::Utility(pallet_utility::Call::batch{..}) ), - ProxyType::Price => matches!(c, RuntimeCall::Loans(pallet_loans::Call::price { .. })), ProxyType::Invest => matches!( c, RuntimeCall::Investments(pallet_investments::Call::update_invest_order{..}) | @@ -646,7 +645,7 @@ impl InstanceFilter for ProxyType { RuntimeCall::Investments(pallet_investments::Call::collect_redemptions{..}) | // Investors should be able to close and execute an epoch // in order to get their orders fulfilled. - RuntimeCall::Loans(pallet_loans::Call::update_nav{..}) | + RuntimeCall::Loans(pallet_loans_ref::Call::update_portfolio_valuation{..}) | RuntimeCall::PoolSystem(pallet_pool_system::Call::close_epoch{..}) | RuntimeCall::PoolSystem(pallet_pool_system::Call::submit_solution{..}) | RuntimeCall::PoolSystem(pallet_pool_system::Call::execute_epoch{..}) | @@ -1467,26 +1466,25 @@ impl pallet_interest_accrual::Config for Runtime { parameter_types! { pub const LoansPalletId: PalletId = cfg_types::ids::LOANS_PALLET_ID; pub const MaxActiveLoansPerPool: u32 = 1000; - pub const MaxWriteOffGroups: u32 = 100; + pub const MaxWriteOffPolicySize: u32 = 100; } -impl pallet_loans::Config for Runtime { +impl pallet_loans_ref::Config for Runtime { type Balance = Balance; - type BlockNumberProvider = System; - type ClassId = CollectionId; + type CollectionId = CollectionId; type CurrencyId = CurrencyId; type InterestAccrual = InterestAccrual; - type LoanId = ItemId; - type LoansPalletId = LoansPalletId; + type ItemId = ItemId; + type LoanId = LoanId; type MaxActiveLoansPerPool = MaxActiveLoansPerPool; - type MaxWriteOffGroups = MaxWriteOffGroups; + type MaxWriteOffPolicySize = MaxWriteOffPolicySize; type NonFungible = Uniques; - type Permission = Permissions; + type Permissions = Permissions; type Pool = PoolSystem; type Rate = Rate; type RuntimeEvent = RuntimeEvent; type Time = Timestamp; - type WeightInfo = weights::pallet_loans::WeightInfo; + type WeightInfo = weights::pallet_loans_ref::WeightInfo; } parameter_types! { @@ -1619,7 +1617,7 @@ construct_runtime!( InterestAccrual: pallet_interest_accrual::{Pallet, Storage, Event, Config} = 184, Uniques: pallet_uniques::{Pallet, Call, Storage, Event} = 185, Keystore: pallet_keystore::{Pallet, Call, Storage, Event} = 186, - Loans: pallet_loans::{Pallet, Call, Storage, Event} = 187, + Loans: pallet_loans_ref::{Pallet, Call, Storage, Event} = 187, } ); @@ -1786,11 +1784,9 @@ impl_runtime_apis! { } fn tranche_token_price(pool_id: PoolId, tranche: TrancheLoc) -> Option{ - let now = as UnixTime>::now().as_secs(); - let mut pool = pallet_pool_system::Pool::::get(pool_id)?; - let nav: Balance = pallet_loans::Pallet::::update_nav_of_pool(pool_id) - .ok() - .map(|(latest, _)| latest.into())?; + let now = ::now().as_secs(); + let mut pool = PoolSystem::pool(pool_id)?; + let nav = Loans::update_nav(pool_id).ok()?; let total_assets = pool.reserve.total.saturating_add(nav); let index: usize = pool.tranches.tranche_index(&tranche)?.try_into().ok()?; let prices = pool @@ -1801,11 +1797,9 @@ impl_runtime_apis! { } fn tranche_token_prices(pool_id: PoolId) -> Option>{ - let now = as UnixTime>::now().as_secs(); - let mut pool = pallet_pool_system::Pool::::get(pool_id)?; - let nav: Balance = pallet_loans::Pallet::::update_nav_of_pool(pool_id) - .ok() - .map(|(latest, _)| latest.into())?; + let now = ::now().as_secs(); + let mut pool = PoolSystem::pool(pool_id)?; + let nav = Loans::update_nav(pool_id).ok()?; let total_assets = pool.reserve.total.saturating_add(nav); pool .tranches @@ -1840,7 +1834,6 @@ impl_runtime_apis! { use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; use frame_support::traits::StorageInfoTrait; use frame_system_benchmarking::Pallet as SystemBench; - use pallet_loans::benchmarking::Pallet as LoansPallet; let mut list = Vec::::new(); @@ -1869,9 +1862,8 @@ impl_runtime_apis! { list_benchmark!(list, extra, pallet_interest_accrual, InterestAccrual); list_benchmark!(list, extra, pallet_uniques, Uniques); list_benchmark!(list, extra, pallet_keystore, Keystore); - list_benchmark!(list, extra, pallet_loans, LoansPallet::); list_benchmark!(list, extra, pallet_restricted_tokens, Tokens); - + list_benchmark!(list, extra, pallet_loans_ref, Loans); let storage_info = AllPalletsWithSystem::storage_info(); @@ -1903,11 +1895,6 @@ impl_runtime_apis! { let mut batches = Vec::::new(); let params = (&config, &whitelist); - use pallet_loans::benchmarking::Pallet as LoansPallet; - impl pallet_loans::benchmarking::Config for Runtime { - type IM = Investments; - } - // It should be called Anchors to make the runtime_benchmarks.sh script works type Anchors = Anchor; @@ -1936,8 +1923,8 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_interest_accrual, InterestAccrual); add_benchmark!(params, batches, pallet_uniques, Uniques); add_benchmark!(params, batches, pallet_keystore, Keystore); - add_benchmark!(params, batches, pallet_loans, LoansPallet::); add_benchmark!(params, batches, pallet_restricted_tokens, Tokens); + add_benchmark!(params, batches, pallet_loans_ref, Loans); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/centrifuge/src/weights/mod.rs b/runtime/centrifuge/src/weights/mod.rs index 08f0d6a480..e6b17318d3 100644 --- a/runtime/centrifuge/src/weights/mod.rs +++ b/runtime/centrifuge/src/weights/mod.rs @@ -21,7 +21,7 @@ pub mod pallet_fees; pub mod pallet_identity; pub mod pallet_interest_accrual; pub mod pallet_keystore; -pub mod pallet_loans; +pub mod pallet_loans_ref; pub mod pallet_migration_manager; pub mod pallet_multisig; pub mod pallet_permissions; diff --git a/runtime/development/src/weights/pallet_loans_ref.rs b/runtime/centrifuge/src/weights/pallet_loans_ref.rs similarity index 94% rename from runtime/development/src/weights/pallet_loans_ref.rs rename to runtime/centrifuge/src/weights/pallet_loans_ref.rs index 565551d44f..062bc5c194 100644 --- a/runtime/development/src/weights/pallet_loans_ref.rs +++ b/runtime/centrifuge/src/weights/pallet_loans_ref.rs @@ -4,7 +4,7 @@ //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev //! DATE: 2023-03-09, STEPS: `2`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `MBP-de-Luis.home`, CPU: `` -//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("development"), DB CACHE: 1024 +//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("centrifuge"), DB CACHE: 1024 // Executed Command: // target/release/centrifuge-chain @@ -12,9 +12,9 @@ // pallet // --pallet=pallet-loans // --chain -// development +// centrifuge // --extrinsic=* -// --output=runtime/development/src/weights/pallet_loans_ref.rs +// --output=runtime/centrifuge/src/weights/pallet_loans_ref.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)]