FastBridgeV2

Git Source

Inherits: Admin, IFastBridgeV2, IFastBridgeV2Errors

FastBridgeV2 is a contract for bridging tokens across chains.

State Variables

DISPUTE_PERIOD

Dispute period for relayed transactions

uint256 public constant DISPUTE_PERIOD = 30 minutes;

REFUND_DELAY

Delay for a transaction after which it could be permisionlessly refunded

uint256 public constant REFUND_DELAY = 7 days;

MIN_DEADLINE_PERIOD

Minimum deadline period to relay a requested bridge transaction

uint256 public constant MIN_DEADLINE_PERIOD = 30 minutes;

MAX_CALL_PARAMS_LENGTH

Maximum length of accepted callParams

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

bridgeTxDetails

Status of the bridge tx on origin chain

mapping(bytes32 => BridgeTxDetails) public bridgeTxDetails;

bridgeRelayDetails

Relay details on destination chain

mapping(bytes32 => BridgeRelay) public bridgeRelayDetails;

senderNonces

Unique bridge nonces tracked per originSender

mapping(address => uint256) public senderNonces;

nonce

This is deprecated and should not be used.

Replaced by senderNonces

uint256 public immutable nonce = 0;

deployBlock

the block the contract was deployed at

uint256 public immutable deployBlock;

Functions

constructor

constructor(address _owner) Admin(_owner);

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

relay

Relays destination side of bridge transaction by off-chain relayer

function relay(bytes memory 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 memory request, bytes32 destTxHash) external;

Parameters

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

claim

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

function claim(bytes memory 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

refund

Refunds an outstanding bridge transaction in case optimistic bridging failed

function refund(bytes memory request) external;

Parameters

NameTypeDescription
requestbytesThe encoded bridge transaction to refund

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

function getBridgeTransaction(bytes memory request) external pure returns (BridgeTransaction memory);

Parameters

NameTypeDescription
requestbytesThe bridge request to decode

bridge

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 bridge(BridgeParams memory params, BridgeParamsV2 memory paramsV2) public payable;

Parameters

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

relay

Relays destination side of bridge transaction by off-chain relayer

function relay(bytes memory 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

prove

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

function prove(bytes32 transactionId, bytes32 destTxHash, address relayer) public onlyRole(RELAYER_ROLE);

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 memory request, address to) public;

Parameters

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

bridgeStatuses

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

bridgeProofs

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

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

getBridgeTransactionV2

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

function getBridgeTransactionV2(bytes memory request) public pure returns (BridgeTransactionV2 memory);

Parameters

NameTypeDescription
requestbytesThe bridge request to decode

_pullToken

Pulls a requested token from the user to the requested recipient.

Be careful of re-entrancy issues when msg.value > 0 and recipient != address(this)

function _pullToken(address recipient, address token, uint256 amount) internal returns (uint256 amountPulled);

_checkedCallRecipient

Calls the Recipient's hook function with the specified callParams and performs all the necessary checks for the returned value.

function _checkedCallRecipient(
    address recipient,
    uint256 msgValue,
    address token,
    uint256 amount,
    bytes memory callParams
)
    internal;

_timeSince

Calculates time since proof submitted

proof.timestamp stores casted uint40(block.timestamp) block timestamps for gas optimization _timeSince(proof) can accomodate rollover case when block.timestamp > type(uint40).max but proof.timestamp < type(uint40).max via unchecked statement

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

Parameters

NameTypeDescription
proofBlockTimestampuint40The bridge proof block timestamp

Returns

NameTypeDescription
deltauint256Time delta since proof submitted