Skip to content

Commit

Permalink
refacto into crates
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Sep 14, 2024
1 parent 66231c0 commit 99cc684
Show file tree
Hide file tree
Showing 88 changed files with 471 additions and 327 deletions.
25 changes: 20 additions & 5 deletions cairo/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,23 @@ version = "0.3.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=bcdca70#bcdca70afdf59c9976148e95cebad5cf63d75a7f"

[[package]]
name = "hyperlane_starknet"
name = "contracts"
version = "0.0.6"
dependencies = [
"alexandria_bytes",
"alexandria_storage",
"openzeppelin",
"snforge_std",
]

[[package]]
name = "mocks"
version = "0.0.6"
dependencies = [
"alexandria_bytes",
"alexandria_storage",
"contracts",
"openzeppelin",
"token",
]

[[package]]
Expand All @@ -74,6 +84,11 @@ version = "0.14.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.14.0#f091c4f51ddeb10297db984acae965328c5a4e5b"

[[package]]
name = "snforge_std"
version = "0.22.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.22.0#9b215944c6c5871c738381b4ded61bbf06e7ba35"
name = "token"
version = "0.0.1"
dependencies = [
"alexandria_bytes",
"alexandria_storage",
"contracts",
"openzeppelin",
]
17 changes: 9 additions & 8 deletions cairo/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
[package]
[workspace]
members = ["crates/*"]

[workspace.package]
name = "hyperlane_starknet"
description = "Implementation of the Hyperlane protocol on Starknet."
version = "0.0.6"
edition = "2023_11"
cairo-version = "2.6.3"
license-file = "../LICENSE"
readme = "../README.md"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
[workspace.dependencies]
starknet = "2.6.3"
alexandria_bytes = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "bcdca70" }
alexandria_storage = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "bcdca70" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.14.0" }


