Router
Inherits: IRouter, Context, IMortgageNFTErrors, IERC20Errors, IGeneralManagerErrors, IOriginationPoolErrors, IOriginationPoolSchedulerErrors
Title: Router
Author: @SocksNFlops
This contract facilitates user interactions with core contracts of the Cash protocol.
State Variables
generalManager
The address of the general manager contract
address public immutable generalManager
rolloverVault
The address of the rollover vault contract
address public immutable rolloverVault
fulfillmentVault
The address of the fulfillment vault contract
address public immutable fulfillmentVault
pyth
The address of the Pyth contract
address public immutable pyth
wrappedNativeToken
The address of the wrapped native token
address public immutable wrappedNativeToken
usdx
The address of the USDX token contract
address public immutable usdx
consol
The address of the Consol token contract
address public immutable consol
originationPoolScheduler
The address of the origination pool scheduler contract
address public immutable originationPoolScheduler
Functions
constructor
constructor(
address _wrappedNativeToken,
address _generalManager,
address _rolloverVault,
address _fulfillmentVault,
address _pyth
) ;
Parameters
| Name | Type | Description |
|---|---|---|
_wrappedNativeToken | address | The address of the wrapped native token (i.e., whype: 0x555...) |
_generalManager | address | The address of the general manager contract |
_rolloverVault | address | The address of the rollover vault contract |
_fulfillmentVault | address | The address of the fulfillment vault contract |
_pyth | address | The address of the Pyth contract |
receive
receive() external payable;
approveCollaterals
Approve all the collaterals to be spent by the general manager
function approveCollaterals() external;
approveUsdTokens
Approve all the usdTokens to be spent by the USDX contract (for depositing into USDX)
function approveUsdTokens() external;
_pullUsdToken
Internal function to pull in USDX via the underlying usdToken
function _pullUsdToken(address usdToken, uint256 usdxAmount) internal;
Parameters
| Name | Type | Description |
|---|---|---|
usdToken | address | The address of the usdToken to pull in |
usdxAmount | uint256 | The amount of USDX to pull in |
_pullInConsol
Internal function to pull in Consol via the underlying usdTokens, USDX, SubConsols, or ForfeitedAssetsPool
function _pullInConsol(address inputToken, uint256 consolAmount) internal;
Parameters
| Name | Type | Description |
|---|---|---|
inputToken | address | The address of the input token to pull in |
consolAmount | uint256 | The amount of Consol to pull in |
_pullCollateral
Internal function to pull in collateral
function _pullCollateral(address collateral, uint256 collateralCollected, bool isNative) internal;
Parameters
| Name | Type | Description |
|---|---|---|
collateral | address | The address of the collateral token to pull in |
collateralCollected | uint256 | The amount of collateral to pull in |
isNative | bool | Whether the collateral is the native token or not (i.e., whype: 0x555...) |
_calculateCost
Internal function to calculate the cost of a borrowing the collateral amount (including the price spread)
function _calculateCost(address collateral, uint256 collateralAmount)
internal
view
returns (uint256 cost, uint8 collateralDecimals);
Parameters
| Name | Type | Description |
|---|---|---|
collateral | address | The address of the collateral token |
collateralAmount | uint256 | The amount of collateral to calculate the cost for |
Returns
| Name | Type | Description |
|---|---|---|
cost | uint256 | The cost of the collateral amount (including the price spread) |
collateralDecimals | uint8 | The decimals of the collateral token |
calculateCollectedAmounts
Calculates the amounts that will be collected from the borrower for a given creation request before sending the request to the general manager
function calculateCollectedAmounts(CreationRequest calldata creationRequest)
public
view
returns (uint256 collateralCollected, uint256 usdxCollected, uint256 paymentAmount, uint8 collateralDecimals);
Parameters
| Name | Type | Description |
|---|---|---|
creationRequest | CreationRequest | The creation request |
Returns
| Name | Type | Description |
|---|---|---|
collateralCollected | uint256 | The amount of collateral that will be collected from the borrower |
usdxCollected | uint256 | The amount of USDX that will be collected from the borrower |
paymentAmount | uint256 | The amount of USDX that will be paid to the fulfilller |
collateralDecimals | uint8 | The decimals of the collateral token |
updatePriceFeedsAndRequestMortgage
Request a mortgage
function updatePriceFeedsAndRequestMortgage(
bytes[] calldata priceUpdates,
address usdToken,
CreationRequest calldata creationRequest,
bool isNative,
uint256 maxCollected
)
public
payable
returns (uint256 collateralCollected, uint256 usdxCollected, uint256 paymentAmount, uint8 collateralDecimals);
Parameters
| Name | Type | Description |
|---|---|---|
priceUpdates | bytes[] | The price updates to send to the Pyth contract |
usdToken | address | The address of the usdToken to pull in |
creationRequest | CreationRequest | The creation request |
isNative | bool | Whether the collateral is the native token or not (i.e., whype: 0x555...) |
maxCollected | uint256 | The maximum amount that can be collected from the borrower (in USDX if non-compounding, in collateral if compounding) |
Returns
| Name | Type | Description |
|---|---|---|
collateralCollected | uint256 | The amount of collateral collected |
usdxCollected | uint256 | The amount of USDX collected |
paymentAmount | uint256 | The amount of payment to be made |
collateralDecimals | uint8 | The decimals of the collateral |
requestMortgage
Request a mortgage
function requestMortgage(
address usdToken,
CreationRequest calldata creationRequest,
bool isNative,
uint256 maxCollected
)
public
payable
returns (uint256 collateralCollected, uint256 usdxCollected, uint256 paymentAmount, uint8 collateralDecimals);
Parameters
| Name | Type | Description |
|---|---|---|
usdToken | address | The address of the usdToken to pull in |
creationRequest | CreationRequest | The creation request |
isNative | bool | Whether the collateral is the native token or not (i.e., whype: 0x555...) |
maxCollected | uint256 | The maximum amount that can be collected from the borrower (in USDX if non-compounding, in collateral if compounding) |
Returns
| Name | Type | Description |
|---|---|---|
collateralCollected | uint256 | The amount of collateral collected |
usdxCollected | uint256 | The amount of USDX collected |
paymentAmount | uint256 | The amount of payment to be made |
collateralDecimals | uint8 | The decimals of the collateral |
periodPay
Make a periodic payment on a mortgage
function periodPay(address inputToken, uint256 tokenId, uint256 inputAmount) external;
Parameters
| Name | Type | Description |
|---|---|---|
inputToken | address | The address of the input token to pull in |
tokenId | uint256 | The token ID |
inputAmount | uint256 | The amount of input token to pull in |
penaltyPay
Make a penalty payment on a mortgage
function penaltyPay(address inputToken, uint256 tokenId, uint256 inputAmount) external;
Parameters
| Name | Type | Description |
|---|---|---|
inputToken | address | The address of the input token to pull in |
tokenId | uint256 | The token ID |
inputAmount | uint256 | The amount of input token to pull in |
refinance
Refinance a mortgage
function refinance(address inputToken, uint256 tokenId, uint8 newTotalPeriods) external;
Parameters
| Name | Type | Description |
|---|---|---|
inputToken | address | The address of the input token to pull in |
tokenId | uint256 | The token ID of the mortgage to refinance |
newTotalPeriods | uint8 | The new total periods of the mortgage |
_getOrCreateOriginationPool
Internal function to get or create the latest origination pool for a given OPoolConfigId
function _getOrCreateOriginationPool(OPoolConfigId oPoolConfigId)
internal
returns (IOriginationPool originationPool);
Parameters
| Name | Type | Description |
|---|---|---|
oPoolConfigId | OPoolConfigId | The OPoolConfigId of the origination pool config |
Returns
| Name | Type | Description |
|---|---|---|
originationPool | IOriginationPool | The origination pool |
originationPoolDeposit
Deposit into an origination pool
function originationPoolDeposit(OPoolConfigId oPoolConfigId, address usdToken, uint256 usdTokenAmount) external;
Parameters
| Name | Type | Description |
|---|---|---|
oPoolConfigId | OPoolConfigId | The OPoolConfigId of the origination pool to deposit into |
usdToken | address | The address of the usdToken to pull in |
usdTokenAmount | uint256 | The amount of usdToken to pull in |
convert
Quotes the amount of output token that would be received for a given amount of input token
function convert(address inputToken, address outputToken, uint256 inputAmount)
public
view
returns (uint256 outputAmount);
Parameters
| Name | Type | Description |
|---|---|---|
inputToken | address | The address of the input token |
outputToken | address | The address of the output token |
inputAmount | uint256 | The amount of input token to convert |
Returns
| Name | Type | Description |
|---|---|---|
outputAmount | uint256 | The amount of output token received |
wrap
Wraps tokens from usdToken -> usdx -> consol
function wrap(address inputToken, address outputToken, uint256 inputAmount) public;
Parameters
| Name | Type | Description |
|---|---|---|
inputToken | address | The address of the input token |
outputToken | address | The address of the output token |
inputAmount | uint256 | The amount of input token to convert |
_vaultDeposit
Internal function to deposit into a liquidity vault
function _vaultDeposit(address vault, address usdToken, uint256 usdTokenAmount) internal;
Parameters
| Name | Type | Description |
|---|---|---|
vault | address | The address of the liquidity vault to deposit into |
usdToken | address | The address of the usdToken to pull in |
usdTokenAmount | uint256 | The amount of usdToken to pull in |
rolloverVaultDeposit
Deposit into the rollover vault
function rolloverVaultDeposit(address usdToken, uint256 usdTokenAmount) external;
Parameters
| Name | Type | Description |
|---|---|---|
usdToken | address | The address of the usdToken to pull in |
usdTokenAmount | uint256 | The amount of usdToken to pull in |
fulfillmentVaultDeposit
Deposit into the fulfillment vault
function fulfillmentVaultDeposit(address usdToken, uint256 usdTokenAmount) external;
Parameters
| Name | Type | Description |
|---|---|---|
usdToken | address | The address of the usdToken to pull in |
usdTokenAmount | uint256 | The amount of usdToken to pull in |