protocol-v2
protocol-v2 copied to clipboard
Fix for #315 (v2 Polygon)
Changes
- On
updateState()ofReserveLogic, add a condition to not do any update if the timestamp has not changed since the last stored on the reserve's data. This is not related to the 100% RF problem, but it simplifies reasoning about this part of the core code and saves important gas on actions happening in the same block. - On
_updateIndexesofReserveLogic, split the 2 update conditions of supply/variable borrow indexes, this way covering the case of 100% RF, on which borrow variable index should be updated (if there is borrow variable debt). The change tries to keep the diff to the minimum - This PR affects only the version of v2 used on v2 Avalanche and v2 Polygon, the so-called "light deployment"
Tests
- The new logic on
_updateIndexescovers exactly the same cases as before, just adding also one when(currentLiquidityRate == 0)and(scaledVariableDebt > 0), which is exactly the one of 100% RF in a reserve. Because of this a new https://github.com/aave/protocol-v2/blob/bf82b9f5287860786ca50c8ccfcb0ff5f6ddef87/test-suites/test-aave/reserve-factor.spec.ts file has been added, testing the case for both when variable and stable debt exists.
Gas report diff
As expected, there is a slight increase in gas on the most common actions, mainly because of the added condition to skip updates whenever the timestamp didn't change.
At the same time, there are savings on flashLoan(), as the tests involve multiple actions, and there is where savings are noticeable.
Before fix
After fix