[dev-dependencies]
[workspace.dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.22.0" }

[tool.fmt]
[workspace.tool.fmt]
sort-module-level-items = true

[[target.starknet-contract]]
# Enable Sierra codegen.
sierra = true

# Enable CASM codegen.
casm = true
# Emit Python-powered hints in order to run compiled CASM class with legacy Cairo VM.
Expand Down
23 changes: 23 additions & 0 deletions cairo/crates/contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "contracts"
version = "0.0.6"
edition = "2023_11"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet.workspace = true
alexandria_bytes.workspace = true
alexandria_storage.workspace = true
openzeppelin.workspace = true


[tool]
fmt.workspace = true

[[target.starknet-contract]]
casm = true
casm-add-pythonic-hints = true

[lib]
name = "contracts"
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ pub trait IGasRouter<TState> {
#[starknet::component]
pub mod GasRouterComponent {
use alexandria_bytes::{Bytes, BytesTrait};
use hyperlane_starknet::contracts::client::mailboxclient_component::{
use contracts::client::mailboxclient_component::{
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl
};
use hyperlane_starknet::contracts::client::router_component::{
use contracts::client::router_component::{
RouterComponent, RouterComponent::RouterComponentInternalImpl, IRouter,
};
use hyperlane_starknet::contracts::hooks::libs::standard_hook_metadata::standard_hook_metadata::StandardHookMetadata;
use hyperlane_starknet::interfaces::{IMailboxClient};
use contracts::hooks::libs::standard_hook_metadata::standard_hook_metadata::StandardHookMetadata;
use contracts::interfaces::{IMailboxClient};
use openzeppelin::access::ownable::{
OwnableComponent, OwnableComponent::InternalImpl as OwnableInternalImpl
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[starknet::contract]
mod mailboxClientProxy {
use hyperlane_starknet::contracts::client::mailboxclient_component::{
use contracts::client::mailboxclient_component::{
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl
};
use openzeppelin::access::ownable::ownable::OwnableComponent::InternalTrait;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#[starknet::component]
pub mod MailboxclientComponent {
use alexandria_bytes::Bytes;
use hyperlane_starknet::interfaces::{
IMailboxClient, IMailboxDispatcher, IMailboxDispatcherTrait
};
use contracts::interfaces::{IMailboxClient, IMailboxDispatcher, IMailboxDispatcherTrait};
use openzeppelin::access::ownable::{
OwnableComponent, OwnableComponent::InternalImpl, OwnableComponent::OwnableImpl
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ pub trait IRouter<TState> {
#[starknet::component]
pub mod RouterComponent {
use alexandria_bytes::Bytes;
use hyperlane_starknet::contracts::client::mailboxclient_component::{
use contracts::client::mailboxclient_component::{
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl
};
use hyperlane_starknet::contracts::libs::enumerable_map::{EnumerableMap, EnumerableMapTrait};
use hyperlane_starknet::interfaces::{
IMailboxClient, IMailboxDispatcher, IMailboxDispatcherTrait
};
use contracts::interfaces::{IMailboxClient, IMailboxDispatcher, IMailboxDispatcherTrait};
use contracts::libs::enumerable_map::{EnumerableMap, EnumerableMapTrait};
use openzeppelin::access::ownable::{
OwnableComponent, OwnableComponent::InternalImpl as OwnableInternalImpl
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
pub mod merkle_tree_hook {
use alexandria_bytes::{Bytes, BytesTrait};
use alexandria_math::pow;
use hyperlane_starknet::contracts::client::mailboxclient_component::{
use contracts::client::mailboxclient_component::{
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl,
MailboxclientComponent::MailboxClientImpl
};
use hyperlane_starknet::contracts::hooks::libs::standard_hook_metadata::standard_hook_metadata::{
use contracts::hooks::libs::standard_hook_metadata::standard_hook_metadata::{
StandardHookMetadata, VARIANT
};
use hyperlane_starknet::contracts::libs::message::{Message, MessageTrait};
use hyperlane_starknet::interfaces::{
use contracts::interfaces::{
IMailboxClientDispatcher, IMailboxClientDispatcherTrait, Types, IMerkleTreeHook,
IPostDispatchHook, IMailboxClient, IMailboxDispatcher, IMailboxDispatcherTrait,
};
use hyperlane_starknet::utils::keccak256::{
reverse_endianness, compute_keccak, ByteData, HASH_SIZE
};
use contracts::libs::message::{Message, MessageTrait};
use contracts::utils::keccak256::{reverse_endianness, compute_keccak, ByteData, HASH_SIZE};
use openzeppelin::access::ownable::OwnableComponent;
use starknet::{ContractAddress, ClassHash};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[starknet::contract]
pub mod protocol_fee {
use alexandria_bytes::{Bytes, BytesTrait};
use hyperlane_starknet::contracts::hooks::libs::standard_hook_metadata::standard_hook_metadata::{
use contracts::hooks::libs::standard_hook_metadata::standard_hook_metadata::{
StandardHookMetadata, VARIANT,
};
use hyperlane_starknet::contracts::libs::message::Message;
use hyperlane_starknet::interfaces::{IPostDispatchHook, Types, IProtocolFee, ETH_ADDRESS};
use contracts::interfaces::{IPostDispatchHook, Types, IProtocolFee, ETH_ADDRESS};
use contracts::libs::message::Message;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::token::erc20::interface::{
ERC20ABI, ERC20ABIDispatcher, ERC20ABIDispatcherTrait
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alexandria_bytes::Bytes;
use contracts::hooks::merkle_tree_hook::merkle_tree_hook::Tree;
use contracts::libs::message::Message;
use core::array::ArrayTrait;
use hyperlane_starknet::contracts::hooks::merkle_tree_hook::merkle_tree_hook::Tree;
use hyperlane_starknet::contracts::libs::message::Message;
use starknet::ContractAddress;
use starknet::EthAddress;

Expand Down
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions cairo/crates/contracts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pub mod interfaces;
pub mod mailbox;
pub mod libs {
pub mod aggregation_ism_metadata;
pub mod checkpoint_lib;
pub mod enumerable_map;
pub mod math;
pub mod message;
pub mod multisig {
pub mod merkleroot_ism_metadata;
pub mod message_id_ism_metadata;
}
}
pub mod hooks {
pub mod merkle_tree_hook;
pub mod protocol_fee;
pub mod libs {
pub mod standard_hook_metadata;
}
}
pub mod client {
pub mod gas_router_component;
pub mod mailboxclient;
pub mod mailboxclient_component;
pub mod router_component;
}
pub mod utils {
pub mod keccak256;
pub mod store_arrays;
pub mod utils;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod checkpoint_lib {
use alexandria_bytes::{Bytes, BytesTrait, BytesStore};
use hyperlane_starknet::contracts::libs::message::Message;
use hyperlane_starknet::utils::keccak256::{
use contracts::libs::message::Message;
use contracts::utils::keccak256::{
reverse_endianness, compute_keccak, ByteData, u64_word_size, u256_word_size, HASH_SIZE,
to_eth_signature
};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alexandria_bytes::{Bytes, BytesTrait, BytesStore};
use alexandria_math::BitShift;
use hyperlane_starknet::utils::keccak256::{
use contracts::utils::keccak256::{
reverse_endianness, compute_keccak, ByteData, u256_word_size, u64_word_size, ADDRESS_SIZE,
u128_mask,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#[starknet::contract]
pub mod mailbox {
use alexandria_bytes::{Bytes, BytesTrait};
use core::starknet::event::EventEmitter;
use hyperlane_starknet::contracts::libs::message::{Message, MessageTrait, HYPERLANE_VERSION};
use hyperlane_starknet::interfaces::{
use contracts::interfaces::{
IMailbox, IMailboxDispatcher, IMailboxDispatcherTrait, IInterchainSecurityModuleDispatcher,
IInterchainSecurityModuleDispatcherTrait, IPostDispatchHookDispatcher,
ISpecifiesInterchainSecurityModuleDispatcher,
ISpecifiesInterchainSecurityModuleDispatcherTrait, IPostDispatchHookDispatcherTrait,
IMessageRecipientDispatcher, IMessageRecipientDispatcherTrait, ETH_ADDRESS,
};
use hyperlane_starknet::utils::utils::U256TryIntoContractAddress;
use contracts::libs::message::{Message, MessageTrait, HYPERLANE_VERSION};
use contracts::utils::utils::U256TryIntoContractAddress;
use core::starknet::event::EventEmitter;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::token::erc20::interface::{
ERC20ABI, ERC20ABIDispatcher, ERC20ABIDispatcherTrait
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use alexandria_math::BitShift;
use contracts::libs::checkpoint_lib::checkpoint_lib::HYPERLANE_ANNOUNCEMENT;
use core::byte_array::{ByteArray, ByteArrayTrait};
use core::integer::u128_byte_reverse;
use core::keccak::cairo_keccak;
use core::starknet::SyscallResultTrait;
use core::to_byte_array::{FormatAsByteArray, AppendFormattedToByteArray};
use hyperlane_starknet::contracts::libs::checkpoint_lib::checkpoint_lib::HYPERLANE_ANNOUNCEMENT;
use starknet::{EthAddress, eth_signature::is_eth_signature_valid, secp256_trait::Signature};

pub const ETH_SIGNED_MESSAGE: felt252 = '\x19Ethereum Signed Message:\n32';
Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions cairo/crates/mocks/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "mocks"
version.workspace = true
edition.workspace = true
cairo-version.workspace = true

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet.workspace = true
alexandria_bytes.workspace = true
alexandria_storage.workspace = true
openzeppelin.workspace = true
contracts = { path = "../contracts" }
token = { path = "../token" }



[tool]
fmt.workspace = true

[[target.starknet-contract]]
casm = true

[lib]
name = "mocks"
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait IEnumerableMapHolder<TContractState> {

#[starknet::contract]
pub mod EnumerableMapHolder {
use hyperlane_starknet::contracts::libs::enumerable_map::{EnumerableMap, EnumerableMapTrait};
use contracts::libs::enumerable_map::{EnumerableMap, EnumerableMapTrait};

#[storage]
struct Storage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use starknet::ContractAddress;
#[starknet::component]
pub mod ERC4626Component {
use core::integer::BoundedInt;

use hyperlane_starknet::contracts::token::interfaces::ierc4626::{
IERC4626, IERC4626Camel, IERC4626Metadata
};
use openzeppelin::introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait};
use openzeppelin::introspection::src5::{
SRC5Component, SRC5Component::SRC5Impl, SRC5Component::InternalTrait as SRC5INternalTrait
Expand All @@ -21,6 +17,8 @@ pub mod ERC4626Component {
};
use starknet::{ContractAddress, get_caller_address, get_contract_address};

use token::interfaces::ierc4626::{IERC4626, IERC4626Camel, IERC4626Metadata};

#[storage]
struct Storage {
ERC4626_asset: ContractAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#[starknet::contract]
mod ERC4626Mock {
use hyperlane_starknet::contracts::mocks::erc4626_component::{
ERC4626Component, ERC4626HooksEmptyImpl
};
use mocks::erc4626_component::{ERC4626Component, ERC4626HooksEmptyImpl};
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc20::ERC20Component;
use openzeppelin::token::erc20::interface::{IERC20, IERC20Dispatcher, IERC20DispatcherTrait};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ trait IERC4626YieldSharing<TContractState> {

#[starknet::contract]
mod ERC4626YieldSharingMock {
use contracts::libs::math;
use core::integer::BoundedInt;
use hyperlane_starknet::contracts::libs::math;
use hyperlane_starknet::contracts::mocks::erc4626_component::{
ERC4626Component, ERC4626HooksEmptyImpl
};
use hyperlane_starknet::contracts::token::interfaces::ierc4626::IERC4626;
use mocks::erc4626_component::{ERC4626Component, ERC4626HooksEmptyImpl};
use openzeppelin::access::ownable::{OwnableComponent};
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc20::ERC20Component;
use openzeppelin::token::erc20::interface::{IERC20, IERC20Dispatcher, IERC20DispatcherTrait};
use starknet::{get_contract_address, get_caller_address, ContractAddress};
use token::interfaces::ierc4626::IERC4626;

component!(path: ERC4626Component, storage: erc4626, event: ERC4626Event);
component!(path: ERC20Component, storage: erc20, event: ERC20Event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#[starknet::contract]
pub mod fee_hook {
use alexandria_bytes::{Bytes, BytesTrait, BytesStore};
use hyperlane_starknet::contracts::libs::message::Message;
use hyperlane_starknet::interfaces::{
use contracts::interfaces::{
IPostDispatchHook, IPostDispatchHookDispatcher, IPostDispatchHookDispatcherTrait, Types
};
use contracts::libs::message::Message;
use starknet::ContractAddress;

#[storage]
Expand Down
File renamed without changes.
Loading

0 comments on commit 99cc684

Please sign in to comment.