@jinn-network/client 0.1.1 → 0.1.2-canary.d6e72dfd
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 +14 -0
- package/CONTRIBUTING.md +123 -0
- package/README.md +210 -37
- package/deployments/deployment-claim-registry-baseSepolia.json +13 -0
- package/deployments/deployment-jinn-testnet-faucet-baseSepolia-fast.json +15 -0
- package/dist/adapters/claim-registry/abi.d.ts +127 -0
- package/dist/adapters/claim-registry/abi.js +93 -0
- package/dist/adapters/claim-registry/abi.js.map +1 -0
- package/dist/adapters/claim-registry/client.d.ts +89 -0
- package/dist/adapters/claim-registry/client.js +205 -0
- package/dist/adapters/claim-registry/client.js.map +1 -0
- package/dist/adapters/mech/adapter.d.ts +1 -0
- package/dist/adapters/mech/adapter.js +75 -41
- package/dist/adapters/mech/adapter.js.map +1 -1
- package/dist/adapters/mech/contracts.d.ts +2 -0
- package/dist/adapters/mech/contracts.js +57 -7
- package/dist/adapters/mech/contracts.js.map +1 -1
- package/dist/adapters/mech/ipfs.d.ts +8 -0
- package/dist/adapters/mech/ipfs.js +12 -0
- package/dist/adapters/mech/ipfs.js.map +1 -1
- package/dist/adapters/mech/types.d.ts +20 -46
- package/dist/adapters/mech/types.js +16 -35
- package/dist/adapters/mech/types.js.map +1 -1
- package/dist/api/gather-status.d.ts +1 -0
- package/dist/api/gather-status.js +33 -1
- package/dist/api/gather-status.js.map +1 -1
- package/dist/api/portfolio-v0-build.d.ts +81 -0
- package/dist/api/portfolio-v0-build.js +141 -0
- package/dist/api/portfolio-v0-build.js.map +1 -0
- package/dist/api/portfolio-v0-doctor.d.ts +37 -0
- package/dist/api/portfolio-v0-doctor.js +123 -0
- package/dist/api/portfolio-v0-doctor.js.map +1 -0
- package/dist/api/rewards-build.js +1 -1
- package/dist/api/rewards-build.js.map +1 -1
- package/dist/api/status-build.d.ts +7 -0
- package/dist/api/status-build.js +1 -0
- package/dist/api/status-build.js.map +1 -1
- package/dist/bin/jinn-mcp.d.ts +0 -12
- package/dist/bin/jinn-mcp.js +5 -14
- package/dist/bin/jinn-mcp.js.map +1 -1
- package/dist/build-meta.json +1 -1
- package/dist/cli/commands/auth.js +115 -25
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/commands/bootstrap.js +1 -0
- package/dist/cli/commands/bootstrap.js.map +1 -1
- package/dist/cli/commands/doctor.js +130 -14
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/fleet-scale.js +1 -0
- package/dist/cli/commands/fleet-scale.js.map +1 -1
- package/dist/cli/commands/fund-requirements.js +2 -0
- package/dist/cli/commands/fund-requirements.js.map +1 -1
- package/dist/cli/commands/intents.d.ts +17 -0
- package/dist/cli/commands/intents.js +489 -0
- package/dist/cli/commands/intents.js.map +1 -0
- package/dist/cli/commands/keys-backup.js +13 -11
- package/dist/cli/commands/keys-backup.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts +3 -0
- package/dist/cli/commands/mcp.js +19 -0
- package/dist/cli/commands/mcp.js.map +1 -0
- package/dist/cli/commands/plugin-install.js +8 -4
- package/dist/cli/commands/plugin-install.js.map +1 -1
- package/dist/cli/commands/quickstart.js +60 -4
- package/dist/cli/commands/quickstart.js.map +1 -1
- package/dist/cli/commands/rewards.js +27 -1
- package/dist/cli/commands/rewards.js.map +1 -1
- package/dist/cli/commands/submit-intent.js +108 -5
- package/dist/cli/commands/submit-intent.js.map +1 -1
- package/dist/cli/commands/version.js +1 -0
- package/dist/cli/commands/version.js.map +1 -1
- package/dist/cli/deployment-digest.js +5 -0
- package/dist/cli/deployment-digest.js.map +1 -1
- package/dist/cli/execution-context.js +1 -0
- package/dist/cli/execution-context.js.map +1 -1
- package/dist/cli/index.js +4 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/intent-registry-access.d.ts +64 -0
- package/dist/cli/intent-registry-access.js +187 -0
- package/dist/cli/intent-registry-access.js.map +1 -0
- package/dist/cli/introspection-context.js +1 -0
- package/dist/cli/introspection-context.js.map +1 -1
- package/dist/cli/password.d.ts +21 -9
- package/dist/cli/password.js +45 -24
- package/dist/cli/password.js.map +1 -1
- package/dist/config.d.ts +110 -8
- package/dist/config.js +41 -12
- package/dist/config.js.map +1 -1
- package/dist/daemon/creator.d.ts +7 -1
- package/dist/daemon/creator.js +38 -3
- package/dist/daemon/creator.js.map +1 -1
- package/dist/daemon/daemon.d.ts +43 -0
- package/dist/daemon/daemon.js +87 -2
- package/dist/daemon/daemon.js.map +1 -1
- package/dist/earning/bootstrap.d.ts +2 -1
- package/dist/earning/bootstrap.js +72 -4
- package/dist/earning/bootstrap.js.map +1 -1
- package/dist/earning/contracts.d.ts +10 -0
- package/dist/earning/contracts.js +24 -0
- package/dist/earning/contracts.js.map +1 -1
- package/dist/earning/jinn-rewards.d.ts +9 -0
- package/dist/earning/jinn-rewards.js +7 -0
- package/dist/earning/jinn-rewards.js.map +1 -1
- package/dist/intents/prediction-apy-v0-auto.d.ts +11 -0
- package/dist/intents/prediction-apy-v0-auto.js +46 -0
- package/dist/intents/prediction-apy-v0-auto.js.map +1 -0
- package/dist/intents/prediction-apy-v0-template.d.ts +8 -0
- package/dist/intents/prediction-apy-v0-template.js +22 -0
- package/dist/intents/prediction-apy-v0-template.js.map +1 -0
- package/dist/intents/prediction-v0-auto.d.ts +53 -0
- package/dist/intents/prediction-v0-auto.js +84 -0
- package/dist/intents/prediction-v0-auto.js.map +1 -0
- package/dist/intents/prediction-v0-template.d.ts +65 -0
- package/dist/intents/prediction-v0-template.js +125 -0
- package/dist/intents/prediction-v0-template.js.map +1 -0
- package/dist/main.js +149 -1
- package/dist/main.js.map +1 -1
- package/dist/mcp/operator-server.d.ts +1 -1
- package/dist/mcp/operator-server.js +1 -1
- package/dist/preflight/claude-auth.d.ts +12 -1
- package/dist/preflight/claude-auth.js +21 -3
- package/dist/preflight/claude-auth.js.map +1 -1
- package/dist/restorer/engine/canonical-json.d.ts +18 -0
- package/dist/restorer/engine/canonical-json.js +59 -0
- package/dist/restorer/engine/canonical-json.js.map +1 -0
- package/dist/restorer/engine/claim.d.ts +69 -0
- package/dist/restorer/engine/claim.js +104 -0
- package/dist/restorer/engine/claim.js.map +1 -0
- package/dist/restorer/engine/delivery.d.ts +52 -0
- package/dist/restorer/engine/delivery.js +63 -0
- package/dist/restorer/engine/delivery.js.map +1 -0
- package/dist/restorer/engine/engine.d.ts +203 -0
- package/dist/restorer/engine/engine.js +753 -0
- package/dist/restorer/engine/engine.js.map +1 -0
- package/dist/restorer/engine/manifest-assembly.d.ts +67 -0
- package/dist/restorer/engine/manifest-assembly.js +79 -0
- package/dist/restorer/engine/manifest-assembly.js.map +1 -0
- package/dist/restorer/engine/packaging.d.ts +87 -0
- package/dist/restorer/engine/packaging.js +350 -0
- package/dist/restorer/engine/packaging.js.map +1 -0
- package/dist/restorer/engine/persistence.d.ts +170 -0
- package/dist/restorer/engine/persistence.js +381 -0
- package/dist/restorer/engine/persistence.js.map +1 -0
- package/dist/restorer/engine/recovery.d.ts +22 -0
- package/dist/restorer/engine/recovery.js +24 -0
- package/dist/restorer/engine/recovery.js.map +1 -0
- package/dist/restorer/engine/registry.d.ts +62 -0
- package/dist/restorer/engine/registry.js +73 -0
- package/dist/restorer/engine/registry.js.map +1 -0
- package/dist/restorer/engine/signing.d.ts +30 -0
- package/dist/restorer/engine/signing.js +39 -0
- package/dist/restorer/engine/signing.js.map +1 -0
- package/dist/restorer/engine/state.d.ts +42 -0
- package/dist/restorer/engine/state.js +87 -0
- package/dist/restorer/engine/state.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.d.ts +64 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.js +96 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/index.d.ts +101 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/index.js +710 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/index.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.d.ts +137 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.js +865 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.d.ts +74 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.js +74 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.d.ts +97 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.js +226 -0
- package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-prediction/index.d.ts +43 -0
- package/dist/restorer/impls/claude-mcp-prediction/index.js +230 -0
- package/dist/restorer/impls/claude-mcp-prediction/index.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.d.ts +38 -0
- package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.js +135 -0
- package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-prediction/prompt.d.ts +8 -0
- package/dist/restorer/impls/claude-mcp-prediction/prompt.js +54 -0
- package/dist/restorer/impls/claude-mcp-prediction/prompt.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.d.ts +36 -0
- package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.js +137 -0
- package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.js.map +1 -0
- package/dist/restorer/impls/claude-mcp-prediction/types.d.ts +82 -0
- package/dist/restorer/impls/claude-mcp-prediction/types.js +6 -0
- package/dist/restorer/impls/claude-mcp-prediction/types.js.map +1 -0
- package/dist/restorer/impls/legacy-claude/index.d.ts +45 -0
- package/dist/restorer/impls/legacy-claude/index.js +71 -0
- package/dist/restorer/impls/legacy-claude/index.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.d.ts +68 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.js +117 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.d.ts +49 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.js +91 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.d.ts +78 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.js +274 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.d.ts +23 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.js +49 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.d.ts +25 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.js +44 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.d.ts +17 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.js +43 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/index.d.ts +43 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/index.js +431 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/index.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/score.d.ts +21 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/score.js +32 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/score.js.map +1 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/types.d.ts +32 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/types.js +8 -0
- package/dist/restorer/impls/portfolio-v0-evaluator/types.js.map +1 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/index.d.ts +39 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/index.js +98 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/index.js.map +1 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.d.ts +2 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.js +7 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.js.map +1 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/types.d.ts +4 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/types.js +2 -0
- package/dist/restorer/impls/prediction-apy-v0-baseline/types.js.map +1 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.d.ts +2 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.js +7 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.js.map +1 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/index.d.ts +39 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/index.js +186 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/index.js.map +1 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/score.d.ts +9 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/score.js +20 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/score.js.map +1 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/types.d.ts +7 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/types.js +2 -0
- package/dist/restorer/impls/prediction-apy-v0-evaluator/types.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-baseline/index.d.ts +29 -0
- package/dist/restorer/impls/prediction-v0-baseline/index.js +94 -0
- package/dist/restorer/impls/prediction-v0-baseline/index.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-baseline/strategy.d.ts +8 -0
- package/dist/restorer/impls/prediction-v0-baseline/strategy.js +41 -0
- package/dist/restorer/impls/prediction-v0-baseline/strategy.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-baseline/types.d.ts +7 -0
- package/dist/restorer/impls/prediction-v0-baseline/types.js +2 -0
- package/dist/restorer/impls/prediction-v0-baseline/types.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.d.ts +20 -0
- package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.js +66 -0
- package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.d.ts +9 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.js +23 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.d.ts +3 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.js +13 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.d.ts +7 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.js +93 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.d.ts +5 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.js +20 -0
- package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-evaluator/index.d.ts +33 -0
- package/dist/restorer/impls/prediction-v0-evaluator/index.js +208 -0
- package/dist/restorer/impls/prediction-v0-evaluator/index.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-evaluator/score.d.ts +8 -0
- package/dist/restorer/impls/prediction-v0-evaluator/score.js +15 -0
- package/dist/restorer/impls/prediction-v0-evaluator/score.js.map +1 -0
- package/dist/restorer/impls/prediction-v0-evaluator/types.d.ts +7 -0
- package/dist/restorer/impls/prediction-v0-evaluator/types.js +2 -0
- package/dist/restorer/impls/prediction-v0-evaluator/types.js.map +1 -0
- package/dist/restorer/types.d.ts +177 -0
- package/dist/restorer/types.js +7 -0
- package/dist/restorer/types.js.map +1 -0
- package/dist/store/store.d.ts +3 -1
- package/dist/store/store.js +3 -0
- package/dist/store/store.js.map +1 -1
- package/dist/types/desired-state.d.ts +53 -0
- package/dist/types/desired-state.js +20 -0
- package/dist/types/desired-state.js.map +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.js +4 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/portfolio.d.ts +1000 -0
- package/dist/types/portfolio.js +168 -0
- package/dist/types/portfolio.js.map +1 -0
- package/dist/types/prediction-apy.d.ts +919 -0
- package/dist/types/prediction-apy.js +121 -0
- package/dist/types/prediction-apy.js.map +1 -0
- package/dist/types/prediction.d.ts +925 -0
- package/dist/types/prediction.js +140 -0
- package/dist/types/prediction.js.map +1 -0
- package/dist/venues/aave-v3/addresses.d.ts +6 -0
- package/dist/venues/aave-v3/addresses.js +19 -0
- package/dist/venues/aave-v3/addresses.js.map +1 -0
- package/dist/venues/aave-v3/client.d.ts +81 -0
- package/dist/venues/aave-v3/client.js +97 -0
- package/dist/venues/aave-v3/client.js.map +1 -0
- package/dist/venues/chainlink/client.d.ts +99 -0
- package/dist/venues/chainlink/client.js +130 -0
- package/dist/venues/chainlink/client.js.map +1 -0
- package/dist/venues/chainlink/feeds.d.ts +8 -0
- package/dist/venues/chainlink/feeds.js +9 -0
- package/dist/venues/chainlink/feeds.js.map +1 -0
- package/dist/venues/hyperliquid/account-value.d.ts +30 -0
- package/dist/venues/hyperliquid/account-value.js +30 -0
- package/dist/venues/hyperliquid/account-value.js.map +1 -0
- package/dist/venues/hyperliquid/client.d.ts +63 -0
- package/dist/venues/hyperliquid/client.js +135 -0
- package/dist/venues/hyperliquid/client.js.map +1 -0
- package/dist/venues/hyperliquid/grid.d.ts +36 -0
- package/dist/venues/hyperliquid/grid.js +61 -0
- package/dist/venues/hyperliquid/grid.js.map +1 -0
- package/dist/venues/hyperliquid/types.d.ts +81 -0
- package/dist/venues/hyperliquid/types.js +8 -0
- package/dist/venues/hyperliquid/types.js.map +1 -0
- package/dist/withdraw/run-withdraw-plan.js +2 -0
- package/dist/withdraw/run-withdraw-plan.js.map +1 -1
- package/docker-compose.yml +44 -0
- package/package.json +12 -1
- package/skills/jinn-operator/SKILL.md +85 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session orchestrator for claude-mcp-prediction.
|
|
3
|
+
*
|
|
4
|
+
* Single-session (no cadence loop, no market-move triggers). Spawns Claude
|
|
5
|
+
* once with the prediction MCP + prompt, polls a shared "submitted" flag to
|
|
6
|
+
* detect `submit_prediction` tool call, and terminates after a short grace
|
|
7
|
+
* period so Claude's tool response reaches it.
|
|
8
|
+
*
|
|
9
|
+
* Slimmed-down version of:
|
|
10
|
+
* client/src/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.ts:97-209
|
|
11
|
+
*/
|
|
12
|
+
import { appendFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
const DEFAULT_SESSION_MAX_MS = 180_000;
|
|
16
|
+
const DEFAULT_POLL_INTERVAL_MS = 500;
|
|
17
|
+
const DEFAULT_SUBMISSION_GRACE_MS = 2_000;
|
|
18
|
+
export async function spawnSession(sessionId, prompt, deps) {
|
|
19
|
+
const sessionMaxMs = deps.sessionMaxMs ?? DEFAULT_SESSION_MAX_MS;
|
|
20
|
+
const pollIntervalMs = deps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
21
|
+
const submissionGraceMs = deps.submissionGraceMs ?? DEFAULT_SUBMISSION_GRACE_MS;
|
|
22
|
+
const sessionDir = join(deps.workingDir, 'sessions', sessionId);
|
|
23
|
+
mkdirSync(sessionDir, { recursive: true });
|
|
24
|
+
const transcriptPath = join(sessionDir, 'transcript.txt');
|
|
25
|
+
const startedAt = Date.now();
|
|
26
|
+
writeFileSync(transcriptPath, `=== Session ${sessionId} started at ${new Date(startedAt).toISOString()} ===\n\n`);
|
|
27
|
+
const args = [
|
|
28
|
+
'-p', prompt,
|
|
29
|
+
'--mcp-config', deps.mcpConfigPath,
|
|
30
|
+
'--strict-mcp-config',
|
|
31
|
+
'--allowedTools', 'mcp__jinn-prediction__*',
|
|
32
|
+
];
|
|
33
|
+
if (deps.claudeModel)
|
|
34
|
+
args.push('--model', deps.claudeModel);
|
|
35
|
+
// Minimal env allowlist — same set as the HL orchestrator.
|
|
36
|
+
const agentEnv = {};
|
|
37
|
+
for (const key of [
|
|
38
|
+
'PATH', 'HOME', 'USER', 'SHELL', 'LANG', 'TERM', 'TMPDIR',
|
|
39
|
+
'XDG_CONFIG_HOME', 'XDG_DATA_HOME', 'XDG_CACHE_HOME',
|
|
40
|
+
'NODE_PATH', 'NODE_OPTIONS', 'NPM_CONFIG_PREFIX',
|
|
41
|
+
// Anthropic auth — required for Claude Code to reach the model.
|
|
42
|
+
'CLAUDE_CODE_OAUTH_TOKEN', 'ANTHROPIC_API_KEY',
|
|
43
|
+
]) {
|
|
44
|
+
if (process.env[key])
|
|
45
|
+
agentEnv[key] = process.env[key];
|
|
46
|
+
}
|
|
47
|
+
deps.log({ level: 'info', msg: `prediction-session: spawning ${sessionId}`, data: { claudePath: deps.claudePath } });
|
|
48
|
+
const spawnFn = deps._spawnFn ?? spawn;
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
const child = spawnFn(deps.claudePath, args, {
|
|
51
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
52
|
+
env: agentEnv,
|
|
53
|
+
});
|
|
54
|
+
let stdout = '';
|
|
55
|
+
let aborted = false;
|
|
56
|
+
let terminatedEarly = false;
|
|
57
|
+
child.stdout?.on('data', (d) => {
|
|
58
|
+
const chunk = d.toString();
|
|
59
|
+
stdout += chunk;
|
|
60
|
+
appendFileSync(transcriptPath, chunk);
|
|
61
|
+
});
|
|
62
|
+
child.stderr?.on('data', (d) => {
|
|
63
|
+
appendFileSync(transcriptPath, `[stderr] ${d.toString()}`);
|
|
64
|
+
});
|
|
65
|
+
const sessionTimeout = setTimeout(() => {
|
|
66
|
+
if (!child.killed) {
|
|
67
|
+
deps.log({ level: 'warn', msg: `prediction-session: ${sessionId} reached sessionMaxMs; killing`, data: { sessionMaxMs } });
|
|
68
|
+
child.kill('SIGTERM');
|
|
69
|
+
}
|
|
70
|
+
}, sessionMaxMs);
|
|
71
|
+
// Poll for submit_prediction: once the flag flips, give Claude a short grace
|
|
72
|
+
// window to receive the tool response + close the connection, then SIGTERM.
|
|
73
|
+
let graceTimer = null;
|
|
74
|
+
const pollTimer = setInterval(() => {
|
|
75
|
+
if (graceTimer || child.killed)
|
|
76
|
+
return;
|
|
77
|
+
if (deps.isSubmitted()) {
|
|
78
|
+
deps.log({ level: 'info', msg: `prediction-session: ${sessionId} submit_prediction invoked; scheduling graceful termination` });
|
|
79
|
+
terminatedEarly = true;
|
|
80
|
+
graceTimer = setTimeout(() => {
|
|
81
|
+
if (!child.killed)
|
|
82
|
+
child.kill('SIGTERM');
|
|
83
|
+
}, submissionGraceMs);
|
|
84
|
+
}
|
|
85
|
+
}, pollIntervalMs);
|
|
86
|
+
const onAbort = () => {
|
|
87
|
+
if (aborted)
|
|
88
|
+
return;
|
|
89
|
+
aborted = true;
|
|
90
|
+
deps.log({ level: 'info', msg: `prediction-session: ${sessionId} window abort; killing` });
|
|
91
|
+
child.kill('SIGTERM');
|
|
92
|
+
};
|
|
93
|
+
deps.abort.addEventListener('abort', onAbort);
|
|
94
|
+
const cleanup = () => {
|
|
95
|
+
clearTimeout(sessionTimeout);
|
|
96
|
+
if (graceTimer)
|
|
97
|
+
clearTimeout(graceTimer);
|
|
98
|
+
clearInterval(pollTimer);
|
|
99
|
+
deps.abort.removeEventListener('abort', onAbort);
|
|
100
|
+
};
|
|
101
|
+
child.on('exit', (code, signal) => {
|
|
102
|
+
cleanup();
|
|
103
|
+
const endedAt = Date.now();
|
|
104
|
+
appendFileSync(transcriptPath, `\n\n=== Session ended at ${new Date(endedAt).toISOString()} (code=${code} signal=${signal} submitted=${deps.isSubmitted()} terminatedEarly=${terminatedEarly} aborted=${aborted}) ===\n`);
|
|
105
|
+
deps.log({
|
|
106
|
+
level: 'info',
|
|
107
|
+
msg: `prediction-session: ${sessionId} exited`,
|
|
108
|
+
data: { code, signal, durationMs: endedAt - startedAt, submitted: deps.isSubmitted(), aborted },
|
|
109
|
+
});
|
|
110
|
+
resolve({
|
|
111
|
+
sessionId,
|
|
112
|
+
startedAt,
|
|
113
|
+
endedAt,
|
|
114
|
+
transcriptPath,
|
|
115
|
+
submitted: deps.isSubmitted(),
|
|
116
|
+
stdout,
|
|
117
|
+
aborted: aborted || deps.abort.aborted,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
child.on('error', (err) => {
|
|
121
|
+
cleanup();
|
|
122
|
+
const endedAt = Date.now();
|
|
123
|
+
appendFileSync(transcriptPath, `\n\n=== Session spawn error: ${err.message} ===\n`);
|
|
124
|
+
deps.log({ level: 'error', msg: `prediction-session: ${sessionId} spawn error`, data: { err: err.message } });
|
|
125
|
+
resolve({
|
|
126
|
+
sessionId,
|
|
127
|
+
startedAt,
|
|
128
|
+
endedAt,
|
|
129
|
+
transcriptPath,
|
|
130
|
+
submitted: deps.isSubmitted(),
|
|
131
|
+
stdout,
|
|
132
|
+
aborted: deps.abort.aborted,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=session-orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-orchestrator.js","sourceRoot":"","sources":["../../../../src/restorer/impls/claude-mcp-prediction/session-orchestrator.ts"],"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C7B,MAAM;gBACN,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO;aACvC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACxB,OAAO,EAAE,CAAC;YACV,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3B,cAAc,CAAC,cAAc,EAAE,gCAAgC,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC;YACpF,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,uBAAuB,SAAS,cAAc,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC9G,OAAO,CAAC;gBACN,SAAS;gBACT,SAAS;gBACT,OAAO;gBACP,cAAc;gBACd,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE;gBAC7B,MAAM;gBACN,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;aAC5B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for claude-mcp-prediction — a RestorerImpl that spawns Claude with
|
|
3
|
+
* two MCP tools to decide a prediction.v0 probability.
|
|
4
|
+
*/
|
|
5
|
+
import type { PublicClient } from 'viem';
|
|
6
|
+
export interface McpToolContent {
|
|
7
|
+
type: 'text';
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
export interface McpToolResult {
|
|
11
|
+
content: McpToolContent[];
|
|
12
|
+
}
|
|
13
|
+
/** Discriminated union for the tool registry. Kept open to add future tools. */
|
|
14
|
+
export interface PredictionToolDefinition {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
/** Zod object schema — registered as the MCP input-schema shape. */
|
|
18
|
+
schema: import('zod').ZodObject<import('zod').ZodRawShape>;
|
|
19
|
+
handler: (args: unknown) => Promise<McpToolResult>;
|
|
20
|
+
}
|
|
21
|
+
export interface SubmissionState {
|
|
22
|
+
probability: string | null;
|
|
23
|
+
rationale: string | null;
|
|
24
|
+
submittedAt: number | null;
|
|
25
|
+
}
|
|
26
|
+
export interface PredictionToolDeps {
|
|
27
|
+
/** Chainlink AggregatorV3 proxy address the intent is anchored to. */
|
|
28
|
+
feed: `0x${string}`;
|
|
29
|
+
/** Human-readable feed description, echoed in tool responses. */
|
|
30
|
+
feedDescription: string;
|
|
31
|
+
/** Venue label — used to sanity-check in the tool response. */
|
|
32
|
+
venue: 'chainlink-base' | 'chainlink-base-sepolia';
|
|
33
|
+
/** viem public client for reading the feed. */
|
|
34
|
+
publicClient: PublicClient;
|
|
35
|
+
/**
|
|
36
|
+
* Called when Claude invokes `submit_prediction`. The impl mutates its own
|
|
37
|
+
* SubmissionState via this callback and signals the orchestrator to terminate.
|
|
38
|
+
*/
|
|
39
|
+
onSubmit: (submission: {
|
|
40
|
+
probability: string;
|
|
41
|
+
rationale: string;
|
|
42
|
+
}) => void;
|
|
43
|
+
}
|
|
44
|
+
export interface ClaudeMcpPredictionConfig {
|
|
45
|
+
rpcUrl?: string;
|
|
46
|
+
claudeModel?: string;
|
|
47
|
+
claudePath?: string;
|
|
48
|
+
/** Max wall time for the Claude session (ms). Default 3 min. */
|
|
49
|
+
sessionMaxMs?: number;
|
|
50
|
+
/** Injected deps for test mode — bypasses the real Claude spawn. */
|
|
51
|
+
_testDeps?: TestDeps;
|
|
52
|
+
}
|
|
53
|
+
export interface TestDeps {
|
|
54
|
+
/**
|
|
55
|
+
* Replacement for the real session spawn. Given the MCP config path + prompt,
|
|
56
|
+
* must eventually call the `onSubmit` callback registered on the tools
|
|
57
|
+
* (via in-process MCP, or by writing to the submission state directly).
|
|
58
|
+
*
|
|
59
|
+
* Minimum-viable mock: immediately invoke the submit callback passed in ctx,
|
|
60
|
+
* then return a stub SessionResult.
|
|
61
|
+
*/
|
|
62
|
+
runSession?: (args: {
|
|
63
|
+
sessionId: string;
|
|
64
|
+
prompt: string;
|
|
65
|
+
mcpConfigPath: string;
|
|
66
|
+
workingDir: string;
|
|
67
|
+
implStateDir: string;
|
|
68
|
+
timeoutMs: number;
|
|
69
|
+
signalSubmit: (probability: string, rationale: string) => void;
|
|
70
|
+
}) => Promise<SessionResult>;
|
|
71
|
+
}
|
|
72
|
+
export interface SessionResult {
|
|
73
|
+
sessionId: string;
|
|
74
|
+
startedAt: number;
|
|
75
|
+
endedAt: number;
|
|
76
|
+
transcriptPath: string;
|
|
77
|
+
/** True iff `submit_prediction` was called before timeout/abort. */
|
|
78
|
+
submitted: boolean;
|
|
79
|
+
/** Accumulated stdout for post-mortem. */
|
|
80
|
+
stdout: string;
|
|
81
|
+
aborted: boolean;
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/restorer/impls/claude-mcp-prediction/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* legacy-claude — RestorerImpl fallback for spec=undefined (health-check) intents.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the existing ClaudeRunner so that intents with no spec.kind continue to
|
|
5
|
+
* work via the RestorationEngine. Registered as the default fallback in the impl
|
|
6
|
+
* registry (supports spec.kind === '').
|
|
7
|
+
*
|
|
8
|
+
* The engine calls findFor({ kind: '' }) for legacy intents because
|
|
9
|
+
* PersistedIntent.specKind is null → coerced to '' in runImpl().
|
|
10
|
+
*/
|
|
11
|
+
import { type Runner } from '../../../runner/runner.js';
|
|
12
|
+
import type { RestorerImpl, RestorationContext, RestorationOutput, ReadyStatus, EnableResult, IntentEnableMetadata } from '../../types.js';
|
|
13
|
+
export interface LegacyClaudeConfig {
|
|
14
|
+
runner: Runner;
|
|
15
|
+
/** Passed to RunnerContext. Defaults to /tmp */
|
|
16
|
+
workingDirectory?: string;
|
|
17
|
+
/** Timeout in ms passed to runner. Defaults to 300000 */
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
/** Passed to runner for artifact storage */
|
|
20
|
+
storePath?: string;
|
|
21
|
+
/** Daemon API URL for MCP server */
|
|
22
|
+
daemonApiUrl?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class LegacyClaudeImpl implements RestorerImpl {
|
|
25
|
+
private readonly config;
|
|
26
|
+
readonly name = "legacy-claude";
|
|
27
|
+
readonly version = "1.0.0";
|
|
28
|
+
constructor(config: LegacyClaudeConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Supports the empty-string kind produced by the engine for intents with no spec.
|
|
31
|
+
* Also supports explicitly undefined-kind intents routed by registry default config.
|
|
32
|
+
*/
|
|
33
|
+
supports(ctx: {
|
|
34
|
+
kind: string;
|
|
35
|
+
type?: 'restoration' | 'evaluation';
|
|
36
|
+
}): boolean;
|
|
37
|
+
canAttempt(): Promise<{
|
|
38
|
+
ok: true;
|
|
39
|
+
}>;
|
|
40
|
+
isReady(): Promise<ReadyStatus>;
|
|
41
|
+
enableMetadata(): IntentEnableMetadata;
|
|
42
|
+
onEnable(_args: Record<string, string | undefined>): Promise<EnableResult>;
|
|
43
|
+
run(ctx: RestorationContext): Promise<RestorationOutput>;
|
|
44
|
+
}
|
|
45
|
+
export default LegacyClaudeImpl;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* legacy-claude — RestorerImpl fallback for spec=undefined (health-check) intents.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the existing ClaudeRunner so that intents with no spec.kind continue to
|
|
5
|
+
* work via the RestorationEngine. Registered as the default fallback in the impl
|
|
6
|
+
* registry (supports spec.kind === '').
|
|
7
|
+
*
|
|
8
|
+
* The engine calls findFor({ kind: '' }) for legacy intents because
|
|
9
|
+
* PersistedIntent.specKind is null → coerced to '' in runImpl().
|
|
10
|
+
*/
|
|
11
|
+
// ── Impl ──────────────────────────────────────────────────────────────────────
|
|
12
|
+
export class LegacyClaudeImpl {
|
|
13
|
+
config;
|
|
14
|
+
name = 'legacy-claude';
|
|
15
|
+
version = '1.0.0';
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Supports the empty-string kind produced by the engine for intents with no spec.
|
|
21
|
+
* Also supports explicitly undefined-kind intents routed by registry default config.
|
|
22
|
+
*/
|
|
23
|
+
supports(ctx) {
|
|
24
|
+
// legacy-claude handles restoration-type health-check intents with no spec.kind.
|
|
25
|
+
// It never runs as an evaluator.
|
|
26
|
+
if (ctx.type === 'evaluation')
|
|
27
|
+
return false;
|
|
28
|
+
return ctx.kind === '' || ctx.kind === 'legacy';
|
|
29
|
+
}
|
|
30
|
+
async canAttempt() {
|
|
31
|
+
return { ok: true };
|
|
32
|
+
}
|
|
33
|
+
async isReady() {
|
|
34
|
+
return { ready: true };
|
|
35
|
+
}
|
|
36
|
+
enableMetadata() {
|
|
37
|
+
return {
|
|
38
|
+
description: 'legacy-claude — handles health-check intents (no spec.kind). Always enabled.',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async onEnable(_args) {
|
|
42
|
+
return { status: 'ready' };
|
|
43
|
+
}
|
|
44
|
+
async run(ctx) {
|
|
45
|
+
const { intent, workingDir, log } = ctx;
|
|
46
|
+
log({ level: 'info', msg: 'legacy-claude: starting', data: { requestId: intent.id } });
|
|
47
|
+
const runnerCtx = {
|
|
48
|
+
requestId: intent.id,
|
|
49
|
+
workingDirectory: workingDir ?? this.config.workingDirectory ?? '/tmp',
|
|
50
|
+
timeoutMs: this.config.timeoutMs ?? 300_000,
|
|
51
|
+
storePath: this.config.storePath,
|
|
52
|
+
daemonApiUrl: this.config.daemonApiUrl,
|
|
53
|
+
};
|
|
54
|
+
const result = await this.config.runner.run(intent, runnerCtx);
|
|
55
|
+
log({ level: 'info', msg: 'legacy-claude: runner completed', data: { hasData: !!result.data } });
|
|
56
|
+
const output = {
|
|
57
|
+
venueRef: { name: 'legacy' },
|
|
58
|
+
gating: {
|
|
59
|
+
result: result.data,
|
|
60
|
+
},
|
|
61
|
+
informational: {
|
|
62
|
+
runnerResult: result.data,
|
|
63
|
+
artifactCount: result.artifacts?.length ?? 0,
|
|
64
|
+
},
|
|
65
|
+
artifacts: [],
|
|
66
|
+
};
|
|
67
|
+
return output;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export default LegacyClaudeImpl;
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/restorer/impls/legacy-claude/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0BH,iFAAiF;AAEjF,MAAM,OAAO,gBAAgB;IAIE;IAHpB,IAAI,GAAG,eAAe,CAAC;IACvB,OAAO,GAAG,OAAO,CAAC;IAE3B,YAA6B,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;IAAG,CAAC;IAE3D;;;OAGG;IACH,QAAQ,CAAC,GAA0D;QACjE,iFAAiF;QACjF,iCAAiC;QACjC,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY;YAAE,OAAO,KAAK,CAAC;QAC5C,OAAO,GAAG,CAAC,IAAI,KAAK,EAAE,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,cAAc;QACZ,OAAO;YACL,WAAW,EACT,8EAA8E;SACjF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAyC;QACtD,OAAO,EAAE,MAAM,EAAE,OAAO,EAA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 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical metric computation for portfolio.v0 — §7.6.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth shared by both the restorer and evaluator.
|
|
5
|
+
* Pure functions; no I/O.
|
|
6
|
+
*/
|
|
7
|
+
import type { HlFill } from '../../../venues/hyperliquid/types.js';
|
|
8
|
+
/** A single point on the equity curve: [timestamp_ms, accountValue_as_number]. */
|
|
9
|
+
export interface EquityPoint {
|
|
10
|
+
ts: number;
|
|
11
|
+
value: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build an equity curve from the pre/post snapshot values and fills.
|
|
15
|
+
*
|
|
16
|
+
* Per §7.6: the curve is sampled at:
|
|
17
|
+
* - preSnapshot.capturedAt (value = preSnapshot accountValue)
|
|
18
|
+
* - every fill.time (value = inline equity; see note below)
|
|
19
|
+
* - postSnapshot.capturedAt (value = postSnapshot accountValue)
|
|
20
|
+
*
|
|
21
|
+
* Note: HL does not return per-fill equity. The evaluator uses the
|
|
22
|
+
* pre/post accountValues and the fill timestamps as curve shape anchors.
|
|
23
|
+
* For drawdown calculation purposes the curve is:
|
|
24
|
+
* pre-equity → (fills sorted by time but using pre/post values interpolated
|
|
25
|
+
* between them) → post-equity.
|
|
26
|
+
*
|
|
27
|
+
* Actually §7.6 says "sampled at preSnapshot.capturedAt + every fill.time +
|
|
28
|
+
* postSnapshot.capturedAt". Since HL only provides point-in-time equity at
|
|
29
|
+
* pre/post (not at each fill), the canonical approach is to use linear
|
|
30
|
+
* interpolation between the pre and post equity values at each fill timestamp.
|
|
31
|
+
* This matches what the restorer can compute and is deterministic.
|
|
32
|
+
*/
|
|
33
|
+
export declare function equityCurve(preTs: number, preValue: number, postTs: number, postValue: number, fillTimes: number[]): EquityPoint[];
|
|
34
|
+
/**
|
|
35
|
+
* Compute max drawdown percentage over an equity curve.
|
|
36
|
+
*
|
|
37
|
+
* Per §7.6:
|
|
38
|
+
* Drawdown at P = 100 * (peak_so_far - equity_P) / peak_so_far
|
|
39
|
+
* maxDrawdownPct = max over all P
|
|
40
|
+
*
|
|
41
|
+
* Returns 0 if the curve has fewer than 2 points or no drawdown.
|
|
42
|
+
*/
|
|
43
|
+
export declare function maxDrawdownPct(curve: EquityPoint[]): number;
|
|
44
|
+
/**
|
|
45
|
+
* Compute equity return percentage.
|
|
46
|
+
*
|
|
47
|
+
* Per §7.6: 100 * (postValue - preValue) / preValue
|
|
48
|
+
*
|
|
49
|
+
* Returns 0 if preValue is 0.
|
|
50
|
+
*/
|
|
51
|
+
export declare function equityReturnPct(preValue: number, postValue: number): number;
|
|
52
|
+
/**
|
|
53
|
+
* Count fills where closedPnl is non-zero.
|
|
54
|
+
*
|
|
55
|
+
* Per §7.6: count of fills where closedPnl != 0
|
|
56
|
+
*
|
|
57
|
+
* Parses as float to handle "0", "0.0", "0.00", "-0.0", "+0.0" etc.
|
|
58
|
+
* NaN (non-numeric input) and empty string are treated as not-closed (excluded).
|
|
59
|
+
*/
|
|
60
|
+
export declare function closedTradesCount(fills: HlFill[]): number;
|
|
61
|
+
/**
|
|
62
|
+
* Compute traded notional multiple.
|
|
63
|
+
*
|
|
64
|
+
* Per §7.6: sum_i(|sz_i * px_i|) / preValue
|
|
65
|
+
*
|
|
66
|
+
* Returns 0 if preValue is 0.
|
|
67
|
+
*/
|
|
68
|
+
export declare function tradedNotionalMultiple(fills: HlFill[], preValue: number): number;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical metric computation for portfolio.v0 — §7.6.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth shared by both the restorer and evaluator.
|
|
5
|
+
* Pure functions; no I/O.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Build an equity curve from the pre/post snapshot values and fills.
|
|
9
|
+
*
|
|
10
|
+
* Per §7.6: the curve is sampled at:
|
|
11
|
+
* - preSnapshot.capturedAt (value = preSnapshot accountValue)
|
|
12
|
+
* - every fill.time (value = inline equity; see note below)
|
|
13
|
+
* - postSnapshot.capturedAt (value = postSnapshot accountValue)
|
|
14
|
+
*
|
|
15
|
+
* Note: HL does not return per-fill equity. The evaluator uses the
|
|
16
|
+
* pre/post accountValues and the fill timestamps as curve shape anchors.
|
|
17
|
+
* For drawdown calculation purposes the curve is:
|
|
18
|
+
* pre-equity → (fills sorted by time but using pre/post values interpolated
|
|
19
|
+
* between them) → post-equity.
|
|
20
|
+
*
|
|
21
|
+
* Actually §7.6 says "sampled at preSnapshot.capturedAt + every fill.time +
|
|
22
|
+
* postSnapshot.capturedAt". Since HL only provides point-in-time equity at
|
|
23
|
+
* pre/post (not at each fill), the canonical approach is to use linear
|
|
24
|
+
* interpolation between the pre and post equity values at each fill timestamp.
|
|
25
|
+
* This matches what the restorer can compute and is deterministic.
|
|
26
|
+
*/
|
|
27
|
+
export function equityCurve(preTs, preValue, postTs, postValue, fillTimes) {
|
|
28
|
+
const points = [];
|
|
29
|
+
// Pre snapshot
|
|
30
|
+
points.push({ ts: preTs, value: preValue });
|
|
31
|
+
// Fill time points — linear interpolation between pre and post
|
|
32
|
+
const duration = postTs - preTs;
|
|
33
|
+
const sorted = [...fillTimes].sort((a, b) => a - b);
|
|
34
|
+
for (const ts of sorted) {
|
|
35
|
+
const clampedTs = Math.max(preTs, Math.min(postTs, ts));
|
|
36
|
+
const frac = duration > 0 ? (clampedTs - preTs) / duration : 0;
|
|
37
|
+
const value = preValue + frac * (postValue - preValue);
|
|
38
|
+
points.push({ ts: clampedTs, value });
|
|
39
|
+
}
|
|
40
|
+
// Post snapshot
|
|
41
|
+
points.push({ ts: postTs, value: postValue });
|
|
42
|
+
return points;
|
|
43
|
+
}
|
|
44
|
+
// ── maxDrawdownPct ────────────────────────────────────────────────────────────
|
|
45
|
+
/**
|
|
46
|
+
* Compute max drawdown percentage over an equity curve.
|
|
47
|
+
*
|
|
48
|
+
* Per §7.6:
|
|
49
|
+
* Drawdown at P = 100 * (peak_so_far - equity_P) / peak_so_far
|
|
50
|
+
* maxDrawdownPct = max over all P
|
|
51
|
+
*
|
|
52
|
+
* Returns 0 if the curve has fewer than 2 points or no drawdown.
|
|
53
|
+
*/
|
|
54
|
+
export function maxDrawdownPct(curve) {
|
|
55
|
+
if (curve.length < 2)
|
|
56
|
+
return 0;
|
|
57
|
+
let peakSoFar = curve[0].value;
|
|
58
|
+
let maxDd = 0;
|
|
59
|
+
for (const point of curve) {
|
|
60
|
+
if (point.value > peakSoFar) {
|
|
61
|
+
peakSoFar = point.value;
|
|
62
|
+
}
|
|
63
|
+
if (peakSoFar > 0) {
|
|
64
|
+
const dd = (100 * (peakSoFar - point.value)) / peakSoFar;
|
|
65
|
+
if (dd > maxDd)
|
|
66
|
+
maxDd = dd;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return maxDd;
|
|
70
|
+
}
|
|
71
|
+
// ── equityReturnPct ───────────────────────────────────────────────────────────
|
|
72
|
+
/**
|
|
73
|
+
* Compute equity return percentage.
|
|
74
|
+
*
|
|
75
|
+
* Per §7.6: 100 * (postValue - preValue) / preValue
|
|
76
|
+
*
|
|
77
|
+
* Returns 0 if preValue is 0.
|
|
78
|
+
*/
|
|
79
|
+
export function equityReturnPct(preValue, postValue) {
|
|
80
|
+
if (preValue === 0)
|
|
81
|
+
return 0;
|
|
82
|
+
return (100 * (postValue - preValue)) / preValue;
|
|
83
|
+
}
|
|
84
|
+
// ── closedTradesCount ─────────────────────────────────────────────────────────
|
|
85
|
+
/**
|
|
86
|
+
* Count fills where closedPnl is non-zero.
|
|
87
|
+
*
|
|
88
|
+
* Per §7.6: count of fills where closedPnl != 0
|
|
89
|
+
*
|
|
90
|
+
* Parses as float to handle "0", "0.0", "0.00", "-0.0", "+0.0" etc.
|
|
91
|
+
* NaN (non-numeric input) and empty string are treated as not-closed (excluded).
|
|
92
|
+
*/
|
|
93
|
+
export function closedTradesCount(fills) {
|
|
94
|
+
return fills.filter((f) => {
|
|
95
|
+
const v = parseFloat(f.closedPnl);
|
|
96
|
+
return !isNaN(v) && v !== 0;
|
|
97
|
+
}).length;
|
|
98
|
+
}
|
|
99
|
+
// ── tradedNotionalMultiple ────────────────────────────────────────────────────
|
|
100
|
+
/**
|
|
101
|
+
* Compute traded notional multiple.
|
|
102
|
+
*
|
|
103
|
+
* Per §7.6: sum_i(|sz_i * px_i|) / preValue
|
|
104
|
+
*
|
|
105
|
+
* Returns 0 if preValue is 0.
|
|
106
|
+
*/
|
|
107
|
+
export function tradedNotionalMultiple(fills, preValue) {
|
|
108
|
+
if (preValue === 0)
|
|
109
|
+
return 0;
|
|
110
|
+
const total = fills.reduce((acc, f) => {
|
|
111
|
+
const sz = parseFloat(f.sz);
|
|
112
|
+
const px = parseFloat(f.px);
|
|
113
|
+
return acc + Math.abs(sz * px);
|
|
114
|
+
}, 0);
|
|
115
|
+
return total / preValue;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=canonical-metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-metrics.js","sourceRoot":"","sources":["../../../../src/restorer/impls/portfolio-v0-evaluator/canonical-metrics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,WAAW,CACzB,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,SAAiB,EACjB,SAAmB;IAEnB,MAAM,MAAM,GAAkB,EAAE,CAAC;IAEjC,eAAe;IACf,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE5C,+DAA+D;IAC/D,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;IAChC,MAAM,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,KAAK,MAAM,EAAE,IAAI,MA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ability.hyperliquid_reachable
|
|
5
|
+
* availability.hl_pre_snapshot_rederivable
|
|
6
|
+
* availability.hl_fills_rederivable
|
|
7
|
+
*
|
|
8
|
+
* FAIL in any of these → verdict INDETERMINATE per §7.3.
|
|
9
|
+
*/
|
|
10
|
+
import type { HlGridPoint } from '../../../../venues/hyperliquid/types.js';
|
|
11
|
+
import type { Check } from '../types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Wraps a HL API call that should succeed if HL is reachable.
|
|
14
|
+
*
|
|
15
|
+
* Returns PASS if the call completes without throwing, FAIL otherwise.
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkHlReachable(reachable: boolean, errorMsg?: string): Check;
|
|
18
|
+
/**
|
|
19
|
+
* Check whether the pre-snapshot equity can be rederived from the portfolio
|
|
20
|
+
* grid. A bracket must exist around preTs.
|
|
21
|
+
*
|
|
22
|
+
* Returns PASS if a bracket is found, FAIL if the grid has no bracket.
|
|
23
|
+
*/
|
|
24
|
+
export declare function checkPreSnapshotRederivable(grid: HlGridPoint[], preTs: number): Check;
|
|
25
|
+
/**
|
|
26
|
+
* Check whether fills could be fetched without clamping.
|
|
27
|
+
*
|
|
28
|
+
* If startTimeClamped is true, HL silently moved the retention horizon and
|
|
29
|
+
* fills are incomplete — FAIL.
|
|
30
|
+
*/
|
|
31
|
+
export declare function checkFillsRederivable(startTimeClamped: boolean): Check;
|
|
32
|
+
/**
|
|
33
|
+
* Check whether the post-snapshot is rederivable (no funding accrual issue).
|
|
34
|
+
*
|
|
35
|
+
* Per §7.5: if postSnapshot.capturedAt > endTs + 60s, emit SKIP and
|
|
36
|
+
* downstream consistency checks should be skipped → INDETERMINATE.
|
|
37
|
+
*
|
|
38
|
+
* This check is named availability.hl_post_snapshot_rederivable and uses
|
|
39
|
+
* SKIP status to propagate INDETERMINATE via the derivation rule (SKIP ≠ FAIL
|
|
40
|
+
* for availability — a FAIL would cause INDETERMINATE, but SKIP means we
|
|
41
|
+
* surface it separately).
|
|
42
|
+
*
|
|
43
|
+
* However, per §7.3 the derivation rule is:
|
|
44
|
+
* if any "availability.*" FAIL → INDETERMINATE
|
|
45
|
+
*
|
|
46
|
+
* A SKIP doesn't trigger INDETERMINATE via the rule, so the eval impl must
|
|
47
|
+
* handle this edge case explicitly by checking for SKIP in downstream checks.
|
|
48
|
+
*/
|
|
49
|
+
export declare function checkPostSnapshotFundingAccrual(postCapturedAt: number, endTs: number): Check;
|