-
Notifications
You must be signed in to change notification settings - Fork 323
/
kakarot_deployment.py
113 lines (97 loc) · 3.29 KB
/
kakarot_deployment.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
# %% Imports
import logging
from uvloop import run
from kakarot_scripts.constants import (
BLOCK_GAS_LIMIT,
DEFAULT_GAS_PRICE,
ETH_TOKEN_ADDRESS,
EVM_ADDRESS,
NETWORK,
RPC_CLIENT,
NetworkType,
)
from kakarot_scripts.utils.kakarot import eth_chain_id
from kakarot_scripts.utils.starknet import deploy as deploy_starknet
from kakarot_scripts.utils.starknet import (
dump_deployments,
execute_calls,
get_declarations,
get_deployments,
get_starknet_account,
invoke,
register_lazy_account,
remove_lazy_account,
)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# %%
async def deploy_or_upgrade_kakarot(owner):
# %% Load data
class_hash = get_declarations()
starknet_deployments = get_deployments()
# 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"],
)
# Initialize the chain_id if it's value is not set
if await eth_chain_id() == 0:
await invoke("kakarot", "initialize_chain_id", NETWORK["chain_id"])
else:
logger.info("✅ Kakarot already up to date.")
else:
starknet_deployments["kakarot"] = await deploy_starknet(
"kakarot",
owner.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,
NETWORK["chain_id"],
)
await invoke(
"kakarot",
"set_base_fee",
DEFAULT_GAS_PRICE,
address=starknet_deployments["kakarot"],
)
# Temporarily set the coinbase to the default EVM deployer so that
# fees are not sent to 0x0 but rather sent back to the deployer itself,
# until the coinbase is set to the deployed contract later on.
await invoke(
"kakarot",
"set_coinbase",
int(EVM_ADDRESS, 16),
address=starknet_deployments["kakarot"],
)
dump_deployments(starknet_deployments)
# %% Run
async def main():
try:
await RPC_CLIENT.get_class_by_hash(get_declarations()["kakarot"])
except Exception:
logger.error("❌ Kakarot is not declared, exiting...")
return
account = await get_starknet_account()
register_lazy_account(account.address)
await deploy_or_upgrade_kakarot(account)
await execute_calls()
remove_lazy_account(account.address)
def main_sync():
run(main())
if __name__ == "__main__":
main_sync()