diff --git a/deploy_rln_contract.sh b/deploy_rln_contract.sh index 6f1a6ff..ec01ad4 100644 --- a/deploy_rln_contract.sh +++ b/deploy_rln_contract.sh @@ -2,54 +2,17 @@ set -e -# 1. Retrieve contract details from the git repo and extract bytecode -apk add curl -repo_url="https://github.com/waku-org/waku-rln-contract/blob/main/deployments/sepolia/" -poseidon_hasher_json="PoseidonHasher.json" -waku_rln_registry_impl_json="WakuRlnRegistry_Implementation.json"; -waku_rln_registry_proxy_json="WakuRlnRegistry_Proxy.json" +# 1. Install foundry +curl -L https://foundry.paradigm.xyz | bash && . /root/.bashrc && foundryup && export PATH=$PATH:$HOME/.foundry/bin -curl -o "$poseidon_hasher_json" "$repo_url$poseidon_hasher_json" -curl -o "$waku_rln_registry_impl_json" "$repo_url$waku_rln_registry_impl_json" -curl -o "$waku_rln_registry_proxy_json" "$repo_url$waku_rln_registry_proxy_json" +#. 2. Clone and build waku-rln-contract repo +git clone https://github.com/waku-org/waku-rln-contract.git +cd /waku-rln-contract +forge install && yarn install && yarn compile -json_contents=$(cat $poseidon_hasher_json) -poseidon_hasher_bytecode=$(echo "$json_contents" | grep -o 'bytecode\\"[^,]*' | awk -F '0x' '{print "0x" substr($2, 1, length($2)-2)}') +# 3. Create .env file with RPC_PROVIDER variable +echo "creating .env file with RPC_PROVIDER=$RPC_URL" +echo "RPC_PROVIDER=$RPC_URL" > .env -json_contents=$(cat $waku_rln_registry_impl_json) -waku_rln_registry_impl_bytecode=$(echo "$json_contents" | grep -o 'bytecode\\"[^,]*' | awk -F '0x' '{print "0x" substr($2, 1, length($2)-2)}') - -json_contents=$(cat $waku_rln_registry_proxy_json) -waku_rln_registry_proxy_bytecode=$(echo "$json_contents" | grep -o 'bytecode\\"[^,]*' | awk -F '0x' '{print "0x" substr($2, 1, length($2)-2)}') - -echo "Deploying RLN contracts..." - -# 2. Deploy Poseidon Hasher -poseidon_address=$(cast send --rpc-url $RPC_URL --private-key $PRIVATE_KEY --create $poseidon_hasher_bytecode | grep contractAddress | cut -d' ' -f10) - -# 3. Deploy Waku Rln Registry Implementation -implementation_address=$(cast send --rpc-url $RPC_URL --private-key $PRIVATE_KEY --create $waku_rln_registry_impl_bytecode | grep contractAddress | cut -d' ' -f10) - -# 4. Concatenate Waku Rln Registry Proxy Bytecode with constructor arguments in the form of -# constructor(address implementation, bytes memory data) -# where data = abi.encodeWithSignature("initialize(address)", address(poseidonHasher)) - -constructor_arguments=$(cast abi-encode "constructor(address impl, bytes data)" "$implementation_address" $(cast calldata "initialize(address)" "$poseidon_address") | cut -c 3-) -waku_rln_registry_proxy_bytecode_with_constructor_arguments="$waku_rln_registry_proxy_bytecode$constructor_arguments" - -# 5. Deploy Waku Rln Registry Proxy -waku_rln_registry_proxy_address=$(cast send --rpc-url $RPC_URL --private-key $PRIVATE_KEY --create $waku_rln_registry_proxy_bytecode_with_constructor_arguments | grep contractAddress | cut -d' ' -f10) - -# 6. Deploy New Storage -deploy_new_storage_out=$(cast send --rpc-url $RPC_URL --private-key $PRIVATE_KEY $waku_rln_registry_proxy_address "newStorage()") -# Fetch the new storage address -new_storage_address=$(cast call --rpc-url $RPC_URL $waku_rln_registry_proxy_address "storages(uint16)(address)" 0) - -printf "%-50s %s\n" "Contract" "Contract Address" -printf "%-50s %s\n" "--------" "----------------" - -# Print data in table format -printf "%-50s %s\n" "PoseidonHasher" "$poseidon_address" -printf "%-50s %s\n" "Waku_Rln_Registry_Implementation" "$implementation_address" -printf "%-50s %s\n" "Waku_Rln_Registry_Proxy" "$waku_rln_registry_proxy_address" -printf "%-50s %s\n" "New_Storage" "$new_storage_address" \ No newline at end of file +# 3. Deploy the contracts +yarn deploy localhost_integration \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b0514d3..d965fd7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,9 +16,6 @@ services: com.centurylinklabs.watchtower.enable: '${WATCHTOWER_ENABLED:-false}' ports: - 127.0.0.1:8545:8545 - environment: - - RPC_URL=http://localhost:8545 - - PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 command: - anvil --port=8545 @@ -29,10 +26,21 @@ services: --block-time=12 --silent --config-out=anvil-config.txt - & /opt/deploy_rln_contract.sh - & tail -f /dev/null + networks: + - simulation + + contract-repo-deployer: + image: node:hydrogen-bullseye + labels: + com.centurylinklabs.watchtower.enable: '${WATCHTOWER_ENABLED:-false}' + environment: + - RPC_URL=${RPC_URL:-http://foundry:8545} + command: + - '/opt/deploy_rln_contract.sh' volumes: - - ./deploy_rln_contract.sh:/opt/deploy_rln_contract.sh:Z + - ./deploy_rln_contract.sh:/opt/deploy_rln_contract.sh + depends_on: + - foundry networks: - simulation @@ -64,7 +72,7 @@ services: replicas: ${NUM_NWAKU_NODES:-5} entrypoint: sh environment: - - RPC_URL=http://foundry:8545 + - RPC_URL=${RPC_URL:-http://foundry:8545} - PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - RLN_CONTRACT_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 - RLN_CREDENTIAL_PATH=/keystore.json @@ -75,7 +83,7 @@ services: - ./run_nwaku.sh:/opt/run_nwaku.sh:Z depends_on: - bootstrap - - foundry + - contract-repo-deployer networks: - simulation @@ -173,7 +181,7 @@ services: ports: - 127.0.0.1:8090:8090 environment: - - NODE_ENDPOINT=http://foundry:8545 + - NODE_ENDPOINT=${RPC_URL:-http://foundry:8545} - MONGO_CLIENT_URI=mongodb://mongodb:27017 - REINDEX_ENDPOINT=http://ingestion/reindex/ - MONGO_DB_NAME=epirus @@ -212,7 +220,7 @@ services: ingestion: image: web3labs/epirus-free-ingestion:latest environment: - - NODE_ENDPOINT=http://foundry:8545 + - NODE_ENDPOINT=${RPC_URL:-http://foundry:8545} - MONGO_CLIENT_URI=mongodb://mongodb:27017 - MONGO_DB_NAME=epirus - LIST_OF_METRICS_TO_CALCULATE_PER_MINUTE=hourly,daily,monthly,yearly