-
Notifications
You must be signed in to change notification settings - Fork 194
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
Convert katana/contracts
into a Scarb workspace
#2523
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
.snfoundry_cache/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scarb 2.8.3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Contract classes used in Katana |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "katana_account" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"openzeppelin", | ||
] | ||
|
||
[[package]] | ||
name = "katana_messaging" | ||
version = "0.1.0" | ||
|
||
[[package]] | ||
name = "openzeppelin" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
dependencies = [ | ||
"openzeppelin_access", | ||
"openzeppelin_account", | ||
"openzeppelin_finance", | ||
"openzeppelin_governance", | ||
"openzeppelin_introspection", | ||
"openzeppelin_merkle_tree", | ||
"openzeppelin_presets", | ||
"openzeppelin_security", | ||
"openzeppelin_token", | ||
"openzeppelin_upgrades", | ||
"openzeppelin_utils", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_access" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
dependencies = [ | ||
"openzeppelin_introspection", | ||
"openzeppelin_utils", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_account" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
dependencies = [ | ||
"openzeppelin_introspection", | ||
"openzeppelin_utils", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_finance" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
dependencies = [ | ||
"openzeppelin_access", | ||
"openzeppelin_token", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_governance" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
dependencies = [ | ||
"openzeppelin_access", | ||
"openzeppelin_introspection", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_introspection" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
|
||
[[package]] | ||
name = "openzeppelin_merkle_tree" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
|
||
[[package]] | ||
name = "openzeppelin_presets" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
dependencies = [ | ||
"openzeppelin_access", | ||
"openzeppelin_account", | ||
"openzeppelin_finance", | ||
"openzeppelin_introspection", | ||
"openzeppelin_token", | ||
"openzeppelin_upgrades", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_security" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
|
||
[[package]] | ||
name = "openzeppelin_token" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
dependencies = [ | ||
"openzeppelin_account", | ||
"openzeppelin_governance", | ||
"openzeppelin_introspection", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin_upgrades" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" | ||
|
||
[[package]] | ||
name = "openzeppelin_utils" | ||
version = "0.17.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[workspace] | ||
members = [ "account", "messaging/cairo" ] | ||
|
||
[workspace.package] | ||
version = "0.1.0" | ||
edition = "2023_11" | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
|
||
[workspace.dependencies] | ||
starknet = "2.8.2" | ||
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.17.0" } | ||
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.31.0" } | ||
assert_macros = "2.8.2" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "katana_account" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
|
||
[dependencies] | ||
starknet.workspace = true | ||
openzeppelin.workspace = true | ||
|
||
[[target.starknet-contract]] | ||
sierra = true |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||||||||||||||
// SPDX-License-Identifier: MIT | ||||||||||||||||||
// OpenZeppelin Contracts for Cairo v0.17.0 (presets/account.cairo) | ||||||||||||||||||
|
||||||||||||||||||
/// # Account Preset | ||||||||||||||||||
/// | ||||||||||||||||||
/// OpenZeppelin's upgradeable account which can change its public key and declare, deploy, or call | ||||||||||||||||||
/// contracts. | ||||||||||||||||||
#[starknet::contract(account)] | ||||||||||||||||||
pub mod Account { | ||||||||||||||||||
use openzeppelin_account::AccountComponent; | ||||||||||||||||||
use openzeppelin_introspection::src5::SRC5Component; | ||||||||||||||||||
use openzeppelin_upgrades::UpgradeableComponent; | ||||||||||||||||||
use openzeppelin_upgrades::interface::IUpgradeable; | ||||||||||||||||||
use starknet::ClassHash; | ||||||||||||||||||
|
||||||||||||||||||
component!(path: AccountComponent, storage: account, event: AccountEvent); | ||||||||||||||||||
component!(path: SRC5Component, storage: src5, event: SRC5Event); | ||||||||||||||||||
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); | ||||||||||||||||||
|
||||||||||||||||||
// Account Mixin | ||||||||||||||||||
#[abi(embed_v0)] | ||||||||||||||||||
pub(crate) impl AccountMixinImpl = | ||||||||||||||||||
AccountComponent::AccountMixinImpl<ContractState>; | ||||||||||||||||||
impl AccountInternalImpl = AccountComponent::InternalImpl<ContractState>; | ||||||||||||||||||
|
||||||||||||||||||
// Upgradeable | ||||||||||||||||||
impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl<ContractState>; | ||||||||||||||||||
|
||||||||||||||||||
#[storage] | ||||||||||||||||||
pub struct Storage { | ||||||||||||||||||
#[substorage(v0)] | ||||||||||||||||||
pub account: AccountComponent::Storage, | ||||||||||||||||||
#[substorage(v0)] | ||||||||||||||||||
pub src5: SRC5Component::Storage, | ||||||||||||||||||
#[substorage(v0)] | ||||||||||||||||||
pub upgradeable: UpgradeableComponent::Storage | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
#[event] | ||||||||||||||||||
#[derive(Drop, starknet::Event)] | ||||||||||||||||||
enum Event { | ||||||||||||||||||
#[flat] | ||||||||||||||||||
AccountEvent: AccountComponent::Event, | ||||||||||||||||||
#[flat] | ||||||||||||||||||
SRC5Event: SRC5Component::Event, | ||||||||||||||||||
#[flat] | ||||||||||||||||||
UpgradeableEvent: UpgradeableComponent::Event | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
#[constructor] | ||||||||||||||||||
pub fn constructor(ref self: ContractState, public_key: felt252) { | ||||||||||||||||||
self.account.initializer(public_key); | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure all components are properly initialized in the constructor. Ohayo, sensei! In the Apply this diff to initialize all components: pub fn constructor(ref self: ContractState, public_key: felt252) {
self.account.initializer(public_key);
+ self.upgradeable.initializer();
+ self.src5.initializer();
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
#[abi(embed_v0)] | ||||||||||||||||||
impl UpgradeableImpl of IUpgradeable<ContractState> { | ||||||||||||||||||
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { | ||||||||||||||||||
self.account.assert_only_self(); | ||||||||||||||||||
self.upgradeable.upgrade(new_class_hash); | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+57
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider emitting an event upon upgrading the contract. Ohayo, sensei! Emitting an event when the contract is upgraded improves transparency and allows off-chain services to track upgrades. Consider emitting the Apply this diff to emit the event: fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.account.assert_only_self();
self.upgradeable.upgrade(new_class_hash);
+ UpgradeableEvent::Upgraded { new_class_hash }.emit();
}
|
||||||||||||||||||
} | ||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Legacy (Cairo 0) contracts. Not compilable as they are mainly used as references. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Visit https://foundry-rs.github.io/starknet-foundry/appendix/snfoundry-toml.html for more information | ||
|
||
# [sncast.myprofile1] # Define a profile name | ||
# url = "http://127.0.0.1:5050/" # Url of the RPC provider | ||
# accounts_file = "../account-file" # Path to the file with the account data | ||
# account = "mainuser" # Account from `accounts_file` or default account file that will be used for the transactions | ||
# keystore = "~/keystore" # Path to the keystore file | ||
# wait_params = { timeout = 500, retry_interval = 10 } # Wait for submitted transaction parameters | ||
# block_explorer = "StarkScan" # Block explorer service used to display links to transaction details |
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.
💡 Codebase verification
Ohayo again, sensei!
I've spotted some version discrepancies in our dependencies:
v0.17.0
but the latest tag isv0.1.0
.v0.31.0
but the latest tag isv0.20.1
.These mismatches suggest that the versions in
Scarb.toml
might be incorrect or ahead of the repository's actual releases. Please verify the intended versions to ensure compatibility and stability.🔗 Analysis chain
Ohayo again, sensei! Dependencies are looking sharp!
The choice of dependencies is spot-on for our Starknet project. I appreciate the use of specific versions and tags - it's crucial for reproducibility.
Let's double-check if we're using the latest stable versions:
This script will help us ensure we're using the most up-to-date versions. If any discrepancies are found, we might want to consider updating.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 804