Skip to content

fix: prevent oracle deviation check from permanently bricking markets (H1)#84

Open
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:fix/h1-oracle-deviation-anchor-lock
Open

fix: prevent oracle deviation check from permanently bricking markets (H1)#84
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:fix/h1-oracle-deviation-anchor-lock

Conversation

@0x-SquidSol
Copy link
Copy Markdown
Contributor

Summary

  • The 30% historical deviation check rejected fast-moving prices but never recorded the rejection in price history
  • The old anchor price persisted forever, causing every subsequent fetch to also be rejected
  • Markets were permanently bricked until keeper restart (which clears in-memory priceHistory)

Fix

Add a consecutive rejection counter per market (deviationRejections Map):

  • After 5 consecutive cross-validated prices are rejected, accept the price as a legitimate move
  • Counter resets whenever a normal price is accepted (no lingering state)
  • Recovery time: ~25 seconds (5 cycles × ~5s rate limit)

Why this is safe

  • Cross-validation (DexScreener + Jupiter within 10%) already guards against bad data
  • A single bad data point only counts as 1 rejection — nowhere near the threshold of 5
  • Intermittent bad data (2 bad, 1 good, 2 bad) resets the counter on each good fetch

Test plan

  • H1: accepts deviated price after 5 consecutive rejections (no permanent brick)
  • H1: resets rejection counter when a normal price is accepted
  • All 47 oracle deviation tests pass
  • All 135 tests pass across full suite

🤖 Generated with Claude Code

… (H1)

The 30% historical deviation check rejected prices that moved too fast
but never recorded the rejected price in history. This meant the old
anchor price persisted forever, and every subsequent fetch at the new
(legitimate) price was also rejected — permanently bricking the oracle
for that market until the keeper process was restarted.

Add a consecutive rejection counter per market. After 5 consecutive
cross-validated prices are rejected by the deviation check, accept
the price as a legitimate move and update the anchor. This:
- Still filters single bad data points (1 out of 5 won't pass)
- Recovers automatically in ~25s (5 cycles at ~5s each)
- Resets the counter whenever a normal price is accepted
- Requires no process restart for recovery

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

Warning

Rate limit exceeded

@0x-SquidSol has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 45 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 45 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 09b675fc-afe0-49a6-a01b-01446417690c

📥 Commits

Reviewing files that changed from the base of the PR and between 63ad1a0 and 3b1767b.

📒 Files selected for processing (2)
  • src/services/oracle.ts
  • tests/services/oracle-deviation.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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