Skip to main content
The Oracle-Priced Purchase example sells a USD-priced item for SOL using a Pyth PriceUpdateV2 price account. It is a focused starting point for any protocol instruction whose amount depends on a live market price.
The example reads the price as Account<'info, PriceUpdateV2>, and its tests use Pyth receiver fixtures. MagicBlock real-time feeds are owned by the pricing oracle program and have a different discriminator, so this account type rejects them (Anchor error 3007). To use a MagicBlock feed, decode it with try_deserialize_unchecked, check the account key and owner, and take the exponent from the feed list, as shown in Oracle Implementation. If you only change the decoding, the example uses the feed’s +8 exponent field and charges 1 lamport for a $1.00 item.

View Repository

Build and test the Anchor example against local oracle fixtures.

Prediction & Trading Architecture

Apply the pricing pattern to positions, collateral, liquidation, and settlement.

What the example demonstrates

  • binding program configuration to an expected oracle feed ID;
  • rejecting prices that are not fully verified, not positive, or older than 60 seconds. The positive-price check matters: a new MagicBlock feed starts as fully verified with a price of 0;
  • converting a USD-denominated amount into lamports;
  • enforcing a buyer-provided maximum to protect against price movement.

Oracle Overview

Understand MagicBlock’s low-latency pricing feeds.

Oracle Implementation

Read and validate pricing accounts in your program.