Bridge
Facilitates deposits, creation and votiing of deposit proposals, and deposit executions. @author ChainSafe Systems.
constructor(uint8 chainID, 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. @param chainID ID of chain the Bridge contract exists on. @param initialRelayers Addresses that should be initially granted the relayer role. @param initialRelayerThreshold Number of votes needed for a deposit proposal to be considered passed.
isRelayer(address relayer) → bool
external
Returns true if {relayer} has the relayer role. @param relayer Address to check.
renounceAdmin(address newAdmin)
external
Removes admin role from {msg.sender} and grants it to {newAdmin}. @notice Only callable by an address that currently has the admin role. @param newAdmin Address that admin role will be granted to.
adminPauseTransfers()
external
Pauses deposits, proposal creation and voting, and deposit executions. @notice Only callable by an address that currently has the admin role.
adminUnpauseTransfers()
external
Unpauses deposits, proposal creation and voting, and deposit executions. @notice Only callable by an address that currently has the admin role.
adminChangeRelayerThreshold(uint256 newThreshold)
external
Modifies the number of votes required for a proposal to be considered passed.
@notice Only callable by an address that currently has the admin role.
@param newThreshold Value _relayerThreshold
will be changed to.
@notice Emits RelayerThresholdChanged
event.
adminAddRelayer(address relayerAddress)
external
Grants {relayerAddress} the relayer role and increases {_totalRelayer} count.
@notice Only callable by an address that currently has the admin role.
@param relayerAddress Address of relayer to be added.
@notice Emits RelayerAdded
event.
adminRemoveRelayer(address relayerAddress)
external
Removes relayer role for {relayerAddress} and decreases {_totalRelayer} count.
@notice Only callable by an address that currently has the admin role.
@param relayerAddress Address of relayer to be removed.
@notice Emits RelayerRemoved
event.
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
.
@notice Only callable by an address that currently has the admin role.
@param handlerAddress Address of handler resource will be set for.
@param resourceID ResourceID to be used when making deposits.
@param tokenAddress Address of contract to be called when a deposit is made and a deposited is executed.
adminSetGenericResource(address handlerAddress, bytes32 resourceID, address contractAddress, bytes4 depositFunctionSig, bytes4 executeFunctionSig)
external
Sets a new resource for handler contracts that use the IGenericHandler interface,
and maps the {handlerAddress} to {resourceID} in _resourceIDToHandlerAddress
.
@notice Only callable by an address that currently has the admin role.
@param handlerAddress Address of handler resource will be set for.
@param resourceID ResourceID to be used when making deposits.
@param contractAddress Address of contract to be called when a deposit is made and a deposited is executed.
adminSetBurnable(address handlerAddress, address tokenAddress)
external
Sets a resource as burnable for handler contracts that use the IERCHandler interface. @notice Only callable by an address that currently has the admin role. @param handlerAddress Address of handler resource will be set for. @param tokenAddress Address of contract to be called when a deposit is made and a deposited is executed.
getProposal(uint8 originChainID, uint64 depositNonce, bytes32 dataHash) → struct Bridge.Proposal
external
Returns a proposal. @param originChainID Chain ID deposit originated from. @param depositNonce ID of proposal generated by proposal’s origin Bridge contract. @param dataHash Hash of data to be provided when deposit proposal is executed. @return Proposal 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.
adminChangeFee(uint256 newFee)
external
Changes deposit fee.
@notice Only callable by admin.
@param newFee Value _fee
will be updated to.
adminWithdraw(address handlerAddress, address tokenAddress, address recipient, uint256 amountOrTokenID)
external
Used to manually withdraw funds from ERC safes. @param handlerAddress Address of handler to withdraw from. @param tokenAddress Address of token to withdraw. @param recipient Address to withdraw tokens to. @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to withdraw.
deposit(uint8 destinationChainID, bytes32 resourceID, bytes data)
external
Initiates a transfer using a specified handler contract.
@notice Only callable when Bridge is not paused.
@param destinationChainID ID of chain deposit will be bridged to.
@param resourceID ResourceID used to find address of handler to be used for deposit.
@param data Additional data to be passed to specified handler.
@notice Emits Deposit
event.
voteProposal(uint8 chainID, uint64 depositNonce, bytes32 resourceID, bytes32 dataHash)
external
When called, {msg.sender} will be marked as voting in favor of proposal.
@notice Only callable by relayers when Bridge is not paused.
@param chainID ID of chain deposit originated from.
@param depositNonce ID of deposited generated by origin Bridge contract.
@param dataHash Hash of data provided when deposit was made.
@notice Proposal must not have already been passed or executed.
@notice {msg.sender} must not have already voted on proposal.
@notice Emits ProposalEvent
event with status indicating the proposal status.
@notice Emits ProposalVote
event.
cancelProposal(uint8 chainID, uint64 depositNonce, bytes32 dataHash)
public
Executes a deposit proposal that is considered passed using a specified handler contract.
@notice Only callable by relayers when Bridge is not paused.
@param chainID ID of chain deposit originated from.
@param depositNonce ID of deposited generated by origin Bridge contract.
@param dataHash Hash of data originally provided when deposit was made.
@notice Proposal must be past expiry threshold.
@notice Emits ProposalEvent
event with status {Cancelled}.
executeProposal(uint8 chainID, uint64 depositNonce, bytes data, bytes32 resourceID)
external
Executes a deposit proposal that is considered passed using a specified handler contract.
@notice Only callable by relayers when Bridge is not paused.
@param chainID ID of chain deposit originated from.
@param resourceID ResourceID to be used when making deposits.
@param depositNonce ID of deposited generated by origin Bridge contract.
@param data Data originally provided when deposit was made.
@notice Proposal must have Passed status.
@notice Hash of {data} must equal proposal’s {dataHash}.
@notice Emits ProposalEvent
event with status {Executed}.
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. @param addrs Array of addresses to transfer {amounts} to. @param amounts Array of amonuts to transfer to {addrs}.
getRoleMemberCount(bytes32 role) → uint256
public
Returns the number of accounts that have role
. Can be used
together with {getRoleMember} to enumerate all bearers of a role.
getRoleMember(bytes32 role, uint256 index) → address
public
Returns one of the accounts that have role
. index
must be a
value between 0 and {getRoleMemberCount}, non-inclusive.
Role bearers are not sorted in any particular way, and their ordering may
change at any point.
WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
you perform all queries on the same block. See the following
forum post
for more information.
getRoleAdmin(bytes32 role) → bytes32
public
Returns the admin role that controls role
. See {grantRole} and
{revokeRole}.
To change a role’s admin, use {_setRoleAdmin}.
grantRole(bytes32 role, address account)
public
Grants role
to account
.
If account
had not been already granted role
, emits a {RoleGranted}
event.
Requirements:
- the caller must have role
's admin role.
revokeRole(bytes32 role, address account)
public
Revokes role
from account
.
If account
had been granted role
, emits a {RoleRevoked} event.
Requirements:
- the caller must have role
's admin role.
renounceRole(bytes32 role, address account)
public
Revokes role
from the calling account.
Roles are often managed via {grantRole} and {revokeRole}: this function’s
purpose is to provide a mechanism for accounts to lose their privileges
if they are compromised (such as when a trusted device is misplaced).
If the calling account had been granted role
, emits a {RoleRevoked}
event.
Requirements:
- the caller must be account
.
_setupRole(bytes32 role, address account)
internal
Grants role
to account
.
If account
had not been already granted role
, emits a {RoleGranted}
event. Note that unlike {grantRole}, this function doesn’t perform any
checks on the calling account.
This function should only be called from the constructor when setting up the initial roles for the system. Using this function in any other way is effectively circumventing the admin system imposed by {AccessControl}. |
ProposalEvent(uint8 originChainID, uint64 depositNonce, enum Bridge.ProposalStatus status, bytes32 resourceID, bytes32 dataHash)
event
ProposalVote(uint8 originChainID, uint64 depositNonce, enum Bridge.ProposalStatus status, bytes32 resourceID)
event
RoleGranted(bytes32 role, address account, address sender)
event
Emitted when account
is granted role
.
sender
is the account that originated the contract call, an admin role
bearer except when using {_setupRole}.