Skip to content
Lattice

TellorAdapterLib

Git Source

Title: TellorAdapterLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Tellor (https://github.com/tellor-io)

Library wrapping the dispute-based Tellor oracle with per-feed dispute-buffer + staleness configuration and WAD normalization, exposing the shared IPriceOracleReader read surface.

Three-layer pattern: this library holds the logic + namespaced storage; the stateless TellorAdapter facet forwards to it. Reads use Tellor's getDataBefore at a dispute buffer offset (so disputed values are removed first) and validate presence, future timestamp, and staleness on-chain. SpotPrice values are abi.encode(uint256) at 18 decimals (WAD).

Functions

tellorAdapterStorage

function tellorAdapterStorage() internal pure returns (TellorAdapterStorage storage $);

Returns

NameTypeDescription
$TellorAdapterStorage

__TellorAdapter_init

Initializes TellorAdapter with the Tellor contract and registers the ERC-165 interface.

Must be called between preInitializer / postInitializer.

function __TellorAdapter_init(address tellor_) internal;

Parameters

NameTypeDescription
tellor_address

registerInterface

Writes true to the ERC-165 map slot for ITellorAdapter.

function registerInterface() internal;

tellor

function tellor() internal view returns (address);

Returns

NameTypeDescription
<none>address

getFeed

function getFeed(bytes32 key) internal view returns (bytes32 queryId, uint48 disputeBuffer, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
queryIdbytes32
disputeBufferuint48
maxStalenessuint48

getDataBefore

Returns the validated raw Tellor value bytes and report timestamp, read with the feed's dispute buffer.

Validates: registration, presence (found + non-empty), future timestamp, and staleness. Reads getDataBefore at block.timestamp - disputeBuffer so disputed values have time to be removed first.

function getDataBefore(bytes32 key) internal view returns (bytes memory value, uint256 timestamp);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
valuebytes
timestampuint256

latestAnswer

Returns the latest Tellor value normalized to 18 decimals (WAD).

SpotPrice values are already 1e18-scaled abi.encode(uint256), so this only widens uint256 -> int256. getDataBefore already validated presence + staleness; a zero price or one >= 2^255 (which would wrap to a negative int256) is treated as missing data. value comes from a permissionless reporter, so the upper-bound guard is load-bearing, not defensive.

function latestAnswer(bytes32 key) internal view returns (int256 answerWad);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
answerWadint256

setTellor

function setTellor(address tellor_) internal;

Parameters

NameTypeDescription
tellor_address

registerFeed

function registerFeed(bytes32 key, bytes32 queryId, uint48 disputeBuffer, uint48 maxStaleness) internal;

Parameters

NameTypeDescription
keybytes32
queryIdbytes32
disputeBufferuint48
maxStalenessuint48

unregisterFeed

function unregisterFeed(bytes32 key) internal;

Parameters

NameTypeDescription
keybytes32

_requireTellor

function _requireTellor() private view returns (address t);

Returns

NameTypeDescription
taddress