Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ifalabs.com/llms.txt

Use this file to discover all available pages before exploring further.

The IFÁ Labs oracle contract exposes a focused set of read-only functions for querying price data. All functions are view — they cost no gas when called externally and have no side effects. This page is the complete reference for every function, struct, and enum in the contract interface.

Data Types

Before the function reference, the types returned by the contract:

PriceFeed Struct

The primary return type for all single-asset price queries.
struct PriceFeed {
    int256  price;           // Scaled price value
    int8    decimal;         // Negative exponent — divide by 10^(-decimal) for human-readable price
    uint256 lastUpdateTime;  // Unix timestamp of the last on-chain update
}
FieldTypeDescription
priceint256Raw scaled price. For decimal = -18, divide by 1e18 for the human-readable value. Always positive for current feeds.
decimalint8Negative scaling exponent. All current feeds return -18. Read dynamically — do not hardcode.
lastUpdateTimeuint256Unix timestamp of the last submitted price update. Use this for staleness checks.

DerivedPair Struct

The return type for cross-asset pair calculations.
struct DerivedPair {
    int256  price;           // Derived cross-asset price, scaled
    int8    decimal;         // Negative exponent for scaling
    uint256 lastUpdateTime;  // Timestamp of the most recent underlying feed update
}
The lastUpdateTime for a derived pair reflects the older of the two underlying feed timestamps — the derived price is only as fresh as its least-recently-updated component.

PairDirection Enum

Controls the direction of a derived pair calculation.
enum PairDirection {
    Forward,   // asset0 priced in asset1 terms: "how much asset1 is one asset0 worth?"
    Backward   // asset1 priced in asset0 terms: "how much asset0 is one asset1 worth?"
}
ValueMeaningExample
Forwardasset0 / asset1getPairbyId(CNGN, USDT, Forward) → CNGN/USDT rate
Backwardasset1 / asset0getPairbyId(CNGN, USDT, Backward) → USDT/CNGN rate

Functions

getAssetInfo

Fetches the current price feed for a single asset.
function getAssetInfo(bytes32 _assetIndex)
    external
    view
    returns (PriceFeed memory assetInfo, bool exist);
Parameters:
ParameterTypeDescription
_assetIndexbytes32The asset ID — keccak256(abi.encodePacked("SYMBOL/USD"))
Returns:
Return ValueTypeDescription
assetInfoPriceFeedPrice, decimal, and last update timestamp
existbooltrue if the asset is supported and has data. false if the asset ID is not recognised.
Behaviour:
  • Returns exist = false for unrecognised asset IDs. Does not revert.
  • assetInfo fields are zero-valued when exist = false. Always check exist before using assetInfo.
  • Safe to call with any bytes32 value — will never revert on invalid input.
Example:
bytes32 USDT_ID = 0x6ca0cef6107263f3b09a51448617b659278cff744f0e702c24a2f88c91e65a0d;

(IIfaPriceFeed.PriceFeed memory info, bool exists) = ORACLE.getAssetInfo(USDT_ID);

require(exists, "Asset not supported");
require(block.timestamp - info.lastUpdateTime <= 3600, "Price stale");

uint256 price = uint256(info.price) / 1e18;

getAssetsInfo

Batch version of getAssetInfo. Fetches price feeds for multiple assets in a single call.
function getAssetsInfo(bytes32[] calldata _assetIndexes)
    external
    view
    returns (PriceFeed[] memory infos, bool[] memory exists);
Parameters:
ParameterTypeDescription
_assetIndexesbytes32[]Array of asset IDs to query
Returns:
Return ValueTypeDescription
infosPriceFeed[]Array of price feeds — same order as input
existsbool[]Array of existence flags — same order as input
Behaviour:
  • Results are returned in the same order as the input array.
  • Each element in exists corresponds to the same-index element in infos.
  • Does not revert if an asset ID is unrecognised — returns exists[i] = false for that element.
  • Always check exists[i] before using infos[i].
Example:
bytes32[] memory ids = new bytes32[](3);
ids[0] = USDT_ASSET_ID;
ids[1] = USDC_ASSET_ID;
ids[2] = CNGN_ASSET_ID;

(IIfaPriceFeed.PriceFeed[] memory infos, bool[] memory exists) =
    ORACLE.getAssetsInfo(ids);

for (uint256 i = 0; i < ids.length; i++) {
    require(exists[i], "Unsupported asset in batch");
    // Use infos[i].price, infos[i].decimal, infos[i].lastUpdateTime
}
Use getAssetsInfo any time your contract needs more than one price in the same transaction. One external call is significantly cheaper than N consecutive getAssetInfo calls.

getPairbyId

Computes a derived cross-asset price for a single pair.
function getPairbyId(
    bytes32      _assetIndex0,
    bytes32      _assetIndex1,
    PairDirection _direction
)
    external
    view
    returns (DerivedPair memory);
Parameters:
ParameterTypeDescription
_assetIndex0bytes32Asset ID of the first asset
_assetIndex1bytes32Asset ID of the second asset
_directionPairDirectionForward for asset0/asset1, Backward for asset1/asset0
Returns:
Return ValueTypeDescription
DerivedPairDerivedPairDerived price, decimal, and the older of the two underlying timestamps
Behaviour:
  • Both underlying USD feeds must exist and be non-zero. If either is missing, the function reverts.
  • Self-pairing (same asset ID for both parameters) is blocked — reverts with an error.
  • lastUpdateTime reflects the older of the two underlying feed timestamps.
