Giter Site home page Giter Site logo

aitimate / crypyo-arbitrage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andreistefanwork/crypyo-arbitrage

0.0 0.0 0.0 684 KB

Arbitrage on Ethereum, leveraging dYdX flash loans and KyberSwap's Aggregator API

License: MIT License

Shell 1.13% JavaScript 12.52% TypeScript 35.35% Solidity 51.00%

crypyo-arbitrage's Introduction

Arbitrage on Ethereum, leveraging dYdX Flash Loans and KyberSwap's Aggregator API

Arbitrage strategy

  • use KyberSwap Router to find the best route to take when swapping assets
    • find best route and swap token A for token B
    • find best route and swap token B for token A
    • if the token A final balance is greater than the token A initial balance, then the arbitrage is profitable
  • for a big leverage, make use of flash loans, to move large amounts of assets from one exchange to another
  • all operations on the blockchain are performed inside a single transaction
  • in the event that arbitrage is not profitable, the only losses incurred are gas fees.

Trading pair: WETH <-> USDC

Liquidity aggregator: KyberSwap

Flash loan provider: DyDx

img.png

Development

Batch | Monitor blockchain for arbitrage opportunities

  • Node.js program that listens to new blocks by using a websocket connection

    • use web3.eth.subscribe
  • initialize a web3.js instance over websocket connection

  • hide the sensible data in a .env file

  • when a new block is mined, the job uses KyberSwap Aggregator API to evaluate the arbitrage opportunity

    • use KyberSwap Aggregator API to get the best route to swap X WETH for Y USDC
    • use KyberSwap Aggregator API to get the best route to swap Y USDC for Z WETH
    • if Z - X - gasFees > 0, then the arbitrage is profitable
  • if the arbitrage is profitable, the job sends a transaction to the Arbitrage Smart Contract

  • The program can also be used to withdraw profits accumulated by the Arbitrage Smart Contract

Solidity Smart Contract | Take action on arbitrage opportunities

  • use DyDx to create a flash loan for X WETH
  • call AggregationRouter with encoded swap data to swap X WETH for Y USDC
  • call AggregationRouter with encoded swap data to swap Y USDC for Z WETH
  • if Z > X, then the arbitrage is profitable and the transaction should succeed, else the transaction will revert

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.