GPT-5 finding
Insufficient balance check happens before trade-size cap in buy_shares, causing false “Insufficient balance” errors
mediumbughigh
- backend/wonderwall/simulations/polymarket/platform.py:128-138
- backend/wonderwall/simulations/polymarket/platform.py:156-161
The platform rejects trades when balance < requested amount, but the actual executed amount is later capped to min(requested, 2% of pool). A user with balance less than the requested amount but greater than the capped amount is incorrectly blocked.
Recommendation
Compute the effective amount before the balance check, e.g.: - Calculate pool_total and max_trade first. - effective_amount = min(float(requested), max_trade). - If balance < effective_amount, return insufficient balance; otherwise proceed using effective_amount for the trade and all bookkeeping.