RebalanceModule
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
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();
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
Name | Type | Description |
---|---|---|
totalDebtBase | uint256 | The total debt in base units. |
aavePoolAddress | address | The address of the Aave pool. |
usdcAddress | address | The address of the USDC token. |
totalCollateralBase | uint256 | The total collateral in base units. |
currentLiquidationThreshold | uint256 | The current liquidation threshold. |
healthFactorTarget | uint16 | The target health factor. |
Returns
Name | Type | Description |
---|---|---|
repaymentAmountUSDC | uint256 | The amount of USDC repaid. |