clob-client-sdks 5.3.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.

Potentially problematic release.


This version of clob-client-sdks might be problematic. Click here for more details.

Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -0
  3. package/dist/client.d.ts +165 -0
  4. package/dist/client.js +954 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/config.d.ts +12 -0
  7. package/dist/config.js +28 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/constants.d.ts +3 -0
  10. package/dist/constants.js +7 -0
  11. package/dist/constants.js.map +1 -0
  12. package/dist/endpoints.d.ts +67 -0
  13. package/dist/endpoints.js +82 -0
  14. package/dist/endpoints.js.map +1 -0
  15. package/dist/errors.d.ts +9 -0
  16. package/dist/errors.js +15 -0
  17. package/dist/errors.js.map +1 -0
  18. package/dist/headers/index.d.ts +7 -0
  19. package/dist/headers/index.js +41 -0
  20. package/dist/headers/index.js.map +1 -0
  21. package/dist/http-helpers/index.d.ts +21 -0
  22. package/dist/http-helpers/index.js +166 -0
  23. package/dist/http-helpers/index.js.map +1 -0
  24. package/dist/index.d.ts +8 -0
  25. package/dist/index.js +9 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/order-builder/builder.d.ts +30 -0
  28. package/dist/order-builder/builder.js +52 -0
  29. package/dist/order-builder/builder.js.map +1 -0
  30. package/dist/order-builder/helpers.d.ts +51 -0
  31. package/dist/order-builder/helpers.js +279 -0
  32. package/dist/order-builder/helpers.js.map +1 -0
  33. package/dist/order-builder/index.d.ts +1 -0
  34. package/dist/order-builder/index.js +2 -0
  35. package/dist/order-builder/index.js.map +1 -0
  36. package/dist/rfq-client.d.ts +64 -0
  37. package/dist/rfq-client.js +397 -0
  38. package/dist/rfq-client.js.map +1 -0
  39. package/dist/rfq-deps.d.ts +45 -0
  40. package/dist/rfq-deps.js +2 -0
  41. package/dist/rfq-deps.js.map +1 -0
  42. package/dist/signing/constants.d.ts +14 -0
  43. package/dist/signing/constants.js +16 -0
  44. package/dist/signing/constants.js.map +1 -0
  45. package/dist/signing/eip712.d.ts +10 -0
  46. package/dist/signing/eip712.js +34 -0
  47. package/dist/signing/eip712.js.map +1 -0
  48. package/dist/signing/hmac.d.ts +9 -0
  49. package/dist/signing/hmac.js +58 -0
  50. package/dist/signing/hmac.js.map +1 -0
  51. package/dist/signing/index.d.ts +2 -0
  52. package/dist/signing/index.js +3 -0
  53. package/dist/signing/index.js.map +1 -0
  54. package/dist/types.d.ts +667 -0
  55. package/dist/types.js +37 -0
  56. package/dist/types.js.map +1 -0
  57. package/dist/utilities.d.ts +16 -0
  58. package/dist/utilities.js +93 -0
  59. package/dist/utilities.js.map +1 -0
  60. package/package.json +110 -0
