Skip to content

Feat: Fly2241 btc rbtc ratio management#937

Open
AndresQuijano wants to merge 7 commits intohot-cold-walletfrom
fly2241_btc_rbtc_ratio_management
Open

Feat: Fly2241 btc rbtc ratio management#937
AndresQuijano wants to merge 7 commits intohot-cold-walletfrom
fly2241_btc_rbtc_ratio_management

Conversation

@AndresQuijano
Copy link
Contributor

@AndresQuijano AndresQuijano commented Mar 18, 2026

What

This is the second part of the feature to make the BTC/RBTC liquidity ratio configurable instead of keep it as 50-50

Why

Give the chance to split the liquidity in a more convenient way for the liquidity provider

Depends on #933

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change
  • Documentation update
  • Refactoring (no functional changes, no api changes)
  • Performance improvement
  • Test updates
  • Security fix
  • Deployment/Infrastructure changes

Affected part of the project

  • Management UI / API
  • PegIn flow
  • PegOut flow
  • Utility scripts
  • Configuration files
  • Metrics and alerting

Related Issues

Jira ticket

How to test

Start the LPS in local and do the magic with the password.
Authenticate in the UI management.
Go to the next card for liquidity ratio and move the values around.
Check that, after an update, the cooldown gets activated

Reviewer Guidelines

The ratio was initially a configuration variable but with this PR it is moved to be a value that can be only updated via API
The not firing condition during cooldown was removed from low liquidity alerts by product manager recommendation

Screenshots (if applicable)

image

@AndresQuijano AndresQuijano force-pushed the fly2241_btc_rbtc_ratio_management branch from d6f7bcb to 988390f Compare March 18, 2026 20:43
@github-actions
Copy link

github-actions bot commented Mar 18, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

@AndresQuijano AndresQuijano marked this pull request as ready for review March 18, 2026 22:16
@AndresQuijano AndresQuijano requested a review from a team as a code owner March 18, 2026 22:16
@alexjavabraz alexjavabraz requested a review from Copilot March 19, 2026 15:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR completes the second part of making the BTC/RBTC liquidity ratio configurable via the Management API/UI (instead of via env/config), adding endpoints and UI to preview/apply ratio changes and persisting the ratio + cooldown in state configuration.

Changes:

  • Add GET/POST /management/liquidity-ratio endpoints plus UI slider + confirmation modal to preview and apply ratio changes.
  • Introduce GetLiquidityRatioUseCase (preview + impact computation) and SetLiquidityRatioUseCase (persist ratio + activate cooldown).
  • Remove BTC_LIQUIDITY_TARGET_PERCENTAGE env/config support and remove cooldown-based suppression from low-liquidity alerts.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/mocks/use_case_registry_mock.go Regenerated registry mock to include new liquidity-ratio use cases.
