Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions watchtower/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Validator Monitoring Script

This script monitors a specified validator on the Hyperliquid network (testnet or mainnet) and sends alerts to a Telegram channel if the validator is not active or is jailed.

## Prerequisites

- **Bash**: Ensure you have a Unix-like environment with Bash installed.
- **Curl**: The script uses `curl` to make HTTP requests.
- **JQ**: A lightweight and flexible command-line JSON processor. Install it using your package manager (e.g., `apt-get install jq` on Debian-based systems).

## Setup

1. **Make the Script Executable**:

```bash
chmod +x /path/to/your/script.sh
```

2. **Crontab Setup**:
To run the script every 15 minutes, add it to your crontab:

```bash
crontab -e
```

Add the following line, replacing placeholders with your actual values:

```bash
*/15 * * * * /path/to/your/script.sh -t your_telegram_api_token -c your_telegram_chat_id -v your_target_validator_address -n testnet >> /path/to/your/logfile.log 2>&1
```

## Usage

Run the script with the following options:

```bash
./script.sh -t TELEGRAM_API_TOKEN -c TELEGRAM_CHAT_ID -v TARGET_VALIDATOR -n NETWORK
```

- `-t TELEGRAM_API_TOKEN`: Your Telegram bot API token.
- `-c TELEGRAM_CHAT_ID`: The chat ID of the Telegram channel or user to send alerts to.
- `-v TARGET_VALIDATOR`: The address of the validator to monitor.
- `-n NETWORK`: Specify the network to use: `testnet` or `mainnet`.

## Example

```bash
./script.sh -t 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 -c -987654321 -v 0xd5f63fd075529c9fea3bd051c9926e4e080bd4aa -n testnet
```

## Logging

The script logs its activities with timestamps to the console. If you have set up the cron job, it will also log to the specified file, helping you monitor its execution and troubleshoot any issues.

## License

This script is provided "as-is" without any warranties. Use it at your own risk.

---

### Notes:
- Ensure all paths and values are correctly set in the crontab and when running the script manually.
- Modify the script as needed to fit your specific requirements or environment settings.


85 changes: 85 additions & 0 deletions watchtower/hyperliquid_watchtower.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

# Function to log messages
log() {
local message="$1"
echo "$(date '+%Y-%m-%d %H:%M:%S') - $message"
}

# Function to display usage
usage() {
echo "Usage: $0 -t TELEGRAM_API_TOKEN -c TELEGRAM_CHAT_ID -v TARGET_VALIDATOR -n NETWORK"
echo " -n NETWORK Specify the network to use: 'testnet' or 'mainnet'"
exit 1
}

# Parse command-line arguments
while getopts ":t:c:v:n:" opt; do
case $opt in
t) TELEGRAM_API_TOKEN="$OPTARG"
;;
c) TELEGRAM_CHAT_ID="$OPTARG"
;;
v) TARGET_VALIDATOR="$OPTARG"
;;
n) NETWORK="$OPTARG"
;;
*) usage
;;
esac
done

# Check if all required arguments are provided
if [ -z "$TELEGRAM_API_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ] || [ -z "$TARGET_VALIDATOR" ] || [ -z "$NETWORK" ]; then
usage
fi

# Set API URL based on the network
case $NETWORK in
testnet)
API_URL="https://api.hyperliquid-testnet.xyz/info"
;;
mainnet)
API_URL="https://api.hyperliquid.xyz/info"
;;
*)
echo "Invalid network specified. Use 'testnet' or 'mainnet'."
exit 1
;;
esac

# Payload for the API request
PAYLOAD='{ "type": "validatorSummaries"}'

log "Starting script with target validator: $TARGET_VALIDATOR on $NETWORK using API URL: $API_URL"

# Fetch the JSON data from the API
response=$(curl -s -X POST --header "Content-Type: application/json" --data "$PAYLOAD" "$API_URL")

# Clean the response to remove any control characters
clean_response=$(echo "$response" | tr -d '\000-\037')

# Convert the target validator address to lowercase for comparison
target_validator=$(echo "$TARGET_VALIDATOR" | tr '[:upper:]' '[:lower:]')

# Check if the response contains the desired validator with the specific conditions
validator_status=$(echo "$clean_response" | jq -r --arg target_validator "$target_validator" '
.[] | select(.validator | ascii_downcase == $target_validator) | {isActive, isJailed}
')

is_active=$(echo "$validator_status" | jq -r '.isActive')
is_jailed=$(echo "$validator_status" | jq -r '.isJailed')

log "Validator status - isActive: $is_active, isJailed: $is_jailed"

# Check the conditions and send an alert if necessary
if [ "$is_active" != "true" ] || [ "$is_jailed" != "false" ]; then
message="Alert: Validator $TARGET_VALIDATOR is not active or is jailed."
log "$message"
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_API_TOKEN/sendMessage" \
-d chat_id="$TELEGRAM_CHAT_ID" \
-d text="$message"
fi

log "Script execution completed."