GithubHelp home page GithubHelp logo

starit / uniswap-skim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nicholashc/uniswap-skim

0.0 0.0 0.0 12.98 MB

scripts to scan all of the uniswapV2๐Ÿฆ„ contracts on ethereum and search for skim opportunities

License: The Unlicense

JavaScript 97.32% Solidity 2.68%

uniswap-skim's Introduction

uniswap-skim

Scripts to scan all of the UniswapV2๐Ÿฆ„ contracts on the Ethereum network and search for mismatched balances/reserves.

about

UniswapV2 has an interesting function called skim(address) that lets anyone claim a positive discrepancy between the actual token balance in the contract and the reserve number stored in the Pair contract.

These scripts scan all of the uniV2๐Ÿฆ„ contracts to look for those opportunities. Usually there are only a handful, but tokens with changing supplies like aTokens or rebase tokens like AMPL can create some chaos. Most of the skim balances are so small that they aren't worth the gas to call. But sometimes they are profitable.

If you try to call skim from an EOA expect to be frontrun. There are an increasing number of bots searching for these opportunities. You may want to use something like the Forwarder.sol contract example or even something more sophisticated.

install

  1. clone the repo
  2. cd into the repo
  3. run npm i to install the dependencies (web3 and axios)

usage

  1. there are two main scripts:
  • uniMarkets.js scans for any newly deployed markets since the last known Pair and appends logs/events.js with any new markets
  • skim.js checks every market in log/events.js and looks for skim opportunities. It attempts to use the coingecko api to find a price for the value of the skim-able tokens
  1. from the root of the repo directory npm run update will run uniMarket.js and update the logs to the latest block
  2. from the root of the repo directory npm run skim will search for skim-able opportunities

usage notes

  1. the scripts are hardcoded to use a local node on port 8546 with a websockets connection. If you are using different ports or infura, change this in the code
  2. there is a "token blacklist" array that includes tokens that are self-destructed, not actually contracts, or totally non-standard ERC20. This reduces overall errors
  3. there is a "whitelist" that correctly names tokens who didn't follow the ERC-20 standard and return a byte32 for their name (looking at you MKR). there is probably a smarter way to deal with this edge case than hardcoding but ยฏ\(ใƒ„)/ยฏ
  4. if you run into problems updating events.js try: A) hardcode the path directory in fs.writeFile() in uniMarkets.js B) define the block range for eth.getLogs more narrowly if updating a long time period
  5. skim.js defaults to return skim-able values that are greater than $0.01 so you can see some results. you can change this by altering the variable minDollarVal in skim.js. Skim-able values are also returned when coingecko does not have a price for the token (but they have most)
  6. events.js in this repo is current as of block 11057149 and there are 15,230 uniV2๐Ÿฆ„ Pairs
  7. skim.js can take a few minutes to run as there are over 15,000 pairs to search!
  8. if uniMarkets.js returns no results it's possible that there were no new pairs were deployed since the last time you called the function
  9. the script ignores cases where the reserve is higher than the balance, since that is not skim-able (this happens with rebase coins sometimes)

example output

what your terminal should roughly look like after running npm run update

uniswap-skim npm run update

> [email protected] update /yourDirectory/uniswap-skim
> node ./scripts/uniMarkets.js

๐Ÿฆ„ pair #: 9786 deployed in block: 10898080
๐Ÿฆ„ pair #: 9787 deployed in block: 10898182
๐Ÿฆ„ pair #: 9788 deployed in block: 10898201
๐Ÿฆ„ pair #: 9789 deployed in block: 10898327
๐Ÿฆ„ pair #: 9790 deployed in block: 10898366
๐Ÿฆ„ pair #: 9791 deployed in block: 10898390

what your terminal should roughly look like after running npm run skim

uniswap-skim npm run skim

> [email protected] skim /yourDirectory/uniswap-skim
> node ./scripts/skim.js

{
  "pairAddress": "0x321d87e1757c8c9b57e7af5aa3fe13d2ae774445",
  "pairIndex": 9355,
  "token0": {
    "address": "0x29e240cfd7946ba20895a7a02edb25c210f9f324",
    "name": "yearn Aave Interest bearing LINK",
    "decimals": "18",
    "balance": "252,858.663596952206854028",
    "reserve": "252,858.663596952206854028",
    "imbalance": false
  },
  "token1": {
    "address": "0xa64bd6c70cb9051f6a9ba1f163fdc07e0dfb5f84",
    "name": "Aave Interest bearing LINK",
    "decimals": "18",
    "balance": "267,963.012522435165106136",
    "reserve": "267,962.996672942810947153",
    "imbalance": {
      "diff": "0.015849492360200192",
      "usdPrice": 10.35,
      "value": "$0.16๐Ÿฆ„"
    }
  }
}

disclaimers

I take no responsibility for any use, misuse, mistakes, or funds lost or received related to the use of this code. Use, modify, ignore as you see fit. There is also a benevolent way to correct uniV2๐Ÿฆ„ balance/reserve discrepancies by calling sync(). ๐Ÿ˜ˆ or ๐Ÿ˜‡: the choice is yours!

uniswap-skim's People

Contributors

nicholashc avatar nickhc avatar dependabot[bot] 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.