Skip to content

feat(fractional): fractional ownership analytics / performance metrics (#273)#407

Merged
LaGodxy merged 2 commits into
MettaChain:mainfrom
omonxooo-commits:feature/273-fractional-analytics
Apr 29, 2026
Merged

feat(fractional): fractional ownership analytics / performance metrics (#273)#407
LaGodxy merged 2 commits into
MettaChain:mainfrom
omonxooo-commits:feature/273-fractional-analytics

Conversation

@omonxooo-commits

Copy link
Copy Markdown
Contributor

Summary

Closes #273

Tracks per-token performance metrics directly inside the fractional ownership contract, where the authoritative share data lives.

Changes

New type

  • FractionalMetricstrade_count, total_volume, unique_holders, all_time_high_price, all_time_low_price

New storage

  • token_metrics: Mapping<u64, FractionalMetrics> — one record per property token
  • is_holder: Mapping<(AccountId, u64), bool> — tracks whether an account currently holds shares, used to maintain an accurate unique_holders count without iterating

New message

  • get_metrics(token_id) -> FractionalMetrics — read-only query; returns zero-valued struct for unknown tokens

Private helpers

  • record_trade(token_id, volume, price_per_share) — increments trade_count, adds to total_volume, updates ATH/ATL
  • update_holder(account, token_id, new_balance) — adjusts unique_holders only when an account crosses the zero-balance boundary

Hooks added to existing messages

Message What is recorded
mint_shares update_holder on recipient
buy_shares record_trade (volume + price) + update_holder on seller and buyer
redeem_shares record_trade (payout + last price) + update_holder on redeemer

Tests

6 new #[ink::test] cases:

  • Default metrics are all zero for unknown token
  • mint_shares increments unique_holders (no double-count for same account)
  • redeem_shares (all shares) decrements unique_holders to 0
  • redeem_shares records trade_count and total_volume
  • ATH/ATL price tracking across multiple trades
  • Cumulative volume accumulates correctly across trades

- Add FractionalMetrics struct (trade_count, total_volume, unique_holders,
  all_time_high_price, all_time_low_price)
- Add token_metrics and is_holder storage mappings
- Add get_metrics query message
- Add record_trade private helper: increments trade_count, total_volume, ATH/ATL
- Add update_holder private helper: tracks unique_holders via is_holder bitmap
- Hook record_trade + update_holder into buy_shares, redeem_shares, mint_shares
- Add 6 unit tests covering all analytics paths
@drips-wave

drips-wave Bot commented Apr 29, 2026

Copy link
Copy Markdown

@omonxooo-commits 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

@LaGodxy LaGodxy merged commit 604309e into MettaChain:main Apr 29, 2026
9 of 11 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.

Fractional Ownership: Add fractional ownership analytics

2 participants