Skip to content

Commit

Permalink
Merge pull request #219 from poanetwork/develop
Browse files Browse the repository at this point in the history
Merge the develop branch to the master branch, preparation to v2.1.0
  • Loading branch information
akolotov committed May 23, 2019
2 parents 9aeb632 + 46a4862 commit a6e8c72
Show file tree
Hide file tree
Showing 34 changed files with 1,260 additions and 309 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -21,6 +21,9 @@
# contracts build
/src/contracts

# compiled css
*.css

npm-debug.log*
yarn-debug.log*
yarn-error.log*
27 changes: 16 additions & 11 deletions README.md
Expand Up @@ -22,12 +22,13 @@ For a complete picture of the POA Bridge functionality, it is useful to explore

## Bridge UI Application

The UI provides an intuitive interface for assets transfer between networks running the Bridge smart contracts. Users can connect to a web3 wallet such as [Nifty Wallet](https://chrome.google.com/webstore/detail/nifty-wallet/jbdaocneiiinmjbjlgalhcelgbejmnid?hl=en) or [MetaMask](https://metamask.io/) and complete the transfer through a web browser.
The UI provides an intuitive interface for assets transfer between networks running the Bridge smart contracts. Users can connect to a web3 wallet such as [Nifty Wallet](https://github.com/poanetwork/nifty-wallet) or [MetaMask](https://metamask.io/) and complete the transfer through a web browser.

The current implementation allows for several bridge modes.

1. `Native-to-ERC20` Coins on a Home network can be converted to ERC20-compatible tokens on a Foreign network. Coins are locked on the Home side and the corresponding amount of ERC20 tokens are minted on the Foreign side. When the operation is reversed, tokens are burnt on the Foreign side and unlocked in the Home network.
2. `ERC20-to-ERC20` ERC20-compatible tokens on the Foreign network are locked and minted as ERC20-compatible tokens (ERC677 tokens) on the Home network. When transferred from Home to Foreign, they are burnt on the Home side and unlocked in the Foreign network. This can be considered a form of atomic swap when a user swaps the token "X" in network "A" to the token "Y" in network "B".
3. `ERC20-to-Native` Pre-existing tokens in the Foreign network are locked and coins are minted in the Home network. In this mode, the Home network consensus engine invokes Parity's Block Reward contract to mint coins per the bridge contract request.

![Bridge UI](bridge-ui.png)

Expand All @@ -50,7 +51,7 @@ The wallet must be funded to cover gas costs related to the transfer. With the N
- Click the `Transfer` button.
- Confirm the transaction via the web3 wallet.

The same address is used to send a coin from the Home network and receive a token on the Foreign Network. In order to send assets in the opposite direction, change the network in the web3 wallet. This will change the bridge interface to show the selected network on the left side of the bridge.
The same address is used to send a coin from the Home network and receive a token on the Foreign Network. In order to send assets in the opposite direction, change the network in the web3 wallet. This changes the bridge interface to show the selected network on the left side of the bridge.

![Web3 Wallet Change Network](web3wallet_network.gif)

Expand All @@ -65,7 +66,8 @@ The same address is used to send a coin from the Home network and receive a toke
- Wallet Resources
- [MetaMask](https://consensys.zendesk.com/hc/en-us/categories/360001045692-Using-MetaMask)
- [Nifty Wallet](https://poanet.zendesk.com/hc/en-us/articles/360008957634-Nifty-Wallet)
- [AlphaWallet (iOS and Android)](https://alphawallet.github.io/AlphaWallet-Download-Page/)
- [AlphaWallet (iOS and Android)](https://alphawallet.com/)

## Getting Started

The following is an example setup using the POA Sokol testnet as the Home network, and the Ethereum Kovan testnet as the Foreign network. The instructions for the Bridge UI are identical for an `ERC20-to-ERC20` configuration, but the smart contract deployment steps will vary.
Expand All @@ -75,7 +77,7 @@ The following is an example setup using the POA Sokol testnet as the Home networ
- [poa-bridge-contracts](https://github.com/poanetwork/poa-bridge-contracts)
- [token-bridge](https://github.com/poanetwork/token-bridge)
- [node.js](https://nodejs.org/en/download/)
- [AlphaWallet](https://alphawallet.github.io/AlphaWallet-Download-Page/) or [Nifty Wallet](https://chrome.google.com/webstore/detail/nifty-wallet/jbdaocneiiinmjbjlgalhcelgbejmnid?hl=en) or [MetaMask](https://metamask.io/)
- [AlphaWallet](https://alphawallet.com/) or [Nifty Wallet](https://github.com/poanetwork/nifty-wallet) or [MetaMask](https://metamask.io/)

### Example Setup

Expand Down Expand Up @@ -137,12 +139,13 @@ If successful, you will see bridge processes run when you issue a command. For e
* `git clone https://github.com/poanetwork/bridge-ui.git`
* `cd bridge-ui`
* Update submodules
`git submodule update --init --recursive --remote`
`git submodule update --init --recursive`
* Install dependencies
`npm install`
* Create a .env file from the example file[.env.example](.env.example)
_**Note**: The bridge UI configuration should be performed with an unprivileged Linux account or with the following flag `npm install --unsafe-perm`. [More information](https://docs.npmjs.com/misc/scripts#user)_
* Create a .env file from the example file [.env.example](.env.example)
`cp .env.example .env`
* Insert the addresses from the bridgeDeploymentResults.json file into the .env file.
* Insert the addresses from the bridgeDeploymentResults.json file (from step 4) into the .env file. No other changes are needed, see [Env Parameter Details](#env-parameter-details) for information about each parameter.
`cat ../poa-bridge-contracts/deploy/bridgeDeploymentResults.json`
```bash
# HomeBridge address in bridgeDeploymentResults.json
Expand All @@ -154,7 +157,12 @@ If successful, you will see bridge processes run when you issue a command. For e
# public RPC node for Home network
REACT_APP_HOME_HTTP_PARITY_URL=https://sokol.poa.network
```
Explanation:

* Run `npm run start`
* Make sure your web3 wallet (Nifty Wallet, AlphaWallet or MetaMask) is funded and connected to the POA Sokol Network (see step 2)
* Specify an amount and click `Transfer` to complete a cross-chain transaction from Sokol to Kovan

### Env Parameter Details

Name | Description
--------- | -------
Expand Down Expand Up @@ -183,9 +191,6 @@ REACT_APP_TITLE | The title for the bridge UI page. `%c` will be replaced by the
REACT_APP_DESCRIPTION | The meta description for the deployed bridge page.
APP_STYLES | The set of styles to render the bridge UI page. Currently only `classic` is implemented

* Run `npm run start`
* Make sure your web3 wallet (Nifty Wallet, AlphaWallet or MetaMask) is funded and connected to the POA Sokol Network (see step 2)
* Specify an amount and click `Transfer` to complete a cross-chain transaction from Sokol to Kovan

## Testing

Expand Down
4 changes: 2 additions & 2 deletions e2e-script/MetaMask.js
Expand Up @@ -127,12 +127,12 @@ class MetaMask extends Page {
let url;
switch (provider) {
case 77: {
url = "http://10.1.0.102:8545";
url = "http://localhost:8541";
networks.push(177);
break;
}
case 42: {
url = "http://10.1.0.103:8545";
url = "http://localhost:8542";
networks.push(142);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions e2e-script/config.json
@@ -1,7 +1,7 @@
{
"startUrl" : "http://10.1.0.101:3000",
"erc20Url" : "http://10.1.0.104:3000",
"erc20NativeUrl" : "http://10.1.0.105:3000",
"startUrl" : "http://localhost:3000",
"erc20Url" : "http://localhost:3001",
"erc20NativeUrl" : "http://localhost:3002",
"homeAccount": "./e2e-script/accounts/user77_7FC1.json",
"foreignAccount": "./e2e-script/accounts/user42_7FC1.json"
}
52 changes: 6 additions & 46 deletions e2e-script/docker-compose.yml
Expand Up @@ -2,33 +2,21 @@ version: '3'
services:
parity1:
build: parity
networks:
testnet:
ipv4_address: 10.1.0.102
ports:
- "8541:8545"
parity2:
build:
context: parity
dockerfile: Dockerfile-foreign
networks:
testnet:
ipv4_address: 10.1.0.103
ports:
- "8542:8545"
contracts:
build: contracts
networks:
- testnet
command: "true"
redis:
image: "redis:4"
networks:
- testnet
rabbit:
image: "rabbitmq:3-management"
networks:
- testnet
ports:
- "15672:15672"
bridge:
Expand Down Expand Up @@ -57,8 +45,6 @@ services:
- HOME_POLLING_INTERVAL=500
- FOREIGN_POLLING_INTERVAL=500
- ALLOW_HTTP=yes
networks:
- testnet
command: "true"
bridge-erc20:
build: bridge
Expand Down Expand Up @@ -87,8 +73,6 @@ services:
- HOME_POLLING_INTERVAL=500
- FOREIGN_POLLING_INTERVAL=500
- ALLOW_HTTP=yes
networks:
- testnet
command: "true"
bridge-erc20-native:
build: bridge
Expand Down Expand Up @@ -117,16 +101,14 @@ services:
- HOME_POLLING_INTERVAL=500
- FOREIGN_POLLING_INTERVAL=500
- ALLOW_HTTP=yes
networks:
- testnet
command: "true"
ui:
build: ..
environment:
- REACT_APP_HOME_BRIDGE_ADDRESS=0x32198D570fffC7033641F8A9094FFDCaAEF42624
- REACT_APP_FOREIGN_BRIDGE_ADDRESS=0x2B6871b9B02F73fa24F4864322CdC78604207769
- REACT_APP_FOREIGN_HTTP_PARITY_URL=http://10.1.0.103:8545
- REACT_APP_HOME_HTTP_PARITY_URL=http://10.1.0.102:8545
- REACT_APP_FOREIGN_HTTP_PARITY_URL=http://localhost:8542
- REACT_APP_HOME_HTTP_PARITY_URL=http://localhost:8541
- REACT_APP_HOME_NATIVE_NAME=POA
- REACT_APP_HOME_NETWORK_NAME=Sokol
- REACT_APP_FOREIGN_NETWORK_NAME=Kovan
Expand All @@ -142,19 +124,14 @@ services:
- REACT_APP_FOREIGN_GAS_PRICE_SPEED_TYPE=standard
- REACT_APP_FOREIGN_GAS_PRICE_FALLBACK=5000000000
- REACT_APP_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=15000
ports:
- "3000:3000"
networks:
testnet:
ipv4_address: 10.1.0.101
command: "true"
ui-erc20:
build: ..
environment:
- REACT_APP_HOME_BRIDGE_ADDRESS=0x1feB40aD9420b186F019A717c37f5546165d411E
- REACT_APP_FOREIGN_BRIDGE_ADDRESS=0x4a58D6d8D416a5fBCAcf3dC52eb8bE8948E25127
- REACT_APP_FOREIGN_HTTP_PARITY_URL=http://10.1.0.103:8545
- REACT_APP_HOME_HTTP_PARITY_URL=http://10.1.0.102:8545
- REACT_APP_FOREIGN_HTTP_PARITY_URL=http://localhost:8542
- REACT_APP_HOME_HTTP_PARITY_URL=http://localhost:8541
- REACT_APP_HOME_NATIVE_NAME=POA
- REACT_APP_HOME_NETWORK_NAME=Sokol
- REACT_APP_FOREIGN_NETWORK_NAME=Kovan
Expand All @@ -170,19 +147,14 @@ services:
- REACT_APP_FOREIGN_GAS_PRICE_SPEED_TYPE=standard
- REACT_APP_FOREIGN_GAS_PRICE_FALLBACK=5000000000
- REACT_APP_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=15000
ports:
- "3001:3000"
networks:
testnet:
ipv4_address: 10.1.0.104
command: "true"
ui-erc20-native:
build: ..
environment:
- REACT_APP_HOME_BRIDGE_ADDRESS=0x488Af810997eD1730cB3a3918cD83b3216E6eAda
- REACT_APP_FOREIGN_BRIDGE_ADDRESS=0x488Af810997eD1730cB3a3918cD83b3216E6eAda
- REACT_APP_FOREIGN_HTTP_PARITY_URL=http://10.1.0.103:8545
- REACT_APP_HOME_HTTP_PARITY_URL=http://10.1.0.102:8545
- REACT_APP_FOREIGN_HTTP_PARITY_URL=http://localhost:8542
- REACT_APP_HOME_HTTP_PARITY_URL=http://localhost:8541
- REACT_APP_HOME_NATIVE_NAME=POA
- REACT_APP_HOME_NETWORK_NAME=Sokol
- REACT_APP_FOREIGN_NETWORK_NAME=Kovan
Expand All @@ -198,16 +170,4 @@ services:
- REACT_APP_FOREIGN_GAS_PRICE_SPEED_TYPE=standard
- REACT_APP_FOREIGN_GAS_PRICE_FALLBACK=5000000000
- REACT_APP_FOREIGN_GAS_PRICE_UPDATE_INTERVAL=15000
ports:
- "3002:3000"
networks:
testnet:
ipv4_address: 10.1.0.105
command: "true"
networks:
testnet:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.1.0.0/24
2 changes: 1 addition & 1 deletion e2e-script/parity/Dockerfile
@@ -1,4 +1,4 @@
FROM parity/parity:v2.2.11
FROM parity/parity:v2.3.3

WORKDIR /stuff

Expand Down
2 changes: 1 addition & 1 deletion e2e-script/parity/Dockerfile-foreign
@@ -1,4 +1,4 @@
FROM parity/parity:v2.2.11
FROM parity/parity:v2.3.3

WORKDIR /stuff

Expand Down
6 changes: 3 additions & 3 deletions e2e-script/run-tests.sh
Expand Up @@ -15,9 +15,9 @@ docker-compose run -d bridge-erc20-native npm run watcher:collected-signatures
docker-compose run -d bridge-erc20-native npm run watcher:affirmation-request
docker-compose run -d bridge npm run sender:home
docker-compose run -d bridge npm run sender:foreign
docker-compose run -d ui npm start
docker-compose run -d ui-erc20 npm start
docker-compose run -d ui-erc20-native npm start
docker-compose run -d -p 3000:3000 ui npm start
docker-compose run -d -p 3001:3000 ui-erc20 npm start
docker-compose run -d -p 3002:3000 ui-erc20-native npm start
cd ..
npm run startE2e
rc=$?
Expand Down
4 changes: 2 additions & 2 deletions e2e-script/scripts/blocks.js
@@ -1,7 +1,7 @@
const Web3 = require('web3')

const homeWeb3 = new Web3(new Web3.providers.HttpProvider('http://10.1.0.102:8545'))
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider('http://10.1.0.103:8545'))
const homeWeb3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8541'))
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8542'))
const account = '0x7FC1442AB55Da569940Eb750AaD2BAA63DA4010E'
const privateKey = '0x460635eb4ac4287de2d2393985e19b4a9f948ac533453a1044ab8d50330b0df9'
homeWeb3.eth.accounts.wallet.add(privateKey)
Expand Down

0 comments on commit a6e8c72

Please sign in to comment.