Skip to content

Commit 2260ae1

Browse files
authored
chore: add alerts when the proofs sender has low balance (yetanotherco#643)
1 parent a885386 commit 2260ae1

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

alerts/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
SLACK_WEBHOOK_URL=<YOUR_SLACK_WEBHOOK_URL>
2+
TELEGRAM_BOT_TOKEN=<YOUR_TELEGRAM_BOT_TOKEN>
3+
TELEGRAM_CHAT_ID=<YOUR_TELEGRAM_CHAT_ID>
24

35
# Variables for contract_alerts.sh
46
RPC_URL=<YOUR_RPC_URL>
@@ -9,3 +11,9 @@ VERIFIED_BATCH_TOPIC=<YOUR_VERIFIED_BATCH_TOPIC>
911
# Variables for process_errors_alerts.sh
1012
SERVICE=<YOUR_SERVICE>
1113
EXPRESSION=<GREP_EXPRESSION>
14+
15+
# Variables for balance_alerts.sh
16+
RPC_URL=<YOUR_RPC_URL>
17+
PAYMENT_CONTRACT_ADDRESS=<YOUR_PAYMENT_CONTRACT_ADDRESS>
18+
BALANCE_THRESHOLD=<YOUR_BALANCE_THRESHOLD_IN_ETH>
19+
WALLET_ADDRESS=<YOUR_WALLET_ADDRESS>

alerts/balance_alerts.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# Load env file from $1 path
4+
source $1
5+
6+
# Function to send slack message
7+
# @param message
8+
function send_slack_message() {
9+
curl -X POST -H 'Content-type: application/json' \
10+
--data "{\"text\":\"$1\"}" \
11+
$SLACK_WEBHOOK_URL
12+
}
13+
14+
# Function to send telegram message
15+
# @param message
16+
function send_telegram_message() {
17+
curl -s -X POST https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage \
18+
-d chat_id=$TELEGRAM_CHAT_ID \
19+
-d text="$1" \
20+
-d disable_notification=true
21+
}
22+
23+
# Flags to avoid sending multiple alerts
24+
balance_alert=false
25+
26+
while :
27+
do
28+
balance_wei=$(cast call --rpc-url $RPC_URL $PAYMENT_CONTRACT_ADDRESS "UserBalances(address)(uint256)" $WALLET_ADDRESS | cut -d' ' -f1)
29+
30+
balance_eth=$(cast from-wei $balance_wei)
31+
32+
if [ 1 -eq "$(echo "$balance_eth < $BALANCE_THRESHOLD" | bc)" ]; then
33+
message="⚠️ WARNING: Wallet $WALLET_ADDRESS balance ($balance_eth ETH) is below $BALANCE_THRESHOLD ETH"
34+
printf "$message\n"
35+
if [ "$balance_alert" = false ]; then
36+
send_slack_message "$message"
37+
send_telegram_message "$message"
38+
fi
39+
balance_alert=true
40+
else
41+
message="🟩 INFO: Wallet $WALLET_ADDRESS balance ($balance_eth ETH) is above $BALANCE_THRESHOLD ETH"
42+
printf "$message\n"
43+
if [ "$balance_alert" = true ]; then
44+
send_slack_message "$message"
45+
send_telegram_message "$message"
46+
fi
47+
balance_alert=false
48+
fi
49+
50+
sleep 600
51+
done

0 commit comments

Comments
 (0)