Intelli X
  • Introduction
    • What is IntelliX
    • Sample Use Cases
      • Structured Data with Custom Validation
      • AI and LLM-Based Use Cases for Unstructured Data Processing
  • understanding intellix
    • Bitcoin Proof-of-Stake Oracle
    • Modularity and Programmability
    • AI-Powered Unstructured Data Processing
    • Data Flows in IntelliX
    • Architecture Components
  • DEVELOPER GUIDE
    • Onboarding a new Price Feed using Configuration
    • Push and Pull Flows and Contracts
Powered by GitBook
On this page
  • Declarative Approach
  • Programmatic Approach
  1. understanding intellix

Modularity and Programmability

IntelliX provides a high degree of modularity and programmability, allowing oracle developers to customize their implementations at varying levels of complexity. Developers can choose between two approaches: a declarative method, which is easier to implement, and a programmatic method for more advanced use cases requiring greater control.

IntelliX offers flexibility in how data is fetched and processed. Below are two approaches for publishing a price feed.

Declarative Approach

In the declarative approach, developers can configure key parameters like data source URLs, update frequency, and aggregation rules using a simple configuration file. This method is ideal for handling standard data sources with minimal setup.

The sample configuration below fetches price data from four cryptocurrency exchanges (Binance, Coinbase, Kraken, Bitfinex), extracts price values using a JSONPath processor and publishes the resulting data on-chain every 60 seconds. The data is published on multiple blockchain networks, including Bitlayer, BSC, and Merlin, and validated using an average-median approach.

sources:
    
    - id: binance
      type: url
      url: "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT"
      
    - id: coinbase
      type: url
      url: "https://api.exchange.coinbase.com/products/BTC-USD/ticker"
    
    - id: kraken
      type: url
      url: "https://api.kraken.com/0/public/Ticker?pair=XBTUSD"
    
    - id: bitfinex
      type: url
      url: "https://api-pub.bitfinex.com/v2/ticker/tBTCUSD"

update_frequency: 60  # Fetches data every 60 seconds

processors:
    - type: json_path
      source: [binance, coinbase]
      path: "$.price"
      
    - type: json_path
      source: kraken
      path: "$.result.XXBTZUSD.c[0]"
    
    - type: json_path
      source: bitfinex
      path: "$[6]"
      
publishers:
    
    - type: bitlayer
      contract_address: "0x1234567890abcdef1234567890abcdef12345678"
      
    - type: bsc
      contract_address: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef"
      
    - type: merlin
      contract_address: "0xabcdef123456abcdef123456abcdef123456abcdef"

validators:
   type: price_avg_median
   
output_schema:
   type: "ufixed256x18"  # ABI-compatible type for a floating point

Programmatic Approach

For more complex use cases, IntelliX allows developers to programmatically define their fetching and aggregation logic, offering maximum flexibility for custom workflows, data transformations, and integrations.

In the example below, the developer manually defines how to fetch price data from multiple APIs and calculates the average price. This approach allows full customization of the data fetching and processing logic, making it ideal for more advanced or unique use cases.

import statistics

# Custom price fetching function for BTC/USDT
def fetch():
    # Fetch price data from specified APIs
    binance = fetch_from_api("https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT")
    coinbase = fetch_from_api("https://api.coinbase.com/v2/prices/BTC-USD/spot")
    kraken = fetch_from_api("https://api.kraken.com/0/public/Ticker?pair=XBTUSD")
    bitfinex = fetch_from_api("https://api.bitfinex.com/v1/pubticker/btcusd")
    
    # Extract price values, adjusting for each API's response format
    price_binance = float(binance['price'])
    price_coinbase = float(coinbase['data']['amount'])
    price_kraken = float(kraken['result']['XXBTZUSD']['c'][0])
    price_bitfinex = float(bitfinex['last_price'])
    
    # Return prices as an array of floats
    return [
        price_binance,
        price_coinbase,
        price_kraken,
        price_bitfinex
    ]

# Custom validation function with median and average aggregation
def validate(data):
    # Calculate the median of each inner array
    medians = [statistics.median(prices) for prices in data]
    
    # Calculate the average of the resulting medians
    average_median = sum(medians) / len(medians)
    
    # Return the aggregated result
    return average_median

The fetch() function is responsible for retrieving the latest BTC/USDT price data from multiple cryptocurrency exchange APIs. It performs the following steps:

  1. Fetch Data: Calls each API endpoint to retrieve the BTC/USDT price.

  2. Extract Prices: Extracts the price data from each API response and converts them to floats for uniformity.

  3. Return: Outputs an array of floats, where each float represents the BTC/USDT price from a specific exchange. This array is meant to be used by multiple fetchers in a distributed system setup to gather data from a range of sources.

The validate() function aggregates the data collected by multiple fetchers, using a two-step approach:

  1. Input: Takes an array of arrays as input, where each inner array is the result of a fetch() function call by a different fetcher.

  2. Median Calculation: Calculates the median of each inner array. This median represents a single fetcher’s perspective on the BTC/USDT price, helping reduce the influence of outliers within each source's collected data.

  3. Average Calculation: Averages the medians from all fetchers, producing a final aggregated value that represents a robust consensus of the BTC/USDT price across sources and fetchers.

PreviousBitcoin Proof-of-Stake OracleNextAI-Powered Unstructured Data Processing

Last updated 7 months ago