-
Notifications
You must be signed in to change notification settings - Fork 63
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
Conversation
There was a problem hiding this 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
increateMarket
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
if you are only talking about createMarket, this is easily fixable if we agree that it's a problem (I'm still not convinced)
it doesn't cost a lot, and simplifies the spec (accrue interest is always called when the accrueInterest is called).
what do you mean?
you mean that we increase the number of calls to the irm, which costs gas right?
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. |
The base branch was changed.
this is unclear to me? |
There was a problem hiding this 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
Co-authored-by: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com> Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
…tor/accrue-interest
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 |
There was a problem hiding this 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...
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
[Certora] Accrue interest fix
There was a problem hiding this 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
_accrueInterest
(before the write of lastUpdate)_accrueInterest
(always emitted)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