RebalanceModule

Git Source

Inherits: IRebalanceModule

Author: EridianAlpha

This contract contains the functions for AavePM to rebalance the Aave position by repaying debt to increase the 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;

REBALANCE_HFT_BUFFER

The buffer for the Health Factor Target rebalance calculation

uint16 public constant REBALANCE_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();

rebalance

Rebalance the Aave position.

Caller must have MANAGER_ROLE. The function rebalances the Aave position. If the health factor is below the target, it repays debt to increase the health factor.

function rebalance() public onlyAavePM returns (uint256 repaymentAmountUSDC);

_repayDebt

Repay debt to increase the health factor.

This function repays debt to increase the health factor.

function _repayDebt(
    uint256 totalDebtBase,
    address aavePoolAddress,
    address usdcAddress,
    uint256 totalCollateralBase,
    uint256 currentLiquidationThreshold,
    uint16 healthFactorTarget
) private returns (uint256 repaymentAmountUSDC);

Parameters

NameTypeDescription
totalDebtBaseuint256The total debt in base units.
aavePoolAddressaddressThe address of the Aave pool.
usdcAddressaddressThe address of the USDC token.
totalCollateralBaseuint256The total collateral in base units.
currentLiquidationThresholduint256The current liquidation threshold.
healthFactorTargetuint16The target health factor.

Returns

NameTypeDescription
repaymentAmountUSDCuint256The amount of USDC repaid.