Skip to content

feat(stablecoin): add price feed interface#109

Open
3esmit wants to merge 6 commits into
mainfrom
issue-96-price-feed-interface
Open

feat(stablecoin): add price feed interface#109
3esmit wants to merge 6 commits into
mainfrom
issue-96-price-feed-interface

Conversation

@3esmit
Copy link
Copy Markdown
Collaborator

@3esmit 3esmit commented May 14, 2026

Closes #96

Summary

Adds the documented price-feed interface as a shared oracle surface and introduces a Mock Oracle Program that can write canonical price accounts for tests and development.
The mock oracle has no upstream oracle integration: it only materializes the supplied mocked price into the same account shape that consumers read.

This does not implement a TWAP oracle, RedStone adaptor, or stablecoin rate-update instruction.

What Changed

  • Added oracle_core with the canonical OraclePriceAccount fields:
    base_asset, quote_asset, price, timestamp, source_identifier, and
    confidence_interval.
  • Added the consumer-side PriceFeed interface, AccountPriceFeed,
    PriceFeedConfig, PriceFeedReading, PriceFeedError, and shared
    validate_price_account checks.
  • Re-exported the oracle price-feed surface from stablecoin_core so existing
    stablecoin consumers can use the interface without duplicating oracle types.
  • Added the mock_oracle program family with a set_price instruction that writes a supplied mock price into an authorized price account owned by the Mock Oracle Program.
  • Added artifacts/mock_oracle-idl.json and regenerated artifacts/stablecoin-idl.json.
  • Updated workspace manifests and guest locks for oracle_core and mock_oracle.
  • Updated two ATA integration tests to match the current ATA::Transfer instruction shape so the full integration test gate compiles.

Justification

Issue #96 requires a configurable feed interface that can read market prices from an external feed account, enforce a caller-selected freshness threshold, and return errors when the feed is unavailable, stale, or inconsistent with the expected asset pair.

Keeping the canonical account and consumer checks in oracle_core lets real oracle producers and mock feeds write the same account shape while each consuming program owns its validation policy. The Mock Oracle Program intentionally avoids any real oracle verification and only provides a controlled way to set prices through the public program interface.

Risks

  • Price scaling is intentionally not fixed here. Future controller code must document the chosen precision before using PriceFeedReading::price in financial math.
  • Timestamp units are consumer-owned: timestamp, current_timestamp, and max_age must use the same unit.
  • The mock oracle accepts caller-supplied prices by design and should not be treated as a production oracle source.

Validation

cargo +nightly fmt --all -- --check
taplo fmt --check .
git diff --check
cargo +1.94.0 build -p idl-gen --release
# full IDL drift loop from AGENTS.md
RISC0_SKIP_BUILD=1 cargo +1.94.0 clippy --workspace --all-targets -- -D warnings
RISC0_DEV_MODE=1 cargo +1.94.0 test --workspace --exclude integration_tests
RISC0_DEV_MODE=1 cargo +1.94.0 test -p integration_tests

Copilot AI review requested due to automatic review settings May 14, 2026 04:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a shared oracle/price-feed surface (oracle_core) and a development-only Mock Oracle program that can author canonical OraclePriceAccount data for tests and local development, then wires stablecoin consumers to use/re-export that shared interface.

Changes:

  • Introduces oracle_core with OraclePriceAccount, PriceFeed trait + helpers (AccountPriceFeed, validate_price_account, error/reading/config types).
  • Adds mock_oracle program family (core + program + RISC0 methods/guest) with a set_price instruction that writes canonical price accounts.
  • Updates workspace manifests/locks, regenerates IDLs, and adjusts ATA integration tests for the updated ATA::Transfer instruction shape.

Reviewed changes

Copilot reviewed 20 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
stablecoin/methods/guest/Cargo.toml Adds oracle_core dependency for the stablecoin guest build.
stablecoin/methods/guest/Cargo.lock Locks oracle_core into the stablecoin guest dependency graph.
stablecoin/core/src/lib.rs Removes local oracle types and re-exports the shared oracle_core price-feed surface.
stablecoin/core/Cargo.toml Adds oracle_core dependency to stablecoin core.
oracle/core/src/lib.rs New shared oracle account + consumer-side validation/reading interface and tests.
oracle/core/Cargo.toml New oracle_core crate manifest.
mock_oracle/src/tests.rs Unit tests for mock oracle set_price behavior and preconditions.
mock_oracle/src/set_price.rs Implements set_price to write OraclePriceAccount into an authorized account.
mock_oracle/src/lib.rs Mock oracle program crate root exporting core and instruction modules.
mock_oracle/methods/src/lib.rs Host-side embed of the mock oracle guest ELF via risc0_build.
mock_oracle/methods/guest/src/bin/mock_oracle.rs Guest entrypoint implementing the set_price instruction.
mock_oracle/methods/guest/Cargo.toml Guest crate manifest for building the mock oracle zkVM binary.
mock_oracle/methods/guest/Cargo.lock New guest lockfile for mock oracle guest dependencies.
mock_oracle/methods/Cargo.toml Host methods crate manifest for embedding guest artifacts.
mock_oracle/methods/build.rs Build script calling risc0_build::embed_methods().
mock_oracle/core/src/lib.rs Defines mock oracle instruction payloads (Instruction, PriceUpdate) and conversion into OraclePriceAccount.
mock_oracle/core/Cargo.toml New mock_oracle_core crate manifest.
mock_oracle/Cargo.toml New mock_oracle_program crate manifest.
integration_tests/tests/ata.rs Updates ATA tests to use ata_core::Instruction::Transfer { amount } shape.
Cargo.toml Adds new crates to the workspace and workspace deps; bumps workspace borsh to 1.5.
Cargo.lock Locks new workspace crates (oracle_core, mock_oracle_*, methods) and dependency updates.
artifacts/stablecoin-idl.json Regenerated stablecoin IDL reflecting shared oracle account type exposure.
artifacts/mock_oracle-idl.json New committed IDL for the mock oracle program.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread oracle/core/src/lib.rs Outdated
@3esmit 3esmit requested a review from Copilot May 14, 2026 04:58
@3esmit 3esmit requested a review from 0x-r4bbit May 14, 2026 05:01
@3esmit 3esmit self-assigned this May 14, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 26 changed files in this pull request and generated 1 comment.

Comment thread oracle/core/src/account.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 26 changed files in this pull request and generated 1 comment.

Comment thread mock_oracle/src/set_price.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 26 changed files in this pull request and generated no new comments.

3esmit added 6 commits May 18, 2026 13:23
Add shared oracle_core price-feed types and account-backed validation.

Wire stablecoin to re-export the shared oracle interface and add the mock_oracle program plus IDL artifact.

Update ATA integration tests for the current Transfer instruction shape.

Refs #96
Use borsh::object_length to reserve the exact serialized size for OraclePriceAccount data without relying on size_of_val.

Add coverage for string-backed source identifiers.
@3esmit 3esmit force-pushed the issue-96-price-feed-interface branch from ccf821a to fe8207c Compare May 18, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement price feed interface

2 participants