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

Add declare script for presets #1118

Merged
merged 22 commits into from
Oct 8, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ target/

# Starknet Foundry
.snfoundry_cache/
*-sepolia_state.json
snfoundry.toml

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
32 changes: 32 additions & 0 deletions sncast_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Starknet Foundry Cast Scripts

This crate provides scripts using Starknet Foundry's Cast package.

## Prerequisites

Running these scripts will likely require an already-deployed account with funds to execute.
This crate can also be tested with [starknet-devnet](https://github.com/0xSpaceShard/starknet-devnet-rs).

## Usage

`cd` into the `sncast_scripts/` directory.
Run the command:

```bash
sncast script run <SCRIPT> --url <URL>
```

## Scripts

### `declare_presets`

Declares the preset contracts.
Here's the command using a starkli-style account:

```bash
sncast \
--account path/to/account.json \
--keystore path/to/key.json \
script run declare_presets \
--url http://127.0.0.1:5050
Comment on lines +28 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--account path/to/account.json \
--keystore path/to/key.json \
script run declare_presets \
--url http://127.0.0.1:5050
script run declare_presets \
--account path/to/account.json \
--keystore path/to/key.json \
--url http://127.0.0.1:5050

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having options after the command feels more natural.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but sncast only accepts the account flag before the command

```
104 changes: 104 additions & 0 deletions sncast_scripts/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "openzeppelin_access"
version = "0.17.0"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "0.17.0"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_finance"
version = "0.17.0"
dependencies = [
"openzeppelin_access",
"openzeppelin_token",
]

[[package]]
name = "openzeppelin_governance"
version = "0.17.0"
dependencies = [
"openzeppelin_access",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_introspection"
version = "0.17.0"

[[package]]
name = "openzeppelin_presets"
version = "0.17.0"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_finance",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
]

[[package]]
name = "openzeppelin_testing"
version = "0.17.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "openzeppelin_token"
version = "0.17.0"
dependencies = [
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_upgrades"
version = "0.17.0"

[[package]]
name = "openzeppelin_utils"
version = "0.17.0"

[[package]]
name = "sncast_scripts"
version = "0.1.0"
dependencies = [
"openzeppelin_presets",
"openzeppelin_testing",
"sncast_std",
]

[[package]]
name = "sncast_std"
version = "0.30.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:cfd7c73a6f9984880249babfa8664b69c5f7209c737b1081156a284061ccd41a"

[[package]]
name = "snforge_scarb_plugin"
version = "0.2.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:2e4ce3ebe3f49548bd26908391b5d78537a765d827df0d96c32aeb88941d0d67"

[[package]]
name = "snforge_std"
version = "0.30.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:2f3c4846881813ac0f5d1460981249c9f5e2a6831e752beedf9b70975495b4ec"
dependencies = [
"snforge_scarb_plugin",
]
25 changes: 25 additions & 0 deletions sncast_scripts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "sncast_scripts"
version = "0.1.0"

[dependencies]
starknet = "2.8.2"
sncast_std = "0.30.0"
openzeppelin_presets = { path = "../" }
openzeppelin_testing = { path = "../" }

[lib]
sierra = true
casm = true

[[target.starknet-contract]]
sierra = true
casm = true
build-external-contracts = [
"openzeppelin_presets::account::AccountUpgradeable",
"openzeppelin_presets::erc20::ERC20Upgradeable",
"openzeppelin_presets::erc721::ERC721Upgradeable",
"openzeppelin_presets::erc1155::ERC1155Upgradeable",
"openzeppelin_presets::eth_account::EthAccountUpgradeable",
"openzeppelin_presets::vesting::VestingWallet",
]
47 changes: 47 additions & 0 deletions sncast_scripts/src/declare_presets.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use openzeppelin_testing::common::IntoBase16String;
use sncast_std::{declare, get_nonce, FeeSettings, EthFeeSettings};

const MAX_FEE: felt252 = 99_999_999_999_999_999;

fn main() {
let contracts = array![
"AccountUpgradeable",
"ERC20Upgradeable",
"ERC721Upgradeable",
"ERC1155Upgradeable",
"EthAccountUpgradeable",
"VestingWallet"
];

let mut consumed_latest_nonce = false;
let mut nonce = get_nonce('latest');

for contract in contracts {
if (!consumed_latest_nonce) {
consumed_latest_nonce = true;
} else {
nonce = get_nonce('pending');
}

declare_preset(contract, nonce);
};

println!("");
}

fn declare_preset(contract: ByteArray, nonce: felt252) {
println!("\nDeclaring {contract}:");

let declare_result = declare(
contract,
FeeSettings::Eth(EthFeeSettings { max_fee: Option::Some(MAX_FEE) }),
Option::Some(nonce)
);

// Print output
// Note that the tx hash will already display from the declaration
match declare_result {
Result::Ok(r) => println!("Class hash = {}", r.class_hash.into_base_16_string()),
Result::Err(r) => println!("{:?}", r)
}
}
1 change: 1 addition & 0 deletions sncast_scripts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod declare_presets;