@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 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/restorer/impls/portfolio-v0-evaluator/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RestorerImpl, RestorationContext, RestorationOutput, ReadyStatus, EnableResult, IntentEnableMetadata } from '../../types.js';
|
|
2
|
+
export interface PredictionApyV0BaselineConfig {
|
|
3
|
+
rpcUrl?: string;
|
|
4
|
+
archiveRpcUrl?: string;
|
|
5
|
+
_testDeps?: {
|
|
6
|
+
twApyBpsOverWindow?: (args: {
|
|
7
|
+
windowEndTs: number;
|
|
8
|
+
twaWindowSeconds: number;
|
|
9
|
+
sampleCount: number;
|
|
10
|
+
pool: `0x${string}`;
|
|
11
|
+
reserve: `0x${string}`;
|
|
12
|
+
}) => Promise<{
|
|
13
|
+
twApyBps: number;
|
|
14
|
+
sampleCount: number;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class PredictionApyV0BaselineImpl implements RestorerImpl {
|
|
19
|
+
private readonly config;
|
|
20
|
+
readonly name = "prediction-apy-v0-baseline";
|
|
21
|
+
readonly version = "1.0.0";
|
|
22
|
+
constructor(config?: PredictionApyV0BaselineConfig);
|
|
23
|
+
supports(ctx: {
|
|
24
|
+
kind: string;
|
|
25
|
+
type?: 'restoration' | 'evaluation';
|
|
26
|
+
}): boolean;
|
|
27
|
+
isReady(): Promise<ReadyStatus>;
|
|
28
|
+
enableMetadata(): IntentEnableMetadata;
|
|
29
|
+
onEnable(_args: Record<string, string | undefined>): Promise<EnableResult>;
|
|
30
|
+
canAttempt(intent: import('../../../types/desired-state.js').DesiredState): Promise<{
|
|
31
|
+
ok: false;
|
|
32
|
+
reason: string;
|
|
33
|
+
} | {
|
|
34
|
+
ok: true;
|
|
35
|
+
reason?: undefined;
|
|
36
|
+
}>;
|
|
37
|
+
run(ctx: RestorationContext): Promise<RestorationOutput>;
|
|
38
|
+
}
|
|
39
|
+
export default PredictionApyV0BaselineImpl;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { createPublicClient, http } from 'viem';
|
|
4
|
+
import { base, baseSepolia, mainnet } from 'viem/chains';
|
|
5
|
+
import { PredictionApyV0IntentSchema } from '../../../types/prediction-apy.js';
|
|
6
|
+
import { twApyBpsOverWindow } from '../../../venues/aave-v3/client.js';
|
|
7
|
+
import { persistencePredict } from './strategy.js';
|
|
8
|
+
function chainForVenue(venue) {
|
|
9
|
+
if (venue === 'aave-v3-base-sepolia')
|
|
10
|
+
return { chain: baseSepolia, chainId: 84532 };
|
|
11
|
+
if (venue === 'aave-v3-mainnet')
|
|
12
|
+
return { chain: mainnet, chainId: 1 };
|
|
13
|
+
return { chain: base, chainId: 8453 };
|
|
14
|
+
}
|
|
15
|
+
export class PredictionApyV0BaselineImpl {
|
|
16
|
+
config;
|
|
17
|
+
name = 'prediction-apy-v0-baseline';
|
|
18
|
+
version = '1.0.0';
|
|
19
|
+
constructor(config = {}) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
supports(ctx) {
|
|
23
|
+
return ctx.kind === 'prediction.apy.v0' && ctx.type !== 'evaluation';
|
|
24
|
+
}
|
|
25
|
+
async isReady() {
|
|
26
|
+
return { ready: true };
|
|
27
|
+
}
|
|
28
|
+
enableMetadata() {
|
|
29
|
+
return {
|
|
30
|
+
description: 'prediction.apy.v0 — submit APY prediction in bps from Aave v3 reserve data.',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async onEnable(_args) {
|
|
34
|
+
return { status: 'ready' };
|
|
35
|
+
}
|
|
36
|
+
async canAttempt(intent) {
|
|
37
|
+
const parsed = PredictionApyV0IntentSchema.safeParse(intent);
|
|
38
|
+
if (!parsed.success)
|
|
39
|
+
return { ok: false, reason: `Invalid prediction.apy.v0 intent: ${parsed.error.message}` };
|
|
40
|
+
if (Date.now() > parsed.data.window.endTs)
|
|
41
|
+
return { ok: false, reason: 'window already closed' };
|
|
42
|
+
return { ok: true };
|
|
43
|
+
}
|
|
44
|
+
async run(ctx) {
|
|
45
|
+
const parsed = PredictionApyV0IntentSchema.parse(ctx.intent);
|
|
46
|
+
const { venue, pool, reserve } = parsed.spec.oracle;
|
|
47
|
+
const { chain, chainId } = chainForVenue(venue);
|
|
48
|
+
const rpcUrl = this.config.rpcUrl ?? this.config.archiveRpcUrl;
|
|
49
|
+
let twApyBps;
|
|
50
|
+
let sampleCount;
|
|
51
|
+
if (this.config._testDeps?.twApyBpsOverWindow) {
|
|
52
|
+
const result = await this.config._testDeps.twApyBpsOverWindow({
|
|
53
|
+
pool: pool,
|
|
54
|
+
reserve: reserve,
|
|
55
|
+
windowEndTs: parsed.spec.question.resolveTs,
|
|
56
|
+
twaWindowSeconds: parsed.spec.metric.twaWindowSeconds,
|
|
57
|
+
sampleCount: parsed.spec.metric.sampleCount,
|
|
58
|
+
});
|
|
59
|
+
twApyBps = result.twApyBps;
|
|
60
|
+
sampleCount = result.sampleCount;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const publicClient = createPublicClient({ chain, transport: http(rpcUrl) });
|
|
64
|
+
const actual = await publicClient.getChainId();
|
|
65
|
+
if (actual !== chainId) {
|
|
66
|
+
throw new Error(`oracle venue mismatch: ${venue} expects chain ${chainId}, got ${actual}`);
|
|
67
|
+
}
|
|
68
|
+
const result = await twApyBpsOverWindow({
|
|
69
|
+
publicClient,
|
|
70
|
+
pool: pool,
|
|
71
|
+
reserve: reserve,
|
|
72
|
+
windowEndTs: parsed.spec.question.resolveTs,
|
|
73
|
+
twaWindowSeconds: parsed.spec.metric.twaWindowSeconds,
|
|
74
|
+
sampleCount: parsed.spec.metric.sampleCount,
|
|
75
|
+
});
|
|
76
|
+
twApyBps = result.twApyBps;
|
|
77
|
+
sampleCount = result.sampleCount;
|
|
78
|
+
}
|
|
79
|
+
const prediction = persistencePredict(twApyBps);
|
|
80
|
+
const submittedAt = Date.now();
|
|
81
|
+
writeFileSync(join(ctx.workingDir, 'prediction-apy.json'), JSON.stringify({ ...prediction, submittedAt, twApyBps }, null, 2));
|
|
82
|
+
return {
|
|
83
|
+
venueRef: { name: 'aave-v3' },
|
|
84
|
+
gating: {
|
|
85
|
+
predictedBps: prediction.predictedBps,
|
|
86
|
+
submittedAt: String(submittedAt),
|
|
87
|
+
modelId: prediction.modelId,
|
|
88
|
+
},
|
|
89
|
+
informational: {
|
|
90
|
+
twApyBps,
|
|
91
|
+
sampleCount,
|
|
92
|
+
},
|
|
93
|
+
artifacts: [{ path: 'prediction-apy.json', role: 'prediction_submission' }],
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export default PredictionApyV0BaselineImpl;
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/restorer/impls/prediction-apy-v0-baseline/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,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C;gBAChC,OAAO,EAAE,UAAU,CAAC,OAAO;aAC5B;YACD,aAAa,EAAE;gBACb,QAAQ;gBACR,WAAW;aACZ;YACD,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC;SAC5E,CAAC;IACJ,CAAC;CACF;AAED,eAAe,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../../src/restorer/impls/prediction-apy-v0-baseline/strategy.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC1C,OAAO,EAAE,oBAAoB;KAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/restorer/impls/prediction-apy-v0-baseline/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function deriveGroundTruthBps(intent, twApyBps) {
|
|
2
|
+
if (intent.spec.metric.type !== 'supply-apy-twa-bps') {
|
|
3
|
+
throw new Error(`unsupported metric: ${intent.spec.metric.type}`);
|
|
4
|
+
}
|
|
5
|
+
return String(Math.round(twApyBps));
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=canonical-metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-metrics.js","sourceRoot":"","sources":["../../../../src/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,oBAAoB,CAAC,MAA6B,EAAE,QAAgB;IAClF,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RestorerImpl, RestorationContext, RestorationOutput } from '../../types.js';
|
|
2
|
+
import type { DesiredState } from '../../../types/desired-state.js';
|
|
3
|
+
export interface PredictionApyV0EvaluatorConfig {
|
|
4
|
+
evaluatorPk: `0x${string}`;
|
|
5
|
+
evaluatorSafeAddress: `0x${string}`;
|
|
6
|
+
rpcUrl?: string;
|
|
7
|
+
archiveRpcUrl?: string;
|
|
8
|
+
_testDeps?: {
|
|
9
|
+
twApyBpsOverWindow?: (args: {
|
|
10
|
+
windowEndTs: number;
|
|
11
|
+
twaWindowSeconds: number;
|
|
12
|
+
sampleCount: number;
|
|
13
|
+
pool: `0x${string}`;
|
|
14
|
+
reserve: `0x${string}`;
|
|
15
|
+
}) => Promise<{
|
|
16
|
+
twApyBps: number;
|
|
17
|
+
sampleCount: number;
|
|
18
|
+
}>;
|
|
19
|
+
expectedIntentCid?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare class PredictionApyV0Evaluator implements RestorerImpl {
|
|
23
|
+
private readonly config;
|
|
24
|
+
readonly name = "prediction-apy-v0-evaluator";
|
|
25
|
+
readonly version = "1.0.0";
|
|
26
|
+
constructor(config: PredictionApyV0EvaluatorConfig);
|
|
27
|
+
supports(ctx: {
|
|
28
|
+
kind: string;
|
|
29
|
+
type?: 'restoration' | 'evaluation';
|
|
30
|
+
}): boolean;
|
|
31
|
+
canAttempt(intent: DesiredState): Promise<{
|
|
32
|
+
ok: true;
|
|
33
|
+
} | {
|
|
34
|
+
ok: false;
|
|
35
|
+
reason: string;
|
|
36
|
+
}>;
|
|
37
|
+
run(ctx: RestorationContext): Promise<RestorationOutput>;
|
|
38
|
+
}
|
|
39
|
+
export default PredictionApyV0Evaluator;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { createPublicClient, http, keccak256, stringToHex } from 'viem';
|
|
4
|
+
import { base, baseSepolia, mainnet } from 'viem/chains';
|
|
5
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
6
|
+
import { PredictionApyV0IntentSchema, PredictionApySubmissionManifestSchema, } from '../../../types/prediction-apy.js';
|
|
7
|
+
import { twApyBpsOverWindow } from '../../../venues/aave-v3/client.js';
|
|
8
|
+
import { deriveGroundTruthBps } from './canonical-metrics.js';
|
|
9
|
+
import { computeScore } from './score.js';
|
|
10
|
+
function parseSubmissionManifest(manifestJson) {
|
|
11
|
+
const raw = JSON.parse(manifestJson);
|
|
12
|
+
const direct = PredictionApySubmissionManifestSchema.safeParse(raw);
|
|
13
|
+
if (direct.success)
|
|
14
|
+
return direct.data;
|
|
15
|
+
const normalized = {
|
|
16
|
+
schemaVersion: 'prediction.apy.v0.submission.v1',
|
|
17
|
+
generatedAt: raw['generatedAt'],
|
|
18
|
+
intent: raw['intent'],
|
|
19
|
+
restorer: raw['restorer'],
|
|
20
|
+
window: raw['window'],
|
|
21
|
+
prediction: {
|
|
22
|
+
predictedBps: String(raw['gating']?.['predictedBps'] ?? ''),
|
|
23
|
+
submittedAt: Number(raw['gating']?.['submittedAt'] ?? 0),
|
|
24
|
+
modelId: String(raw['gating']?.['modelId'] ?? ''),
|
|
25
|
+
},
|
|
26
|
+
signature: raw['signature'],
|
|
27
|
+
};
|
|
28
|
+
return PredictionApySubmissionManifestSchema.parse(normalized);
|
|
29
|
+
}
|
|
30
|
+
function chainForVenue(venue) {
|
|
31
|
+
if (venue === 'aave-v3-base-sepolia')
|
|
32
|
+
return { chain: baseSepolia, chainId: 84532 };
|
|
33
|
+
if (venue === 'aave-v3-mainnet')
|
|
34
|
+
return { chain: mainnet, chainId: 1 };
|
|
35
|
+
return { chain: base, chainId: 8453 };
|
|
36
|
+
}
|
|
37
|
+
export class PredictionApyV0Evaluator {
|
|
38
|
+
config;
|
|
39
|
+
name = 'prediction-apy-v0-evaluator';
|
|
40
|
+
version = '1.0.0';
|
|
41
|
+
constructor(config) {
|
|
42
|
+
this.config = config;
|
|
43
|
+
}
|
|
44
|
+
supports(ctx) {
|
|
45
|
+
return ctx.kind === 'prediction.apy.v0' && ctx.type === 'evaluation';
|
|
46
|
+
}
|
|
47
|
+
async canAttempt(intent) {
|
|
48
|
+
if (intent.spec?.kind !== 'prediction.apy.v0')
|
|
49
|
+
return { ok: false, reason: 'spec.kind is not prediction.apy.v0' };
|
|
50
|
+
if (intent.type !== 'evaluation')
|
|
51
|
+
return { ok: false, reason: 'type is not evaluation' };
|
|
52
|
+
if (typeof intent.context?.['restorationResult'] !== 'string') {
|
|
53
|
+
return { ok: false, reason: 'context.restorationResult required' };
|
|
54
|
+
}
|
|
55
|
+
return { ok: true };
|
|
56
|
+
}
|
|
57
|
+
async run(ctx) {
|
|
58
|
+
const intent = PredictionApyV0IntentSchema.parse(ctx.intent);
|
|
59
|
+
const submission = parseSubmissionManifest(ctx.intent.context['restorationResult']);
|
|
60
|
+
const checks = [];
|
|
61
|
+
const { venue, pool, reserve } = intent.spec.oracle;
|
|
62
|
+
const { chain, chainId } = chainForVenue(venue);
|
|
63
|
+
let twApyBps;
|
|
64
|
+
let sampleCount;
|
|
65
|
+
try {
|
|
66
|
+
if (this.config._testDeps?.twApyBpsOverWindow) {
|
|
67
|
+
const result = await this.config._testDeps.twApyBpsOverWindow({
|
|
68
|
+
pool: pool,
|
|
69
|
+
reserve: reserve,
|
|
70
|
+
windowEndTs: intent.spec.question.resolveTs,
|
|
71
|
+
twaWindowSeconds: intent.spec.metric.twaWindowSeconds,
|
|
72
|
+
sampleCount: intent.spec.metric.sampleCount,
|
|
73
|
+
});
|
|
74
|
+
twApyBps = result.twApyBps;
|
|
75
|
+
sampleCount = result.sampleCount;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const rpcUrl = this.config.archiveRpcUrl ?? this.config.rpcUrl;
|
|
79
|
+
const publicClient = createPublicClient({ chain, transport: http(rpcUrl) });
|
|
80
|
+
const actual = await publicClient.getChainId();
|
|
81
|
+
if (actual !== chainId) {
|
|
82
|
+
throw new Error(`oracle venue mismatch: ${venue} expects chain ${chainId}, got ${actual}`);
|
|
83
|
+
}
|
|
84
|
+
const result = await twApyBpsOverWindow({
|
|
85
|
+
publicClient,
|
|
86
|
+
pool: pool,
|
|
87
|
+
reserve: reserve,
|
|
88
|
+
windowEndTs: intent.spec.question.resolveTs,
|
|
89
|
+
twaWindowSeconds: intent.spec.metric.twaWindowSeconds,
|
|
90
|
+
sampleCount: intent.spec.metric.sampleCount,
|
|
91
|
+
});
|
|
92
|
+
twApyBps = result.twApyBps;
|
|
93
|
+
sampleCount = result.sampleCount;
|
|
94
|
+
}
|
|
95
|
+
checks.push({ name: 'availability.aave_readable', status: 'PASS' });
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
checks.push({ name: 'availability.aave_readable', status: 'FAIL', detail: String(error) });
|
|
99
|
+
twApyBps = 0;
|
|
100
|
+
sampleCount = 0;
|
|
101
|
+
}
|
|
102
|
+
if (submission.prediction.submittedAt >= intent.window.startTs &&
|
|
103
|
+
submission.prediction.submittedAt <= intent.window.endTs) {
|
|
104
|
+
checks.push({ name: 'eligibility.submission_within_window', status: 'PASS' });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
checks.push({ name: 'eligibility.submission_within_window', status: 'FAIL' });
|
|
108
|
+
}
|
|
109
|
+
if (submission.intent.cid === (this.config._testDeps?.expectedIntentCid ?? submission.intent.cid)) {
|
|
110
|
+
checks.push({ name: 'integrity.intent_ref', status: 'PASS' });
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
checks.push({ name: 'integrity.intent_ref', status: 'FAIL' });
|
|
114
|
+
}
|
|
115
|
+
if (intent.spec.metric.toleranceBps > 0) {
|
|
116
|
+
checks.push({ name: 'spec.tolerance_positive', status: 'PASS' });
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
checks.push({ name: 'spec.tolerance_positive', status: 'FAIL' });
|
|
120
|
+
}
|
|
121
|
+
const verdict = deriveVerdict(checks);
|
|
122
|
+
const groundTruthBps = deriveGroundTruthBps(intent, twApyBps);
|
|
123
|
+
const scored = computeScore(verdict, submission.prediction.predictedBps, groundTruthBps, intent.spec.metric.toleranceBps);
|
|
124
|
+
const evaluatorAccount = privateKeyToAccount(this.config.evaluatorPk);
|
|
125
|
+
const baseManifest = {
|
|
126
|
+
schemaVersion: 'prediction.apy.v0.verdict.v1',
|
|
127
|
+
generatedAt: Date.now(),
|
|
128
|
+
intent: submission.intent,
|
|
129
|
+
evaluator: { safeAddress: this.config.evaluatorSafeAddress, agentEoa: evaluatorAccount.address },
|
|
130
|
+
window: intent.window,
|
|
131
|
+
verdict,
|
|
132
|
+
score: scored.score,
|
|
133
|
+
scoreBasis: scored.scoreBasis,
|
|
134
|
+
scoreVersion: scored.scoreVersion,
|
|
135
|
+
oracleReading: {
|
|
136
|
+
pool: pool,
|
|
137
|
+
reserve: reserve,
|
|
138
|
+
sampleCount,
|
|
139
|
+
twaWindowSeconds: intent.spec.metric.twaWindowSeconds,
|
|
140
|
+
resolveTs: intent.spec.question.resolveTs,
|
|
141
|
+
},
|
|
142
|
+
claimed: {
|
|
143
|
+
predictedBps: submission.prediction.predictedBps,
|
|
144
|
+
submittedAt: submission.prediction.submittedAt,
|
|
145
|
+
modelId: submission.prediction.modelId,
|
|
146
|
+
submissionManifestCid: 'inline',
|
|
147
|
+
},
|
|
148
|
+
groundTruth: {
|
|
149
|
+
twApyBps: groundTruthBps,
|
|
150
|
+
errorBps: scored.errorBps,
|
|
151
|
+
},
|
|
152
|
+
checks,
|
|
153
|
+
};
|
|
154
|
+
const hash = keccak256(stringToHex(JSON.stringify(baseManifest)));
|
|
155
|
+
const sig = await evaluatorAccount.sign({ hash });
|
|
156
|
+
const verdictManifest = {
|
|
157
|
+
...baseManifest,
|
|
158
|
+
signature: { algo: 'secp256k1', signer: evaluatorAccount.address, hash, sig },
|
|
159
|
+
};
|
|
160
|
+
writeFileSync(join(ctx.workingDir, 'verdict.json'), JSON.stringify(verdictManifest, null, 2));
|
|
161
|
+
return {
|
|
162
|
+
venueRef: { name: 'aave-v3' },
|
|
163
|
+
gating: {
|
|
164
|
+
verdict,
|
|
165
|
+
score: scored.score,
|
|
166
|
+
groundTruthBps,
|
|
167
|
+
errorBps: scored.errorBps,
|
|
168
|
+
},
|
|
169
|
+
informational: {
|
|
170
|
+
predictedBps: submission.prediction.predictedBps,
|
|
171
|
+
},
|
|
172
|
+
artifacts: [{ path: 'verdict.json', role: 'evaluation_verdict' }],
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function deriveVerdict(checks) {
|
|
177
|
+
if (checks.some((c) => c.name.startsWith('availability.') && c.status !== 'PASS'))
|
|
178
|
+
return 'INDETERMINATE';
|
|
179
|
+
if (checks.some((c) => c.name.startsWith('eligibility.') && c.status === 'FAIL'))
|
|
180
|
+
return 'REJECTED';
|
|
181
|
+
if (checks.some((c) => (c.name.startsWith('integrity.') || c.name.startsWith('spec.')) && c.status === 'FAIL'))
|
|
182
|
+
return 'FAIL';
|
|
183
|
+
return 'PASS';
|
|
184
|
+
}
|
|
185
|
+
export default PredictionApyV0Evaluator;
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/restorer/impls/prediction-apy-v0-evaluator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAA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
|
1
|
+
import type { Verdict } from './types.js';
|
|
2
|
+
export declare const SCORE_BASIS: "absolute-error-linear.v1";
|
|
3
|
+
export declare const SCORE_VERSION: "1";
|
|
4
|
+
export declare function computeScore(verdict: Verdict, predictedBps: string, groundTruthBps: string, toleranceBps: number): {
|
|
5
|
+
score: string;
|
|
6
|
+
scoreBasis: typeof SCORE_BASIS;
|
|
7
|
+
scoreVersion: typeof SCORE_VERSION;
|
|
8
|
+
errorBps: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const SCORE_BASIS = 'absolute-error-linear.v1';
|
|
2
|
+
export const SCORE_VERSION = '1';
|
|
3
|
+
const SCALE = 1000000000000000000n;
|
|
4
|
+
export function computeScore(verdict, predictedBps, groundTruthBps, toleranceBps) {
|
|
5
|
+
const p = BigInt(predictedBps);
|
|
6
|
+
const g = BigInt(groundTruthBps);
|
|
7
|
+
const err = p > g ? p - g : g - p;
|
|
8
|
+
if (verdict !== 'PASS') {
|
|
9
|
+
return { score: '0', scoreBasis: SCORE_BASIS, scoreVersion: SCORE_VERSION, errorBps: err.toString() };
|
|
10
|
+
}
|
|
11
|
+
const tol = BigInt(toleranceBps);
|
|
12
|
+
if (tol <= 0n)
|
|
13
|
+
throw new Error('toleranceBps must be positive');
|
|
14
|
+
if (err >= tol) {
|
|
15
|
+
return { score: '0', scoreBasis: SCORE_BASIS, scoreVersion: SCORE_VERSION, errorBps: err.toString() };
|
|
16
|
+
}
|
|
17
|
+
const score = ((tol - err) * SCALE) / tol;
|
|
18
|
+
return { score: score.toString(), scoreBasis: SCORE_BASIS, scoreVersion: SCORE_VERSION, errorBps: err.toString() };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.js","sourceRoot":"","sources":["../../../../src/restorer/impls/prediction-apy-v0-evaluator/score.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,G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
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/restorer/impls/prediction-apy-v0-evaluator/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RestorerImpl, RestorationContext, RestorationOutput, ReadyStatus, EnableResult, IntentEnableMetadata } from '../../types.js';
|
|
2
|
+
import { type RoundReading } from '../../../venues/chainlink/client.js';
|
|
3
|
+
export interface PredictionV0BaselineConfig {
|
|
4
|
+
rpcUrl?: string;
|
|
5
|
+
_testDeps?: {
|
|
6
|
+
readChainlink?: (feed: `0x${string}`) => Promise<RoundReading>;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare class PredictionV0BaselineImpl implements RestorerImpl {
|
|
10
|
+
private readonly config;
|
|
11
|
+
readonly name = "prediction-v0-baseline";
|
|
12
|
+
readonly version = "1.0.0";
|
|
13
|
+
constructor(config?: PredictionV0BaselineConfig);
|
|
14
|
+
supports(ctx: {
|
|
15
|
+
kind: string;
|
|
16
|
+
type?: 'restoration' | 'evaluation';
|
|
17
|
+
}): boolean;
|
|
18
|
+
isReady(): Promise<ReadyStatus>;
|
|
19
|
+
enableMetadata(): IntentEnableMetadata;
|
|
20
|
+
onEnable(_args: Record<string, string | undefined>): Promise<EnableResult>;
|
|
21
|
+
canAttempt(intent: import('../../../types/desired-state.js').DesiredState): Promise<{
|
|
22
|
+
ok: true;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
reason: string;
|
|
26
|
+
}>;
|
|
27
|
+
run(ctx: RestorationContext): Promise<RestorationOutput>;
|
|
28
|
+
}
|
|
29
|
+
export default PredictionV0BaselineImpl;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* prediction-v0-baseline — reference RestorerImpl for prediction.v0.
|
|
3
|
+
*
|
|
4
|
+
* §5 of spec/2026-04-20-prediction-v0-pis-phase-1-design.md
|
|
5
|
+
*/
|
|
6
|
+
import { writeFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { createPublicClient, http } from 'viem';
|
|
9
|
+
import { baseSepolia, base } from 'viem/chains';
|
|
10
|
+
import { PredictionV0IntentSchema } from '../../../types/prediction.js';
|
|
11
|
+
import { readChainlinkLatest, scaleToDecimal, } from '../../../venues/chainlink/client.js';
|
|
12
|
+
import { spotCarryPredict } from './strategy.js';
|
|
13
|
+
export class PredictionV0BaselineImpl {
|
|
14
|
+
config;
|
|
15
|
+
name = 'prediction-v0-baseline';
|
|
16
|
+
version = '1.0.0';
|
|
17
|
+
constructor(config = {}) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
}
|
|
20
|
+
supports(ctx) {
|
|
21
|
+
return ctx.kind === 'prediction.v0' && ctx.type !== 'evaluation';
|
|
22
|
+
}
|
|
23
|
+
async isReady() {
|
|
24
|
+
// Zero external deps — prediction.v0 runs against on-chain oracles only.
|
|
25
|
+
return { ready: true };
|
|
26
|
+
}
|
|
27
|
+
enableMetadata() {
|
|
28
|
+
return {
|
|
29
|
+
description: 'prediction.v0 — submit probability predictions against on-chain price feeds. No external credentials required.',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async onEnable(_args) {
|
|
33
|
+
return { status: 'ready' };
|
|
34
|
+
}
|
|
35
|
+
async canAttempt(intent) {
|
|
36
|
+
const parsed = PredictionV0IntentSchema.safeParse(intent);
|
|
37
|
+
if (!parsed.success)
|
|
38
|
+
return { ok: false, reason: `Invalid prediction.v0 intent: ${parsed.error.message}` };
|
|
39
|
+
if (Date.now() > parsed.data.window.endTs) {
|
|
40
|
+
return { ok: false, reason: 'window already closed' };
|
|
41
|
+
}
|
|
42
|
+
return { ok: true };
|
|
43
|
+
}
|
|
44
|
+
async run(ctx) {
|
|
45
|
+
const { intent, workingDir, log } = ctx;
|
|
46
|
+
const parsed = PredictionV0IntentSchema.parse(intent);
|
|
47
|
+
const { feed, venue } = parsed.spec.oracle;
|
|
48
|
+
log({ level: 'info', msg: 'prediction-v0-baseline: starting', data: { feed, venue } });
|
|
49
|
+
// Read the feed (injection seam for tests)
|
|
50
|
+
const read = this.config._testDeps?.readChainlink;
|
|
51
|
+
let snapshot;
|
|
52
|
+
if (read) {
|
|
53
|
+
snapshot = await read(feed);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const expectedChainId = venue === 'chainlink-base' ? 8453 : 84532;
|
|
57
|
+
const chain = venue === 'chainlink-base' ? base : baseSepolia;
|
|
58
|
+
const pc = createPublicClient({ chain, transport: http(this.config.rpcUrl) });
|
|
59
|
+
const actualChainId = await pc.getChainId();
|
|
60
|
+
if (actualChainId !== expectedChainId) {
|
|
61
|
+
throw new Error(`oracle venue mismatch: spec says ${venue} (chainId ${expectedChainId}) but RPC chainId is ${actualChainId}`);
|
|
62
|
+
}
|
|
63
|
+
snapshot = await readChainlinkLatest(feed, pc);
|
|
64
|
+
}
|
|
65
|
+
const currentPrice = scaleToDecimal(snapshot.answer, snapshot.decimals);
|
|
66
|
+
const { probability, modelId } = spotCarryPredict(parsed, currentPrice);
|
|
67
|
+
const submittedAt = Date.now();
|
|
68
|
+
const prediction = { probability, submittedAt, modelId };
|
|
69
|
+
writeFileSync(join(workingDir, 'prediction.json'), JSON.stringify(prediction, null, 2));
|
|
70
|
+
log({ level: 'info', msg: 'prediction-v0-baseline: submitted', data: { currentPrice, probability, modelId } });
|
|
71
|
+
return {
|
|
72
|
+
venueRef: { name: 'chainlink' },
|
|
73
|
+
gating: {
|
|
74
|
+
probability,
|
|
75
|
+
submittedAt: String(submittedAt),
|
|
76
|
+
modelId,
|
|
77
|
+
},
|
|
78
|
+
informational: {
|
|
79
|
+
oracleSnapshot: {
|
|
80
|
+
feed,
|
|
81
|
+
roundId: String(snapshot.roundId),
|
|
82
|
+
answer: String(snapshot.answer),
|
|
83
|
+
updatedAt: snapshot.updatedAt,
|
|
84
|
+
},
|
|
85
|
+
currentPrice,
|
|
86
|
+
},
|
|
87
|
+
artifacts: [
|
|
88
|
+
{ path: 'prediction.json', role: 'prediction_submission' },
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export default PredictionV0BaselineImpl;
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/restorer/impls/prediction-v0-baseline/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAWhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,mBAAmB,EACnB,cAAc,GAEf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AASjD,MAAM,OAAO,wBAAwB;IAIN;IAHpB,IAAI,GAAG,wBAAwB,CAAC;IAChC,OAAO,GAAG,OAAO,CAAC;IAE3B,YAA6B,SAAqC,EAAE;QAAvC,WAAM,GAAN,MAAM,CAAiC;IAAG,CAAC;IAExE,QAAQ,CAAC,GAA0D;QACjE,OAAO,GAAG,CAAC,IAAI,KAAK,eAAe,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,OAAO;QACX,yEAAyE;QACzE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,cAAc;QACZ,OAAO;YACL,WAAW,EACT,gHAAgH;SACnH,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAyC;QACtD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;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AM,CAAC,WAAW,CAAC;gBAChC,OAAO;aACR;YACD,aAAa,EAAE;gBACb,cAAc,EAAE;oBACd,IAAI;oBACJ,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;oBACjC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;oBAC/B,SAAS,EAAE,QAAQ,CAAC,SAAS;iBAC9B;gBACD,YAAY;aACb;YACD,SAAS,EAAE;gBACT,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,uBAAuB,EAAE;aAC3D;SACF,CAAC;IACJ,CAAC;CACF;AAED,eAAe,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spot-carry baseline — "current state tends to persist."
|
|
3
|
+
*
|
|
4
|
+
* §5.3 of spec/2026-04-20-prediction-v0-pis-phase-1-design.md
|
|
5
|
+
*/
|
|
6
|
+
import type { PredictionV0Intent } from '../../../types/prediction.js';
|
|
7
|
+
import type { StrategyPrediction } from './types.js';
|
|
8
|
+
export declare function spotCarryPredict(intent: PredictionV0Intent, currentPrice: string): StrategyPrediction;
|