PriceHub
A gas-optimized, bit-packed multi-feed price registry. You can use the FeedCodec library (see PriceHub contract interface SDK) for single-slot storage compression and efficient data retrieval via hand-written assembly.
PriceHub contract interface SDK:
https://drive.google.com/file/d/1OOxqEoSRPP6zzFoScpMl4G9NH8OHbVj0/view?usp=sharing
PriceHub exposes two price query styles:
- Standard interface (Decoded view).
- Compact interface (Bare-metal view): an efficient access pattern where the compact path returns packed data via
staticcallto minimize cross-contract gas. You must integrate theFeedCodeclibrary in your own contract logic (see PriceHub contract interface SDK) to decode the rawbytes32words.
Functions
| Name | Description | View type |
|---|---|---|
| fetch | Returns a human-readable price snapshot for a given data source | Decoded view |
| fetchBatch | Returns an array of decoded snapshots for multiple data sources | Decoded view |
| fetchCompact | Returns the raw 256-bit packed word for a given data source | Bare-metal view |
| fetchCompactBatch | Returns an array of raw packed words for multiple data sources | Bare-metal view |
| decimals | Returns the decimal precision used for prices | |
| description | Returns a human-readable description of this hub | |
| version | Returns the version number of this hub implementation | |
| isAuthorizedCaller | Checks whether a given account is on the authorized-caller whitelist |
1. fetch
Returns a human-readable price snapshot for a given data source.
Note: Executes only if the calling contract has been pre-whitelisted by the protocol. You must supply the querying contract address to obtain read access.
function fetch(bytes4 feedId) external view returns (PriceSnapshot memory priceSnapshot)
Parameters
- feedId: 4-byte unique identifier.
Return values
- priceSnapshot: Decoded struct with price and timestamps. If the
feedIddoes not exist, returns a zero-initialized snapshot.
1.1 PriceSnapshot struct definition
Records a price snapshot at a specific point in time.
/**
* @notice Price snapshot at a specific point in time
* @dev Fields are physically packed to specific bit widths for storage efficiency:
* @param price Fixed-point aggregated price with 18 decimal places (80 bits)
* @param aggregatedTs Timestamp when off-chain aggregation occurred (48 bits)
* @param onchainTs Timestamp when the price was packed and stored on-chain (48 bits)
*/
struct PriceSnapshot {
uint80 price;
uint48 aggregatedTs;
uint48 onchainTs;
}2. fetchBatch
Returns decoded snapshots for multiple data sources.
Note: Executes only if the calling contract has been pre-whitelisted by the protocol. You must supply the querying contract address to obtain read access.
function fetchBatch(bytes4[] calldata feedIds) external view returns (PriceSnapshot[] memory priceSnapshots)
Parameters
- feedIds: Array of 4-byte unique identifiers.
Return values
- priceSnapshots: Array of decoded
PriceSnapshotstructs. For any non-existentfeedId, the corresponding slot contains a zero-initialized snapshot.
3. fetchCompact
Returns the raw 256-bit packed word for a given data source.
For gas-sensitive applications, prefer this method to obtain the compact word and decode it inside your business contract using FeedCodec. This minimizes gas overhead associated with staticcall return data.
Note: Executes only if the calling contract has been pre-whitelisted by the protocol. You must supply the querying contract address to obtain read access.
function fetchCompact(bytes4 feedId) external view returns (bytes32 packed)
Parameters
- feedId: 4-byte unique identifier.
Return values
- packed: Raw storage word with physical layout:
[reserved (80b)][on-chain timestamp (48b)][aggregation timestamp (48b)][price (80b)]. If the ID does not exist, returnsbytes32(0).
4. fetchCompactBatch
Returns an array of raw packed words for multiple data sources.
For gas-sensitive applications, prefer this method to obtain compact words and decode them in your business contract with FeedCodec. This minimizes gas overhead associated with staticcall return data.
Note: Executes only if the calling contract has been pre-whitelisted by the protocol. You must supply the querying contract address to obtain read access.
function fetchCompactBatch(bytes4[] calldata feedIds) external view returns (bytes32[] memory packedList)
Parameters
- feedIds: Array of 4-byte unique identifiers.
Return values
- packedList: Array of raw 256-bit packed words. For any non-existent
feedId, the corresponding slot containsbytes32(0).
5. decimals
Returns the price precision shared by all feeds in this hub.
function decimals() external view returns (uint8 decimals)
Parameters
(none)
Return values
- decimals: Constant precision for price sources (typically 18).
6. description
Returns a human-readable description of this hub.
function description() external view returns (string memory description)
Parameters
(none)
Return values
- description: Human-readable description of this hub.
7. version
Returns the version number of this hub implementation.
function version() external view returns (uint256 version)
Parameters
(none)
Return values
- version: Version number.
8. isAuthorizedCaller
Checks whether a given account is on the authorized-caller whitelist.
function isAuthorizedCaller(address account) external view returns (bool isAuthorizedCaller)
Parameters
- account: Address of the contract to query.
Return values
- isAuthorizedCaller:
trueif that contract address is on the whitelist.