Price Feed
Oracle-style price feed with staleness detection
Deployed
Anchor 0.32
Program ID
6uafjLqqMeP4DgYqDuVPCL9BVabC7ruQC6SnDdUvXqC5
Repository
ExpertVagabond/solana-price-feed
Binary Size
215K
Cluster
Devnet
Instructions
IX
initialize_feed
Creates a new price feed for a trading pair with the specified decimal precision.
| Parameter | Type | Description |
|---|---|---|
symbol | String | Trading pair symbol, e.g. "SOL/USD" (max 16 characters) |
decimals | u8 | Number of decimal places for the price value |
IX
update_price
Publishes a new price update with a confidence interval. Only callable by the authority.
| Parameter | Type | Description |
|---|---|---|
price | i64 | Current price value (signed to support negative rates) |
confidence | u64 | Confidence interval around the price |
IX
read_price
Reads the current price from the feed. Returns an error if the price data is stale.
| Parameter | Type | Description |
|---|---|---|
| No parameters | ||
IX
transfer_authority
Transfers the price update authority to a new wallet.
| Parameter | Type | Description |
|---|---|---|
new_authority | Pubkey | The new authority wallet address |
Accounts
PriceFeed
| Field | Type | Description |
|---|---|---|
authority | Pubkey | Oracle operator with update permissions |
symbol | String | Trading pair symbol (e.g. "SOL/USD") |
decimals | u8 | Price decimal precision |
price | i64 | Latest price value |
confidence | u64 | Confidence interval width |
last_update | i64 | Timestamp of the last price update |
update_count | u64 | Total number of price updates |
bump | u8 | PDA bump seed |
PDA Derivation
feed
seeds = [b"feed", authority]
Error Codes
SymbolTooLong
Feed symbol exceeds the maximum 16 character limit
StalePrice
The price data has not been updated recently enough to be reliable
Overflow
Arithmetic overflow in price calculation
Usage Example
import { Program, BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; // Initialize a SOL/USD price feed with 8 decimal places const [feedPda] = PublicKey.findProgramAddressSync( [Buffer.from("feed"), authority.publicKey.toBuffer()], program.programId ); await program.methods .initializeFeed("SOL/USD", 8) .accounts({ feed: feedPda, authority: authority.publicKey, }) .signers([authority]) .rpc(); // Publish a price update: $145.50 with $0.25 confidence await program.methods .updatePrice( new BN(14_550_000_000), // price: $145.50 (8 decimals) new BN(25_000_000) // confidence: $0.25 ) .accounts({ feed: feedPda, authority: authority.publicKey, }) .signers([authority]) .rpc(); // Read the current price const feedData = await program.account.priceFeed.fetch(feedPda); console.log(`Price: ${feedData.price.toNumber() / 1e8}`); console.log(`Confidence: +/- ${feedData.confidence.toNumber() / 1e8}`);