BridgeBase
Inherits: Receiver, OwnableUpgradeable, UUPSUpgradeable
State Variables
connectors
Mapping of connectors to the token address
mapping(address => IBridgeConnector) public connectors;
localAddress
Mapping of source and destination addresses to the connector address
mapping(address => address) public localAddress;
bridgeRoots
The bridge roots of finalized epochs
mapping(uint256 => bytes32) public bridgeRoots;
lightClient
The light client used to get the finalized bridge root
IBridgeLightClient public lightClient;
tokenAddresses
The addresses of the registered tokens
address[] public tokenAddresses;
finalizedEpoch
The epoch of the last finalized epoch
uint256 public finalizedEpoch;
appliedEpoch
The epoch of the last applied epoch
uint256 public appliedEpoch;
finalizationInterval
The interval between epoch finalizations
uint256 public finalizationInterval;
lastFinalizedBlock
The block number of the last finalized epoch
uint256 public lastFinalizedBlock;
feeMultiplierFinalize
This multiplier is used to calculate the proper part of the relaying cost for bridging actions(state finalization)
uint256 public feeMultiplierFinalize;
feeMultiplierApply
This multiplier is used to calculate the proper part of the relaying cost for bridging actions(state application)
uint256 public feeMultiplierApply;
registrationFee
Global connector registration fee. Connectors must pay this fee to register
uint256 public registrationFee;
settlementFee
Global transaction settlement fee. Connector must pay settlementFee * numberOfTransactions
to settle the transaction
uint256 public settlementFee;
__gap
gap for upgrade safety <- can be used to add new storage variables(using up to 49 32 byte slots) in new versions of this contract If used, decrease the number of slots in the next contract that inherits this one(ex. uint256[48] __gap;)
uint256[49] __gap;
Functions
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor();
__BridgeBase_init
function __BridgeBase_init(
IBridgeLightClient _lightClient,
uint256 _finalizationInterval,
uint256 _feeMultiplierFinalize,
uint256 _feeMultiplierApply,
uint256 _registrationFee,
uint256 _settlementFee
) internal onlyInitializing;
__BridgeBase_init_unchained
function __BridgeBase_init_unchained(
IBridgeLightClient _lightClient,
uint256 _finalizationInterval,
uint256 _feeMultiplierFinalize,
uint256 _feeMultiplierApply,
uint256 _registrationFee,
uint256 _settlementFee
) internal onlyInitializing;
_authorizeUpgrade
function _authorizeUpgrade(address newImplementation) internal override onlyOwner;
setFeeMultiplierFinalize
Only the owner can call this function.
Sets the fee multiplier for finalizing epochs.
function setFeeMultiplierFinalize(uint256 _feeMultiplierFinalize) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_feeMultiplierFinalize | uint256 | The fee multiplier for finalizing epochs. |
setFeeMultiplierApply
Only the owner can call this function.
Sets the fee multiplier for applying epochs.
function setFeeMultiplierApply(uint256 _feeMultiplierApply) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_feeMultiplierApply | uint256 | The fee multiplier for applying epochs. |
setSettlementFee
Only the owner can call this function.
Sets the settlement fee.
function setSettlementFee(uint256 _settlementFee) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_settlementFee | uint256 | The settlement fee to be set. |
setFinalizationInterval
Only the owner can call this function.
Sets the finalization interval.
function setFinalizationInterval(uint256 _finalizationInterval) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_finalizationInterval | uint256 | The finalization interval to be set. |
setLightClient
Only the owner can call this function.
Sets the light client.
function setLightClient(IBridgeLightClient _lightClient) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_lightClient | IBridgeLightClient | The address of the light client contract. |
setConnectorOwner
Only the owner can call this function.
Changes the connector owner.
function setConnectorOwner(address connector_address, address newOwner) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
connector_address | address | The connector address. |
newOwner | address | The new owner address. |
removeConnector
Only the owner can call this function.
Removes a connector from the bridge.
function removeConnector(address connector_address) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
connector_address | address | The connector address. |
withdrawFunds
Only the owner can call this function.
Withdraws the funds from the contract.
function withdrawFunds() public onlyOwner;
registeredTokens
function registeredTokens() public view returns (address[] memory);
Returns
Name | Type | Description |
---|---|---|
<none> | address[] | An array of addresses of the registered tokens. |
getBridgeRoot
Gets the bridge root for the given epoch.
function getBridgeRoot(uint256 epoch) public view returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
epoch | uint256 | The epoch for which the bridge root is to be retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The bridge root as a bytes32 value. |
getBridgeRoot
Returns the latest bridge root.
DO NOT REMOVE! Is used by the node to put it to the pillar block
function getBridgeRoot() public view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The latest bridge root as a bytes32 value. |
registerConnector
Registers a contract with the EthBridge by providing a connector contract.
function registerConnector(IBridgeConnector connector) public payable;
Parameters
Name | Type | Description |
---|---|---|
connector | IBridgeConnector | The address of the connector contract. |
removeTokenAddress
function removeTokenAddress(address tokenAddress) internal;
delistConnector
function delistConnector(IBridgeConnector connector) internal;
applyState
Applies the given state with proof to the contracts.
function applyState(SharedStructs.StateWithProof calldata state_with_proof) public;
Parameters
Name | Type | Description |
---|---|---|
state_with_proof | SharedStructs.StateWithProof | The state with proof to be applied. |
shouldFinalizeEpoch
Checks whether the current epoch should be finalized.
DO NOT REMOVE! Is used by the node to identify if we need to call a finalization
function shouldFinalizeEpoch() public view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A boolean value indicating whether the current epoch should be finalized. |
finalizeEpoch
Finalizes the current epoch.
function finalizeEpoch() public;
getStateWithProof
function getStateWithProof() public view returns (SharedStructs.StateWithProof memory ret);
Returns
Name | Type | Description |
---|---|---|
ret | SharedStructs.StateWithProof | finalized states with proof for all tokens |
Events
Finalized
Events
event Finalized(uint256 indexed epoch, bytes32 bridgeRoot);
ConnectorRegistered
event ConnectorRegistered(address indexed connector, address indexed token_source, address indexed token_destination);
ConnectorDelisted
event ConnectorDelisted(address indexed connector, uint256 indexed epoch);