Skip to content

fix: add keeper wallet SOL balance monitoring (C4)#82

Open
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:fix/c4-sol-balance-monitoring
Open

fix: add keeper wallet SOL balance monitoring (C4)#82
0x-SquidSol wants to merge 1 commit intodcccrypto:mainfrom
0x-SquidSol:fix/c4-sol-balance-monitoring

Conversation

@0x-SquidSol
Copy link
Copy Markdown
Contributor

Summary

  • The keeper wallet pays transaction fees but had zero balance monitoring — when SOL ran out, all transactions silently failed
  • Adds startup + periodic (60s) balance checks via connection.getBalance()
  • Alerts via Discord at 0.05 SOL (warning) and 0.01 SOL (critical)
  • Health endpoint degrades to "down" when balance is critical (can't send txs)
  • Exposes wallet section in /health response with address, balance, and status

What's added

Feature Detail
Startup log Wallet address + balance logged on boot
Periodic check Every 60s, piggybacks on existing stale oracle interval
Warning alert At 0.05 SOL — sendWarningAlert to Discord
Critical alert At 0.01 SOL — sendCriticalAlert to Discord
Alert rate-limiting Max one alert per 5 minutes
Health endpoint wallet.address, wallet.balanceLamports, wallet.balanceSol, wallet.balanceStatus
Health degradation Balance < 0.01 SOL → status "down" (HTTP 503)
Error handling Balance check failure logged at debug, never crashes keeper

Test plan

  • All 133 existing tests pass
  • Zero type errors in index.ts (pre-existing SDK type errors unrelated)
  • Balance check wrapped in try/catch — RPC failure is non-fatal
  • checkWalletBalance tested implicitly via startup flow

🤖 Generated with Claude Code

The keeper wallet pays transaction fees for all cranks, liquidations,
oracle pushes, and ADL operations. Previously, when the wallet ran out
of SOL, all transactions silently failed with no alert, no log, and no
health degradation.

Add SOL balance monitoring:
- Log wallet address at startup
- Check balance at startup and every 60s (piggybacks on stale oracle interval)
- Warn at 0.05 SOL, critical alert at 0.01 SOL via Discord
- Rate-limit alerts to once per 5 minutes
- Expose wallet balance in /health endpoint response
- Degrade health status to "down" when balance is critical
- Include balance in startup Discord notification
- All balance checks are non-fatal (try/catch, never crashes keeper)

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 16 minutes and 14 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 16 minutes and 14 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: 44c6ebf3-a5b6-4ba4-8350-e567a85cbfd2

📥 Commits

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

📒 Files selected for processing (1)
  • src/index.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