GithubHelp home page GithubHelp logo

ibhi / bot Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 118 KB

(Winning) submission for https://gitcoin.co/issue/liquity/beta/2/100025005

License: MIT License

JavaScript 49.43% Solidity 4.61% TypeScript 45.95%

bot's Introduction

This project contains code to arbitrage the ETH/LUSD rates on Uniswap and the redemption rate on Liquity. It is designed for the Kovan testnet, however this can be adapted by changing the addresses in constants.ts.

Improvements

I can now update this page as the competition has finished. Since submitting, I have realized some improvements that could be made, notably:

* Add a function to withdraw the LUSD balance of the contract (redemptions can give LUSD as a gas refund or your calculations can be incorrect and lead to some residual LUSD).
* Instead of using low level Solidity calls, implement the TroveManager and UniswapPair interface types and use those.

Design

It works by querying prices from the Uniswap pair and the Chainlink oracle every block. If LUSD is sufficiently cheaper on Uniswap, then the bot will calculate how much would get by swapping ETH for LUSD on Uniswap after slippage. It will then pass the result of that calculation into redeemLUSD. We then generate the transaction data from these actions and pass it to our arbitrager smart contract. This smart contract will transfer the specified amount of WETH to Uniswap, execute the swap for LUSD, then redeem the LUSD through the TroveManager contract. It will also revert if the balance after execution is lower than the balance before to ensure that we do not lose money (except gas) even if we are frontrun or if our transaction is included late.

Run

First, install dependencies:

$ npm install

Due to a bug (?) in @liquity/lib-ethers, you need to run:

$ cp node_modules/@liquity/lib-ethers/deployments/default/kovan.json node_modules/@liquity/lib-ethers/dist/deployments/dev.json 

before running the code.

Next, deploy contracts/Execute.sol using Ethereum Remix. Make sure to add some initial ETH to it or it will not be able to function. Replace ARBITRAGE_CONTRACT_ADDRESS in constants.ts with the deployed address.

Once you have done that, you can run (using the private key of the address that deployed the contract):

$ ETHEREUM_PRIVATE_KEY=xxxx INFURA_KEY=xxxx npm start 

Example Transactions

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.