From 2392851bd0c34ec1e65d9b42e56694f05d7dd823 Mon Sep 17 00:00:00 2001 From: lemunozm Date: Wed, 27 Sep 2023 09:35:17 +0200 Subject: [PATCH] remove InvestmentProperties trait --- libs/test-utils/src/mocks/order_manager.rs | 40 ++++++----------- libs/traits/src/investments.rs | 51 +--------------------- libs/types/src/investments.rs | 24 ---------- pallets/investments/src/benchmarking.rs | 8 ++-- pallets/pool-registry/src/benchmarking.rs | 4 +- pallets/pool-system/src/benchmarking.rs | 7 +-- 6 files changed, 19 insertions(+), 115 deletions(-) diff --git a/libs/test-utils/src/mocks/order_manager.rs b/libs/test-utils/src/mocks/order_manager.rs index 7d8c41c0c1..cd3325357f 100644 --- a/libs/test-utils/src/mocks/order_manager.rs +++ b/libs/test-utils/src/mocks/order_manager.rs @@ -15,9 +15,12 @@ pub use pallet::*; #[frame_support::pallet] pub mod pallet { use cfg_traits::investments::{ - Investment, InvestmentAccountant, InvestmentProperties, OrderManager, TrancheCurrency, + Investment, InvestmentAccountant, OrderManager, TrancheCurrency, + }; + use cfg_types::{ + investments::InvestmentInfo, + orders::{FulfillmentWithPrice, TotalOrder}, }; - use cfg_types::orders::{FulfillmentWithPrice, TotalOrder}; use frame_support::{ pallet_prelude::*, traits::fungibles::{Inspect, Mutate, Transfer}, @@ -48,8 +51,6 @@ pub mod pallet { From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { type FundsAccount: Get; @@ -58,6 +59,7 @@ pub mod pallet { Amount = BalanceOf, Error = DispatchError, InvestmentId = Self::InvestmentId, + InvestmentInfo = InvestmentInfo, Self::InvestmentId>, >; type PoolId: Member + Parameter + Default + Copy + MaxEncodedLen; @@ -87,8 +89,6 @@ pub mod pallet { >::Balance: From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { pub invest_orders: Vec<(T::InvestmentId, BalanceOf)>, pub redeem_orders: Vec<(T::InvestmentId, BalanceOf)>, @@ -100,8 +100,6 @@ pub mod pallet { >::Balance: From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { fn default() -> Self { Self { @@ -117,8 +115,6 @@ pub mod pallet { >::Balance: From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { fn build(&self) { for (id, amount) in &self.invest_orders { @@ -144,8 +140,6 @@ pub mod pallet { >::Balance: From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { // TODO: Remove once we are on Substrate:polkadot-v0.9.29 } @@ -155,8 +149,6 @@ pub mod pallet { >::Balance: From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { // TODO: Remove once we are on Substrate:polkadot-v0.9.29 } @@ -166,8 +158,6 @@ pub mod pallet { >::Balance: From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { /// **Test Method** /// @@ -184,7 +174,7 @@ pub mod pallet { let details = T::Accountant::info(investment_id)?; T::Tokens::transfer( - details.payment_currency(), + details.payment_currency, &T::FundsAccount::get().into_account_truncating(), &OrderManagerAccount::get::(), amount, @@ -218,8 +208,6 @@ pub mod pallet { >::Balance: From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { type Amount = BalanceOf; type CurrencyId = CurrencyOf; @@ -239,7 +227,7 @@ pub mod pallet { currency: Self::CurrencyId, ) -> bool { T::Accountant::info(investment_id) - .map(|info| info.payment_currency() == currency) + .map(|info| info.payment_currency == currency) .unwrap_or(false) } @@ -265,7 +253,7 @@ pub mod pallet { currency: Self::CurrencyId, ) -> bool { T::Accountant::info(investment_id) - .map(|info| info.payment_currency() == currency) + .map(|info| info.payment_currency == currency) .unwrap_or(false) } @@ -298,8 +286,6 @@ pub mod pallet { >::Balance: From + FixedPointOperand + MaxEncodedLen + MaybeSerializeDeserialize, >::AssetId: MaxEncodedLen + MaybeSerializeDeserialize, - >::InvestmentInfo: - InvestmentProperties>, { type Error = DispatchError; type Fulfillment = FulfillmentWithPrice; @@ -344,9 +330,9 @@ pub mod pallet { let tokens_to_transfer_to_pool = fulfillment.of_amount.mul_floor(orders.amount); let details = T::Accountant::info(asset_id)?; T::Tokens::transfer( - details.payment_currency(), + details.payment_currency, &OrderManagerAccount::get::(), - &details.payment_account(), + &details.owner, tokens_to_transfer_to_pool, true, ) @@ -410,8 +396,8 @@ pub mod pallet { .unwrap(); let details = T::Accountant::info(asset_id)?; T::Tokens::transfer( - details.payment_currency(), - &details.payment_account(), + details.payment_currency, + &details.owner, &OrderManagerAccount::get::(), payment_currency_to_move_to_order_manager, false, diff --git a/libs/traits/src/investments.rs b/libs/traits/src/investments.rs index 95cad1d49f..905966de61 100644 --- a/libs/traits/src/investments.rs +++ b/libs/traits/src/investments.rs @@ -186,7 +186,7 @@ pub trait OrderManager { pub trait InvestmentAccountant { type Error; type InvestmentId; - type InvestmentInfo: InvestmentProperties; + type InvestmentInfo; type Amount; /// Information about an asset. Must allow to derive @@ -219,55 +219,6 @@ pub trait InvestmentAccountant { ) -> Result<(), Self::Error>; } -/// A trait that allows to retrieve information -/// about an investment class. -pub trait InvestmentProperties { - /// The overarching Currency that payments - /// for this class are made in - type Currency; - /// Who the investment class can be identified - type Id; - - /// Returns the owner of the investment class - fn owner(&self) -> AccountId; - - /// Returns the id of the investment class - fn id(&self) -> Self::Id; - - /// Returns the currency in which the investment class - /// can be bought. - fn payment_currency(&self) -> Self::Currency; - - /// Returns the account a payment for the investment class - /// must be made to. - /// - /// Defaults to owner. - fn payment_account(&self) -> AccountId { - self.owner() - } -} - -impl> InvestmentProperties for &T { - type Currency = T::Currency; - type Id = T::Id; - - fn owner(&self) -> AccountId { - (*self).owner() - } - - fn id(&self) -> Self::Id { - (*self).id() - } - - fn payment_currency(&self) -> Self::Currency { - (*self).payment_currency() - } - - fn payment_account(&self) -> AccountId { - (*self).payment_account() - } -} - /// Trait to handle Investment Portfolios for accounts pub trait InvestmentsPortfolio { type InvestmentId; diff --git a/libs/types/src/investments.rs b/libs/types/src/investments.rs index 90eee5fff7..57b127d782 100644 --- a/libs/types/src/investments.rs +++ b/libs/types/src/investments.rs @@ -11,7 +11,6 @@ // GNU General Public License for more details. use cfg_primitives::OrderId; -use cfg_traits::investments::InvestmentProperties; use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{dispatch::fmt::Debug, RuntimeDebug}; use scale_info::TypeInfo; @@ -35,29 +34,6 @@ pub struct InvestmentInfo { pub payment_currency: Currency, } -impl InvestmentProperties - for InvestmentInfo -where - AccountId: Clone, - Currency: Clone, - InvestmentId: Clone, -{ - type Currency = Currency; - type Id = InvestmentId; - - fn owner(&self) -> AccountId { - self.owner.clone() - } - - fn id(&self) -> Self::Id { - self.id.clone() - } - - fn payment_currency(&self) -> Self::Currency { - self.payment_currency.clone() - } -} - /// The outstanding collections for an account #[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub struct InvestCollection { diff --git a/pallets/investments/src/benchmarking.rs b/pallets/investments/src/benchmarking.rs index b69f90e9ca..7d83b221ca 100644 --- a/pallets/investments/src/benchmarking.rs +++ b/pallets/investments/src/benchmarking.rs @@ -13,7 +13,7 @@ use cfg_traits::{ benchmarking::{InvestmentIdBenchmarkHelper, PoolBenchmarkHelper}, - investments::{Investment, InvestmentAccountant, InvestmentProperties, OrderManager}, + investments::{Investment, InvestmentAccountant, OrderManager}, }; use cfg_types::orders::FulfillmentWithPrice; use frame_benchmarking::{account, impl_benchmark_test_suite, v2::*, whitelisted_caller}; @@ -58,7 +58,7 @@ mod benchmarks { fn update_invest_order() { let caller: T::AccountId = whitelisted_caller(); let investment_id = Helper::::get_investment_id(); - let currency_id = T::Accountant::info(investment_id)?.payment_currency(); + let currency_id = T::Accountant::info(investment_id)?.payment_currency; T::Tokens::mint_into(currency_id, &caller, 1u32.into())?; @@ -82,9 +82,7 @@ mod benchmarks { fn collect_investments(n: Linear<1, 10>) { let caller: T::AccountId = whitelisted_caller(); let investment_id = Helper::::get_investment_id(); - let currency_id = T::Accountant::info(investment_id) - .unwrap() - .payment_currency(); + let currency_id = T::Accountant::info(investment_id)?.payment_currency; T::Tokens::mint_into(currency_id, &caller, 1u32.into())?; diff --git a/pallets/pool-registry/src/benchmarking.rs b/pallets/pool-registry/src/benchmarking.rs index 98d52bc558..fb7076415b 100644 --- a/pallets/pool-registry/src/benchmarking.rs +++ b/pallets/pool-registry/src/benchmarking.rs @@ -13,7 +13,7 @@ //! Module provides benchmarking for Loan Pallet use cfg_primitives::{Moment, PoolEpochId}; -use cfg_traits::investments::{InvestmentAccountant, InvestmentProperties, TrancheCurrency as _}; +use cfg_traits::investments::TrancheCurrency as _; use cfg_types::{ pools::TrancheMetadata, tokens::{CurrencyId, TrancheCurrency}, @@ -70,8 +70,6 @@ benchmarks! { MaxTranches = ::MaxTranches>, T: pallet_timestamp::Config, ::Tokens: Inspect, - <::Accountant as InvestmentAccountant>::InvestmentInfo: - InvestmentProperties, <::Lookup as sp_runtime::traits::StaticLookup>::Source: From<::AccountId>, ::Permission: Permissions, diff --git a/pallets/pool-system/src/benchmarking.rs b/pallets/pool-system/src/benchmarking.rs index b4b5f44c15..32c8037c0f 100644 --- a/pallets/pool-system/src/benchmarking.rs +++ b/pallets/pool-system/src/benchmarking.rs @@ -13,10 +13,7 @@ //! Module provides benchmarking for Loan Pallet use cfg_primitives::PoolEpochId; -use cfg_traits::{ - investments::{InvestmentAccountant, InvestmentProperties, TrancheCurrency as _}, - UpdateState, -}; +use cfg_traits::{investments::TrancheCurrency as _, UpdateState}; use cfg_types::{ pools::TrancheMetadata, tokens::{CurrencyId, CustomMetadata, TrancheCurrency}, @@ -53,8 +50,6 @@ benchmarks! { EpochId = PoolEpochId> + pallet_investments::Config, ::Tokens: Inspect, - <::Accountant as InvestmentAccountant>::InvestmentInfo: - InvestmentProperties, T::AccountId: EncodeLike<::AccountId>, <::Lookup as sp_runtime::traits::StaticLookup>::Source: From<::AccountId>,