@polymarket/clob-client-v2 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  2. package/dist/client.cjs +886 -0
  3. package/dist/client.cjs.map +1 -0
  4. package/dist/client.d.cts +165 -0
  5. package/dist/client.d.ts +167 -0
  6. package/dist/client.js +886 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/config.cjs +35 -0
  9. package/dist/config.cjs.map +1 -0
  10. package/dist/config.d.cts +16 -0
  11. package/dist/config.d.ts +16 -0
  12. package/dist/config.js +32 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/constants.cjs +15 -0
  15. package/dist/constants.cjs.map +1 -0
  16. package/dist/constants.js +10 -0
  17. package/dist/constants.js.map +1 -0
  18. package/dist/endpoints.cjs +125 -0
  19. package/dist/endpoints.cjs.map +1 -0
  20. package/dist/endpoints.js +65 -0
  21. package/dist/endpoints.js.map +1 -0
  22. package/dist/errors.cjs +20 -0
  23. package/dist/errors.cjs.map +1 -0
  24. package/dist/errors.d.cts +11 -0
  25. package/dist/errors.d.ts +11 -0
  26. package/dist/errors.js +17 -0
  27. package/dist/errors.js.map +1 -0
  28. package/dist/fees/index.cjs +21 -0
  29. package/dist/fees/index.cjs.map +1 -0
  30. package/dist/fees/index.d.cts +5 -0
  31. package/dist/fees/index.d.ts +5 -0
  32. package/dist/fees/index.js +19 -0
  33. package/dist/fees/index.js.map +1 -0
  34. package/dist/headers/index.cjs +34 -0
  35. package/dist/headers/index.cjs.map +1 -0
  36. package/dist/headers/index.d.cts +9 -0
  37. package/dist/headers/index.d.ts +11 -0
  38. package/dist/headers/index.js +33 -0
  39. package/dist/headers/index.js.map +1 -0
  40. package/dist/http-helpers/index.cjs +109 -0
  41. package/dist/http-helpers/index.cjs.map +1 -0
  42. package/dist/http-helpers/index.js +101 -0
  43. package/dist/http-helpers/index.js.map +1 -0
  44. package/dist/index.cjs +35 -2600
  45. package/dist/index.d.cts +14 -1039
  46. package/dist/index.d.ts +16 -1039
  47. package/dist/index.js +15 -2543
  48. package/dist/order-builder/helpers/buildMarketOrderCreationArgs.cjs +43 -0
  49. package/dist/order-builder/helpers/buildMarketOrderCreationArgs.cjs.map +1 -0
  50. package/dist/order-builder/helpers/buildMarketOrderCreationArgs.js +42 -0
  51. package/dist/order-builder/helpers/buildMarketOrderCreationArgs.js.map +1 -0
  52. package/dist/order-builder/helpers/buildOrder.cjs +30 -0
  53. package/dist/order-builder/helpers/buildOrder.cjs.map +1 -0
  54. package/dist/order-builder/helpers/buildOrder.js +30 -0
  55. package/dist/order-builder/helpers/buildOrder.js.map +1 -0
  56. package/dist/order-builder/helpers/buildOrderCreationArgs.cjs +45 -0
  57. package/dist/order-builder/helpers/buildOrderCreationArgs.cjs.map +1 -0
  58. package/dist/order-builder/helpers/buildOrderCreationArgs.js +44 -0
  59. package/dist/order-builder/helpers/buildOrderCreationArgs.js.map +1 -0
  60. package/dist/order-builder/helpers/calculateBuyMarketPrice.cjs +24 -0
  61. package/dist/order-builder/helpers/calculateBuyMarketPrice.cjs.map +1 -0
  62. package/dist/order-builder/helpers/calculateBuyMarketPrice.js +24 -0
  63. package/dist/order-builder/helpers/calculateBuyMarketPrice.js.map +1 -0
  64. package/dist/order-builder/helpers/calculateSellMarketPrice.cjs +24 -0
  65. package/dist/order-builder/helpers/calculateSellMarketPrice.cjs.map +1 -0
  66. package/dist/order-builder/helpers/calculateSellMarketPrice.js +24 -0
  67. package/dist/order-builder/helpers/calculateSellMarketPrice.js.map +1 -0
  68. package/dist/order-builder/helpers/createMarketOrder.cjs +31 -0
  69. package/dist/order-builder/helpers/createMarketOrder.cjs.map +1 -0
  70. package/dist/order-builder/helpers/createMarketOrder.js +31 -0
  71. package/dist/order-builder/helpers/createMarketOrder.js.map +1 -0
  72. package/dist/order-builder/helpers/createOrder.cjs +31 -0
  73. package/dist/order-builder/helpers/createOrder.cjs.map +1 -0
  74. package/dist/order-builder/helpers/createOrder.js +31 -0
  75. package/dist/order-builder/helpers/createOrder.js.map +1 -0
  76. package/dist/order-builder/helpers/getMarketOrderRawAmounts.cjs +36 -0
  77. package/dist/order-builder/helpers/getMarketOrderRawAmounts.cjs.map +1 -0
  78. package/dist/order-builder/helpers/getMarketOrderRawAmounts.js +36 -0
  79. package/dist/order-builder/helpers/getMarketOrderRawAmounts.js.map +1 -0
  80. package/dist/order-builder/helpers/getOrderRawAmounts.cjs +36 -0
  81. package/dist/order-builder/helpers/getOrderRawAmounts.cjs.map +1 -0
  82. package/dist/order-builder/helpers/getOrderRawAmounts.js +36 -0
  83. package/dist/order-builder/helpers/getOrderRawAmounts.js.map +1 -0
  84. package/dist/order-builder/helpers/roundingConfig.cjs +28 -0
  85. package/dist/order-builder/helpers/roundingConfig.cjs.map +1 -0
  86. package/dist/order-builder/helpers/roundingConfig.js +27 -0
  87. package/dist/order-builder/helpers/roundingConfig.js.map +1 -0
  88. package/dist/order-builder/index.d.ts +1 -0
  89. package/dist/order-builder/orderBuilder.cjs +51 -0
  90. package/dist/order-builder/orderBuilder.cjs.map +1 -0
  91. package/dist/order-builder/orderBuilder.d.cts +37 -0
  92. package/dist/order-builder/orderBuilder.d.ts +39 -0
  93. package/dist/order-builder/orderBuilder.js +51 -0
  94. package/dist/order-builder/orderBuilder.js.map +1 -0
  95. package/dist/order-utils/exchangeOrderBuilderV1.cjs +128 -0
  96. package/dist/order-utils/exchangeOrderBuilderV1.cjs.map +1 -0
  97. package/dist/order-utils/exchangeOrderBuilderV1.d.ts +2 -0
  98. package/dist/order-utils/exchangeOrderBuilderV1.js +127 -0
  99. package/dist/order-utils/exchangeOrderBuilderV1.js.map +1 -0
  100. package/dist/order-utils/exchangeOrderBuilderV2.cjs +190 -0
  101. package/dist/order-utils/exchangeOrderBuilderV2.cjs.map +1 -0
  102. package/dist/order-utils/exchangeOrderBuilderV2.d.ts +2 -0
  103. package/dist/order-utils/exchangeOrderBuilderV2.js +189 -0
  104. package/dist/order-utils/exchangeOrderBuilderV2.js.map +1 -0
  105. package/dist/order-utils/index.d.ts +7 -0
  106. package/dist/order-utils/model/ctfExchangeV1TypedData.cjs +60 -0
  107. package/dist/order-utils/model/ctfExchangeV1TypedData.cjs.map +1 -0
  108. package/dist/order-utils/model/ctfExchangeV1TypedData.js +57 -0
  109. package/dist/order-utils/model/ctfExchangeV1TypedData.js.map +1 -0
  110. package/dist/order-utils/model/ctfExchangeV2TypedData.cjs +56 -0
  111. package/dist/order-utils/model/ctfExchangeV2TypedData.cjs.map +1 -0
  112. package/dist/order-utils/model/ctfExchangeV2TypedData.js +53 -0
  113. package/dist/order-utils/model/ctfExchangeV2TypedData.js.map +1 -0
  114. package/dist/order-utils/model/eip712.cjs +24 -0
  115. package/dist/order-utils/model/eip712.cjs.map +1 -0
  116. package/dist/order-utils/model/eip712.d.cts +9 -0
  117. package/dist/order-utils/model/eip712.d.ts +9 -0
  118. package/dist/order-utils/model/eip712.js +23 -0
  119. package/dist/order-utils/model/eip712.js.map +1 -0
  120. package/dist/order-utils/model/order.d.cts +5 -0
  121. package/dist/order-utils/model/order.d.ts +5 -0
  122. package/dist/order-utils/model/orderDataV1.d.cts +68 -0
  123. package/dist/order-utils/model/orderDataV1.d.ts +69 -0
  124. package/dist/order-utils/model/orderDataV2.d.cts +68 -0
  125. package/dist/order-utils/model/orderDataV2.d.ts +69 -0
  126. package/dist/order-utils/model/side.cjs +11 -0
  127. package/dist/order-utils/model/side.cjs.map +1 -0
  128. package/dist/order-utils/model/side.d.cts +8 -0
  129. package/dist/order-utils/model/side.d.ts +8 -0
  130. package/dist/order-utils/model/side.js +10 -0
  131. package/dist/order-utils/model/side.js.map +1 -0
  132. package/dist/order-utils/model/signatureTypeV1.cjs +21 -0
  133. package/dist/order-utils/model/signatureTypeV1.cjs.map +1 -0
  134. package/dist/order-utils/model/signatureTypeV1.d.cts +18 -0
  135. package/dist/order-utils/model/signatureTypeV1.d.ts +18 -0
  136. package/dist/order-utils/model/signatureTypeV1.js +20 -0
  137. package/dist/order-utils/model/signatureTypeV1.js.map +1 -0
  138. package/dist/order-utils/model/signatureTypeV2.cjs +25 -0
  139. package/dist/order-utils/model/signatureTypeV2.cjs.map +1 -0
  140. package/dist/order-utils/model/signatureTypeV2.d.cts +22 -0
  141. package/dist/order-utils/model/signatureTypeV2.d.ts +22 -0
  142. package/dist/order-utils/model/signatureTypeV2.js +24 -0
  143. package/dist/order-utils/model/signatureTypeV2.js.map +1 -0
  144. package/dist/order-utils/utils.cjs +9 -0
  145. package/dist/order-utils/utils.cjs.map +1 -0
  146. package/dist/order-utils/utils.js +8 -0
  147. package/dist/order-utils/utils.js.map +1 -0
  148. package/dist/signing/constants.cjs +7 -0
  149. package/dist/signing/constants.cjs.map +1 -0
  150. package/dist/signing/constants.js +6 -0
  151. package/dist/signing/constants.js.map +1 -0
  152. package/dist/signing/eip712.cjs +51 -0
  153. package/dist/signing/eip712.cjs.map +1 -0
  154. package/dist/signing/eip712.d.ts +2 -0
  155. package/dist/signing/eip712.js +51 -0
  156. package/dist/signing/eip712.js.map +1 -0
  157. package/dist/signing/hmac.cjs +40 -0
  158. package/dist/signing/hmac.cjs.map +1 -0
  159. package/dist/signing/hmac.js +39 -0
  160. package/dist/signing/hmac.js.map +1 -0
  161. package/dist/signing/index.d.ts +2 -0
  162. package/dist/signing/signer.cjs +41 -0
  163. package/dist/signing/signer.cjs.map +1 -0
  164. package/dist/signing/signer.d.cts +17 -0
  165. package/dist/signing/signer.d.ts +17 -0
  166. package/dist/signing/signer.js +39 -0
  167. package/dist/signing/signer.js.map +1 -0
  168. package/dist/types/clob.cjs +35 -0
  169. package/dist/types/clob.cjs.map +1 -0
  170. package/dist/types/clob.d.cts +425 -0
  171. package/dist/types/clob.d.ts +425 -0
  172. package/dist/types/clob.js +32 -0
  173. package/dist/types/clob.js.map +1 -0
  174. package/dist/types/index.d.ts +5 -0
  175. package/dist/types/ordersV1.cjs +29 -0
  176. package/dist/types/ordersV1.cjs.map +1 -0
  177. package/dist/types/ordersV1.d.cts +115 -0
  178. package/dist/types/ordersV1.d.ts +116 -0
  179. package/dist/types/ordersV1.js +28 -0
  180. package/dist/types/ordersV1.js.map +1 -0
  181. package/dist/types/ordersV2.cjs +30 -0
  182. package/dist/types/ordersV2.cjs.map +1 -0
  183. package/dist/types/ordersV2.d.cts +113 -0
  184. package/dist/types/ordersV2.d.ts +114 -0
  185. package/dist/types/ordersV2.js +29 -0
  186. package/dist/types/ordersV2.js.map +1 -0
  187. package/dist/types/unifiedOrder.cjs +10 -0
  188. package/dist/types/unifiedOrder.cjs.map +1 -0
  189. package/dist/types/unifiedOrder.d.cts +44 -0
  190. package/dist/types/unifiedOrder.d.ts +45 -0
  191. package/dist/types/unifiedOrder.js +9 -0
  192. package/dist/types/unifiedOrder.js.map +1 -0
  193. package/dist/utilities.cjs +50 -0
  194. package/dist/utilities.cjs.map +1 -0
  195. package/dist/utilities.js +43 -0
  196. package/dist/utilities.js.map +1 -0
  197. package/package.json +3 -3
  198. package/dist/index.cjs.map +0 -1
  199. package/dist/index.js.map +0 -1
