forked from vechain-labs/uni-v2-deploy-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_univ2.py
77 lines (65 loc) · 2.54 KB
/
deploy_univ2.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
# This script deploys only Uni V2
# Inputs: network url, json files, deployer wallet, VVET contract address
# Factory deploy: about 3690 VTHO
# Router deploy: about 5740 VHTO
import sys
from thor_requests.connect import Connect
from thor_requests.wallet import Wallet
from thor_requests.contract import Contract
from thor_requests import utils
# Read in Params
SCRIPT_NAME = sys.argv[0]
NETWORK = sys.argv[1] # eg. 'https://solo.veblocks.net'
PRIVATE_KEY = sys.argv[2]
FACTORY_FILE = sys.argv[3]
ROUTER_FILE = sys.argv[4]
VVET_CONTRACT_ADDRESS = sys.argv[5]
# Prepare wallet and network
w = Wallet.fromPrivateKey(bytes.fromhex(PRIVATE_KEY))
c = Connect(NETWORK)
factory_contract = Contract.fromFile(FACTORY_FILE)
router_contract = Contract.fromFile(ROUTER_FILE)
vvet_contract_address = VVET_CONTRACT_ADDRESS
if not vvet_contract_address:
raise Exception("Set vVET contract address first!")
# Detect if VVET contract is ready
a = c.get_account(vvet_contract_address)
if not utils.is_contract(a):
raise Exception(f"{vvet_contract_address} is not a smart contract")
# Detect wallet balance
account = c.get_account(w.getAddress())
print('Wallet balance:')
print('VET:', int(account['balance'], 16) / (10 ** 18))
print('VTHO:', int(account['energy'], 16) / (10 ** 18))
print('Is human:', not utils.is_contract(account))
# Deploy Factory
fee_to_setter = w.getAddress() # fee to setter is me.
response = c.deploy(w, factory_contract, ['address', 'address'], [fee_to_setter, vvet_contract_address])
tx_id = response['id']
print('deploy_factory_tx:', tx_id)
# Wait for Receipt
receipt = c.wait_for_tx_receipt(tx_id, 30)
if not receipt:
raise Exception(f"receipt not found! by tx id: {tx_id}")
# Print deployed address
if utils.is_reverted(receipt):
print(c.replay_tx(tx_id))
raise Exception(f"{tx_id} is reverted!")
deployed_factory_addresses = utils.read_created_contracts(receipt)
factory_address = deployed_factory_addresses[0]
print('factory_address:', factory_address)
# Deploy Router
response = c.deploy(w, router_contract, ['address','address'], [factory_address, vvet_contract_address])
tx_id = response['id']
print('deploy_router_tx:', tx_id)
# Wait for Receipt
receipt = c.wait_for_tx_receipt(tx_id, 30)
if not receipt:
raise Exception(f"receipt not found! by tx id: {tx_id}")
# Print deployed address
if utils.is_reverted(receipt):
print(c.replay_tx(tx_id))
raise Exception(f"{tx_id} is reverted!")
deployed_router_addresses = utils.read_created_contracts(receipt)
router_address = deployed_router_addresses[0]
print('router_address:', router_address)