@dimes-dot-fi/sdk 1.0.3 → 1.1.0

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.
Files changed (45) hide show
  1. package/README.md +15 -0
  2. package/dist/{dimes-client-C8wtMofm.d.cts → aliases-CXfmUrAb.d.cts} +12 -126
  3. package/dist/{dimes-client-C8wtMofm.d.ts → aliases-CXfmUrAb.d.ts} +12 -126
  4. package/dist/{chunk-BRANC7OH.mjs → chunk-EI5V5Z6G.mjs} +2 -2
  5. package/dist/{chunk-JGK55KDX.cjs → chunk-JWAPH4GD.cjs} +5 -5
  6. package/dist/{chunk-JGK55KDX.cjs.map → chunk-JWAPH4GD.cjs.map} +1 -1
  7. package/dist/{chunk-LQ5LLBR6.mjs → chunk-S65RABUT.mjs} +3 -2
  8. package/dist/{chunk-LQ5LLBR6.mjs.map → chunk-S65RABUT.mjs.map} +1 -1
  9. package/dist/{chunk-XXTTXLCT.cjs → chunk-UUE4HG2H.cjs} +3 -2
  10. package/dist/chunk-UUE4HG2H.cjs.map +1 -0
  11. package/dist/chunk-YUCGNELT.mjs +22 -0
  12. package/dist/chunk-YUCGNELT.mjs.map +1 -0
  13. package/dist/chunk-ZK56XS4X.cjs +22 -0
  14. package/dist/chunk-ZK56XS4X.cjs.map +1 -0
  15. package/dist/contract/index.cjs +13 -13
  16. package/dist/contract/index.d.cts +3 -2
  17. package/dist/contract/index.d.ts +3 -2
  18. package/dist/contract/index.mjs +1 -1
  19. package/dist/dimes-client-DfRPwGRk.d.ts +128 -0
  20. package/dist/dimes-client-Tfh-DX2h.d.cts +128 -0
  21. package/dist/{dimes-error-DJTpDU75.d.ts → dimes-error-CfbcQlUB.d.ts} +1 -1
  22. package/dist/{dimes-error-BfhINan2.d.cts → dimes-error-CrKY79nQ.d.cts} +1 -1
  23. package/dist/index.cjs +11 -7
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +7 -5
  26. package/dist/index.d.ts +7 -5
  27. package/dist/index.mjs +7 -3
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/{quote-CH01NmnL.d.cts → quote-BB2YieGk.d.ts} +2 -1
  30. package/dist/{quote-_6hQton4.d.ts → quote-DqF3MEbh.d.cts} +2 -1
  31. package/dist/react/index.cjs +4 -4
  32. package/dist/react/index.d.cts +3 -2
  33. package/dist/react/index.d.ts +3 -2
  34. package/dist/react/index.mjs +2 -2
  35. package/dist/types-B7_dC7HC.d.ts +42 -0
  36. package/dist/types-C9X_jp99.d.cts +42 -0
  37. package/dist/ws/index.cjs +133 -0
  38. package/dist/ws/index.cjs.map +1 -0
  39. package/dist/ws/index.d.cts +35 -0
  40. package/dist/ws/index.d.ts +35 -0
  41. package/dist/ws/index.mjs +133 -0
  42. package/dist/ws/index.mjs.map +1 -0
  43. package/package.json +13 -2
  44. package/dist/chunk-XXTTXLCT.cjs.map +0 -1
  45. /package/dist/{chunk-BRANC7OH.mjs.map → chunk-EI5V5Z6G.mjs.map} +0 -0
