Skip to content

Commit

Permalink
cleaner more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
marczeller committed Aug 18, 2024
1 parent 5c79ceb commit 221ff5b
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 161 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -39,4 +44,7 @@ mint:
TARGET_NETWORK=$(NETWORK) forge script script/MintToTreasury.s.sol:MintToTreasuryScript --broadcast

clean:
@rm -rf $(LOG_DIR) broadcast cache out
@find $(LOG_DIR) -type f -delete
@find broadcast -mindepth 1 -delete
@find cache -mindepth 1 -delete
@find out -mindepth 1 -delete
82 changes: 64 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
95 changes: 0 additions & 95 deletions dolce_vita_collector.sh

This file was deleted.

95 changes: 49 additions & 46 deletions dolce_vita_collector_with_notifications.sh
100644 β†’ 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,67 @@ 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() {
local message=$1
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"

0 comments on commit 221ff5b

Please sign in to comment.