Skip to content

Comments

Prediction market trade modal with mint / swap / merge / redeem functionality#13435

Open
mzparacha wants to merge 13 commits intomasterfrom
feature/prediction-market-trade-modal
Open

Prediction market trade modal with mint / swap / merge / redeem functionality#13435
mzparacha wants to merge 13 commits intomasterfrom
feature/prediction-market-trade-modal

Conversation

@mzparacha
Copy link
Contributor

@mzparacha mzparacha commented Feb 23, 2026

Link to Issue

Closes: #13375

Description of Changes

Screen.Recording.2026-02-24.at.11.49.22.PM.mov

Summary

Implements the Prediction Market Trade Modal for minting, swapping, merging, and redeeming PASS/FAIL outcome tokens, aligned with the Futarchy protocol contracts (BinaryVault, FutarchyRouter, UniswapV3Strategy) and the reference logic in app.js / FutarchyGovernor.

Contract integration (predictionMarketTrade.ts)

  • Mint: Approve collateral to vault → vault.mint(marketId, amount, collateralAddress).
  • Swap: router.getStrategy(marketId) → approve sell token (PASS or FAIL) to strategystrategy.executeSwap(buyPass, amountIn, minOut). Correct token selection: sell FAIL when buying PASS, sell PASS when buying FAIL.
  • Merge: Approve both PASS and FAIL to vault → vault.merge(marketId, amount).
  • Redeem: Approve winning token to vault → vault.redeem(marketId, amount) (after market is resolved).
  • Helpers: getPredictionMarketBalancesFromChain, getCollateralBalanceAndSymbol, getVaultCollateralBalance, parseTokenAmount, applySlippage, formatTokenDisplay (used in UI).

Modal UI (PredictionMarketTradeModal.tsx + SCSS)

  • Header: Title, market prompt, collateral row (symbol, your balance, total minted, market end time).
  • Collapsible details: Click-to-expand section with copyable addresses: Vault, Collateral, Router, PASS token, FAIL token, Strategy, Governor (when present), and “Balances for” (wallet). Each row has a copy button; section has a clear border.
  • PASS/FAIL balance cards: Display balances (from API or on-chain fallback), with short token address (e.g. 0x6A76…43eA) and copy button on the same line as “PASS BALANCE” / “FAIL BALANCE”; compact styling.
  • Tabs: Mint, Swap, Merge, Redeem. Redeem is always clickable; when market is not resolved, in-tab message explains that redemption is available after resolution.
  • Mint tab: Amount input, collateral symbol and balance (ERC20 e.g. WETH/USDC), “Available” and MAX using collateral balance; info banner (equal PASS + FAIL received). No protocol-fee summary (contract does not charge a fee).
  • Swap tab: “You Sell” / “You Buy” panels with balances and amount; direction toggle; slippage presets (Auto, 0.5%, 1%, 2%, 5%, No min) and custom; “Min. Received” summary. Uses collateral decimals for PASS/FAIL amounts (fixes USDC 6-decimal display). Banner when sell balance is 0 (mint first).
  • Merge tab: Amount to merge, “Available” (min of PASS/FAIL), MAX; summary: tokens to burn, 1:1 collateral, “Collateral to be returned” with correct symbol. Uses collateral decimals.
  • Redeem tab: Amount input when market is resolved; winning token and max redeem; summary.
  • Footer: Cancel + context-specific primary action (Deposit and Mint / Swap / Merge / Redeem). Buttons disabled when amount invalid or exceeds balance (with correct decimals).

Balance and decimals handling

  • PASS/FAIL and collateral use collateral token decimals (e.g. 6 for USDC, 18 for WETH) for parsing and display so “Total minted” and balances show correctly.
  • When API has no position, PASS/FAIL balances are fetched on-chain and refetched after mint/swap/merge.

Thread card (ThreadPredictionMarketCard.tsx)

  • Shows collateral symbol and user balance, total minted (formatted with correct decimals), and opens the trade modal.

Other

  • Market type: end_time, strategy_address, governor_address added where used.
  • Removed non-existent protocol fee (0.1%) from UI; removed swap summary rows (Exchange Rate, Network Fee, Available ETH) per product; added “Market ends” date in the collateral section.

