Files
proxmox/scripts/fee-management.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

104 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fee management and optimization for bridge operations
# Usage: ./fee-management.sh [check|estimate|alert]
set -euo pipefail
# Load IP configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_PROJECT="/home/intlc/projects/smom-dbis-138"
source "$SOURCE_PROJECT/.env" 2>/dev/null || true
RPC_URL="${RPC_URL_138_PUBLIC:-http://${RPC_PUBLIC_1:-192.168.11.221}:8545}"
WETH9_BRIDGE="${CCIPWETH9_BRIDGE_CHAIN138:-0x971cD9D156f193df8051E48043C476e53ECd4693}"
LINK_TOKEN="${LINK_TOKEN_CHAIN138:-0x326C977E6efc84E512bB9C30f76E30c160eD06FB}"
ALERT_THRESHOLD=1.0 # Alert if fees exceed 1 ETH equivalent
ACTION="${1:-check}"
# Check LINK token balance
check_link_balance() {
DEPLOYER=$(cast wallet address --private-key "$PRIVATE_KEY" 2>/dev/null || echo "")
if [ -z "$DEPLOYER" ]; then
echo "ERROR: Cannot determine deployer address"
return 1
fi
LINK_BAL=$(cast call "$LINK_TOKEN" "balanceOf(address)" "$DEPLOYER" --rpc-url "$RPC_URL" 2>/dev/null || echo "0")
LINK_BAL_ETH=$(echo "scale=6; $LINK_BAL / 1000000000000000000" | bc 2>/dev/null || echo "0")
echo "LINK Balance: $LINK_BAL_ETH LINK"
if (( $(echo "$LINK_BAL_ETH < 0.1" | bc -l 2>/dev/null || echo 1) )); then
echo "⚠️ WARNING: Low LINK balance. May need to add more for fees."
fi
}
# Estimate fees for all chains
estimate_fees() {
local amount_wei="${1:-1000000000000000000}" # 1 ETH default
echo "=== Fee Estimation ==="
echo "Amount: $(echo "scale=4; $amount_wei / 1000000000000000000" | bc) ETH"
echo ""
declare -A CHAINS=(
["BSC"]="11344663589394136015"
["Polygon"]="4051577828743386545"
["Avalanche"]="6433500567565415381"
["Base"]="15971525489660198786"
["Arbitrum"]="4949039107694359620"
["Optimism"]="3734403246176062136"
["Ethereum"]="5009297550715157269"
)
local total_fees=0
for chain in "${!CHAINS[@]}"; do
selector="${CHAINS[$chain]}"
fee=$(cast call "$WETH9_BRIDGE" "calculateFee(uint64,uint256)" "$selector" "$amount_wei" --rpc-url "$RPC_URL" 2>/dev/null || echo "0")
if [ "$fee" != "0" ]; then
fee_eth=$(echo "scale=6; $fee / 1000000000000000000" | bc 2>/dev/null || echo "0")
echo "$chain: $fee_eth ETH"
total_fees=$(echo "$total_fees + $fee" | bc)
fi
done
total_fees_eth=$(echo "scale=6; $total_fees / 1000000000000000000" | bc 2>/dev/null || echo "0")
echo ""
echo "Total Fees (all chains): $total_fees_eth ETH"
}
# Check fees and alert if high
check_fees() {
check_link_balance
echo ""
estimate_fees
# Check if fees exceed threshold
local test_amount=$(cast --to-wei 1.0 ether 2>/dev/null)
local bsc_fee=$(cast call "$WETH9_BRIDGE" "calculateFee(uint64,uint256)" "11344663589394136015" "$test_amount" --rpc-url "$RPC_URL" 2>/dev/null || echo "0")
local bsc_fee_eth=$(echo "scale=6; $bsc_fee / 1000000000000000000" | bc 2>/dev/null || echo "0")
if (( $(echo "$bsc_fee_eth > $ALERT_THRESHOLD" | bc -l 2>/dev/null || echo 0) )); then
echo ""
echo "⚠️ ALERT: Fees exceed threshold ($ALERT_THRESHOLD ETH)"
fi
}
case "$ACTION" in
check) check_fees ;;
estimate) estimate_fees "${2:-1000000000000000000}" ;;
alert) check_fees ;;
*)
echo "Usage: $0 [check|estimate|alert]"
exit 1
;;
esac