Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.3.0 #87

Open
wants to merge 85 commits into
base: main
Choose a base branch
from
Open

V3.3.0 #87

wants to merge 85 commits into from

Conversation

sakulstra
Copy link
Contributor

@sakulstra sakulstra commented Dec 10, 2024

Summary

v3.3 version of the Aave protocol, including:

  • Introduction of bad debt accounting, to be compatible with the upcoming Umbrella system.
  • Improvement of the liquidations close factor mechanism, and complementary ones.
  • Optimisation of ReserveConfiguration bit operations.
  • Misc integrations changes on Pool, PoolDataProvider, different peripheral contracts.

Changelog


-> Core

ReserveConfiguration

  • The bitmasks and bit operations have been inverted, causing exactly the same output on the bitmaps data, but in a more efficient way.

Pool

  • Added new events related with deficit data
  • Added permissioned eliminateReserveDeficit(), by a new Umbrella role registered on the PoolAddressesProvider.
  • Added new getters for commonly used addresses (a/v Token) and deficit.
  • [BREAKING] Removed getReserveDataExtended(), marked as deprecated on 3.2.

Errors

  • New 101-105 codes

DataTypes

  • __deprecatedStableBorrowRate (not exposed already) has been replaced by deficit

ConfiguratorLogic

  • Minor internal changes to fetch data more efficiently from the Pool.

ReserveLogic

  • On updateState(), use reserveCache.reserveLastUpdateTimestamp as .cache() is always done just before in the protocol flow. Same for getIsVirtualAccActive().
  • Added eliminateDeficit() function

LiquidationLogic

  • Added new MIN_BASE_MAX_CLOSE_FACTOR_THRESHOLD and MIN_LEFTOVER_BASE public constants
  • Added management of bad debt accounting (deficit) and burning, whenever it accrues.
  • Introduced new logic to avoid protocol dust.

-> Periphery

AaveProtocolDataProvider

  • Uses more granular getters on the Pool, saving gas and reducing future problems with backwards compatibility.
  • Exposes the new deficit reserve data field via a getReserveDeficit() getter.

UIPoolDataProvider

  • [BREAKING] The AggregatedReserveData struct returned from getReservesData() now has an extra deficit field.
  • Backwards compatible change of type returned for networkBaseTokenPriceInUsdProxyAggregator and marketReferenceCurrencyPriceInUsdProxyAggregator.

WrappedTokenGatewayV3

  • Uses more granular getters on the Pool, saving gas and reducing future problems with backwards compatibility.
  • Now exposes WETH & POOL as public variables

ParaswapAdapters

  • Uses more granular getters on the Pool, saving gas and reducing future problems with backwards compatibility.

EmissionManager

  • setRewardOracle() now requires a different input type for rewardOracle, but backwards compatible

RewardsController

  • Transparent changes on internal interface types used, no effect externally

All instances of the ChainlinkOracle interface have been aligned to a single version containing all methods.
While we are aware that non of the contract actually needs all methods, it improves DX within the aave-v3-origin repo to assume they do.


Steps planned for upgrade stage

  • Require that deficit storage variables are zero, to assure that there is not “dirty” data from the previous __deprecatedStableBorrowRate. Not on initialise because that would be the only aspects added there, and it is not worth it.
  • (not necessarily on upgrade) "clean up" existing bad debt before the activation of Umbrella.

sakulstra and others added 30 commits October 16, 2024 10:04
Tracking of reserve deficit and instant removal of bad debt.

This newly introduced feature allows the removal of excess debt.
When a users collateral if fully liquidated but debt is left in the protocol, the debt generates yield although it is expected to never be payed back.
With the reserve deficit tracking, this debt is immediately burned and tracked in a local state.
In addition a new method is introduced which allows burning aTokens in order the resolve the realized debt.

---------

Co-authored-by: Lukas <[email protected]>
* fix: refine docs

* fix: typo
accessing the configuration cache should be save in this case and reduces gas overhead by around 300gas per access
umbrella should be a single address tied to the pool, so using acl is overkill, which also will be cheaper
- adding `getReserveVariableDebtToken` getter
- adjusting close factor to apply to whole position, not per reserve
- adjusting close factor to increase to 100% when debt/collateral are below a threshold
- adjusting liquidations to force full liquidation/or keep a leftover that is high enough to allow further liqudiations
* fix: migrate to dedicated getters

* test: cleanup tests

* feat: add pdp getter

* fix: remove unused validate

* refacto: remove getReserveDataExtended
- refactor to assume the umbrella never has debt

