Skip to content

Commit

Permalink
Update deploy scripts to match latest version from kakarot
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementWalter committed Jul 25, 2023
1 parent 524b282 commit 5c41f3f
Show file tree
Hide file tree
Showing 17 changed files with 315,052 additions and 307 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"python.testing.pytestArgs": ["packages"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"githubPullRequests.ignoredPullRequestBranches": ["staging"]
}
17,708 changes: 17,707 additions & 1 deletion packages/starksheet-cairo/build/BasicCellRenderer.json

Large diffs are not rendered by default.

48,288 changes: 48,287 additions & 1 deletion packages/starksheet-cairo/build/ERC20.json

Large diffs are not rendered by default.

158,962 changes: 158,961 additions & 1 deletion packages/starksheet-cairo/build/Sheet.json

Large diffs are not rendered by default.

41,263 changes: 41,262 additions & 1 deletion packages/starksheet-cairo/build/Starksheet.json

Large diffs are not rendered by default.

24,101 changes: 24,100 additions & 1 deletion packages/starksheet-cairo/build/UriRenderer.json

Large diffs are not rendered by default.

2,641 changes: 2,640 additions & 1 deletion packages/starksheet-cairo/build/execute.json

Large diffs are not rendered by default.

8,063 changes: 8,062 additions & 1 deletion packages/starksheet-cairo/build/math.json

Large diffs are not rendered by default.

13,617 changes: 13,616 additions & 1 deletion packages/starksheet-cairo/build/proxy.json

Large diffs are not rendered by default.

