-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deploy Openzeppelin accounts script (#1396)
Time spent on this PR: 0.5 ## 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: - [ ] Bugfix - [x] 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? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Resolves #<Issue number> ## What is the new behavior? Script that allows the deployment of OpenZeppelin accounts, saving the private key on AWS Secrets and exporting a JSON containing the addresses of the deployed accounts and the secret ID to retrieve the private key (file stored in `kakarot_scripts/data`). **Parameters to configure in order to run the script:** - **num_accounts** - The number of OZ accounts. - **amount** - The amount to send to the address to deploy the accounts. - **private_key** - The private key to use, which will also be saved on AWS Secrets. Therefore, it only needs to be provided the first time; in subsequent executions, you can use an empty string `""` to retrieve the previous key. Otherwise, the secret will be updated. - **class_hash** - The class hash of OpenZeppelinAccount. To interact with AWS Secrets, boto3 requires the AWS configuration variables to be set up. [Here is the documentation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/configure/index.html) <!-- 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/1396) <!-- Reviewable:end -->
- Loading branch information
Showing
5 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
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 = [] | ||
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters