The in-range liquidity accumulator should be used with care. Calculating TWAL is addressed in finer detail in the whitepaper. To derive the harmonic mean liquidity over an interval, the caller needs to retrieve two observations, one after the other, take the delta of the two values, then divide the time elapsed by this value. The liquidity accumulator value increases monotonically and grows by the value of seconds / in-range liquidity - per second. The liquidity accumulator stores the value of seconds / in-range liquidity at the time of the observation. See OracleLibrary for an example of how to use the tick accumulator. Note that using an arithmetic mean tick to derive a price corresponds to a geometric mean price. Calculating a TWAP from the tick accumulator is also covered in the whitepaper. To derive the arithmetic mean tick over an interval, the caller needs to retrieve two observations, one after the other, take the delta of the two values, and divide by the time elapsed between them. The tick accumulator value increases monotonically and grows by the value of the current tick - per second. The tick accumulator stores the cumulative sum of the active tick at the time of the observation. Note that because the oracle is only updated at most once every block, calling observe with a secondsAgo value of 0 will return the most recently written observation, which can only be as recent as the beginning of the current block (or older). This is one of the primary reasons to use observe over observations. Note: if the times don't correspond exactly to a block in which an observation was written, a counterfactual observation will be constructed, removing the need for the caller to interpolate manually. Note that each of the given times must be more recent (or as old as) the oldest stored observation. Returns ( int56 memory tickCumulatives, uint160 memory secondsPerLiquidit圜umulativeX128s ) Įach time observe is called, the caller must specify an array containing any number of seconds ago, denoting the times to return observations from. Observations įunction observe ( uint32 calldata secondsAgos ) Additionally, the v3 oracle's considerable maximum length makes oracle price manipulation significantly more difficult, as the calling contract may cheaply construct a time-weighted average over any arbitrary range inside of (or fully encompassing) the length of the oracle array. Storing price and liquidity history directly in the pool contract substantially reduces the potential for logical errors on the part of the calling contract, and reduces integration costs by eliminating the need to store historical values. However, any party willing to pay the transaction fees may increase the number of tracked observations (up to a maximum of 65535), expanding the period of data availability to ~9 days or more. This limits how far into the past users may access data. At first, each pool tracks only a single observation, overwriting it as blocks elapse. Historical data is stored as an array of observations. This capability unlocks a wide range of on-chain use cases. For Uniswap V1 information see the V1 Subgraph.Unfamiliar with the concept of an oracle? Check out the Ethereum Foundation's oracle overview first.Īll Uniswap v3 pools can serve as oracles, offering access to historical price and liquidity data. The Uniswap V2 Subgraph only tracks data on Uniswap V2. To learn more about querying a subgraph refer to The Graph's documentation. It is not intended to be used as a data source for structuring transactions (contracts should be referenced directly for the most reliable live data). The subgraph provides a snapshot of the current state of Uniswap and also tracks historical data. Uniswap V2 Subgraph - source code for deployed subgraph. Subgraph Explorer - sandbox for querying data and endpoints for developers. The subgraph runs on The Graph protocol's hosted service and can be openly queried. The subgraph updates any time a transaction is made on Uniswap. It organizes data about pairs, tokens, Uniswap as a whole, and more. The Uniswap subgraph indexes data from the Uniswap contracts over time. This section explains the Uniswap Subgraph and how to interact with it.
0 Comments
Leave a Reply. |