diff --git a/.gitignore b/.gitignore index 63ca29e..e14ca3f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ out/ .env .secret .secret* +!onchain/.secret.local .infura .DS_Store diff --git a/containers/bootstrap.sh b/containers/bootstrap.sh index 6a61154..5caec53 100755 --- a/containers/bootstrap.sh +++ b/containers/bootstrap.sh @@ -7,6 +7,25 @@ if ! command -v jq >/dev/null 2>&1; then fi ROOT_DIR=/workspace +GIT_BRANCH="${GIT_BRANCH:-}" + +# Checkout branch if specified +if [[ -n "$GIT_BRANCH" ]]; then + cd "$ROOT_DIR" + git config --global --add safe.directory "$ROOT_DIR" 2>/dev/null || true + CURRENT=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") + + if [[ "$CURRENT" != "$GIT_BRANCH" ]]; then + echo "[bootstrap] Switching to branch: $GIT_BRANCH" + # Try local branch first, then remote + if git rev-parse --verify "$GIT_BRANCH" >/dev/null 2>&1; then + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[bootstrap] WARNING: Could not checkout $GIT_BRANCH" + else + git fetch origin "$GIT_BRANCH" 2>/dev/null || true + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[bootstrap] WARNING: Could not checkout $GIT_BRANCH" + fi + fi +fi STATE_DIR=$ROOT_DIR/tmp/podman LOG_DIR=$STATE_DIR/logs SETUP_LOG=$LOG_DIR/setup.log @@ -28,10 +47,6 @@ DEFAULT_DEPLOYER_ADDR=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 DEPLOYER_PK=${DEPLOYER_PK:-$DEFAULT_DEPLOYER_PK} DEPLOYER_ADDR=${DEPLOYER_ADDR:-$DEFAULT_DEPLOYER_ADDR} -DEFAULT_TXNBOT_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d -DEFAULT_TXNBOT_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 -TXNBOT_PRIVATE_KEY=${TXNBOT_PRIVATE_KEY:-$DEFAULT_TXNBOT_PRIVATE_KEY} -TXNBOT_ADDRESS=${TXNBOT_ADDRESS:-$DEFAULT_TXNBOT_ADDRESS} TXNBOT_FUND_VALUE=${TXNBOT_FUND_VALUE:-1ether} log() { @@ -67,6 +82,23 @@ maybe_set_deployer_from_mnemonic() { DEPLOYER_ADDR=${DEPLOYER_ADDR:-$DEFAULT_DEPLOYER_ADDR} } +derive_txnbot_wallet() { + if [[ -f "$MNEMONIC_FILE" ]]; then + local mnemonic + mnemonic="$(tr -d '\n\r' <"$MNEMONIC_FILE")" + if [[ -n "$mnemonic" ]]; then + TXNBOT_PRIVATE_KEY="$(cast wallet private-key --mnemonic "$mnemonic" --mnemonic-index 2)" + TXNBOT_ADDRESS="$(cast wallet address --private-key "$TXNBOT_PRIVATE_KEY")" + log "Derived txnBot wallet: $TXNBOT_ADDRESS (account index 2)" + return + fi + fi + # Fallback to hardcoded Anvil account 1 + TXNBOT_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d + TXNBOT_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 + log "Using default txnBot wallet: $TXNBOT_ADDRESS" +} + run_forge_script() { log "Deploying contracts to fork" pushd "$ROOT_DIR/onchain" >/dev/null @@ -191,6 +223,7 @@ main() { log "Waiting for Anvil" wait_for_rpc maybe_set_deployer_from_mnemonic + derive_txnbot_wallet run_forge_script extract_addresses fund_liquidity_manager @@ -206,6 +239,7 @@ main() { log "Kraiken: $KRAIKEN" log "Stake: $STAKE" log "LiquidityManager: $LIQUIDITY_MANAGER" + log "txnBot: $TXNBOT_ADDRESS" wait $prime_pid log "Block mining complete" } diff --git a/containers/landing-dev-entrypoint.sh b/containers/landing-dev-entrypoint.sh index a8c50af..31004fe 100755 --- a/containers/landing-dev-entrypoint.sh +++ b/containers/landing-dev-entrypoint.sh @@ -2,6 +2,26 @@ set -euo pipefail ROOT_DIR=/workspace +GIT_BRANCH="${GIT_BRANCH:-}" + +# Checkout branch if specified +if [[ -n "$GIT_BRANCH" ]]; then + cd "$ROOT_DIR" + git config --global --add safe.directory "$ROOT_DIR" 2>/dev/null || true + CURRENT=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") + + if [[ "$CURRENT" != "$GIT_BRANCH" ]]; then + echo "[landing-entrypoint] Switching to branch: $GIT_BRANCH" + # Try local branch first, then remote + if git rev-parse --verify "$GIT_BRANCH" >/dev/null 2>&1; then + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[landing-entrypoint] WARNING: Could not checkout $GIT_BRANCH" + else + git fetch origin "$GIT_BRANCH" 2>/dev/null || true + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[landing-entrypoint] WARNING: Could not checkout $GIT_BRANCH" + fi + fi +fi + LANDING_DIR=$ROOT_DIR/landing REQUIRED_DIST="$ROOT_DIR/kraiken-lib/dist/index.js" diff --git a/containers/ponder-dev-entrypoint.sh b/containers/ponder-dev-entrypoint.sh index f90d7b0..aa22f8f 100755 --- a/containers/ponder-dev-entrypoint.sh +++ b/containers/ponder-dev-entrypoint.sh @@ -2,6 +2,26 @@ set -euo pipefail ROOT_DIR=/workspace +GIT_BRANCH="${GIT_BRANCH:-}" + +# Checkout branch if specified +if [[ -n "$GIT_BRANCH" ]]; then + cd "$ROOT_DIR" + git config --global --add safe.directory "$ROOT_DIR" 2>/dev/null || true + CURRENT=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") + + if [[ "$CURRENT" != "$GIT_BRANCH" ]]; then + echo "[ponder-entrypoint] Switching to branch: $GIT_BRANCH" + # Try local branch first, then remote + if git rev-parse --verify "$GIT_BRANCH" >/dev/null 2>&1; then + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[ponder-entrypoint] WARNING: Could not checkout $GIT_BRANCH" + else + git fetch origin "$GIT_BRANCH" 2>/dev/null || true + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[ponder-entrypoint] WARNING: Could not checkout $GIT_BRANCH" + fi + fi +fi + CONTRACT_ENV=$ROOT_DIR/tmp/podman/contracts.env PONDER_WORKDIR=$ROOT_DIR/services/ponder diff --git a/containers/txn-bot-entrypoint.sh b/containers/txn-bot-entrypoint.sh index dbc0624..aa71f3a 100755 --- a/containers/txn-bot-entrypoint.sh +++ b/containers/txn-bot-entrypoint.sh @@ -2,6 +2,26 @@ set -euo pipefail ROOT_DIR=/workspace +GIT_BRANCH="${GIT_BRANCH:-}" + +# Checkout branch if specified +if [[ -n "$GIT_BRANCH" ]]; then + cd "$ROOT_DIR" + git config --global --add safe.directory "$ROOT_DIR" 2>/dev/null || true + CURRENT=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") + + if [[ "$CURRENT" != "$GIT_BRANCH" ]]; then + echo "[txn-bot-entrypoint] Switching to branch: $GIT_BRANCH" + # Try local branch first, then remote + if git rev-parse --verify "$GIT_BRANCH" >/dev/null 2>&1; then + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[txn-bot-entrypoint] WARNING: Could not checkout $GIT_BRANCH" + else + git fetch origin "$GIT_BRANCH" 2>/dev/null || true + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[txn-bot-entrypoint] WARNING: Could not checkout $GIT_BRANCH" + fi + fi +fi + TXNBOT_ENV_FILE=$ROOT_DIR/tmp/podman/txnBot.env BOT_DIR=$ROOT_DIR/services/txnBot REQUIRED_DIST=$ROOT_DIR/kraiken-lib/dist/index.js diff --git a/containers/webapp-dev-entrypoint.sh b/containers/webapp-dev-entrypoint.sh index e0aac82..da751cf 100755 --- a/containers/webapp-dev-entrypoint.sh +++ b/containers/webapp-dev-entrypoint.sh @@ -2,6 +2,26 @@ set -euo pipefail ROOT_DIR=/workspace +GIT_BRANCH="${GIT_BRANCH:-}" + +# Checkout branch if specified +if [[ -n "$GIT_BRANCH" ]]; then + cd "$ROOT_DIR" + git config --global --add safe.directory "$ROOT_DIR" 2>/dev/null || true + CURRENT=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown") + + if [[ "$CURRENT" != "$GIT_BRANCH" ]]; then + echo "[webapp-entrypoint] Switching to branch: $GIT_BRANCH" + # Try local branch first, then remote + if git rev-parse --verify "$GIT_BRANCH" >/dev/null 2>&1; then + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[webapp-entrypoint] WARNING: Could not checkout $GIT_BRANCH" + else + git fetch origin "$GIT_BRANCH" 2>/dev/null || true + git checkout "$GIT_BRANCH" 2>/dev/null || echo "[webapp-entrypoint] WARNING: Could not checkout $GIT_BRANCH" + fi + fi +fi + CONTRACT_ENV=$ROOT_DIR/tmp/podman/contracts.env APP_DIR=$ROOT_DIR/web-app SWAP_ROUTER=0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4 diff --git a/docs/test-accounts.md b/docs/test-accounts.md new file mode 100644 index 0000000..3163a6d --- /dev/null +++ b/docs/test-accounts.md @@ -0,0 +1,14 @@ +# Test Accounts + +Mnemonic: `test test test test test test test test test test test junk` + +All accounts receive 10000 ETH on Anvil startup. + +| Index | Address | Purpose | +|-------|---------|---------| +| 0 | 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 | Deployer | +| 1 | 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 | LiquidityManager Operator | +| 2 | 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC | txnBot | +| 3 | 0x90F79bf6EB2c4f870365E785982E1f101E93b906 | Test User | + +**Funding**: Use `/cheap` on webapp for Base Sepolia testnet. diff --git a/onchain/.secret.local b/onchain/.secret.local new file mode 100644 index 0000000..66eeda6 --- /dev/null +++ b/onchain/.secret.local @@ -0,0 +1 @@ +test test test test test test test test test test test junk \ No newline at end of file diff --git a/podman-compose.yml b/podman-compose.yml index 19830bf..6055088 100644 --- a/podman-compose.yml +++ b/podman-compose.yml @@ -39,8 +39,10 @@ services: command: ["/workspace/containers/bootstrap.sh"] volumes: - .:/workspace:z + - .git:/workspace/.git:ro,z environment: - ANVIL_RPC=http://anvil:8545 + - GIT_BRANCH=${GIT_BRANCH:-} depends_on: anvil: condition: service_healthy @@ -60,11 +62,13 @@ services: entrypoint: ["/workspace/containers/ponder-dev-entrypoint.sh"] volumes: - .:/workspace:z + - .git:/workspace/.git:ro,z - ./kraiken-lib/dist:/workspace/kraiken-lib/dist:ro,z - ponder-node-modules:/workspace/services/ponder/node_modules working_dir: /workspace environment: - CHOKIDAR_USEPOLLING=1 + - GIT_BRANCH=${GIT_BRANCH:-} depends_on: anvil: condition: service_healthy @@ -89,11 +93,13 @@ services: entrypoint: ["/workspace/containers/webapp-dev-entrypoint.sh"] volumes: - .:/workspace:z + - .git:/workspace/.git:ro,z - ./kraiken-lib/dist:/workspace/kraiken-lib/dist:ro,z - webapp-node-modules:/workspace/web-app/node_modules working_dir: /workspace environment: - CHOKIDAR_USEPOLLING=1 + - GIT_BRANCH=${GIT_BRANCH:-} depends_on: ponder: condition: service_healthy @@ -113,11 +119,13 @@ services: entrypoint: ["/workspace/containers/landing-dev-entrypoint.sh"] volumes: - .:/workspace:z + - .git:/workspace/.git:ro,z - ./kraiken-lib/dist:/workspace/kraiken-lib/dist:ro,z - landing-node-modules:/workspace/landing/node_modules working_dir: /workspace environment: - CHOKIDAR_USEPOLLING=1 + - GIT_BRANCH=${GIT_BRANCH:-} depends_on: ponder: condition: service_healthy @@ -137,10 +145,13 @@ services: entrypoint: ["/workspace/containers/txn-bot-entrypoint.sh"] volumes: - .:/workspace:z + - .git:/workspace/.git:ro,z - ./kraiken-lib/dist:/workspace/kraiken-lib/dist:ro,z - txn-node-modules:/workspace/services/txnBot/node_modules - kraiken-node-modules:/workspace/kraiken-lib/node_modules working_dir: /workspace + environment: + - GIT_BRANCH=${GIT_BRANCH:-} depends_on: ponder: condition: service_healthy diff --git a/scripts/dev.sh b/scripts/dev.sh index 30b0157..f51e3e5 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -18,6 +18,11 @@ start_stack() { rm -f "$PID_FILE" fi + # Show branch if set + if [[ -n "${GIT_BRANCH:-}" ]]; then + echo "Branch: $GIT_BRANCH" + fi + echo "Building kraiken-lib..." ./scripts/build-kraiken-lib.sh @@ -71,7 +76,16 @@ check_health() { } usage() { - echo "Usage: $0 {start|stop|health}" + cat <