Feat: Fly2241 btc rbtc ratio management#937
Feat: Fly2241 btc rbtc ratio management#937AndresQuijano wants to merge 7 commits intohot-cold-walletfrom
Conversation
d6f7bcb to
988390f
Compare
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files |
There was a problem hiding this comment.
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-ratioendpoints plus UI slider + confirmation modal to preview and apply ratio changes. - Introduce
GetLiquidityRatioUseCase(preview + impact computation) andSetLiquidityRatioUseCase(persist ratio + activate cooldown). - Remove
BTC_LIQUIDITY_TARGET_PERCENTAGEenv/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.
internal/usecases/liquidity_provider/set_liquidity_ratio_test.go
Outdated
Show resolved
Hide resolved
| }, nil | ||
| } | ||
|
|
||
| func calculateTarget(maxLiquidity *entities.Wei, percentage uint64) (*entities.Wei, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
same comment for the functions below
| ) | ||
| } | ||
|
|
||
| func calculateThreshold(target *entities.Wei, tolerance liquidity_provider.ExcessTolerance) *entities.Wei { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Yes, good catch, refactored
| const CooldownAfterRatioChange int64 = 10800 // 3 hours | ||
| const ( | ||
| CooldownAfterRatioChange int64 = 10800 // 3 hours | ||
| DefaultBtcLiquidityTargetPercentage uint64 = 50 |
There was a problem hiding this comment.
shouldn't this be in the defaults file?
There was a problem hiding this comment.
I moved DefaultBtcLiquidityTargetPercentage to the default file but I think CooldownAfterRatioChange should live here
There was a problem hiding this comment.
you created a separate file called liquidity_ratio, I think you should do the same for the tests
There was a problem hiding this comment.
I moved the tests to a separated file
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
Affected part of the project
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)