refactor: encapsulate agglayer faucet and bridge in structs#2379
refactor: encapsulate agglayer faucet and bridge in structs#2379Farukest wants to merge 4 commits into0xMiden:nextfrom
Conversation
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
4ff25f3 to
af9371e
Compare
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
| 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); |
crates/miden-agglayer/src/lib.rs
Outdated
| /// # 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( |
There was a problem hiding this comment.
Is it possible to replace this function with calls to AggLayerFaucet::new directly?
There was a problem hiding this comment.
Done @PhilippGackstatter 👍
removed create_agglayer_faucet_component and now using AggLayerFaucet::new directly in create_agglayer_faucet_builder
crates/miden-agglayer/src/lib.rs
Outdated
| 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) |
There was a problem hiding this comment.
It might make sense to get rid of bridge_out_component and inline that logic here, but cc @mmagician for double checking.
|
All done @PhilippGackstatter need review. let me know if I miss something else. thanks |
ce95977 to
49541ba
Compare
- Remove create_agglayer_faucet_component helper, use AggLayerFaucet::new directly - Inline bridge_out_component logic in From<AggLayerBridge> impl
49541ba to
ff354f0
Compare
partylikeits1983
left a comment
There was a problem hiding this comment.
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
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
a9e083d to
dd6771a
Compare
dd6771a to
d533563
Compare
|
superseded by #2371 |
Summary
AggLayerFaucetstruct withnew()constructor andFrom<AggLayerFaucet> for AccountComponentAggLayerBridgestruct withnew()constructor andFrom<AggLayerBridge> for AccountComponentLazyLockconstantscreate_agglayer_faucet_componentandcreate_bridge_account_componentto use new structsContext
This follows the pattern established by
NetworkFungibleFaucetin PR #2335, improving code maintainability by encapsulating configuration in dedicated types with trait-based conversion.Test plan
cargo +nightly fmtpassescargo clippy -p miden-agglayerpassescargo test -p miden-agglayerpassesCloses #2371