@@ -0,0 +1,886 @@
1
+ const require_constants = require('./constants.cjs');
2
+ const require_endpoints = require('./endpoints.cjs');
3
+ const require_errors = require('./errors.cjs');
4
+ const require_index = require('./fees/index.cjs');
5
+ const require_index$1 = require('./headers/index.cjs');
6
+ const require_index$2 = require('./http-helpers/index.cjs');
7
+ const require_signatureTypeV2 = require('./order-utils/model/signatureTypeV2.cjs');
8
+ const require_side = require('./order-utils/model/side.cjs');
9
+ const require_clob = require('./types/clob.cjs');
10
+ const require_ordersV1 = require('./types/ordersV1.cjs');
11
+ const require_ordersV2 = require('./types/ordersV2.cjs');
12
+ const require_unifiedOrder = require('./types/unifiedOrder.cjs');
13
+ const require_utilities = require('./utilities.cjs');
14
+ const require_calculateBuyMarketPrice = require('./order-builder/helpers/calculateBuyMarketPrice.cjs');
15
+ const require_calculateSellMarketPrice = require('./order-builder/helpers/calculateSellMarketPrice.cjs');
16
+ const require_roundingConfig = require('./order-builder/helpers/roundingConfig.cjs');
17
+ const require_orderBuilder = require('./order-builder/orderBuilder.cjs');
18
+
19
+ //#region src/client.ts
20
+ var ClobClient = class {
21
+ host;
22
+ chainId;
23
+ signer;
24
+ creds;
25
+ orderBuilder;
26
+ tickSizes;
27
+ negRisk;
28
+ feeInfos;
29
+ feeRates;
30
+ builderFeeRates;
31
+ tokenConditionMap;
32
+ useServerTime;
33
+ builderConfig;
34
+ signatureType;
35
+ funderAddress;
36
+ cachedVersion;
37
+ retryOnError;
38
+ throwOnError;
39
+ feeSlippage;
40
+ constructor({ host, chain, signer, creds, signatureType, funderAddress, useServerTime, builderConfig, getSigner, retryOnError, throwOnError, feeSlippage }) {
41
+ this.host = host.endsWith("/") ? host.slice(0, -1) : host;
42
+ this.chainId = chain;
43
+ if (signer !== void 0) this.signer = signer;
44
+ if (creds !== void 0) this.creds = creds;
45
+ this.orderBuilder = new require_orderBuilder.OrderBuilder(signer, chain, signatureType, funderAddress, getSigner);
46
+ this.signatureType = signatureType ?? require_signatureTypeV2.SignatureTypeV2.EOA;
47
+ this.funderAddress = funderAddress;
48
+ this.tickSizes = {};
49
+ this.negRisk = {};
50
+ this.feeRates = {};
51
+ this.feeInfos = {};
52
+ this.builderFeeRates = {};
53
+ this.tokenConditionMap = {};
54
+ this.retryOnError = retryOnError;
55
+ this.throwOnError = throwOnError;
56
+ this.feeSlippage = feeSlippage ?? 0;
57
+ require_index.validateFeeSlippage(this.feeSlippage);
58
+ this.useServerTime = useServerTime;
59
+ if (builderConfig !== void 0) this.builderConfig = builderConfig;
60
+ }
61
+ async getOk() {
62
+ return this.get(`${this.host}${require_endpoints.OK}`);
63
+ }
64
+ async postHeartbeat(heartbeatId = "") {
65
+ this.canL2Auth();
66
+ const body = JSON.stringify({ heartbeat_id: heartbeatId });
67
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, {
68
+ method: require_index$2.POST,
69
+ requestPath: require_endpoints.HEARTBEAT,
70
+ body
71
+ }, this.useServerTime ? await this.getServerTime() : void 0);
72
+ return this.post(`${this.host}${require_endpoints.HEARTBEAT}`, {
73
+ headers,
74
+ data: { heartbeat_id: heartbeatId }
75
+ });
76
+ }
77
+ async getVersion() {
78
+ return (await this.get(`${this.host}/version`))?.version ?? 2;
79
+ }
80
+ async getServerTime() {
81
+ return this.get(`${this.host}${require_endpoints.TIME}`);
82
+ }
83
+ async getSamplingSimplifiedMarkets(next_cursor = require_constants.INITIAL_CURSOR) {
84
+ return this.get(`${this.host}${require_endpoints.GET_SAMPLING_SIMPLIFIED_MARKETS}`, { params: { next_cursor } });
85
+ }
86
+ async getSamplingMarkets(next_cursor = require_constants.INITIAL_CURSOR) {
87
+ return this.get(`${this.host}${require_endpoints.GET_SAMPLING_MARKETS}`, { params: { next_cursor } });
88
+ }
89
+ async getSimplifiedMarkets(next_cursor = require_constants.INITIAL_CURSOR) {
90
+ return this.get(`${this.host}${require_endpoints.GET_SIMPLIFIED_MARKETS}`, { params: { next_cursor } });
91
+ }
92
+ async getMarkets(next_cursor = require_constants.INITIAL_CURSOR) {
93
+ return this.get(`${this.host}${require_endpoints.GET_MARKETS}`, { params: { next_cursor } });
94
+ }
95
+ async getMarket(conditionID) {
96
+ return this.get(`${this.host}${require_endpoints.GET_MARKET}${conditionID}`);
97
+ }
98
+ async getClobMarketInfo(conditionID) {
99
+ const result = await this.get(`${this.host}${require_endpoints.GET_CLOB_MARKET}${conditionID}`);
100
+ if (!result?.t) throw new Error(`failed to fetch market info for condition id ${conditionID}`);
101
+ for (const token of result.t) {
102
+ if (!token) continue;
103
+ const tokenId = token.t;
104
+ this.tokenConditionMap[tokenId] = conditionID;
105
+ this.tickSizes[tokenId] = result.mts.toString();
106
+ this.negRisk[tokenId] = result.nr ?? false;
107
+ this.feeInfos[tokenId] = {
108
+ rate: result.fd?.r ?? 0,
109
+ exponent: result.fd?.e ?? 0
110
+ };
111
+ }
112
+ return result;
113
+ }
114
+ async getOrderBook(tokenID) {
115
+ return this.get(`${this.host}${require_endpoints.GET_ORDER_BOOK}`, { params: { token_id: tokenID } });
116
+ }
117
+ async getOrderBooks(params) {
118
+ return this.post(`${this.host}${require_endpoints.GET_ORDER_BOOKS}`, { data: params });
119
+ }
120
+ async getTickSize(tokenID) {
121
+ if (tokenID in this.tickSizes) return this.tickSizes[tokenID];
122
+ if (tokenID in this.tokenConditionMap) {
123
+ await this.getClobMarketInfo(this.tokenConditionMap[tokenID]);
124
+ return this.tickSizes[tokenID];
125
+ }
126
+ const result = await this.get(`${this.host}${require_endpoints.GET_TICK_SIZE}`, { params: { token_id: tokenID } });
127
+ this.tickSizes[tokenID] = result.minimum_tick_size.toString();
128
+ return this.tickSizes[tokenID];
129
+ }
130
+ async getNegRisk(tokenID) {
131
+ if (tokenID in this.negRisk) return this.negRisk[tokenID];
132
+ if (tokenID in this.tokenConditionMap) {
133
+ await this.getClobMarketInfo(this.tokenConditionMap[tokenID]);
134
+ return this.negRisk[tokenID];
135
+ }
136
+ const result = await this.get(`${this.host}${require_endpoints.GET_NEG_RISK}`, { params: { token_id: tokenID } });
137
+ this.negRisk[tokenID] = result.neg_risk;
138
+ return this.negRisk[tokenID];
139
+ }
140
+ async getFeeRateBps(tokenID) {
141
+ if (tokenID in this.feeRates) return this.feeRates[tokenID];
142
+ const result = await this.get(`${this.host}${require_endpoints.GET_FEE_RATE}`, { params: { token_id: tokenID } });
143
+ this.feeRates[tokenID] = result.base_fee;
144
+ return this.feeRates[tokenID];
145
+ }
146
+ async getFeeExponent(tokenID) {
147
+ if (tokenID in this.feeInfos) return this.feeInfos[tokenID].exponent;
148
+ await this._ensureMarketInfoCached(tokenID);
149
+ return this.feeInfos[tokenID].exponent;
150
+ }
151
+ /**
152
+ * Calculates the hash for the given orderbook
153
+ * @param orderbook
154
+ * @returns
155
+ */
156
+ async getOrderBookHash(orderbook) {
157
+ return require_utilities.generateOrderBookSummaryHash(orderbook);
158
+ }
159
+ async getMidpoint(tokenID) {
160
+ return this.get(`${this.host}${require_endpoints.GET_MIDPOINT}`, { params: { token_id: tokenID } });
161
+ }
162
+ async getMidpoints(params) {
163
+ return this.post(`${this.host}${require_endpoints.GET_MIDPOINTS}`, { data: params });
164
+ }
165
+ async getPrice(tokenID, side) {
166
+ return this.get(`${this.host}${require_endpoints.GET_PRICE}`, { params: {
167
+ token_id: tokenID,
168
+ side
169
+ } });
170
+ }
171
+ async getPrices(params) {
172
+ return this.post(`${this.host}${require_endpoints.GET_PRICES}`, { data: params });
173
+ }
174
+ async getSpread(tokenID) {
175
+ return this.get(`${this.host}${require_endpoints.GET_SPREAD}`, { params: { token_id: tokenID } });
176
+ }
177
+ async getSpreads(params) {
178
+ return this.post(`${this.host}${require_endpoints.GET_SPREADS}`, { data: params });
179
+ }
180
+ async getLastTradePrice(tokenID) {
181
+ return this.get(`${this.host}${require_endpoints.GET_LAST_TRADE_PRICE}`, { params: { token_id: tokenID } });
182
+ }
183
+ async getLastTradesPrices(params) {
184
+ return this.post(`${this.host}${require_endpoints.GET_LAST_TRADES_PRICES}`, { data: params });
185
+ }
186
+ async getPricesHistory(params) {
187
+ if (!params.interval && (params.startTs === void 0 || params.endTs === void 0)) throw new Error("getPricesHistory requires either interval or both startTs and endTs");
188
+ return this.get(`${this.host}${require_endpoints.GET_PRICES_HISTORY}`, { params });
189
+ }
190
+ /**
191
+ * Creates a new API key for a user
192
+ * @param nonce
193
+ * @returns ApiKeyCreds
194
+ */
195
+ async createApiKey(nonce) {
196
+ this.canL1Auth();
197
+ const endpoint = `${this.host}${require_endpoints.CREATE_API_KEY}`;
198
+ const headers = await require_index$1.createL1Headers(this.signer, this.chainId, nonce, this.useServerTime ? await this.getServerTime() : void 0);
199
+ return await this.post(endpoint, { headers }).then((apiKeyRaw) => {
200
+ return {
201
+ key: apiKeyRaw.apiKey,
202
+ secret: apiKeyRaw.secret,
203
+ passphrase: apiKeyRaw.passphrase
204
+ };
205
+ });
206
+ }
207
+ /**
208
+ * Derives an existing API key for a user
209
+ * @param nonce
210
+ * @returns ApiKeyCreds
211
+ */
212
+ async deriveApiKey(nonce) {
213
+ this.canL1Auth();
214
+ const endpoint = `${this.host}${require_endpoints.DERIVE_API_KEY}`;
215
+ const headers = await require_index$1.createL1Headers(this.signer, this.chainId, nonce, this.useServerTime ? await this.getServerTime() : void 0);
216
+ return await this.get(endpoint, { headers }).then((apiKeyRaw) => {
217
+ return {
218
+ key: apiKeyRaw.apiKey,
219
+ secret: apiKeyRaw.secret,
220
+ passphrase: apiKeyRaw.passphrase
221
+ };
222
+ });
223
+ }
224
+ async createOrDeriveApiKey(nonce) {
225
+ return this.createApiKey(nonce).then((response) => {
226
+ if (!response.key) return this.deriveApiKey(nonce);
227
+ return response;
228
+ });
229
+ }
230
+ async getApiKeys() {
231
+ this.canL2Auth();
232
+ const endpoint = require_endpoints.GET_API_KEYS;
233
+ const headerArgs = {
234
+ method: require_index$2.GET,
235
+ requestPath: endpoint
236
+ };
237
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
238
+ return this.get(`${this.host}${endpoint}`, { headers });
239
+ }
240
+ async getClosedOnlyMode() {
241
+ this.canL2Auth();
242
+ const endpoint = require_endpoints.CLOSED_ONLY;
243
+ const headerArgs = {
244
+ method: require_index$2.GET,
245
+ requestPath: endpoint
246
+ };
247
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
248
+ return this.get(`${this.host}${endpoint}`, { headers });
249
+ }
250
+ async deleteApiKey() {
251
+ this.canL2Auth();
252
+ const endpoint = require_endpoints.DELETE_API_KEY;
253
+ const headerArgs = {
254
+ method: require_index$2.DELETE,
255
+ requestPath: endpoint
256
+ };
257
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
258
+ return this.del(`${this.host}${endpoint}`, { headers });
259
+ }
260
+ async createReadonlyApiKey() {
261
+ this.canL2Auth();
262
+ const endpoint = require_endpoints.CREATE_READONLY_API_KEY;
263
+ const headerArgs = {
264
+ method: require_index$2.POST,
265
+ requestPath: endpoint
266
+ };
267
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
268
+ return this.post(`${this.host}${endpoint}`, { headers });
269
+ }
270
+ async getReadonlyApiKeys() {
271
+ this.canL2Auth();
272
+ const endpoint = require_endpoints.GET_READONLY_API_KEYS;
273
+ const headerArgs = {
274
+ method: require_index$2.GET,
275
+ requestPath: endpoint
276
+ };
277
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
278
+ return this.get(`${this.host}${endpoint}`, { headers });
279
+ }
280
+ async deleteReadonlyApiKey(key) {
281
+ this.canL2Auth();
282
+ const endpoint = require_endpoints.DELETE_READONLY_API_KEY;
283
+ const payload = { key };
284
+ const headerArgs = {
285
+ method: require_index$2.DELETE,
286
+ requestPath: endpoint,
287
+ body: JSON.stringify(payload)
288
+ };
289
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
290
+ return this.del(`${this.host}${endpoint}`, {
291
+ headers,
292
+ data: payload
293
+ });
294
+ }
295
+ async getOrder(orderID) {
296
+ this.canL2Auth();
297
+ const endpoint = `${require_endpoints.GET_ORDER}${orderID}`;
298
+ const headerArgs = {
299
+ method: require_index$2.GET,
300
+ requestPath: endpoint
301
+ };
302
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
303
+ return this.get(`${this.host}${endpoint}`, { headers });
304
+ }
305
+ async getTrades(params, only_first_page = false, next_cursor) {
306
+ this.canL2Auth();
307
+ const endpoint = require_endpoints.GET_TRADES;
308
+ const headerArgs = {
309
+ method: require_index$2.GET,
310
+ requestPath: endpoint
311
+ };
312
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
313
+ let results = [];
314
+ next_cursor = next_cursor || require_constants.INITIAL_CURSOR;
315
+ while (next_cursor !== require_constants.END_CURSOR && (next_cursor === require_constants.INITIAL_CURSOR || !only_first_page)) {
316
+ const _params = {
317
+ ...params,
318
+ next_cursor
319
+ };
320
+ const response = await this.get(`${this.host}${endpoint}`, {
321
+ headers,
322
+ params: _params
323
+ });
324
+ next_cursor = response.next_cursor;
325
+ results = [...results, ...response.data];
326
+ }
327
+ return results;
328
+ }
329
+ async getTradesPaginated(params, next_cursor) {
330
+ this.canL2Auth();
331
+ const endpoint = require_endpoints.GET_TRADES;
332
+ const headerArgs = {
333
+ method: require_index$2.GET,
334
+ requestPath: endpoint
335
+ };
336
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
337
+ next_cursor = next_cursor || require_constants.INITIAL_CURSOR;
338
+ const _params = {
339
+ ...params,
340
+ next_cursor
341
+ };
342
+ const { data, ...rest } = await this.get(`${this.host}${endpoint}`, {
343
+ headers,
344
+ params: _params
345
+ });
346
+ return {
347
+ trades: Array.isArray(data) ? [...data] : [],
348
+ ...rest
349
+ };
350
+ }
351
+ async getBuilderTrades(params, next_cursor) {
352
+ if (!params.builder_code || params.builder_code === require_constants.bytes32Zero) throw new Error("builderCode is required and cannot be zero");
353
+ const _params = {
354
+ ...params,
355
+ next_cursor: next_cursor || require_constants.INITIAL_CURSOR
356
+ };
357
+ const { data, ...rest } = await this.get(`${this.host}${require_endpoints.GET_BUILDER_TRADES}`, { params: _params });
358
+ return {
359
+ trades: Array.isArray(data) ? [...data] : [],
360
+ ...rest
361
+ };
362
+ }
363
+ async getNotifications() {
364
+ this.canL2Auth();
365
+ const endpoint = require_endpoints.GET_NOTIFICATIONS;
366
+ const headerArgs = {
367
+ method: require_index$2.GET,
368
+ requestPath: endpoint
369
+ };
370
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
371
+ return this.get(`${this.host}${endpoint}`, {
372
+ headers,
373
+ params: { signature_type: this.orderBuilder.signatureType }
374
+ });
375
+ }
376
+ async dropNotifications(params) {
377
+ this.canL2Auth();
378
+ const endpoint = require_endpoints.DROP_NOTIFICATIONS;
379
+ const l2HeaderArgs = {
380
+ method: require_index$2.DELETE,
381
+ requestPath: endpoint
382
+ };
383
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
384
+ return this.del(`${this.host}${endpoint}`, {
385
+ headers,
386
+ params: require_index$2.parseDropNotificationParams(params)
387
+ });
388
+ }
389
+ async getBalanceAllowance(params) {
390
+ this.canL2Auth();
391
+ const endpoint = require_endpoints.GET_BALANCE_ALLOWANCE;
392
+ const headerArgs = {
393
+ method: require_index$2.GET,
394
+ requestPath: endpoint
395
+ };
396
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
397
+ const _params = {
398
+ ...params,
399
+ signature_type: this.orderBuilder.signatureType
400
+ };
401
+ return this.get(`${this.host}${endpoint}`, {
402
+ headers,
403
+ params: _params
404
+ });
405
+ }
406
+ async updateBalanceAllowance(params) {
407
+ this.canL2Auth();
408
+ const endpoint = require_endpoints.UPDATE_BALANCE_ALLOWANCE;
409
+ const headerArgs = {
410
+ method: require_index$2.GET,
411
+ requestPath: endpoint
412
+ };
413
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
414
+ const _params = {
415
+ ...params,
416
+ signature_type: this.orderBuilder.signatureType
417
+ };
418
+ return this.get(`${this.host}${endpoint}`, {
419
+ headers,
420
+ params: _params
421
+ });
422
+ }
423
+ async createOrder(userOrder, options) {
424
+ this.canL1Auth();
425
+ const orderToSign = { ...userOrder };
426
+ if (this.builderConfig?.builderCode && !orderToSign.builderCode) orderToSign.builderCode = this.builderConfig.builderCode;
427
+ const { tokenID } = orderToSign;
428
+ const tickSize = await this._resolveTickSize(tokenID, options?.tickSize);
429
+ if (!require_utilities.priceValid(orderToSign.price, tickSize)) throw new Error(`invalid price (${orderToSign.price}), min: ${parseFloat(tickSize)} - max: ${1 - parseFloat(tickSize)}`);
430
+ orderToSign.price = require_utilities.roundNormal(orderToSign.price, require_roundingConfig.ROUNDING_CONFIG[tickSize].price);
431
+ const version = await this.resolveVersion();
432
+ if (version === 2 && orderToSign.side === require_side.Side.BUY && "userUSDCBalance" in orderToSign && orderToSign.userUSDCBalance !== void 0) orderToSign.size = await this.adjustBuyAmountForBalance(tokenID, orderToSign.size * orderToSign.price, orderToSign.price, orderToSign.userUSDCBalance, orderToSign.builderCode) / orderToSign.price;
433
+ const negRisk = options?.negRisk ?? await this.getNegRisk(tokenID);
434
+ if (version === 1) {
435
+ const userFeeRateBps = "feeRateBps" in orderToSign ? orderToSign.feeRateBps : void 0;
436
+ orderToSign.feeRateBps = await this._resolveFeeRateBps(tokenID, userFeeRateBps);
437
+ }
438
+ return this.orderBuilder.buildOrder(orderToSign, {
439
+ tickSize,
440
+ negRisk
441
+ }, version);
442
+ }
443
+ async createMarketOrder(userMarketOrder, options) {
444
+ this.canL1Auth();
445
+ const { tokenID } = userMarketOrder;
446
+ await this._ensureMarketInfoCached(tokenID);
447
+ const tickSize = await this._resolveTickSize(tokenID, options?.tickSize);
448
+ if (!userMarketOrder.price) userMarketOrder.price = await this.calculateMarketPrice(tokenID, userMarketOrder.side, userMarketOrder.amount, userMarketOrder.orderType);
449
+ if (!require_utilities.priceValid(userMarketOrder.price, tickSize)) throw new Error(`invalid price (${userMarketOrder.price}), min: ${parseFloat(tickSize)} - max: ${1 - parseFloat(tickSize)}`);
450
+ const orderToSign = { ...userMarketOrder };
451
+ if (this.builderConfig?.builderCode && !orderToSign.builderCode) orderToSign.builderCode = this.builderConfig.builderCode;
452
+ await this.ensureBuilderFeeRateCached(orderToSign.builderCode);
453
+ if (orderToSign.side === require_side.Side.BUY && "userUSDCBalance" in orderToSign && orderToSign.userUSDCBalance !== void 0) {
454
+ const price = orderToSign.price;
455
+ orderToSign.amount = await this.adjustBuyAmountForBalance(tokenID, orderToSign.amount, price, orderToSign.userUSDCBalance, orderToSign.builderCode);
456
+ }
457
+ const negRisk = options?.negRisk ?? await this.getNegRisk(tokenID);
458
+ const version = await this.resolveVersion();
459
+ if (version === 1) {
460
+ const userFeeRateBps = "feeRateBps" in orderToSign ? orderToSign.feeRateBps : void 0;
461
+ orderToSign.feeRateBps = await this._resolveFeeRateBps(tokenID, userFeeRateBps);
462
+ }
463
+ return this.orderBuilder.buildMarketOrder(orderToSign, {
464
+ tickSize,
465
+ negRisk
466
+ }, version);
467
+ }
468
+ async createAndPostOrder(userOrder, options, orderType = require_clob.OrderType.GTC, postOnly = false, deferExec = false) {
469
+ let postOrderResponse;
470
+ await this._retryOnVersionUpdate(async () => {
471
+ const order = await this.createOrder(userOrder, options);
472
+ postOrderResponse = await this.postOrder(order, orderType, postOnly, deferExec);
473
+ });
474
+ return postOrderResponse;
475
+ }
476
+ async createAndPostMarketOrder(userMarketOrder, options, orderType = require_clob.OrderType.FOK, deferExec = false) {
477
+ let postOrderMarketResponse;
478
+ await this._retryOnVersionUpdate(async () => {
479
+ const order = await this.createMarketOrder(userMarketOrder, options);
480
+ postOrderMarketResponse = await this.postOrder(order, orderType, false, deferExec);
481
+ });
482
+ return postOrderMarketResponse;
483
+ }
484
+ async getOpenOrders(params, only_first_page = false, next_cursor) {
485
+ this.canL2Auth();
486
+ const endpoint = require_endpoints.GET_OPEN_ORDERS;
487
+ const l2HeaderArgs = {
488
+ method: require_index$2.GET,
489
+ requestPath: endpoint
490
+ };
491
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
492
+ let results = [];
493
+ next_cursor = next_cursor || require_constants.INITIAL_CURSOR;
494
+ while (next_cursor !== require_constants.END_CURSOR && (next_cursor === require_constants.INITIAL_CURSOR || !only_first_page)) {
495
+ const _params = {
496
+ ...params,
497
+ next_cursor
498
+ };
499
+ const response = await this.get(`${this.host}${endpoint}`, {
500
+ headers,
501
+ params: _params
502
+ });
503
+ next_cursor = response.next_cursor;
504
+ results = [...results, ...response.data];
505
+ }
506
+ return results;
507
+ }
508
+ async getPreMigrationOrders(only_first_page = false, next_cursor) {
509
+ this.canL2Auth();
510
+ const endpoint = require_endpoints.GET_PRE_MIGRATION_ORDERS;
511
+ const l2HeaderArgs = {
512
+ method: require_index$2.GET,
513
+ requestPath: endpoint
514
+ };
515
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
516
+ let results = [];
517
+ next_cursor = next_cursor || require_constants.INITIAL_CURSOR;
518
+ while (next_cursor !== require_constants.END_CURSOR && (next_cursor === require_constants.INITIAL_CURSOR || !only_first_page)) {
519
+ const _params = { next_cursor };
520
+ const response = await this.get(`${this.host}${endpoint}`, {
521
+ headers,
522
+ params: _params
523
+ });
524
+ next_cursor = response.next_cursor;
525
+ results = [...results, ...response.data];
526
+ }
527
+ return results;
528
+ }
529
+ async postOrder(order, orderType = require_clob.OrderType.GTC, postOnly = false, deferExec = false) {
530
+ this.canL2Auth();
531
+ if (postOnly && (orderType === require_clob.OrderType.FOK || orderType === require_clob.OrderType.FAK)) throw new Error("postOnly is not supported for FOK/FAK orders");
532
+ const endpoint = require_endpoints.POST_ORDER;
533
+ const orderPayload = require_unifiedOrder.isV2Order(order) ? require_ordersV2.orderToJsonV2(order, this.creds?.key || "", orderType, postOnly, deferExec) : require_ordersV1.orderToJsonV1(order, this.creds?.key || "", orderType, postOnly, deferExec);
534
+ const l2HeaderArgs = {
535
+ method: require_index$2.POST,
536
+ requestPath: endpoint,
537
+ body: JSON.stringify(orderPayload)
538
+ };
539
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
540
+ const res = await this.post(`${this.host}${endpoint}`, {
541
+ headers,
542
+ data: orderPayload
543
+ }, true);
544
+ if (this._isOrderVersionMismatch(res)) await this.resolveVersion(true);
545
+ return this.throwIfError(res);
546
+ }
547
+ async postOrders(args, postOnly = false, deferExec = false) {
548
+ this.canL2Auth();
549
+ if (postOnly && args.some(({ orderType }) => orderType === require_clob.OrderType.FOK || orderType === require_clob.OrderType.FAK)) throw new Error("postOnly is not supported for FOK/FAK orders");
550
+ const endpoint = require_endpoints.POST_ORDERS;
551
+ const ordersPayload = [];
552
+ for (const arg of args) {
553
+ const { order, orderType } = arg;
554
+ const orderPayload = require_unifiedOrder.isV2Order(order) ? require_ordersV2.orderToJsonV2(order, this.creds?.key || "", orderType, postOnly, deferExec) : require_ordersV1.orderToJsonV1(order, this.creds?.key || "", orderType, postOnly, deferExec);
555
+ ordersPayload.push(orderPayload);
556
+ }
557
+ const l2HeaderArgs = {
558
+ method: require_index$2.POST,
559
+ requestPath: endpoint,
560
+ body: JSON.stringify(ordersPayload)
561
+ };
562
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
563
+ const res = await this.post(`${this.host}${endpoint}`, {
564
+ headers,
565
+ data: ordersPayload
566
+ }, true);
567
+ if (this._isOrderVersionMismatch(res)) await this.resolveVersion(true);
568
+ return this.throwIfError(res);
569
+ }
570
+ async cancelOrder(payload) {
571
+ this.canL2Auth();
572
+ const endpoint = require_endpoints.CANCEL_ORDER;
573
+ const l2HeaderArgs = {
574
+ method: require_index$2.DELETE,
575
+ requestPath: endpoint,
576
+ body: JSON.stringify(payload)
577
+ };
578
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
579
+ return this.del(`${this.host}${endpoint}`, {
580
+ headers,
581
+ data: payload
582
+ });
583
+ }
584
+ async cancelOrders(ordersHashes) {
585
+ this.canL2Auth();
586
+ const endpoint = require_endpoints.CANCEL_ORDERS;
587
+ const l2HeaderArgs = {
588
+ method: require_index$2.DELETE,
589
+ requestPath: endpoint,
590
+ body: JSON.stringify(ordersHashes)
591
+ };
592
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
593
+ return this.del(`${this.host}${endpoint}`, {
594
+ headers,
595
+ data: ordersHashes
596
+ });
597
+ }
598
+ async cancelAll() {
599
+ this.canL2Auth();
600
+ const endpoint = require_endpoints.CANCEL_ALL;
601
+ const l2HeaderArgs = {
602
+ method: require_index$2.DELETE,
603
+ requestPath: endpoint
604
+ };
605
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
606
+ return this.del(`${this.host}${endpoint}`, { headers });
607
+ }
608
+ async cancelMarketOrders(payload) {
609
+ this.canL2Auth();
610
+ const endpoint = require_endpoints.CANCEL_MARKET_ORDERS;
611
+ const l2HeaderArgs = {
612
+ method: require_index$2.DELETE,
613
+ requestPath: endpoint,
614
+ body: JSON.stringify(payload)
615
+ };
616
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, l2HeaderArgs, this.useServerTime ? await this.getServerTime() : void 0);
617
+ return this.del(`${this.host}${endpoint}`, {
618
+ headers,
619
+ data: payload
620
+ });
621
+ }
622
+ async isOrderScoring(params) {
623
+ this.canL2Auth();
624
+ const endpoint = require_endpoints.IS_ORDER_SCORING;
625
+ const headerArgs = {
626
+ method: require_index$2.GET,
627
+ requestPath: endpoint
628
+ };
629
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
630
+ return this.get(`${this.host}${endpoint}`, {
631
+ headers,
632
+ params
633
+ });
634
+ }
635
+ async areOrdersScoring(params) {
636
+ this.canL2Auth();
637
+ const endpoint = require_endpoints.ARE_ORDERS_SCORING;
638
+ const payload = JSON.stringify(params?.orderIds);
639
+ const headerArgs = {
640
+ method: require_index$2.POST,
641
+ requestPath: endpoint,
642
+ body: payload
643
+ };
644
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
645
+ return this.post(`${this.host}${endpoint}`, {
646
+ headers,
647
+ data: payload
648
+ });
649
+ }
650
+ async getEarningsForUserForDay(date) {
651
+ this.canL2Auth();
652
+ const endpoint = require_endpoints.GET_EARNINGS_FOR_USER_FOR_DAY;
653
+ const headerArgs = {
654
+ method: require_index$2.GET,
655
+ requestPath: endpoint
656
+ };
657
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
658
+ let results = [];
659
+ let next_cursor = require_constants.INITIAL_CURSOR;
660
+ while (next_cursor !== require_constants.END_CURSOR) {
661
+ const params = {
662
+ date,
663
+ signature_type: this.orderBuilder.signatureType,
664
+ next_cursor
665
+ };
666
+ const response = await this.get(`${this.host}${endpoint}`, {
667
+ headers,
668
+ params
669
+ });
670
+ next_cursor = response.next_cursor;
671
+ results = [...results, ...response.data];
672
+ }
673
+ return results;
674
+ }
675
+ async getTotalEarningsForUserForDay(date) {
676
+ this.canL2Auth();
677
+ const endpoint = require_endpoints.GET_TOTAL_EARNINGS_FOR_USER_FOR_DAY;
678
+ const headerArgs = {
679
+ method: require_index$2.GET,
680
+ requestPath: endpoint
681
+ };
682
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
683
+ const params = {
684
+ date,
685
+ signature_type: this.orderBuilder.signatureType
686
+ };
687
+ return await this.get(`${this.host}${endpoint}`, {
688
+ headers,
689
+ params
690
+ });
691
+ }
692
+ async getUserEarningsAndMarketsConfig(date, order_by = "", position = "", no_competition = false) {
693
+ this.canL2Auth();
694
+ const endpoint = require_endpoints.GET_REWARDS_EARNINGS_PERCENTAGES;
695
+ const headerArgs = {
696
+ method: require_index$2.GET,
697
+ requestPath: endpoint
698
+ };
699
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
700
+ let results = [];
701
+ let next_cursor = require_constants.INITIAL_CURSOR;
702
+ while (next_cursor !== require_constants.END_CURSOR) {
703
+ const params = {
704
+ date,
705
+ signature_type: this.orderBuilder.signatureType,
706
+ next_cursor,
707
+ order_by,
708
+ position,
709
+ no_competition
710
+ };
711
+ const response = await this.get(`${this.host}${endpoint}`, {
712
+ headers,
713
+ params
714
+ });
715
+ next_cursor = response.next_cursor;
716
+ results = [...results, ...response.data];
717
+ }
718
+ return results;
719
+ }
720
+ async getRewardPercentages() {
721
+ this.canL2Auth();
722
+ const endpoint = require_endpoints.GET_LIQUIDITY_REWARD_PERCENTAGES;
723
+ const headerArgs = {
724
+ method: require_index$2.GET,
725
+ requestPath: endpoint
726
+ };
727
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
728
+ const _params = { signature_type: this.orderBuilder.signatureType };
729
+ return this.get(`${this.host}${endpoint}`, {
730
+ headers,
731
+ params: _params
732
+ });
733
+ }
734
+ async getCurrentRewards() {
735
+ let results = [];
736
+ let next_cursor = require_constants.INITIAL_CURSOR;
737
+ while (next_cursor !== require_constants.END_CURSOR) {
738
+ const response = await this.get(`${this.host}${require_endpoints.GET_REWARDS_MARKETS_CURRENT}`, { params: { next_cursor } });
739
+ next_cursor = response.next_cursor;
740
+ results = [...results, ...response.data];
741
+ }
742
+ return results;
743
+ }
744
+ async getRawRewardsForMarket(conditionId) {
745
+ let results = [];
746
+ let next_cursor = require_constants.INITIAL_CURSOR;
747
+ while (next_cursor !== require_constants.END_CURSOR) {
748
+ const response = await this.get(`${this.host}${require_endpoints.GET_REWARDS_MARKETS}${conditionId}`, { params: { next_cursor } });
749
+ next_cursor = response.next_cursor;
750
+ results = [...results, ...response.data];
751
+ }
752
+ return results;
753
+ }
754
+ async calculateMarketPrice(tokenID, side, amount, orderType = require_clob.OrderType.FOK) {
755
+ const book = await this.getOrderBook(tokenID);
756
+ if (!book) throw new Error("no orderbook");
757
+ if (side === require_side.Side.BUY) {
758
+ if (!book.asks) throw new Error("no match");
759
+ return require_calculateBuyMarketPrice.calculateBuyMarketPrice(book.asks, amount, orderType);
760
+ } else {
761
+ if (!book.bids) throw new Error("no match");
762
+ return require_calculateSellMarketPrice.calculateSellMarketPrice(book.bids, amount, orderType);
763
+ }
764
+ }
765
+ async createBuilderApiKey() {
766
+ this.canL2Auth();
767
+ const endpoint = require_endpoints.CREATE_BUILDER_API_KEY;
768
+ const headerArgs = {
769
+ method: require_index$2.POST,
770
+ requestPath: endpoint
771
+ };
772
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
773
+ return this.post(`${this.host}${endpoint}`, { headers });
774
+ }
775
+ async getBuilderApiKeys() {
776
+ this.canL2Auth();
777
+ const endpoint = require_endpoints.GET_BUILDER_API_KEYS;
778
+ const headerArgs = {
779
+ method: require_index$2.GET,
780
+ requestPath: endpoint
781
+ };
782
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
783
+ return this.get(`${this.host}${endpoint}`, { headers });
784
+ }
785
+ async revokeBuilderApiKey() {
786
+ this.canL2Auth();
787
+ const endpoint = require_endpoints.REVOKE_BUILDER_API_KEY;
788
+ const headerArgs = {
789
+ method: require_index$2.DELETE,
790
+ requestPath: endpoint
791
+ };
792
+ const headers = await require_index$1.createL2Headers(this.signer, this.creds, headerArgs, this.useServerTime ? await this.getServerTime() : void 0);
793
+ return this.del(`${this.host}${endpoint}`, { headers });
794
+ }
795
+ async getMarketTradesEvents(conditionID) {
796
+ return this.get(`${this.host}${require_endpoints.GET_MARKET_TRADES_EVENTS}${conditionID}`);
797
+ }
798
+ canL1Auth() {
799
+ if (this.signer === void 0) throw require_errors.L1_AUTH_UNAVAILABLE_ERROR;
800
+ }
801
+ canL2Auth() {
802
+ if (this.signer === void 0) throw require_errors.L1_AUTH_UNAVAILABLE_ERROR;
803
+ if (this.creds === void 0) throw require_errors.L2_AUTH_NOT_AVAILABLE;
804
+ }
805
+ isBuilderOrder(builderCode) {
806
+ return builderCode !== void 0 && builderCode !== require_constants.bytes32Zero;
807
+ }
808
+ async getBuilderTakerFeeRate(builderCode) {
809
+ if (!this.isBuilderOrder(builderCode)) return 0;
810
+ await this.ensureBuilderFeeRateCached(builderCode);
811
+ return this.builderFeeRates[builderCode ?? ""]?.taker ?? 0;
812
+ }
813
+ async adjustBuyAmountForBalance(tokenID, amount, price, userUSDCBalance, builderCode) {
814
+ await this._ensureMarketInfoCached(tokenID);
815
+ const builderTakerFeeRate = await this.getBuilderTakerFeeRate(builderCode);
816
+ return require_index.adjustBuyAmountForFees(amount, price, userUSDCBalance, this.feeInfos[tokenID].rate, this.feeInfos[tokenID].exponent, builderTakerFeeRate, this.feeSlippage);
817
+ }
818
+ async _ensureMarketInfoCached(tokenID) {
819
+ if (tokenID in this.feeInfos) return;
820
+ if (!(tokenID in this.tokenConditionMap)) {
821
+ const result = await this.get(`${this.host}${require_endpoints.GET_MARKET_BY_TOKEN}${tokenID}`);
822
+ if (!result?.condition_id) throw new Error(`failed to resolve condition id for token ${tokenID}`);
823
+ this.tokenConditionMap[tokenID] = result.condition_id;
824
+ }
825
+ await this.getClobMarketInfo(this.tokenConditionMap[tokenID]);
826
+ }
827
+ async ensureBuilderFeeRateCached(builderCode) {
828
+ if (!builderCode || builderCode === require_constants.bytes32Zero) return;
829
+ if (builderCode in this.builderFeeRates) return;
830
+ const result = await this.get(`${this.host}${require_endpoints.GET_BUILDER_FEES}${builderCode}`);
831
+ this.builderFeeRates[builderCode] = {
832
+ maker: result.builder_maker_fee_rate_bps / require_constants.BUILDER_FEES_BPS,
833
+ taker: result.builder_taker_fee_rate_bps / require_constants.BUILDER_FEES_BPS
834
+ };
835
+ }
836
+ async _resolveTickSize(tokenID, tickSize) {
837
+ const minTickSize = await this.getTickSize(tokenID);
838
+ if (tickSize) {
839
+ if (require_utilities.isTickSizeSmaller(tickSize, minTickSize)) throw new Error(`invalid tick size (${tickSize}), minimum for the market is ${minTickSize}`);
840
+ } else tickSize = minTickSize;
841
+ return tickSize;
842
+ }
843
+ async _resolveFeeRateBps(tokenID, userFeeRateBps) {
844
+ const marketFeeRateBps = await this.getFeeRateBps(tokenID);
845
+ if (marketFeeRateBps > 0 && userFeeRateBps !== void 0 && userFeeRateBps !== marketFeeRateBps) throw new Error(`invalid user provided fee rate: ${userFeeRateBps}, fee rate for the market must be ${marketFeeRateBps}`);
846
+ return marketFeeRateBps;
847
+ }
848
+ async resolveVersion(forceUpdate = false) {
849
+ if (!forceUpdate && this.cachedVersion !== void 0) return this.cachedVersion;
850
+ const apiVersion = await this.getVersion();
851
+ this.cachedVersion = apiVersion;
852
+ return apiVersion;
853
+ }
854
+ async _retryOnVersionUpdate(retryFunc) {
855
+ const version = await this.resolveVersion();
856
+ for (let attempt = 0; attempt < 2; attempt++) {
857
+ await retryFunc();
858
+ if (version === await this.resolveVersion()) break;
859
+ }
860
+ }
861
+ _isOrderVersionMismatch(resp) {
862
+ const error = resp?.error;
863
+ if (!error) return false;
864
+ return (typeof error === "string" ? error : JSON.stringify(error)).includes(require_constants.ORDER_VERSION_MISMATCH_ERROR);
865
+ }
866
+ throwIfError(result) {
867
+ if (this.throwOnError && result && typeof result === "object" && "error" in result) throw new require_errors.ApiError(typeof result.error === "string" ? result.error : JSON.stringify(result.error), result.status, result);
868
+ return result;
869
+ }
870
+ async get(endpoint, options, skipThrow = false) {
871
+ const result = await require_index$2.get(endpoint, options);
872
+ return skipThrow ? result : this.throwIfError(result);
873
+ }
874
+ async post(endpoint, options, skipThrow = false) {
875
+ const result = await require_index$2.post(endpoint, options, this.retryOnError);
876
+ return skipThrow ? result : this.throwIfError(result);
877
+ }
878
+ async del(endpoint, options, skipThrow = false) {
879
+ const result = await require_index$2.del(endpoint, options);
880
+ return skipThrow ? result : this.throwIfError(result);
881
+ }
882
+ };
883
+
884
+ //#endregion
885
+ exports.ClobClient = ClobClient;
886
+ //# sourceMappingURL=client.cjs.map