# xOracle

&#x20;![](https://lh5.googleusercontent.com/FcqOQacV0NagWCSme3BGXy0PP2zxdfq6eXoINUTm8P7GlhjIITJ8eeO9GU2wRHPISKXZd8dvBLMnuaiGwIRHzl5NvB_P6mRLhUGibFMYQrVJp_UCbaX1hEXhy50o3EArw1Spwerb19ARCnUHsAaFCAc)

The xOracle is a decentralized pricing data solution for Blockchain Ecosystems.

## **Overview**

An Oracle Price Feed is a decentralized mechanism for providing real-time, accurate pricing data within a blockchain ecosystem. By utilizing a network of independent data providers, known as "oracles," an Oracle Pricefeed ensures that the pricing data is accurate and tamper-proof. Smart contracts are used to define the rules and incentives for data providers, and handle the distribution of rewards for accurate and timely data submissions.

#### Architecture

The architecture of an Oracle Price Feed consists of several key components

* **Data providers:** These are independent entities that collect and report pricing data to the network. They may be individuals, organizations, or even other smart contracts.
* **Smart contracts:** These are the backbone of the Oracle Price Feed, and handle the following tasks
  * Defining the rules and incentives for data providers
  * Collecting and validating pricing data
  * Determining which data is considered valid
  * Distributing rewards to data providers for accurate and timely submissions
* **Token:** A token is used to incentivize data providers to submit accurate and timely data. Tokens can be earned by data providers for each valid submission and used for various purposes within the ecosystem, such as paying transaction fees or accessing premium features.
* **Oracle network:** The oracle network is the network of all the data providers and smart contracts that together form the Oracle Price Feed.

#### Features

* **Decentralized:** The Oracle Price Feed utilizes a network of independent data providers, ensuring that the pricing data is accurate and tamper-proof.
* **Real-time:** Data providers are incentivized to submit pricing data in real-time, ensuring that the data is always up-to-date.
* **Customizable:** The smart contracts used in the Oracle Price Feed can be customized to suit the specific needs of the ecosystem.
* **Token-based incentives:** Data providers are incentivized to submit accurate and timely data through the use of a token, which can be earned and used within the ecosystem.

#### Use Case

Oracle Price Feeds can be used in a variety of decentralized finance (DeFi) and prediction market applications where accurate pricing data is crucial these include

* **Decentralized exchanges:** An Oracle Price Feed can be used to provide real-time pricing data for assets traded on a decentralized exchange.
* **Collateralized lending:** An Oracle Price Feed can be used to determine the value of collateral for lending platforms.
* **Prediction markets:** An Oracle Price Feed can be used to determine the outcome of predictions based on market data.

## The xOracle's Architecture

<figure><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FsZKRFL6c3U69jwRZj75u%2FxOracle_-_Architecture.png?alt=media&#x26;token=939b4bdc-c526-445b-aee1-a55429606a9e" alt=""><figcaption><p>xOracle System Diagram</p></figcaption></figure>

### Data Layer

The first component of xOracle - xOracle chain A.K.A the data layer -  is accountable for timely updates of fresh data from multiple reliable data sources to obtain up-to-date price data. This is where xOracle’s price feed nodes are fed with raw price data from off-chain centralized exchanges (Eg. Binance, Kucoin) and on-chain decentralized exchanges (Eg. Pancakeswap)&#x20;

As price feeds are employed by smart contracts to execute crucial on-chain events, our xOracle price feed guarantees maximum data integrity through the use of timestamps.

Additionally, both the timestamp and the price data are signed whenever it is fed into the price feed nodes, thus ensuring that the data used by the relay nodes are not compromised.

The price feeds are set to update at 4-second intervals, also known as the heartbeat interval, using the formula:

> ```solidity
> timestamp = block.timestamp - (block.timestamp % 4)
> ```

This guarantees that every single price feed node will have refined price data for the relay nodes every 4 seconds. The more price feed nodes there are, the more accurate, sustainable and secure the price data becomes.

### Execution Layer

