- Truffle v5.1.47 (core: 5.1.47)
- Solidity v0.5.16 (solc-js)
- Node v12.16.3
- Web3.js v1.2.1
- Ganache v2.5.4
- npm
- cd into project directory
- Run
npm install
- Create a
.secret
file and add your Metamask's seed phrase in the file
- Create a new project on Ganache
- Add truffle-config.js from project folder
- In the Chain section, ensure Gas Limit is 6721975
- Start Ganache Server
- cd into project directory
- Run
truffle migrate --reset --network development
in console
- Open up Metamask and add a new Custom RPC
- The RPC URL can be found on Ganache
- Import the first account on Ganache to your Metamask. The private key of that account can be found by clicking on the 'key' icon on Ganache
- You can add all the accounts in Ganache to simulate multiple users.
- Only the first account is the owner account which deployed all the contracts. This will be the account that will have the initial supply of SCSE, MAE and EEE tokens.
- If you do not see the ETH being reflected in your Metamask wallet, change to another network and change back to Ganache
- cd into '.Something Funky Is Nice/dex-exchange'
- Run
npm install
- Run
npm run start
in console - If all token balances are 0 in the website, make sure your Metamask account is connected to the website
For this assignment, we will have an Owner who will be deploying all of our contracts. This Owner will be allocated the initial supply of tokens for SCSE, MAE and EEE. Thus, 1 million of each tokens will be allocated to the Owner.
The Owner will sell these tokens on the exchange at an affordable price.
Users who wish to obtain these tokens will have to trade their ETH for these tokens. Before doing so, they have to first swap their ETH to the base token, WETH. Only by doing so, can they trade on the exchange using the trading pairs available.
In our Exchange, we have a structure holding onto these coins, SCSE, EEE and MAE. In each of these coins, it holds a Buy and Sell book.
In the Token's Order Book, it is used to store the Limit Orders that users had made in the exchange. A limit order has a price and amount. In order to easily insert new Limit Orders, we shall do the following:
- In each Order Book, it stores multiple Price which are linked together using a linked list. This Price are inserted in ascending order.
- We used a linked list as this allows for easier insertion of new prices.
- Deletion of Price when there are no more Amount nodes in it is achieved by connecting it's sibling nodes to each other instead of that Price node.
- In each Price, there may be one or more Amount.
- We also used a linked list to connect these Amount but it is not used to insert the Amount in an order. The linked list is to allow for easier deletion of Amount when an order has been fully filled or when an order is deleted by the user.
- Deletion of Amount node is the same as Price.
- The nodes in Amount are inserted based on a Queue system. The oldest orders have a higher priority than the newer orders. New orders are place behind older orders.
For a Buy Market Order, it is similar to the Buy Limit Order, with the only difference being there is no price indication. The order will take whatever is inside the Sell Order Book and trade the amount that the user wants from the cheapest price order to the most expensive price order. This continues until the amount is fully filled, the user ran out of WETH to trade or there is no more orders in the Sell Order Book.
For a Sell Market Order, it is the opposite of a Buy Market Order. It searches the Buy Order Book from the most expensive orders to the least expensive orders.
In order to use the functionality of the website, users MUST install Metamask.
In order to facilitate a smooth trading experience, we will use Wrapped Ethereum as our base token to trade. Users are able to swap their ETH to WETH in our exchange and vice versa.
Funky Crypto Exchange supports the following trading pair:
- WETH/SCSE
- WETH/MAE
- WETH/EEE
Users are able to view their balances that they currently have in their Metamask account on our exchange.
Funky Crypto Exchange supports the following transactions:
Users are able to view both Buy and Sell order books for each trading pair.
Users are able to view their own orders that they have made on each trading pair.
Users are able to cancel the orders they have previously made.