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

refactor accrueInterest #642

Closed
wants to merge 17 commits into from
Closed

Conversation

MathisGD
Copy link
Contributor

@MathisGD MathisGD commented Dec 9, 2023

  • fixes the weird position of the event emission in _accrueInterest (before the write of lastUpdate)
  • it removes a early return that are dangerous imo
  • it simplifies the spec of the event emission in _accrueInterest (always emitted)
  • alls irm calls are done through one function
  • now blue is irm reentrancy safe

I opened this PR to 1- remove the weird call to the irm, and 2- synchronize the update of “lastUpdate” and the call to the irm
in accrueInterest, elapsed=block.timestamp which is weird but as totalBorrow=0 it’s ok
but now I changed my mind, I think that it’s better to update first “lastUpdate” and have elapsed=0 in accrueInterest

@MathisGD MathisGD self-assigned this Dec 9, 2023
src/Morpho.sol Outdated Show resolved Hide resolved
src/Morpho.sol Outdated Show resolved Hide resolved
src/Morpho.sol Outdated Show resolved Hide resolved
src/Morpho.sol Outdated Show resolved Hide resolved
src/Morpho.sol Outdated Show resolved Hide resolved
@MathisGD MathisGD changed the title refactor accrue interest refactor accrueInterest Dec 10, 2023
Copy link
Collaborator

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

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

The only benefit of this PR to me is that we call the IRM every time the market is interacted with, which can be useful for stateful IRMs
Otherwise, all other changes in the code are drawbacks:

  • change in the order in which events are emitted
  • AccrueInterest events are emitted when interest accrued is zero (so it is useless)
  • call to _accrueInterest in createMarket is more complex
  • the IRM costs gas to call

However, it seems to me that this property:

we call the IRM every time the market is interacted with

is unnecessary, because the stateful IRM can always re-calculate the evolution of the state between blocks, based on the last state that is passed to it every time... So I am currently against this change, because the benefit doesn't cover the cost of drawbacks

@MathisGD
Copy link
Contributor Author

  • change in the order in which events are emitted

if you are only talking about createMarket, this is easily fixable if we agree that it's a problem (I'm still not convinced)

  • AccrueInterest events are emitted when interest accrued is zero (so it is useless)

it doesn't cost a lot, and simplifies the spec (accrue interest is always called when the accrueInterest is called).

  • call to _accrueInterest in createMarket is more complex

what do you mean?

  • the IRM costs gas to call

you mean that we increase the number of calls to the irm, which costs gas right?

we call the IRM every time the market is interacted with

is unnecessary, because the stateful IRM can always re-calculate the evolution of the state between blocks, based on the last state that is passed to it every time... So I am currently against this change, because the benefit doesn't cover the cost of drawbacks

not sure what you mean here. If you want an irm that depends all interactions (including multiple interactions in the same block) how can it recompute this if you don't call it when the state changes.

Jean-Grimal
Jean-Grimal previously approved these changes Dec 11, 2023
Base automatically changed from fix/issue-259 to post-cantina December 11, 2023 09:49
@MerlinEgalite MerlinEgalite dismissed Jean-Grimal’s stale review December 11, 2023 09:49

The base branch was changed.

@adhusson
Copy link
Contributor

now blue is irm reentrancy safe

this is unclear to me?

@MathisGD MathisGD changed the base branch from post-cantina to feat/skip-irm-0 December 11, 2023 13:34
@MerlinEgalite MerlinEgalite requested review from a team, adhusson, Rubilmax, QGarchery, MerlinEgalite and Jean-Grimal and removed request for a team December 11, 2023 13:39
Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

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

I'm a bit uncomfortable with this refactor, we're changing a lot of lines for no really big upsides

src/Morpho.sol Outdated Show resolved Hide resolved
src/Morpho.sol Outdated Show resolved Hide resolved
Base automatically changed from feat/skip-irm-0 to post-cantina December 12, 2023 15:11
MathisGD and others added 3 commits December 13, 2023 13:08
Co-authored-by: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com>
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
@Rubilmax
Copy link
Collaborator

Based on morpho-org/metamorpho#269, for a MetaMorpho vault with 10 markets and the AdaptiveCurveIRM, this PR makes a deposit on MM cost on avg 40k more (+5.5% of 715k, min +7k max +117k) which means on avg on a market it costs +4k gas to supply

The tests may not be relevant because 50% of the time, an interaction happens in the same block of another in the same market

Copy link
Collaborator

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

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

I feel like it will be costly at scale because I am so bullish Blue will become the base layer of lending that I expect multiple interactions in a single block
But at worst it leaves room for improvement for V2...

MathisGD and others added 2 commits December 18, 2023 11:27
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
Copy link
Contributor

@QGarchery QGarchery left a comment

Choose a reason for hiding this comment

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

Last argument against: we just skip the call of the IRM for idle markets, whereas we gained much more before. This is too bad, and I still think the changes in this PR are not worth the potential added gas cost and changing that many lines, but I'm not blocking it

@MathisGD MathisGD closed this Dec 19, 2023
@MathisGD MathisGD deleted the refactor/accrue-interest branch December 19, 2023 07:41
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