{"version":3,"file":"orderBuilder.cjs","names":["SignatureTypeV2","createOrder","createMarketOrder"],"sources":["../../src/order-builder/orderBuilder.ts"],"sourcesContent":["import { SignatureTypeV2, type SignedOrderV1, type SignedOrderV2 } from \"../order-utils/index.js\";\nimport type { ClobSigner } from \"../signing/signer.js\";\nimport type {\n\tChain,\n\tCreateOrderOptions,\n\tUserMarketOrderV1,\n\tUserMarketOrderV2,\n\tUserOrderV1,\n\tUserOrderV2,\n} from \"../types/index.js\";\n\nimport { createMarketOrder, createOrder } from \"./helpers/index.js\";\n\nexport class OrderBuilder {\n\treadonly signer: ClobSigner;\n\n\treadonly chainId: Chain;\n\n\t// Signature type used sign orders, defaults to EOA type\n\treadonly signatureType: SignatureTypeV2;\n\n\t// Address which holds funds to be used.\n\t// Used for Polymarket proxy wallets and other smart contract wallets\n\t// If not provided, funderAddress is the signer address\n\treadonly funderAddress?: string;\n\n\t/**\n\t * Optional function to dynamically resolve the signer.\n\t * If provided, this function will be called to obtain a fresh signer instance\n\t * (e.g., for smart contract wallets or when the signer may change).\n\t * Should return a Wallet or JsonRpcSigner, or a Promise resolving to one.\n\t * If not provided, the static `signer` property is used.\n\t */\n\tprivate getSigner?: () => Promise<ClobSigner> | ClobSigner;\n\n\tconstructor(\n\t\tsigner: ClobSigner,\n\t\tchainId: Chain,\n\t\tsignatureType?: SignatureTypeV2,\n\t\tfunderAddress?: string,\n\t\tgetSigner?: () => Promise<ClobSigner> | ClobSigner,\n\t) {\n\t\tthis.signer = signer;\n\t\tthis.chainId = chainId;\n\t\tthis.signatureType = signatureType === undefined ? SignatureTypeV2.EOA : signatureType;\n\t\tthis.funderAddress = funderAddress;\n\t\tthis.getSigner = getSigner;\n\t}\n\n\t/**\n\t * Generate and sign a order\n\t */\n\tpublic async buildOrder(\n\t\tuserOrder: UserOrderV1 | UserOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/**\n\t * Generate and sign a market order\n\t */\n\tpublic async buildMarketOrder(\n\t\tuserMarketOrder: UserMarketOrderV1 | UserMarketOrderV2,\n\t\toptions: CreateOrderOptions,\n\t\tversion: number,\n\t): Promise<SignedOrderV1 | SignedOrderV2> {\n\t\tconst signer = await this.resolveSigner();\n\t\treturn createMarketOrder(\n\t\t\tsigner,\n\t\t\tthis.chainId,\n\t\t\tthis.signatureType,\n\t\t\tthis.funderAddress,\n\t\t\tuserMarketOrder,\n\t\t\toptions,\n\t\t\tversion,\n\t\t);\n\t}\n\n\t/** Unified getter: use fresh signer if available */\n\tprivate async resolveSigner(): Promise<ClobSigner> {\n\t\tif (this.getSigner) {\n\t\t\tconst s = await this.getSigner();\n\t\t\tif (!s) throw new Error(\"getSigner() function returned undefined or null\");\n\t\t\treturn s;\n\t\t}\n\t\treturn this.signer;\n\t}\n}\n"],"mappings":";;;;;AAaA,IAAa,eAAb,MAA0B;CACzB,AAAS;CAET,AAAS;CAGT,AAAS;CAKT,AAAS;;;;;;;;CAST,AAAQ;CAER,YACC,QACA,SACA,eACA,eACA,WACC;AACD,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,gBAAgB,kBAAkB,SAAYA,wCAAgB,MAAM;AACzE,OAAK,gBAAgB;AACrB,OAAK,YAAY;;;;;CAMlB,MAAa,WACZ,WACA,SACA,SACyC;AAEzC,SAAOC,gCADQ,MAAM,KAAK,eAAe,EAGxC,KAAK,SACL,KAAK,eACL,KAAK,eACL,WACA,SACA,QACA;;;;;CAMF,MAAa,iBACZ,iBACA,SACA,SACyC;AAEzC,SAAOC,4CADQ,MAAM,KAAK,eAAe,EAGxC,KAAK,SACL,KAAK,eACL,KAAK,eACL,iBACA,SACA,QACA;;;CAIF,MAAc,gBAAqC;AAClD,MAAI,KAAK,WAAW;GACnB,MAAM,IAAI,MAAM,KAAK,WAAW;AAChC,OAAI,CAAC,EAAG,OAAM,IAAI,MAAM,kDAAkD;AAC1E,UAAO;;AAER,SAAO,KAAK"}