-
Notifications
You must be signed in to change notification settings - Fork 0
/
launchmevcommit
executable file
·209 lines (175 loc) · 6.71 KB
/
launchmevcommit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
missing_utils=()
required_utilities=(
jq
sed
curl
cast
)
for util in "${required_utilities[@]}"; do
if ! command -v "${util}" &> /dev/null; then
missing_utils+=("${util}")
fi
done
if [[ ${#missing_utils[@]} -ne 0 ]]; then
echo "Error: The following utilities are required and not installed: ${missing_utils[*]}."
exit 1
fi
# Default variables
DEVENV=false
NODE_TYPE=""
MEV_COMMIT_VERSION="v0.4.2"
ROOT_DIRECTORY="${HOME}/.mev-commit"
RPC_URL="https://chainrpc.testnet.mev-commit.xyz"
FAUCET_URL="http://faucet.testnet.mev-commit.xyz"
CONTRACTS_URL="$(curl --silent https://contracts.testnet.mev-commit.xyz)"
ARTIFACTS_URL="https://github.com/primev/mev-commit/releases/download/${MEV_COMMIT_VERSION}"
# Function to show usage
usage() {
echo "Usage: $0 --rpc-url <RPC_URL> --node-type <NODE_TYPE> --devenv"
exit 1
}
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case ${1} in
--rpc-url) RPC_URL="${2}"; shift ;;
--node-type) NODE_TYPE="${2}"; shift ;;
--devenv) DEVENV=true ;;
*) echo "Error: Unknown parameter passed: ${1}"; usage ;;
esac
shift
done
# Check if RPC_URL and NODE_TYPE are provided
if [ -z "${NODE_TYPE}" ]; then
echo "Error: Missing required argument --node-type."
usage
fi
if [ ${DEVENV} == true ]; then
IP_ADDRESS=$(echo "${RPC_URL}" | sed -E 's#.*://([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*#\1#')
if [[ ! "${IP_ADDRESS}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: No IP address found in the URL."
exit 1
fi
FAUCET_URL="http://${IP_ADDRESS}"
RESPONSE=$(curl --silent --fail "${IP_ADDRESS}:1111/meta.json")
if [ $? -ne 0 ]; then
echo "Error: Failed to fetch meta.json."
exit 1
fi
VERSION=$(echo "${RESPONSE}" | jq -r '.version')
if [ -z "${VERSION}" ]; then
echo "Error: Failed to fetch version."
exit 1
fi
CONTRACTS_URL="$(curl --silent --fail http://${IP_ADDRESS}:1010/contracts.json)"
if [ $? -ne 0 ]; then
echo "Error: Failed to fetch contracts."
exit 1
fi
ARTIFACTS_URL="http://${IP_ADDRESS}:1111"
else
VERSION=${MEV_COMMIT_VERSION:1}
fi
# Contract Addresses
export MEV_COMMIT_BLOCK_TRACKER_ADDR="$(echo ${CONTRACTS_URL} | jq -r '.BlockTracker')"
export MEV_COMMIT_BIDDER_REGISTRY_ADDR="$(echo ${CONTRACTS_URL} | jq -r '.BidderRegistry')"
export MEV_COMMIT_PROVIDER_REGISTRY_ADDR="$(echo ${CONTRACTS_URL} | jq -r '.ProviderRegistry')"
export MEV_COMMIT_PRECONF_ADDR="$(echo ${CONTRACTS_URL} | jq -r '.PreConfCommitmentStore')"
# Determine OS and Architecture
OS=$(uname -s)
ARCH=$(uname -m)
# Select the correct file based on OS and Architecture
case $OS in
"Darwin")
case $ARCH in
"arm64") FILE="mev-commit_${VERSION}_Darwin_arm64.tar.gz" ;;
"x86_64") FILE="mev-commit_${VERSION}_Darwin_x86_64.tar.gz" ;;
*) echo "Error: Unsupported architecture"; exit 1 ;;
esac
;;
"Linux")
case $ARCH in
"arm64") FILE="mev-commit_${VERSION}_Linux_arm64.tar.gz" ;;
"x86_64") FILE="mev-commit_${VERSION}_Linux_x86_64.tar.gz" ;;
*) echo "Error: Unsupported architecture"; exit 1 ;;
esac
;;
"Windows_NT")
FILE="mev-commit_${VERSION}_Windows_x86_64.zip"
;;
*)
echo "Error: Unsupported operating system"
exit 1
;;
esac
# Download the file using curl
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Downloading mev-commit files...\033[0m"
curl -s -L "${ARTIFACTS_URL}/${FILE}" -o "${FILE}"
# Check if the download was successful
if [ ! -f "${FILE}" ]; then
echo "Error: Failed to download the file."
exit 1
fi
# Check the file type
file "${FILE}"
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Installing foundry...\033[0m"
# Create the foundry directory if it doesn't exist
if [ ! -d ~/.foundry/bin ]; then
curl -s -L https://foundry.paradigm.xyz | bash
${HOME}/.foundry/bin/foundryup
fi
# Create the target directory if it doesn't exist
mkdir -p ${ROOT_DIRECTORY}
# Extract the file to the target directory with verbose output
tar -xzf "${FILE}" -C ${ROOT_DIRECTORY} || { echo "Extraction failed"; exit 1; }
# Check if the extraction was successful
if [ ! -f ${ROOT_DIRECTORY}/mev-commit ]; then
echo "Error: Failed to find the mev-commit executable."
exit 1
fi
# Navigate to the target directory
cd ${ROOT_DIRECTORY} || exit 1
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Initializing mev-commit...\033[0m"
./mev-commit --settlement-rpc-endpoint "${RPC_URL}" --peer-type ${NODE_TYPE} --bootnodes /dnsaddr/bootnode.testnet.mev-commit.xyz &
server_pid=$!
# Function to cleanup on exit
cleanup() {
echo "Killing mev-commit node with PID $server_pid"
kill $server_pid
exit 0
}
# Set trap to call cleanup on script exit
trap cleanup EXIT SIGINT SIGTERM
echo -e "\033[31m[\033[34m*\033[31m]\033[33m To kill mev-commit, exit the script. \033[0m"
sleep 5
KEY=$(cat ${ROOT_DIRECTORY}/key)
ADDRESS=$(cast wallet address --private-key "0x${KEY}")
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Created private key and saved.\033[0m"
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Wallet Address: ${ADDRESS} \033[0m"
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Waiting for Wallet Address: ${ADDRESS} to be funded. Please go to ${FAUCET_URL} to fund.\033[0m"
while true; do
balance=$(${HOME}/.foundry/bin/cast balance ${ADDRESS} --rpc-url ${RPC_URL})
balance_in_ether=$(echo "scale=18; $balance / 1000000000000000000" | bc)
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Balance: $balance_in_ether ETH \033[0m"
if (( $(echo "$balance_in_ether > 0" | bc -l) )); then
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Account ${ADDRESS} is now funded. \033[0m"
break
else
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Waiting for account ${ADDRESS} to be funded... Please go to ${FAUCET_URL} to fund. \033[0m"
sleep 5
fi
done
sleep 10
if [ "${NODE_TYPE}" == "bidder" ]; then
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Sending auto deposit request...\033[0m"
CURL_RESPONSE=$(curl --silent --show-error --write-out "%{http_code}" --output /dev/null -X POST "http://localhost:13523/v1/bidder/auto_deposit/1000000000000000000")
if [ "${CURL_RESPONSE}" -ne 200 ]; then
echo "Error: Failed to send auto deposit request. HTTP status code: ${CURL_RESPONSE}"
exit 1
fi
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Auto deposit request sent successfully. \033[0m"
fi
if [ "${NODE_TYPE}" == "provider" ]; then
echo -e "\033[31m[\033[34m*\033[31m]\033[33m Next, to register and stake as a provider, visit https://docs.primev.xyz/get-started/providers/registering-a-provider \033[0m"
fi
wait $server_pid