Skip to main content

LoanManager

Git Source

Inherits: ILoanManager, ERC165, Context

Title: The LoanManager contract

Author: SocksNFlops

The LoanManager implementation contract

In order to minimize smart contract risk, we are hedging towards immutability.

State Variables

consol

Returns the Consol token address

address public immutable override consol

generalManager

Returns the general manager address

address public immutable override generalManager

nft

Returns the mortgage NFT address

address public immutable override nft

mortgagePositions

The mapping of tokenIds to mortgage positions

mapping(uint256 => MortgagePosition) private mortgagePositions

Functions

constructor

Constructor

constructor(
string memory nftName,
string memory nftSymbol,
address _nftMetadataGenerator,
address _consol,
address _generalManager
) ;

Parameters

NameTypeDescription
nftNamestringThe name of the NFT
nftSymbolstringThe symbol of the NFT
_nftMetadataGeneratoraddressThe address of the NFT metadata generator
_consoladdressThe address of the Consol contract
_generalManageraddressThe address of the GeneralManager contract

_applyPendingMissedPayments

Calculates the number of missed payments and penalty amount for a mortgage position and updates them in memory (not storage)

function _applyPendingMissedPayments(MortgagePosition memory mortgagePosition)
internal
view
returns (MortgagePosition memory outputMortgagePosition, uint256 penaltyAmount, uint8 additionalPaymentsMissed);

Parameters

NameTypeDescription
mortgagePositionMortgagePositionThe mortgage position to calculate the missed payments and penalty amount for

Returns

NameTypeDescription
outputMortgagePositionMortgagePositionThe updated mortgage position
penaltyAmountuint256The penalty amount
additionalPaymentsMisseduint8The number of missed payments

_imposePenalty

Applies pending missed payments to a mortgage position and emits a penalty imposed event if a penalty was imposed

function _imposePenalty(uint256 tokenId) internal;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage position

imposePenaltyBefore

Modifier to apply penalties to a mortgage position before it is fetched and used or returned

modifier imposePenaltyBefore(uint256 tokenId) ;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage position

onlyGeneralManager

Modifier to check if the caller is the general manager

modifier onlyGeneralManager() ;

_validateMortgageOwner

Validates that the caller is the owner of the mortgage

function _validateMortgageOwner(uint256 tokenId) internal view;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage position

onlyMortgageOwner

Modifier to check if the caller is the owner of the mortgage

modifier onlyMortgageOwner(uint256 tokenId) ;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage position

_validateMortgageExistsAndActive

Validates that the mortgage position exists and is active

function _validateMortgageExistsAndActive(uint256 tokenId) internal view;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage position

mortgageExistsAndActive

Modifier to check if the mortgage position exists and is active

modifier mortgageExistsAndActive(uint256 tokenId) ;

Parameters

NameTypeDescription
tokenIduint256The ID of the mortgage position

_withdrawSubConsol

Withdraws the SubConsol from the Consol contract

function _withdrawSubConsol(address subConsol, uint256 amount) internal;

Parameters

NameTypeDescription
subConsoladdressThe address of the subConsol contract
amountuint256The amount of SubConsol to withdraw

_subConsolWithdrawCollateral

Withdraws the collateral from the subConsol

function _subConsolWithdrawCollateral(
address subConsol,
address receiver,
uint256 collateralAmount,
uint256 amount,
bool async
) internal;

Parameters

NameTypeDescription
subConsoladdressThe address of the subConsol contract
receiveraddressThe address of the receiver
collateralAmountuint256The amount of collateral to withdraw
amountuint256The amount of SubConsol to burn
asyncboolWhether to withdraw the collateral asynchronously

_consolTransferFrom

Transfers Consol from one address to another

function _consolTransferFrom(address from, address to, uint256 amount) internal;

Parameters

NameTypeDescription
fromaddressThe address of the sender
toaddressThe address of the recipient
amountuint256The amount of Consol to transfer

