Git Product home page Git Product logo

sonhnguyenn / flash-arbitrage-watcher Goto Github PK

View Code? Open in Web Editor NEW

This project forked from n0name-sw3/flash-arbitrage-watcher

0.0 0.0 1.0 3.16 MB

Fast arbitrage monitoring system leveraging Aave flash loans for fast arbitrage and Dfuse Lifecycle for safe monitoring.

Home Page: https://n0name-sw3.github.io/flash-arbitrage-watcher/

License: The Unlicense

JavaScript 94.44% HTML 4.60% CSS 0.95%

flash-arbitrage-watcher's Introduction

Welcome to flash-arbitrage-watcher ๐Ÿ‘‹

Version License: Unlicense

This project aims to prove the concept of a fast arbitrage monitoring system leveraging Aave flash loans for fast arbitrage and Dfuse Lifecycle for safe monitoring.

It has been submitted as a response to the Sustain Web3 challenge in the Most Innovative Integration of dfuse Lifecycle category.

demo

โœจ Demo

Set-up

The demo starts by requesting three secret parameters :

  • an Ethereum private key, with some Ropsten ether on it. It should be given in hexa-format, prefixed with 0x.
  • a valid Infura key.
  • a Dfuse API secret key.

Users should be warned that the demo runs on the Ropsten public testnet and that some Ropsten ether will be used during the process.

Workflow

Overview

Multiple decentralized exchanges (DEXes) may, at a certain time, provide different prices for a given pair of token. When the difference is large enough, some arbitrage opportunities arise, allowing for some direct profit and contributing to the stability of prices.

In this demo, we use the example of two major DEXes (Uniswap and Kyber) and the exchange rate of BAT tokens against DAI.

Aave is a market protocol which introduces, in addition to traditional overcollateralized loans, the notion of undercollateralized loans with flash loans.

Flash loans allow anyone to use the liquidity pool of a given token with no personal collateral under the condition that the loan is contracted and repaid in the same transaction. In the context of arbitrage, transactions can thus use larger amounts of tokens and consequently speed up arbitrage and stabilisation of prices.

However, transactions that would virtually benefit from arbitrage and return some new tokens to the sender when broadcast may, as new transactions are integrated to the block, change DEX rates and make the original transaction less profitable or even not profitable anymore. That is the reason why Dfuse Lifecycle can be very useful in this context. As exchange rates are fetched, expected returns from arbitrage are continuously computed. Every time a positive return is expected, an arbitrage transaction is broadcast that leverages flash loans to maximize the amount of tokens at stake and expand returns. As long as this transaction is not mined, exchange rates are still watched so that if broadcast transaction becomes less profitable then it can be cancelled by broadcasting an empty replacement transaction.

Details of the demo

In the demo, exchange rates are simulated. In practice, any pending transaction which updates order books of DEXes should be watched with Dfuse in order to continuously compute current exchange rates. With simple rules integrating maximum price slippage, a minimum expected return on arbitrage is computed. If the latter becomes greater than Aave flash loan fees, then a transaction is automatically broadcast to leverage Aave liquidity pool and benefit from arbitrage opportunities.

While this first transaction is pending, in the demo the returns from arbitrage grow into negative ones and the transaction becomes non-profitable and even costly because of flash loan fees. A replacement transaction is thus automatically broadcast with a higher gas price to cancel the first transaction.

In the demo, the returns from arbitrage then become profitable again. A new transaction leveraging flash loans is broadcast. As we can see in details of the transaction, the flash loan feature is actually implemented (1 DAI is borrowed during the transaction). Exchange rates being simulated for the sake of the demo, the selling and buying operations are not executed on DEXes though.

In real condition, instead of the low amount of DAI borrowed in this proof of concept, more than 563970 DAI and 276085 BAT could be instantly borrowed from Aave liquidity pools with no personal collateral required.

As demonstrated in this PoC, Dfuse Lifecycle helps adding some safety to the process. It doesn't protect from Miner Extractable Value operations which are however less likely to take place in practice.

Available Scripts

Install

yarn install

Usage

yarn start

Run tests

yarn test

Lint

yarn lint

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a โญ๏ธ if this project helped you!

๐Ÿ“ License

Copyright ยฉ 2020 n0name-sw3.
This project is Unlicense licensed.


This README was generated with โค๏ธ by readme-md-generator

flash-arbitrage-watcher's People

Contributors

philippemts avatar

Forkers

cawood

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.