Consume Price Feeds

Once your Rollup is deployed, all price feeds will automatically be ingested from the base layer by the Rollup every time a block is produced (every two seconds). Fresh prices are pushed to a predeploy oracle smart contract on the Rollup which exists at the following address:

Smart Contract
Address

L2PriceOracle

0x4200000000000000000000000000000000000420

Prices can be fetched by binding the L2PriceOracle smart contract interface (below) to the predeploy address (above) or by simply inheriting from the provided Solidity SDK (recommended) which doesn't require an address to be specified.

Both methods return Pyth price objects. The type definition for this is available via the @pythnetwork/pyth-sdk-solidity package on npm. See Using the Solidity SDK for more information.

IL2PriceOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

import {PythStructs} from "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";

interface IL2PriceOracle {
    function getPriceUnsafe(
        bytes32 id
    ) external view returns (PythStructs.Price memory);

    function getPriceNoOlderThan(
        bytes32 id,
        uint256 age
    ) external view returns (PythStructs.Price memory);
}

Last updated