FastBridgeV2

Git Source

Inherits: AdminV2, MulticallTarget, IFastBridgeV2, IFastBridgeV2Errors

Core component of the SynapseRFQ protocol, enabling Relayers (Solvers) to fulfill bridge requests. Supports ERC20 and native gas tokens, along with the Zap feature for executing actions on the destination chain. Users interact with the off-chain Quoter API to obtain a current quote for a bridge transaction. They then submit the bridge request with the quote to this contract, depositing their assets in escrow. Relayers can fulfill requests by relaying them to the destination chain and must prove fulfillment to claim funds. Guards monitor proofs and can dispute discrepancies. Users can reclaim funds by cancelling their requests if it has not been fulfilled within the specified deadline.

State Variables

DISPUTE_PERIOD

The duration of the dispute period for relayed transactions.

uint256 public constant DISPUTE_PERIOD = 30 minutes;

MIN_DEADLINE_PERIOD

The minimum required time between transaction request and deadline.

uint256 public constant MIN_DEADLINE_PERIOD = 30 minutes;

MAX_ZAP_DATA_LENGTH

The maximum allowed length for zapData.

uint256 public constant MAX_ZAP_DATA_LENGTH = 2 ** 16 - 1;

bridgeTxDetails

Maps transaction IDs to bridge details (status, destination chain ID, proof timestamp, and relayer). Note: this is only stored for transactions having local chain as the origin chain.

mapping(bytes32 => BridgeTxDetails) public bridgeTxDetails;

bridgeRelayDetails

Maps transaction IDs to relay details (block number, block timestamp, and relayer). Note: this is only stored for transactions having local chain as the destination chain.

mapping(bytes32 => BridgeRelay) public bridgeRelayDetails;

senderNonces

Maps sender addresses to their unique bridge nonce.

mapping(address => uint256) public senderNonces;

nonce

This variable is deprecated and should not be used.

Replaced by senderNonces.

uint256 public immutable nonce = 0;

Functions

constructor

Initializes the FastBridgeV2 contract with the provided default admin, sets the default cancel delay, and records the deploy block number.

constructor(address defaultAdmin) AdminV2(defaultAdmin);

bridge

Initiates bridge on origin chain to be relayed by off-chain relayer

function bridge(BridgeParams memory params) external payable;

Parameters

NameTypeDescription
paramsBridgeParamsThe parameters required to bridge

refund

Note: this function is deprecated and will be removed in a future version.

Replaced by cancel.

function refund(bytes calldata request) external;

Parameters

NameTypeDescription
requestbytesThe encoded bridge transaction to refund

relay

Relays destination side of bridge transaction by off-chain relayer

function relay(bytes calldata request) external payable;

Parameters

NameTypeDescription
requestbytesThe encoded bridge transaction to relay on destination chain

prove

Provides proof on origin side that relayer provided funds on destination side of bridge transaction

function prove(bytes calldata request, bytes32 destTxHash) external;

Parameters

NameTypeDescription
requestbytesThe encoded bridge transaction to prove on origin chain
destTxHashbytes32The destination tx hash proving bridge transaction was relayed

claimV2

Completes bridge transaction on origin chain by claiming originally deposited capital.

function claimV2(bytes calldata request) external;

Parameters

NameTypeDescription
requestbytesThe encoded bridge transaction to claim on origin chain

dispute

Disputes an outstanding proof in case relayer provided dest chain tx is invalid

function dispute(bytes32 transactionId) external onlyRole(GUARD_ROLE);

Parameters

NameTypeDescription
transactionIdbytes32The transaction id associated with the encoded bridge transaction to dispute

canClaim

Checks if the dispute period has passed so bridge deposit can be claimed

function canClaim(bytes32 transactionId, address relayer) external view returns (bool);

Parameters

NameTypeDescription
transactionIdbytes32The transaction id associated with the encoded bridge transaction to check
relayeraddressThe address of the relayer attempting to claim

getBridgeTransaction

Decodes bridge request into a bridge transaction

*This method is added to achieve backwards compatibility with decoding requests into V1 structs:

  • zapNative is partially reported as a zero/non-zero flag
  • zapData is ignored In order to process all kinds of requests use getBridgeTransactionV2 instead.*
function getBridgeTransaction(bytes calldata request) external view returns (BridgeTransaction memory);

Parameters

NameTypeDescription
requestbytesThe bridge request to decode

getBridgeTransactionV2

Decodes bridge request into a bridge transaction V2 struct used by FastBridgeV2

