Push based oracles
Push Based Oracle
The Push-Based Oracle system enables contracts to receive real-time updates based on predefined criteria such as fixed intervals, specific price deviations, or a combination of both. This design provides flexibility and efficiency for decentralized applications needing accurate and timely data.
Usage
Method 1: Separate Oracle Contract
In this method, any contract that needs data can read directly from the Oracle contract. The Oracle maintains updates as a mapping, where each key maps to a Data struct containing the latest timestamp and value.
The updates mapping is a key-value store where:
Key: A unique identifier, typically a string, representing the asset or data type (e.g., DIA/USD, BTC/USD).
Value: A Data struct containing:
key: The identifier of the data entry (redundant for reference but useful for integrity checks).
timestamp: The timestamp of the latest update.
value: The most recent value associated with the key.
Example
Example Oracle Contract:
Sepolia:
0x76a4BA6e4A40Bc613821e2a468a1e94FcCa4CE83
The following key pairs are available in the demo oracle:
DIA/USD
BTC/USD
ETH/USD
Method 2: Direct Delivery to Contracts
In this method, updates are pushed to the receiving contract via a callback mechanism. The receiving contract must implement a specific interface and define a callback function to handle the incoming data.
Your contract must implement IMessageRecipient and IInterchainSecurityModule.
The Oracle invokes the handle callback function in the receiving contract to deliver updates. The data payload is decoded and can be stored or processed as needed.
Access push based oracle
To access push based oracles, use the updates(pair_name) function. Here’s how you can interact with it:
Use the full pair name (e.g., DIA/USD) as the pair_name
Query the contract using Etherscan's "Read" section.
The response contains the following data fields:
Key: The identifier of the asset pair (e.g., DIA/USD).
Timestamp: The time of the latest price update.
Value: The most recent price of the asset.
Last updated