GithubHelp home page GithubHelp logo

ltfschoen / dex Goto Github PK

View Code? Open in Web Editor NEW
32.0 4.0 25.0 422 KB

Decentralised Exchange (DEX) for Ethereum

License: MIT License

JavaScript 100.00%
solidity exchange tokens ico ethereum dex ganache-cli decentralised-exchange

dex's Introduction

Setup

  • Fork and clone the repository

  • Install NVM

  • Switch to Node version specified in .nvmrc

nvm install
npm install -g truffle
  • Terminal Tab 2 - Install Test Framework with Ethereum TestRPC
npm install -g ganache-cli
  • Terminal Tab 2 - Start Ethereum Blockchain Protocol Node Simulation
ganache-cli \
  --port="8500" \
  --mnemonic "copy obey episode awake damp vacant protect hold wish primary travel shy" \
  --verbose \
  --networkId=3 \
  --gasLimit=7984452 \
  --gasPrice=2000000000;
  • Optionally Install Geth and run the Testnet using Geth in the project directory:

    • Show installation directory of Geth and Go, and show Go path Reference
which geth
which go
echo $GOPATH
geth version
  • Show where Geth Chain directories are stored:
find ~ -type d -name 'chaindata'
brew tap ethereum/ethereum
brew install ethereum
brew upgrade ethereum
  • Terminal Tab 1 - Compile and Deploy the FixedSupplyToken Contract
truffle migrate --network development
  • Terminal Tab 1 - Run Sample Unit Tests on the Truffle Contract. Truffle Re-Deploys the Contracts
truffle test

Debugging

  • Debug the Solidity Smart Contract in Remix IDE
  • Verify the Solidity Smart Contract compiles by pasting it in MIST using https://github.com/ltfschoen/geth-node
  • Verify the Solidity Smart Contract compiles by deploying it to Ethereum TestRPC using Truffle

TODO

  • - Incorporate Automated Market Maker (AMM) similar to that described in 0x Whitepaper

Initial Setup - Truffle, TestRPC, Unit Tests (FixedSupplyContract)

npm install -g truffle
  • Setup Truffle to Manage Contracts (i.e. MetaCoin sample), Migrations and Unit Tests
truffle init

truffle migrate --network development
npm install -g ganache-cli
  • Start Ethereum Blockchain Protocol Node Simulation with 10x Accounts on http://localhost:8500
    • Creates 10x Private Keys and provides a Mnemonic. Assigns to each associated Address 100 Ether.
    • Note: Private Keys may be imported into Metamask Client
    • Note: Mnemonic may be used subsequently with Ethereum TestRPC to re-create the Accounts with `
ganache-cli
  • Restart TestRPC with Same Accounts (i.e. ganache-cli --mnemonic "copy obey episode awake damp vacant protect hold wish primary travel shy")
ganache-cli --port 8500 --mnemonic <INSERT_MNEMONIC> 
  • Add FixedSupplyToken to Truffle Contracts folder

  • Remove MetaCoin from Truffle Contracts folder

  • Update 2nd Migration file to deploy FixedSupplyToken

  • Compile and Deploy the FixedSupplyToken Contract

truffle migrate --network development
  • Run Sample Unit Tests on the Truffle MetaCoin Contract. Truffle Re-Deploys the MetaCoin Contracts
truffle test

Troubleshooting

  • Try restarting Ganache TestRPC if you encounter error sender doesn't have enough funds to send tx. The upfront cost is: x and the sender's account only has: y

  • Fix error Error: Error: Exceeds block gas limit that may occur when sending Gas Limit say of 50000000 when truffle.js has gas property set as gas: 4712388,, by changing to a smaller value: myExchangeInstance.buyToken("FIXED", web3.toWei(4, "finney"), 5, {from: accounts[0], gas: 4000000});

  • Fix Error: VM Exception while processing transaction: out of gas. In the buyToken function it always occurs after a certain line of code. Simply increase the Gas Limit to the Mainnet's limit (currently shown as 7984452 at https://ethstats.net/) in both Ganache CLI Flags and in truffle.js

dex's People

Contributors

ltfschoen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dex's Issues

Could we(ABLE project) contribute and use to your eth dex for our open source project?

Hello, we are ABLE project developers who create a solution to problems with traditional bank lending-deposit spreads, and nontransparent and centralized cryptocurrency financial services.

We were very interested in your project. Especially, we were impressed with the way it used the whole transaction history in Ethereum. (not only hash)
Could we contribute part of your project and use your project in our open source project; ethereum based ABLE platform. And if you are interested to our open source project, we want to invite you to our project.
Please contact [email protected].

Below is our motto, and homepage link
https://www.able-project.io/
The ABLE project will create a solution to problems with traditional bank lending-deposit spreads, and nontransparent and centralized cryptocurrency financial services, basing the solution on the transparency and reliability of a blockchain system. The ABLE project is the first cryptocurrency-specific financial solution that provides cryptocurrency financial products through person-to-person loanmatching systems and decentralized exchanges.

The ABLE project will create a platform that enables cryptocurrencybased financial activities to center around the ABLE account, emanating from the fact that banking activities are carried out primarily through bank accounts. Users propose deposit and loan interest rates through a matching system, eliminating the lending-deposit spread by directly connecting users on a peer-to-peer basis. The ABLE project supports decentralized exchanges and provides decentralized cryptocurrency wealth management services through smart contracts. Ultimately the project aims to evolve into the ABLE Ecosystem through its integration with external systems, including simple payments.

Why check again after decrease buy's ETH, and decrease seller's token???

In NEW ORDER - BID and ASK ORDER functions, why you check the balance of buyer's ETH and seller's token after decrease ETH and token??
I cannot understand.

// Overflow Check
// 09 Unit Test: balanceEthForAddress[msg.sender] is initially 3000000000000000000 (3 ETH)
require(balanceEthForAddress[msg.sender] >= totalAmountOfEtherAvailable);
require(balanceEthForAddress[msg.sender] - totalAmountOfEtherAvailable <= balanceEthForAddress[msg.sender]);

// Decrease the Buyer's Account Balance of tokens by the amount the Sell Offer Order Entry is willing to accept in exchange for ETH
balanceEthForAddress[msg.sender] -= totalAmountOfEtherAvailable;

// Overflow Checks
require(balanceEthForAddress[msg.sender] >= totalAmountOfEtherAvailable);<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE

and

// Overflow Check
require(tokenBalanceForAddress[msg.sender][tokenNameIndex] >= amountOfTokensNecessary);

// Decrease the Seller's Account Balance of tokens by amount they are offering since the Buy Offer Order Entry is willing to accept it all in exchange for ETH
tokenBalanceForAddress[msg.sender][tokenNameIndex] -= amountOfTokensNecessary;

// Overflow Check
require(tokenBalanceForAddress[msg.sender][tokenNameIndex] >= amountOfTokensNecessary); <<<<<<<<<<<<<<<<<<<<<<<<<< HERE

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.