Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b345ab0
fix: simplify restart mechanism to prevent orphan processes
fengtality Dec 3, 2025
b33ead7
feat: add gateway.sh lifecycle manager script
fengtality Dec 3, 2025
7817a46
feat: update pnpm start to use lifecycle wrapper
fengtality Dec 3, 2025
dcf1e82
feat: add server lifecycle endpoints and run in foreground
fengtality Dec 3, 2025
54729f5
Merge branch 'refactor/http-errors' into fix/restart-race-condition
fengtality Dec 3, 2025
ec133a4
Merge branch 'refactor/http-errors' of github.com:hummingbot/gateway …
fengtality Dec 3, 2025
fd79190
Merge branch 'fix/restart-race-condition' of github.com:hummingbot/ga…
fengtality Dec 3, 2025
ea91744
fix: remove orphaned RPC provider namespace references
fengtality Dec 3, 2025
75cf8b8
feat: integrate AlphaRouter for split routing in Uniswap quote-swap
fengtality Dec 4, 2025
05467f7
feat: add maxHops/maxSplits support to PancakeSwap Smart Router
fengtality Dec 4, 2025
9628f4e
fix: add maximumSplits to PancakeSwap JSON schema
fengtality Dec 4, 2025
09698d1
fix: correct quoteCurrency parameter for EXACT_OUTPUT trades in Alpha…
fengtality Dec 4, 2025
b7d6d45
fix: correct transaction status handling for pending Ethereum transac…
fengtality Dec 4, 2025
3c39479
refactor: reduce Uniswap router log verbosity
fengtality Dec 4, 2025
ed1e609
Merge branch 'refactor/http-errors' into fix/restart-race-condition
fengtality Dec 5, 2025
e920493
Merge branch 'fix/restart-race-condition' into feat/alpha-router-spli…
fengtality Dec 5, 2025
74852a0
Merge branch 'development' into fix/restart-race-condition
fengtality Dec 9, 2025
086623f
Merge branch 'fix/restart-race-condition' into feat/alpha-router-spli…
fengtality Dec 9, 2025
8b8b3e9
Merge branch 'development' into fix/restart-race-condition
rapcmia Dec 16, 2025
bf2e374
Merge branch 'fix/restart-race-condition' into feat/alpha-router-spli…
nikspz Dec 17, 2025
f4e465c
fix: add multi-hop routing support for PancakeSwap
fengtality Dec 23, 2025
530e7f1
fix: display full route path with intermediate tokens in routePath
fengtality Dec 30, 2025
751cfcb
Merge pull request #568 from hummingbot/feat/alpha-router-split-routing
rapcmia Jan 9, 2026
ff590c3
Revert "feat: add split routing in Uniswap and Pancakeswap quote-swap"
rapcmia Jan 9, 2026
2de88cb
Merge pull request #588 from hummingbot/revert-568-feat/alpha-router-…
rapcmia Jan 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ src/**/*.js.map
*.log

# MCP servers configuration
.mcp.json
.mcp.json

# PID files from gateway lifecycle manager
*.pid
273 changes: 273 additions & 0 deletions gateway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
#!/bin/bash
#
# Gateway lifecycle manager
# Usage: ./gateway.sh [start|stop|restart|status]
#
# This script manages the Gateway server process, handling restarts automatically
# when the server exits with code 0 (restart requested).
#

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PID_FILE="$SCRIPT_DIR/gateway.pid"
WRAPPER_PID_FILE="$SCRIPT_DIR/gateway-wrapper.pid"
LOG_FILE="$SCRIPT_DIR/logs/gateway.log"

# Ensure logs directory exists
mkdir -p "$SCRIPT_DIR/logs"

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

log() {
echo -e "${GREEN}[Gateway]${NC} $1"
}

warn() {
echo -e "${YELLOW}[Gateway]${NC} $1"
}

error() {
echo -e "${RED}[Gateway]${NC} $1"
}

# Check if Gateway is running
is_running() {
if [ -f "$PID_FILE" ]; then
local pid=$(cat "$PID_FILE")
if kill -0 "$pid" 2>/dev/null; then
return 0
fi
fi
return 1
}

# Check if wrapper is running
is_wrapper_running() {
if [ -f "$WRAPPER_PID_FILE" ]; then
local pid=$(cat "$WRAPPER_PID_FILE")
if kill -0 "$pid" 2>/dev/null; then
return 0
fi
fi
return 1
}

# Start the Gateway server in a restart loop
start_gateway() {
if is_wrapper_running; then
error "Gateway wrapper is already running (PID: $(cat "$WRAPPER_PID_FILE"))"
return 1
fi

if is_running; then
error "Gateway is already running (PID: $(cat "$PID_FILE"))"
return 1
fi

log "Starting Gateway..."

# Parse additional arguments
local dev_mode=""
shift # Remove 'start' from args
while [[ $# -gt 0 ]]; do
case $1 in
--dev)
dev_mode="--dev"
shift
;;
--passphrase=*)
export GATEWAY_PASSPHRASE="${1#*=}"
shift
;;
--passphrase)
export GATEWAY_PASSPHRASE="$2"
shift 2
;;
*)
shift
;;
esac
done

# Check for required passphrase (from arg or environment)
if [ -z "$GATEWAY_PASSPHRASE" ]; then
error "Passphrase is required"
error "Usage: $0 start --passphrase=yourpassphrase [--dev]"
error " or: GATEWAY_PASSPHRASE=yourpassphrase $0 start [--dev]"
return 1
fi

