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:
- Authority: The
claim_winnings function must require the bettor's signature (bettor.require_auth()).
- Market Validation: Market must be in
Resolved state. Errors: ErrorCode::MarketNotFound, ErrorCode::MarketStillActive.
- No Double Claim: Once claimed, the specific bet record must be deleted or marked as claimed.
- 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:
Description
Developer Goal: Enable users to claim their share of the prize pool after a market is resolved.
Technical Prerequisites:
sac-token(Stellar Asset Contract) interface.Detailed Requirements:
claim_winningsfunction must require the bettor's signature (bettor.require_auth()).Resolvedstate. Errors:ErrorCode::MarketNotFound,ErrorCode::MarketStillActive.Payout = (UserBetAmount * NetPrizePool) / WinningOutcomeTotalStaked.NetPrizePool = TotalMarketStaked - (TotalMarketStaked * BaseFee / 10000).Implementation Guide:
Security Guardrails:
transfer.WinningOutcomeTotalStakedis 0 (though technically impossible if a bet exists).Verification Checklist:
claim_winningsimplemented inbets.rs.git checkout -b features/issue-1-advanced-payout-rewardsdevelopbranch