Skip to main content

PRICEv1

Price oracle data storage

The Olympus Price Oracle contract provides a standard interface for OHM price data against a reserve asset. It also implements a moving average price calculation (same as a TWAP) on the price feed data over a configured duration and observation frequency. The data provided by this contract is used by the Olympus Range Operator to perform market operations. The Olympus Price Oracle is updated each epoch by the Olympus Heart contract.

Methods

INIT

function INIT() external nonpayable

Initialization function for the module

This function is called when the module is installed or upgraded by the kernel.MUST BE GATED BY onlyKernel. Used to encompass any initialization or upgrade logic.

KEYCODE

function KEYCODE() external pure returns (Keycode)

5 byte identifier for a module.

Returns

NameTypeDescription
_0Keycodeundefined

VERSION

function VERSION() external pure returns (uint8 major, uint8 minor)

Returns which semantic version of a module is being implemented.

Returns

NameTypeDescription
majoruint8- Major version upgrade indicates breaking change to the interface.
minoruint8- Minor version change retains backward-compatible interface.

changeKernel

function changeKernel(contract Kernel newKernel_) external nonpayable

Function used by kernel when migrating to a new kernel.

Parameters

NameTypeDescription
newKernel_contract Kernelundefined

changeMovingAverageDuration

function changeMovingAverageDuration(uint48 movingAverageDuration_) external nonpayable

Change the moving average window (duration)

Changing the moving average duration will erase the current observations array and require the initialize function to be called again. Ensure that you have saved the existing data and can re-populate before calling this function.

Parameters

NameTypeDescription
movingAverageDuration_uint48- Moving average duration in seconds, must be a multiple of observation frequency

changeObservationFrequency

function changeObservationFrequency(uint48 observationFrequency_) external nonpayable

Change the observation frequency of the moving average (i.e. how often a new observation is taken)

Changing the observation frequency clears existing observation data since it will not be taken at the right time intervals. Ensure that you have saved the existing data and/or can re-populate before calling this function.

Parameters

NameTypeDescription
observationFrequency_uint48- Observation frequency in seconds, must be a divisor of the moving average duration

changeUpdateThresholds

function changeUpdateThresholds(uint48 ohmEthUpdateThreshold_, uint48 reserveEthUpdateThreshold_) external nonpayable

Change the update thresholds for the price feeds

The update thresholds should be set based on the update threshold of the chainlink oracles.

Parameters

NameTypeDescription
ohmEthUpdateThreshold_uint48- Maximum allowed time between OHM/ETH price feed updates
reserveEthUpdateThreshold_uint48- Maximum allowed time between Reserve/ETH price feed updates

cumulativeObs

function cumulativeObs() external view returns (uint256)

Running sum of observations to calculate the moving average price from

See getMovingAverage()

Returns

NameTypeDescription
_0uint256undefined

decimals

function decimals() external view returns (uint8)

Number of decimals in the price values provided by the contract.

Returns

NameTypeDescription
_0uint8undefined

getCurrentPrice

function getCurrentPrice() external view returns (uint256)

Get the current price of OHM in the Reserve asset from the price feeds

Returns

NameTypeDescription
_0uint256undefined

getLastPrice

function getLastPrice() external view returns (uint256)

Get the last stored price observation of OHM in the Reserve asset

Returns

NameTypeDescription
_0uint256undefined

getMovingAverage

function getMovingAverage() external view returns (uint256)

Get the moving average of OHM in the Reserve asset over the defined window (see movingAverageDuration and observationFrequency).

Returns

NameTypeDescription
_0uint256undefined

initialize

function initialize(uint256[] startObservations_, uint48 lastObservationTime_) external nonpayable

Initialize the price moduleAccess restricted to activated policies

This function must be called after the Price module is deployed to activate it and after updating the observationFrequency or movingAverageDuration (in certain cases) in order for the Price module to function properly.

Parameters

NameTypeDescription
startObservations_uint256[]- Array of observations to initialize the moving average with. Must be of length numObservations.
lastObservationTime_uint48- Unix timestamp of last observation being provided (in seconds).

initialized

function initialized() external view returns (bool)

Whether the price module is initialized (and therefore active).

