Skip to content

Add polymarket #2059

Merged
babgev merged 27 commits into
mainfrom
dev
Jul 8, 2026
Merged

Add polymarket #2059
babgev merged 27 commits into
mainfrom
dev

Conversation

@babgev

@babgev babgev commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

arentant and others added 27 commits June 25, 2026 21:19
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>
…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.
Add source_address to swap types and use it instead of the input
transaction's `from` (wrong for gasless). Show "-" when source/dest
address is absent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The address-book entry and the searched-address preview each wrapped the
shared AddressWithIcon in their own divergent container: the book row
hovered the wrong way (bg-secondary-600) with no pointer cursor, and the
searched preview was a darker bg-secondary-600 box with shadow/transform.

Extract a shared AddressPickerItem that renders the row at the
connected-wallet reference style (bg-secondary-500, lightening
hover:bg-secondary-400, pointer cursor, rounded-lg) and use it in both
AddressBook and ManualAddressInput. All three picker rows now match.

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

fix: unify destination address-picker row styling
Addresses in history, resolves BAB-267
…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>
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 commented Jul 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
layerswapapp Building Building Preview Jul 8, 2026 12:34am

Request Review

@babgev babgev merged commit eb10224 into main Jul 8, 2026
1 of 2 checks passed
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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

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.

3 participants