use abax_library::structs::{
AssetRulesError, ReserveDataError, ReserveRestrictionsError,
};
use pendzl::{
contracts::{access_control::AccessControlError, psp22::PSP22Error},
math::errors::MathError,
};
use crate::{
flash_loan_receiver::FlashLoanReceiverError, price_feed::PriceFeedError,
};
use ink::prelude::format;
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum LendingPoolError {
PSP22Error(PSP22Error),
AccessControlError(AccessControlError),
MathError(MathError),
AssetRulesError(AssetRulesError),
ReserveDataError(ReserveDataError),
ReserveRestrictionsError(ReserveRestrictionsError),
PriceFeedError(PriceFeedError),
FlashLoanReceiverError(FlashLoanReceiverError),
AmountNotGreaterThanZero,
AlreadyRegistered,
AssetNotRegistered,
AssetIsProtocolStablecoin,
AssetIsNotProtocolStablecoin,
RuleBorrowDisable,
RuleCollateralDisable,
InsufficientCollateral,
InsufficientDebt,
Collaterized,
InsufficientDeposit,
MinimumRecieved,
NothingToRepay,
NothingToCompensateWith,
TakingNotACollateral,
VectorsInconsistentLengths,
MarketRuleInvalidId,
DepositFeeTooHigh,
TwEntryInvalidIndex(u8),
TooEarlyToAdjustRate,
}
impl From<AssetRulesError> for LendingPoolError {
fn from(error: AssetRulesError) -> Self {
LendingPoolError::AssetRulesError(error)
}
}
impl From<ReserveDataError> for LendingPoolError {
fn from(error: ReserveDataError) -> Self {
LendingPoolError::ReserveDataError(error)
}
}
impl From<ReserveRestrictionsError> for LendingPoolError {
fn from(error: ReserveRestrictionsError) -> Self {
LendingPoolError::ReserveRestrictionsError(error)
}
}
impl From<MathError> for LendingPoolError {
fn from(error: MathError) -> Self {
LendingPoolError::MathError(error)
}
}
impl From<PSP22Error> for LendingPoolError {
fn from(error: PSP22Error) -> Self {
LendingPoolError::PSP22Error(error)
}
}
impl From<PriceFeedError> for LendingPoolError {
fn from(error: PriceFeedError) -> Self {
LendingPoolError::PriceFeedError(error)
}
}
impl From<AccessControlError> for LendingPoolError {
fn from(error: AccessControlError) -> Self {
LendingPoolError::AccessControlError(error)
}
}
impl From<LendingPoolError> for PSP22Error {
fn from(error: LendingPoolError) -> Self {
match error {
LendingPoolError::MathError(MathError::Underflow) => {
PSP22Error::InsufficientBalance
}
e => PSP22Error::Custom(format!("{e:?}")),
}
}
}
impl From<FlashLoanReceiverError> for LendingPoolError {
fn from(flash_error: FlashLoanReceiverError) -> Self {
LendingPoolError::FlashLoanReceiverError(flash_error)
}
}
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum MultiOpError {
OperationError(u32, LendingPoolError),
}