Skip to content

refactor: encapsulate agglayer faucet and bridge in structs#2379

Closed
Farukest wants to merge 4 commits into0xMiden:nextfrom
Farukest:feat/issue-2371-agglayer-structs
Closed

refactor: encapsulate agglayer faucet and bridge in structs#2379
Farukest wants to merge 4 commits into0xMiden:nextfrom
Farukest:feat/issue-2371-agglayer-structs

Conversation

@Farukest
Copy link
Contributor

Summary

  • Add AggLayerFaucet struct with new() constructor and From<AggLayerFaucet> for AccountComponent
  • Add AggLayerBridge struct with new() constructor and From<AggLayerBridge> for AccountComponent
  • Define storage slot names as static LazyLock constants
  • Update create_agglayer_faucet_component and create_bridge_account_component to use new structs

Context

This follows the pattern established by NetworkFungibleFaucet in PR #2335, improving code maintainability by encapsulating configuration in dedicated types with trait-based conversion.

Test plan

  • cargo +nightly fmt passes
  • cargo clippy -p miden-agglayer passes
  • cargo test -p miden-agglayer passes

Closes #2371

Add `AggLayerFaucet` and `AggLayerBridge` structs with `new()`
constructors and `From<T> for AccountComponent` trait implementations.
This follows the pattern established by `NetworkFungibleFaucet` and
improves code maintainability by:

- Encapsulating configuration in dedicated types
- Using trait-based conversion instead of manual storage slot creation
- Providing accessor methods for struct fields
- Defining storage slot names as static constants

The existing `create_agglayer_faucet_component` and
`create_bridge_account_component` functions now delegate to these
new types.

Closes 0xMiden#2371
@Farukest Farukest force-pushed the feat/issue-2371-agglayer-structs branch from 4ff25f3 to af9371e Compare January 31, 2026 20:02
Resolve merge conflict in lib.rs:
- Keep struct-based implementation (AggLayerFaucet) over inline logic
- This aligns with PR goal of encapsulating agglayer components in structs
Comment on lines 135 to 145
impl From<AggLayerFaucet> for AccountComponent {
fn from(faucet: AggLayerFaucet) -> Self {
// Create network faucet metadata slot: [max_supply, decimals, token_symbol, 0]
let metadata_word = Word::new([
faucet.max_supply,
Felt::from(faucet.decimals),
faucet.token_symbol.into(),
FieldElement::ZERO,
]);
let metadata_slot =
StorageSlot::with_value(NetworkFungibleFaucet::metadata_slot().clone(), metadata_word);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's update this once #2380 is merged.

/// # Panics
/// Panics if the token symbol is invalid or storage slot names are malformed.
/// Panics if the token symbol is invalid.
pub fn create_agglayer_faucet_component(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to replace this function with calls to AggLayerFaucet::new directly?

Copy link
Contributor Author

@Farukest Farukest Feb 4, 2026

Choose a reason for hiding this comment

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

Done @PhilippGackstatter 👍
removed create_agglayer_faucet_component and now using AggLayerFaucet::new directly in create_agglayer_faucet_builder

Comment on lines 204 to 209
impl From<AggLayerBridge> for AccountComponent {
fn from(_bridge: AggLayerBridge) -> Self {
let bridge_storage_slots =
vec![StorageSlot::with_empty_map(AggLayerBridge::bridge_slot().clone())];

bridge_out_component(bridge_storage_slots)
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make sense to get rid of bridge_out_component and inline that logic here, but cc @mmagician for double checking.

@Farukest
Copy link
Contributor Author

Farukest commented Feb 4, 2026

All done @PhilippGackstatter need review. let me know if I miss something else. thanks

@Farukest Farukest force-pushed the feat/issue-2371-agglayer-structs branch from ce95977 to 49541ba Compare February 5, 2026 04:27
- Remove create_agglayer_faucet_component helper, use AggLayerFaucet::new directly
- Inline bridge_out_component logic in From<AggLayerBridge> impl
@Farukest Farukest force-pushed the feat/issue-2371-agglayer-structs branch from 49541ba to ff354f0 Compare February 5, 2026 04:57
Copy link
Contributor

@partylikeits1983 partylikeits1983 left a comment

Choose a reason for hiding this comment

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

Looks good to me, its just there are a few in flight PRs on agglayer branch(s) that will probably need to be merged into agglayer first, then agglayer into next before we should add this.

cc @mmagician

@partylikeits1983 partylikeits1983 dismissed their stale review February 5, 2026 08:26

Will approve once other PRs land on agglayer. This looks good, just not quite ready to merge to next. Also agglayer related work is first merged to the agglayer branch for staging

@mmagician mmagician marked this pull request as draft February 5, 2026 12:44
@mmagician mmagician added the agglayer PRs or issues related to AggLayer bridging integration label Feb 5, 2026
@Farukest Farukest force-pushed the feat/issue-2371-agglayer-structs branch from a9e083d to dd6771a Compare February 14, 2026 05:54
@Farukest Farukest marked this pull request as ready for review February 14, 2026 05:54
@Farukest Farukest marked this pull request as draft February 14, 2026 05:55
@mmagician
Copy link
Collaborator

superseded by #2371

@mmagician mmagician closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agglayer PRs or issues related to AggLayer bridging integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AggLayer: Encapsulate the creation of agglayer faucet and bridge in structs with new constructor

4 participants