Skip to content

🦄 A simple yet powerful open source mempool & transaction explorer in real time for EVM Dexes

License

Notifications You must be signed in to change notification settings

we-commit/in-dex-explorer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trojan Finance.

A simple yet powerfull open source transaction explorer for EVM dexes.
Currently working for: Uniswapv2 / Uniswapv3 / Sushiswap / 1inch.



Main Features.

Live Mempool.

Details

It includes mempool (pendingTxs) transactions so you can be aware of incoming movements, **that for example**, may impact in a token price.

We take the mempool input data for every new pending transaction, we decode it to get the target DEX router (univ2 univ3 sushiswap), the tokens and pools involved in the swap, the swap route, the swap method, the swap inputs and outputs amounts. With this data we classify txs and store them in a backend database connected to websocket server that monitor and publish every new pending transaction and their failed/confirmed/dropped/replaced changes.

Real Time Updates

Details

The mempool interface run with real time updates, so you can be aware of some kind of "extendend network state"... like watching the future transactions to be included (or not) in the confirmed netwrok state.

In terms of a DEX Swap over a token pair/pool this mean a new impact on it, changing the price (in some cases) of a token in the exosystem.

For example .

Just by watching the UI u are able to realize if a token its being traded like really fast (HOT), or if a token its not beign traded at all.

This give the user (a defi trader) a better idea of what its really happening in the network, protocol, dex or token.

Look at the difference between the following tokens, and get your own idea.

Token / ETH Prices

The interface uses the Uniswap SDK to get the prices of all tokens listed in the explorer.

Block Information

We query gas now and blocknative API to get latest and next block information.

Token / Transaction Links

The interface generate a couple of usefull links for the selected token and the showed transactions, so you can easily see the transaction details in etherscan and validate it.

Known Address in TX Tags

The interface shows a TAG in the transaction header of the explorer, in case a known whale address is involved in the transaction. We use sibil list to import some public / verified users from https://raw.githubusercontent.com/Uniswap/sybil-list/master/verified.json.

We are looking for a way to import more whales addresses from other sources.

Backend

Details

There are some usefull things trojan does in the backend... hope you can discover them but just to start i can post the first one.

  • Tokens. after the app start runing, listening all the swap trades, some times they got new tokens related, and we dont have the token data, so we go and get the token information from the network and we add it to our database, you can realize that this happends usually when a new token its created in the network (recetly added or deployed on main net) so you can actually be aware of all new tokens beign swapped in uniswap and get an opportunity to jump in a good project ... =)

  • In a similar way for every tx , trojan inspect the addresses related , from, receiver, to, etc, and tag them if they are knows, so you can actually be aware to, for example, when a whale wake up ...

  • etc .....


Running.

Clone the reposity and install dependencies.

git clone https://github.com/we-commit/in-dex-explorer.git

Requirements

Node

Use nodejs v14.16.1+ and run with yarn.

MongoDB

Gget the connection information to later set the ATLAS_STRING .env variable and connect to the database.

Environment file.

.env In the root folder.

# serverUser pass _ID1_ _DB_NAME_ _ID2_
ATLAS_STRING=mongodb://serverUser:pass@cluster0-shard-00-00._ID1_.mongodb.net:27017,cluster0-shard-00-01._ID1_.mongodb.net:27017,cluster0-shard-00-02._ID1_.mongodb.net:27017/_DB_NAME_?ssl=true&replicaSet=atlas-_ID2_-shard-0&authSource=admin&retryWrites=true&w=majority

# must be the same that replaced _DB_NAME_
DB_NAME=TROJAN-DB-ETH

# a collection prefix when tables are created.
COLLECTION_PREFIX=_ETH_

# ws CORS url
CORS_ORIGIN=*

GAS_STATION_API_URL=https://ethgasstation.info/api/ethgasAPI.json?
BLOCKNATIVE_API_URL=https://api.blocknative.com/gasprices/blockprices

# Get a key in blocknative.
BLOCKNATIVE_API_KEY=9999999999999999999999999999999999999999999999999999

# this is the main websocket provider FULL URL, used to listen to the events of the network.
URL=wss://mainnet.infura.io/ws/v3/99999999999999

# a list of several providers key used to get transaction data, tokens, pools, etc.
# as we run listener in separated server origins (MEMPOOL LISTENER, BLOCK LISTENER AND CONFIRMATION LISTENER)

BLOCKS_URL=wss://emerald-emerald-emerald.quiknode.pro/99999999999999999999999999999/
MEMPOOL_URL=wss://emerald-emerald-emerald.quiknode.pro/99999999999999999999999999999/
CONFIRMED_URL=wss://emerald-emerald-emerald.quiknode.pro/99999999999999999999999999999/
INFURA_URL=wss://mainnet.infura.io/ws/v3/99999999999999999999999999999
ALCHEMY_URL=wss://eth-mainnet.g.alchemy.com/v2/99999999999999999999999999999

# !!! IMPORTANT !!! DEX router address, used to check if a new transaction is a DEX transaction.
UNIV2=0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
UNIV3=0xE592427A0AEce92De3Edee1F18E0157C05861564
SUSHIV2=0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F

# used just to import tokens from the network, and init the database with a token information Cache,
# this saves a lot of calls to the network as we need token data like **decimals** to decode and parse swaps amounts correctly.

