LoanManager
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
| Name | Type | Description |
|---|---|---|
nftName | string | The name of the NFT |
nftSymbol | string | The symbol of the NFT |
_nftMetadataGenerator | address | The address of the NFT metadata generator |
_consol | address | The address of the Consol contract |
_generalManager | address | The 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
| Name | Type | Description |
|---|---|---|
mortgagePosition | MortgagePosition | The mortgage position to calculate the missed payments and penalty amount for |
Returns
| Name | Type | Description |
|---|---|---|
outputMortgagePosition | MortgagePosition | The updated mortgage position |
penaltyAmount | uint256 | The penalty amount |
additionalPaymentsMissed | uint8 | The 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The ID of the mortgage position |
onlyMortgageOwner
Modifier to check if the caller is the owner of the mortgage
modifier onlyMortgageOwner(uint256 tokenId) ;
Parameters
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The ID of the mortgage position |
_validateMortgageExistsAndActive
Validates that the mortgage position exists and is active
function _validateMortgageExistsAndActive(uint256 tokenId) internal view;
Parameters
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The ID of the mortgage position |
mortgageExistsAndActive
Modifier to check if the mortgage position exists and is active
modifier mortgageExistsAndActive(uint256 tokenId) ;
Parameters
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The ID of the mortgage position |
_withdrawSubConsol
Withdraws the SubConsol from the Consol contract
function _withdrawSubConsol(address subConsol, uint256 amount) internal;
Parameters
| Name | Type | Description |
|---|---|---|
subConsol | address | The address of the subConsol contract |
amount | uint256 | The 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
| Name | Type | Description |
|---|---|---|
subConsol | address | The address of the subConsol contract |
receiver | address | The address of the receiver |
collateralAmount | uint256 | The amount of collateral to withdraw |
amount | uint256 | The amount of SubConsol to burn |
async | bool | Whether to withdraw the collateral asynchronously |
_consolTransferFrom
Transfers Consol from one address to another
function _consolTransferFrom(address from, address to, uint256 amount) internal;
Parameters
| Name | Type | Description |
|---|---|---|
from | address | The address of the sender |
to | address | The address of the recipient |
amount | uint256 | The 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
| Name | Type | Description |
|---|---|---|
collateral | address | The address of the collateral |
subConsol | address | The address of the subConsol |
collateralAmount | uint256 | The amount of collateral to deposit |
amount | uint256 | The 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
| Name | Type | Description |
|---|---|---|
amountBorrowed | uint256 | The 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
| Name | Type | Description |
|---|---|---|
mortgageParams | MortgageParams | The 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId of the mortgage position |
Returns
| Name | Type | Description |
|---|---|---|
outputMortgagePosition | MortgagePosition | The mortgage position |
imposePenalty
Imposes applicable penalties to a mortgage position
function imposePenalty(uint256 tokenId)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId);
Parameters
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId of the mortgage position |
amount | uint256 | The amount to pay |
penaltyPay
Pays the penalty for a mortgage position
function penaltyPay(uint256 tokenId, uint256 amount)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId);
Parameters
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId of the mortgage position |
amount | uint256 | The amount to pay |
redeemMortgage
Redeems a mortgage position
function redeemMortgage(uint256 tokenId, bool async)
external
override
mortgageExistsAndActive(tokenId)
imposePenaltyBefore(tokenId)
onlyMortgageOwner(tokenId);
Parameters
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId of the mortgage position |
async | bool | Whether 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId of the mortgage position |
totalPeriods | uint8 | The 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The 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
| Name | Type | Description |
|---|---|---|
inputToken | address | The address of the input token |
outputToken | address | The address of the output token |
amount | uint256 | The amount of tokens to swap |
data | bytes | The 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId of the mortgage position |
currentPrice | uint256 | The current price of the collateral |
amount | uint256 | The amount of the principal being coverted |
collateralAmount | uint256 | The amount of the collateral being withdrawn during the conversion |
receiver | address | The 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
| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId of the mortgage position |
amountIn | uint256 | The amount of the principal being added to the mortgage position |
collateralAmountIn | uint256 | The amount of collateral being added to the mortgage position |
newInterestRate | uint16 | The new interest rate of the mortgage position |