All Projects → poanetwork → Tokenbridge Contracts

poanetwork / Tokenbridge Contracts

Licence: gpl-3.0
Smart contracts for TokenBridge

Programming Languages

javascript
184084 projects - #8 most used programming language
solidity
1140 projects

Labels

Projects that are alternatives of or similar to Tokenbridge Contracts

Matterbridge
bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Stars: ✭ 4,452 (+4846.67%)
Mutual labels:  bridge
Creative Cloud Linux
PlayOnLinux install script for Adobe Creative Cloud
Stars: ✭ 725 (+705.56%)
Mutual labels:  bridge
Ethudp
Ethernet over UDP, similar of VXLAN, transport Ethernet packet via UDP
Stars: ✭ 43 (-52.22%)
Mutual labels:  bridge
Mautrix Whatsapp
A Matrix-WhatsApp puppeting bridge
Stars: ✭ 484 (+437.78%)
Mutual labels:  bridge
Jpype
JPype is cross language bridge to allow python programs full access to java class libraries.
Stars: ✭ 685 (+661.11%)
Mutual labels:  bridge
Wkwebviewjavascriptbridge
🌉 A Bridge for Sending Messages between Swift and JavaScript in WKWebViews.
Stars: ✭ 863 (+858.89%)
Mutual labels:  bridge
Pg Amqp Bridge
Send messages to RabbitMQ from PostgreSQL
Stars: ✭ 334 (+271.11%)
Mutual labels:  bridge
Soluble Japha
PHP Java integration
Stars: ✭ 59 (-34.44%)
Mutual labels:  bridge
Hmq
High performance mqtt broker
Stars: ✭ 722 (+702.22%)
Mutual labels:  bridge
React Native Create Bridge
A CLI tool that bridges React Native modules & UI components with ease 🎉
Stars: ✭ 966 (+973.33%)
Mutual labels:  bridge
Mautrix Telegram
A Matrix-Telegram hybrid puppeting/relaybot bridge
Stars: ✭ 508 (+464.44%)
Mutual labels:  bridge
Qtsharp
Mono/.NET bindings for Qt
Stars: ✭ 532 (+491.11%)
Mutual labels:  bridge
Mautrix Hangouts
A Matrix-Hangouts puppeting bridge
Stars: ✭ 29 (-67.78%)
Mutual labels:  bridge
Gravity
Gravity Programming Language
Stars: ✭ 3,968 (+4308.89%)
Mutual labels:  bridge
Psr Http Message Bridge
PSR-7 Bridge
Stars: ✭ 1,034 (+1048.89%)
Mutual labels:  bridge
Matrix Appservice Discord
A bridge between Matrix and Discord.
Stars: ✭ 383 (+325.56%)
Mutual labels:  bridge
Lin
Parser for contract bridge "lin" notation
Stars: ✭ 5 (-94.44%)
Mutual labels:  bridge
Btc Parachain
BTC-Parachain: Trustless Bitcoin on Polkadot
Stars: ✭ 70 (-22.22%)
Mutual labels:  bridge
Vue Bridge Webview
javascript bridge android/ios webview
Stars: ✭ 52 (-42.22%)
Mutual labels:  bridge
Emodbus
Modbus library for both RTU and TCP protocols. Primarily developed on and for ESP32 MCUs.
Stars: ✭ 29 (-67.78%)
Mutual labels:  bridge

Join the chat at https://gitter.im/poanetwork/poa-bridge Build Status Coverage Status

POA Bridge Smart Contracts

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.

Bridge Overview

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

  1. Solidity smart contracts, contained in this repository.
  2. Token Bridge. A NodeJS oracle responsible for listening to events and sending transactions to authorize asset transfers.
  3. Bridge UI Application. A DApp interface to transfer tokens and coins between chains.
  4. Bridge Monitor. A tool for checking balances and unprocessed events in bridged networks.
  5. Bridge Deployment Playbooks. Manages configuration instructions for remote deployments.

Bridge Smart Contracts Summary

Operations

Currently, the contracts support four types of relay operations:

  • Tokenize the native coin in one blockchain network (Home) into an ERC20 token in another network (Foreign).
  • Swap a token presented by an existing ERC20 contract in a Foreign network into an ERC20 token in the Home network, where one pair of bridge contracts corresponds to one pair of ERC20 tokens.
  • to mint new native coins in Home blockchain network from a token presented by an existing ERC20 contract in a Foreign network.
  • Transfer arbitrary data between two blockchain networks as so the data could be interpreted as an arbitrary contract method invocation.

Components

