Skip to content

Commit

Permalink
remove manual execution of scripts during deployment (#388)
Browse files Browse the repository at this point in the history
- added create eve token and setup access control as part of the deploy
script in docker
- sourcing all configurable variables through .env file to docker. 
- adding a new command for world upgrade
  • Loading branch information
0xxlegolas authored Feb 5, 2025
1 parent deed527 commit 1216cce
Show file tree
Hide file tree
Showing 15 changed files with 939 additions and 738 deletions.
11 changes: 11 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# .env for the docker file
ERC20_TOKEN_NAME=EVE TOKEN
ERC20_TOKEN_SYMBOL=EVE
ERC20_INITIAL_SUPPLY=10000000000
EVE_TOKEN_NAMESPACE=eveerc20
# By default the token is minted to this address, you can transfer from this admin to other accounts or change this address
EVE_TOKEN_ADMIN=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

# ADMIN ACCESS ACCOUNTS (to assign to the ADMIN access to the world contracts)
# Add the list of admins by comma separated address
ADMIN_ACCOUNTS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266,0x70997970C51812dc3A010C7d01b50e0d17dc79C8,0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
2 changes: 1 addition & 1 deletion build/package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Pull the image from our docker registry (URL TBD).
and run it with the command:

```bash
docker run --name world-deployer -it deployer-image --rpc-url http://host.docker.internal:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
docker run --env-file .env --name world-deployer -it deployer-image --rpc-url http://host.docker.internal:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

```

Expand Down
102 changes: 64 additions & 38 deletions build/package/deploy-in-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/sh
set -eou pipefail

# Define the log file
LOG_FILE="./logfile.log"
mkdir -p logs

# Ensure the log file is copied to the logs folder on exit
trap 'cp $LOG_FILE "logs/$(date +%Y%m%d_%H%M%S)-deploy-in-docker.log"' EXIT

bar_size=40
bar_char_done="#"
bar_char_todo="-"
Expand Down Expand Up @@ -41,14 +48,14 @@ get_chain_id() {

# Check if curl command was successful (exit code 0)
if [ $success -ne 0 ]; then
echo "Error: Failed to fetch chain ID from RPC URL: $rpc_url"
echo "Error: Failed to fetch chain ID from RPC URL: $rpc_url" | tee -a $LOG_FILE
return 1
fi

# Extract the result and handle the case where no result is found
local chain_id_hex=$(echo "$response" | jq -r '.result')
if [ "$chain_id_hex" = "null" ] || [ -z "$chain_id_hex" ]; then
echo "Error: No valid chain ID returned from the RPC URL: $rpc_url"
echo "Error: No valid chain ID returned from the RPC URL: $rpc_url" | tee -a $LOG_FILE
return 1
fi

Expand Down Expand Up @@ -78,7 +85,7 @@ while [ $# -gt 0 ]; do
shift 2
;;
*)
echo "Unknown option: $1"
echo "Unknown option: $1" | tee -a $LOG_FILE
exit 1
;;
esac
Expand All @@ -88,67 +95,67 @@ done
# Fetch and export the chain ID
chain_id=$(get_chain_id "$rpc_url")
wait
echo "Using chain ID: $chain_id"
echo "Using chain ID: $chain_id" | tee -a $LOG_FILE

## Temporarily hardcode private key and rpc url before adding them as params
export RPC_URL="$rpc_url"
export PRIVATE_KEY="$private_key"

show_progress 0 7
show_progress 0 8

#1 Deploying the standard contracts
echo " - Deploying standard contracts..."
pnpm nx run @eveworld/standard-contracts:deploy 1> '/dev/null'
echo " - Deploying standard contracts..." | tee -a $LOG_FILE
pnpm nx run @eveworld/standard-contracts:deploy >> $LOG_FILE 2>&1
wait
show_progress 1 7
show_progress 1 8

export FORWARDER_ADDRESS=$(cat ./standard-contracts/broadcast/Deploy.s.sol/$chain_id/run-latest.json | jq '.transactions|first|.contractAddress' | tr -d \")

#2 Deploy the world core
#
# If the world address was not set by a parameter we deploy a new core
# If the world address was passed as a parameter we are updating that world
echo " - Deploying world..."
echo " - Deploying world..." | tee -a $LOG_FILE
if [ -z "$world_address" ]; then
# If not set, execute a command to obtain the value
echo "No world address parameter set - Deploying a new world..."
pnpm nx deploy @eveworld/world-core 1> '/dev/null'
echo "No world address parameter set - Deploying a new world..." | tee -a $LOG_FILE
pnpm nx deploy @eveworld/world-core >> $LOG_FILE 2>&1
wait
show_progress 2 7
show_progress 2 8
world_address=$(cat ./mud-contracts/core/deploys/$chain_id/latest.json | jq '.worldAddress' | tr -d \")
export WORLD_ADDRESS="$world_address"
else
# If set, use that value
export WORLD_ADDRESS="$world_address"
echo "World address parameter set - Updating the world @ ${WORLD_ADDRESS}..."
pnpm nx deploy @eveworld/world-core --worldAddress '${WORLD_ADDRESS}' 1> '/dev/null'
echo "World address parameter set - Updating the world @ ${WORLD_ADDRESS}..." | tee -a $LOG_FILE
pnpm nx deploy @eveworld/world-core --worldAddress '${WORLD_ADDRESS}' >> $LOG_FILE 2>&1
wait
show_progress 2 7
show_progress 2 8
fi

#3 Configure the world to receive the forwarder
echo " - Configuring trusted forwarder within the world"
pnpm nx setForwarder @eveworld/world-core 1> '/dev/null'
echo " - Configuring trusted forwarder within the world" | tee -a $LOG_FILE
pnpm nx setForwarder @eveworld/world-core >> $LOG_FILE 2>&1

wait
show_progress 3 7
show_progress 3 8

#4 Deploy smart object framework
#
echo " - Installing smart object framework into world"
pnpm nx deploy @eveworld/smart-object-framework --worldAddress '${WORLD_ADDRESS}' 1> '/dev/null'
show_progress 4 7
echo " - Installing smart object framework into world" | tee -a $LOG_FILE
pnpm nx deploy @eveworld/smart-object-framework --worldAddress '${WORLD_ADDRESS}' >> $LOG_FILE 2>&1
show_progress 4 8

#5 Deploy world features
echo " - Deploying world features"
deployment_output=$(pnpm nx deploy @eveworld/world --worldAddress '${WORLD_ADDRESS}' 2>&1)
echo " - Deploying world features" | tee -a $LOG_FILE
deployment_output=$(pnpm nx deploy @eveworld/world --worldAddress '${WORLD_ADDRESS}' 2>&1 | tee -a $LOG_FILE)

# Extract the ERC721 token address from the output
smart_deployable_token_address=$(echo "$deployment_output" \
| grep "Deploying Smart Deployable token with address:" \
| grep -oE "0x[0-9a-fA-F]{40}")
if [ -z "$smart_deployable_token_address" ]; then
echo "Error: Failed to extract Deployable token address from deployment output."
echo "Error: Failed to extract Deployable token address from deployment output." | tee -a $LOG_FILE
exit 1
fi
export SMART_DEPLOYABLE_TOKEN_ADDRESS="$smart_deployable_token_address"
Expand All @@ -158,37 +165,56 @@ smart_character_token_address=$(echo "$deployment_output" \
| grep -oE "0x[0-9a-fA-F]{40}")

if [ -z "$smart_character_token_address" ]; then
echo "Error: Failed to extract Smart Character token address from deployment output."
echo "Error: Failed to extract Smart Character token address from deployment output." | tee -a $LOG_FILE
exit 1
fi
export SMART_CHARACTER_TOKEN_ADDRESS="$smart_character_token_address"

eve_token_address=$(echo "$deployment_output" \
| grep "Deploying ERC20 token with address:" \
| grep -oE "0x[0-9a-fA-F]{40}")

if [ -z "$eve_token_address" ]; then
echo "Error: Failed to extract EVE token address from deployment output." | tee -a $LOG_FILE
exit 1
fi
export EVE_TOKEN_ADDRESS="$eve_token_address"

wait
show_progress 5 7
show_progress 5 8

#6 Delegate Namespace Access
echo " - Delegating namespace access to forwarder contract"
pnpm nx delegateNamespaceAccess @eveworld/world-core 1> '/dev/null'
show_progress 6 7
echo " - Delegating namespace access to forwarder contract" | tee -a $LOG_FILE
pnpm nx delegateNamespaceAccess @eveworld/world-core >> $LOG_FILE 2>&1
show_progress 6 8

#7 Setup access control
echo " - Setting up access control" | tee -a $LOG_FILE
pnpm nx access-config:configure-all @eveworld/world > /dev/null >> $LOG_FILE 2>&1

wait
show_progress 7 8
echo " - Access controlled applied" | tee -a $LOG_FILE

echo " - Collecting ABIs"
echo " - Collecting ABIs" | tee -a $LOG_FILE
mkdir -p abis
mkdir -p abis/trusted-forwarder
mkdir -p abis/world

#7 Copy ABIS to be used for External consumption
#8 Copy ABIS to be used for External consumption
cp standard-contracts/out/ERC2771ForwarderWithHashNonce.sol/ERC2771Forwarder.abi.json "abis/trusted-forwarder/ERC2771Forwarder-${IMAGE_TAG}.abi.json"
cp mud-contracts/world/out/IWorld.sol/IWorld.abi.json "abis/world/IWorld-${IMAGE_TAG}.abi.json"

# Custom ERC2771 Compatible IWorld contract
jq 'map((.name? |= gsub("^eveworld__"; "")) // .)' "abis/world/IWorld-${IMAGE_TAG}.abi.json" > "abis/world/ERC2771IWorld-${IMAGE_TAG}.abi.json"

show_progress 7 7
show_progress 8 8

# Update run_env.json with the extracted addresses
echo '{"WORLD_ADDRESS":"'$WORLD_ADDRESS'", "FORWARDER_ADDRESS":"'$FORWARDER_ADDRESS'", "SMART_DEPLOYABLE_TOKEN_ADDRESS":"'$SMART_DEPLOYABLE_TOKEN_ADDRESS'", "SMART_CHARACTER_TOKEN_ADDRESS": "'$SMART_CHARACTER_TOKEN_ADDRESS'"}' > run_env.json

echo "World address: $WORLD_ADDRESS"
echo "Trusted forwarder address: $FORWARDER_ADDRESS"
echo "Smart Deployable token address: $SMART_DEPLOYABLE_TOKEN_ADDRESS"
echo "Smart Character token address: $SMART_CHARACTER_TOKEN_ADDRESS"
echo '{"WORLD_ADDRESS":"'$WORLD_ADDRESS'", "FORWARDER_ADDRESS":"'$FORWARDER_ADDRESS'", "EVE_TOKEN_ADDRESS":"'$EVE_TOKEN_ADDRESS'", "SMART_DEPLOYABLE_TOKEN_ADDRESS":"'$SMART_DEPLOYABLE_TOKEN_ADDRESS'", "SMART_CHARACTER_TOKEN_ADDRESS": "'$SMART_CHARACTER_TOKEN_ADDRESS'"}' > run_env.json

echo "World address: $WORLD_ADDRESS" | tee -a $LOG_FILE
echo "Trusted forwarder address: $FORWARDER_ADDRESS" | tee -a $LOG_FILE
echo "Smart Deployable token address: $SMART_DEPLOYABLE_TOKEN_ADDRESS" | tee -a $LOG_FILE
echo "Smart Character token address: $SMART_CHARACTER_TOKEN_ADDRESS" | tee -a $LOG_FILE
echo "EVE token address: $EVE_TOKEN_ADDRESS" | tee -a $LOG_FILE
2 changes: 1 addition & 1 deletion end-to-end-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@eveworld/smart-object-framework": "0.0.8",
"@eveworld/world": "0.0.17",
"@eveworld/world-core": "link:../mud-contracts/core",
"@latticexyz/cli": "2.2.8",
"@latticexyz/cli": "2.2.14",
"@latticexyz/gas-report": "2.2.8",
"@latticexyz/schema-type": "2.2.8",
"@latticexyz/store": "2.2.8",
Expand Down
2 changes: 1 addition & 1 deletion mud-contracts/common/constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.13",
"license": "MIT",
"dependencies": {
"@latticexyz/cli": "2.2.8",
"@latticexyz/cli": "2.2.14",
"@latticexyz/schema-type": "2.2.8",
"@latticexyz/store": "2.2.8",
"@latticexyz/world": "2.2.8",
Expand Down
8 changes: 4 additions & 4 deletions mud-contracts/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"build:mud": "rm -rf src/codegen && mud tablegen && mud worldgen",
"clean": "rm -rf src/codegen && rm -rf out && rm -rf cache",
"deploy": "PRIVATE_KEY=$PRIVATE_KEY mud deploy --rpc $RPC_URL",
"setForwarder": "WORLD_ADDRESS=$WORLD_ADDRESS FORWARDER_ADDRESS=$FORWARDER_ADDRESS forge script script/SetForwarder.s.sol:SetForwarder --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig \"run(address)\" $WORLD_ADDRESS -vvv",
"delegateNamespaceAccess": "WORLD_ADDRESS=$WORLD_ADDRESS FORWARDER_ADDRESS=$FORWARDER_ADDRESS forge script script/DelegateNamespace.s.sol:DelegateNamespace --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig \"run(address)\" $WORLD_ADDRESS -vvvv",
"setForwarder": "WORLD_ADDRESS=$WORLD_ADDRESS FORWARDER_ADDRESS=$FORWARDER_ADDRESS forge script script/SetForwarder.s.sol:SetForwarder --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig \"run(address)\" $WORLD_ADDRESS",
"delegateNamespaceAccess": "WORLD_ADDRESS=$WORLD_ADDRESS FORWARDER_ADDRESS=$FORWARDER_ADDRESS forge script script/DelegateNamespace.s.sol:DelegateNamespace --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --sig \"run(address)\" $WORLD_ADDRESS",
"dev": "pnpm mud dev-contracts",
"lint": "pnpm run prettier && pnpm run solhint",
"prettier": "prettier 'src/**/*.sol' './*.ts' --plugin=prettier-plugin-solidity --check",
Expand All @@ -20,7 +20,7 @@
"test": "tsc --noEmit && mud test"
},
"dependencies": {
"@latticexyz/cli": "2.2.8",
"@latticexyz/cli": "2.2.14",
"@latticexyz/schema-type": "2.2.8",
"@latticexyz/store": "2.2.8",
"@latticexyz/world": "2.2.8",
Expand All @@ -40,4 +40,4 @@
"solhint-plugin-mud": "2.2.8",
"typescript": "^5.4.5"
}
}
}
6 changes: 3 additions & 3 deletions mud-contracts/smart-object-framework-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"license": "MIT",
"private": true,
"scripts": {
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
"build": "pnpm run clean && pnpm run build:mud && pnpm run build:abi",
"build:abi": "forge build",
"build:abi-ts": "mud abi-ts",
"build:mud": "rm -rf src/codegen && mud tablegen && mud worldgen",
"clean": "rm -rf src/codegen && rm -rf out && rm -rf cache",
"clean": "forge clean && rm -rf src/codegen && rm -rf out && rm -rf cache",
"deploy:local": "PRIVATE_KEY=$PRIVATE_KEY mud deploy --rpc $RPC_URL",
"dev": "pnpm mud dev-contracts",
"lint": "pnpm run prettier && pnpm run solhint",
Expand Down Expand Up @@ -37,4 +37,4 @@
"solhint-plugin-mud": "2.2.11",
"typescript": "^5.4.5"
}
}
}
2 changes: 1 addition & 1 deletion mud-contracts/smart-object-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@eveworld/common-constants": "0.0.13",
"@latticexyz/cli": "2.2.8",
"@latticexyz/cli": "2.2.14",
"@latticexyz/schema-type": "2.2.8",
"@latticexyz/store": "2.2.8",
"@latticexyz/world": "2.2.8",
Expand Down
15 changes: 12 additions & 3 deletions mud-contracts/world/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
DEBUG=mud:*
#
# Anvil default private key:
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
RPC_URL=http://127.0.0.1:8545
PRIVATE_KEY=
RPC_URL=
CHAIN_ID=31337
# TO BE POPULATED FROM the /world-chain-contracts/pnpm run dev .scripts/deploy-all.sh process
WORLD_ADDRESS=
Expand All @@ -18,4 +18,13 @@ WORLD_ADDRESS=
BASE_URI=http://127.0.0.1:8080/ipfs/

# ADMIN ACCESS ACCOUNTS (to assign to the ADMIN access list in the InventoryAccess.s.sol script)
ADMIN_ACCOUNTS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # only the deployer account for testing
# Add the list of admins by comma separated address
ADMIN_ACCOUNTS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266,0x70997970C51812dc3A010C7d01b50e0d17dc79C8,0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC

ERC20_TOKEN_NAME=EVE TOKEN
ERC20_TOKEN_SYMBOL=EVE
ERC20_INITIAL_SUPPLY=10000000000
EVE_TOKEN_NAMESPACE=test
# By default the token is minted to this address, you can transfer from this admin to other accounts or change this address
EVE_TOKEN_ADMIN=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

11 changes: 0 additions & 11 deletions mud-contracts/world/.env.devnet

This file was deleted.

11 changes: 0 additions & 11 deletions mud-contracts/world/.env.testnet

This file was deleted.

Loading

0 comments on commit 1216cce

Please sign in to comment.