diff --git a/lana/app/src/accounting_init/mod.rs b/lana/app/src/accounting_init/mod.rs index 942b641756..648b240423 100644 --- a/lana/app/src/accounting_init/mod.rs +++ b/lana/app/src/accounting_init/mod.rs @@ -11,7 +11,8 @@ use crate::chart_of_accounts::ChartOfAccounts; use cala_ledger::CalaLedger; use error::*; -use primitives::*; +pub use primitives::CreditFacilitiesAccountPaths; +use primitives::{ChartIds, DepositsAccountPaths, LedgerJournalId}; #[derive(Clone)] pub struct JournalInit { diff --git a/lana/app/src/app/mod.rs b/lana/app/src/app/mod.rs index d410a52ea7..533320190e 100644 --- a/lana/app/src/app/mod.rs +++ b/lana/app/src/app/mod.rs @@ -12,7 +12,7 @@ use crate::{ audit::{Audit, AuditCursor, AuditEntry}, authorization::{init as init_authz, AppAction, AppObject, AuditAction, Authorization}, chart_of_accounts::ChartOfAccounts, - credit_facility::CreditFacilities, + credit_facility::{CreditFacilities, CreditFacilityAccountFactories}, customer::Customers, dashboard::Dashboard, deposit::Deposits, @@ -96,18 +96,8 @@ impl LanaApp { let customers = Customers::new(&pool, &config.customer, &deposits, &authz); let applicants = Applicants::new(&pool, &config.sumsub, &customers, &jobs); - let collateral_factory = - chart_of_accounts.transaction_account_factory(charts_init.credit_facilities.collateral); - let facility_factory = - chart_of_accounts.transaction_account_factory(charts_init.credit_facilities.facility); - let disbursed_receivable_factory = chart_of_accounts - .transaction_account_factory(charts_init.credit_facilities.disbursed_receivable); - let interest_receivable_factory = chart_of_accounts - .transaction_account_factory(charts_init.credit_facilities.interest_receivable); - let interest_income_factory = chart_of_accounts - .transaction_account_factory(charts_init.credit_facilities.interest_income); - let fee_income_factory = - chart_of_accounts.transaction_account_factory(charts_init.credit_facilities.fee_income); + let credit_account_factories = + CreditFacilityAccountFactories::new(&chart_of_accounts, charts_init.credit_facilities); let credit_facilities = CreditFacilities::init( &pool, config.credit_facility, @@ -117,12 +107,7 @@ impl LanaApp { &deposits, &price, &outbox, - collateral_factory, - facility_factory, - disbursed_receivable_factory, - interest_receivable_factory, - interest_income_factory, - fee_income_factory, + credit_account_factories, &cala, journal_init.journal_id, ) diff --git a/lana/app/src/credit_facility/ledger/credit_facility_accounts.rs b/lana/app/src/credit_facility/ledger/credit_facility_accounts.rs index 12010cc744..36d1c07272 100644 --- a/lana/app/src/credit_facility/ledger/credit_facility_accounts.rs +++ b/lana/app/src/credit_facility/ledger/credit_facility_accounts.rs @@ -5,6 +5,8 @@ use cala_ledger::AccountId as LedgerAccountId; use chart_of_accounts::TransactionAccountFactory; use crate::{ + accounting_init::CreditFacilitiesAccountPaths, + chart_of_accounts::ChartOfAccounts, primitives::{LedgerTxId, Satoshis, UsdCents}, terms::InterestPeriod, }; @@ -35,34 +37,32 @@ impl CreditFacilityAccountIds { #[derive(Clone)] pub struct CreditFacilityAccountFactories { - pub facility_factory: TransactionAccountFactory, - pub disbursed_receivable_factory: TransactionAccountFactory, - pub collateral_factory: TransactionAccountFactory, - pub interest_receivable_factory: TransactionAccountFactory, - pub interest_income_factory: TransactionAccountFactory, - pub fee_income_factory: TransactionAccountFactory, + pub facility: TransactionAccountFactory, + pub disbursed_receivable: TransactionAccountFactory, + pub collateral: TransactionAccountFactory, + pub interest_receivable: TransactionAccountFactory, + pub interest_income: TransactionAccountFactory, + pub fee_income: TransactionAccountFactory, } impl CreditFacilityAccountFactories { pub fn new( - facility_factory: TransactionAccountFactory, - disbursed_receivable_factory: TransactionAccountFactory, - collateral_factory: TransactionAccountFactory, - interest_receivable_factory: TransactionAccountFactory, - interest_income_factory: TransactionAccountFactory, - fee_income_factory: TransactionAccountFactory, + chart_of_accounts: &ChartOfAccounts, + credit_facilities: CreditFacilitiesAccountPaths, ) -> Self { Self { - facility_factory, - disbursed_receivable_factory, - collateral_factory, - interest_receivable_factory, - interest_income_factory, - fee_income_factory, + facility: chart_of_accounts.transaction_account_factory(credit_facilities.facility), + disbursed_receivable: chart_of_accounts + .transaction_account_factory(credit_facilities.disbursed_receivable), + collateral: chart_of_accounts.transaction_account_factory(credit_facilities.collateral), + interest_receivable: chart_of_accounts + .transaction_account_factory(credit_facilities.interest_receivable), + interest_income: chart_of_accounts + .transaction_account_factory(credit_facilities.interest_income), + fee_income: chart_of_accounts.transaction_account_factory(credit_facilities.fee_income), } } } - #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct CreditFacilityLedgerBalance { pub facility: UsdCents, diff --git a/lana/app/src/credit_facility/ledger/mod.rs b/lana/app/src/credit_facility/ledger/mod.rs index bbc64c4006..1ee69d1460 100644 --- a/lana/app/src/credit_facility/ledger/mod.rs +++ b/lana/app/src/credit_facility/ledger/mod.rs @@ -538,7 +538,7 @@ impl CreditLedger { credit_facility_id ); self.account_factories - .collateral_factory + .collateral .create_transaction_account_in_op( &mut op, account_ids.collateral_account_id, @@ -552,7 +552,7 @@ impl CreditLedger { credit_facility_id ); self.account_factories - .facility_factory + .facility .create_transaction_account_in_op( &mut op, account_ids.facility_account_id, @@ -566,7 +566,7 @@ impl CreditLedger { credit_facility_id ); self.account_factories - .disbursed_receivable_factory + .disbursed_receivable .create_transaction_account_in_op( &mut op, account_ids.disbursed_receivable_account_id, @@ -580,7 +580,7 @@ impl CreditLedger { credit_facility_id ); self.account_factories - .interest_receivable_factory + .interest_receivable .create_transaction_account_in_op( &mut op, account_ids.interest_receivable_account_id, @@ -594,7 +594,7 @@ impl CreditLedger { credit_facility_id ); self.account_factories - .interest_income_factory + .interest_income .create_transaction_account_in_op( &mut op, account_ids.interest_account_id, @@ -608,7 +608,7 @@ impl CreditLedger { credit_facility_id ); self.account_factories - .fee_income_factory + .fee_income .create_transaction_account_in_op( &mut op, account_ids.fee_income_account_id, diff --git a/lana/app/src/credit_facility/mod.rs b/lana/app/src/credit_facility/mod.rs index bcc09d8dc9..24bc3fddc9 100644 --- a/lana/app/src/credit_facility/mod.rs +++ b/lana/app/src/credit_facility/mod.rs @@ -12,8 +12,6 @@ mod repo; use std::collections::HashMap; -use chart_of_accounts::TransactionAccountFactory; - use authz::PermissionCheck; use cala_ledger::CalaLedger; use deposit::{DepositAccount, DepositAccountHolderId}; @@ -41,7 +39,7 @@ use error::*; pub use history::*; pub use interest_accrual::*; use jobs::*; -use ledger::*; +pub use ledger::*; use processes::activate_credit_facility::*; pub use processes::approve_credit_facility::*; pub use processes::approve_disbursal::*; @@ -78,31 +76,14 @@ impl CreditFacilities { deposits: &Deposits, price: &Price, outbox: &Outbox, - collateral_factory: TransactionAccountFactory, - facility_factory: TransactionAccountFactory, - disbursed_receivable_factory: TransactionAccountFactory, - interest_receivable_factory: TransactionAccountFactory, - interest_income_factory: TransactionAccountFactory, - fee_income_factory: TransactionAccountFactory, + account_factories: CreditFacilityAccountFactories, cala: &CalaLedger, journal_id: cala_ledger::JournalId, ) -> Result { let publisher = CreditFacilityPublisher::new(outbox); let credit_facility_repo = CreditFacilityRepo::new(pool, &publisher); let disbursal_repo = DisbursalRepo::new(pool); - let ledger = CreditLedger::init( - cala, - journal_id, - CreditFacilityAccountFactories::new( - facility_factory, - disbursed_receivable_factory, - collateral_factory, - interest_receivable_factory, - interest_income_factory, - fee_income_factory, - ), - ) - .await?; + let ledger = CreditLedger::init(cala, journal_id, account_factories).await?; let approve_disbursal = ApproveDisbursal::new( &disbursal_repo, &credit_facility_repo,