WRAPPED=https://wrapped.tokensoft.eth.link/
ROLL=https://app.tryroll.com/tokens.json
SUSHISWAP=https://raw.githubusercontent.com/sushiswapclassic/token-list/master/sushiswap.tokenlist.json
ONE_INCH=https://tokens.1inch.eth.link
COINGECKO=https://tokens.coingecko.com/uniswap/all.json
COMPOUND=https://raw.githubusercontent.com/compound-finance/token-list/master/compound.tokenlist.json
DEFIPRIME=https://defiprime.com/defiprime.tokenlist.json
MESSARI=https://messari.io/tokenlist/messari-verified
OPYN=https://raw.githubusercontent.com/opynfinance/opyn-tokenlist/master/opyn-v1.tokenlist.json
SNX=https://synths.snx.eth.link/
SET=https://raw.githubusercontent.com/SetProtocol/uniswap-tokenlist/main/set.tokenlist.json
AVE=https://tokenlist.aave.eth.link
AGORA=https://datafi.theagora.eth.link
CMCDEFI=https://defi.cmc.eth.link
CMCSTABLECOIN=https://stablecoin.cmc.eth.link
CMC200ERC20=https://erc20.cmc.eth.link
KLEROS=https://t2crtokens.eth.link
FURUCOMBO=https://cdn.furucombo.app/furucombo.tokenlist.json
KYBER=https://api.kyber.network/tokenlist
MYCRYPTOAPI=https://uniswap.mycryptoapi.com/
ZAPPER=https://zapper.fi/api/token-list
UMA=https://umaproject.org/uma.tokenlist.json
BAZAR=https://raw.githubusercontent.com/EthereansOS/Organizations-Interface/master/bazar-tokens-list/dist/decentralizedFlexibleOrganizations.json
ZERION=https://tokenlist.zerion.eth.link


# used to build the front on heroku, this env vars are used in set-heroku script
# at the moment heroku build the client.
# infura key, google analitycs ID, and the heroku app url where the websocket server will be exposed
REACT_APP_CHAIN_ID=1
REACT_APP_GOOGLE_ANALYTICS_ID=UA-999999999999999-1
REACT_APP_NETWORK_URL=https://mainnet.infura.io/v3/999999999999999
REACT_APP_WS_URL_TROJAN=https://localhost:3001/ # or https://mysuperwebsocket.herokuapp.com/ # ensure it ends on /
REACT_APP_APP_IS_OFFLINE=false
SKIP_PREFLIGHT_CHECK=true

./client/.env In the client folder.
REACT_APP_CHAIN_ID=1
REACT_APP_GOOGLE_ANALYTICS_ID=UA-999999999999999-1
REACT_APP_NETWORK_URL=https://mainnet.infura.io/v3/999999999999999
REACT_APP_WS_URL_TROJAN=http://localhost:3001/
REACT_APP_APP_IS_OFFLINE=false
SKIP_PREFLIGHT_CHECK=true


Runing init scripts.

  • In the root folder:

    yarn install
    
  • Go to the client folder:

    cd client
    yarn install
    
  • In the root folder again. Connect to mongodb, create DB, create collections and indexes as required.

      yarn create-indexes
    
      "create-indexes": "ts-node ./src/utils/initServer/create-indexes.ts",
    
  • Import some known tokens and pools. To get a database with the initial data.

    yarn init-pools && yarn init-tokens
    
    "init-tokens": "ts-node ./src/utils/initServer/init-tokens.ts",
    "init-pools": "ts-node ./src/utils/initServer/init-pools.ts",
    
  • Import known addres, to get a sample data base to tag transactions with a known user tag.

    yarn init-whales
    
    "init-whales": "ts-node ./src/utils/initServer/init-whales.ts",
    

    All these steps are required to start the app. This can take some time, specially on tokens and pools, for pools we scan factories from creation block up to the latest, so pretty much lot of blocks, but if you need a fast way to get and validate pools addresses and information this is really usefull. And same for token decimals and data.

Start Backend Services.

Having the ./.env file created, go to the repo root folder and run:

yarn build-all

  • Block Listener:

Start some common but not less important tasks. As blocks information and clear cache tables. Start and wait to get a couple of blocks information.

yarn blocks
  • Mempool Listener:

Start a pending mempool listener. Used to get the new txs, filter by dex swap, and decode their input data as needed. This is like the most expensive task, as it must get all the network incoming transactions hashes, get the transactionResponse (details), and classify it.

yarn mempool
  • Confirmation Listener.

Start an event listener, filtering by router address and swap event topic. Getting for each confirmed block, all the confirmation events and transaction related, updating the pending transaction status as correpond.

yarn confirmed
  • Start Websocket and App Client server.

Connected to the mongo cluster oplog and uses socket.io rooms pattern to serve live data over a token in a dex. Every time a tx its writen or modified in mongo, the oplog will inform that action so we can send updates to the websocket clients subscribed to a token room.

It also expose the client_build app to the public.

yarn websocket
Cheers! 🐶

Community.

Jump in...

About

🦄 A simple yet powerful open source mempool & transaction explorer in real time for EVM Dexes

Topics

Resources

License

Stars

Watchers

Forks