ReinvestModule

Git Source

Inherits: IReinvestModule

Author: EridianAlpha

This contract contains the functions for AavePM to borrow USDC, swap to wstETH, and supply to Aave maintaining the target health factor.

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;

REINVEST_HFT_BUFFER

The buffer for the Health Factor Target reinvest calculation

uint16 public constant REINVEST_HFT_BUFFER = 10;

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();

reinvest

Reinvest the Aave position.

This function reinvests the Aave position by borrowing USDC, swapping to wstETH, and supplying it back to Aave.

function reinvest() public onlyAavePM returns (uint256 reinvestedDebt);

Returns

NameTypeDescription
reinvestedDebtuint256The amount of debt reinvested.

_reinvestAction

Reinvest the Aave position.

This function actions the reinvestment of the Aave position.

function _reinvestAction(
    IAavePM aavePM,
    uint256 totalDebtBase,
    address aavePoolAddress,
    address usdcAddress,
    address wstETHAddress,
    uint256 initialCollateralBase,
    uint256 currentLiquidationThreshold,
    uint16 healthFactorTarget
) private returns (uint256 borrowAmountUSDC);

Parameters

NameTypeDescription
aavePMIAavePMThe Aave Position Manager contract.
totalDebtBaseuint256The total debt in base units.
aavePoolAddressaddressThe address of the Aave pool.
usdcAddressaddressThe address of the USDC token.
wstETHAddressaddressThe address of the wstETH token.
initialCollateralBaseuint256The initial collateral in base units.
currentLiquidationThresholduint256The current liquidation threshold.
healthFactorTargetuint16The target health factor.

Returns

NameTypeDescription
borrowAmountUSDCuint256The amount of USDC borrowed.