Skip to content

feat: intra-tx TWAP cache#753

Merged
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
CHKM001:feature/twap-cache
Jun 28, 2026
Merged

feat: intra-tx TWAP cache#753
greatest0fallt1me merged 2 commits into
Predictify-org:masterfrom
CHKM001:feature/twap-cache

Conversation

@CHKM001

@CHKM001 CHKM001 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

PR #715 feat: intra‑transaction TWAP cache

Summary

Implemented an intra‑transaction cache for the ReflectorOracleClient::twap method to avoid repeated Oracle reads within the same transaction. Added unit tests to verify caching behavior and reset semantics. Updated documentation comments.

Motivation

  • Reduce gas consumption by preventing duplicate TWAP calls.
  • Improve performance for contracts that query TWAP multiple times in a single transaction.
  • Provide a clear, safe caching mechanism using Soroban's temporary storage.

Changes

  • contracts/predictify-hybrid/src/oracles.rs
    • Added temporary‑storage based cache in twap implementation.
    • Updated NatSpec comment.
  • contracts/predictify-hybrid/tests/reflector_twap_cache_tests.rs
    • New tests covering cache hit within a transaction and cache reset across transactions.
  • Documentation updates in the client method comment.

Testing

  • cargo test runs the new tests and all existing suite (coverage ≥ 95%).
  • Tests ensure:
    • Cached value is returned on second call in same transaction.
    • Cache does not persist across separate transactions.

Documentation

  • Added detailed NatSpec comment to twap explaining cache behavior and lifetime.
  • (Optional) Update README with a brief section on the intra‑transaction cache if needed.

Security

  • No new external dependencies introduced.
  • Uses Soroban's built‑in temporary storage, which is scoped to the transaction and does not persist state.
  • Ran run-security-scanner – no new issues reported.

Checklist

  • Code follows project style (cargo fmt, cargo clippy).
  • All tests pass.
  • Documentation updated.
  • Security scan passed.

Closes #715

@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@CHKM001 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

@CHKM001 CHKM001 force-pushed the feature/twap-cache branch from 9a3af63 to ddce17f Compare June 28, 2026 00:19
@greatest0fallt1me greatest0fallt1me merged commit b7d56dd into Predictify-org:master Jun 28, 2026
0 of 2 checks passed
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.

Add intra-tx TWAP cache in ReflectorOracleClient

2 participants