Skip to content

Commit

Permalink
redeploy + some fixes (#1196)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

<!-- Give an estimate of the time you spent on this PR in terms of work
days.
Did you spend 0.5 days on this PR or rather 2 days?  -->

Time spent on this PR: 0.3 day

## Pull request type

<!-- Please try to limit your pull request to one type,
submit multiple pull requests if needed. -->

Please check the type of change your PR introduces:

- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?
Staging can't run correctly currently.

Resolves #NA

## What is the new behavior?
- Upgrades Kakarot on staging 
- Adds a type of network "staging" which allows upgrades but also uses
the "EVM" fixture.

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1196)
<!-- Reviewable:end -->
  • Loading branch information
greged93 committed Jun 10, 2024
1 parent 2f41420 commit a63a987
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 20 deletions.
4 changes: 2 additions & 2 deletions deployments/kakarot-staging/declarations.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"kakarot": "0x7a4394ca8608f89bb947e81d364e18a3651369c67ec1f008ae2b9fae3dee69a",
"kakarot": "0x701a9ab6675823700bb14629c63683f720ffbb57dc445d6c87ebfea8e55904a",
"account_contract": "0x1276d0b017701646f8646b69de6c3b3584edce71879678a679f28c07a9971cf",
"account_contract_fixture": "0x3a247bfdb923a0e950871336d9ffd9d1d052ef79ce31909954f5c2e81e77e00",
"uninitialized_account": "0x600f6862938312a05a0cfecba0dcaf37693efc9e4075a6adfb62e196022678e",
"EVM": "0x7f14daf9420729ca261433e62404b0415c308e15f7f6fc576f665110e2ac8b9",
"EVM": "0x76157e8119e18e6df44c7f7511857136898480104422510463462e1b1c149e5",
"OpenzeppelinAccount": "0x6153ccf69fd20f832c794df36e19135f0070d0576144f0b47f75a226e4be530",
"Cairo1Helpers": "0x28ece3751ecf5bdf2d791eb64a65bfb6a8816432b698870dba2f38a36101d58",
"Cairo1HelpersFixture": "0x4e7811d9bbba41193bd3c77d05c16f7aaa55dd1d601686b50f6fa0e3766a712",
Expand Down
4 changes: 2 additions & 2 deletions deployments/kakarot-staging/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"artifact": "build/kakarot.json"
},
"EVM": {
"address": "0x75902a70542cd56454643f9c3fead34d3acb77012ed4c4a0356bcd044a73dc4",
"tx": "0x40c861ad7dcb7a5fd90f0d3164c99c6e6e9d746820f9a0fa34f98d2f9c22bdc",
"address": "0x4a64f9b67916a4496dd3ca2321dd1f5739d0dff33c0930684da1c695691c88f",
"tx": "0x7a805d7b596283b7d56afaded869f0384379cd99faf28ba6ca1e1aa098497d2",
"artifact": "build/fixtures/EVM.json"
},
"Counter": {
Expand Down
27 changes: 17 additions & 10 deletions kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,33 @@

BEACON_ROOT_ADDRESS = "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"


class NetworkType(Enum):
PROD = "prod"
DEV = "dev"
STAGING = "staging"


NETWORKS = {
"mainnet": {
"name": "mainnet",
"explorer_url": "https://starkscan.co",
"rpc_url": f"https://starknet-mainnet.infura.io/v3/{os.getenv('INFURA_KEY')}",
"devnet": False,
"type": NetworkType.PROD,
"chain_id": StarknetChainId.MAINNET,
},
"goerli": {
"name": "starknet-goerli",
"explorer_url": "https://testnet.starkscan.co",
"rpc_url": f"https://starknet-goerli.infura.io/v3/{os.getenv('INFURA_KEY')}",
"devnet": False,
"type": NetworkType.PROD,
"chain_id": StarknetChainId.GOERLI,
},
"sepolia": {
"name": "starknet-sepolia",
"explorer_url": "https://sepolia.starkscan.co/",
"rpc_url": "https://starknet-sepolia.public.blastapi.io/rpc/v0_6",
"devnet": False,
"type": NetworkType.PROD,
"chain_id": StarknetChainId.SEPOLIA_TESTNET,
"check_interval": 5,
"max_wait": 30,
Expand All @@ -50,47 +57,47 @@
"name": "starknet-devnet",
"explorer_url": "",
"rpc_url": "http://127.0.0.1:5050/rpc",
"devnet": True,
"type": NetworkType.DEV,
"check_interval": 0.01,
"max_wait": 1,
},
"katana": {
"name": "katana",
"explorer_url": "",
"rpc_url": os.getenv("KATANA_RPC_URL", "http://127.0.0.1:5050"),
"devnet": True,
"type": NetworkType.DEV,
"check_interval": 0.01,
"max_wait": 2,
},
"madara": {
"name": "madara",
"explorer_url": "",
"rpc_url": os.getenv("MADARA_RPC_URL", "http://127.0.0.1:9944"),
"devnet": False,
"type": NetworkType.DEV,
"check_interval": 6,
"max_wait": 30,
},
"sharingan": {
"name": "sharingan",
"explorer_url": "",
"rpc_url": os.getenv("SHARINGAN_RPC_URL"),
"devnet": False,
"type": NetworkType.PROD,
"check_interval": 6,
"max_wait": 30,
},
"kakarot-sepolia": {
"name": "kakarot-sepolia",
"explorer_url": "",
"rpc_url": os.getenv("KAKAROT_SEPOLIA_RPC_URL"),
"devnet": False,
"type": NetworkType.PROD,
"check_interval": 6,
"max_wait": 360,
},
"kakarot-staging": {
"name": "kakarot-staging",
"explorer_url": "",
"rpc_url": os.getenv("KAKAROT_STAGING_RPC_URL"),
"devnet": True,
"type": NetworkType.STAGING,
"check_interval": 1,
"max_wait": 30,
},
Expand All @@ -108,7 +115,7 @@
"name": os.getenv("RPC_NAME", "custom-rpc"),
"rpc_url": os.getenv("RPC_URL"),
"explorer_url": "",
"devnet": False,
"type": NetworkType.PROD,
"check_interval": float(os.getenv("CHECK_INTERVAL", 0.1)),
"max_wait": float(os.getenv("MAX_WAIT", 30)),
}
Expand Down
26 changes: 23 additions & 3 deletions kakarot_scripts/deploy_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
EVM_ADDRESS,
NETWORK,
RPC_CLIENT,
NetworkType,
)
from kakarot_scripts.utils.starknet import (
declare,
Expand All @@ -20,6 +21,7 @@
get_deployments,
get_starknet_account,
invoke,
upgrade,
)

