Skip to content

feat: #240 Contract: Implement TWAP for reliable oracle pricing#311

Open
Chinonso-Peter wants to merge 1 commit intoceejaylaboratory:mainfrom
Chinonso-Peter:main
Open

feat: #240 Contract: Implement TWAP for reliable oracle pricing#311
Chinonso-Peter wants to merge 1 commit intoceejaylaboratory:mainfrom
Chinonso-Peter:main

Conversation

@Chinonso-Peter
Copy link
Copy Markdown

Implemented #240 in src/oracle_consumer/lib.rs (line 1) and added .codex to .gitignore (line 28).

The oracle consumer now keeps a bounded per-asset observation history, computes a real time-weighted average price over a configurable lookback window, rejects stale data, and requires history that actually covers the requested TWAP window so a fresh flash-loan-distorted spot update can’t dominate the returned price. The default get_price(asset) path now returns TWAP instead of the latest spot price, and admin setters were added for the TWAP window, max price age, and retained observation count.

I also added unit tests covering initialization, spot updates, bounded history, full-window coverage requirements, and the key manipulation-resistance behavior where a late spike only slightly moves the reported price instead of replacing it.

Verification passed with an isolated crate test run:
cargo test --manifest-path /tmp/oracle_consumer_check/Cargo.toml

closes #240

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 27, 2026

@Chinonso-Peter Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Contract: Implement TWAP for reliable oracle pricing

1 participant