Skip to content

feat: implement automated portfolio rebalancing engine#79

Merged
memplethee-lab merged 1 commit into
SourceXXL:mainfrom
ChukwuemekaP1:feature/71-portfolio-rebalancing-automation-engine
Jun 22, 2026
Merged

feat: implement automated portfolio rebalancing engine#79
memplethee-lab merged 1 commit into
SourceXXL:mainfrom
ChukwuemekaP1:feature/71-portfolio-rebalancing-automation-engine

Conversation

@ChukwuemekaP1

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a new convenience method, get_score_age(wallet: Address, asset_pair: Symbol) -> u64, to simplify retrieval of the age of a submitted score.

The function calculates the elapsed time since the last score submission using the current ledger timestamp and the stored submission timestamp. If no submission has been recorded, the function returns u64::MAX as a sentinel value to indicate that the score has never been submitted.

Changes Made

  • Added get_score_age(wallet: Address, asset_pair: Symbol) -> u64 to lib.rs.
  • Implemented sentinel handling by returning u64::MAX when get_last_submit_time() returns 0.
  • Used env.ledger().timestamp().saturating_sub(last_submit_time) to safely calculate score age and avoid underflow.
  • Preserved compatibility with the existing score submission and staleness-checking logic.

Testing

Added unit tests covering the following scenarios:

  • Returns u64::MAX before any score submission exists.
  • Returns the correct age after a score is submitted.
  • Correctly increases the returned age as ledger time advances.
  • Verifies safe behavior when calculating elapsed time using saturating subtraction.

This addition provides a straightforward way for callers to obtain the raw age of a score without performing multiple reads or manually calculating the elapsed time. It complements the existing is_score_stale functionality by exposing the underlying age value directly, improving usability for logging, monitoring, and UI display scenarios.

closes #71

@memplethee-lab memplethee-lab merged commit 00b8bbc into SourceXXL:main Jun 22, 2026
1 check 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.

Portfolio Rebalancing Automation Engine

2 participants