pmxt-core 2.23.0 → 2.24.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 (40) hide show
  1. package/dist/exchanges/kalshi/api.d.ts +1 -1
  2. package/dist/exchanges/kalshi/api.js +1 -1
  3. package/dist/exchanges/limitless/api.d.ts +1 -1
  4. package/dist/exchanges/limitless/api.js +1 -1
  5. package/dist/exchanges/myriad/api.d.ts +1 -1
  6. package/dist/exchanges/myriad/api.js +1 -1
  7. package/dist/exchanges/opinion/api.d.ts +1 -1
  8. package/dist/exchanges/opinion/api.js +1 -1
  9. package/dist/exchanges/polymarket/api-clob.d.ts +1 -1
  10. package/dist/exchanges/polymarket/api-clob.js +1 -1
  11. package/dist/exchanges/polymarket/api-data.d.ts +1 -1
  12. package/dist/exchanges/polymarket/api-data.js +1 -1
  13. package/dist/exchanges/polymarket/api-gamma.d.ts +1 -1
  14. package/dist/exchanges/polymarket/api-gamma.js +1 -1
  15. package/dist/exchanges/polymarket/auth.js +42 -8
  16. package/dist/exchanges/polymarket/index.js +56 -19
  17. package/dist/exchanges/probable/api.d.ts +1 -1
  18. package/dist/exchanges/probable/api.js +1 -1
  19. package/dist/exchanges/smarkets/api.d.ts +8067 -0
  20. package/dist/exchanges/smarkets/api.js +10698 -0
  21. package/dist/exchanges/smarkets/auth.d.ts +56 -0
  22. package/dist/exchanges/smarkets/auth.js +105 -0
  23. package/dist/exchanges/smarkets/config.d.ts +41 -0
  24. package/dist/exchanges/smarkets/config.js +47 -0
  25. package/dist/exchanges/smarkets/errors.d.ts +31 -0
  26. package/dist/exchanges/smarkets/errors.js +186 -0
  27. package/dist/exchanges/smarkets/fetcher.d.ts +177 -0
  28. package/dist/exchanges/smarkets/fetcher.js +342 -0
  29. package/dist/exchanges/smarkets/index.d.ts +54 -0
  30. package/dist/exchanges/smarkets/index.js +285 -0
  31. package/dist/exchanges/smarkets/normalizer.d.ts +18 -0
  32. package/dist/exchanges/smarkets/normalizer.js +267 -0
  33. package/dist/exchanges/smarkets/price.d.ts +26 -0
  34. package/dist/exchanges/smarkets/price.js +44 -0
  35. package/dist/exchanges/smarkets/price.test.d.ts +1 -0
  36. package/dist/exchanges/smarkets/price.test.js +50 -0
  37. package/dist/index.d.ts +4 -0
  38. package/dist/index.js +5 -1
  39. package/dist/server/app.js +12 -2
  40. package/package.json +3 -3
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/kalshi/Kalshi.yaml
3
- * Generated at: 2026-04-04T07:52:19.224Z
3
+ * Generated at: 2026-04-06T14:01:00.935Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const kalshiApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.kalshiApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/kalshi/Kalshi.yaml
6
- * Generated at: 2026-04-04T07:52:19.224Z
6
+ * Generated at: 2026-04-06T14:01:00.935Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.kalshiApiSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/limitless/Limitless.yaml
3
- * Generated at: 2026-04-04T07:52:19.272Z
3
+ * Generated at: 2026-04-06T14:01:00.982Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const limitlessApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.limitlessApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/limitless/Limitless.yaml
6
- * Generated at: 2026-04-04T07:52:19.272Z
6
+ * Generated at: 2026-04-06T14:01:00.982Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.limitlessApiSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/myriad/myriad.yaml
3
- * Generated at: 2026-04-04T07:52:19.286Z
3
+ * Generated at: 2026-04-06T14:01:00.996Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const myriadApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.myriadApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/myriad/myriad.yaml
6
- * Generated at: 2026-04-04T07:52:19.286Z
6
+ * Generated at: 2026-04-06T14:01:00.996Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.myriadApiSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/opinion/opinion-openapi.yaml
3
- * Generated at: 2026-04-04T07:52:19.290Z
3
+ * Generated at: 2026-04-06T14:01:01.002Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const opinionApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.opinionApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/opinion/opinion-openapi.yaml
6
- * Generated at: 2026-04-04T07:52:19.290Z
6
+ * Generated at: 2026-04-06T14:01:01.002Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.opinionApiSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketClobAPI.yaml
3
- * Generated at: 2026-04-04T07:52:19.235Z
3
+ * Generated at: 2026-04-06T14:01:00.943Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketClobSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketClobSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketClobAPI.yaml
6
- * Generated at: 2026-04-04T07:52:19.235Z
6
+ * Generated at: 2026-04-06T14:01:00.943Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketClobSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/Polymarket_Data_API.yaml
3
- * Generated at: 2026-04-04T07:52:19.249Z
3
+ * Generated at: 2026-04-06T14:01:00.959Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketDataSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketDataSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/Polymarket_Data_API.yaml
6
- * Generated at: 2026-04-04T07:52:19.249Z
6
+ * Generated at: 2026-04-06T14:01:00.959Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketDataSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketGammaAPI.yaml
3
- * Generated at: 2026-04-04T07:52:19.246Z
3
+ * Generated at: 2026-04-06T14:01:00.956Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketGammaSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketGammaSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketGammaAPI.yaml
6
- * Generated at: 2026-04-04T07:52:19.246Z
6
+ * Generated at: 2026-04-06T14:01:00.956Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketGammaSpec = {
@@ -158,22 +158,56 @@ class PolymarketAuth {
158
158
  if (this.clobClient) {
159
159
  return this.clobClient;
160
160
  }
161
- // 1. Determine proxy and signature type early
161
+ // 1. Determine proxy and signature type early.
162
+ //
163
+ // Important: if signatureType is not provided we MUST run discovery
164
+ // even when funderAddress is provided. Previously this branch was
165
+ // skipped whenever funderAddress was set, which silently defaulted
166
+ // signatureType to 0 (EOA). For wallets whose funds live on a Gnosis
167
+ // Safe (the modern Polymarket onboarding default) the CLOB then
168
+ // reports balance "0" instead of the real value, with no error.
169
+ const sigTypeProvided = this.credentials.signatureType !== undefined && this.credentials.signatureType !== null;
162
170
  let proxyAddress = this.credentials.funderAddress || undefined;
163
- let signatureType = this.mapSignatureType(this.credentials.signatureType);
164
- if (!proxyAddress) {
165
- const discovered = await this.discoverProxy();
166
- proxyAddress = discovered.proxyAddress;
167
- if (this.credentials.signatureType === undefined || this.credentials.signatureType === null) {
168
- signatureType = discovered.signatureType;
171
+ let signatureType = sigTypeProvided
172
+ ? this.mapSignatureType(this.credentials.signatureType)
173
+ : undefined;
174
+ // Run discovery if either piece is missing. Note: discoverProxy()
175
+ // returns a synthetic { proxyAddress: signerEOA, signatureType: 0 }
176
+ // fallback when its HTTP call fails — that fallback should NOT be
177
+ // used to populate signatureType when funderAddress is already set,
178
+ // because it would silently assign EOA semantics to a Gnosis Safe.
179
+ let discoverySucceeded = false;
180
+ if (!proxyAddress || signatureType === undefined) {
181
+ try {
182
+ const discovered = await this.discoverProxy();
183
+ discoverySucceeded =
184
+ !!this.discoveredProxyAddress &&
185
+ this.discoveredSignatureType !== undefined;
186
+ if (!proxyAddress) {
187
+ proxyAddress = discovered.proxyAddress;
188
+ }
189
+ if (signatureType === undefined && discoverySucceeded) {
190
+ signatureType = discovered.signatureType;
191
+ }
192
+ }
193
+ catch {
194
+ // Discovery failure is handled by the heuristic below.
169
195
  }
170
196
  }
171
197
  // Get API credentials (L1 auth)
172
- // Pass signature type if we know it (some accounts need it for derivation?)
173
198
  const apiCreds = await this.getApiCredentials();
174
199
  // 3. Defaults
175
200
  const signerAddress = this.signer.address;
176
201
  const finalProxyAddress = (proxyAddress || signerAddress);
202
+ // If signature type is still unknown, infer from address relationship:
203
+ // when the funder differs from the signer EOA, the funder must be a
204
+ // proxy/safe — default to Gnosis Safe (2), which is what Polymarket
205
+ // has created for new accounts since 2023. Users on the legacy
206
+ // Polymarket Proxy (1) need to set signatureType explicitly.
207
+ if (signatureType === undefined) {
208
+ signatureType =
209
+ finalProxyAddress.toLowerCase() !== signerAddress.toLowerCase() ? 2 : 0;
210
+ }
177
211
  const finalSignatureType = signatureType;
178
212
  // Create L2-authenticated client
179
213
  // console.log(`[PolymarketAuth] Initializing ClobClient | Signer: ${signerAddress} | Funder: ${finalProxyAddress} | SigType: ${finalSignatureType}`);
@@ -357,45 +357,82 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
357
357
  const client = await auth.getClobClient();
358
358
  // Polymarket relies strictly on USDC (Polygon)
359
359
  const USDC_DECIMALS = 6;
360
- // Try fetching from CLOB client first
360
+ // Try fetching from CLOB client first.
361
+ //
362
+ // Note on the bundled @polymarket/clob-client error model: its HTTP
363
+ // wrapper swallows axios errors and RETURNS an envelope shaped like
364
+ // { error, status } instead of throwing. We must therefore validate
365
+ // the shape of the result before using it, otherwise downstream
366
+ // parseFloat() yields NaN and the on-chain fallback never triggers.
361
367
  let total = 0;
368
+ let clobBalanceAvailable = false;
362
369
  try {
363
370
  const balRes = await client.getBalanceAllowance({
364
371
  asset_type: clob_client_1.AssetType.COLLATERAL,
365
372
  });
366
- const rawBalance = parseFloat(balRes.balance);
367
- total = rawBalance / Math.pow(10, USDC_DECIMALS);
373
+ if (balRes && typeof balRes.balance === 'string') {
374
+ const rawBalance = parseFloat(balRes.balance);
375
+ if (Number.isFinite(rawBalance)) {
376
+ total = rawBalance / Math.pow(10, USDC_DECIMALS);
377
+ clobBalanceAvailable = true;
378
+ }
379
+ }
380
+ // If balRes was an error envelope, fall through to on-chain.
368
381
  }
369
382
  catch (clobError) {
370
- // If CLOB fails or returns 0 (suspiciously), we can try on-chain
371
- // but let's assume we proceed to on-chain check if total is 0
372
- // or just do on-chain check always for robustness if possible.
373
- // For now, let's trust CLOB but add On-Chain fallback if CLOB returns 0.
383
+ // Network/transport error fall through to on-chain.
374
384
  }
375
385
  // On-Chain Fallback/Check (Robustness)
376
- // If CLOB reported 0, let's verify on-chain because sometimes CLOB is behind or confused about proxies
377
- if (total === 0) {
386
+ // Trigger when CLOB couldn't tell us, or reported a true zero (CLOB
387
+ // can lag or be confused about proxies for newly funded wallets).
388
+ if (!clobBalanceAvailable || total === 0) {
378
389
  try {
379
390
  const targetAddress = await auth.getEffectiveFunderAddress();
380
391
  const balances = await this.getAddressOnChainBalance(targetAddress);
381
- total = balances[0]?.total ?? 0;
392
+ const onChain = balances[0]?.total ?? 0;
393
+ if (onChain > 0) {
394
+ total = onChain;
395
+ }
382
396
  }
383
397
  catch {
384
398
  }
385
399
  }
386
- // 2. Fetch open orders to calculate locked funds
387
- // We only care about BUY orders for USDC balance locking
388
- const openOrders = await client.getOpenOrders({});
400
+ // 2. Fetch open orders to calculate locked funds.
401
+ // We only care about BUY orders for USDC balance locking.
402
+ //
403
+ // The bundled @polymarket/clob-client throws "response.data is not
404
+ // iterable" from inside its getOpenOrders pagination loop whenever
405
+ // the CLOB API returns an HTTP error envelope (the library spreads
406
+ // response.data unconditionally). This is the root cause of #72:
407
+ // a wallet that has not completed Polymarket onboarding triggers an
408
+ // upstream auth/setup rejection that surfaces here as an opaque
409
+ // TypeError. Catch it and translate to a clear AuthenticationError.
389
410
  let locked = 0;
390
- if (openOrders && Array.isArray(openOrders)) {
391
- for (const order of openOrders) {
392
- if (order.side === clob_client_1.Side.BUY) {
393
- const remainingSize = parseFloat(order.original_size) - parseFloat(order.size_matched);
394
- const price = parseFloat(order.price);
395
- locked += remainingSize * price;
411
+ try {
412
+ const openOrders = await client.getOpenOrders({});
413
+ if (Array.isArray(openOrders)) {
414
+ for (const order of openOrders) {
415
+ if (order.side === clob_client_1.Side.BUY) {
416
+ const remainingSize = parseFloat(order.original_size) - parseFloat(order.size_matched);
417
+ const price = parseFloat(order.price);
418
+ locked += remainingSize * price;
419
+ }
396
420
  }
397
421
  }
398
422
  }
423
+ catch (ordersError) {
424
+ const msg = String(ordersError?.message ?? ordersError);
425
+ if (msg.includes('is not iterable')) {
426
+ throw new errors_1.AuthenticationError('Polymarket CLOB rejected the request to list open orders. ' +
427
+ 'This usually means the wallet has not completed Polymarket ' +
428
+ 'onboarding (no proxy/safe exists for this signer), or that ' +
429
+ 'funderAddress / signatureType need to be passed explicitly. ' +
430
+ 'Visit https://polymarket.com to complete account setup, or ' +
431
+ 'pass funderAddress and signatureType in credentials.', 'Polymarket');
432
+ }
433
+ // Unexpected failure — surface through the standard mapper.
434
+ throw ordersError;
435
+ }
399
436
  return [{
400
437
  currency: 'USDC',
401
438
  total: total,
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/probable/probable.yaml
3
- * Generated at: 2026-04-04T07:52:19.280Z
3
+ * Generated at: 2026-04-06T14:01:00.988Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const probableApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.probableApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/probable/probable.yaml
6
- * Generated at: 2026-04-04T07:52:19.280Z
6
+ * Generated at: 2026-04-06T14:01:00.988Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.probableApiSpec = {