Overview
The Fee Escrow lets platforms charge a fee on trades placed through the polynode SDK. Fees are optional, per-order, and fully on-chain. The system uses an escrow model: fees are pulled before order placement and either distributed on fill or refunded on cancel. Users never lose fees on unfilled orders. Key properties:- Fees are opt-in. Set
feeBps: 0to skip the escrow entirely. - Each order gets its own escrow entry with an independent affiliate and split.
- If the operator doesn’t settle within 72 hours, the user can self-refund on-chain.
- All escrow operations are gasless via Polymarket’s relayer.
How It Works
Contract
| Field | Value |
|---|---|
| Address | 0xa11D28433B79D0A88F3119b16A090075752258EA |
| Chain | Polygon (137) |
| USDC | 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 (USDC.e) |
| Timeout | 72 hours (user self-refund after this) |
Setup
Users need one additional USDC approval for the escrow contract. This is added to the existing approval batch during wallet setup (7th approval, gasless, batched with the 6 Polymarket approvals).Fee Authorization (EIP-712)
The user signs a typed message authorizing a specific fee amount for a specific order. This prevents anyone from pulling more than the user agreed to.Order Types
Every order type works with the escrow. The fee is pulled before submission and settled based on the order outcome.Limit Buy (GTC, resting)
Order rests on the book. If cancelled before fill, fee is refunded.0x39cb2d... placed at 20c, cancelled, fee refunded. Safe net change: $0.00.
Market Buy (fills immediately)
Order fills instantly. Fee is distributed to treasury.Limit Sell (GTC, resting)
Same flow as limit buy. Rests on book, refunded on cancel.0x71f943... placed at 45c, cancelled, fee refunded.
Market Sell (fills immediately)
Batch Cancel
Multiple resting orders can be cancelled at once. Each gets its own refund.cancelAll(), both fees refunded.
No Fee (Opt-Out)
IffeeBps is 0, the SDK skips the escrow entirely. The order goes straight to the CLOB with no fee interaction. Existing behavior is completely unchanged.
Affiliate Revenue Sharing
Each order can specify an affiliate address and their share of the fee. The split is set per-order, so different partners can have different rates.| Split | Treasury | Affiliate |
|---|---|---|
affiliateShareBps: 10000 (default — you keep 100%) | $0.00 | $0.10 |
affiliateShareBps: 7000 (share 30% with polynode) | $0.03 | $0.07 |
affiliateShareBps: 5000 (50/50 split) | $0.05 | $0.05 |
Partial Fills
If an order partially fills, the fee is proportionally distributed. The remainder stays in escrow until the order fully fills or is cancelled.72-Hour Safety Net
If the operator hasn’t settled an order within 72 hours, anyone can callclaimRefund(orderId) to return the undistributed fee to the user. This is permissionless and requires no API key or operator involvement.
Security
The contract has been through three independent security audits:- Signature malleability — rejected (secp256k1 s-value upper bound check)
- Replay attacks — prevented by per-signer sequential nonces
- Affiliate share overflow — capped at 10000 bps (100%)
- Self-referential payer — blocked (payer cannot be the escrow contract)
- ecrecover(0) — rejected explicitly
- Operator compromise — operator can be revoked by Safe owner instantly
- Stuck funds — 72-hour user self-refund + owner emergency withdraw
SDK Integration
Enable fee collection with a single config option. Everything else is automatic.Basic Setup
affiliate field is required when feeBps > 0. This is the wallet where your fees are sent. By default, you keep 100% of the fee. If you want to share a portion with the polynode treasury, set affiliateShareBps to less than 10000:
feeConfig is set with feeBps > 0, every order automatically:
- Calculates the fee from the order’s price and size
- Signs an EIP-712 authorization (free, off-chain)
- Pulls the fee into escrow before the order reaches the CLOB
- Refunds the fee automatically if the order is cancelled
Fee Calculation
The fee is calculated as:feeBps: 50:
Placing an Order with Fees
feeEscrowTxHash (the on-chain transaction that moved USDC into escrow) and feeAmount (how much was charged).
Cancelling (Auto-Refund)
cancelAll() also triggers refunds for every cancelled order that had a fee.
Per-Order Fee Override
Override the globalfeeConfig on individual orders:
Opting Out
SetfeeBps: 0 or omit feeConfig entirely. The SDK skips the escrow and the order goes straight to the CLOB with zero overhead. Existing behavior is completely unchanged.
What the SDK Does Under the Hood
When you calltrader.order() with feeBps > 0:
Approvals
The escrow contract requires one USDC approval. This is automatically included in the approval batch duringensureReady() — the 7th approval alongside the 6 Polymarket approvals. For Safe wallets, it’s batched into the same multicall transaction (no extra gas). For EOA wallets, it’s one additional approval TX (~$0.001 MATIC).
