Bridge Validators

Introduction

BridgeValidator is an abstract contract with transaction verification logic that specific validator contracts must inherit to move liquidity on Superform. It ensures that submitted transaction data has the intended bridging outcome and was not corrupted in generation or in the process of transmitting through the Superform API. Superform's ProtocolAdmin may add more bridge validators to allow for more sources of liquidity.

Core Concepts

There are two core validation mechanisms all bridge validators must implement:

  1. validateReceiver: Where TxData is validated to the intended receiver

  2. validateTxData: Where TxData is validated to against the amount of input token, destination chain, and receiver

Along with three core decoding mechanisms:

  1. decodeAmountIn: Where TxData is decoded to return the amount of the input token for both direct and cross chain actions

  2. decodeDstSwap: Where same-chain swap TxData is decoded to return the input token and amount

  3. decodeSwapOutputToken: Where same-chain swap TxData is decoded to return the output token

validateReceiver

This function validates the receiver's address based on the provided transaction data and intended receiver.

function validateReceiver(
    bytes calldata txData_,
    address receiver_
) external view returns (bool);

validateTxData

This function performs multiple checks on the transaction data provided to ensure proper behavior. These checks are implemented on a case-by-case basis depending on the bridge infrastructure being integrated.

function validateTxData(
    ValidateTxDataArgs calldata args_
) external view virtual override;

struct ValidateTxDataArgs {
    bytes txData,
    uint64 srcChainId,
    uint64 dstChainId,
    uint64 liqDstChainId,
    bool deposit,
    address superform,
    address srcSender,
    address liqDataToken
    address liqDataInterimToken;
}

decodeAmountIn

This function returns the decoded minAmount expected to be received post bridging/swapping actions. This is used in multiple places in core contracts, notably in Router implementations.

function decodeAmountIn(
    bytes calldata txData_,
    bool genericSwapDisallowed_
) external pure override returns (uint256 amount_)

decodeDstSwap

This function returns the necessary information for processing swaps on the destination chain, the amount of the expected output token and address. This is used in DstSwapper.

function decodeDstSwap(
    bytes calldata txData_
) external pure override returns (address token_, uint256 amount_)

decodeSwapOutputToken

This function returns the neccessary information for figuring out the final token address to be received after a swap. This is used in direct action validation in ERC4626Form.

function decodeSwapOutputToken(
    bytes calldata txData_
) external pure override returns (address token_)

Last updated