{"id":18492940,"url":"https://github.com/graphprotocol/uniswap-subgraph","last_synced_at":"2025-04-08T21:31:38.090Z","repository":{"id":35894272,"uuid":"165687910","full_name":"graphprotocol/uniswap-subgraph","owner":"graphprotocol","description":"This is for uniswap-v1. If you are looking for the uniswap v2 subgraph, please go to https://github.com/uniswap/uniswap-v2-subgraph","archived":false,"fork":false,"pushed_at":"2022-12-08T23:36:39.000Z","size":1097,"stargazers_count":105,"open_issues_count":18,"forks_count":57,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-27T17:04:49.204Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/graphprotocol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-14T15:47:00.000Z","updated_at":"2025-02-15T20:24:08.000Z","dependencies_parsed_at":"2022-08-09T09:40:58.683Z","dependency_job_id":null,"html_url":"https://github.com/graphprotocol/uniswap-subgraph","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphprotocol%2Funiswap-subgraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphprotocol%2Funiswap-subgraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphprotocol%2Funiswap-subgraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphprotocol%2Funiswap-subgraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graphprotocol","download_url":"https://codeload.github.com/graphprotocol/uniswap-subgraph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247931482,"owners_count":21020242,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T13:11:57.565Z","updated_at":"2025-04-08T21:31:36.187Z","avatar_url":"https://github.com/graphprotocol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Uniswap-subgraph\n\n[Uniswap](https://uniswap.io/) is a decentralized protocol for automated token exchange on Ethereum.\n\nThis Subgraph dynamically tracks any exchange created by the uniswap factory. Any exchange, any user of the protocol, and any transaction of the protocol can be queried.\n\n## Running Locally\n\nMake sure to update package.json settings to point to your own graph account.\n\n## Important Info\n\n- USD values are based on the Compound Finance DAI oracle, which gets its prices from the Maker oracle.\n- You can find the profit of a liquidity provider with the following information:\n  - Find the ratio of total tokens owned by the user out of all tokens:\n    - `(liquidityTokensMinted - liquidityTokensBurned) / totalLiquidityTokens = ratio`\n  - With that ratio, figure out how much ETH and token could be withdrawn. You must take the tokens and convert to ETH for total ETH they could withdraw:\n    - `ratio * ethBalance = ethWithdrawable`\n    - `ratio * tokenBalance * tokenPrice = tokenWithdrawableInEth`\n    - `ethWithdrawable + tokenWithdrawable = totalWithdrawable`\n  - Now take `ethDeposited - ethWithdrawn = totalEth`\n  - And `(tokenDeposited - tokenWithdrawn) * tokenPrice = totalTokensInEth`\n  - Current Liquidity profit is:\n    - `profit = totalWithdrawable - totalEth - totalTokensInEth`\n\nCurrently only the top 50 coins have decimals incorporated into values. This is because not all uniswap exchanges created have proper ERC-20 interfaces, and calling decimals fails. So with dynamic contracts, we had to opt for hardcoding in the top 50 exchanges by volume. The others have tokens represented as the full large number. (i.e. 123456789123456789 instead of 1.23456789123456789). We are tracking this issue here: https://github.com/graphprotocol/graph-node/issues/892\n\n## Queries\n\nBelow are a few ways to show how to query the uniswap-subgraph for data. The queries show most of the information that is queryable, but there are many other filtering options that can be used, just check out the [querying api](https://thegraph.com/docs/graphql-api). These queries can be used locally or in The Graph Explorer playground.\n\n### Querying Aggregated Uniswap Data\n\nThis query fetches aggredated data from all uniswap exchanges, to give a view into how much activity is happening within the whole protocol\n\n```graphql\n{\n  uniswap(id: \"1\") {\n    exchangeCount\n    totalVolumeInEth\n    totalLiquidityInEth\n    totalVolumeUSD\n    totalLiquidityUSD\n\n    totalTokenBuys\n    totalTokenSells\n    totalAddLiquidity\n    totalRemoveLiquidity\n  }\n}\n```\n\n### Querying a Uniswap Exchange\n\nThis query fetches high level information on each uniswap exchange contract.\n\n```graphql\n{\n  exchanges(where: { tokenSymbol: \"MKR\" }) {\n    id\n    tokenAddress\n    tokenSymbol\n    tokenName\n    tokenDecimals\n    fee\n    version\n    startTime\n\n    ethLiquidity\n    tokenLiquidity\n    ethBalance\n    tokenBalance\n    combinedBalanceInEth\n    combinedBalanceInUSD\n    ROI\n    totalUniToken\n\n    addLiquidityCount\n    removeLiquidityCount\n    sellTokenCount\n    buyTokenCount\n\n    lastPrice\n    price\n    tradeVolumeToken\n    tradeVolumeEth\n    totalValue\n    weightedAvgPrice\n\n    lastPriceUSD\n    priceUSD\n    weightedAvgPriceUSD\n  }\n}\n```\n\n### Querying User Data\n\n#### Transactions\n\nThis query fetches a user trading Dai between two timestamps, and returns a maximum of ten of their transactions.\n\n```graphql\n{\n  transactions(\n    where: {\n      timeStamp_gt: 1544832000\n      timeStamp_lt: 1545696000\n      tokenSymbol: \"DAI\"\n      userAddress: \"0x85c5c26dc2af5546341fc1988b9d178148b4838b\"\n    }\n    first: 10\n  ) {\n    id\n    exchangeAddress\n    userAddress\n    block\n    ethAmount\n    tokenAmount\n    fee\n    event\n    timeStamp\n  }\n}\n```\n\n#### User Balances on Exchanges\n\nThis query fetches a single user, and all their exchange balances.\n\n```graphql\n{\n  user(id: \"0x0000000000c90bc353314b6911180ed7e06019a9\") {\n    exchangeBalances {\n      userAddress\n      exchangeAddress\n\n      ethDeposited\n      tokensDeposited\n      ethWithdrawn\n      tokensWithdrawn\n      uniTokensMinted\n      uniTokensBurned\n\n      ethBought\n      ethSold\n      tokensBought\n      tokensSold\n      ethFeesPaid\n      tokenFeesPaid\n      ethFeesInUSD\n      tokenFeesInUSD\n    }\n  }\n}\n```\n\n### Querying Historical Data\n\n#### ExchangeHistory\n\nThis query fetches historical data for the MKR exchange, ordered by time:\n\n```graphql\n{\n  exchangeHistories(where: { tokenSymbol: \"MKR\" }, orderBy: timestamp, orderDirection: desc) {\n    id\n    exchangeAddress\n    tokenSymbol\n    tokenAddress\n    type\n    timestamp\n    ethLiquidity\n    tokenLiquidity\n    ethBalance\n    tokenBalance\n    combinedBalanceInEth\n    combinedBalanceInUSD\n    ROI\n    totalUniToken\n    priceUSD\n    price\n    tradeVolumeToken\n    tradeVolumeEth\n    feeInEth\n  }\n}\n```\n\nThese queries fetch historical data as the events that were emitted, split into trade events and liquidity events:\n\n```graphql\n{\n  liquidityEvents {\n    id\n    type\n    provider\n    ethAmount\n    tokenAmount\n    exchangeAddress\n    timestamp\n    txhash\n    block\n    tokenAddress\n    symbol\n    decimals\n    name\n  }\n  tradeEvents {\n    id\n    type\n    buyer\n    eth\n    token\n    exchangeAddress\n    timestamp\n    txhash\n    block\n    tokenFee\n    ethFee\n    tokenAddress\n    symbol\n    decimals\n    name\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphprotocol%2Funiswap-subgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphprotocol%2Funiswap-subgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphprotocol%2Funiswap-subgraph/lists"}