Commit cb8138db authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

Initial commit

parents
Pipeline #883 canceled with stages
build/
node_modules/
src/types/
.DS_STORE
yarn-error.log
\ No newline at end of file
This diff is collapsed.
# Uniswap V2 Subgraph
[Uniswap](https://uniswap.org/) is a decentralized protocol for automated token exchange on Ethereum.
This subgraph dynamically tracks any pair created by the uniswap factory. It tracks of the current state of Uniswap contracts, and contains derived stats for things like historical data and USD prices.
- aggregated data across pairs and tokens,
- data on individual pairs and tokens,
- data on transactions
- data on liquidity providers
- historical data on Uniswap, pairs or tokens, aggregated by day
## Running Locally
Make sure to update package.json settings to point to your own graph account.
## 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](https://thegraph.com/docs/graphql-api). These queries can be used locally or in The Graph Explorer playground.
## Key Entity Overviews
#### UniswapFactory
Contains data across all of Uniswap V2. This entity tracks important things like total liquidity (in ETH and USD, see below), all time volume, transaction count, number of pairs and more.
#### Token
Contains data on a specific token. This token specific data is aggregated across all pairs, and is updated whenever there is a transaction involving that token.
#### Pair
Contains data on a specific pair.
#### Transaction
Every transaction on Uniswap is stored. Each transaction contains an array of mints, burns, and swaps that occured within it.
#### Mint, Burn, Swap
These contain specifc information about a transaction. Things like which pair triggered the transaction, amounts, sender, recipient, and more. Each is linked to a parent Transaction entity.
## Example Queries
### Querying Aggregated Uniswap Data
This query fetches aggredated data from all uniswap pairs and tokens, to give a view into how much activity is happening within the whole protocol.
```graphql
{
uniswapFactories(first: 1) {
pairCount
totalVolumeUSD
totalLiquidityUSD
}
}
```
subgraph.yaml
修改factory地址和开始区块,如果开始区块距今不满足7天,explorer info前端会报错
这个subgraph主要是为了获取区块基本信息,部署完swap的subgraph后,可以使用任意一个factory地址替换
部署完成后可以供usd1swap movaswap同时使用,也可以部署两个分开用
部署
yarn
yarn codegen
graph remove movat/swap-block --node http://13.204.105.72:8020
graph create movat/swap-block --node http://13.204.105.72:8020
graph deploy movat/swap-block --ipfs http://13.204.105.72:5001 --node http://13.204.105.72:8020
[
{
"inputs": [
{
"internalType": "address",
"name": "_feeToSetter",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "pair",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "PairCreated",
"type": "event"
},
{
"constant": true,
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "allPairs",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "allPairsLength",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "tokenA",
"type": "address"
},
{
"internalType": "address",
"name": "tokenB",
"type": "address"
}
],
"name": "createPair",
"outputs": [
{
"internalType": "address",
"name": "pair",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeTo",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeToSetter",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "getPair",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "_feeTo",
"type": "address"
}
],
"name": "setFeeTo",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "_feeToSetter",
"type": "address"
}
],
"name": "setFeeToSetter",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
{
"name": "uniswap-v2-subgraph",
"version": "1.0.0",
"repository": "https://github.com/graphprotocol/uniswap-v2-subgraph",
"license": "GPL-3.0-or-later",
"scripts": {
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"create-local": "graph create davekaj/uniswap --node http://127.0.0.1:8020",
"deploy-local": "graph deploy davekaj/uniswap --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy ianlapham/uniswap-v2-dev --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy-staging": "graph deploy $THE_GRAPH_GITHUB_USER/$THE_GRAPH_SUBGRAPH_NAME /Uniswap --ipfs https://api.staging.thegraph.com/ipfs/ --node https://api.staging.thegraph.com/deploy/",
"watch-local": "graph deploy graphprotocol/Uniswap2 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.21.3",
"@graphprotocol/graph-ts": "^0.20.1",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^6.2.2",
"eslint-config-prettier": "^6.1.0",
"prettier": "^1.18.2",
"typescript": "^3.5.2"
}
}
type Block @entity {
id: ID!
number: BigInt!
timestamp: BigInt!
parentHash: String
author: String
difficulty: BigInt
totalDifficulty: BigInt
gasUsed: BigInt
gasLimit: BigInt
receiptsRoot: String
transactionsRoot: String
stateRoot: String
size: BigInt
unclesHash: String
}
\ No newline at end of file
import { ethereum } from '@graphprotocol/graph-ts'
import { Block } from '../types/schema'
export function handleBlock(block: ethereum.Block): void {
let id = block.hash.toHex()
let blockEntity = new Block(id);
blockEntity.number = block.number;
blockEntity.timestamp = block.timestamp;
blockEntity.parentHash = block.parentHash.toHex();
blockEntity.author = block.author.toHex();
blockEntity.difficulty = block.difficulty;
blockEntity.totalDifficulty = block.totalDifficulty;
blockEntity.gasUsed = block.gasUsed;
blockEntity.gasLimit = block.gasLimit;
blockEntity.receiptsRoot = block.receiptsRoot.toHex();
blockEntity.transactionsRoot = block.transactionsRoot.toHex();
blockEntity.stateRoot = block.stateRoot.toHex();
blockEntity.size = block.size;
blockEntity.unclesHash = block.unclesHash.toHex();
blockEntity.save();
}
\ No newline at end of file
specVersion: 0.0.2
description: Uniswap is a decentralized protocol for automated token exchange on Ethereum.
repository: https://github.com/Uniswap/uniswap-v2-blocks-subgraph
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: Factory
network: mainnet
source:
address: '0x759A45623b833247cC44FCbcA4D201c83F99D712'
abi: Factory
startBlock: 1
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/blocks.ts
entities:
- Blocks
abis:
- name: Factory
file: ./abis/factory.json
blockHandlers:
- handler: handleBlock
graph remove movat/uniswap-blocks --node http://13.204.105.72:8020
graph create movat/uniswap-blocks --node http://13.204.105.72:8020
graph deploy movat/uniswap-blocks --ipfs http://13.204.105.72:5001 --node http://13.204.105.72:8020
curl http://13.204.105.72:5001/api/v0/version
curl http://13.204.105.72:8000/subgraphs/name/movat/uniswap
QmXT56qe3bbBT19SHJ8YvzHTCm5XuKLh4KVUhXjRmp2aqK
QmbQZUUV7N9kD7z5x8BKBdXzVHQ11o1gpEGEGuahKnukAh
graph remove movabeta/usdswap-blocks --node http://13.204.105.72:8020
graph create movabeta/usdswap-blocks --node http://13.204.105.72:8020
graph deploy movabeta/usdswap-blocks --ipfs http://13.204.105.72:5001 --node http://13.204.105.72:8020
{
"extends": "./node_modules/@graphprotocol/graph-ts/tsconfig.json",
"compilerOptions": {
"types": ["@graphprotocol/graph-ts"]
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment