-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper.sh
242 lines (199 loc) · 8.72 KB
/
helper.sh
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/env bash
set -e
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
export DOCKER_NETWORK_ENDPOINT=http://ganache:8545
export SM_IMAGE_NAME="skale-manager"
export ALLOCATOR_IMAGE_NAME="skale-allocator"
export IMA_IMAGE_NAME="ima-contracts"
export SGX_WALLET_CONTAINER_NAME="sgx-simulator"
export DOCKER_NETWORK=${DOCKER_NETWORK:-testnet}
export GANACHE_VERSION=${GANACHE_VERSION:-beta}
export GANACHE_GAS_LIMIT=${GANACHE_GAS_LIMIT:-80000000}
run_manager () {
: "${1?Pass MANAGER_TAG to ${FUNCNAME[0]}}"
echo Going to run $SM_IMAGE_NAME:$1 docker container...
mkdir -p $DIR/contracts_data/openzeppelin
docker rm -f $SM_IMAGE_NAME || true
docker pull skalenetwork/$SM_IMAGE_NAME:$1
docker run \
-ti \
--name $SM_IMAGE_NAME \
-v $DIR/contracts_data:/usr/src/manager/data \
--mount type=volume,dst=/usr/src/manager/.openzeppelin,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=$DIR/contracts_data/openzeppelin \
--network $DOCKER_NETWORK \
skalenetwork/$SM_IMAGE_NAME:$1 \
bash
}
# Deploy SKALE Manager to the specified RPC endpoint
#
# Results will saved in {CURRENT_DIR}/contracts_data/{NETWORK_NAME}.json
#
#:param MANAGER_TAG: Tag of the SKALE Manager Docker container
#:type MANAGER_TAG: str
#:param ENDPOINT: Ethereum RPC endpoint
#:type ENDPOINT: str
#:param ETH_PRIVATE_KEY: Ethereum private key (WITHOUT 0x prefix)
#:type ETH_PRIVATE_KEY: str
#:param NETWORK: Network from the truffle-config.json file - not used
#:type NETWORK: str
deploy_manager () {
: "${1?Pass MANAGER_TAG to ${FUNCNAME[0]}}"
: "${2?Pass ENDPOINT to ${FUNCNAME[0]}}"
: "${3?Pass ETH_PRIVATE_KEY to ${FUNCNAME[0]}}"
: "${4?Pass GAS_PRICE to ${FUNCNAME[0]}}"
: "${5?Pass NETWORK to ${FUNCNAME[0]}}"
: "${6?Pass ETHERSCAN to ${FUNCNAME[0]}}"
echo Going to run $SM_IMAGE_NAME:$1 docker container...
mkdir -p $DIR/contracts_data/openzeppelin
rm $DIR/contracts_data/skale-manager-* || true
deploy="npx hardhat run migrations/deploy.ts --network custom"
post_deploy="cp .openzeppelin/* openzeppelin-artifacts/"
cmd="${deploy} && ${post_deploy}"
anvil_response=$(curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"anvil_nodeInfo" ,"id":1}' ${ENDPOINT})
echo $anvil_response
if [[ $anvil_response != *"error"* ]]; then
anvil_fix="sed -i 's/devInstanceMetadata.forkedNetwork !== undefined/false/g' node_modules/@openzeppelin/upgrades-core/dist/manifest.js"
cmd="${anvil_fix} && ${cmd}"
fi
echo CMD $cmd
docker rm -f $SM_IMAGE_NAME || true
docker pull skalenetwork/$SM_IMAGE_NAME:$1
docker run \
--name $SM_IMAGE_NAME \
-v $DIR/contracts_data:/usr/src/manager/data \
--mount type=volume,dst=/usr/src/manager/openzeppelin-artifacts,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=$DIR/contracts_data/openzeppelin \
--network $DOCKER_NETWORK \
-e ENDPOINT=$2 \
-e PRIVATE_KEY=$3 \
-e GASPRICE=$4 \
-e ETHERSCAN=$6 \
skalenetwork/$SM_IMAGE_NAME:$1 \
/bin/bash -c "$cmd"
echo Copying $DIR/contracts_data/skale-manager-* to $DIR/contracts_data/manager.json
cp $DIR/contracts_data/skale-manager-* $DIR/contracts_data/manager.json
docker rm -f $SM_IMAGE_NAME || true
}
# Deploy SKALE Allocator to the specified RPC endpoint
#
# Results will saved in {CURRENT_DIR}/allocator_contracts_data/{NETWORK_NAME}.json
#
#:param ALLOCATOR_TAG: Tag of the SKALE Allocator Docker container
#:type ALLOCATOR_TAG: str
#:param ENDPOINT: Ethereum RPC endpoint
#:type ENDPOINT: str
#:param ETH_PRIVATE_KEY: Ethereum private key (WITHOUT 0x prefix)
#:type ETH_PRIVATE_KEY: str
#:param ALLOCATOR_PRODUCTION: Production or develop contracts
#:type ALLOCATOR_PRODUCTION: bool
deploy_allocator () {
: "${1?Pass ALLOCATOR_TAG to ${FUNCNAME[0]}}"
: "${2?Pass ENDPOINT to ${FUNCNAME[0]}}"
: "${3?Pass ETH_PRIVATE_KEY to ${FUNCNAME[0]}}"
: "${4?Pass ALLOCATOR_PRODUCTION to ${FUNCNAME[0]}}"
: "${5?Pass GAS_PRICE to ${FUNCNAME[0]}}"
SM_ABI_FILEPATH=$DIR/contracts_data/manager.json
if [ ! -f $SM_ABI_FILEPATH ]; then
echo "$SM_ABI_FILEPATH file not found!"
exit 3
fi
echo Going to run $ALLOCATOR_IMAGE_NAME:$1 docker container...
docker rm -f $ALLOCATOR_IMAGE_NAME || true
mkdir -p $DIR/allocator_contracts_data/openzeppelin
docker pull skalenetwork/$ALLOCATOR_IMAGE_NAME:$1
DEPLOY_TIMEOUT=1200
docker run \
-d \
--name $ALLOCATOR_IMAGE_NAME \
-v $DIR/contracts_data:/usr/src/manager_data \
-v $DIR/allocator_contracts_data:/usr/src/allocator/data \
--mount type=volume,dst=/usr/src/allocator/.openzeppelin,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=$DIR/allocator_contracts_data/openzeppelin \
--network $DOCKER_NETWORK \
-e ENDPOINT=$2 \
-e PRIVATE_KEY=$3 \
-e PRODUCTION=$4 \
-e GASPRICE=$5 \
skalenetwork/$ALLOCATOR_IMAGE_NAME:$1 \
sleep $DEPLOY_TIMEOUT
DEPLOY_CMD="npx hardhat run migrations/deploy.ts --network custom || true"
docker exec $ALLOCATOR_IMAGE_NAME bash -c "cp /usr/src/manager_data/manager.json /usr/src/allocator/scripts/manager.json"
docker exec $ALLOCATOR_IMAGE_NAME bash -c "$DEPLOY_CMD"
echo Copying $DIR/allocator_contracts_data/skale-allocator-* to $DIR/allocator_contracts_data/allocator.json
cp $DIR/allocator_contracts_data/skale-allocator-* $DIR/allocator_contracts_data/allocator.json
docker rm -f $ALLOCATOR_IMAGE_NAME || true
}
# Deploy SKALE Manager to the specified RPC endpoint
#
# Results will saved in {CURRENT_DIR}/contracts_data/{NETWORK_NAME}.json
#
#:param MANAGER_TAG: Tag of the SKALE Manager Docker container
#:type MANAGER_TAG: str
#:param ENDPOINT: Ethereum RPC endpoint
#:type ENDPOINT: str
#:param ETH_PRIVATE_KEY: Ethereum private key (WITHOUT 0x prefix)
#:type ETH_PRIVATE_KEY: str
deploy_ima_proxy () {
: "${1?Pass IMA_TAG to ${FUNCNAME[0]}}"
: "${2?Pass ENDPOINT to ${FUNCNAME[0]}}"
: "${3?Pass ETH_PRIVATE_KEY to ${FUNCNAME[0]}}"
: "${4?Pass GAS_PRICE to ${FUNCNAME[0]}}"
: "${5?Pass SKALE_MANAGER_ADDRESS to ${FUNCNAME[0]}}"
echo Going to run $IMA_IMAGE_NAME:$1 docker container...
mkdir -p $DIR/contracts_data/ima-openzeppelin
docker rm -f $IMA_IMAGE_NAME || true
docker pull skalenetwork/$IMA_IMAGE_NAME:$1
deploy="pwd && ls -altr && yarn deploy-to-mainnet"
post_deploy="cp .openzeppelin/* openzeppelin-artifacts/"
cmd="${deploy} && ${post_deploy}"
echo CMD $cmd
docker run \
--name $IMA_IMAGE_NAME \
-v $DIR/contracts_data:/app/data \
--mount type=volume,dst=/app/openzeppelin-artifacts,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=$DIR/contracts_data/ima-openzeppelin \
--network $DOCKER_NETWORK \
-e URL_W3_ETHEREUM=$2 \
-e PRIVATE_KEY_FOR_ETHEREUM=$3 \
-e GASPRICE=$4 \
-e SKALE_MANAGER_ADDRESS=$5 \
-e NETWORK_FOR_ETHEREUM="mainnet" \
skalenetwork/$IMA_IMAGE_NAME:$1 \
bash -c "$cmd"
echo "Copying $DIR/contracts_data/proxyMainnet.json -> $DIR/contracts_data/ima.json"
cp $DIR/contracts_data/proxyMainnet.json $DIR/contracts_data/ima.json
docker rm -f $IMA_IMAGE_NAME || true
}
# Run ganache container with given private key
#
# Previous ganache container will be removed
#
#:param ETH_PRIVATE_KEY: Ethereum private key (WITHOUT 0x prefix)
#:type ETH_PRIVATE_KEY: str
run_ganache () {
: "${1?Pass ETH_PRIVATE_KEY to ${FUNCNAME[0]}}"
echo Going to run ganache docker container...
docker rm -f ganache || true
docker run -d --network $DOCKER_NETWORK -p 8545:8545 -p 8546:8546 \
--name ganache trufflesuite/ganache:$GANACHE_VERSION \
--account="0x${1},100000000000000000000000000" -l 80000000 -b 0.01
}
# Run docker container with sgx simulator
#
# Previous sgx-simulator container will be removed
#
#:param SGX_WALLET_TAG: Tag of the SGX simulator Docker container
#:type SGX_WALLET_TAG: str
run_sgx_simulator () {
: "${1?Pass SGX_WALLET_TAG to ${FUNCNAME[0]}}"
SGX_WALLET_IMAGE_NAME=skalenetwork/sgxwallet_sim:$1
docker rm -f $SGX_WALLET_CONTAINER_NAME || true
docker pull $SGX_WALLET_IMAGE_NAME
docker run -d -p 1026-1031:1026-1031 --name $SGX_WALLET_CONTAINER_NAME $SGX_WALLET_IMAGE_NAME -s -y -a
}
create_test_docker_network () {
docker network create $DOCKER_NETWORK || true
}
create_universal_abi_file () {
: "${1?Pass MANAGER_FILEPATH to ${FUNCNAME[0]}}"
: "${2?Pass ALLOCATOR_FILEPATH to ${FUNCNAME[0]}}"
: "${3?Pass RESULT_FILEPATH to ${FUNCNAME[0]}}"
python $DIR/create_universal_abi_file.py $1 $2 $3
}