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

Convert katana/contracts into a Scarb workspace #2523

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 11, 2024

from now on, all feature contracts on Katana should define its source code in this workspace. To ensure that all contracts can easily be reproduced.

Summary by CodeRabbit

  • New Features

    • Introduced an upgradeable account module for enhanced account management.
    • Added a new configuration file for StarkNet Foundry framework.
    • Updated workspace configuration for the Katana project, including new dependencies.
  • Documentation

    • Updated README.md to include information on contract classes and legacy contracts.
  • Chores

    • Updated tool versions for improved compatibility.

Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

Ohayo, sensei! The changes in this pull request involve updates across multiple files in the Katana project. Key modifications include updates to the .gitignore to ignore specific directories, changes to the .tool-versions file to specify a new version of scarb, and the introduction of a new workspace configuration in Scarb.toml. Additionally, new content was added to several README files, and a new account module was introduced in lib.cairo. A new configuration file for StarkNet Foundry was also created.

Changes

File Path Change Summary
crates/katana/contracts/.gitignore Added entries: target/ and .snfoundry_cache/ to be ignored by Git.
crates/katana/contracts/.tool-versions Added scarb 2.8.3; deleted scarb 2.5.4 from messaging/cairo.
crates/katana/contracts/README.md Added mention of "Contract classes used in Katana."
crates/katana/contracts/Scarb.toml Introduced workspace config, defined members, and added several dependencies.
crates/katana/contracts/account/src/lib.cairo Introduced an upgradeable account module with components and interfaces.
crates/katana/contracts/legacy/README.md Added note about legacy contracts being non-compilable and for reference only.
crates/katana/contracts/messaging/cairo/Scarb.toml Updated version and dependency declarations to workspace references.
crates/katana/contracts/snfoundry.toml Created new configuration file for StarkNet Foundry settings.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Katana
    participant StarkNet

    User->>Katana: Deploy contract
    Katana->>StarkNet: Interact with StarkNet
    StarkNet-->>Katana: Response
    Katana-->>User: Contract deployed successfully
Loading

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (5)
crates/katana/contracts/account/Scarb.toml (3)

8-10: Dependencies look sharp, sensei!

The use of workspace versions for starknet and openzeppelin is a solid choice for maintaining consistency across the project. These dependencies are appropriate for a StarkNet contract project.

Consider specifying exact versions or version ranges for these dependencies in the workspace configuration. This practice can enhance reproducibility and make it easier to track which versions of these libraries are being used in your project.


12-13: Target configuration is on point, sensei!

The StarkNet contract target is correctly defined, and setting 'sierra' to true is appropriate for the contract's compilation or deployment settings.

Consider exploring additional target configuration options that might be beneficial for your specific use case. For example, you might want to set explicit casm or allowed-libfuncs options depending on your project requirements.


1-13: Ohayo once more, sensei! Overall, this Scarb.toml configuration is well-structured and appropriate.

The file correctly defines the katana_account package, its dependencies, and the target configuration for a StarkNet contract. The use of workspace values promotes consistency across the project.

As you continue to develop the Katana project, consider maintaining a centralized document or README that explains the purpose and structure of this Scarb workspace. This will help new contributors understand how the various packages in the workspace interact and how to add new contracts or dependencies in the future.

crates/katana/contracts/Scarb.toml (1)

4-6: Package info is on point, sensei!

The version and edition choices look solid. Starting with 0.1.0 is perfect for our new workspace. I'm curious about the specific features in the "2023_11" edition that benefit our project.

Consider adding a comment explaining why we chose this specific edition. It'll help future contributors understand our decision-making process.

crates/katana/contracts/account/src/lib.cairo (1)

29-37: Add documentation comments to the Storage struct for clarity.

Ohayo, sensei! Adding documentation to the Storage struct enhances readability and aids future development by explaining the purpose of each substorage component.

Consider adding comments like this:

