Skip to content

calp-pro/uniswap-v2-loader

Repository files navigation

calp.pro icon  uniswap-v2-loader  Coverage

Fast DeFi AMM pools loader. Optimized for Multi-core CPUs with smart disk-cache.
This package is a loader that allows you to download protocol addresses yourself.
If you want to instantly get all addresses (pools and their tokens), use the packages from the next section.
Those packages check for updates every hour and republish the package with updated data.

Uniswap V2 based protocols

Install

  • CLI
    • npm i -g uniswap-v2-loader
      
  • Node.js API
    • npm i --save uniswap-v2-loader
      

CLI

uniswap-v2-loader --from=1 --to=3

Output:

2,0x12ede161c702d1494612d19f05992f43aa6a26fb,0x06af07097c9eeb7fd685c692751d5c66db49c215,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
3,0xa478c2975ab1ea89e8196811f51a7b7ade33eb11,0x6b175474e89094c44da98b954eedeac495271d0f,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

API

Methods:

  • load(config)
    • return Promise(<Pair>[])
  • subscribe(callback, config)
    • Continuous synchronization engine. Performs initial load and subsequently polls for new pairs.
    • return unsubscribe function

where config is common Object with set of parameters to loader.

config is an Object (key/value)

  • from
    • Start index (inclusive).
    • Type: number
    • Default: 0
  • to
    • End index (inclusive).
    • Type: number
    • Default: undefined
  • filename
    • CSV cache path.
    • Type: string
    • Default: OS cache folder
  • factory
    • Smart contract factory address.
    • Type: string
    • Default: 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f
  • key
    • Alchemy API Key
    • Type: string
    • Default: FZBvlPrOxtgaKBBkry3SH0W1IqH4Y5tu
  • multicall_size
    • RPC batch size per multicall request.
    • Type:number
    • Default: 50
  • workers
    • Number of parallel worker threads.
    • Type: number
    • Default: CPU - 1
  • progress
    • Each loaded pair execute this callback: (id, total, pair) => {}.
    • Callback arguments:
      • id fabric index of pair contract (int)
      • total total amount of pairs at fabric at current moment
      • pair instance of Pair({id: number, pair: string, token0: string, token1: string})
    • Type: function
    • Default: undefined
  • abort_signal
    • Signal to cancel loading and release workers.
    • Type: AbortSignal
    • Default: undefined
  • update_timeout
    • Polling interval in milliseconds. Used only in subscribe
    • Type: number
    • Default: 5000

Schema Pair

Standardized liquidity pool object.

Property Type Description
id number Numeric index of the pair in the factory
pair string DEX pair address
token0 string Token address
token1 string Token address

Example <Pair>[]

[
  {
    "id": 0,
    "pair": "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
    "token0": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "token1": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
  }
]

Smart Cross-Platform Caching

The loader automatically identifies the optimal persistent storage path for your operating system to ensure zero-configuration caching:

  • Linux: $XDG_CACHE_HOME or ~/.cache/
  • macOS: ~/Library/Caches/
  • Windows: %LOCALAPPDATA% or AppData/Local/

Cache files are named following the pattern ${package_name}_{factory_address}.csv.

API Usage

const { load } = require('uniswap-v2-loader')

console.time('SushiSwap')

load({ 
  factory: '0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac',
  to: 100,
  progress: (i, total, pair) =>
    console.log(pair.token0, pair.token1)
})
.then(pairs => {
  console.timeEnd('SushiSwap')
  console.log(pairs.length, 'pairs')
})

About

Uniswap v2 pairs loader

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors