Skip to content

Commit

Permalink
Add declare script for presets (#1118)
Browse files Browse the repository at this point in the history
* start declare script

* fix fmt

* fix fmt

* update Scarb

* finish declare script

* fix fmt

* update scarb

* move max_fee to const

* fix const

* add readme to declare script

* tidy up

* bump version

* move scripts to root

* add foundry items to gitignore

* Apply suggestions from code review

Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com>

* fix var

* change to v0.1

* remove dir

* update scarb.lock

---------

Co-authored-by: immrsd <103599616+immrsd@users.noreply.github.com>
  • Loading branch information
andrew-fleming and immrsd authored Oct 8, 2024
1 parent 1cbef43 commit c5cd715
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 0 deletions.
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
```
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;

0 comments on commit c5cd715

Please sign in to comment.