Skip to content

Commit

Permalink
feat(crates): bump edition
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSacha committed Jan 15, 2025
1 parent 7ae2c7a commit e228144
Show file tree
Hide file tree
Showing 24 changed files with 690 additions and 628 deletions.
6 changes: 3 additions & 3 deletions cairo/crates/contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "contracts"
version = "0.0.6"
edition = "2023_11"
version.workspace = true
edition.workspace = true

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

Expand All @@ -11,11 +11,11 @@ alexandria_bytes.workspace = true
alexandria_math.workspace = true
alexandria_storage.workspace = true
alexandria_data_structures.workspace = true
assert_macros.workspace = true
openzeppelin.workspace = true
mocks = {path = "../mocks"}

[dev-dependencies]
assert_macros.workspace = true
snforge_std.workspace = true

[tool]
Expand Down
68 changes: 38 additions & 30 deletions cairo/crates/contracts/src/client/gas_router_component.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,49 @@ pub trait IGasRouter<TState> {
ref self: TState,
gas_configs: Option<Array<GasRouterConfig>>,
domain: Option<u32>,
gas: Option<u256>
gas: Option<u256>,
);
fn quote_gas_payment(self: @TState, destination_domain: u32) -> u256;
}

/// # Gas Router Component Module
///
/// This module provides a gas management mechanism for routing messages across domains.
/// It allows setting gas limits for specific destinations and quoting gas payments for
/// This module provides a gas management mechanism for routing messages across domains.
/// It allows setting gas limits for specific destinations and quoting gas payments for
/// message dispatches.
///
/// ## Key Concepts
///
/// - **Gas Configuration**: This module allows users to set gas limits for specific destination
/// - **Gas Configuration**: This module allows users to set gas limits for specific destination
/// domains, either individually or through an array of configurations.
///
/// - **Message Dispatching**: Gas management is integrated with the message dispatch system,
/// - **Message Dispatching**: Gas management is integrated with the message dispatch system,
/// enabling the module to quote gas payments for dispatching messages to other domains.
///
/// - **Ownership-based Access Control**: The ability to set gas limits is restricted to the
/// - **Ownership-based Access Control**: The ability to set gas limits is restricted to the
/// contract owner.
///
/// - **Component Composition**: The `GasRouterComponent` integrates with other components such as
/// `RouterComponent` for dispatching messages and `MailboxclientComponent` for mailbox interactions.
/// - **Component Composition**: The `GasRouterComponent` integrates with other components such as
/// `RouterComponent` for dispatching messages and `MailboxclientComponent` for mailbox
/// interactions.
#[starknet::component]
pub mod GasRouterComponent {
use starknet::storage::{StorageMapWriteAccess, StorageMapReadAccess};
use alexandria_bytes::{Bytes, BytesTrait};
use contracts::client::mailboxclient_component::{
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl,
};
use contracts::client::router_component::{
RouterComponent, RouterComponent::RouterComponentInternalImpl, IRouter,
};
use contracts::hooks::libs::standard_hook_metadata::standard_hook_metadata::StandardHookMetadata;
use contracts::interfaces::{IMailboxClient};
use openzeppelin::access::ownable::{
OwnableComponent, OwnableComponent::InternalImpl as OwnableInternalImpl
OwnableComponent, OwnableComponent::InternalImpl as OwnableInternalImpl,
};
use starknet::ContractAddress;
use starknet::storage::{Map};


#[derive(Copy, Drop, Serde)]
pub struct GasRouterConfig {
Expand All @@ -53,8 +57,8 @@ pub mod GasRouterComponent {
}

#[storage]
struct Storage {
destination_gas: LegacyMap<u32, u256>,
pub struct Storage {
destination_gas: Map<u32, u256>,
}

#[embeddable_as(GasRouterImpl)]
Expand All @@ -68,15 +72,18 @@ pub mod GasRouterComponent {
> of super::IGasRouter<ComponentState<TContractState>> {
/// Sets the gas limit for a specified domain or applies an array of gas configurations.
///
/// This function allows the contract owner to configure gas limits for one or multiple domains.
/// If an array of `GasRouterConfig` is provided via `gas_configs`, the function iterates over
/// the array and applies each configuration. If a specific `domain` and `gas` are provided,
/// the function sets the gas limit for that domain.
/// This function allows the contract owner to configure gas limits for one or multiple
/// domains.
/// If an array of `GasRouterConfig` is provided via `gas_configs`, the function iterates
/// over the array and applies each configuration. If a specific `domain` and `gas` are
/// provided, the function sets the gas limit for that domain.
///
/// # Arguments
///
/// * `gas_configs` - An optional array of `GasRouterConfig`, each containing a `domain` and a `gas` value.
/// * `domain` - An optional `u32` representing the domain for which the gas limit is being set.
/// * `gas_configs` - An optional array of `GasRouterConfig`, each containing a `domain` and
/// a `gas` value.
/// * `domain` - An optional `u32` representing the domain for which the gas limit is being
/// set.
/// * `gas` - An optional `u256` representing the gas limit for the given domain.
///
/// # Panics
Expand All @@ -86,7 +93,7 @@ pub mod GasRouterComponent {
ref self: ComponentState<TContractState>,
gas_configs: Option<Array<GasRouterConfig>>,
domain: Option<u32>,
gas: Option<u256>
gas: Option<u256>,
) {
let owner_comp = get_dep_component!(@self, Owner);
owner_comp.assert_only_owner();
Expand All @@ -105,11 +112,11 @@ pub mod GasRouterComponent {
Option::None => {
match (domain, gas) {
(
Option::Some(domain), Option::Some(gas)
Option::Some(domain), Option::Some(gas),
) => { self._set_destination_gas(domain, gas); },
_ => { panic!("Set destination gas: Invalid arguments"); }
_ => { panic!("Set destination gas: Invalid arguments"); },
}
}
},
}
}

Expand All @@ -121,13 +128,14 @@ pub mod GasRouterComponent {
///
/// # Arguments
///
/// * `destination_domain` - A `u32` representing the domain to which the message is being sent.
/// * `destination_domain` - A `u32` representing the domain to which the message is being
/// sent.
///
/// # Returns
///
/// A `u256` value representing the quoted gas payment.
fn quote_gas_payment(
self: @ComponentState<TContractState>, destination_domain: u32
self: @ComponentState<TContractState>, destination_domain: u32,
) -> u256 {
let mailbox_comp = get_dep_component!(self, MailBoxClient);
let hook = mailbox_comp.get_hook();
Expand All @@ -141,10 +149,10 @@ pub mod GasRouterComponent {
+HasComponent<TContractState>,
impl MailBoxClient: MailboxclientComponent::HasComponent<TContractState>,
impl Router: RouterComponent::HasComponent<TContractState>,
+Drop<TContractState>
+Drop<TContractState>,
> of InternalTrait<TContractState> {
fn _Gas_router_hook_metadata(
self: @ComponentState<TContractState>, destination: u32
self: @ComponentState<TContractState>, destination: u32,
) -> Bytes {
StandardHookMetadata::override_gas_limits(self.destination_gas.read(destination))
}
Expand All @@ -158,7 +166,7 @@ pub mod GasRouterComponent {
destination: u32,
value: u256,
message_body: Bytes,
hook: ContractAddress
hook: ContractAddress,
) -> u256 {
let mut router_comp = get_dep_component_mut!(ref self, Router);
router_comp
Expand All @@ -167,20 +175,20 @@ pub mod GasRouterComponent {
value,
message_body,
self._Gas_router_hook_metadata(destination),
hook
hook,
)
}

fn _Gas_router_quote_dispatch(
self: @ComponentState<TContractState>,
destination: u32,
message_body: Bytes,
hook: ContractAddress
hook: ContractAddress,
) -> u256 {
let mut router_comp = get_dep_component!(self, Router);
router_comp
._Router_quote_dispatch(
destination, message_body, self._Gas_router_hook_metadata(destination), hook
destination, message_body, self._Gas_router_hook_metadata(destination), hook,
)
}
}
Expand Down
14 changes: 9 additions & 5 deletions cairo/crates/contracts/src/client/mailboxclient.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#[starknet::contract]
mod mailboxClientProxy {
use contracts::client::mailboxclient_component::{
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl,
};
use openzeppelin::access::ownable::ownable::OwnableComponent::InternalTrait;
use openzeppelin::access::ownable::{OwnableComponent,};
use openzeppelin::access::ownable::{OwnableComponent};
use openzeppelin::upgrades::{interface::IUpgradeable, upgradeable::UpgradeableComponent};
use starknet::{ContractAddress, ClassHash};
use starknet::storage::{
StorageMapWriteAccess, StorageMapReadAccess, StoragePointerWriteAccess,
StoragePointerReadAccess,
};
component!(path: MailboxclientComponent, storage: mailboxclient, event: MailboxclientEvent);
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);
Expand All @@ -27,7 +31,7 @@ mod mailboxClientProxy {
#[substorage(v0)]
upgradeable: UpgradeableComponent::Storage,
#[substorage(v0)]
mailboxclient: MailboxclientComponent::Storage,
pub mailboxclient: MailboxclientComponent::Storage,
}

#[constructor]
Expand All @@ -36,7 +40,7 @@ mod mailboxClientProxy {
_mailbox: ContractAddress,
_owner: ContractAddress,
_hook: ContractAddress,
_interchain_security_module: ContractAddress
_interchain_security_module: ContractAddress,
) {
self.ownable.initializer(_owner);
self
Expand All @@ -58,7 +62,7 @@ mod mailboxClientProxy {
impl Upgradeable of IUpgradeable<ContractState> {
/// Upgrades the contract to a new implementation.
/// Callable only by the owner
///
///
/// # Arguments
///
/// * `new_class_hash` - The class hash of the new implementation.
Expand Down
Loading

0 comments on commit e228144

Please sign in to comment.