@predictasiax/api 2.0.0 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
1
  # @predictasiax/api Changelog
2
2
 
3
+ ## v2.2.0 — 2026-09-05
4
+
5
+ **Trust Layer — public Merkle verifier.**
6
+
7
+ ### Added
8
+ - **`pax.audit`** — new resource for the public no-auth verifier surface. Any
9
+ third party (auditor / investor / external verifier) can independently
10
+ reconstruct the hash-chained event log + Merkle batches + R2 anchors without
11
+ trusting the PAX API at all.
12
+ - **`pax.audit.status()`** — live counts: total events, batches, anchored,
13
+ anchor lag, publisher mode.
14
+ - **`pax.audit.latestBatch()`** — most recent Merkle batch metadata.
15
+ - **`pax.audit.getBatch(batchNum)`** — inspect any historical batch.
16
+ - **`pax.audit.getEvent(seq)`** — inspect one event (payload, event_hash,
17
+ prev_event_hash — full hash-chain surface).
18
+ - **`pax.audit.getProof(seq)`** — Merkle inclusion proof (sibling hashes)
19
+ proving the event is in its batch's `merkle_root`. Algo: OpenZeppelin
20
+ sorted-pair sha256 — Solidity-compatible for on-chain verification.
21
+ - **`pax.audit.getAnchor(batchNum)`** — resolve to external anchor URL
22
+ (R2 signed payload) for out-of-band verification.
23
+ - **`AuditResource.verifyProof(leaf, root, proof)`** — Node-side local
24
+ verification helper.
25
+ - **`AuditResource.verifyProofAsync(leaf, root, proof)`** — WebCrypto
26
+ variant for browsers / edge runtimes.
27
+ - **New types**: `AuditStatus`, `AuditBatch`, `AuditEvent`, `MerkleProof`.
28
+
29
+ ### Why this matters
30
+ Polymarket and OPINION Labs both publish smart-contract audit PDFs, but
31
+ neither exposes a live public verifier over their operational ledger. PAX now
32
+ does — auditors can chain-verify every fill without contacting PAX support.
33
+
34
+ ## v2.1.0 — 2026-09-05
35
+ ## v2.1.0 — 2026-09-05
36
+
37
+ **Polymarket-parity + surpass surface.**
38
+
39
+ ### Added
40
+ - **`pax.orders.placeBatch(orders)`** — POST `/v1/orders/batch`, up to 25 orders
41
+ per request, sequential CLOB processing, per-item results + summary.
42
+ Batch cap env-tunable server-side (BATCH_ORDERS_MAX default 25).
43
+ - **`pax.orders.cancelBatch(orderIds)`** — DELETE `/v1/orders/batch`, up to 50
44
+ cancels per request. Same shape as `placeBatch`.
45
+ - **`pax.fees`** namespace — new `FeesResource`:
46
+ - **`pax.fees.estimate(params)`** — GET `/v1/fees/estimate`, pre-trade 5-actor
47
+ split preview. Returns identical `fee` block shape as post-trade responses.
48
+ - **New types**: `BatchOrderResultItem`, `BatchCancelResultItem`, `BatchOrderSummary`,
49
+ `BatchOrdersResult`, `BatchCancelResult`, `FeeEstimateParams`, `FeeEstimate`.
50
+ - Auto Idempotency-Key is generated for batch POST/DELETE (server middleware
51
+ requires it globally on `/v1/*` mutations).
52
+
53
+ ### Retained
54
+ - All v2.0.0 resources unchanged — batch is additive.
55
+ - Single-order `pax.orders.place` / `.cancel` continue to work; use them for
56
+ latency-sensitive single-order flows where batch would add serialization.
57
+
58
+ ## v2.0.0 — 2026-09-05
3
59
  ## v2.0.0 — 2026-09-05
4
60
 
5
61
  **Aligned with PAX API v2.0.0 (`https://api.predictasiax.com/v1`).**
