Giter Site home page Giter Site logo

subnatant / etherex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from etherex/etherex

1.0 2.0 0.0 6.3 MB

EtherEx is an open source, fully transparent, next generation decentralized exchange built on Ethereum.

Home Page: http://etherex.github.io/etherex

License: MIT License

JavaScript 77.49% CSS 8.07% HTML 0.20% Python 14.23%

etherex's Introduction

EtherEx

Build Status SlackIn Join the chat at https://gitter.im/etherex/etherex

Decentralized exchange built on Ethereum.

About

This repository contains the source code that runs the exchange on Ethereum as a set of contracts, along with the UI, tests, tools and documentation.

Components

  • contracts: Ethereum contracts in Serpent
  • frontend: React.js UI
  • tests: EtherEx tests

Requirements

Installation

Start by cloning this repository.

git clone https://github.com/etherex/etherex.git

Development / testing

This will install pyethereum and ethereum-serpent if you don't already have those installed.

pip install -r dev_requirements.txt

Running tests

py.test -vvrs

Refer to Serpent and pyethereum for their respective usage.

UI development

You will need a working node.js setup (instructions) and globally installed grunt-cli (instructions).

cd frontend
npm install
grunt

Deployment

Requires a working cpp-ethereum client with JSONRPC, Serpent and PyEPM

cd contracts
pyepm EtherEx.yaml

API

  • The API is the format of the data field for the Ethereum transactions.
  • Subcurrencies need to support the Subcurrency API.
  • You only need an Ethereum client to use the API.

Operations

Methods (with serpent type definitions):

price:i:i
buy:iii:i
sell:iii:i
trade:ia:i
deposit:iii:i
withdraw:ii:i
cancel:i:i
add_market:iiiii:i
get_market:i:a
get_trade_ids:i:a
get_trade:i:a
get_sub_balance:ii:a

Price API

<method> <market_id>

Trade API

Add buy / sell trade

<method> <amount> <price> <market ID>

Trade

<method> <max amount> <trade IDs>

Deposit (subcurrency contracts only, see below)

<method> <address> <amount> <market ID>

Withdraw

<method> <amount> <market ID>

Cancel trade

<method> <trade ID>

Adding a market

<method> <currency name> <contract address> <decimal precision> <price denominator> <minimum total>

Market names

Market names follow the "/ETH" convention. When registering a new market, submit the currency name as a three or four letter uppercase identifier, ex.: "BOB" for BobCoin.

Contract address

The subcurrency contract address.

Decimal precision

The subcurrency's decimal precision as an integer.

Price denominator

  • Denominator for price precision, ex. 10000 (10000 => 1 / 10000 => 0.0001)

Minimum trade total

When adding a subcurrency, set the minimum trade total high enough to make economic sense. A minimum of 10 ETH (1000000000000000000000 wei) is recommended.

Market IDs

1 = ETX/ETH

New market IDs will be created as DAO creators add their subcurrency to the exchange.

Subcurrency API

Subcurrency contracts need to support the deposit ABI call.

It is a different approach than the MetaCoin API which will not be used, as the Approve API is all-or-nothing and gives too much permissions to the exchange. The new procedure is explained below, and the sample ETX contract can be used as an example.

Each subcurrency has to notify the exchange of each asset transfer from a user's address to the exchange's address. The amount of extra code necessary to support this feature is comparable if not smaller than with the other approach.

Setting the exchange's address

The first step a subcurrency has to take is to store the exchange's address for future comparison of recipients. This can be done during the initialization of the contract, however, adding an ABI call to update the address and market_id is highly recommended.

data owner
data exchange
data market_id

def init():
    self.owner = msg.sender
...

def set_exchange(addr, market_id):
    if msg.sender == self.owner:
        self.exchange = addr
        self.market_id = market_id
        return(1)
    return(0)

After registering the subcurrency using the add_market ABI call, the subcurrency will receive a market_id. Since there are currently no return values to actual transactions, this market_id will need to be inspected from the exchange's contract storage or from the UI.

Notifying the exchange of deposits

The second step has to be executed on each asset transfer. The gas costs of comparing the recipient to the exchange's address are minimal but a separate ABI call might be used later on, depending on how this approach will play out on the testnet. The relevant part below is the one under Notify exchange of deposit, the top part being what can be considered standard subcurrency functionality. Notice the extern definition that will be used for the deposit method.

extern exchange: [deposit:iii:i]

def send(recipient, amount):
    # Get user balance
    balance = self.storage[msg.sender]

    # Make sure balance is above or equal to amount
    if balance >= amount:

        # Update balances
        self.storage[msg.sender] = balance - amount
        self.storage[recipient] += amount

        # Notify exchange of deposit
        if recipient == self.exchange:
            ret = self.exchange.deposit(msg.sender, amount, self.market_id, datasz=3)
            # Exchange returns our new balance as confirmation
            if ret >= amount:
                return(1)
            # We return 2 as error code for notification failure
            return(2)

        return(1)
    return(0)

TODO: Solidity examples.

Notes

  • Your Ethereum address is used as your identity

TODO

Architecture

  • Document error codes of return values
  • Implement Wallet section (transactions, balances, etc.) (in progress)
  • Re-implement NameReg support and integration
  • Start the Tools section, find and list ideas
    • subcurrency registration (in progress)
    • subcurrency creation tools/wizard
    • raw transact (?)
    • trading tools (...)
    • ...
  • Use NatSpec
  • Look into how Whisper and Swarm could be used and integrated
  • Start working on X-Chain
  • Update this TODO more frequently
  • Start using GitHub issues instead
  • Better, rock solid tests, and way more of them
  • Total unilateral world takeover

UX/UI

  • Graphs, beautiful graphs
  • Advanced trading features (stoploss, etc.)
  • Animations/transitions
  • Check/clear buttons
  • Wallet design and theming
  • More/new mockups / wireframes
  • More/new design elements
  • Implement new mockups / design elements

License

Released under the MIT License, see LICENSE file.

etherex's People

Contributors

caktux avatar jorisbontje avatar debris avatar cdetrio avatar

Stargazers

Wintermooch avatar

Watchers

James Cloos avatar  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.