Giter VIP home page Giter VIP logo

ewc-system-contracts's Introduction

EWC system contracts

Infrastructure contracts for EnergyWeb Chain (EWC) live launch.

Build Status Coverage Status

Maintainers

Primary: Adam Nagy (@ngyam)

Heiko Burkhardt (@hai-ko), Jonas Bentke (@jbentke)

Pre-requisites

  • node 8
  • npm
  • Optional: python 3.6 environment for Slither

Quickstart

npm install -D

and code away. Dependencies are installed locally.

Contracts

Important: all contracts go to the chainspec, deployed at the same time with their addresses known beforehans, so no deployment/migration scripts are written. The contracts are compiled and put into the chainspec by our Genesis/Chainspec generator: https://github.com/energywebfoundation/ewf-genesis-generator

Compiler version: 0.5.8 (reason)

Validator set

# Relay

Implements the Parity's reporting validator set interface. Relays all function calls to a worker "Relayed" contract. This pattern is chosen for upgradeability.

  • Deployment:

    constructor(address _owner, address _relayedSet)
    

    It expects the Relayed address and contract owner address in the constructor.

# Relayed

Implements the actual validator set logic and storage.

  • Deployment:

    constructor(address _owner, address _relaySet, address[] memory _initial)
    

    It expects the Relay address, contract owner and the initial validator addresses in the constructor.

Reward contract

Contains the reward logic. Rewards are issued upon new blocks. The contract implements Parity's BlockReward interface.

Rewarded entities:

  1. Block authors: rewarded for a total of 10 years with ~10 mil tokens based on a discrete S curve distribution. The S curve calculator can be found here.
  2. Community fund: A multisig wallet controlled by the community. Rewarded for a total of 10 years with ~37.9 mil tokens. A constant amount is paid out with each new block.
  • Deployment:

    constructor(address _communityFundAddress, uint256 _communityFundAmount)
    

    Expects the address of the community fund (ideally a mutltisig wallet) and the constant amount that is paid to the fund with each new block in wei.

Holding contract

Holds investor funds, which are available to withdraw after a certain time period has passed.

  • Deployment:

    constructor()
    

    No params needed. The initial holding records are hardcoded into the constructor.

Node control

EWF's node control system contracts. Consists of 3 contracts for upgradeability.

# NodeControlLookUp

Serves as a lookup contract for the node control logic.

  • Deployment:

    constructor(NodeControlDb _nodeControlDb, address _owner)
    

    Constructor expects the address of the db and the owner.

# NodeControlDb

Stores validator node state information.

  • Deployment:

    constructor(NodeControlLookUp _lookUpContract, address _owner)
    

    Constructor expects the address of the lookup contract and the owner.

# NodeControSimple

On-chain node control logic. Can issue update commands to nodes.

  • Deployment:

    constructor(NodeControlDb _nodeControlDb, address _owner)
    

    Constructor expects the address of the db and the owner.

Parity's Name Registry (SimpleRegistry)

This contract is Parity's Registry contract. The minor modification is that the SimpleRegistry was made Ownable and the following functions are only allowed to be called by the owner:

reserve()
confirmReverseAs()
setFee()
drain()

Functionally, this contract is just a placeholer, giving possibilities for future use.

  • Deployment:

    constructor(address _owner)
    

    Constructor expects the address of the owner only.

Other third party contracts used

Compiling the contracts

With the locally installed truffle:

npx truffle compile

Expected warnings:

  • ValidatorSetRelayed.sol:128:9: Warning: Unused function parameter. This function is according to Parity spec. but we are not using tthe _proof param for anything right now.
  • NodeControl contracts -> Warning: Experimental features are turned on. Expected because of ABIEncoderV2.

Running the tests

npm test

The test script starts a ganache instance and stops it afterwards.

Linting

2 linters are set up:

  • Solhint:
    npm run lint:solhint
    
  • Solium
    npm run lint:solium
    

Coverage report

Solidity coverage

npm run coverage

Security analysis

  • Slither by Trail of bits:

    1. Make sure a python 3.6 env is active.

    2. Install

      pip install slither-analyzer
      

      or sometimes

      pip3 install slither-analyzer
      
    3. Then run

    npm run security
    
  • MythX security checker (truffle security plugin by ConsenSys):

    Already installed with the other local deps. Note that for a full check you need to have a registered account (free). Pass in the account params as env vars.

    MYTHX_ETH_ADDRESS=0xYOURADDRESS MYTHX_PASSWORD=yourpass npm run verify
    

Contributing

Please read our CONTRIBUTING guide for our code of conduct and for the process of submitting pull requests to us.

Versioning

We use SemVer for versioning.

License

This project is licensed under the GPLv3 License - see the LICENSE file for details.

FAQ

ewc-system-contracts's People

Contributors

danzipie avatar hai-ko avatar ngyam avatar slockitpush avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.