protocol-v2 icon indicating copy to clipboard operation
protocol-v2 copied to clipboard

Fix for #315 (v2 Polygon)

Open eboadom opened this issue 3 years ago • 1 comments

Changes

  • On updateState() of ReserveLogic, 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 _updateIndexes of ReserveLogic, 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 _updateIndexes covers 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.

eboadom avatar Oct 13 '22 11:10 eboadom

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

pre-100-rf-fix-gas-master

After fix 100-rf-fix-gas

eboadom avatar Oct 17 '22 13:10 eboadom