The second component of xOracle, known as the execution layer - is responsible for addressing support requests from the application site. On this layer, relay nodes monitor the requested event from the application site on all chains. Upon submission of a request, our xOracle price feed uses timestamps to retrieve the price and respond back to the requester.

Moreover, the fulfillRequest requires proof of signature for the dataset. Verifying whether the signature is legitimately signed by the signer (price feed node).

The entire procedure, from request to fulfillRequest takes only 6-9 seconds then the xOracle will respond to the requester with real-time price.

### Application Layer

The final component of xOracle - the application layer - is responsible for interfacing with xOracle. This layer is a part of the smart contract application which can interface with the xOracle contract.&#x20;

As our xOracle offers a low-price API (under development), the cost of running xOracle will be charged through the transaction gas. xOracle simplifies the implementation process for developers to manage the costs whether to charge with users or charge with the team.

By designing xOracle chain as a center for price feed, we can install plug-ins to add more relay nodes to support more EVM chains that are in service without incurring additional operating costs. This allows us to scale xOracle to support any chains rapidly and effectively in the long run.

In the future roadmap, we plan to allocate our revenue from xOracle according to governance votes such as buy-back and burn (TEM), rewards distribution (Community Staking), etc.

## Price Feed Tokens

<table><thead><tr><th width="206" align="center">Token Index</th><th>Token Symbol</th></tr></thead><tbody><tr><td align="center">0</td><td><img src="https://lh6.googleusercontent.com/esdE484ZInC6KjekXv6Rq2UyOpa9wrHmHOCtG6AHAWnugeO-unLa05QMAVJp4K_7K0cUCwCD59We08Bqm6TKs56_MuPG08YGofmVg1jPy0aJ8TvEHn6wB-Z2gwCQDk_lBR1TPGl6tP0PVwfZsrdYVFI" alt="BTC" data-size="line"> BTC</td></tr><tr><td align="center">1</td><td><img src="https://lh6.googleusercontent.com/7K4hXud3FOz1hbo8hsEJCpEFLkszNlswS2TpnCsaKxRd2z4XjIbzrJFMFvBkasi-OzRWG32n6Go9YTvpfinQXfkHvPWfjQSKvyLrmKiY2xyErVgsjNaAsZ-E7KAITaIgPJHfW_RUzj63oa_EsVAtLmM" alt="ETH" data-size="line"> ETH</td></tr><tr><td align="center">2</td><td><img src="https://lh3.googleusercontent.com/yUGbNyDIrR2KfOrBvwQG4iYqX12gzULG1ufOrSpnSbVa04vXb3HOlvKCTjOW_ghvRLGk0cvd4NrWvS2x9qWGA3EjWwBE-4hVOt-HWjw0cajvdu7DI1t3th5fQ_xc3wx8Q0VMJJ7dup7wOdJy9PHabaE" alt="BNB" data-size="line"> BNB</td></tr><tr><td align="center">3</td><td><img src="https://lh4.googleusercontent.com/dvmjPWkXiCpvZ9snyrminCdncu7Wxk1S7HU4jewouQKDFIwps_KbXugWvY5wjDKel2XxL06kolMzM7FkQH5g-jF5w2UjgW97TLHc7kZLD3m_kkz8s84-3hYnGYvXQ7HZeHl7YcVL67PFW8EZFYQ2qxY" alt="USDT" data-size="line"> USDT</td></tr><tr><td align="center">4</td><td><img src="https://lh5.googleusercontent.com/dd2MkWtr_QODvmpyW4WecCzHpNDL5cJOuS80s0yW1MhptHPTHt7F48OeMQa0t6VAfMrpb-wFx7a8qdmhw_kYlokMjGEqQXgxi1R5DHESCDrVCBetdSDLImhiKV60O-IvVctkY4ftgPHzNZkL2crRKGc" alt="BUSD" data-size="line"> BUSD</td></tr><tr><td align="center">5</td><td><img src="https://lh6.googleusercontent.com/A8PBtUzAkdyvIj6vU69LThFi5DpGELfo5DTfqQA0u5Bt9pOoBerYUjsQCGd29mKevn0Vnxne6r9MUQjFJ2HtQdkbfPv3blxyGHzfkG_KtwQ8En7AfMIQpFY8PsEjvfh9csjpDGk_M6sdfBUAQ6Bxq5s" alt="USDC" data-size="line"> USDC</td></tr><tr><td align="center">6</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2F23KW7LUjH1pByfLN8Jzd%2FBadge_Dai.webp?alt=media&#x26;token=b17fbd35-8939-432e-9f53-0b3a6cefa63e" alt="DAI" data-size="line"> DAI</td></tr><tr><td align="center">10</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2F2QkqU8i83FrvU2gONAUB%2Fxrp-symbol-white-128.webp?alt=media&#x26;token=6cfff1de-5de3-4a08-b96e-24339259ed0c" alt="XRP" data-size="line"> XRP</td></tr><tr><td align="center">11</td><td><img src="https://lh3.googleusercontent.com/Ld4k09_Dax30C4ffxuDKwK5A0iMZc6cq-jJJg7dodqvSpv9QEYVwCut2UeFSkRdiew1VPHxV44Yk9t6-_SLSuTdoaCXoXRraeMmJaKZ6KzBnkYyFhPtIXc90XVfM9Uw835VmMogRze95jEnZclLpqiU" alt="DOGE" data-size="line"> DOGE</td></tr><tr><td align="center">12</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FY5Ie3d7Q6lCHFNmkZX2C%2Ftron-logo.webp?alt=media&#x26;token=148df825-8a5e-468b-a1b4-8dfd25c19c9f" alt="TRX" data-size="line"> TRX</td></tr><tr><td align="center">20</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FYz0M04ox9yTtDs31YXK0%2Fcardano.webp?alt=media&#x26;token=34701e9d-6708-4cd9-90fd-4f0e3ad9e9b9" alt="ADA" data-size="line"> ADA</td></tr><tr><td align="center">21</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FDencNXe6Fin9cOu8cfmg%2Fmatic-token-icon.webp?alt=media&#x26;token=eb2daa11-84af-4639-a461-ecc7fca14768" alt="MATIC" data-size="line"> MATIC</td></tr><tr><td align="center">22</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FItkShsfY6x7nqNbvhL1V%2Fsolana.webp?alt=media&#x26;token=6b1385ed-44e0-498a-b581-e9aff316887d" alt="SOL" data-size="line"> SOL</td></tr><tr><td align="center">23</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FSLLXWqUjGR26kX69TdgT%2Fpolkadot.webp?alt=media&#x26;token=7bcbf749-4ca4-4e70-9a36-4e3f31348396" alt="DOT" data-size="line"> DOT</td></tr><tr><td align="center">24</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FCM6N1hTQExDFVLDjFHC9%2FAvalanche_Circle_RedWhite_Trans.webp?alt=media&#x26;token=1c80dd10-ae95-4b74-ba0e-68a647ec3d28" alt="AVAX" data-size="line"> AVAX</td></tr><tr><td align="center">25</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FRWDzuvJBHSNGr7x0cn6i%2FFantom_round.webp?alt=media&#x26;token=e36d1db3-6552-48e1-ac28-2e67c7cf5ac7" alt="FTM" data-size="line"> FTM</td></tr><tr><td align="center">26</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2Fr8s8BivxjMcZuv61hHiW%2Fnear.webp?alt=media&#x26;token=496609b7-2e95-4276-8b84-7e4a00a4a5b9" alt="NEAR" data-size="line"> NEAR</td></tr><tr><td align="center">27</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FDG93LmpYfsCWYHnyz1KE%2Fcosmos_hub.webp?alt=media&#x26;token=30ce223e-6a93-4a74-9d0b-c89612331ec6" alt="ATOM" data-size="line"> ATOM</td></tr><tr><td align="center">28</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FwMaQaJJRGC55L2E8nbis%2FOptimism.webp?alt=media&#x26;token=fbe597a7-9991-4381-bd1a-5284c90a655f" alt="OP" data-size="line"> OP</td></tr><tr><td align="center">29</td><td><img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FD6PPtaqXOcEmEvRpIFbi%2Fphoto_2023-03-29_21.webp?alt=media&#x26;token=2ced149c-c8ab-4267-a3ba-df34daa7bf5b" alt="ARB" data-size="line"> ARB</td></tr></tbody></table>

