Multi-Feed Contract
A gas-optimized, bit-packed multi-asset price registry. One contract returns the latest prices for many feeds, each identified by a 4-byte feedId, optimized for consistency and gas efficiency.
Multi-Feed contract interface:
IMultiFeed.sol
Codec library:
FeedCodec.sol
Multi-Feed exposes two price query styles:
- Decoded view. Returns a friendly
PriceSnapshotstruct viafetch/fetchBatch. - Compact view. Returns a packed
bytes32word viastaticcallfromfetchCompact/fetchCompactBatchto minimize cross-contract gas overhead. We recommend using theFeedCodeclibrary in your consumer contract to decode the packed data; see the packed word bit layout under fetchCompact.
Read-access policy
Each feed instance runs in one of two modes — whitelist (only addresses on the authorized-caller list, plus regular EOAs that have not been delegated via ERC-7702, may read) or open-read (any caller may read). Functions marked onlyReadAccess below are subject to this policy; all other functions are always callable. Use isOpenRead and isAuthorizedCaller to query the current state.
Functions
| Name | Description | View type | Modifier |
|---|---|---|---|
| fetch | Decoded snapshot for a single feed. | Decoded view | onlyReadAccess |
| fetchBatch | Decoded snapshots for multiple feeds. | Decoded view | onlyReadAccess |
| fetchCompact | Raw packed word for a single feed. | Compact view | onlyReadAccess |
| fetchCompactBatch | Raw packed words for multiple feeds. | Compact view | onlyReadAccess |
| decimals | Decimal precision shared by all feeds. | — | — |
| description | Human-readable description of this registry. | — | — |
| version | Version number of the implementation. | — | — |
| contractType | Contract type identifier (2 for Multi-Feed). | — | — |
| isAuthorizedCaller | Checks whether an address is whitelisted. | — | — |
| isOpenRead | Returns whether open-read mode is active. | — | — |
1. fetch
Returns a decoded snapshot for a single feed.
function fetch(bytes4 feedId) external view returns (PriceSnapshot memory priceSnapshot)Parameters
- feedId: 4-byte feed identifier.
Return values
- priceSnapshot: Decoded struct with price and timestamps. A zero-initialized snapshot is returned if the feed has never been updated.
1.1 PriceSnapshot struct definition
Records a price snapshot at a specific point in time. Fields are bit-packed for storage efficiency:
struct PriceSnapshot {
uint80 price; // aggregated price
uint48 aggregatedTs; // off-chain aggregation timestamp
uint48 onchainTs; // on-chain update timestamp
}2. fetchBatch
Returns decoded snapshots for multiple feeds in one call.
function fetchBatch(bytes4[] calldata feedIds) external view returns (PriceSnapshot[] memory priceSnapshots)Parameters
- feedIds: Array of 4-byte feed identifiers.
Return values
- priceSnapshots: Array of decoded
PriceSnapshotstructs, index-aligned withfeedIds. Feeds that have never been updated yield zero-initialized snapshots.
3. fetchCompact
Returns the raw 256-bit packed word for a single feed. This is the cheapest read path; we recommend using the FeedCodec library in your consumer contract to decode it.
function fetchCompact(bytes4 feedId) external view returns (bytes32 packed)Parameters
- feedId: 4-byte feed identifier.
Return values
- packed: Raw 256-bit packed word, or
bytes32(0)if the feed has never been updated.
3.1 Packed word bit layout
The 256-bit word returned by fetchCompact / fetchCompactBatch:
| Bit range | Segment | Type | Meaning |
|---|---|---|---|
[255:176] | Reserved | — | Zero-filled |
[175:128] | OnchainTs | uint48 | On-chain update timestamp |
[127:80] | AggTs | uint48 | Off-chain aggregation timestamp |
[79:0] | Price | uint80 | Aggregated price |
4. fetchCompactBatch
Returns raw packed words for multiple feeds in one call. Same recommendation as fetchCompact: decode locally using FeedCodec for maximum gas efficiency.
function fetchCompactBatch(bytes4[] calldata feedIds) external view returns (bytes32[] memory packedList)Parameters
- feedIds: Array of 4-byte feed identifiers.
Return values
- packedList: Array of raw 256-bit packed words, index-aligned with
feedIds. Feeds that have never been updated yieldbytes32(0).
5. decimals
Returns the decimal precision shared by all feeds in this registry.
function decimals() external view returns (uint8 precision)Parameters
(none)
Return values
- precision: Decimal precision shared by all feeds.
6. description
Returns a human-readable description of this registry.
function description() external view returns (string memory desc)Parameters
(none)
Return values
- desc: A string identifier.
7. version
Returns the version number of the current implementation.
function version() external view returns (uint256 versionNumber)Parameters
(none)
Return values
- versionNumber: A monotonically increasing version identifier.
8. contractType
Returns the contract type identifier, used to distinguish feed implementations within the project.
function contractType() external view returns (uint256 typeId)Parameters
(none)
Return values
- typeId: Type id (
2for Multi-Feed).
9. isAuthorizedCaller
Checks whether an address is whitelisted as an authorized caller for price reads when open-read mode is disabled.
function isAuthorizedCaller(address account) external view returns (bool whitelisted)Parameters
- account: Address to query.
Return values
- whitelisted:
trueif the account is on the authorized-caller whitelist.
10. isOpenRead
Returns whether open-read mode is currently active. When true, any caller can read prices; when false, only whitelisted callers and regular EOAs (that have not been delegated via ERC-7702) are permitted.
function isOpenRead() external view returns (bool enabled)Parameters
(none)
Return values
- enabled:
trueif open-read mode is active.