logging.basicConfig()
Expand All @@ -43,7 +45,7 @@ async def main():
class_hash = get_declarations()

deployments = get_deployments()
if deployments.get("kakarot") and not NETWORK["devnet"]:
if 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(
deployments["kakarot"]["address"]
Expand Down Expand Up @@ -74,7 +76,25 @@ async def main():
BLOCK_GAS_LIMIT,
)

if NETWORK["devnet"]:
if NETWORK["type"] is NetworkType.STAGING:
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,
],
)
deployments["Counter"] = await upgrade("Counter")
deployments["MockPragmaOracle"] = await upgrade("MockPragmaOracle")

if NETWORK["type"] is NetworkType.DEV:
deployments["EVM"] = await deploy(
"EVM",
account.address, # owner
Expand All @@ -94,7 +114,7 @@ async def main():
logger.info(f"ℹ️ Found default EVM address {EVM_ADDRESS}")
from kakarot_scripts.utils.kakarot import get_eoa

amount = 0.02 if not NETWORK["devnet"] else 100
amount = 0.02 if NETWORK["type"] is not NetworkType.DEV else 100
await get_eoa(amount=amount)


Expand Down
27 changes: 25 additions & 2 deletions kakarot_scripts/utils/starknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
SOURCE_DIR,
ArtifactType,
ChainId,
NetworkType,
)

logging.basicConfig()
Expand Down Expand Up @@ -308,9 +309,13 @@ def compile_contract(contract):
artifact,
"--cairo_path",
str(SOURCE_DIR),
*(["--no_debug_info"] if not NETWORK["devnet"] else []),
*(["--no_debug_info"] if NETWORK["type"] is not NetworkType.DEV else []),
*(["--account_contract"] if contract["is_account_contract"] else []),
*(["--disable_hint_validation"] if NETWORK["devnet"] else []),
*(
["--disable_hint_validation"]
if NETWORK["type"] is NetworkType.DEV
else []
),
],
capture_output=True,
)
Expand Down Expand Up @@ -480,6 +485,24 @@ async def deploy(contract_name, *args):
}


async def upgrade(contract_name, *args):
deployments = get_deployments()
if not deployments.get(contract_name):
return await deploy(contract_name, *args)

logger.info(f"ℹ️ {contract_name} already deployed, checking version.")
class_hash = get_declarations()

deployed_class_hash = await RPC_CLIENT.get_class_hash_at(
deployments[contract_name]["address"]
)
if deployed_class_hash != class_hash[contract_name]:
logger.info(f"ℹ️ redeploying {contract_name}.")
return await deploy(contract_name, *args)

return deployments[contract_name]


async def invoke_address(contract_address, function_name, *calldata, account=None):
account = account or (await get_starknet_account())
logger.info(
Expand Down
3 changes: 2 additions & 1 deletion tests/end_to_end/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from starknet_py.contract import Contract
from starknet_py.net.account.account import Account

from kakarot_scripts.constants import NetworkType
from kakarot_scripts.utils.starknet import wait_for_transaction
from tests.utils.helpers import generate_random_private_key

Expand All @@ -28,7 +29,7 @@ def default_fee():
"""
from kakarot_scripts.constants import NETWORK

if NETWORK["devnet"]:
if NETWORK["type"] is NetworkType.DEV:
return int(0)
else:
return int(1e16)
Expand Down

0 comments on commit a63a987

Please sign in to comment.