Dfinance peg zone smart contracts implementation, based on PoA (Proof of Authority) government model, supports ETH and any ERC20 approved token.
Allowing to move ETH and ERC20 tokens between Ethereum blockchain and DFinance Blockchain.
Right now security is reached by PoA validators, that inspected by dfinance community, later it should be replaced with Proof of Stake (PoS) algorithm to reach more decentralization.
This work is in progress, but general functionality is already implemented:
- N/2+1 validators needed to reach consensus
- Allowing to remove/add validators by consensus
- Validator takes fees for their support
- Validator can propose for a listing any ERC20 token
- Support of a minimum exchange amount and capacity of any ETH/ERC20 token
- Allowing to lock ETH/ERC20 tokens
- Allowing to withdraw ETH/ERC20 tokens
- Basic migration implemented
- Basic pause/resume function implemented for safe migration
In a nutshell, main motivation to use multiple native currencies from different blockchains inside dfinance blockchain, is that it will provide more liquidity for financial derivatives and financial operations and will not be limited by one ecosystem. This idea opens new doors for a many use cases we can bring to blockchain technology such as DeFi, Swaps, Futures, Options.
During our development we are going to make the same solutions for popular blockchains, such as Bitcoin, EOS, Tron, Lisk, etc.
This repository contains only smart contract part, it doesnt include relay node part, and Cosmos/WB part (module for Wallets Blockchain), described initiatives will be announced later.
For easy explanation let's make a small glossary:
Currency
- Any ETH/ERC20 tokenValidator
- Validator account involved in PoA consensusPeggy
- Peg zone allowing to move tokens between chainsConsensus
- When any action requires validators N/2+1 approve, where N is total amount of PoA validatorsmETH
- Example currency, 1:1 to ETH, but exists on dfinance blockchain
So let's look at ETH to mETH UML as example
mETH to ETH conversion going to work in the same way, but lock will start at dfinance blockchain, and withdraw will happen at Ethereum blockchain.
Current repository contains smart contracts part like:
- PoAGovernment.sol - Implements validators logic and PoA consensus logic on actions during peg zone life cycle
- Bridge.sol - Implements bridge to lock/withdraw Ethereum and any listed ERC20 tokens, when user want to move his ETH or ERC20 tokens to dfinance blockchain
- BankStorage.sol - Keeps ETH or ERC20 tokens and split fees between validators
In PoA implementations we have list of validators, maximum is 11, minimum is 3. Each sensitive call to Bridge done under validation consensus, means any validator can initiate a transaction to Bridge contract or to itself contract (in case if needs to add new validator or remove it and etc), then, once transaction reaches N/2+1 confirmations from the rest of validators, transaction could be executed.
Fees splits between all active validators, and if value can't be divided without reminder, smart contract will save reminder for next exchange.
To get accrued fees validator should make a call request to BankStorage contract with the amount and address of currency he wants to withdraw.
Requirements:
Installation:
yarn install
After execution of described commands it should be possible to launch tests, migrations.
There is few migrations scripts:
- BankStorageFactory - Migrations for BankStorage contract, based on factory
- PoAFactory migration - Migrations for PoAGovernment contract, same here based on factory
- BridgeFactory migration - Migration for Bridge contract, based on factory
- Bridge creation - Creating new Bridge / PoA / BankStorage instances, connect them (ownership, etc), based on previously created factories
To launch migration we have to provide correct environment variables.
To deploy BankStorageFactory:
CONTRACT=BankStorage ACCOUNT=0x5195.... truffle migrate
Where ACCOUNT
is deployer account address, so replace value with your own.
To deploy PoAGovernmentFactory:
CONTRACT=PoA ACCOUNT=0x5195.... truffle migrate
To deploy BridgeFactory:
CONTRACT=Bridge ACCOUNT=0x5195.... BANK_STORAGE_FACTORY=0x4579... POA_FACTORY=0xc6C11... truffle migrate
Where both BANK_STORAGE_FACTORY
and POA_FACTORY
values (addresses) could be copied from previous two commands outputs (where we deploy BankStorageFactory and PoAGovernmentFactory).
To deploy new Bridge instance:
CONTRACT=NewBridge ACCOUNT=0x5195.... BRIDGE_FACTORY=0x4579... ETH_ADDRESSESS=0x4579...,0x2f39... ETH_CAPACITY=1000000000000000000000 ETH_MIN_EXCHANGE=1000 ETH_FEE_PERCENTAGE=10 GAS_LIMIT=6000000 WB_ADDRESSES=wallets19a9...,wallets17lja...,wallets1mv2ex... truffle migrate
Where:
BRIDGE_FACTORY
- Could be copied from previous command (where we deploy BridgeFactory)ETH_ADDRESSES
- Comma seperated string contains initial validators ETH addressesWB_ADDRESSES
- Comma seperated string contains initial validators WB addressesETH_CAPACITY
- Maximum capacity for ETH exchange contract in WEIETH_MIN_EXCHANGE
- Minimum ETH amount to exchange in WEIETH_FEE_PERCENTAGE
- Fee percent that validator takes for their work for ETH exchange, minimum is 1, maximum is 9999 (normalized percent value, e.g. 100 is 1%, 1 is 0.01%, 9999 is 99.99%)
It's all, to see how to work with deployed contracts visit our (documentation)(/#docs).
When deploy to ropsten, choose ropsten network via --network
parameter and add MNEMONIC
:
.... MNEMONIC="mnemonic words from deployer address account" truffle migrate --network ropsten
Where:
MNEMONIC
- is usually 12 words of account mnemonic of deployer.
Launch ganache-cli
and run:
truffle test
You can look at implemented tests at test folder in current repository.
The code covered with tests, however documentation not generated yet.
Current project is under development and going to evolve together with other parts of dfinance blockchain as Relay Layer and dfinance blockchain itself, anyway we have planned things to:
- More tests coverage
- Allow to stop withdraw/deposit of specific currency
- Allow to do migration without reference on previous contract version
- First refactoring
- PoS government implementation instead of PoA
You are ready to contribute, but please, try to follow solidity style guide and leave comments on new functional.
In case of modification our Javascript code (migrations and tests) follow our eslint configuration.
This project has the following contributors.
Copyright © 2019 Wings Stiftung
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http:https://www.gnu.org/licenses/.