Returns

NameTypeDescription
_0boolundefined

kernel

function kernel() external view returns (contract Kernel)

Returns

NameTypeDescription
_0contract Kernelundefined

lastObservationTime

function lastObservationTime() external view returns (uint48)

Unix timestamp of last observation (in seconds).

Returns

NameTypeDescription
_0uint48undefined

movingAverageDuration

function movingAverageDuration() external view returns (uint48)

Duration (in seconds) over which the moving average is calculated.

Returns

NameTypeDescription
_0uint48undefined

nextObsIndex

function nextObsIndex() external view returns (uint32)

Index of the next observation to make. The current value at this index is the oldest observation.

Returns

NameTypeDescription
_0uint32undefined

numObservations

function numObservations() external view returns (uint32)

Number of observations used in the moving average calculation. Computed from movingAverageDuration / observationFrequency.

Returns

NameTypeDescription
_0uint32undefined

observationFrequency

function observationFrequency() external view returns (uint48)

Frequency (in seconds) that observations should be stored.

Returns

NameTypeDescription
_0uint48undefined

observations

function observations(uint256) external view returns (uint256)

Array of price observations. Check nextObsIndex to determine latest data point.

Observations are stored in a ring buffer where the moving average is the sum of all observations divided by the number of observations. Observations can be cleared by changing the movingAverageDuration or observationFrequency and must be re-initialized.

Parameters

NameTypeDescription
_0uint256undefined

Returns

NameTypeDescription
_0uint256undefined

ohmEthPriceFeed

function ohmEthPriceFeed() external view returns (contract AggregatorV2V3Interface)

OHM/ETH price feed

Returns

NameTypeDescription
_0contract AggregatorV2V3Interfaceundefined

ohmEthUpdateThreshold

function ohmEthUpdateThreshold() external view returns (uint48)

Maximum expected time between OHM/ETH price feed updates

Returns

NameTypeDescription
_0uint48undefined

reserveEthPriceFeed

function reserveEthPriceFeed() external view returns (contract AggregatorV2V3Interface)

Reserve/ETH price feed

Returns

NameTypeDescription
_0contract AggregatorV2V3Interfaceundefined

reserveEthUpdateThreshold

function reserveEthUpdateThreshold() external view returns (uint48)

Maximum expected time between OHM/ETH price feed updates

Returns

NameTypeDescription
_0uint48undefined

updateMovingAverage

function updateMovingAverage() external nonpayable

Trigger an update of the moving average. Permissioned.

This function does not have a time-gating on the observationFrequency on this contract. It is set on the Heart policy contract. The Heart beat frequency should be set to the same value as the observationFrequency.

Events

MovingAverageDurationChanged

event MovingAverageDurationChanged(uint48 movingAverageDuration_)

Parameters

NameTypeDescription
movingAverageDuration_uint48undefined

NewObservation

event NewObservation(uint256 timestamp_, uint256 price_, uint256 movingAverage_)

Parameters

NameTypeDescription
timestamp_uint256undefined
price_uint256undefined
movingAverage_uint256undefined

ObservationFrequencyChanged

event ObservationFrequencyChanged(uint48 observationFrequency_)

Parameters

NameTypeDescription
observationFrequency_uint48undefined

UpdateThresholdsChanged

event UpdateThresholdsChanged(uint48 ohmEthUpdateThreshold_, uint48 reserveEthUpdateThreshold_)

Parameters

NameTypeDescription
ohmEthUpdateThreshold_uint48undefined
reserveEthUpdateThreshold_uint48undefined

Errors

KernelAdapter_OnlyKernel

error KernelAdapter_OnlyKernel(address caller_)

Parameters

NameTypeDescription
caller_addressundefined

Module_PolicyNotPermitted

error Module_PolicyNotPermitted(address policy_)

Parameters

NameTypeDescription
policy_addressundefined

Price_AlreadyInitialized

error Price_AlreadyInitialized()

Price_BadFeed

error Price_BadFeed(address priceFeed)

Parameters

NameTypeDescription
priceFeedaddressundefined

Price_InvalidParams

error Price_InvalidParams()

Price_NotInitialized

error Price_NotInitialized()