Skip to main content

Solidity API

SafeCast

This contract facilitates the following:

  • deposits
  • creation and voting of deposit proposals
  • deposit executions
  • rollup executions and state settlements

toUint200

function toUint200(uint256 value) internal pure returns (uint200)

toUint128

function toUint128(uint256 value) internal pure returns (uint128)

toUint40

function toUint40(uint256 value) internal pure returns (uint40)

toUint8

function toUint8(uint256 value) internal pure returns (uint8)

Bridge

MAX_RELAYERS

uint256 MAX_RELAYERS

Limit relayers number because proposal can fit only so much votes

_domainID

uint8 _domainID

_relayerThreshold

uint8 _relayerThreshold

_fee

uint128 _fee

_expiry

uint40 _expiry

ProposalStatus

enum ProposalStatus {
Inactive,
Active,
Passed,
Executed,
Cancelled
}

Proposal

struct Proposal {
enum Bridge.ProposalStatus _status;
uint200 _yesVotes;
uint8 _yesVotesTotal;
uint40 _proposedBlock;
}

_depositCounts

mapping(uint8 => uint64) _depositCounts

_resourceIDToHandlerAddress

mapping(bytes32 => address) _resourceIDToHandlerAddress

_proposals

mapping(uint72 => mapping(bytes32 => struct Bridge.Proposal)) _proposals

RelayerThresholdChanged

event RelayerThresholdChanged(uint256 newThreshold)

RelayerAdded

event RelayerAdded(address relayer)

RelayerRemoved

event RelayerRemoved(address relayer)

RolluperAdded

event RolluperAdded(address rolluper)

RolluperRemoved

event RolluperRemoved(address rolluper)

Deposit

event Deposit(uint8 destinationDomainID, bytes32 resourceID, uint64 depositNonce, address user, bytes data, bytes handlerResponse)

ProposalEvent

event ProposalEvent(uint8 originDomainID, bytes32 resourceID, uint64 depositNonce, enum Bridge.ProposalStatus status, bytes32 dataHash)

ProposalVote

event ProposalVote(uint8 originDomainID, uint64 depositNonce, enum Bridge.ProposalStatus status, bytes32 dataHash)

FailedHandlerExecution

event FailedHandlerExecution(bytes lowLevelData)

ExecRollup

event ExecRollup(uint8 destDomainID, bytes32 resourceID, bytes32 senderResourceID, uint64 nonce, uint64 batchSize, uint256 startBlock, bytes32 proof)

SettleStateChanges

event SettleStateChanges(uint8 originDomainId, bytes32 resourceID, uint64 nonce, uint64 batchIdx, uint64 totalBatch)

RELAYER_ROLE

bytes32 RELAYER_ROLE

onlyAdmin

modifier onlyAdmin()

onlyAdminOrRelayer

modifier onlyAdminOrRelayer()

onlyRelayers

modifier onlyRelayers()

constructor

constructor(uint8 domainID, address[] initialRelayers, uint256 initialRelayerThreshold, uint256 fee, uint256 expiry) public

Initializes Bridge, creates and grants {msg.sender} the admin role, creates and grants {initialRelayers} the relayer role.

NameTypeDescription
domainIDuint8ID of chain the Bridge contract exists on.
initialRelayersaddress[]Addresses that should be initially granted the relayer role.
initialRelayerThresholduint256Number of votes needed for a deposit proposal to be considered passed.
feeuint256
expiryuint256

renounceAdmin

function renounceAdmin(address newAdmin) external

Removes admin role from {msg.sender} and grants it to {newAdmin}.

Requirements:

  • It must be called by only admin.
NameTypeDescription
newAdminaddressAddress that admin role will be granted to.

adminPauseTransfers

function adminPauseTransfers() external

Pauses deposits, proposal creation and voting, and deposit executions.

Requirements:

  • It must be called by only admin.

adminUnpauseTransfers

function adminUnpauseTransfers() external

Unpauses deposits, proposal creation and voting, and deposit executions.

Requirements:

  • It must be called by only admin.

adminChangeRelayerThreshold

function adminChangeRelayerThreshold(uint256 newThreshold) external

Modifies the number of votes required for a proposal to be considered passed.

Requirements:

  • It must be called by only admin.

Emits {RelayerThresholdChanged} event.

