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
proof
bytes32[]
to validate the whitelist check.
constructor
Creates a new instance of IonHandlerBase
Parameters
_ilkIndex
uint8
of the ilk for which this instance is associated with.
_ionPool
IonPool
address of IonPool
core contract.
_gemJoin
GemJoin
the GemJoin
associated with the ilkIndex
of this contract.
_whitelist
Whitelist
the Whitelist
module address.
depositAndBorrow
Combines gem-joining and depositing collateral and then borrowing into one compound action.
Parameters
amountCollateral
uint256
Amount of collateral to deposit. [WAD]
amountToBorrow
uint256
Amount of WETH to borrow. Due to rounding, true borrow amount might be slightly less. [WAD]
proof
bytes32[]
that the user is whitelisted.
_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
vaultHolder
address
The user who will be responsible for repaying debt.
receiver
address
The user who receives the borrowed funds.
amountCollateral
uint256
to move into vault. [WAD]
amountToBorrow
uint256
out of the vault. [WAD]
amountToBorrowType
AmountToBorrow
Whether the amountToBorrow
is a min or max. This will dictate the rounding direction when converting to normalized amount. If it is a minimum, then the rounding will be rounded up. If it is a maximum, then the rounding will be rounded down.
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
collateralToWithdraw
uint256
in collateral terms. [WAD]
_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
user
address
Address of the user.
Returns
repayAmount
uint256
Amount of base asset required to repay all debt (this mimics IonPool's behavior). [WAD]
normalizedDebt
uint256
Total normalized debt held by user
's vault. [WAD]
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
debtToRepay
uint256
In ETH terms. [WAD]
collateralToWithdraw
uint256
In collateral terms. [WAD]
_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
vaultHolder
address
The user whose debt will be repaid.
receiver
address
The user who receives the the withdrawn collateral.
collateralToWithdraw
uint256
to move into vault. [WAD]
debtToRepay
uint256
out of the vault. [WAD]
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).