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);
NameDescription

txData_

bytes transaction data to be executed

receiver_

address of the intended receiver of the tokens after transaction data is executed

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;
}
NameDescription

txData_

bytes transaction data to be executed

srcChainId_

uint64 EVM chain id of where the funds originate from

dstChainId_

uint64 EVM chain id of the target chain of the action

liqDstChainId_

uint64 EVM chain id of where the funds are going. On deposits its where the Superform is located, on withdrawals it can be any arbitrary EVM chain id supported by the bridge

deposit_

bool where true if the action is a deposit, false if it is a withdrawal

superform_

address of the Superform

srcSender_

address of the user sending the transaction on the source chain

liqDataToken_

address of the token being swapped

liqDataInterimToken_

address of the token that can be used as an intermediary token on the destination chain

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_)
NameDescription

txData_

bytes transaction data to decode minAmount from

genericSwapDisallowed_

bool to represent if generic swaps are not allowed

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_)
NameDescription

txData_

bytes transaction data

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_)
NameDescription

txData_

bytes transaction data

Last updated