These contracts provide the core functionality for the POA bridge. They implement the logic to relay assests between two EVM-based blockchain networks. The contracts collect bridge validator's signatures to approve and facilitate relay operations.
The POA bridge smart contracts are intended to work with the bridge process implemented on NodeJS. Please refer to the bridge process documentation to configure and deploy the bridge.
The POA Bridge allows users to transfer assets between two chains in the Ethereum ecosystem. It is composed of several elements which are located in different POA Network repositories:
Bridge Elements
Currently, the contracts support four types of relay operations:
The POA bridge contracts consist of several components:
AMB-ERC-TO-ERC
mode: the ERC20 token (in fact, the ERC677 extension is used) is deployed on the Home network;ERC-TO-NATIVE
mode: The home network nodes must support consensus engine that allows using a smart contract for block reward calculation;Responsibilities and roles of the bridge:
UserRequestForSignature
events on Home Bridge and sign an approval to relay assets on Foreign networkCollectedSignatures
events on Home Bridge. As soon as enough signatures are collected, transfer all collected signatures to the Foreign Bridge contract.UserRequestForAffirmation
or Transfer
(depending on the bridge mode) events on the Foreign Bridge and send approval to Home Bridge to relay assets from Foreign Network to HomeERC-TO-NATIVE
mode: send ERC20 tokens to the Foreign Bridge to receive native coins from the Home Bridge, send native coins to the Home Bridge to unlock ERC20 tokens from the Foreign Bridge;ARBITRARY-MESSAGE
mode: Invoke Home/Foreign Bridge to send a message that will be executed on the other Network as an arbitrary contract method invocation;AMB-ERC-TO-ERC
mode: transfer ERC20 tokens to the Foreign Mediator which will interact with Foreign AMB Bridge to mint ERC20 tokens on the Home Network, transfer ERC20 tokens to the Home Mediator which will interact with Home AMB Bridge to unlock ERC20 tokens on Foreign network.There are two ways to deploy contracts:
npm install
Please read the README.md in the deploy
folder for instructions and .env file configuration
npm test
npm run coverage
The results can be found in the coverage
directory.
Fattened contracts can be used to verify the contract code in a block explorer like BlockScout or Etherscan. The following command will prepare flattened version of the contracts:
npm run flatten
The flattened contracts can be found in the flats
directory.
Docker and Docker Compose can be used to deploy contracts without NodeJS installed on the system.
If you are on Linux, we recommend you create a docker group and add your user to it, so that you can use the CLI without sudo
.
docker-compose up --build
Note: The container must be rebuilt every time the code in a contract or deployment script is changed.
.env
file in the deploy
directory as described in the deployment README.md.docker-compose run bridge-contracts deploy.sh
or with Linux:
./deploy.sh
docker-compose images bridge-contracts
flats
directory.
docker cp name-of-your-container:/contracts/flats ./
$ docker-compose run bridge-contracts bash
$ npm test
$ npm run coverage
If the container is no longer needed, it can be shutdown:
docker-compose down
The GAS_CONSUMPTION file includes Min, Max, and Avg gas consumption figures for contracts associated with each bridge mode.
The REWARD_MANAGEMENT file includes information on how rewards are distributed among the validators on each bridge mode.
To test the bridge scripts in ERC20-to-ERC20 mode on a testnet like Sokol or Kovan, you must deploy an ERC20 token to the foreign network. This can be done by running the following command:
cd deploy
node testenv-deploy.js token
or with Docker:
./deploy.sh token
See the CONTRIBUTING document for contribution, testing and pull request protocol.
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.