FastBridge
Inherits: IFastBridge, Admin
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;
bridgeStatuses
Status of the bridge tx on origin chain
mapping(bytes32 => BridgeStatus) public bridgeStatuses;
bridgeProofs
Proof of relayed bridge tx on origin chain
mapping(bytes32 => BridgeProof) public bridgeProofs;
bridgeRelays
Whether bridge has been relayed on destination chain
mapping(bytes32 => bool) public bridgeRelays;
nonce
to prevent replays
uint256 public nonce;
deployBlock
uint256 public immutable deployBlock;
Functions
constructor
constructor(address _owner) Admin(_owner);
_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);
getBridgeTransaction
Decodes bridge request into a bridge transaction
function getBridgeTransaction(bytes memory request) public pure returns (BridgeTransaction memory);
Parameters
Name | Type | Description |
---|---|---|
request | bytes | The bridge request to decode |
bridge
Initiates bridge on origin chain to be relayed by off-chain relayer
function bridge(BridgeParams memory params) external payable;
Parameters
Name | Type | Description |
---|---|---|
params | BridgeParams | The parameters required to bridge |
relay
Relays destination side of bridge transaction by off-chain relayer
function relay(bytes memory request) external payable onlyRole(RELAYER_ROLE);
Parameters
Name | Type | Description |
---|---|---|
request | bytes | The 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 onlyRole(RELAYER_ROLE);
Parameters
Name | Type | Description |
---|---|---|
request | bytes | The encoded bridge transaction to prove on origin chain |
destTxHash | bytes32 | The destination tx hash proving bridge transaction was relayed |
_timeSince
Calculates time since proof submitted
proof.timestamp stores casted uint96(block.timestamp) block timestamps for gas optimization _timeSince(proof) can accomodate rollover case when block.timestamp > type(uint96).max but proof.timestamp < type(uint96).max via unchecked statement
function _timeSince(BridgeProof memory proof) internal view returns (uint256 delta);
Parameters
Name | Type | Description |
---|---|---|
proof | BridgeProof | The bridge proof |
Returns
Name | Type | Description |
---|---|---|
delta | uint256 | Time delta since proof submitted |
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
Name | Type | Description |
---|---|---|
transactionId | bytes32 | The transaction id associated with the encoded bridge transaction to check |
relayer | address | The address of the relayer attempting to claim |
claim
Completes bridge transaction on origin chain by claiming originally deposited capital
function claim(bytes memory request, address to) external onlyRole(RELAYER_ROLE);
Parameters
Name | Type | Description |
---|---|---|
request | bytes | The encoded bridge transaction to claim on origin chain |
to | address | The recipient address of the funds |
dispute
Disputes an outstanding proof in case relayer provided dest chain tx is invalid
function dispute(bytes32 transactionId) external onlyRole(GUARD_ROLE);
Parameters
Name | Type | Description |
---|---|---|
transactionId | bytes32 | The 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
Name | Type | Description |
---|---|---|
request | bytes | The encoded bridge transaction to refund |
Enums
BridgeStatus
enum BridgeStatus {
NULL,
REQUESTED,
RELAYER_PROVED,
RELAYER_CLAIMED,
REFUNDED
}