diff --git a/Makefile b/Makefile index 122631c..c7ba617 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,12 @@ $(LOG_DIR): fetch-reserves: $(LOG_DIR) @echo "Fetching reserves list for all networks..." - @forge script ${FETCH_RESERVES_SCRIPT} -vvvv + @forge script ${FETCH_RESERVES_SCRIPT} -vvvv || true + @if [ -f "./logs/reserves.json" ] && [ -s "./logs/reserves.json" ]; then \ + echo "Reserves fetched successfully"; \ + else \ + echo "Failed to fetch reserves" && exit 1; \ + fi mint: @if [ -z "$(NETWORK)" ]; then \ @@ -39,4 +44,7 @@ mint: TARGET_NETWORK=$(NETWORK) forge script script/MintToTreasury.s.sol:MintToTreasuryScript --broadcast clean: - @rm -rf $(LOG_DIR) broadcast cache out \ No newline at end of file + @find $(LOG_DIR) -type f -delete + @find broadcast -mindepth 1 -delete + @find cache -mindepth 1 -delete + @find out -mindepth 1 -delete \ No newline at end of file diff --git a/README.md b/README.md index 7c7b6b4..86944e9 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # ACI's Dolce Vita Collector -This project automates the process of minting to treasury for various Aave Pools across multiple networks. It includes a scheduled script that runs daily and weekly, with Telegram notifications for monitoring. +This project automates the process of minting to treasury for various Aave Pools across multiple networks. It includes scheduled scripts that run daily for L2 networks and weekly for MAINNET, with Telegram notifications for monitoring. ## Setup 1. Clone the repository: ``` - git clone https://github.com/yourusername/dolce_vita_collector.git + git clone cd dolce_vita_collector ``` @@ -27,9 +27,12 @@ This project automates the process of minting to treasury for various Aave Pools ``` 5. Set up the automated script and Telegram notifications: - - Ensure the `dolce_vita_collector_with_notifications.sh` script is in place and executable. + - Ensure the `dolce_vita_collector_with_notifications.sh` script is executable: + ``` + chmod +x dolce_vita_collector_with_notifications.sh + ``` - Set up systemd services and timers for daily and weekly runs (see "Automated Runs" section). - - Configure the Telegram bot token and chat ID in the script. + - Configure the Telegram bot token and chat ID in the `.env` file. ## Usage @@ -38,24 +41,24 @@ This project automates the process of minting to treasury for various Aave Pools make fetch-reserves ``` -- To mint to treasury for a specific network and pool: +- To mint to treasury for a specific network: ``` - make mint-to-treasury NETWORK=MAINNET POOL=MAIN + make mint NETWORK=MAINNET ``` -- The automated script runs daily (excluding MAINNET) and weekly (including MAINNET) at 8:00 AM UTC. +- The automated script runs daily for L2 networks and weekly for MAINNET at 8:00 AM UTC. ## Automated Runs -To set up automated runs, you need to create systemd service and timer files. Replace `/path/to/` with the actual path to your cloned repository. +To set up automated runs, you need to create systemd service and timer files. -1. Create service files: +1. Create and edit service files: ``` sudo nano /etc/systemd/system/dolce-vita-daily.service sudo nano /etc/systemd/system/dolce-vita-weekly.service ``` -2. Create timer files: +2. Create and edit timer files: ``` sudo nano /etc/systemd/system/dolce-vita-daily.timer sudo nano /etc/systemd/system/dolce-vita-weekly.timer @@ -70,6 +73,8 @@ To set up automated runs, you need to create systemd service and timer files. Re Refer to the provided service and timer file templates in the `systemd` directory and adjust paths as necessary. +Note: After cloning the repository, make sure to update the paths in the systemd service files to match the location where you've cloned the project. Replace `/home/yourusername/` with the path to your home directory or wherever you've placed the project. + ## Monitoring The script sends Telegram notifications for: @@ -79,25 +84,66 @@ The script sends Telegram notifications for: To manually trigger a run: ``` -/path/to/dolce_vita_collector/dolce_vita_collector_with_notifications.sh +./dolce_vita_collector_with_notifications.sh --l2s-only ``` -Add `--include-mainnet` for a run that includes MAINNET. +For a MAINNET run: +``` +./dolce_vita_collector_with_notifications.sh --mainnet-only +``` -## Logs +Note: Make sure you're in the project directory when running these commands, or use the full path to the script from your home directory: + +``` +~/dolce_vita_collector/dolce_vita_collector_with_notifications.sh --l2s-only +``` -Logs are stored in `/var/log/dolce_vita_collector/`: -- `daily.log`: For daily runs -- `weekly.log`: For weekly runs (including MAINNET) +or -Ensure the log directory exists and is writable by the user running the script. +``` +~/dolce_vita_collector/dolce_vita_collector_with_notifications.sh --mainnet-only +``` + +## Logs + +Logs are stored in the `logs` directory within the project folder: +- `dolce_vita_collector_log.txt`: Contains logs for both daily and weekly runs ## Customization When setting up this project, make sure to: 1. Update all paths in the scripts and service files to match your system's directory structure. -2. Configure your own Telegram bot token and chat ID in the notification script. +2. Configure your own Telegram bot token and chat ID in the `.env` file. 3. Adjust the systemd service files to use the correct user and group for your system. +4. If you've cloned this repository to a different location, update the paths in the systemd service files accordingly. + +## Supported Networks + +The script supports the following networks: +- MAINNET (weekly run) +- AVALANCHE +- OPTIMISM +- POLYGON +- ARBITRUM +- METIS +- BASE +- GNOSIS +- BNB +- SCROLL + +L2 networks are processed in the daily run, while MAINNET is processed in the weekly run. + +## Troubleshooting + +If you encounter any issues: +1. Check the log file for error messages. +2. Ensure all environment variables in the `.env` file are correctly set. +3. Verify that the systemd services and timers are correctly configured and running. +4. Check your Telegram bot setup if you're not receiving notifications. + +## Contributing + +Contributions are welcome! Please feel free to submit a Pull Request. ## License diff --git a/dolce_vita_collector.sh b/dolce_vita_collector.sh deleted file mode 100755 index b6a712c..0000000 --- a/dolce_vita_collector.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash - -# Get the directory where the script is located -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - -# Log file -LOG_FILE="${SCRIPT_DIR}/logs/dolce_vita_collector_log.txt" - -# Ensure the logs directory exists -mkdir -p "${SCRIPT_DIR}/logs" - -# Function to log messages -log_message() { - echo "$(date +"%Y-%m-%d %H:%M:%S"): $1" | tee -a "$LOG_FILE" -} - -# Function to execute and log a command with timeout -execute_command_with_timeout() { - local COMMAND="$1" - local TIMEOUT=180 # 180 seconds = 3 minutes - - log_message "Executing with ${TIMEOUT}s timeout: $COMMAND" - - timeout $TIMEOUT $COMMAND - local EXIT_CODE=$? - - if [ $EXIT_CODE -eq 0 ]; then - log_message "$COMMAND successful" - return 0 - elif [ $EXIT_CODE -eq 124 ]; then - log_message "$COMMAND timed out after ${TIMEOUT} seconds" - return 1 - else - log_message "$COMMAND failed with exit code $EXIT_CODE" - return 1 - fi -} - -# Check if MAINNET should be included -INCLUDE_MAINNET=0 -if [ "$1" == "--include-mainnet" ]; then - INCLUDE_MAINNET=1 -fi - -# Array of networks -NETWORKS=( - "AVALANCHE" - "OPTIMISM" - "POLYGON" - "ARBITRUM" - "METIS" - "BASE" - "GNOSIS" - "BNB" - "SCROLL" -) - -# Add MAINNET if flag is set -if [ $INCLUDE_MAINNET -eq 1 ]; then - NETWORKS+=("MAINNET") -fi - -# Main execution -log_message "Script execution started" - -# Execute make clean -execute_command_with_timeout "make clean" - -# Execute make fetch-reserves and wait for it to complete -if execute_command_with_timeout "make fetch-reserves"; then - log_message "make fetch-reserves completed successfully. Proceeding with minting." - - log_message "Starting minting process for all networks" - - for NETWORK in "${NETWORKS[@]}"; do - log_message "Processing $NETWORK" - - COMMAND="make mint NETWORK=$NETWORK" - if execute_command_with_timeout "$COMMAND"; then - log_message "Minting successful for $NETWORK" - else - log_message "Minting failed or timed out for $NETWORK. Moving to next network." - fi - - echo "----------------------------------------" - done - - log_message "Minting process completed for all networks" -else - log_message "make fetch-reserves failed or timed out. Aborting minting process." -fi - -log_message "Script execution completed" - -exit 0 \ No newline at end of file diff --git a/dolce_vita_collector_with_notifications.sh b/dolce_vita_collector_with_notifications.sh old mode 100644 new mode 100755 index e63d059..b76be64 --- a/dolce_vita_collector_with_notifications.sh +++ b/dolce_vita_collector_with_notifications.sh @@ -6,9 +6,8 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Load environment variables source "$SCRIPT_DIR/.env" -LOG_DIR="/var/log/dolce_vita_collector" -COUNTER_FILE="${LOG_DIR}/counter.log" -MAX_LINES=2000 +LOG_DIR="$SCRIPT_DIR/logs" +LOG_FILE="$LOG_DIR/dolce_vita_collector_log.txt" # Function to send Telegram messages send_telegram_message() { @@ -16,54 +15,58 @@ send_telegram_message() { curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" -d chat_id="$TELEGRAM_CHAT_ID" -d text="$message" } -# Initialize the counter and date if they don't exist -if [ ! -f $COUNTER_FILE ]; then - mkdir -p "$LOG_DIR" - echo "Loop Counter: 0" > $COUNTER_FILE - echo "Last Run: Never" >> $COUNTER_FILE -fi - -# Read the current counter value and date of last run -counter=$(grep -o '[0-9]\+' $COUNTER_FILE | head -n 1) -last_run=$(grep 'Last Run:' $COUNTER_FILE) +# Function to log messages +log_message() { + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" + send_telegram_message "$1" +} -# Increment the counter -counter=$((counter + 1)) -current_date=$(date '+%Y-%m-%d %H:%M:%S') +# Check for command line arguments +if [ "$1" == "--mainnet-only" ]; then + NETWORKS=("MAINNET") + log_message "🔄 Starting Dolce Vita Collector script (MAINNET only)" +elif [ "$1" == "--l2s-only" ]; then + NETWORKS=("AVALANCHE" "OPTIMISM" "POLYGON" "ARBITRUM" "METIS" "BASE" "GNOSIS" "BNB" "SCROLL") + log_message "🔄 Starting Dolce Vita Collector script (L2s only)" +else + log_message "❌ Error: Invalid or no argument provided. Use --mainnet-only or --l2s-only" + exit 1 +fi -# Update the counter file with the new counter and date -echo "Loop Counter: $counter" > $COUNTER_FILE -echo "Last Run: $current_date" >> $COUNTER_FILE +# Run make clean +log_message "Running make clean" +make clean +if [ $? -ne 0 ]; then + log_message "⚠️ Warning: make clean failed" +fi -# Determine if this is a weekly run (with MAINNET) -if [[ "$1" == "--include-mainnet" ]]; then - run_type="Weekly (including MAINNET)" - log_file="${LOG_DIR}/weekly.log" +# Run make fetch-reserves with a timeout of 180 seconds +log_message "Running make fetch-reserves (180s timeout)" +timeout 180 make fetch-reserves +FETCH_RESULT=$? +if [ $FETCH_RESULT -eq 124 ]; then + log_message "❌ Error: make fetch-reserves timed out after 180 seconds" + exit 1 +elif [ $FETCH_RESULT -ne 0 ]; then + log_message "❌ Error: make fetch-reserves failed with status: $FETCH_RESULT" + exit 1 else - run_type="Daily" - log_file="${LOG_DIR}/daily.log" + log_message "✅ make fetch-reserves completed successfully" fi -# Log the start of the process -{ - echo "🚀 Starting Dolce Vita Collector $run_type script..." - echo "Loop Counter: $counter" - echo "Last Run: $current_date" - - send_telegram_message "🚀 Starting Dolce Vita Collector $run_type script. Loop Counter: $counter. Last Run: $current_date" - - # Run the original script - if "$SCRIPT_DIR/dolce_vita_collector.sh" "$@"; then - echo "🎉 Dolce Vita Collector $run_type script completed successfully." - send_telegram_message "🎉 Dolce Vita Collector $run_type script completed successfully. Loop Counter: $counter." - else - echo "⚠️ Dolce Vita Collector $run_type script encountered errors." - send_telegram_message "⚠️ Dolce Vita Collector $run_type script encountered errors. Loop Counter: $counter." - fi +# Check if reserves.json exists and is not empty +if [ -f "$SCRIPT_DIR/logs/reserves.json" ] && [ -s "$SCRIPT_DIR/logs/reserves.json" ]; then + log_message "✅ reserves.json exists and is not empty" +else + log_message "❌ Error: reserves.json is missing or empty" + exit 1 +fi - # Truncate the log file to keep only the last $MAX_LINES lines - tail -n $MAX_LINES $log_file > $log_file.tmp && mv $log_file.tmp $log_file +# Run make mint for each network without checking for success +for network in "${NETWORKS[@]}"; do + log_message "Running make mint for $network" + timeout 180 make mint NETWORK=$network + log_message "Completed make mint for $network" +done - # Concatenate the counter file and the log file - cat $COUNTER_FILE $log_file > $log_file.tmp && mv $log_file.tmp $log_file -} | ts '[%Y-%m-%d %H:%M:%S]' >> $log_file +log_message "🏁 Dolce Vita Collector script completed" \ No newline at end of file