-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcommand.py
executable file
·255 lines (228 loc) · 9.56 KB
/
command.py
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
#!/usr/bin/env python3
import json
import re
from pathlib import Path
from PyInquirer import prompt, Separator
import os
def run_command(command):
os.system(command)
def update_contracts_mumbai():
BASE_PATH = Path('contracts/deployments')
#networks = list(os.listdir(BASE_PATH))
#network = prompt([
# {
# 'type': 'list',
# 'name': 'network',
# 'message': 'Which network?',
# 'choices': networks
# },
#])['network']
network = 'mumbai'
creaton_admin = json.load(open(BASE_PATH / network / 'CreatonAdmin.json'))
creaton_admin['address'] = prompt([
{
'type': 'input',
'name': 'address',
'message': "Hardhat deployment files doesn't include the proxy address. Enter it manually:",
},
])['address']
creator = json.load(open(BASE_PATH / network / 'CreatorV1.json'))
#twitter = json.load(open(BASE_PATH / network / 'TwitterVerification.json'))
paymaster = json.load(open(BASE_PATH / network / 'CreatonPaymaster.json'))
#staking = json.load(open(BASE_PATH / network / 'MetatxStaking.json'))
#token = json.load(open(BASE_PATH / network / 'CreatonToken.json'))
contracts_info = {'network': network, 'CreatonAdmin': creaton_admin, 'Creator': creator,
#'TwitterVerification': twitter,
'Paymaster': paymaster
#'CreatonStaking': staking,
#'CreatonToken': token
}
for name, contract in contracts_info.items():
if name == 'network':
continue
contracts_info[name] = {'abi': contract['abi'], 'address': contract['address']} # remove all extra info
REACT_CONTRACT_PATH = Path('react-app/src/contracts-staging-mumbai.json')
json.dump(contracts_info, open(REACT_CONTRACT_PATH, 'w'), indent=2)
print(f'Updated {REACT_CONTRACT_PATH}')
update_subgraph(creaton_admin, creator, network)
def update_contracts_dev():
BASE_PATH = Path('contracts/deployments')
#networks = list(os.listdir(BASE_PATH))
#network = prompt([
# {
# 'type': 'list',
# 'name': 'network',
# 'message': 'Which network?',
# 'choices': networks
# },
#])['network']
network = 'mumbai'
creaton_admin = json.load(open(BASE_PATH / network / 'CreatonAdmin.json'))
creaton_admin['address'] = prompt([
{
'type': 'input',
'name': 'address',
'message': "Hardhat deployment files doesn't include the proxy address. Enter it manually:",
},
])['address']
creator = json.load(open(BASE_PATH / network / 'CreatorV1.json'))
#twitter = json.load(open(BASE_PATH / network / 'TwitterVerification.json'))
#paymaster = json.load(open(BASE_PATH / network / 'CreatonPaymaster.json'))
#staking = json.load(open(BASE_PATH / network / 'MetatxStaking.json'))
#token = json.load(open(BASE_PATH / network / 'CreatonToken.json'))
contracts_info = {'network': network, 'CreatonAdmin': creaton_admin, 'Creator': creator
#'TwitterVerification': twitter,
#'Paymaster': paymaster
#'CreatonStaking': staking,
#'CreatonToken': token
}
for name, contract in contracts_info.items():
if name == 'network':
continue
contracts_info[name] = {'abi': contract['abi'], 'address': contract['address']} # remove all extra info
REACT_CONTRACT_PATH = Path('react-app/src/contracts-dev-mumbai.json')
json.dump(contracts_info, open(REACT_CONTRACT_PATH, 'w'), indent=2)
print(f'Updated {REACT_CONTRACT_PATH}')
update_subgraph(creaton_admin, creator, network)
def update_contracts():
BASE_PATH = Path('contracts/deployments')
#networks = list(os.listdir(BASE_PATH))
#network = prompt([
# {
# 'type': 'list',
# 'name': 'network',
# 'message': 'Which network?',
# 'choices': networks
# },
#])['network']
network = 'matic'
creaton_admin = json.load(open(BASE_PATH / network / 'CreatonAdmin.json'))
creaton_admin['address'] = prompt([
{
'type': 'input',
'name': 'address',
'message': "Hardhat deployment files doesn't include the proxy address. Enter it manually:",
},
])['address']
creator = json.load(open(BASE_PATH / network / 'CreatorV1.json'))
#twitter = json.load(open(BASE_PATH / network / 'TwitterVerification.json'))
#paymaster = json.load(open(BASE_PATH / network / 'CreatonPaymaster.json'))
#staking = json.load(open(BASE_PATH / network / 'MetatxStaking.json'))
#token = json.load(open(BASE_PATH / network / 'CreatonToken.json'))
contracts_info = {'network': network, 'CreatonAdmin': creaton_admin, 'Creator': creator
#'TwitterVerification': twitter,
#'Paymaster': paymaster
#'CreatonStaking': staking,
#'CreatonToken': token
}
for name, contract in contracts_info.items():
if name == 'network':
continue
contracts_info[name] = {'abi': contract['abi'], 'address': contract['address']} # remove all extra info
REACT_CONTRACT_PATH = Path('react-app/src/contracts.json')
json.dump(contracts_info, open(REACT_CONTRACT_PATH, 'w'), indent=2)
print(f'Updated {REACT_CONTRACT_PATH}')
update_subgraph(creaton_admin, creator, network)
def yesno(question):
return prompt([
{
'type': 'list',
'name': 'yesno',
'message': question,
'choices': [
'Yes please',
'No thanks',
]
},
])['yesno'] == 'Yes please'
def update_subgraph(creaton_admin, creator, network):
SUBGRAPH_ABI_PATH = Path('subgraph/abis')
json.dump(creator['abi'], open(SUBGRAPH_ABI_PATH / 'Creator.json', 'w'), indent=2)
print(f"Updated {SUBGRAPH_ABI_PATH / 'Creator.json'}")
json.dump(creaton_admin['abi'], open(SUBGRAPH_ABI_PATH / 'CreatonAdmin.json', 'w'), indent=2)
print(f"Updated {SUBGRAPH_ABI_PATH / 'CreatonAdmin.json'}")
converted_lines = []
yaml_path = 'subgraph/subgraph.yaml'
for line in open(yaml_path).readlines():
if 'network:' in line:
if network not in line:
print(f'Subgraph yaml config is for {line.strip()} but this configuration is for network {network}'
f'Refusing to update the subgraph')
return
if '#CreatonAdminAddress' in line:
# Replacing the address
line = re.sub(r'0x[^"]+', creaton_admin['address'], line)
converted_lines.append(line)
with open(yaml_path, 'w') as f:
f.write(''.join(converted_lines))
print(f'Updated {yaml_path}')
if yesno('Deploy on Matic?'):
run_command('cd subgraph && npm run deploy')
def deploy_contracts_mumbai():
run_command('npm run mumbai:contracts')
if yesno('Update the contract addresses in staging subgraph and staging react?'):
return update_contracts_mumbai()
if yesno('Update the contract addresses in dev subgraph and dev react?'):
return update_contracts_dev()
def upgrade_creator_mumbai():
run_command('npm run mumbai:upgradecreator')
if yesno('Update the contract addresses in subgraph and react?'):
return update_contracts_mumbai()
if yesno('Update the contract addresses in dev subgraph and dev react?'):
return update_contracts_dev()
def deploy_contracts():
run_command('npm run matic:contracts')
if yesno('Update the contract addresses in subgraph and react?'):
return update_contracts()
def main():
question = [
{
'type': 'list',
'name': 'subproject',
'message': 'What do you want to do?',
'choices': [
'contracts',
'subgraph',
'react-app',
Separator(),
'deploy contracts',
'deploy contracts mumbai testnet',
'update contracts',
'update contracts staging mumbai testnet',
'update contracts dev mumbai testnet',
'run subgraph docker',
'upgrade Creator Beacon'
]
},
]
subproject = prompt(question)['subproject']
if subproject == 'deploy contracts mumbai testnet':
return deploy_contracts_mumbai()
if subproject == 'deploy contracts':
return deploy_contracts()
if subproject == 'update contracts':
return update_contracts()
if subproject == 'update contracts staging mumbai testnet':
return update_contracts_mumbai()
if subproject == 'update contracts dev mumbai testnet':
return update_contracts_dev()
if subproject == 'upgrade Creator Beacon':
return upgrade_creator_mumbai()
if subproject == 'run subgraph docker':
run_command('cd subgraph && docker-compose up')
return
json_config = json.load(open(Path(subproject) / 'package.json'))
scripts = json_config['scripts']
choices = [{'name': f'{command} -> {description}', 'value': command} for command, description in scripts.items()]
command_question = [
{
'type': 'list',
'name': 'command',
'message': f'Which npm run command in {subproject}?',
'choices': choices
},
]
command = prompt(command_question)['command']
run_command(f'cd {subproject} && npm run {command}')
if __name__ == '__main__':
main()