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.
The types of pools that have oracles include but are not limited to:
enum Variable { PAIR_PRICE, BPT_PRICE, INVARIANT }
struct OracleAverageQuery {
Variable variable;
uint256 secs;
uint256 ago;
}
getTimeWeightedAverage(OracleAverageQuery[] queries)
returns (uint256[] results)
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 secondsago
- The time in seconds from since end of that duration.
Prices are represented as 18 decimal fixed point values.
enum Variable { PAIR_PRICE, BPT_PRICE, INVARIANT }
getLatest(Variable variable) returns (uint256)
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 }
.
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.