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
Name | Type | Description |
---|---|---|
|
| to validate the whitelist check. |
constructor
Creates a new instance of IonHandlerBase
Parameters
Name | Type | Description |
---|---|---|
|
| of the ilk for which this instance is associated with. |
|
| address of |
|
| the |
|
| the |
depositAndBorrow
Combines gem-joining and depositing collateral and then borrowing into one compound action.
Parameters
Name | Type | Description |
---|---|---|
|
| Amount of collateral to deposit. [WAD] |
|
| Amount of WETH to borrow. Due to rounding, true borrow amount might be slightly less. [WAD] |
|
| 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
Name | Type | Description |
---|---|---|
|
| The user who will be responsible for repaying debt. |
|
| The user who receives the borrowed funds. |
|
| to move into vault. [WAD] |
|
| out of the vault. [WAD] |
|
| Whether the |
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
Name | Type | Description |
---|---|---|
|
| 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
Name | Type | Description |
---|---|---|
|
| Address of the user. |
Returns
Name | Type | Description |
---|---|---|
|
| Amount of base asset required to repay all debt (this mimics IonPool's behavior). [WAD] |
|
| Total normalized debt held by |
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
Name | Type | Description |
---|---|---|
|
| In ETH terms. [WAD] |
|
| 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
Name | Type | Description |
---|---|---|
|
| The user whose debt will be repaid. |
|
| The user who receives the the withdrawn collateral. |
|
| to move into vault. [WAD] |
|
| 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).