-
Notifications
You must be signed in to change notification settings - Fork 357
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
andrew-fleming
merged 22 commits into
OpenZeppelin:main
from
andrew-fleming:add-declare-script
Oct 8, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
afe0325
start declare script
andrew-fleming 448e326
fix fmt
andrew-fleming 3c57b59
fix fmt
andrew-fleming 5f041a6
Merge branch 'main' into add-declare-script
andrew-fleming d9cacfa
update Scarb
andrew-fleming 3c2d97c
finish declare script
andrew-fleming cb9cb73
fix fmt
andrew-fleming 14bb7c2
Merge branch 'main' into add-declare-script
andrew-fleming 26d79d9
update scarb
andrew-fleming 20404e5
move max_fee to const
andrew-fleming 5faafd1
fix const
andrew-fleming 5bf86a5
add readme to declare script
andrew-fleming ccc83f4
tidy up
andrew-fleming dda57e5
bump version
andrew-fleming 0be5f15
move scripts to root
andrew-fleming b8d770d
add foundry items to gitignore
andrew-fleming d60dd8e
Apply suggestions from code review
andrew-fleming 8d6ae3c
fix var
andrew-fleming ec24f12
change to v0.1
andrew-fleming 183e9b8
remove dir
andrew-fleming 98a8453
Merge branch 'main' into add-declare-script
andrew-fleming 956a586
update scarb.lock
andrew-fleming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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 | ||
``` |
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,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", | ||
] |
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,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", | ||
] |
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,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) | ||
} | ||
} |
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 @@ | ||
mod declare_presets; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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