The POA bridge contracts consist of several components:

  • The Home Bridge smart contract. This is currently deployed in POA.Network.
  • The Foreign Bridge smart contract. This is deployed in the Ethereum Mainnet.
  • Depending on the type of relay operations the following components are also used:
    • in NATIVE-TO-ERC mode: the ERC20 token (in fact, the ERC677 extension is used) is deployed on the Foreign network;
    • in AMB-NATIVE-TO-ERC mode: the ERC20 token (in fact, the ERC677 extension is used) is deployed on the Foreign network;
    • in ERC-TO-ERC mode: the ERC20 token (in fact, the ERC677 extension is used) is deployed on the Home network;
    • in AMB-ERC-TO-ERC mode: the ERC20 token (in fact, the ERC677 extension is used) is deployed on the Home network;
    • in ERC-TO-NATIVE mode: The home network nodes must support consensus engine that allows using a smart contract for block reward calculation;
  • The Validators smart contract is deployed in both the POA.Network and the Ethereum Mainnet.

Bridge Roles and Responsibilities

Responsibilities and roles of the bridge:

  • Administrator role (representation of a multisig contract):
    • add/remove validators
    • set daily limits on both bridges
    • set maximum per transaction limit on both bridges
    • set minimum per transaction limit on both bridges
    • upgrade contracts in case of vulnerability
    • set minimum required signatures from validators in order to relay a user's transaction
  • Validator role:
    • provide 100% uptime to relay transactions
    • listen for UserRequestForSignature events on Home Bridge and sign an approval to relay assets on Foreign network
    • listen for CollectedSignatures events on Home Bridge. As soon as enough signatures are collected, transfer all collected signatures to the Foreign Bridge contract.
    • listen for 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 Home
  • User role:
    • sends assets to Bridge contracts:
      • in NATIVE-TO-ERC mode: send native coins to the Home Bridge to receive ERC20 tokens from the Foreign Bridge, send ERC20 tokens to the Foreign Bridge to unlock native coins from the Home Bridge;
      • in ERC-TO-ERC mode: transfer ERC20 tokens to the Foreign Bridge to mint ERC20 tokens on the Home Network, transfer ERC20 tokens to the Home Bridge to unlock ERC20 tokens on Foreign networks;
      • in ERC-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;
      • in 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;
      • in 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.
      • in AMB-NATIVE-TO-ERC mode: send native coins to the Home Mediator which will interact with Home AMB Bridge to mint ERC20 tokens on the Foreign Network, transfer ERC20 tokens to the Foreign Mediator which will interact with Foreign AMB Bridge to unlock native coins from Home network.
      • in AMB-ERC-TO-NATIVE mode: send ERC20 tokens to the Foreign Mediator which will interact with Foreign AMB Bridge to receive native coins from the Home Mediator on the Home Network, send native coins to the Home Mediator which will interact with Home AMB Bridge to unlock ERC20 tokens from the Foreign Mediator.
      • in MULTI-AMB-ERC-TO-ERC mode: transfer any ERC20/ERC677 tokens to the Foreign Mediator which will interact with Foreign AMB Bridge to mint ERC677 tokens on the Home Network, transfer ERC677 tokens to the Home Mediator which will interact with Home AMB Bridge to unlock associated ERC20/ERC677 tokens on the Foreign network.

Usage

There are two ways to deploy contracts:

  • install and use NodeJS
  • use Docker to deploy

Deployment with NodeJS

Install Dependencies

npm install

Deploy

Please read the README.md in the deploy folder for instructions and .env file configuration

Test

npm test

Run coverage tests

npm run coverage

The results can be found in the coverage directory.

Flatten

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.

Deployment in the Docker environment

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.

Prepare the docker container

docker-compose up --build

Note: The container must be rebuilt every time the code in a contract or deployment script is changed.

Deploy the contracts

  1. Create the .env file in the deploy directory as described in the deployment README.md.
  2. Run deployment process:
    docker-compose run bridge-contracts deploy.sh
    
    or with Linux:
    ./deploy.sh
    

Copy flatten sources (if needed)

  1. Discover the container name:
    docker-compose images bridge-contracts
    
  2. In the following command, use the container name to copy the flattened contracts code to the current working directory. The contracts will be located in the flats directory.
    docker cp name-of-your-container:/contracts/flats ./
    

Test contract and run coverage (if needed)

$ docker-compose run bridge-contracts bash
$ npm test
$ npm run coverage

Shutdown the container

If the container is no longer needed, it can be shutdown:

docker-compose down

Gas Consumption

The GAS_CONSUMPTION file includes Min, Max, and Avg gas consumption figures for contracts associated with each bridge mode.

Reward Management

The REWARD_MANAGEMENT file includes information on how rewards are distributed among the validators on each bridge mode.

Testing environment

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

For testing bridge scripts in ERC20-to-NATIVE mode, you can deploy an interest receiver to the foreign network. This can be done by running the following command:

cd deploy
node testenv-deploy.js interestReceiver

or with Docker:

./deploy.sh interestReceiver

Contributing

See the CONTRIBUTING document for contribution, testing and pull request protocol.

License

License: GPL v3.0

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].