alloy_zksync/contracts/l2/
l2_bridge.rs

1use L2Bridge::finalizeDepositCall;
2use alloy::{
3    primitives::{Address, Bytes, U256},
4    sol_types::SolCall,
5};
6
7alloy::sol! {
8    /// L2Bridge contract for finalizing deposits from Layer 1.
9    #[sol(rpc)]
10    contract L2Bridge {
11        /// Finalizes a deposit from Layer 1 to Layer 2.
12        ///
13        /// # Arguments
14        ///
15        /// * `_l1Sender` - The address of the sender on Layer 1.
16        /// * `_l2Receiver` - The address of the receiver on Layer 2.
17        /// * `_l1Token` - The address of the token on Layer 1.
18        /// * `_amount` - The amount of the token to deposit.
19        /// * `_data` - Encoded deposit token data.
20        function finalizeDeposit(
21            address _l1Sender,
22            address _l2Receiver,
23            address _l1Token,
24            uint256 _amount,
25            bytes calldata _data
26        );
27    }
28}
29
30/// Encodes the calldata for finalizing a deposit.
31///
32/// This function encodes the sender address, receiver address, Layer 1 token address,
33/// amount, and token data into a `Bytes` object for use in deposit finalization operations.
34///
35/// # Arguments
36///
37/// * `sender` - The address of the sender on Layer 1.
38/// * `receiver` - The address of the receiver on Layer 2.
39/// * `l1_token_address` - The address of the token on Layer 1.
40/// * `amount` - The amount of the token to deposit.
41/// * `token_data` - Encoded deposit token data.
42///
43/// # Returns
44///
45/// The encoded calldata as `Bytes`.
46pub(crate) fn encode_finalize_deposit_calldata(
47    sender: Address,
48    receiver: Address,
49    l1_token_address: Address,
50    amount: U256,
51    token_data: Bytes,
52) -> Bytes {
53    let call = finalizeDepositCall {
54        _l1Sender: sender,
55        _l2Receiver: receiver,
56        _l1Token: l1_token_address,
57        _amount: amount,
58        _data: token_data,
59    };
60
61    call.abi_encode().into()
62}