@@ -0,0 +1,35 @@
1
+ import { a as PositionEventType, P as PositionEvent, N as NotificationEvent } from '../types-C9X_jp99.cjs';
2
+ export { b as NotificationCode, c as NotificationEventEnvelope, d as PositionEventEnvelope, n as notificationCodes, p as positionEventTypes } from '../types-C9X_jp99.cjs';
3
+ import '../aliases-CXfmUrAb.cjs';
4
+
5
+ interface PositionSocketOptions {
6
+ baseUrl?: string;
7
+ getToken: () => string | null;
8
+ }
9
+ type EventCallback = (event: PositionEvent) => void;
10
+ type NotificationCallback = (event: NotificationEvent) => void;
11
+ type ConnectionCallback = () => void;
12
+ type ErrorCallback = (error: unknown) => void;
13
+ declare class PositionSocket {
14
+ private socket;
15
+ private readonly baseUrl;
16
+ private readonly getToken;
17
+ private readonly eventListeners;
18
+ private readonly connectListeners;
19
+ private readonly disconnectListeners;
20
+ private readonly errorListeners;
21
+ private readonly notificationListeners;
22
+ constructor(options: PositionSocketOptions);
23
+ get connected(): boolean;
24
+ connect(): void;
25
+ disconnect(): void;
26
+ reconnectWithToken(): void;
27
+ on(event: PositionEventType | "*", cb: EventCallback): () => void;
28
+ onConnect(cb: ConnectionCallback): () => void;
29
+ onDisconnect(cb: ConnectionCallback): () => void;
30
+ onError(cb: ErrorCallback): () => void;
31
+ onNotification(cb: NotificationCallback): () => void;
32
+ private emit;
33
+ }
34
+
35
+ export { NotificationEvent, PositionEvent, PositionEventType, PositionSocket, type PositionSocketOptions };
@@ -0,0 +1,35 @@
1
+ import { a as PositionEventType, P as PositionEvent, N as NotificationEvent } from '../types-B7_dC7HC.js';
2
+ export { b as NotificationCode, c as NotificationEventEnvelope, d as PositionEventEnvelope, n as notificationCodes, p as positionEventTypes } from '../types-B7_dC7HC.js';
3
+ import '../aliases-CXfmUrAb.js';
4
+
5
+ interface PositionSocketOptions {
6
+ baseUrl?: string;
7
+ getToken: () => string | null;
8
+ }
9
+ type EventCallback = (event: PositionEvent) => void;
10
+ type NotificationCallback = (event: NotificationEvent) => void;
11
+ type ConnectionCallback = () => void;
12
+ type ErrorCallback = (error: unknown) => void;
13
+ declare class PositionSocket {
14
+ private socket;
15
+ private readonly baseUrl;
16
+ private readonly getToken;
17
+ private readonly eventListeners;
18
+ private readonly connectListeners;
19
+ private readonly disconnectListeners;
20
+ private readonly errorListeners;
21
+ private readonly notificationListeners;
22
+ constructor(options: PositionSocketOptions);
23
+ get connected(): boolean;
24
+ connect(): void;
25
+ disconnect(): void;
26
+ reconnectWithToken(): void;
27
+ on(event: PositionEventType | "*", cb: EventCallback): () => void;
28
+ onConnect(cb: ConnectionCallback): () => void;
29
+ onDisconnect(cb: ConnectionCallback): () => void;
30
+ onError(cb: ErrorCallback): () => void;
31
+ onNotification(cb: NotificationCallback): () => void;
32
+ private emit;
33
+ }
34
+
35
+ export { NotificationEvent, PositionEvent, PositionEventType, PositionSocket, type PositionSocketOptions };
@@ -0,0 +1,133 @@
1
+ import {
2
+ notificationCodes,
3
+ positionEventTypes
4
+ } from "../chunk-YUCGNELT.mjs";
5
+
6
+ // src/ws/position-socket.ts
7
+ import { camelizeKeys } from "humps";
8
+ import { io } from "socket.io-client";
9
+ var wsNamespace = "/v1/ws/prediction-markets/customer-positions";
10
+ function camelizeEnvelope(envelope) {
11
+ return {
12
+ id: envelope.id,
13
+ type: envelope.type,
14
+ createdAt: envelope.created_at,
15
+ data: camelizeKeys(envelope.data)
16
+ };
17
+ }
18
+ var PositionSocket = class {
19
+ socket = null;
20
+ baseUrl;
21
+ getToken;
22
+ eventListeners = /* @__PURE__ */ new Map();
23
+ connectListeners = /* @__PURE__ */ new Set();
24
+ disconnectListeners = /* @__PURE__ */ new Set();
25
+ errorListeners = /* @__PURE__ */ new Set();
26
+ notificationListeners = /* @__PURE__ */ new Set();
27
+ constructor(options) {
28
+ this.baseUrl = options.baseUrl ?? "https://api.dimes.fi";
29
+ this.getToken = options.getToken;
30
+ }
31
+ get connected() {
32
+ return this.socket?.connected ?? false;
33
+ }
34
+ connect() {
35
+ if (this.socket?.connected) {
36
+ return;
37
+ }
38
+ this.socket?.disconnect();
39
+ const token = this.getToken();
40
+ if (!token) {
41
+ return;
42
+ }
43
+ const getToken = this.getToken;
44
+ this.socket = io(`${this.baseUrl}${wsNamespace}`, {
45
+ auth: (cb) => cb({ token: getToken() }),
46
+ transports: ["websocket"],
47
+ reconnection: true,
48
+ reconnectionDelay: 1e3,
49
+ reconnectionDelayMax: 3e4
50
+ });
51
+ this.socket.on("connect", () => {
52
+ for (const cb of this.connectListeners) {
53
+ cb();
54
+ }
55
+ });
56
+ this.socket.on("disconnect", () => {
57
+ for (const cb of this.disconnectListeners) {
58
+ cb();
59
+ }
60
+ });
61
+ this.socket.on("error", (err) => {
62
+ for (const cb of this.errorListeners) {
63
+ cb(err);
64
+ }
65
+ });
66
+ for (const eventType of positionEventTypes) {
67
+ this.socket.on(eventType, (envelope) => {
68
+ const event = camelizeEnvelope(envelope);
69
+ this.emit(eventType, event);
70
+ this.emit("*", event);
71
+ });
72
+ }
73
+ this.socket.on("notification", (envelope) => {
74
+ const event = {
75
+ id: envelope.id,
76
+ type: "notification",
77
+ createdAt: envelope.created_at,
78
+ data: envelope.data
79
+ };
80
+ for (const cb of this.notificationListeners) {
81
+ cb(event);
82
+ }
83
+ });
84
+ }
85
+ disconnect() {
86
+ this.socket?.disconnect();
87
+ this.socket = null;
88
+ }
89
+ reconnectWithToken() {
90
+ this.disconnect();
91
+ this.connect();
92
+ }
93
+ on(event, cb) {
94
+ let set = this.eventListeners.get(event);
95
+ if (!set) {
96
+ set = /* @__PURE__ */ new Set();
97
+ this.eventListeners.set(event, set);
98
+ }
99
+ set.add(cb);
100
+ return () => set.delete(cb);
101
+ }
102
+ onConnect(cb) {
103
+ this.connectListeners.add(cb);
104
+ return () => this.connectListeners.delete(cb);
105
+ }
106
+ onDisconnect(cb) {
107
+ this.disconnectListeners.add(cb);
108
+ return () => this.disconnectListeners.delete(cb);
109
+ }
110
+ onError(cb) {
111
+ this.errorListeners.add(cb);
112
+ return () => this.errorListeners.delete(cb);
113
+ }
114
+ onNotification(cb) {
115
+ this.notificationListeners.add(cb);
116
+ return () => this.notificationListeners.delete(cb);
117
+ }
118
+ emit(event, data) {
119
+ const set = this.eventListeners.get(event);
120
+ if (!set) {
121
+ return;
122
+ }
123
+ for (const cb of set) {
124
+ cb(data);
125
+ }
126
+ }
127
+ };
128
+ export {
129
+ PositionSocket,
130
+ notificationCodes,
131
+ positionEventTypes
132
+ };
133
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ws/position-socket.ts"],"sourcesContent":["import { camelizeKeys } from \"humps\";\nimport { io, type Socket } from \"socket.io-client\";\nimport type { Position } from \"../types\";\nimport {\n positionEventTypes,\n type NotificationEvent,\n type NotificationEventEnvelope,\n type PositionEvent,\n type PositionEventEnvelope,\n type PositionEventType,\n} from \"./types\";\n\nexport interface PositionSocketOptions {\n baseUrl?: string;\n getToken: () => string | null;\n}\n\ntype EventCallback = (event: PositionEvent) => void;\ntype NotificationCallback = (event: NotificationEvent) => void;\ntype ConnectionCallback = () => void;\ntype ErrorCallback = (error: unknown) => void;\n\nconst wsNamespace = \"/v1/ws/prediction-markets/customer-positions\";\n\nfunction camelizeEnvelope(envelope: PositionEventEnvelope): PositionEvent {\n return {\n id: envelope.id,\n type: envelope.type,\n createdAt: envelope.created_at,\n data: camelizeKeys(envelope.data) as unknown as Position,\n };\n}\n\nexport class PositionSocket {\n private socket: Socket | null = null;\n\n private readonly baseUrl: string;\n\n private readonly getToken: () => string | null;\n\n private readonly eventListeners = new Map<string, Set<EventCallback>>();\n\n private readonly connectListeners = new Set<ConnectionCallback>();\n\n private readonly disconnectListeners = new Set<ConnectionCallback>();\n\n private readonly errorListeners = new Set<ErrorCallback>();\n\n private readonly notificationListeners = new Set<NotificationCallback>();\n\n constructor(options: PositionSocketOptions) {\n this.baseUrl = options.baseUrl ?? \"https://api.dimes.fi\";\n this.getToken = options.getToken;\n }\n\n public get connected(): boolean {\n return this.socket?.connected ?? false;\n }\n\n public connect(): void {\n if (this.socket?.connected) {\n return;\n }\n\n this.socket?.disconnect();\n\n const token = this.getToken();\n if (!token) {\n return;\n }\n\n const getToken = this.getToken;\n this.socket = io(`${this.baseUrl}${wsNamespace}`, {\n auth: (cb) => cb({ token: getToken() }),\n transports: [\"websocket\"],\n reconnection: true,\n reconnectionDelay: 1000,\n reconnectionDelayMax: 30000,\n });\n\n this.socket.on(\"connect\", () => {\n for (const cb of this.connectListeners) {\n cb();\n }\n });\n\n this.socket.on(\"disconnect\", () => {\n for (const cb of this.disconnectListeners) {\n cb();\n }\n });\n\n this.socket.on(\"error\", (err: unknown) => {\n for (const cb of this.errorListeners) {\n cb(err);\n }\n });\n\n for (const eventType of positionEventTypes) {\n this.socket.on(eventType, (envelope: PositionEventEnvelope) => {\n const event = camelizeEnvelope(envelope);\n this.emit(eventType, event);\n this.emit(\"*\", event);\n });\n }\n\n this.socket.on(\"notification\", (envelope: NotificationEventEnvelope) => {\n const event: NotificationEvent = {\n id: envelope.id,\n type: \"notification\",\n createdAt: envelope.created_at,\n data: envelope.data,\n };\n for (const cb of this.notificationListeners) {\n cb(event);\n }\n });\n }\n\n public disconnect(): void {\n this.socket?.disconnect();\n this.socket = null;\n }\n\n public reconnectWithToken(): void {\n this.disconnect();\n this.connect();\n }\n\n public on(event: PositionEventType | \"*\", cb: EventCallback): () => void {\n let set = this.eventListeners.get(event);\n if (!set) {\n set = new Set();\n this.eventListeners.set(event, set);\n }\n set.add(cb);\n return () => set.delete(cb);\n }\n\n public onConnect(cb: ConnectionCallback): () => void {\n this.connectListeners.add(cb);\n return () => this.connectListeners.delete(cb);\n }\n\n public onDisconnect(cb: ConnectionCallback): () => void {\n this.disconnectListeners.add(cb);\n return () => this.disconnectListeners.delete(cb);\n }\n\n public onError(cb: ErrorCallback): () => void {\n this.errorListeners.add(cb);\n return () => this.errorListeners.delete(cb);\n }\n\n public onNotification(cb: NotificationCallback): () => void {\n this.notificationListeners.add(cb);\n return () => this.notificationListeners.delete(cb);\n }\n\n private emit(event: string, data: PositionEvent): void {\n const set = this.eventListeners.get(event);\n if (!set) {\n return;\n }\n for (const cb of set) {\n cb(data);\n }\n }\n}\n"],"mappings":";;;;;;AAAA,SAAS,oBAAoB;AAC7B,SAAS,UAAuB;AAqBhC,IAAM,cAAc;AAEpB,SAAS,iBAAiB,UAAgD;AACxE,SAAO;AAAA,IACL,IAAI,SAAS;AAAA,IACb,MAAM,SAAS;AAAA,IACf,WAAW,SAAS;AAAA,IACpB,MAAM,aAAa,SAAS,IAAI;AAAA,EAClC;AACF;AAEO,IAAM,iBAAN,MAAqB;AAAA,EAClB,SAAwB;AAAA,EAEf;AAAA,EAEA;AAAA,EAEA,iBAAiB,oBAAI,IAAgC;AAAA,EAErD,mBAAmB,oBAAI,IAAwB;AAAA,EAE/C,sBAAsB,oBAAI,IAAwB;AAAA,EAElD,iBAAiB,oBAAI,IAAmB;AAAA,EAExC,wBAAwB,oBAAI,IAA0B;AAAA,EAEvE,YAAY,SA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",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "TypeScript SDK for the Dimes prediction market API",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -37,6 +37,16 @@
37
37
  "types": "./dist/contract/index.d.cts",