## Example: Request Prices

view full code: <https://github.com/Crown-Labs/xoracle-contracts/blob/main/contracts/example/RequestPrices.sol>

```solidity
    // Request oracle prices
    function requestPrices() external {
        // allowance req fee 
        // (require deposit WETH on this contract)
        IERC20(weth).approve(xOracle, type(uint256).max);

        // make payload and call
        bytes memory payload = ""; // no payload
        uint256 expiration = 0; // no expired
        uint256 callbackMaxGasLimit = 5000000; // 5M
        IXOracle(xOracle).requestPrices(payload, expired, maxGasPrice, callbackMaxGasLimit);
    }
    
    // Implementable callback
    function xOracleCall(
        uint256 _reqId, 
        bool _priceUpdate, 
        bytes memory _payload
    ) external onlyXOracle {
        // do thing
        // ...
    }

    // Get the last price by Token Index
    function getPrice(uint256 _tokenIndex) external view returns (uint256) {
        (, uint256 price, , ) = IXOracle(xOracle).getLastPrice(_tokenIndex);
        return price;
    }
```

## xOracle Contract

### <img src="https://3804870498-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkl990RPEsHxiRuhduGai%2Fuploads%2FLXYAzKizfmqKFeUcR9v3%2Flinea.svg?alt=media&#x26;token=d2730289-a319-4b1c-bc14-9f5c4dbbc2bd" alt="" data-size="line"> Linea Testnet