28 changes: 12 additions & 16 deletions packages/starksheet-cairo/deployments/katana/deployments.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
{
"BasicCellRenderer": {
"address": "0x7a594e86cc7b3aca304c5d930173b9edf012c32cdabc56d6a0839028db16046",
"tx": "0x28ce03e5620fd8fa46950cae8662f02dd29ed8915b5b1c0d360d456eb020935",
"artifact": "build/BasicCellRenderer.json",
"alias": "basic_cell_renderer"
"address": "0x47ae818d59330d63ba514a2822179b01313a9f9bf38fc2aa2c71fce1a965721",
"tx": "0x1831e5720f59268f506318bae81de4598abbb012cca9cb1544561ac1648ee35",
"artifact": "build/BasicCellRenderer.json"
},
"math": {
"address": "0x90804b8614b751c99c4000cfc114d21e258864515171042f93d082fcb3bb11",
"tx": "0x7a7c24760fea164abe754d15b414a883377f7d6a2ede5a2d33a5daff7026eac",
"artifact": "build/math.json",
"alias": "math"
"address": "0x1885ddc5917c19b1fb805bbe6a2d41abf221aff0c9610793faff9a3529f2994",
"tx": "0x23226e2763cde9f709ae77effb23c74c631e9d693ccfda9d44db281ad2233cd",
"artifact": "build/math.json"
},
"execute": {
"address": "0x1ee218aac697527a6f2ed647f4589fcb1a914bd61e45ad781af8f3807e17e7f",
"tx": "0x2b29413355992e917407f0593b03a65abcb133e9c2a2cea0ad44d053b763fee",
"artifact": "build/execute.json",
"alias": "execute"
"address": "0x1f2cae998679b9a469156a08b99d8247ece51644ccb60625c65f68d15ecd4b0",
"tx": "0x4737b2541fd141fd2e1c96d382bd5f8a7e1b59ed16b1ebd594bf996c7502440",
"artifact": "build/execute.json"
},
"Starksheet": {
"address": "0x2c21a6d5a4183f377de248d5ba8041a2b50bb2e0ec982f4e71e5b60cc60758c",
"tx": "0xdf8b871ffb47cbf13d114729672c0630adaee0babe1a4b2ddd2655fdf54332",
"artifact": "build/Starksheet.json",
"alias": "starksheet"
"address": "0x540abc165710b1637d28c3a4f26a5d925b8fd79dbe6e0b8eb8d813c40683967",
"tx": "0x2ae87193d5214bddb08b792fc99f8ea3b43782afec4b9d6f5bac2bfa7d44500",
"artifact": "build/Starksheet.json"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Sheet": "0x1759e57ef31878f7dc5695b7095a174997da09fde32e5bc1aeb2c9b70fcc56c",
"Starksheet": "0x38e88274237b46e2296ee0109f3c0c6e7791afb54a3a0623d66b926a02eac2e",
"BasicCellRenderer": "0x2694071ff6342f6d05f4ae54ebd48533fb7be2a6056b07fa22520e08f4bca89",
"UriRenderer": "0x7a7c733fa4802f34d06d87fb990d5766ea4971f5ead396cbb655b2824d3235a",
"math": "0x65585eab9a699786217dfd49573fe81108ea59ec398fce4292908accd526aa4",
"execute": "0x6d959eb4c0fb37f5a975c1b2a5b3f55ad7dc3c64a88c19fcd95fa159fa81e",
"proxy": "0x7657c969f82c665731ea2cbd29e5063a72375a113443e48013c9a7cee16c31b",
"ERC20": "0x76927a7de4cf94327fb0a74097bb43b8d28ea062e35abfde9ab189d1ef16ee"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"BasicCellRenderer": {
"address": "0x259d3d1381f9f88a1fdb13738a5658721fe778e40cc69606a5fb1c6fd038bc8",
"tx": "0x6cca55fe9d18fead995d4a1e72d6db1643900064b9771b1745428a444f2021a",
"artifact": "build/BasicCellRenderer.json"
},
"math": {
"address": "0x373a9d36615e35fb741016977b6aaf5e626eef08801bb6f7fff722a16d641f1",
"tx": "0xb6453ada3fc256a788ac3c6e822a0286e4c286512c3b002cd70a4e5d3fe94c",
"artifact": "build/math.json"
},
"execute": {
"address": "0x11ed1758a1c75a29c8f7491600b4035adbd472da33137793b85128abaed79da",
"tx": "0x6896c16aea9986a8a029a5d2ed20fbe55672933d92eeb4b333da2ff06a6ecf1",
"artifact": "build/execute.json"
},
"Starksheet": {
"address": "0x5cb797f51592997390214de2982be3a7aca3a87a512fc4ce40f0c1b9553c06a",
"tx": "0x7c64ed35731991487db7c61c06756c32658fa8a7c49acfd935be05380a9995a",
"artifact": "build/Starksheet.json"
}
}
2 changes: 1 addition & 1 deletion packages/starksheet-cairo/scripts/starksheet_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from dotenv import load_dotenv
from utils.constants import COMPILED_CONTRACTS, NETWORK
from utils.deployment import compile_contract
from utils.starknet import compile_contract

load_dotenv()
logging.basicConfig()
Expand Down
41 changes: 13 additions & 28 deletions packages/starksheet-cairo/scripts/starksheet_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
from asyncio import run

from dotenv import load_dotenv
from utils.constants import COMPILED_CONTRACTS, NETWORK
from utils.deployment import (
from utils.constants import COMPILED_CONTRACTS
from utils.starknet import (
declare,
deploy,
dump_declarations,
dump_deployments,
get_account,
get_alias,
get_artifact,
get_declarations,
get_deployments,
get_starknet_account,
)

load_dotenv()
Expand All @@ -25,7 +25,7 @@
# %% Main
async def main():
# %% Declarations
account = await get_account()
account = await get_starknet_account()
logger.info(f"ℹ️ Using account {hex(account.address)} as deployer")

class_hash = {
Expand All @@ -38,36 +38,21 @@ async def main():
class_hash = get_declarations()
deployments = get_deployments()
deployments = {
contract_name: {
**dict(zip(["address", "tx"], await deploy(contract_name))),
"artifact": get_artifact(contract_name),
"alias": get_alias(contract_name),
}
contract_name: await deploy(contract_name)
for contract_name in [
"BasicCellRenderer",
"math",
"execute",
]
}
deployments["Starksheet"] = {
**dict(
zip(
["address", "tx"],
await deploy(
"Starksheet",
(await get_account()).address, # owner
class_hash["Sheet"], # sheet_class_hash
class_hash["proxy"], # proxy_class_hash
deployments["BasicCellRenderer"][
"address"
], # default_renderer_address
int(0.01 * 1e18), # sheet_price
),
)
),
"artifact": get_artifact("Starksheet"),
"alias": get_alias("Starksheet"),
}
deployments["Starksheet"] = await deploy(
"Starksheet",
(await get_starknet_account()).address, # owner
class_hash["Sheet"], # sheet_class_hash
class_hash["proxy"], # proxy_class_hash
deployments["BasicCellRenderer"]["address"], # default_renderer_address
int(0.01 * 1e18), # sheet_price
)
dump_deployments(deployments)


Expand Down
131 changes: 84 additions & 47 deletions packages/starksheet-cairo/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,100 +1,133 @@
import json
import logging
import os
import re
from enum import Enum
from math import ceil, log
from pathlib import Path

import requests
from dotenv import load_dotenv
from eth_keys import keys
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.net.models.chains import StarknetChainId

logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
load_dotenv()


class ChainId(Enum):
mainnet = int.from_bytes(b"SN_MAIN", "big")
testnet = int.from_bytes(b"SN_GOERLI", "big")
testnet2 = int.from_bytes(b"SN_GOERLI2", "big")
katana = int.from_bytes(b"KATANA", "big")


NETWORKS = {
"mainnet": {
"name": "mainnet",
"explorer_url": "https://starkscan.co",
"rpc_url": f"https://starknet-mainnet.infura.io/v3/{os.getenv('INFURA_KEY')}",
"chain_id": ChainId.mainnet,
"starknet_id_address": 0x05DBDEDC203E92749E2E746E2D40A768D966BD243DF04A6B712E222BC040A9AF,
"starknet_id_naming": 0x06AC597F8116F886FA1C97A23FA4E08299975ECAF6B598873CA6792B9BBFB678,
"gateway": "mainnet",
"devnet": False,
"chain_id": StarknetChainId.MAINNET,
},
"testnet": {
"name": "testnet",
"explorer_url": "https://testnet.starkscan.co",
"rpc_url": f"https://starknet-goerli.infura.io/v3/{os.getenv('INFURA_KEY')}",
"chain_id": ChainId.testnet,
"starknet_id_address": 0x0783A9097B26EAE0586373B2CE0ED3529DDC44069D1E0FBC4F66D42B69D6850D,
"starknet_id_naming": 0x003BAB268E932D2CECD1946F100AE67CE3DFF9FD234119EA2F6DA57D16D29FCE,
"gateway": "testnet",
"devnet": False,
"chain_id": StarknetChainId.TESTNET,
},
"testnet2": {
"name": "testnet2",
"explorer_url": "https://testnet-2.starkscan.co",
"rpc_url": f"https://starknet-goerli2.infura.io/v3/{os.getenv('INFURA_KEY')}",
"chain_id": ChainId.testnet2,
"starknet_id_address": "",
"starknet_id_naming": "",
"gateway": "testnet2",
"devnet": False,
"chain_id": StarknetChainId.TESTNET2,
},
"devnet": {
"name": "devnet",
"starknet-devnet": {
"name": "starknet-devnet",
"explorer_url": "",
"rpc_url": "http://127.0.0.1:5050/rpc",
"chain_id": ChainId.testnet,
"starknet_id_address": 0x0783A9097B26EAE0586373B2CE0ED3529DDC44069D1E0FBC4F66D42B69D6850D,
"starknet_id_naming": 0x003BAB268E932D2CECD1946F100AE67CE3DFF9FD234119EA2F6DA57D16D29FCE,
},
"docker": {
"name": "docker",
"explorer_url": "https://devnet.starkscan.co",
"rpc_url": "http://127.0.0.1:5050/rpc",
"chain_id": ChainId.testnet,
"starknet_id_address": 0x0783A9097B26EAE0586373B2CE0ED3529DDC44069D1E0FBC4F66D42B69D6850D,
"starknet_id_naming": 0x003BAB268E932D2CECD1946F100AE67CE3DFF9FD234119EA2F6DA57D16D29FCE,
"devnet": True,
"check_interval": 0.1,
"max_wait": 1,
},
"katana": {
"name": "katana",
"explorer_url": "",
"rpc_url": "http://127.0.0.1:5050",
"chain_id": ChainId.katana,
"starknet_id_address": "",
"starknet_id_naming": "",
"devnet": True,
"check_interval": 0.1,
"max_wait": 1,
},
"madara": {
"name": "madara",
"explorer_url": "",
"rpc_url": "http://127.0.0.1:9944",
"chain_id": ChainId.testnet,
"starknet_id_address": "",
"starknet_id_naming": "",
"devnet": False,
"check_interval": 6,
"max_wait": 30,
},
"sharingan": {
"name": "sharingan",
"explorer_url": "",
"rpc_url": os.getenv("SHARINGAN_RPC_URL"),
"chain_id": ChainId.testnet,
"starknet_id_address": "",
"starknet_id_naming": "",
"devnet": False,
"check_interval": 6,
"max_wait": 30,
},
}

NETWORK = NETWORKS[os.getenv("STARKNET_NETWORK", "devnet")]
NETWORK["account_address"] = os.environ.get(
f"{NETWORK['name'].upper()}_ACCOUNT_ADDRESS"
) or os.environ.get("ACCOUNT_ADDRESS")
NETWORK["private_key"] = os.environ.get(
f"{NETWORK['name'].upper()}_PRIVATE_KEY"
) or os.environ.get("PRIVATE_KEY")
if os.getenv("STARKNET_NETWORK") is not None:
if NETWORKS.get(os.environ["STARKNET_NETWORK"]) is not None:
NETWORK = NETWORKS[os.environ["STARKNET_NETWORK"]]
else:
raise ValueError(
f"STARKNET_NETWORK {os.environ['STARKNET_NETWORK']} given in env variable unknown"
)
else:
NETWORK = {
"name": "",
"rpc_url": os.getenv("RPC_URL"),
"explorer_url": "",
"devnet": False,
"check_interval": 6,
"max_wait": 30,
}

prefix = NETWORK["name"].upper().replace("-", "_")
NETWORK["account_address"] = os.environ.get(f"{prefix}_ACCOUNT_ADDRESS")
if NETWORK["account_address"] is None:
logger.warning(
f"⚠️ {prefix}_ACCOUNT_ADDRESS not set, defaulting to ACCOUNT_ADDRESS"
)
NETWORK["account_address"] = os.getenv("ACCOUNT_ADDRESS")
NETWORK["private_key"] = os.environ.get(f"{prefix}_PRIVATE_KEY")
if NETWORK["private_key"] is None:
logger.warning(f"⚠️ {prefix}_PRIVATE_KEY not set, defaulting to PRIVATE_KEY")
NETWORK["private_key"] = os.getenv("PRIVATE_KEY")

RPC_CLIENT = FullNodeClient(node_url=NETWORK["rpc_url"])
GATEWAY_CLIENT = GatewayClient(NETWORK["gateway"]) if NETWORK.get("gateway") else None
CLIENT = GATEWAY_CLIENT if GATEWAY_CLIENT is not None else RPC_CLIENT

try:
response = requests.post(
RPC_CLIENT.url,
json={
"jsonrpc": "2.0",
"method": f"starknet_chainId",
"params": [],
"id": 0,
},
)
payload = json.loads(response.text)

class ChainId(Enum):
chain_id = int(payload["result"], 16)

NETWORK["chain_id"] = ChainId.chain_id
except:
pass

ETH_TOKEN_ADDRESS = 0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7
SOURCE_DIR = Path("src")
Expand All @@ -120,4 +153,8 @@ class ChainId(Enum):

ALLOW_LIST = []

logger.info(f"ℹ️ Using Chain id {NETWORK['chain_id'].name} with RPC {RPC_CLIENT.url}")
if NETWORK.get("chain_id"):
logger.info(
f"ℹ️ Connected to CHAIN_ID {NETWORK['chain_id'].value.to_bytes(ceil(log(NETWORK['chain_id'].value, 256)), 'big')} "
f"with {f'Gateway {GATEWAY_CLIENT.net}' if GATEWAY_CLIENT is not None else f'RPC {RPC_CLIENT.url}'}"
)
Loading

0 comments on commit 5c41f3f

Please sign in to comment.