# Save wrapper PID
echo "$$" > "$WRAPPER_PID_FILE"

# Handle Ctrl+C gracefully
trap 'log "Received interrupt signal. Stopping..."; rm -f "$WRAPPER_PID_FILE"; exit 130' INT TERM

# Run in foreground with restart loop
while true; do
log "Starting Gateway server..."

# Run Gateway
cd "$SCRIPT_DIR"
START_SERVER=true node dist/index.js $dev_mode
exit_code=$?

if [ $exit_code -eq 0 ]; then
log "Gateway requested restart (exit code 0). Restarting in 2 seconds..."
sleep 2
else
log "Gateway stopped (exit code $exit_code). Not restarting."
rm -f "$WRAPPER_PID_FILE"
break
fi
done
}

# Stop the Gateway server
stop_gateway() {
local stopped=0

# First, stop the wrapper to prevent restart
if is_wrapper_running; then
local wrapper_pid=$(cat "$WRAPPER_PID_FILE")
log "Stopping Gateway wrapper (PID: $wrapper_pid)..."
kill "$wrapper_pid" 2>/dev/null
rm -f "$WRAPPER_PID_FILE"
stopped=1
fi

# Then stop the Gateway process
if is_running; then
local pid=$(cat "$PID_FILE")
log "Stopping Gateway server (PID: $pid)..."
kill "$pid" 2>/dev/null

# Wait for process to stop
local count=0
while kill -0 "$pid" 2>/dev/null && [ $count -lt 10 ]; do
sleep 1
count=$((count + 1))
done

if kill -0 "$pid" 2>/dev/null; then
warn "Gateway didn't stop gracefully, force killing..."
kill -9 "$pid" 2>/dev/null
fi

rm -f "$PID_FILE"
stopped=1
fi

if [ $stopped -eq 1 ]; then
log "Gateway stopped"
else
warn "Gateway is not running"
fi
}

# Restart the Gateway server (via API)
restart_gateway() {
if ! is_running; then
warn "Gateway is not running. Starting..."
start_gateway "$@"
return
fi

log "Requesting Gateway restart via API..."

# Determine protocol based on dev mode
local protocol="https"
local curl_opts="-k"

# Try to detect if running in dev mode by checking the process
if ps aux | grep -v grep | grep "node dist/index.js" | grep -q "\-\-dev"; then
protocol="http"
curl_opts=""
fi

local port=$(grep -E "^port:" "$SCRIPT_DIR/conf/server.yml" 2>/dev/null | awk '{print $2}' || echo "15888")

curl -s -X POST $curl_opts "$protocol://localhost:$port/restart" > /dev/null

if [ $? -eq 0 ]; then
log "Restart request sent. Gateway will restart automatically."
else
error "Failed to send restart request. Is Gateway running?"
fi
}

# Show Gateway status
status_gateway() {
echo ""
if is_wrapper_running; then
log "Wrapper: ${GREEN}running${NC} (PID: $(cat "$WRAPPER_PID_FILE"))"
else
log "Wrapper: ${RED}not running${NC}"
fi

if is_running; then
local pid=$(cat "$PID_FILE")
log "Gateway: ${GREEN}running${NC} (PID: $pid)"

# Try to get status from API
local port=$(grep -E "^port:" "$SCRIPT_DIR/conf/server.yml" 2>/dev/null | awk '{print $2}' || echo "15888")
local response=$(curl -s -k "https://localhost:$port/" 2>/dev/null || curl -s "http://localhost:$port/" 2>/dev/null)

if [ -n "$response" ]; then
log "API: ${GREEN}responding${NC}"
else
warn "API: ${YELLOW}not responding${NC}"
fi
else
log "Gateway: ${RED}not running${NC}"
fi
echo ""
}

# Show usage
usage() {
echo ""
echo "Gateway Lifecycle Manager"
echo ""
echo "Usage: $0 <command> [options]"
echo ""
echo "Commands:"
echo " start --passphrase=<pass> [--dev] Start Gateway server"
echo " stop Stop Gateway server"
echo " restart Restart Gateway server"
echo " status Show Gateway status"
echo ""
echo "Options:"
echo " --passphrase=<pass> Passphrase for wallet encryption (required for start)"
echo " --dev Run in HTTP mode (development)"
echo ""
echo "Examples:"
echo " $0 start --passphrase=mypassword"
echo " $0 start --passphrase=mypassword --dev"
echo " $0 stop"
echo " $0 status"
echo ""
}

# Main
case "${1:-}" in
start)
start_gateway "$@"
;;
stop)
stop_gateway
;;
restart)
restart_gateway "$@"
;;
status)
status_gateway
;;
*)
usage
exit 1
;;
esac
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"lint": "eslint src test --format table --fix",
"setup": "bash ./gateway-setup.sh",
"setup:with-defaults": "bash ./gateway-setup.sh --with-defaults",
"start": "START_SERVER=true node dist/index.js",
"start": "bash ./gateway.sh start",
"stop": "bash ./gateway.sh stop",
"status": "bash ./gateway.sh status",
"copy-files": "copyfiles 'src/templates/namespace/*.json' 'src/templates/*.yml' 'src/templates/chains/**/*.yml' 'src/templates/connectors/*.yml' 'src/templates/tokens/**/*.json' 'src/templates/pools/*.json' dist && copyfiles -u 1 'src/connectors/pancakeswap-sol/idl/*.json' dist",
"test": "GATEWAY_TEST_MODE=dev jest --verbose",
"test:clear-cache": "jest --clearCache",
Expand Down
Loading