<table><thead><tr><th width="272">Contract</th><th>Address</th></tr></thead><tbody><tr><td>xOracle</td><td><a href="https://goerli.lineascan.build/address/0xB1CBd1d5A394E6B4BDaA687468266Caf533D9035">0xB1CBd1d5A394E6B4BDaA687468266Caf533D9035</a></td></tr><tr><td>BTC/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0x3432dD444774c4A88D330EdB127D837072e5cc9e">0x3432dD444774c4A88D330EdB127D837072e5cc9e</a></td></tr><tr><td>ETH/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0xe767d64F9b37fe809232a7f20304d28F03EED2B1">0xe767d64F9b37fe809232a7f20304d28F03EED2B1</a></td></tr><tr><td>BNB/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0x0c8b54e305E8CBb9958671a9C02467328EF4c95C">0x0c8b54e305E8CBb9958671a9C02467328EF4c95C</a></td></tr><tr><td>USDT/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0x4B114D9D36b09FcC71C492C29e7F8796C655A08d">0x4B114D9D36b09FcC71C492C29e7F8796C655A08d</a></td></tr><tr><td>BUSD/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0x4926B8803db627a3a77687cB9160725c0845Aabb">0x4926B8803db627a3a77687cB9160725c0845Aabb</a></td></tr><tr><td>USDC/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0xA23902465EC47904b4b53dCD95f2395b45F33E4F">0xA23902465EC47904b4b53dCD95f2395b45F33E4F</a></td></tr><tr><td>MATIC/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0xE41CEc959C332968226B2a07f6252Bc57964de1d">0xE41CEc959C332968226B2a07f6252Bc57964de1d</a></td></tr><tr><td>OP/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0x81E12991821d0bFdFC7D1a79D49056bcFa0Eaf75">0x81E12991821d0bFdFC7D1a79D49056bcFa0Eaf75</a></td></tr><tr><td>ARB/USD PriceFeed</td><td><a href="https://goerli.lineascan.build/address/0x9b5C82a57AcF5569e10fe1f1783ab57230B18ab9">0x9b5C82a57AcF5569e10fe1f1783ab57230B18ab9</a></td></tr></tbody></table>

