Skip to content

Add stabilityFee parameter for Protocol Stability #85

@vishalchangrani

Description

@vishalchangrani

Related issue

Related PR

Context

Introduce a new stabilityFeeRate parameter that is applied in updateInterestRates by reducing debitIncome.

The combination of insuranceRate + stabilityFeeRate would be deducted from the amount paid out to lenders.

Funds collected via stabilityFeeRate can be withdrawn from the protocol by the owner and used to ensure the stability of MOET. This is a more permissioned feature than insuranceRate, which is intended to remain within the protocol and not be extracted.

This task includes integrating stabilityFeeRate into interest rate calculations and ensuring the collected funds are properly tracked and withdrawable.

Proposed solution

Stability Fee Implementation

  1. Add fields to TokenState + initialize defaults in init().
access(all) var stabilityFeeRate: UFix64
access(all) var lastStabilityFeeCollection: UFix64
  1. Add setters for stabilityFeeRate and lastStabilityFeeCollection with access(EImplementation).
  2. Add Add stabilityFunds map to Pool resource + initialize.

access(self) var stabilityFunds: @{Type: {FungibleToken.Vault}}

  1. Update updateInterestRates() function to include stability fee.
  • FixedRateInterestCurve:
    creditRate = debitRate - insuranceRate - stabilityFee

  • KinkInterestCurve:

stabilityAmount = totalCreditBalance * stabilityFee
creditRate = (debitIncome - insuranceAmount - stabilityAmount) / totalCreditBalance
  1. Add collectStabilityFee() function.
    Similar to collectInsurance() but simpler - no swap, just withdraw from reservesand return vault.
    (collectInsurance() impl here)

  2. Update the logic and renameupdateInterestRatesAndCollectInsurance() to updateInterestRatesAndCollectFees().
    (updateInterestRatesAndCollectInsurance() impl here)

  3. Update Pool resource with additional functions.

access(EGovernance) fun setStabilityFeeRate(tokenType: Type, stabilityFeeRate: UFix64)
access(EGovernance) fun withdrawStabilityFund(tokenType: Type, amount: UFix64, recipient: &{FungibleToken.Receiver})
access(all) view fun stabilityFundBalance(tokenType: Type): UFix64

Questions to discuss

  1. What should be the default value for stabilityFeeRate?
  2. Should events be added for stabilityFeeRate and lastStabilityFeeCollection updates?
  3. What access control should the stability fund withdrawal function have - EGovernance or another entitlement?
  4. Who manages the logic that determines when stability fund withdrawals occur?

Metadata

Metadata

Labels

QS FCM Audit First RoundTask to address QuantStamp Audit comments from their first round of review of the FCM contracts.⎈ QuantStampThis issue is related to QuantStamp review comment

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions