temichelle13 / uniswap-top-trades-query

This query retrieves the top 10 trades by volume on the Uniswap subgraph, providing insights into the most significant trades.
1 stars 0 forks source link

Uniswap Top Trades Query: Fetch and Analyze Top Trades on Arbitrum

This project contains a script to query the top 10 trades by volume on the Uniswap V2 subgraph using The Graph API. This information can be used for market analysis, trading strategies, and understanding liquidity flows.

Table of Contents

  1. Project Overview
  2. Why This Query is Useful
  3. Querying the Uniswap Subgraph
  4. Subgraph to Query
  5. Getting an API Key
  6. Installation
  7. Running the Script
  8. Example Output
  9. Error Handling and Troubleshooting
  10. Advanced Configuration
  11. Contributing
  12. References

Project Overview

This project provides a script to query and analyze the top 10 trades by volume on the Uniswap V2 platform deployed on the Arbitrum network. It leverages The Graph API to fetch data from the Uniswap V2 subgraph. The primary components of the project include:

Architecture:

Why This Query is Useful

Analyzing the top trades by volume enables users to gain insights into the most significant transactions on the Uniswap V2 platform. This information is crucial for:

Real-World Example:

Querying the Uniswap Subgraph

Subgraph to Query

The subgraph used in this project is the Uniswap V2 subgraph deployed on the Arbitrum network. A subgraph is a specific dataset that The Graph indexes and makes available for querying via GraphQL. This allows for efficient and flexible data retrieval from decentralized applications.

You can explore the subgraph here: Uniswap V2 Subgraph on Arbitrum

To query this subgraph from the terminal, use the following URL: https://gateway-arbitrum.network.thegraph.com/api/[YOUR_API_KEY]/subgraphs/id/EYCKATKGBKLWvSfwvBjzfCBmGwYNdVkduYXVivCsLRFu

Prerequisites

Ensure you have the following prerequisites before running the script:

Setting Up Node.js:

If you don't have Node.js installed, follow this guide to set it up for your operating system.

Getting an API Key

  1. Visit The Graph's Explorer.
  2. Sign up or log in by selecting the "connect wallet" button in the top right corner of the page to connect your Web3 or Cryptocurrency wallet such as Coinbase Wallet, MetaMask, Safe, or WalletConnet.
  3. Navigate to your dashboard and create a new API key. Copy this key for use in our query. It will remain on your dashboard until you delete it, ensuring easy access if you forget or lose it. You can also create another one if needed.

Screenshots: connect-wallet create-api-key-screen

Note: Each API key has usage limits. Refer to The Graph's documentation for more details on quotas and limitations.

Installation

1. Clone the Repository:

Open your terminal and run the following commands:

git clone https://github.com/temichelle13/uniswap-top-trades-query
cd uniswap-top-trades-query

Note: This will clone the repository to your local machine and navigate into the project's root directory.

2. Install Dependencies:

npm install axios dotenv

This command installs the necessary dependencies: axios for HTTP requests and dotenv for environment variable management

Note: Ensure you run these commands from the root directory of the cloned repository, which we navigated to it the previous step.

3. Set Up Environment Variables

Sample .env File:

GRAPH_API_KEY=your_api_key_here

Why Use Environment Variables?

Environment variables allow you to manage configuration settings and sensitive information, like API keys, securely and separately from your source code. This helps to keep your private information and assets safe.

Running the Script

Execute the following command to run the script and fetch the top 10 trades by volume from the Uniswap V2 subgraph:

node query.js

The script will output details of the top trades, including trade IDs, transaction IDs, amounts in USD, and trading pairs.

Interpreting the Results:

Performance Considerations:

Example Query

query TopTrades {
  swaps(first: 10, orderBy: amountUSD, orderDirection: desc) {
    id
    amountUSD
    transaction {
      id
    }
    pair {
      token0 {
        symbol
      }
      token1 {
        symbol
      }
    }
  }
}
`;

Example Output

Upon successful execution, the script will produce an output similar to the following:

Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-27
  Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
  Amount (USD): 4.3981656918396856e+33
  Pair: Unknown Token / 0xDEV
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-28
  Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
  Amount (USD): 4.3981656918396856e+33
  Pair: USDC / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-31
  Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
  Amount (USD): 4.3981656918396856e+33
  Pair: ZKLK / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-26
  Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
  Amount (USD): 4.3981656918396856e+33
  Pair: PALAI / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-29
  Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
  Amount (USD): 4.3981656918396856e+33
  Pair: TPAD / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-32
  Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
  Amount (USD): 4.3981656918396856e+33
  Pair: PEPE / Unknown Token
---------------------------------------
Trade ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152-30
  Transaction ID: 0x76f2546586ac5b1ba522babaa5fbbd9e65ca2047f39497b6b277a08da35cb152
  Amount (USD): 4.3981656918396856e+33
  Pair: CRYPT / Unknown Token
---------------------------------------
Trade ID: 0x310307c773fcdbfacc21dba2ed454c48511529cf9e18dfe192f4d98c53bb42de-1
  Transaction ID: 0x310307c773fcdbfacc21dba2ed454c48511529cf9e18dfe192f4d98c53bb42de
  Amount (USD): 4.3981656918396856e+33
  Pair: PEPE / Unknown Token
---------------------------------------
Trade ID: 0xea696c395092e2697212b5de2fbb00a10870286bd9a6e4fe903ca53250c55ab6-0
  Transaction ID: 0xea696c395092e2697212b5de2fbb00a10870286bd9a6e4fe903ca53250c55ab6
  Amount (USD): 1.278864171116066e+18
  Pair: TRIAS / USDC
---------------------------------------
Trade ID: 0x97a6234a8eb09a6f193d1488e94c2262a8e7ee34b0e84afdbdbbe7e2bc1b7739-0
  Transaction ID: 0x97a6234a8eb09a6f193d1488e94c2262a8e7ee34b0e84afdbdbbe7e2bc1b7739
  Amount (USD): 1.2137438260380554e+16
  Pair: $MONG / MING
---------------------------------------

Error Handling and Troubleshooting

Common Errors

Troubleshooting Steps

Additional Resources:

Advanced Configuration

Modifying the Query

To customize the query, edit the query.js file. For example, to fetch trades for a different token pair, modify the GraphQL query string accordingly.

Example:

const query = `
{
  trades(first: 10, orderBy: volumeUSD, orderDirection: desc, where: {pair: "0x1234567890abcdef"}) {
    id
    transaction {
      id
    }
    volumeUSD
    pair {
      token0 {
        symbol
      }
      token1 {
        symbol
      }
    }
  }
}

Integration with Other Services

You can extend this project by integrating it with other services such as:

Contributing

Contributions are always welcome to this project! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them with a detailed message.
  4. Push your changes to your forked repository.
  5. Submit a pull request to the main repository.

Code of Conduct: Please adhere to our Code of Conduct to ensure a positive and inclusive community.

Detailed Contribution Guidelines: Refer to our Contributing Guide for more details on how to contribute.

Summary:

References

Additional Resources:

Additional Notes

This project demonstrates how to interact with The Graph's GraphQL endpoint to fetch data from a subgraph. The provided query fetches the top 10 trades by volume from the Uniswap V2 subgraph on the Arbitrum network.

Dependencies

Repository

Visit the GitHub repository to explore the project.