Co-authored-by: Ernesto Boado <[email protected]>
@@ -50,8 +50,9 @@ library DataTypes {
uint128 variableBorrowIndex;
//the current variable borrow rate. Expressed in ray
uint128 currentVariableBorrowRate;
// DEPRECATED on v3.2.0
uint128 __deprecatedStableBorrowRate;
/// @notice reused `__deprecatedStableBorrowRate` storage from pre 3.2
Copy link
Contributor

@miguelmtzinf miguelmtzinf Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is more a @dev than a @notice imho
how do we know that starts with 0 value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we checked, but also on the upgrade proposal we're iterating all reserves and ensure it's 0.

* @param caller The caller that triggered the DeficitCovered event
* @param amountCovered The amount of deficit covered
*/
event DeficitCovered(address indexed reserve, address caller, uint256 amountCovered);
Copy link
Contributor

@miguelmtzinf miguelmtzinf Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to make caller indexed? It's basically the liquidator right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the address calling the function and in effect burning it's aTokens / GHO - it's a permissioned entity registered as UMBRELLA on the addresses provider.

I don't see the point in making it indexed though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case there are multiple Umbrella instances could be useful. If gas costs are not relevant I may be a good idea to add it.

* an amount of debt corresponding to `MAX_LIQUIDATION_CLOSE_FACTOR`.
* A value of 0.95e18 results in 0.95
* @dev This constant represents a base value threshold.
* If the total collateral or debt on a position is below this threshold, the close factor is raised to 100%.
Copy link
Contributor

@miguelmtzinf miguelmtzinf Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth clarifying is in value terms? no token amounts

* A value of 0.95e18 results in 0.95
* @dev This constant represents a base value threshold.
* If the total collateral or debt on a position is below this threshold, the close factor is raised to 100%.
* @notice The default value assumes that the basePrice is usd denominated by 8 decimals and needs to be adjusted in a non USD-denominated pool.
Copy link
Contributor

@miguelmtzinf miguelmtzinf Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is more a @dev imho

* fix: remove gas diff - it's outdated and we now have it on every commit to main
* fix: address miguels feedback
* ci: bump workflows give permissions to write commit comments
* fix: bump revisions
: IERC20(params.asset).balanceOf(msg.sender);
require(balanceWriteOff <= userBalance, Errors.NOT_ENOUGH_AVAILABLE_USER_BALANCE);

if (reserveCache.reserveConfiguration.getIsVirtualAccActive()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small opt - cache this bool

// assets without virtual accounting can never be a collateral
bool isCollateral = userConfig.isUsingAsCollateral(reserve.id);
if (isCollateral && balanceWriteOff == userBalance) {
userConfig.setUsingAsCollateral(reserve.id, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we thought about imposing Umbrella not having the aTokens being used as collateral? Maybe we can even replace the isBorrowingAny with this check, and simplify this part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially it actually was like that, but eventually we got convinced that with umbrella being mutable via addresses provider it doesn't make to much sense to optimize here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow the rationale. My point was about imposing a specific state for Umbrella and do not see how being mutable relates.

require(isActive, Errors.RESERVE_INACTIVE);

uint256 balanceWriteOff = params.amount;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line break is unnecessary imo

) {
bool isDebtMoreThanLeftoverThreshold = ((vars.userReserveDebt - vars.actualDebtToLiquidate) *
vars.debtAssetPrice) /
vars.debtAssetUnit >=
Copy link
Contributor

@miguelmtzinf miguelmtzinf Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this? MIN_LEFTOVER_BASE has same number of decimals (8)
Same for the collateral side

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you elaborate, I don't understand the question tbh.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asking if we need to divide by asset units, as both things we are comparing are denominated in same terms (8 units)

DataTypes.UserConfigurationMap storage userConfig,
address user,
address debtAsset,
uint256 userReserveDebt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing this as @param in the docs

sakulstra and others added 7 commits December 11, 2024 16:19
typo fixes

Co-authored-by: miguelmtz <[email protected]>
* Added LiquidationDataProvider contract

* Minor changes from comments in PR

* Minor changes from comments in PR 2

* Added one more function to the LiquidationDataProvider contract + fixed one bug in the _isReserveReadyForLiquidations function

* Added the LiquidationDataProvider contract to deployment scripts

* Replaced the LiquidationHelper library with the LiquidationDataProvider contract in the PoolLiquidationTests test

* fix: refactor tests where possible

* fix: add tests

* fix: add tests

* Removed the _getReserveFullInfo function from the LiquidationDataProvider contract

---------

Co-authored-by: Lukas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants