graphprotocol / uniswap-subgraph Goto Github PK
View Code? Open in Web Editor NEWThis is for uniswap-v1. If you are looking for the uniswap v2 subgraph, please go to https://github.com/uniswap/uniswap-v2-subgraph
This is for uniswap-v1. If you are looking for the uniswap v2 subgraph, please go to https://github.com/uniswap/uniswap-v2-subgraph
There are these queries that I was expected to return the same value but don't. Is it expected behavior? Why?
This query is returning a list of transactions
{
transactions (where: {user: "0x000000000a3c7c86345a35a0e97a4bb4370a8dd9"}) {
tx
}
}
But that isn't:
{
user (id: "0x000000000a3c7c86345a35a0e97a4bb4370a8dd9") {
txs {
tx
}
}
}
Thanks!
Hello,
I deployed subgraph to my onw thegraph.com,but when sync block faild.
The error message is:
Done processing Ethereum trigger, waiting_ms: 0, handler: handleSync, total_ms: 24, trigger_type: Log, address: 0xcc6b…4f5c, signature: Sync(uint112,uint112), block_hash: 0x2a154b942389a98412a014ef72b9b2228f8410a10ec932ee0febaa4bc00d7e74, block_number: 10674061
I am running the following query regularly (every 1 minute). Usually it works fine, but ~1 time per 300 queries it raises the error Failed to get entities from store: canceling statement due to conflict with recovery
.
Has anyone had the same or similar problem?
{
pairs(where: { id_in: ["0x8878df9e1a7c87dcbf6d3999d997f262c05d8c70","0x819f3450da6f110ba6ea52195b3beafa246062de","0x0c4a68cf6857cc76fe946d04fe85fac5fae9625e","0x3dd49f67e9d5bc4c5e6634b3f70bfd9dc1b6bd74","0x7924a818013f39cf800f5589ff1f1f0def54f31f","0x88d97d199b9ed37c29d846d00d443de980832a22","0xde5b7ff5b10cc5f8c95a2e2b643e3abf5179c987","0x3b3d4eefdc603b232907a7f3d0ed1eea5c62b5f7","0x4dd26482738be6c06c31467a19dcda9ad781e8c4","0x2fdbadf3c4d5a8666bc06645b8358ab803996e28","0x23bff8ca20aac06efdf23cee3b8ae296a30dfd27","0xb6909b960dbbe7392d405429eb2b3649752b4838","0x7dd3f5705504002dc946aeafe6629b9481b72272","0x26aad2da94c59524ac0d93f6d6cbf9071d7086f2","0x4d5ef58aac27d99935e5b6b4a6778ff292059991","0x87febfb3ac5791034fd5ef1a615e9d9627c2665d","0xd3d2e2692501a5c9ca623199d38826e513033a17","0xbb2b8038a1640196fbe3e38816f3e67cba72d940","0x1d6432aefeae2c0ff1393120541863822a4e6fa7","0xddf9b7a31b32ebaf5c064c80900046c9e5b7c65f","0xe1573b9d29e2183b1af0e743dc2754979a40d237","0xd4405f0704621dbe9d4dea60e128e0c3b26bddbd","0x88ff79eb2bc5850f27315415da8685282c7610f9","0x9973bb0fe5f8df5de730776df09e946c74254fb3","0x12d4444f96c644385d8ab355f6ddf801315b6254","0x8bd1661da98ebdd3bd080f0be4e6d9be8ce9858c","0x01962144d41415cca072900fe87bbe2992a99f10","0xdc98556ce24f007a5ef6dc1ce96322d65832a819","0xec6a6b7db761a5c9910ba8fcab98116d384b1b85","0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b974","0xb9b752f7f4a4680eeb327ffe728f46666763a796","0x303ffcd201831db88422b76f633458e94e05c33e","0xa3b79b78678c15eec77389b380988b0229da1876","0x32ce7e48debdccbfe0cd037cc89526e4382cb81b","0xa478c2975ab1ea89e8196811f51a7b7ade33eb11","0xce84867c3c02b05dc570d0135103d3fb9cc19433","0x0c722a487876989af8a05fffb6e32e45cc23fb3a","0xdfc14d2af169b0d36c4eff567ada9b2e0cae044f","0xab3f9bf1d81ddb224a2014e98b238638824bcf20","0xb27de0ba2abfbfdf15667a939f041b52118af5ba","0x4dc02e1bb2ec1ce4c50c351e6e06505e7b1dce8d","0x97c4adc5d28a86f9470c70dd91dc6cc2f20d2d4d","0xba65016890709dbc9491ca7bf5de395b8441dc8b","0x4d96369002fc5b9687ee924d458a7e5baa5df34e","0xf043c39a106db6b58c76995f30ba35fd211c3b76","0x9b7dad79fc16106b47a3dab791f389c167e15eb0","0xe3ee3d5f7e9c750490d99ab166edc1886de0a85e","0xc2adda861f89bbb333c90c492cb837741916a225","0x56feaccb7f750b997b36a68625c7c596f0b41a58","0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc","0x0d0d65e7a7db277d3e0f5e1676325e75f3340455","0xc50ef7861153c51d383d9a7d48e6c9467fb90c38","0x10db37f4d9b3bc32ae8303b46e6166f7e9652d28","0xbe55c87dff2a9f5c95cb5c07572c51fd91fe0732","0xd65e975c7d0d5871eff8b079120e43c9f377ada1","0x1107b6081231d7f256269ad014bf92e041cb08df","0xc76225124f3caab07f609b1d147a31de43926cd6","0xf421c3f2e695c2d4c0765379ccace8ade4a480d9","0xf66369997ae562bc9eec2ab9541581252f9ca383","0xcffdded873554f362ac02f8fb1f02e5ada10516f","0x43ae24960e5534731fc831386c07755a2dc33d47","0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852","0xd3d8c734f06229e36febd07505d8f57b7b78af7c"] }) {
token0 {
symbol
}
reserve0
reserveUSD
}
}
Failed to get entities from store: canceling statement due to conflict with recovery, query = "/* qid: b415f1bb122a7d2c-902dae5258e93193 */\nselect \'Pair\' as entity, to_jsonb(c.*) as data from (select * \n from \"sgd25626\".\"pair\" c\n where c.\"block_range\" @> $1 and (\"id\" in ($2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $60, $61, $62, $63, $64))\n\n order by \"id\", block_range\n limit 100) c -- binds: [12201172, \"0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc\", \"0x43ae24960e5534731fc831386c07755a2dc33d47\", \"0xc2adda861f89bbb333c90c492cb837741916a225\", \"0xb6909b960dbbe7392d405429eb2b3649752b4838\", \"0xa478c2975ab1ea89e8196811f51a7b7ade33eb11\", \"0xbb2b8038a1640196fbe3e38816f3e67cba72d940\", \"0xd3d2e2692501a5c9ca623199d38826e513033a17\", \"0x2fdbadf3c4d5a8666bc06645b8358ab803996e28\", \"0xa2107fa5b38d9bbd2c461d6edf11b11a50f6b974\", \"0xdfc14d2af169b0d36c4eff567ada9b2e0cae044f\", \"0xcffdded873554f362ac02f8fb1f02e5ada10516f\", \"0x8bd1661da98ebdd3bd080f0be4e6d9be8ce9858c\", \"0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852\", \"0xab3f9bf1d81ddb224a2014e98b238638824bcf20\", \"0x8878df9e1a7c87dcbf6d3999d997f262c05d8c70\", \"0xf421c3f2e695c2d4c0765379ccace8ade4a480d9\", \"0x88d97d199b9ed37c29d846d00d443de980832a22\", \"0xd3d8c734f06229e36febd07505d8f57b7b78af7c\", \"0xce84867c3c02b05dc570d0135103d3fb9cc19433\", \"0xc50ef7861153c51d383d9a7d48e6c9467fb90c38\", \"0xddf9b7a31b32ebaf5c064c80900046c9e5b7c65f\", \"0xba65016890709dbc9491ca7bf5de395b8441dc8b\", \"0x26aad2da94c59524ac0d93f6d6cbf9071d7086f2\", \"0xb9b752f7f4a4680eeb327ffe728f46666763a796\", \"0x9b7dad79fc16106b47a3dab791f389c167e15eb0\", \"0x819f3450da6f110ba6ea52195b3beafa246062de\", \"0xb27de0ba2abfbfdf15667a939f041b52118af5ba\", \"0x0c4a68cf6857cc76fe946d04fe85fac5fae9625e\", \"0x7924a818013f39cf800f5589ff1f1f0def54f31f\", \"0xde5b7ff5b10cc5f8c95a2e2b643e3abf5179c987\", \"0x3b3d4eefdc603b232907a7f3d0ed1eea5c62b5f7\", \"0x4dd26482738be6c06c31467a19dcda9ad781e8c4\", \"0x23bff8ca20aac06efdf23cee3b8ae296a30dfd27\", \"0x7dd3f5705504002dc946aeafe6629b9481b72272\", \"0x4d5ef58aac27d99935e5b6b4a6778ff292059991\", \"0x87febfb3ac5791034fd5ef1a615e9d9627c2665d\", \"0xe1573b9d29e2183b1af0e743dc2754979a40d237\", \"0x88ff79eb2bc5850f27315415da8685282c7610f9\", \"0x9973bb0fe5f8df5de730776df09e946c74254fb3\", \"0x12d4444f96c644385d8ab355f6ddf801315b6254\", \"0xdc98556ce24f007a5ef6dc1ce96322d65832a819\", \"0xec6a6b7db761a5c9910ba8fcab98116d384b1b85\", \"0x303ffcd201831db88422b76f633458e94e05c33e\", \"0x0c722a487876989af8a05fffb6e32e45cc23fb3a\", \"0x4dc02e1bb2ec1ce4c50c351e6e06505e7b1dce8d\", \"0x4d96369002fc5b9687ee924d458a7e5baa5df34e\", \"0x56feaccb7f750b997b36a68625c7c596f0b41a58\", \"0x0d0d65e7a7db277d3e0f5e1676325e75f3340455\", \"0xbe55c87dff2a9f5c95cb5c07572c51fd91fe0732\", \"0xd65e975c7d0d5871eff8b079120e43c9f377ada1\", \"0xc76225124f3caab07f609b1d147a31de43926cd6\", \"0xf66369997ae562bc9eec2ab9541581252f9ca383\", \"0x3dd49f67e9d5bc4c5e6634b3f70bfd9dc1b6bd74\", \"0x1d6432aefeae2c0ff1393120541863822a4e6fa7\", \"0xd4405f0704621dbe9d4dea60e128e0c3b26bddbd\", \"0x01962144d41415cca072900fe87bbe2992a99f10\", \"0xa3b79b78678c15eec77389b380988b0229da1876\", \"0x32ce7e48debdccbfe0cd037cc89526e4382cb81b\", \"0x97c4adc5d28a86f9470c70dd91dc6cc2f20d2d4d\", \"0xf043c39a106db6b58c76995f30ba35fd211c3b76\", \"0xe3ee3d5f7e9c750490d99ab166edc1886de0a85e\", \"0x10db37f4d9b3bc32ae8303b46e6166f7e9652d28\", \"0x1107b6081231d7f256269ad014bf92e041cb08df\"]"
It seems that for some providers of sETH/ETH pool subgraph shows incorrect balance.
Here are some of the affected providers:
I checked some other pools and they didn't seem to have this issue.
To reproduce:
{
userExchangeDatas(where: {
user: "0x0d7f2e43b77deb6e922640a4b7edc5b7e874dd70",
exchange: "0xe9cf7887b93150d4f2da7dfc6d502b216438f244"
}) {
uniTokenBalance
}
}
vs
etherscan
Recent Synthetix update might be relevant but I'm not sure how.
they both share teh same addr. to fix
Everything worked up until point 6 < https://github.com/graphprotocol/uniswap-subgraph#steps-to-get-the-uniswap-subgraph-running >
Compiling graph-server-json-rpc v0.5.0 (/home/ubuntu/graph-node/server/json-rpc)
error[E0309]: the parameter type `U` may not live long enough
--> runtime/wasm/src/module/mod.rs:139:5
|
135 | pub(crate) struct WasmiModule<'a, T, L, S, U> {
| - help: consider adding an explicit lifetime bound `U: 'a`...
...
139 | host_exports: &'a HostExports<T, L, S, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...so that the reference type `&'a host_exports::HostExports<T, L, S, U>` does not outlive the data it points at
--> runtime/wasm/src/module/mod.rs:139:5
|
139 | host_exports: &'a HostExports<T, L, S, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0309]: the parameter type `S` may not live long enough
--> runtime/wasm/src/module/mod.rs:139:5
|
135 | pub(crate) struct WasmiModule<'a, T, L, S, U> {
| - help: consider adding an explicit lifetime bound `S: 'a`...
...
139 | host_exports: &'a HostExports<T, L, S, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...so that the reference type `&'a host_exports::HostExports<T, L, S, U>` does not outlive the data it points at
--> runtime/wasm/src/module/mod.rs:139:5
|
139 | host_exports: &'a HostExports<T, L, S, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0309]: the parameter type `L` may not live long enough
--> runtime/wasm/src/module/mod.rs:139:5
|
135 | pub(crate) struct WasmiModule<'a, T, L, S, U> {
| - help: consider adding an explicit lifetime bound `L: 'a`...
...
139 | host_exports: &'a HostExports<T, L, S, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...so that the reference type `&'a host_exports::HostExports<T, L, S, U>` does not outlive the data it points at
--> runtime/wasm/src/module/mod.rs:139:5
|
139 | host_exports: &'a HostExports<T, L, S, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0309]: the parameter type `T` may not live long enough
--> runtime/wasm/src/module/mod.rs:139:5
|
135 | pub(crate) struct WasmiModule<'a, T, L, S, U> {
| - help: consider adding an explicit lifetime bound `T: 'a`...
...
139 | host_exports: &'a HostExports<T, L, S, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...so that the reference type `&'a host_exports::HostExports<T, L, S, U>` does not outlive the data it points at
--> runtime/wasm/src/module/mod.rs:139:5
|
139 | host_exports: &'a HostExports<T, L, S, U>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0309`.
error: Could not compile `graph-runtime-wasm`.
warning: build failed, waiting for other jobs to finish...
error: build failed
Any thoughts on this error?
Many thanks
Tim
right now there is some janky logic for comparisons with 0
apparently this is fixed in the new ts version so we should update the comparison function
uniswap-subgraph/src/mappings/exchange.ts
Lines 152 to 155 in edcf0b2
uniswap-subgraph/src/mappings/exchange.ts
Lines 365 to 368 in edcf0b2
Both of these can cause the price to go to 0. Basically, a brand new exchange, or an exchange that has a very very small token price, can result in this number being 0. It will then change its value the next time any token or eth is purchased.
This needs to just work better. I have some ideas that hopefully I can get to next week
Time travel queries could provide subgraph efficiencies, and simplicity for the Uniswap subgraph.
The Blocklytics blog post had a really good summary of the approach: https://blocklytics.org/blog/ethereum-blocks-subgraph-made-for-time-travel/
https://blocklytics.org/blog/bancor-subgraph-24h-volume/
I am not immediately clear on how and where this could be an improvement. It is worth noting though and keeping an issue open. Likely it could decrease complexity of the subgraph (and make it easier to maintain) as well as lower the amount of entities we are storing (and decrease the 3 day sync time).
Hello!
I'm very glad to have an opportunity to use thegraph as a source of data for Uniswap. I succeeded in using HTTP queries following the guide and the playground at https://thegraph.com/explorer/subgraph/graphprotocol/uniswap
Example:
Request
{
"query" : "
{ exchanges(where: {tokenAddress: \"0x6b175474e89094c44da98b954eedeac495271d0f\"})
{ tokenAddress tokenSymbol startTime price priceUSD }
}
"
}
Response
{"data":{ "exchanges":
[{"price":"137.235425158258860500","priceUSD":"1.007148187411886213892813100555711444280861568563425025772874606616100759801755264482597497036750276","startTime":1573833929,"tokenAddress":"0x6b175474e89094c44da98b954eedeac495271d0f","tokenSymbol":"DAI"}]}}
Now I want my application to listen for live exchanges updates (price changes). There is a subscription
in GraphQL to do so but I couldn't handle using websocket api. For example an external playground (https://www.websocket.org/echo.html) is unable to connect to wss://api.thegraph.com/subgraphs/name/graphprotocol/uniswap. Is it currently enabled? Could you please provide any details on how it should be used so far (ideally extending the playground with subscriptions)? I do not really want to go deeper into GraphQL related client libraries for now, just want to try out simple 'native' ws tools as I've done with the http query.
So I'd like to be able perform something like
Request
{
"subscription" : "
{ exchanges(where: {tokenAddress: \"0x6b175474e89094c44da98b954eedeac495271d0f\"})
{ tokenAddress tokenSymbol startTime price priceUSD }
}
"
}
using websocket.
Thank you. Couldn't find any less formal channel for communications.
UPD:
Actually it seems that connection could be acquired through my application, but no messages are being transmitted and the WS client receives 'Connection closed' after 5 minutes.
I just connect to wss://api.thegraph.com/subgraphs/name/graphprotocol/uniswap then subscribe to it and send a message from the snippet above.
Good timing, apparently the issue that was blocking us from doing dynamic data sources is fixed graphprotocol/graph-node#892 .
I haven't looked into it deeply, but from what I interpret, we can now get null
returned instead of the graph node crashing. This should allow us to handle all contracts dynamically. This will also allow us to make token, decimals, and name all required in schema.graphql
(Noah did this in his PR but I just noticed we didn't add it in Ians PR)
@ianlapham take a look at this, let me know if you have any questions. If you can implement it that would be amazing! This week I am busy but I can get to it next week. If you need help reach out on discord.
First I implemented the graph node to update the data source and store them in the db that can be queried via the GraphQL endpoint (I used Infura's mainnet endpoint in my docker-compose file)
After cloning from the uniswap's subgraph repo, I installed all the dependencies and ran the following commands
npm run codegen
npm run build
npm run create-local
npm run deploy-local
I got messages like
Upload subgraph to IPFS
Build completed: QmagGaBm7FL9uQWg1bk52Eb3LTN4owkvxEKkirtyXNLQc9
Deployed to http://127.0.0.1:8000/subgraphs/name/mohaiminuleraj/uniswap-v3/graphql
Subgraph endpoints:
Queries (HTTP): http://127.0.0.1:8000/subgraphs/name/mohaiminuleraj/uniswap-v3
Subscriptions (WS): http://127.0.0.1:8001/subgraphs/name/mohaiminuleraj/uniswap-v3
But unfortunately, I can't seem to retrieve the blockchain data and store them in the Postgres DB (using graph-node)
When trying to query the exchange data on user uniToken balances, the query throws "entry is null" error. Here's a query to reproduce:
{
userExchangeDatas(where: {
userAddress: "0x46499275b5c4d67dfa46B92D89aADA3158ea392e",
uniTokenBalance_gt: 0
}) {
uniTokenBalance
exchangeAddress
exchange {
id
}
}
}
I think this is due to exchange
field not set during UserExchangeData entry creation.
Big Decimal is done, after compound is done, fix uniswap up
Sometimes the subgraph crashes due to unforeseen handler errors.
Then it takes three days to sync and test.
What we could do instead, is have a subgraph that only includes 4 hardcoded exchanges - the three stablecoin exchanges used for the oracle, and the exchange that failed.
This way, we can quickly test the handler as the syncing time will be reduced to minutes rather than 3 days.
I don't think this needs to be created until we run into this problem again , and we can't afford to wait three days. It should be very easy to get this up and running.
See this issue to follow progress of big decimal graphprotocol/graph-node#720
Features that will be added after bigDecimal is added
See the condensed schema below for Uniswap
and Exchange
# Uniswap global values across all exchanges
type Uniswap @entity {
id: ID!
exchanges: [Exchange!]!
.........
}
type Exchange @entity {
id: ID! # Uniswap Exchange address
...........
# Fields used to help derived relationship
factory: Uniswap! @derivedFrom(field: "exchanges")
}
This is a bad pattern because we are deriving factory from exchange, while factory -> exchange has a relationship of 1-n
. Right now we are deriving the factory from the exchanges, even though we know factory will always have id 1
and that there is only one factory. We should do the following:
# Uniswap global values across all exchanges
type Uniswap @entity {
id: ID!
exchanges: [Exchange!]! @derivedFrom(field: "factory")
......
}
type Exchange @entity {
id: ID! # Uniswap Exchange address
...........
factory: Uniswap!
}
And set each Exchanges
factory value to the string 1
. This will allow for simpler sql queries within graph-node
Hello,
I am currently trying to query for all swaps made under my account but am running into a situation where it does not seem possible for me to retrieve transactions with just an ETH address.
This is the TX which I am unable to retrieve:
https://etherscan.io/tx/0xd4a59c72cc2e32db55724907fd1171d9b7c4f907b8086ce030debeb9592b80a9
Inside the subgraph's playground, this swap was not included when filtering on a simple clause like this:
swaps(where: { to: $address })
I was only able to fetch this swap after looking through all transactions
included in that same block and got this response json:
"swaps": [
{
"amount0In": "2680.069038095470019237",
"amount0Out": "0",
"amount1In": "0",
"amount1Out": "5",
"pair": {
"token0": {
"symbol": "PIE"
},
"token1": {
"symbol": "WETH"
}
},
"timestamp": "1597256972",
"sender": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
"to": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d"
}
]
In this response, both the sender and to addresses are the Uniswap contract address and my own ETH address is not included inside the swap response at all.
I am pretty new to the graph protocol, but it appears to me either the sender or to address should match my address so it can be queried and filtered on.
If this is not an issue, how is it possible to query this swap from only having an ETH address?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.