@polymarket/clob-client-v2 1.0.3 → 1.0.4

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.
package/dist/index.d.cts CHANGED
@@ -69,7 +69,8 @@ interface OrderResponse {
69
69
  success: boolean;
70
70
  errorMsg: string;
71
71
  orderID: string;
72
- transactionsHashes: string[];
72
+ transactionsHashes?: string[];
73
+ tradeIDs?: string[];
73
74
  status: string;
74
75
  takingAmount: string;
75
76
  makingAmount: string;
@@ -103,7 +104,9 @@ interface MakerOrder {
103
104
  fee_rate_bps: string;
104
105
  asset_id: string;
105
106
  outcome: string;
106
- side: Side;
107
+ side?: Side;
108
+ builder_fee?: string;
109
+ builder_code?: string;
107
110
  }
108
111
  interface Trade {
109
112
  id: string;
@@ -116,13 +119,15 @@ interface Trade {
116
119
  price: string;
117
120
  status: string;
118
121
  match_time: string;
122
+ match_time_nano?: string;
119
123
  last_update: string;
120
124
  outcome: string;
121
125
  bucket_index: number;
122
126
  owner: string;
123
127
  maker_address: string;
124
128
  maker_orders: MakerOrder[];
125
- transaction_hash: string;
129
+ transaction_hash?: string;
130
+ err_msg?: string | null;
126
131
  trader_side: "TAKER" | "MAKER";
127
132
  }
128
133
  interface ApiKeysResponse {
@@ -207,7 +212,7 @@ interface BalanceAllowanceParams {
207
212
  }
208
213
  interface BalanceAllowanceResponse {
209
214
  balance: string;
210
- allowance: string;
215
+ allowances: Record<string, string>;
211
216
  }
212
217
  interface OrderScoringParams {
213
218
  order_id: string;
@@ -257,7 +262,14 @@ type TokenConditionMap = Record<string, string>;
257
262
  interface FeeDetails {
258
263
  r?: number;
259
264
  e?: number;
260
- to: boolean;
265
+ to?: boolean;
266
+ }
267
+ interface ClobRewards {
268
+ mi?: number;
269
+ ma?: number;
270
+ e?: boolean;
271
+ smoa?: boolean;
272
+ moas?: number;
261
273
  }
262
274
  interface ClobToken {
263
275
  t: string;
@@ -265,12 +277,22 @@ interface ClobToken {
265
277
  }
266
278
  interface MarketDetails {
267
279
  c: string;
268
- t: [ClobToken | null, ClobToken | null];
280
+ t: [ClobToken, ClobToken];
269
281
  mts: number;
270
- nr: boolean;
282
+ nr?: boolean;
271
283
  fd?: FeeDetails;
272
284
  mbf?: number;
273
285
  tbf?: number;
286
+ r: ClobRewards | null;
287
+ ao?: boolean;
288
+ mos?: number;
289
+ sd?: number;
290
+ gst?: string;
291
+ cbos?: boolean;
292
+ aot?: string;
293
+ rfqe?: boolean;
294
+ itode?: boolean;
295
+ ibce?: boolean;
274
296
  }
275
297
  interface PaginationPayload {
276
298
  readonly limit: number;
@@ -364,6 +386,8 @@ interface BuilderTrade {
364
386
  bucketIndex: number;
365
387
  fee: string;
366
388
  feeUsdc: string;
389
+ builderFee: string;
390
+ builderCode: string;
367
391
  err_msg?: string | null;
368
392
  createdAt: string | null;
369
393
  updatedAt: string | null;
@@ -908,7 +932,7 @@ declare class ClobClient {
908
932
  * @param orderbook
909
933
  * @returns
910
934
  */
911
- getOrderBookHash(orderbook: OrderBookSummary): string;
935
+ getOrderBookHash(orderbook: OrderBookSummary): Promise<string>;
912
936
  getMidpoint(tokenID: string): Promise<any>;
913
937
  getMidpoints(params: BookParams[]): Promise<any>;
914
938
  getPrice(tokenID: string, side: string): Promise<any>;
@@ -1012,4 +1036,4 @@ declare class ApiError extends Error {
1012
1036
  declare const createL1Headers: (signer: ClobSigner, chainId: Chain, nonce?: number, timestamp?: number, address?: string) => Promise<L1PolyHeader>;
1013
1037
  declare const createL2Headers: (signer: ClobSigner, creds: ApiKeyCreds, l2HeaderArgs: L2HeaderArgs, timestamp?: number) => Promise<L2PolyHeader>;
1014
1038
 
1015
- export { ApiError, type ApiKeyCreds, type ApiKeyRaw, type ApiKeysResponse, AssetType, type BalanceAllowanceParams, type BalanceAllowanceResponse, type BanStatus, type BookParams, type BuilderApiKey, type BuilderApiKeyResponse, type BuilderConfig, type BuilderFeeRates, type BuilderTrade, type BuilderTradeParams, type BuilderTradesResponse, COLLATERAL_TOKEN_DECIMALS, CONDITIONAL_TOKEN_DECIMALS, Chain, ClobClient, type ClobClientOptions, type ClobErrorResponseBody, type ClobToken, type ContractConfig, type CreateOrderOptions, type DropNotificationParams, type Earning, type FeeDetails, type FeeInfo, type FeeInfos, type FeeRates, type L1PolyHeader, L1_AUTH_UNAVAILABLE_ERROR, type L2HeaderArgs, type L2PolyHeader, L2_AUTH_NOT_AVAILABLE, type MakerOrder, type MarketDetails, type MarketPrice, type MarketReward, type MarketTradeEvent, type NegRisk, type NewOrderV1, type NewOrderV2, type Notification, type OpenOrder, type OpenOrderParams, type OpenOrdersResponse, type OrderBookSummary, OrderBuilder, type OrderMarketCancelParams, type OrderPayload, type OrderResponse, type OrderScoring, type OrderScoringParams, type OrderSummary, OrderType, type OrdersScoring, type OrdersScoringParams, type PaginationPayload, type PostOrdersArgs, type PostOrdersV1Args, type PostOrdersV2Args, type PreMigrationOrder, type PreMigrationOrdersResponse, type PriceHistoryFilterParams, PriceHistoryInterval, type ReadonlyApiKeyResponse, type RewardsConfig, type RewardsPercentages, type RoundConfig, Side, SignatureTypeV1, SignatureTypeV2, type SignedOrder, type SimpleHeaders, type TickSize, type TickSizes, type Token, type TokenConditionMap, type TotalUserEarning, type Trade, type TradeParams, type TradesPaginatedResponse, type UserEarning, type UserMarketOrderV1, type UserMarketOrderV2, type UserOrderV1, type UserOrderV2, type UserRewardsEarning, type VersionedPostOrdersArgs, type VersionedSignedOrder, type VersionedUserMarketOrder, type VersionedUserOrder, adjustBuyAmountForFees, createL1Headers, createL2Headers, getContractConfig, isV2Order, orderToJsonV1, orderToJsonV2 };
1039
+ export { ApiError, type ApiKeyCreds, type ApiKeyRaw, type ApiKeysResponse, AssetType, type BalanceAllowanceParams, type BalanceAllowanceResponse, type BanStatus, type BookParams, type BuilderApiKey, type BuilderApiKeyResponse, type BuilderConfig, type BuilderFeeRates, type BuilderTrade, type BuilderTradeParams, type BuilderTradesResponse, COLLATERAL_TOKEN_DECIMALS, CONDITIONAL_TOKEN_DECIMALS, Chain, ClobClient, type ClobClientOptions, type ClobErrorResponseBody, type ClobRewards, type ClobToken, type ContractConfig, type CreateOrderOptions, type DropNotificationParams, type Earning, type FeeDetails, type FeeInfo, type FeeInfos, type FeeRates, type L1PolyHeader, L1_AUTH_UNAVAILABLE_ERROR, type L2HeaderArgs, type L2PolyHeader, L2_AUTH_NOT_AVAILABLE, type MakerOrder, type MarketDetails, type MarketPrice, type MarketReward, type MarketTradeEvent, type NegRisk, type NewOrderV1, type NewOrderV2, type Notification, type OpenOrder, type OpenOrderParams, type OpenOrdersResponse, type OrderBookSummary, OrderBuilder, type OrderMarketCancelParams, type OrderPayload, type OrderResponse, type OrderScoring, type OrderScoringParams, type OrderSummary, OrderType, type OrdersScoring, type OrdersScoringParams, type PaginationPayload, type PostOrdersArgs, type PostOrdersV1Args, type PostOrdersV2Args, type PreMigrationOrder, type PreMigrationOrdersResponse, type PriceHistoryFilterParams, PriceHistoryInterval, type ReadonlyApiKeyResponse, type RewardsConfig, type RewardsPercentages, type RoundConfig, Side, SignatureTypeV1, SignatureTypeV2, type SignedOrder, type SimpleHeaders, type TickSize, type TickSizes, type Token, type TokenConditionMap, type TotalUserEarning, type Trade, type TradeParams, type TradesPaginatedResponse, type UserEarning, type UserMarketOrderV1, type UserMarketOrderV2, type UserOrderV1, type UserOrderV2, type UserRewardsEarning, type VersionedPostOrdersArgs, type VersionedSignedOrder, type VersionedUserMarketOrder, type VersionedUserOrder, adjustBuyAmountForFees, createL1Headers, createL2Headers, getContractConfig, isV2Order, orderToJsonV1, orderToJsonV2 };
package/dist/index.d.ts CHANGED
@@ -69,7 +69,8 @@ interface OrderResponse {
69
69
  success: boolean;
70
70
  errorMsg: string;
71
71
  orderID: string;
72
- transactionsHashes: string[];
72
+ transactionsHashes?: string[];
73
+ tradeIDs?: string[];
73
74
  status: string;
74
75
  takingAmount: string;
75
76
  makingAmount: string;
@@ -103,7 +104,9 @@ interface MakerOrder {
103
104
  fee_rate_bps: string;
104
105
  asset_id: string;
105
106
  outcome: string;
106
- side: Side;
107
+ side?: Side;
108
+ builder_fee?: string;
109
+ builder_code?: string;
107
110
  }
108
111
  interface Trade {
109
112
  id: string;
@@ -116,13 +119,15 @@ interface Trade {
116
119
  price: string;
117
120
  status: string;
118
121
  match_time: string;
122
+ match_time_nano?: string;
119
123
  last_update: string;
120
124
  outcome: string;
121
125
  bucket_index: number;
122
126
  owner: string;
123
127
  maker_address: string;
124
128
  maker_orders: MakerOrder[];
125
- transaction_hash: string;
129
+ transaction_hash?: string;
130
+ err_msg?: string | null;
126
131
  trader_side: "TAKER" | "MAKER";
127
132
  }
128
133
  interface ApiKeysResponse {
@@ -207,7 +212,7 @@ interface BalanceAllowanceParams {
207
212
  }
208
213
  interface BalanceAllowanceResponse {
209
214
  balance: string;
210
- allowance: string;
215
+ allowances: Record<string, string>;
211
216
  }
212
217
  interface OrderScoringParams {
213
218
  order_id: string;
@@ -257,7 +262,14 @@ type TokenConditionMap = Record<string, string>;
257
262
  interface FeeDetails {
258
263
  r?: number;
259
264
  e?: number;
260
- to: boolean;
265
+ to?: boolean;
266
+ }
267
+ interface ClobRewards {
268
+ mi?: number;
269
+ ma?: number;
270
+ e?: boolean;
271
+ smoa?: boolean;
272
+ moas?: number;
261
273
  }
262
274
  interface ClobToken {
263
275
  t: string;
@@ -265,12 +277,22 @@ interface ClobToken {
265
277
  }
266
278
  interface MarketDetails {
267
279
  c: string;
268
- t: [ClobToken | null, ClobToken | null];
280
+ t: [ClobToken, ClobToken];
269
281
  mts: number;
270
- nr: boolean;
282
+ nr?: boolean;
271
283
  fd?: FeeDetails;
272
284
  mbf?: number;
273
285
  tbf?: number;
286
+ r: ClobRewards | null;
287
+ ao?: boolean;
288
+ mos?: number;
289
+ sd?: number;
290
+ gst?: string;
291
+ cbos?: boolean;
292
+ aot?: string;
293
+ rfqe?: boolean;
294
+ itode?: boolean;
295
+ ibce?: boolean;
274
296
  }
275
297
  interface PaginationPayload {
276
298
  readonly limit: number;
@@ -364,6 +386,8 @@ interface BuilderTrade {
364
386
  bucketIndex: number;
365
387
  fee: string;
366
388
  feeUsdc: string;
389
+ builderFee: string;
390
+ builderCode: string;
367
391
  err_msg?: string | null;
368
392
  createdAt: string | null;
369
393
  updatedAt: string | null;
@@ -908,7 +932,7 @@ declare class ClobClient {
908
932
  * @param orderbook
909
933
  * @returns
910
934
  */
911
- getOrderBookHash(orderbook: OrderBookSummary): string;
935
+ getOrderBookHash(orderbook: OrderBookSummary): Promise<string>;
912
936
  getMidpoint(tokenID: string): Promise<any>;
913
937
  getMidpoints(params: BookParams[]): Promise<any>;
914
938
  getPrice(tokenID: string, side: string): Promise<any>;
@@ -1012,4 +1036,4 @@ declare class ApiError extends Error {
1012
1036
  declare const createL1Headers: (signer: ClobSigner, chainId: Chain, nonce?: number, timestamp?: number, address?: string) => Promise<L1PolyHeader>;
1013
1037
  declare const createL2Headers: (signer: ClobSigner, creds: ApiKeyCreds, l2HeaderArgs: L2HeaderArgs, timestamp?: number) => Promise<L2PolyHeader>;
1014
1038
 
1015
- export { ApiError, type ApiKeyCreds, type ApiKeyRaw, type ApiKeysResponse, AssetType, type BalanceAllowanceParams, type BalanceAllowanceResponse, type BanStatus, type BookParams, type BuilderApiKey, type BuilderApiKeyResponse, type BuilderConfig, type BuilderFeeRates, type BuilderTrade, type BuilderTradeParams, type BuilderTradesResponse, COLLATERAL_TOKEN_DECIMALS, CONDITIONAL_TOKEN_DECIMALS, Chain, ClobClient, type ClobClientOptions, type ClobErrorResponseBody, type ClobToken, type ContractConfig, type CreateOrderOptions, type DropNotificationParams, type Earning, type FeeDetails, type FeeInfo, type FeeInfos, type FeeRates, type L1PolyHeader, L1_AUTH_UNAVAILABLE_ERROR, type L2HeaderArgs, type L2PolyHeader, L2_AUTH_NOT_AVAILABLE, type MakerOrder, type MarketDetails, type MarketPrice, type MarketReward, type MarketTradeEvent, type NegRisk, type NewOrderV1, type NewOrderV2, type Notification, type OpenOrder, type OpenOrderParams, type OpenOrdersResponse, type OrderBookSummary, OrderBuilder, type OrderMarketCancelParams, type OrderPayload, type OrderResponse, type OrderScoring, type OrderScoringParams, type OrderSummary, OrderType, type OrdersScoring, type OrdersScoringParams, type PaginationPayload, type PostOrdersArgs, type PostOrdersV1Args, type PostOrdersV2Args, type PreMigrationOrder, type PreMigrationOrdersResponse, type PriceHistoryFilterParams, PriceHistoryInterval, type ReadonlyApiKeyResponse, type RewardsConfig, type RewardsPercentages, type RoundConfig, Side, SignatureTypeV1, SignatureTypeV2, type SignedOrder, type SimpleHeaders, type TickSize, type TickSizes, type Token, type TokenConditionMap, type TotalUserEarning, type Trade, type TradeParams, type TradesPaginatedResponse, type UserEarning, type UserMarketOrderV1, type UserMarketOrderV2, type UserOrderV1, type UserOrderV2, type UserRewardsEarning, type VersionedPostOrdersArgs, type VersionedSignedOrder, type VersionedUserMarketOrder, type VersionedUserOrder, adjustBuyAmountForFees, createL1Headers, createL2Headers, getContractConfig, isV2Order, orderToJsonV1, orderToJsonV2 };
1039
+ export { ApiError, type ApiKeyCreds, type ApiKeyRaw, type ApiKeysResponse, AssetType, type BalanceAllowanceParams, type BalanceAllowanceResponse, type BanStatus, type BookParams, type BuilderApiKey, type BuilderApiKeyResponse, type BuilderConfig, type BuilderFeeRates, type BuilderTrade, type BuilderTradeParams, type BuilderTradesResponse, COLLATERAL_TOKEN_DECIMALS, CONDITIONAL_TOKEN_DECIMALS, Chain, ClobClient, type ClobClientOptions, type ClobErrorResponseBody, type ClobRewards, type ClobToken, type ContractConfig, type CreateOrderOptions, type DropNotificationParams, type Earning, type FeeDetails, type FeeInfo, type FeeInfos, type FeeRates, type L1PolyHeader, L1_AUTH_UNAVAILABLE_ERROR, type L2HeaderArgs, type L2PolyHeader, L2_AUTH_NOT_AVAILABLE, type MakerOrder, type MarketDetails, type MarketPrice, type MarketReward, type MarketTradeEvent, type NegRisk, type NewOrderV1, type NewOrderV2, type Notification, type OpenOrder, type OpenOrderParams, type OpenOrdersResponse, type OrderBookSummary, OrderBuilder, type OrderMarketCancelParams, type OrderPayload, type OrderResponse, type OrderScoring, type OrderScoringParams, type OrderSummary, OrderType, type OrdersScoring, type OrdersScoringParams, type PaginationPayload, type PostOrdersArgs, type PostOrdersV1Args, type PostOrdersV2Args, type PreMigrationOrder, type PreMigrationOrdersResponse, type PriceHistoryFilterParams, PriceHistoryInterval, type ReadonlyApiKeyResponse, type RewardsConfig, type RewardsPercentages, type RoundConfig, Side, SignatureTypeV1, SignatureTypeV2, type SignedOrder, type SimpleHeaders, type TickSize, type TickSizes, type Token, type TokenConditionMap, type TotalUserEarning, type Trade, type TradeParams, type TradesPaginatedResponse, type UserEarning, type UserMarketOrderV1, type UserMarketOrderV2, type UserOrderV1, type UserOrderV2, type UserRewardsEarning, type VersionedPostOrdersArgs, type VersionedSignedOrder, type VersionedUserMarketOrder, type VersionedUserOrder, adjustBuyAmountForFees, createL1Headers, createL2Headers, getContractConfig, isV2Order, orderToJsonV1, orderToJsonV2 };
package/dist/index.js CHANGED
@@ -201,20 +201,34 @@ var buildClobEip712Signature = async (signer, chainId, timestamp, nonce, address
201
201
  };
202
202
 
203
203
  // src/signing/hmac.ts
204
- import crypto from "crypto";
205
- function replaceAll(s, search, replace) {
206
- return s.split(search).join(replace);
207
- }
208
- var buildPolyHmacSignature = (secret, timestamp, method, requestPath, body) => {
204
+ var buildPolyHmacSignature = async (secret, timestamp, method, requestPath, body) => {
209
205
  let message = timestamp + method + requestPath;
210
206
  if (body !== void 0) {
211
207
  message += body;
212
208
  }
213
- const base64Secret = Buffer.from(secret, "base64");
214
- const hmac = crypto.createHmac("sha256", base64Secret);
215
- const sig = hmac.update(message).digest("base64");
216
- const sigUrlSafe = replaceAll(replaceAll(sig, "+", "-"), "/", "_");
217
- return sigUrlSafe;
209
+ const binarySecret = atob(secret);
210
+ const keyBytes = new Uint8Array(binarySecret.length);
211
+ for (let i = 0; i < binarySecret.length; i++) {
212
+ keyBytes[i] = binarySecret.charCodeAt(i);
213
+ }
214
+ const key = await globalThis.crypto.subtle.importKey(
215
+ "raw",
216
+ keyBytes,
217
+ { name: "HMAC", hash: "SHA-256" },
218
+ false,
219
+ ["sign"]
220
+ );
221
+ const sigBuffer = await globalThis.crypto.subtle.sign(
222
+ "HMAC",
223
+ key,
224
+ new TextEncoder().encode(message)
225
+ );
226
+ const sigBytes = new Uint8Array(sigBuffer);
227
+ let binary = "";
228
+ for (let i = 0; i < sigBytes.length; i++) {
229
+ binary += String.fromCharCode(sigBytes[i]);
230
+ }
231
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_");
218
232
  };
219
233
 
220
234
  // src/headers/index.ts
@@ -243,7 +257,7 @@ var createL2Headers = async (signer, creds, l2HeaderArgs, timestamp) => {
243
257
  ts = timestamp;
244
258
  }
245
259
  const address = await getSignerAddress(signer);
246
- const sig = buildPolyHmacSignature(
260
+ const sig = await buildPolyHmacSignature(
247
261
  creds.secret,
248
262
  ts,
249
263
  l2HeaderArgs.method,
@@ -295,7 +309,6 @@ var post = async (endpoint, options, retryOnError = false) => {
295
309
  return resp.data;
296
310
  } catch (err) {
297
311
  if (retryOnError && isTransientAxiosError(err)) {
298
- console.log("[CLOB Client-v2] transient error, retrying once after 30 ms");
299
312
  await sleep(30);
300
313
  try {
301
314
  const resp = await request(
@@ -338,15 +351,6 @@ var del = async (endpoint, options) => {
338
351
  var errorHandling = (err) => {
339
352
  if (axios.isAxiosError(err)) {
340
353
  if (err.response) {
341
- console.error(
342
- "[CLOB Client] request error",
343
- JSON.stringify({
344
- status: err.response?.status,
345
- statusText: err.response?.statusText,
346
- data: err.response?.data,
347
- config: err.response?.config
348
- })
349
- );
350
354
  if (err.response?.data) {
351
355
  if (typeof err.response?.data === "string" || err.response?.data instanceof String) {
352
356
  return { error: err.response?.data, status: err.response?.status };
@@ -358,16 +362,9 @@ var errorHandling = (err) => {
358
362
  }
359
363
  }
360
364
  if (err.message) {
361
- console.error(
362
- "[CLOB Client] request error",
363
- JSON.stringify({
364
- error: err.message
365
- })
366
- );
367
365
  return { error: err.message };
368
366
  }
369
367
  }
370
- console.error("[CLOB Client] request error", err);
371
368
  return { error: err };
372
369
  };
373
370
  var isTransientAxiosError = (err) => {
@@ -996,7 +993,6 @@ function isV2Order(order) {
996
993
  }
997
994
 
998
995
  // src/utilities.ts
999
- import { createHash } from "crypto";
1000
996
  var roundNormal = (num, decimals) => {
1001
997
  if (decimalPlaces(num) <= decimals) {
1002
998
  return num;
@@ -1025,9 +1021,12 @@ var decimalPlaces = (num) => {
1025
1021
  }
1026
1022
  return arr[1].length;
1027
1023
  };
1028
- var generateOrderBookSummaryHash = (orderbook) => {
1024
+ var generateOrderBookSummaryHash = async (orderbook) => {
1029
1025
  orderbook.hash = "";
1030
- const hash = createHash("sha1").update(JSON.stringify(orderbook)).digest("hex");
1026
+ const data = new TextEncoder().encode(JSON.stringify(orderbook));
1027
+ const hashBuffer = await globalThis.crypto.subtle.digest("SHA-1", data);
1028
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
1029
+ const hash = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
1031
1030
  orderbook.hash = hash;
1032
1031
  return hash;
1033
1032
  };
@@ -1535,7 +1534,7 @@ var ClobClient = class {
1535
1534
  * @param orderbook
1536
1535
  * @returns
1537
1536
  */
1538
- getOrderBookHash(orderbook) {
1537
+ async getOrderBookHash(orderbook) {
1539
1538
  return generateOrderBookSummaryHash(orderbook);
1540
1539
  }
1541
1540
  async getMidpoint(tokenID) {