Skip to content

Add liquidation risk simulation CLI for Sovryn#298

Open
Baliram77 wants to merge 2 commits intorsksmart:mainfrom
Baliram77:feature/liquidation-risk
Open

Add liquidation risk simulation CLI for Sovryn#298
Baliram77 wants to merge 2 commits intorsksmart:mainfrom
Baliram77:feature/liquidation-risk

Conversation

@Baliram77
Copy link
Copy Markdown

@Baliram77 Baliram77 commented Mar 16, 2026

This PR adds a new risk command group for liquidation stress testing:

  • rsk-cli risk simulate --shock : run Sovryn v1 liquidation simulations under price shocks
  • rsk-cli risk sandbox --ltv --threshold : compare default vs custom risk parameters
  • rsk-cli risk report --format json|table: structured stress-test output (CI/CD friendly)

Implementation details:

  • New risk engine under src/services/risk/ (types, data sources, engine, reporting).
  • Sovryn v1 positions fetched from the public subgraph, mapped into BorrowPosition and priced via CoinGecko.
  • Logging and spinners use the existing logger and spinner utilities with isExternal flag, so the feature is safe to use both in the CLI and MCP server.
  • README updated with a “Liquidation Risk (Stress Testing)” section and example usage.

Testing

  • npm run build
  • node dist/bin/index.js risk simulate --shock 40
  • node dist/bin/index.js risk sandbox --ltv 65 --threshold 80
  • rsk-cli risk simulate --shock 40 --asset rbtc (if this isin't work run this first npm link)
  • node dist/bin/index.js risk report --format json (may occasionally hit CoinGecko 429 rate limits)

@Baliram77
Copy link
Copy Markdown
Author

Thanks for the review — I pushed a follow-up commit (4dc54b9) addressing all findings:

  • Normalized Sovryn amounts with decimals handling (wei/decimal-safe).
  • Fixed stablecoin pricing (usd treated as $1; XUSD/DOC map to usd, no invalid CoinGecko id).
  • Added timeouts to CoinGecko + subgraph calls and routed live paths through the timeout-aware helper.
  • Unified liquidation eligibility logic and removed the 5-step cap undercount issue.
  • Added input validation (NaN rejection, enforce 0 < shock < 100).
  • Implemented insolvency threshold estimation via binary search.
  • Added Sovryn pagination beyond 1000 results.
  • Extracted formatNumber to src/utils/format.ts.
  • Removed // comments in the risk-related files.
  • Tested: npm run build, risk simulate, risk sandbox, risk report.

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.

1 participant