Giter Club home page Giter Club logo

dex-smart-contract's Introduction

DEX smart contract

The smart contract samples of some tokens for the Decentralized Exchange

Init smart contracts

If you have already put smart contracts in genesis block, just change the code from await BTM.deployed() to await BTM.at("address") then run truffle migrate -f 3 --to 3 --network development
Otherwise just run truffle deploy --network development

Architecture

The smart contract samples used to deploy in creation block. The tokens contracts for selling and buying, and the Exchange contract used to allows two users to interact with. There is no matching engine logic inside the exchange contract, it is supposed to have trade logic only.

Smart Contract API

To execute a trade, executeTrade needs to be called with the following arguments:

Argument Type Description
buyAmount uint256 Amount of buyToken tokens the maker wants to buy
sellAmount uint256 Amount of sellToken tokens the maker wants to sell
expires uint256 Blocknumber at which the order will no longer be valuable
nonce uint256 Random number to ensure uniqueness of the order
feeMake uint256 Percentage of fee taken from maker token value
feeTake uint256 Percentage of fee taken from taker token value
amount uint256 Amount of buyToken the taker wants to sell
tradeNonce uint256 Random number to ensure uniqueness of the trade
buyToken address Address of buyToken (token the maker wants to buy)
sellToken address Address of sellToken (token the maker wants to sell)
maker address Maker Address
taker address Taker Address
vMaker uint8 Maker Signature v Parameter
vTaker uint8 Taker Signature v Parameter
rMaker bytes32 Maker Signature r Parameter
rTaker bytes32 Maker Signature r Parameter
sMaker bytes32 Maker Signature s Parameter
sTaker bytes32 Maker Signature s Parameter

Each group of values must be packed together in array based on their type (See Exchange.sol)

To do a hard cancel, cancelOrder needs to be called with the following arguments

Argument Type Description
buyAmount uint256 Amount of buyToken tokens the maker wants to buy
sellAmount uint256 Amount of sellToken tokens the maker wants to sell
expires uint256 Blocknumber at which the order will no longer be valuable
nonce uint256 Random number to ensure uniqueness of the order
feeMake uint256 Percentage of fee taken from maker token value
feeTake uint256 Percentage of fee taken from taker token value
buyToken address Address of buyToken (token the maker wants to buy)
sellToken address Address of sellToken (token the maker wants to sell)
maker address Maker Address
v uint8 Maker Signature v Parameter
r bytes32 Maker Signature r Parameter
s bytes32 Maker Signature s Parameter

Each group of values must be packed together in array based on their type (See Exchange.sol)

Development and Testing Environment Setup

Requirements :

  • OSX or Linux (Windows setup is likely possible but not covered in this guide)
  • Node (version 8.9.4 recommended)
  • Solidity Compiler (v0.4.24)
  • Ganache-cli (v6.1.3)
  • Truffle (v4.1.12)
  • npm (version 6.1.0)

Testing Environment Setup :

  • Clone the repository and install dependencies
git clone [email protected]:tomochain/dex-smart-contract.git
cd dex-smart-contract
yarn
  • Install the latest version of truffle (Truffle v4.0.6)
yarn global add truffle
  • Compile contracts
truffle compile
  • Initialize testrpc (or geth)
./start_rpc.sh
  • Migrate contracts to chosen network
truffle migrate --network development
  • Make sure you are using the latest version of node
nvm install 8.9.4
nvm use 8.9.4
  • Fill in truffle.js and deploy_contracts.js with appropriate wallet addresses. Unlock the corresponding addresses.

  • Verify all tests are passing.

You need to re-migrate all contracts before running the test suite

truffle migrate --reset && truffle test
  • You can interact with the contracts via the console
truffle console
  • You can watch for changes on the fileystem with:
npm run watch
  • Lint
npm run lint

Contribution

This is a fork of the Proof project !

Please try your best to follow the guidance here:

https://chris.beams.io/posts/git-commit/

License

The smart contract (i.e. all code inside of the contracts and test directories) is licensed under the MIT License, also included in our repository in the LICENSE file.

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.