Skip to content

Advanced Payout & Reward Distribution system #1

@hman38705

Description

@hman38705

Description

Developer Goal: Enable users to claim their share of the prize pool after a market is resolved.

Technical Prerequisites:

  • Familiarity with sac-token (Stellar Asset Contract) interface.
  • Understanding of integer division precision in Rust.

Detailed Requirements:

  1. Authority: The claim_winnings function must require the bettor's signature (bettor.require_auth()).
  2. Market Validation: Market must be in Resolved state. Errors: ErrorCode::MarketNotFound, ErrorCode::MarketStillActive.
  3. No Double Claim: Once claimed, the specific bet record must be deleted or marked as claimed.
  4. Math:
    • Payout = (UserBetAmount * NetPrizePool) / WinningOutcomeTotalStaked.
    • NetPrizePool = TotalMarketStaked - (TotalMarketStaked * BaseFee / 10000).

Implementation Guide:

// 1. Get Market and check status
// 2. Fetch Bet using DataKey::Bet(market_id, bettor)
// 3. Calculate Fee using modules::fees::calculate_fee
// 4. Calculate Payout using fixed-point math: 
//    (bet.amount * net_pool) / market.outcome_total_staked[bet.outcome]
// 5. client.transfer(e.current_contract_address(), bettor, payout_amount)
// 6. e.storage().persistent().remove(&bet_key)

Security Guardrails:

  • Reentrancy: Perform all storage deletions before calling the token transfer.
  • Division by Zero: Handle cases where WinningOutcomeTotalStaked is 0 (though technically impossible if a bet exists).
  • Rounding: Always round down for payouts to ensure the contract never tries to send more than it has.

Verification Checklist:

  • Function claim_winnings implemented in bets.rs.
  • Integration test simulates 3 winners with different amounts claiming correctly.
  • Attempting to claim twice results in an error.
  • git checkout -b features/issue-1-advanced-payout-rewards
  • Pr Request create your pr against develop branch

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions