Skip to content

feat(frontend): keeper profitability scatter plot mechanism#655

Open
Adeolu01 wants to merge 1 commit into
SoroLabs:mainfrom
Adeolu01:feat/625-keeper-profitability-scatter-plot
Open

feat(frontend): keeper profitability scatter plot mechanism#655
Adeolu01 wants to merge 1 commit into
SoroLabs:mainfrom
Adeolu01:feat/625-keeper-profitability-scatter-plot

Conversation

@Adeolu01

Copy link
Copy Markdown

Summary

Implements the Keeper Profitability Scatter Plot mechanism (issue #625): a reliable visualisation of keeper profit versus execution volume that handles network partitions and RPC failures gracefully.

All work is additive — no existing files are modified. New code lives under frontend/src/lib/keeper-profitability, frontend/src/components/keeper-profitability, and frontend/src/hooks/useKeeperProfitability.ts.

Resilient data pipeline (resilientSource.ts)

The data source wraps any economics fetcher and never rejects — every call resolves to a result with an explicit connection status, so the chart keeps rendering through outages:

  • Per-attempt timeout via AbortController aborts a hung RPC.
  • Exponential backoff with full jitter between retries.
  • Circuit breaker opens after consecutive failures, serves cached data while open, then allows a single trial fetch after a cooldown.
  • Stale-while-error cache (live → degraded → stale → offline) with TTL expiry.
  • Partial-data tolerance: invalid RPC rows are dropped, not fatal, and reported via droppedRecords / degraded.

Pure computation core (profitability.ts)

No I/O or DOM, fully deterministic: profit/margin/ROI, linear scales, point projection, an OLS trend line, and summary statistics — exhaustively unit tested.

React & UI

  • useKeeperProfitability: polling hook with in-flight cancellation and graceful degradation, stable against unstable config props.
  • KeeperProfitabilityChart: dependency-free SVG scatter plot with a break-even baseline, tier colouring (profitable/break-even/loss), accessible focusable points with tooltips, a colour legend, a summary panel, and a connection-status banner with manual retry. Renders meaningfully in loading, live, degraded, stale, and offline states.

Testing

  • 49 unit/integration tests covering the maths (all branches), the resilient source (retries, backoff bounds, circuit open/cooldown/reset, stale cache, TTL expiry, timeout, abort), the hook, and every UI component including loading/offline/empty states.
  • Feature coverage: 97% statements / 93% branches / 95% functions — exceeds the >90% requirement.
npx jest src/lib/keeper-profitability src/hooks/__tests__/useKeeperProfitability src/components/keeper-profitability

Documentation

frontend/docs/KEEPER_PROFITABILITY_SCATTER.md documents the architecture, resilience model, plot semantics, and usage.

Acceptance criteria

  • Feature implemented to requirements (resilient to RPC failures and network partitions)
  • Unit and integration tests passing (>90% coverage)
  • Security review: input validation on all RPC rows, no unsafe eval/DOM injection, bounded retries
  • Comprehensive documentation

closes #625

Implements a resilient Keeper Profitability scatter plot that handles network
partitions and RPC failures gracefully.

- ResilientSource: wraps any economics fetcher with per-attempt timeouts,
  exponential backoff with full jitter, a circuit breaker, and a
  stale-while-error cache. It never rejects — every call resolves to a result
  with an explicit connection status (live, degraded, stale, offline) and a
  dropped-records count for partial data.
- profitability.ts: pure, deterministic maths for profit/margin/ROI, linear
  scales, point projection, an OLS trend line, and summary statistics.
- useKeeperProfitability: polling hook with in-flight cancellation and graceful
  degradation, stable against unstable config props.
- KeeperProfitabilityChart: dependency-free SVG scatter plot with a break-even
  baseline, tier colouring, accessible focusable points and tooltips, a colour
  legend, summary panel, and a connection-status banner with manual retry.
- 49 unit/integration tests; 97% statements / 93% branch coverage on the
  feature, plus documentation in docs/KEEPER_PROFITABILITY_SCATTER.md.
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@Adeolu01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@GBOYEE

GBOYEE commented Jun 28, 2026

Copy link
Copy Markdown

@GBOYEE has applied to work on this issue as part of the Stellar Wave Program's 6th wave.

Implement following existing patterns and conventions. Add tests, ensure CI passes, and document any new API surface.

ℹ️ Repo Maintainers: To accept this application, review their application or assign @GBOYEE to this issue.

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.

[Frontend] Construct Keeper Profitability Scatter Plot Mechanism

2 participants