Coder Social home page Coder Social logo

tokenswap's Introduction

TokenSwap based on Uniswap

The project has been made using the React truffle box and Material UI.

How it works?

Exchange smart contract uses the constant product function, xy = k(constant) to facilitate the exchange of an ERC20 token with Ether.

Assume that there are 2 tokens A and B in an exchange contract. Let x be the number of A tokens and y be the number of B tokens in the contract. A user wants to swap dx number of A tokens, to get dy number of B tokens back. This swapping of tokens would happen in such a way that even after the trade takes place the product of the amount of both the tokens would still be the same constant - k.

So, (x + dx)(y - dy) = k

=> xy - xdy + ydx - dxdy = xy (as xy = k)

=> dy(dx + x) = ydx

=> dy = y(dx/(dx + x))

dy = y(dx/(dx + x)) is the formula which is being used here to facilitate the swaps.

Getting Started

Deploying Contracts

Before proceeding, ensure that you have truffle installed. You can install it using the following command

npm install -g truffle

After cloning the repo, the following changes need to be made -

Rename .secretExample as .secret and replace insert your Mnemonic phrase with the Mnemonic phrase of your MetaMask account

Rename .envExample as .env and replace YOUR_INFURA_KEY with your Infura key for the Rinkeby Test network.

Then install the neccessary dependencies. To do this, start a new terminal in the repo. Inside the terminal, type the following commands -

cd TokenSwap
npm install

Next compile the solidity files -

truffle compile

You can now deploy the files locally using Ganache -

truffle migrate

You can download Ganache from here

You can also test the files using the command -

truffle test

To deploy the contracts on network -

truffle migrate --network

To deploy the contracts on Goerli -

truffle migrate --network goerli

Frontend

Go to the client folder -

cd client

Install packages -

npm install

To start the React App -

npm start

tokenswap's People

Contributors

gomathi1806 avatar

Stargazers

 avatar

Watchers

 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.