Skip to content

feat: implement market comment API with pagination, thumbs-up, and ad…#644

Merged
Hahfyeex merged 2 commits intoHahfyeex:Defaultfrom
Grace-CODE-D:feat/market-comment-api
Mar 30, 2026
Merged

feat: implement market comment API with pagination, thumbs-up, and ad…#644
Hahfyeex merged 2 commits intoHahfyeex:Defaultfrom
Grace-CODE-D:feat/market-comment-api

Conversation

@Grace-CODE-D
Copy link
Copy Markdown
Contributor

…min moderation

Automated Market Settlement Logic (#11)

Description

Implements the automated market settlement logic that processes an Oracle's "Result" and calculates winning shares with precise fixed-point arithmetic.

Changes

New Files

Modified Files

Key Features

Fixed-Point Arithmetic

  • Uses 7 decimal places of precision (10^7) for calculations
  • No floating-point operations to avoid precision loss
  • All monetary values stored as integers

Payout Formula

payout_pool = floor(total_pool × 97 / 100)  // 3% platform fee
individual_payout = floor(bet_amount × payout_pool / winning_stake)

Dust Handling

The implementation ensures 100% conservation by redistributing dust (remainder from integer division):

  1. Calculate ideal payouts using integer division
  2. Track dust: dust = payout_pool - sum(payouts)
  3. Redistribute dust in 1-unit increments to first N winners

Market State Transition

  • resolve_market() transitions market from Locked → Resolved
  • distribute_rewards() executes payout calculation and transfers

Testing

All 15 tests passing:

  • test_platform_fee - 3% fee calculation
  • test_payout_pool - 97% payout pool calculation
  • test_basic_payout - Single and multiple bettor scenarios
  • test_exact_division - Cases with no dust
  • test_dust_redistribution - Dust handling verification
  • test_zero_winning_stake - Edge case handling
  • test_large_amounts - Real XLM amount simulation
  • test_conservation_property - All payouts sum to payout_pool

Documentation

See docs/math_spec.md for:

  • Payout formula derivation
  • Dust handling algorithm explanation
  • Conservation property proof
  • Edge case handling
  • Security considerations

Related Issues

Closes #635

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@Grace-CODE-D 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

@Hahfyeex Hahfyeex merged commit 02f6cb9 into Hahfyeex:Default Mar 30, 2026
3 of 5 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.

[BE] Implement Market Comment API with Moderation

2 participants