Skip to main content

Router

Git Source

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

NameTypeDescription
_wrappedNativeTokenaddressThe address of the wrapped native token (i.e., whype: 0x555...)
_generalManageraddressThe address of the general manager contract
_rolloverVaultaddressThe address of the rollover vault contract
_fulfillmentVaultaddressThe address of the fulfillment vault contract
_pythaddressThe 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

NameTypeDescription
usdTokenaddressThe address of the usdToken to pull in
usdxAmountuint256The 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

NameTypeDescription
inputTokenaddressThe address of the input token to pull in
consolAmountuint256The amount of Consol to pull in

_pullCollateral

Internal function to pull in collateral

function _pullCollateral(address collateral, uint256 collateralCollected, bool isNative) internal;

Parameters

NameTypeDescription
collateraladdressThe address of the collateral token to pull in
collateralCollecteduint256The amount of collateral to pull in
isNativeboolWhether 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

NameTypeDescription
collateraladdressThe address of the collateral token
collateralAmountuint256The amount of collateral to calculate the cost for

Returns

NameTypeDescription
costuint256The cost of the collateral amount (including the price spread)
collateralDecimalsuint8The 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

NameTypeDescription
creationRequestCreationRequestThe creation request

Returns

NameTypeDescription
collateralCollecteduint256The amount of collateral that will be collected from the borrower
usdxCollecteduint256The amount of USDX that will be collected from the borrower
paymentAmountuint256The amount of USDX that will be paid to the fulfilller
collateralDecimalsuint8The 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

NameTypeDescription
priceUpdatesbytes[]The price updates to send to the Pyth contract
usdTokenaddressThe address of the usdToken to pull in
creationRequestCreationRequestThe creation request
isNativeboolWhether the collateral is the native token or not (i.e., whype: 0x555...)
maxCollecteduint256The maximum amount that can be collected from the borrower (in USDX if non-compounding, in collateral if compounding)

Returns

NameTypeDescription
collateralCollecteduint256The amount of collateral collected
usdxCollecteduint256The amount of USDX collected
paymentAmountuint256The amount of payment to be made
collateralDecimalsuint8The 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

NameTypeDescription
usdTokenaddressThe address of the usdToken to pull in
creationRequestCreationRequestThe creation request
isNativeboolWhether the collateral is the native token or not (i.e., whype: 0x555...)
maxCollecteduint256The maximum amount that can be collected from the borrower (in USDX if non-compounding, in collateral if compounding)

Returns

NameTypeDescription
collateralCollecteduint256The amount of collateral collected
usdxCollecteduint256The amount of USDX collected
paymentAmountuint256The amount of payment to be made
collateralDecimalsuint8The decimals of the collateral

periodPay

Make a periodic payment on a mortgage

function periodPay(address inputToken, uint256 tokenId, uint256 inputAmount) external;

Parameters

NameTypeDescription
inputTokenaddressThe address of the input token to pull in
tokenIduint256The token ID
inputAmountuint256The 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

NameTypeDescription
inputTokenaddressThe address of the input token to pull in
tokenIduint256The token ID
inputAmountuint256The amount of input token to pull in

refinance

Refinance a mortgage

function refinance(address inputToken, uint256 tokenId, uint8 newTotalPeriods) external;

Parameters

NameTypeDescription
inputTokenaddressThe address of the input token to pull in
tokenIduint256The token ID of the mortgage to refinance
newTotalPeriodsuint8The 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

NameTypeDescription
oPoolConfigIdOPoolConfigIdThe OPoolConfigId of the origination pool config

Returns

NameTypeDescription
originationPoolIOriginationPoolThe origination pool

originationPoolDeposit

Deposit into an origination pool

function originationPoolDeposit(OPoolConfigId oPoolConfigId, address usdToken, uint256 usdTokenAmount) external;

Parameters

NameTypeDescription
oPoolConfigIdOPoolConfigIdThe OPoolConfigId of the origination pool to deposit into
usdTokenaddressThe address of the usdToken to pull in
usdTokenAmountuint256The 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

NameTypeDescription
inputTokenaddressThe address of the input token
outputTokenaddressThe address of the output token
inputAmountuint256The amount of input token to convert

Returns

NameTypeDescription
outputAmountuint256The amount of output token received

wrap

Wraps tokens from usdToken -> usdx -> consol

function wrap(address inputToken, address outputToken, uint256 inputAmount) public;

Parameters

NameTypeDescription
inputTokenaddressThe address of the input token
outputTokenaddressThe address of the output token
inputAmountuint256The 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

NameTypeDescription
vaultaddressThe address of the liquidity vault to deposit into
usdTokenaddressThe address of the usdToken to pull in
usdTokenAmountuint256The amount of usdToken to pull in

rolloverVaultDeposit

Deposit into the rollover vault

function rolloverVaultDeposit(address usdToken, uint256 usdTokenAmount) external;

Parameters

NameTypeDescription
usdTokenaddressThe address of the usdToken to pull in
usdTokenAmountuint256The amount of usdToken to pull in

fulfillmentVaultDeposit

Deposit into the fulfillment vault

function fulfillmentVaultDeposit(address usdToken, uint256 usdTokenAmount) external;

Parameters

NameTypeDescription
usdTokenaddressThe address of the usdToken to pull in
usdTokenAmountuint256The amount of usdToken to pull in