/** * PolyNodeTrader — place orders on Polymarket with local credential custody * and builder attribution via the polynode co-signer. * * Usage: * const trader = new PolyNodeTrader({ polynodeKey: 'pn_live_...' }); * await trader.ensureReady('0xprivatekey...'); * const result = await trader.order({ tokenId: '...', side: 'BUY', price: 0.55, size: 100 }); * await trader.cancelOrder(result.orderId!); * trader.close(); */ import { SignatureType } from './types.js'; import type { TraderConfig, TradingSigner, ReadyStatus, LinkResult, WalletInfo, WalletExport, ApprovalStatus, BalanceInfo, OrderParams, OrderResult, CancelResult, OpenOrder, OrderHistoryRow, HistoryParams, SplitParams, MergeParams, ConvertParams, PositionResult } from './types.js'; export declare class PolyNodeTrader { private config; private db; private activeSigner; private activeWallet; private builderCreds; /** * Generate a fresh EOA wallet (private key + address). * Use this when the user has no existing wallet at all. * * Returns { privateKey, address } — the user MUST back up the private key. * Pass the privateKey to ensureReady() to complete onboarding. */ static generateWallet(): Promise<{ privateKey: string; address: string; }>; constructor(config?: TraderConfig); private getDb; private getCosignerConfig; /** * Build a FeeAuth if fee escrow is enabled for this order. * Returns null when fees are disabled (feeBps=0 or no feeConfig). */ private buildFeeAuth; /** * One-call onboarding: derive addresses, deploy Safe if needed, * set approvals if needed, create/derive CLOB credentials. * Everything gasless for Safe wallets. * * If no `type` is specified, auto-detects the wallet type: * - Safe deployed on-chain → uses Safe (type 2) * - Proxy deployed on-chain → uses Proxy (type 1) * - Neither → creates a new Safe (type 2, gasless) * * This means users importing a key from Polymarket don't need to * know which wallet type they have. Just pass the private key. */ ensureReady(signer: TradingSigner, opts?: { type?: SignatureType; }): Promise; /** * Link a wallet manually (derive credentials, store locally). * Checks on-chain state for Safe deployment and approvals. * Does NOT deploy or approve — use ensureReady() for that. */ linkWallet(signer: TradingSigner, opts?: { type?: SignatureType; }): Promise; /** * Import existing CLOB credentials directly (no signing needed). */ linkCredentials(opts: { wallet: string; apiKey: string; apiSecret: string; apiPassphrase: string; signatureType?: SignatureType; funderAddress?: string; }): void; unlinkWallet(address?: string): void; getLinkedWallets(): WalletInfo[]; /** * Export a wallet's full state — everything needed to restore on another machine. * Does NOT include the private key (user must manage that themselves). */ exportWallet(wallet?: string): WalletExport | null; /** * Export all wallets. */ exportAll(): WalletExport[]; /** * Import a previously exported wallet. */ importWallet(exported: WalletExport): void; checkApprovals(wallet?: string): Promise; checkBalance(wallet?: string): Promise; /** * Ask the V2 CLOB to refresh its cached view of on-chain balance + allowance. * Call this after setting/changing approvals — the CLOB rejects orders until * it has seen the new state. No-op for V1. */ refreshBalanceAllowance(assetType?: 'COLLATERAL' | 'CONDITIONAL', wallet?: string): Promise<{ ok: boolean; status: number; }>; /** * Read the V2 CLOB's current cached view of balance + allowance. * Returns the three spender allowances the CLOB validates against. * No-op for V1 (V1 has no equivalent endpoint at this path). */ getBalanceAllowance(assetType?: 'COLLATERAL' | 'CONDITIONAL', wallet?: string): Promise<{ balance: string; allowances: Record; } | null>; /** * Place an order on Polymarket. * * Routes to V1 or V2 exchange based on `exchangeVersion` in config. * V1 uses @polymarket/clob-client for order signing. * V2 uses native EIP-712 signing with the V2 order struct. */ order(params: OrderParams): Promise; /** * Place a V1 order (current exchange, USDC.e collateral). */ private orderV1; /** * Place a V2 order (V2 exchange, PolyUSD collateral). * * Uses native EIP-712 signing — no @polymarket/clob-client dependency. * V2 orders have timestamp, metadata, builder fields instead of * taker, expiration, nonce, feeRateBps. */ private orderV2; /** * Cancel an order. */ cancelOrder(orderId: string): Promise; /** * Cancel all orders, optionally for a specific market. */ cancelAll(market?: string): Promise; /** * Get open orders from Polymarket CLOB. */ getOpenOrders(params?: { market?: string; assetId?: string; }): Promise; /** * Wrap USDC.e into PolyUSD via the Collateral Onramp contract. * * Steps: * 1. Approve the Onramp to spend USDC.e (if not already approved) * 2. Call wrap(USDC_E, funder, amount) on the Onramp * * @param amount - Raw amount in 6-decimal units (e.g. 1000000n = 1 USDC.e) * @returns Transaction hash */ wrapToPolyUsd(amount: bigint): Promise; /** * Unwrap PolyUSD back into USDC.e via the Collateral Offramp contract. * * Calls unwrap(USDC_E, funder, amount) on the Offramp. * * @param amount - Raw amount in 6-decimal units (e.g. 1000000n = 1 PolyUSD) * @returns Transaction hash */ unwrapFromPolyUsd(amount: bigint): Promise; /** * Get the PolyUSD balance for the active funder address. * @returns Raw balance in 6-decimal units */ getPolyUsdBalance(): Promise; /** * Get the USDC.e balance for the active funder address. * @returns Raw balance in 6-decimal units */ getUsdceBalance(): Promise; /** * Split USDC into YES + NO outcome tokens for a market. * Gasless for Safe wallets. Auto-detects neg-risk vs standard markets. */ split(params: SplitParams): Promise; /** * Merge YES + NO outcome tokens back into USDC. * Gasless for Safe wallets. Auto-detects neg-risk vs standard markets. */ merge(params: MergeParams): Promise; /** * Convert NO positions on selected outcomes into USDC + YES on complementary outcomes. * Only works on neg-risk multi-outcome markets (e.g. "Who will win the World Cup?"). * * @example * // Convert NO positions on outcomes 0 and 1, $100 per outcome * await trader.convert({ marketId: '0xabc...', outcomeIndices: [0, 1], amount: 100 }); */ convert(params: ConvertParams): Promise; private getRelayConfig; private isNegRisk; /** * Pre-fetch market metadata for faster order construction. */ prefetchMeta(tokenIds: string[]): Promise; private fetchMeta; getOrderHistory(params?: HistoryParams): OrderHistoryRow[]; close(): void; private getStoredCreds; private requireSigner; /** * Execute a batch of transactions via the Polymarket relayer (gasless, through Safe/Proxy). * Mirrors the pattern used by setApprovals/deploySafe in onboarding.ts. */ private executeViaRelay; /** * Provision a per-user relayer API key via SIWE login through our co-signer. * The co-signer handles the Gamma auth, creates the key, and caches it in Redis. * This gives the user unlimited gasless on-chain operations (no builder quota consumed). */ private provisionRelayerKey; private ensureBuilderCreds; } export { SignatureType } from './types.js'; export type { TraderConfig, TradingSigner, ReadyStatus, LinkResult, WalletInfo, WalletExport, ApprovalStatus, BalanceInfo, BuilderCredentials, FeeConfig, OrderParams, OrderResult, CancelResult, SplitParams, MergeParams, ConvertParams, PositionResult, OpenOrder, OrderHistoryRow, HistoryParams, MarketMeta, EIP1193Provider, GeneratedWallet, RouterSigner, Eip712Payload, ExchangeVersion, V2OrderData, SignedV2Order, V2OrderPayload, V2NegRiskExchange, } from './types.js'; export { deriveSafeAddress, deriveProxyAddress, deriveDepositWalletAddress, detectWalletType } from './onboarding.js'; export { splitPosition, mergePositions, convertPositions, splitPositionV2, mergePositionsV2 } from './position-management.js'; export type { RelayConfig } from './position-management.js'; export { TradingSqliteBackend } from './sqlite-backend.js'; export { BunSqliteBackend } from './bun-sqlite-backend.js'; export { InMemoryStorage } from './storage.js'; export type { TradingStorage } from './storage.js'; export { createPrivySigner, createPrivyClient, createPrivySignerFromEnv, setPrivyWalletApprovals } from './privy.js'; export type { PrivyConfig } from './privy.js'; export { buildV2Order, signV2Order, buildV2Payload, getV2ExchangeAddress, computeV2Amounts, } from './v2-order.js'; export type { BuildV2OrderParams } from './v2-order.js'; export { POLY_USD, COLLATERAL_ONRAMP, COLLATERAL_OFFRAMP, V2_SPENDERS, DEPOSIT_WALLET_FACTORY, DEPOSIT_WALLET_IMPL, } from './constants.js'; //# sourceMappingURL=index.d.ts.map