@dimes-dot-fi/sdk 1.4.3 → 2.0.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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -19
  3. package/dist/{aliases-C2l_JZX_.d.cts → aliases-BJyM8ydu.d.cts} +288 -4
  4. package/dist/{aliases-C2l_JZX_.d.ts → aliases-BJyM8ydu.d.ts} +288 -4
  5. package/dist/{chunk-UHQZSMUD.cjs → chunk-53U53KZ2.cjs} +5 -1
  6. package/dist/chunk-53U53KZ2.cjs.map +1 -0
  7. package/dist/chunk-5VHDXPRV.mjs +240 -0
  8. package/dist/chunk-5VHDXPRV.mjs.map +1 -0
  9. package/dist/{chunk-DYPABUKC.cjs → chunk-72LTVPD2.cjs} +16 -1
  10. package/dist/chunk-72LTVPD2.cjs.map +1 -0
  11. package/dist/{chunk-COSLZ5TM.cjs → chunk-DIH3ORFA.cjs} +38 -16
  12. package/dist/chunk-DIH3ORFA.cjs.map +1 -0
  13. package/dist/chunk-FAW2C5AM.cjs +240 -0
  14. package/dist/chunk-FAW2C5AM.cjs.map +1 -0
  15. package/dist/{chunk-SGA6OZEU.mjs → chunk-NHAIL4SN.mjs} +34 -12
  16. package/dist/chunk-NHAIL4SN.mjs.map +1 -0
  17. package/dist/{chunk-4MO3HKMS.mjs → chunk-PK2PRTQW.mjs} +5 -1
  18. package/dist/chunk-PK2PRTQW.mjs.map +1 -0
  19. package/dist/{chunk-BVILILIV.mjs → chunk-PZCBUVPD.mjs} +16 -1
  20. package/dist/chunk-PZCBUVPD.mjs.map +1 -0
  21. package/dist/contract/index.cjs +5534 -305
  22. package/dist/contract/index.cjs.map +1 -1
  23. package/dist/contract/index.d.cts +68 -10
  24. package/dist/contract/index.d.ts +68 -10
  25. package/dist/contract/index.mjs +5524 -295
  26. package/dist/contract/index.mjs.map +1 -1
  27. package/dist/{dimes-client-ty6xwk0b.d.cts → dimes-client-DYFvnZUx.d.ts} +57 -10
  28. package/dist/{dimes-client-u5wLYVfp.d.ts → dimes-client-DZPhU1CG.d.cts} +57 -10
  29. package/dist/{dimes-error-5ldDx2_G.d.cts → dimes-error-BlQWPqhQ.d.cts} +2 -2
  30. package/dist/{dimes-error-D2RVknPr.d.ts → dimes-error-DBKV5bfr.d.ts} +2 -2
  31. package/dist/index.cjs +164 -12
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +151 -12
  34. package/dist/index.d.ts +151 -12
  35. package/dist/index.mjs +161 -9
  36. package/dist/index.mjs.map +1 -1
  37. package/dist/quote-BFNgVsY-.d.ts +39 -0
  38. package/dist/quote-CanwfT9m.d.cts +39 -0
  39. package/dist/react/index.cjs +416 -18
  40. package/dist/react/index.cjs.map +1 -1
  41. package/dist/react/index.d.cts +165 -8
  42. package/dist/react/index.d.ts +165 -8
  43. package/dist/react/index.mjs +414 -16
  44. package/dist/react/index.mjs.map +1 -1
  45. package/dist/{types-CM14Dx5b.d.cts → types-ClHQbIcY.d.ts} +3 -3
  46. package/dist/{types-CVcrVq0A.d.ts → types-Co-2bQSi.d.cts} +3 -3
  47. package/dist/ws/index.cjs +4 -230
  48. package/dist/ws/index.cjs.map +1 -1
  49. package/dist/ws/index.d.cts +3 -3
  50. package/dist/ws/index.d.ts +3 -3
  51. package/dist/ws/index.mjs +5 -231
  52. package/dist/ws/index.mjs.map +1 -1
  53. package/package.json +43 -4
  54. package/dist/chunk-4MO3HKMS.mjs.map +0 -1
  55. package/dist/chunk-BVILILIV.mjs.map +0 -1
  56. package/dist/chunk-COSLZ5TM.cjs.map +0 -1
  57. package/dist/chunk-DYPABUKC.cjs.map +0 -1
  58. package/dist/chunk-SGA6OZEU.mjs.map +0 -1
  59. package/dist/chunk-UHQZSMUD.cjs.map +0 -1
  60. package/dist/quote-DoRJUXld.d.cts +0 -30
  61. package/dist/quote-GCNVcEoo.d.ts +0 -30
@@ -1,4 +1,4 @@
1
- import { M as Market, C as CreateOfferParams, O as Offer, P as Position, B as PositionTransactions, d as ContractInfo, f as CustomerLimit } from './aliases-C2l_JZX_.cjs';
1
+ import { M as Market, C as CreateQuoteParams, Q as Quote, P as Position, c as PositionTransactions, d as ContractInfo, e as CustomerLimit, F as FeeRates, f as FeeReportParams, g as FeeReport } from './aliases-BJyM8ydu.js';
2
2
 
