Developers
Search…
Oracle Pools

Overview

Oracle Pools are Balancer pools that can report back time-weighted average prices for tokens within the pool.
Different poolTypes can implement Oracle Functionality. Since WeightedPool2Tokens were the first pool to implement the oracles, they were originally referred to as "Oracle Pools," but they are no longer alone in providing this functionality.

Pool Types with Oracles

The types of pools that have oracles include but are not limited to:

Getting Oracle Data

getTimeWeightedAverage

1
enum Variable { PAIR_PRICE, BPT_PRICE, INVARIANT }
2
struct OracleAverageQuery {
3
Variable variable;
4
uint256 secs;
5
uint256 ago;
6
}
7
getTimeWeightedAverage(OracleAverageQuery[] queries)
8
returns (uint256[] results)
Copied!
Returns time weighted average prices corresponding to the variables in each query.
  • variable - One of { PAIR_PRICE, BPT_PRICE, INVARIANT }
  • secs - The duration of the query in seconds
  • ago - The time in seconds from since end of that duration.
Prices are represented as 18 decimal fixed point values.

getLatest

1
enum Variable { PAIR_PRICE, BPT_PRICE, INVARIANT }
2
getLatest(Variable variable) returns (uint256)
Copied!
For a simpler query (which is more prone to error/manipulation), you can also query getLatest to get the latest value of variable, which is one of { PAIR_PRICE, BPT_PRICE, INVARIANT }.

Additional Queries

The above are just samples of what you can query. For a more complete list, please refer to the Full APIs for the WeightedPool2Tokens and MetaStablePool.