NameTypeDescription
newThresholduint256Value {_relayerThreshold} will be changed to.

adminAddRelayer

function adminAddRelayer(address relayerAddress) external

Grants {relayerAddress} the relayer role.

Requirements:

  • It must be called by only admin.
  • {relayerAddress} must not already has relayer role.
  • The number of current relayer must be less than {MAX_RELAYERS}

Emits {RelayerAdded} event.

admin role is checked in grantRole()

NameTypeDescription
relayerAddressaddressAddress of relayer to be added.

adminRemoveRelayer

function adminRemoveRelayer(address relayerAddress) external

Removes relayer role for {relayerAddress}.

Requirements:

  • It must be called by only admin.
  • {relayerAddress} must has relayer role.

Emits {RelayerRemoved} event.

admin role is checked in revokeRole()

NameTypeDescription
relayerAddressaddressAddress of relayer to be removed.

adminSetResource

function adminSetResource(address handlerAddress, bytes32 resourceID, address tokenAddress) external

Sets a new resource for handler contracts that use the IERCHandler interface, and maps the {handlerAddress} to {resourceID} in {_resourceIDToHandlerAddress}.

Requirements:

  • It must be called by only admin.
NameTypeDescription
handlerAddressaddressAddress of handler resource will be set for.
resourceIDbytes32ResourceID to be used when making deposits.
tokenAddressaddressAddress of contract to be called when a deposit is made and a deposited is executed.

adminSetBurnable

function adminSetBurnable(address handlerAddress, address tokenAddress) external

Sets a resource as burnable for handler contracts that use the IERCHandler interface.

Requirements:

  • It must be called by only admin.
NameTypeDescription
handlerAddressaddressAddress of handler resource will be set for.
tokenAddressaddressAddress of contract to be called when a deposit is made and a deposited is executed.

adminSetDepositNonce

function adminSetDepositNonce(uint8 domainID, uint64 nonce) external

Sets the nonce for the specific domainID.

Requirements:

  • It must be called by only admin.
  • {nonce} must be greater than the current nonce.
NameTypeDescription
domainIDuint8Domain ID for increasing nonce.
nonceuint64The nonce value to be set.

adminChangeFee

function adminChangeFee(uint256 newFee) external

Changes deposit fee.

Requirements:

  • It must be called by only admin.
  • The current fee must not be equal to new fee.
NameTypeDescription
newFeeuint256Value {_fee} will be updated to.

adminWithdraw

function adminWithdraw(address handlerAddress, bytes data) external

Used to manually withdraw funds from ERC safes.

Requirements:

  • It must be called by only admin.
NameTypeDescription
handlerAddressaddressAddress of handler to withdraw from.
databytesABI-encoded withdrawal params relevant to the specified handler.

deposit

function deposit(uint8 destinationDomainID, bytes32 resourceID, bytes data) external payable

Initiates a transfer using a specified handler contract.

Requirements:

  • Bridge must be not be paused.
  • {msg.value} must be greater than or equal to {_fee}.
  • Handler must be registered with {resourceID}.

Emits {Deposit} event with all necessary parameters and a handler response.

  • ERC20Handler: responds with an empty data.
  • ERC721Handler: responds with the deposited token metadata acquired by calling a tokenURI method in the token contract.
  • ERC1155Handler: responds with an empty data.
  • NativeTokenHandler: responds with an empty data.

RollupHandler doesn't support this function.

NameTypeDescription
destinationDomainIDuint8ID of chain deposit will be bridged to.
resourceIDbytes32ResourceID used to find address of handler to be used for deposit.
databytesAdditional data to be passed to specified handler.

voteProposal

function voteProposal(uint8 domainID, uint64 depositNonce, bytes32 resourceID, bytes data) external

When called, {msg.sender} will be marked as voting in favor of proposal.

Requirements:

  • It must be called by only relayer.
  • Bridge must not be paused.
  • Handler must be registered with {resourceID}.
  • Proposal must not have already been passed or executed.
  • Relayer must vote only once.

Emits {ProposalEvent} event with status indicating the proposal status. Emits {ProposalVote} event.

NameTypeDescription
domainIDuint8ID of chain deposit originated from.
depositNonceuint64ID of deposited generated by origin Bridge contract.
resourceIDbytes32
databytesData originally provided when deposit was made.

cancelProposal

