Skip to content

refac: Implement Per Asset Timestamp Tracking#42

Open
Olowodarey wants to merge 2 commits intoNeko-Protocol:devfrom
Olowodarey:rwacon
Open

refac: Implement Per Asset Timestamp Tracking#42
Olowodarey wants to merge 2 commits intoNeko-Protocol:devfrom
Olowodarey:rwacon

Conversation

@Olowodarey
Copy link

This PR fixes a design issue in the RWA Oracle where a single global last_timestamp was used to validate price updates for all assets.

Because different assets can have independent update frequencies and timelines (e.g. stocks vs crypto, different data providers), a global timestamp caused valid updates to be incorrectly rejected.

This change introduces per-asset timestamp tracking while preserving the global timestamp for SEP-40 compatibility.


Problem

Previously:

  • last_timestamp was stored globally in RWAOracleStorage

  • Updating one asset advanced the timestamp for all assets

  • This caused:

    • First-time updates on other assets to fail
    • Assets with slower update cadences to be blocked
    • Incorrect enforcement of C-02 timestamp validation

Example:

  • Update AAPL at t = 1000
  • Update TSLA at t = 500 → incorrectly rejected

Solution

This PR introduces per-asset timestamp validation:

  • Added DataKey::LastTimestamp(Asset) to store timestamps per asset
  • Timestamp validation (C-02) now checks the asset’s own last timestamp
  • Global last_timestamp is still updated for backward compatibility (SEP-40)
  • Assets can update independently without interfering with each other

Implementation Details

New Storage Key

DataKey::LastTimestamp(Asset)

Updated Logic

  • set_asset_price_internal now:

    • Validates timestamps per asset
    • Stores per-asset timestamps in persistent storage
    • Continues updating global last_timestamp for SEP-40 compatibility

Tests Added

A total of 10 unit tests now cover all required scenarios.

Existing / Core Per-Asset Timestamp Tests

  • test_per_asset_timestamps_independent
  • test_same_asset_requires_newer_timestamp
  • test_same_asset_same_timestamp_rejected
  • test_same_asset_newer_timestamp_accepted
  • test_global_timestamp_still_updated

Additional Coverage & Compatibility Tests

  • test_independent_timestamps_for_different_assets
  • test_updating_asset_with_older_timestamp_than_another_asset
  • test_per_asset_timestamp_retrieval
  • test_global_timestamp_still_updates
  • test_backward_compatibility_with_sep40

All existing tests continue to pass.


Verification

image

closes #31

@vercel
Copy link

vercel bot commented Jan 31, 2026

@Olowodarey is attempting to deploy a commit to the fabianalejandrosanchezduran-gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

@aguilar1x
Copy link
Contributor

@Olowodarey

This issue depends on #25, please wait until I finish merging that milestone so you can validate your PR.

@aguilar1x
Copy link
Contributor

@Olowodarey

Pr #25 merge, you can now continue with your issue.

- Changed test_same_asset_requires_newer_timestamp to expect panic
- Changed test_same_asset_same_timestamp_rejected to expect panic
- Both tests now correctly validate that timestamps must be strictly increasing per asset
- All 29 tests passing
@Olowodarey
Copy link
Author

@aguilar1x check now

@aguilar1x
Copy link
Contributor

@aguilar1x check now

Can you fix the conflicts in your branch?

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.

[refactor] Implement Per-Asset Timestamp Tracking

2 participants

Comments