RedStoneAdapterLib
Title: RedStoneAdapterLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from RedStone (https://github.com/redstone-finance/redstone-oracles-monorepo)
Library wrapping RedStone Push price-feed adapters with per-feed staleness configuration, exposing the shared IPriceOracleReader read surface.
Three-layer pattern: this library holds the logic + namespaced storage; the stateless
RedStoneAdapter facet forwards to it. Reads use the RedStone PriceFeedsAdapter's
getValueForDataFeed (8 decimals) with the batch update time from getTimestampsFromLatestUpdate,
and validate zero value, future timestamp, and staleness on-chain. Targets the RedStone Push
model; the Core/pull (calldata-injection) model is a separate follow-up.
Constants
WAD_SCALE
RedStone Push values carry 8 decimals; scale to 18 (WAD) by 1e10.
uint256 private constant WAD_SCALE = 1e10;Functions
redStoneAdapterStorage
function redStoneAdapterStorage() internal pure returns (RedStoneAdapterStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | RedStoneAdapterStorage |
__RedStoneAdapter_init
Registers the IRedStoneAdapter ERC-165 interface.
Must be called between preInitializer / postInitializer.
function __RedStoneAdapter_init() internal;registerInterface
Writes true to the ERC-165 map slot for IRedStoneAdapter.
function registerInterface() internal;getFeed
function getFeed(bytes32 key) internal view returns (address adapter, bytes32 dataFeedId, uint48 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| adapter | address | |
| dataFeedId | bytes32 | |
| maxStaleness | uint48 |
getValueForDataFeed
Returns the validated raw RedStone value (8 decimals) and the batch update timestamp.
Validates: registration, non-zero value, future-timestamp, and staleness. Staleness uses the
adapter's seconds-based blockTimestamp from the latest batch update.
function getValueForDataFeed(bytes32 key) internal view returns (uint256 value, uint256 timestamp);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| value | uint256 | |
| timestamp | uint256 |
latestAnswer
Returns the latest RedStone value normalized to 18 decimals (WAD): value * 1e10.
A value large enough to overflow int256 after scaling is rejected rather than wrapped.
function latestAnswer(bytes32 key) internal view returns (int256 answerWad);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 |
registerFeed
function registerFeed(bytes32 key, address adapter, bytes32 dataFeedId, uint48 maxStaleness) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| adapter | address | |
| dataFeedId | bytes32 | |
| maxStaleness | uint48 |
unregisterFeed
function unregisterFeed(bytes32 key) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |