IonHandlerBase
The base handler contract for simpler interactions with the IonPool
core contract. It combines various individual interactions into one compound interaction to facilitate reaching user end-goals in atomic fashion.
To actually borrow from IonPool
, a user must submit a "normalized" borrow amount. This contract is designed to be user-intuitive and, thus, allows a user to submit a standard desired borrow amount, which this contract will then convert into to the appropriate "normalized" borrow amount.
State Variables
BASE
WETH
ILK_INDEX
POOL
JOIN
LST_TOKEN
WHITELIST
Functions
checkDeadline
Checks if the tx is being executed before the designated deadline for execution.
This is used to prevent txs that have sat in the mempool for too long from executing at unintended prices.
onlyWhitelistedBorrowers
Checks if msg.sender
is on the whitelist.
This contract will be on the protocolControlledWhitelist
. As such, it will validate that users are on the whitelist itself and be able to bypass the whitelist check on IonPool
.
Parameters
constructor
Creates a new instance of IonHandlerBase
Parameters
depositAndBorrow
Combines gem-joining and depositing collateral and then borrowing into one compound action.
Parameters
_depositAndBorrow
Handles all logic to gem-join and deposit collateral, followed by a borrow. It is also possible to use this function simply to gem-join and deposit collateral atomically by setting amountToBorrow
to 0.
Parameters
repayFullAndWithdraw
Will repay all debt and withdraw desired collateral amount. This function can also simply be used for a full repayment (which may be difficult through a direct tx to the IonPool
) by setting collateralToWithdraw
to 0.
Will repay the debt belonging to msg.sender
. This function is necessary because with rate
updating every single block, it may be difficult to repay a full amount if a user uses the total debt from a previous block. If a user ends up repaying all but dust amounts of debt (due to a slight rate
change), then they repayment will likely fail due to the dust
parameter.
Parameters
_getFullRepayAmount
Helper function to get the repayment amount for all the debt of a user
.
This simply emulates the rounding behaviour of the IonPool
to arrive at an accurate value.
Parameters
Returns
repayAndWithdraw
Combines repaying debt and then withdrawing and gem-exitting collateral into one compound action. If repaying all is the intention, use repayFullAndWithdraw()
instead to prevent tx revert from dust amounts of debt in vault.
Parameters
_repayAndWithdraw
Handles all logic to repay debt, followed by a collateral withdrawal and gem-exit. This function can also be used to just withdraw and gem-exit in atomic fashion by setting the debtToRepay
to 0.
Parameters
receive
ETH cannot be directly sent to this contract.
To allow unwrapping of WETH into ETH.
Errors
CannotSendEthToContract
FlashloanRepaymentTooExpensive
TransactionDeadlineReached
Enums
AmountToBorrow
During conversion from borrow amount -> "normalized" borrow amount," there is division required. In certain scenarios, it may be desirable to round up during division, in others, to round down. This enum allows a developer to indicate the rounding direction by describing the amountToBorrow
. If it IS_MIN
, then the final borrowed amount should be larger than amountToBorrow
(round up), and vice versa for IS_MAX
(round down).