With the ever growing DEFI world and the appearance of multiple decentralized exchanges on the different blockchains, the WEB3 ecosystem needs a way to compare the pros & cons of swapping on each DEX.
This excatly what Paraswap & 1inch protocol are trying to do, they aggregate the prices of tokens from multiple exchanges in each Blockchain (for example: uniswap, sushiswap, shibaswap in the Ethereum Mainnet), then they compare those prices and the swapping fee and offer to their user the best exchange rate possible.
In this Dapp, i built a simplified version of Paraswap it works on 4 blockchains: Ethereum, Polygon, Binance Smart Chain and the kovan testnet.For the moment it supports some well known tokens (ETH, Matic, Dai, USDC,...).
Please install or have installed the following:
- nodejs and npm
- python
- MetaMask Chrome extension installed in your browser
-
Installing Brownie: Brownie is a python framework for smart contracts development,testing and deployments. It's quit like HardHat but it uses python for writing test and deployements scripts instead of javascript. Here is a simple way to install brownie.
pip install --user pipx pipx ensurepath # restart your terminal pipx install eth-brownie
Or if you can't get pipx to work, via pip (it's recommended to use pipx)
pip install eth-brownie
Install ganache-cli:
npm install -g ganache-cli
-
Clone the repo:
git clone https://github.com/kaymen99/Dex-aggregator.git cd Dex-aggregator
-
Set your environment variables To be able to deploy to real testnets you need to add your PRIVATE_KEY (You can find your PRIVATE_KEY from your ethereum wallet like metamask) and the infura project Id (just create an infura account it's free) to the .env file:
PRIVATE_KEY=<PRIVATE_KEY> WEB3_INFURA_PROJECT_ID=<< YOUR INFURA PROJECT ID >>
You can choose to use ethereum testnets like rinkeby, Kovan or any other evm compatible testnet. You'll also need some eth in the testnet. You can get it into your wallet by using a public faucet.
After going throught the installation part you can start the app by running:
cd front-end
yarn
yarn start
The front-end is built using the following libraries:
- Ethers.js: used as interface between the UI and the deployed smart contract
- Web3modal: for conecting to Metamask
- @reduxjs/toolkit & redux-persist: for managing the app states (account, balance, blockchain)
- Material UI: used for react components and styles
- Swap component: It finds the best price possible for the user tokens from the supported exchanges and allow user to approve & excute the swap transaction
- Exchanges component: For getting the token prices on the different exchanges
If you have any question or problem running this project just contact me: aymenMir1001@gmail.com
Distributed under the MIT License. See LICENSE.txt
for more information.