diff --git a/crates/katana/contracts/.gitignore b/crates/katana/contracts/.gitignore new file mode 100644 index 0000000000..04af505f16 --- /dev/null +++ b/crates/katana/contracts/.gitignore @@ -0,0 +1,2 @@ +target/ +.snfoundry_cache/ diff --git a/crates/katana/contracts/.tool-versions b/crates/katana/contracts/.tool-versions new file mode 100644 index 0000000000..2060b90785 --- /dev/null +++ b/crates/katana/contracts/.tool-versions @@ -0,0 +1 @@ +scarb 2.8.3 diff --git a/crates/katana/contracts/README.md b/crates/katana/contracts/README.md new file mode 100644 index 0000000000..e861a8d551 --- /dev/null +++ b/crates/katana/contracts/README.md @@ -0,0 +1 @@ +Contract classes used in Katana diff --git a/crates/katana/contracts/Scarb.lock b/crates/katana/contracts/Scarb.lock new file mode 100644 index 0000000000..ccff40fa32 --- /dev/null +++ b/crates/katana/contracts/Scarb.lock @@ -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" diff --git a/crates/katana/contracts/Scarb.toml b/crates/katana/contracts/Scarb.toml new file mode 100644 index 0000000000..e90bdfe502 --- /dev/null +++ b/crates/katana/contracts/Scarb.toml @@ -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" diff --git a/crates/katana/contracts/account/Scarb.toml b/crates/katana/contracts/account/Scarb.toml new file mode 100644 index 0000000000..a18acec7c9 --- /dev/null +++ b/crates/katana/contracts/account/Scarb.toml @@ -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 diff --git a/crates/katana/contracts/account/src/lib.cairo b/crates/katana/contracts/account/src/lib.cairo new file mode 100644 index 0000000000..9e0ef9d549 --- /dev/null +++ b/crates/katana/contracts/account/src/lib.cairo @@ -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; + impl AccountInternalImpl = AccountComponent::InternalImpl; + + // Upgradeable + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl; + + #[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 { + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { + self.account.assert_only_self(); + self.upgradeable.upgrade(new_class_hash); + } + } +} diff --git a/crates/katana/contracts/legacy/README.md b/crates/katana/contracts/legacy/README.md new file mode 100644 index 0000000000..7156f71971 --- /dev/null +++ b/crates/katana/contracts/legacy/README.md @@ -0,0 +1 @@ +Legacy (Cairo 0) contracts. Not compilable as they are mainly used as references. diff --git a/crates/katana/contracts/account_with_dummy_validate.cairo b/crates/katana/contracts/legacy/account_with_dummy_validate.cairo similarity index 100% rename from crates/katana/contracts/account_with_dummy_validate.cairo rename to crates/katana/contracts/legacy/account_with_dummy_validate.cairo diff --git a/crates/katana/contracts/erc20.cairo b/crates/katana/contracts/legacy/erc20.cairo similarity index 100% rename from crates/katana/contracts/erc20.cairo rename to crates/katana/contracts/legacy/erc20.cairo diff --git a/crates/katana/contracts/test_contract.cairo b/crates/katana/contracts/legacy/test_contract.cairo similarity index 100% rename from crates/katana/contracts/test_contract.cairo rename to crates/katana/contracts/legacy/test_contract.cairo diff --git a/crates/katana/contracts/universal_deployer.cairo b/crates/katana/contracts/legacy/universal_deployer.cairo similarity index 100% rename from crates/katana/contracts/universal_deployer.cairo rename to crates/katana/contracts/legacy/universal_deployer.cairo diff --git a/crates/katana/contracts/messaging/cairo/.tool-versions b/crates/katana/contracts/messaging/cairo/.tool-versions deleted file mode 100644 index 49edbb5364..0000000000 --- a/crates/katana/contracts/messaging/cairo/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -scarb 2.5.4 diff --git a/crates/katana/contracts/messaging/cairo/Scarb.toml b/crates/katana/contracts/messaging/cairo/Scarb.toml index d339966bb7..0a698c11ea 100644 --- a/crates/katana/contracts/messaging/cairo/Scarb.toml +++ b/crates/katana/contracts/messaging/cairo/Scarb.toml @@ -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 diff --git a/crates/katana/contracts/snfoundry.toml b/crates/katana/contracts/snfoundry.toml new file mode 100644 index 0000000000..7d45ecda85 --- /dev/null +++ b/crates/katana/contracts/snfoundry.toml @@ -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