_depositCollateralToConsolForGeneralManager

Deposits the collateral -> subConsol -> Consol into the general manager

function _depositCollateralToConsolForGeneralManager(
address collateral,
address subConsol,
uint256 collateralAmount,
uint256 amount
) internal;

Parameters

NameTypeDescription
collateraladdressThe address of the collateral
subConsoladdressThe address of the subConsol
collateralAmountuint256The amount of collateral to deposit
amountuint256The amount of subConsol to deposit

_forfeitConsol

Forfeits the Consol in the LoanManager contract

function _forfeitConsol() internal;

_validateMinimumAmountBorrowed

Validates that the amount borrowed is above a minimum threshold

function _validateMinimumAmountBorrowed(uint256 amountBorrowed) internal pure;

Parameters

NameTypeDescription
amountBorroweduint256The amount borrowed

supportsInterface

function supportsInterface(bytes4 interfaceId) public view override returns (bool);

createMortgage

Creates a new mortgage position

function createMortgage(MortgageParams memory mortgageParams) external override onlyGeneralManager;

Parameters

NameTypeDescription
mortgageParamsMortgageParamsThe parameters for the mortgage position

getMortgagePosition

Returns the mortgage position for a given tokenId

function getMortgagePosition(uint256 tokenId)
external
view
override
returns (MortgagePosition memory outputMortgagePosition);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position

Returns

NameTypeDescription
outputMortgagePositionMortgagePositionThe mortgage position

imposePenalty

Imposes applicable penalties to a mortgage position

function imposePenalty(uint256 tokenId)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position

periodPay

Pays the monthly payment for a mortgage position

function periodPay(uint256 tokenId, uint256 amount)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
amountuint256The amount to pay

penaltyPay

Pays the penalty for a mortgage position

function penaltyPay(uint256 tokenId, uint256 amount)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
amountuint256The amount to pay

redeemMortgage

Redeems a mortgage position

function redeemMortgage(uint256 tokenId, bool async)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId)
onlyMortgageOwner(tokenId);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
asyncboolWhether to allow redemption to be asynchronous

refinanceMortgage

Refinances a mortgage position

function refinanceMortgage(uint256 tokenId, uint8 totalPeriods)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId)
onlyMortgageOwner(tokenId);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
totalPeriodsuint8The total number of periods that the mortgage is being refinanced to.

forecloseMortgage

Forecloses a mortgage position

function forecloseMortgage(uint256 tokenId)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId);

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position

flashSwapCallback

Called to msg.sender after transferring to the recipient from IConsol#flashSwap.

Used to facilitate foreclosures

function flashSwapCallback(address inputToken, address outputToken, uint256 amount, bytes calldata data) external;

Parameters

NameTypeDescription
inputTokenaddressThe address of the input token
outputTokenaddressThe address of the output token
amountuint256The amount of tokens to swap
databytesThe data to pass into the callback

convertMortgage

Converts a mortgage position

function convertMortgage(
uint256 tokenId,
uint256 currentPrice,
uint256 amount,
uint256 collateralAmount,
address receiver
) external override mortgageExistsAndActive(tokenId) imposePenaltyBefore(tokenId) onlyGeneralManager;

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
currentPriceuint256The current price of the collateral
amountuint256The amount of the principal being coverted
collateralAmountuint256The amount of the collateral being withdrawn during the conversion
receiveraddressThe address receiving the converted assets

expandBalanceSheet

Expands the balance sheet of a mortgage position by adding addtional principal and collateral to the mortgage position

function expandBalanceSheet(uint256 tokenId, uint256 amountIn, uint256 collateralAmountIn, uint16 newInterestRate)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId)
onlyGeneralManager;

Parameters

NameTypeDescription
tokenIduint256The tokenId of the mortgage position
amountInuint256The amount of the principal being added to the mortgage position
collateralAmountInuint256The amount of collateral being added to the mortgage position
newInterestRateuint16The new interest rate of the mortgage position