AbstractBridge

An abstract class that provides a skeleton implementation for bridging assets.

AbstractBridge is an abstract class that provides a skeleton implementation for bridging assets between Layer 1 and Layer 2. It serves as a base class that contains common functionality shared across different bridge implementations.

This class implements the core bridging functionality such as:

  • Token deposits from L1 to L2
  • Token withdrawals from L2 to L1
  • Withdrawal finalization on L1
  • ERC20 token approval management
  • Transaction validation and gas estimation

Abstract Methods

Concrete bridge implementations must define the following abstract methods:

getSecondBridgeDepositCalldata

Returns the deposit calldata for the second bridge.

Inputs

ParameterTypeDescription
transactionIDepositTransactionDeposit transaction.
protected abstract getSecondBridgeDepositCalldata(
  transaction: IDepositTransaction
): Promise<string>;

populateWithdrawTransaction

Populates the withdraw transaction for the bridge.

Inputs

ParameterTypeDescription
transactionIWithdrawTransactionWithdraw transaction.
protected abstract populateWithdrawTransaction(
  transaction: IWithdrawTransaction
): Promise<TransactionLike>;

finalizeL1Deposit

Finalizes the L1 deposit.

Inputs

ParameterTypeDescription
bridgeAddressAddressThe address of the bridge contract to be used.
finalizeParamsFinalizeL1DepositParamsFinalize L1 deposit parameters.
overrides?ethers.OverridesTransaction's overrides which may be used to pass L1 gasLimit, gasPrice, value, etc.
protected abstract finalizeL1Deposit(
  bridgeAddress: Address,
  finalizeParams: FinalizeL1DepositParams,
  overrides?: Overrides
): Promise<ContractTransactionResponse>;

checkIfWithdrawalIsFinalized

Checks if a withdrawal has been finalized on L1.

Inputs

ParameterTypeDescription
bridgeAddressAddressThe address of the bridge contract to be used.
finalizeParamsFinalizeL1DepositParamsFinalize withdrawal parameters.
protected abstract checkIfWithdrawalIsFinalized(
  bridgeAddress: Address,
  finalizeParams: FinalizeL1DepositParams
): Promise<boolean>;

Validation Hooks

The class provides optional validation hooks that can be overridden:

validateDepositParams

Validates deposit transaction parameters. The function is expected to throw an exception if the deposit parameters are not valid.

Inputs

ParameterTypeDescription
transactionIDepositTransactionDeposit transaction.
protected async validateDepositParams(
  transaction: IDepositTransaction
): Promise<void>;

validateWithdrawParams

Validates withdrawal transaction parameters. The function is expected to throw an exception if the withdrawal parameters are not valid.

Inputs

ParameterTypeDescription
transactionIWithdrawTransactionWithdraw transaction.
protected async validateWithdrawParams(
  transaction: IWithdrawTransaction
): Promise<void>;

Complete Implementation Example

For a complete implementation example, see the USDCBridge class which extends AbstractBridge and implements all required abstract methods for USDC token bridging operations.


Made with ❤️ by the ZKsync Community