Skip to content

Store uniswap universal router decoded data to Mongo DB as mutations and distribute decoded data as subscriptions

Notifications You must be signed in to change notification settings

HiroyukiNaito/uniswap-universal-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uniswap-universal-graphql

Store uniswap universal router decoded data to Mongo DB as mutations and distribute decoded data as subscriptions and GraphQL query

Prerequisite

  • Uniswap Universal Publisher: The GraphQL receive data from the Uniswap Universal Publisher through mutations
  • Mongo DB: Mutations register data to the Mongo DB

Installation and Running

1. Install Node Js

$ sudo apt install nodejs

2. Install uniswap-universal-graphql

$ cd ./[application execute path]
$ git clone https://github.com/HiroyukiNaito/uniswap-universal-graphql.git
$ cd uniswap-universal-graphql
$ yarn install 

3. Set environmental valuables of uniswap-universal-graphql

$ vi .env
# Your Mongo DB server (DNS name or IP address)
MONGODB_SERVER=localhost

# Database which store Uniswap universal router data
MONGODB_DB=uniswapData

# Your Mongo DB user name
MONGODB_USER=user

# Your Mongo DB user password
MONGODB_PASSWORD=password

# Maximum object number by query 
QUERY_LIMIT=100

# Access token for Mmutation
APP_SECRET=AccessToken

# Data will expire (delete) following seconds
EXPIRE_TIME=86400

# If you want to use GraphiQL, assign 'ON' 
GRAPHIQL=ON

4. Export environmental valuables

$ export $(cat .env | xargs)

5. Run the app

$ yarn nodemon app

6. Models and Schemas

Model Name Indeces Description
txnPools _id, hash(unique), createdAt (ttl: 2592000) Transaction Pool Data. This data will vanish after a month
txns _id, hash(unique), createdAt, blockHeader.timestamp L1 Transaction Data
l2txns _id, hash(unique), createdAt, blockHeader.timestamp L2 Transaction Data

7. Subscriptions

Can subscribe L1 latest txpool data, L1 transaction data and L2 transaction data

Subscription example

  • Subscribe all properties in the most recent txpool data
subscription {
  txnPool {
    provider
    blockNumber
    blockHash
    hash
    type
    to
    from
    nonce
    gasLimit
    gasPrice
    maxPriorityFeePerGas
    maxFeePerGas
    data
    value
    chainId
    createdAt
    decodedData {
      contents
      deadline
    }
    accessList
    signature {
      _type
      networkV
      r
      s
      v
    }
  }  
}
  • Subscribe almost all properties in the most recent L1 Transaction data
subscription {
  txn {
    provider
    blockNumber
    blockHash
    hash
    type
    to
    from
    nonce
    gasLimit
    gasPrice
    maxPriorityFeePerGas
    maxFeePerGas
    data
    value
    chainId
    createdAt
    decodedData {
      contents
      deadline
    }
    accessList
    signature {
      _type
      networkV
      r
      s
      v
    }
    blockHeader {
     _type
     baseFeePerGas
     difficulty
     extraData
     gasLimit
     gasUsed
     hash
     miner
     nonce
     number
     parentHash
     timestamp
    }
  }  
}
  • Subscribe almost all properties in the most recent L1 Transaction data in bulk
subscription {
  txnBulk {
    provider
    blockNumber
    blockHash
    hash
    type
    to
    from
    nonce
    gasLimit
    gasPrice
    maxPriorityFeePerGas
    maxFeePerGas
    data
    value
    chainId
    createdAt
    decodedData {
      contents
      deadline
    }
    accessList
    signature {
      _type
      networkV
      r
      s
      v
    }
    blockHeader {
     _type
     baseFeePerGas
     difficulty
     extraData
     gasLimit
     gasUsed
     hash
     miner
     nonce
     number
     parentHash
     timestamp
    }
  }  
}
  • Subscribe almost all properties in the most recent L2 Transaction data
  • Note: L2 Uniswap transaction are significantly fewer than L1
subscription {
  l2txn {
    provider
    blockNumber
    blockHash
    hash
    type
    to
    from
    nonce
    gasLimit
    gasPrice
    maxPriorityFeePerGas
    maxFeePerGas
    data
    value
    chainId
    createdAt
    decodedData {
      contents
      deadline
    }
    accessList
    signature {
      _type
      networkV
      r
      s
      v
    }
    blockHeader {
     _type
     baseFeePerGas
     difficulty
     extraData
     gasLimit
     gasUsed
     hash
     miner
     nonce
     number
     parentHash
     timestamp
    }
  }  
}
  • Subscribe almost all properties in the most recent L2 Transaction data in bulk
  • Note: L2 Uniswap transaction are significantly fewer than L1
subscription {
  l2txnBulk {
    provider
    blockNumber
    blockHash
    hash
    type
    to
    from
    nonce
    gasLimit
    gasPrice
    maxPriorityFeePerGas
    maxFeePerGas
    data
    value
    chainId
    createdAt
    decodedData {
      contents
      deadline
    }
    accessList
    signature {
      _type
      networkV
      r
      s
      v
    }
    blockHeader {
     _type
     baseFeePerGas
     difficulty
     extraData
     gasLimit
     gasUsed
     hash
     miner
     nonce
     number
     parentHash
     timestamp
    }
  }  
}

8. Query Data

  • Can list all obtained L1 txpool data, L1 transaction data and L2 transaction data stored in Mongo DB
  • Other useful queries are considered now. Any suggestions are welcomed.

Query example

  • List all txpool data
query {
  txnPoolList(limit: 100) {
    provider
    blockNumber
    blockHash
    hash
    type
    to
    from
    nonce
    gasLimit
    gasPrice
    maxPriorityFeePerGas
    maxFeePerGas
    data
    value
    chainId
    createdAt
    decodedData {
      contents
      deadline
    }
    accessList
    signature {
      _type
      networkV
      r
      s
      v
    }
  }  
}
  • List all L1 transaction data
query {
  txnList(limit: 100) {
    provider
    blockNumber
    blockHash
    hash
    type
    to
    from
    nonce
    gasLimit
    gasPrice
    maxPriorityFeePerGas
    maxFeePerGas
    data
    value
    chainId
    createdAt
    decodedData {
      contents
      deadline
    }
    accessList
    signature {
      _type
      networkV
      r
      s
      v
    }
    blockHeader {
     _type
     baseFeePerGas
     difficulty
     extraData
     gasLimit
     gasUsed
     hash
     miner
     nonce
     number
     parentHash
     timestamp
    }
  }  
}
  • List all L2 transaction data
query {
  l2txnList(limit: 100){
    provider
    blockNumber
    blockHash
    hash
    type
    to
    from
    nonce
    gasLimit
    gasPrice
    maxPriorityFeePerGas
    maxFeePerGas
    data
    value
    chainId
    createdAt
    decodedData {
      contents
      deadline
    }
    accessList
    signature {
      _type
      networkV
      r
      s
      v
    }
    blockHeader {
     _type
     baseFeePerGas
     difficulty
     extraData
     gasLimit
     gasUsed
     hash
     miner
     nonce
     number
     parentHash
     timestamp
    }
  }  
}

About

Store uniswap universal router decoded data to Mongo DB as mutations and distribute decoded data as subscriptions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published