Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Configuration
- MAX_MINTS=100
- DEFAULT_FEE_THRESHOLD=500
- # $kibble
- TOKEN_ID=c468e99ac3b533e503eac5ccf4f0e3362772f80cead8b7f71d802305d02f73d0_0
- LOG_FILE="./mint_operations.log"
- # ANSI color codes
- GREEN='\033[0;32m'
- RED='\033[0;31m'
- YELLOW='\033[0;33m'
- NC='\033[0m' # No Color
- # Function to log messages
- log_message() {
- local color=$2
- local message="[$(date '+%Y-%m-%d %H:%M:%S')] $1"
- echo -e "${color}${message}${NC}"
- echo -e "$message" | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' >> "$LOG_FILE"
- }
- # Function to display usage
- usage() {
- echo "Usage: $0 <config_file1> <config_file2> ... [-f fee_threshold]"
- echo " -f fee_threshold: Optional. Set the fee threshold (default: $DEFAULT_FEE_THRESHOLD)"
- exit 1
- }
- # Store all arguments
- args=("$@")
- # Find the position of -f option
- f_position=-1
- for i in "${!args[@]}"; do
- if [[ ${args[i]} == "-f" ]]; then
- f_position=$i
- break
- fi
- done
- # Parse -f option if present
- if [[ $f_position -ne -1 ]]; then
- if [[ $((f_position + 1)) -lt ${#args[@]} ]]; then
- FEE_THRESHOLD=${args[$((f_position + 1))]}
- # Remove -f and its value from args
- unset 'args[f_position]'
- unset 'args[$((f_position + 1))]'
- # Reindex array
- args=("${args[@]}")
- else
- echo "Error: -f option requires a value" >&2
- usage
- fi
- fi
- # Set FEE_THRESHOLD to default if not provided
- FEE_THRESHOLD=${FEE_THRESHOLD:-$DEFAULT_FEE_THRESHOLD}
- # Check if config files are provided as arguments
- if [ ${#args[@]} -eq 0 ]; then
- log_message "Error: No config files provided." "$RED"
- usage
- fi
- # Store config files in an array
- CONFIG_FILES=("${args[@]}")
- log_message "Starting mint operations. Will attempt $MAX_MINTS mints. Fee threshold: $FEE_THRESHOLD"
- # Run yarn build
- log_message "Running yarn build..."
- if yarn build; then
- log_message "yarn build completed successfully."
- else
- log_message "Error: yarn build failed. Exiting script."
- exit 1
- fi
- mints_completed=0
- config_index=0
- while [ $mints_completed -lt $MAX_MINTS ]; do
- fee=$(curl -sSL "https://mempool.fractal.rushfi.app/api/v1/fees/recommended" | jq -r '.hourFee')
- if [ "$fee" -le $FEE_THRESHOLD ]; then
- ((mints_completed++))
- attempt=1
- # Get the current config file
- current_config=${CONFIG_FILES[$config_index]}
- # Update the MINT_COMMAND with the current config file
- MINT_COMMAND="yarn workspace @cat-protocol/cat-cli cli mint -i ${TOKEN_ID} --max-fee-rate ${FEE_THRESHOLD} -c ${current_config}"
- echo "${MINT_COMMAND}"
- log_message "Mint $mints_completed: Starting mint operation (Fee: $fee, Config: $current_config)" "$GREEN"
- while true; do
- # Run the command and capture its output
- output=$($MINT_COMMAND 2>&1)
- exit_code=$?
- # Log the output without duplicating it
- echo "$output" | sed 's/^/ /' # Indent the output for better readability
- # Check for success pattern in the output using a regular expression
- if echo "$output" | grep -qE "Minting [0-9.]+ [A-Za-z]+ tokens in txid"; then
- mint_amount=$(echo "$output" | grep -E "Minting" | sed -E 's/.*Minting ([0-9.]+) [A-Za-z]+ tokens.*/\1/')
- txid=$(echo "$output" | grep -E "Minting" | sed -E 's/.*in txid: ([a-f0-9]+).*/\1/')
- token_name=$(echo "$output" | grep -E "Minting" | sed -E 's/.*Minting [0-9.]+ ([A-Za-z]+) tokens.*/\1/')
- log_message "Mint $mints_completed completed successfully: Minted $mint_amount $token_name tokens (txid: $txid, Config: $current_config)" "$YELLOW"
- break
- elif echo "$output" | grep -qE "mint token \[[A-Za-z]+\] failed"; then
- log_message "Mint $mints_completed failed (Attempt $attempt, Config: $current_config)" "$RED"
- ((attempt++))
- else
- log_message "Mint $mints_completed encountered an unexpected error (Attempt $attempt, Exit code: $exit_code, Config: $current_config)" "$RED"
- ((attempt++))
- fi
- done
- # Move to the next config file
- config_index=$(( (config_index + 1) % ${#CONFIG_FILES[@]} ))
- else
- log_message "Fee too high ($fee). Waiting 5 seconds before checking again..." "$RED"
- sleep 5
- fi
- done
- log_message "Completed all $MAX_MINTS mint operations." "$GREEN"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement