MIM4U: nginx install/deploy/backup scripts, rate limit, CSP, docs; submodule pointer; txpool retry script
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Made-with: Cursor
This commit is contained in:
147
scripts/deployment/deploy-transaction-mirror-and-pmm-pool-after-txpool-clear.sh
Executable file
147
scripts/deployment/deploy-transaction-mirror-and-pmm-pool-after-txpool-clear.sh
Executable file
@@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env bash
|
||||
# Deploy TransactionMirror and create DODO cUSDT/cUSDC PMM pool on Chain 138.
|
||||
# Run after clearing RPC tx pool (./scripts/clear-all-transaction-pools.sh) so deployer nonce is not stuck.
|
||||
#
|
||||
# Uses: smom-dbis-138/.env (PRIVATE_KEY, RPC_URL_138, RPC_URL_138_PUBLIC, DODO_PMM_INTEGRATION, GAS_PRICE)
|
||||
# and config/ip-addresses.conf for RPC fallbacks. Always checks nonce, RPC active, and gas.
|
||||
#
|
||||
# Usage: ./scripts/deployment/deploy-transaction-mirror-and-pmm-pool-after-txpool-clear.sh [--dry-run] [--force]
|
||||
# --dry-run Check env, RPC, nonce only; no deploy.
|
||||
# --force Skip RPC reachability check (not recommended).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
SMOM="${PROJECT_ROOT}/smom-dbis-138"
|
||||
|
||||
DRY_RUN=""
|
||||
FORCE=""
|
||||
for a in "$@"; do
|
||||
[[ "$a" == "--dry-run" ]] && DRY_RUN=1
|
||||
[[ "$a" == "--force" ]] && FORCE=1
|
||||
done
|
||||
|
||||
# 1) Load dotenv: project config (RPCs) then smom-dbis-138/.env (PRIVATE_KEY, overrides)
|
||||
[[ -f "${PROJECT_ROOT}/config/ip-addresses.conf" ]] && source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
||||
if [[ ! -f "$SMOM/.env" ]]; then
|
||||
echo "Missing $SMOM/.env. Abort." >&2
|
||||
exit 1
|
||||
fi
|
||||
set -a
|
||||
source "$SMOM/.env"
|
||||
set +a
|
||||
|
||||
# 2) RPC: prefer .env, fallback to config
|
||||
RPC="${RPC_URL_138:-http://192.168.11.211:8545}"
|
||||
PUBLIC_RPC="${RPC_URL_138_PUBLIC:-http://192.168.11.221:8545}"
|
||||
[[ -z "${PRIVATE_KEY:-}" ]] && echo "PRIVATE_KEY not set in $SMOM/.env. Abort." >&2 && exit 1
|
||||
# Chain 138 gas: min 1 gwei; use GAS_PRICE from .env or default
|
||||
GAS_PRICE="${GAS_PRICE_138:-${GAS_PRICE:-1000000000}}"
|
||||
|
||||
echo "=== TransactionMirror + PMM pool (Chain 138) ==="
|
||||
echo "RPC: $RPC"
|
||||
echo "Gas price: $GAS_PRICE wei"
|
||||
echo ""
|
||||
|
||||
# 3) Ensure RPC is active (chainId 138)
|
||||
rpc_ok=""
|
||||
if [[ -z "$FORCE" ]]; then
|
||||
chain_id_hex=$(curl -s -m 10 -X POST "$RPC" -H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' 2>/dev/null | sed -n 's/.*"result":"\([^"]*\)".*/\1/p') || true
|
||||
if [[ "$chain_id_hex" == "0x8a" ]]; then
|
||||
rpc_ok=1
|
||||
else
|
||||
if [[ -n "$chain_id_hex" ]]; then
|
||||
echo "RPC returned chainId $chain_id_hex (expected 0x8a for Chain 138)." >&2
|
||||
else
|
||||
echo "RPC unreachable or invalid response: $RPC" >&2
|
||||
fi
|
||||
if [[ "$RPC" == *"192.168.11.211"* ]] && [[ "$PUBLIC_RPC" != *"192.168.11.211"* ]]; then
|
||||
pub_hex=$(curl -s -m 5 -X POST "$PUBLIC_RPC" -H "Content-Type: application/json" \
|
||||
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' 2>/dev/null | sed -n 's/.*"result":"\([^"]*\)".*/\1/p') || true
|
||||
if [[ "$pub_hex" == "0x8a" ]]; then
|
||||
echo "Using Public RPC: $PUBLIC_RPC" >&2
|
||||
RPC="$PUBLIC_RPC"
|
||||
rpc_ok=1
|
||||
fi
|
||||
fi
|
||||
if [[ -z "$rpc_ok" ]]; then
|
||||
echo "Set RPC_URL_138 (and optionally RPC_URL_138_PUBLIC) in $SMOM/.env to a reachable Chain 138 RPC." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "(--force: skipping RPC check)" >&2
|
||||
fi
|
||||
|
||||
# 4) Always check deployer nonce (pending) and set NEXT_NONCE for scripts
|
||||
DEPLOYER=$(cast wallet address --private-key "$PRIVATE_KEY" 2>/dev/null) || { echo "cast wallet address failed. Check PRIVATE_KEY in .env." >&2; exit 1; }
|
||||
NONCE_PENDING=$(cast nonce "$DEPLOYER" --rpc-url "$RPC" --block pending 2>/dev/null) || true
|
||||
NONCE_LATEST=$(cast nonce "$DEPLOYER" --rpc-url "$RPC" --block latest 2>/dev/null) || true
|
||||
# Normalize: empty or non-numeric -> use latest, then 0; ensure decimal for export
|
||||
[[ -z "${NONCE_PENDING//[0-9a-fA-Fx]/}" && -n "$NONCE_PENDING" ]] || NONCE_PENDING="$NONCE_LATEST"
|
||||
[[ -z "${NONCE_PENDING//[0-9a-fA-Fx]/}" && -n "$NONCE_PENDING" ]] || NONCE_PENDING="0"
|
||||
NONCE_PENDING=$((NONCE_PENDING))
|
||||
NONCE_LATEST=$((NONCE_LATEST))
|
||||
# Use pending nonce so we don't resend at same nonce (avoids "Known transaction" / "Replacement underpriced")
|
||||
export NEXT_NONCE=$NONCE_PENDING
|
||||
echo "Deployer: $DEPLOYER"
|
||||
echo "Nonce (pending): $NONCE_PENDING (latest: $NONCE_LATEST) — using NEXT_NONCE=$NEXT_NONCE"
|
||||
echo ""
|
||||
|
||||
if [[ -n "$DRY_RUN" ]]; then
|
||||
echo "[dry-run] Would run:"
|
||||
echo " 1. NEXT_NONCE=$NEXT_NONCE forge script script/DeployTransactionMirror.s.sol:DeployTransactionMirror --rpc-url \"\$RPC\" --broadcast --private-key \"\$PRIVATE_KEY\" --with-gas-price $GAS_PRICE"
|
||||
echo " 2. NEXT_NONCE=\$(next after 1) forge script script/dex/CreateCUSDTCUSDCPool.s.sol:CreateCUSDTCUSDCPool --rpc-url \"\$RPC\" --broadcast --private-key \"\$PRIVATE_KEY\" --with-gas-price $GAS_PRICE"
|
||||
echo " 3. $PROJECT_ROOT/scripts/verify/check-contracts-on-chain-138.sh \"$RPC\""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cd "$SMOM"
|
||||
export RPC_URL_138="$RPC"
|
||||
export DODO_PMM_INTEGRATION="${DODO_PMM_INTEGRATION_ADDRESS:-${DODO_PMM_INTEGRATION:-0x79cdbaFBaA0FdF9F55D26F360F54cddE5c743F7D}}"
|
||||
|
||||
echo "Deploying TransactionMirror (NEXT_NONCE=$NEXT_NONCE, gas $GAS_PRICE)..."
|
||||
forge script script/DeployTransactionMirror.s.sol:DeployTransactionMirror \
|
||||
--rpc-url "$RPC" --broadcast --private-key "$PRIVATE_KEY" --with-gas-price "$GAS_PRICE"
|
||||
|
||||
# Re-query pending nonce for pool deploy; wait briefly so first tx can be mined (reduces "Replacement transaction underpriced")
|
||||
sleep 3
|
||||
NONCE_USED_FIRST=$NEXT_NONCE
|
||||
NEXT_NONCE=$(cast nonce "$DEPLOYER" --rpc-url "$RPC" --block pending 2>/dev/null) || true
|
||||
[[ -z "${NEXT_NONCE//[0-9a-fA-Fx]/}" && -n "$NEXT_NONCE" ]] || NEXT_NONCE=$((NONCE_USED_FIRST + 1))
|
||||
NEXT_NONCE=$((NEXT_NONCE))
|
||||
export NEXT_NONCE
|
||||
|
||||
# Retry pool deploy with gas bump on "Replacement transaction underpriced"
|
||||
POOL_GAS="$GAS_PRICE"
|
||||
POOL_MAX_RETRIES=4
|
||||
POOL_RETRY=0
|
||||
while true; do
|
||||
echo ""
|
||||
echo "Creating DODO cUSDT/cUSDC pool (NEXT_NONCE=$NEXT_NONCE, gas $POOL_GAS)..."
|
||||
POOL_OUTPUT=$(forge script script/dex/CreateCUSDTCUSDCPool.s.sol:CreateCUSDTCUSDCPool \
|
||||
--rpc-url "$RPC" --broadcast --private-key "$PRIVATE_KEY" --with-gas-price "$POOL_GAS" 2>&1) || true
|
||||
echo "$POOL_OUTPUT"
|
||||
if echo "$POOL_OUTPUT" | grep -q "Replacement transaction underpriced"; then
|
||||
POOL_RETRY=$((POOL_RETRY + 1))
|
||||
if [[ $POOL_RETRY -ge $POOL_MAX_RETRIES ]]; then
|
||||
echo "Error: Pool deploy failed after $POOL_MAX_RETRIES attempts (Replacement transaction underpriced). Clear tx pool or increase GAS_PRICE_138." >&2
|
||||
exit 1
|
||||
fi
|
||||
POOL_GAS=$((POOL_GAS * 12 / 10))
|
||||
echo "Replacement transaction underpriced — retrying at same nonce $NEXT_NONCE with gas price $POOL_GAS wei (attempt $((POOL_RETRY + 1))/$POOL_MAX_RETRIES)."
|
||||
sleep 5
|
||||
continue
|
||||
fi
|
||||
if echo "$POOL_OUTPUT" | grep -q "Script ran successfully"; then
|
||||
break
|
||||
fi
|
||||
echo "Pool deploy failed. Check output above." >&2
|
||||
exit 1
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "Running on-chain verification..."
|
||||
"$PROJECT_ROOT/scripts/verify/check-contracts-on-chain-138.sh" "$RPC"
|
||||
Reference in New Issue
Block a user