Skip to content

Add stabilityFee parameter for Protocol Stability#105

Merged
UlyanaAndrukhiv merged 47 commits intomainfrom
UlianaAndrukhiv/85-stability
Jan 27, 2026
Merged

Add stabilityFee parameter for Protocol Stability#105
UlyanaAndrukhiv merged 47 commits intomainfrom
UlianaAndrukhiv/85-stability

Conversation

@UlyanaAndrukhiv
Copy link
Copy Markdown
Contributor

@UlyanaAndrukhiv UlyanaAndrukhiv commented Jan 13, 2026

Closes: #85

Context

Implements a new stabilityFeeRate parameter for the FlowCreditMarket protocol 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:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@UlyanaAndrukhiv
Copy link
Copy Markdown
Contributor Author

@turbolent, @Gornutz, could you please review the contract part changes of this PR when you get a chance? Thanks in advance!

Copy link
Copy Markdown
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice, looks good from a Cadence code quality perspective 👍
Didn't review the actual logic

Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Copy link
Copy Markdown
Contributor

@Gornutz Gornutz left a comment

Choose a reason for hiding this comment

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

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%

Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
// 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>() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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%.

  1. If we have a fixed rate curve, we will calculate creditRate = 0.1-0.05 = 0.05 = 5%.
  • We interpret protocolFeeRate/insuranceRate as a percentage of a total debit balance
  1. If we have a different rate curve, we will calculate creditRate = (0.1)(1-0.05)(debitBalance/creditBalance)
  • If debitBalance/creditBalance is close to 1, then creditRate ~= 0.95 = 9.5%.
  • We interpret protocolFeeRate/insuranceRate as a percentage of a debit income

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My understanding is that the protocol fees should be interpreted as a percentage of debit income, based on #105 (review).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 😅.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 2bbc399

Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
@UlyanaAndrukhiv UlyanaAndrukhiv changed the base branch from main to kan/insurance-rate-stability-rate January 21, 2026 12:04
…CreditMarket into UlianaAndrukhiv/85-stability
…/FlowCreditMarket into UlianaAndrukhiv/85-stability
@UlyanaAndrukhiv UlyanaAndrukhiv marked this pull request as ready for review January 22, 2026 16:38
@UlyanaAndrukhiv UlyanaAndrukhiv requested a review from a team as a code owner January 22, 2026 16:38
@UlyanaAndrukhiv UlyanaAndrukhiv changed the title [Draft] Add stabilityFee parameter for Protocol Stability Add stabilityFee parameter for Protocol Stability Jan 22, 2026
Comment thread cadence/contracts/FlowCreditMarket.cdc
Comment thread docs/interest_rate_and_insurance_mechanism.md Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc
Comment thread cadence/contracts/FlowCreditMarket.cdc
Comment thread cadence/tests/stability_collection_test.cdc Outdated
Comment thread cadence/tests/stability_collection_test.cdc Outdated
Comment thread docs/interest_rate_and_protocol_fees.md Outdated
Comment thread docs/interest_rate_and_protocol_fees.md
@UlyanaAndrukhiv
Copy link
Copy Markdown
Contributor Author

UlyanaAndrukhiv commented Jan 27, 2026

@Gornutz or @Kay-Zee would you mind taking a final look at it? Thanks!

Base automatically changed from kan/insurance-rate-stability-rate to main January 27, 2026 14:52
@UlyanaAndrukhiv UlyanaAndrukhiv merged commit 431e8f0 into main Jan 27, 2026
1 check passed
@UlyanaAndrukhiv UlyanaAndrukhiv deleted the UlianaAndrukhiv/85-stability branch January 27, 2026 15:06
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.

Add stabilityFee parameter for Protocol Stability

5 participants