alloy_zksync/contracts/l1/
l1_bridge.rs

1use alloy::{
2    dyn_abi::DynSolValue,
3    primitives::{Address, Bytes, U256},
4};
5
6alloy::sol! {
7     /// L1Bridge contract for interacting with Layer 2 bridges.
8    #[sol(rpc)]
9    contract L1Bridge {
10        /// Retrieves the address of the L2 bridge for a given chain ID.
11        ///
12        /// # Arguments
13        ///
14        /// * `_chainId` - The chain ID.
15        ///
16        /// # Returns
17        ///
18        /// The address of the L2 bridge.
19        function l2BridgeAddress(uint256 _chainId) external view returns (address);
20    }
21}
22
23/// Encodes the calldata for depositing a token.
24///
25/// This function encodes the token address, amount, and receiver address into a `Bytes` object
26/// for use in deposit operations.
27///
28/// # Arguments
29///
30/// * `token` - The address of the token to deposit.
31/// * `amount` - The amount of the token to deposit.
32/// * `receiver` - The address of the receiver.
33///
34/// # Returns
35///
36/// The encoded calldata as `Bytes`.
37pub(crate) fn encode_deposit_token_calldata(
38    token: Address,
39    amount: U256,
40    receiver: Address,
41) -> Bytes {
42    Bytes::from(
43        DynSolValue::Tuple(vec![
44            DynSolValue::Address(token),
45            DynSolValue::Uint(amount, 256),
46            DynSolValue::Address(receiver),
47        ])
48        .abi_encode_params(),
49    )
50}