Fetch Data via Push Model
This guide is designed for external developers who need to retrieve and use prices provided through the Push Model of the Entangle Universal Data Feeds protocol on the Solana blockchain.
The price feeds are regularly pushed to and stored within the Solana Price Oracle on-chain program.
Step 1. Making a sample consumer program
First, a Solana program implementing the core business logic is required. The next step is to integrate the price-consuming functionality, as demonstrated in the example below. This Rust program shows how to retrieve asset prices from the Price Oracle program. The provided example can serve as a template for external developers to create their own price-consumer programs.
Key Function: consume_price
consume_price
The consume_price
method in the example program retrieves the price for a given asset by constructing an instruction and invoking the on-chain Entangle Price Oracle.
The Price Oracle address is provided as part of the accounts set.
The target asset's address is defined as a Program Derived Address (PDA), derived using predefined attributes and the asset name according to Price Oracle rules.
The returned data consists of two parts: price and timestamp.
The price is a 32-byte value, but only the rightmost 16 bytes are used.
The timestamp is a Unix timestamp.
Program Setup
To begin, you’ll need to create a consumer program using the Solana Rust SDK. The program will interact with the Entangle Price Oracle and retrieve asset prices. The following sample is also available on the GitHub.
Step 2. Invoking the program on the client side
The sample script is available on GitHub that demonstrates how to invoke the Consumer Program Sample on Solana. It provides an example of how to interact with the Consumer Program and retrieve asset prices or other relevant data. It can serve as a useful starting point for developers working with price oracles on the Solana blockchain.
There are two articles could be used to check the PUSH model works well on the Solana:
Solana. Setting up the Entangle UDF local testing environment The local testing environment should be initialized by following the instructions provided in the guide of the Price Oracle Solana repository. This ensures that all necessary components are set up correctly, including deploying programs, configuring accounts, and running tests, to create a fully functional local environment for further development and testing of the price oracle and associated programs.
Solana. Sample client for fetching data via the PUSH MODEL This sample client includes a script that interacts with the
udf_solana
program to retrieve the latest price of the certain data key like "NGL/USD."
Step 3. Ensuring price consuming works well
By following the instructions provided above, the process results in a finalized transaction on the Solana network. In this specific case, the transaction contains logs that indicate the price retrieved through cross-program invocation. These logs provide evidence of the successful interaction between the programs, showcasing the retrieved price data.
The following logs are generated when the transaction is executed. The call invokes two Solana programs in turn:
Consumer Program:
Program ID:
3r5ixGQu8DRmJWgFEjwnDUQ6yasfYFXDsUbqkA6gkRtv
Entangle Price Oracle:
Program ID:
7HramSnctpbXqZ4SEzqvqteZdMdj3tEB2c9NT7egPQi7
Price Data for NGL/USD
The resulting price for the NGL/USD pair is interpreted as a u128 big endian value:
129898283383055207
This price should be divided by
10^18
to get the final value.
Interpretation of the Result:
Final Price:
129898283383055207
multiplied by10^18
is interpreted as 0.12989.Timestamp: The price was issued on August 12, 2024, at 22:45:24.
With this guide, you can now integrate Solana's Entangle Universal Data Feeds price data into your decentralized applications. This system efficiently retrieves price and timestamp information, ensuring that your program can access accurate on-chain data with minimal latency.
Last updated