VAL-129 [Refactor] Switch to per-lender "crank" that iterates over snapshots #179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The diff looks huge, but the vast majority of that is tweaking existing tests and adding new ones.
Per convo on Slack, this is a refactor (actually simplification) of the Pool "snapshot" and the per-lender mechanism for "claiming" their portion of the snapshotted funds. Instead of a direct computation using aggregated values, this iterates over the interim snapshots from the time a lender requested and accumulates shares / assets according to each snapshot "redeemableRate" and "fxRate". The global snapshot is still constant-time and run lazily on mutating events (as before).
There are two new functions exposed to the Pool/WithdrawController (very open to feedback on naming and the signatures of these):
claimSnapshots(uint256 limit)
--> iterates of "n == limit" snapshots to "catch up" the lender. This updates the lender's withdrawState -- movingeligibleShares
over toredeemableShares
according to each snapshot.needsClaim() view returns bool
--> signals whether a lender is "caught up" or not.The semantics change slightly, as there's less lazy magic as before. A simple pseudo code scenario to explain:
Basically, a lender will now explicitly need to
claimSnapshots
before their redeemableAssets get allocated. This seems simpler to reason about -- money moves explicitly, and things likemaxRedeem()
simply read from the state vs. doing an invisible computation.This fixes the specific audit issue, and also eliminates some of the "dust" quirks of the direction computation approach.