Skip to content

Commit

Permalink
Convert katana/contracts into a Scarb workspace (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy authored Oct 12, 2024
1 parent 61f318d commit 9b47e7c
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/katana/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
.snfoundry_cache/
1 change: 1 addition & 0 deletions crates/katana/contracts/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scarb 2.8.3
1 change: 1 addition & 0 deletions crates/katana/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Contract classes used in Katana
115 changes: 115 additions & 0 deletions crates/katana/contracts/Scarb.lock
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"
14 changes: 14 additions & 0 deletions crates/katana/contracts/Scarb.toml
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"
13 changes: 13 additions & 0 deletions crates/katana/contracts/account/Scarb.toml
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
62 changes: 62 additions & 0 deletions crates/katana/contracts/account/src/lib.cairo
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);
}

#[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);
}
}
}
1 change: 1 addition & 0 deletions crates/katana/contracts/legacy/README.md
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.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion crates/katana/contracts/messaging/cairo/.tool-versions

This file was deleted.

4 changes: 2 additions & 2 deletions crates/katana/contracts/messaging/cairo/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "katana_messaging"
version = "0.1.0"
version.workspace = true

[dependencies]
starknet = "2.3.1"
starknet.workspace = true

[[target.starknet-contract]]
sierra = true
Expand Down
9 changes: 9 additions & 0 deletions crates/katana/contracts/snfoundry.toml
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

0 comments on commit 9b47e7c

Please sign in to comment.