function getBridgeTransactionV2(bytes calldata request) external pure returns (BridgeTransactionV2 memory);

Parameters

NameTypeDescription
requestbytesThe bridge request to decode

bridgeV2

Initiates bridge on origin chain to be relayed by off-chain relayer, with the ability to provide temporary exclusivity fill rights for the quote relayer.

function bridgeV2(BridgeParams memory params, BridgeParamsV2 memory paramsV2) public payable;

Parameters

NameTypeDescription
paramsBridgeParamsThe parameters required to bridge
paramsV2BridgeParamsV2The parameters for exclusivity fill rights (optional, can be left empty)

cancelV2

Cancels an outstanding bridge transaction in case optimistic bridging failed and returns the full amount to the original sender.

function cancelV2(bytes calldata request) public;

Parameters

NameTypeDescription
requestbytesThe encoded bridge transaction to refund

relayV2

Relays destination side of bridge transaction by off-chain relayer

function relayV2(bytes calldata request, address relayer) public payable;

Parameters

NameTypeDescription
requestbytesThe encoded bridge transaction to relay on destination chain
relayeraddressThe address of the relaying entity which should have control of the origin funds when claimed

proveV2

Provides proof on origin side that relayer provided funds on destination side of bridge transaction

function proveV2(bytes32 transactionId, bytes32 destTxHash, address relayer) public;

Parameters

NameTypeDescription
transactionIdbytes32The transaction id associated with the encoded bridge transaction to prove
destTxHashbytes32The destination tx hash proving bridge transaction was relayed
relayeraddressThe address of the relaying entity which should have control of the origin funds when claimed

claim

Completes bridge transaction on origin chain by claiming originally deposited capital

function claim(bytes calldata request, address to) public;

Parameters

NameTypeDescription
requestbytesThe encoded bridge transaction to claim on origin chain
toaddressThe recipient address of the funds

bridgeStatuses

Returns the status of a bridge transaction

function bridgeStatuses(bytes32 transactionId) public view returns (BridgeStatus status);

Parameters

NameTypeDescription
transactionIdbytes32The ID of the bridge transaction

Returns

NameTypeDescription
statusBridgeStatusBridgeStatus Status of the bridge transaction

bridgeProofs

Returns the timestamp and relayer of a bridge proof

function bridgeProofs(bytes32 transactionId) public view returns (uint96 timestamp, address relayer);

Parameters

NameTypeDescription
transactionIdbytes32The ID of the bridge transaction

Returns

NameTypeDescription
timestampuint96The timestamp of the bridge proof
relayeraddressThe relayer address of the bridge proof

bridgeRelays

Checks if a transaction has been relayed

function bridgeRelays(bytes32 transactionId) public view returns (bool);

Parameters

NameTypeDescription
transactionIdbytes32The ID of the transaction to check

Returns

NameTypeDescription
<none>boolTrue if the transaction has been relayed, false otherwise

_takeBridgedUserAsset

Takes the bridged asset from the user into FastBridgeV2 custody. The asset will later be claimed by the relayer who completed the relay on the destination chain, or returned to the user via the cancel function if no relay is completed.

function _takeBridgedUserAsset(address token, uint256 amount) internal returns (uint256 amountTaken);

_triggerZapWithChecks

Calls the recipient's hook function with the specified zapData and validates the returned value.

function _triggerZapWithChecks(address recipient, address token, uint256 amount, bytes calldata zapData) internal;

_timeSince

Calculates the time elapsed since a proof was submitted.

The proof.timestamp stores block timestamps as uint40 for gas optimization. _timeSince(proof) handles timestamp rollover when block.timestamp > type(uint40).max but proof.timestamp < type(uint40).max via an unchecked statement.

function _timeSince(uint40 proofBlockTimestamp) internal view returns (uint256 delta);

Parameters

NameTypeDescription
proofBlockTimestampuint40The block timestamp when the proof was submitted.

Returns

NameTypeDescription
deltauint256The time elapsed since proof submission.

_validateBridgeParams

Validates all parameters required for a bridge transaction.

This function's complexity cannot be reduced due to the number of required checks, so we disable the code-complexity rule.

function _validateBridgeParams(
    BridgeParams memory params,
    BridgeParamsV2 memory paramsV2,
    int256 exclusivityEndTime
)
    internal
    view;

_validateRelayParams

Validates all parameters required for a relay transaction.

function _validateRelayParams(bytes calldata request, bytes32 transactionId, address relayer) internal view;