-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into loans/integration-tests
- Loading branch information
Showing
28 changed files
with
1,172 additions
and
388 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use cfg_primitives::Moment; | ||
use cfg_traits::interest::InterestRate; | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use frame_support::{storage::bounded_vec::BoundedVec, RuntimeDebug}; | ||
use scale_info::TypeInfo; | ||
|
||
use crate::{ | ||
entities::input::{PrincipalInput, RepaidInput}, | ||
pallet::Config, | ||
types::{ | ||
policy::WriteOffRule, valuation::ValuationMethod, InterestPayments, Maturity, | ||
PayDownSchedule, | ||
}, | ||
}; | ||
|
||
/// Active loan mutation for internal pricing | ||
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, RuntimeDebug, MaxEncodedLen)] | ||
pub enum InternalMutation<Rate> { | ||
ValuationMethod(ValuationMethod<Rate>), | ||
ProbabilityOfDefault(Rate), | ||
LossGivenDefault(Rate), | ||
DiscountRate(InterestRate<Rate>), | ||
} | ||
|
||
/// Active loan mutation | ||
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, RuntimeDebug, MaxEncodedLen)] | ||
pub enum LoanMutation<Rate> { | ||
Maturity(Maturity), | ||
MaturityExtension(Moment), | ||
InterestRate(InterestRate<Rate>), | ||
InterestPayments(InterestPayments), | ||
PayDownSchedule(PayDownSchedule), | ||
Internal(InternalMutation<Rate>), | ||
} | ||
|
||
/// Change description | ||
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, RuntimeDebug, MaxEncodedLen)] | ||
#[scale_info(skip_type_params(T))] | ||
pub enum Change<T: Config> { | ||
Loan(T::LoanId, LoanMutation<T::Rate>), | ||
Policy(BoundedVec<WriteOffRule<T::Rate>, T::MaxWriteOffPolicySize>), | ||
TransferDebt(T::LoanId, T::LoanId, RepaidInput<T>, PrincipalInput<T>), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use frame_support::RuntimeDebugNoBound; | ||
use scale_info::TypeInfo; | ||
use sp_runtime::{ArithmeticError, DispatchError}; | ||
|
||
use crate::{ | ||
entities::pricing::external::ExternalAmount, | ||
pallet::{Config, Error}, | ||
types::RepaidAmount, | ||
}; | ||
|
||
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, RuntimeDebugNoBound, MaxEncodedLen)] | ||
#[scale_info(skip_type_params(T))] | ||
pub enum PrincipalInput<T: Config> { | ||
Internal(T::Balance), | ||
External(ExternalAmount<T>), | ||
} | ||
|
||
impl<T: Config> PrincipalInput<T> { | ||
pub fn balance(&self) -> Result<T::Balance, ArithmeticError> { | ||
match self { | ||
Self::Internal(amount) => Ok(*amount), | ||
Self::External(external) => external.balance(), | ||
} | ||
} | ||
|
||
pub fn internal(&self) -> Result<T::Balance, DispatchError> { | ||
match self { | ||
Self::Internal(amount) => Ok(*amount), | ||
Self::External(_) => Err(Error::<T>::MismatchedPricingMethod.into()), | ||
} | ||
} | ||
|
||
pub fn external(&self) -> Result<ExternalAmount<T>, DispatchError> { | ||
match self { | ||
Self::Internal(_) => Err(Error::<T>::MismatchedPricingMethod.into()), | ||
Self::External(principal) => Ok(principal.clone()), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, RuntimeDebugNoBound, MaxEncodedLen)] | ||
#[scale_info(skip_type_params(T))] | ||
pub struct RepaidInput<T: Config> { | ||
pub principal: PrincipalInput<T>, | ||
pub interest: T::Balance, | ||
pub unscheduled: T::Balance, | ||
} | ||
|
||
impl<T: Config> RepaidInput<T> { | ||
pub fn repaid_amount(&self) -> Result<RepaidAmount<T::Balance>, ArithmeticError> { | ||
Ok(RepaidAmount { | ||
principal: self.principal.balance()?, | ||
interest: self.interest, | ||
unscheduled: self.unscheduled, | ||
}) | ||
} | ||
} |
Oops, something went wrong.