BorrowAndWithdrawUSDCModule

Git Source

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

NameTypeDescription
_aavePMProxyAddressaddressThe 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

NameTypeDescription
borrowAmountUSDCuint256The amount of USDC to borrow.
_owneraddressThe address to withdraw the USDC to.

Returns

NameTypeDescription
repaidReinvestedDebtuint256The 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

NameTypeDescription
totalCollateralBaseuint256The total collateral base in the Aave pool.
totalDebtBaseuint256The total debt base in the Aave pool.
currentLiquidationThresholduint256The current liquidation threshold in the Aave pool.
borrowAmountUSDCuint256The amount of USDC to borrow.
healthFactorTargetuint256The target Health Factor.

Returns

NameTypeDescription
repaidReinvestedDebtuint256The amount of reinvested debt repaid to increase the Health Factor.