3
3
  declare const marketMovedCodes: Set<string>;
4
4
  type QuoteHint = {
@@ -18,6 +18,9 @@ type QuoteHint = {
18
18
  kind: "raise-slippage";
19
19
  currentSlippageBps: number;
20
20
  maxSlippageBps: number;
21
+ } | {
22
+ kind: "raise-min-fill";
23
+ minFillBps: number;
21
24
  } | {
22
25
  kind: "market-full";
23
26
  } | {
@@ -29,7 +32,7 @@ type Params = Record<string, unknown> | null | undefined;
29
32
  declare function quoteErrorHint(code: string | null, params: Params, context: {
30
33
  leverageBps: number;
31
34
  }): QuoteHint;
32
- type CorrectedField = "collateral" | "leverage" | "slippage";
35
+ type CorrectedField = "collateral" | "leverage" | "slippage" | "minFill";
33
36
  type HintAdjustment = {
34
37
  field: "collateral";
35
38
  fromValue: number;
@@ -48,21 +51,32 @@ type HintAdjustment = {
48
51
  toValue: number;
49
52
  toLabel: string;
50
53
  reason: "raise-slippage";
54
+ } | {
55
+ field: "minFill";
56
+ fromValue: number;
57
+ toValue: number;
58
+ toLabel: string;
59
+ reason: "raise-min-fill";
51
60
  } | null;
52
61
  declare function hintAdjustment(hint: QuoteHint, current: {
53
62
  collateralUsd: number;
54
63
  leverageBps: number;
55
64
  slippageBps: number;
65
+ minFillBps?: number;
56
66
  }): HintAdjustment;
57
67
 
58
68
  interface Paginated<T> {
59
69
  data: T[];
60
70
  hasMore: boolean;
71
+ /** Total matching records. Present only when the request includes `expand: ["total_count"]`. */
72
+ totalCount?: number;
61
73
  }
62
74
 
63
75
  interface AuthProvider {
64
76
  getHeaders(): Promise<Record<string, string>>;
65
77
  refresh?(): Promise<void>;
78
+ /** Synchronously return the current cached JWT, or null if not yet obtained. Used by the WebSocket clients. */
79
+ getToken?(): string | null;
66
80
  }
67
81
  interface ApiKeyAuthOptions {
68
82
  apiKey: string;
@@ -80,6 +94,7 @@ declare class ApiKeyAuth implements AuthProvider {
80
94
  private readonly fetchFn;
81
95
  constructor(options: ApiKeyAuthOptions);
82
96
  getHeaders(): Promise<Record<string, string>>;
97
+ getToken(): string | null;
83
98
  refresh(): Promise<void>;
84
99
  private fetchToken;
85
100
  }
@@ -95,6 +110,7 @@ declare class JwtAuth implements AuthProvider {
95
110
  private refreshPromise;
96
111
  constructor(options: JwtAuthOptions);
97
112
  getHeaders(): Promise<Record<string, string>>;
113
+ getToken(): string | null;
98
114
  refresh(): Promise<void>;
99
115
  private fetchToken;
100
116
  }
@@ -107,32 +123,63 @@ interface DimesClientOptions {
107
123
  maxRetryDelayMs?: number;
108
124
  }
109
125
  type MarketSort = "ticker_asc" | "depth_desc" | "discovered_at_desc";
126
+ type MarketExpand = "total_count" | "prices";
127
+ type PositionStatus = "open" | "unwinding" | "pending" | "closing" | "closed" | "settled" | "liquidated";
110
128
  interface GetMarketsParams {
111
- cursor?: string;
112
129
  limit?: number;
130
+ startingAfter?: string;
131
+ endingBefore?: string;
132
+ expand?: MarketExpand[];
133
+ sort?: MarketSort;
134
+ acceptingNewPositions?: boolean;
113
135
  category?: string;
114
136
  status?: string;
115
137
  provider?: "polymarket" | "kalshi";
116
- sort?: MarketSort;
138
+ }
139
+ interface SearchMarketsParams extends GetMarketsParams {
140
+ query: string;
117
141
  }
118
142
  interface GetPositionsParams {
119
- cursor?: string;
120
143
  limit?: number;
121
- status?: "open" | "closed";
144
+ startingAfter?: string;
145
+ endingBefore?: string;
146
+ expand?: string[];
147
+ sortBy?: "created_at" | "closed_at";
148
+ sortDirection?: "asc" | "desc";
149
+ status?: PositionStatus;
150
+ state?: "active" | "inactive";
151
+ }
152
+ interface GetFeeRatesParams {
153
+ ticker?: string;
122
154
  }
123
155
  declare class DimesClient {
156
+ /** The resolved API base URL. Useful for constructing WebSocket clients against the same host. */
157
+ readonly baseUrl: string;
124
158
  private readonly http;
159
+ private readonly auth;
125
160
  constructor(options: DimesClientOptions);
161
+ /** Synchronously return the current cached JWT, or null. Returns null if the auth provider does not expose one. */
162
+ getToken(): string | null;
126
163
  getMarkets(params?: GetMarketsParams): Promise<Paginated<Market>>;
127
164
  getMarket(ticker: string): Promise<Market>;
128
- createDraftQuote(params: CreateOfferParams): Promise<Offer>;
129
- promoteDraftQuote(draftId: string): Promise<Offer>;
130
- createQuote(params: CreateOfferParams): Promise<Offer>;
165
+ searchMarkets(params: SearchMarketsParams): Promise<Paginated<Market>>;
166
+ createDraftQuote(params: CreateQuoteParams): Promise<Quote>;
167
+ promoteDraftQuote(draftId: string): Promise<Quote>;
168
+ createQuote(params: CreateQuoteParams): Promise<Quote>;
131
169
  getPositions(params?: GetPositionsParams): Promise<Position[]>;
132
170
  getPositionTransactions(positionId: string): Promise<PositionTransactions>;
133
171
  cancelPosition(positionId: string): Promise<void>;
134
172
  getContractInfo(): Promise<ContractInfo>;
173
+ getUserLimits(): Promise<CustomerLimit>;
174
+ getPartnerLimits(): Promise<CustomerLimit>;
175
+ /**
176
+ * @deprecated The `/limits` path was never served by the API. Use {@link getUserLimits}
177
+ * (JWT/user context) or {@link getPartnerLimits} (API-key/partner context). This alias
178
+ * forwards to `getUserLimits` and will be removed in a future major.
179
+ */
135
180
  getLimits(): Promise<CustomerLimit>;
181
+ getFeeRates(params?: GetFeeRatesParams): Promise<FeeRates>;
182
+ getFeeReport(params: FeeReportParams): Promise<FeeReport>;
136
183
  }
137
184
 
138
- export { ApiKeyAuth as A, type CorrectedField as C, DimesClient as D, type GetMarketsParams as G, type HintAdjustment as H, JwtAuth as J, type MarketSort as M, type Paginated as P, type QuoteHint as Q, type ApiKeyAuthOptions as a, type AuthProvider as b, type DimesClientOptions as c, type GetPositionsParams as d, type JwtAuthOptions as e, hintAdjustment as h, marketMovedCodes as m, quoteErrorHint as q };
185
+ export { ApiKeyAuth as A, type CorrectedField as C, DimesClient as D, type GetFeeRatesParams as G, type HintAdjustment as H, JwtAuth as J, type MarketExpand as M, type Paginated as P, type QuoteHint as Q, type SearchMarketsParams as S, type ApiKeyAuthOptions as a, type AuthProvider as b, type DimesClientOptions as c, type GetMarketsParams as d, type GetPositionsParams as e, type JwtAuthOptions as f, type MarketSort as g, type PositionStatus as h, hintAdjustment as i, marketMovedCodes as m, quoteErrorHint as q };
@@ -1,4 +1,4 @@
1
- import { M as Market, C as CreateOfferParams, O as Offer, P as Position, B as PositionTransactions, d as ContractInfo, f as CustomerLimit } from './aliases-C2l_JZX_.js';
1
+ import { M as Market, C as CreateQuoteParams, Q as Quote, P as Position, c as PositionTransactions, d as ContractInfo, e as CustomerLimit, F as FeeRates, f as FeeReportParams, g as FeeReport } from './aliases-BJyM8ydu.cjs';
2
2
 
3
3
  declare const marketMovedCodes: Set<string>;
4
4
  type QuoteHint = {
@@ -18,6 +18,9 @@ type QuoteHint = {
18
18
  kind: "raise-slippage";
19
19
  currentSlippageBps: number;
20
20
  maxSlippageBps: number;
21
+ } | {
22
+ kind: "raise-min-fill";
23
+ minFillBps: number;
21
24
  } | {
22
25
  kind: "market-full";
23
26
  } | {
@@ -29,7 +32,7 @@ type Params = Record<string, unknown> | null | undefined;
29
32
  declare function quoteErrorHint(code: string | null, params: Params, context: {
30
33
  leverageBps: number;
31
34
  }): QuoteHint;
32
- type CorrectedField = "collateral" | "leverage" | "slippage";
35
+ type CorrectedField = "collateral" | "leverage" | "slippage" | "minFill";
33
36
  type HintAdjustment = {
34
37
  field: "collateral";
35
38
  fromValue: number;
@@ -48,21 +51,32 @@ type HintAdjustment = {
48
51
  toValue: number;
49
52
  toLabel: string;
50
53
  reason: "raise-slippage";
54
+ } | {
55
+ field: "minFill";
56
+ fromValue: number;
57
+ toValue: number;
58
+ toLabel: string;
59
+ reason: "raise-min-fill";
51
60
  } | null;
52
61
  declare function hintAdjustment(hint: QuoteHint, current: {
53
62
  collateralUsd: number;
54
63
  leverageBps: number;
55
64
  slippageBps: number;
65
+ minFillBps?: number;
56
66
  }): HintAdjustment;
57
67
 
58
68
  interface Paginated<T> {
59
69
  data: T[];
60
70
  hasMore: boolean;
71
+ /** Total matching records. Present only when the request includes `expand: ["total_count"]`. */
72
+ totalCount?: number;
61
73
  }
62
74
 
63
75
  interface AuthProvider {
64
76
  getHeaders(): Promise<Record<string, string>>;
65
77
  refresh?(): Promise<void>;
78
+ /** Synchronously return the current cached JWT, or null if not yet obtained. Used by the WebSocket clients. */
79
+ getToken?(): string | null;
66
80
  }
67
81
  interface ApiKeyAuthOptions {
68
82
  apiKey: string;
@@ -80,6 +94,7 @@ declare class ApiKeyAuth implements AuthProvider {
80
94
  private readonly fetchFn;
81
95
  constructor(options: ApiKeyAuthOptions);
82
96
  getHeaders(): Promise<Record<string, string>>;
97
+ getToken(): string | null;
83
98
  refresh(): Promise<void>;
84
99
  private fetchToken;
85
100
  }
@@ -95,6 +110,7 @@ declare class JwtAuth implements AuthProvider {
95
110
  private refreshPromise;
96
111
  constructor(options: JwtAuthOptions);
97
112
  getHeaders(): Promise<Record<string, string>>;
113
+ getToken(): string | null;
98
114
  refresh(): Promise<void>;
99
115
  private fetchToken;
100
116
  }
@@ -107,32 +123,63 @@ interface DimesClientOptions {
107
123
  maxRetryDelayMs?: number;
108
124
  }
109
125
  type MarketSort = "ticker_asc" | "depth_desc" | "discovered_at_desc";
126
+ type MarketExpand = "total_count" | "prices";
127
+ type PositionStatus = "open" | "unwinding" | "pending" | "closing" | "closed" | "settled" | "liquidated";
110
128
  interface GetMarketsParams {
111
- cursor?: string;
112
129
  limit?: number;
130
+ startingAfter?: string;
131
+ endingBefore?: string;
132
+ expand?: MarketExpand[];
133
+ sort?: MarketSort;
134
+ acceptingNewPositions?: boolean;
113
135
  category?: string;
114
136
  status?: string;
115
137
  provider?: "polymarket" | "kalshi";
116
- sort?: MarketSort;
138
+ }
139
+ interface SearchMarketsParams extends GetMarketsParams {
140
+ query: string;
117
141
  }
118
142
  interface GetPositionsParams {
119
- cursor?: string;
120
143
  limit?: number;
121
- status?: "open" | "closed";
144
+ startingAfter?: string;
145
+ endingBefore?: string;
146
+ expand?: string[];
147
+ sortBy?: "created_at" | "closed_at";
148
+ sortDirection?: "asc" | "desc";
149
+ status?: PositionStatus;
150
+ state?: "active" | "inactive";
151
+ }
152
+ interface GetFeeRatesParams {
153
+ ticker?: string;
122
154
  }
123
155
  declare class DimesClient {
156
+ /** The resolved API base URL. Useful for constructing WebSocket clients against the same host. */
157
+ readonly baseUrl: string;
124
158
  private readonly http;
159
+ private readonly auth;
125
160
  constructor(options: DimesClientOptions);
161
+ /** Synchronously return the current cached JWT, or null. Returns null if the auth provider does not expose one. */
162
+ getToken(): string | null;
126
163
  getMarkets(params?: GetMarketsParams): Promise<Paginated<Market>>;
127
164
  getMarket(ticker: string): Promise<Market>;
128
- createDraftQuote(params: CreateOfferParams): Promise<Offer>;
129
- promoteDraftQuote(draftId: string): Promise<Offer>;
130
- createQuote(params: CreateOfferParams): Promise<Offer>;
165
+ searchMarkets(params: SearchMarketsParams): Promise<Paginated<Market>>;
166
+ createDraftQuote(params: CreateQuoteParams): Promise<Quote>;
167
+ promoteDraftQuote(draftId: string): Promise<Quote>;
168
+ createQuote(params: CreateQuoteParams): Promise<Quote>;
131
169
  getPositions(params?: GetPositionsParams): Promise<Position[]>;
132
170
  getPositionTransactions(positionId: string): Promise<PositionTransactions>;
133
171
  cancelPosition(positionId: string): Promise<void>;
134
172
  getContractInfo(): Promise<ContractInfo>;
173
+ getUserLimits(): Promise<CustomerLimit>;
174
+ getPartnerLimits(): Promise<CustomerLimit>;
175
+ /**
176
+ * @deprecated The `/limits` path was never served by the API. Use {@link getUserLimits}
177
+ * (JWT/user context) or {@link getPartnerLimits} (API-key/partner context). This alias
178
+ * forwards to `getUserLimits` and will be removed in a future major.
179
+ */
135
180
  getLimits(): Promise<CustomerLimit>;
181
+ getFeeRates(params?: GetFeeRatesParams): Promise<FeeRates>;
182
+ getFeeReport(params: FeeReportParams): Promise<FeeReport>;
136
183
  }
137
184
 
138
- export { ApiKeyAuth as A, type CorrectedField as C, DimesClient as D, type GetMarketsParams as G, type HintAdjustment as H, JwtAuth as J, type MarketSort as M, type Paginated as P, type QuoteHint as Q, type ApiKeyAuthOptions as a, type AuthProvider as b, type DimesClientOptions as c, type GetPositionsParams as d, type JwtAuthOptions as e, hintAdjustment as h, marketMovedCodes as m, quoteErrorHint as q };
185
+ export { ApiKeyAuth as A, type CorrectedField as C, DimesClient as D, type GetFeeRatesParams as G, type HintAdjustment as H, JwtAuth as J, type MarketExpand as M, type Paginated as P, type QuoteHint as Q, type SearchMarketsParams as S, type ApiKeyAuthOptions as a, type AuthProvider as b, type DimesClientOptions as c, type GetMarketsParams as d, type GetPositionsParams as e, type JwtAuthOptions as f, type MarketSort as g, type PositionStatus as h, hintAdjustment as i, marketMovedCodes as m, quoteErrorHint as q };
@@ -1,4 +1,4 @@
1
- import { Q as QuoteHint } from './dimes-client-ty6xwk0b.cjs';
1
+ import { Q as QuoteHint } from './dimes-client-DZPhU1CG.cjs';
2
2
 
3
3
  declare class DimesError extends Error {
4
4
  readonly code: string;
@@ -23,4 +23,4 @@ declare class DimesContractError extends DimesError {
23
23
  constructor(code: string, message: string);
24
24
  }
25
25
 
26
- export { DimesApiError as D, DimesContractError as a, DimesError as b };
26
+ export { DimesContractError as D, DimesApiError as a, DimesError as b };
@@ -1,4 +1,4 @@
1
- import { Q as QuoteHint } from './dimes-client-u5wLYVfp.js';
1
+ import { Q as QuoteHint } from './dimes-client-DYFvnZUx.js';
2
2
 
3
3
  declare class DimesError extends Error {
4
4
  readonly code: string;
@@ -23,4 +23,4 @@ declare class DimesContractError extends DimesError {
23
23
  constructor(code: string, message: string);
24
24
  }
25
25
 
26
- export { DimesApiError as D, DimesContractError as a, DimesError as b };
26
+ export { DimesContractError as D, DimesApiError as a, DimesError as b };
package/dist/index.cjs CHANGED
@@ -4,17 +4,18 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkCOSLZ5TMcjs = require('./chunk-COSLZ5TM.cjs');
8
7
 
8
+ var _chunkDIH3ORFAcjs = require('./chunk-DIH3ORFA.cjs');
9
9
 
10
10
 
11
11
 
12
12
 
13
13
 
14
- var _chunkDYPABUKCcjs = require('./chunk-DYPABUKC.cjs');
15
14
 
15
+ var _chunk72LTVPD2cjs = require('./chunk-72LTVPD2.cjs');
16
16
 
17
- var _chunkUHQZSMUDcjs = require('./chunk-UHQZSMUD.cjs');
17
+
18
+ var _chunk53U53KZ2cjs = require('./chunk-53U53KZ2.cjs');
18
19
 
19
20
  // src/client/dimes-client.ts
20
21
  var _humps = require('humps');
@@ -59,7 +60,7 @@ async function throwFromResponse(response) {
59
60
  const message = _nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _5 => _5.error, 'optionalAccess', _6 => _6.message]), () => ( `API error ${response.status}`));
60
61
  const rawParams = _optionalChain([parsed, 'optionalAccess', _7 => _7.error, 'optionalAccess', _8 => _8.params]);
61
62
  const params = rawParams ? _humps.camelizeKeys.call(void 0, rawParams) : null;
62
- throw new (0, _chunkDYPABUKCcjs.DimesApiError)({ status: response.status, code, type, message, params });
63
+ throw new (0, _chunk72LTVPD2cjs.DimesApiError)({ status: response.status, code, type, message, params });
63
64
  }
64
65
  var HttpClient = class {
65
66
 
@@ -132,16 +133,25 @@ function buildQueryFromEntries(entries) {
132
133
  return `?${search.toString()}`;
133
134
  }
134
135
  var DimesClient = class {
136
+ /** The resolved API base URL. Useful for constructing WebSocket clients against the same host. */
137
+
138
+
135
139
 
136
140
  constructor(options) {
141
+ this.baseUrl = _nullishCoalesce(options.baseUrl, () => ( "https://api.dimes.fi"));
142
+ this.auth = options.auth;
137
143
  this.http = new HttpClient({
138
- baseUrl: _nullishCoalesce(options.baseUrl, () => ( "https://api.dimes.fi")),
144
+ baseUrl: this.baseUrl,
139
145
  auth: options.auth,
140
146
  fetch: options.fetch,
141
147
  maxRetries: options.maxRetries,
142
148
  maxRetryDelayMs: options.maxRetryDelayMs
143
149
  });
144
150
  }
151
+ /** Synchronously return the current cached JWT, or null. Returns null if the auth provider does not expose one. */
152
+ getToken() {
153
+ return _nullishCoalesce(_optionalChain([this, 'access', _10 => _10.auth, 'access', _11 => _11.getToken, 'optionalCall', _12 => _12()]), () => ( null));
154
+ }
145
155
  async getMarkets(params) {
146
156
  const query = params ? buildQueryFromEntries(Object.entries(params)) : "";
147
157
  return this.http.request(`/v1/prediction-markets/markets${query}`);
@@ -149,6 +159,10 @@ var DimesClient = class {
149
159
  async getMarket(ticker) {
150
160
  return this.http.request(`/v1/prediction-markets/markets/${encodeURIComponent(ticker)}`);
151
161
  }
162
+ async searchMarkets(params) {
163
+ const query = buildQueryFromEntries(Object.entries(params));
164
+ return this.http.request(`/v1/prediction-markets/markets/search${query}`);
165
+ }
152
166
  async createDraftQuote(params) {
153
167
  return this.http.request("/v1/prediction-markets/draft-quotes", {
154
168
  method: "POST",
@@ -176,15 +190,36 @@ var DimesClient = class {
176
190
  );
177
191
  }
178
192
  async cancelPosition(positionId) {
179
- await this.http.request(`/v1/prediction-markets/positions/${encodeURIComponent(positionId)}/cancel`, {
180
- method: "POST"
193
+ await this.http.request(`/v1/prediction-markets/positions/${encodeURIComponent(positionId)}`, {
194
+ method: "DELETE"
181
195
  });
182
196
  }
183
197
  async getContractInfo() {
184
198
  return this.http.request("/v1/prediction-markets/contract-info");
185
199
  }
200
+ async getUserLimits() {
201
+ return this.http.request("/v1/prediction-markets/user-limits");
202
+ }
203
+ async getPartnerLimits() {
204
+ return this.http.request("/v1/prediction-markets/partner-limits");
205
+ }
206
+ /**
207
+ * @deprecated The `/limits` path was never served by the API. Use {@link getUserLimits}
208
+ * (JWT/user context) or {@link getPartnerLimits} (API-key/partner context). This alias
209
+ * forwards to `getUserLimits` and will be removed in a future major.
210
+ */
186
211
  async getLimits() {
187
- return this.http.request("/v1/prediction-markets/limits");
212
+ return this.getUserLimits();
213
+ }
214
+ async getFeeRates(params) {
215
+ const query = params ? buildQueryFromEntries(Object.entries(params)) : "";
216
+ return this.http.request(`/v1/prediction-markets/fee-rates${query}`);
217
+ }
218
+ async getFeeReport(params) {
219
+ return this.http.request("/v1/prediction-markets/fee-reports", {
220
+ method: "POST",
221
+ body: JSON.stringify(_humps.decamelizeKeys.call(void 0, params))
222
+ });
188
223
  }
189
224
  };
190
225
 
@@ -210,6 +245,9 @@ var ApiKeyAuth = (_class = class {
210
245
  }
211
246
  return { Authorization: `Bearer ${this.jwt}` };
212
247
  }
248
+ getToken() {
249
+ return this.jwt;
250
+ }
213
251
  async refresh() {
214
252
  if (this.refreshPromise) {
215
253
  await this.refreshPromise;
@@ -227,13 +265,13 @@ var ApiKeyAuth = (_class = class {
227
265
  method: "POST",
228
266
  headers: {
229
267
  "Content-Type": "application/json",
230
- Authorization: `Bearer ${this.apiKey}`
268
+ Authorization: `Api-Key ${this.apiKey}`
231
269
  },
232
270
  body: JSON.stringify({ wallet_address: this.walletAddress })
233
271
  });
234
272
  if (!response.ok) {
235
273
  const text = await response.text();
236
- throw new (0, _chunkDYPABUKCcjs.DimesError)("auth_token_failed", `Failed to obtain auth token (${response.status}): ${text}`);
274
+ throw new (0, _chunk72LTVPD2cjs.DimesError)("auth_token_failed", `Failed to obtain auth token (${response.status}): ${text}`);
237
275
  }
238
276
  const data = await response.json();
239
277
  this.jwt = data.token;
@@ -257,6 +295,9 @@ var JwtAuth = (_class2 = class {
257
295
  }
258
296
  return { Authorization: `Bearer ${this.jwt}` };
259
297
  }
298
+ getToken() {
299
+ return this.jwt;
300
+ }
260
301
  async refresh() {
261
302
  if (this.refreshPromise) {
262
303
  await this.refreshPromise;
@@ -273,7 +314,7 @@ var JwtAuth = (_class2 = class {
273
314
  const response = await this.fetchFn(this.tokenUrl);
274
315
  if (!response.ok) {
275
316
  const text = await response.text();
276
- throw new (0, _chunkDYPABUKCcjs.DimesError)(
317
+ throw new (0, _chunk72LTVPD2cjs.DimesError)(
277
318
  "auth_token_failed",
278
319
  `Failed to fetch token from ${this.tokenUrl} (${response.status}): ${text}`
279
320
  );
@@ -421,6 +462,25 @@ function maxViableLeverageBpsForCollateral(market, side, collateralUsd) {
421
462
  }
422
463
 
423
464
  // src/utils/fees.ts
465
+ var BPS_DIVISOR = 1e4;
466
+ function resolveProtocolOriginationFeeBps(tiers, leverageBps) {
467
+ const lastTier = tiers[tiers.length - 1];
468
+ if (!lastTier) {
469
+ return 0;
470
+ }
471
+ for (const tier of tiers) {
472
+ if (leverageBps <= tier.maxLeverageBps) {
473
+ return tier.feeBps;
474
+ }
475
+ }
476
+ return lastTier.feeBps;
477
+ }
478
+ function resolveOriginationFeeBps(tiers, leverageBps, partnerOriginationFeeBps) {
479
+ return resolveProtocolOriginationFeeBps(tiers, leverageBps) + partnerOriginationFeeBps;
480
+ }
481
+ function computeOriginationFeeUsdcUnits(notionalUsdcUnits, combinedOriginationFeeBps) {
482
+ return Math.floor(notionalUsdcUnits * combinedOriginationFeeBps / BPS_DIVISOR);
483
+ }
424
484
  function getEntry(position) {
425
485
  return position.entry;
426
486
  }
@@ -443,6 +503,98 @@ function getOriginationFeeBreakdown(position) {
443
503
  };
444
504
  }
445
505
 
506
+ // src/utils/max-gain.ts
507
+ var BPS_DIVISOR2 = 1e4;
508
+ var USDC_UNITS_PER_USD = 1e6;
509
+ var TOKEN_UNITS_PER_TOKEN = 1e6;
510
+ function computePolymarketTradingFee(input) {
511
+ const { notionalUsdcUnits, priceUsd, feeRateBps } = input;
512
+ const feeExponent = _nullishCoalesce(input.feeExponent, () => ( 1));
513
+ const builderTakerFeeRateBps = _nullishCoalesce(input.builderTakerFeeRateBps, () => ( 0));
514
+ if (priceUsd <= 0) {
515
+ return 0;
516
+ }
517
+ const notionalUsd = notionalUsdcUnits / USDC_UNITS_PER_USD;
518
+ const contracts = notionalUsd / priceUsd;
519
+ const curvature = (priceUsd * (1 - priceUsd)) ** feeExponent;
520
+ const protocolFeeUsdcUnits = feeRateBps / BPS_DIVISOR2 * contracts * curvature * USDC_UNITS_PER_USD;
521
+ const builderFeeUsdcUnits = builderTakerFeeRateBps / BPS_DIVISOR2 * notionalUsdcUnits;
522
+ return Math.ceil(protocolFeeUsdcUnits + builderFeeUsdcUnits);
523
+ }
524
+ function expectedPositionTokenUnits(notionalUsdcUnits, entryPriceUsd, slippageBps = 0) {
525
+ if (entryPriceUsd <= 0) {
526
+ return 0;
527
+ }
528
+ const notionalUsd = notionalUsdcUnits / USDC_UNITS_PER_USD;
529
+ const tokens = notionalUsd / entryPriceUsd;
530
+ const slippageFactor = (BPS_DIVISOR2 - slippageBps) / BPS_DIVISOR2;
531
+ return Math.floor(tokens * slippageFactor * TOKEN_UNITS_PER_TOKEN);
532
+ }
533
+ function estimateLiquidationPrice(entryPriceUsd, leverageBps, liquidationFeeBps) {
534
+ const leverage = leverageBps / BPS_DIVISOR2;
535
+ if (leverage <= 1) {
536
+ return 0;
537
+ }
538
+ const loanPerToken = entryPriceUsd * ((leverage - 1) / leverage);
539
+ return loanPerToken * (1 + liquidationFeeBps / BPS_DIVISOR2);
540
+ }
541
+ function computeMaxGain(input) {
542
+ const fullValueOnWinUsdcUnits = input.positionTokenUnits;
543
+ const grossMaxGainUsdcUnits = fullValueOnWinUsdcUnits - input.notionalUsdcUnits;
544
+ const netMaxGainUsdcUnits = grossMaxGainUsdcUnits - input.expectedOpenTradingFeeUsdcUnits - input.originationFeeUsdcUnits;
545
+ return {
546
+ fullValueOnWinUsdcUnits,
547
+ grossMaxGainUsdcUnits,
548
+ netMaxGainUsdcUnits
549
+ };
550
+ }
551
+
552
+ // src/utils/partial-close.ts
553
+ var BPS_DIVISOR3 = 1e4;
554
+ var BPS_DIVISOR_BIG = 10000n;
555
+ var tokenUnitsPerToken = 1000000n;
556
+ var partialCloseMinTokens = 5n;
557
+ var partialCloseMinFractionBps = 2000n;
558
+ function closeTokenUnitsForPct(currentTokenUnits, pctBps) {
559
+ const clampedBps = BigInt(Math.max(0, Math.min(BPS_DIVISOR3, Math.round(pctBps))));
560
+ return currentTokenUnits * clampedBps / BPS_DIVISOR_BIG;
561
+ }
562
+ function pctBpsForCloseTokenUnits(currentTokenUnits, closeTokenUnits) {
563
+ if (currentTokenUnits <= 0n) {
564
+ return 0;
565
+ }
566
+ return Number(closeTokenUnits * BPS_DIVISOR_BIG / currentTokenUnits);
567
+ }
568
+ function fallbackMinPartialCloseTokenUnits(originalTokenUnits) {
569
+ const floorTokens = partialCloseMinTokens * tokenUnitsPerToken;
570
+ const floorFraction = originalTokenUnits * partialCloseMinFractionBps / BPS_DIVISOR_BIG;
571
+ return floorFraction > floorTokens ? floorFraction : floorTokens;
572
+ }
573
+ function clampCloseTokenUnits(value, min, max) {
574
+ if (value < min) {
575
+ return min;
576
+ }
577
+ if (value > max) {
578
+ return max;
579
+ }
580
+ return value;
581
+ }
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
446
598
 
447
599
 
448
600
 
@@ -469,5 +621,5 @@ function getOriginationFeeBreakdown(position) {
469
621
 
470
622
 
471
623
 
472
- exports.ApiKeyAuth = ApiKeyAuth; exports.DimesApiError = _chunkDYPABUKCcjs.DimesApiError; exports.DimesClient = DimesClient; exports.DimesContractError = _chunkDYPABUKCcjs.DimesContractError; exports.DimesError = _chunkDYPABUKCcjs.DimesError; exports.JwtAuth = JwtAuth; exports.buildQuoteParams = _chunkCOSLZ5TMcjs.buildQuoteParams; exports.defaultSide = defaultSide; exports.executeQuote = _chunkCOSLZ5TMcjs.executeQuote; exports.formatErrorMessage = _chunkDYPABUKCcjs.formatErrorMessage; exports.getOriginationFeeBreakdown = getOriginationFeeBreakdown; exports.getSidedEligibility = getSidedEligibility; exports.hintAdjustment = _chunkCOSLZ5TMcjs.hintAdjustment; exports.isClosedPosition = isClosedPosition; exports.isFullyClosed = isFullyClosed; exports.isFullyOpen = isFullyOpen; exports.isOpenPosition = isOpenPosition; exports.leverageMaxBps = leverageMaxBps; exports.marketMovedCodes = _chunkCOSLZ5TMcjs.marketMovedCodes; exports.maxLeverageBpsAtNotional = maxLeverageBpsAtNotional; exports.maxViableLeverageBpsForCollateral = maxViableLeverageBpsForCollateral; exports.positionEventTypes = _chunkUHQZSMUDcjs.positionEventTypes; exports.quoteErrorHint = _chunkCOSLZ5TMcjs.quoteErrorHint; exports.rejectionReasonShort = rejectionReasonShort; exports.rejectionReasonText = rejectionReasonText; exports.resolveFriendlyMessage = _chunkDYPABUKCcjs.resolveFriendlyMessage;
624
+ exports.ApiKeyAuth = ApiKeyAuth; exports.DimesApiError = _chunk72LTVPD2cjs.DimesApiError; exports.DimesClient = DimesClient; exports.DimesContractError = _chunk72LTVPD2cjs.DimesContractError; exports.DimesError = _chunk72LTVPD2cjs.DimesError; exports.JwtAuth = JwtAuth; exports.buildQuoteParams = _chunkDIH3ORFAcjs.buildQuoteParams; exports.clampCloseTokenUnits = clampCloseTokenUnits; exports.closeTokenUnitsForPct = closeTokenUnitsForPct; exports.computeMaxGain = computeMaxGain; exports.computeOriginationFeeUsdcUnits = computeOriginationFeeUsdcUnits; exports.computePolymarketTradingFee = computePolymarketTradingFee; exports.defaultSide = defaultSide; exports.estimateLiquidationPrice = estimateLiquidationPrice; exports.executeQuote = _chunkDIH3ORFAcjs.executeQuote; exports.expectedPositionTokenUnits = expectedPositionTokenUnits; exports.fallbackMinPartialCloseTokenUnits = fallbackMinPartialCloseTokenUnits; exports.formatErrorMessage = _chunk72LTVPD2cjs.formatErrorMessage; exports.getOriginationFeeBreakdown = getOriginationFeeBreakdown; exports.getSidedEligibility = getSidedEligibility; exports.hintAdjustment = _chunkDIH3ORFAcjs.hintAdjustment; exports.isClosedPosition = isClosedPosition; exports.isFullyClosed = isFullyClosed; exports.isFullyOpen = isFullyOpen; exports.isMarketMovedError = _chunkDIH3ORFAcjs.isMarketMovedError; exports.isOpenPosition = isOpenPosition; exports.leverageMaxBps = leverageMaxBps; exports.marketMovedCodes = _chunkDIH3ORFAcjs.marketMovedCodes; exports.maxLeverageBpsAtNotional = maxLeverageBpsAtNotional; exports.maxViableLeverageBpsForCollateral = maxViableLeverageBpsForCollateral; exports.partialCloseMinFractionBps = partialCloseMinFractionBps; exports.partialCloseMinTokens = partialCloseMinTokens; exports.pctBpsForCloseTokenUnits = pctBpsForCloseTokenUnits; exports.positionEventTypes = _chunk53U53KZ2cjs.positionEventTypes; exports.quoteErrorHint = _chunkDIH3ORFAcjs.quoteErrorHint; exports.rejectionReasonShort = rejectionReasonShort; exports.rejectionReasonText = rejectionReasonText; exports.resolveFriendlyMessage = _chunk72LTVPD2cjs.resolveFriendlyMessage; exports.resolveOriginationFeeBps = resolveOriginationFeeBps; exports.resolveProtocolOriginationFeeBps = resolveProtocolOriginationFeeBps; exports.tokenUnitsPerToken = tokenUnitsPerToken;
473
625
  //# sourceMappingURL=index.cjs.map