Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy Openzeppelin accounts script #1396

Merged
merged 6 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class NetworkType(Enum):
"chain_id": StarknetChainId.MAINNET,
"check_interval": 1,
"max_wait": 10,
"class_hash": 0x061DAC032F228ABEF9C6626F995015233097AE253A7F72D68552DB02F2971B8F,
},
"sepolia": {
"name": "starknet-sepolia",
Expand All @@ -50,6 +51,7 @@ class NetworkType(Enum):
"chain_id": StarknetChainId.SEPOLIA,
"check_interval": 1,
"max_wait": 10,
"class_hash": 0x061DAC032F228ABEF9C6626F995015233097AE253A7F72D68552DB02F2971B8F,
},
"starknet-devnet": {
"name": "starknet-devnet",
Expand All @@ -68,6 +70,7 @@ class NetworkType(Enum):
"type": NetworkType.DEV,
"check_interval": 0.01,
"max_wait": 3,
"class_hash": 0x6153CCF69FD20F832C794DF36E19135F0070D0576144F0B47F75A226E4BE530,
"relayers": [
{
"address": 0xB3FF441A68610B30FD5E2ABBF3A1548EB6BA6F3559F2862BF2DC757E5828CA,
Expand Down
62 changes: 62 additions & 0 deletions kakarot_scripts/utils/deploy_oz.py
eugypalu marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# %% Imports
import asyncio
import json
import logging
import secrets

import boto3

from kakarot_scripts.utils.starknet import deploy_starknet_account

# Initialize AWS Secrets Manager client
client = boto3.client("secretsmanager")
SECRET_NAME = "relayers_private_key"

eugypalu marked this conversation as resolved.
Show resolved Hide resolved
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


# %% Get private key
def get_private_key():
"""Retrieve or generate a private key."""
try:
response = client.get_secret_value(SecretId=SECRET_NAME)
private_key = response["SecretString"]
secret_id = response["ARN"]
except client.exceptions.ResourceNotFoundException:
private_key = hex(secrets.randbits(256))
secret_id = client.create_secret(Name=SECRET_NAME, SecretString=private_key)[
"ARN"
]
return private_key, secret_id


# %% Deploy accounts
async def main():
"""Deploy 'num_accounts' accounts and store the private keys in AWS Secrets Manager."""
num_accounts = 30 # Number of accounts to create
amount = 0.1 # Initial funding amount for each relayer account
accounts_data = []
eugypalu marked this conversation as resolved.
Show resolved Hide resolved
private_key, secret_id = get_private_key()

accounts_data = [
{
"secret_id": secret_id,
"address": (
await deploy_starknet_account(private_key=private_key, amount=amount)
)["address"],
}
for _ in range(num_accounts)
]
logger.info(f"{num_accounts} accounts deployed and saved to 'oz_accounts.json'")

# Save the account data to a JSON file
with open("kakarot_scripts/data/oz_accounts.json", "w") as json_file:
json.dump(accounts_data, json_file, indent=2)


# %% Run
if __name__ == "__main__":
# Deploy the accounts and store private keys in AWS Secrets Manager
asyncio.run(main())
4 changes: 3 additions & 1 deletion kakarot_scripts/utils/starknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ async def deploy_starknet_account(class_hash=None, private_key=None, amount=1):
)
key_pair = KeyPair.from_private_key(int(private_key, 16))
constructor_calldata = [key_pair.public_key]
class_hash = class_hash or get_declarations()["OpenzeppelinAccount"]
class_hash = class_hash or NETWORK.get(
"class_hash", get_declarations().get("OpenzeppelinAccount")
)
address = compute_address(
salt=salt,
class_hash=class_hash,
Expand Down
71 changes: 69 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async-lru = "^2.0.4"
toml = "^0.10.2"
scikit-learn = "^1.5.1"
seaborn = "^0.13.2"
boto3 = "^1.35.12"

[tool.poetry.group.dev.dependencies]
pytest = "^8.1.1"
Expand Down
Loading