Orally
  • 👋Introduction
  • ❔Why Orally?
  • Orally Price Feed Integration Guide
  • quick-start
    • 🌱Sybil: data feeds
    • 🐬Apollo: request feeds from EVM
    • 🎬Pythia: automation
    • 📖Useful addresses & Links
  • Overview
    • 💡Video Overview
    • ✨How Orally Works
    • 🔐Security and Reliability
    • 📖Glossary
  • Page
  • Problems
    • The Oracle Problem
    • Frozen Oracle Problem
  • 🛰️Use Cases
  • Orally Products
    • 🧙‍♂️Sybil
    • 🦉Pythia
    • 🐬Apollo
    • 🕵️‍♂️Cassandra (DAuth)
    • ▶️Deplhos
    • 📧Hermes
  • Utilised ICP features
    • 🛠️ECDSA threshold Signatures
    • ✴️HTTP Outcalls
    • ⏳ICP timers (heartbeat system)
    • 🌀Random tape
    • 💱Exchange rate canister
  • FAQ
Powered by GitBook
On this page
  • Frontend Subscribe
  • Subscription Usage Examples
  1. quick-start

Pythia: automation

PreviousApollo: request feeds from EVMNextUseful addresses & Links

Last updated 1 year ago

Pythia is a flexible automation oracle capable of executing transactions at scheduled intervals, providing randomness, or delivering price feeds from Sybil. This guide will walk you through the process of creating a subscription using both the front-end application and Solidity.

Frontend Subscribe

For frontend subscription, follow these steps:

  1. Visit the Pythia application page at .

  2. Set up your own subscription by choosing the chain where your contract resides, specifying your contract address, and defining the method to be executed.

  3. Define the automation frequency, and if desired, add payload to execution transactions as randomness or price feed from Sybil.

  4. Authenticate with Self Identity Wallet Extension (SIWE), top up your execution wallet, and submit your subscription.

You can also create a subscription through Solidity using the contract. Here's the contract's interface:

interface IOrallyPythiaSubscriptionsRegistry {
    function subscribe(
        address target,
        string calldata method,
        uint256 frequency,
        bool is_random,
        string calldata pair_id
    ) external;

    function unsubscribe(uint256 subscription_id) external;
}

Subscription Usage Examples

Here are a few examples demonstrating how to use the Pythia subscription in different scenarios:

  1. Basic Execution: An example where the Pythia oracle executes a simple update to a value.

import {OrallyPythiaConsumer} from "../consumers/OrallyPythiaConsumer.sol";

contract PythiaExecutionExample is OrallyPythiaConsumer {
    uint256 public value;

    constructor(
        address _pythiaRegistry
    ) OrallyPythiaConsumer(_pythiaRegistry) {}

    function updateValue(uint256 _value) external onlyExecutor {
        value = _value;
    }
}
  1. Raffle: In this scenario, Pythia is used to randomly pick a raffle winner.

import {OrallyPythiaConsumer} from "../consumers/OrallyPythiaConsumer.sol";

contract RaffleExample is OrallyPythiaConsumer {
    uint256 maxNumberOfTickets;
    uint256 ticketPrice;
    address[] entries;

    constructor(
        address _pythiaRegistry,
        uint256 _maxNumberOfTickets,
        uint256 _ticketPrice
    ) OrallyPythiaConsumer(_pythiaRegistry) {
        maxNumberOfTickets = _maxNumberOfTickets;
        ticketPrice = _ticketPrice;
    }

    function enterRaffle() external payable {
        require(
            entries.length < maxNumberOfTickets,
            "RaffleExample: Raffle is full"
        );
        require(
            msg.value == ticketPrice,
            "RaffleExample: Ticket price is not correct"
        );
        entries.push(msg.sender);
    }

    function pickWinner(uint256 _randomNumber) external onlyExecutor {
        require(
            entries.length == maxNumberOfTickets,
            "RaffleExample: Raffle is not full"
        );
        uint256 winnerIndex = _randomNumber % entries.length;
        payable(entries[winnerIndex]).call{value: address(this).balance}("");
    }
}
  1. Price Feed: This example demonstrates how Pythia can be used to regularly update a price feed using data from Sybil.

import {OrallyPythiaConsumer} from "../consumers/OrallyPythiaConsumer.sol";

interface IFxPriceFeedExample {
    function pair() external view returns (string memory);

    function baseTokenAddr() external view returns (address);

    function decimalPlaces() external view returns (uint256);
}

contract FxPriceFeedExample is OrallyPythiaConsumer, IFxPriceFeedExample {
    uint256 public rate;
    uint256 public lastUpdate;
    string public pair;
    address public baseTokenAddr;
    uint256 public decimalPlaces;

    constructor(
        address _pythiaRegistry,
        string memory _pair,
        address _baseTokenAddr,
        uint256 _decimalPlaces
    ) OrallyPythiaConsumer(_pythiaRegistry) {
        pair = _pair;
        baseTokenAddr = _baseTokenAddr;
        decimalPlaces = _decimalPlaces;
    }

    function updateRate(
        string memory _pairId,
        uint256 _rate,
        uint256 _decimals,
        uint256 _timestamp
    ) external onlyExecutor {
        rate = (_rate * (10 ** decimalPlaces)) / (10 ** _decimals); // normalise rate
        lastUpdate = _timestamp;
    }

    function updateTime() external view returns (uint256) {
        return lastUpdate;
    }

    function exchangeRate() external view returns (uint256) {
        return rate;
    }
}

These examples should help you get started with using Pythia. With its robust features, Pythia offers great flexibility in automating transactions and retrieving real-time data, making it a vital tool for any decentralized application.

🎬
Pythia DApp
OrallyPythiaSubscriptionsRegistry