#[storage]
+/// Storage struct combining account, SRC5, and upgradeable components.
pub struct Storage {
    #[substorage(v0)]
+   /// Storage for account-related data.
    pub account: AccountComponent::Storage,
    #[substorage(v0)]
+   /// Storage for SRC5 interoperability.
    pub src5: SRC5Component::Storage,
    #[substorage(v0)]
+   /// Storage for upgradeability features.
    pub upgradeable: UpgradeableComponent::Storage
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 61f318d and fc2cab2.

⛔ Files ignored due to path filters (1)
  • crates/katana/contracts/Scarb.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • crates/katana/contracts/.gitignore (1 hunks)
  • crates/katana/contracts/.tool-versions (1 hunks)
  • crates/katana/contracts/README.md (1 hunks)
  • crates/katana/contracts/Scarb.toml (1 hunks)
  • crates/katana/contracts/account/Scarb.toml (1 hunks)
  • crates/katana/contracts/account/src/lib.cairo (1 hunks)
  • crates/katana/contracts/legacy/README.md (1 hunks)
  • crates/katana/contracts/messaging/cairo/.tool-versions (0 hunks)
  • crates/katana/contracts/messaging/cairo/Scarb.toml (1 hunks)
  • crates/katana/contracts/snfoundry.toml (1 hunks)
💤 Files with no reviewable changes (1)
  • crates/katana/contracts/messaging/cairo/.tool-versions
✅ Files skipped from review due to trivial changes (5)
  • crates/katana/contracts/.gitignore
  • crates/katana/contracts/.tool-versions
  • crates/katana/contracts/README.md
  • crates/katana/contracts/legacy/README.md
  • crates/katana/contracts/snfoundry.toml
🧰 Additional context used
🔇 Additional comments (5)
crates/katana/contracts/messaging/cairo/Scarb.toml (3)

3-3: Ohayo, sensei! Excellent workspace version declaration!

The change from a fixed version string to version.workspace = true is a great move. This allows for centralized version management across multiple packages in the Scarb workspace, making it easier to maintain consistent versions and update them all at once.


6-6: Dojo-level dependency management, sensei!

Changing the starknet dependency to starknet.workspace = true is a wise decision. This ensures that all packages in the Scarb workspace use the same version of the starknet dependency, promoting consistency and simplifying updates across the project.


3-6: Ohayo once more, sensei! Your Scarb-fu is strong!

The changes in this Scarb.toml file are perfectly aligned with the PR objectives of establishing a Scarb workspace for the katana/contracts directory. By using workspace declarations for both version and dependencies, you're setting up a structure that will make it easier to manage and reproduce all feature contracts within Katana. This is a solid foundation for the new workspace structure. Keep up the excellent work!

crates/katana/contracts/account/Scarb.toml (1)

1-4: Ohayo, sensei! Package configuration looks good!

The package name "katana_account" accurately reflects its purpose within the Katana project. Using workspace values for version and edition ensures consistency across the project, which is a great practice.

crates/katana/contracts/Scarb.toml (1)

1-2: Ohayo, sensei! Workspace configuration looks good!

The workspace setup aligns perfectly with our PR objectives. It's great to see the modular structure with separate members for "account" and "messaging/cairo". This will indeed facilitate the reproducibility of our contracts as intended.

Comment on lines +10 to +14
[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"
Copy link

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:

  • OpenZeppelin: Specified as v0.17.0 but the latest tag is v0.1.0.
  • Starknet Foundry: Specified as v0.31.0 but the latest tag is v0.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:

#!/bin/bash
# Description: Verify the latest versions of our dependencies

# Check starknet version
echo "Latest starknet version:"
cargo search starknet | grep "starknet ="

# Check assert_macros version
echo "Latest assert_macros version:"
cargo search assert_macros | grep "assert_macros ="

# Check latest OpenZeppelin tag
echo "Latest OpenZeppelin tag:"
git ls-remote --tags https://github.com/OpenZeppelin/cairo-contracts.git | sort -V | tail -n 1

# Check latest Starknet Foundry tag
echo "Latest Starknet Foundry tag:"
git ls-remote --tags https://github.com/foundry-rs/starknet-foundry | sort -V | tail -n 1

Length of output: 804

Comment on lines +57 to +60
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.account.assert_only_self();
self.upgradeable.upgrade(new_class_hash);
}
Copy link

Choose a reason for hiding this comment

The 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 UpgradeableEvent after the upgrade operation.

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();
}

Committable suggestion was skipped due to low confidence.

Comment on lines +51 to +53
pub fn constructor(ref self: ContractState, public_key: felt252) {
self.account.initializer(public_key);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure all components are properly initialized in the constructor.

Ohayo, sensei! In the constructor, only the account component is initialized. To ensure all components function correctly, consider initializing the upgradeable and src5 components as well.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn constructor(ref self: ContractState, public_key: felt252) {
self.account.initializer(public_key);
}
pub fn constructor(ref self: ContractState, public_key: felt252) {
self.account.initializer(public_key);
self.upgradeable.initializer();
self.src5.initializer();
}

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.59%. Comparing base (61f318d) to head (fc2cab2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2523   +/-   ##
=======================================
  Coverage   68.59%   68.59%           
=======================================
  Files         387      387           
  Lines       49988    49988           
=======================================
+ Hits        34289    34290    +1     
+ Misses      15699    15698    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kariy kariy merged commit 9b47e7c into main Oct 12, 2024
15 checks passed
@kariy kariy deleted the katana/update-default-account branch October 12, 2024 01:36
@coderabbitai coderabbitai bot mentioned this pull request Oct 23, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant