BridgeBase

Git Source

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

NameTypeDescription
_feeMultiplierFinalizeuint256The 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

NameTypeDescription
_feeMultiplierApplyuint256The fee multiplier for applying epochs.

setSettlementFee

Only the owner can call this function.

Sets the settlement fee.

function setSettlementFee(uint256 _settlementFee) public onlyOwner;

Parameters

NameTypeDescription
_settlementFeeuint256The settlement fee to be set.

setFinalizationInterval

Only the owner can call this function.

Sets the finalization interval.

function setFinalizationInterval(uint256 _finalizationInterval) public onlyOwner;

Parameters

NameTypeDescription
_finalizationIntervaluint256The finalization interval to be set.

setLightClient

Only the owner can call this function.

Sets the light client.

function setLightClient(IBridgeLightClient _lightClient) public onlyOwner;

Parameters

NameTypeDescription
_lightClientIBridgeLightClientThe 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

NameTypeDescription
connector_addressaddressThe connector address.
newOwneraddressThe 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

NameTypeDescription
connector_addressaddressThe 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

NameTypeDescription
<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

NameTypeDescription
epochuint256The epoch for which the bridge root is to be retrieved.

Returns

NameTypeDescription
<none>bytes32The 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

NameTypeDescription
<none>bytes32The 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

NameTypeDescription
connectorIBridgeConnectorThe 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

NameTypeDescription
state_with_proofSharedStructs.StateWithProofThe 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

NameTypeDescription
<none>boolA 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

NameTypeDescription
retSharedStructs.StateWithProoffinalized 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);