Smart Contracts
The page describes all smart contracts of the system with all the functions.
Last updated
The page describes all smart contracts of the system with all the functions.
Last updated
All the system contracts are described below. To find entrypoints to each contract, follow here:
The Registry contract serves as a central configuration store for the system.
constructor(address _rolesManager, uint16 _network)
Initializes the contract with a roles manager address and network identifier
Validates: _rolesManager is not zero address, _network is not zero
getRolesManager()
, getFeesReceiver()
, getInterNetworkExecutor()
, getCentralGateway()
, getVaultToken()
, getNetwork()
, getGateways(uint16)
, getTokensReceivers(uint16)
, getProtocolFee()
, getVaultFee()
Getter functions for various system parameters
Validation: Some getters (e.g., getFeesReceiver) revert if the value is not set
setSpecificGateway(uint16 _network, bytes32 _gateway)
, setTokensReceiver(uint16 _network, bytes32 _receiver)
, setCentralGateway(address _gateway)
, setRolesManager(address _rolesManager)
, setFeesReceiver(address _feesReceiver)
, setInterNetworkExecutor(address _interNetworkExecutor)
, setIntraNetworkExecutor(address _intraNetworkExecutor)
, setVaultToken(address _vaultToken)
, setProtocolFee(uint256 _protocolFee)
, setVaultFee(uint256 _vaultFee)
Setter functions for various system parameters
Limitation: Can only be called by an address with the OPERATOR role
Validation: Some setters (e.g., setVaultToken) check for zero address, setProtocolFee and setVaultFee check for valid fee range (0 < fee <= 100)
The RolesManager contract handles role-based access control for the system.
constructor(address defaultAdmin)
Initializes the contract, granting DEFAULT_ADMIN_ROLE and OPERATOR role to the defaultAdmin
grantOperator(address _operator)
, revokeOperator(address _operator)
Grant or revoke the OPERATOR role
Limitation: Can only be called by an address with the DEFAULT_ADMIN_ROLE
hasRole(address account, bytes32 role)
Checks if an account has a specific role
constructor(IRegistry _registry, IVaultDeployer _vaultDeployer)
Initializes the contract with registry and vault deployer addresses
Deploys a new vault
swap(InterNetworkSwapActions calldata params)
Initiate cross-network swap.
Validation: Checks for valid token addresses, non-zero amounts, and valid swap data
Limitation: Can only swap to or from the vault token
storeMessage(CrossChainEVMMessage calldata message)
Stores a cross-chain message
Limitation: Can only be called by the central gateway
Validation: Checks for duplicate messages
execute(ExecutionMessage calldata message)
Executes a stored cross-chain message
Limitation: Can only be called by an authorized message broadcaster
Validation: Checks for message existence and prevents double execution
The IntraNetworkExecutor contract handles token swaps within the same network.
constructor(IRegistry _registry)
Initializes the contract with a registry address
swap(SwapAction calldata params)
Executes an intra-network swap
Validation: Checks for valid token addresses, non-zero amounts, and valid swap data
The Gateway contract handles cross-network message passing and token bridging.
constructor(IRegistry _registry)
Initializes the contract with a registry address
setMessagingProtocolGateways(uint16 network, address gateway)
Sets the gateway for a specific network
Limitation: Can only be called by an address with the OPERATOR role
processMessage(CrossChainEVMMessage calldata message)
Processes an incoming cross-chain message
Limitation: Can only be called by a trusted gateway for the source network
publishMessage(GatewayAction calldata message)
Publishes a cross-chain message to another network
Limitation: Can only be called by the inter-network executor
receiveTokens(address token, uint256 amount)
Receives tokens from another network and adds them to the vault
Validation: Transfers tokens to the vault and calls addReserves
The OneLayerGateway contract is an alternative gateway implementation.
constructor(IRegistry _registry)
Initializes the contract with a registry address
publishMessage(GatewayAction calldata message)
Publishes a cross-chain message
Limitation: Can only be called by the central gateway
receiveMessage(CrossChainMessage calldata message)
Receives a cross-chain message and forwards it to the central gateway
Limitation: Can only be called by an authorized message broadcaster
The Vault contract manages token deposits, withdrawals, and bridging.
constructor(address _token, address _executor, address _registry)
Initializes the contract with token, executor, and registry addresses
getShareValue(uint256 _shares)
Calculates the token value of a given number of shares
deposit(uint256 _amount)
Allows users to deposit tokens and receive shares
Validation: Checks for non-zero amount
withdraw(uint256 _shares)
Allows users to withdraw tokens by burning shares
Validation: Checks for sufficient balance and shares
addFees(uint256 amount)
Adds fees to the vault
Limitation: Can only be called by allowed reserve modifiers (central gateway or executor)
Validation: Checks for non-zero amount
addReserves(uint256 amount)
Adds reserves to the vault
Limitation: Can only be called by allowed reserve modifiers
Validation: Checks for non-zero amount
requestFunds(uint256 amount)
Allows the executor to request funds from the vault
Limitation: Can only be called by the executor
Validation: Checks for sufficient balance
bridge(uint16 networkIdentifier, uint256 amount)
Bridges tokens to another network
Limitation: Can only be called by an address with the VAULT_BRIDGE_AUTHORITY role
Validation: Checks for sufficient balance
The VaultDeployer contract is responsible for deploying new Vault instances.
deployVault(address _token, address _executor, address _registry)
Deploys a new Vault contract
Returns the address of the newly deployed Vault
The CommonExecutor is an abstract contract providing common functionality for executors.
constructor(IRegistry _registry)
Initializes the contract with a registry address
_valueIn(IERC20 tokenA, uint256 amount)
Internal function to handle token input
Validation: Checks for sufficient value if the token is native currency
_swap(IERC20 tokenA, uint256 amount, address swapContract, bytes calldata swapData)
Internal function to perform a token swap
_deliverTokens(IERC20 tokenB, address receiver)
Internal function to deliver tokens to a receiver
_transferFees(IERC20 tokenA, uint256 amount)
Internal function to transfer fees
The InterNetworkExecutor contract handles cross-network token swaps. Details of the flow can be found in the page