AO RedStone Oracle

High level overview

img.png

  1. The AO Builders Relayer is loading a subset of prices offered by RedStone Primary Data Service.
    Currently, offered prices (in relation to USD) are:
    "BTC", "ETH", "USDC", "USDT", "SOL", "stETH", "AR"

  2. The Relayer sends the RedStone data to the Verifier Process (code).

  3. The Oracle Verifier Process verifies the prices signatures and timestamps using the official RedStone protocol package. This package is attached to the Process code via Warp QuickJs plugin.

  4. If the prices are properly verified - i.e.

    • They are signed by a set of trusted RedStone nodes
    • Their timestamp is not too old in relation to the message timestamp

    they are sent to the Storage Process (code).

  5. The Oracle Storage Process can be used by other Processes in the AO Testnet to load prices (example).

Ask for price from the Oracle Storage Process

If you want to ask for a price from your process - send a message to the Oracle Storage Process with Action = 'Request-Latest-Data' and Tickers = ['AR', 'ETH', ...]

Example:

ao.send({
    Target = '4fVi8P-xSRWxZ0EE0EpltDe8WJJvcD9QyFXMqfk-1UQ', -- the Oracle Storage Process id
    ReqId = msg.Id,
    Action = "v1/Request-Latest-Data", -- 'Request-Latest-Data' can be used for backwards compatibility
    Tickers = json.encode({ "AR", "BTC" }) -- required prices
})

In response, the Oracle Storage Process sends Action = "Receive-RedStone-Prices" with all the requested prices in the Data. Example Data (please note that it is a stringified JSON!) in the message:

"Data": {
   "AR": {
      "a": "0x51Ce04Be4b3E32572C4Ec9135221d0691Ba7d202", // the address of the RedStone node which provided the price
      "v": 27.346234546008, // the price value
      "t": 1719774710000 // the timestamp of the price
   }
}

Example asking contract is here.

Full example flow:

  1. User sends a transaction with action Check-Prices to the example process.
  2. The example process in response sends a request for prices to the Oracle process (action Request-Latest-Data).
  3. The Oracle process responds to the example contract with the latest requested prices sent in the Data field of the message (action Receive-RedStone-Prices)

Using the AOS 2.0 'reply/receive'

You can also use the reply/receive API introduced in the AOS 2.0. In order to do so, call the v2/Request-Latest-Data Action, e.g:

local oracleData = ao.send({
    Target = '4fVi8P-xSRWxZ0EE0EpltDe8WJJvcD9QyFXMqfk-1UQ', -- the Oracle Storage Process id
    Action = "v2/Request-Latest-Data", -- 'Request-Latest-Data' can be used for backwards compatibility
    Tickers = json.encode({ "AR", "BTC" }) -- required prices
}).receive().Data