|
| 1 | +.POSIX: |
| 2 | +.SILENT: |
| 3 | + |
| 4 | +.PHONY: devnet-up devnet-down check-deps clean all |
| 5 | + |
| 6 | +# Variables |
| 7 | +ANVIL_PORT = 8545 |
| 8 | +ANVIL_BLOCK_TIME = 2 |
| 9 | +RISC0_DEV_MODE = 1 |
| 10 | +RUST_LOG = info,broker=debug,boundless_market=debug |
| 11 | +PRIV_KEY = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 |
| 12 | +DEPOSIT_AMOUNT = 10 |
| 13 | + |
| 14 | +LOGS_DIR = logs |
| 15 | +PID_FILE = $(LOGS_DIR)/devnet.pid |
| 16 | + |
| 17 | +all: devnet-up |
| 18 | + |
| 19 | +# Check that required dependencies are installed |
| 20 | +check-deps: |
| 21 | + for cmd in forge cargo anvil jq; do \ |
| 22 | + command -v $$cmd >/dev/null 2>&1 || { echo "Error: $$cmd is not installed."; exit 1; }; \ |
| 23 | + done |
| 24 | + |
| 25 | +devnet-up: check-deps |
| 26 | + mkdir -p $(LOGS_DIR) |
| 27 | + echo "Building contracts..." |
| 28 | + forge build || { echo "Failed to build contracts"; $(MAKE) devnet-down; exit 1; } |
| 29 | + echo "Building Rust project..." |
| 30 | + cargo build --bin broker || { echo "Failed to build broker binary"; $(MAKE) devnet-down; exit 1; } |
| 31 | + echo "Starting Anvil..." |
| 32 | + anvil -b $(ANVIL_BLOCK_TIME) > $(LOGS_DIR)/anvil.txt 2>&1 & echo $$! >> $(PID_FILE) |
| 33 | + sleep 5 |
| 34 | + echo "Deploying contracts..." |
| 35 | + RISC0_DEV_MODE=$(RISC0_DEV_MODE) forge script contracts/scripts/Deploy.s.sol --rpc-url http://localhost:$(ANVIL_PORT) --broadcast -vv || { echo "Failed to deploy contracts"; $(MAKE) devnet-down; exit 1; } |
| 36 | + echo "Fetching contract addresses..." |
| 37 | + { \ |
| 38 | + SET_VERIFIER_ADDRESS=$$(jq -re '.transactions[] | select(.contractName == "RiscZeroSetVerifier") | .contractAddress' ./broadcast/Deploy.s.sol/31337/run-latest.json); \ |
| 39 | + PROOF_MARKET_ADDRESS=$$(jq -re '.transactions[] | select(.contractName == "ProofMarket") | .contractAddress' ./broadcast/Deploy.s.sol/31337/run-latest.json); \ |
| 40 | + echo "Contract deployed at addresses:"; \ |
| 41 | + echo "SET_VERIFIER_ADDRESS=$$SET_VERIFIER_ADDRESS"; \ |
| 42 | + echo "PROOF_MARKET_ADDRESS=$$PROOF_MARKET_ADDRESS"; \ |
| 43 | + echo "Updating .env file..."; \ |
| 44 | + sed -i.bak "s/^SET_VERIFIER_ADDRESS=.*/SET_VERIFIER_ADDRESS=$$SET_VERIFIER_ADDRESS/" .env && \ |
| 45 | + sed -i.bak "s/^PROOF_MARKET_ADDRESS=.*/PROOF_MARKET_ADDRESS=$$PROOF_MARKET_ADDRESS/" .env && \ |
| 46 | + rm .env.bak; \ |
| 47 | + echo ".env file updated successfully."; \ |
| 48 | + echo "Starting Broker service..."; \ |
| 49 | + RISC0_DEV_MODE=$(RISC0_DEV_MODE) RUST_LOG=$(RUST_LOG) ./target/debug/broker \ |
| 50 | + --priv-key $(PRIV_KEY) \ |
| 51 | + --proof-market-addr $$PROOF_MARKET_ADDRESS \ |
| 52 | + --set-verifier-addr $$SET_VERIFIER_ADDRESS \ |
| 53 | + --deposit-amount $(DEPOSIT_AMOUNT) > $(LOGS_DIR)/broker.txt 2>&1 & echo $$! >> $(PID_FILE); \ |
| 54 | + } || { echo "Failed to fetch addresses or start broker"; $(MAKE) devnet-down; exit 1; } |
| 55 | + echo "Devnet is up and running!" |
| 56 | + echo "Make sure to run 'source .env' to load the environment variables." |
| 57 | + |
| 58 | +devnet-down: |
| 59 | + echo "Bringing down all services..." |
| 60 | + if [ -f $(PID_FILE) ]; then \ |
| 61 | + while read pid; do \ |
| 62 | + kill $$pid 2>/dev/null || true; \ |
| 63 | + done < $(PID_FILE); \ |
| 64 | + rm $(PID_FILE); \ |
| 65 | + fi |
| 66 | + echo "Devnet stopped." |
| 67 | + |
| 68 | +clean: devnet-down |
| 69 | + echo "Cleaning up..." |
| 70 | + rm -rf $(LOGS_DIR) ./broadcast |
| 71 | + cargo clean |
| 72 | + forge clean |
| 73 | + echo "Cleanup complete." |
0 commit comments