> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pragma.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> Dive into our on-chain design

<Card title="Smart Contract Design" icon="cubes">
  An overview of the contract structure that makes Pragma secure, robust, and easy to integrate
</Card>

## Contract Structure

The V1 of the Pragma Oracle consists of three smart contracts, that each play a role in making the oracle easy to use and robust.

<Frame>
  <img width="100%" height="100%" src="https://mintcdn.com/pragma-a70dd633/10WsAM0SCV2mMOnM/images/flowchart/Flowchart-2.webp?fit=max&auto=format&n=10WsAM0SCV2mMOnM&q=85&s=9d413c711767713fa2c150d546e17f40" alt="Pragma contract architecture flowchart" data-path="images/flowchart/Flowchart-2.webp" />
</Frame>

<CardGroup cols={3}>
  <Card title="Publisher Registry" icon="address-book">
    The most static component, designed to be updated extremely infrequently because its state should be permanent (each publisher and their address). Currently an ownable contract but will become permissionless as Pragma decentralizes.
  </Card>

  <Card title="Oracle Proxy" icon="shuffle">
    A proxy contract that coordinates the Publisher Registry and the Oracle implementation(s). This is the contract which protocols interact with directly.
  </Card>

  <Card title="Oracle Implementation" icon="gears">
    Contains the logic for storing and aggregating specific key/value data streams. Designed to be updated only as frequently as absolutely necessary.
  </Card>
</CardGroup>

## Aggregation Mechanism

<Frame>
  <img width="100%" height="100%" src="https://mintcdn.com/pragma-a70dd633/10WsAM0SCV2mMOnM/images/flowchart/publishers.webp?fit=max&auto=format&n=10WsAM0SCV2mMOnM&q=85&s=99a5853c0eb5b490b95f14488aecb1db" alt="Publisher aggregation flowchart" data-path="images/flowchart/publishers.webp" />
</Frame>

Our system incorporates multiple publishers, each responsible for providing data from various sources. To determine the price for a given source, we consider the prices submitted by all these publishers. Our approach involves conducting an initial on-chain aggregation based on the median of these prices. This median value then becomes the established price for that particular source.

<Steps>
  <Step title="Data Collection">
    Multiple publishers submit data from various sources to the Oracle
  </Step>

  <Step title="Initial Aggregation">
    For each source, a median price is calculated from publisher-submitted values
  </Step>

  <Step title="Final Aggregation">
    When consuming data, users can select their preferred method to aggregate across sources
  </Step>
</Steps>

This aggregation process is triggered when one of the aggregation functions, as outlined in the [Consuming Data](/starknet/development) section, is called. During this process, users have the flexibility to choose their preferred method of aggregation for the sources. This choice allows them to tailor the final price calculation according to their specific needs or criteria. By utilizing this method of aggregation, we enhance the security of the final price determination, making it less vulnerable to manipulation, as it incorporates a broad and balanced range of data from multiple publishers.

## Security Measures

<CardGroup cols={2}>
  <Card title="Peer Reviews" icon="users">
    Our contracts have thoroughly been peer-reviewed by multiple actors in the Starknet ecosystem
  </Card>

  <Card title="Professional Audit" icon="shield-check">
    Complete audit by Nethermind, with the report available <a href="https://github.com/NethermindEth/PublicAuditReports/blob/2b073f2c136cc4e8afe2e135c1be03699b2a7515/NM0147-FINAL_PRAGMA.pdf">here</a>
  </Card>

  <Card title="Bug Bounty" icon="bug">
    Active bug bounty program through <a href="https://immunefi.com/bug-bounty/pragmaoracle/information/">ImmuneFi</a>
  </Card>

  <Card title="Direct Contact" icon="envelope">
    Direct communication channel at <a href="mailto:matthias@pragma.build">[matthias@pragma.build](mailto:matthias@pragma.build)</a>
  </Card>
</CardGroup>

## Explore the Data

<Card title="Interactive Explorer" icon="chart-line">
  We have a fully-fledged explorer available on our <a href="https://www.pragma.build/assets">website</a>.
  There you can explore what's happening on and off-chain, who is providing data, and more.
  If there is any other information you would like to see displayed, let us know!
</Card>

## Deployed Contracts

<Tabs>
  <Tab title="Mainnet">
    <table>
      <thead>
        <tr>
          <th>Contract</th>
          <th>Address</th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td>Publisher Registry</td>
          <td><a href="https://voyager.online/contract/0x24a55b928496ef83468fdb9a5430fe031ac386b8f62f5c2eb7dd20ef7237415">0x24a55b928496ef83468fdb9a5430fe031ac386b8f62f5c2eb7dd20ef7237415</a></td>
        </tr>

        <tr>
          <td>Oracle</td>
          <td><a href="https://voyager.online/contract/0x2a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b">0x2a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b</a></td>
        </tr>
      </tbody>
    </table>
  </Tab>

  <Tab title="Sepolia">
    <table>
      <thead>
        <tr>
          <th>Contract</th>
          <th>Address</th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td>Publisher Registry</td>
          <td><a href="https://sepolia.voyager.online/contract/0x1b08e27ab436cd491631156da5f3aa7ff04aee1e6ca925eb2ca84397c22b74d">0x1b08e27ab436cd491631156da5f3aa7ff04aee1e6ca925eb2ca84397c22b74d</a></td>
        </tr>

        <tr>
          <td>Oracle</td>
          <td><a href="https://sepolia.voyager.online/contract/0x36031daa264c24520b11d93af622c848b2499b66b41d611bac95e13cfca131a">0x36031daa264c24520b11d93af622c848b2499b66b41d611bac95e13cfca131a</a></td>
        </tr>
      </tbody>
    </table>
  </Tab>
</Tabs>
