/** * Trading module types */ /** Signature types matching Polymarket's exchange contracts */ export declare enum SignatureType { EOA = 0, POLY_PROXY = 1, POLY_GNOSIS_SAFE = 2, /** ERC-1271 signatures for deposit wallets (V2 only) */ POLY_1271 = 3 } /** Which exchange protocol version to use for order placement */ export type ExchangeVersion = 'v1' | 'v2'; /** * Flexible signer input — accepts any common wallet type. * * - `string` → hex private key (creates viem WalletClient internally) * - ethers v5/v6 Signer → detected by `_signTypedData` method * - viem WalletClient → detected by `signTypedData` + `account` * - EIP-1193 provider → for browser wallets (Privy React, MetaMask, etc.) * - RouterSigner → Dome-compatible { getAddress, signTypedData } (Privy server-auth, etc.) */ export type TradingSigner = string | { _signTypedData: Function; getAddress: Function; } | { signTypedData: Function; account: { address: string; }; } | { provider: EIP1193Provider; address: string; safeAddress?: string; } | RouterSigner; export interface EIP1193Provider { request: (args: { method: string; params?: any[]; }) => Promise; } /** * Dome-compatible signer interface. * Works with Privy server-auth, or any custom signer that implements * getAddress() and signTypedData(). * * This is the interface returned by createPrivySigner(). */ export interface RouterSigner { getAddress(): Promise; signTypedData(payload: Eip712Payload): Promise; /** Optional: sign a raw message (needed for Safe transaction execution during approvals) */ signMessage?(message: string | Uint8Array): Promise; /** Optional: send a transaction directly (used for Privy gas-sponsored approvals) */ sendTransaction?(tx: { to: string; data: string; chainId: number; }): Promise; } export interface Eip712Payload { domain: Record; types: Record; primaryType: string; message: Record; } /** Returned by PolyNodeTrader.generateWallet() */ export interface GeneratedWallet { /** Hex-encoded private key (0x-prefixed). User MUST back this up. */ privateKey: string; /** The derived EOA address */ address: string; } /** Optional fee configuration for per-order fee collection via on-chain escrow. */ export interface FeeConfig { /** Fee in basis points (e.g. 50 = 0.5% of order notional). 0 = no fee. */ feeBps: number; /** Affiliate address to receive a share of the fee. */ affiliate?: string; /** Affiliate's share of the fee in basis points (e.g. 3000 = 30% to affiliate). */ affiliateShareBps?: number; } export interface BuilderCredentials { /** Polymarket builder API key (from polymarket.com/settings?tab=builder) */ key: string; /** Polymarket builder secret (base64-encoded) */ secret: string; /** Polymarket builder passphrase */ passphrase: string; } export interface TraderConfig { /** polynode API key (for builder attribution via co-signer) */ polynodeKey?: string; /** Path to local SQLite database. Default: ./polynode-trading.db */ dbPath?: string; /** * Pluggable storage backend. Options: * - omit or `undefined` → auto-detect (better-sqlite3 if available, in-memory fallback) * - `'memory'` → in-memory storage (no persistence, works in Bun/Deno/edge) * - Custom `TradingStorage` object → bring your own database */ storage?: 'memory' | import('./storage.js').TradingStorage; /** Co-signer URL. Default: https://trade.polynode.dev */ cosignerUrl?: string; /** If true, submit directly to CLOB when co-signer is unreachable */ fallbackDirect?: boolean; /** Wallet type for new users. Default: POLY_GNOSIS_SAFE (2) */ defaultSignatureType?: SignatureType; /** RPC URL for on-chain reads (balance/approval checks). Default: publicnode */ rpcUrl?: string; /** * Your own Polymarket builder credentials for order attribution. * If provided, all orders are attributed to YOUR builder profile instead of polynode's. * Get these from polymarket.com/settings?tab=builder */ builderCredentials?: BuilderCredentials; /** * Exchange protocol version. Default: 'v1'. * - 'v1' uses clob.polymarket.com + V1 exchange contracts + USDC.e collateral * - 'v2' uses clob.polymarket.com + V2 exchange contracts + PolyUSD collateral */ exchangeVersion?: ExchangeVersion; /** Fee escrow config. If feeBps > 0, fees are pulled before each order. */ feeConfig?: FeeConfig; } export interface ReadyStatus { wallet: string; funderAddress: string; signatureType: SignatureType; safeDeployed: boolean; approvalsSet: boolean; credentialsStored: boolean; /** Full CLOB credentials — user should back these up */ credentials: { apiKey: string; apiSecret: string; apiPassphrase: string; }; /** What was done during this call */ actions: string[]; } export interface LinkResult { wallet: string; funderAddress: string; signatureType: SignatureType; /** Full CLOB credentials — user should back these up */ credentials: { apiKey: string; apiSecret: string; apiPassphrase: string; }; } export interface WalletInfo { wallet: string; funderAddress: string; signatureType: SignatureType; credentials: { apiKey: string; apiSecret: string; apiPassphrase: string; }; createdAt: number; } /** Full wallet export — everything the user needs to restore on another machine */ export interface WalletExport { wallet: string; funderAddress: string; signatureType: SignatureType; credentials: { apiKey: string; apiSecret: string; apiPassphrase: string; }; safeDeployed: boolean; approvalsSet: boolean; createdAt: number; } export interface ApprovalStatus { funderAddress: string; usdc: { ctfExchange: boolean; negRiskCtfExchange: boolean; negRiskAdapter: boolean; feeEscrow: boolean; }; ctf: { ctfExchange: boolean; negRiskCtfExchange: boolean; negRiskAdapter: boolean; }; allApproved: boolean; } export interface BalanceInfo { funderAddress: string; usdc: string; usdcRaw: string; matic: string; } export type OrderSide = 'BUY' | 'SELL'; export type OrderType = 'GTC' | 'GTD' | 'FOK' | 'FAK'; export interface OrderParams { tokenId: string; side: OrderSide; price: number; size: number; type?: OrderType; /** Expiration timestamp (only for GTD, V1 only) */ expiration?: number; /** If true, order only rests on book (no immediate fill) */ postOnly?: boolean; /** V2: Which neg-risk exchange to use ('A' or 'B'). Default: 'A'. Ignored for standard markets. */ negRiskExchange?: V2NegRiskExchange; /** V2: Metadata bytes32 (default: zero bytes32) */ metadata?: string; /** V2: Builder bytes32 for attribution (default: zero bytes32) */ builder?: string; /** Per-order fee override. If set, overrides config-level feeConfig for this order. */ feeConfig?: FeeConfig; } export interface OrderResult { success: boolean; orderId?: string; status?: string; error?: string; makingAmount?: string; takingAmount?: string; /** Fee escrow transaction hash, if a fee was pulled for this order. */ feeEscrowTxHash?: string; /** Fee amount in USDC (human-readable, e.g. "0.05"). */ feeAmount?: string; } export interface CancelResult { canceled: string[]; notCanceled: Record; } export interface OpenOrder { id: string; market: string; assetId: string; side: string; price: string; originalSize: string; sizeMatched: string; status: string; createdAt: string; orderType: string; } export interface SplitParams { /** Market condition ID. The SDK auto-detects whether to use NegRiskAdapter or CTF. */ conditionId: string; /** Amount in USDC (e.g. 100 = $100). The SDK handles 6-decimal conversion. */ amount: number; } export interface MergeParams { /** Market condition ID. */ conditionId: string; /** Amount in USDC (e.g. 100 = $100). */ amount: number; } export interface ConvertParams { /** Neg-risk market group ID (negRiskMarketID from market data). */ marketId: string; /** Outcome indices to convert (e.g. [0, 1] converts outcomes at index 0 and 1). */ outcomeIndices: number[]; /** Amount per outcome in USDC (e.g. 100 = $100). */ amount: number; } export interface PositionResult { success: boolean; txHash?: string; error?: string; } export interface MarketMeta { tokenId: string; tickSize: string; feeRateBps: number; negRisk: boolean; fetchedAt: number; } export interface OrderHistoryRow { id: number; walletAddress: string; orderId: string | null; tokenId: string; side: string; price: number; size: number; orderType: string; status: string; errorMsg: string | null; responseJson: string | null; createdAt: number; feeAmountRaw: string | null; escrowOrderId: string | null; feeEscrowTxHash: string | null; } export interface HistoryParams { limit?: number; offset?: number; tokenId?: string; side?: OrderSide; } export interface StoredCredentials { walletAddress: string; funderAddress: string | null; apiKey: string; apiSecret: string; apiPassphrase: string; signatureType: SignatureType; safeDeployed: boolean; approvalsSet: boolean; createdAt: number; updatedAt: number; } /** V2 order struct for EIP-712 signing */ export interface V2OrderData { salt: number; maker: string; signer: string; tokenId: string; makerAmount: string; takerAmount: string; side: 'BUY' | 'SELL'; signatureType: number; timestamp: string; metadata: string; builder: string; } /** Signed V2 order ready for CLOB submission */ export interface SignedV2Order extends V2OrderData { signature: string; } /** Full V2 CLOB payload */ export interface V2OrderPayload { order: SignedV2Order & { taker: string; expiration: string; }; owner: string; orderType: OrderType; postOnly: boolean; deferExec: boolean; } /** V2 exchange address selection for neg-risk markets */ export type V2NegRiskExchange = 'A' | 'B'; export interface FeeAuthRequest { escrowOrderId: string; payer: string; signer: string; feeAmount: string; deadline: number; nonce: number; signature: string; affiliate: string; affiliateShareBps: number; /** V2-routing hint for the cosigner. Set when exchangeVersion === 'v2' so the * cosigner picks the V2 FeeEscrow operator; omitted for V1 (preserves * backwards compatibility with V1 customers). */ escrow_contract?: string; } export interface CosignerRequest { method: string; path: string; body?: string; headers: Record; builder_credentials?: BuilderCredentials; fee_auth?: FeeAuthRequest; } //# sourceMappingURL=types.d.ts.map