function cancelProposal(uint8 domainID, bytes32 resourceID, uint64 depositNonce, bytes32 dataHash) external

Cancels a deposit proposal that has not been executed yet.

Requirements:

  • It must be called by only relayer or admin.
  • Bridge must not be paused.
  • Proposal must be past expiry threshold.

Emits {ProposalEvent} event with status {Cancelled}.

NameTypeDescription
domainIDuint8ID of chain deposit originated from.
resourceIDbytes32
depositNonceuint64ID of deposited generated by origin Bridge contract.
dataHashbytes32Hash of data originally provided when deposit was made.

transferFunds

function transferFunds(address payable[] addrs, uint256[] amounts) external

Transfers eth in the contract to the specified addresses. The parameters addrs and amounts are mapped 1-1. This means that the address at index 0 for addrs will receive the amount (in WEI) from amounts at index 0.

NameTypeDescription
addrsaddress payable[]Array of addresses to transfer {amounts} to.
amountsuint256[]Array of amonuts to transfer to {addrs}.

executeRollup

function executeRollup(uint8 destDomainID, bytes32 resourceID, uint64 batchSize, uint256 startBlock, bytes32 state) external

Executes rollup.

Requirements:

  • It must be called by only relayer.
  • Bridge must not be paused.
  • Handler must be registered with {resourceID}.
  • {msg.sender} must be registered in handler.

Emits {ExecRollup} event which is handled by relayer.

settleStateChanges

function settleStateChanges(uint8 originDomainID, bytes32 resourceID, uint64 nonce, bytes state, bytes32[] proof) external

Settles state changes.

Requirements:

  • Handler must be registered with {resourceID}.

It can be called by anyone.

getProposal

function getProposal(uint8 originDomainID, uint64 depositNonce, bytes32 dataHash) external view returns (struct Bridge.Proposal)

Returns a proposal.

NameTypeDescription
originDomainIDuint8Chain ID deposit originated from.
depositNonceuint64ID of proposal generated by proposal's origin Bridge contract.
dataHashbytes32Hash of data to be provided when deposit proposal is executed.
NameTypeDescription
[0]struct Bridge.ProposalProposal which consists of: - _dataHash Hash of data to be provided when deposit proposal is executed. - _yesVotes Number of votes in favor of proposal. - _noVotes Number of votes against proposal. - _status Current status of proposal.

_hasVotedOnProposal

function _hasVotedOnProposal(uint72 destNonce, bytes32 dataHash, address relayer) external view returns (bool)

Returns true if {relayer} has voted on {destNonce} {dataHash} proposal.

Naming left unchanged for backward compatibility.

NameTypeDescription
destNonceuint72destinationDomainID + depositNonce of the proposal.
dataHashbytes32Hash of data to be provided when deposit proposal is executed.
relayeraddressAddress to check.

isRelayer

function isRelayer(address relayer) external view returns (bool)

Returns true if {relayer} has the relayer role.

NameTypeDescription
relayeraddressAddress to check.

executeProposal

function executeProposal(uint8 domainID, uint64 depositNonce, bytes data, bytes32 resourceID, bool revertOnFail) public

Executes a deposit proposal that is considered passed using a specified handler contract.

Requirements:

  • It must be called by only relayer.
  • Bridge must not be paused.
  • Proposal must have Passed status.
  • Hash of {data} must equal proposal's {dataHash}.

Emits {ProposalEvent} event with status {Executed}. Emits {FailedExecution} event with the failed reason.

NameTypeDescription
domainIDuint8ID of chain deposit originated from.
depositNonceuint64ID of deposited generated by origin Bridge contract.
databytesData originally provided when deposit was made.
resourceIDbytes32ResourceID to be used when making deposits.
revertOnFailboolDecision if the transaction should be reverted in case of handler's executeProposal is reverted or not.

_totalRelayers

function _totalRelayers() public view returns (uint256)

Returns total relayers number.

Added for backwards compatibility.

_onlyAdminOrRelayer

function _onlyAdminOrRelayer() private view

_onlyAdmin

function _onlyAdmin() private view

_onlyRelayers

function _onlyRelayers() private view

_relayerBit

function _relayerBit(address relayer) private view returns (uint256)

_hasVoted

function _hasVoted(struct Bridge.Proposal proposal, address relayer) private view returns (bool)