package/dist/index.cjs CHANGED
@@ -33,7 +33,9 @@ __export(index_exports, {
33
33
  APIPromise: () => APIPromise,
34
34
  AccountResource: () => AccountResource,
35
35
  ApplyResource: () => ApplyResource,
36
+ AuditResource: () => AuditResource,
36
37
  CursorPage: () => CursorPage,
38
+ FeesResource: () => FeesResource,
37
39
  GrantsResource: () => GrantsResource,
38
40
  KeysResource: () => KeysResource,
39
41
  MarketsResource: () => MarketsResource,
@@ -363,7 +365,7 @@ async function runWithRetry(fn, opts = {}) {
363
365
  }
364
366
 
365
367
  // src/http.ts
366
- var VERSION = "2.0.0";
368
+ var VERSION = "2.2.0";
367
369
  var ENV_URLS = {
368
370
  production: "https://api.predictasiax.com/v1",
369
371
  prod: "https://api.predictasiax.com/v1",
@@ -784,6 +786,96 @@ var AccountResource = class extends Resource {
784
786
  }
785
787
  };
786
788
 
789
+ // src/resources/audit.ts
790
+ var AuditResource = class extends Resource {
791
+ status(opts) {
792
+ return this._apiPromise(
793
+ () => this._http.request("GET", "/v1/audit/status", void 0, void 0, opts)
794
+ );
795
+ }
796
+ latestBatch(opts) {
797
+ return this._apiPromise(
798
+ () => this._http.request("GET", "/v1/audit/batches/latest", void 0, void 0, opts)
799
+ );
800
+ }
801
+ getBatch(batchNum, opts) {
802
+ return this._apiPromise(
803
+ () => this._http.request("GET", `/v1/audit/batches/${batchNum}`, void 0, void 0, opts)
804
+ );
805
+ }
806
+ getEvent(seq, opts) {
807
+ return this._apiPromise(
808
+ () => this._http.request("GET", `/v1/audit/events/${seq}`, void 0, void 0, opts)
809
+ );
810
+ }
811
+ getProof(seq, opts) {
812
+ return this._apiPromise(
813
+ () => this._http.request("GET", `/v1/audit/proof/${seq}`, void 0, void 0, opts)
814
+ );
815
+ }
816
+ getAnchor(batchNum, opts) {
817
+ return this._apiPromise(
818
+ () => this._http.request("GET", `/v1/audit/anchor/${batchNum}`, void 0, void 0, opts)
819
+ );
820
+ }
821
+ /**
822
+ * Verify a Merkle inclusion proof locally (client-side). Mirrors
823
+ * OpenZeppelin's sorted-pair sha256 algorithm — identical logic to the
824
+ * server-side batcher, so callers can independently confirm inclusion
825
+ * without trusting the API response.
826
+ */
827
+ static verifyProof(leaf, root, proof) {
828
+ const crypto = globalThis.crypto || require("crypto");
829
+ let hash = leaf;
830
+ for (const sibling of proof) {
831
+ const [a, b] = hash < sibling ? [hash, sibling] : [sibling, hash];
832
+ if (crypto.subtle && typeof crypto.subtle.digest === "function") {
833
+ throw new Error("Use verifyProofAsync() in browser/edge runtimes (WebCrypto is async)");
834
+ }
835
+ hash = crypto.createHash("sha256").update(a + b).digest("hex");
836
+ }
837
+ return hash === root;
838
+ }
839
+ /** Async variant using WebCrypto — works in browsers, Deno, Bun, edge runtimes. */
840
+ static async verifyProofAsync(leaf, root, proof) {
841
+ const enc = new TextEncoder();
842
+ async function sha(s) {
843
+ const buf = await globalThis.crypto.subtle.digest("SHA-256", enc.encode(s));
844
+ return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
845
+ }
846
+ let hash = leaf;
847
+ for (const sibling of proof) {
848
+ const [a, b] = hash < sibling ? [hash, sibling] : [sibling, hash];
849
+ hash = await sha(a + b);
850
+ }
851
+ return hash === root;
852
+ }
853
+ };
854
+
855
+ // src/resources/fees.ts
856
+ var FeesResource = class extends Resource {
857
+ estimate(params, opts) {
858
+ const query = {
859
+ size: String(params.size),
860
+ price: String(params.price)
861
+ };
862
+ if (params.marketId) query.market_id = params.marketId;
863
+ if (params.side) query.side = params.side;
864
+ if (params.action) query.action = params.action;
865
+ if (params.vipDiscount != null) query.vip_discount = String(params.vipDiscount);
866
+ if (params.sharpMultiplier != null) query.sharp_multiplier = String(params.sharpMultiplier);
867
+ if (params.isMintTaker) query.is_mint_taker = "1";
868
+ if (params.isAmmMaker) query.is_amm_maker = "1";
869
+ if (params.acquisitionBuilderId) query.acquisition_builder_id = params.acquisitionBuilderId;
870
+ if (params.executionBuilderId) query.execution_builder_id = params.executionBuilderId;
871
+ if (params.operatorId) query.operator_id = params.operatorId;
872
+ if (params.marketCreatorId) query.market_creator_id = params.marketCreatorId;
873
+ return this._apiPromise(
874
+ () => this._http.request("GET", "/v1/fees/estimate", query, void 0, opts)
875
+ );
876
+ }
877
+ };
878
+
787
879
  // src/resources/grants.ts
788
880
  var GrantsResource = class extends Resource {
789
881
  /** List every grant the authenticated user has, oldest last. */
@@ -973,6 +1065,59 @@ var OrdersResource = class extends Resource {
973
1065
  opts
974
1066
  );
975
1067
  }
1068
+ /**
1069
+ * Place multiple orders in a single request (up to 25 per batch).
1070
+ *
1071
+ * Each order is processed sequentially by the CLOB engine (single-writer per
1072
+ * market). Response contains a `results` array with one entry per input order
1073
+ * (indexed) plus a `summary` with counts + duration. One bad order does not
1074
+ * fail the whole batch — inspect `results[i].ok` per item.
1075
+ *
1076
+ * Batch cap is env-tunable server-side (BATCH_ORDERS_MAX, default 25). Exceeding
1077
+ * returns `413 BATCH_TOO_LARGE`.
1078
+ */
1079
+ placeBatch(orders, opts) {
1080
+ const wireOrders = orders.map((o) => {
1081
+ const body = {
1082
+ market_id: o.marketId,
1083
+ outcome_id: o.outcomeId,
1084
+ side: o.side,
1085
+ order_type: o.orderType,
1086
+ size: String(o.size)
1087
+ };
1088
+ if (o.price !== void 0) body.price = String(o.price);
1089
+ if (o.clientOrderId) body.client_order_id = o.clientOrderId;
1090
+ if (o.timeInForce) body.time_in_force = o.timeInForce;
1091
+ return body;
1092
+ });
1093
+ return this._apiPromise(
1094
+ () => this._http.request(
1095
+ "POST",
1096
+ "/v1/orders/batch",
1097
+ void 0,
1098
+ { orders: wireOrders },
1099
+ opts
1100
+ )
1101
+ );
1102
+ }
1103
+ /**
1104
+ * Cancel multiple orders in a single request (up to 50 per batch).
1105
+ *
1106
+ * Each cancel is processed sequentially by the CLOB engine. Response mirrors
1107
+ * `placeBatch` shape — inspect `results[i].ok` per item. Batch cap env-tunable
1108
+ * server-side (BATCH_CANCEL_MAX, default 50).
1109
+ */
1110
+ cancelBatch(orderIds, opts) {
1111
+ return this._apiPromise(
1112
+ () => this._http.request(
1113
+ "DELETE",
1114
+ "/v1/orders/batch",
1115
+ void 0,
1116
+ { orderIds },
1117
+ opts
1118
+ )
1119
+ );
1120
+ }
976
1121
  };
977
1122
 
978
1123
  // src/resources/sandbox.ts
@@ -1054,6 +1199,10 @@ var PaxClient = class {
1054
1199
  apply;
1055
1200
  // POST /v1/apply + GET /v1/apply/{code}
1056
1201
  grants;
1202
+ fees;
1203
+ // v2.1+: GET /v1/fees/estimate
1204
+ audit;
1205
+ // v2.2+: public Merkle chain verifier (no-auth)
1057
1206
  constructor(opts) {
1058
1207
  this._http = new HttpClient(opts);
1059
1208
  this.markets = new MarketsResource(this._http);
@@ -1065,6 +1214,8 @@ var PaxClient = class {
1065
1214
  this.sandboxKeys = new SandboxKeysResource(this._http);
1066
1215
  this.apply = new ApplyResource(this._http);
1067
1216
  this.grants = new GrantsResource(this._http);
1217
+ this.fees = new FeesResource(this._http);
1218
+ this.audit = new AuditResource(this._http);
1068
1219
  }
1069
1220
  get baseUrl() {
1070
1221
  return this._http.baseUrl;
@@ -1337,7 +1488,9 @@ var PaxWSClient = class {
1337
1488
  APIPromise,
1338
1489
  AccountResource,
1339
1490
  ApplyResource,
1491
+ AuditResource,
1340
1492
  CursorPage,
1493
+ FeesResource,
1341
1494
  GrantsResource,
1342
1495
  KeysResource,
1343
1496
  MarketsResource,