Skip to content

Start on insurance fund implementation#75

Merged
UlyanaAndrukhiv merged 67 commits intomainfrom
kan/insurance-rate-stability-rate
Jan 27, 2026
Merged

Start on insurance fund implementation#75
UlyanaAndrukhiv merged 67 commits intomainfrom
kan/insurance-rate-stability-rate

Conversation

@Kay-Zee
Copy link
Copy Markdown
Member

@Kay-Zee Kay-Zee commented Dec 12, 2025

Closes: #84

Description

Implementation of insurance fund


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

Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc
@Kay-Zee Kay-Zee changed the title Start on interest rate implementation Start on insurance fund implementation Dec 24, 2025
@vishalchangrani
Copy link
Copy Markdown
Contributor

Tracked by Issue: #84

Comment on lines +33 to +35
debitIncome = totalDebitBalance * debitRate
insuranceAmount = totalCreditBalance * insuranceRate
creditRate = (debitIncome - insuranceAmount) / totalCreditBalance
Copy link
Copy Markdown
Contributor

@mts1715 mts1715 Jan 7, 2026

Choose a reason for hiding this comment

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

More clearly:
creditRate = debitRate * (totalDebitBalance / totalCreditBalance) - insuranceRate

Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc Outdated
Comment thread cadence/contracts/FlowCreditMarket.cdc
Comment thread cadence/contracts/FlowCreditMarket.cdc
import "MockDexSwapper"
import "DeFiActions"

/// TEST-ONLY: Test transaction to configure a MockDexSwapper as the insurance swapper for a token.
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.

This transaction hard-codes a MOET-typed source for swapped funds but allows specifying a different output type for the created Swapper. I think we should:

  • change the file name and documentation to reflect that this will always swap to MOET
  • remove the swapperOutTypeIdentifier parameter and hard-code it to MOET

Copy link
Copy Markdown
Contributor

@UlyanaAndrukhiv UlyanaAndrukhiv Jan 26, 2026

Choose a reason for hiding this comment

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

I intentionally kept swapperOutTypeIdentifier configurable in this test transaction so we can explicitly test the validation logic in setInsuranceSwapper.

In particular, this allows us to verify that the function correctly rejects invalid swappers and triggers the expected error:
Swapper output type must be MOET. If the transaction hard-codes the output type to MOET, these failure paths would no longer be testable via transactions.

I also updated the documentation (942a305) for cadence/tests/transactions/flow-credit-market/pool-governance/set_insurance_swapper_mock.cdc to clarify that this flexibility is intended for test-only use.
For production usage, there is a dedicated transaction at:
cadence/transactions/flow-credit-market/pool-governance/set_insurance_swapper.cdc

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.

Makes sense -- thanks for explaining + adding that to the docs

Comment thread cadence/tests/insurance_collection_formula_test.cdc
Comment thread cadence/tests/insurance_rate_test.cdc Outdated
Comment thread cadence/tests/insurance_swapper_test.cdc Outdated
Comment thread docs/interest_rate_and_insurance_mechanism.md Outdated
Copy link
Copy Markdown
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

Reviewed the diff since my last review. Looks good besides the coverage file.

Comment thread lcov.info Outdated
@UlyanaAndrukhiv
Copy link
Copy Markdown
Contributor

@Gornutz, @liobrasil, since you’ve already reviewed this PR, would you mind taking a final look so we could merge it? Thanks!

@UlyanaAndrukhiv UlyanaAndrukhiv merged commit 56d92d6 into main Jan 27, 2026
1 check passed
@UlyanaAndrukhiv UlyanaAndrukhiv deleted the kan/insurance-rate-stability-rate branch January 27, 2026 14:52
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.

Insurance fund implementation

8 participants