LoanManager

Git Source

Inherits: ILoanManager, IERC721Receiver, LoanManagerStorage, ReentrancyGuard, VersionedInitializable

State Variables

LOAN_MANAGER_REVISION

uint256 public constant LOAN_MANAGER_REVISION = 0x1;

HUNDRED_PERCENT

uint256 public constant HUNDRED_PERCENT = 1e6;

SCALED_ONE

uint256 private constant SCALED_ONE = 1e18;

PRECISION

uint256 public constant PRECISION = 1e27;

ADDRESSES_PROVIDER

IPoolAddressesProvider public immutable ADDRESSES_PROVIDER;

Functions

constructor

constructor(IPoolAddressesProvider provider);

initialize

Initializes the Loan Manager.

Function is invoked by the proxy contract when the Loan Manager Contract is added to the PoolAddressesProvider of the market

function initialize(IPoolAddressesProvider provider_) external virtual initializer;

Parameters

NameTypeDescription

provider_

IPoolAddressesProvider

The address of the PoolAddressesProvider

whenNotPaused

Can only be called when the function is not paused

modifier whenNotPaused();

onlyPoolAdminOrGovernor

Can only be called by the Pool Admin or the Governor

modifier onlyPoolAdminOrGovernor();

onlyPoolAdmin

Can only be called by the Pool Admin

modifier onlyPoolAdmin();

getRevision

Returns the revision number of the contract

Needs to be defined in the inherited class as a constant.

function getRevision() internal pure virtual override returns (uint256 revision_);

Returns

NameTypeDescription

revision_

uint256

The revision number

getLoanInfo

Gets the loan info

function getLoanInfo(uint16 loanId_) external view returns (Loan.Info memory loan_);

Parameters

NameTypeDescription

loanId_

uint16

The id of the loan

Returns

NameTypeDescription

loan_

Loan.Info

Struct that contains the info of the loan

accruedInterest

Gets the amounf of interest up until this point in time

function accruedInterest() public view override returns (uint256 accruedInterest_);

Returns

NameTypeDescription

accruedInterest_

uint256

The amount of accrued interest up until this point in time

assetsUnderManagement

Gets the total assets under management

function assetsUnderManagement() public view override returns (uint256 assetsUnderManagement_);

Returns

NameTypeDescription

assetsUnderManagement_

uint256

The total assets under management

getLoanPaymentDetailedBreakdown

Gets the detailed payment breakdown of a loan up until this point in time

function getLoanPaymentDetailedBreakdown(uint16 loanId_)
    public
    view
    override
    returns (uint256 principal_, uint256[2] memory interest_);

Parameters

NameTypeDescription

loanId_

uint16

The id of the loan

Returns

NameTypeDescription

principal_

uint256

The principal due for the loan

interest_

uint256[2]

Interest Parameter [0]: The interest due for the loan [1]: The late interest due for the loan

getLoanPaymentBreakdown

Gets the payment breakdown of a loan up until this point in time

function getLoanPaymentBreakdown(uint16 loanId_) public view override returns (uint256 principal_, uint256 interest_);

Parameters

NameTypeDescription

loanId_

uint16

The id of the loan

Returns

NameTypeDescription

principal_

uint256

The principal due for the loan

interest_

uint256

The interest due for the loan

onERC721Received

function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4);

updateAccounting

Manually updates the accounting state of the pool

function updateAccounting() external whenNotPaused onlyPoolAdminOrGovernor;

approveLoan

Approves loan to be created with the following terms.

function approveLoan(
    address collateralAsset_,
    uint256 receivablesTokenId_,
    uint256 gracePeriod_,
    uint256 principalRequested_,
    uint256[2] memory rates_
)
    external
    override
    whenNotPaused
    returns (uint16 loanId_);

Parameters

NameTypeDescription

collateralAsset_

address

receivablesTokenId_

uint256

Token ID of the receivable that would be used as collateral

gracePeriod_

uint256

Grace period for the loan

principalRequested_

uint256

Amount of principal approved by the buyer

rates_

uint256[2]

Rates parameters: [0]: interestRate, [1]: lateInterestPremiumRate,

Returns

NameTypeDescription

loanId_

uint16

Id of the loan that is created

fundLoan

Funds the loan

function fundLoan(uint16 loanId_) external override nonReentrant whenNotPaused onlyPoolAdmin;

Parameters

NameTypeDescription

loanId_

uint16

The id of the loan

repayLoan

Repays the loan. (note that the loan can be repaid early but not partially)

function repayLoan(uint16 loanId_) external override whenNotPaused returns (uint256 principal_, uint256 interest_);

Parameters

NameTypeDescription

loanId_

uint16

Id of the loan to repay

Returns

NameTypeDescription

principal_

uint256

Principal amount repaid

interest_

uint256

Interest amount repaid

withdrawFunds

Withdraw the funds from a loan.

function withdrawFunds(uint16 loanId_, address destination_, uint256 amount_) external override whenNotPaused;

Parameters

NameTypeDescription

loanId_

uint16

Id of the loan to withdraw funds from

destination_

address

The destination address for the funds

amount_

uint256

The amount to withdraw

impairLoan

Impairs the loan

function impairLoan(uint16 loanId_) external override whenNotPaused onlyPoolAdminOrGovernor;

Parameters

NameTypeDescription

loanId_

uint16

The id of the loan

removeLoanImpairment

Removes the impairment on the loan

function removeLoanImpairment(uint16 loanId_) external override nonReentrant whenNotPaused onlyPoolAdminOrGovernor;

Parameters

NameTypeDescription

loanId_

uint16

The id of the loan

triggerDefault

Triggers the default of a loan

function triggerDefault(uint16 loanId_)
    external
    override
    whenNotPaused
    onlyPoolAdmin
    returns (uint256 remainingLosses_, uint256 protocolFees_);

