Skip to content

Commit

Permalink
Refactor healthFactor check
Browse files Browse the repository at this point in the history
  • Loading branch information
EridianAlpha committed Jun 3, 2024
1 parent 0d0a200 commit 24ddadf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/AaveFunctions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ contract AaveFunctions is TokenSwaps {
/// @notice Withdraw wstETH from Aave.
/// // TODO: Update comment.
function _aaveWithdrawCollateral(address aavePoolAddress, address tokenAddress, uint256 withdrawAmount) internal {
// TODO: This should have a HF check to make sure that this withdrawal doesn't drop the HF below the target.
IPool(aavePoolAddress).withdraw(tokenAddress, withdrawAmount, address(this));
}

/// @notice Borrow USDC from Aave.
/// // TODO: Update comment.
/// @param borrowAmount The amount of USDC to borrow. 8 decimal places to the dollar. e.g. 100000000 = $1.00.
function _aaveBorrow(address aavePoolAddress, address tokenAddress, uint256 borrowAmount) internal {
// TODO: This should have a HF check to make sure that this borrow doesn't drop the HF below the target.
IPool(aavePoolAddress).borrow(tokenAddress, borrowAmount, 2, 0, address(this));
}

Expand Down Expand Up @@ -105,7 +103,7 @@ contract AaveFunctions is TokenSwaps {
}

/// @notice // TODO: Add comment.
function _checkHealthFactorAboveMinimum(IAavePM aavePM, address aavePoolAddress)
function _checkHealthFactorAboveMinimum()
internal
view
returns (
Expand All @@ -117,6 +115,9 @@ contract AaveFunctions is TokenSwaps {
uint256 healthFactor
)
{
IAavePM aavePM = IAavePM(address(this));
address aavePoolAddress = aavePM.getContractAddress("aavePool");

// TODO: Improve check.
(totalCollateralBase, totalDebtBase, availableBorrowsBase, currentLiquidationThreshold, ltv, healthFactor) =
IPool(aavePoolAddress).getUserAccountData(address(this));
Expand Down
2 changes: 1 addition & 1 deletion src/Rebalance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract Rebalance is TokenSwaps, AaveFunctions {
// Safety check to ensure the health factor is above the minimum target.
// It is also used to calculate the ?? by returning the updated position values.
/* (uint256 endCollateralBase,,,,,) = */
_checkHealthFactorAboveMinimum(aavePM, aavePoolAddress);
_checkHealthFactorAboveMinimum();
}

function _repayDebt(
Expand Down
2 changes: 1 addition & 1 deletion src/Reinvest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract Reinvest is TokenSwaps, AaveFunctions {

// Safety check to ensure the health factor is above the minimum target.
// It is also used to calculate the reinvested collateral by returning the updated position values.
(uint256 endCollateralBase,,,,,) = _checkHealthFactorAboveMinimum(aavePM, aavePoolAddress);
(uint256 endCollateralBase,,,,,) = _checkHealthFactorAboveMinimum();

// Calculate the reinvested collateral by comparing the initial and end collateral values.
if (endCollateralBase > initialCollateralBase) {
Expand Down

0 comments on commit 24ddadf

Please sign in to comment.