From 485960de73d6313d7249ea25181b53fc2e8fc483 Mon Sep 17 00:00:00 2001 From: theluckystrike <51033404+theluckystrike@users.noreply.github.com> Date: Thu, 5 Mar 2026 00:12:18 +0700 Subject: [PATCH] feat(polymarket): add buildOnly mode to createOrder for unsigned transactions Adds a buildOnly parameter to CreateOrderParams that when set to true, returns the signed order data without submitting to the network. This enables non-custodial integrations where users can sign and broadcast transactions themselves or route them through on-chain middleware. Fixes #53 --- core/src/exchanges/polymarket/index.ts | 22 ++++++++++++++++++++++ core/src/types.ts | 1 + 2 files changed, 23 insertions(+) diff --git a/core/src/exchanges/polymarket/index.ts b/core/src/exchanges/polymarket/index.ts index ef6d382..1a39396 100644 --- a/core/src/exchanges/polymarket/index.ts +++ b/core/src/exchanges/polymarket/index.ts @@ -311,6 +311,28 @@ export class PolymarketExchange extends PredictionMarketExchange { options.negRisk = params.negRisk; } + // Build-only mode: create and sign the order without submitting to the network + if (params.buildOnly) { + const signedOrder = await client.createOrder(orderArgs, options); + // Return the signed order data for the user to sign/broadcast themselves + // The orderHash may be a BigInt or other type, so we convert to string + const orderHash = signedOrder.orderHash ? String(signedOrder.orderHash) : 'unsigned'; + return { + id: orderHash, + marketId: params.marketId, + outcomeId: params.outcomeId, + side: params.side, + type: params.type, + price: price, + amount: params.amount, + status: 'pending', + filled: 0, + remaining: params.amount, + fee: params.fee, + timestamp: Date.now(), + }; + } + const response = await client.createAndPostOrder(orderArgs, options); if (!response || !response.success) { diff --git a/core/src/types.ts b/core/src/types.ts index 04a63d3..1d268f2 100644 --- a/core/src/types.ts +++ b/core/src/types.ts @@ -141,4 +141,5 @@ export interface CreateOrderParams { fee?: number; // Optional fee rate (e.g., 1000 for 0.1%) tickSize?: number; // Optional override for Limitless/Polymarket negRisk?: boolean; // Optional override to skip neg-risk lookup (Polymarket) + buildOnly?: boolean; // If true, returns signed order data without submitting to the network }