@@ -0,0 +1,93 @@
1
+ import { Side as UtilsSide } from "@polymarket/order-utils";
2
+ import { OrderType, Side } from "./types.js";
3
+ export function orderToJson(order, owner, orderType, deferExec = false, postOnly) {
4
+ if (postOnly === true && orderType !== OrderType.GTC && orderType !== OrderType.GTD) {
5
+ throw new Error("postOnly is only supported for GTC and GTD orders");
6
+ }
7
+ let side = Side.BUY;
8
+ if (order.side == UtilsSide.BUY) {
9
+ side = Side.BUY;
10
+ }
11
+ else {
12
+ side = Side.SELL;
13
+ }
14
+ return {
15
+ deferExec,
16
+ order: {
17
+ salt: parseInt(order.salt, 10),
18
+ maker: order.maker,
19
+ signer: order.signer,
20
+ taker: order.taker,
21
+ tokenId: order.tokenId,
22
+ makerAmount: order.makerAmount,
23
+ takerAmount: order.takerAmount,
24
+ side,
25
+ expiration: order.expiration,
26
+ nonce: order.nonce,
27
+ feeRateBps: order.feeRateBps,
28
+ signatureType: order.signatureType,
29
+ signature: order.signature,
30
+ },
31
+ owner,
32
+ orderType,
33
+ ...(typeof postOnly === "boolean" ? { postOnly } : {}),
34
+ };
35
+ }
36
+ export const roundNormal = (num, decimals) => {
37
+ if (decimalPlaces(num) <= decimals) {
38
+ return num;
39
+ }
40
+ return Math.round((num + Number.EPSILON) * 10 ** decimals) / 10 ** decimals;
41
+ };
42
+ export const roundDown = (num, decimals) => {
43
+ if (decimalPlaces(num) <= decimals) {
44
+ return num;
45
+ }
46
+ return Math.floor(num * 10 ** decimals) / 10 ** decimals;
47
+ };
48
+ export const roundUp = (num, decimals) => {
49
+ if (decimalPlaces(num) <= decimals) {
50
+ return num;
51
+ }
52
+ return Math.ceil(num * 10 ** decimals) / 10 ** decimals;
53
+ };
54
+ export const decimalPlaces = (num) => {
55
+ if (Number.isInteger(num)) {
56
+ return 0;
57
+ }
58
+ const arr = num.toString().split(".");
59
+ if (arr.length <= 1) {
60
+ return 0;
61
+ }
62
+ return arr[1].length;
63
+ };
64
+ /**
65
+ * Converts ArrayBuffer to hex string
66
+ */
67
+ function arrayBufferToHex(buffer) {
68
+ const bytes = new Uint8Array(buffer);
69
+ return Array.from(bytes)
70
+ .map(b => b.toString(16).padStart(2, "0"))
71
+ .join("");
72
+ }
73
+ /**
74
+ * Calculates the hash for the given orderbook
75
+ * @param orderbook
76
+ * @returns
77
+ */
78
+ export const generateOrderBookSummaryHash = async (orderbook) => {
79
+ orderbook.hash = "";
80
+ const message = JSON.stringify(orderbook);
81
+ const messageBuffer = new TextEncoder().encode(message);
82
+ const hashBuffer = await globalThis.crypto.subtle.digest("SHA-1", messageBuffer);
83
+ const hash = arrayBufferToHex(hashBuffer);
84
+ orderbook.hash = hash;
85
+ return hash;
86
+ };
87
+ export const isTickSizeSmaller = (a, b) => {
88
+ return parseFloat(a) < parseFloat(b);
89
+ };
90
+ export const priceValid = (price, tickSize) => {
91
+ return price >= parseFloat(tickSize) && price <= 1 - parseFloat(tickSize);
92
+ };
93
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,SA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AK,IAAI,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC9E,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "clob-client-sdks",
3
+ "description": "TypeScript client for CLOB (Central Limit Order Book)",
4
+ "version": "5.3.4",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Polymarket/clob-client.git"
8
+ },
9
+ "homepage": "https://github.com/Polymarket/clob-client",
10
+ "bugs": {
11
+ "url": "https://github.com/Polymarket/clob-client/issues"
12
+ },
13
+ "contributors": [
14
+ {
15
+ "name": "Jonathan Amenechi",
16
+ "url": "https://github.com/JonathanAmenechi"
17
+ },
18
+ {
19
+ "name": "Rodrigo Calvo",
20
+ "url": "https://github.com/poly-rodr"
21
+ },
22
+ {
23
+ "name": "Matt Walker",
24
+ "url": "https://github.com/mttwlkr"
25
+ },
26
+ {
27
+ "name": "Liam Kovatch",
28
+ "url": "https://github.com/l-kov"
29
+ },
30
+ {
31
+ "name": "Mike Shrieve",
32
+ "url": "https://github.com/mshrieve"
33
+ },
34
+ {
35
+ "name": "Danny Dresner",
36
+ "url": "https://github.com/ddresner-pm"
37
+ }
38
+ ],
39
+ "main": "dist/index.js",
40
+ "types": "dist/index.d.ts",
41
+ "type": "module",
42
+ "files": [
43
+ "dist"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "sideEffects": false,
49
+ "keywords": [
50
+ "blockchain",
51
+ "ethereum"
52
+ ],
53
+ "engines": {
54
+ "node": ">=20.10"
55
+ },
56
+ "license": "MIT",
57
+ "packageManager": "pnpm@9.15.4",
58
+ "scripts": {
59
+ "build": "make build",
60
+ "lint": "make lint",
61
+ "deploy": "pnpm build && npm publish --access public --provenance",
62
+ "test": "make test",
63
+ "prepublishOnly": "npm run build",
64
+ "pack:dry": "npm run build && npm pack --dry-run"
65
+ },
66
+ "dependencies": {
67
+ "@ethersproject/providers": "^5.7.2",
68
+ "@ethersproject/units": "^5.7.0",
69
+ "@ethersproject/wallet": "^5.7.0",
70
+ "@polymarket/builder-signing-sdk": "^0.0.8",
71
+ "@polymarket/order-utils": "^3.0.1",
72
+ "axios": "^1.0.0",
73
+ "browser-or-node": "^2.1.1",
74
+ "decode-sdk": "^1.0.4",
75
+ "ethers": "^5.7.1",
76
+ "tslib": "^2.4.0"
77
+ },
78
+ "devDependencies": {
79
+ "@babel/core": "7.23.2",
80
+ "@babel/traverse": ">=7.23.2",
81
+ "@types/chai": "^4.3.3",
82
+ "@types/mocha": "^9.1.1",
83
+ "@types/node": "^22.19.1",
84
+ "@types/ws": "^8.5.3",
85
+ "@typescript-eslint/eslint-plugin": "^5.37.0",
86
+ "@typescript-eslint/parser": "^5.37.0",
87
+ "chai": "^4.3.6",
88
+ "dotenv": "^16.0.2",
89
+ "eslint": "^8.23.1",
90
+ "eslint-config-prettier": "^8.5.0",
91
+ "eslint-config-standard-with-typescript": "^23.0.0",
92
+ "eslint-plugin-import": "^2.26.0",
93
+ "eslint-plugin-n": "^15.2.5",
94
+ "eslint-plugin-node": "^11.1.0",
95
+ "eslint-plugin-promise": "^6.0.1",
96
+ "eslint-plugin-unused-imports": "^2.0.0",
97
+ "jsdom": "^20.0.0",
98
+ "jsdom-global": "^3.0.2",
99
+ "mocha": "^10.0.0",
100
+ "nyc": "^15.1.0",
101
+ "path": "^0.12.7",
102
+ "prettier": "^2.7.1",
103
+ "ts-mocha": "^10.0.0",
104
+ "typescript": "^5.9.3",
105
+ "ws": "^8.11.0"
106
+ },
107
+ "resolutions": {
108
+ "@babel/traverse": ">=7.23.2"
109
+ }
110
+ }