Add stabilityFee parameter for Protocol Stability#105
Conversation
|
@turbolent, @Gornutz, could you please review the contract part changes of this PR when you get a chance? Thanks in advance! |
turbolent
left a comment
There was a problem hiding this comment.
Nice, looks good from a Cadence code quality perspective 👍
Didn't review the actual logic
There was a problem hiding this comment.
Actually noticed that with the current implementation that we can run into underflow issues if we a have a insuranceRate or stabilityFeeRate that is greater than the interest that's be generated. As we are subtracting that flat out instead of it being a proportional % to the total amount of interest being collected.
For a mental model that the two insuranceRate and stabilityFeeRate's behave very similar to AAVE's reserve rate. With how the fee amount generated is proportional to the interest generated, instead of it being a flat hurdle rate.
For an example with the current implementation and we have the following -
Current 10% Borrow Rate, 0.1% insurance, 5% stability -> 10% - 0.1% - 5% = 4.9%
then with the proportional model
10% Borrow Rate, 0.1% insurance, 5% stability -> 10% * (1 - (0.1% + 5%)) = 9.49%
Then if the borrow Rate was 3%
Current 3% Borrow Rate, 0.1% insurance, 5% stability -> 3% - 0.1% - 5% = -2.1%
then with the proportional model
3% Borrow Rate, 0.1% insurance, 5% stability -> 3% * (1- (0.1% + 5%)) = 2.85%
Co-authored-by: Bastian Müller <bastian@turbolent.com>
…CreditMarket into UlianaAndrukhiv/85-stability
…last_stability_collection script. Added test helpers
| // 2. KinkInterestCurve (and others): reserve factor model | ||
| // Insurance is a percentage of interest income, not a fixed spread | ||
| // Insurance and stability are percentages of interest income, not a fixed spread | ||
| if self.interestCurve.getType() == Type<FlowCreditMarket.FixedRateInterestCurve>() { |
There was a problem hiding this comment.
Currently the protocol fees can have wildly different values depending on the interest rate curve being used. I'm guessing this is a mistake (from a prior PR), but if it is desired we should clearly document why it is desired, and document how protocolFeeRate and insuranceRate can be interpreted in different ways.
For example, suppose the debit interest rate is 10% and the protocol fee rate is 5%.
- If we have a fixed rate curve, we will calculate
creditRate = 0.1-0.05 = 0.05 = 5%.
- We interpret
protocolFeeRate/insuranceRateas a percentage of a total debit balance
- If we have a different rate curve, we will calculate
creditRate = (0.1)(1-0.05)(debitBalance/creditBalance)
- If
debitBalance/creditBalanceis close to 1, thencreditRate ~= 0.95 = 9.5%. - We interpret
protocolFeeRate/insuranceRateas a percentage of a debit income
There was a problem hiding this comment.
My understanding is that the protocol fees should be interpreted as a percentage of debit income, based on #105 (review).
There was a problem hiding this comment.
I also feel like that fact that we need to inspect the InterestCurve's implementation type here indicates that the current InterestCurve is a poor abstraction. This is literally the only usage of InterestCurve in the whole smart contract -- we should be able to use it without breaking that abstraction 😅.
Co-authored-by: Jordan Schalm <jordan.schalm@gmail.com>
…CreditMarket into UlianaAndrukhiv/85-stability
…/FlowCreditMarket into UlianaAndrukhiv/85-stability
…/FlowCreditMarket into UlianaAndrukhiv/85-stability
…/FlowCreditMarket into UlianaAndrukhiv/85-stability
Co-authored-by: Jordan Schalm <jordan.schalm@gmail.com>
…/FlowCreditMarket into UlianaAndrukhiv/85-stability
…/FlowCreditMarket into UlianaAndrukhiv/85-stability
Closes: #85
Context
Implements a new
stabilityFeeRateparameter for theFlowCreditMarketprotocol that enables collecting stability fees from interest income to support stability.The implementation follows the proposed solution from the issue discussion, with a default stability fee rate of
5%.For contributor use:
masterbranchFiles changedin the Github PR explorer