@polymarket/clob-client-v2 1.0.3 → 1.0.5
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.cjs +51 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -9
- package/dist/index.d.ts +33 -9
- package/dist/index.js +51 -32
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
280
|
+
t: [ClobToken, ClobToken];
|
|
269
281
|
mts: number;
|
|
270
|
-
nr
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
280
|
+
t: [ClobToken, ClobToken];
|
|
269
281
|
mts: number;
|
|
270
|
-
nr
|
|
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,49 @@ var buildClobEip712Signature = async (signer, chainId, timestamp, nonce, address
|
|
|
201
201
|
};
|
|
202
202
|
|
|
203
203
|
// src/signing/hmac.ts
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
var decodeBase64Secret = (secret) => {
|
|
205
|
+
const normalized = secret.replace(/-/g, "+").replace(/_/g, "/");
|
|
206
|
+
const padded = normalized + "=".repeat((4 - normalized.length % 4) % 4);
|
|
207
|
+
const binary = atob(padded);
|
|
208
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
209
|
+
const bytes = new Uint8Array(buffer);
|
|
210
|
+
for (let i = 0; i < binary.length; i++) {
|
|
211
|
+
bytes[i] = binary.charCodeAt(i);
|
|
212
|
+
}
|
|
213
|
+
return bytes;
|
|
214
|
+
};
|
|
215
|
+
var buildPolyHmacSignature = async (secret, timestamp, method, requestPath, body) => {
|
|
216
|
+
if (!secret) {
|
|
217
|
+
throw new Error("buildPolyHmacSignature: secret is empty");
|
|
218
|
+
}
|
|
219
|
+
if (!globalThis.crypto?.subtle) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
"buildPolyHmacSignature: globalThis.crypto.subtle is unavailable. Requires Node >=20 or a secure browser context (HTTPS or localhost)."
|
|
222
|
+
);
|
|
223
|
+
}
|
|
209
224
|
let message = timestamp + method + requestPath;
|
|
210
225
|
if (body !== void 0) {
|
|
211
226
|
message += body;
|
|
212
227
|
}
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
228
|
+
const keyBytes = decodeBase64Secret(secret);
|
|
229
|
+
const key = await globalThis.crypto.subtle.importKey(
|
|
230
|
+
"raw",
|
|
231
|
+
keyBytes,
|
|
232
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
233
|
+
false,
|
|
234
|
+
["sign"]
|
|
235
|
+
);
|
|
236
|
+
const sigBuffer = await globalThis.crypto.subtle.sign(
|
|
237
|
+
"HMAC",
|
|
238
|
+
key,
|
|
239
|
+
new TextEncoder().encode(message)
|
|
240
|
+
);
|
|
241
|
+
const sigBytes = new Uint8Array(sigBuffer);
|
|
242
|
+
let binary = "";
|
|
243
|
+
for (let i = 0; i < sigBytes.length; i++) {
|
|
244
|
+
binary += String.fromCharCode(sigBytes[i]);
|
|
245
|
+
}
|
|
246
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_");
|
|
218
247
|
};
|
|
219
248
|
|
|
220
249
|
// src/headers/index.ts
|
|
@@ -243,7 +272,7 @@ var createL2Headers = async (signer, creds, l2HeaderArgs, timestamp) => {
|
|
|
243
272
|
ts = timestamp;
|
|
244
273
|
}
|
|
245
274
|
const address = await getSignerAddress(signer);
|
|
246
|
-
const sig = buildPolyHmacSignature(
|
|
275
|
+
const sig = await buildPolyHmacSignature(
|
|
247
276
|
creds.secret,
|
|
248
277
|
ts,
|
|
249
278
|
l2HeaderArgs.method,
|
|
@@ -295,7 +324,6 @@ var post = async (endpoint, options, retryOnError = false) => {
|
|
|
295
324
|
return resp.data;
|
|
296
325
|
} catch (err) {
|
|
297
326
|
if (retryOnError && isTransientAxiosError(err)) {
|
|
298
|
-
console.log("[CLOB Client-v2] transient error, retrying once after 30 ms");
|
|
299
327
|
await sleep(30);
|
|
300
328
|
try {
|
|
301
329
|
const resp = await request(
|
|
@@ -338,15 +366,6 @@ var del = async (endpoint, options) => {
|
|
|
338
366
|
var errorHandling = (err) => {
|
|
339
367
|
if (axios.isAxiosError(err)) {
|
|
340
368
|
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
369
|
if (err.response?.data) {
|
|
351
370
|
if (typeof err.response?.data === "string" || err.response?.data instanceof String) {
|
|
352
371
|
return { error: err.response?.data, status: err.response?.status };
|
|
@@ -358,16 +377,9 @@ var errorHandling = (err) => {
|
|
|
358
377
|
}
|
|
359
378
|
}
|
|
360
379
|
if (err.message) {
|
|
361
|
-
console.error(
|
|
362
|
-
"[CLOB Client] request error",
|
|
363
|
-
JSON.stringify({
|
|
364
|
-
error: err.message
|
|
365
|
-
})
|
|
366
|
-
);
|
|
367
380
|
return { error: err.message };
|
|
368
381
|
}
|
|
369
382
|
}
|
|
370
|
-
console.error("[CLOB Client] request error", err);
|
|
371
383
|
return { error: err };
|
|
372
384
|
};
|
|
373
385
|
var isTransientAxiosError = (err) => {
|
|
@@ -996,7 +1008,6 @@ function isV2Order(order) {
|
|
|
996
1008
|
}
|
|
997
1009
|
|
|
998
1010
|
// src/utilities.ts
|
|
999
|
-
import { createHash } from "crypto";
|
|
1000
1011
|
var roundNormal = (num, decimals) => {
|
|
1001
1012
|
if (decimalPlaces(num) <= decimals) {
|
|
1002
1013
|
return num;
|
|
@@ -1025,9 +1036,17 @@ var decimalPlaces = (num) => {
|
|
|
1025
1036
|
}
|
|
1026
1037
|
return arr[1].length;
|
|
1027
1038
|
};
|
|
1028
|
-
var generateOrderBookSummaryHash = (orderbook) => {
|
|
1039
|
+
var generateOrderBookSummaryHash = async (orderbook) => {
|
|
1040
|
+
if (!globalThis.crypto?.subtle) {
|
|
1041
|
+
throw new Error(
|
|
1042
|
+
"generateOrderBookSummaryHash: globalThis.crypto.subtle is unavailable. Requires Node >=20 or a secure browser context (HTTPS or localhost)."
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1029
1045
|
orderbook.hash = "";
|
|
1030
|
-
const
|
|
1046
|
+
const data = new TextEncoder().encode(JSON.stringify(orderbook));
|
|
1047
|
+
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-1", data);
|
|
1048
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
1049
|
+
const hash = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1031
1050
|
orderbook.hash = hash;
|
|
1032
1051
|
return hash;
|
|
1033
1052
|
};
|
|
@@ -1535,7 +1554,7 @@ var ClobClient = class {
|
|
|
1535
1554
|
* @param orderbook
|
|
1536
1555
|
* @returns
|
|
1537
1556
|
*/
|
|
1538
|
-
getOrderBookHash(orderbook) {
|
|
1557
|
+
async getOrderBookHash(orderbook) {
|
|
1539
1558
|
return generateOrderBookSummaryHash(orderbook);
|
|
1540
1559
|
}
|
|
1541
1560
|
async getMidpoint(tokenID) {
|