From 75e88b5c8cc802b5870a0a5d1c95cd46fd239cda Mon Sep 17 00:00:00 2001 From: lemunozm Date: Wed, 27 Sep 2023 09:00:09 +0200 Subject: [PATCH 1/3] remove extra where bounds --- pallets/investments/src/benchmarking.rs | 8 +--- pallets/investments/src/lib.rs | 63 +++++++------------------ pallets/investments/src/mock.rs | 1 + 3 files changed, 19 insertions(+), 53 deletions(-) diff --git a/pallets/investments/src/benchmarking.rs b/pallets/investments/src/benchmarking.rs index aaf4ac8bc6..b69f90e9ca 100644 --- a/pallets/investments/src/benchmarking.rs +++ b/pallets/investments/src/benchmarking.rs @@ -26,8 +26,6 @@ use crate::{Call, Config, CurrencyOf, Pallet}; struct Helper(sp_std::marker::PhantomData); impl Helper where - >::InvestmentInfo: - InvestmentProperties>, T::Accountant: PoolBenchmarkHelper + InvestmentIdBenchmarkHelper< InvestmentId = T::InvestmentId, @@ -46,8 +44,6 @@ where #[benchmarks( where - >::InvestmentInfo: - InvestmentProperties>, T::Accountant: PoolBenchmarkHelper + InvestmentIdBenchmarkHelper< InvestmentId = T::InvestmentId, @@ -74,7 +70,7 @@ mod benchmarks { fn update_redeem_order() { let caller: T::AccountId = whitelisted_caller(); let investment_id = Helper::::get_investment_id(); - let currency_id: CurrencyOf = T::Accountant::info(investment_id)?.id().into(); + let currency_id: CurrencyOf = investment_id.into(); T::Tokens::mint_into(currency_id, &caller, 1u32.into())?; @@ -112,7 +108,7 @@ mod benchmarks { fn collect_redemptions(n: Linear<1, 10>) { let caller: T::AccountId = whitelisted_caller(); let investment_id = Helper::::get_investment_id(); - let currency_id: CurrencyOf = T::Accountant::info(investment_id)?.id().into(); + let currency_id: CurrencyOf = investment_id.into(); T::Tokens::mint_into(currency_id, &caller, 1u32.into())?; diff --git a/pallets/investments/src/lib.rs b/pallets/investments/src/lib.rs index 647ed43c63..af1f95fa15 100644 --- a/pallets/investments/src/lib.rs +++ b/pallets/investments/src/lib.rs @@ -117,11 +117,7 @@ pub mod pallet { /// Configure the pallet by specifying the parameters and types on which it /// depends. #[pallet::config] - pub trait Config: frame_system::Config - where - >::InvestmentInfo: - InvestmentProperties>, - { + pub trait Config: frame_system::Config { /// Because this pallet emits events, it depends on the runtime's /// definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -129,6 +125,13 @@ pub mod pallet { /// The underlying investments one can invest into type InvestmentId: Member + Parameter + Copy + MaxEncodedLen + Into>; + /// Properties used for the Accountant type + type InvestmentInfo: InvestmentProperties< + Self::AccountId, + Id = Self::InvestmentId, + Currency = CurrencyOf, + >; + /// Something that knows how to handle accounting for the given /// investments and provides metadata about them type Accountant: InvestmentAccountant< @@ -136,6 +139,7 @@ pub mod pallet { Error = DispatchError, InvestmentId = Self::InvestmentId, Amount = Self::Amount, + InvestmentInfo = Self::InvestmentInfo, >; /// A representation for an investment or redemption. Usually this @@ -208,13 +212,6 @@ pub mod pallet { #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); - #[pallet::hooks] - impl Hooks> for Pallet where - >::InvestmentInfo: - InvestmentProperties> - { - } - #[pallet::storage] #[pallet::getter(fn invest_order_id)] pub(crate) type InvestOrderId = @@ -289,11 +286,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub (super) fn deposit_event)] - pub enum Event - where - >::InvestmentInfo: - InvestmentProperties>, - { + pub enum Event { /// Fulfilled orders were collected. /// [investment_id, who, collected_orders, Collection, CollectOutcome] InvestOrdersCollected { @@ -412,11 +405,7 @@ pub mod pallet { } #[pallet::call] - impl Pallet - where - >::InvestmentInfo: - InvestmentProperties>, - { + impl Pallet { /// Update an order to invest into a given investment. /// /// If the requested amount is greater than the current @@ -517,11 +506,7 @@ pub mod pallet { } } -impl Pallet -where - >::InvestmentInfo: - InvestmentProperties>, -{ +impl Pallet { pub(crate) fn do_update_investment( who: T::AccountId, investment_id: T::InvestmentId, @@ -1124,11 +1109,7 @@ where } } -impl InvestmentsPortfolio for Pallet -where - >::InvestmentInfo: - InvestmentProperties>, -{ +impl InvestmentsPortfolio for Pallet { type AccountInvestmentPortfolio = AccountInvestmentPortfolioOf; type Balance = T::Amount; type CurrencyId = CurrencyOf; @@ -1159,11 +1140,7 @@ where Ok(investments_currency) } } -impl Investment for Pallet -where - >::InvestmentInfo: - InvestmentProperties>, -{ +impl Investment for Pallet { type Amount = T::Amount; type CurrencyId = CurrencyOf; type Error = DispatchError; @@ -1244,11 +1221,7 @@ where } } -impl OrderManager for Pallet -where - >::InvestmentInfo: - InvestmentProperties>, -{ +impl OrderManager for Pallet { type Error = DispatchError; type Fulfillment = FulfillmentWithPrice; type InvestmentId = T::InvestmentId; @@ -1524,11 +1497,7 @@ where } } -impl InvestmentCollector for Pallet -where - >::InvestmentInfo: - InvestmentProperties>, -{ +impl InvestmentCollector for Pallet { type Error = DispatchError; type InvestmentId = T::InvestmentId; type Result = (); diff --git a/pallets/investments/src/mock.rs b/pallets/investments/src/mock.rs index 4c40d7bd92..f85296d0fc 100644 --- a/pallets/investments/src/mock.rs +++ b/pallets/investments/src/mock.rs @@ -162,6 +162,7 @@ impl pallet_investments::Config for MockRuntime { type CollectedInvestmentHook = NoopCollectHook; type CollectedRedemptionHook = NoopCollectHook; type InvestmentId = InvestmentId; + type InvestmentInfo = accountant_mock::InvestmentInfo; type MaxOutstandingCollects = MaxOutstandingCollect; type PreConditions = Always; type RuntimeEvent = RuntimeEvent; From ded9971963ef94b77f15f15da48ef86fbfe96bd6 Mon Sep 17 00:00:00 2001 From: lemunozm Date: Wed, 27 Sep 2023 09:00:31 +0200 Subject: [PATCH 2/3] use concrete InvestmentInfo --- libs/test-utils/src/mocks/accountant.rs | 52 ++++++----------------- pallets/investments/src/lib.rs | 56 ++++++++++--------------- pallets/investments/src/mock.rs | 10 ++--- 3 files changed, 38 insertions(+), 80 deletions(-) diff --git a/libs/test-utils/src/mocks/accountant.rs b/libs/test-utils/src/mocks/accountant.rs index 26d2cfdabf..759b7d22f5 100644 --- a/libs/test-utils/src/mocks/accountant.rs +++ b/libs/test-utils/src/mocks/accountant.rs @@ -12,12 +12,7 @@ /// Exposes a struct $name that implements the `trait Accountant`. The struct /// expects one generic parameter that implements the fungibles traits -/// `Inspect`, `Mutate` and `Transfer`. Furthermore, there exists a struct -/// `GenesisConfig` that implements `trait GenesisBuild` that can be used -/// like any other `GenesisConfig` to initialize state in the -/// `TestExternalities`. -/// -/// Also exports a `struct InvestmentInfo` to be used in the `GenesisConfig` +/// `Inspect`, `Mutate` and `Transfer`. /// /// * E.g.: `MockAccountant` @@ -54,7 +49,7 @@ /// /// // Using the `GenesisConfig` /// use accountant_mock::InvestmentInfo; -/// let storage = GenesisBuild::build_storage(&accountant_mock::GenesisConfig { +/// let storage = GenesisBuild::init(&accountant_mock::Genesis { /// infos: vec![ /// ( /// InvestmentId::Tranche(0, [0;16]), @@ -79,32 +74,28 @@ macro_rules! impl_mock_accountant { use super::*; - #[derive(Default, serde::Serialize, serde::Deserialize)] - pub struct GenesisConfig { + pub type InvestmentInfo = + cfg_types::investments::InvestmentInfo<$account_id, $currency_id, $investment_id>; + + #[derive(Default)] + pub struct Genesis { pub infos: Vec<($investment_id, InvestmentInfo)>, } - impl frame_support::traits::GenesisBuild<()> for GenesisConfig { - fn build(&self) { + pub struct $name(sp_std::marker::PhantomData); + + impl $name { + pub fn init(genesis: Genesis) { __private_STATE.with(|s| { let mut state = s.borrow_mut(); - for (id, info) in &self.infos { + for (id, info) in &genesis.infos { state.add(id.clone(), info.clone()) } }) } } - pub struct $name(sp_std::marker::PhantomData); - - #[derive(Clone, serde::Serialize, serde::Deserialize)] - pub struct InvestmentInfo { - pub owner: $account_id, - pub id: $investment_id, - pub payment_currency: $currency_id, - } - impl cfg_traits::investments::InvestmentAccountant<$account_id> for $name where Tokens: frame_support::traits::tokens::fungibles::Mutate<$account_id> @@ -187,23 +178,6 @@ macro_rules! impl_mock_accountant { } } - impl cfg_traits::investments::InvestmentProperties<$account_id> for InvestmentInfo { - type Currency = $currency_id; - type Id = $investment_id; - - fn owner(&self) -> $account_id { - self.owner - } - - fn id(&self) -> Self::Id { - self.id - } - - fn payment_currency(&self) -> Self::Currency { - self.payment_currency - } - } - mod __private { use super::*; @@ -235,7 +209,7 @@ macro_rules! impl_mock_accountant { pub fn add(&mut self, investment_id: $investment_id, info: InvestmentInfo) { // NOTE: We deliberately update the info here as add() is only called - // upon GenesisConfig.build(). We assume, if we are running in the + // upon init(). We assume, if we are running in the // same thread this means a new initialization is wanted. for (curr_id, curr_info) in &mut self.infos { if *curr_id == investment_id { diff --git a/pallets/investments/src/lib.rs b/pallets/investments/src/lib.rs index af1f95fa15..40e02d5971 100644 --- a/pallets/investments/src/lib.rs +++ b/pallets/investments/src/lib.rs @@ -16,8 +16,7 @@ use cfg_primitives::OrderId; use cfg_traits::{ investments::{ - Investment, InvestmentAccountant, InvestmentCollector, InvestmentProperties, - InvestmentsPortfolio, OrderManager, + Investment, InvestmentAccountant, InvestmentCollector, InvestmentsPortfolio, OrderManager, }, PreConditions, StatusNotificationHook, }; @@ -109,7 +108,7 @@ pub enum CollectType { #[frame_support::pallet] pub mod pallet { - use cfg_types::investments::ForeignInvestmentInfo; + use cfg_types::investments::{ForeignInvestmentInfo, InvestmentInfo}; use sp_runtime::{traits::AtLeast32BitUnsigned, FixedPointNumber, FixedPointOperand}; use super::*; @@ -125,13 +124,6 @@ pub mod pallet { /// The underlying investments one can invest into type InvestmentId: Member + Parameter + Copy + MaxEncodedLen + Into>; - /// Properties used for the Accountant type - type InvestmentInfo: InvestmentProperties< - Self::AccountId, - Id = Self::InvestmentId, - Currency = CurrencyOf, - >; - /// Something that knows how to handle accounting for the given /// investments and provides metadata about them type Accountant: InvestmentAccountant< @@ -139,7 +131,7 @@ pub mod pallet { Error = DispatchError, InvestmentId = Self::InvestmentId, Amount = Self::Amount, - InvestmentInfo = Self::InvestmentInfo, + InvestmentInfo = InvestmentInfo, Self::InvestmentId>, >; /// A representation for an investment or redemption. Usually this @@ -541,7 +533,7 @@ impl Pallet { total_order, &who, investment_id, - info, + info.payment_currency, order, amount, )?; @@ -580,7 +572,7 @@ impl Pallet { amount, })?; - let info = T::Accountant::info(investment_id).map_err(|_| Error::::UnknownInvestment)?; + let _ = T::Accountant::info(investment_id).map_err(|_| Error::::UnknownInvestment)?; let cur_order_id = ActiveRedeemOrders::::try_mutate( investment_id, |total_order| -> Result { @@ -603,7 +595,6 @@ impl Pallet { total_order, &who, investment_id, - info, order, amount, )?; @@ -647,7 +638,7 @@ impl Pallet { who: T::AccountId, investment_id: T::InvestmentId, ) -> DispatchResultWithPostInfo { - let info = T::Accountant::info(investment_id).map_err(|_| Error::::UnknownInvestment)?; + let _ = T::Accountant::info(investment_id).map_err(|_| Error::::UnknownInvestment)?; let (collected_investment, post_dispatch_info) = InvestOrders::::try_mutate( &who, investment_id, @@ -663,8 +654,7 @@ impl Pallet { who: who.clone(), investment_id, }); - // TODO: Return correct weight - // - Accountant::info() + Storage::read() + Storage::write() + // TODO: Return correct weight + Storage::read() + Storage::write() return Ok((Default::default(), ().into())); }; @@ -684,8 +674,7 @@ impl Pallet { who: who.clone(), investment_id, }); - // TODO: Return correct weight - // - Accountant::info() + 2 * Storage::read() + Storage::write() + // TODO: Return correct weight 2 * Storage::read() + Storage::write() return Ok((Default::default(), ().into())); } @@ -713,7 +702,7 @@ impl Pallet { ); T::Accountant::transfer( - info.id(), + investment_id, &InvestmentAccount { investment_id }.into_account_truncating(), &who, collection.payout_investment_invest, @@ -847,7 +836,7 @@ impl Pallet { let investment_account = InvestmentAccount { investment_id }.into_account_truncating(); T::Tokens::transfer( - info.payment_currency(), + info.payment_currency, &investment_account, &who, collection.payout_investment_redeem, @@ -907,7 +896,7 @@ impl Pallet { total_order: &mut TotalOrder, who: &T::AccountId, investment_id: T::InvestmentId, - info: impl InvestmentProperties, Id = T::InvestmentId>, + payment_currency: CurrencyOf, order: &mut OrderOf, amount: T::Amount, ) -> DispatchResult { @@ -920,14 +909,13 @@ impl Pallet { &mut total_order.amount, )?; - T::Tokens::transfer(info.payment_currency(), send, recv, transfer_amount, false).map(|_| ()) + T::Tokens::transfer(payment_currency, send, recv, transfer_amount, false).map(|_| ()) } pub(crate) fn do_update_redeem_order( total_order: &mut TotalOrder, who: &T::AccountId, investment_id: T::InvestmentId, - info: impl InvestmentProperties, Id = T::InvestmentId>, order: &mut OrderOf, amount: T::Amount, ) -> DispatchResult { @@ -940,7 +928,7 @@ impl Pallet { &mut total_order.amount, )?; - T::Accountant::transfer(info.id(), send, recv, transfer_amount) + T::Accountant::transfer(investment_id, send, recv, transfer_amount) } #[allow(clippy::type_complexity)] @@ -1121,7 +1109,7 @@ impl InvestmentsPortfolio for Pallet { investment_id: T::InvestmentId, ) -> Result, DispatchError> { let info = T::Accountant::info(investment_id).map_err(|_| Error::::UnknownInvestment)?; - Ok(info.payment_currency()) + Ok(info.payment_currency) } /// Get the investments and associated payment currencies and balances for @@ -1159,7 +1147,7 @@ impl Investment for 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) } @@ -1184,7 +1172,7 @@ impl Investment for 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) } @@ -1354,9 +1342,9 @@ impl OrderManager for Pallet { let info = T::Accountant::info(investment_id)?; T::Tokens::transfer( - info.payment_currency(), + info.payment_currency, &investment_account, - &info.payment_account(), + &info.owner, invest_amount, false, )?; @@ -1371,7 +1359,7 @@ impl OrderManager for Pallet { .checked_mul_int(invest_amount) .ok_or(ArithmeticError::Overflow)?; - T::Accountant::deposit(&investment_account, info.id(), amount_of_investment_units)?; + T::Accountant::deposit(&investment_account, info.id, amount_of_investment_units)?; // The previous OrderId is always 1 away // @@ -1446,14 +1434,14 @@ impl OrderManager for Pallet { let info = T::Accountant::info(investment_id)?; T::Tokens::transfer( - info.payment_currency(), - &info.payment_account(), + info.payment_currency, + &info.owner, &investment_account, redeem_amount_payment, false, )?; - T::Accountant::withdraw(&investment_account, info.id(), redeem_amount)?; + T::Accountant::withdraw(&investment_account, info.id, redeem_amount)?; // The previous OrderId is always 1 away // diff --git a/pallets/investments/src/mock.rs b/pallets/investments/src/mock.rs index f85296d0fc..d6ce6255d8 100644 --- a/pallets/investments/src/mock.rs +++ b/pallets/investments/src/mock.rs @@ -18,7 +18,7 @@ use cfg_primitives::*; use cfg_traits::{investments::OrderManager, PreConditions}; use cfg_types::{ fixed_point::Rate, - investments::InvestmentAccount, + investments::{InvestmentAccount, InvestmentInfo}, orders::{FulfillmentWithPrice, TotalOrder}, tokens::CurrencyId, }; @@ -162,7 +162,6 @@ impl pallet_investments::Config for MockRuntime { type CollectedInvestmentHook = NoopCollectHook; type CollectedRedemptionHook = NoopCollectHook; type InvestmentId = InvestmentId; - type InvestmentInfo = accountant_mock::InvestmentInfo; type MaxOutstandingCollects = MaxOutstandingCollect; type PreConditions = Always; type RuntimeEvent = RuntimeEvent; @@ -295,8 +294,7 @@ impl TestExternalitiesBuilder { .assimilate_storage(&mut storage) .unwrap(); - use accountant_mock::InvestmentInfo; - accountant_mock::GenesisConfig { + MockAccountant::::init(accountant_mock::Genesis { infos: vec![ ( INVESTMENT_0_0, @@ -315,9 +313,7 @@ impl TestExternalitiesBuilder { }, ), ], - } - .assimilate_storage(&mut storage) - .unwrap(); + }); let mut externalities = TestExternalities::new(storage); externalities.execute_with(|| { From bf1224fbec054cd68de23cb8f628f51cc618fcd0 Mon Sep 17 00:00:00 2001 From: lemunozm Date: Wed, 27 Sep 2023 09:35:17 +0200 Subject: [PATCH 3/3] 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>,