@polymarket/types 0.0.0-canary-20260421120448

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Polymarket
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # `@polymarket/types`
2
+
3
+ The `@polymarket/types` package is shared TypeScript types for the Polymarket SDK.
4
+
5
+ ---
6
+
7
+ **It is not intended to be used directly. Its interface will change without notice, use it at your own risk.**
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pnpm add @polymarket/types
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import type { MarketId } from '@polymarket/types';
19
+ ```
20
+
21
+ ## Development
22
+
23
+ From the monorepo root:
24
+
25
+ ```bash
26
+ pnpm --filter @polymarket/types build
27
+ ```
28
+
29
+ ## License
30
+
31
+ MIT
@@ -0,0 +1,145 @@
1
+ import { Result, ResultAsync } from 'neverthrow';
2
+ export * from 'neverthrow';
3
+ import { Tagged } from 'type-fest';
4
+
5
+ /**
6
+ * A tuple type representing a non-empty array.
7
+ */
8
+ type NonEmptyArray<T> = readonly [T, ...T[]];
9
+
10
+ /**
11
+ * A string encoded as hexadecimal and prefixed with `0x`.
12
+ */
13
+ type HexString = `0x${string}`;
14
+ /**
15
+ * A hex-encoded 32-byte private key prefixed with `0x`.
16
+ */
17
+ type PrivateKey = Tagged<HexString, 'PrivateKey'>;
18
+ /**
19
+ * An EVM account or contract address.
20
+ */
21
+ type EvmAddress = Tagged<HexString, 'EvmAddress'>;
22
+ /**
23
+ * A hex-encoded EVM signature.
24
+ */
25
+ type EvmSignature = Tagged<HexString, 'EvmSignature'>;
26
+ /**
27
+ * A transaction hash returned by an EVM-compatible network.
28
+ */
29
+ type TxHash = Tagged<HexString, 'TxHash'>;
30
+ /**
31
+ * Checks whether a value is a hex string prefixed with `0x`.
32
+ */
33
+ declare function isHexString(value: unknown): value is HexString;
34
+ /**
35
+ * Checks whether a value is a hex-encoded 32-byte private key.
36
+ */
37
+ declare function isPrivateKey(value: unknown): value is PrivateKey;
38
+
39
+ /**
40
+ * The all-zero EVM address used to indicate the absence of a specific account.
41
+ */
42
+ declare const ZERO_ADDRESS: EvmAddress;
43
+
44
+ /**
45
+ * Base class for errors thrown by the Polymarket SDK.
46
+ */
47
+ declare abstract class PolymarketError extends Error {
48
+ /**
49
+ * Returns `true` when the provided value is a `PolymarketError`.
50
+ */
51
+ static isError(error: unknown): error is PolymarketError;
52
+ }
53
+ /**
54
+ * Error thrown when code reaches a state that should be impossible.
55
+ */
56
+ declare class InvariantError extends PolymarketError {
57
+ name: "InvariantError";
58
+ }
59
+
60
+ /**
61
+ * Returns `true` if the array contains at least one element.
62
+ */
63
+ declare function isNonEmptyArray<T>(value: readonly T[]): value is NonEmptyArray<T>;
64
+ /**
65
+ * Returns `true` if the value is `null` or `undefined`.
66
+ */
67
+ declare function isNullish(value: unknown): value is null | undefined;
68
+ /**
69
+ * Returns `true` if the value is not `null` or `undefined`.
70
+ */
71
+ declare function isPresent<T>(value: T): value is Exclude<T, null | undefined>;
72
+
73
+ /**
74
+ * Flattens an object type for clearer IDE hovers and inferred signatures.
75
+ */
76
+ type Prettify<T> = {
77
+ [K in keyof T]: T[K];
78
+ } & {};
79
+ /**
80
+ * Asserts that a condition is truthy.
81
+ *
82
+ * @internal
83
+ *
84
+ * @param condition - Value expected to be truthy.
85
+ * @param message - Message used for the thrown `InvariantError`.
86
+ */
87
+ declare function invariant(condition: unknown, message: string): asserts condition;
88
+ /**
89
+ * Throws an `InvariantError` and narrows the current code path to `never`.
90
+ *
91
+ * Useful for unreachable branches and exhaustive checks.
92
+ *
93
+ * @param message - Message used for the thrown `InvariantError`.
94
+ */
95
+ declare function never(message?: string): never;
96
+ /**
97
+ * Resolves after the provided delay in milliseconds.
98
+ */
99
+ declare function delay(ms: number): Promise<void>;
100
+
101
+ /**
102
+ * Refines a value to exclude `null` and `undefined`.
103
+ */
104
+ declare function expectPresent<T>(value: T, message?: string): Exclude<T, null | undefined>;
105
+ /**
106
+ * Refines an array to a non-empty tuple or throws when the array is empty.
107
+ */
108
+ declare function expectNonEmptyArray<T>(value: readonly T[], message?: string): NonEmptyArray<T>;
109
+ /**
110
+ * Refines a string to a hex string or throws when the value is invalid.
111
+ */
112
+ declare function expectHexString(value: string, message?: string): HexString;
113
+ /**
114
+ * Refines a string to an EVM address or throws when the value is invalid.
115
+ */
116
+ declare function expectEvmAddress(value: unknown, message?: string): EvmAddress;
117
+ /**
118
+ * Refines a string to an EVM signature or throws when the value is invalid.
119
+ */
120
+ declare function expectEvmSignature(value: unknown, message?: string): EvmSignature;
121
+ /**
122
+ * Refines a string to a transaction hash or throws when the value is invalid.
123
+ */
124
+ declare function expectTxHash(value: unknown, message?: string): TxHash;
125
+
126
+ /**
127
+ * Extracts the success value from a {@link Result} or {@link ResultAsync}, or
128
+ * throws the error branch.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const value = unwrap(result.andThen(step1).andThen(step2));
133
+ *
134
+ * // value === 42
135
+ * ```
136
+ *
137
+ * @internal
138
+ *
139
+ * @param result - Result to unwrap.
140
+ * @returns The success value of the `result`.
141
+ */
142
+ declare function unwrap<T, E>(result: Result<T, E>): T;
143
+ declare function unwrap<T, E>(result: ResultAsync<T, E>): Promise<T>;
144
+
145
+ export { type EvmAddress, type EvmSignature, type HexString, InvariantError, type NonEmptyArray, PolymarketError, type Prettify, type PrivateKey, type TxHash, ZERO_ADDRESS, delay, expectEvmAddress, expectEvmSignature, expectHexString, expectNonEmptyArray, expectPresent, expectTxHash, invariant, isHexString, isNonEmptyArray, isNullish, isPresent, isPrivateKey, never, unwrap };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import {ResultAsync}from'neverthrow';export*from'neverthrow';var a="0x0000000000000000000000000000000000000000";var i=class e extends Error{static isError(r){return r instanceof e}},o=class extends i{name="InvariantError"};function d(e){return e.length>0}function p(e){return e==null}function c(e){return !p(e)}function t(e,r){if(!e)throw new o(r)}function E(e="Unexpected call to never()"){throw new o(e)}function T(e){return new Promise(r=>setTimeout(r,e))}function n(e){return typeof e=="string"&&/^0x[a-fA-F0-9]+$/.test(e)}function l(e){return n(e)&&e.length===66}function w(e,r="Expected value to be present"){return t(e!=null,r),e}function S(e,r="Expected a non-empty array"){return t(e.length>0,r),e}function H(e,r="Expected a hex string"){return t(n(e),r),e}function P(e,r="Expected an EVM address"){return t(n(e)&&e.length===42,r),e}function k(e,r="Expected an EVM signature"){return t(n(e)&&e.length===132,r),e}function N(e,r="Expected a transaction hash"){return t(n(e)&&e.length===66,r),e}function s(e){throw e}function b(e){return e instanceof ResultAsync?e.match(r=>r,s):e.match(r=>r,s)}export{o as InvariantError,i as PolymarketError,a as ZERO_ADDRESS,T as delay,P as expectEvmAddress,k as expectEvmSignature,H as expectHexString,S as expectNonEmptyArray,w as expectPresent,N as expectTxHash,t as invariant,n as isHexString,d as isNonEmptyArray,p as isNullish,c as isPresent,l as isPrivateKey,E as never,b as unwrap};//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts","../src/errors.ts","../src/guards.ts","../src/helpers.ts","../src/hex.ts","../src/refinements.ts","../src/result.ts"],"names":["ZERO_ADDRESS","PolymarketError","_PolymarketError","error","InvariantError","isNonEmptyArray","value","isNullish","isPresent","invariant","condition","message","never","delay","ms","resolve","isHexString","isPrivateKey","expectPresent","expectNonEmptyArray","expectHexString","expectEvmAddress","expectEvmSignature","expectTxHash","throwError","unwrap","result","ResultAsync"],"mappings":"6DAKO,IAAMA,CAAAA,CACX,6CCHK,IAAeC,CAAAA,CAAf,MAAeC,CAAAA,SAAwB,KAAM,CAIlD,OAAO,OAAA,CAAQC,CAAAA,CAA0C,CACvD,OAAOA,CAAAA,YAAiBD,CAC1B,CACF,CAAA,CAKaE,CAAAA,CAAN,cAA6BH,CAAgB,CACzC,IAAA,CAAO,gBAClB,ECZO,SAASI,CAAAA,CACdC,CAAAA,CAC2B,CAC3B,OAAOA,CAAAA,CAAM,MAAA,CAAS,CACxB,CAKO,SAASC,CAAAA,CAAUD,CAAAA,CAA2C,CACnE,OAAOA,CAAAA,EAAU,IACnB,CAKO,SAASE,CAAAA,CAAaF,CAAAA,CAAiD,CAC5E,OAAO,CAACC,CAAAA,CAAUD,CAAK,CACzB,CCNO,SAASG,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACmB,CACnB,GAAI,CAACD,EACH,MAAM,IAAIN,CAAAA,CAAeO,CAAO,CAEpC,CASO,SAASC,CAAAA,CAAMD,CAAAA,CAAU,4BAAA,CAAqC,CACnE,MAAM,IAAIP,CAAAA,CAAeO,CAAO,CAClC,CAKO,SAASE,CAAAA,CAAMC,CAAAA,CAA2B,CAC/C,OAAO,IAAI,OAAA,CAASC,CAAAA,E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AAA,EAAKA,CAAAA,CAAM,MAAA,GAAW,EAAA,CAAIK,CAAO,CAAA,CACrDL,CACT,CCzEA,SAASkB,CAAAA,CAAWrB,CAAAA,CAAuB,CACzC,MAAMA,CACR,CAoBO,SAASsB,CAAAA,CACdC,CAAAA,CACgB,CAChB,OAAIA,CAAAA,YAAkBC,WAAAA,CACbD,CAAAA,CAAO,KAAA,CAAOpB,CAAAA,EAAUA,CAAAA,CAAOkB,CAAU,CAAA,CAG3CE,CAAAA,CAAO,KAAA,CAAOpB,CAAAA,EAAUA,CAAAA,CAAOkB,CAAU,CAClD","file":"index.js","sourcesContent":["import type { EvmAddress } from './hex';\n\n/**\n * The all-zero EVM address used to indicate the absence of a specific account.\n */\nexport const ZERO_ADDRESS =\n '0x0000000000000000000000000000000000000000' as EvmAddress;\n","/**\n * Base class for errors thrown by the Polymarket SDK.\n */\nexport abstract class PolymarketError extends Error {\n /**\n * Returns `true` when the provided value is a `PolymarketError`.\n */\n static isError(error: unknown): error is PolymarketError {\n return error instanceof PolymarketError;\n }\n}\n\n/**\n * Error thrown when code reaches a state that should be impossible.\n */\nexport class InvariantError extends PolymarketError {\n override name = 'InvariantError' as const;\n}\n","import type { NonEmptyArray } from './array';\n\n/**\n * Returns `true` if the array contains at least one element.\n */\nexport function isNonEmptyArray<T>(\n value: readonly T[],\n): value is NonEmptyArray<T> {\n return value.length > 0;\n}\n\n/**\n * Returns `true` if the value is `null` or `undefined`.\n */\nexport function isNullish(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * Returns `true` if the value is not `null` or `undefined`.\n */\nexport function isPresent<T>(value: T): value is Exclude<T, null | undefined> {\n return !isNullish(value);\n}\n","import { InvariantError } from './errors';\n\n/**\n * Flattens an object type for clearer IDE hovers and inferred signatures.\n */\nexport type Prettify<T> = {\n [K in keyof T]: T[K];\n} & {};\n\n/**\n * Asserts that a condition is truthy.\n *\n * @internal\n *\n * @param condition - Value expected to be truthy.\n * @param message - Message used for the thrown `InvariantError`.\n */\nexport function invariant(\n condition: unknown,\n message: string,\n): asserts condition {\n if (!condition) {\n throw new InvariantError(message);\n }\n}\n\n/**\n * Throws an `InvariantError` and narrows the current code path to `never`.\n *\n * Useful for unreachable branches and exhaustive checks.\n *\n * @param message - Message used for the thrown `InvariantError`.\n */\nexport function never(message = 'Unexpected call to never()'): never {\n throw new InvariantError(message);\n}\n\n/**\n * Resolves after the provided delay in milliseconds.\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import type { Tagged } from 'type-fest';\n\n/**\n * A string encoded as hexadecimal and prefixed with `0x`.\n */\nexport type HexString = `0x${string}`;\n\n/**\n * A hex-encoded 32-byte private key prefixed with `0x`.\n */\nexport type PrivateKey = Tagged<HexString, 'PrivateKey'>;\n\n/**\n * An EVM account or contract address.\n */\nexport type EvmAddress = Tagged<HexString, 'EvmAddress'>;\n\n/**\n * A hex-encoded EVM signature.\n */\nexport type EvmSignature = Tagged<HexString, 'EvmSignature'>;\n\n/**\n * A transaction hash returned by an EVM-compatible network.\n */\nexport type TxHash = Tagged<HexString, 'TxHash'>;\n\n/**\n * Checks whether a value is a hex string prefixed with `0x`.\n */\nexport function isHexString(value: unknown): value is HexString {\n return typeof value === 'string' && /^0x[a-fA-F0-9]+$/.test(value);\n}\n\n/**\n * Checks whether a value is a hex-encoded 32-byte private key.\n */\nexport function isPrivateKey(value: unknown): value is PrivateKey {\n return isHexString(value) && value.length === 66;\n}\n","import type { NonEmptyArray } from './array';\nimport { invariant } from './helpers';\nimport {\n type EvmAddress,\n type EvmSignature,\n type HexString,\n isHexString,\n type TxHash,\n} from './hex';\n\n/**\n * Refines a value to exclude `null` and `undefined`.\n */\nexport function expectPresent<T>(\n value: T,\n message = 'Expected value to be present',\n): Exclude<T, null | undefined> {\n invariant(value !== null && value !== undefined, message);\n return value as Exclude<T, null | undefined>;\n}\n\n/**\n * Refines an array to a non-empty tuple or throws when the array is empty.\n */\nexport function expectNonEmptyArray<T>(\n value: readonly T[],\n message = 'Expected a non-empty array',\n): NonEmptyArray<T> {\n invariant(value.length > 0, message);\n\n return value as NonEmptyArray<T>;\n}\n\n/**\n * Refines a string to a hex string or throws when the value is invalid.\n */\nexport function expectHexString(\n value: string,\n message = 'Expected a hex string',\n): HexString {\n invariant(isHexString(value), message);\n return value;\n}\n\n/**\n * Refines a string to an EVM address or throws when the value is invalid.\n */\nexport function expectEvmAddress(\n value: unknown,\n message = 'Expected an EVM address',\n): EvmAddress {\n invariant(isHexString(value) && value.length === 42, message);\n return value as EvmAddress;\n}\n\n/**\n * Refines a string to an EVM signature or throws when the value is invalid.\n */\nexport function expectEvmSignature(\n value: unknown,\n message = 'Expected an EVM signature',\n): EvmSignature {\n invariant(isHexString(value) && value.length === 132, message);\n return value as EvmSignature;\n}\n\n/**\n * Refines a string to a transaction hash or throws when the value is invalid.\n */\nexport function expectTxHash(\n value: unknown,\n message = 'Expected a transaction hash',\n): TxHash {\n invariant(isHexString(value) && value.length === 66, message);\n return value as TxHash;\n}\n","import { type Result, ResultAsync } from 'neverthrow';\n\nfunction throwError(error: unknown): never {\n throw error;\n}\n\n/**\n * Extracts the success value from a {@link Result} or {@link ResultAsync}, or\n * throws the error branch.\n *\n * @example\n * ```ts\n * const value = unwrap(result.andThen(step1).andThen(step2));\n *\n * // value === 42\n * ```\n *\n * @internal\n *\n * @param result - Result to unwrap.\n * @returns The success value of the `result`.\n */\nexport function unwrap<T, E>(result: Result<T, E>): T;\nexport function unwrap<T, E>(result: ResultAsync<T, E>): Promise<T>;\nexport function unwrap<T, E>(\n result: Result<T, E> | ResultAsync<T, E>,\n): T | Promise<T> {\n if (result instanceof ResultAsync) {\n return result.match((value) => value, throwError);\n }\n\n return result.match((value) => value, throwError);\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@polymarket/types",
3
+ "version": "0.0.0-canary-20260421120448",
4
+ "description": "Shared TypeScript types for the Polymarket SDK.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./dist/index.js"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "sideEffects": false,
15
+ "dependencies": {
16
+ "neverthrow": "^8.2.0",
17
+ "type-fest": "^5.5.0"
18
+ },
19
+ "devDependencies": {
20
+ "tsup": "^8.5.1",
21
+ "typescript": "^6.0.2"
22
+ },
23
+ "license": "MIT",
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "typecheck": "tsc -p tsconfig.json --noEmit"
30
+ }
31
+ }