@perpbrain/sdk 0.0.0-stage → 0.1.2

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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -2
  3. package/dist/cjs/card.d.ts +2 -0
  4. package/dist/cjs/card.js +311 -0
  5. package/dist/cjs/cli.d.ts +3 -0
  6. package/dist/cjs/cli.js +33 -0
  7. package/dist/cjs/guarded.d.ts +12 -0
  8. package/dist/cjs/guarded.js +52 -0
  9. package/dist/cjs/guards.d.ts +154 -0
  10. package/dist/cjs/guards.js +855 -0
  11. package/dist/cjs/index.d.ts +16 -0
  12. package/dist/cjs/index.js +66 -0
  13. package/dist/cjs/package.json +1 -0
  14. package/dist/cjs/receipt.d.ts +45 -0
  15. package/dist/cjs/receipt.js +855 -0
  16. package/dist/cjs/study.d.ts +29 -0
  17. package/dist/cjs/study.js +259 -0
  18. package/dist/cjs/vendor/costs.d.ts +64 -0
  19. package/dist/cjs/vendor/costs.js +247 -0
  20. package/dist/cjs/vendor/execution.d.ts +44 -0
  21. package/dist/cjs/vendor/execution.js +132 -0
  22. package/dist/cjs/vendor/fees.d.ts +17 -0
  23. package/dist/cjs/vendor/fees.js +82 -0
  24. package/dist/cjs/vendor/funding_adapter.d.ts +11 -0
  25. package/dist/cjs/vendor/funding_adapter.js +33 -0
  26. package/dist/cjs/vendor/info.d.ts +24 -0
  27. package/dist/cjs/vendor/info.js +55 -0
  28. package/dist/cjs/vendor/queries.d.ts +69 -0
  29. package/dist/cjs/vendor/queries.js +210 -0
  30. package/dist/cjs/vendor/rateLimit.d.ts +14 -0
  31. package/dist/cjs/vendor/rateLimit.js +57 -0
  32. package/dist/cjs/vendor/simDefaults.d.ts +31 -0
  33. package/dist/cjs/vendor/simDefaults.js +49 -0
  34. package/dist/cjs/vendor/simulate.d.ts +130 -0
  35. package/dist/cjs/vendor/simulate.js +610 -0
  36. package/dist/esm/card.d.ts +2 -0
  37. package/dist/esm/card.js +308 -0
  38. package/dist/esm/cli.d.ts +3 -0
  39. package/dist/esm/cli.js +31 -0
  40. package/dist/esm/guarded.d.ts +12 -0
  41. package/dist/esm/guarded.js +49 -0
  42. package/dist/esm/guards.d.ts +154 -0
  43. package/dist/esm/guards.js +841 -0
  44. package/dist/esm/index.d.ts +16 -0
  45. package/dist/esm/index.js +20 -0
  46. package/dist/esm/receipt.d.ts +45 -0
  47. package/dist/esm/receipt.js +839 -0
  48. package/dist/esm/study.d.ts +29 -0
  49. package/dist/esm/study.js +249 -0
  50. package/dist/esm/vendor/costs.d.ts +64 -0
  51. package/dist/esm/vendor/costs.js +240 -0
  52. package/dist/esm/vendor/execution.d.ts +44 -0
  53. package/dist/esm/vendor/execution.js +122 -0
  54. package/dist/esm/vendor/fees.d.ts +17 -0
  55. package/dist/esm/vendor/fees.js +74 -0
  56. package/dist/esm/vendor/funding_adapter.d.ts +11 -0
  57. package/dist/esm/vendor/funding_adapter.js +30 -0
  58. package/dist/esm/vendor/info.d.ts +24 -0
  59. package/dist/esm/vendor/info.js +49 -0
  60. package/dist/esm/vendor/queries.d.ts +69 -0
  61. package/dist/esm/vendor/queries.js +196 -0
  62. package/dist/esm/vendor/rateLimit.d.ts +14 -0
  63. package/dist/esm/vendor/rateLimit.js +53 -0
  64. package/dist/esm/vendor/simDefaults.d.ts +31 -0
  65. package/dist/esm/vendor/simDefaults.js +44 -0
  66. package/dist/esm/vendor/simulate.d.ts +130 -0
  67. package/dist/esm/vendor/simulate.js +605 -0
  68. package/package.json +64 -4
