Skip to content

fix: cache oracle keypair, remove dead replay code, fix pnlPct (L1+L2+L7)#97

Open
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:fix/l1-l2-l7-keypair-dead-code-pnlpct
Open

fix: cache oracle keypair, remove dead replay code, fix pnlPct (L1+L2+L7)#97
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:fix/l1-l2-l7-keypair-dead-code-pnlpct

Conversation

@0x-SquidSol
Copy link
Copy Markdown
Contributor

@0x-SquidSol 0x-SquidSol commented Apr 9, 2026

Summary

Three low-severity cleanups:

L1 — Oracle keypair not cached:

  • loadKeypair() called on every pushPrice() invocation, re-parsing from env/disk each cycle
  • Now cached as private readonly _keypair at construction, matching all other services

L2 — Dead signature replay tracking:

  • recentSignatures Maps in CrankService and LiquidationService were written to but never read
  • No .has() or .get() calls existed — the "BC1: Signature replay protection" was dead code
  • Removed Maps, TTL constants, .set() calls, and cleanup loops from both services
  • Solana's runtime already prevents signature replay at the protocol level

L7 — ADL pnlPct display off by 100x:

  • Divided by 1,000,000 then appended %, showing 30% as "0.3000%"
  • Now divides by 10,000 to correctly display as "30.00%"

Test plan

  • All 133 tests pass
  • Net -23 lines of dead code removed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Style

    • Updated PNL percentage display format for improved readability.
  • Refactor

    • Streamlined transaction signature handling mechanisms across services.
    • Optimized keypair initialization to enhance efficiency.

…y (L1+L2+L7)

L1: OracleService called loadKeypair() on every pushPrice() invocation,
re-parsing the keypair from env/disk each cycle. Now cached as a class
field at construction, matching CrankService/LiquidationService/AdlService.

L2: recentSignatures Maps in CrankService and LiquidationService were
written to but never read — no .has() or .get() calls existed. The
"BC1: Signature replay protection" was dead code. Removed the Maps,
TTL constants, .set() calls, and cleanup loops from both services.
Solana's runtime already prevents signature replay at the protocol level.

L7: ADL pnlPct display divided by 1_000_000 then appended %, showing
30% as "0.3000%". Now divides by 10_000 (= 1M/100) to correctly
display as "30.00%".

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

coderabbitai Bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ab48065f-c762-4a48-bc45-8459ff70c405

📥 Commits

Reviewing files that changed from the base of the PR and between 3280971 and 62136f5.

📒 Files selected for processing (4)
  • src/services/adl.ts
  • src/services/crank.ts
  • src/services/liquidation.ts
  • src/services/oracle.ts
💤 Files with no reviewable changes (2)
  • src/services/liquidation.ts
  • src/services/crank.ts

📝 Walkthrough

Walkthrough

This PR modifies four service files to streamline transaction handling and logging: adjusts ADL PnL percentage formatting, removes in-memory signature replay-protection maps from crank and liquidation services, and refactors oracle service to initialize keypair once at construction rather than per-call.

Changes

Cohort / File(s) Summary
ADL Logging Format
src/services/adl.ts
Updated pnlPct value logging by changing the fixed-point scaling factor from 1_000_000 to 10_000 and reformatting output from toFixed(4) to toFixed(2) with a % suffix.
Signature Replay Protection Removal
src/services/crank.ts, src/services/liquidation.ts
Eliminated in-memory replay-protection mechanisms: removed recentSignatures map, signatureTTLMs TTL configuration, signature-recording logic in the success path, and periodic cleanup routines.
Oracle Keypair Caching
src/services/oracle.ts
Moved keypair initialization from per-call loading in pushPrice() to a single construction-time initialization via private readonly _keypair field, replacing repeated environment parsing with reusable cached instance.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Hop, hop, through the code we go,
Signatures cleaned, fresh paths to show,
Keypairs cached, no loading twice,
Numbers formatted, all precise—
Hopping lighter, faster, right!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes all three main changes: oracle keypair caching, removal of dead replay code, and pnlPct display fix, with specific layer identifiers (L1+L2+L7).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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