/** * Polymarket V2 PMCT withdrawal. * * Two flows are supported, dispatched on input shape: * * 1. **UDA / PMCT transfer** (legacy) — caller supplies `userId` + * `sendPmctTransfer`. The backend handles the unwrap/route via * PermissionedRamp. Returns a {@link CustomWithdrawalConfig}. * * 2. **Wallet unwrap** — caller supplies `proxyAddress`, a `publicClient`, * and a batched `sendTransactions` primitive. `preWithdrawalAction` * reads the pUSD allowance and returns the approve (when needed) + * `unwrap()` to USDCe as an array of {@link WithdrawalTransaction}s. * The SDK prepends those to the withdrawal txn and atomically broadcasts * the batch via the integrator's `sendTransactions`. Returns a * {@link WalletWithdrawalConfig}. */ import { type Address, type PublicClient, type TransactionReceipt } from 'viem'; import { POLYGON_USDCE, PUSD_TOKEN } from '../../consts/polymarket'; import type { AllowedRecipient } from '../../domains/withdrawalAllowlist'; import type { CustomWithdrawalConfig, FunkitCheckoutActionParams, WalletWithdrawalConfig } from '../../providers/FunkitCheckoutContext/types'; import type { WithdrawalSignContext, WithdrawalTransaction } from '../../wallets/Wallet'; export { POLYGON_USDCE, PUSD_TOKEN }; export interface PolymarketWithdrawalCallbackConfig { userId: string; modalTitle?: string; disableConnectedWallet?: boolean; sourceTokenSymbol?: string; defaultReceiveToken?: string; sourceTokenAddress?: Address; iconSrc?: string; /** * Addresses the user may withdraw to, applied only while the * `enable-withdrawal-allowlist` gate is on. The user picks one from this * list instead of typing an address, and an empty list blocks the * withdrawal. Cash withdrawals are off while a list is set. */ allowedRecipients?: AllowedRecipient[]; /** * Opens the integrator's screen for managing `allowedRecipients`. Without * it, the recipient picker hides its Manage and Add links. The picker shows * only while the `enable-withdrawal-allowlist` gate is on. */ onManageAllowedRecipients?: () => void; /** * Execute the ERC-20 transfer of PMCT from the user's proxy to the UDA. * Called after the UDA address is generated. * Should return when the transaction has been submitted (not necessarily confirmed). */ sendPmctTransfer: (params: { /** The UDA address to send PMCT to */ udaAddress: Address; /** Amount in base units (from the quote) */ amountBaseUnit: bigint; }) => Promise; } /** * Caller-supplied batched submitter. Receives the full ordered list of txs * (helper-injected approve+unwrap, then the SDK's withdrawal txn). Must * broadcast them atomically in a single user signature and return a tx hash * that {@link WithdrawalClient.confirmTransaction} can wait on. */ export type PolymarketSendTransactions = (txs: WithdrawalTransaction[], signContext?: WithdrawalSignContext) => Promise; export interface PolymarketWalletUnwrapWithdrawalConfig { /** Polymarket proxy that holds pUSD and signs the batched tx. */ proxyAddress: Address; /** Polygon public client used for the pre-flight allowance read. */ publicClient: PublicClient; /** * Batched send primitive. The SDK passes the full ordered list of txs — * helper-emitted `approve(pUSD → offramp)` (only when allowance is * insufficient) and `offramp.unwrap(USDCe, proxy, amount)` from * `preWithdrawalAction`, followed by the withdrawal txn — and the * integrator broadcasts them atomically in a single user signature. */ sendTransactions: PolymarketSendTransactions; /** * Optional override for waiting on a tx receipt. Defaults to * `publicClient.waitForTransactionReceipt`. */ confirmTransaction?: (txHash: string, chainId: number) => Promise; modalTitle?: string; disableConnectedWallet?: boolean; sourceTokenSymbol?: string; sourceTokenAddress?: Address; defaultReceiveToken?: string; iconSrc?: string; /** * Addresses the user may withdraw to, applied only while the * `enable-withdrawal-allowlist` gate is on. The user picks one from this * list instead of typing an address, and an empty list blocks the * withdrawal. Cash withdrawals are off while a list is set. */ allowedRecipients?: AllowedRecipient[]; /** * Opens the integrator's screen for managing `allowedRecipients`. Without * it, the recipient picker hides its Manage and Add links. The picker shows * only while the `enable-withdrawal-allowlist` gate is on. */ onManageAllowedRecipients?: () => void; } /** * Combined input — supplies params for both flows. * * @deprecated The `enable-polymarket-wallet-withdrawal` rollout is complete, * so this always resolves to the wallet-unwrap flow and the UDA params * (`userId`, `sendPmctTransfer`) are ignored. Pass * {@link PolymarketWalletUnwrapWithdrawalConfig} instead. */ export interface PolymarketWithdrawalConfig extends PolymarketWithdrawalCallbackConfig, PolymarketWalletUnwrapWithdrawalConfig { } /** * Combined entry point. Always returns the wallet-unwrap * {@link WalletWithdrawalConfig} — see {@link PolymarketWithdrawalConfig}. * * ```ts * const withdrawalConfig = createPolymarketWithdrawalConfig({ * userId: walletAddress, * sendPmctTransfer: async ({ udaAddress, amountBaseUnit }) => { ... }, * proxyAddress, * publicClient, * sendTransactions: async (txs) => myBatchedSend(txs), * }) * ``` */ export declare function createPolymarketWithdrawalConfig(config: PolymarketWithdrawalConfig): WalletWithdrawalConfig; /** * Legacy UDA / PMCT transfer flow. Returns a {@link CustomWithdrawalConfig}. * * ```ts * const withdrawalConfig = createPolymarketWithdrawalConfig({ * userId: walletAddress, * sendPmctTransfer: async ({ udaAddress, amountBaseUnit }) => { ... }, * }) * ``` */ export declare function createPolymarketWithdrawalConfig(config: PolymarketWithdrawalCallbackConfig): CustomWithdrawalConfig; /** * Wallet-flow with embedded pUSD → USDCe unwrap. Returns a * {@link WalletWithdrawalConfig} whose `preWithdrawalAction` and `wallet` * coordinate via a closure-scoped queue, so the integrator only sees the * batched `sendTransactions` primitive. * * ```ts * const withdrawalConfig = createPolymarketWithdrawalConfig({ * proxyAddress, * publicClient, * sendTransactions: async (txs) => myBatchedSend(txs), * }) * ``` */ export declare function createPolymarketWithdrawalConfig(config: PolymarketWalletUnwrapWithdrawalConfig): WalletWithdrawalConfig; /** Polymarket CollateralOnramp on Polygon — permissionless wrap USDC.e → pUSD. */ export declare const COLLATERAL_ONRAMP_ADDRESS: Address; export declare const COLLATERAL_ONRAMP_ABI: readonly [{ readonly name: 'wrap'; readonly type: 'function'; readonly inputs: readonly [{ readonly name: '_asset'; readonly type: 'address'; }, { readonly name: '_to'; readonly type: 'address'; }, { readonly name: '_amount'; readonly type: 'uint256'; }]; readonly outputs: readonly []; readonly stateMutability: 'nonpayable'; }]; /** VaultDepositor on Polygon — same address used by other VaultDepositor flows. */ export declare const VAULT_DEPOSITOR_POLYGON: `0x${string}`; /** * Minimal VaultDepositor ABI — only the mediated `deposit` entrypoint is used. * VaultDepositor pulls full msg.sender balance, replaces AMOUNT_PLACEHOLDER in * callData with the actual amount, and forwards to the target vault. */ export declare const VAULT_DEPOSITOR_ABI: readonly [{ readonly name: 'deposit'; readonly type: 'function'; readonly stateMutability: 'nonpayable'; readonly inputs: readonly [{ readonly name: 'token'; readonly type: 'address'; }, { readonly name: 'vault'; readonly type: 'address'; }, { readonly name: 'callData'; readonly type: 'bytes'; }, { readonly name: 'minAmountOut'; readonly type: 'uint256'; }]; readonly outputs: readonly [{ readonly name: 'returnData'; readonly type: 'bytes'; }]; }]; /** Sentinel the VaultDepositor replaces with the actual deposit amount at exec time. */ export declare const AMOUNT_PLACEHOLDER = 115792089237316195423570985008687907853269984665640564039457584007912570601199n; export interface PolymarketPerpsDepositConfig { /** * Polymarket Perps account credited with the deposit */ recipientAddress: Address; } /** * Builds the `generateActionsParams` callback for a Polymarket Perps deposit. * * Both legs run inside a single Relay Router V3 `cleanupErc20sViaCall` sweep, * each mediated by the VaultDepositor proxy so the flow composes with * EXACT_INPUT quoting — the VaultDepositor pulls msg.sender's full balance and * substitutes AMOUNT_PLACEHOLDER at exec time, so arrival amounts don't need to * be known at quote time: * 1. USDC.e → pUSD via `CollateralOnramp.wrap`, attributing pUSD to Relay * Router V3. * 2. pUSD → `POLYMARKET_PERPS_ADDRESS.deposit`, crediting `recipientAddress`. * * Usage: * ```ts * const checkoutConfig: FunkitCheckoutConfig = { * // ... * generateActionsParams: createPerpsGenerateActionParams({ * recipientAddress: proxyAddress, * }), * } * ``` */ export declare function createPerpsGenerateActionParams(config: PolymarketPerpsDepositConfig): () => Promise;