-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·308 lines (265 loc) · 8.94 KB
/
deploy.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env bash
# Phat Cats - Crypto-Cards
# - https://crypto-cards.io
# - https://phatcats.co
#
# Copyright 2019 (c) Phat Cats, Inc.
# Ganache Local Accounts
# - 1 = Not used
# - 2 = Oracle Bridge
# - 3 = Contract Proxy Admin
# - 4 = Contract Owner
# - 5 = Treasury In-House Account
# - 6 = Test User A
# - 7 = Test User B
# - 8 = Test User C
freshLoad=
initialize=
linkContracts=
runTransactions=
runErc20Migration=
runErc721Migration=
proxyAdmin=
ownerAccount=
inHouseAccount=
networkId=
networkName="local"
verbose=
silent=
usage() {
echo "usage: ./deploy.sh [[-n [local|ropsten|mainnet] [-f] [-v]] | [-h]]"
echo " -n | --network [local|ropsten|mainnet] Deploys contracts to the specified network (default is local)"
echo " -f | --fresh Run all deployments from the beginning, instead of updating"
echo " -i | --initialize Run Contract Initializations"
echo " -l | --link Run Contract Linking"
echo " -t | --transactions Run Test Transactions (Local Only)"
echo " -m20 | --migrate20 Run ERC20 Token Migration"
echo " -m721 | --migrate721 Run ERC721 Token Migration"
echo " -v | --verbose Outputs verbose logging"
echo " -s | --silent Suppresses the Beep at the end of the script"
echo " -h | --help Displays this help screen"
}
echoHeader() {
echo " "
echo "-----------------------------------------------------------"
echo "-----------------------------------------------------------"
}
echoBeep() {
[[ -z "$silent" ]] && {
afplay /System/Library/Sounds/Glass.aiff
}
}
setEnvVars() {
export $(egrep -v '^#' .env | xargs)
if [[ "$networkName" == "ropsten" ]]; then
networkId="3"
networkProvider="ropsten"
proxyAdmin="$ROPSTEN_PROXY_ADMIN"
ownerAccount="$ROPSTEN_OWNER_ACCOUNT"
inHouseAccount="$ROPSTEN_IN_HOUSE_ACCOUNT"
elif [ "$networkName" == "mainnet" ]; then
networkId="1"
networkProvider="mainnet"
proxyAdmin="$MAINNET_PROXY_ADMIN"
ownerAccount="$MAINNET_OWNER_ACCOUNT"
inHouseAccount="$MAINNET_IN_HOUSE_ACCOUNT"
else
networkName="local"
networkId="5777"
networkProvider="dev-5777"
proxyAdmin="$LOCAL_PROXY_ADMIN"
ownerAccount="$LOCAL_OWNER_ACCOUNT"
inHouseAccount="$LOCAL_IN_HOUSE_ACCOUNT"
fi
walletMnemonicType="proxy"
[[ -n "$initialize" || -n "$runTransactions" || -n "$linkContracts" || -n "$runErc20Migration" || -n "$runErc721Migration" ]] && {
walletMnemonicType="owner"
}
# Pass State to Truffle Scripts
export CCC_WALLET_MNEMONIC_TYPE="$walletMnemonicType"
export CCC_NETWORK_NAME="$networkName"
export CCC_NETWORK_PROVIDER="$networkProvider"
export CCC_NETWORK_ID="$networkId"
export CCC_VERBOSE_LOGS="$verbose"
}
startSession() {
echoHeader
fromAccount="Contract Owner"
[[ "$1" == "$proxyAdmin" ]] && {
fromAccount="Proxy Admin"
}
echo "Starting ZOS Session from $fromAccount"
echo " - using proxyAdmin: $proxyAdmin"
echo " - using owner: $ownerAccount"
echo " - using network: $networkName"
zos session --network "$networkName" --from "$1" --expires 3600 --timeout 3600
}
deployFresh() {
startSession "$proxyAdmin"
if [[ "$networkName" == "local" ]]; then
echoHeader
echo "NOTE: Be sure to run the Oraclize Ethereum-bridge first!"
echo "CMD: ethereum-bridge -H localhost:7545 -a 1 --dev"
else
echoHeader
echo "NOTE: Be sure to remove the Oraclize Address Resolver from the Oracle Contract!"
echo "LINE: OAR = OraclizeAddrResolverI( ... )"
fi
echoHeader
echo "Clearing previous build..."
rm -rf build/
rm -r "./zos.$networkProvider.json"
echoHeader
if [[ "$networkName" == "local" ]]; then
echo "Deploying with dependencies..."
zos push --deploy-dependencies
else
echo "Deploying without dependencies..."
zos push
fi
echoHeader
echo "Creating Contract: CryptoCardsOracle"
oracleAddress=$(zos create CryptoCardsOracle --init initialize --args "$ownerAccount")
sleep 1s
echoHeader
echo "Creating Contract: CryptoCardsTreasury"
treasuryAddress=$(zos create CryptoCardsTreasury --init initialize --args "$ownerAccount")
sleep 1s
echoHeader
echo "Creating Contract: CryptoCardsLib"
libAddress=$(zos create CryptoCardsLib --init initialize --args "$ownerAccount")
sleep 1s
echoHeader
echo "Creating Contract: CryptoCardsGum"
gumAddress=$(zos create CryptoCardsGum --init initialize --args "$ownerAccount")
sleep 1s
echoHeader
echo "Creating Contract: CryptoCardsCards"
cardsAddress=$(zos create CryptoCardsCards --init initialize --args "$ownerAccount")
sleep 1s
echoHeader
echo "Creating Contract: CryptoCardsPacks"
packsAddress=$(zos create CryptoCardsPacks --init initialize --args "$ownerAccount")
sleep 1s
echoHeader
echo "Creating Contract: CryptoCardsTokenMigrator"
tokenMigrator=$(zos create CryptoCardsTokenMigrator --init initialize --args "$ownerAccount")
sleep 1s
echoHeader
echo "Creating Contract: CryptoCardsController"
controllerAddress=$(zos create CryptoCardsController --init initialize --args "$ownerAccount")
sleep 1s
echoHeader
echo "Contract Addresses: "
echo " - controllerAddress: ${controllerAddress:(-42)}"
echo " - oracleAddress: ${oracleAddress:(-42)}"
echo " - treasuryAddress: ${treasuryAddress:(-42)}"
echo " - packsAddress: ${packsAddress:(-42)}"
echo " - cardsAddress: ${cardsAddress:(-42)}"
echo " - gumAddress: ${gumAddress:(-42)}"
echo " - tokenMigrator: ${tokenMigrator:(-42)}"
echo " - libAddress: ${libAddress:(-42)}"
echoHeader
echo "Contract Deployment Complete!"
echo " "
echoBeep
}
deployUpdate() {
startSession "$proxyAdmin"
echo " "
echo "Pushing Contract Updates.."
zos push
echo "Updating Logic Contracts.."
zos update CryptoCardsLib
zos update CryptoCardsGum
zos update CryptoCardsCards
zos update CryptoCardsPacks
zos update CryptoCardsTreasury
zos update CryptoCardsOracle
zos update CryptoCardsTokenMigrator
zos update CryptoCardsController
echo " "
echo "Contract Updates Complete!"
echo " "
echoBeep
}
runInitializations() {
startSession "$ownerAccount"
echoHeader
echo "Initializing Contracts..."
truffle exec ./scripts/initializations.js --network "$networkName"
echoBeep
}
runContractLinking() {
startSession "$ownerAccount"
echoHeader
echo "Linking Token Contracts..."
truffle exec ./scripts/link_tokens.js --network "$networkName"
echoBeep
}
runTransactions() {
startSession "$ownerAccount"
echoHeader
echo "Running Test Transactions..."
truffle exec ./scripts/transactions.js --network "$networkName"
echoBeep
}
runErc20Migration() {
startSession "$ownerAccount"
echoHeader
echo "Running ERC20 Token Migration..."
truffle exec ./scripts/migrate_erc20.js --network "$networkName"
echoBeep
}
runErc721Migration() {
startSession "$ownerAccount"
echoHeader
echo "Running ERC721 Token Migration..."
truffle exec ./scripts/migrate_erc721.js --network "$networkName"
echoBeep
}
while [[ "$1" != "" ]]; do
case $1 in
-n | --network ) shift
networkName=$1
;;
-f | --fresh ) freshLoad="yes"
;;
-i | --initialize ) initialize="yes"
;;
-l | --link ) linkContracts="yes"
;;
-t | --transactions ) runTransactions="yes"
;;
-m20 | --migrate20 ) runErc20Migration="yes"
;;
-m721 | --migrate721 ) runErc721Migration="yes"
;;
-v | --verbose ) verbose="yes"
;;
-s | --silent ) silent="yes"
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
setEnvVars
if [[ -n "$freshLoad" ]]; then
deployFresh
elif [[ -n "$linkContracts" ]]; then
runContractLinking
elif [[ -n "$runTransactions" ]]; then
runTransactions
elif [[ -n "$runErc20Migration" ]]; then
runErc20Migration
elif [[ -n "$runErc721Migration" ]]; then
runErc721Migration
elif [[ -n "$initialize" ]]; then
runInitializations
else
deployUpdate
fi