Price Oracles
Last updated
Last updated
on the XRP Ledger bring real-world pricing data on-chain—bridging external market data with decentralized applications (dApps). This feature enables dApps, decentralized exchanges, and DeFi protocols to function with up-to-date, verifiable price feeds.
Price Oracles are on-chain ledger objects that store external price information (e.g., XRP/USD). They are created and updated via the OracleSet transaction, and can be removed using the OracleDelete transaction. dApps can access this data to trigger smart contract logic, perform asset conversions, or maintain stablecoins.
Reliable Data Feeds: Provide verified, real-time pricing data from trusted providers.
Decentralized Trust: Price data is recorded on the immutable XRPL ledger.
Data Aggregation: Multiple oracle instances can be aggregated to calculate mean, median, or trimmed mean values, reducing the impact of outliers.
The PriceOracle object includes fields such as Owner
, Provider
, PriceDataSeries
, and LastUpdateTime
. You use an OracleSet transaction to create or update an oracle instance, while the OracleDelete transaction removes it from the ledger. Additionally, the get_aggregate_price
API allows for combining data from multiple Price Oracle objects to generate reliable price statistics.
Real-World Data Integration Seamlessly integrate external pricing data into on-chain applications.
Enhanced Transparency and Security Data stored on XRPL is verifiable and tamper-resistant.
Robust Data Aggregation Aggregating data from several oracles minimizes anomalies and improves reliability.
Dynamic Data Management Easily update or remove price feeds with dedicated transactions.
Before working with Price Oracles, ensure you have:
An active Owner account on the XRPL that meets the XRP reserve requirements.
Sufficient XRP to cover transaction fees.
Trust in your external data provider (e.g., a reputable API or on-chain oracle service).
Begin by installing the XRPL library:
Then, initialize your XRPL client and wallet:
Submit an OracleSet transaction to create or update a Price Oracle instance:
Use the ledger_entry
API to fetch the on-chain Price Oracle object:
To get a decimal representation of the AssetPrice convert it from HEX to a Number:
Aggregate data from multiple oracles with the get_aggregate_price
API:
To delete the Oracle Object from your Account perform an OracleDelete
Transaction.
Ensure your account meets the reserve requirement, especially when including more than five token pairs in PriceDataSeries
.
Validate that the LastUpdateTime
reflects current pricing data.
Maintain consistency for the Provider
and AssetClass
fields across updates.
All OracleSet and OracleDelete transactions must be signed by the owner account or its authorized multi-signers.
Price Oracles empower the XRPL ecosystem by enabling:
Decentralized Finance (DeFi) Utilize real-world price data to support lending, derivatives, and other DeFi products.
Stablecoin Management Maintain stablecoin peg values with aggregated price feeds.
Efficient Trading and DEX Integration Provide reliable market data for order matching and automated market making.
By integrating Price Oracles, developers can build robust, data-driven applications that benefit from transparent and up-to-date market insights.
Remember to disconnect your client after operations:
Happy building with Price Oracles on XRPL!