• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    TypeScript
  • Created almost 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is for uniswap-v1. If you are looking for the uniswap v2 subgraph, please go to https://github.com/uniswap/uniswap-v2-subgraph

Uniswap-subgraph

Uniswap is a decentralized protocol for automated token exchange on Ethereum.

This 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.

Running Locally

Make sure to update package.json settings to point to your own graph account.

Important Info

  • USD values are based on the Compound Finance DAI oracle, which gets its prices from the Maker oracle.
  • You can find the profit of a liquidity provider with the following information:
    • Find the ratio of total tokens owned by the user out of all tokens:
      • (liquidityTokensMinted - liquidityTokensBurned) / totalLiquidityTokens = ratio
    • 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:
      • ratio * ethBalance = ethWithdrawable
      • ratio * tokenBalance * tokenPrice = tokenWithdrawableInEth
      • ethWithdrawable + tokenWithdrawable = totalWithdrawable
    • Now take ethDeposited - ethWithdrawn = totalEth
    • And (tokenDeposited - tokenWithdrawn) * tokenPrice = totalTokensInEth
    • Current Liquidity profit is:
      • profit = totalWithdrawable - totalEth - totalTokensInEth

Currently 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: graphprotocol/graph-node#892

Queries

Below 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. These queries can be used locally or in The Graph Explorer playground.

Querying Aggregated Uniswap Data

This query fetches aggredated data from all uniswap exchanges, to give a view into how much activity is happening within the whole protocol

{
  uniswap(id: "1") {
    exchangeCount
    totalVolumeInEth
    totalLiquidityInEth
    totalVolumeUSD
    totalLiquidityUSD

    totalTokenBuys
    totalTokenSells
    totalAddLiquidity
    totalRemoveLiquidity
  }
}

Querying a Uniswap Exchange

This query fetches high level information on each uniswap exchange contract.

{
  exchanges(where: { tokenSymbol: "MKR" }) {
    id
    tokenAddress
    tokenSymbol
    tokenName
    tokenDecimals
    fee
    version
    startTime

    ethLiquidity
    tokenLiquidity
    ethBalance
    tokenBalance
    combinedBalanceInEth
    combinedBalanceInUSD
    ROI
    totalUniToken

    addLiquidityCount
    removeLiquidityCount
    sellTokenCount
    buyTokenCount

    lastPrice
    price
    tradeVolumeToken
    tradeVolumeEth
    totalValue
    weightedAvgPrice

    lastPriceUSD
    priceUSD
    weightedAvgPriceUSD
  }
}

Querying User Data

Transactions

This query fetches a user trading Dai between two timestamps, and returns a maximum of ten of their transactions.

{
  transactions(
    where: {
      timeStamp_gt: 1544832000
      timeStamp_lt: 1545696000
      tokenSymbol: "DAI"
      userAddress: "0x85c5c26dc2af5546341fc1988b9d178148b4838b"
    }
    first: 10
  ) {
    id
    exchangeAddress
    userAddress
    block
    ethAmount
    tokenAmount
    fee
    event
    timeStamp
  }
}

User Balances on Exchanges

This query fetches a single user, and all their exchange balances.

{
  user(id: "0x0000000000c90bc353314b6911180ed7e06019a9") {
    exchangeBalances {
      userAddress
      exchangeAddress

      ethDeposited
      tokensDeposited
      ethWithdrawn
      tokensWithdrawn
      uniTokensMinted
      uniTokensBurned

      ethBought
      ethSold
      tokensBought
      tokensSold
      ethFeesPaid
      tokenFeesPaid
      ethFeesInUSD
      tokenFeesInUSD
    }
  }
}

Querying Historical Data

ExchangeHistory

This query fetches historical data for the MKR exchange, ordered by time:

{
  exchangeHistories(where: { tokenSymbol: "MKR" }, orderBy: timestamp, orderDirection: desc) {
    id
    exchangeAddress
    tokenSymbol
    tokenAddress
    type
    timestamp
    ethLiquidity
    tokenLiquidity
    ethBalance
    tokenBalance
    combinedBalanceInEth
    combinedBalanceInUSD
    ROI
    totalUniToken
    priceUSD
    price
    tradeVolumeToken
    tradeVolumeEth
    feeInEth
  }
}

These queries fetch historical data as the events that were emitted, split into trade events and liquidity events:

{
  liquidityEvents {
    id
    type
    provider
    ethAmount
    tokenAmount
    exchangeAddress
    timestamp
    txhash
    block
    tokenAddress
    symbol
    decimals
    name
  }
  tradeEvents {
    id
    type
    buyer
    eth
    token
    exchangeAddress
    timestamp
    txhash
    block
    tokenFee
    ethFee
    tokenAddress
    symbol
    decimals
    name
  }
}

More Repositories

1

graph-node

Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
Rust
2,882
star
2

graph-tooling

Monorepo for various tools used by subgraph developers.
TypeScript
387
star
3

contracts

Contracts repository for The Graph protocol
TypeScript
316
star
4

indexer

Graph Protocol indexer components and infrastructure
TypeScript
236
star
5

graph-ts

TypeScript/AssemblyScript library for writing mappings for The Graph
214
star
6

example-subgraph

An example to help you get started with The Graph
Solidity
179
star
7

graph-client

The Graph library for building GraphQL-based dapps in a decentralized way.
TypeScript
172
star
8

everest

Registry of crypto projects
JavaScript
98
star
9

docs

Documentation for The Graph
MDX
78
star
10

graph-network-subgraph

The subgraph, the smart contracts, the tests, and documents for the Graph Explorer Decentralized Application
TypeScript
69
star
11

