feat(twap-oracle): implement create_price_feed instruction#128
Open
0x-r4bbit wants to merge 1 commit into
Open
feat(twap-oracle): implement create_price_feed instruction#1280x-r4bbit wants to merge 1 commit into
0x-r4bbit wants to merge 1 commit into
Conversation
643adef to
0b97584
Compare
There was a problem hiding this comment.
Pull request overview
Implements TWAP oracle “price feed registration” by adding a CreatePriceFeed instruction that initializes a PriceObservations PDA for a given price source and records the initial tick + timestamp, replacing the prior no-op instruction.
Changes:
- Add
CreatePriceFeedinstruction intwap_oracle_coreplusPriceObservations/ObservationEntrydata model and PDA helpers. - Implement program-side
create_price_feedlogic and expose it via the guest method entrypoint. - Update dependencies, locks, and regenerated IDL artifacts accordingly.
Reviewed changes
Copilot reviewed 10 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| programs/twap_oracle/src/noop.rs | Removes the obsolete no-op instruction implementation. |
| programs/twap_oracle/src/lib.rs | Switches exported module from noop to create_price_feed. |
| programs/twap_oracle/src/create_price_feed.rs | Adds the instruction implementation and unit tests for initializing PriceObservations. |
| programs/twap_oracle/methods/guest/src/bin/twap_oracle.rs | Exposes the new create_price_feed instruction through the guest entrypoint. |
| programs/twap_oracle/methods/guest/Cargo.toml | Adds clock_core dependency for the guest build. |
| programs/twap_oracle/methods/guest/Cargo.lock | Locks clock_core and bumps transitive deps for the guest build. |
| programs/twap_oracle/core/src/lib.rs | Adds CreatePriceFeed, PriceObservations, ObservationEntry, capacity constant, and PDA derivation helpers. |
| programs/twap_oracle/core/Cargo.toml | Enables workspace lints and adds risc0-zkvm dependency used for PDA seed hashing. |
| programs/twap_oracle/Cargo.toml | Adds clock_core dependency and enables workspace lints for the program crate. |
| programs/token/methods/guest/Cargo.lock | Transitive dependency lockfile updates. |
| programs/stablecoin/methods/guest/Cargo.lock | Transitive dependency lockfile updates. |
| programs/ata/methods/guest/Cargo.lock | Transitive dependency lockfile updates. |
| programs/amm/methods/guest/Cargo.lock | Transitive dependency lockfile updates. |
| Cargo.lock | Workspace lockfile updates reflecting new/updated dependencies. |
| artifacts/twap_oracle-idl.json | Regenerated TWAP oracle IDL reflecting create_price_feed and new account/type definitions. |
| artifacts/stablecoin-idl.json | Regenerated stablecoin IDL reflecting newly visible types from twap_oracle_core. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0b97584 to
e36903f
Compare
Adds the CreatePriceObservations instruction to the TWAP oracle program. The instruction initialises a PriceObservations PDA for a given price source account and time window, writing the initial tick and timestamp as the first entry. Key design decisions: - Per-window accounts: each (price_source, window_duration) pair maps to a distinct PriceObservations PDA. The window duration is baked into the PDA seed so a single price source can support multiple TWAP windows (24h, 7d, 30d) at independent sampling rates without sharing a buffer. - window_duration not stored on struct: it is implicit in the PDA address. Any reader that located the account already knows the window duration used to derive it. Storing it would be redundant. - Authorization is implicit: the PriceObservations PDA is derived from the price source account ID, so is_authorized = true on the price source proves the caller controls it without a redundant authority field. - Impersonation is prevented by the PDA check: passing a controlled price source with a victim's observations account ID fails immediately because the computed PDA (from the attacker's source) does not match. Closes #126
e36903f to
c59316b
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.
Adds the CreatePriceObservations instruction to the TWAP oracle program.
The instruction initialises a PriceObservations PDA for a given price
source account and time window, writing the initial tick and timestamp
as the first entry.
Key design decisions:
Per-window accounts: each (price_source, window_duration) pair maps to
a distinct PriceObservations PDA. The window duration is baked into the
PDA seed so a single price source can support multiple TWAP windows
(24h, 7d, 30d) at independent sampling rates without sharing a buffer.
window_duration not stored on struct: it is implicit in the PDA address.
Any reader that located the account already knows the window duration
used to derive it. Storing it would be redundant.
Authorization is implicit: the PriceObservations PDA is derived from
the price source account ID, so is_authorized = true on the price source
proves the caller controls it without a redundant authority field.
Impersonation is prevented by the PDA check: passing a controlled price
source with a victim's observations account ID fails immediately because
the computed PDA (from the attacker's source) does not match.
Closes #126