Skip to content

netqo/vaultwatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VaultWatch - ERC-4626 Deposit Monitor

ci Rust 2021 License: MIT

A lightweight Rust bot that monitors any ERC-4626 vault for deposit availability and sends a Telegram notification when capacity opens up.

How It Works

  1. Polls the configured vault contract at a configurable interval (default: 30s).
  2. Calls maxDeposit(address) to get the current available deposit capacity.
  3. Calls totalAssets() for informational context.
  4. If available >= DEPOSIT_THRESHOLD, fires a Telegram alert and logs to console.
  5. Alert cooldown: Telegram only fires once per above-threshold window. Resets when available drops below 95% of the threshold (hysteresis, so a vault that oscillates around the threshold does not alert every poll).
  6. The cooldown flag is persisted to STATE_FILE (default ./vaultwatch.state) so a restart while the slot is still open does not re-alert.
  7. Sends a startup notification to Telegram on launch so you know the bot is online.

Configuration

All configuration is done via environment variables (.env file):

Variable Required Description Example
RPC_URL yes Ethereum JSON-RPC endpoint https://ethereum.publicnode.com
VAULT_ADDRESS yes ERC-4626 vault contract address 0x99CD4Ec3f88A45940936F469E4bB72A2A701EEB9
VAULT_NAME no Display name for logs (default: ERC-4626 Vault) stUSDS
TOKEN_DECIMALS no Token decimal precision (default: 18) 18
DEPOSIT_THRESHOLD no Min available to trigger alert (default: 2000) 2000
POLL_INTERVAL_SECS no Seconds between polls (default: 30) 30
TELEGRAM_BOT_TOKEN no Telegram Bot API token 123456:ABC-DEF...
TELEGRAM_CHAT_ID no Target chat/channel ID -1001234567890
STATE_FILE no Path to the cooldown state file (default: ./vaultwatch.state) /var/lib/vaultwatch/state.json

Telegram fields are optional. If both are set, the bot sends alerts; otherwise it runs in console-only mode.

Project Structure

src/
  main.rs        -- entry point, wiring only
  config.rs      -- Config struct, env loading, banner
  contract.rs    -- ERC-4626 ABI binding, connect, poll logic
  fmt.rs         -- token formatting, fill percentage, timestamp
  log.rs         -- colored console logging with prefixes
  state.rs       -- on-disk cooldown-flag persistence
  telegram.rs    -- Telegram Bot API (startup + alert messages)

Building and Running

cargo build --release
cargo run --release

Log Prefixes

[*] info      (cyan)
[!] warning   (yellow)
[+] positive  (green)
[-] error     (red)
[?] input     (yellow)

Verbosity is configurable via RUST_LOG (parsed by tracing-subscriber's EnvFilter). Defaults to info.

RUST_LOG=vaultwatch=warn cargo run   # silence the per-poll info line
RUST_LOG=vaultwatch=error cargo run  # only errors
RUST_LOG=vaultwatch=debug cargo run  # extra detail if added later

Tech Stack

Crate Role
ethers ERC-4626 contract calls via JSON-RPC
tokio Single-threaded async runtime + timer
reqwest Reusable HTTP client for Telegram Bot API
serde JSON serialization for Telegram payloads
dotenvy Load .env file at startup
tracing Structured logging emit
tracing-subscriber Runtime log filtering (RUST_LOG) + custom format
eyre Error handling

About

Lightweight Rust bot that monitors ERC-4626 vault deposit capacity and sends Telegram alerts when a deposit slot opens up.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages