Skip to content

astraly-labs/pragma-oracle

Repository files navigation

Pragma

Pragma, Starknet's native provable oracle.

What's Pragma ?

Pragma is a decentralized oracle built natively on Starknet. It leverages cairo to make data feeds computation fully trustless.

  • Pragma is built from the ground up to remove any trust assumptions in current oracles' design. There isn't any off-chain infrastructure, raw-data is directly pushed on-chain by whitelisted data providers. Then the aggregation happens at the smart contract level.
  • Pragma offers a top-notch developer experience, reviewed by key actors of DeFi on Starknet. The goal is to make the life of DeFi protocols as easy as possible.

Overview

  • Account contract mostly use for testing purposes and as a reference.
  • Ownable contract used for access control.
  • Entry & Data Structures defines data structures used within the protocol along with generic aggregations methods. It is designed from the ground up to ensure that adding new entry types is done seamlessly without involving any breaking changes.
  • Operations defines a few utilities libraries (time series, sorting, bits manipulation) that will be used for different aggregation methods and optimizing storage operations.
  • Oracle is the main entrypoint of the protocol. It is the contract that end developers will interact with to fetch any kind of data. It's been thought and built for retro-compatibility and heavily leverages unique aspects of Cairo, notably enums, traits and generics.
  • Publisher Registry handles the registration of different publishers along with the sources they are allowed to push data from.
  • Summary Stats acts as a proxy contract for more sophisticated kind of data aggregation such as volatility and mean.
  • Randomness is the VRF requestor implementation, also includes an example on how to request random words.

Testing

  • Test suite, unit tests are provided under the functions' implementations directly whereas full flow integration tests lie within this test suite. It uses cairo-test for now and test thoroughly for any edge case.

A few key testing features are missing such as fuzzing and proper hooks, mocking cheatcodes. This will come as cairo tooling matures and improves.

Documentation

More extensive documentation can be found on our official website.

Audit

Pragma Starknet has been peer-reviewed by many other key-projects in the industries. It has also been audited by Nethermind, you can find the full report under the audits folder.

Deployment addresses

This repo will gradually replace the previous Pragma implementation in Cairo 0 which you can find here.

Starknet Sepolia

Starknet Mainnet

Pragma Devnet

Local Deployment

Prerequisites:

  1. Compile contracts
cd pragma-oracle
scarb build
  1. Install dependencies
cd ../pragma-deployer
python -m venv .venv && source .venv/bin/activate
poetry install
  1. Setup env file
# Make sure you are in the pragma-deployer folder
cp .env.example .env

Populate the variables depending on where you wish to deploy.

  1. Deploy contracts & setup

Make sure your local devnet is running, see latest instructions here.

You can also specify a different network by setting STARKNET_NETWORK to a different value e.g sepolia, mainnet or pragma_devnet.

STARKNET_NETWORK=devnet poetry run deploy-pragma --port [DEVNET_PORT]
STARKNET_NETWORK=devnet poetry run deploy-summary-stats --port [DEVNET_PORT]
STARKNET_NETWORK=devnet poetry run register-publishers --port [DEVNET_PORT]

Once the contracts are declared/deployed you'll find them under the deployments/ folder at the root of the repo.

Questions and feedback

For any question or feedback you can send an email to matthias@pragma.build

License

The code is under the MIT LICENSE, see LICENSE.