# 🔮 Oracle system

### The Role of Oracle in Perpetual3

Perpetual3's Oracle system operates by having its identity encoded within the smart contract's global state. This identity is represented by an Ed25519 public key. This public key serves as a unique identifier for the Oracle and is used for verifying the Oracle data used in transactions.

The Oracle data, along with the corresponding signature, is provided by the user during the transaction. The smart contract uses this data and signature to verify the authenticity of the Oracle's information. This is done by checking the signature against the Oracle public key stored in the smart contract.

### Data Generation Process

The Oracle data generation process starts with the Oracle accepting key transaction parameters like fiat price, fiat currency (e.g., USD, EUR). Furthermore, it also requires the payment type, which could be a Layer 1 token such as ALGO or ETH, or any other fungible token like USDC or USDT.

Upon receipt of these parameters, the Oracle generates the necessary data as follows:

1. **Price Conversion**: The Oracle leverages APIs like Coin gecko to convert the provided fiat price into its equivalent cryptocurrency value. This step ensures that the payment reflects the current market rate of the chosen cryptocurrency against the provided fiat currency.
2. **Data Signing**: After the price conversion, the Oracle appends the round number in which the conversion was made and signs this data using its private key. The signature ensures the integrity of the data and allows for its verification at a later stage by the smart contract.

Here is a simplified representation of this process:

1. User provides: Fiat price, Fiat currency, Payment type.
2. Oracle converts Fiat price into equivalent cryptocurrency value and adds the round number in which the conversion was made.
3. Oracle signs the generated data and send back to the customer that later submit this data to the smart contract.

{% hint style="info" %}
We chose to build our own oracle system because we need access to various price feeds of a lot of cryptocurrencies that are not usually supported by other oracles and may require a lot of time to be integrated.
{% endhint %}

{% hint style="info" %}
While the current Oracle system operates centrally, we are actively working on a roadmap towards a more decentralized architecture. This progression will include leveraging distributed Oracle networks and decentralized price feeds, to ensure robustness and maintain security, while enhancing transparency and trust in the system. Stay tuned for updates on our ongoing development and innovations.
{% endhint %}

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://perpetualweb3.gitbook.io/perpetual3-web3-commerce/web3-merchants/oracle-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
