forked from kkrt-labs/kakarot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_kakarot.py
207 lines (183 loc) · 6.49 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
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
# %% Imports
import logging
from uvloop 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_and_fund_evm_address,
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 call, declare
from kakarot_scripts.utils.starknet import deploy as deploy_starknet
from kakarot_scripts.utils.starknet import (
dump_declarations,
dump_deployments,
execute_calls,
get_balance,
get_declarations,
)
from kakarot_scripts.utils.starknet import get_deployments as get_starknet_deployments
from kakarot_scripts.utils.starknet import (
get_starknet_account,
invoke,
register_lazy_account,
remove_lazy_account,
)
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# %% Main
async def main():
# %% Declarations
account = await get_starknet_account()
register_lazy_account(account.address)
logger.info(f"ℹ️ Using account 0x{account.address:064x} as deployer")
balance_pref = await get_balance(account.address)
class_hash = {contract: await declare(contract) for contract in DECLARED_CONTRACTS}
dump_declarations(class_hash)
# %% Starknet Deployments
class_hash = get_declarations()
starknet_deployments = get_starknet_deployments()
if NETWORK["type"] is not NetworkType.PROD:
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"],
BLOCK_GAS_LIMIT,
)
await invoke(
"EVM",
"set_coinbase",
COINBASE,
address=starknet_deployments["EVM"],
)
starknet_deployments["Counter"] = await deploy_starknet("Counter")
starknet_deployments["MockPragmaOracle"] = await deploy_starknet(
"MockPragmaOracle"
)
starknet_deployments["UniversalLibraryCaller"] = await deploy_starknet(
"UniversalLibraryCaller"
)
starknet_deployments["BenchmarkCairoCalls"] = await deploy_starknet(
"BenchmarkCairoCalls"
)
# Deploy or upgrade Kakarot
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"]
)
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"],
BLOCK_GAS_LIMIT,
)
await invoke(
"kakarot",
"set_base_fee",
DEFAULT_GAS_PRICE,
address=starknet_deployments["kakarot"],
)
dump_deployments(starknet_deployments)
# Execute calls in lazy mode
# After this point, Kakarot needs to be deployed for the remaining calls to be executed
await execute_calls()
remove_lazy_account(account.address)
# %% EVM Deployments
evm_deployments = get_evm_deployments()
# %% Pre-EIP155 deployments, done only once
await deploy_with_presigned_tx(
MULTICALL3_DEPLOYER,
MULTICALL3_SIGNED_TX,
name="Multicall3",
max_fee=int(0.1e18),
)
await deploy_with_presigned_tx(
ARACHNID_PROXY_DEPLOYER,
ARACHNID_PROXY_SIGNED_TX,
name="Arachnid Proxy",
max_fee=int(0.1e18),
)
await deploy_with_presigned_tx(
CREATEX_DEPLOYER,
CREATEX_SIGNED_TX,
amount=0.3,
name="CreateX",
max_fee=int(0.2e18),
)
if not EVM_ADDRESS:
logger.info("ℹ️ No EVM address provided, skipping EVM deployments")
return
logger.info(f"ℹ️ Using account {EVM_ADDRESS} as deployer")
await deploy_and_fund_evm_address(
EVM_ADDRESS, amount=100 if NETWORK["type"] is NetworkType.DEV else 0.01
)
bridge = await deploy_evm("CairoPrecompiles", "EthStarknetBridge")
evm_deployments["Bridge"] = {
"address": int(bridge.address, 16),
"starknet_address": bridge.starknet_address,
}
await invoke(
"kakarot", "set_authorized_cairo_precompile_caller", int(bridge.address, 16), 1
)
await invoke("kakarot", "set_coinbase", int(bridge.address, 16))
coinbase = (await call("kakarot", "get_coinbase")).coinbase
if coinbase == 0:
logger.error("❌ Coinbase is set to 0, all transaction fees will be lost")
else:
logger.info(f"✅ Coinbase set to: 0x{coinbase:040x}")
weth = await deploy_evm("WETH", "WETH9")
evm_deployments["WETH"] = {
"address": int(weth.address, 16),
"starknet_address": weth.starknet_address,
}
dump_evm_deployments(evm_deployments)
balance_after = await get_balance(account.address)
logger.info(
f"ℹ️ Deployer balance changed from {balance_pref / 1e18} to {balance_after / 1e18} ETH"
)
# %% Run
def main_sync():
run(main())
if __name__ == "__main__":
main_sync()