Smart Contracts

The page describes all smart contracts of the system with all the functions.

Detailed Description of Solidity Contracts

All the system contracts are described below. To find entrypoints to each contract, follow here:

Registry

The Registry contract serves as a central configuration store for the system.

Functions:

  1. 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

  2. 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

  3. 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)

RolesManager

The RolesManager contract handles role-based access control for the system.

Functions:

  1. constructor(address defaultAdmin)

    • Initializes the contract, granting DEFAULT_ADMIN_ROLE and OPERATOR role to the defaultAdmin

  2. 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

  3. hasRole(address account, bytes32 role)

    • Checks if an account has a specific role

InterNetworkExecutor

The InterNetworkExecutor contract handles cross-network token swaps. Details of the flow can be found in the Interchain Swap page

Functions:

  1. constructor(IRegistry _registry, IVaultDeployer _vaultDeployer)

    • Initializes the contract with registry and vault deployer addresses

    • Deploys a new vault

  2. 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

  3. storeMessage(CrossChainEVMMessage calldata message)

    • Stores a cross-chain message

    • Limitation: Can only be called by the central gateway

    • Validation: Checks for duplicate messages

  4. 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

IntraNetworkExecutor

The IntraNetworkExecutor contract handles token swaps within the same network.

Functions:

  1. constructor(IRegistry _registry)

    • Initializes the contract with a registry address

  2. swap(SwapAction calldata params)

    • Executes an intra-network swap

    • Validation: Checks for valid token addresses, non-zero amounts, and valid swap data

Gateway

The Gateway contract handles cross-network message passing and token bridging.

Functions:

  1. constructor(IRegistry _registry)

    • Initializes the contract with a registry address

  2. setMessagingProtocolGateways(uint16 network, address gateway)

    • Sets the gateway for a specific network

    • Limitation: Can only be called by an address with the OPERATOR role

  3. processMessage(CrossChainEVMMessage calldata message)

    • Processes an incoming cross-chain message

    • Limitation: Can only be called by a trusted gateway for the source network

  4. publishMessage(GatewayAction calldata message)

    • Publishes a cross-chain message to another network

    • Limitation: Can only be called by the inter-network executor

  5. 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

OneLayerGateway

The OneLayerGateway contract is an alternative gateway implementation.

Functions:

  1. constructor(IRegistry _registry)

    • Initializes the contract with a registry address

  2. publishMessage(GatewayAction calldata message)

    • Publishes a cross-chain message

    • Limitation: Can only be called by the central gateway

  3. 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

Vault

The Vault contract manages token deposits, withdrawals, and bridging.

Functions:

  1. constructor(address _token, address _executor, address _registry)

    • Initializes the contract with token, executor, and registry addresses

  2. getShareValue(uint256 _shares)

    • Calculates the token value of a given number of shares

  3. deposit(uint256 _amount)

    • Allows users to deposit tokens and receive shares

    • Validation: Checks for non-zero amount

  4. withdraw(uint256 _shares)

    • Allows users to withdraw tokens by burning shares

    • Validation: Checks for sufficient balance and shares

  5. 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

  6. addReserves(uint256 amount)

    • Adds reserves to the vault

    • Limitation: Can only be called by allowed reserve modifiers

    • Validation: Checks for non-zero amount

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

  8. 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

VaultDeployer

The VaultDeployer contract is responsible for deploying new Vault instances.

Functions:

  1. deployVault(address _token, address _executor, address _registry)

    • Deploys a new Vault contract

    • Returns the address of the newly deployed Vault

CommonExecutor

The CommonExecutor is an abstract contract providing common functionality for executors.

Functions:

  1. constructor(IRegistry _registry)

    • Initializes the contract with a registry address

  2. _valueIn(IERC20 tokenA, uint256 amount)

    • Internal function to handle token input

    • Validation: Checks for sufficient value if the token is native currency

  3. _swap(IERC20 tokenA, uint256 amount, address swapContract, bytes calldata swapData)

    • Internal function to perform a token swap

  4. _deliverTokens(IERC20 tokenB, address receiver)

    • Internal function to deliver tokens to a receiver

  5. _transferFees(IERC20 tokenA, uint256 amount)

    • Internal function to transfer fees

Diagram Code
classDiagram
    class Registry {
        +getRolesManager()
        +getFeesReceiver()
        +getInterNetworkExecutor()
        +getCentralGateway()
        +getVaultToken()
        +getNetwork()
        +getGateways()
        +getTokensReceivers()
        +getProtocolFee()
        +getVaultFee()
    }

    class RolesManager {
        +OPERATOR
        +MESSAGES_BROADCASTER
        +VAULT_BRIDGE_AUTHORITY
        +grantOperator()
        +revokeOperator()
        +hasRole()
    }

    class InterNetworkExecutor {
        +swap()
        +storeMessage()
        +execute()
    }

    class IntraNetworkExecutor {
        +swap()
    }

    class Gateway {
        +processMessage()
        +publishMessage()
        +bridge()
        +receiveTokens()
    }

    class OneLayerGateway {
        +publishMessage()
        +receiveMessage()
    }

    class Vault {
        +deposit()
        +withdraw()
        +addFees()
        +addReserves()
        +requestFunds()
        +bridge()
    }

    class VaultDeployer {
        +deployVault()
    }

    class CommonExecutor {
        #_valueIn()
        #_swap()
        #_deliverTokens()
        #_transferFees()
    }

    InterNetworkExecutor --|> CommonExecutor
    IntraNetworkExecutor --|> CommonExecutor

    Registry ..> RolesManager : uses
    InterNetworkExecutor ..> Registry : uses
    IntraNetworkExecutor ..> Registry : uses
    Gateway ..> Registry : uses
    OneLayerGateway ..> Registry : uses
    Vault ..> Registry : uses

    InterNetworkExecutor ..> Gateway : uses
    InterNetworkExecutor ..> Vault : uses
    Gateway ..> InterNetworkExecutor : uses
    OneLayerGateway ..> Gateway : uses
    Vault ..> Gateway : uses

    VaultDeployer ..> Vault : deploys

    CommonExecutor ..> Registry : uses

Last updated