@jinn-network/client 0.1.3-canary.2d6b2676 → 0.1.3-canary.8e61ba74
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/dist/adapters/adapter.d.ts +15 -4
- package/dist/adapters/local/adapter.d.ts +9 -8
- package/dist/adapters/local/adapter.js +47 -74
- package/dist/adapters/local/adapter.js.map +1 -1
- package/dist/adapters/mech/adapter.d.ts +29 -13
- package/dist/adapters/mech/adapter.js +316 -311
- package/dist/adapters/mech/adapter.js.map +1 -1
- package/dist/adapters/mech/contracts.d.ts +62 -16
- package/dist/adapters/mech/contracts.js +226 -92
- package/dist/adapters/mech/contracts.js.map +1 -1
- package/dist/adapters/mech/safe-revert.js +0 -6
- package/dist/adapters/mech/safe-revert.js.map +1 -1
- package/dist/adapters/mech/types.d.ts +237 -84
- package/dist/adapters/mech/types.js +125 -50
- package/dist/adapters/mech/types.js.map +1 -1
- package/dist/agent/agent-ws.d.ts +1 -0
- package/dist/agent/agent-ws.js +13 -1
- package/dist/agent/agent-ws.js.map +1 -1
- package/dist/agent/operator-claude.js +4 -0
- package/dist/agent/operator-claude.js.map +1 -1
- package/dist/api/gather-status.d.ts +0 -1
- package/dist/api/gather-status.js +0 -1
- package/dist/api/gather-status.js.map +1 -1
- package/dist/api/setup-endpoints.d.ts +20 -0
- package/dist/api/setup-endpoints.js +110 -3
- package/dist/api/setup-endpoints.js.map +1 -1
- package/dist/build-info.json +4 -4
- package/dist/build-meta.json +1 -1
- package/dist/cli/commands/auth.js +6 -3
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/commands/bootstrap.js +0 -1
- package/dist/cli/commands/bootstrap.js.map +1 -1
- package/dist/cli/commands/create.js +3 -3
- package/dist/cli/commands/doctor.js +4 -12
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/fleet-scale.js +0 -1
- package/dist/cli/commands/fleet-scale.js.map +1 -1
- package/dist/cli/commands/fund-requirements.js +0 -1
- package/dist/cli/commands/fund-requirements.js.map +1 -1
- package/dist/cli/commands/migrate-agent-id.js +0 -1
- package/dist/cli/commands/migrate-agent-id.js.map +1 -1
- package/dist/cli/commands/solver-nets.js +1 -1
- package/dist/cli/commands/solver-plugins.js +3 -1
- package/dist/cli/commands/solver-plugins.js.map +1 -1
- package/dist/cli/commands/tasks.js +20 -11
- package/dist/cli/commands/tasks.js.map +1 -1
- package/dist/cli/commands/version.js +0 -1
- package/dist/cli/commands/version.js.map +1 -1
- package/dist/cli/deployment-digest.js +0 -5
- package/dist/cli/deployment-digest.js.map +1 -1
- package/dist/cli/execution-context.js +0 -1
- package/dist/cli/execution-context.js.map +1 -1
- package/dist/cli/introspection-context.js +0 -1
- package/dist/cli/introspection-context.js.map +1 -1
- package/dist/config.d.ts +410 -22
- package/dist/config.js +41 -30
- package/dist/config.js.map +1 -1
- package/dist/daemon/creator.d.ts +3 -3
- package/dist/daemon/creator.js +3 -3
- package/dist/daemon/creator.js.map +1 -1
- package/dist/daemon/daemon.d.ts +3 -6
- package/dist/daemon/daemon.js +30 -9
- package/dist/daemon/daemon.js.map +1 -1
- package/dist/daemon/jinn-claim-loop-canonical.d.ts +11 -11
- package/dist/daemon/jinn-claim-loop-canonical.js +17 -17
- package/dist/daemon/jinn-claim-loop-canonical.js.map +1 -1
- package/dist/daemon/jinn-claim-loop-mock.d.ts +4 -4
- package/dist/daemon/jinn-claim-loop-mock.js +7 -7
- package/dist/daemon/jinn-claim-loop-mock.js.map +1 -1
- package/dist/daemon/jinn-claim-loop.d.ts +4 -4
- package/dist/daemon/jinn-claim-loop.js +3 -3
- package/dist/dashboard/assets/{index-Bxlk5qpa.js → index-CaUOdCs6.js} +6 -6
- package/dist/dashboard/index.html +1 -1
- package/dist/earning/bootstrap.d.ts +0 -1
- package/dist/earning/bootstrap.js +0 -1
- package/dist/earning/bootstrap.js.map +1 -1
- package/dist/earning/contracts.d.ts +18 -20
- package/dist/earning/contracts.js +18 -29
- package/dist/earning/contracts.js.map +1 -1
- package/dist/earning/funding-plan.d.ts +0 -1
- package/dist/earning/funding-plan.js +0 -1
- package/dist/earning/funding-plan.js.map +1 -1
- package/dist/earning/migrate-agent-id.d.ts +0 -1
- package/dist/earning/migrate-agent-id.js +0 -1
- package/dist/earning/migrate-agent-id.js.map +1 -1
- package/dist/erc8004/reputation.d.ts +2 -2
- package/dist/erc8004/reputation.js +2 -2
- package/dist/events/types.d.ts +2 -2
- package/dist/harnesses/engine/delivery.d.ts +10 -6
- package/dist/harnesses/engine/delivery.js +10 -6
- package/dist/harnesses/engine/delivery.js.map +1 -1
- package/dist/harnesses/engine/engine.d.ts +16 -29
- package/dist/harnesses/engine/engine.js +67 -106
- package/dist/harnesses/engine/engine.js.map +1 -1
- package/dist/harnesses/engine/persistence.d.ts +5 -1
- package/dist/harnesses/engine/persistence.js +10 -2
- package/dist/harnesses/engine/persistence.js.map +1 -1
- package/dist/harnesses/external-impls/loader.d.ts +1 -1
- package/dist/harnesses/impls/claude-code-learner/types.d.ts +1 -1
- package/dist/harnesses/impls/claude-mcp-prediction/index.d.ts +1 -1
- package/dist/harnesses/impls/claude-mcp-prediction/index.js +6 -6
- package/dist/harnesses/impls/claude-mcp-prediction/types.d.ts +1 -1
- package/dist/harnesses/impls/claude-mcp-prediction/types.js +1 -1
- package/dist/harnesses/impls/index.js +5 -5
- package/dist/harnesses/impls/portfolio-v0-evaluator/index.js +1 -1
- package/dist/harnesses/impls/portfolio-v0-evaluator/index.js.map +1 -1
- package/dist/harnesses/impls/prediction-v0-baseline/index.d.ts +4 -4
- package/dist/harnesses/impls/prediction-v0-baseline/index.js +10 -10
- package/dist/harnesses/impls/prediction-v0-evaluator/canonical-metrics.d.ts +3 -3
- package/dist/harnesses/impls/prediction-v0-evaluator/checks/availability.d.ts +1 -1
- package/dist/harnesses/impls/prediction-v0-evaluator/index.d.ts +4 -4
- package/dist/harnesses/impls/prediction-v0-evaluator/index.js +11 -11
- package/dist/harnesses/impls/prediction-v1-baseline/index.d.ts +31 -0
- package/dist/harnesses/impls/prediction-v1-baseline/index.js +79 -0
- package/dist/harnesses/impls/prediction-v1-baseline/index.js.map +1 -0
- package/dist/harnesses/impls/prediction-v1-evaluator/index.d.ts +32 -0
- package/dist/harnesses/impls/prediction-v1-evaluator/index.js +198 -0
- package/dist/harnesses/impls/prediction-v1-evaluator/index.js.map +1 -0
- package/dist/harnesses/manifest/types.d.ts +1 -1
- package/dist/harnesses/manifest/types.js +1 -1
- package/dist/harnesses/types.d.ts +2 -1
- package/dist/harnesses/types.js.map +1 -1
- package/dist/main.js +2 -26
- package/dist/main.js.map +1 -1
- package/dist/mcp/operator-server.js +1 -1
- package/dist/mcp/operator-server.js.map +1 -1
- package/dist/mcp/server.js +2 -2
- package/dist/plugins/manifest.d.ts +1 -1
- package/dist/plugins/manifest.js +1 -1
- package/dist/plugins/manifest.js.map +1 -1
- package/dist/plugins/registry.js +1 -1
- package/dist/plugins/registry.js.map +1 -1
- package/dist/plugins/resolvers.js +2 -1
- package/dist/plugins/resolvers.js.map +1 -1
- package/dist/plugins/types.d.ts +4 -8
- package/dist/plugins/validator.js +5 -7
- package/dist/plugins/validator.js.map +1 -1
- package/dist/preflight/claude-auth.d.ts +3 -1
- package/dist/preflight/claude-auth.js +5 -5
- package/dist/preflight/claude-auth.js.map +1 -1
- package/dist/setup/claude-code-install.d.ts +19 -0
- package/dist/setup/claude-code-install.js +51 -0
- package/dist/setup/claude-code-install.js.map +1 -0
- package/dist/solver-nets/contracts.d.ts +2 -0
- package/dist/solver-nets/contracts.js +2 -0
- package/dist/solver-nets/contracts.js.map +1 -0
- package/dist/solver-nets/registry.d.ts +2 -0
- package/dist/solver-nets/registry.js +13 -5
- package/dist/solver-nets/registry.js.map +1 -1
- package/dist/solver-types/constants.d.ts +1 -1
- package/dist/solver-types/constants.js +1 -1
- package/dist/solver-types/index.d.ts +5 -5
- package/dist/solver-types/index.js +5 -5
- package/dist/solver-types/prediction-apy-v0-auto.js +12 -0
- package/dist/solver-types/prediction-apy-v0-auto.js.map +1 -1
- package/dist/solver-types/prediction-v0-auto.d.ts +4 -4
- package/dist/solver-types/prediction-v0-auto.js +22 -10
- package/dist/solver-types/prediction-v0-auto.js.map +1 -1
- package/dist/solver-types/prediction-v0-template.d.ts +10 -10
- package/dist/solver-types/prediction-v0-template.js +16 -16
- package/dist/solver-types/prediction-v0-template.js.map +1 -1
- package/dist/solver-types/prediction-v0.d.ts +2 -2
- package/dist/solver-types/prediction-v0.js +11 -11
- package/dist/solver-types/prediction-v1-auto.d.ts +22 -0
- package/dist/solver-types/prediction-v1-auto.js +211 -0
- package/dist/solver-types/prediction-v1-auto.js.map +1 -0
- package/dist/solver-types/prediction-v1.d.ts +3 -0
- package/dist/solver-types/prediction-v1.js +29 -0
- package/dist/solver-types/prediction-v1.js.map +1 -0
- package/dist/solver-types/solver-type.d.ts +5 -4
- package/dist/store/store.d.ts +4 -0
- package/dist/store/store.js +28 -4
- package/dist/store/store.js.map +1 -1
- package/dist/tasks/posting-service.d.ts +5 -2
- package/dist/tasks/posting-service.js +12 -6
- package/dist/tasks/posting-service.js.map +1 -1
- package/dist/tasks/sources.d.ts +2 -2
- package/dist/tasks/sources.js +10 -7
- package/dist/tasks/sources.js.map +1 -1
- package/dist/templates/harnesses/alternative-harness/package.json.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/coordinator.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/index.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/mock-harness.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/phases/debrief.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/phases/execute.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/phases/improve.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/phases/memory.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/phases/orient.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/phases/plan.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/src/phases/strategize.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/test/coordinator.test.ts.tmpl +1 -1
- package/dist/templates/harnesses/alternative-harness/test/unit.test.ts.tmpl +1 -1
- package/dist/templates/harnesses/evaluator/package.json.tmpl +1 -1
- package/dist/templates/harnesses/evaluator/src/index.ts.tmpl +1 -1
- package/dist/templates/harnesses/evaluator/test/unit.test.ts.tmpl +1 -1
- package/dist/templates/harnesses/forecaster/package.json.tmpl +1 -1
- package/dist/templates/harnesses/forecaster/src/index.ts.tmpl +1 -1
- package/dist/templates/harnesses/forecaster/test/unit.test.ts.tmpl +1 -1
- package/dist/trajectory/schema.d.ts +10 -10
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/payloads/index.d.ts +1 -0
- package/dist/types/payloads/index.js +6 -0
- package/dist/types/payloads/index.js.map +1 -1
- package/dist/types/payloads/prediction-v1.d.ts +2 -0
- package/dist/types/payloads/prediction-v1.js +2 -0
- package/dist/types/payloads/prediction-v1.js.map +1 -0
- package/dist/types/prediction-v1.d.ts +2 -0
- package/dist/types/prediction-v1.js +2 -0
- package/dist/types/prediction-v1.js.map +1 -0
- package/dist/types/prediction.d.ts +559 -19
- package/dist/types/prediction.js +12 -9
- package/dist/types/prediction.js.map +1 -1
- package/dist/types/task-document.d.ts +389 -0
- package/dist/types/task-document.js +11 -0
- package/dist/types/task-document.js.map +1 -1
- package/dist/types/task.d.ts +285 -1
- package/dist/types/task.js +6 -1
- package/dist/types/task.js.map +1 -1
- package/dist/vendor/@jinn-network/sdk/README.md +61 -0
- package/dist/vendor/@jinn-network/sdk/dist/capabilities.d.ts +52 -0
- package/dist/vendor/@jinn-network/sdk/dist/capabilities.js +1 -0
- package/dist/vendor/@jinn-network/sdk/dist/contracts.d.ts +105 -0
- package/dist/vendor/@jinn-network/sdk/dist/contracts.js +147 -0
- package/dist/vendor/@jinn-network/sdk/dist/harness.d.ts +69 -0
- package/dist/vendor/@jinn-network/sdk/dist/harness.js +1 -0
- package/dist/vendor/@jinn-network/sdk/dist/index.d.ts +2 -0
- package/dist/vendor/@jinn-network/sdk/dist/index.js +5 -0
- package/dist/vendor/@jinn-network/sdk/dist/manifest.d.ts +69 -0
- package/dist/vendor/@jinn-network/sdk/dist/manifest.js +3 -0
- package/dist/vendor/@jinn-network/sdk/dist/payloads/prediction-v1.d.ts +223 -0
- package/dist/vendor/@jinn-network/sdk/dist/payloads/prediction-v1.js +64 -0
- package/dist/vendor/@jinn-network/sdk/dist/plugins.d.ts +36 -0
- package/dist/vendor/@jinn-network/sdk/dist/plugins.js +54 -0
- package/dist/vendor/@jinn-network/sdk/dist/prediction-v1.d.ts +870 -0
- package/dist/vendor/@jinn-network/sdk/dist/prediction-v1.js +80 -0
- package/dist/vendor/@jinn-network/sdk/dist/solvernets/index.d.ts +2 -0
- package/dist/vendor/@jinn-network/sdk/dist/solvernets/index.js +1 -0
- package/dist/vendor/@jinn-network/sdk/dist/solvernets/prediction-v1.d.ts +6 -0
- package/dist/vendor/@jinn-network/sdk/dist/solvernets/prediction-v1.js +3 -0
- package/dist/vendor/@jinn-network/sdk/dist/types.d.ts +116 -0
- package/dist/vendor/@jinn-network/sdk/dist/types.js +21 -0
- package/dist/vendor/@jinn-network/sdk/package.json +34 -0
- package/dist/venues/polymarket/client.d.ts +77 -0
- package/dist/venues/polymarket/client.js +309 -0
- package/dist/venues/polymarket/client.js.map +1 -0
- package/dist/withdraw/run-withdraw-plan.js +0 -2
- package/dist/withdraw/run-withdraw-plan.js.map +1 -1
- package/package.json +8 -6
- package/plugins/jinn-prediction-plugin/.claude-plugin/plugin.json +13 -86
- package/plugins/jinn-prediction-plugin/.mcp.json +8 -0
- package/plugins/jinn-prediction-plugin/GEMINI.md +3 -0
- package/plugins/jinn-prediction-plugin/gemini-extension.json +13 -0
- package/plugins/jinn-prediction-plugin/jinn.plugin.json +23 -0
- package/plugins/jinn-prediction-plugin/schemas/prediction-v1-solution.schema.json +34 -0
- package/plugins/jinn-prediction-plugin/schemas/prediction-v1-task.schema.json +118 -0
- package/plugins/jinn-prediction-plugin/schemas/prediction-v1-verdict.schema.json +84 -0
- package/templates/harnesses/alternative-harness/package.json.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/coordinator.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/index.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/mock-harness.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/phases/debrief.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/phases/execute.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/phases/improve.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/phases/memory.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/phases/orient.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/phases/plan.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/src/phases/strategize.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/test/coordinator.test.ts.tmpl +1 -1
- package/templates/harnesses/alternative-harness/test/unit.test.ts.tmpl +1 -1
- package/templates/harnesses/evaluator/package.json.tmpl +1 -1
- package/templates/harnesses/evaluator/src/index.ts.tmpl +1 -1
- package/templates/harnesses/evaluator/test/unit.test.ts.tmpl +1 -1
- package/templates/harnesses/forecaster/package.json.tmpl +1 -1
- package/templates/harnesses/forecaster/src/index.ts.tmpl +1 -1
- package/templates/harnesses/forecaster/test/unit.test.ts.tmpl +1 -1
- package/dist/adapters/claim-registry/abi.d.ts +0 -127
- package/dist/adapters/claim-registry/abi.js +0 -93
- package/dist/adapters/claim-registry/abi.js.map +0 -1
- package/dist/adapters/claim-registry/client.d.ts +0 -98
- package/dist/adapters/claim-registry/client.js +0 -225
- package/dist/adapters/claim-registry/client.js.map +0 -1
- package/dist/adapters/mech/claim-policy.d.ts +0 -40
- package/dist/adapters/mech/claim-policy.js +0 -104
- package/dist/adapters/mech/claim-policy.js.map +0 -1
- package/dist/harnesses/engine/claim.d.ts +0 -69
- package/dist/harnesses/engine/claim.js +0 -111
- package/dist/harnesses/engine/claim.js.map +0 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const WindowSchema = z.object({
|
|
3
|
+
startTs: z.number().int().nonnegative(),
|
|
4
|
+
endTs: z.number().int().nonnegative(),
|
|
5
|
+
});
|
|
6
|
+
export const DecimalProbabilitySchema = z
|
|
7
|
+
.string()
|
|
8
|
+
.regex(/^(0(\.\d+)?|1(\.0+)?)$/, 'must be a decimal string in [0,1]');
|
|
9
|
+
export const IsoDateTimeSchema = z.string().datetime({ offset: true });
|
|
10
|
+
export const PredictionV1ClaimPolicySchema = z.object({
|
|
11
|
+
mode: z.enum(['exclusive', 'parallel']).default('exclusive'),
|
|
12
|
+
maxClaims: z.number().int().positive(),
|
|
13
|
+
maxClaimsPerOperator: z.number().int().positive().default(1),
|
|
14
|
+
claimWindowStartTs: z.number().int().optional(),
|
|
15
|
+
claimWindowEndTs: z.number().int().optional(),
|
|
16
|
+
submissionDeadlineTs: z.number().int().optional(),
|
|
17
|
+
claimLeaseTtlSeconds: z.number().int().positive().default(30 * 60),
|
|
18
|
+
policyHook: z.string().regex(/^0x[0-9a-fA-F]*$/).optional(),
|
|
19
|
+
}).passthrough();
|
|
20
|
+
export const PredictionV1SpecSchema = z.object({
|
|
21
|
+
question: z.object({
|
|
22
|
+
kind: z.literal('binary'),
|
|
23
|
+
text: z.string().min(1),
|
|
24
|
+
yesLabel: z.literal('YES'),
|
|
25
|
+
noLabel: z.literal('NO'),
|
|
26
|
+
}),
|
|
27
|
+
source: z.object({
|
|
28
|
+
type: z.literal('prediction-market'),
|
|
29
|
+
venue: z.literal('polymarket'),
|
|
30
|
+
url: z.string().url(),
|
|
31
|
+
identifiers: z.object({
|
|
32
|
+
marketId: z.string().min(1),
|
|
33
|
+
conditionId: z.string().min(1),
|
|
34
|
+
yesTokenId: z.string().min(1),
|
|
35
|
+
noTokenId: z.string().min(1),
|
|
36
|
+
}),
|
|
37
|
+
}),
|
|
38
|
+
resolution: z.object({
|
|
39
|
+
expectedResolutionTime: IsoDateTimeSchema,
|
|
40
|
+
rulesText: z.string().min(1),
|
|
41
|
+
rulesUrl: z.string().url(),
|
|
42
|
+
timezone: z.string().optional(),
|
|
43
|
+
}),
|
|
44
|
+
consensusSnapshot: z.object({
|
|
45
|
+
sampledAt: IsoDateTimeSchema,
|
|
46
|
+
probabilityYes: DecimalProbabilitySchema,
|
|
47
|
+
method: z.literal('best-bid-ask-midpoint'),
|
|
48
|
+
bestBidYes: DecimalProbabilitySchema,
|
|
49
|
+
bestAskYes: DecimalProbabilitySchema,
|
|
50
|
+
spread: DecimalProbabilitySchema,
|
|
51
|
+
source: z.literal('polymarket-clob'),
|
|
52
|
+
}),
|
|
53
|
+
eligibilitySnapshot: z.object({
|
|
54
|
+
sampledAt: IsoDateTimeSchema,
|
|
55
|
+
timeToResolutionHours: z.number(),
|
|
56
|
+
liquidityUsd: z.string().min(1),
|
|
57
|
+
volume24hUsd: z.string().min(1),
|
|
58
|
+
orderbookAgeSeconds: z.number().nonnegative(),
|
|
59
|
+
selectionReason: z.string().min(1),
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
export const PredictionV1TaskSchema = z
|
|
63
|
+
.object({
|
|
64
|
+
id: z.string().min(1),
|
|
65
|
+
description: z.string().min(1),
|
|
66
|
+
solverType: z.literal('prediction.v1'),
|
|
67
|
+
role: z.enum(['restoration', 'evaluation']).optional(),
|
|
68
|
+
window: WindowSchema,
|
|
69
|
+
claimPolicy: PredictionV1ClaimPolicySchema,
|
|
70
|
+
spec: PredictionV1SpecSchema,
|
|
71
|
+
eligibility: z.record(z.unknown()).default({}),
|
|
72
|
+
})
|
|
73
|
+
.refine((d) => d.window.endTs > d.window.startTs, {
|
|
74
|
+
message: 'window.endTs must be > window.startTs',
|
|
75
|
+
path: ['window'],
|
|
76
|
+
})
|
|
77
|
+
.refine((d) => Date.parse(d.spec.resolution.expectedResolutionTime) > d.window.startTs, {
|
|
78
|
+
message: 'expectedResolutionTime must be after window.startTs',
|
|
79
|
+
path: ['spec', 'resolution', 'expectedResolutionTime'],
|
|
80
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { PREDICTION_V1_SOLVER_NET_CONTRACT, SOLVER_NET_CONTRACTS, PayloadValidationException, getSolverNetContract, validateTask, assertTask, validateSolutionPayload, assertSolutionPayload, validateVerdictPayload, assertVerdictPayload, buildSolutionOutput, buildVerdictOutput, } from '../contracts.js';
|
|
2
|
+
export type { SolverNetContractRole, PayloadKind, SupportedSolverType, CredentialRequirement, SolverNetEvaluationFunction, SolverNetAggregationFunction, SolverNetClaimPolicyDefaults, SolverNetContract, SolverNetContractMap, PayloadValidationIssue, PayloadValidationFailure, PayloadValidationSuccess, PayloadValidationResult, BuildSolutionOutputArgs, BuildVerdictOutputArgs, } from '../contracts.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PREDICTION_V1_SOLVER_NET_CONTRACT, SOLVER_NET_CONTRACTS, PayloadValidationException, getSolverNetContract, validateTask, assertTask, validateSolutionPayload, assertSolutionPayload, validateVerdictPayload, assertVerdictPayload, buildSolutionOutput, buildVerdictOutput, } from '../contracts.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DecimalProbabilitySchema, IsoDateTimeSchema, PredictionV1ClaimPolicySchema, PredictionV1SpecSchema, PredictionV1TaskSchema, } from '../prediction-v1.js';
|
|
2
|
+
export type { PredictionV1Spec, PredictionV1Task } from '../prediction-v1.js';
|
|
3
|
+
export { PredictionV1RestorationPayloadSchema, PredictionV1VerdictPayloadSchema, } from '../payloads/prediction-v1.js';
|
|
4
|
+
export type { PredictionV1RestorationPayload, PredictionV1VerdictPayload, } from '../payloads/prediction-v1.js';
|
|
5
|
+
export { PREDICTION_V1_SOLVER_NET_CONTRACT, PayloadValidationException, getSolverNetContract, validateTask, assertTask, validateSolutionPayload, assertSolutionPayload, validateVerdictPayload, assertVerdictPayload, buildSolutionOutput, buildVerdictOutput, } from '../contracts.js';
|
|
6
|
+
export type { PayloadValidationIssue, PayloadValidationFailure, PayloadValidationSuccess, PayloadValidationResult, BuildSolutionOutputArgs, BuildVerdictOutputArgs, } from '../contracts.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { DecimalProbabilitySchema, IsoDateTimeSchema, PredictionV1ClaimPolicySchema, PredictionV1SpecSchema, PredictionV1TaskSchema, } from '../prediction-v1.js';
|
|
2
|
+
export { PredictionV1RestorationPayloadSchema, PredictionV1VerdictPayloadSchema, } from '../payloads/prediction-v1.js';
|
|
3
|
+
export { PREDICTION_V1_SOLVER_NET_CONTRACT, PayloadValidationException, getSolverNetContract, validateTask, assertTask, validateSolutionPayload, assertSolutionPayload, validateVerdictPayload, assertVerdictPayload, buildSolutionOutput, buildVerdictOutput, } from '../contracts.js';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export type Hex = `0x${string}`;
|
|
2
|
+
export type Address = Hex;
|
|
3
|
+
export interface IntentWindow {
|
|
4
|
+
startTs: number;
|
|
5
|
+
endTs: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Task {
|
|
8
|
+
id: string;
|
|
9
|
+
description: string;
|
|
10
|
+
solverType: string;
|
|
11
|
+
role?: 'restoration' | 'evaluation';
|
|
12
|
+
context?: Record<string, unknown>;
|
|
13
|
+
spec?: Record<string, unknown>;
|
|
14
|
+
window?: IntentWindow;
|
|
15
|
+
eligibility?: Record<string, unknown>;
|
|
16
|
+
attemptId?: string;
|
|
17
|
+
attemptNumber?: number;
|
|
18
|
+
restorationRequestId?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface OutputArtifact {
|
|
21
|
+
artifactType: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
path?: string;
|
|
24
|
+
cid?: string;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface RationaleEntry {
|
|
28
|
+
message: string;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
export interface Solution {
|
|
32
|
+
venueRef: {
|
|
33
|
+
name: string;
|
|
34
|
+
};
|
|
35
|
+
preSnapshot?: Record<string, unknown>;
|
|
36
|
+
postSnapshot?: Record<string, unknown>;
|
|
37
|
+
fills?: unknown[];
|
|
38
|
+
gating: Record<string, unknown>;
|
|
39
|
+
informational?: Record<string, unknown>;
|
|
40
|
+
solutionPayload?: Record<string, unknown>;
|
|
41
|
+
verdictPayload?: Record<string, unknown>;
|
|
42
|
+
artifacts?: OutputArtifact[];
|
|
43
|
+
rationale?: RationaleEntry[];
|
|
44
|
+
}
|
|
45
|
+
export interface TrajectorySpanInput {
|
|
46
|
+
name: string;
|
|
47
|
+
kind: string;
|
|
48
|
+
startTimeUnixNano: string;
|
|
49
|
+
endTimeUnixNano: string;
|
|
50
|
+
attributes: Record<string, unknown>;
|
|
51
|
+
events: Array<{
|
|
52
|
+
name: string;
|
|
53
|
+
timeUnixNano: string;
|
|
54
|
+
attributes?: Record<string, unknown>;
|
|
55
|
+
}>;
|
|
56
|
+
status: {
|
|
57
|
+
code: 'OK' | 'ERROR' | 'UNSET';
|
|
58
|
+
message?: string;
|
|
59
|
+
};
|
|
60
|
+
parentSpanId?: string | null;
|
|
61
|
+
}
|
|
62
|
+
export interface TrajectoryCollector {
|
|
63
|
+
addSpan(input: TrajectorySpanInput): unknown;
|
|
64
|
+
}
|
|
65
|
+
export interface ReadyStatus {
|
|
66
|
+
ready: boolean;
|
|
67
|
+
reason?: string;
|
|
68
|
+
nextStep?: {
|
|
69
|
+
description: string;
|
|
70
|
+
cli?: string;
|
|
71
|
+
url?: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export declare const REQUIRES_LIVE_DAEMON_READINESS: ReadyStatus;
|
|
75
|
+
export interface EnableArgDef {
|
|
76
|
+
name: string;
|
|
77
|
+
description: string;
|
|
78
|
+
required: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface IntentEnableMetadata {
|
|
81
|
+
description: string;
|
|
82
|
+
requiredArgs?: EnableArgDef[];
|
|
83
|
+
externalResources?: Array<{
|
|
84
|
+
name: string;
|
|
85
|
+
url: string;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export type EnableResult = {
|
|
89
|
+
status: 'ready';
|
|
90
|
+
details?: Record<string, unknown>;
|
|
91
|
+
} | {
|
|
92
|
+
status: 'waiting_for_external_action';
|
|
93
|
+
action: {
|
|
94
|
+
description: string;
|
|
95
|
+
url?: string;
|
|
96
|
+
};
|
|
97
|
+
details?: Record<string, unknown>;
|
|
98
|
+
nextInvocation: {
|
|
99
|
+
cli: string;
|
|
100
|
+
purpose: string;
|
|
101
|
+
};
|
|
102
|
+
} | {
|
|
103
|
+
status: 'missing_args';
|
|
104
|
+
required: EnableArgDef[];
|
|
105
|
+
example: {
|
|
106
|
+
cli: string;
|
|
107
|
+
};
|
|
108
|
+
} | {
|
|
109
|
+
status: 'error';
|
|
110
|
+
message: string;
|
|
111
|
+
details?: Record<string, unknown>;
|
|
112
|
+
};
|
|
113
|
+
export declare class SkippableError extends Error {
|
|
114
|
+
readonly reason: string;
|
|
115
|
+
constructor(reason: string, message?: string);
|
|
116
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Public contract surface for Jinn external Harness authors.
|
|
2
|
+
//
|
|
3
|
+
// These types are mirrored from `client/src/harnesses/types.ts` at SDK
|
|
4
|
+
// publish time. The SDK is the stable boundary; @jinn-network/client
|
|
5
|
+
// internals are not.
|
|
6
|
+
export const REQUIRES_LIVE_DAEMON_READINESS = {
|
|
7
|
+
ready: false,
|
|
8
|
+
reason: 'requires live daemon',
|
|
9
|
+
nextStep: {
|
|
10
|
+
description: 'Run the daemon with a configured fleet and wallet',
|
|
11
|
+
cli: 'jinn run',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export class SkippableError extends Error {
|
|
15
|
+
reason;
|
|
16
|
+
constructor(reason, message) {
|
|
17
|
+
super(message ?? reason);
|
|
18
|
+
this.name = 'SkippableError';
|
|
19
|
+
this.reason = reason;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jinn-network/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Stable SDK surface for Jinn SolverNets, Harnesses, plugins, and typed payloads.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./harness": {
|
|
15
|
+
"import": "./dist/harness.js",
|
|
16
|
+
"types": "./dist/harness.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./plugins": {
|
|
19
|
+
"import": "./dist/plugins.js",
|
|
20
|
+
"types": "./dist/plugins.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./solvernets": {
|
|
23
|
+
"import": "./dist/solvernets/index.js",
|
|
24
|
+
"types": "./dist/solvernets/index.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./solvernets/prediction-v1": {
|
|
27
|
+
"import": "./dist/solvernets/prediction-v1.js",
|
|
28
|
+
"types": "./dist/solvernets/prediction-v1.d.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"zod": "^3.22.0"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public Polymarket data client for prediction.v1.
|
|
3
|
+
*
|
|
4
|
+
* Uses only unauthenticated Gamma / CLOB market-data endpoints. No trading,
|
|
5
|
+
* signing, order placement, or wallet surface belongs in this module.
|
|
6
|
+
*/
|
|
7
|
+
export interface PolymarketClientConfig {
|
|
8
|
+
gammaBaseUrl?: string;
|
|
9
|
+
clobBaseUrl?: string;
|
|
10
|
+
fetchImpl?: typeof fetch;
|
|
11
|
+
}
|
|
12
|
+
export interface ListMarketCandidatesArgs extends PolymarketClientConfig {
|
|
13
|
+
limit?: number;
|
|
14
|
+
offset?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface GetMarketArgs extends PolymarketClientConfig {
|
|
17
|
+
marketId?: string;
|
|
18
|
+
slug?: string;
|
|
19
|
+
conditionId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface GetOrderbookArgs extends PolymarketClientConfig {
|
|
22
|
+
marketId: string;
|
|
23
|
+
conditionId: string;
|
|
24
|
+
yesTokenId: string;
|
|
25
|
+
}
|
|
26
|
+
export interface GetResolutionArgs extends PolymarketClientConfig {
|
|
27
|
+
marketId?: string;
|
|
28
|
+
slug?: string;
|
|
29
|
+
conditionId?: string;
|
|
30
|
+
sourceUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface MarketCandidate {
|
|
33
|
+
venue: 'polymarket';
|
|
34
|
+
marketId: string;
|
|
35
|
+
conditionId: string;
|
|
36
|
+
slug: string;
|
|
37
|
+
url: string;
|
|
38
|
+
question: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
rulesText: string;
|
|
41
|
+
endTime: string;
|
|
42
|
+
active: boolean;
|
|
43
|
+
closed: boolean;
|
|
44
|
+
archived: boolean;
|
|
45
|
+
outcomes: ['YES', 'NO'];
|
|
46
|
+
tokenIds: {
|
|
47
|
+
yes: string;
|
|
48
|
+
no: string;
|
|
49
|
+
};
|
|
50
|
+
liquidityUsd: string;
|
|
51
|
+
volume24hUsd: string;
|
|
52
|
+
}
|
|
53
|
+
export interface OrderbookSnapshot {
|
|
54
|
+
venue: 'polymarket';
|
|
55
|
+
marketId: string;
|
|
56
|
+
conditionId: string;
|
|
57
|
+
sampledAt: string;
|
|
58
|
+
bestBidYes: string;
|
|
59
|
+
bestAskYes: string;
|
|
60
|
+
midpointYes: string;
|
|
61
|
+
spread: string;
|
|
62
|
+
source: 'polymarket-clob';
|
|
63
|
+
}
|
|
64
|
+
export interface ResolutionSnapshot {
|
|
65
|
+
venue: 'polymarket';
|
|
66
|
+
marketId: string;
|
|
67
|
+
conditionId: string;
|
|
68
|
+
status: 'unresolved' | 'resolved' | 'invalid' | 'cancelled' | 'ambiguous';
|
|
69
|
+
outcome?: 'YES' | 'NO';
|
|
70
|
+
resolvedAt?: string;
|
|
71
|
+
sourceUrl: string;
|
|
72
|
+
}
|
|
73
|
+
export declare function normalizeMarketCandidate(raw: unknown): MarketCandidate | null;
|
|
74
|
+
export declare function listMarketCandidates(args?: ListMarketCandidatesArgs): Promise<MarketCandidate[]>;
|
|
75
|
+
export declare function getMarket(args: GetMarketArgs): Promise<MarketCandidate>;
|
|
76
|
+
export declare function getOrderbook(args: GetOrderbookArgs): Promise<OrderbookSnapshot>;
|
|
77
|
+
export declare function getResolution(args: GetResolutionArgs): Promise<ResolutionSnapshot>;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public Polymarket data client for prediction.v1.
|
|
3
|
+
*
|
|
4
|
+
* Uses only unauthenticated Gamma / CLOB market-data endpoints. No trading,
|
|
5
|
+
* signing, order placement, or wallet surface belongs in this module.
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_GAMMA_BASE_URL = 'https://gamma-api.polymarket.com';
|
|
8
|
+
const DEFAULT_CLOB_BASE_URL = 'https://clob.polymarket.com';
|
|
9
|
+
function clientFetch(config) {
|
|
10
|
+
return config.fetchImpl ?? fetch;
|
|
11
|
+
}
|
|
12
|
+
function gammaUrl(config, path, params = {}) {
|
|
13
|
+
const url = new URL(path, config.gammaBaseUrl ?? DEFAULT_GAMMA_BASE_URL);
|
|
14
|
+
for (const [key, value] of Object.entries(params)) {
|
|
15
|
+
if (value !== undefined)
|
|
16
|
+
url.searchParams.set(key, String(value));
|
|
17
|
+
}
|
|
18
|
+
return url.toString();
|
|
19
|
+
}
|
|
20
|
+
function clobUrl(config, path, params = {}) {
|
|
21
|
+
const url = new URL(path, config.clobBaseUrl ?? DEFAULT_CLOB_BASE_URL);
|
|
22
|
+
for (const [key, value] of Object.entries(params)) {
|
|
23
|
+
if (value !== undefined)
|
|
24
|
+
url.searchParams.set(key, String(value));
|
|
25
|
+
}
|
|
26
|
+
return url.toString();
|
|
27
|
+
}
|
|
28
|
+
async function readJson(url, fetchImpl) {
|
|
29
|
+
const response = await fetchImpl(url, { method: 'GET' });
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
throw new Error(`Polymarket request failed ${response.status}: ${url}`);
|
|
32
|
+
}
|
|
33
|
+
return response.json();
|
|
34
|
+
}
|
|
35
|
+
function asRecord(value) {
|
|
36
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
37
|
+
? value
|
|
38
|
+
: {};
|
|
39
|
+
}
|
|
40
|
+
function firstString(record, keys) {
|
|
41
|
+
for (const key of keys) {
|
|
42
|
+
const value = record[key];
|
|
43
|
+
if (typeof value === 'string' && value.trim())
|
|
44
|
+
return value.trim();
|
|
45
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
46
|
+
return String(value);
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
function firstBoolean(record, keys, fallback = false) {
|
|
51
|
+
for (const key of keys) {
|
|
52
|
+
const value = record[key];
|
|
53
|
+
if (typeof value === 'boolean')
|
|
54
|
+
return value;
|
|
55
|
+
if (typeof value === 'string') {
|
|
56
|
+
if (value.toLowerCase() === 'true')
|
|
57
|
+
return true;
|
|
58
|
+
if (value.toLowerCase() === 'false')
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return fallback;
|
|
63
|
+
}
|
|
64
|
+
function parseStringArray(value) {
|
|
65
|
+
if (Array.isArray(value))
|
|
66
|
+
return value.map(String);
|
|
67
|
+
if (typeof value !== 'string')
|
|
68
|
+
return [];
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(value);
|
|
71
|
+
return Array.isArray(parsed) ? parsed.map(String) : [];
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return value.split(',').map((part) => part.trim()).filter(Boolean);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function decimalString(value, fallback = '0') {
|
|
78
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
79
|
+
return value.toFixed(2);
|
|
80
|
+
if (typeof value === 'string' && value.trim())
|
|
81
|
+
return value.trim();
|
|
82
|
+
return fallback;
|
|
83
|
+
}
|
|
84
|
+
function normalizeOutcome(value) {
|
|
85
|
+
return value.trim().toUpperCase();
|
|
86
|
+
}
|
|
87
|
+
function buildMarketUrl(slug) {
|
|
88
|
+
return slug ? `https://polymarket.com/event/${slug}` : 'https://polymarket.com';
|
|
89
|
+
}
|
|
90
|
+
function rulesTextOf(record) {
|
|
91
|
+
return firstString(record, [
|
|
92
|
+
'rules',
|
|
93
|
+
'resolutionRules',
|
|
94
|
+
'resolution_rules',
|
|
95
|
+
'description',
|
|
96
|
+
'question',
|
|
97
|
+
]) ?? '';
|
|
98
|
+
}
|
|
99
|
+
function endTimeOf(record) {
|
|
100
|
+
return firstString(record, ['endDateIso', 'endDate', 'end_date', 'endTime', 'end_time']) ?? '';
|
|
101
|
+
}
|
|
102
|
+
function tokenIdsFor(record, outcomes) {
|
|
103
|
+
const ids = parseStringArray(record['clobTokenIds'] ?? record['clob_token_ids'] ?? record['tokenIds']);
|
|
104
|
+
if (ids.length < 2)
|
|
105
|
+
return null;
|
|
106
|
+
const yesIndex = outcomes.findIndex((outcome) => normalizeOutcome(outcome) === 'YES');
|
|
107
|
+
const noIndex = outcomes.findIndex((outcome) => normalizeOutcome(outcome) === 'NO');
|
|
108
|
+
if (yesIndex < 0 || noIndex < 0)
|
|
109
|
+
return null;
|
|
110
|
+
const yes = ids[yesIndex];
|
|
111
|
+
const no = ids[noIndex];
|
|
112
|
+
return yes && no ? { yes, no } : null;
|
|
113
|
+
}
|
|
114
|
+
export function normalizeMarketCandidate(raw) {
|
|
115
|
+
const record = asRecord(raw);
|
|
116
|
+
const marketId = firstString(record, ['id', 'marketId', 'market_id']);
|
|
117
|
+
const conditionId = firstString(record, ['conditionId', 'condition_id']);
|
|
118
|
+
const slug = firstString(record, ['slug', 'marketSlug', 'eventSlug']) ?? '';
|
|
119
|
+
const question = firstString(record, ['question', 'title']) ?? '';
|
|
120
|
+
const outcomes = parseStringArray(record['outcomes']).map(normalizeOutcome);
|
|
121
|
+
const binary = outcomes.length === 2 && outcomes.includes('YES') && outcomes.includes('NO');
|
|
122
|
+
const tokenIds = binary ? tokenIdsFor(record, outcomes) : null;
|
|
123
|
+
const endTime = endTimeOf(record);
|
|
124
|
+
if (!marketId || !conditionId || !question || !binary || !tokenIds || !endTime) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const url = firstString(record, ['url']) ?? buildMarketUrl(slug);
|
|
128
|
+
return {
|
|
129
|
+
venue: 'polymarket',
|
|
130
|
+
marketId,
|
|
131
|
+
conditionId,
|
|
132
|
+
slug,
|
|
133
|
+
url,
|
|
134
|
+
question,
|
|
135
|
+
...(firstString(record, ['description']) ? { description: firstString(record, ['description']) } : {}),
|
|
136
|
+
rulesText: rulesTextOf(record),
|
|
137
|
+
endTime,
|
|
138
|
+
active: firstBoolean(record, ['active'], true),
|
|
139
|
+
closed: firstBoolean(record, ['closed'], false),
|
|
140
|
+
archived: firstBoolean(record, ['archived'], false),
|
|
141
|
+
outcomes: ['YES', 'NO'],
|
|
142
|
+
tokenIds,
|
|
143
|
+
liquidityUsd: decimalString(record['liquidity'] ?? record['liquidityNum'] ?? record['liquidity_usd']),
|
|
144
|
+
volume24hUsd: decimalString(record['volume24hr'] ?? record['volume24h'] ?? record['volume24hUsd'] ?? record['volume_24h']),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export async function listMarketCandidates(args = {}) {
|
|
148
|
+
const body = await readJson(gammaUrl(args, '/markets', {
|
|
149
|
+
active: true,
|
|
150
|
+
closed: false,
|
|
151
|
+
archived: false,
|
|
152
|
+
limit: args.limit ?? 100,
|
|
153
|
+
offset: args.offset ?? 0,
|
|
154
|
+
}), clientFetch(args));
|
|
155
|
+
const rows = Array.isArray(body)
|
|
156
|
+
? body
|
|
157
|
+
: Array.isArray(asRecord(body)['data'])
|
|
158
|
+
? asRecord(body)['data']
|
|
159
|
+
: [];
|
|
160
|
+
return rows
|
|
161
|
+
.map(normalizeMarketCandidate)
|
|
162
|
+
.filter((candidate) => candidate !== null);
|
|
163
|
+
}
|
|
164
|
+
export async function getMarket(args) {
|
|
165
|
+
const fetchImpl = clientFetch(args);
|
|
166
|
+
let raw;
|
|
167
|
+
if (args.marketId) {
|
|
168
|
+
raw = await readJson(gammaUrl(args, `/markets/${encodeURIComponent(args.marketId)}`), fetchImpl);
|
|
169
|
+
}
|
|
170
|
+
else if (args.slug) {
|
|
171
|
+
raw = await readJson(gammaUrl(args, `/markets/slug/${encodeURIComponent(args.slug)}`), fetchImpl);
|
|
172
|
+
}
|
|
173
|
+
else if (args.conditionId) {
|
|
174
|
+
const candidates = await listMarketCandidates({ ...args, limit: 500 });
|
|
175
|
+
const found = candidates.find((candidate) => candidate.conditionId === args.conditionId);
|
|
176
|
+
if (!found)
|
|
177
|
+
throw new Error(`Polymarket market not found for conditionId=${args.conditionId}`);
|
|
178
|
+
return found;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
throw new Error('getMarket requires marketId, slug, or conditionId');
|
|
182
|
+
}
|
|
183
|
+
const candidate = normalizeMarketCandidate(raw);
|
|
184
|
+
if (!candidate)
|
|
185
|
+
throw new Error('Polymarket market response is not an eligible binary market');
|
|
186
|
+
return candidate;
|
|
187
|
+
}
|
|
188
|
+
function timestampToIso(value) {
|
|
189
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
190
|
+
return new Date(value > 10_000_000_000 ? value : value * 1000).toISOString();
|
|
191
|
+
}
|
|
192
|
+
if (typeof value === 'string' && value.trim()) {
|
|
193
|
+
const numeric = Number(value);
|
|
194
|
+
if (Number.isFinite(numeric))
|
|
195
|
+
return timestampToIso(numeric);
|
|
196
|
+
const parsed = Date.parse(value);
|
|
197
|
+
if (Number.isFinite(parsed))
|
|
198
|
+
return new Date(parsed).toISOString();
|
|
199
|
+
}
|
|
200
|
+
return new Date().toISOString();
|
|
201
|
+
}
|
|
202
|
+
function bestBidAsk(book) {
|
|
203
|
+
const bids = Array.isArray(book['bids']) ? book['bids'] : [];
|
|
204
|
+
const asks = Array.isArray(book['asks']) ? book['asks'] : [];
|
|
205
|
+
const bid = Math.max(...bids.map((row) => Number(asRecord(row)['price'])).filter(Number.isFinite));
|
|
206
|
+
const ask = Math.min(...asks.map((row) => Number(asRecord(row)['price'])).filter(Number.isFinite));
|
|
207
|
+
if (!Number.isFinite(bid) || !Number.isFinite(ask))
|
|
208
|
+
return null;
|
|
209
|
+
return { bid, ask };
|
|
210
|
+
}
|
|
211
|
+
function probability(value) {
|
|
212
|
+
return Math.max(0, Math.min(1, value)).toFixed(4);
|
|
213
|
+
}
|
|
214
|
+
export async function getOrderbook(args) {
|
|
215
|
+
const raw = await readJson(clobUrl(args, '/book', { token_id: args.yesTokenId }), clientFetch(args));
|
|
216
|
+
const book = asRecord(raw);
|
|
217
|
+
const best = bestBidAsk(book);
|
|
218
|
+
if (!best) {
|
|
219
|
+
throw new Error(`Polymarket orderbook has no usable YES bid/ask for token ${args.yesTokenId}`);
|
|
220
|
+
}
|
|
221
|
+
const midpoint = (best.bid + best.ask) / 2;
|
|
222
|
+
return {
|
|
223
|
+
venue: 'polymarket',
|
|
224
|
+
marketId: args.marketId,
|
|
225
|
+
conditionId: args.conditionId,
|
|
226
|
+
sampledAt: timestampToIso(book['timestamp']),
|
|
227
|
+
bestBidYes: probability(best.bid),
|
|
228
|
+
bestAskYes: probability(best.ask),
|
|
229
|
+
midpointYes: probability(midpoint),
|
|
230
|
+
spread: probability(best.ask - best.bid),
|
|
231
|
+
source: 'polymarket-clob',
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function outcomeFromRecord(record) {
|
|
235
|
+
const explicit = firstString(record, [
|
|
236
|
+
'winningOutcome',
|
|
237
|
+
'winning_outcome',
|
|
238
|
+
'winner',
|
|
239
|
+
'resolvedOutcome',
|
|
240
|
+
'resolved_outcome',
|
|
241
|
+
'outcome',
|
|
242
|
+
]);
|
|
243
|
+
if (explicit) {
|
|
244
|
+
const normalized = normalizeOutcome(explicit);
|
|
245
|
+
if (normalized === 'YES')
|
|
246
|
+
return 'YES';
|
|
247
|
+
if (normalized === 'NO')
|
|
248
|
+
return 'NO';
|
|
249
|
+
}
|
|
250
|
+
const outcomes = parseStringArray(record['outcomes']).map(normalizeOutcome);
|
|
251
|
+
const prices = parseStringArray(record['outcomePrices'] ?? record['outcome_prices']);
|
|
252
|
+
if (outcomes.length === prices.length && outcomes.length > 0) {
|
|
253
|
+
const winnerIndex = prices.findIndex((price) => Number(price) >= 0.999);
|
|
254
|
+
const winner = winnerIndex >= 0 ? outcomes[winnerIndex] : undefined;
|
|
255
|
+
if (winner === 'YES' || winner === 'NO')
|
|
256
|
+
return winner;
|
|
257
|
+
}
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
export async function getResolution(args) {
|
|
261
|
+
let market = null;
|
|
262
|
+
let record = {};
|
|
263
|
+
const fetchImpl = clientFetch(args);
|
|
264
|
+
let raw;
|
|
265
|
+
if (args.marketId) {
|
|
266
|
+
raw = await readJson(gammaUrl(args, `/markets/${encodeURIComponent(args.marketId)}`), fetchImpl);
|
|
267
|
+
}
|
|
268
|
+
else if (args.slug) {
|
|
269
|
+
raw = await readJson(gammaUrl(args, `/markets/slug/${encodeURIComponent(args.slug)}`), fetchImpl);
|
|
270
|
+
}
|
|
271
|
+
else if (args.conditionId) {
|
|
272
|
+
market = await getMarket(args);
|
|
273
|
+
raw = await readJson(gammaUrl(args, `/markets/${encodeURIComponent(market.marketId)}`), fetchImpl);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
throw new Error('getResolution requires marketId, slug, or conditionId');
|
|
277
|
+
}
|
|
278
|
+
record = asRecord(raw);
|
|
279
|
+
market = normalizeMarketCandidate(record) ?? market;
|
|
280
|
+
const conditionId = market?.conditionId ?? args.conditionId ?? firstString(record, ['conditionId', 'condition_id']) ?? '';
|
|
281
|
+
const marketId = market?.marketId ?? args.marketId ?? firstString(record, ['id', 'marketId', 'market_id']) ?? '';
|
|
282
|
+
const sourceUrl = market?.url ?? args.sourceUrl ?? buildMarketUrl(firstString(record, ['slug']) ?? '');
|
|
283
|
+
const closed = firstBoolean(record, ['closed'], market?.closed ?? false);
|
|
284
|
+
const archived = firstBoolean(record, ['archived'], market?.archived ?? false);
|
|
285
|
+
const outcome = outcomeFromRecord(record);
|
|
286
|
+
const resolutionStatus = firstString(record, ['resolutionStatus', 'umaResolutionStatus', 'status'])?.toLowerCase() ?? '';
|
|
287
|
+
if (/cancel/.test(resolutionStatus)) {
|
|
288
|
+
return { venue: 'polymarket', marketId, conditionId, status: 'cancelled', sourceUrl };
|
|
289
|
+
}
|
|
290
|
+
if (/invalid/.test(resolutionStatus)) {
|
|
291
|
+
return { venue: 'polymarket', marketId, conditionId, status: 'invalid', sourceUrl };
|
|
292
|
+
}
|
|
293
|
+
if (closed && outcome) {
|
|
294
|
+
return {
|
|
295
|
+
venue: 'polymarket',
|
|
296
|
+
marketId,
|
|
297
|
+
conditionId,
|
|
298
|
+
status: 'resolved',
|
|
299
|
+
outcome,
|
|
300
|
+
resolvedAt: timestampToIso(firstString(record, ['resolvedAt', 'resolutionTime', 'updatedAt', 'endDate'])),
|
|
301
|
+
sourceUrl,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
if (closed || archived) {
|
|
305
|
+
return { venue: 'polymarket', marketId, conditionId, status: 'ambiguous', sourceUrl };
|
|
306
|
+
}
|
|
307
|
+
return { venue: 'polymarket', marketId, conditionId, status: 'unresolved', sourceUrl };
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=client.js.map
|