@polymarket/clob-client 4.22.4 → 4.22.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.
- package/dist/client.d.ts +112 -0
- package/dist/client.js +840 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +33 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +10 -0
- package/dist/constants.js.map +1 -0
- package/dist/endpoints.d.ts +48 -0
- package/dist/endpoints.js +62 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -0
- package/dist/headers/index.d.ts +7 -0
- package/dist/headers/index.js +45 -0
- package/dist/headers/index.js.map +1 -0
- package/dist/http-helpers/index.d.ts +18 -0
- package/dist/http-helpers/index.js +116 -0
- package/dist/http-helpers/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/order-builder/builder.d.ts +29 -0
- package/dist/order-builder/builder.js +47 -0
- package/dist/order-builder/builder.js.map +1 -0
- package/dist/order-builder/helpers.d.ts +49 -0
- package/dist/order-builder/helpers.js +292 -0
- package/dist/order-builder/helpers.js.map +1 -0
- package/dist/order-builder/index.d.ts +1 -0
- package/dist/order-builder/index.js +5 -0
- package/dist/order-builder/index.js.map +1 -0
- package/dist/signing/constants.d.ts +14 -0
- package/dist/signing/constants.js +19 -0
- package/dist/signing/constants.js.map +1 -0
- package/dist/signing/eip712.d.ts +10 -0
- package/dist/signing/eip712.js +39 -0
- package/dist/signing/eip712.js.map +1 -0
- package/dist/signing/hmac.d.ts +9 -0
- package/dist/signing/hmac.js +32 -0
- package/dist/signing/hmac.js.map +1 -0
- package/dist/signing/index.d.ts +2 -0
- package/dist/signing/index.js +6 -0
- package/dist/signing/index.js.map +1 -0
- package/dist/types.d.ts +435 -0
- package/dist/types.js +34 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +15 -0
- package/dist/utilities.js +89 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +2 -2
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { SignatureType, SignedOrder } from "@polymarket/order-utils";
|
|
2
|
+
import { AxiosRequestHeaders } from "axios";
|
|
3
|
+
export interface ApiKeyCreds {
|
|
4
|
+
key: string;
|
|
5
|
+
secret: string;
|
|
6
|
+
passphrase: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ApiKeyRaw {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
secret: string;
|
|
11
|
+
passphrase: string;
|
|
12
|
+
}
|
|
13
|
+
export interface L2HeaderArgs {
|
|
14
|
+
method: string;
|
|
15
|
+
requestPath: string;
|
|
16
|
+
body?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface L1PolyHeader extends AxiosRequestHeaders {
|
|
19
|
+
POLY_ADDRESS: string;
|
|
20
|
+
POLY_SIGNATURE: string;
|
|
21
|
+
POLY_TIMESTAMP: string;
|
|
22
|
+
POLY_NONCE: string;
|
|
23
|
+
}
|
|
24
|
+
export interface L2PolyHeader extends AxiosRequestHeaders {
|
|
25
|
+
POLY_ADDRESS: string;
|
|
26
|
+
POLY_SIGNATURE: string;
|
|
27
|
+
POLY_TIMESTAMP: string;
|
|
28
|
+
POLY_API_KEY: string;
|
|
29
|
+
POLY_PASSPHRASE: string;
|
|
30
|
+
}
|
|
31
|
+
export interface L2WithBuilderHeader extends L2PolyHeader {
|
|
32
|
+
POLY_BUILDER_API_KEY: string;
|
|
33
|
+
POLY_BUILDER_TIMESTAMP: string;
|
|
34
|
+
POLY_BUILDER_PASSPHRASE: string;
|
|
35
|
+
POLY_BUILDER_SIGNATURE: string;
|
|
36
|
+
}
|
|
37
|
+
export declare enum Side {
|
|
38
|
+
BUY = "BUY",
|
|
39
|
+
SELL = "SELL"
|
|
40
|
+
}
|
|
41
|
+
export declare enum OrderType {
|
|
42
|
+
GTC = "GTC",
|
|
43
|
+
FOK = "FOK",
|
|
44
|
+
GTD = "GTD",
|
|
45
|
+
FAK = "FAK"
|
|
46
|
+
}
|
|
47
|
+
export interface PostOrdersArgs {
|
|
48
|
+
order: SignedOrder;
|
|
49
|
+
orderType: OrderType;
|
|
50
|
+
}
|
|
51
|
+
export interface NewOrder<T extends OrderType> {
|
|
52
|
+
readonly order: {
|
|
53
|
+
readonly salt: number;
|
|
54
|
+
readonly maker: string;
|
|
55
|
+
readonly signer: string;
|
|
56
|
+
readonly taker: string;
|
|
57
|
+
readonly tokenId: string;
|
|
58
|
+
readonly makerAmount: string;
|
|
59
|
+
readonly takerAmount: string;
|
|
60
|
+
readonly expiration: string;
|
|
61
|
+
readonly nonce: string;
|
|
62
|
+
readonly feeRateBps: string;
|
|
63
|
+
readonly side: Side;
|
|
64
|
+
readonly signatureType: SignatureType;
|
|
65
|
+
readonly signature: string;
|
|
66
|
+
};
|
|
67
|
+
readonly owner: string;
|
|
68
|
+
readonly orderType: T;
|
|
69
|
+
readonly deferExec: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface UserOrder {
|
|
72
|
+
/**
|
|
73
|
+
* TokenID of the Conditional token asset being traded
|
|
74
|
+
*/
|
|
75
|
+
tokenID: string;
|
|
76
|
+
/**
|
|
77
|
+
* Price used to create the order
|
|
78
|
+
*/
|
|
79
|
+
price: number;
|
|
80
|
+
/**
|
|
81
|
+
* Size in terms of the ConditionalToken
|
|
82
|
+
*/
|
|
83
|
+
size: number;
|
|
84
|
+
/**
|
|
85
|
+
* Side of the order
|
|
86
|
+
*/
|
|
87
|
+
side: Side;
|
|
88
|
+
/**
|
|
89
|
+
* Fee rate, in basis points, charged to the order maker, charged on proceeds
|
|
90
|
+
*/
|
|
91
|
+
feeRateBps?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Nonce used for onchain cancellations
|
|
94
|
+
*/
|
|
95
|
+
nonce?: number;
|
|
96
|
+
/**
|
|
97
|
+
* Timestamp after which the order is expired.
|
|
98
|
+
*/
|
|
99
|
+
expiration?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Address of the order taker. The zero address is used to indicate a public order
|
|
102
|
+
*/
|
|
103
|
+
taker?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface UserMarketOrder {
|
|
106
|
+
/**
|
|
107
|
+
* TokenID of the Conditional token asset being traded
|
|
108
|
+
*/
|
|
109
|
+
tokenID: string;
|
|
110
|
+
/**
|
|
111
|
+
* Price used to create the order
|
|
112
|
+
* If it is not present the market price will be used.
|
|
113
|
+
*/
|
|
114
|
+
price?: number;
|
|
115
|
+
/**
|
|
116
|
+
* BUY orders: $$$ Amount to buy
|
|
117
|
+
* SELL orders: Shares to sell
|
|
118
|
+
*/
|
|
119
|
+
amount: number;
|
|
120
|
+
/**
|
|
121
|
+
* Side of the order
|
|
122
|
+
*/
|
|
123
|
+
side: Side;
|
|
124
|
+
/**
|
|
125
|
+
* Fee rate, in basis points, charged to the order maker, charged on proceeds
|
|
126
|
+
*/
|
|
127
|
+
feeRateBps?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Nonce used for onchain cancellations
|
|
130
|
+
*/
|
|
131
|
+
nonce?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Address of the order taker. The zero address is used to indicate a public order
|
|
134
|
+
*/
|
|
135
|
+
taker?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Specifies the type of order execution:
|
|
138
|
+
* - FOK (Fill or Kill): The order must be filled entirely or not at all.
|
|
139
|
+
* - FAK (Fill and Kill): The order can be partially filled, and any unfilled portion is canceled.
|
|
140
|
+
*/
|
|
141
|
+
orderType?: OrderType.FOK | OrderType.FAK;
|
|
142
|
+
}
|
|
143
|
+
export interface OrderPayload {
|
|
144
|
+
orderID: string;
|
|
145
|
+
}
|
|
146
|
+
export interface ApiKeysResponse {
|
|
147
|
+
apiKeys: ApiKeyCreds[];
|
|
148
|
+
}
|
|
149
|
+
export interface BanStatus {
|
|
150
|
+
closed_only: boolean;
|
|
151
|
+
}
|
|
152
|
+
export interface OrderResponse {
|
|
153
|
+
success: boolean;
|
|
154
|
+
errorMsg: string;
|
|
155
|
+
orderID: string;
|
|
156
|
+
transactionsHashes: string[];
|
|
157
|
+
status: string;
|
|
158
|
+
takingAmount: string;
|
|
159
|
+
makingAmount: string;
|
|
160
|
+
}
|
|
161
|
+
export interface OpenOrder {
|
|
162
|
+
id: string;
|
|
163
|
+
status: string;
|
|
164
|
+
owner: string;
|
|
165
|
+
maker_address: string;
|
|
166
|
+
market: string;
|
|
167
|
+
asset_id: string;
|
|
168
|
+
side: string;
|
|
169
|
+
original_size: string;
|
|
170
|
+
size_matched: string;
|
|
171
|
+
price: string;
|
|
172
|
+
associate_trades: string[];
|
|
173
|
+
outcome: string;
|
|
174
|
+
created_at: number;
|
|
175
|
+
expiration: string;
|
|
176
|
+
order_type: string;
|
|
177
|
+
}
|
|
178
|
+
export type OpenOrdersResponse = OpenOrder[];
|
|
179
|
+
export interface TradeParams {
|
|
180
|
+
id?: string;
|
|
181
|
+
maker_address?: string;
|
|
182
|
+
market?: string;
|
|
183
|
+
asset_id?: string;
|
|
184
|
+
before?: string;
|
|
185
|
+
after?: string;
|
|
186
|
+
}
|
|
187
|
+
export interface OpenOrderParams {
|
|
188
|
+
id?: string;
|
|
189
|
+
market?: string;
|
|
190
|
+
asset_id?: string;
|
|
191
|
+
}
|
|
192
|
+
export interface MakerOrder {
|
|
193
|
+
order_id: string;
|
|
194
|
+
owner: string;
|
|
195
|
+
maker_address: string;
|
|
196
|
+
matched_amount: string;
|
|
197
|
+
price: string;
|
|
198
|
+
fee_rate_bps: string;
|
|
199
|
+
asset_id: string;
|
|
200
|
+
outcome: string;
|
|
201
|
+
side: Side;
|
|
202
|
+
}
|
|
203
|
+
export interface Trade {
|
|
204
|
+
id: string;
|
|
205
|
+
taker_order_id: string;
|
|
206
|
+
market: string;
|
|
207
|
+
asset_id: string;
|
|
208
|
+
side: Side;
|
|
209
|
+
size: string;
|
|
210
|
+
fee_rate_bps: string;
|
|
211
|
+
price: string;
|
|
212
|
+
status: string;
|
|
213
|
+
match_time: string;
|
|
214
|
+
last_update: string;
|
|
215
|
+
outcome: string;
|
|
216
|
+
bucket_index: number;
|
|
217
|
+
owner: string;
|
|
218
|
+
maker_address: string;
|
|
219
|
+
maker_orders: MakerOrder[];
|
|
220
|
+
transaction_hash: string;
|
|
221
|
+
trader_side: "TAKER" | "MAKER";
|
|
222
|
+
}
|
|
223
|
+
export declare enum Chain {
|
|
224
|
+
POLYGON = 137,
|
|
225
|
+
AMOY = 80002
|
|
226
|
+
}
|
|
227
|
+
export interface MarketPrice {
|
|
228
|
+
t: number;
|
|
229
|
+
p: number;
|
|
230
|
+
}
|
|
231
|
+
export interface PriceHistoryFilterParams {
|
|
232
|
+
market?: string;
|
|
233
|
+
startTs?: number;
|
|
234
|
+
endTs?: number;
|
|
235
|
+
fidelity?: number;
|
|
236
|
+
interval?: PriceHistoryInterval;
|
|
237
|
+
}
|
|
238
|
+
export declare enum PriceHistoryInterval {
|
|
239
|
+
MAX = "max",
|
|
240
|
+
ONE_WEEK = "1w",
|
|
241
|
+
ONE_DAY = "1d",
|
|
242
|
+
SIX_HOURS = "6h",
|
|
243
|
+
ONE_HOUR = "1h"
|
|
244
|
+
}
|
|
245
|
+
export interface DropNotificationParams {
|
|
246
|
+
ids: string[];
|
|
247
|
+
}
|
|
248
|
+
export interface Notification {
|
|
249
|
+
type: number;
|
|
250
|
+
owner: string;
|
|
251
|
+
payload: any;
|
|
252
|
+
}
|
|
253
|
+
export interface OrderMarketCancelParams {
|
|
254
|
+
market?: string;
|
|
255
|
+
asset_id?: string;
|
|
256
|
+
}
|
|
257
|
+
export interface OrderBookSummary {
|
|
258
|
+
market: string;
|
|
259
|
+
asset_id: string;
|
|
260
|
+
timestamp: string;
|
|
261
|
+
bids: OrderSummary[];
|
|
262
|
+
asks: OrderSummary[];
|
|
263
|
+
min_order_size: string;
|
|
264
|
+
tick_size: string;
|
|
265
|
+
neg_risk: boolean;
|
|
266
|
+
hash: string;
|
|
267
|
+
}
|
|
268
|
+
export interface OrderSummary {
|
|
269
|
+
price: string;
|
|
270
|
+
size: string;
|
|
271
|
+
}
|
|
272
|
+
export declare enum AssetType {
|
|
273
|
+
COLLATERAL = "COLLATERAL",
|
|
274
|
+
CONDITIONAL = "CONDITIONAL"
|
|
275
|
+
}
|
|
276
|
+
export interface BalanceAllowanceParams {
|
|
277
|
+
asset_type: AssetType;
|
|
278
|
+
token_id?: string;
|
|
279
|
+
}
|
|
280
|
+
export interface BalanceAllowanceResponse {
|
|
281
|
+
balance: string;
|
|
282
|
+
allowance: string;
|
|
283
|
+
}
|
|
284
|
+
export interface OrderScoringParams {
|
|
285
|
+
order_id: string;
|
|
286
|
+
}
|
|
287
|
+
export interface OrderScoring {
|
|
288
|
+
scoring: boolean;
|
|
289
|
+
}
|
|
290
|
+
export interface OrdersScoringParams {
|
|
291
|
+
orderIds: string[];
|
|
292
|
+
}
|
|
293
|
+
export type OrdersScoring = {
|
|
294
|
+
[orderId in string]: boolean;
|
|
295
|
+
};
|
|
296
|
+
export type CreateOrderOptions = {
|
|
297
|
+
tickSize: TickSize;
|
|
298
|
+
negRisk?: boolean;
|
|
299
|
+
};
|
|
300
|
+
export type TickSize = "0.1" | "0.01" | "0.001" | "0.0001";
|
|
301
|
+
export interface RoundConfig {
|
|
302
|
+
readonly price: number;
|
|
303
|
+
readonly size: number;
|
|
304
|
+
readonly amount: number;
|
|
305
|
+
}
|
|
306
|
+
export interface TickSizes {
|
|
307
|
+
[tokenId: string]: TickSize;
|
|
308
|
+
}
|
|
309
|
+
export interface NegRisk {
|
|
310
|
+
[tokenId: string]: boolean;
|
|
311
|
+
}
|
|
312
|
+
export interface FeeRates {
|
|
313
|
+
[tokenId: string]: number;
|
|
314
|
+
}
|
|
315
|
+
export interface PaginationPayload {
|
|
316
|
+
readonly limit: number;
|
|
317
|
+
readonly count: number;
|
|
318
|
+
readonly next_cursor: string;
|
|
319
|
+
readonly data: any[];
|
|
320
|
+
}
|
|
321
|
+
export interface MarketTradeEvent {
|
|
322
|
+
event_type: string;
|
|
323
|
+
market: {
|
|
324
|
+
condition_id: string;
|
|
325
|
+
asset_id: string;
|
|
326
|
+
question: string;
|
|
327
|
+
icon: string;
|
|
328
|
+
slug: string;
|
|
329
|
+
};
|
|
330
|
+
user: {
|
|
331
|
+
address: string;
|
|
332
|
+
username: string;
|
|
333
|
+
profile_picture: string;
|
|
334
|
+
optimized_profile_picture: string;
|
|
335
|
+
pseudonym: string;
|
|
336
|
+
};
|
|
337
|
+
side: Side;
|
|
338
|
+
size: string;
|
|
339
|
+
fee_rate_bps: string;
|
|
340
|
+
price: string;
|
|
341
|
+
outcome: string;
|
|
342
|
+
outcome_index: number;
|
|
343
|
+
transaction_hash: string;
|
|
344
|
+
timestamp: string;
|
|
345
|
+
}
|
|
346
|
+
export interface BookParams {
|
|
347
|
+
token_id: string;
|
|
348
|
+
side: Side;
|
|
349
|
+
}
|
|
350
|
+
export interface UserEarning {
|
|
351
|
+
date: string;
|
|
352
|
+
condition_id: string;
|
|
353
|
+
asset_address: string;
|
|
354
|
+
maker_address: string;
|
|
355
|
+
earnings: number;
|
|
356
|
+
asset_rate: number;
|
|
357
|
+
}
|
|
358
|
+
export interface TotalUserEarning {
|
|
359
|
+
date: string;
|
|
360
|
+
asset_address: string;
|
|
361
|
+
maker_address: string;
|
|
362
|
+
earnings: number;
|
|
363
|
+
asset_rate: number;
|
|
364
|
+
}
|
|
365
|
+
export interface RewardsPercentages {
|
|
366
|
+
[market: string]: number;
|
|
367
|
+
}
|
|
368
|
+
export interface Token {
|
|
369
|
+
token_id: string;
|
|
370
|
+
outcome: string;
|
|
371
|
+
price: number;
|
|
372
|
+
}
|
|
373
|
+
export interface RewardsConfig {
|
|
374
|
+
asset_address: string;
|
|
375
|
+
start_date: string;
|
|
376
|
+
end_date: string;
|
|
377
|
+
rate_per_day: number;
|
|
378
|
+
total_rewards: number;
|
|
379
|
+
}
|
|
380
|
+
export interface MarketReward {
|
|
381
|
+
condition_id: string;
|
|
382
|
+
question: string;
|
|
383
|
+
market_slug: string;
|
|
384
|
+
event_slug: string;
|
|
385
|
+
image: string;
|
|
386
|
+
rewards_max_spread: number;
|
|
387
|
+
rewards_min_size: number;
|
|
388
|
+
tokens: Token[];
|
|
389
|
+
rewards_config: RewardsConfig[];
|
|
390
|
+
}
|
|
391
|
+
export interface Earning {
|
|
392
|
+
asset_address: string;
|
|
393
|
+
earnings: number;
|
|
394
|
+
asset_rate: number;
|
|
395
|
+
}
|
|
396
|
+
export interface UserRewardsEarning {
|
|
397
|
+
condition_id: string;
|
|
398
|
+
question: string;
|
|
399
|
+
market_slug: string;
|
|
400
|
+
event_slug: string;
|
|
401
|
+
image: string;
|
|
402
|
+
rewards_max_spread: number;
|
|
403
|
+
rewards_min_size: number;
|
|
404
|
+
market_competitiveness: number;
|
|
405
|
+
tokens: Token[];
|
|
406
|
+
rewards_config: RewardsConfig[];
|
|
407
|
+
maker_address: string;
|
|
408
|
+
earning_percentage: number;
|
|
409
|
+
earnings: Earning[];
|
|
410
|
+
}
|
|
411
|
+
export interface BuilderTrade {
|
|
412
|
+
id: string;
|
|
413
|
+
tradeType: string;
|
|
414
|
+
takerOrderHash: string;
|
|
415
|
+
builder: string;
|
|
416
|
+
market: string;
|
|
417
|
+
assetId: string;
|
|
418
|
+
side: string;
|
|
419
|
+
size: string;
|
|
420
|
+
sizeUsdc: string;
|
|
421
|
+
price: string;
|
|
422
|
+
status: string;
|
|
423
|
+
outcome: string;
|
|
424
|
+
outcomeIndex: number;
|
|
425
|
+
owner: string;
|
|
426
|
+
maker: string;
|
|
427
|
+
transactionHash: string;
|
|
428
|
+
matchTime: string;
|
|
429
|
+
bucketIndex: number;
|
|
430
|
+
fee: string;
|
|
431
|
+
feeUsdc: string;
|
|
432
|
+
err_msg?: string | null;
|
|
433
|
+
createdAt: string | null;
|
|
434
|
+
updatedAt: string | null;
|
|
435
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetType = exports.PriceHistoryInterval = exports.Chain = exports.OrderType = exports.Side = void 0;
|
|
4
|
+
var Side;
|
|
5
|
+
(function (Side) {
|
|
6
|
+
Side["BUY"] = "BUY";
|
|
7
|
+
Side["SELL"] = "SELL";
|
|
8
|
+
})(Side = exports.Side || (exports.Side = {}));
|
|
9
|
+
var OrderType;
|
|
10
|
+
(function (OrderType) {
|
|
11
|
+
OrderType["GTC"] = "GTC";
|
|
12
|
+
OrderType["FOK"] = "FOK";
|
|
13
|
+
OrderType["GTD"] = "GTD";
|
|
14
|
+
OrderType["FAK"] = "FAK";
|
|
15
|
+
})(OrderType = exports.OrderType || (exports.OrderType = {}));
|
|
16
|
+
var Chain;
|
|
17
|
+
(function (Chain) {
|
|
18
|
+
Chain[Chain["POLYGON"] = 137] = "POLYGON";
|
|
19
|
+
Chain[Chain["AMOY"] = 80002] = "AMOY";
|
|
20
|
+
})(Chain = exports.Chain || (exports.Chain = {}));
|
|
21
|
+
var PriceHistoryInterval;
|
|
22
|
+
(function (PriceHistoryInterval) {
|
|
23
|
+
PriceHistoryInterval["MAX"] = "max";
|
|
24
|
+
PriceHistoryInterval["ONE_WEEK"] = "1w";
|
|
25
|
+
PriceHistoryInterval["ONE_DAY"] = "1d";
|
|
26
|
+
PriceHistoryInterval["SIX_HOURS"] = "6h";
|
|
27
|
+
PriceHistoryInterval["ONE_HOUR"] = "1h";
|
|
28
|
+
})(PriceHistoryInterval = exports.PriceHistoryInterval || (exports.PriceHistoryInterval = {}));
|
|
29
|
+
var AssetType;
|
|
30
|
+
(function (AssetType) {
|
|
31
|
+
AssetType["COLLATERAL"] = "COLLATERAL";
|
|
32
|
+
AssetType["CONDITIONAL"] = "CONDITIONAL";
|
|
33
|
+
})(AssetType = exports.AssetType || (exports.AssetType = {}));
|
|
34
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA+CA,IAAY,IAGX;AAHD,WAAY,IAAI;IACZ,mBAAW,CAAA;IACX,qBAAa,CAAA;AACjB,CAAC,EAHW,IAAI,GAAJ,YAAI,KAAJ,YAAI,QAGf;AAED,IAAY,SAKX;AALD,WAAY,SAAS;IACjB,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,wBAAW,CAAA;AACf,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB;AAkND,IAAY,KAGX;AAHD,WAAY,KAAK;IACb,yCAAa,CAAA;IACb,qCAAY,CAAA;AAChB,CAAC,EAHW,KAAK,GAAL,aAAK,KAAL,aAAK,QAGhB;AAeD,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC5B,mCAAW,CAAA;IACX,uCAAe,CAAA;IACf,sCAAc,CAAA;IACd,wCAAgB,CAAA;IAChB,uCAAe,CAAA;AACnB,CAAC,EANW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAM/B;AAmCD,IAAY,SAGX;AAHD,WAAY,SAAS;IACjB,sCAAyB,CAAA;IACzB,wCAA2B,CAAA;AAC/B,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SignedOrder } from "@polymarket/order-utils";
|
|
2
|
+
import { NewOrder, OrderBookSummary, OrderType, TickSize } from "./types";
|
|
3
|
+
export declare function orderToJson<T extends OrderType>(order: SignedOrder, owner: string, orderType: T, deferExec?: boolean): NewOrder<T>;
|
|
4
|
+
export declare const roundNormal: (num: number, decimals: number) => number;
|
|
5
|
+
export declare const roundDown: (num: number, decimals: number) => number;
|
|
6
|
+
export declare const roundUp: (num: number, decimals: number) => number;
|
|
7
|
+
export declare const decimalPlaces: (num: number) => number;
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the hash for the given orderbook
|
|
10
|
+
* @param orderbook
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare const generateOrderBookSummaryHash: (orderbook: OrderBookSummary) => string;
|
|
14
|
+
export declare const isTickSizeSmaller: (a: TickSize, b: TickSize) => boolean;
|
|
15
|
+
export declare const priceValid: (price: number, tickSize: TickSize) => boolean;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.priceValid = exports.isTickSizeSmaller = exports.generateOrderBookSummaryHash = exports.decimalPlaces = exports.roundUp = exports.roundDown = exports.roundNormal = exports.orderToJson = void 0;
|
|
4
|
+
const order_utils_1 = require("@polymarket/order-utils");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
function orderToJson(order, owner, orderType, deferExec = false) {
|
|
8
|
+
let side = types_1.Side.BUY;
|
|
9
|
+
if (order.side == order_utils_1.Side.BUY) {
|
|
10
|
+
side = types_1.Side.BUY;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
side = types_1.Side.SELL;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
deferExec,
|
|
17
|
+
order: {
|
|
18
|
+
salt: parseInt(order.salt, 10),
|
|
19
|
+
maker: order.maker,
|
|
20
|
+
signer: order.signer,
|
|
21
|
+
taker: order.taker,
|
|
22
|
+
tokenId: order.tokenId,
|
|
23
|
+
makerAmount: order.makerAmount,
|
|
24
|
+
takerAmount: order.takerAmount,
|
|
25
|
+
side,
|
|
26
|
+
expiration: order.expiration,
|
|
27
|
+
nonce: order.nonce,
|
|
28
|
+
feeRateBps: order.feeRateBps,
|
|
29
|
+
signatureType: order.signatureType,
|
|
30
|
+
signature: order.signature,
|
|
31
|
+
},
|
|
32
|
+
owner,
|
|
33
|
+
orderType,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.orderToJson = orderToJson;
|
|
37
|
+
const roundNormal = (num, decimals) => {
|
|
38
|
+
if ((0, exports.decimalPlaces)(num) <= decimals) {
|
|
39
|
+
return num;
|
|
40
|
+
}
|
|
41
|
+
return Math.round((num + Number.EPSILON) * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
|
42
|
+
};
|
|
43
|
+
exports.roundNormal = roundNormal;
|
|
44
|
+
const roundDown = (num, decimals) => {
|
|
45
|
+
if ((0, exports.decimalPlaces)(num) <= decimals) {
|
|
46
|
+
return num;
|
|
47
|
+
}
|
|
48
|
+
return Math.floor(num * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
|
49
|
+
};
|
|
50
|
+
exports.roundDown = roundDown;
|
|
51
|
+
const roundUp = (num, decimals) => {
|
|
52
|
+
if ((0, exports.decimalPlaces)(num) <= decimals) {
|
|
53
|
+
return num;
|
|
54
|
+
}
|
|
55
|
+
return Math.ceil(num * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
|
56
|
+
};
|
|
57
|
+
exports.roundUp = roundUp;
|
|
58
|
+
const decimalPlaces = (num) => {
|
|
59
|
+
if (Number.isInteger(num)) {
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
const arr = num.toString().split(".");
|
|
63
|
+
if (arr.length <= 1) {
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
return arr[1].length;
|
|
67
|
+
};
|
|
68
|
+
exports.decimalPlaces = decimalPlaces;
|
|
69
|
+
/**
|
|
70
|
+
* Calculates the hash for the given orderbook
|
|
71
|
+
* @param orderbook
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
const generateOrderBookSummaryHash = (orderbook) => {
|
|
75
|
+
orderbook.hash = "";
|
|
76
|
+
const hash = (0, crypto_1.createHash)("sha1").update(JSON.stringify(orderbook)).digest("hex");
|
|
77
|
+
orderbook.hash = hash;
|
|
78
|
+
return hash;
|
|
79
|
+
};
|
|
80
|
+
exports.generateOrderBookSummaryHash = generateOrderBookSummaryHash;
|
|
81
|
+
const isTickSizeSmaller = (a, b) => {
|
|
82
|
+
return parseFloat(a) < parseFloat(b);
|
|
83
|
+
};
|
|
84
|
+
exports.isTickSizeSmaller = isTickSizeSmaller;
|
|
85
|
+
const priceValid = (price, tickSize) => {
|
|
86
|
+
return price >= parseFloat(tickSize) && price <= 1 - parseFloat(tickSize);
|
|
87
|
+
};
|
|
88
|
+
exports.priceValid = priceValid;
|
|
89
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":";;;AAAA,yDAAyE;AACzE,mCAAoC;AACpC,mCAAgF;AAEhF,SAAgB,WAAW,CACvB,KAAkB,EAClB,KAAa,EACb,SAAY,EACZ,SAAS,GAAG,KAAK;IAEjB,IAAI,IAAI,GAAG,YAAI,CAAC,GAAG,CAAC;IACpB,IAAI,KAAK,CAAC,IAAI,IAAI,kBAAS,CAAC,GAAG,EAAE;QAC7B,IAAI,GAAG,YAAI,CAAC,GAAG,CAAC;KACnB;SAAM;QACH,IAAI,GAAG,YAAI,CAAC,IAAI,CAAC;KACpB;IAED,OAAO;QACH,SAAS;QACT,KAAK,EAAE;YACH,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9B,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,IAAI;YACJ,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC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|
+
"version": "4.22.6",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
7
7
|
"name": "Jonathan Amenechi",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"test": "make test"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@polymarket/builder-signing-sdk": "^0.0.
|
|
48
|
+
"@polymarket/builder-signing-sdk": "^0.0.7",
|
|
49
49
|
"@polymarket/order-utils": "^2.1.0",
|
|
50
50
|
"axios": "^0.27.2",
|
|
51
51
|
"browser-or-node": "^2.1.1",
|