research

Research, proposals, papers, and specs
TeX
48
star
12

ipfs-sync

Script to sync files from one IPFS node to another
JavaScript
48
star
13

ethdenver-dapp

ETHDenver example dApp built on The Graph
JavaScript
43
star
14

erc20-subgraph

TypeScript
33
star
15

hardhat-graph

TypeScript
33
star
16

decentraland-subgraph

Decentraland data source for The Graph
TypeScript
29
star
17

common-ts

Common TypeScript library for use in Graph Protocol components
TypeScript
24
star
18

ens-rainbow

Rust
22
star
19

ens-subgraph

Official repo: https://github.com/ensdomains/ens-subgraph
TypeScript
22
star
20

aragon-subgraph

DAO - subgraph
TypeScript
21
star
21

mission-control-indexer

Technical indexer documentation and infrastructure templates for the Mission Control testnet
TypeScript
21
star
22

indexer-rs

Rewrite of indexer-service in Rust with TAP payments implementation
Rust
21
star
23

token-distribution

Token distribution contracts
TypeScript
21
star
24

agora

Cost model
Rust
20
star
25

rfcs

Graph Protocol RFCs and Engineering Plans
CSS
16
star
26

mission-control-curator

15
star
27

0x-subgraph

Subgraph that tracks events of the 0x protocol
TypeScript
15
star
28

example-subgraphs

TypeScript
14
star
29

allocation-optimizer

Agents and algorithms for optimizing Indexer decision problems.
Julia
14
star
30

firehose-cosmos

Cosmos Firehose integration
Go
11
star
31

support

Community support for the Hosted Service of The Graph
10
star
32

full-stack-graph-app

Deploy a full stack app leveraging The Graph with one click.
TypeScript
10
star
33

compound-v1-subgraph

Compound is an open-source protocol for algorithmic, efficient Money Markets on the Ethereum blockchain.
TypeScript
9
star
34

crypto-buddies

Gatsby React app interview challenge
JavaScript
8
star
35

augur-subgraph

Subgraph for the Augur protocol
TypeScript
8
star
36

qlog

A tool to summarize and analyze graph-node query logs
Rust
8
star
37

bitsausage

Bitsausage auction project
JavaScript
7
star
38

registry-starter

Starting point for apps that curate data
JavaScript
7
star
39

graph-network-analytics-subgraph

Analytics subgraph for Graph Network
TypeScript
6
star
40

stable-hash

A structured hash that is platform independent and has backward compatibility
Rust
6
star
41

common-subgraphs

Subgraphs that are generally useful and/or good examples
Shell
6
star
42

sportx-subgraph

SportX provides a sports betting platform for Ethereum.
TypeScript
6
star
43

block-oracle

Rust
6
star
44

graph-improvement-proposals

The canonical repository for The Graph's protocol governance. Read more about it: https://thegraph.com/ecosystem/governance/
5
star
45

FOAM-subgraph

The FOAM Proof of Location protocol empowers a permissionless and autonomous network of radio beacons that can offer secure location services.
TypeScript
5
star
46

hackathon-react-apollo-app

React, Apollo & Material UI example app
JavaScript
5
star
47

solidity-bindgen

Rust
5
star
48

hardhat-graph-demo

Demo repository for the hardhat-graph plugin
TypeScript
4
star
49

dharma-subgraph

Dharma protocol subgraph
TypeScript
4
star
50

hackathon-scaffold

A starting point for building dApps on The Graph
JavaScript
4
star
51

mutations

TypeScript
4
star
52

compound-subgraph-wrapper

A wrapper service that extends the Compound subgraph with custom resolvers
TypeScript
4
star
53

cosmoshub-ts

TypeScript
4
star
54

memefactory-subgraph

Memefactory subgraph for The Graph
TypeScript
3
star
55

eip-712-derive

Easy EIP-712
Rust
3
star
56

ipfs-mgm

IPFS cli for content syncing
Go
3
star
57

graph-node-docker

Preconfigured Docker image for running a Graph Node
Dockerfile
3
star
58

adchain-subgraph

Example subgraph project for querying the AdChain TCR
TypeScript
3
star
59

graph-local-state

Shell
2
star
60

thegarii

The Graph Arweave Integration Implementation
Rust
2
star
61

codex

2
star
62

maker-subgraph

Subgraph for maker
TypeScript
2
star
63

governance-subgraph

Subgraph for graph governance
TypeScript
2
star
64

firehose-arweave

The firehose integration with the garii
Go
2
star
65

autotasks

A collection of Defender Autotasks to interact with The Graph protocol contracts
TypeScript
2
star
66

query-examples

Provides examples of how to query Subgraphs published to The Graph Network in a variety of frameworks/languages
2
star
67

DEPRECATED-compound-v2-subgraph

Compound is an open-source protocol for algorithmic, efficient Money Markets on the Ethereum blockchain. DEPRECATED - see the repository under compound-finances github for the current repository https://github.com/graphprotocol/compound-v2-subgraph-1
TypeScript
2
star
68

everest-subgraph

Subgraph for the MetaCartel Everest project registry
1
star
69

hack-for-freedom

1
star
70

ethcc-hackathon

1
star
71

gitcoin-beyond-blockchain-hackathon

A three week virtual hackathon running from June 24th to July 10th powered by Gitcoin
1
star
72

network-support

Graph Network issues and feature requests
1
star
73

subgraph-oracle

The Subgraph Oracle
Rust
1
star
74

graph-pino

Pino log message formatter for The Graph
JavaScript
1
star