@@ -0,0 +1,16 @@
1
+ /** Read-only and simulation-only SDK surface. */
2
+ export { CODES, HARD_MAX_DAILY_LOSS_PCT, HARD_MAX_OPEN_POSITIONS, HARD_MAX_ORDER_RATE, HARD_MAX_SLIPPAGE_BPS, PRESETS, STALE_BLOCK_MS, STALE_HALT_MS, GuardBlocked, GuardConfigError, GuardLoosenError, GuardSession, defaultGuards, defaultSnapshot, fromConfig, survivalReport, wireCode, } from "./guards.ts";
3
+ export type { GuardCode, GuardLimits, GuardOverrides, GuardResult, Guards, MarketSnapshot, PresetName, SimIntent, SurvivalDay, Violation, } from "./guards.ts";
4
+ export { guardedSimulate } from "./guarded.ts";
5
+ export type { GuardedSimulateResult } from "./guarded.ts";
6
+ export { renderReceiptCard } from "./card.ts";
7
+ export { RECEIPT_KIND, RECEIPT_STATEMENT, RECEIPT_VERSION, buildGuardedReceipt, buildReceiptDir, buildReceiptFiles, canonical, costBreakdownFromReceipt, exampleInputs, limitsPayload, sha256Json, simulateInputs, snapshotRows, verifyReceipt, verifyReceiptAt, writeReceiptDir, } from "./receipt.ts";
8
+ export type { BuiltReceipt } from "./receipt.ts";
9
+ export { executionCost } from "./vendor/costs.ts";
10
+ export type { CostBreakdown } from "./vendor/costs.ts";
11
+ export type { VerifyReport } from "./receipt.ts";
12
+ export { InfoClient } from "./vendor/info.ts";
13
+ export { fees, funding, markets, orderBook, positions } from "./vendor/queries.ts";
14
+ export { simulate } from "./vendor/simulate.ts";
15
+ export type { Bar, Book, Decision, Fill, FillGuard, GuardContext, SimulateResult, } from "./vendor/simulate.ts";
16
+ export declare const READ_AND_SIM_TOOLS: readonly ["markets", "order_book", "funding", "positions", "fees", "simulate", "get_limits", "trigger_kill_switch", "get_cost_breakdown"];
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /** Read-only and simulation-only SDK surface. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.READ_AND_SIM_TOOLS = exports.simulate = exports.positions = exports.orderBook = exports.markets = exports.funding = exports.fees = exports.InfoClient = exports.executionCost = exports.writeReceiptDir = exports.verifyReceiptAt = exports.verifyReceipt = exports.snapshotRows = exports.simulateInputs = exports.sha256Json = exports.limitsPayload = exports.exampleInputs = exports.costBreakdownFromReceipt = exports.canonical = exports.buildReceiptFiles = exports.buildReceiptDir = exports.buildGuardedReceipt = exports.RECEIPT_VERSION = exports.RECEIPT_STATEMENT = exports.RECEIPT_KIND = exports.renderReceiptCard = exports.guardedSimulate = exports.wireCode = exports.survivalReport = exports.fromConfig = exports.defaultSnapshot = exports.defaultGuards = exports.GuardSession = exports.GuardLoosenError = exports.GuardConfigError = exports.GuardBlocked = exports.STALE_HALT_MS = exports.STALE_BLOCK_MS = exports.PRESETS = exports.HARD_MAX_SLIPPAGE_BPS = exports.HARD_MAX_ORDER_RATE = exports.HARD_MAX_OPEN_POSITIONS = exports.HARD_MAX_DAILY_LOSS_PCT = exports.CODES = void 0;
5
+ var guards_ts_1 = require("./guards.js");
6
+ Object.defineProperty(exports, "CODES", { enumerable: true, get: function () { return guards_ts_1.CODES; } });
7
+ Object.defineProperty(exports, "HARD_MAX_DAILY_LOSS_PCT", { enumerable: true, get: function () { return guards_ts_1.HARD_MAX_DAILY_LOSS_PCT; } });
8
+ Object.defineProperty(exports, "HARD_MAX_OPEN_POSITIONS", { enumerable: true, get: function () { return guards_ts_1.HARD_MAX_OPEN_POSITIONS; } });
9
+ Object.defineProperty(exports, "HARD_MAX_ORDER_RATE", { enumerable: true, get: function () { return guards_ts_1.HARD_MAX_ORDER_RATE; } });
10
+ Object.defineProperty(exports, "HARD_MAX_SLIPPAGE_BPS", { enumerable: true, get: function () { return guards_ts_1.HARD_MAX_SLIPPAGE_BPS; } });
11
+ Object.defineProperty(exports, "PRESETS", { enumerable: true, get: function () { return guards_ts_1.PRESETS; } });
12
+ Object.defineProperty(exports, "STALE_BLOCK_MS", { enumerable: true, get: function () { return guards_ts_1.STALE_BLOCK_MS; } });
13
+ Object.defineProperty(exports, "STALE_HALT_MS", { enumerable: true, get: function () { return guards_ts_1.STALE_HALT_MS; } });
14
+ Object.defineProperty(exports, "GuardBlocked", { enumerable: true, get: function () { return guards_ts_1.GuardBlocked; } });
15
+ Object.defineProperty(exports, "GuardConfigError", { enumerable: true, get: function () { return guards_ts_1.GuardConfigError; } });
16
+ Object.defineProperty(exports, "GuardLoosenError", { enumerable: true, get: function () { return guards_ts_1.GuardLoosenError; } });
17
+ Object.defineProperty(exports, "GuardSession", { enumerable: true, get: function () { return guards_ts_1.GuardSession; } });
18
+ Object.defineProperty(exports, "defaultGuards", { enumerable: true, get: function () { return guards_ts_1.defaultGuards; } });
19
+ Object.defineProperty(exports, "defaultSnapshot", { enumerable: true, get: function () { return guards_ts_1.defaultSnapshot; } });
20
+ Object.defineProperty(exports, "fromConfig", { enumerable: true, get: function () { return guards_ts_1.fromConfig; } });
21
+ Object.defineProperty(exports, "survivalReport", { enumerable: true, get: function () { return guards_ts_1.survivalReport; } });
22
+ Object.defineProperty(exports, "wireCode", { enumerable: true, get: function () { return guards_ts_1.wireCode; } });
23
+ var guarded_ts_1 = require("./guarded.js");
24
+ Object.defineProperty(exports, "guardedSimulate", { enumerable: true, get: function () { return guarded_ts_1.guardedSimulate; } });
25
+ var card_ts_1 = require("./card.js");
26
+ Object.defineProperty(exports, "renderReceiptCard", { enumerable: true, get: function () { return card_ts_1.renderReceiptCard; } });
27
+ var receipt_ts_1 = require("./receipt.js");
28
+ Object.defineProperty(exports, "RECEIPT_KIND", { enumerable: true, get: function () { return receipt_ts_1.RECEIPT_KIND; } });
29
+ Object.defineProperty(exports, "RECEIPT_STATEMENT", { enumerable: true, get: function () { return receipt_ts_1.RECEIPT_STATEMENT; } });
30
+ Object.defineProperty(exports, "RECEIPT_VERSION", { enumerable: true, get: function () { return receipt_ts_1.RECEIPT_VERSION; } });
31
+ Object.defineProperty(exports, "buildGuardedReceipt", { enumerable: true, get: function () { return receipt_ts_1.buildGuardedReceipt; } });
32
+ Object.defineProperty(exports, "buildReceiptDir", { enumerable: true, get: function () { return receipt_ts_1.buildReceiptDir; } });
33
+ Object.defineProperty(exports, "buildReceiptFiles", { enumerable: true, get: function () { return receipt_ts_1.buildReceiptFiles; } });
34
+ Object.defineProperty(exports, "canonical", { enumerable: true, get: function () { return receipt_ts_1.canonical; } });
35
+ Object.defineProperty(exports, "costBreakdownFromReceipt", { enumerable: true, get: function () { return receipt_ts_1.costBreakdownFromReceipt; } });
36
+ Object.defineProperty(exports, "exampleInputs", { enumerable: true, get: function () { return receipt_ts_1.exampleInputs; } });
37
+ Object.defineProperty(exports, "limitsPayload", { enumerable: true, get: function () { return receipt_ts_1.limitsPayload; } });
38
+ Object.defineProperty(exports, "sha256Json", { enumerable: true, get: function () { return receipt_ts_1.sha256Json; } });
39
+ Object.defineProperty(exports, "simulateInputs", { enumerable: true, get: function () { return receipt_ts_1.simulateInputs; } });
40
+ Object.defineProperty(exports, "snapshotRows", { enumerable: true, get: function () { return receipt_ts_1.snapshotRows; } });
41
+ Object.defineProperty(exports, "verifyReceipt", { enumerable: true, get: function () { return receipt_ts_1.verifyReceipt; } });
42
+ Object.defineProperty(exports, "verifyReceiptAt", { enumerable: true, get: function () { return receipt_ts_1.verifyReceiptAt; } });
43
+ Object.defineProperty(exports, "writeReceiptDir", { enumerable: true, get: function () { return receipt_ts_1.writeReceiptDir; } });
44
+ var costs_ts_1 = require("./vendor/costs.js");
45
+ Object.defineProperty(exports, "executionCost", { enumerable: true, get: function () { return costs_ts_1.executionCost; } });
46
+ var info_ts_1 = require("./vendor/info.js");
47
+ Object.defineProperty(exports, "InfoClient", { enumerable: true, get: function () { return info_ts_1.InfoClient; } });
48
+ var queries_ts_1 = require("./vendor/queries.js");
49
+ Object.defineProperty(exports, "fees", { enumerable: true, get: function () { return queries_ts_1.fees; } });
50
+ Object.defineProperty(exports, "funding", { enumerable: true, get: function () { return queries_ts_1.funding; } });
51
+ Object.defineProperty(exports, "markets", { enumerable: true, get: function () { return queries_ts_1.markets; } });
52
+ Object.defineProperty(exports, "orderBook", { enumerable: true, get: function () { return queries_ts_1.orderBook; } });
53
+ Object.defineProperty(exports, "positions", { enumerable: true, get: function () { return queries_ts_1.positions; } });
54
+ var simulate_ts_1 = require("./vendor/simulate.js");
55
+ Object.defineProperty(exports, "simulate", { enumerable: true, get: function () { return simulate_ts_1.simulate; } });
56
+ exports.READ_AND_SIM_TOOLS = [
57
+ "markets",
58
+ "order_book",
59
+ "funding",
60
+ "positions",
61
+ "fees",
62
+ "simulate",
63
+ "get_limits",
64
+ "trigger_kill_switch",
65
+ "get_cost_breakdown",
66
+ ];
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,45 @@
1
+ /** Re-derive a simulation receipt. The check is verified and reproducible. */
2
+ import { GuardSession, type Guards, type MarketSnapshot } from "./guards.ts";
3
+ import { type GuardedSimulateResult } from "./guarded.ts";
4
+ import { type CostBreakdown } from "./vendor/costs.ts";
5
+ export declare const RECEIPT_STATEMENT = "verified and reproducible";
6
+ export declare const RECEIPT_KIND = "perpbrain.sim-receipt";
7
+ export declare const RECEIPT_VERSION = 5;
8
+ export interface VerifyReport {
9
+ status: "VERIFIED" | "MISMATCH";
10
+ mismatches: string[];
11
+ }
12
+ export declare function verifyReceipt(receipt: unknown, manifest: Uint8Array, inputs: Uint8Array): VerifyReport;
13
+ export declare function canonical(value: unknown): string;
14
+ export declare function sha256Json(value: unknown): string;
15
+ export declare function costBreakdownFromReceipt(receipt: unknown): CostBreakdown;
16
+ export interface BuiltReceipt {
17
+ receipt: Record<string, unknown>;
18
+ manifest: Record<string, unknown>;
19
+ receiptBytes: Uint8Array;
20
+ manifestBytes: Uint8Array;
21
+ inputsBytes: Uint8Array;
22
+ }
23
+ export declare function exampleInputs(): Record<string, unknown>;
24
+ export declare function limitsPayload(limits: Guards): Record<string, unknown>;
25
+ export declare function snapshotRows(snapshot: MarketSnapshot): Record<string, unknown>[];
26
+ export declare function simulateInputs(inputs: Record<string, unknown>): Record<string, unknown>;
27
+ export declare function buildReceiptFiles(inputs: Record<string, unknown>, result: Record<string, unknown>, limits: Record<string, unknown>, marketSnapshot: Record<string, unknown>[]): BuiltReceipt;
28
+ export declare function writeReceiptDir(directory: string, built: BuiltReceipt): string;
29
+ export declare function buildReceiptDir(directory: string, inputs?: Record<string, unknown>, limits?: Guards | null, snapshot?: MarketSnapshot | null): string;
30
+ /**
31
+ * Write a verifiable receipt from a successful `guardedSimulate` result.
32
+ *
33
+ * Verification reruns the unguarded simulator on the raw inputs, so the
34
+ * hashed result is `simulateInputs`, not the guarded result object. Guard
35
+ * metadata attached to that object (`guardPreset`, `limits`, `limitsHash`,
36
+ * `effectiveLimitsPerCoin`, `loosened`, `marketSnapshotId`, `guardViolations`)
37
+ * must not be hashed. The market snapshot defaults to `defaultSnapshot`; an
38
+ * empty snapshot list would refuse coins as `coin_not_allowed`.
39
+ *
40
+ * Receipt inputs use snake_case (`bar_index`, `time_ms`), even though the
41
+ * TypeScript `Decision` / `Bar` types are camelCase.
42
+ */
43
+ export declare function buildGuardedReceipt(directory: string, inputs: Record<string, unknown>, result: GuardedSimulateResult | Record<string, unknown>, session: GuardSession, snapshot?: MarketSnapshot | null): string;
44
+ /** Read a receipt.json file, or a directory that contains one, and check it. */
45
+ export declare function verifyReceiptAt(path: string): VerifyReport;