Skip to content

Add Polymarket withdrawal#2047

Merged
babgev merged 17 commits into
devfrom
arentant/polymarket-withdrawal
Jul 8, 2026
Merged

Add Polymarket withdrawal#2047
babgev merged 17 commits into
devfrom
arentant/polymarket-withdrawal

Conversation

@arentant

@arentant arentant commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Implements Polymarket as an extended (UI-synthesized) source network,
mirroring the Hyperliquid extended-route pattern. Users withdraw pUSD from
their Polymarket funder wallet via a gasless relayer transfer into a
Polymarket bridge address, which converts pUSD to USDC and delivers it to a
Layerswap Polygon deposit address; the backend then bridges to the final
destination.

- Synthesize POLYMARKET_MAINNET (type 'polymarket') from Polygon at settings
  inflation; register polymarketProvider in the extended-routes registry
- Resolve the funder across deposit-wallet / Safe / proxy derivations (pure
  viem CREATE2, no Polymarket SDK) and read pUSD + legacy USDC.e balances
- Gasless relayer signing (Safe SafeTx + deposit-wallet Batch) via viem;
  relayer proxied through pages/api/polymarket/relay with the builder key
  held server-side
- Polymarket bridge client (quote / withdraw / status) with a $2 minimum
  guard surfaced to route limits, plus balance + gas providers and the
  withdrawal component + hook

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
layerswapapp Canceled Canceled Jul 8, 2026 12:14am

Request Review

@arentant arentant changed the title Add Polymarket as a gasless withdrawal source Add Polymarket withdrawal Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Storybook preview: https://layerswap.github.io/layerswapapp/pr-preview/pr-2047/

…ss batch processing

- Updated `usePolymarketWithdrawal` to handle new Depository-based withdrawal flow.
- Removed legacy PolymarketBridgeClient and related API calls.
- Introduced new functions for building deposit wallet batch requests and handling deposit actions.
- Enhanced error handling and logging for withdrawal processes.
- Adjusted context and hooks to accommodate changes in withdrawal parameters and state management.
- Updated constants and types to reflect new funding mechanisms and requirements.
…lookup

Balance discovery only checked locally-derived funders (deposit/safe/proxy),
which cannot reproduce older account vintages whose funder contracts use
constants we don't hardcode. Those balances were silently reported as zero.

Add Polymarket's authoritative proxyWallet from GET /public-profile as an
extra balance candidate (best-effort, CORS-open, read client-side; 404/error
falls back to derivation). When the profile wallet isn't one of the derived,
classifiable addresses it is tagged 'unknown' and deduped by address, so its
balance is surfaced but withdrawal shows "Unsupported account" instead of
mishandling it as a Safe.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…assification

A funder surfaced via Polymarket's public profile that local CREATE2 derivation
can't reproduce was tagged 'unknown' and rejected as unsupported — even when it's
a real DepositWallet deployed by an older factory/implementation (e.g. beacon
proxy), owned by the connected EOA, and holding funds.

Add classifyPolymarketFunder(): read ERC-5267 eip712Domain() + owner() on-chain.
When the domain is "DepositWallet" and the connected EOA owns it, the wallet is
drivable through the existing deposit-wallet batch path regardless of vintage
(its EIP-712 domain matches the signature we already produce). The withdrawal
hook now classifies an 'unknown' funder lazily, at withdrawal time, and routes a
confirmed deposit wallet through the deposit path; anything still unclassifiable
stays "Unsupported account". Fails cleanly if the relayer rejects — the owner
signature authorizes only the exact batch, so no funds move on failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
babgev and others added 2 commits July 8, 2026 02:12
The app is deployed under a Next.js basePath (e.g. /app), and every same-origin
URL in the codebase is basePath-prefixed via router.basePath — except the
Polymarket relayer client, which hardcoded fetch('/api/polymarket/relay'). Under
a basePath deployment that resolves to /api/polymarket/relay instead of
/app/api/polymarket/relay, so Vercel returns a platform 404 and the withdrawal
fails at the relayer nonce/submit step. Balance discovery was unaffected because
it only calls external URLs (gamma-api + Polygon RPC), which is why balances
worked while withdrawal 404'd.

Thread router.basePath from usePolymarketWithdrawal into getRelayerNonce /
isPolymarketDeployed / submitRelayerTransaction (and getRelayerTransaction);
relayer fetches now target `${basePath}/api/polymarket/relay`. Defaults to ''
so root deployments and local dev (no basePath) are unchanged.

Verified against the deployment: /app/api/polymarket/relay?action=nonce returns
{"nonce":"0"} while the un-prefixed path returns a Vercel NOT_FOUND page.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel vercel Bot temporarily deployed to Preview – layerswapapp July 8, 2026 00:14 Inactive
@babgev babgev merged commit 7669ef6 into dev Jul 8, 2026
1 of 2 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.

2 participants