Parameters

NameTypeDescription

loanId_

uint16

The id of the loan that is triggered

Returns

NameTypeDescription

remainingLosses_

uint256

The amount of remaining losses

protocolFees_

uint256

The amount of protocol fees

_getIssuance

function _getIssuance(uint256 issuanceRate_, uint256 interval_) internal pure returns (uint256 issuance_);

_getInterestBreakdown

function _getInterestBreakdown(
    uint256 currentTime_,
    uint256 startDate_,
    uint256 dueDate_,
    uint256 principal_,
    uint256 interestRate_,
    uint256 lateInterestPremiumRate_
)
    internal
    pure
    returns (uint256[2] memory interest_);

_getInterest

function _getInterest(
    uint256 principal_,
    uint256 interestRate_,
    uint256 interval_
)
    internal
    pure
    returns (uint256 interest_);

_getLateInterest

function _getLateInterest(
    uint256 currentTime_,
    uint256 principal_,
    uint256 interestRate_,
    uint256 dueDate_,
    uint256 lateInterestPremiumRate_
)
    internal
    pure
    returns (uint256 lateInterest_);

_getPeriodicInterestRate

function _getPeriodicInterestRate(
    uint256 interestRate_,
    uint256 interval_
)
    internal
    pure
    returns (uint256 periodicInterestRate_);

_poolConfigurator

function _poolConfigurator() internal view returns (address poolConfigurator_);

_globals

function _globals() internal view returns (address globals_);

_governor

function _governor() internal view returns (address governor_);

_poolAdmin

function _poolAdmin() internal view returns (address poolAdmin_);

_pool

function _pool() internal view returns (address pool_);

_vault

function _vault() internal view returns (address vault_);

_updateInterestAccounting

function _updateInterestAccounting(int256 accountedInterestAdjustment_, int256 issuanceRateAdjustment_) internal;

_updateUnrealizedLosses

function _updateUnrealizedLosses(int256 lossesAdjustment_) internal;

_updatePrincipalOut

function _updatePrincipalOut(int256 principalOutAdjustment_) internal;

_clearLoanAccounting

function _clearLoanAccounting(uint16 loanId_) internal;

_advanceGlobalPaymentAccounting

function _advanceGlobalPaymentAccounting() internal;

_updateIssuanceParams

function _updateIssuanceParams(uint256 issuanceRate_, uint112 accountedInterest_) internal;

_compareAndSubtractAccountedInterest

function _compareAndSubtractAccountedInterest(uint256 amount_) internal;

_getAccruedAmount

function _getAccruedAmount(
    uint256 totalAccruingAmount_,
    uint256 startTime_,
    uint256 endTime_,
    uint256 currentTime_
)
    internal
    pure
    returns (uint256 accruedAmount_);

_getDefaultInterestAndFees

function _getDefaultInterestAndFees(
    uint16 loanId_,
    Loan.PaymentInfo memory paymentInfo_
)
    internal
    view
    returns (uint256 netInterest_, uint256 netLateInterest_, uint256 protocolFees_);

_getInterestAndFeesFromLiquidationInfo

function _getInterestAndFeesFromLiquidationInfo(uint16 loanId_)
    internal
    view
    returns (uint256 netInterest_, uint256 netLateInterest_, uint256 protocolFees_);

_getNetInterest

function _getNetInterest(uint256 interest_, uint256 feeRate_) internal pure returns (uint256 netInterest_);

_getPaymentAccruedInterest

function _getPaymentAccruedInterest(
    uint256 startTime_,
    uint256 endTime_,
    uint256 paymentIssuanceRate_
)
    internal
    pure
    returns (uint256 accruedInterest_);

_accountToEndOfPayment

function _accountToEndOfPayment(
    uint256 paymentId_,
    uint256 issuanceRate_,
    uint256 intervalStart_,
    uint256 intervalEnd_
)
    internal
    returns (uint256 accountedInterestIncrease_, uint256 issuanceRateReduction_);

_deletePayment

function _deletePayment(uint16 loanId_) internal;

_handlePaymentAccounting

function _handlePaymentAccounting(uint16 loanId_) internal returns (uint256 issuanceRate_);

_queuePayment

function _queuePayment(uint16 loanId_, uint256 startDate_, uint256 dueDate_) internal returns (uint256 newRate_);

_reverseLoanImpairment

function _reverseLoanImpairment(Loan.LiquidationInfo memory liquidationInfo_) internal;

_addPaymentToList

function _addPaymentToList(uint48 paymentDueDate_) internal returns (uint24 paymentId_);

_removePaymentFromList

function _removePaymentFromList(uint256 paymentId_) internal;

_distributeClaimedFunds

function _distributeClaimedFunds(uint16 loanId_, uint256 principal_, uint256 interest_) internal;

_handleDefault

function _handleDefault(
    uint16 loanId_,
    uint256 netInterest_,
    uint256 netLateInterest_
)
    internal
    returns (uint256 remainingLosses_);

_revertIfPaused

function _revertIfPaused() internal view;

_revertIfNotPoolAdminOrGovernor

function _revertIfNotPoolAdminOrGovernor() internal view;

_revertIfNotPoolAdmin

function _revertIfNotPoolAdmin() internal view;

_revertIfCallerNotReceivableBuyer

function _revertIfCallerNotReceivableBuyer(address buyer_) internal view;

_revertIfInvalidReceivable

function _revertIfInvalidReceivable(
    uint256 receivablesTokenId_,
    address buyer_,
    address seller_,
    uint256 repaymentTimestamp_
)
    internal
    view;

_min

function _min(uint256 a_, uint256 b_) internal pure returns (uint256 minimum_);

Last updated