1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2587],{92587:(e,t,r)=>{r.d(t,{ClobClient:()=>e$,OrderType:()=>a,Side:()=>s,SignatureTypeV2:()=>i});let i=((g={})[g.EOA=0]="EOA",g[g.POLY_PROXY=1]="POLY_PROXY",g[g.POLY_GNOSIS_SAFE=2]="POLY_GNOSIS_SAFE",g[g.POLY_1271=3]="POLY_1271",g),s=((p={}).BUY="BUY",p.SELL="SELL",p),a=((m={}).GTC="GTC",m.FOK="FOK",m.GTD="GTD",m.FAK="FAK",m),n="MA==",o="LTE=",h="0x0000000000000000000000000000000000000000000000000000000000000000",d="/v1/heartbeats",u="/data/trades",c=Error("Signer is needed to interact with this endpoint!"),l=Error("API Credentials are needed to interact with this endpoint!");var g,p,m,y,f=class extends Error{status;data;constructor(e,t,r){super(e),this.name="ApiError",this.status=t,this.data=r}};function w(e){if(!Number.isFinite(e)||e<0||e>100||e>0&&e<1)throw Error("feeSlippage must be 0 or a percentage between 1 and 100")}let k=async e=>{let t=e.account?.address;if("string"==typeof t&&t.length>0)return t;if("function"==typeof e.requestAddresses){let[t]=await e.requestAddresses();if("string"==typeof t&&t.length>0)return t}if("function"==typeof e.getAddresses){let[t]=await e.getAddresses();if("string"==typeof t&&t.length>0)return t}throw Error("wallet client is missing account address")},v=async e=>{if("function"==typeof e._signTypedData)return e.getAddress();if("function"==typeof e.signTypedData)return k(e);throw Error("unsupported signer type")},S=async({signer:e,domain:t,types:r,value:i,primaryType:s})=>{if("function"==typeof e._signTypedData)return e._signTypedData(t,r,i);if("function"==typeof e.signTypedData){let a=e.account??await k(e);return e.signTypedData({account:a,domain:t,types:r,primaryType:s,message:i})}throw Error("unsupported signer type")},T=async(e,t,r,i,s)=>{let a=s??await v(e),n=r.toString();return await S({signer:e,domain:{name:"ClobAuthDomain",version:"1",chainId:t},types:{ClobAuth:[{name:"address",type:"address"},{name:"timestamp",type:"string"},{name:"nonce",type:"uint256"},{name:"message",type:"string"}]},value:{address:a,timestamp:n,nonce:i,message:"This message attests that I control the given wallet"},primaryType:"ClobAuth"})},A=async(e,t,r,i,s)=>{if(!e)throw Error("buildPolyHmacSignature: secret is empty");if(!globalThis.crypto?.subtle)throw Error("buildPolyHmacSignature: globalThis.crypto.subtle is unavailable. Requires Node >=20 or a secure browser context (HTTPS or localhost).");let a=t+r+i;void 0!==s&&(a+=s);let n=(e=>{let t=e.replace(/-/g,"+").replace(/_/g,"/"),r=atob(t+"=".repeat((4-t.length%4)%4)),i=new Uint8Array(new ArrayBuffer(r.length));for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i})(e),o=await globalThis.crypto.subtle.importKey("raw",n,{name:"HMAC",hash:"SHA-256"},!1,["sign"]),h=new Uint8Array(await globalThis.crypto.subtle.sign("HMAC",o,new TextEncoder().encode(a))),d="";for(let e=0;e<h.length;e++)d+=String.fromCharCode(h[e]);return btoa(d).replace(/\+/g,"-").replace(/\//g,"_")},b=async(e,t,r,i,s)=>{let a=Math.floor(Date.now()/1e3);void 0!==i&&(a=i);let n=0;void 0!==r&&(n=r);let o=await T(e,t,a,n,s);return{POLY_ADDRESS:s??await v(e),POLY_SIGNATURE:o,POLY_TIMESTAMP:`${a}`,POLY_NONCE:`${n}`}},E=async(e,t,r,i)=>{let s=Math.floor(Date.now()/1e3);return void 0!==i&&(s=i),{POLY_ADDRESS:await v(e),POLY_SIGNATURE:await A(t.secret,s,r.method,r.requestPath,r.body),POLY_TIMESTAMP:`${s}`,POLY_API_KEY:t.key,POLY_PASSPHRASE:t.passphrase}};var O=r(59185),$=r(41463),B="u">typeof window&&void 0!==window.document;void 0!==$&&null!=$.versions&&$.versions.node,"object"==typeof self&&self.constructor&&self.constructor.name,"u">typeof window&&"nodejs"===window.name||"u">typeof navigator&&"userAgent"in navigator&&"string"==typeof navigator.userAgent&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")),"u">typeof Deno&&void 0!==Deno.version&&Deno.version.deno,void 0!==$&&null!=$.versions&&$.versions.bun;let _="POST",C="DELETE",I=async(e,t,r,i,s)=>(((e,t={})=>{B||(t["User-Agent"]="@polymarket/clob-client",t.Accept="*/*",t.Connection="keep-alive",t["Content-Type"]="application/json","GET"===e&&(t["Accept-Encoding"]="gzip"))})(t,r),await (0,O.A)({method:t,url:e,headers:r,data:i,params:s})),P=async(e,t,r=!1)=>{try{return(await I(e,_,t?.headers,t?.data,t?.params)).data}catch(i){if(r&&L(i)){await new Promise(e=>
1setTimeout(e,30));try{return(await I(e,_,t?.headers,t?.data,t?.params)).data}catch(e){return R(e)}}return R(i)}},F=async(e,t)=>{try{return(await I(e,"GET",t?.headers,t?.data,t?.params)).data}catch(e){return R(e)}},x=async(e,t)=>{try{return(await I(e,C,t?.headers,t?.data,t?.params)).data}catch(e){return R(e)}},R=e=>{if(O.A.isAxiosError(e)){if(e.response&&e.response?.data)return"string"==typeof e.response?.data||e.response?.data instanceof String||!Object.prototype.hasOwnProperty.call(e.response?.data,"error")?{error:e.response?.data,status:e.response?.status}:{...e.response?.data,status:e.response?.status};if(e.message)return{error:e.message}}return{error:e}},L=e=>{if(!O.A.isAxiosError(e))return!1;if(!e.response)return!0;let t=e.response.status??0;return t>=500&&t<600||["ECONNABORTED","ENETUNREACH","EAI_AGAIN","ETIMEDOUT"].includes((e.code??"").toString())};function D(e,t,r,i=!1,s=!1){return{deferExec:s,postOnly:i,order:{salt:parseInt(e.salt,10),maker:e.maker,signer:e.signer,taker:e.taker,tokenId:e.tokenId,makerAmount:e.makerAmount,takerAmount:e.takerAmount,side:e.side,expiration:e.expiration,nonce:e.nonce,feeRateBps:e.feeRateBps,signatureType:e.signatureType,signature:e.signature},owner:t,orderType:r}}function M(e,t,r,i=!1,s=!1){return{deferExec:s,postOnly:i,order:{salt:parseInt(e.salt,10),maker:e.maker,signer:e.signer,taker:e.taker,tokenId:e.tokenId,makerAmount:e.makerAmount,takerAmount:e.takerAmount,side:e.side,signatureType:e.signatureType,timestamp:e.timestamp,expiration:e.expiration,metadata:e.metadata,builder:e.builder,signature:e.signature},owner:t,orderType:r}}function Y(e){return"version"in e&&"order"in e?2===e.version||3===e.version:"timestamp"in e&&"metadata"in e&&"builder"in e}let V=(e,t)=>z(e)<=t?e:Math.round((e+Number.EPSILON)*10**t)/10**t,q=(e,t)=>
1z(e)<=t?e:Math.floor(e*10**t)/10**t,N=(e,t)=>z(e)<=t?e:Math.ceil(e*10**t)/10**t,z=e=>{if(Number.isInteger(e))return 0;let t=e.toString().split(".");return t.length<=1?0:t[1].length},K=async e=>{if(!globalThis.crypto?.subtle)throw Error("generateOrderBookSummaryHash: globalThis.crypto.subtle is unavailable. Requires Node >=20 or a secure browser context (HTTPS or localhost).");e.hash="";let t=new TextEncoder().encode(JSON.stringify(e)),r=Array.from(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-1",t))).map(e=>e.toString(16).padStart(2,"0")).join("");return e.hash=r,r},G=(e,t)=>e>=parseFloat(t)&&e<=1-parseFloat(t),U={"0.1":{price:1,size:2,amount:3},"0.01":{price:2,size:2,amount:4},"0.005":{price:3,size:2,amount:5},"0.0025":{price:4,size:2,amount:6},"0.001":{price:3,size:2,amount:5},"0.0001":{price:4,size:2,amount:6}},j={exchange:"0xdFE02Eb6733538f8Ea35D585af8DE5958AD99E40",negRiskAdapter:"0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296",negRiskExchange:"0xC5d563A36AE78145C45a50134d48A1215220f80a",collateral:"0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB",conditionalTokens:"0x69308FB512518e39F9b16112fA8d994F4e2Bf8bB",exchangeV2:"0xE111180000d2663C0091e4f400237545B87B996B",negRiskExchangeV2:"0xe2222d279d744050d28e00520010520000310F59",exchangeV3:"0x9fE6e61422AdB6F610d8597F9684b16912D50C3D"},H={exchange:"0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",negRiskAdapter:"0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296",negRiskExchange:"0xC5d563A36AE78145C45a50134d48A1215220f80a",collateral:"0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB",conditionalTokens:"0x4D97DCd97eC945f40cF65F87097ACe5EA0476045",exchangeV2:"0xE111180000d2663C0091e4f400237545B87B996B",negRiskExchangeV2:"0xe2222d279d744050d28e00520010520000310F59",exchangeV3:"0xe3333700cA9d93003F00f0F71f8515005F6c00Aa"},J=e=>{switch(e){case 137:return H;case 80002:return j;default:throw Error("Invalid network")}};var X=r(16323),W=r(74652);async function Z(e,t,r,i,a,n=2){let{side:o,rawMakerAmt:d,rawTakerAmt:u}=((e,t,r,i)=>{let a=q(r,i.price);if(e===s.BUY){let e=q(t,i.size),r=e/a;return z(r)>i.amount&&z(r=N(r,i.amount+4))>i.amount&&(r=q(r,i.amount)),{side:s.BUY,rawMakerAmt:e,rawTakerAmt:r}}{let e=q(t,i.size),r=e*a;return z(r)>i.amount&&z(r=N(r,i.amount+4))>i.amount&&(r=q(r,i.amount)),{side:s.SELL,rawMakerAmt:e,rawTakerAmt:r}}})(i.side,i.amount,i.price||1,a),c=(0,X.X)(d.toString(),6).toString(),l=(0,X.X)(u.toString(),6).toString();return 1===n?{maker:t,taker:i.taker??W.X,tokenId:i.tokenID,makerAmount:c,takerAmount:l,side:o,signer:e,signatureType:r,feeRateBps:i.feeRateBps?.toString()??"0",nonce:i.nonce?.toString()??"0"}:{maker:t,tokenId:i.tokenID,makerAmount:c,takerAmount:l,side:o,signer:e,signatureType:r,timestamp:Date.now().toString(),metadata:"metadata"in i?i.metadata??h:h,builder:i.builderCode??h}}let Q=[{name:"salt",type:"uint256"},{name:"maker",type:"address"},{name:"signer",type:"address"},{name:"taker",type:"address"},{name:"tokenId",type:"uint256"},{name:"makerAmount",type:"uint256"},{name:"takerAmount",type:"uint256"},{name:"expiration",type:"uint256"},{name:"nonce",type:"uint256"},{name:"feeRateBps",type:"uint256"},{name:"side",type:"uint8"},{name:"signatureType",type:"uint8"}],ee=[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],et=((y={})[y.EOA=0]="EOA",y[y.POLY_PROXY=1]="POLY_PROXY",y[y.POLY_GNOSIS_SAFE=2]="POLY_GNOSIS_SAFE",y);function er(){return`${Math.round(Math.random()*Date.now())}`}var ei=r(83893),es=class{constructor(e,t,r,i=er){this.contractAddress=e,this.chainId=t,this.signer=r,this.generateSalt=i}async buildSignedOrder(e){let t=await this.buildOrder(e),r=this.buildOrderTypedData(t),i=await this.buildOrderSignature(r);return{...t,signature:i}}async buildOrder({maker:e,taker:t,tokenId:r,makerAmount:i,takerAmount:s,side:a,feeRateBps:n,nonce:o,signer:h,expiration:d,signatureType:u}){let c,l,g;h||(h=e);let p=await v(this.signer);if(h!==p)throw Error("signer does not match");return d||(d="0"),u||(u=et.EOA),c=void 0!==t&&t?t:"0x0000000000000000000000000000000000000000",l=void 0!==n&&n?n.toString():"0",g=void 0!==o&&o?o.toString():"0",{salt:this.generateSalt(),maker:e,signer:h,taker:c,tokenId:r,makerAmount:i,takerAmount:s,expiration:d,nonce:g,feeRateBps:l,side:a,signatureType:u}}buildOrderTypedData(e){return{primaryType:"Order",types:{EIP712Domain:ee,Order:Q},domain:{name:"Polymarket CTF Exchange",version:"1",chainId:this.chainId,verifyingContract:this.contractAddress},message:{salt:e.salt,maker:e.maker,signer:e.signer,taker:e.taker,tokenId:e.tokenId,makerAmount:e.makerAmount,takerAmount:e.takerAmount,expiration:e.expiration,nonce:e.nonce,feeRateBps:e.feeRateBps,side:+("BUY"!==e.side),signatureType:e.signatureType}}}buildOrderSignature(e){return delete e.types.EIP712Domain,S({signer:this.signer,domain:e.domain,types:e.types,value:e.message,primaryType:e.primaryType})}buildOrderHash(e){return(0,ei.Zh)(e)}};let ea="Polymarket CTF Exchange",en=[{name:"salt",type:"uint256"},{name:"maker",type:"address"},{name:"signer",type:"address"},{name:"tokenId",type:"uint256"},{name:"makerAmount",type:"uint256"},{name:"takerAmount",type:"uint256"},{name:"side",type:"uint8"},{name:"signatureType",type:"uint8"},{name:"timestamp",type:"uint256"},{name:"metadata",type:"bytes32"},{name:"builder",type:"bytes32"}];var eo=r(18860),eh=r(84428),ed=r(44497);let eu="Order(uint256 salt,address maker,address signer,uint256 tokenId,uint256 makerAmount,uint256 takerAmount,uint8 side,uint8 signatureType,uint256 timestamp,bytes32 metadata,bytes32 builder)",ec=(0,eo.S)((0,eh.nj)(eu)),el=(0,eo.S)((0,eh.nj)("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")),eg=[{name:"contents",type:"Order"},{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"},{name:"salt",type:"bytes32"}],ep=(0,eo.S)((0,eh.nj)(ea));var em=class{appDomainSep;constructor(e,t,r,i=er,s="2"){this.contractAddress=e,this.chainId=t,this.signer=r,this.generateSalt=i,this.domainVersion=s,this.appDomainSep=(0,eo.S)((0,ed.h)([{type:"bytes32"},{type:"bytes32"},{type:"bytes32"},{type:"uint256"},{type:"address"}],[el,ep,(0,eo.S)((0,eh.nj)(s)),BigInt(t),e]))}async buildSignedOrder(e){let t=await this.buildOrder(e),r=this.buildOrderTypedData(t),i=await this.buildOrderSignature(r);return{...t,signature:i}}async buildOrder({maker:e,tokenId:t,makerAmount:r,takerAmount:s,side:a,signer:n,signatureType:o,timestamp:d,metadata:u,builder:c,expiration:l}){if(n||(n=e),o!==i.POLY_1271){let e=await v(this.signer);if(n!==e)throw Error("signer does not match")}return{salt:this.generateSalt(),maker:e,signer:n,tokenId:t,makerAmount:r,takerAmount:s,side:a,signatureType:o??i.EOA,metadata:u??h,builder:c??h,timestamp:d??Date.now().toString(),expiration:l??"0"}}buildOrderTypedData(e){return{primaryType:"Order",types:{EIP712Domain:ee,Order:en},domain:{name:ea,version:this.domainVersion,chainId:this.chainId,verifyingContract:this.contractAddress},message:{salt:e.salt,maker:e.maker,signer:e.signer,tokenId:e.tokenId,makerAmount:e.makerAmount,takerAmount:e.takerAmount,timestamp:e.timestamp,side:+("BUY"!==e.side),signatureType:e.signatureType,metadata:e.metadata,builder:e.builder}}}async buildOrderSignature(e){delete e.types.EIP712Domain;let t=e.message;if(t.signatureType!==i.POLY_1271)return S({signer:this.signer,domain:e.domain,types:e.types,value:e.message,primaryType:e.primaryType});let r=(0,eo.S)((0,ed.h)([{type:"bytes32"},{type:"uint256"},{type:"address"},{type:"address"},{type:"uint256"},{type:"uint256"},{type:"uint256"},{type:"uint8"},{type:"uint8"},{type:"uint256"},{type:"bytes32"},{type:"bytes32"}],[ec,BigInt(t.salt),t.maker,t.signer,BigInt(t.tokenId),BigInt(t.makerAmount),BigInt(t.takerAmount),t.side,t.signatureType,BigInt(t.timestamp),t.metadata,t.builder])),s=await S({signer:this.signer,domain:{name:ea,version:this.domainVersion,chainId:this.chainId,verifyingContract:this.contractAddress},types:{TypedDataSign:eg,Order:en},primaryType:"TypedDataSign",value:{contents:e.message,name:"DepositWallet",version:"1",chainId:this.chainId,verifyingContract:t.signer,salt:h}}),a="ba".padStart(4,"0");return`0x${s.slice(2)}${this.appDomainSep.slice(2)}${r.slice(2)}${(0,eh.nj)(eu).slice(2)}${a}`}buildOrderHash(e){return(0,ei.Zh)(e)}},ey=class extends em{constructor(e,t,r,i=er){super(e,t,r,i,"3")}};let ef=async(e,t,r,i,s=2)=>{switch(s){case 1:return ew(e,t,r,i);case 2:return ek(e,t,r,i);
1case 3:return ev(e,t,r,i);default:throw Error(`unsupported order version ${s}`)}},ew=async(e,t,r,i)=>new es(t,r,e).buildSignedOrder(i),ek=async(e,t,r,i)=>new em(t,r,e).buildSignedOrder(i),ev=async(e,t,r,i)=>new ey(t,r,e).buildSignedOrder(i),eS=async(e,t,r,s,a,n,o)=>{let h,d=await v(e),u=void 0===s?d:s,c=r===i.POLY_1271?u:d,l=J(t),g=await Z(c,u,r,a,U[n.tickSize],o);switch(o){case 1:if(r===i.POLY_1271)throw Error("signature type POLY_1271 is not supported for v1 orders");h=n.negRisk?l.negRiskExchange:l.exchange;break;case 2:h=n.negRisk?l.negRiskExchangeV2:l.exchangeV2;break;case 3:h=l.exchangeV3;break;default:throw Error(`unsupported order version ${o}`)}return ef(e,h,t,g,o)};async function eT(e,t,r,i,a,n=2){let{side:o,rawMakerAmt:d,rawTakerAmt:u}=((e,t,r,i)=>{let a=V(r,i.price);if(e===s.BUY){let e=q(t,i.size),r=e*a;return z(r)>i.amount&&z(r=N(r,i.amount+4))>i.amount&&(r=q(r,i.amount)),{side:s.BUY,rawMakerAmt:r,rawTakerAmt:e}}{let e=q(t,i.size),r=e*a;return z(r)>i.amount&&z(r=N(r,i.amount+4))>i.amount&&(r=q(r,i.amount)),{side:s.SELL,rawMakerAmt:e,rawTakerAmt:r}}})(i.side,i.size,i.price,a),c=(0,X.X)(d.toString(),6).toString(),l=(0,X.X)(u.toString(),6).toString();return 1===n?{maker:t,taker:i.taker??W.X,tokenId:i.tokenID,makerAmount:c,takerAmount:l,side:o,signer:e,signatureType:r,feeRateBps:i.feeRateBps?.toString()??"0",nonce:i.nonce?.toString()??"0",expiration:void 0!==i.expiration?i.expiration.toString():"0"}:{maker:t,tokenId:i.tokenID,makerAmount:c,takerAmount:l,side:o,signer:e,signatureType:r,timestamp:Date.now().toString(),metadata:"metadata"in i?i.metadata??h:h,builder:i.builderCode??h,expiration:void 0!==i.expiration?i.expiration.toString():"0"}}let eA=async(e,t,r,s,a,n,o)=>{let h,d=await v(e),u=void 0===s?d:s,c=r===i.POLY_1271?u:d,l=J(t),g=await eT(c,u,r,a,U[n.tickSize],o);switch(o){case 1:if(r===i.POLY_1271)throw Error("signature type POLY_1271 is not supported for v1 orders");h=n.negRisk?l.negRiskExchange:l.exchange;break;case 2:h=n.negRisk?l.negRiskExchangeV2:l.exchangeV2;break;case 3:h=l.exchangeV3;break;default:throw Error(`unsupported order version ${o}`)}return ef(e,h,t,g,o)},eb=async(e,t,r,s,a)=>{if(!eE(a.makerAmount)||!eE(a.takerAmount))throw Error("makerAmount and takerAmount must be positive decimal integers");let n=await v(e),o=s??n,d=r===i.POLY_1271?o:n;return await ef(e,J(t).exchangeV3,t,{maker:o,signer:d,tokenId:a.tokenID,makerAmount:a.makerAmount,takerAmount:a.takerAmount,side:a.side,signatureType:r,timestamp:Date.now().toString(),metadata:a.metadata??h,builder:a.builderCode??h,expiration:a.expiration?.toString()??"0"},3)},eE=e=>/^[0-9]+$/.test(e)&&BigInt(e)>0n;var eO=class{signer;chainId;signatureType;funderAddress;getSigner;constructor(e,t,r,s,a){this.signer=e,this.chainId=t,this.signatureType=void 0===r?i.EOA:r,this.funderAddress=s,this.getSigner=a}async buildOrder(e,t,r){return eA(await this.resolveSigner(),this.chainId,this.signatureType,this.funderAddress,e,t,r)}async buildMarketOrder(e,t,r){return eS(await this.resolveSigner(),this.chainId,this.signatureType,this.funderAddress,e,t,r)}async buildExchangeV3OrderFromAmounts(e){return eb(await this.resolveSigner(),this.chainId,this.signatureType,this.funderAddress,e)}
1async resolveSigner(){if(this.getSigner){let e=await this.getSigner();if(!e)throw Error("getSigner() function returned undefined or null");return e}return this.signer}},e$=class{host;chainId;signer;creds;orderBuilder;tickSizes;negRisk;feeInfos;feeRates;builderFeeRates;tokenConditionMap;useServerTime;builderConfig;signatureType;funderAddress;cachedVersion;retryOnError;throwOnError;feeSlippage;constructor({host:e,chain:t,signer:r,creds:s,signatureType:a,funderAddress:n,useServerTime:o,builderConfig:h,getSigner:d,retryOnError:u,throwOnError:c,feeSlippage:l}){this.host=e.endsWith("/")?e.slice(0,-1):e,this.chainId=t,void 0!==r&&(this.signer=r),void 0!==s&&(this.creds=s),this.orderBuilder=new eO(r,t,a,n,d),this.signatureType=a??i.EOA,this.funderAddress=n,this.tickSizes={},this.negRisk={},this.feeRates={},this.feeInfos={},this.builderFeeRates={},this.tokenConditionMap={},this.retryOnError=u,this.throwOnError=c,this.feeSlippage=l??0,w(this.feeSlippage),this.useServerTime=o,void 0!==h&&(this.builderConfig=h)}async getOk(){return this.get(`${this.host}/ok`)}async postHeartbeat(e=""){this.canL2Auth();let t=JSON.stringify({heartbeat_id:e}),r=await E(this.signer,this.creds,{method:_,requestPath:d,body:t}
1,this.useServerTime?await this.getServerTime():void 0);return this.post(`${this.host}${d}`,{headers:r,data:{heartbeat_id:e}})}async getVersion(){return(await this.get(`${this.host}/version`))?.version??2}async getServerTime(){return this.get(`${this.host}/time`)}async getSamplingSimplifiedMarkets(e=n){return this.get(`${this.host}/sampling-simplified-markets`,{params:{next_cursor:e}})}async getSamplingMarkets(e=n){return this.get(`${this.host}/sampling-markets`,{params:{next_cursor:e}})}async getSimplifiedMarkets(e=n){return this.get(`${this.host}/simplified-markets`,{params:{next_cursor:e}})}async getMarkets(e=n){return this.get(`${this.host}/markets`,{params:{next_cursor:e}})}async getMarket(e){return this.get(`${this.host}/markets/${e}`)}async getClobMarketInfo(e){let t=await this.get(`${this.host}/clob-markets/${e}`);if(!t?.t)throw Error(`failed to fetch market info for condition id ${e}`);for(let r of t.t){if(!r)continue;let i=r.t;this.tokenConditionMap[i]=e,this.tickSizes[i]=t.mts.toString(),this.negRisk[i]=t.nr??!1,this.feeInfos[i]={rate:t.fd?.r??0,exponent:t.fd?.e??0}}return t}async getOrderBook(e){return this.get(`${this.host}/book`,{params:{token_id:e}})}async getOrderBooks(e){return this.post(`${this.host}/books`,{data:e})}async getTickSize(e){if(e in this.tickSizes)return this.tickSizes[e];if(e in this.tokenConditionMap)return await this.getClobMarketInfo(this.tokenConditionMap[e]),this.tickSizes[e];let t=await this.get(`${this.host}/tick-size`,{params:{token_id:e}});return this.tickSizes[e]=t.minimum_tick_size.toString(),this.tickSizes[e]}async getNegRisk(e){if(e in this.negRisk)return this.negRisk[e];if(e in this.tokenConditionMap)return await this.getClobMarketInfo(this.tokenConditionMap[e]),this.negRisk[e];let t=await this.get(`${this.host}/neg-risk`,{params:{token_id:e}});return this.negRisk[e]=t.neg_risk,this.negRisk[e]}async getFeeRateBps(e){if(e in this.feeRates)return this.feeRates[e];let t=await this.get(`${this.host}/fee-rate`,{params:{token_id:e}});return this.feeRates[e]=t.base_fee,this.feeRates[e]}async getFeeExponent(e){return e in this.feeInfos||await this._ensureMarketInfoCached(e),this.feeInfos[e].exponent}async getOrderBookHash(e){return K(e)}async getMidpoint(e){return this.get(`${this.host}/midpoint`,{params:{token_id:e}})}async getMidpoints(e){return this.post(`${this.host}/midpoints`,{data:e})}async getPrice(e,t){return this.get(`${this.host}/price`,{params:{token_id:e,side:t}})}async getPrices(e){return this.post(`${this.host}/prices`,{data:e})}async getSpread(e){return this.get(`${this.host}/spread`,{params:{token_id:e}})}async getSpreads(e){return this.post(`${this.host}/spreads`,{data:e})}async getLastTradePrice(e){return this.get(`${this.host}/last-trade-price`,{params:{token_id:e}})}async getLastTradesPrices(e){return this.post(`${this.host}/last-trades-prices`,{data:e})}async getPricesHistory(e){if(!e.interval&&(void 0===e.startTs||void 0===e.endTs))throw Error("getPricesHistory requires either interval or both startTs and endTs");return this.get(`${this.host}/prices-history`,{params:e})}async createApiKey(e){this.canL1Auth();let t=`${this.host}/auth/api-key`,r=await b(this.signer,this.chainId,e,this.useServerTime?await this.get
1ServerTime():void 0);return await this.post(t,{headers:r}).then(e=>({key:e.apiKey,secret:e.secret,passphrase:e.passphrase}))}async deriveApiKey(e){this.canL1Auth();let t=`${this.host}/auth/derive-api-key`,r=await b(this.signer,this.chainId,e,this.useServerTime?await this.getServerTime():void 0);return await this.get(t,{headers:r}).then(e=>({key:e.apiKey,secret:e.secret,passphrase:e.passphrase}))}async createOrDeriveApiKey(e){return this.createApiKey(e).then(t=>t.key?t:this.deriveApiKey(e))}async getApiKeys(){this.canL2Auth();let e="/auth/api-keys",t=await E(this.signer,this.creds,{method:"GET",requestPath:e},this.useServerTime?await this.getServerTime():void 0);return this.get(`${this.host}${e}`,{headers:t})}async getClosedOnlyMode(){this.canL2Auth();let e="/auth/ban-status/closed-only",t=await E(this.signer,this.creds,{method:"GET",requestPath:e},this.useServerTime?await this.getServerTime():void 0);return this.get(`${this.host}${e}`,{headers:t})}async deleteApiKey(){this.canL2Auth();let e="/auth/api-key",t=await E(this.signer,this.creds,{method:C,requestPath:e}
1,this.useServerTime?await this.getServerTime():void 0);return this.del(`${this.host}${e}`,{headers:t})}async createReadonlyApiKey(){this.canL2Auth();let e="/auth/readonly-api-key",t=await E(this.signer,this.creds,{method:_,requestPath:e},this.useServerTime?await this.getServerTime():void 0);return this.post(`${this.host}${e}`,{headers:t})}async getReadonlyApiKeys(){this.canL2Auth();let e="/auth/readonly-api-keys",t=await E(this.signer,this.creds,{method:"GET",requestPath:e},this.useServerTime?await this.getServerTime():void 0);return this.get(`${this.host}${e}`,{headers:t})}async deleteReadonlyApiKey(e){this.canL2Auth();let t="/auth/readonly-api-key",r={key:e},i={method:C,requestPath:t,body:JSON.stringify(r)},s=await E(this.signer,this.creds,i,this.useServerTime?await this.getServerTime():void 0);return this.del(`${this.host}${t}`,{headers:s,data:r})}async getOrder(e){this.canL2Auth();let t=`/data/order/${e}`,r=await E(this.signer,this.creds,{method:"GET",requestPath:t},this.useServerTime?await this.getServerTime():void 0);return this.get(`${this.host}${t}`,{headers:r})}async getTrades(e,t=!1,r){this.canL2Auth();let i=await E(this.signer,this.creds,{method:"GET",requestPath:u}
1,this.useServerTime?await this.getServerTime():void 0),s=[];for(r=r||n;r!==o&&(r===n||!t);){let t={...e,next_cursor:r},a=await this.get(`${this.host}${u}`,{headers:i,params:t});r=a.next_cursor,s=[...s,...a.data]}return s}async getTradesPaginated(e,t){this.canL2Auth();let r=await E(this.signer,this.creds,{method:"GET",requestPath:u},this.useServerTime?await this.getServerTime():void 0);t=t||n;let i={...e,next_cursor:t},{data:s,...a}=await this.get(`${this.host}${u}`,{headers:r,params:i});return{trades:Array.isArray(s)?[...s]:[],...a}}async getBuilderTrades(e,t){if(!e.builder_code||e.builder_code===h)throw Error("builderCode is required and cannot be zero");let r={...e,next_cursor:t||n},{data:i,...s}=await this.get(`${this.host}/builder/trades`,{params:r});return{trades:Array.isArray(i)?[...i]:[],...s}}async getNotifications(){this.canL2Auth();let e="/notifications",t=await E(this.signer,this.creds,{method:"GET",requestPath:e},this.useServerTime?await this.getServerTime():void 0);return this.get(`${this.host}${e}`,{headers:t,params:{signature_type:this.orderBuilder.signatureType}})}async dropNotifications(e){let t;this.canL2Auth();let r="/notifications",i=await E(this.signer,this.creds,{method:C,requestPath:r}
1,this.useServerTime?await this.getServerTime():void 0);return this.del(`${this.host}${r}`,{headers:i,params:(t={},void 0!==e&&void 0!==e.ids&&(t.ids=e?.ids.join(",")),t)})}async getBalanceAllowance(e){this.canL2Auth();let t="/balance-allowance",r=await E(this.signer,this.creds,{method:"GET",requestPath:t},this.useServerTime?await this.getServerTime():void 0),i={...e,signature_type:this.orderBuilder.signatureType};return this.get(`${this.host}${t}`,{headers:r,params:i})}async updateBalanceAllowance(e){this.canL2Auth();let t="/balance-allowance/update",r=await E(this.signer,this.creds,{method:"GET",requestPath:t},this.useServerTime?await this.getServerTime():void 0),i={...e,signature_type:this.orderBuilder.signatureType};return this.get(`${this.host}${t}`,{headers:r,params:i})}async createOrder(e,t){this.canL1Auth();let r={...e};this.builderConfig?.builderCode&&!r.builderCode&&(r.builderCode=this.builderConfig.builderCode);let{tokenID:i}=r,a=await this._resolveTickSize(i,t?.tickSize);if(!G(r.price,a))throw Error(`invalid price (${r.price}), min: ${parseFloat(a)} - max: ${1-parseFloat(a)}`);r.price=V(r.price,U[a].price);let n=t?.version??await this.resolveVersion();1!==n&&r.side===s.BUY&&"userUSDCBalance"in r&&void 0!==r.userUSDCBalance&&(r.size=await this.adjustBuyAmountForBalance(i,r.size*r.price,r.price,r.userUSDCBalance,r.builderCode)/r.price);let o=t?.negRisk??await this.getNegRisk(i);if(1===n){let e="feeRateBps"in r?r.feeRateBps:void 0;r.feeRateBps=await this._resolveFeeRateBps(i,e)}return this.orderBuilder.buildOrder(r,{tickSize:a,negRisk:o},n)}async createMarketOrder(e,t){this.canL1Auth();let{tokenID:r}=e;await this._ensureMarketInfoCached(r);let i=await this._resolveTickSize(r,t?.tickSize);if(e.price||(e.price=await this.calculateMarketPrice(r,e.side,e.amount,e.orderType)),!G(e.price,i))throw Error(`invalid price (${e.price}), min: ${parseFloat(i)} - max: ${1-parseFloat(i)}`);let a={...e};if(this.builderConfig?.builderCode&&!a.builderCode&&(a.builderCode=this.builderConfig.builderCode),await this.ensureBuilderFeeRateCached(a.builderCode),a.side===s.BUY&&"userUSDCBalance"in a&&void 0!==a.userUSDCBalance){let e=a.price;a.amount=await this.adjustBuyAmountForBalance(r,a.amount,e,a.userUSDCBalance,a.builderCode)}let n=t?.negRisk??await this.getNegRisk(r),o=t?.version??await this.resolveVersion();if(1===o){let e="feeRateBps"in a?a.feeRateBps:void 0;a.feeRateBps=await this._resolveFeeRateBps(r,e)}return this.orderBuilder.buildMarketOrder(a,{tickSize:i,negRisk:n},o)}async createExchangeV3OrderFromAmounts(e){this.canL1Auth();let t={...e};return this.builderConfig?.builderCode&&!t.builderCode&&(t.builderCode=this.builderConfig.builderCode),this.orderBuilder.buildExchangeV3OrderFromAmounts(t)}async createAndPostOrder(e,t,r=a.GTC,i=!1,s=!1){let n;return await this._retryOnVersionUpdate(async()=>{let a=await this.createOrder(e,t);n=await this.postOrder(a,r,i,s)}),n}async createAndPostMarketOrder(e,t,r=a.FOK,i=!1){let s;return await this._retryOnVersionUpdate(async()=>{let a=await this.createMarketOrder(e,t);s=await this.postOrder(a,r,!1,i)}),s}async getOpenOrders(e,t=!1,r){this.canL2Auth();let i="/data/orders",s=await E(this.signer,this.creds,{method:"GET",requestPath:i}
1,this.useServerTime?await this.getServerTime():void 0),a=[];for(r=r||n;r!==o&&(r===n||!t);){let t={...e,next_cursor:r},n=await this.get(`${this.host}${i}`,{headers:s,params:t});r=n.next_cursor,a=[...a,...n.data]}return a}async getPreMigrationOrders(e=!1,t){this.canL2Auth();let r="/data/pre-migration-orders",i=await E(this.signer,this.creds,{method:"GET",requestPath:r},this.useServerTime?await this.getServerTime():void 0),s=[];for(t=t||n;t!==o&&(t===n||!e);){let e={next_cursor:t},a=await this.get(`${this.host}${r}`,{headers:i,params:e});t=a.next_cursor,s=[...s,...a.data]}return s}async postOrder(e,t=a.GTC,r=!1,i=!1){if(this.canL2Auth(),r&&(t===a.FOK||t===a.FAK))throw Error("postOnly is not supported for FOK/FAK orders");let s="/order",n=Y(e)?M(e,this.creds?.key||"",t,r,i):D(e,this.creds?.key||"",t,r,i),o={method:_,requestPath:s,body:JSON.stringify(n)},h=await E(this.signer,this.creds,o,this.useServerTime?await this.getServerTime():void 0),d=await this.post(`${this.host}${s}`,{headers:h,data:n},!0);return this._isOrderVersionMismatch(d)&&await this.resolveVersion(!0),this.throwIfError(d)}async postOrders(e,t=!1,r=!1){if(this.canL2Auth(),t&&e.some(({orderType:e})=>e===a.FOK||e===a.FAK))throw Error("postOnly is not supported for FOK/FAK orders");let i="/orders",s=[];for(let i of e){let{order:e,orderType:a}=i,n=Y(e)?M(e,this.creds?.key||"",a,t,r):D(e,this.creds?.key||"",a,t,r);s.push(n)}let n={method:_,requestPath:i,body:JSON.stringify(s)},o=await E(this.signer,this.creds,n,this.useServerTime?await this.get
1ServerTime():void 0),h=await this.post(`${this.host}${i}`,{headers:o,data:s},!0);return this._isOrderVersionMismatch(h)&&await this.resolveVersion(!0),this.throwIfError(h)}async cancelOrder(e){this.canL2Auth();let t="/order",r={method:C,requestPath:t,body:JSON.stringify(e)},i=await E(this.signer,this.creds,r,this.useServerTime?await this.getServerTime():void 0);return this.del(`${this.host}${t}`,{headers:i,data:e})}async cancelOrders(e){this.canL2Auth();let t="/orders",r={method:C,requestPath:t,body:JSON.stringify(e)},i=await E(this.signer,this.creds,r,this.useServerTime?await this.getServerTime():void 0);return this.del(`${this.host}${t}`,{headers:i,data:e})}async cancelAll(){this.canL2Auth();let e="/cancel-all",t=await E(this.signer,this.creds,{method:C,requestPath:e},this.useServerTime?await this.getServerTime():void 0);return this.del(`${this.host}${e}`,{headers:t})}async cancelMarketOrders(e){this.canL2Auth();let t="/cancel-market-orders",r={method:C,requestPath:t,body:JSON.stringify(e)},i=await E(this.signer,this.creds,r,this.useServerTime?await this.get
1ServerTime():void 0);return this.del(`${this.host}${t}`,{headers:i,data:e})}async isOrderScoring(e){this.canL2Auth();let t="/order-scoring",r=await E(this.signer,this.creds,{method:"GET",requestPath:t},this.useServerTime?await this.getServerTime():void 0);return this.get(`${this.host}${t}`,{headers:r,params:e})}async areOrdersScoring(e){this.canL2Auth();let t="/orders-scoring",r=JSON.stringify(e?.orderIds),i=await E(this.signer,this.creds,{method:_,requestPath:t,body:r},this.useServerTime?await this.getServerTime():void 0);return this.post(`${this.host}${t}`,{headers:i,data:r})}async getEarningsForUserForDay(e){this.canL2Auth();let t="/rewards/user",r=await E(this.signer,this.creds,{method:"GET",requestPath:t},this.useServerTime?await this.getServerTime():void 0),i=[],s=n;for(;s!==o;){let a={date:e,signature_type:this.orderBuilder.signatureType,next_cursor:s},n=await this.get(`${this.host}${t}`,{headers:r,params:a});s=n.next_cursor,i=[...i,...n.data]}return i}async getTotalEarningsForUserForDay(e){this.canL2Auth();let t="/rewards/user/total",r=await E(this.signer,this.creds,{method:"GET",requestPath:t}
1,this.useServerTime?await this.getServerTime():void 0),i={date:e,signature_type:this.orderBuilder.signatureType};return await this.get(`${this.host}${t}`,{headers:r,params:i})}async getUserEarningsAndMarketsConfig(e,t="",r="",i=!1){this.canL2Auth();let s="/rewards/user/markets",a=await E(this.signer,this.creds,{method:"GET",requestPath:s},this.useServerTime?await this.getServerTime():void 0),h=[],d=n;for(;d!==o;){let n={date:e,signature_type:this.orderBuilder.signatureType,next_cursor:d,order_by:t,position:r,no_competition:i},o=await this.get(`${this.host}${s}`,{headers:a,params:n});d=o.next_cursor,h=[...h,...o.data]}return h}async getRewardPercentages(){this.canL2Auth();let e="/rewards/user/percentages",t=await E(this.signer,this.creds,{method:"GET",requestPath:e},this.useServerTime?await this.getServerTime():void 0),r={signature_type:this.orderBuilder.signatureType};return this.get(`${this.host}${e}`,{headers:t,params:r})}async getCurrentRewards(){let e=[],t=n;for(;t!==o;){let r=await this.get(`${this.host}/rewards/markets/current`,{params:{next_cursor:t}});t=r.next_cursor,e=[...e,...r.data]}return e}async getRawRewardsForMarket(e){let t=[],r=n;for(;r!==o;){let i=await this.get(`${this.host}/rewards/markets/${e}`,{params:{next_cursor:r}});r=i.next_cursor,t=[...t,...i.data]}return t}async calculateMarketPrice(e,t,r,i=a.FOK){let n=await this.getOrderBook(e);if(!n)throw Error("no orderbook");if(t===s.BUY){if(!n.asks)throw Error("no match");return((e,t,r)=>{if(!e.length)throw Error("no match");let i=0;for(let r=e.length-1;r>=0;r--){let s=e[r];if((i+=parseFloat(s.size)*parseFloat(s.price))>=t)return parseFloat(s.price)}if(r===a.FOK)throw Error("no match");return parseFloat(e[0].price)})(n.asks,r,i)}if(!n.bids)throw Error("no match");return((e,t,r)=>{if(!e.length)throw Error("no match");let i=0;for(let r=e.length-1;r>=0;r--){let s=e[r];if((i+=parseFloat(s.size))>=t)return parseFloat(s.price)}if(r===a.FOK)throw Error("no match");return parseFloat(e[0].price)})(n.bids,r,i)}async createBuilderApiKey(){this.canL2Auth();let e="/auth/builder-api-key",t=await E(this.signer,this.creds,{method:_,requestPath:e}
1,this.useServerTime?await this.getServerTime():void 0);return this.post(`${this.host}${e}`,{headers:t})}async getBuilderApiKeys(){this.canL2Auth();let e="/auth/builder-api-key",t=await E(this.signer,this.creds,{method:"GET",requestPath:e},this.useServerTime?await this.getServerTime():void 0);return this.get(`${this.host}${e}`,{headers:t})}async revokeBuilderApiKey(){this.canL2Auth();let e="/auth/builder-api-key",t=await E(this.signer,this.creds,{method:C,requestPath:e},this.useServerTime?await this.getServerTime():void 0);return this.del(`${this.host}${e}`,{headers:t})}async getMarketTradesEvents(e){return this.get(`${this.host}/markets/live-activity/${e}`)}canL1Auth(){if(void 0===this.signer)throw c}canL2Auth(){if(void 0===this.signer)throw c;if(void 0===this.creds)throw l}isBuilderOrder(e){return void 0!==e&&e!==h}async getBuilderTakerFeeRate(e){return this.isBuilderOrder(e)?(await this.ensureBuilderFeeRateCached(e),this.builderFeeRates[e??""]?.taker??0):0}async adjustBuyAmountForBalance(e,t,r,i,s){await this._ensureMarketInfoCached(e);let a=await this.getBuilderTakerFeeRate(s);return function(e,t,r,i,s,a,n=0){w(n);let o=i*(t*(1-t))**s*(1+n/100),h=Math.min(e,r),d=h/t*o,u=h*a;return r<=e+d+u?Math.max(r-d-u,0):e}(t,r,i,this.feeInfos[e].rate,this.feeInfos[e].exponent,a,this.feeSlippage)}async _ensureMarketInfoCached(e){if(!(e in this.feeInfos)){if(!(e in this.tokenConditionMap)){let t=await this.get(`${this.host}/markets-by-token/${e}`);if(!t?.condition_id)throw Error(`failed to resolve condition id for token ${e}`);this.tokenConditionMap[e]=t.condition_id}await this.getClobMarketInfo(this.tokenConditionMap[e])}}async ensureBuilderFeeRateCached(e){if(!e||e===h||e in this.builderFeeRates)return;let t=await this.get(`${this.host}/fees/builder-fees/${e}`);this.builderFeeRates[e]={maker:t.builder_maker_fee_rate_bps/1e4,taker:t.builder_taker_fee_rate_bps/1e4}}async _resolveTickSize(e,t){let r=await this.getTickSize(e);if(t){if(parseFloat(t)<parseFloat(r))throw Error(`invalid tick size (${t}), minimum for the market is ${r}`)}else t=r;return t}async _resolveFeeRateBps(e,t){let r=await this.getFeeRateBps(e);if(r>0&&void 0!==t&&t!==r)throw Error(`invalid user provided fee rate: ${t}, fee rate for the market must be ${r}`);return r}async resolveVersion(e=!1){if(!e&&void 0!==this.cachedVersion)return this.cachedVersion;let t=await this.getVersion();return this.cachedVersion=t,t}async _retryOnVersionUpdate(e){let t=await this.resolveVersion();for(let r=0;r<2&&(await e(),t!==await this.resolveVersion());r++);}_isOrderVersionMismatch(e){let t=e?.error;return!!t&&("string"==typeof t?t:JSON.stringify(t)).includes("order_version_mismatch")}throwIfError(e){if(this.throwOnError&&e&&"object"==typeof e&&"error"in e)throw new f("string"==typeof e.error?e.error:JSON.stringify(e.error),e.status,e);return e}async get(e,t,r=!1){let i=await F(e,t);return r?i:this.throwIfError(i)}async post(e,t,r=!1){let i=await P(e,t,this.retryOnError);return r?i:this.throwIfError(i)}async del(e,t,r=!1){let i=await x(e,t);return r?i:this.throwIfError(i)}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.