feat(stablecoin): add price feed interface#109
Open
3esmit wants to merge 6 commits into
Open
Conversation
There was a problem hiding this comment.
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_corewithOraclePriceAccount,PriceFeedtrait + helpers (AccountPriceFeed,validate_price_account, error/reading/config types). - Adds
mock_oracleprogram family (core + program + RISC0 methods/guest) with aset_priceinstruction that writes canonical price accounts. - Updates workspace manifests/locks, regenerates IDLs, and adjusts ATA integration tests for the updated
ATA::Transferinstruction 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.
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.
ccf821a to
fe8207c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
oracle_corewith the canonicalOraclePriceAccountfields:base_asset,quote_asset,price,timestamp,source_identifier, andconfidence_interval.PriceFeedinterface,AccountPriceFeed,PriceFeedConfig,PriceFeedReading,PriceFeedError, and sharedvalidate_price_accountchecks.stablecoin_coreso existingstablecoin consumers can use the interface without duplicating oracle types.
mock_oracleprogram family with aset_priceinstruction that writes a supplied mock price into an authorized price account owned by the Mock Oracle Program.artifacts/mock_oracle-idl.jsonand regeneratedartifacts/stablecoin-idl.json.oracle_coreandmock_oracle.ATA::Transferinstruction 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_corelets 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
PriceFeedReading::pricein financial math.timestamp,current_timestamp, andmax_agemust use the same unit.Validation