Skip to content

Commit

Permalink
fix: consider deficit as part of unbacked
Browse files Browse the repository at this point in the history
this patch, prevent termporarily overpaying liquidity providers while the deficit is not resolved

fix: add tests to check ir invariants

fix: move update rates
  • Loading branch information
sakulstra committed Dec 10, 2024
1 parent 80d3454 commit 1fa3d57
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 104 deletions.
4 changes: 4 additions & 0 deletions docs/3.3/Aave-v3.3-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ We plan on adding more dedicated getters in the future as we see fit.

The previously deprecated `pool.getReserveDataExtended()` was removed.
You can fetch the data via `pool.getReserveData()`, `pool.getVirtualUnderlyingBalance()` & `pool.getVirtualUnderlyingBalance()`.

While the interface of `calculateInterestRates` did not change, the usage assumptions changed.
Instead of passing `reserve.unbacked` you now have to pass `reserve.deficit + reserve.unbacked`.
The rational being that both values represent unbacked tokens on the pool.
1 change: 1 addition & 0 deletions docs/3.3/Aave-v3.3-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Formal properties in natural language of the 3.3 features.
- Deficit added during the liquidation can't be more than the user's debt
- Deficit can only be created and eliminated for an `active` reserve.
- Edge case: deficit can be created and eliminated even is a reserve is `paused` in case it is not the main liquidated asset. Both actions don't affect a user negatively, and preventing the burning of bad debt on paused reserves could create overhead for the protocol.
- For the interest rate calculation, deficit is treated equally as the unbacked parameter, given that it should be reducing utilisation.

### 2. Liquidation mechanics

Expand Down
5 changes: 2 additions & 3 deletions src/contracts/protocol/libraries/logic/LiquidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ library LiquidationLogic {
: IERC20(params.asset).balanceOf(msg.sender);
require(balanceWriteOff <= userBalance, Errors.NOT_ENOUGH_AVAILABLE_USER_BALANCE);

// update ir due to updateState
reserve.updateInterestRatesAndVirtualBalance(reserveCache, params.asset, 0, 0);

if (reserveCache.reserveConfiguration.getIsVirtualAccActive()) {
// assets without virtual accounting can never be a collateral
bool isCollateral = userConfig.isUsingAsCollateral(reserve.id);
Expand Down Expand Up @@ -163,6 +160,8 @@ library LiquidationLogic {

reserve.deficit -= balanceWriteOff.toUint128();

reserve.updateInterestRatesAndVirtualBalance(reserveCache, params.asset, 0, 0);

emit DeficitCovered(params.asset, msg.sender, balanceWriteOff);
}

Expand Down
2 changes: 1 addition & 1 deletion src/contracts/protocol/libraries/logic/ReserveLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ library ReserveLogic {
reserve.interestRateStrategyAddress
).calculateInterestRates(
DataTypes.CalculateInterestRatesParams({
unbacked: reserve.unbacked,
unbacked: reserve.unbacked + reserve.deficit,
liquidityAdded: liquidityAdded,
liquidityTaken: liquidityTaken,
totalDebt: totalVariableDebt,
Expand Down
Loading

0 comments on commit 1fa3d57

Please sign in to comment.