-
Notifications
You must be signed in to change notification settings - Fork 10
/
deploy
executable file
·215 lines (179 loc) · 10 KB
/
deploy
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
#!/bin/bash
#set -e
#set -o pipefail
<< LICENSE
The MIT License (MIT)
Copyright 2018 - 2019, Autonomous Software.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
LICENSE
usage()
{
cat <<- _EOM_
deploy: compile and push metronome to a local parity instance by default,
overriding auction launch date, price and supply, if specified.
By default, deploy deploys to a local clean ETH "dev chain" instance of parity.
If -i or --interactive is offerred in local deployment then it will do deploy and launch in one step.
If --test is offered, deploy will connect to test network and deploy there. Note you will need NA testnet ETH. Contact your SA for help.
For live and testnet, launch has to be done in second step after deploy and initialization done
If --live is offered, deploy will connect to the default parity instance.
If --chain etc is offered, deploy will deploy to ETC. Note that deploy will
consider ETC to be the "Non OG" chain, and initialize a destination metronome.
usage: deploy [--supply supply of Metronome] [-P | --pass <password> ]
[-p | --price <price at start of MET Auction] [--live | --test]
[-O | --owner <owner eth address> ] [--auction auction_epoch_seconds] [-t | --timescale Time Mult]
[-i | --interactive] [--seed ] [--chain eth|etc ] | [-h]
[-v | --validators <list of three validators address>]
[-p <parity host>]
_EOM_
}
source ./basescript
if [[ $LOCAL = 0 ]] && [[ $VALIDATORS = "[]" ]];
then
echo " Live and Test net deploy requires validators address. Use -v or --validators."
exit 1
fi
echo "About to Deploy Metronome to $DEST.."
if [[ $LOCAL = 1 ]] && [[ $TIMESCALE = 1 ]]
then
echo "Running on local chain but realtime.. Can I suggest -t 1000?"
fi
read -p "Press enter to continue"
echo "Cleaning up old deploy stuff..."
rm $CHAIN_DIR/metronome.js 2>/dev/null
if [[ $LOCAL = 1 ]] && [[ $DEVNET = 0 ]]
then
rm -rf $DATADIR
mkdir -p $DATADIR
fi
NODES_CACHE=/tmp/natestnet/chains/GethTranslation/network/nodes.json
if [ $TEST = 1 ] && [ -f $NODES_CACHE ]
then
rm $NODES_CACHE
fi
echo 'devnet'
echo $DEVNET
#set account for devnet
if [[ $DEVNET = 1 ]]; then
#create deployer account with default passphrase
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"parity_newAccountFromPhrase","params":["user", ""],"id":0}' $PARITY_URL >/dev/null
LOCAL_ETH=0x004ec07d2329997267ec62b4166639513386f32e
fi
echo "Authorizing deployer account ..."
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["'$LOCAL_ETH'", "'$PASS'","0x3000"],"id":1}' $PARITY_URL >/dev/null
if [[ $LOCAL = 1 ]] && [[ $OWNER_ADDRESS = 0x0 ]]
then
sleep 5
echo "Creating new account for the owner"
PASS=''
response=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["'$PASS'"],"id":1}' $PARITY_URL)
OWNER_ADDRESS=`echo "$response" | jq .result`
OWNER_ADDRESS=${OWNER_ADDRESS//\"/}
echo "Metronome owner for dev chain $OWNER_ADDRESS"
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"'$LOCAL_ETH'", "to":"'$OWNER_ADDRESS'", "value":"0x1BC16D674EC80000"}],"id":1}' $PARITY_URL >/dev/null
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["'$OWNER_ADDRESS'", "'$PASS'","0x3000"],"id":1}' $PARITY_URL >/dev/null
fi
sleep 5
echo "Deploying on $DEST.."
TMP_DIR=$CHAIN_DIR/tmp
mkdir $TMP_DIR
echo "" > $CHAIN_DIR/metronome.js
echo "Compiling and deploying Proceeds contract"
echo -e "contracts/monolithic.sol:Proceeds\n$TMP_DIR/Proceeds.js" | SETH_URL=$PARITY_URL ETHER_ADDR=$LOCAL_ETH $SOLDEPLOY contracts/monolithic.sol >/dev/null > $TMP_DIR/Proceeds.txt
echo "Compiling and deploying Auctions contract"
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["'$LOCAL_ETH'", "'$PASS'","0x3000"],"id":1}' $PARITY_URL >/dev/null
echo -e "contracts/monolithic.sol:Auctions\n$TMP_DIR/Auctions.js" | SETH_URL=$PARITY_URL ETHER_ADDR=$LOCAL_ETH $SOLDEPLOY contracts/monolithic.sol >/dev/null > $TMP_DIR/Auctions.txt
echo "Compiling and deploying AutonomousConverter contract"
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["'$LOCAL_ETH'", "'$PASS'","0x3000"],"id":1}' $PARITY_URL >/dev/null
echo -e "contracts/monolithic.sol:AutonomousConverter\n$TMP_DIR/AutonomousConverter.js" | SETH_URL=$PARITY_URL ETHER_ADDR=$LOCAL_ETH $SOLDEPLOY contracts/monolithic.sol >/dev/null > $TMP_DIR/AutonomousConverter.txt
echo "Compiling and deploying SmartToken contract"
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["'$LOCAL_ETH'", "'$PASS'","0x3000"],"id":1}' $PARITY_URL >/dev/null
echo -e "contracts/monolithic.sol:SmartToken\n$TMP_DIR/SmartToken.js" | SETH_URL=$PARITY_URL ETHER_ADDR=$LOCAL_ETH $SOLDEPLOY contracts/monolithic.sol >/dev/null > $TMP_DIR/SmartToken.txt
echo "Compiling and deploying METToken contract"
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["'$LOCAL_ETH'", "'$PASS'","0x3000"],"id":1}' $PARITY_URL >/dev/null
echo -e "contracts/monolithic.sol:METToken\n$TMP_DIR/METToken.js" | SETH_URL=$PARITY_URL ETHER_ADDR=$LOCAL_ETH $SOLDEPLOY contracts/monolithic.sol >/dev/null > $TMP_DIR/METToken.txt
echo "Compiling and deploying TokenPorter contract"
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_unlockAccount","params":["'$LOCAL_ETH'", "'$PASS'","0x3000"],"id":1}' $PARITY_URL >/dev/null
echo -e "contracts/monolithic.sol:TokenPorter\n$TMP_DIR/TokenPorter.js" | SETH_URL=$PARITY_URL ETHER_ADDR=$LOCAL_ETH $SOLDEPLOY contracts/monolithic.sol >/dev/null > $TMP_DIR/TokenPorter.txt
echo "Compiling and deploying Validator contract"
echo -e "contracts/monolithic.sol:Validator\n$TMP_DIR/Validator.js" | SETH_URL=$PARITY_URL ETHER_ADDR=$LOCAL_ETH $SOLDEPLOY contracts/monolithic.sol >/dev/null > $TMP_DIR/Validator.txt
echo "Copying ABI and Addresses"
cat $TMP_DIR/Proceeds.js $TMP_DIR/Auctions.js $TMP_DIR/AutonomousConverter.js $TMP_DIR/SmartToken.js $TMP_DIR/METToken.js $TMP_DIR/TokenPorter.js $TMP_DIR/Validator.js > $CHAIN_DIR/metronome.js
#rm -r $TMP_DIR
#Reading founder list
foundersArray="[]"
if [[ "$CHAIN" = "eth" ]]
then
input="./foundersList.csv"
foundersArray=""
while IFS=',' read -r f1 f2
do
#echo "$f1 $f2"
f2=${f2//[$'\r']}
foundersArray="$foundersArray'$f1$f2', "
done < <(tail -n "+2" $input)
foundersArray="[$foundersArray]"
foundersArray=${foundersArray/, ]/]}
fi
foundersArray="var FOUNDERS = $foundersArray"
#echo $foundersArray
if [[ $LOCAL = 1 ]] && [[ $VALIDATORS = "[]" ]]; then
echo "Creating new account for the owner"
response=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["'$CHAIN'"],"id":1}' $PARITY_URL)
validator1=`echo "$response" | jq .result`
validator1=${validator1//\"/}
echo "Metronome validator for dev chain $validator1"
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"'$LOCAL_ETH'", "to":"'$validator1'", "value":"0x1BC16D674EC80000"}],"id":1}' $PARITY_URL >/dev/null
response=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["'$CHAIN'"],"id":1}' $PARITY_URL)
validator2=`echo "$response" | jq .result`
validator2=${validator2//\"/}
echo "Metronome validator for dev chain $validator2"
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"'$LOCAL_ETH'", "to":"'$validator2'", "value":"0x1BC16D674EC80000"}],"id":1}' $PARITY_URL >/dev/null
VALIDATORS="['$OWNER_ADDRESS', '$validator1', '$validator2']"
echo "VALIDATORS $VALIDATORS"
fi
cat <<EOF > $CHAIN_DIR/const.js
// File generated by deploy -- edits will get overwritten!
var PRICE = $PRICE
var ONE = 1
var NUMTOKENS = $SUPPLY
var START = $AUCTION
var TIMESCALE = 1
var MINPRICE = 3300000000000
var ETHER_ADDR = '$LOCAL_ETH'
var OWNER_ADDRESS = '$OWNER_ADDRESS'
var OWNER_PASS = '$PASS'
var VALIDATORS = $VALIDATORS
var ISA_ENDTIME = '$ISA_ENDTIME'
$foundersArray
EOF
PRELOAD="--preload $CHAIN_DIR/metronome.js,$CHAIN_DIR/const.js,js/common.js,$CHAIN_DIR/initMetronome.js"
# Local with interactive will deploy, init and launch Metronome.
if [[ $LOCAL = 1 ]] && [[ $INTERACTIVE = 1 ]]
then
geth attach $PARITY_URL $PRELOAD,$CHAIN_DIR/launchMetronome.js$SEED
exit 0
fi
# For live and test environment, we want to force two step process 1) Deploy and init 2) launch
if [[ $INTERACTIVE = 1 ]]
then
geth attach $PARITY_URL $PRELOAD
else
geth --exec 'eth.blockNumber' attach $PARITY_URL $PRELOAD
fi
echo 'To launch metronome, execute launch script using command ./launch --chain '$CHAIN' --owner <address of new owner of contracts> --pass <password of owners address>'
exit 0