All pages
Powered by GitBook
1 of 3

Coin X Oracle 🔮

Purpose

Coin X Oracle allows developers to easily deploy price oracles from various feeds without having to worry about each provider's intricacies and interfaces.

Upon requesting a price update, the Coin X Oracle will collect the price from various feeds and run a set of checks to make sure of its liveness and accuracy.

Flow

  1. Request a price update

  2. Collect the data from predetermined providers.

  3. Run a set of checks to ensure the price accuracy and liveness.

Security

The entire process from the data request to reading it inside a DeFi dApp happens in one transaction block atomically through the use of hot potatoes. Price consumers have 100% confidence in the liveness and accuracy of the data.

Feeds

The following feeds are available:

  • Pyth Network

  • Switchboard

Refer to the SuiTears💧interface documentation to learn Coin X Oracle's interface.

https://github.com/interest-protocol/coin-x-oracle

Pyth Network

Reliable, low-latency market data from institutional sources.

Why Pyth?

The first price provider supported by Coin X Oracle is Pyth Network. It is the leading Oracle provider on Sui Network and the largest first-party Oracle Network in the world. It supports of over 50 chains and offers 450 price feeds.

First Party Institutional Providers

Pyth network data sources do not rely on intermediaries to ensure reliability and liveness of the data.

Price Confidence

Pyth Network is the only provider that offers a price confidence metric in all price feeds. Assets do not have a single price in a market at any given point in time. By providing a confidence range, DeFi dApps can design their invariant to take into account price variance.

Interface

Structs

struct PriceInfoObjectKey has copy, drop, store {}

A dynamic field key to store the sui::object::ID of the pyth::price_info::PriceInfoObject that can that provide data to the oracle.

struct ConfidenceKey has copy, drop, store {}

A dynamic field key to save the minimum required price confidence. It is a percentage, where 100% is represented by 1e18.

struct PythFeed has drop {}

A witness that is added to the suitears::oracle::Request to prove that it collected data from Coin X Oracle's Pyth Network module.

Functions

report

It requests a price from Pyth Network and submits the information to a Coin X oracle request.

public fun report<Witness: drop>(
    oracle: &Oracle<Witness>, 
    request: &mut Request, 
    wormhole_state: &WormholeState,
    pyth_state: &PythState,
    buf: vector<u8>,
    price_info_object: &mut PriceInfoObject,
    pyth_fee: Coin<SUI>,
    clock_object: &Clock
 )
  • @param self. A suiterars::oracle::Oracle with this module's witness.

  • @param request. A hot potato issued from the self to create a suiterars::oracle::Price.

  • @param wormhole_state. The state of the Wormhole module on Sui.

  • @param pyth_state. The state of the Pyth module on Sui.

  • @param buf. Price attestations in bytes.

  • @param price_info_object. An object that contains price information. One per asset.

  • @param pyth_fee. There is a cost to request a price update from Pyth.

  • @param clock_object. The shared Clock object from Sui

Aborts

  • the price_info_object is not whitelisted.

  • the price confidence is out of range.

  • the price is negative or zero.

Switchboard

Why Switchboard ?

Switchboard provides a trusted execution environment to ensure off-chain oracles are not tempered with.It also allows for developers to deploy custom oracles.

Interface

Structs

struct AggregatorKey has copy, drop, store {}

A dynamic field key to store the address of the switchboard::aggregator::Aggregator that can that provide data to the oracle.

 struct SwitchboardFeed has drop {}

A witness that is added to the suitears::oracle::Request to prove that it collected data from Coin X Oracle's Pyth Network module.

Functions

report

It requests a price from Pyth Network and submits the information to a Coin X oracle request.

public fun report<Witness: drop>(oracle: &Oracle<Witness>, request: &mut Request, aggregator: &Aggregator)
  • @param self. A suiterars::oracle::Oracle with this module's witness.

  • @param request. A hot potato issued from the self to create a suiterars::oracle::Price.

  • @param aggregator. switchboard::aggregator::Aggregator that the self will use to fetch the price.

Aborts

  • the aggregator is not whitelisted.

  • the aggregator price is negative or zero.