All checks were successful
CI / lint-and-test (push) Successful in 9m52s
Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
2.2 KiB
Bash
Executable File
70 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Sync contract addresses from contracts/deployments/chain138.json into app env files.
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
DEPLOY="$ROOT/contracts/deployments/chain138.json"
|
|
|
|
if [[ ! -f "$DEPLOY" ]]; then
|
|
echo "Missing $DEPLOY — run: cd contracts && pnpm run deploy:chain138" >&2
|
|
exit 1
|
|
fi
|
|
|
|
TREASURY=$(jq -r '.contracts.TreasuryWallet' "$DEPLOY")
|
|
FACTORY=$(jq -r '.contracts.SubAccountFactory' "$DEPLOY")
|
|
DEPLOY_BLOCK=$(jq -r '.deployBlock // empty' "$DEPLOY")
|
|
|
|
if [[ -z "$TREASURY" || "$TREASURY" == "null" ]]; then
|
|
echo "TreasuryWallet missing in deployment JSON" >&2
|
|
exit 1
|
|
fi
|
|
|
|
set_env() {
|
|
local file="$1"
|
|
local key="$2"
|
|
local value="$3"
|
|
if [[ ! -f "$file" ]]; then
|
|
touch "$file"
|
|
fi
|
|
if grep -q "^${key}=" "$file" 2>/dev/null; then
|
|
sed -i "s|^${key}=.*|${key}=${value}|" "$file"
|
|
else
|
|
echo "${key}=${value}" >> "$file"
|
|
fi
|
|
}
|
|
|
|
PUBLIC_RPC="${CHAIN138_PUBLIC_RPC_URL:-https://rpc-http-pub.d-bis.org}"
|
|
LAN_RPC="${CHAIN138_RPC_URL:-http://192.168.11.211:8545}"
|
|
LAN_WS="${CHAIN138_WS_URL:-ws://192.168.11.211:8546}"
|
|
|
|
for f in "$ROOT/frontend/.env.local" "$ROOT/frontend/.env.production"; do
|
|
[[ -f "$f" ]] || continue
|
|
set_env "$f" NEXT_PUBLIC_TREASURY_WALLET_ADDRESS "$TREASURY"
|
|
set_env "$f" NEXT_PUBLIC_SUB_ACCOUNT_FACTORY_ADDRESS "$FACTORY"
|
|
set_env "$f" NEXT_PUBLIC_CHAIN138_RPC_URL "$PUBLIC_RPC"
|
|
set_env "$f" NEXT_PUBLIC_CHAIN138_WS_URL ""
|
|
set_env "$f" NEXT_PUBLIC_CHAIN138_EXPLORER_URL "${CHAIN138_PUBLIC_EXPLORER_URL:-https://explorer.d-bis.org}"
|
|
set_env "$f" NEXT_PUBLIC_CHAIN_ID "138"
|
|
done
|
|
|
|
for f in "$ROOT/backend/.env" "$ROOT/backend/.env.indexer"; do
|
|
[[ -f "$f" ]] || continue
|
|
set_env "$f" CONTRACT_ADDRESS "$TREASURY"
|
|
set_env "$f" FACTORY_ADDRESS "$FACTORY"
|
|
set_env "$f" RPC_URL "$LAN_RPC"
|
|
set_env "$f" CLIENT_RPC_URL "$PUBLIC_RPC"
|
|
set_env "$f" CHAIN_ID "138"
|
|
if [[ -n "$DEPLOY_BLOCK" && "$DEPLOY_BLOCK" != "null" ]]; then
|
|
set_env "$f" START_BLOCK "$DEPLOY_BLOCK"
|
|
fi
|
|
done
|
|
|
|
for f in "$ROOT/backend/.env.indexer"; do
|
|
[[ -f "$f" ]] || continue
|
|
set_env "$f" FACTORY_ADDRESS "$FACTORY"
|
|
done
|
|
|
|
echo "Synced deployment addresses:"
|
|
echo " TreasuryWallet: $TREASURY"
|
|
echo " SubAccountFactory: $FACTORY"
|