Example:
// How much USDT is one CNGN worth?
IIfaPriceFeed.DerivedPair memory pair = ORACLE.getPairbyId(
    CNGN_ASSET_ID,
    USDT_ASSET_ID,
    IIfaPriceFeed.PairDirection.Forward
);

uint256 cngnInUsdt = uint256(pair.price) / 1e18;

getPairsbyIdForward

Batch derived pair calculation — all pairs in the forward direction.
function getPairsbyIdForward(
    bytes32[] calldata _assetIndexes0,
    bytes32[] calldata _assetsIndexes1
)
    external
    view
    returns (DerivedPair[] memory);
Parameters:
ParameterTypeDescription
_assetIndexes0bytes32[]Array of first assets (numerator)
_assetsIndexes1bytes32[]Array of second assets (denominator)
Returns: Array of DerivedPair structs — same order as inputs. Behaviour:
  • Input arrays must be the same length. Mismatched lengths revert with InvalidAssetIndexLength.
  • Each pair is computed independently. A failure in one pair reverts the entire call.
Example:
bytes32[] memory assets0 = new bytes32[](2);
bytes32[] memory assets1 = new bytes32[](2);

assets0[0] = CNGN_ASSET_ID; assets1[0] = USDT_ASSET_ID;
assets0[1] = ZARP_ASSET_ID; assets1[1] = USDC_ASSET_ID;

IIfaPriceFeed.DerivedPair[] memory pairs =
    ORACLE.getPairsbyIdForward(assets0, assets1);

// pairs[0] = CNGN/USDT
// pairs[1] = ZARP/USDC

getPairsbyIdBackward

Batch derived pair calculation — all pairs in the backward direction.
function getPairsbyIdBackward(
    bytes32[] calldata _assetIndexes0,
    bytes32[] calldata _assetsIndexes1
)
    external
    view
    returns (DerivedPair[] memory);
Parameters:
ParameterTypeDescription
_assetIndexes0bytes32[]Array of first assets
_assetsIndexes1bytes32[]Array of second assets
Returns: Array of DerivedPair structs in backward direction — asset1 priced in asset0 terms. Behaviour: Identical to getPairsbyIdForward except direction is reversed for all pairs. Same length requirement and revert behaviour apply. Example:
// How much CNGN is one USDT worth?
bytes32[] memory assets0 = new bytes32[](1);
bytes32[] memory assets1 = new bytes32[](1);

assets0[0] = CNGN_ASSET_ID;
assets1[0] = USDT_ASSET_ID;

IIfaPriceFeed.DerivedPair[] memory pairs =
    ORACLE.getPairsbyIdBackward(assets0, assets1);

// pairs[0] = USDT/CNGN (how many CNGN per USDT)

getPairsbyId

Batch derived pair calculation with per-pair direction control.
function getPairsbyId(
    bytes32[]      calldata _assetIndexes0,
    bytes32[]      calldata _assetsIndexes1,
    PairDirection[] calldata _directions
)
    external
    view
    returns (DerivedPair[] memory);
Parameters:
ParameterTypeDescription
_assetIndexes0bytes32[]Array of first assets
_assetsIndexes1bytes32[]Array of second assets
_directionsPairDirection[]Per-pair direction — must be the same length as asset arrays
Returns: Array of DerivedPair structs — each computed with its specified direction. Behaviour:
  • All three input arrays must be the same length. Mismatched lengths revert with InvalidAssetOrDirectionLength.
  • Use this function when you need a mix of forward and backward pairs in a single call.
Example:
bytes32[]       memory assets0    = new bytes32[](2);
bytes32[]       memory assets1    = new bytes32[](2);
PairDirection[] memory directions = new PairDirection[](2);

assets0[0]    = CNGN_ASSET_ID;
assets1[0]    = USDT_ASSET_ID;
directions[0] = IIfaPriceFeed.PairDirection.Forward;   // CNGN/USDT

assets0[1]    = USDT_ASSET_ID;
assets1[1]    = ZARP_ASSET_ID;
directions[1] = IIfaPriceFeed.PairDirection.Backward;  // ZARP/USDT

IIfaPriceFeed.DerivedPair[] memory pairs =
    ORACLE.getPairsbyId(assets0, assets1, directions);

Custom Errors

The contract uses custom errors for gas-efficient reverts. These are the errors you may encounter when calling derived pair functions:
ErrorSignatureWhen It Occurs
InvalidAssetIndexLengthInvalidAssetIndexLength(uint256 len0, uint256 len1)Batch function receives arrays of different lengths
InvalidAssetOrDirectionLengthInvalidAssetOrDirectionLength(uint256 len0, uint256 len1, uint256 lenDir)getPairsbyId receives mismatched array lengths
Note: getAssetInfo and getAssetsInfo do not revert on unsupported assets — they return exist = false. Only derived pair functions can revert due to missing or invalid underlying feeds.

Quick Reference

FunctionAssetsDirection ControlReverts on Bad Input
getAssetInfoSingleN/ANo — returns exist = false
getAssetsInfoBatchN/ANo — returns exists[i] = false
getPairbyIdSingle pairPer callYes — missing feed or self-pair
getPairsbyIdForwardBatchAll forwardYes — array length mismatch
getPairsbyIdBackwardBatchAll backwardYes — array length mismatch
getPairsbyIdBatchPer pairYes — array length mismatch

Installing the Interface

The full interface with all types, functions, and natspec documentation is available via npm:
npm install ifapricefeed-interface
import "ifapricefeed-interface/IIfaPriceFeed.sol";
Source: github.com/IFA-Labs/IfaPriceFeed-interface

Next Steps

Event Reference

Events emitted by the oracle contract for monitoring and indexing.

Complete Example Contract

See all functions used together in a production-ready integration.