Portfolio
Inherits: IPortfolio, UpgradeableBase, LoansManager
This smart contract represents a portfolio of loans that are managed by tranches. Each tranche can have different risk profiles and yields. The main functions are starting the portfolio, closing senior and equity tranches, and handling loans. It uses the LoansManager contract to manage loans and relies on TranchePool contracts for tranche management.
Min number of tranches is 2, first tranche is always equity.
State Variables
GOVERNANCE_ROLE
bytes32 public constant GOVERNANCE_ROLE = 0x71840dc4906352362b0cdaf79870196c8e42acafade72d5d5a6d59291253ceb1;
tranches
tranche[0] is always equity
ITranchePool[] public tranches;
tranchesData
TrancheData[] public tranchesData;
status
Status public status;
startTimestamp
uint40 public startTimestamp;
stoppedTimestamp
uint256 public stoppedTimestamp;
Functions
initialize
function initialize(
address manager,
address governance,
IERC20 _asset,
IProtocolConfig _protocolConfig,
TrancheInitData[] memory tranchesInitData,
IFixedInterestBulletLoans _fixedInterestBulletLoans
)
public
initializer;
Parameters
Name | Type | Description |
---|---|---|
manager | address | |
governance | address | |
_asset | IERC20 | |
_protocolConfig | IProtocolConfig | |
tranchesInitData | TrancheInitData[] | [{equityTrancheAddress, targetApr}, {seniorTrancheAddress, targetApr}] |
_fixedInterestBulletLoans | IFixedInterestBulletLoans |
start
Starts the portfolio to issue loans.
- changes the state to Live
- gathers assets to the portfolio from every tranche.*
function start() external whenNotPaused;
closeSenior
Allow the senior tranche to withdraw.
- changes the state to SeniorClosed
- Distribute the remaining assets to the senior tranche.*
function closeSenior() external whenNotPaused;
closeEquity
Allow the equity tranche to withdraw.
- changes the state to EquityClosed
- Distribute the remaining assets to the equity tranche.*
function closeEquity() external whenNotPaused;
calculateWaterfall
calculate each tranche values based only on the current assets.
no fee
function calculateWaterfall() public view returns (uint256[] memory);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256[] | Array of current tranche values |
calculateWaterfallForTranche
no fee
function calculateWaterfallForTranche(uint256 waterfallIndex) external view returns (uint256);
calculateWaterfallWithLoansForTranche
no fee
function calculateWaterfallWithLoansForTranche(uint256 waterfallIndex) external view returns (uint256);
calculateWaterfallWithLoans
calculate each tranche values given the (current assets + loans value).
no fee
function calculateWaterfallWithLoans() public view returns (uint256[] memory);
loansValue
calculate the total value of all active loans in the contract.
function loansValue() public view returns (uint256);
getTokenBalance
get token balance of this contract
function getTokenBalance() external view returns (uint256);
_validateStart
function _validateStart() internal view;
_validateCloseSenior
function _validateCloseSenior() internal view;
_validateCloseEquity
validate portfolio
function _validateCloseEquity() internal view;
_distributeToTranches
function _distributeToTranches(uint256 lowestIndex) internal;
_calculateWaterfall
calculate each tranche values based only on the current assets and the status.
1. if the portfolio is in the preparation / equity closed stage, return the current assets of each tranche. 2. if the portfolio is in the live / paused stage, calculate based on the current assets in the portfolio and the loans value. 3. if the portfolio is in the senior closed stage, return the current assets of each tranche except for the equity tranche.
function _calculateWaterfall(uint256 assetsLeft) internal view returns (uint256[] memory);
_assumedTrancheValue
function _assumedTrancheValue(uint256 trancheIdx, uint256 timestamp) internal view returns (uint256);
_changePortfolioStatus
function _changePortfolioStatus(Status newStatus) internal;
addLoan
Create loan
function addLoan(AddLoanParams calldata params) external whenNotPaused returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
params | AddLoanParams | Loan params |
fundLoan
Fund the loan
function fundLoan(uint256 loanId) external whenNotPaused returns (uint256 principal);
Parameters
Name | Type | Description |
---|---|---|
loanId | uint256 | Loan id |
repayLoan
Repay the loan
function repayLoan(uint256 loanId) external whenNotPaused returns (uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
loanId | uint256 | Loan id |
repayDefaultedLoan
Repay the loan
function repayDefaultedLoan(uint256 loanId, uint256 amount) external whenNotPaused;
Parameters
Name | Type | Description |
---|---|---|
loanId | uint256 | Loan id |
amount | uint256 | amount |
cancelLoan
cancel the loan
function cancelLoan(uint256 loanId) external;
Parameters
Name | Type | Description |
---|---|---|
loanId | uint256 | loan id |
getAssumedCurrentValues
function getAssumedCurrentValues()
public
view
returns (uint256 equityValue, uint256 fixedRatePoolValue, uint256 overdueValue);
stopPortfolio
stop the portfolio
function stopPortfolio() external;
restartPortfolio
restart the portfolio
function restartPortfolio() external;
checkPortfolioNeedStop
function checkPortfolioNeedStop(
uint256 equityValue,
uint256 fixedRatePoolValue,
uint256 overdueValue
)
public
returns (bool);
checkPortfolioNeedRestart
function checkPortfolioNeedRestart(
uint256 equityValue,
uint256 fixedRatePoolValue,
uint256 overdueValue
)
public
returns (bool);
markLoanAsDefaulted
Cancel the loan
function markLoanAsDefaulted(uint256 loanId) external whenNotPaused;
Parameters
Name | Type | Description |
---|---|---|
loanId | uint256 | Loan id |
increaseTokenBalance
function increaseTokenBalance(uint256 amount) external;
_requireManagerOrCollateralOwner
function _requireManagerOrCollateralOwner(address collateral, uint256 collateralId) internal view;
_requireTranchePool
function _requireTranchePool() internal view;
_requireGovernanceRole
function _requireGovernanceRole() internal view;
_grantGovernanceRole
function _grantGovernanceRole(address governance) internal;