Skip to content

Commit

Permalink
Support for newer versions of OZ
Browse files Browse the repository at this point in the history
  • Loading branch information
ksew1 committed Jul 8, 2024
1 parent a128991 commit b73ee0c
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Cast

#### Added

- Newest class hash for OpenZeppelin account contracts

## [0.26.0] - 2024-07-03

### Forge
Expand Down
2 changes: 1 addition & 1 deletion crates/sncast/src/helpers/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ inputs = []
pub const UDC_ADDRESS: FieldElement =
felt!("0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf");
pub const OZ_CLASS_HASH: FieldElement =
felt!("0x061dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f");
felt!("0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6");
pub const ARGENT_CLASS_HASH: FieldElement =
felt!("0x029927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b");

Expand Down
10 changes: 10 additions & 0 deletions crates/sncast/tests/data/accounts/accounts.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@
"public_key": "0x515f196ae6e5c062ed82d3182a6115faf9117450ac3f1b1daeb67bda0580c26",
"salt": "0x5bb823302091cf89",
"type": "braavos"
},
"oz": {
"address": "0x1eae312dad53cf9d1c435891648cc48b14c901bec0e1bc87c332fcdca1a762f",
"class_hash": "0xe2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6",
"deployed": false,
"legacy": false,
"private_key": "0x6a3fff2b1333a4ed3dd6f9afc957c4ec9ac73af69590a6312ffeddb6caf0f20",
"public_key": "0x6aa82f4db6c740c27751885f47f2b73eed6c70d12d059965a563a04678c8405",
"salt": "0xc3990d6bbb890e77",
"type": "open_zeppelin"
}
}
}
10 changes: 5 additions & 5 deletions crates/sncast/tests/e2e/account/add.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::helpers::constants::{
DEVNET_OZ_CLASS_HASH_CAIRO_0, DEVNET_PREDEPLOYED_ACCOUNT_ADDRESS, URL,
DEVNET_OZ_CLASS_HASH_CAIRO_0, DEVNET_OZ_CLASS_HASH_CAIRO_1, DEVNET_PREDEPLOYED_ACCOUNT_ADDRESS,
URL,
};
use crate::helpers::runner::runner;
use camino::Utf8PathBuf;
Expand All @@ -8,7 +9,6 @@ use conversions::string::IntoHexStr;
use indoc::{formatdoc, indoc};
use serde_json::json;
use shared::test_utils::output_assert::assert_stderr_contains;
use sncast::helpers::constants::OZ_CLASS_HASH;
use std::fs::{self, File};
use tempfile::tempdir;
use test_case::test_case;
Expand Down Expand Up @@ -104,7 +104,7 @@ pub async fn test_existent_account_address() {
"alpha-sepolia": {
"my_account_add": {
"address": DEVNET_PREDEPLOYED_ACCOUNT_ADDRESS,
"class_hash": &OZ_CLASS_HASH.into_hex_string(),
"class_hash": &DEVNET_OZ_CLASS_HASH_CAIRO_1.into_hex_string(),
"deployed": true,
"legacy": false,
"private_key": "0x456",
Expand Down Expand Up @@ -317,7 +317,7 @@ pub async fn test_detect_deployed() {
"alpha-sepolia": {
"my_account_add": {
"address": DEVNET_PREDEPLOYED_ACCOUNT_ADDRESS,
"class_hash": &OZ_CLASS_HASH.into_hex_string(),
"class_hash": &DEVNET_OZ_CLASS_HASH_CAIRO_1.into_hex_string(),
"deployed": true,
"private_key": "0x5",
"public_key": "0x788435d61046d3eec54d77d25bd194525f4fa26ebe6575536bc6f656656b74c",
Expand Down Expand Up @@ -573,7 +573,7 @@ pub async fn test_private_key_as_int_in_file() {
"legacy": false,
"private_key": "0x456",
"public_key": "0x5f679dacd8278105bd3b84a15548fe84079068276b0e84d6cc093eb5430f063",
"class_hash": &OZ_CLASS_HASH.into_hex_string(),
"class_hash": &DEVNET_OZ_CLASS_HASH_CAIRO_1.into_hex_string(),
"type": "open_zeppelin"
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use test_case::test_case;

#[test_case("oz_cairo_0"; "cairo_0_account")]
#[test_case("oz_cairo_1"; "cairo_1_account")]
#[test_case("oz"; "oz_account")]
#[test_case("argent"; "argent_account")]
#[test_case("braavos"; "braavos_account")]
#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use test_case::test_case;

#[test_case("oz_cairo_0"; "cairo_0_account")]
#[test_case("oz_cairo_1"; "cairo_1_account")]
#[test_case("oz"; "oz_account")]
#[test_case("argent"; "argent_account")]
#[test_case("braavos"; "braavos_account")]
#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use test_case::test_case;

#[test_case("oz_cairo_0"; "cairo_0_account")]
#[test_case("oz_cairo_1"; "cairo_1_account")]
#[test_case("oz"; "oz_account")]
#[test_case("argent"; "argent_account")]
#[test_case("braavos"; "braavos_account")]
#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/multicall/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use test_case::test_case;

#[test_case("oz_cairo_0"; "cairo_0_account")]
#[test_case("oz_cairo_1"; "cairo_1_account")]
#[test_case("oz"; "oz_account")]
#[test_case("argent"; "argent_account")]
#[test_case("braavos"; "braavos_account")]
#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/script/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use test_case::test_case;

#[test_case("oz_cairo_0"; "cairo_0_account")]
#[test_case("oz_cairo_1"; "cairo_1_account")]
#[test_case("oz"; "oz_account")]
#[test_case("argent"; "argent_account")]
#[test_case("braavos"; "braavos_account")]
#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/script/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use test_case::test_case;

#[test_case("oz_cairo_0"; "cairo_0_account")]
#[test_case("oz_cairo_1"; "cairo_1_account")]
#[test_case("oz"; "oz_account")]
#[test_case("argent"; "argent_account")]
#[test_case("braavos"; "braavos_account")]
#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/script/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use test_case::test_case;

#[test_case("oz_cairo_0"; "cairo_0_account")]
#[test_case("oz_cairo_1"; "cairo_1_account")]
#[test_case("oz"; "oz_account")]
#[test_case("argent"; "argent_account")]
#[test_case("braavos"; "braavos_account")]
#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions crates/sncast/tests/e2e/script/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use test_case::test_case;

#[test_case("oz_cairo_0"; "cairo_0_account")]
#[test_case("oz_cairo_1"; "cairo_1_account")]
#[test_case("oz"; "oz_account")]
#[test_case("argent"; "argent_account")]
#[test_case("braavos"; "braavos_account")]
#[tokio::test]
Expand Down
9 changes: 8 additions & 1 deletion crates/sncast/tests/helpers/constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use starknet::core::types::FieldElement;
use starknet::macros::felt;

pub const ACCOUNT: &str = "user1";
pub const ACCOUNT_FILE_PATH: &str = "tests/data/accounts/accounts.json";
pub const SEPOLIA_RPC_URL: &str = "http://188.34.188.184:7070/rpc/v0_7";
Expand All @@ -7,7 +10,7 @@ pub const NETWORK: &str = "testnet";
pub const SEED: u32 = 1_053_545_548;

// Block number used by devnet to fork the Sepolia testnet network in the tests
pub const FORK_BLOCK_NUMBER: u32 = 58_340;
pub const FORK_BLOCK_NUMBER: u32 = 68_000;

pub const CONTRACTS_DIR: &str = "tests/data/contracts";
pub const SCRIPTS_DIR: &str = "tests/data/scripts";
Expand All @@ -18,6 +21,10 @@ pub const DEVNET_OZ_CLASS_HASH_CAIRO_0: &str =
pub const DEVNET_PREDEPLOYED_ACCOUNT_ADDRESS: &str =
"0x691a61b12a7105b1372cc377f135213c11e8400a546f6b0e7ea0296046690ce";

// OpenZeppelin account contract v0.8.1
pub const DEVNET_OZ_CLASS_HASH_CAIRO_1: FieldElement =
felt!("0x061dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f");

pub const MAP_CONTRACT_ADDRESS_SEPOLIA: &str =
"0xcd8f9ab31324bb93251837e4efb4223ee195454f6304fcfcb277e277653008";

Expand Down
2 changes: 2 additions & 0 deletions crates/sncast/tests/helpers/devnet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::helpers::constants::{FORK_BLOCK_NUMBER, SEED, SEPOLIA_RPC_URL, URL};
use crate::helpers::fixtures::{
deploy_argent_account, deploy_braavos_account, deploy_cairo_0_account, deploy_keystore_account,
deploy_latest_oz_account,
};
use ctor::{ctor, dtor};
use std::net::TcpStream;
Expand Down Expand Up @@ -69,6 +70,7 @@ fn start_devnet() {

rt.block_on(deploy_keystore_account());
rt.block_on(deploy_cairo_0_account());
rt.block_on(deploy_latest_oz_account());
rt.block_on(deploy_argent_account());
rt.block_on(deploy_braavos_account());
}
Expand Down
14 changes: 12 additions & 2 deletions crates/sncast/tests/helpers/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::helpers::constants::{ACCOUNT_FILE_PATH, DEVNET_OZ_CLASS_HASH_CAIRO_0, URL};
use anyhow::Context;
use camino::{Utf8Path, Utf8PathBuf};
use conversions::string::IntoHexStr;
use serde::de::DeserializeOwned;
use serde::Deserialize;
use serde_json::{json, Map, Value};
use sncast::helpers::braavos::BraavosAccountFactory;
use sncast::helpers::constants::{
ARGENT_CLASS_HASH, BRAAVOS_BASE_ACCOUNT_CLASS_HASH, BRAAVOS_CLASS_HASH,
ARGENT_CLASS_HASH, BRAAVOS_BASE_ACCOUNT_CLASS_HASH, BRAAVOS_CLASS_HASH, OZ_CLASS_HASH,
};
use sncast::helpers::scarb_utils::get_package_metadata;
use sncast::state::state_file::{
Expand Down Expand Up @@ -69,7 +70,16 @@ pub async fn deploy_cairo_0_account() {
)
.await;
}

pub async fn deploy_latest_oz_account() {
let (address, salt, private_key) = get_account_deployment_data("oz");
deploy_oz_account(
address.as_str(),
OZ_CLASS_HASH.into_hex_string().as_str(),
salt.as_str(),
private_key,
)
.await;
}
pub async fn deploy_argent_account() {
let provider = get_provider(URL).expect("Failed to get the provider");
let chain_id = get_chain_id(&provider)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/appendix/sncast/account/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Address of the account.
## `--type, -t <ACCOUNT_TYPE>`
Required.

Type of the account. Possible values: oz, argent.
Type of the account. Possible values: oz, argent, braavos.

## `--class-hash, -c <CLASS_HASH>`
Optional.
Expand Down
10 changes: 9 additions & 1 deletion docs/src/appendix/sncast/account/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ Account name under which account information is going to be saved.
## `--type, -t <ACCOUNT_TYPE>`
Optional. Required if `--class-hash` is passed.

Type of the account. Possible values: oz, argent. Defaults to oz.
Type of the account. Possible values: oz, argent, braavos. Defaults to oz.

Versions of the account contracts:

| Account Contract | Version | Class Hash |
|------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `oz` | v0.14.0 | [0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6](https://starkscan.co/class/0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6) |
| `argent` | v0.3.1 | [0x029927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b](https://starkscan.co/class/0x029927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b) |
| `braavos` | v1.0.0 | [0x00816dd0297efc55dc1e7559020a3a825e81ef734b558f03c83325d4da7e6253](https://starkscan.co/class/0x00816dd0297efc55dc1e7559020a3a825e81ef734b558f03c83325d4da7e6253) |

## `--salt, -s <SALT>`
Optional.
Expand Down
5 changes: 3 additions & 2 deletions docs/src/starknet/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ To remove an account from the accounts file, you can use `sncast account delete
> Accounts creation and deployment is supported for
> - OpenZeppelin
> - Argent (with guardian set to 0)
> - Braavos
## Examples

Expand Down Expand Up @@ -99,15 +100,15 @@ For a detailed CLI description, see [account delete command reference](../append
### Custom Account Contract
By default, `sncast` creates/deploys an account using [openzeppelin contract's class hash](https://starkscan.co/class/0x058d97f7d76e78f44905cc30cb65b91ea49a4b908a76703c54197bca90f81773).
By default, `sncast` creates/deploys an account using [openzeppelin contract's class hash](https://starkscan.co/class/0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6).
It is possible to create an account using custom openzeppelin contract declared to starknet. This can be achieved
with `--class-hash` flag:
```shell
$ sncast \
account create \
--name some-name \
--class-hash 0x058d97f7d76e78f44905cc30cb65b91ea49a4b908a76703c54197bca90f81773
--class-hash 0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6
Account successfully created. Prefund generated address with at least 432300000000 tokens. It is good to send more in the case of higher demand, max_fee * 2 = 864600000000
command: account create
Expand Down

0 comments on commit b73ee0c

Please sign in to comment.