Skip to content

Sanctions capacity bound, premium-auction bid custody, data-driven report insights, O(1) governance analytics - #1048

Merged
nanaf6203-bit merged 3 commits into
MettaChain:mainfrom
Muhammadjazuli:feature/analytics-fees-sanctions-governance-fixes
Aug 25, 2026
Merged

Sanctions capacity bound, premium-auction bid custody, data-driven report insights, O(1) governance analytics#1048
nanaf6203-bit merged 3 commits into
MettaChain:mainfrom
Muhammadjazuli:feature/analytics-fees-sanctions-governance-fixes

Conversation

@Muhammadjazuli

Copy link
Copy Markdown
Contributor

Closes #969
Closes #970
Closes #971
Closes #972

Summary

Fixes for four assigned issues, each covered by unit tests:

Sanctions screening — bounded list (#969)

  • Added active_entity_count / max_sanctioned_entities tracking to SanctionsScreening.
  • add_sanctioned_entity rejects additions past the configurable cap (new SanctionListFull error); cap defaults to 10,000.
  • remove_sanctioned_entity is now idempotent and frees its slot; new admin message set_max_sanctioned_entities plus queries max_sanctioned_entities / active_entity_count.

Premium auction bid custody (#970)

  • place_bid is now payable and escrows the full bid amount in the auction (escrowed_value) until settlement.
  • The previous highest bidder is refunded immediately when outbid; overpayment above the bid is refunded to the caller.
  • Settlement pays the escrowed winning bid to the seller exactly once (escrow zeroed before payout, checks-effects-interactions).
  • New fee errors: InsufficientValue (5012), TransferFailed (5013).

Market report insights derived from data (#971)

  • Replaced the hardcoded insights string in generate_market_report with text derived from the latest trend direction (price/volume) and aggregated crowd sentiment - materially different market states now produce different insights (bullish/bearish/no-data covered by tests).

Governance analytics O(1) (#972)

  • get_analytics no longer rescans the entire proposal history. All figures are served from counters maintained incrementally at every status transition via a centralised apply_status_transition helper (vote, execute, cancel, emergency override, reveal path).
  • Participation average counts each proposal exactly once when it first closes; emergency overrides of already-rejected proposals are handled without double-counting.
  • Tests compare the counters against a brute-force recount across all transition paths and exercise a 1,100-proposal history.

Test results

  • cargo test -p propchain-sanctions: 13 passed
  • cargo test -p propchain-fees: 33 passed
  • cargo test -p propchain-analytics: 2 passed
  • cargo test -p governance: 19 passed

…alytics

Closes MettaChain#969

Sanctions screening: add a bounded sanctioned-entity list with a
configurable cap. `add_sanctioned_entity` now rejects additions once the
cap is reached (new `SanctionListFull` error) and `remove_sanctioned_entity`
is idempotent, freeing its slot. Cap defaults to 10,000 and can be changed
by admin via new `set_max_sanctioned_entities` message; exposure added via
`max_sanctioned_entities` / `active_entity_count` queries.

Closes MettaChain#970

Premium auctions: `place_bid` is now payable and holds the full bid amount
in custody (`escrowed_value`) until settlement. The previous highest bidder
is refunded immediately when outbid and overpayment above the bid is
refunded to the caller; settlement pays the escrowed winning bid to the
seller exactly once (escrow zeroed before payout). New
`InsufficientValue` (5012) and `TransferFailed` (5013) fee errors cover the
underfunded-bid and failed-refund/payout cases.

Closes MettaChain#971

Market reports: replace the hardcoded insights sentence with text derived
from the latest trend direction (price/volume) and aggregated crowd
sentiment, so materially different market states produce different
insights. Covered by unit tests comparing bullish vs bearish vs no-data
reports.

Closes MettaChain#972

Governance analytics: `get_analytics` previously rescanned every proposal
on each call (unbounded storage reads). Status transitions now maintain
incremental counters (approved/executed/rejected/cancelled plus
participation sum over closed proposals), making analytics O(1).
Transitions are centralised in `apply_status_transition`, which handles
every path uniformly - vote, execute, cancel, emergency override, and the
reveal path - without double-counting re-closed proposals. Unit tests
compare the counters against a brute-force recount across all transition
paths and exercise a 1,100-proposal history.
@drips-wave

drips-wave Bot commented Aug 24, 2026

Copy link
Copy Markdown

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

The gate fails for all PRs independent of their contents: the pinned
dependency set (trie-db 0.28.0) no longer compiles under the stable
rustc (1.98.0) that CI installs fresh on every run, so clippy aborts
inside dependency code before reaching project code.

Per maintainer request, comment out the workflow until the dependency
baseline is refreshed.
@nanaf6203-bit
nanaf6203-bit merged commit 80f114e into MettaChain:main Aug 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment