Giter Site home page Giter Site logo

zrx-arbitrage-bot's Introduction

0x Arbitrage Bot

  1. Used 0x Api to fetch best swap rate available as it is a DEX aggregator.
  2. Used DODO Flashloan to get the capital required for trade.
  3. Used Solidity for writing smart contract and Hardhat to compile and deploy the contract on Polygon.
  4. Used Ethers.js to interact with the smart contract after detecting an arbitrage opportunity using the 0x api.

2022-02-25_17-45

Steps to Deploy the bot

  1. git clone [email protected]:proro485/zrx-arbitrage-bot.git
  2. cd zrx-arbitrage-bot
  3. yarn install
  4. Create a .env file and add these variables POLYGON_RPC_URL = <your_rpc_url> , PRIVATE_KEY = <your_private_key>. Note : If you don't have an RPC url then create one using this referal link of Alchemy. Also don't forget to add "0x" infront of your private key.
  5. Now you can open a terminal in this directory and run this command to deploy: npx hardhat run scripts/deploy.js --network polygon (You will get the contract address on the console, you can check the transaction here PolygonScan

Steps to Run the bot

  1. npx hardhat run scripts/dualArb.js --network polygon (this script looks for arbitrage with only two assets for eg. X -> Y -> X)
  2. npx hardhat run scripts/triArb.js --network polygon (this script looks for triangular arbitrage for eg. X -> Y -> Z -> X)

Customizing the settings

  1. To change the pairs of tokens to find arbitrage in, you can go to the constants/polygon/tokens.js there you would find an array of name dualTokensList and triTokensList you can uncomment the pair of tokens you would like to get searched for arbitrage.
  2. If you want to add new tokens, then add them to constants/polygon/addresses.js within the array with name KNOWN_TOKENS and also to the constants/polygon/tokens.js in the tokens object. Now after adding the token info at these two locations you can add the order of trading in the dualTokens or triTokensList in the same file.
  3. If you want to change the amount used for arbitraging, then go the the utils/utilities.js file and change the amount in the toBorrow function it is currently set to 10000 USD and equivalent amounts for WMATIC, WETH, WBTC. Also after changing this you might want to update the profit percentage so change that inside the getBPS function (1 BPS is 0.01%, 10 BPS is 0.1%, 100BPS is 1%), you have to change the value of the amount which is passed as a parameter, you can also change the BPS value returned for that amount to any value you like.
  4. Also you can increase/decrease the gas price by changing the gasPrice variable in the scripts/dualArb.js and scripts/triArb.js. Just search for gasPrice inside the file.

zrx-arbitrage-bot's People

Contributors

proro485 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.