0047 XLS-47d Price Oracles #129
Replies: 9 comments 19 replies
-
Serveral existing oracles are using trustlines for the same purpose (e.g. https://github.com/XRPL-Labs/XRPL-Persist-Price-Oracle and https://dev.to/wietse/aggregated-xrp-usd-price-info-on-the-xrp-ledger-1087). This XLS suggests a new LedgerObject and API methods for the same purpose. The main benefit is less abstraction and better discoverability? Or do I miss something 😀 IMO on-chain oracles are mainly beneficial to smart contracts (as you also write in the abstract), as off-chain applications might be better served by faster APIs than waiting for off-chain data to be updated to an on-chain oracle to be consumed off-chain again. What is the main purpose for on-chain oracles without smart contract support, or is this envisioned in a Hooks environment? In that case, it might not even be necessary as Hooks, if I understand correctly, already offers a higher abstraction for storing arbitrary information. |
Beta Was this translation helpful? Give feedback.
-
Aside from the obvious question "how is this useful without smart contracts?" ... why are price and scale specified individually as uint64 and uint8? The XRPL already has a bespoke base-10 floating point system STAmount which gives you 54 bits of mantissa and 8 bits of exponent. All IOU balances are currently encoded this way, why not use it here too? |
Beta Was this translation helpful? Give feedback.
-
I'm interested in the trust part? Anyone can create prices for any asset? I could see a price, spin up 30 accounts and submit prices? EDIT: You choose the oracles that you want the price aggregated from. I misunderstood that. |
Beta Was this translation helpful? Give feedback.
-
I like this concept but let's talk use case. If there were native smart contracts, this would definitely be useful to add to the ledger but what's the rationale behind this without smart contracts as users could AND would be requesting price data from third party sites, APIs and services? |
Beta Was this translation helpful? Give feedback.
-
Having spent a number of hours actually building Oracles. There are a number of issues I would like to cover with this spec.
Here is an example of data I produce as a Oracle. Notice the vast amount of data I produce with the records, this speaks to the attestation of the result set. The rawData, exchanges data was collected from, timestamp, age of data, etc... From this raw data im able as a provider to attest to the results produced. I would suggest reworking this spec for the following.
Here I can now optionally keep my oracle data private (offline to those i service) via the URI. And/Or publicly publish the data via the pair list field. This makes this a lot more flexible in the way data can be provided from oracles and allows even other ledgers/chains to submit their records here (the URI simply references their hashes) or external centralised databases can be referenced in the same way. |
Beta Was this translation helpful? Give feedback.
-
Hi @gregtatcam
Fair enough with regards to using the submission hash as the identifier back to the attestation, agreed that can be achieved like that. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Thank you all for the feedback. I'm going to close this discussion by the end of the next week (October 6) and move the updated specs draft to the standards. The update is going to include the array of token pairs and URI per @lathanbritz suggestion. It'll also consolidate create and update into one transaction. |
Beta Was this translation helpful? Give feedback.
-
Moved to standards. |
Beta Was this translation helpful? Give feedback.
-
Latest version of spec: XLS-47 Price Oracles
Implementation: PR #4789
Oracles on XRP Ledger
Abstract
This proposal adds on-chain
PriceOracle
object to XRPL ledger. A blockchain oracle is a system or service that acts as a bridge between a blockchain network and the external world, providing off-chain data or information to decentralized applications (dApps) on the blockchain. Oracles are used to bring real-world data, for instance market prices, exchange rates, interest rates, or weather conditions onto the blockchain, enabling dApps to access and utilize information that resides outside the blockchain. This document outlines the protocols involved inPriceOracle
on XRPL ledger and provides guidelines for developers and system architects to implement and utilize this solution effectively. It introduces a new on-ledgerPriceOracle
object and the transactions to create, delete, and update thePriceOracle
and addsget_aggregate_price
API to retrieve an aggregate mean, trimmed mean, and median for the provided price oracles. This feature requires an amendment.Terminology
Creating
PriceOracle
instance on XRPLOn-Ledger Data Structure
PriceOracle
objectThe
PriceOracle
ledger entry represents thePriceOracle
object on XRPL ledger and contains the following fields:OracleID
string
HASH256
Owner
string
ACCOUNTID
Symbol
string
CURRENCY
PriceUnit
string
CURRENCY
SymbolClass
string
BLOB
SymbolPrice
number
UINT64
Scale
number
UINT8
LastUpdateTime
number
UINT32
Provider
string
BLOB
PreviousTxnID
string
UINT256
PreviousTxnLgrSeq
string
UINT32
OracleID
. The ID of a PriceOracle object is the SHA-512Half of the following values, concatenated in order:ORACLE
(0x52)Owner
is the account that has the update and delete privileges. It is recommended that this account has an associatedsigner list
.Symbol
is the symbol to be priced. Any arbitrary value should be allowed and interpreted exactly like other asset code fields in the ledger. A new enum value STI_CURRENCY and class STCurrency are introduced to support theCURRENCY
field.PriceUnit
is the denomination in which the prices are expressed. Any arbitrary value should be allowed and interpreted exactly like other asset code fields in the ledger.SymbolClass
describes a type of the asset, for instance "currency", "commodity", "index". It is a string of up to ten ASCII hex encoded characters (0x20-0x7E).SymbolPrice
is the scaled asset price, which is the price value after applying the scaling factor.Scale
is the price's scaling factor. It represents the price's precision level. For instance, ifScale
is6
and the original price is0.155
then the scaled price is155000
. Formally,Scale
range is {0-10}.LastUpdateTime
is the specific point in time when the data was last updated. TheLastUpdateTime
is the ripple epoch time.Provider
identifies an Oracle Provider, for instancechainlink
. It is a string of up to 16 ASCII hex encoded characters (0x20-0x7E).PreviousTxnID
is the hash of the previous transaction to modify this entry. (Same as on other objects with this field.).PreviousTxnLgrSeq
is the ledger index of the ledger when this object was most recently updated/created. (Same as other objects with this field.)Example of
PriceOracle
JSONTransactions
This proposal introduces several new transactions to allow for the creation, update, and deletion of the
PriceOracle
object.Transaction for creating
PriceOracle
instanceWe define a new transaction CreateOracle for creating a new
PriceOracle
instance. Before the transaction can be submitted, the Oracle Provider has to do the following:Account
XRPL account with sufficient XRP balance to meet the reserve and the transaction fee requirements.Account
account public key so that it can be used for verification by dApp’s.Transaction fields for CreateOracle transaction
TransactionType
string
Indicates a new transaction type
CreateOracle
. The integer value is 41.Account
string
ACCOUNTID
Account
is the account that has the Oracle update and delete privileges.Symbol
string
CURRENCY
Symbol
is the symbol to be priced.PriceUnit
string
CURRENCY
PriceUnit
is the denomination in which the prices are expressed.SymbolClass
string
BLOB
SymbolClass
describes an asset type.Provider
string
BLOB
Provider
identifies an Oracle Provider.The transaction fails if:
OracleID
already exists.Account
account doesn't exist.Account
account or the account's multi signers.On success the transaction creates a new
PriceOracle
object.Example of CreateOracle transaction JSON
Transaction for deleting Oracle instance
We define a new transaction DeleteOracle for deleting an Oracle instance.
Transaction fields for DeleteOracle transaction
TransactionType
string
Indicates a new transaction type
DeleteOracle
. The integer value is 42.OracleID
string
The ID of an Oracle object.
Account
string
ACCOUNTID
Account
is the account that has the Oracle update and delete privileges.DeleteOracle transaction deletes the
Oracle
object from the ledger.The transaction fails if:
OracleID
doesn't exist.Account
account or the account's multi signers.On success the transaction deletes the
Oracle
object.Example of DeleteOracle transaction JSON
Transaction for updating PriceOracle instance
We define a new transaction UpdateOracle for updating an Oracle instance.
Transaction fields for UpdateOracle transaction
TransactionType
string
UINT16
Indicates a new transaction type
UpdateOracle
. The integer value is 43.OracleID
string
HASH256
The ID of an Oracle object.
Account
string
ACCOUNTID
Account
is the account that has the Oracle update and delete privileges.SymbolPrice
number
UINT64
SymbolPrice
is the scaled asset price, which is the price value after applying the scaling factor.Scale
number
UINT8
Scale
is the price's scaling factor.LastUpdateTime
number
UINT32
LastUpdateTime
is the specific point in time when the data was last updated.The transaction fails if:
OracleID
doesn't exist.Account
account or the account's multi signers.On success the transaction updates the respective Oracle data.
Example of Price UpdateOracle transaction JSON
API's
Retrieving The Oracle
An Oracle object can be retrieved with the
ledger_entry
API call by specifying theOracleID
ID.Example of
ledger_entry
API JSONRequest JSON
Response JSON
Oracle Aggregation
get_aggregate_price
API retrieves the aggregate price of the PriceOracle.API fields are:
ledger_index
string
ornumber
(positive integer)The ledger index of the max ledger to use, or a shortcut string to choose a ledger automatically.
ledger_hash
string
A 20-byte hex string for the max ledger version to use.
symbol
string
symbol
is the symbol to be priced.price_unit
string
price_unit
is the denomination in which the prices are expressed.oracles
array
oracles
is an array oforacle_id
objects to aggregate over.trim
number
trim
is the percentage of outliers to trim. Valid trim range is 1-25.flags
number
flags
specifies aggregation type. At least one flag must be specified. The flags can be bitwise added.fSimpleAverage
fMedian
fTrimmedMean
trim
parameter should specify the percentage to trim. For instance, iftrim
is set to 10% then the lowest 5% and highest 5% of price points are removed.Example of get_aggregate_price API JSON
Request JSON
Response JSON
Beta Was this translation helpful? Give feedback.
All reactions