TellorAdapterLib
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
| Name | Type | Description |
|---|---|---|
| $ | 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
| Name | Type | Description |
|---|---|---|
| tellor_ | address |
registerInterface
Writes true to the ERC-165 map slot for ITellorAdapter.
function registerInterface() internal;tellor
function tellor() internal view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
getFeed
function getFeed(bytes32 key) internal view returns (bytes32 queryId, uint48 disputeBuffer, uint48 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| queryId | bytes32 | |
| disputeBuffer | uint48 | |
| maxStaleness | uint48 |
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
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| value | bytes | |
| timestamp | uint256 |
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
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 |
setTellor
function setTellor(address tellor_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| tellor_ | address |
registerFeed
function registerFeed(bytes32 key, bytes32 queryId, uint48 disputeBuffer, uint48 maxStaleness) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| queryId | bytes32 | |
| disputeBuffer | uint48 | |
| maxStaleness | uint48 |
unregisterFeed
function unregisterFeed(bytes32 key) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
_requireTellor
function _requireTellor() private view returns (address t);Returns
| Name | Type | Description |
|---|---|---|
| t | address |