For the complete documentation index, see llms.txt. This page is also available as Markdown.

PriceOracle

Git Source

Inherits: ElaraBase, IPriceOracle

Title: Price Oracle Contract

Extensible price oracle with support for multiple oracle types

  • Currently supports Chainlink with ability to add more oracle types

  • Invariants:

  • Only authorized accounts can configure token pricing

  • Prices are always returned with 18 decimals precision

  • Oracle prices must be positive and not stale

  • Upgradeability:

  • Uses {ElaraBase} for UUPS upgradeability pattern

  • Initializer must be called exactly once; preserve storage layout

  • Access Control:

  • Configuration functions restricted via ElaraBase-restricted modifier

Note: security-contact: [email protected]

State Variables

DECIMALS

Number of decimals used for price values

All prices returned by this oracle are normalized to 18 decimals

defaultHeartbeat

Default maximum acceptable age of price data in seconds

Used when a token config omits a heartbeat; typically 3600 seconds (1 hour)

oracleTypes

Oracle type for each token

Maps token address to oracle type (NONE if not configured)

chainlinkConfigs

Chainlink configurations

Only populated for tokens with OracleType.CHAINLINK

Functions

initialize

Initialize the price oracle with default configuration

Security:

  • Only callable during initialization via {initializer} modifier

  • Sets up the base contract via ElaraBase-__ElaraBase_init

  • Sets defaultHeartbeat to 3600 seconds (1 hour)

  • Critical for establishing access control; must be called exactly once per proxy

Parameters

Name
Type
Description

_accessManager

address

Address of the access manager contract

setDefaultHeartbeat

deactivateToken

getPrice

decimals

getOracleType

_getChainlinkPrice

Fetches price from Chainlink feed and validates it

Reverts if price is non-positive or stale. Any revert from the external feed call (including malformed data or feed downtime) is caught and re-thrown as {InvalidPrice}.

Parameters

Name
Type
Description

token

address

Token address to get price for

Returns

Name
Type
Description

<none>

uint256

Normalized price with 18 decimals precision

_normalizeDecimals

Normalize decimals from one precision to another

Parameters

Name
Type
Description

value

uint256

Value to normalize

fromDecimals

uint8

Current decimal precision

toDecimals

uint8

Target decimal precision

Returns

Name
Type
Description

<none>

uint256

Normalized value

Structs

ChainlinkConfig

Chainlink-specific oracle configuration per token

Last updated

Was this helpful?