FLO-2: setInsuranceRate() and setStabilityFeeRate() Retroactively Applies New Rates and Fails to Update Interest Rates#254
Open
UlyanaAndrukhiv wants to merge 8 commits intomainfrom
Conversation
UlyanaAndrukhiv
commented
Mar 10, 2026
Comment on lines
+563
to
+573
| // NOTE: | ||
| // We intentionally do not use `equalWithinVariance` with `defaultUFixVariance` here. | ||
| // The default variance is designed for deterministic math, but insurance collection | ||
| // depends on block timestamps, which can differ slightly between test runs. | ||
| // A larger, time-aware tolerance is required. | ||
| let expectedCollectedInsuranceAmount= expectedCollectedInsuranceAmountAfterPhase1 + expectedCollectedInsuranceAmountAfterPhase2 // 5.25854589 + 10.51709179 | ||
| diff = expectedCollectedInsuranceAmount > insuranceAfterPhase2 | ||
| ? expectedCollectedInsuranceAmount - insuranceAfterPhase2 | ||
| : insuranceAfterPhase2 - expectedCollectedInsuranceAmount | ||
|
|
||
| Test.assert(diff < tolerance, message: "Insurance collected should be around \(expectedCollectedInsuranceAmount) but current \(insuranceAfterPhase2)") |
Contributor
Author
There was a problem hiding this comment.
This code was updated to use the equalWithinVariance helper with a custom variance in the refactoring PR
jordanschalm
approved these changes
Mar 11, 2026
Member
jordanschalm
left a comment
There was a problem hiding this comment.
Looks good.
Reviewing this I realized there is some tension between our solutions for FLO-1 and FLO-2:
- For FLO-1, our solution to avoid failing to collect protocol fees is to skip collection until there is sufficient reserves.
- For FLO-2, we add a collection at the time of rate change, and rely on this collection to ensure fees due under the old rate are collected first.
If we do a rate change when there is insufficient reserves to pay the fees, then we will skip the collection and will over/under-collect the fees for the previous period under the new rate.
I don't think we need to solve this right now, but I think it is worth documenting as a known edge case. @UlyanaAndrukhiv Do you mind documenting this alongside the protocol fee logic, either in this PR, or the one for FLO-1?
…low/FlowCreditMarket into UlianaAndrukhiv/211-update-fee-rates
Co-authored-by: Jordan Schalm <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes: #211
Context
This PR forces fee collection and interest rate updates before applying the new rate, ensuring:
updateInterestRates()is triggered socurrentCreditRateremains consistentNew tests were added, and some tests were updated according to these changes.