Test Plan

Prerequisites

  • Wallet connected on the correct chain (e.g. Base Sepolia).
  • Community has a prediction market thread with a deployed market (vault, router, p/f tokens, collateral).
  • For mint: user has the market’s collateral token (e.g. WETH or USDC).

1. Open modal and header

  • From a thread with a prediction market, click “Trade” (or equivalent) to open the trade modal.
  • Header shows market title/prompt, collateral symbol, your collateral balance, and “Total minted” (correct decimals for USDC vs WETH).
  • “Market ends” shows the correct date/time when end_time is present.
  • Collapsible details: collapsed by default; click to expand; Vault, Collateral, Router, PASS token, FAIL token (and Strategy/Governor if API returns them), “Balances for” (wallet) each have a copy button; copying shows “Copied” and pasted value is the full address.

2. PASS/FAIL balance cards

  • PASS and FAIL cards show balances (from API or on-chain).
  • Each card shows short address (e.g. 0x6A76…43eA) and copy icon on the same line as “PASS BALANCE” / “FAIL BALANCE”.
  • Copy button copies the full token address. After mint/swap/merge, balances update (or refetch).

3. Mint

  • Mint tab shows “Available: X.XX <symbol>” and MAX uses collateral balance.
  • Enter amount <= balance → primary button enabled; submit mints and shows success; modal closes or refreshes; PASS/FAIL balances increase.
  • Enter amount > balance → primary button disabled or submit shows “Insufficient <symbol>” error.
  • With 0 collateral balance, MAX disabled and message reflects need to hold collateral (e.g. wrap ETH first for WETH).

4. Swap

  • Swap tab: “You Sell” FAIL / “You Buy” PASS (or reverse via toggle). Balances and “Min. Received” use correct decimals.
  • Enter amount <= sell balance → Swap enabled; submit executes swap; success and balances update.
  • Amount > sell balance → Swap disabled or error on submit.
  • With 0 sell balance, banner says to mint first; “No min” or high slippage allows swap when pool rate is poor (e.g. “Slippage exceeded” resolved with 5% or “No min”).
  • Slippage presets and custom work; “Min. Received” reflects chosen slippage (or “Any PASS/FAIL” for No min).

5. Merge

  • Merge tab: “Available” is min(PASS, FAIL); MAX fills that amount.
  • Enter amount <= available → Merge enabled; submit merges and returns collateral; success and balances decrease.
  • “Collateral to be returned” uses the correct collateral symbol (e.g. USDC, WETH).

6. Redeem

  • When market is not resolved: Redeem tab is clickable; in-tab message says redemption is available after resolution; primary button disabled.
  • When market is resolved: Enter amount <= winning token balance → Redeem enabled; submit redeems for collateral; success.

7. Edge cases and copy

  • Balances for a new wallet (no API position) load from chain and display correctly.
  • All copy buttons in the collapsible section and on PASS/FAIL cards copy the correct full address and show “Copied” (or error toast on failure).

8. Manual contract check (optional)

  • On Basescan (or chain explorer): vault address holds collateral; PASS/FAIL token balanceOf(user) matches modal after mint/swap/merge.

Deployment Plan

  • No infra or env changes required. Frontend-only; works with existing chain and API.

Other Considerations

  • Follow-up: consider a “quote” or expected output for swap (if strategy exposes a view) to improve UX before “Slippage exceeded”.
  • Strategy and Governor addresses in the details section depend on API including strategy_address and governor_address in the market payload.

@mzparacha mzparacha requested a review from masvelio as a code owner February 23, 2026 15:27
@mzparacha mzparacha marked this pull request as draft February 23, 2026 15:28
@mzparacha mzparacha self-assigned this Feb 24, 2026
@mzparacha mzparacha marked this pull request as ready for review February 24, 2026 18:43
@mzparacha mzparacha changed the title Build prediction market trade modal UI component Prediction market trade modal with mint / swap / merge / redeem functionality Feb 24, 2026
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.

Build prediction market trade modal UI component

3 participants