Oracle Aggregation Strategies
Implementations
Arithmetic mean
An averaging strategy that calculates the arithmetic mean (simple average).
- Contract:
ArithmeticAveraging
Geometric mean
An averaging strategy that calculates the geometric mean .
Note that input values of zero are treated as one as the natural log of zero is undefined.
- Contract:
GeometricAveraging
Harmonic mean
An averaging strategy that calculates the harmonic mean .
Note that since Solidity does not support floating point numbers, weights are shifted to the left by a fixed number of bits before the calculation is performed. This shift is to prevent the result from being rounded down to zero when the weights are smaller than the input values.
Consider how large the input values are and how small the weights are when choosing the number of bits to shift by. For example, if the smallest weight can be 1 and the largest input value can be 2^32 (32 bit input), then using a weight-shift of 80 bits will ensure 48 (80-32) bits of precision in the result.
- Contract:
HarmonicAveragingWS80
- This contract shifts the weights to the left by 80 bits.
- Contract:
HarmonicAveragingWS140
- This contract shifts the weights to the left by 140 bits.
- Contract:
HarmonicAveragingWS192
- This contract shifts the weights to the left by 192 bits.