AaveV3Borrower
IMPLEMENTATION
address of the implementation contract
ORACLE
price oracle and pool address can be obtained from AAVE's address provider contract
INTEREST_RATE_MODE
REFERRAL_CODE
constructor
contract's constructor
Parameters
_addressesProvider
address
address of AAVE's address provider
_referralCode
uint256
code used by aave to identify certain partners, this can be safely set to 0
_interestRateMode
uint256
interest rate mode for borrowing assets. 0 for none, 1 for stable, 2 for variable
debtToken
convenience function to obtain the address of the non transferrable debt token overlying of some asset
Parameters
asset
contract IERC20
the underlying asset
interestRateMode
uint256
the interest rate (stable or variable) of the debt token
Return Values
debtTkn
contract ICreditDelegationToken
the overlying debt token
_staticdelegatecall
intermediate function to allow a call to be delagated to IMPLEMENTATION while preserving the a view
attribute.
scheme is as follows: for some view
function f
of IMPLEMENTATION, one does staticcall(_staticdelegatecall(f))
which will retain for the view
attribute
maxGettableUnderlying
Returns max redeem R and borrow capacity B|R, which would occur after the redeem.
maxBorrowAfterRedeemInUnderlying
is always 0 if tryBorrow
is false
.
Parameters
asset
contract IERC20
the underlying asset to withdraw and potentially borrow
tryBorrow
bool
also computes borrow capacity after all redeem is complete (costs extra gas).
onBehalf
address
user for whom max redeem/borrow is computed
Return Values
maxRedeemableUnderlying
uint256
maximum amount onBehalf
can redeem of asset
maxBorrowAfterRedeemInUnderlying
uint256
max amount onBehalf
can borrow in asset
ater redeeming of maxRedeemableUnderlying
.
getCaps
_repayThenDeposit
deposits assets on AAVE by first repaying debt if any and then supplying to the pool
Parameters
token
contract IERC20
the asset one is depositing
onBehalf
address
the account one is repaying and supplying for
amount
uint256
of asset one is repaying and supplying
_redeemThenBorrow
withdraws liquidity on aave, if not enough liquidity is withdrawn, tries to borrow what's missing.
if onBehalf != address(this)
then this
needs to be approved by onBehalf
using approveDelegation
of the overlying debt token
function will only try to borrow if less than amount
was redeemed and will not try to borrow more than what is missing, even if strict
is not required.
this is forced by aave v3 currently not allowing to repay a debt that was incurred on the same block (so no gas optim can be used). Repaying on the next block would be dangerous as onBehalf
position could possibly be liquidated
Parameters
token
contract IERC20
the asset that needs to be redeemed
onBehalf
address
the account whose collateral is beeing withdrawn and borrowed upon.
amount
uint256
the target amount of token
one needs to redeem
strict
bool
whether call allows contract to redeem more than amount (for gas optimization).
recipient
address
the target address to which redeemed and borrowed tokens should be sent
Return Values
got
uint256
how much asset was transfered to caller
_borrow
tries to borrow some assets from the pool
Parameters
token
contract IERC20
the asset one is borrowing
amount
uint256
onBehalf
address
the account whose collateral is being used to borrow (caller must be approved by onBehalf
-if different- using approveDelegation
from the corresponding debt token (variable or stable))
_repay
repays debt to the pool
Parameters
token
contract IERC20
the asset one is repaying
amount
uint256
of assets one is repaying
onBehalf
address
account whose debt is being repaid
borrowed
returns the debt of a user
user can only borrow underlying in variable or stable, not both
Parameters
underlying
address
the asset whose debt balance is being viewed
account
address
the account whose debt balance is being viewed
Return Values
debt
uint256
the amount of tokens (in units of underlying
) that should be repaid to the pool