test/mocks/set_liquidity_ratio_use_case_mock.go New mock for SetLiquidityRatioUseCase handler tests.
test/mocks/get_liquidity_ratio_use_case_mock.go New mock for GetLiquidityRatioUseCase handler tests.
test/mocks/cold_wallet_mock.go Regenerated cold wallet mock (method ordering/signatures updated).
test/lp-swap/docker-compose.lps.yml Remove env passthrough for BTC_LIQUIDITY_TARGET_PERCENTAGE.
sample-config.env Remove BTC_LIQUIDITY_TARGET_PERCENTAGE sample entry.
pkg/liquidity_ratio.go Add request/response DTOs + mapping for liquidity ratio endpoints.
pkg/liquidity_provider_test.go Add unit test for ToLiquidityRatioResponse mapping.
internal/usecases/liquidity_provider/set_liquidity_ratio_test.go New unit tests for setting ratio + cooldown persistence.
internal/usecases/liquidity_provider/set_liquidity_ratio.go New use case to persist ratio changes and start cooldown.
internal/usecases/liquidity_provider/low_liquidity_alert_test.go Update tests for new alert use case constructor and behavior.
internal/usecases/liquidity_provider/low_liquidity_alert.go Remove cooldown-based skip from low-liquidity alerts.
internal/usecases/liquidity_provider/initialize_state_configuration_test.go Update initialization tests after removing env-driven ratio initialization.
internal/usecases/liquidity_provider/initialize_state_configuration.go Default ratio initialization moved to an internal constant (50) when unset.
internal/usecases/liquidity_provider/get_liquidity_ratio_test.go New unit tests for ratio preview/current computation and cooldown flags.
internal/usecases/liquidity_provider/get_liquidity_ratio.go New use case computing targets/thresholds/impacts for current or preview ratio.
internal/usecases/common.go Register new use case IDs.
internal/configuration/registry/usecase.go Wire new use cases into registry; update constructor call sites.
internal/configuration/environment/environment.go Remove env var parsing/defaults/validation for ratio percentage.
internal/adapters/entrypoints/watcher/liquidity_check_test.go Update watcher tests for updated low-liquidity alert constructor.
internal/adapters/entrypoints/rest/routes/routes_test.go Registry mock setup updated for new endpoints’ use cases.
internal/adapters/entrypoints/rest/routes/management_test.go Expect two additional management endpoints.
internal/adapters/entrypoints/rest/routes/management.go Add GET/POST management routes for liquidity ratio.
internal/adapters/entrypoints/rest/registry/registry.go Extend REST use case registry interface with new use cases.
internal/adapters/entrypoints/rest/handlers/set_liquidity_ratio_test.go New handler tests for POST set-liquidity-ratio.
internal/adapters/entrypoints/rest/handlers/set_liquidity_ratio.go New POST handler with JSON + validator-based request validation.
internal/adapters/entrypoints/rest/handlers/get_liquidity_ratio_test.go New handler tests for GET liquidity-ratio (with/without preview param).
internal/adapters/entrypoints/rest/handlers/get_liquidity_ratio.go New GET handler parsing optional btcPercentage query param.
internal/adapters/entrypoints/rest/assets/static/management.js Add UI logic for ratio slider, preview fetching, and saving via modal confirmation.
internal/adapters/entrypoints/rest/assets/static/management.css Add badge styles for ratio impact visualization.
internal/adapters/entrypoints/rest/assets/management.html Add Liquidity Ratio card and confirmation modal to management UI.
docs/Environment.md Remove documentation for deprecated env var.
docker-compose/mainnet/docker-compose.yml Remove env passthrough for deprecated ratio env var.
docker-compose/local/docker-compose.lps.yml Remove env passthrough for deprecated ratio env var.
docker-compose/docker-compose.yml Remove env passthrough for deprecated ratio env var.
OpenApi.yml Add schemas + paths for new management endpoints.
.mockery.yaml Ensure mockery generates mocks for new use cases.

You can also share your feedback on Copilot code review. Take the survey.

@AndresQuijano AndresQuijano changed the base branch from feat_fly2239_btc_rbtc_ratio to hot-cold-wallet March 20, 2026 14:51
}, nil
}

func calculateTarget(maxLiquidity *entities.Wei, percentage uint64) (*entities.Wei, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pls if the function is specific to the use case make it a receiver, even if it doesn't use the state of the use case, the reason of this is because otherwise it will be accesible from other use cases in the package, which can lead to errors in the future, if we move to use one use case per package in the future, this would be ok, but in the current set up I think it's not worth

Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment for the functions below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

)
}

func calculateThreshold(target *entities.Wei, tolerance liquidity_provider.ExcessTolerance) *entities.Wei {
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't this very similar to the one you used in the cold wallet use case? if yes you could create a separate package with utilities (doesn't need to be in this PR)

Copy link
Contributor Author

@AndresQuijano AndresQuijano Mar 23, 2026

Choose a reason for hiding this comment

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

Yes, good catch, refactored

const CooldownAfterRatioChange int64 = 10800 // 3 hours
const (
CooldownAfterRatioChange int64 = 10800 // 3 hours
DefaultBtcLiquidityTargetPercentage uint64 = 50
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be in the defaults file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved DefaultBtcLiquidityTargetPercentage to the default file but I think CooldownAfterRatioChange should live here

Copy link
Collaborator

Choose a reason for hiding this comment

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

you created a separate file called liquidity_ratio, I think you should do the same for the tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the tests to a separated file

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.

3 participants