Skip to main content

AaveV3Borrower

AaveV3Borrower​

IMPLEMENTATION​

address IMPLEMENTATION

address of the implementation contract

ORACLE​

contract IPriceOracleGetter ORACLE

price oracle and pool address can be obtained from AAVE's address provider contract

INTEREST_RATE_MODE​

uint256 INTEREST_RATE_MODE

REFERRAL_CODE​

uint16 REFERRAL_CODE

constructor​

constructor(address _addressesProvider, uint256 _referralCode, uint256 _interestRateMode) public

contract's constructor

Parameters​

NameTypeDescription
_addressesProvideraddressaddress of AAVE's address provider
_referralCodeuint256code used by aave to identify certain partners, this can be safely set to 0
_interestRateModeuint256interest rate mode for borrowing assets. 0 for none, 1 for stable, 2 for variable

debtToken​

function debtToken(contract IERC20 asset, uint256 interestRateMode) public view returns (contract ICreditDelegationToken debtTkn)

convenience function to obtain the address of the non transferrable debt token overlying of some asset

Parameters​

NameTypeDescription
assetcontract IERC20the underlying asset
interestRateModeuint256the interest rate (stable or variable) of the debt token

Return Values​

NameTypeDescription
debtTkncontract ICreditDelegationTokenthe overlying debt token

_staticdelegatecall​

function _staticdelegatecall(bytes data) external

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​

function maxGettableUnderlying(contract IERC20 asset, bool tryBorrow, address onBehalf) public view returns (uint256 maxRedeemableUnderlying, uint256 maxBorrowAfterRedeemInUnderlying)

Returns max redeem R and borrow capacity B|R, which would occur after the redeem.

maxBorrowAfterRedeemInUnderlying is always 0 if tryBorrow is false.

Parameters​

NameTypeDescription
assetcontract IERC20the underlying asset to withdraw and potentially borrow
tryBorrowboolalso computes borrow capacity after all redeem is complete (costs extra gas).
onBehalfaddressuser for whom max redeem/borrow is computed

Return Values​

NameTypeDescription
maxRedeemableUnderlyinguint256maximum amount onBehalf can redeem of asset
maxBorrowAfterRedeemInUnderlyinguint256max amount onBehalf can borrow in asset ater redeeming of maxRedeemableUnderlying.

getCaps​

function getCaps(contract IERC20 asset) public view returns (uint256 supplyCap, uint256 borrowCap)

_repayThenDeposit​

function _repayThenDeposit(contract IERC20 token, address onBehalf, uint256 amount) internal

deposits assets on AAVE by first repaying debt if any and then supplying to the pool

Parameters​

NameTypeDescription
tokencontract IERC20the asset one is depositing
onBehalfaddressthe account one is repaying and supplying for
amountuint256of asset one is repaying and supplying

_redeemThenBorrow​

function _redeemThenBorrow(contract IERC20 token, address onBehalf, uint256 amount, bool strict, address recipient) internal returns (uint256 got)

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​

NameTypeDescription
tokencontract IERC20the asset that needs to be redeemed
onBehalfaddressthe account whose collateral is beeing withdrawn and borrowed upon.
amountuint256the target amount of token one needs to redeem
strictboolwhether call allows contract to redeem more than amount (for gas optimization).
recipientaddressthe target address to which redeemed and borrowed tokens should be sent

Return Values​

NameTypeDescription
gotuint256how much asset was transfered to caller

_borrow​

function _borrow(contract IERC20 token, uint256 amount, address onBehalf) internal

tries to borrow some assets from the pool

Parameters​

NameTypeDescription
tokencontract IERC20the asset one is borrowing
amountuint256
onBehalfaddressthe 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​

function _repay(contract IERC20 token, uint256 amount, address onBehalf) internal returns (uint256 repaid)

repays debt to the pool

Parameters​

NameTypeDescription
tokencontract IERC20the asset one is repaying
amountuint256of assets one is repaying
onBehalfaddressaccount whose debt is being repaid

borrowed​

function borrowed(address underlying, address account) public view returns (uint256 debt)

returns the debt of a user

user can only borrow underlying in variable or stable, not both

Parameters​

NameTypeDescription
underlyingaddressthe asset whose debt balance is being viewed
accountaddressthe account whose debt balance is being viewed

Return Values​

NameTypeDescription
debtuint256the amount of tokens (in units of underlying) that should be repaid to the pool