## xOracle API

<table data-header-hidden><thead><tr><th width="275">API</th><th>Url</th></tr></thead><tbody><tr><td>Get Prices</td><td><a href="https://api.xoracle.io/prices/xoracle">https://api.xoracle.io/prices/xoracle</a></td></tr><tr><td>Get Price by Node</td><td><a href="https://api.xoracle.io/prices/xoracle/node">https://api.xoracle.io/prices/xoracle/node</a></td></tr><tr><td>Get Prices by Index (<a href="https://api.xoracle.io/prices/xoracle/0">Try call</a>)</td><td><a href="https://api.xoracle.io/prices/xoracle/">https://api.xoracle.io/prices/xoracle/</a>{index}</td></tr><tr><td>Get Pricefeed by Timestamp (<a href="https://api.xoracle.io/prices/pricefeed/1698131220">Try call</a>)</td><td><a href="https://api.xoracle.io/prices/pricefeed/">https://api.xoracle.io/prices/pricefeed/</a>{timestamp}</td></tr><tr><td>Get Token Index Info</td><td><a href="https://api.xoracle.io/prices/tokenIndexInfo">https://api.xoracle.io/prices/tokenIndexInfo</a></td></tr><tr><td>Get Node Info</td><td><a href="https://api.xoracle.io/prices/nodeInfo">https://api.xoracle.io/prices/nodeInfo</a></td></tr><tr><td>Estimate Gas Used (<a href="https://api.xoracle.io/estimate-gas/getGasUsed/59140/0x0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000005e">Try call</a>)</td><td><a href="https://api.xoracle.io/estimate-gas/getGasUsed/">https://api.xoracle.io/estimate-gas/getGasUsed/</a>{ChainId}/{Calldata}</td></tr></tbody></table>

## xOracle Chain Infomation

<table data-header-hidden><thead><tr><th width="276"></th><th></th></tr></thead><tbody><tr><td>Chain ID</td><td>1123581321</td></tr><tr><td>Symbol</td><td><strong>XOR</strong></td></tr><tr><td>RPC</td><td><a href="https://explorer.xoracle.io/">https://rpc.xoracle.io</a></td></tr><tr><td>Block Explorer</td><td><a href="https://explorer.xoracle.io/">https://explorer.xoracle.io</a></td></tr></tbody></table>

## Nodes

<table data-header-hidden><thead><tr><th width="279">Node</th><th>Address</th></tr></thead><tbody><tr><td>RelayNode: Sentinel</td><td>0x9642955e650f8f380e9e5f978c910d684b7a0805</td></tr><tr><td>RelayNode: 0xGuardian</td><td>0xE49EE57521a4eDF93Cb62013CF5B263660b3dD79</td></tr><tr><td></td><td></td></tr><tr><td>Pricefeed: XORNode</td><td>0x866739f5308D27B091445f6A0E10b29539aB6123</td></tr><tr><td>Pricefeed: CommunityNode</td><td>0xa2694632465dffEb3194ad919Ac7E6366b7A67E9</td></tr><tr><td>Pricefeed: Authentic</td><td>0x78a3421C4f2755CBaFe54d65856F9Dc223c3D42b</td></tr><tr><td>Pricefeed: TrustNode</td><td>0x3018A56c5cD12281C7E1C544Dba26492daE06601</td></tr><tr><td></td><td></td></tr><tr><td>Validator 1</td><td>0x91E1B08019d80319aC0Af7048d07e8FDC88bE326</td></tr><tr><td>Validator 2</td><td>0x3688f1eA10B2544414BF3898412987b0b9Be2319</td></tr><tr><td>Validator 3</td><td>0x1085d563e356482eB9d5C6b6Fa59B0123056BFe7</td></tr></tbody></table>

## Links

<table data-header-hidden><thead><tr><th width="283"></th><th></th></tr></thead><tbody><tr><td>xOracle Uptime</td><td><a href="https://uptime.xoracle.io/">https://uptime.xoracle.io</a></td></tr></tbody></table>