38
38
  "default": "./dist/contract/index.cjs"
39
39
  }
40
+ },
41
+ "./ws": {
42
+ "import": {
43
+ "types": "./dist/ws/index.d.mts",
44
+ "default": "./dist/ws/index.mjs"
45
+ },
46
+ "require": {
47
+ "types": "./dist/ws/index.d.cts",
48
+ "default": "./dist/ws/index.cjs"
49
+ }
40
50
  }
41
51
  },
42
52
  "scripts": {
@@ -100,7 +110,8 @@
100
110
  "vitest": "^4.1.5"
101
111
  },
102
112
  "dependencies": {
103
- "humps": "^2.0.1"
113
+ "humps": "^2.0.1",
114
+ "socket.io-client": "^4.8.3"
104
115
  },
105
116
  "publishConfig": {
106
117
  "access": "public"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/alexemery/bl/dimes-sdk/dist/chunk-XXTTXLCT.cjs","../src/utils/parse.ts","../src/utils/format.ts","../src/errors/error-messages.ts","../src/errors/dimes-error.ts"],"names":[],"mappings":"AAAA;ACEO,SAAS,QAAA,CAAS,KAAA,EAA+B;AACtD,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,SAAA,GAAY,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG;AACvD,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,SAAA,GAAY,KAAA,CAAM,IAAA,CAAK,EAAA,IAAM,EAAA,EAAI;AACpD,IAAA,MAAM,OAAA,EAAS,MAAA,CAAO,KAAK,CAAA;AAC3B,IAAA,GAAA,CAAI,MAAA,CAAO,QAAA,CAAS,MAAM,CAAA,EAAG;AAC3B,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAEO,SAAS,QAAA,CAAS,KAAA,EAA+B;AACtD,E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A,IAAA;AACP,EAAA;AACF;AAEa;AACX,EAAA;AACQ,IAAA;AACD,IAAA;AACP,EAAA;AACF;AJ+PU;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/alexemery/bl/dimes-sdk/dist/chunk-XXTTXLCT.cjs","sourcesContent":[null,"export type Params = Record<string, unknown> | null;\n\nexport function asNumber(value: unknown): number | null {\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return value;\n }\n if (typeof value === \"string\" && value.trim() !== \"\") {\n const parsed = Number(value);\n if (Number.isFinite(parsed)) {\n return parsed;\n }\n }\n return null;\n}\n\nexport function asBigInt(value: unknown): bigint | null {\n if (typeof value === \"bigint\") {\n return value;\n }\n if (typeof value === \"string\" && /^-?\\d+$/.test(value.trim())) {\n return BigInt(value.trim());\n }\n if (typeof value === \"number\" && Number.isInteger(value)) {\n return BigInt(value);\n }\n return null;\n}\n\nexport function getParam(params: Params, key: string): unknown {\n return params ? params[key] : undefined;\n}\n","import { asNumber, asBigInt } from \"./parse\";\n\nconst BPS_PER_UNIT = 10_000;\nconst BPS_PER_PCT = 100;\nconst FRACTION_TO_PCT = 100;\nconst PIPS_PER_USD = 1_000_000n;\nconst ROUNDING_OFFSET = 5_000n;\nconst CENTS_DIVISOR = 10_000n;\nconst CENTS_PAD = 2;\n\nexport function formatLeverage(value: unknown): string | null {\n const n = asNumber(value);\n if (n === null) {\n return null;\n }\n return `${(n / BPS_PER_UNIT).toLocaleString(undefined, { maximumFractionDigits: 2 })}x`;\n}\n\nexport function formatBpsPct(value: unknown): string | null {\n const n = asNumber(value);\n if (n === null) {\n return null;\n }\n return `${(n / BPS_PER_PCT).toLocaleString(undefined, { maximumFractionDigits: 2 })}%`;\n}\n\nexport function formatFractionPct(value: unknown): string | null {\n const n = asNumber(value);\n if (n === null) {\n return null;\n }\n return `${(n * FRACTION_TO_PCT).toLocaleString(undefined, { maximumFractionDigits: 1 })}%`;\n}\n\nexport function formatPipsUsd(value: unknown): string | null {\n const big = asBigInt(value);\n if (big === null) {\n return null;\n }\n const negative = big < 0n;\n const absUnits = negative ? -big : big;\n const whole = absUnits / PIPS_PER_USD;\n const frac = absUnits % PIPS_PER_USD;\n const cents = (frac + ROUNDING_OFFSET) / CENTS_DIVISOR;\n const formatted = `$${whole.toLocaleString()}.${cents.toString().padStart(CENTS_PAD, \"0\")}`;\n return negative ? `-${formatted}` : formatted;\n}\n","import { formatLeverage, formatBpsPct, formatFractionPct, formatPipsUsd } from \"../utils/format\";\nimport { type Params, getParam } from \"../utils/parse\";\n\ntype FriendlyEntry = string | ((params: Params) => string);\n\nconst friendlyByCode: Record<string, FriendlyEntry> = {\n invalid_evm_address: \"Invalid EVM address.\",\n invalid_solana_address: \"Invalid Solana address.\",\n invalid_string_for_chain_address: \"Invalid wallet address for the selected chain.\",\n invalid_wallet_address: \"Invalid wallet address.\",\n customer_auth_invalid_wallet_address: \"Invalid wallet address.\",\n\n unauthorized: \"Session expired. Please reconnect your wallet.\",\n forbidden: \"You do not have access to this resource.\",\n\n array_out_of_bounds: \"Internal indexing error. Please try again.\",\n batch_compute_not_available: \"Cached pricing is temporarily unavailable. Try again shortly.\",\n internal_server_error: \"Something went wrong on our side. Please try again.\",\n unexpected_error: \"Something went wrong. Please try again.\",\n provider_not_available: \"Upstream provider is unavailable. Try again shortly.\",\n request_already_in_progress: \"A previous request is still in flight. Wait for it to complete and try again.\",\n math_error: \"A numeric calculation failed. Please try again.\",\n invalid_number: \"Invalid numeric value in request.\",\n invalid_message: \"Received an invalid upstream message.\",\n invalid_filter_combination: \"That combination of filters is not supported.\",\n\n cancel_position_delay_not_elapsed: \"Cancel delay has not elapsed yet. Try again shortly.\",\n cancel_position_transaction_failed: \"Cancel transaction failed on-chain.\",\n cancel_position_not_found: \"Position not found.\",\n cancel_position_not_in_created_state: \"This position can only be cancelled before it has filled.\",\n cancel_position_not_on_polygon: \"Cancel is only supported for Polygon positions.\",\n customer_cancel_position_evm_only: \"Cancel is only supported for EVM positions.\",\n customer_cancel_position_not_cancellable: \"This position can no longer be cancelled.\",\n customer_cancel_position_not_owner: \"You do not own this position.\",\n customer_cancel_position_not_found: \"Position not found.\",\n\n circuit_breaker_price_divergence_tripped: \"Trading is temporarily paused due to price divergence. Try again shortly.\",\n\n customer_market_not_found: \"Market not found.\",\n customer_position_not_found: \"Position not found.\",\n\n close_position_transaction_failed: \"Close transaction failed on-chain.\",\n close_position_transaction_not_found: \"Close transaction not found.\",\n finalize_close_transaction_failed: \"Finalising the close transaction failed.\",\n close_no_open_position_transaction: \"No open transaction found for this position.\",\n close_no_request_close_transaction: \"No close request found for this position.\",\n close_polymarket_order_failed: \"Polymarket close order failed.\",\n close_polymarket_order_retry_failed: \"Polymarket close order failed after retries.\",\n close_position_already_closed: \"This position is already closed.\",\n close_position_has_no_tokens: \"This position has no tokens to close.\",\n close_position_not_found: \"Position not found.\",\n close_position_not_originated: \"Position has not been originated yet — nothing to close.\",\n\n exchange_order_submission_locked: \"Order submission is temporarily locked. Try again shortly.\",\n\n quote_partner_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `Partner position limit reached. Remaining capacity: ${available}.`\n : \"Partner position limit reached. Try a smaller size.\";\n },\n quote_user_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `You have reached your position limit on this market. Remaining capacity: ${available}.`\n : \"You have reached your position limit on this market.\";\n },\n quote_market_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `This market has reached its open-interest cap. Remaining capacity: ${available}.`\n : \"This market has reached its open-interest cap. Try a smaller size or another market.\";\n },\n quote_global_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `Global position limit reached. Remaining capacity: ${available}.`\n : \"Global position limit reached. Try again shortly.\";\n },\n quote_side_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `This side of the market is at its position limit. Remaining capacity: ${available}.`\n : \"This side of the market is at its position limit. Try the other side or a smaller size.\";\n },\n quote_side_capacity_exceeded: (params) => {\n const maxCollateral = formatPipsUsd(getParam(params, \"maxSupportedCollateralUsdPips\"));\n return maxCollateral\n ? `Not enough capacity on this side of the market. Max supported collateral at this size: ${maxCollateral}.`\n : \"Not enough capacity on this side of the market for that size.\";\n },\n quote_position_limit_exceeded: \"Position limit reached for this request.\",\n\n quote_insufficient_liquidity: \"Not enough liquidity on the order book to fill this size.\",\n quote_slippage_too_high: (params) => {\n const max = formatBpsPct(getParam(params, \"maxSlippageBps\"));\n const current = formatBpsPct(getParam(params, \"currentSlippageBps\"));\n if (max && current) {\n return `Required slippage ${current} exceeds your tolerance (${max}). Reduce size or raise tolerance.`;\n }\n if (max) {\n return `Required slippage exceeds your tolerance (${max}). Reduce size or raise tolerance.`;\n }\n return \"Price would move too far to fill this order. Reduce size or raise your slippage tolerance.\";\n },\n quote_event_not_started: \"This event has not started yet. Trading opens at the scheduled start time.\",\n quote_entry_bid_depth_too_low: \"Order book depth on the entry side is too thin to open this position safely.\",\n quote_entry_capacity_exceeded: \"Entry size exceeds the market's available capacity.\",\n quote_entry_depth_too_low: \"Order book depth is too thin to open this position safely.\",\n quote_entry_spread_too_wide: \"Bid/ask spread is too wide to open right now. Try again shortly.\",\n quote_entry_order_book_stale: \"Order book data is stale. Refresh and try again.\",\n quote_entry_price_stale: \"Price data is stale. Refresh and try again.\",\n quote_entry_crypto_price_stale: \"Crypto price data is stale. Refresh and try again.\",\n quote_entry_sport_data_stale: \"Sport event data is stale. Refresh and try again.\",\n quote_entry_volume_too_low: \"Recent traded volume on this market is too low to open new positions.\",\n quote_entry_top_holder_too_high: \"A single trader holds too much of this market. Opening here is restricted.\",\n quote_entry_price_out_of_range: \"Current price is outside the range we can open at. Try again shortly.\",\n quote_entry_exit_drop_too_high: \"Exit liquidity is too thin to safely open this size.\",\n quote_entry_market_too_elapsed: (params) => {\n const elapsed = formatFractionPct(getParam(params, \"pctElapsed\"));\n const max = formatFractionPct(getParam(params, \"maxPctElapsed\"));\n if (elapsed && max) {\n return `Market is ${elapsed} elapsed (max ${max}). Too close to resolution to open new positions.`;\n }\n return \"Market is too close to resolution to open new positions.\";\n },\n quote_entry_excluded_market_type: \"This market type is not supported for leveraged positions.\",\n quote_entry_excluded_sport: \"This sport is not supported for leveraged positions.\",\n quote_price_too_low: \"Underlying price is too low to open a leveraged position.\",\n quote_open_interest_unavailable: \"Open-interest data is unavailable right now. Try again shortly.\",\n\n quote_leverage_below_minimum: (params) => {\n const min = formatLeverage(getParam(params, \"minLeverageBps\"));\n const current = formatLeverage(getParam(params, \"currentLeverageBps\"));\n if (min && current) {\n return `Leverage ${current} is below the minimum allowed (${min}).`;\n }\n if (min) {\n return `Leverage is below the minimum allowed (${min}).`;\n }\n return \"Leverage is below the minimum allowed for this market.\";\n },\n quote_leverage_exceeds_maximum: (params) => {\n const max = formatLeverage(getParam(params, \"maxLeverageBps\"));\n const current = formatLeverage(getParam(params, \"currentLeverageBps\"));\n if (max && current) {\n return `Leverage ${current} is above the maximum allowed (${max}).`;\n }\n if (max) {\n return `Leverage is above the maximum allowed (${max}).`;\n }\n return \"Leverage is above the maximum allowed for this market.\";\n },\n quote_leverage_exceeds_model_max: (params) => {\n const max = formatLeverage(getParam(params, \"maxLeverageBps\"));\n const current = formatLeverage(getParam(params, \"currentLeverageBps\"));\n if (max && current) {\n return `Leverage ${current} exceeds the risk-model limit (${max}) for this market.`;\n }\n if (max) {\n return `Leverage exceeds the risk-model limit (${max}) for this market.`;\n }\n return \"Leverage exceeds the risk-model limit for this market.\";\n },\n quote_leverage_too_high_for_price: (params) => {\n const current = formatLeverage(getParam(params, \"currentLeverageBps\"));\n const max = formatLeverage(getParam(params, \"maxAcceptableLeverageBps\"));\n if (current && max) {\n return `Leverage ${current} is too high for the current price. Maximum is ${max}.`;\n }\n if (current) {\n return `Leverage ${current} is too high for the current price. Reduce leverage.`;\n }\n return \"Leverage is too high for the current price. Reduce leverage.\";\n },\n quote_hard_exit_too_close: \"Hard-exit is too close to entry. Reduce leverage.\",\n quote_liquidation_not_viable: (params) => {\n const tolerance = formatBpsPct(getParam(params, \"minTolerancePctBps\"));\n return tolerance\n ? `Liquidation price is too close to entry (minimum buffer ${tolerance}). Reduce leverage.`\n : \"Liquidation price is not viable at this leverage. Reduce leverage.\";\n },\n\n quote_market_not_active: \"Market is not active.\",\n quote_market_not_eligible: \"Market is not eligible for leveraged trading.\",\n quote_market_not_ready: \"Market is not ready yet. Try again shortly.\",\n quote_market_not_found: \"Market not found.\",\n quote_market_risk_too_high: \"Market risk is too high right now. Try again later.\",\n quote_market_unsupported_category: \"This market category is not supported.\",\n quote_market_no_prices: \"No price data available for this market.\",\n quote_market_missing_polymarket_condition_id: \"This market is missing required Polymarket data.\",\n\n quote_polymarket_market_closed: \"This Polymarket market is closed and not accepting new positions.\",\n quote_polymarket_market_inactive: \"This Polymarket market is inactive and not accepting new positions.\",\n quote_polymarket_market_not_accepting_orders:\n \"Polymarket is not accepting orders on this market right now. Try again shortly or pick another market.\",\n quote_polymarket_missing_token: \"This Polymarket market is missing a tradable outcome token.\",\n quote_invalid_polymarket_wallet_address: \"Invalid Polymarket wallet address.\",\n quote_invalid_kalshi_wallet_address: \"Invalid Kalshi wallet address.\",\n\n kalshi_quote_market_closed: \"This Kalshi market is closed.\",\n\n quote_draft_not_found: \"This quote has expired or does not exist. Please request a new quote.\",\n\n quote_twap_data_stale: \"Reference price (TWAP) is stale. Try again shortly.\",\n quote_twap_data_unavailable: \"Reference price (TWAP) is unavailable for this market.\",\n quote_revision_required: \"Quote needs to be refreshed before submitting.\",\n quote_price_provider_not_found: \"No price provider configured for this market.\",\n\n notional_selector_insufficient_liquidity: \"Not enough liquidity at the selected size.\",\n\n evm_gas_price_circuit_breaker: \"EVM gas price is too high — trading is temporarily paused.\",\n evm_gas_price_spike: \"EVM gas price spiked. Try again shortly.\",\n evm_simulation_failed: \"Transaction simulation failed. The transaction would revert on-chain.\",\n evm_receipt_timeout: \"Transaction confirmation timed out. Check status before retrying.\",\n evm_transaction_failed: \"EVM transaction failed.\",\n\n position_transition_conflicting_operation: \"Another operation on this position is in progress. Try again shortly.\",\n position_transition_invalid_state: \"Position is not in a state that allows this action.\",\n\n quote_creation_disabled: \"Quote creation is temporarily disabled. Try again shortly.\",\n};\n\nfunction humanizeCode(code: string): string {\n const spaced = code.replace(/_/g, \" \");\n return spaced.charAt(0).toUpperCase() + spaced.slice(1);\n}\n\nexport function resolveFriendlyMessage(code: string, params: Params): string | null {\n const entry = friendlyByCode[code];\n if (entry === undefined) {\n return null;\n }\n return typeof entry === \"function\" ? entry(params) : entry;\n}\n\nexport function formatErrorMessage(code: string, params: Params): string {\n return resolveFriendlyMessage(code, params) ?? humanizeCode(code);\n}\n","import type { QuoteHint } from \"../quote/quote-error-hints\";\nimport { resolveFriendlyMessage } from \"./error-messages\";\n\nexport class DimesError extends Error {\n public readonly code: string;\n\n constructor(code: string, message: string) {\n super(message);\n this.name = \"DimesError\";\n this.code = code;\n }\n}\n\nexport class DimesApiError extends DimesError {\n public readonly status: number;\n\n public readonly type: string | null;\n\n public readonly rawMessage: string;\n\n public readonly params: Record<string, unknown> | null;\n\n public readonly hint: QuoteHint | null;\n\n constructor(options: {\n status: number;\n code: string;\n type: string | null;\n message: string;\n params: Record<string, unknown> | null;\n hint?: QuoteHint | null;\n }) {\n const friendly = resolveFriendlyMessage(options.code, options.params) ?? options.message;\n super(options.code, friendly);\n this.name = \"DimesApiError\";\n this.status = options.status;\n this.type = options.type;\n this.rawMessage = options.message;\n this.params = options.params;\n this.hint = options.hint ?? null;\n }\n}\n\nexport class DimesContractError extends DimesError {\n constructor(code: string, message: string) {\n super(code, message);\n this.name = \"DimesContractError\";\n }\n}\n"]}