forked from kkrt-labs/kakarot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_kakarot.py
160 lines (143 loc) · 5.5 KB
/
deploy_kakarot.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
# %% Imports
import logging
from asyncio import run
from kakarot_scripts.constants import (
ARACHNID_PROXY_DEPLOYER,
ARACHNID_PROXY_SIGNED_TX,
BLOCK_GAS_LIMIT,
COINBASE,
CREATEX_DEPLOYER,
CREATEX_SIGNED_TX,
DECLARED_CONTRACTS,
DEFAULT_GAS_PRICE,
ETH_TOKEN_ADDRESS,
EVM_ADDRESS,
MULTICALL3_DEPLOYER,
MULTICALL3_SIGNED_TX,
NETWORK,
RPC_CLIENT,
NetworkType,
)
from kakarot_scripts.utils.kakarot import deploy as deploy_evm
from kakarot_scripts.utils.kakarot import deploy_with_presigned_tx
from kakarot_scripts.utils.kakarot import dump_deployments as dump_evm_deployments
from kakarot_scripts.utils.kakarot import get_deployments as get_evm_deployments
from kakarot_scripts.utils.starknet import declare
from kakarot_scripts.utils.starknet import deploy as deploy_starknet
from kakarot_scripts.utils.starknet import (
dump_declarations,
dump_deployments,
get_declarations,
)
from kakarot_scripts.utils.starknet import get_deployments as get_starknet_deployments
from kakarot_scripts.utils.starknet import get_starknet_account, invoke, upgrade
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# %% Main
async def main():
# %% Declarations
account = await get_starknet_account()
logger.info(f"ℹ️ Using account {hex(account.address)} as deployer")
class_hash = {
contract["contract_name"]: await declare(contract)
for contract in DECLARED_CONTRACTS
}
dump_declarations(class_hash)
# %% Deployments
class_hash = get_declarations()
starknet_deployments = get_starknet_deployments()
evm_deployments = get_evm_deployments()
freshly_deployed = False
if starknet_deployments.get("kakarot") and NETWORK["type"] is not NetworkType.DEV:
logger.info("ℹ️ Kakarot already deployed, checking version.")
deployed_class_hash = await RPC_CLIENT.get_class_hash_at(
starknet_deployments["kakarot"]["address"]
)
if deployed_class_hash != class_hash["kakarot"]:
await invoke("kakarot", "upgrade", class_hash["kakarot"])
await invoke(
"kakarot",
"set_account_contract_class_hash",
class_hash["account_contract"],
)
await invoke(
"kakarot",
"set_cairo1_helpers_class_hash",
class_hash["Cairo1Helpers"],
)
else:
logger.info("✅ Kakarot already up to date.")
else:
starknet_deployments["kakarot"] = await deploy_starknet(
"kakarot",
account.address, # owner
ETH_TOKEN_ADDRESS, # native_token_address_
class_hash["account_contract"], # account_contract_class_hash_
class_hash["uninitialized_account"], # uninitialized_account_class_hash_
class_hash["Cairo1Helpers"],
COINBASE,
BLOCK_GAS_LIMIT,
)
freshly_deployed = True
if NETWORK["type"] is NetworkType.STAGING:
starknet_deployments["EVM"] = await upgrade(
"EVM",
account.address, # owner
ETH_TOKEN_ADDRESS, # native_token_address_
class_hash["account_contract"], # account_contract_class_hash_
class_hash["uninitialized_account"], # uninitialized_account_class_hash_
class_hash["Cairo1Helpers"],
COINBASE,
BLOCK_GAS_LIMIT,
)
starknet_deployments["Counter"] = await upgrade("Counter")
starknet_deployments["MockPragmaOracle"] = await upgrade("MockPragmaOracle")
if NETWORK["type"] is NetworkType.DEV:
starknet_deployments["EVM"] = await deploy_starknet(
"EVM",
account.address, # owner
ETH_TOKEN_ADDRESS, # native_token_address_
class_hash["account_contract"], # account_contract_class_hash_
class_hash["uninitialized_account"], # uninitialized_account_class_hash_
class_hash["Cairo1Helpers"],
COINBASE,
BLOCK_GAS_LIMIT,
)
starknet_deployments["Counter"] = await deploy_starknet("Counter")
starknet_deployments["MockPragmaOracle"] = await deploy_starknet(
"MockPragmaOracle"
)
dump_deployments(starknet_deployments)
if EVM_ADDRESS:
logger.info(f"ℹ️ Found default EVM address {EVM_ADDRESS}")
from kakarot_scripts.utils.kakarot import get_eoa
amount = (
0.02
if NETWORK["type"] is not (NetworkType.DEV or NetworkType.STAGING)
else 100
)
await get_eoa(amount=amount)
# Set the base fee if freshly deployed
if freshly_deployed:
await invoke("kakarot", "set_base_fee", DEFAULT_GAS_PRICE)
# Deploy the solidity contracts
weth = await deploy_evm("WETH", "WETH9")
evm_deployments["WETH"] = {
"address": int(weth.address, 16),
"starknet_address": weth.starknet_address,
}
# Pre-EIP155 deployments
evm_deployments["Multicall3"] = await deploy_with_presigned_tx(
MULTICALL3_DEPLOYER, MULTICALL3_SIGNED_TX, name="Multicall3"
)
evm_deployments["Arachnid_Proxy"] = await deploy_with_presigned_tx(
ARACHNID_PROXY_DEPLOYER, ARACHNID_PROXY_SIGNED_TX, name="Arachnid Proxy"
)
evm_deployments["CreateX"] = await deploy_with_presigned_tx(
CREATEX_DEPLOYER, CREATEX_SIGNED_TX, amount=0.3, name="CreateX"
)
dump_evm_deployments(evm_deployments)
# %% Run
if __name__ == "__main__":
run(main())