BorrowAndWithdrawUSDCModule
Inherits: IBorrowAndWithdrawUSDCModule
Author: EridianAlpha
This contract contains the functions for AavePM to borrow and withdraw USDC from the Aave protocol.
State Variables
VERSION
The version of the contract.
Contract is upgradeable so the version is a constant set on each implementation contract.
string public constant VERSION = "0.0.1";
aavePMProxyAddress
The address of the AavePM proxy contract.
The AavePM proxy address is set on deployment and is immutable.
address public immutable aavePMProxyAddress;
HFT_BUFFER
The buffer for the Health Factor Target calculation
uint16 public constant HFT_BUFFER = 2;
Functions
constructor
Contract constructor to set the AavePM proxy address.
The AavePM proxy address is set on deployment and is immutable.
constructor(address _aavePMProxyAddress);
Parameters
Name | Type | Description |
---|---|---|
_aavePMProxyAddress | address | The address of the AavePM proxy contract. |
onlyAavePM
Modifier to check that only the AavePM contract is the caller.
Uses address(this)
since this contract is called by the AavePM contract using delegatecall.
modifier onlyAavePM();
borrowAndWithdrawUSDC
Borrow USDC from the Aave protocol and withdraw it to the specified owner.
This function borrows USDC from the Aave protocol and withdraws it to the specified owner.
function borrowAndWithdrawUSDC(uint256 borrowAmountUSDC, address _owner)
public
onlyAavePM
returns (uint256 repaidReinvestedDebt);
Parameters
Name | Type | Description |
---|---|---|
borrowAmountUSDC | uint256 | The amount of USDC to borrow. |
_owner | address | The address to withdraw the USDC to. |
Returns
Name | Type | Description |
---|---|---|
repaidReinvestedDebt | uint256 | The amount of reinvested debt repaid (if any) to increase the Health Factor. |
_borrowCalculation
Calculate the amount of reinvested debt to repay to increase the Health Factor.
This function calculates the amount of reinvested debt to repay to increase the Health Factor.
function _borrowCalculation(
uint256 totalCollateralBase,
uint256 totalDebtBase,
uint256 currentLiquidationThreshold,
uint256 borrowAmountUSDC,
uint256 healthFactorTarget
) private pure returns (uint256 repaidReinvestedDebt);
Parameters
Name | Type | Description |
---|---|---|
totalCollateralBase | uint256 | The total collateral base in the Aave pool. |
totalDebtBase | uint256 | The total debt base in the Aave pool. |
currentLiquidationThreshold | uint256 | The current liquidation threshold in the Aave pool. |
borrowAmountUSDC | uint256 | The amount of USDC to borrow. |
healthFactorTarget | uint256 | The target Health Factor. |
Returns
Name | Type | Description |
---|---|---|
repaidReinvestedDebt | uint256 | The amount of reinvested debt repaid to increase the Health Factor. |