@wowok/agent-mcp 3.1.3 → 3.1.4
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/config/config-audit.spec.d.ts +1 -0
- package/dist/config/config-audit.spec.js +1 -0
- package/dist/config/exposure.d.ts +108 -0
- package/dist/config/exposure.js +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +1 -1
- package/dist/config/judgment.d.ts +1228 -0
- package/dist/config/judgment.js +1 -0
- package/dist/config/judgment.spec.d.ts +1 -0
- package/dist/config/judgment.spec.js +1 -0
- package/dist/config/rule-engine.d.ts +299 -0
- package/dist/config/rule-engine.js +1 -0
- package/dist/config/rule-engine.spec.d.ts +1 -0
- package/dist/config/rule-engine.spec.js +1 -0
- package/dist/config/severity.d.ts +7 -0
- package/dist/config/severity.js +1 -0
- package/dist/customer/order-monitor.d.ts +3 -1
- package/dist/customer/order-monitor.js +1 -1
- package/dist/evaluation/acceptance.d.ts +1 -0
- package/dist/evaluation/acceptance.js +1 -1
- package/dist/evaluation/arbitration-game.js +1 -1
- package/dist/evaluation/builtins/demand-match.js +1 -1
- package/dist/evaluation/builtins/graph-service.js +1 -1
- package/dist/evaluation/builtins/graph-service.spec.js +1 -1
- package/dist/evaluation/engine.js +1 -1
- package/dist/evaluation/game-strategy.d.ts +2 -2
- package/dist/evaluation/game-strategy.js +1 -1
- package/dist/evaluation/match-operation.d.ts +2 -2
- package/dist/evaluation/match-operation.js +1 -1
- package/dist/evaluation/standards.d.ts +3 -25
- package/dist/evaluation/standards.js +1 -1
- package/dist/evaluation/types.d.ts +2 -1
- package/dist/experience/realtime-feedback.js +1 -1
- package/dist/extensions/business-modules.js +1 -1
- package/dist/extensions/custom-registry-file.js +1 -1
- package/dist/extensions/industry-audit.spec.d.ts +1 -0
- package/dist/extensions/industry-audit.spec.js +1 -0
- package/dist/extensions/industry-layers.d.ts +8 -0
- package/dist/extensions/industry-layers.js +1 -1
- package/dist/extensions/industry-pack.d.ts +2 -0
- package/dist/extensions/industry-pack.js +1 -1
- package/dist/extensions/mode-evaluator.js +1 -1
- package/dist/extensions/modes.js +1 -1
- package/dist/graph/onchain/analyze.d.ts +3 -1
- package/dist/graph/onchain/analyze.js +1 -1
- package/dist/graph/onchain/analyze.spec.js +1 -1
- package/dist/graph/onchain/edge-schema.d.ts +1 -0
- package/dist/graph/onchain/edge-schema.js +1 -1
- package/dist/graph/onchain/expand.js +1 -1
- package/dist/graph/onchain/exploration.d.ts +28 -0
- package/dist/graph/onchain/exploration.js +1 -0
- package/dist/graph/onchain/exploration.spec.d.ts +1 -0
- package/dist/graph/onchain/exploration.spec.js +1 -0
- package/dist/graph/onchain/exposure.d.ts +18 -0
- package/dist/graph/onchain/exposure.js +1 -0
- package/dist/graph/onchain/exposure.spec.d.ts +1 -0
- package/dist/graph/onchain/exposure.spec.js +1 -0
- package/dist/graph/onchain/graph-policy.spec.d.ts +1 -0
- package/dist/graph/onchain/graph-policy.spec.js +1 -0
- package/dist/graph/onchain/index.d.ts +6 -0
- package/dist/graph/onchain/index.js +1 -1
- package/dist/graph/onchain/interest.js +1 -1
- package/dist/graph/onchain/interest.spec.js +1 -1
- package/dist/graph/onchain/names.js +1 -1
- package/dist/graph/onchain/names.spec.js +1 -1
- package/dist/graph/onchain/policy.d.ts +8 -0
- package/dist/graph/onchain/policy.js +1 -0
- package/dist/graph/onchain/proposal-graph.js +1 -1
- package/dist/graph/onchain/proposal-graph.spec.js +1 -1
- package/dist/graph/onchain/synthesis.d.ts +20 -0
- package/dist/graph/onchain/synthesis.js +1 -0
- package/dist/graph/onchain/synthesis.spec.d.ts +1 -0
- package/dist/graph/onchain/synthesis.spec.js +1 -0
- package/dist/graph/onchain/types.d.ts +11 -1
- package/dist/keeper/keeper.spec.js +1 -1
- package/dist/knowledge/alloc-audit-policy.spec.d.ts +1 -0
- package/dist/knowledge/alloc-audit-policy.spec.js +1 -0
- package/dist/knowledge/allocation-ledger.js +1 -1
- package/dist/knowledge/allocation-puzzle.d.ts +1 -1
- package/dist/knowledge/allocation-puzzle.js +1 -1
- package/dist/knowledge/allocation-risk.d.ts +4 -1
- package/dist/knowledge/allocation-risk.js +1 -1
- package/dist/knowledge/allocation-templates.js +1 -1
- package/dist/knowledge/arb-risk.d.ts +6 -5
- package/dist/knowledge/arb-risk.js +1 -1
- package/dist/knowledge/arbitration-ledger.d.ts +4 -4
- package/dist/knowledge/arbitration-ledger.js +1 -1
- package/dist/knowledge/arbitration-puzzle.d.ts +1 -1
- package/dist/knowledge/arbitration-puzzle.js +1 -1
- package/dist/knowledge/arbitration-risk.d.ts +4 -1
- package/dist/knowledge/arbitration-risk.js +1 -1
- package/dist/knowledge/arbitration-templates.js +1 -1
- package/dist/knowledge/baselines/judgment-baselines.json +289 -0
- package/dist/knowledge/baselines/risk-baselines.spec.js +1 -1
- package/dist/knowledge/baselines/rules/alloc_audit.json +290 -0
- package/dist/knowledge/baselines/rules/allocation.json +492 -0
- package/dist/knowledge/baselines/rules/arb.json +155 -0
- package/dist/knowledge/baselines/rules/arbitration.json +366 -0
- package/dist/knowledge/baselines/rules/bridge.json +197 -0
- package/dist/knowledge/baselines/rules/contact.json +152 -0
- package/dist/knowledge/baselines/rules/demand.json +158 -0
- package/dist/knowledge/baselines/rules/graph.json +453 -0
- package/dist/knowledge/baselines/rules/guard.json +981 -0
- package/dist/knowledge/baselines/rules/machine.json +706 -0
- package/dist/knowledge/baselines/rules/order.json +549 -0
- package/dist/knowledge/baselines/rules/payment.json +205 -0
- package/dist/knowledge/baselines/rules/permission.json +330 -0
- package/dist/knowledge/baselines/rules/personal.json +139 -0
- package/dist/knowledge/baselines/rules/progress.json +346 -0
- package/dist/knowledge/baselines/rules/proof.json +158 -0
- package/dist/knowledge/baselines/rules/registrar.json +159 -0
- package/dist/knowledge/baselines/rules/repository.json +244 -0
- package/dist/knowledge/baselines/rules/resource.json +117 -0
- package/dist/knowledge/baselines/rules/reward.json +471 -0
- package/dist/knowledge/baselines/rules/service.json +595 -0
- package/dist/knowledge/baselines/rules/treasury.json +440 -0
- package/dist/knowledge/baselines/rules/util.json +101 -0
- package/dist/knowledge/bridge-risk.d.ts +6 -5
- package/dist/knowledge/bridge-risk.js +1 -1
- package/dist/knowledge/builtin-templates.d.ts +26 -0
- package/dist/knowledge/builtin-templates.js +1 -0
- package/dist/knowledge/contact-risk.d.ts +6 -5
- package/dist/knowledge/contact-risk.js +1 -1
- package/dist/knowledge/demand-risk.d.ts +6 -5
- package/dist/knowledge/demand-risk.js +1 -1
- package/dist/knowledge/event-semantics.js +1 -1
- package/dist/knowledge/facts-sync.spec.d.ts +1 -0
- package/dist/knowledge/facts-sync.spec.js +1 -0
- package/dist/knowledge/getting-started.js +1 -1
- package/dist/knowledge/guard-design-patterns.js +1 -1
- package/dist/knowledge/guard-field-cognition.d.ts +1 -1
- package/dist/knowledge/guard-field-cognition.js +1 -1
- package/dist/knowledge/guard-ledger.js +1 -1
- package/dist/knowledge/guard-risk.d.ts +4 -1
- package/dist/knowledge/guard-risk.js +1 -1
- package/dist/knowledge/guard-templates.js +1 -1
- package/dist/knowledge/guard-translation.js +1 -1
- package/dist/knowledge/index.d.ts +10 -2
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/industry-registry.js +1 -1
- package/dist/knowledge/industry-strategy.js +1 -1
- package/dist/knowledge/jsonrpc-enum.js +1 -1
- package/dist/knowledge/machine-ledger.js +1 -1
- package/dist/knowledge/machine-risk.d.ts +4 -1
- package/dist/knowledge/machine-risk.js +1 -1
- package/dist/knowledge/machine-templates.js +1 -1
- package/dist/knowledge/machine-translation.js +1 -1
- package/dist/knowledge/migration-preflight.js +1 -1
- package/dist/knowledge/operation-dictionary.js +1 -1
- package/dist/knowledge/order-ledger.js +1 -1
- package/dist/knowledge/order-puzzle.d.ts +3 -3
- package/dist/knowledge/order-puzzle.js +1 -1
- package/dist/knowledge/order-risk.d.ts +6 -3
- package/dist/knowledge/order-risk.js +1 -1
- package/dist/knowledge/order-templates.js +1 -1
- package/dist/knowledge/passport-ledger.js +1 -1
- package/dist/knowledge/passport-templates.js +1 -1
- package/dist/knowledge/payment-risk.d.ts +8 -6
- package/dist/knowledge/payment-risk.js +1 -1
- package/dist/knowledge/payment-tracker.js +1 -1
- package/dist/knowledge/permission-ledger.js +1 -1
- package/dist/knowledge/permission-puzzle.d.ts +12 -12
- package/dist/knowledge/permission-puzzle.js +1 -1
- package/dist/knowledge/permission-risk.d.ts +4 -7
- package/dist/knowledge/permission-risk.js +1 -1
- package/dist/knowledge/permission-templates.js +1 -1
- package/dist/knowledge/personal-risk.d.ts +6 -5
- package/dist/knowledge/personal-risk.js +1 -1
- package/dist/knowledge/progress-ledger.js +1 -1
- package/dist/knowledge/progress-puzzle.d.ts +2 -2
- package/dist/knowledge/progress-puzzle.js +1 -1
- package/dist/knowledge/progress-risk.d.ts +4 -1
- package/dist/knowledge/progress-risk.js +1 -1
- package/dist/knowledge/progress-templates.js +1 -1
- package/dist/knowledge/proof-risk.d.ts +6 -5
- package/dist/knowledge/proof-risk.js +1 -1
- package/dist/knowledge/puzzle-projections.js +1 -1
- package/dist/knowledge/recipient-constraint.d.ts +20 -1
- package/dist/knowledge/recipient-constraint.js +1 -1
- package/dist/knowledge/registrar-risk.d.ts +6 -5
- package/dist/knowledge/registrar-risk.js +1 -1
- package/dist/knowledge/repository-risk.d.ts +7 -6
- package/dist/knowledge/repository-risk.js +1 -1
- package/dist/knowledge/resource-risk.d.ts +6 -5
- package/dist/knowledge/resource-risk.js +1 -1
- package/dist/knowledge/reward-ledger.d.ts +1 -1
- package/dist/knowledge/reward-ledger.js +1 -1
- package/dist/knowledge/reward-puzzle.d.ts +2 -2
- package/dist/knowledge/reward-puzzle.js +1 -1
- package/dist/knowledge/reward-risk.d.ts +4 -1
- package/dist/knowledge/reward-risk.js +1 -1
- package/dist/knowledge/rule-node-analyzers.spec.js +1 -1
- package/dist/knowledge/rule-outcome.js +1 -1
- package/dist/knowledge/scenario-modes.d.ts +2 -2
- package/dist/knowledge/scenario-modes.js +1 -1
- package/dist/knowledge/scenario-topology.js +1 -1
- package/dist/knowledge/service-allocator-audit-node.js +1 -1
- package/dist/knowledge/service-ledger.js +1 -1
- package/dist/knowledge/service-puzzle.d.ts +2 -2
- package/dist/knowledge/service-puzzle.js +1 -1
- package/dist/knowledge/service-risk-node.js +1 -1
- package/dist/knowledge/service-risk.d.ts +4 -1
- package/dist/knowledge/service-risk.js +1 -1
- package/dist/knowledge/service-templates.js +1 -1
- package/dist/knowledge/strategy-manuals.d.ts +1 -1
- package/dist/knowledge/strategy-manuals.js +1 -1
- package/dist/knowledge/template-loader.d.ts +84 -0
- package/dist/knowledge/template-loader.js +1 -0
- package/dist/knowledge/template-loader.spec.d.ts +1 -0
- package/dist/knowledge/template-loader.spec.js +1 -0
- package/dist/knowledge/template-registry.js +1 -1
- package/dist/knowledge/template-scanner.d.ts +17 -0
- package/dist/knowledge/template-scanner.js +1 -0
- package/dist/knowledge/template-scanner.spec.d.ts +1 -0
- package/dist/knowledge/template-scanner.spec.js +1 -0
- package/dist/knowledge/tools-reference.js +1 -1
- package/dist/knowledge/treasury-ledger.d.ts +1 -1
- package/dist/knowledge/treasury-ledger.js +1 -1
- package/dist/knowledge/treasury-puzzle.d.ts +3 -3
- package/dist/knowledge/treasury-puzzle.js +1 -1
- package/dist/knowledge/treasury-risk.d.ts +4 -1
- package/dist/knowledge/treasury-risk.js +1 -1
- package/dist/knowledge/treasury-templates.js +1 -1
- package/dist/knowledge/util-risk.d.ts +6 -5
- package/dist/knowledge/util-risk.js +1 -1
- package/dist/knowledge/workflow-guidance.d.ts +4 -0
- package/dist/knowledge/workflow-guidance.js +1 -1
- package/dist/knowledge/workspace-lists.js +1 -1
- package/dist/monitor/MonitorLoop.js +1 -1
- package/dist/participation/arbitrator-interest.js +1 -1
- package/dist/participation/radar-core.js +1 -1
- package/dist/persona/analyzer.js +1 -1
- package/dist/persona/index.js +1 -1
- package/dist/persona/model.js +1 -1
- package/dist/persona/persona-audit.spec.d.ts +1 -0
- package/dist/persona/persona-audit.spec.js +1 -0
- package/dist/persona/types.d.ts +2 -0
- package/dist/playbooks/service-build/business-puzzle.js +1 -1
- package/dist/playbooks/service-build/facet-money.d.ts +11 -0
- package/dist/playbooks/service-build/facet-money.js +1 -1
- package/dist/playbooks/service-build/machine-panorama.d.ts +17 -0
- package/dist/playbooks/service-build/machine-panorama.js +1 -1
- package/dist/playbooks/service-build/merchant-guide.d.ts +2 -2
- package/dist/playbooks/service-build/migration-planner.d.ts +43 -0
- package/dist/playbooks/service-build/migration-planner.js +1 -0
- package/dist/playbooks/service-build/object-panorama.d.ts +42 -1
- package/dist/playbooks/service-build/object-panorama.js +1 -1
- package/dist/playbooks/service-build/participation-radar.js +1 -1
- package/dist/playbooks/service-build/pipeline-actions.d.ts +1 -1
- package/dist/playbooks/service-build/reverse-mapping.d.ts +1 -0
- package/dist/playbooks/service-build/reverse-mapping.js +1 -1
- package/dist/playbooks/service-build/risk-aggregator.d.ts +2 -1
- package/dist/playbooks/service-build/risk-aggregator.js +1 -1
- package/dist/playbooks/service-build/semantic-graph.js +1 -1
- package/dist/playbooks/service-build/service-panorama.d.ts +53 -1
- package/dist/playbooks/service-build/service-panorama.js +1 -1
- package/dist/playbooks/service-build/topology-evaluation.spec.js +1 -1
- package/dist/playbooks/service-build/topology-query.js +1 -1
- package/dist/playbooks/service-build/workflow-design-assessment.d.ts +2 -2
- package/dist/playbooks/service-build/workflow-design-assessment.js +1 -1
- package/dist/relationship/registry.js +1 -1
- package/dist/review/machine.js +1 -1
- package/dist/review/order.js +1 -1
- package/dist/review/service.js +1 -1
- package/dist/review/types.d.ts +7 -0
- package/dist/safety/confirm-gate.js +1 -1
- package/dist/schema/benchmark-migration/index.d.ts +207 -0
- package/dist/schema/benchmark-migration/index.js +1 -0
- package/dist/schema/call/allocation.d.ts +1 -1
- package/dist/schema/call/allocation.js +1 -1
- package/dist/schema/call/arbitration.d.ts +1 -1
- package/dist/schema/call/arbitration.js +1 -1
- package/dist/schema/call/base.d.ts +5 -5
- package/dist/schema/call/base.js +1 -1
- package/dist/schema/call/contact.d.ts +1 -1
- package/dist/schema/call/demand.d.ts +1 -1
- package/dist/schema/call/guard.d.ts +3 -3
- package/dist/schema/call/machine.d.ts +5 -5
- package/dist/schema/call/order.d.ts +3 -3
- package/dist/schema/call/payment.js +1 -1
- package/dist/schema/call/permission-handler.d.ts +1 -1
- package/dist/schema/call/permission-handler.js +1 -1
- package/dist/schema/call/permission.d.ts +16 -16
- package/dist/schema/call/permission.js +1 -1
- package/dist/schema/call/personal.d.ts +8 -8
- package/dist/schema/call/personal.js +1 -1
- package/dist/schema/call/progress.d.ts +3 -3
- package/dist/schema/call/repository.d.ts +11 -11
- package/dist/schema/call/repository.js +1 -1
- package/dist/schema/call/reward.d.ts +1 -1
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.d.ts +7 -7
- package/dist/schema/call/service.js +1 -1
- package/dist/schema/call/treasury.d.ts +1 -1
- package/dist/schema/common/index.d.ts +6 -6
- package/dist/schema/common/index.js +1 -1
- package/dist/schema/config/index.d.ts +50 -1
- package/dist/schema/config/index.js +1 -1
- package/dist/schema/evaluation/index.d.ts +27 -11
- package/dist/schema/evaluation/index.js +1 -1
- package/dist/schema/goal/index.d.ts +5 -5
- package/dist/schema/goal/planning.d.ts +15 -15
- package/dist/schema/goal/planning.js +1 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -1
- package/dist/schema/interaction/index.d.ts +1 -1
- package/dist/schema/local/index.js +1 -1
- package/dist/schema/messenger/index.d.ts +26 -26
- package/dist/schema/operations.d.ts +33 -33
- package/dist/schema/operations.js +1 -1
- package/dist/schema/persona/index.d.ts +4708 -0
- package/dist/schema/persona/index.js +1 -1
- package/dist/schema/query/bi.d.ts +232 -25
- package/dist/schema/query/bi.js +1 -1
- package/dist/schema/query/index.d.ts +35 -35
- package/dist/schema/query/index.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema/workflow/index.d.ts +1 -1
- package/dist/schema-query-impl/index.d.ts +9 -0
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/benchmark_migration_operation.output.json +793 -0
- package/dist/schemas/benchmark_migration_operation.schema.json +83 -0
- package/dist/schemas/bridge_operation.schema.json +5 -5
- package/dist/schemas/config_operation.output.json +252 -0
- package/dist/schemas/config_operation.schema.json +21 -1
- package/dist/schemas/evaluation_operation.output.json +22 -10
- package/dist/schemas/goal_operation.schema.json +8 -8
- package/dist/schemas/guard2file.schema.json +1 -1
- package/dist/schemas/index.json +7 -1
- package/dist/schemas/machineNode2file.schema.json +1 -1
- package/dist/schemas/messenger_operation.schema.json +24 -12
- package/dist/schemas/onchain_events.output.json +1 -1
- package/dist/schemas/onchain_operations.output.json +4 -2
- package/dist/schemas/onchain_operations.schema.json +189 -139
- package/dist/schemas/onchain_operations_allocation.schema.json +13 -11
- package/dist/schemas/onchain_operations_arbitration.schema.json +10 -8
- package/dist/schemas/onchain_operations_contact.schema.json +7 -5
- package/dist/schemas/onchain_operations_demand.schema.json +7 -5
- package/dist/schemas/onchain_operations_gen_passport.schema.json +5 -3
- package/dist/schemas/onchain_operations_gen_proof.schema.json +1 -1
- package/dist/schemas/onchain_operations_guard.schema.json +5 -3
- package/dist/schemas/onchain_operations_machine.schema.json +22 -18
- package/dist/schemas/onchain_operations_order.schema.json +11 -7
- package/dist/schemas/onchain_operations_payment.schema.json +3 -3
- package/dist/schemas/onchain_operations_permission.schema.json +19 -11
- package/dist/schemas/onchain_operations_personal.schema.json +16 -10
- package/dist/schemas/onchain_operations_progress.schema.json +11 -7
- package/dist/schemas/onchain_operations_proof.schema.json +5 -3
- package/dist/schemas/onchain_operations_repository.schema.json +12 -8
- package/dist/schemas/onchain_operations_reward.schema.json +11 -9
- package/dist/schemas/onchain_operations_service.schema.json +28 -22
- package/dist/schemas/onchain_operations_treasury.schema.json +11 -9
- package/dist/schemas/onchain_table_data.output.json +27 -17
- package/dist/schemas/persona_operation.output.json +15875 -1
- package/dist/schemas/persona_operation.schema.json +3056 -478
- package/dist/schemas/query_toolkit.output.json +343 -63
- package/dist/schemas/query_toolkit.schema.json +1 -1
- package/dist/schemas/workflow_operation.schema.json +4 -2
- package/dist/strategy/scorecard.js +1 -1
- package/dist/tools/handlers/benchmark-migration.d.ts +2 -0
- package/dist/tools/handlers/benchmark-migration.js +1 -0
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/industry-pack.js +1 -1
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/handlers/query.js +1 -1
- package/dist/tools/handlers/schema-query.js +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/move-fn-index.gen.d.ts +3 -0
- package/dist/tools/move-fn-index.gen.js +1 -0
- package/dist/tools/registry/business.js +1 -1
- package/dist/tools/registry/config.js +1 -1
- package/dist/tools/registry/evaluation.js +1 -1
- package/dist/tools/registry/onchain.js +1 -1
- package/dist/tools/sanitize-output.d.ts +3 -0
- package/dist/tools/sanitize-output.js +1 -0
- package/dist/tools/sanitize-output.spec.d.ts +1 -0
- package/dist/tools/sanitize-output.spec.js +1 -0
- package/package.json +9 -4
- package/dist/knowledge/baselines/evaluation-baselines.json +0 -79
package/dist/extensions/modes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getScenarioMode}from'../knowledge/scenario-modes.js';import{getIndustryTraits}from'../knowledge/industry-registry.js';import{getIndustryRiskChecks,getIndustryNeeds}from'../customer/index.js';import{getFlywheelForIndustry}from'../knowledge/acquisition-flywheel.js';const GENERAL_TRAITS={'has_logistics':![],'communication_heavy':![],'pure_digital':![],'long_cycle':![],'deposit_required':![],'multi_tier_allocation':![],'regulatory_intensity':'low','trust_sensitivity':'medium','consumption_frequency':'occasional','avg_ticket_size':'medium'},GENERAL_FLYWHEEL={'industry':'general','trustSellingPoints':[],'keyActions':[],'rewardStrategy':'User-defined','discountStrategy':'User-defined','trustDescription':'User-defined\x20trust\x20mechanism'},GENERAL_MACHINE_SHAPE=[{'name':'paid','role':'Entry:\x20order\x20created\x20and\x20paid'},{'name':'delivering','role':'Service\x20delivery\x20in\x20progress'},{'name':'delivered','role':'Deliverable\x20available\x20for\x20review'},{'name':'completed','role':'Service\x20completed,\x20funds\x20released'},{'name':'cancelled','role':'Pre-delivery\x20cancellation\x20—\x20triggers\x20refund\x20Allocator'}],GENERAL_ALLOCATOR={'recipient':'signer','count':0x1,'mode':'surplus','description':'Default:\x20surplus\x20to\x20service\x20owner\x20(general\x20fallback)'},RETAIL_MACHINE_SHAPE=[{'name':'paid','role':'Entry:\x20order\x20paid\x20via\x20Service.buy();\x20Machine\x20starts\x20here'},{'name':'processing','role':'Merchant\x20prepares\x20order\x20(picking/packing);\x20required_info\x20(shipping\x20address)\x20collected\x20via\x20Messenger'},{'name':'shipped','role':'Merchant\x20ships\x20goods,\x20records\x20shipping\x20WIP\x20(tracking\x20number)'},{'name':'in_transit','role':'Logistics\x20leg\x20active\x20—\x20tracking\x20WIP\x20updates'},{'name':'delivered','role':'Goods\x20delivered\x20to\x20buyer'},{'name':'confirmed','role':'Buyer\x20confirms\x20receipt\x20(confirm_gate:\x20only\x20buyer\x20can\x20confirm)'},{'name':'completed','role':'Funds\x20released\x20to\x20merchant'},{'name':'return_requested','role':'Buyer\x20requests\x20return\x20within\x20refund_window\x20(>=7d)'},{'name':'returned','role':'Buyer\x20ships\x20goods\x20back\x20(return\x20WIP:\x20tracking\x20number)\x20—\x20triggers\x20refund\x20Allocator\x20(R-M1-11\x20compliant)'},{'name':'cancelled','role':'Pre-ship\x20cancellation\x20—\x20triggers\x20refund\x20Allocator'}],RETAIL_GUARDS=[{'template_id':'buy_guard_inventory','host':'service','purpose':'Verify\x20inventory\x20and\x20buyer\x20address\x20on\x20purchase'},{'template_id':'ship_guard_wip','host':'machine','purpose':'Shipping\x20evidence\x20WIP\x20(logistics\x20tracking\x20number)'},{'template_id':'confirm_guard_signer','host':'machine','purpose':'Only\x20buyer\x20can\x20confirm\x20receipt'},{'template_id':'return_guard_timelock','host':'machine','purpose':'Return\x20request\x20gated\x20by\x20refund_window\x20time-lock\x20(clock)'},{'template_id':'refund_guard_permission','host':'machine','purpose':'Return\x20&\x20refund\x20requires\x20merchant\x20permission\x20OR\x20arbiter'},{'template_id':'tpl_payment_exception_compensation','host':'machine','purpose':'Logistics\x20delay\x20exception\x20compensation\x20(§2.13)'}],RETAIL_ALLOCATOR={'recipient':'entity','count':0x3,'mode':'rate','description':'Platform\x2010%\x20+\x20Merchant\x2090%\x20(rate-based\x20split)\x20on\x20completed;\x20full\x20refund\x20to\x20buyer\x20on\x20returned/cancelled\x20via\x20refund\x20Allocator'},RETAIL_KEY_RISK='Products\x20don\x27t\x20match\x20description\x20—\x20no\x20refund\x20path\x20for\x20returns',RETAIL_BUILD_NOTES=['Logistics\x20WIP\x20(tracking\x20number)\x20is\x20essential\x20—\x20shipping\x20evidence\x20protects\x20both\x20parties\x20in\x20return\x20disputes','confirm_gate\x20prevents\x20merchant\x20from\x20self-confirming\x20receipt','Refund\x20path\x20must\x20support\x20return-and-exchange\x20flow;\x20refund_window\x20>=\x207d','Return\x20request\x20is\x20time-lock\x20gated\x20—\x20after\x20the\x20window\x20closes,\x20returns\x20need\x20merchant\x20permission\x20or\x20arbitration','Compensation\x20fund\x20covers\x20return/exchange\x20disputes'],RETAIL_D2C_MACHINE_SHAPE=[{'name':'ordered','role':'Entry:\x20order\x20created\x20(funds\x20escrowed\x20in\x20Allocation)'},{'name':'shipped','role':'Merchant\x20ships\x20goods'},{'name':'delivered','role':'Goods\x20delivered\x20to\x20buyer'},{'name':'completed','role':'Buyer\x20confirms\x20receipt\x20—\x20withdraw_guard\x20releases\x20funds'},{'name':'cancelled','role':'Pre-ship\x20cancellation\x20—\x20refund_guard\x20refunds\x20buyer'}],RETAIL_D2C_GUARDS=[{'template_id':'withdraw_guard_delivery','host':'service','purpose':'Release\x20funds\x20to\x20merchant\x20+\x20processor\x20on\x20order\x20completion\x20(delivery\x20confirmation)'},{'template_id':'refund_guard_cancellation','host':'service','purpose':'Refund\x20100%\x20to\x20buyer\x20on\x20order\x20cancellation'}],RETAIL_D2C_ALLOCATOR={'recipient':'entity','count':0x2,'mode':'rate','description':'Merchant\x2097%\x20+\x20Processor\x203%\x20(rate-based\x20split,\x20no\x20platform\x20commission)'},RETAIL_D2C_KEY_RISK='No\x20platform\x20arbitration\x20—\x20disputes\x20rely\x20on\x20optional\x20Arbitration\x20or\x20off-chain\x20chargeback',RETAIL_D2C_BUILD_NOTES=['Allocation\x20escrow\x20replaces\x20platform\x20custody\x20—\x20funds\x20locked\x20in\x20contract\x20until\x20Guard\x20releases','withdraw_guard\x20enforces\x20delivery\x20gate\x20—\x20merchant\x20must\x20reach\x20\x27completed\x27\x20state\x20to\x20receive\x20payment','refund_guard\x20ensures\x20100%\x20refund\x20on\x20cancellation\x20—\x20no\x20merchant\x20approval\x20needed','No\x20buy_guard\x20needed\x20—\x20D2C\x20doesn\x27t\x20gate\x20purchases\x20(open\x20storefront)','Arbitration\x20is\x20optional\x20—\x20add\x20when\x20dispute\x20volume\x20justifies\x20the\x20cost','Service\x20↔\x20Guard\x20circular\x20dependency:\x20create\x20Service\x20(unpublished)\x20→\x20create\x20Guards\x20→\x20update\x20Service\x20(publish)'],SUPPORTED_INDUSTRY_SET=new Set(['freelance','rental','education','travel','subscription','retail','retail_d2c']);function fetchTemplate(a){const b=a==='retail_d2c'?'retail':a,c=getIndustryTraits(b)??GENERAL_TRAITS,d=SUPPORTED_INDUSTRY_SET['has'](a),e=a==='retail_d2c'?'retail':a,f=d?getIndustryRiskChecks(e):[],g=d?getIndustryNeeds(e):[],h=getFlywheelForIndustry(b)??GENERAL_FLYWHEEL;let i,j,k,l,m;if(a==='retail')i=RETAIL_MACHINE_SHAPE,j=RETAIL_GUARDS,k=RETAIL_ALLOCATOR,l=RETAIL_KEY_RISK,m=RETAIL_BUILD_NOTES;else{if(a==='retail_d2c')i=RETAIL_D2C_MACHINE_SHAPE,j=RETAIL_D2C_GUARDS,k=RETAIL_D2C_ALLOCATOR,l=RETAIL_D2C_KEY_RISK,m=RETAIL_D2C_BUILD_NOTES;else{if(a==='general'){const n=getScenarioMode('general');i=GENERAL_MACHINE_SHAPE,j=[],k=GENERAL_ALLOCATOR,l=n?.['key_risk']??'No\x20safety\x20net\x20—\x20user\x20must\x20design\x20all\x20trust\x20mechanisms\x20manually',m=n?.['build_notes'];}else{const o=getScenarioMode(a);if(!o)throw new Error('[modes.ts]\x20No\x20scenario\x20mode\x20found\x20for\x20industry:\x20'+a);i=o['machine_shape'],j=o['guards'],k=o['allocator'],l=o['key_risk'],m=o['build_notes'];}}}return{'traits':c,'risk_checks':f,'needs':g,'flywheel':h,'machine_shape':i,'guards':j,'allocator':k,'key_risk':l,'build_notes':m};}export const BUILTIN_MODES=[{'name':'freelance','display_name':'Freelance','version':'v1','source':'builtin',...fetchTemplate('freelance'),'analyze':{'key_questions':['Are\x20WIP\x20hashes\x20bound\x20to\x20each\x20milestone,\x20so\x20delivery\x20evidence\x20cannot\x20be\x20substituted\x20after\x20acceptance?','Does\x20the\x20acceptance\x20gate\x20have\x20a\x20time-bounded\x20escape\x20(keeper-driven\x20auto-accept),\x20or\x20can\x20a\x20silent\x20buyer\x20hold\x20the\x20provider\x27s\x20funds\x20hostage\x20indefinitely?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','allocation.distribute_milestone','service.publish','progress.advance','arb.vote_weighted','contact.im_create'],'config_overrides':{'service':{'setting_locked_time':'30d','engagement_type':'milestone'},'machine':{'wip_required':!![],'wip_hash_algorithm':'sha256','acceptance_gate':!![]}},'expected_benefits':[{'metric':'Dispute\x20rate\x20reduction','expected_value':'40%','evidence':'WIP\x20hash\x20+\x20milestone\x20allocation\x20enforces\x20delivery\x20evidence'},{'metric':'Delivery\x20confirmation\x20efficiency','expected_value':'+50%','evidence':'acceptance\x20gate\x20automates\x20acceptance\x20workflow'},{'metric':'Provider\x20payment\x20assurance','expected_value':'100%','evidence':'Funds\x20auto-release\x20to\x20provider\x20after\x20accepted\x20node'}],'risk_appetite':'balanced','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':![],'require_wip_evidence':!![],'other_constraints':['setting_locked_time\x20>=\x207d\x20to\x20lock\x20engagement-period\x20rules','ISSUE-P1-4:\x2048h\x20auto-accept\x20requires\x20off-chain\x20keeper\x20(WoWok\x20Guard\x20does\x20not\x20support\x20time-based\x20triggers).\x20Deploy\x20a\x20keeper\x20service\x20that\x20polls\x20Progress\x20objects\x20in\x20\x27delivered\x27\x20state\x20and\x20calls\x20adminUnhold\x20(permission\x20224)\x20after\x2048h\x20timeout.\x20See\x20keeper\x20template\x20in\x20docs.']},'applicable_conditions':{'business_scale':'small','min_daily_orders':0x1,'other_conditions':['Suitable\x20for\x20mid-to-long-term\x20project\x20delivery','Requires\x20milestone-based\x20phased\x20acceptance']},'similar_industries':['rental','education'],'novel_capabilities':['allocation.distribute_milestone'],'disabled_builtin_constraints':['require_compensation_fund']},{'name':'rental','display_name':'Rental','version':'v1','source':'builtin',...fetchTemplate('rental'),'analyze':{'key_questions':['Is\x20the\x20deposit\x20escrowed\x20on-chain\x20and\x20sized\x20against\x20the\x20item\x27s\x20full\x20replacement\x20value,\x20not\x20just\x20the\x20rental\x20fee?','Are\x20pre-handover\x20and\x20post-return\x20WIP\x20states\x20hash-recorded,\x20so\x20damage\x20attribution\x20is\x20provable\x20rather\x20than\x20asserted?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance','arb.vote_weighted','contact.im_create'],'config_overrides':{'treasury':{'deposit_escrow':!![],'deposit_deductible':!![]},'machine':{'wip_required':!![],'wip_stages':['handover_out','returned'],'inspection_gate':!![]}},'expected_benefits':[{'metric':'Deposit\x20dispute\x20rate','expected_value':'-60%','evidence':'pre-rental\x20WIP\x20mandatorily\x20records\x20item\x27s\x20original\x20state'},{'metric':'Damage\x20liability\x20accuracy','expected_value':'+70%','evidence':'pre/post\x20WIP\x20hash\x20comparison\x20eliminates\x20unfounded\x20deductions'},{'metric':'Trust\x20score','expected_value':'+25%','evidence':'compensation_fund\x20covers\x20damage\x20risk'}],'risk_appetite':'conservative','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':!![],'require_wip_evidence':!![],'max_single_transaction':0x2710,'compensation_fund_coverage_ratio':0xa,'other_constraints':['Deposit\x20must\x20be\x20escrowed\x20(no\x20direct\x20transfer)','lock_duration\x20>=\x207d\x20to\x20prevent\x20arbitrary\x20merchant\x20withdrawal']},'applicable_conditions':{'business_scale':'small','min_daily_orders':0x1,'other_conditions':['Requires\x20physical\x20item\x20handover','Has\x20logistics\x20or\x20offline\x20delivery\x20leg']},'similar_industries':['retail','travel'],'novel_capabilities':[]},{'name':'education','display_name':'Education','version':'v1','source':'builtin',...fetchTemplate('education'),'analyze':{'key_questions':['Does\x20tuition\x20release\x20per\x20attended\x20session\x20(Progress\x20node),\x20so\x20undelivered\x20sessions\x20stay\x20refundable\x20if\x20the\x20institution\x20disappears?','Does\x20setting_locked_time\x20span\x20the\x20full\x20term,\x20so\x20the\x20institution\x20cannot\x20tighten\x20refund\x20rules\x20mid-course?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','allocation.distribute_milestone','service.publish','progress.advance','arb.vote_weighted','contact.im_create'],'config_overrides':{'allocation':{'strategy':{'recipient':'entity','count':0x1,'mode':'amount','description':'1/N\x20of\x20tuition\x20released\x20per\x20session\x20attendance'},'session_threshold':!![]},'service':{'setting_locked_time':'120d','anti_runaway':!![]}},'expected_benefits':[{'metric':'Refund\x20dispute\x20rate','expected_value':'-50%','evidence':'per-session\x20release\x20distributes\x20tuition\x20by\x20class'},{'metric':'Institution\x20runaway\x20risk','expected_value':'eliminated','evidence':'Funds\x20release\x20per\x20session;\x20undelivered\x20portion\x20is\x20refundable'},{'metric':'Attendance\x20traceability','expected_value':'100%','evidence':'attendance_guard\x20signs\x20each\x20session'}],'risk_appetite':'conservative','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':!![],'require_wip_evidence':![],'other_constraints':['setting_locked_time\x20covers\x20the\x20entire\x20term\x20(>=90d)','Long-cycle\x20projects\x20must\x20monitor\x20>90d\x20progress']},'applicable_conditions':{'business_scale':'medium','min_daily_orders':0x1,'other_conditions':['Long-cycle\x20delivery','Requires\x20per-session\x20acceptance','Regulatory\x20intensity:\x20medium']},'similar_industries':['freelance','subscription'],'novel_capabilities':['allocation.distribute_milestone'],'disabled_builtin_constraints':['require_wip_evidence']},{'name':'travel','display_name':'Travel','version':'v1','source':'builtin',...fetchTemplate('travel'),'analyze':{'key_questions':['Does\x20each\x20itinerary\x20segment\x20have\x20its\x20own\x20guard\x20and\x20WIP\x20acceptance,\x20so\x20one\x20failed\x20leg\x20is\x20refundable\x20without\x20unwinding\x20the\x20whole\x20trip?','Is\x20the\x20multi-tier\x20allocation\x20waterfall\x20(agency\x20→\x20hotel/guide/driver)\x20visible\x20on-chain,\x20so\x20the\x20agency\x20cannot\x20silently\x20re-split\x20funds?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance','arb.vote_weighted','contact.im_create'],'config_overrides':{'allocation':{'strategy':{'recipient':'entity','count':0x3,'mode':'amount','description':'Deposit\x2020%\x20to\x20agency,\x20final\x2080%\x20to\x20agency,\x20then\x20agency-side\x20Allocation\x20splits\x20to\x20hotel/guide/driver\x20per\x20segment'},'multi_tier_waterfall':!![],'guard_chaining':!![]},'service':{'supply_chain_suborders':!![],'segment_guard_required':!![]}},'expected_benefits':[{'metric':'Fund\x20transparency','expected_value':'100%','evidence':'multi-tier\x20allocation\x20splits\x20per\x20segment\x20to\x20hotel/guide/driver'},{'metric':'Itinerary\x20change\x20disputes','expected_value':'-45%','evidence':'segment\x20WIP\x20accepts\x20each\x20leg'},{'metric':'Breach\x20compensation\x20assurance','expected_value':'+60%','evidence':'compensation_fund\x20covers\x20itinerary\x20breach'}],'risk_appetite':'balanced','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':!![],'require_wip_evidence':!![],'other_constraints':['Multi-tier\x20allocation\x20requires\x20guard\x20chaining\x20validation','deposit\x2020%\x20+\x20final\x2080%\x20two-stage\x20payment']},'applicable_conditions':{'business_scale':'medium','min_daily_orders':0x1,'other_conditions':['Multi-segment\x20itinerary\x20combination','Requires\x20hotel/guide/driver\x20multi-party\x20allocation']},'similar_industries':['rental','education'],'novel_capabilities':[]},{'name':'subscription','display_name':'Subscription','version':'v1','source':'builtin',...fetchTemplate('subscription'),'analyze':{'key_questions':['Is\x20every\x20periodic\x20charge\x20gated\x20by\x20an\x20explicit\x20user\x20confirmation,\x20with\x20no\x20auto-renew\x20default?','Can\x20the\x20subscriber\x20cancel\x20anytime\x20effective\x20next\x20period,\x20without\x20a\x20dead-end\x20node\x20in\x20the\x20machine?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance','arb.vote_weighted','reward.claim_guard','contact.im_create'],'config_overrides':{'machine':{'no_auto_renew_trap':!![],'user_confirmed_charge':!![],'cancel_anytime':!![],'next_period_effective':!![]},'service':{'creator_data_subscription':!![],'periodic_billing':!![]}},'expected_benefits':[{'metric':'Renewal\x20rate','expected_value':'+25%','evidence':'loyalty\x20reward\x20+\x20transparent\x20subscription\x20mechanism'},{'metric':'Cancellation\x20disputes','expected_value':'eliminated','evidence':'cancel\x20anytime\x20+\x20no\x20auto-renew\x20trap'},{'metric':'Creator\x20retention','expected_value':'+30%','evidence':'deliver_guard_wip\x20prevents\x20content\x20dropout'}],'risk_appetite':'aggressive','risk_constraints':{'require_arbitration':![],'require_compensation_fund':![],'require_wip_evidence':![],'compensation_fund_coverage_ratio':0x3,'other_constraints':['Forbid\x20dead-end\x20nodes\x20(prevent\x20lock-in)','charge_guard\x20requires\x20user\x20confirmation\x20each\x20period']},'applicable_conditions':{'business_scale':'small','min_daily_orders':0x5,'other_conditions':['Pure-digital\x20delivery','Periodic\x20content\x20or\x20SaaS\x20service']},'similar_industries':['freelance','education'],'novel_capabilities':[],'disabled_builtin_constraints':['require_arbitration','require_compensation_fund','require_wip_evidence']},{'name':'retail','display_name':'Retail','version':'v1','source':'builtin',...fetchTemplate('retail'),'analyze':{'key_questions':['Is\x20the\x20logistics\x20tracking\x20number\x20recorded\x20as\x20WIP\x20before\x20the\x20confirm\x20gate,\x20so\x20receipt\x20disputes\x20have\x20carrier\x20evidence?','Is\x20the\x20refund\x20window\x20at\x20least\x207\x20days\x20with\x20an\x20on-chain\x20refund\x20path\x20that\x20does\x20not\x20rely\x20on\x20merchant\x20goodwill?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance','arb.vote_weighted','reward.claim_guard','contact.im_create'],'config_overrides':{'machine':{'wip_required':!![],'wip_field':'tracking_number','confirm_gate':!![],'refund_requires_approval':!![]},'service':{'logistics_mode':'standard','first_order_discount':!![]}},'expected_benefits':[{'metric':'Return\x20dispute\x20rate','expected_value':'-35%','evidence':'logistics\x20WIP\x20+\x20refund\x20path\x20assurance'},{'metric':'Repurchase\x20rate','expected_value':'+20%','evidence':'spend\x20cashback\x20reward'},{'metric':'Product\x20authenticity\x20traceability','expected_value':'100%','evidence':'WIP\x20verifies\x20product/logistics\x20info'}],'risk_appetite':'conservative','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':!![],'require_wip_evidence':![],'compensation_fund_coverage_ratio':0x5,'other_constraints':['refund_window\x20>=\x207d','confirm_gate:\x20only\x20buyer\x20can\x20confirm\x20receipt']},'applicable_conditions':{'business_scale':'medium','min_daily_orders':0xa,'other_conditions':['Has\x20logistics\x20shipping\x20leg','High-frequency\x20small-ticket\x20transactions']},'similar_industries':['rental','subscription'],'novel_capabilities':[],'disabled_builtin_constraints':['require_wip_evidence']},{'name':'retail_d2c','display_name':'Retail\x20D2C\x20(Direct-to-Consumer)','version':'v1','source':'builtin',...fetchTemplate('retail_d2c'),'analyze':{'key_questions':['Do\x20withdraw_guard\x20and\x20refund_guard\x20fully\x20enclose\x20the\x20Allocation\x20escrow,\x20so\x20neither\x20side\x20can\x20move\x20funds\x20outside\x20the\x20contract\x20path?','With\x20no\x20platform\x20arbitration,\x20what\x20off-chain\x20recourse\x20(if\x20any)\x20backs\x20a\x20delivery\x20failure\x20—\x20and\x20is\x20that\x20acceptable\x20for\x20the\x20ticket\x20size?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_withdraw','guard.validate_refund','machine.node_topology','allocation.distribute','service.publish','progress.advance','contact.im_create'],'config_overrides':{'machine':{'wip_required':![],'confirm_gate':!![],'refund_requires_approval':![]},'service':{'logistics_mode':'merchant_managed','multi_recipient_allocation':!![]}},'expected_benefits':[{'metric':'Merchant\x20revenue\x20share','expected_value':'97%','evidence':'No\x20platform\x20commission\x20—\x20only\x203%\x20processing\x20fee'},{'metric':'Fund\x20safety','expected_value':'contract-grade','evidence':'Allocation\x20escrow\x20+\x20Guard\x20verification\x20replaces\x20platform\x20custody'},{'metric':'Delivery\x20reliability','expected_value':'high','evidence':'withdraw_guard\x20enforces\x20delivery\x20confirmation\x20before\x20payment'}],'risk_appetite':'balanced','risk_constraints':{'require_arbitration':![],'require_compensation_fund':![],'require_wip_evidence':![],'other_constraints':['Allocation\x20escrow\x20required\x20(withdraw_guard\x20+\x20refund_guard)','Service\x20↔\x20Guard\x20circular\x20dependency\x20requires\x203-step\x20creation\x20pattern']},'applicable_conditions':{'business_scale':'small','min_daily_orders':0x1,'other_conditions':['Independent\x20storefront\x20(no\x20marketplace)','Merchant-managed\x20logistics','Allocation\x20escrow\x20model']},'similar_industries':['retail','subscription'],'novel_capabilities':['Allocation\x20escrow\x20as\x20platform-custody\x20alternative','Multi-recipient\x20allocation\x20(merchant\x20+\x20processor)'],'disabled_builtin_constraints':['require_arbitration','require_compensation_fund','require_wip_evidence']},{'name':'general','display_name':'General','version':'v1','source':'builtin',...fetchTemplate('general'),'analyze':{'key_questions':['Which\x20trust\x20mechanisms\x20(arbitration,\x20compensation\x20fund,\x20WIP\x20evidence)\x20are\x20missing\x20here,\x20and\x20what\x20does\x20each\x20absence\x20cost\x20in\x20the\x20worst\x20case?','What\x20is\x20the\x20single\x20point\x20of\x20failure\x20—\x20who\x20can\x20unilaterally\x20take\x20funds\x20or\x20stall\x20the\x20workflow?']},'capabilities_used':['permission.index_create','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance'],'expected_benefits':[{'metric':'Flexibility','expected_value':'100%','evidence':'User\x20customizes\x20all\x20trust\x20mechanism\x20parameters'},{'metric':'Degraded\x20safety','expected_value':'usable','evidence':'Can\x20fall\x20back\x20to\x20general\x20at\x20any\x20time'}],'risk_appetite':'balanced','risk_constraints':{'require_arbitration':![],'require_compensation_fund':![],'require_wip_evidence':![]},'applicable_conditions':{'business_scale':'small','other_conditions':['Fallback\x20degraded\x20mode','Hybrid\x20scenarios\x20not\x20covered\x20by\x20other\x20industries']},'similar_industries':[],'novel_capabilities':[],'disabled_builtin_constraints':['require_arbitration','require_compensation_fund','require_wip_evidence']}];
|
|
1
|
+
import{getScenarioMode}from'../knowledge/scenario-modes.js';import{getIndustryTraits}from'../knowledge/industry-registry.js';import{getIndustryRiskChecks,getIndustryNeeds}from'../customer/index.js';import{getFlywheelForIndustry}from'../knowledge/acquisition-flywheel.js';const GENERAL_TRAITS={'has_logistics':![],'communication_heavy':![],'pure_digital':![],'long_cycle':![],'deposit_required':![],'multi_tier_allocation':![],'regulatory_intensity':'low','trust_sensitivity':'medium','consumption_frequency':'occasional','avg_ticket_size':'medium'},GENERAL_FLYWHEEL={'industry':'general','trustSellingPoints':[],'keyActions':[],'rewardStrategy':'User-defined','discountStrategy':'User-defined','trustDescription':'User-defined\x20trust\x20mechanism'},GENERAL_MACHINE_SHAPE=[{'name':'paid','role':'Entry:\x20order\x20created\x20and\x20paid'},{'name':'delivering','role':'Service\x20delivery\x20in\x20progress'},{'name':'delivered','role':'Deliverable\x20available\x20for\x20review'},{'name':'completed','role':'Service\x20completed,\x20funds\x20released'},{'name':'cancelled','role':'Pre-delivery\x20cancellation\x20—\x20triggers\x20refund\x20Allocator'}],GENERAL_ALLOCATOR={'recipient':'signer','count':0x1,'mode':'surplus','description':'Default:\x20surplus\x20to\x20service\x20owner\x20(general\x20fallback)'},RETAIL_D2C_MACHINE_SHAPE=[{'name':'ordered','role':'Entry:\x20order\x20created\x20(funds\x20escrowed\x20in\x20Allocation)'},{'name':'shipped','role':'Merchant\x20ships\x20goods'},{'name':'delivered','role':'Goods\x20delivered\x20to\x20buyer'},{'name':'completed','role':'Buyer\x20confirms\x20receipt\x20—\x20withdraw_guard\x20releases\x20funds'},{'name':'cancelled','role':'Pre-ship\x20cancellation\x20—\x20refund_guard\x20refunds\x20buyer'}],RETAIL_D2C_GUARDS=[{'template_id':'withdraw_guard_delivery','host':'service','purpose':'Release\x20funds\x20to\x20merchant\x20+\x20processor\x20on\x20order\x20completion\x20(delivery\x20confirmation)'},{'template_id':'refund_guard_cancellation','host':'service','purpose':'Refund\x20100%\x20to\x20buyer\x20on\x20order\x20cancellation'}],RETAIL_D2C_ALLOCATOR={'recipient':'entity','count':0x2,'mode':'rate','description':'Merchant\x2097%\x20+\x20Processor\x203%\x20(rate-based\x20split,\x20no\x20platform\x20commission)'},RETAIL_D2C_KEY_RISK='No\x20platform\x20arbitration\x20—\x20disputes\x20rely\x20on\x20optional\x20Arbitration\x20or\x20off-chain\x20chargeback',RETAIL_D2C_BUILD_NOTES=['Allocation\x20escrow\x20replaces\x20platform\x20custody\x20—\x20funds\x20locked\x20in\x20contract\x20until\x20Guard\x20releases','withdraw_guard\x20enforces\x20delivery\x20gate\x20—\x20merchant\x20must\x20reach\x20\x27completed\x27\x20state\x20to\x20receive\x20payment','refund_guard\x20ensures\x20100%\x20refund\x20on\x20cancellation\x20—\x20no\x20merchant\x20approval\x20needed','No\x20buy_guard\x20needed\x20—\x20D2C\x20doesn\x27t\x20gate\x20purchases\x20(open\x20storefront)','Arbitration\x20is\x20optional\x20—\x20add\x20when\x20dispute\x20volume\x20justifies\x20the\x20cost','Service\x20↔\x20Guard\x20circular\x20dependency:\x20create\x20Service\x20(unpublished)\x20→\x20create\x20Guards\x20→\x20update\x20Service\x20(publish)'],SUPPORTED_INDUSTRY_SET=new Set(['freelance','rental','education','travel','subscription','retail','retail_d2c']);function fetchTemplate(a){const b=a==='retail_d2c'?'retail':a,c=getIndustryTraits(b)??GENERAL_TRAITS,d=SUPPORTED_INDUSTRY_SET['has'](a),e=a==='retail_d2c'?'retail':a,f=d?getIndustryRiskChecks(e):[],g=d?getIndustryNeeds(e):[],h=getFlywheelForIndustry(b)??GENERAL_FLYWHEEL;let i,j,k,l,m;if(a==='retail_d2c')i=RETAIL_D2C_MACHINE_SHAPE,j=RETAIL_D2C_GUARDS,k=RETAIL_D2C_ALLOCATOR,l=RETAIL_D2C_KEY_RISK,m=RETAIL_D2C_BUILD_NOTES;else{if(a==='general'){const n=getScenarioMode('general');i=GENERAL_MACHINE_SHAPE,j=[],k=GENERAL_ALLOCATOR,l=n?.['key_risk']??'No\x20safety\x20net\x20—\x20user\x20must\x20design\x20all\x20trust\x20mechanisms\x20manually',m=n?.['build_notes'];}else{const o=getScenarioMode(a);if(!o)throw new Error('[modes.ts]\x20No\x20scenario\x20mode\x20found\x20for\x20industry:\x20'+a);i=o['machine_shape'],j=o['guards'],k=o['allocator'],l=o['key_risk'],m=o['build_notes'];}}return{'traits':c,'risk_checks':f,'needs':g,'flywheel':h,'machine_shape':i,'guards':j,'allocator':k,'key_risk':l,'build_notes':m};}export const BUILTIN_MODES=[{'name':'freelance','display_name':'Freelance','version':'v1','source':'builtin',...fetchTemplate('freelance'),'analyze':{'key_questions':['Are\x20WIP\x20hashes\x20bound\x20to\x20each\x20milestone,\x20so\x20delivery\x20evidence\x20cannot\x20be\x20substituted\x20after\x20acceptance?','Does\x20the\x20acceptance\x20gate\x20have\x20a\x20time-bounded\x20escape\x20(keeper-driven\x20auto-accept),\x20or\x20can\x20a\x20silent\x20buyer\x20hold\x20the\x20provider\x27s\x20funds\x20hostage\x20indefinitely?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','allocation.distribute_milestone','service.publish','progress.advance','arb.vote_weighted','contact.im_create'],'config_overrides':{'service':{'setting_locked_time':'30d','engagement_type':'milestone'},'machine':{'wip_required':!![],'wip_hash_algorithm':'sha256','acceptance_gate':!![]}},'expected_benefits':[{'metric':'Dispute\x20rate\x20reduction','expected_value':'40%','evidence':'WIP\x20hash\x20+\x20milestone\x20allocation\x20enforces\x20delivery\x20evidence'},{'metric':'Delivery\x20confirmation\x20efficiency','expected_value':'+50%','evidence':'acceptance\x20gate\x20automates\x20acceptance\x20workflow'},{'metric':'Provider\x20payment\x20assurance','expected_value':'100%','evidence':'Funds\x20auto-release\x20to\x20provider\x20after\x20accepted\x20node'}],'risk_appetite':'balanced','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':![],'require_wip_evidence':!![],'other_constraints':['setting_locked_time\x20>=\x207d\x20to\x20lock\x20engagement-period\x20rules','ISSUE-P1-4:\x2048h\x20auto-accept\x20requires\x20off-chain\x20keeper\x20(WoWok\x20Guard\x20does\x20not\x20support\x20time-based\x20triggers).\x20Deploy\x20a\x20keeper\x20service\x20that\x20polls\x20Progress\x20objects\x20in\x20\x27delivered\x27\x20state\x20and\x20calls\x20adminUnhold\x20(permission\x20224)\x20after\x2048h\x20timeout.\x20See\x20keeper\x20template\x20in\x20docs.']},'applicable_conditions':{'business_scale':'small','min_daily_orders':0x1,'other_conditions':['Suitable\x20for\x20mid-to-long-term\x20project\x20delivery','Requires\x20milestone-based\x20phased\x20acceptance']},'similar_industries':['rental','education'],'novel_capabilities':['allocation.distribute_milestone'],'disabled_builtin_constraints':['require_compensation_fund']},{'name':'rental','display_name':'Rental','version':'v1','source':'builtin',...fetchTemplate('rental'),'analyze':{'key_questions':['Is\x20the\x20deposit\x20escrowed\x20on-chain\x20and\x20sized\x20against\x20the\x20item\x27s\x20full\x20replacement\x20value,\x20not\x20just\x20the\x20rental\x20fee?','Are\x20pre-handover\x20and\x20post-return\x20WIP\x20states\x20hash-recorded,\x20so\x20damage\x20attribution\x20is\x20provable\x20rather\x20than\x20asserted?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance','arb.vote_weighted','contact.im_create'],'config_overrides':{'treasury':{'deposit_escrow':!![],'deposit_deductible':!![]},'machine':{'wip_required':!![],'wip_stages':['handover_out','returned'],'inspection_gate':!![]}},'expected_benefits':[{'metric':'Deposit\x20dispute\x20rate','expected_value':'-60%','evidence':'pre-rental\x20WIP\x20mandatorily\x20records\x20item\x27s\x20original\x20state'},{'metric':'Damage\x20liability\x20accuracy','expected_value':'+70%','evidence':'pre/post\x20WIP\x20hash\x20comparison\x20eliminates\x20unfounded\x20deductions'},{'metric':'Trust\x20score','expected_value':'+25%','evidence':'compensation_fund\x20covers\x20damage\x20risk'}],'risk_appetite':'conservative','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':!![],'require_wip_evidence':!![],'max_single_transaction':0x2710,'compensation_fund_coverage_ratio':0xa,'other_constraints':['Deposit\x20must\x20be\x20escrowed\x20(no\x20direct\x20transfer)','lock_duration\x20>=\x207d\x20to\x20prevent\x20arbitrary\x20merchant\x20withdrawal']},'applicable_conditions':{'business_scale':'small','min_daily_orders':0x1,'other_conditions':['Requires\x20physical\x20item\x20handover','Has\x20logistics\x20or\x20offline\x20delivery\x20leg']},'similar_industries':['retail','travel'],'novel_capabilities':[]},{'name':'education','display_name':'Education','version':'v1','source':'builtin',...fetchTemplate('education'),'analyze':{'key_questions':['Does\x20tuition\x20release\x20per\x20attended\x20session\x20(Progress\x20node),\x20so\x20undelivered\x20sessions\x20stay\x20refundable\x20if\x20the\x20institution\x20disappears?','Does\x20setting_locked_time\x20span\x20the\x20full\x20term,\x20so\x20the\x20institution\x20cannot\x20tighten\x20refund\x20rules\x20mid-course?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','allocation.distribute_milestone','service.publish','progress.advance','arb.vote_weighted','contact.im_create'],'config_overrides':{'allocation':{'strategy':{'recipient':'entity','count':0x1,'mode':'amount','description':'1/N\x20of\x20tuition\x20released\x20per\x20session\x20attendance'},'session_threshold':!![]},'service':{'setting_locked_time':'120d','anti_runaway':!![]}},'expected_benefits':[{'metric':'Refund\x20dispute\x20rate','expected_value':'-50%','evidence':'per-session\x20release\x20distributes\x20tuition\x20by\x20class'},{'metric':'Institution\x20runaway\x20risk','expected_value':'eliminated','evidence':'Funds\x20release\x20per\x20session;\x20undelivered\x20portion\x20is\x20refundable'},{'metric':'Attendance\x20traceability','expected_value':'100%','evidence':'attendance_guard\x20signs\x20each\x20session'}],'risk_appetite':'conservative','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':!![],'require_wip_evidence':![],'other_constraints':['setting_locked_time\x20covers\x20the\x20entire\x20term\x20(>=90d)','Long-cycle\x20projects\x20must\x20monitor\x20>90d\x20progress']},'applicable_conditions':{'business_scale':'medium','min_daily_orders':0x1,'other_conditions':['Long-cycle\x20delivery','Requires\x20per-session\x20acceptance','Regulatory\x20intensity:\x20medium']},'similar_industries':['freelance','subscription'],'novel_capabilities':['allocation.distribute_milestone'],'disabled_builtin_constraints':['require_wip_evidence']},{'name':'travel','display_name':'Travel','version':'v1','source':'builtin',...fetchTemplate('travel'),'analyze':{'key_questions':['Does\x20each\x20itinerary\x20segment\x20have\x20its\x20own\x20guard\x20and\x20WIP\x20acceptance,\x20so\x20one\x20failed\x20leg\x20is\x20refundable\x20without\x20unwinding\x20the\x20whole\x20trip?','Is\x20the\x20multi-tier\x20allocation\x20waterfall\x20(agency\x20→\x20hotel/guide/driver)\x20visible\x20on-chain,\x20so\x20the\x20agency\x20cannot\x20silently\x20re-split\x20funds?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance','arb.vote_weighted','contact.im_create'],'config_overrides':{'allocation':{'strategy':{'recipient':'entity','count':0x3,'mode':'amount','description':'Deposit\x2020%\x20to\x20agency,\x20final\x2080%\x20to\x20agency,\x20then\x20agency-side\x20Allocation\x20splits\x20to\x20hotel/guide/driver\x20per\x20segment'},'multi_tier_waterfall':!![],'guard_chaining':!![]},'service':{'supply_chain_suborders':!![],'segment_guard_required':!![]}},'expected_benefits':[{'metric':'Fund\x20transparency','expected_value':'100%','evidence':'multi-tier\x20allocation\x20splits\x20per\x20segment\x20to\x20hotel/guide/driver'},{'metric':'Itinerary\x20change\x20disputes','expected_value':'-45%','evidence':'segment\x20WIP\x20accepts\x20each\x20leg'},{'metric':'Breach\x20compensation\x20assurance','expected_value':'+60%','evidence':'compensation_fund\x20covers\x20itinerary\x20breach'}],'risk_appetite':'balanced','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':!![],'require_wip_evidence':!![],'other_constraints':['Multi-tier\x20allocation\x20requires\x20guard\x20chaining\x20validation','deposit\x2020%\x20+\x20final\x2080%\x20two-stage\x20payment']},'applicable_conditions':{'business_scale':'medium','min_daily_orders':0x1,'other_conditions':['Multi-segment\x20itinerary\x20combination','Requires\x20hotel/guide/driver\x20multi-party\x20allocation']},'similar_industries':['rental','education'],'novel_capabilities':[]},{'name':'subscription','display_name':'Subscription','version':'v1','source':'builtin',...fetchTemplate('subscription'),'analyze':{'key_questions':['Is\x20every\x20periodic\x20charge\x20gated\x20by\x20an\x20explicit\x20user\x20confirmation,\x20with\x20no\x20auto-renew\x20default?','Can\x20the\x20subscriber\x20cancel\x20anytime\x20effective\x20next\x20period,\x20without\x20a\x20dead-end\x20node\x20in\x20the\x20machine?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance','arb.vote_weighted','reward.claim_guard','contact.im_create'],'config_overrides':{'machine':{'no_auto_renew_trap':!![],'user_confirmed_charge':!![],'cancel_anytime':!![],'next_period_effective':!![]},'service':{'creator_data_subscription':!![],'periodic_billing':!![]}},'expected_benefits':[{'metric':'Renewal\x20rate','expected_value':'+25%','evidence':'loyalty\x20reward\x20+\x20transparent\x20subscription\x20mechanism'},{'metric':'Cancellation\x20disputes','expected_value':'eliminated','evidence':'cancel\x20anytime\x20+\x20no\x20auto-renew\x20trap'},{'metric':'Creator\x20retention','expected_value':'+30%','evidence':'deliver_guard_wip\x20prevents\x20content\x20dropout'}],'risk_appetite':'aggressive','risk_constraints':{'require_arbitration':![],'require_compensation_fund':![],'require_wip_evidence':![],'compensation_fund_coverage_ratio':0x3,'other_constraints':['Forbid\x20dead-end\x20nodes\x20(prevent\x20lock-in)','charge_guard\x20requires\x20user\x20confirmation\x20each\x20period']},'applicable_conditions':{'business_scale':'small','min_daily_orders':0x5,'other_conditions':['Pure-digital\x20delivery','Periodic\x20content\x20or\x20SaaS\x20service']},'similar_industries':['freelance','education'],'novel_capabilities':[],'disabled_builtin_constraints':['require_arbitration','require_compensation_fund','require_wip_evidence']},{'name':'retail','display_name':'Retail','version':'v1','source':'builtin',...fetchTemplate('retail'),'analyze':{'key_questions':['Is\x20the\x20logistics\x20tracking\x20number\x20recorded\x20as\x20WIP\x20before\x20the\x20confirm\x20gate,\x20so\x20receipt\x20disputes\x20have\x20carrier\x20evidence?','Is\x20the\x20refund\x20window\x20at\x20least\x207\x20days\x20with\x20an\x20on-chain\x20refund\x20path\x20that\x20does\x20not\x20rely\x20on\x20merchant\x20goodwill?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_buy','guard.validate_wip_hash','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance','arb.vote_weighted','reward.claim_guard','contact.im_create'],'config_overrides':{'machine':{'wip_required':!![],'wip_field':'tracking_number','confirm_gate':!![],'refund_requires_approval':!![]},'service':{'logistics_mode':'standard','first_order_discount':!![]}},'expected_benefits':[{'metric':'Return\x20dispute\x20rate','expected_value':'-35%','evidence':'logistics\x20WIP\x20+\x20refund\x20path\x20assurance'},{'metric':'Repurchase\x20rate','expected_value':'+20%','evidence':'spend\x20cashback\x20reward'},{'metric':'Product\x20authenticity\x20traceability','expected_value':'100%','evidence':'WIP\x20verifies\x20product/logistics\x20info'}],'risk_appetite':'conservative','risk_constraints':{'require_arbitration':!![],'require_compensation_fund':!![],'require_wip_evidence':![],'compensation_fund_coverage_ratio':0x5,'other_constraints':['refund_window\x20>=\x207d','confirm_gate:\x20only\x20buyer\x20can\x20confirm\x20receipt']},'applicable_conditions':{'business_scale':'medium','min_daily_orders':0xa,'other_conditions':['Has\x20logistics\x20shipping\x20leg','High-frequency\x20small-ticket\x20transactions']},'similar_industries':['rental','subscription'],'novel_capabilities':[],'disabled_builtin_constraints':['require_wip_evidence']},{'name':'retail_d2c','display_name':'Retail\x20D2C\x20(Direct-to-Consumer)','version':'v1','source':'builtin',...fetchTemplate('retail_d2c'),'analyze':{'key_questions':['Do\x20withdraw_guard\x20and\x20refund_guard\x20fully\x20enclose\x20the\x20Allocation\x20escrow,\x20so\x20neither\x20side\x20can\x20move\x20funds\x20outside\x20the\x20contract\x20path?','With\x20no\x20platform\x20arbitration,\x20what\x20off-chain\x20recourse\x20(if\x20any)\x20backs\x20a\x20delivery\x20failure\x20—\x20and\x20is\x20that\x20acceptable\x20for\x20the\x20ticket\x20size?']},'capabilities_used':['permission.index_create','permission.role_assign','guard.validate_withdraw','guard.validate_refund','machine.node_topology','allocation.distribute','service.publish','progress.advance','contact.im_create'],'config_overrides':{'machine':{'wip_required':![],'confirm_gate':!![],'refund_requires_approval':![]},'service':{'logistics_mode':'merchant_managed','multi_recipient_allocation':!![]}},'expected_benefits':[{'metric':'Merchant\x20revenue\x20share','expected_value':'97%','evidence':'No\x20platform\x20commission\x20—\x20only\x203%\x20processing\x20fee'},{'metric':'Fund\x20safety','expected_value':'contract-grade','evidence':'Allocation\x20escrow\x20+\x20Guard\x20verification\x20replaces\x20platform\x20custody'},{'metric':'Delivery\x20reliability','expected_value':'high','evidence':'withdraw_guard\x20enforces\x20delivery\x20confirmation\x20before\x20payment'}],'risk_appetite':'balanced','risk_constraints':{'require_arbitration':![],'require_compensation_fund':![],'require_wip_evidence':![],'other_constraints':['Allocation\x20escrow\x20required\x20(withdraw_guard\x20+\x20refund_guard)','Service\x20↔\x20Guard\x20circular\x20dependency\x20requires\x203-step\x20creation\x20pattern']},'applicable_conditions':{'business_scale':'small','min_daily_orders':0x1,'other_conditions':['Independent\x20storefront\x20(no\x20marketplace)','Merchant-managed\x20logistics','Allocation\x20escrow\x20model']},'similar_industries':['retail','subscription'],'novel_capabilities':['Allocation\x20escrow\x20as\x20platform-custody\x20alternative','Multi-recipient\x20allocation\x20(merchant\x20+\x20processor)'],'disabled_builtin_constraints':['require_arbitration','require_compensation_fund','require_wip_evidence']},{'name':'general','display_name':'General','version':'v1','source':'builtin',...fetchTemplate('general'),'analyze':{'key_questions':['Which\x20trust\x20mechanisms\x20(arbitration,\x20compensation\x20fund,\x20WIP\x20evidence)\x20are\x20missing\x20here,\x20and\x20what\x20does\x20each\x20absence\x20cost\x20in\x20the\x20worst\x20case?','What\x20is\x20the\x20single\x20point\x20of\x20failure\x20—\x20who\x20can\x20unilaterally\x20take\x20funds\x20or\x20stall\x20the\x20workflow?']},'capabilities_used':['permission.index_create','machine.node_topology','treasury.owner_receive','allocation.distribute','service.publish','progress.advance'],'expected_benefits':[{'metric':'Flexibility','expected_value':'100%','evidence':'User\x20customizes\x20all\x20trust\x20mechanism\x20parameters'},{'metric':'Degraded\x20safety','expected_value':'usable','evidence':'Can\x20fall\x20back\x20to\x20general\x20at\x20any\x20time'}],'risk_appetite':'balanced','risk_constraints':{'require_arbitration':![],'require_compensation_fund':![],'require_wip_evidence':![]},'applicable_conditions':{'business_scale':'small','other_conditions':['Fallback\x20degraded\x20mode','Hybrid\x20scenarios\x20not\x20covered\x20by\x20other\x20industries']},'similar_industries':[],'novel_capabilities':[],'disabled_builtin_constraints':['require_arbitration','require_compensation_fund','require_wip_evidence']}];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Analyzer, Confidence, Finding, FindingKind, FindingSeverity, NodeAnalyzer, Retention, TopoNode, ViewerRole, Viewport } from "./types.js";
|
|
1
|
+
import type { Analyzer, Confidence, Finding, FindingKind, FindingSeverity, NodeAnalyzer, Retention, TopoNode, ViewerRole, Viewport, FindingExposure } from "./types.js";
|
|
2
2
|
import type { NameResolver } from "./names.js";
|
|
3
3
|
export declare function findingWhere(f: {
|
|
4
4
|
id: string;
|
|
@@ -35,6 +35,7 @@ export declare function runAnalyzers(v: Viewport, opts?: {
|
|
|
35
35
|
only?: string[];
|
|
36
36
|
kinds?: FindingKind[];
|
|
37
37
|
}): Finding[];
|
|
38
|
+
export declare function withFindingObjects(findings: Finding[]): Finding[];
|
|
38
39
|
export interface NodeRuleOutcome {
|
|
39
40
|
severity?: FindingSeverity;
|
|
40
41
|
title: string;
|
|
@@ -44,6 +45,7 @@ export interface NodeRuleOutcome {
|
|
|
44
45
|
confidence?: Confidence;
|
|
45
46
|
ruleId?: string;
|
|
46
47
|
evidence?: string;
|
|
48
|
+
exposure?: FindingExposure;
|
|
47
49
|
nativeRisk?: unknown;
|
|
48
50
|
}
|
|
49
51
|
export interface NodeRuleBinding {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{detectFakeOrders,detectShellMerchant}from'./anti-cheat.js';import{orderCompletionInGraph}from'./expand.js';import{PROPOSAL_GAP_ANALYZER}from'./proposal-graph.js';function root(a){const b=a?.['raw'],c=b?.['data']??b;return c&&typeof c==='object'?c:undefined;}function str(a){return typeof a==='string'&&a!=='0x0'?a:undefined;}function big(a){if(a==null)return 0x0n;try{return BigInt(typeof a==='number'?Math['trunc'](a):String(a));}catch{return 0x0n;}}function bool(a){return a===!![]||a===0x1||a==='1';}function asList(a){return Array['isArray'](a)?a:[];}function wfNodeName(a){const b=a['indexOf']('::node::');return b>=0x0?a['slice'](b+'::node::'['length']):a;}function wfMachineOf(a){const b=a['indexOf']('::node::');return b>=0x0?a['slice'](0x0,b):'';}export function findingWhere(a){const b=a['id'];if(b['startsWith']('R4:')){const c=b['slice'](0x3),d=c['indexOf'](':'),e=d>=0x0?c['slice'](0x0,d):c,g=d>=0x0?c['slice'](d+0x1):'';return e+':\x20'+g['split']('→')['map'](h=>wfNodeName(h['trim']()))['join']('\x20→\x20');}if(b['startsWith']('R7:treasury:'))return'Treasury\x20'+b['slice']('R7:treasury:'['length']);if(b['startsWith']('R7:reward:'))return'Reward\x20'+b['slice']('R7:reward:'['length']);if(b['startsWith']('R2:'))return b['slice'](0x3);if(b['startsWith']('R5:')){const [h,i]=b['slice'](0x3)['split']('|');return wfNodeName(h??'')+'\x20('+(i??'window')+')';}return a['title']??a['id'];}export function findingWhereResolved(a,b){const c=a['id'];if(c['startsWith']('R4:')){const d=c['slice'](0x3),e=d['indexOf'](':'),g=e>=0x0?d['slice'](0x0,e):d,h=e>=0x0?d['slice'](e+0x1):'',i=b['resolve'](g)['label'],j=l=>b['resolveWf'](l)?.['node']['label']??b['resolve'](l)['label'],k=h['split']('→')['map'](l=>j(l['trim']()))['join']('\x20→\x20');return i+':\x20'+k;}if(c['startsWith']('R7:treasury:'))return'Treasury\x20'+b['resolve'](c['slice']('R7:treasury:'['length']))['label'];if(c['startsWith']('R7:reward:'))return'Reward\x20'+b['resolve'](c['slice']('R7:reward:'['length']))['label'];if(c['startsWith']('R2:'))return b['resolve'](c['slice'](0x3))['label'];if(c['startsWith']('R5:')){const [l,m]=c['slice'](0x3)['split']('|');return b['resolve'](l??'')['label']+'\x20('+(m??'window')+')';}return a['title']??a['id'];}function typedNodes(a,b){const c=[];for(const d of a['visibleNodes']){const e=a['graph']['nodes']['get'](d);if(e?.['kind']==='object'&&e['objectType']===b&&e['raw']&&!e['proposal'])c['push'](e);}return c;}function edgeList(a,b){return a['visibleEdges']['filter'](c=>c['schema']===b);}function out(a,b,c){return a['visibleEdges']['filter'](d=>d['from']===b['toLowerCase']()&&d['schema']===c);}function inc(a,b,c){return a['visibleEdges']['filter'](d=>d['to']===b['toLowerCase']()&&d['schema']===c);}export const RETENTION_RANK={'complete':0x0,'event_full':0x0,'bounded_exact':0x1,'membership':0x1,'derived':0x2,'bounded_window':0x3,'event_degraded':0x3};const WINDOW_LIMIT=0x1450;export function pathConfidence(a,b){let c=0x0,d=![];for(const g of b){c=Math['max'](c,RETENTION_RANK[g['retention']]??0x0);if(g['retention']==='bounded_window'||g['retention']==='event_degraded'||g['truncated'])d=!![];}if(d){let h=0x0;for(const i of b){if(i['retention']!=='bounded_window'&&!i['truncated'])continue;const j=a['visibleEdges']['filter'](l=>l['schema']===i['schema']&&l['from']===i['from'])['length'];h=Math['max'](h,j);const k=a['graph']['truncations']['find'](l=>l['nodeId']===i['from']&&l['schema']===i['schema']);if(k)h=Math['max'](h,k['observed']);}return{'confidence':'windowed','window':{'observed':h||b['length'],'limit':WINDOW_LIMIT}};}const f=c===0x0?'exact':c===0x2?'derived':'bounded';return{'confidence':f};}function makeFinding(a,b,c,d,e){const {confidence:f,window:g}=pathConfidence(a,e['pathEdges']??[]);return{'id':b,'kind':c,'severity':e['severity']??'info','title':d,'path':e['path'],'confidence':f,...g?{'window':g}:{},'roles':e['roles']??['neutral'],'detail':e['detail'],'suggestion':e['suggestion']};}const MAX_FINDINGS_PER_RULE=0x14,ROLE_OWNER_OR_ADMIN=0x1|0x2;export function buildControlIndex(a){const b=new Map(),c=new Map(),d=new Map(),f=(h,i,j)=>{const l=h['get'](i)??new Set();l['add'](j),h['set'](i,l);},g=new Map();for(const h of edgeList(a,'eoa.permission')){const i=typeof h['payload']?.['roleBits']==='number'?h['payload']['roleBits']:ROLE_OWNER_OR_ADMIN;if((i&ROLE_OWNER_OR_ADMIN)===0x0)continue;f(g,h['from'],h['to']);}for(const j of edgeList(a,'permission.core_binding')){const k=a['graph']['nodes']['get'](j['to']);if(!k||k['kind']!=='object')continue;f(d,j['to'],j['from']);for(const [l,m]of g){if(!m['has'](j['from']))continue;f(b,j['to'],l),f(c,l,j['to']);}}return{'controllers':b,'objectsByEoa':c,'permsOfObject':d};}function machineViews(a){const b=new Map();for(const d of edgeList(a,'wf.transition')){const f=wfMachineOf(d['from']);if(!f)continue;const g=b['get'](f)??[];g['push'](d),b['set'](f,g);}const c=[];for(const [h,i]of b){const j=a['graph']['nodes']['get'](h);if(!j||!a['visibleNodes']['has'](h))continue;const k=new Set([...(function*(){const l=new Set(i['map'](p=>String(p['payload']?.['node']??''))['filter'](Boolean)),o=new Set(i['map'](p=>String(p['payload']?.['prevNode']??''))['filter'](Boolean));for(const p of l)if(!o['has'](p))yield p;}())]);c['push']({'machine':j,'transitions':i,'terminals':k});}return c;}const ROLES_RISK_NEUTRAL_MERCHANT=['neutral','system','merchant'],R1={'id':'R1','kind':'risk','run'(b){const c=buildControlIndex(b),d=[],e=typedNodes(b,'Service'),f=typedNodes(b,'Arbitration');o:for(const g of e){const h=c['controllers']['get'](g['id']);if(!h)continue;for(const i of f){const j=c['controllers']['get'](i['id']);if(!j)continue;const k=c['permsOfObject']['get'](g['id']),l=c['permsOfObject']['get'](i['id']),m=[...k??[]]['some'](n=>l?.['has'](n));if(m)continue;for(const n of h){if(!j['has'](n))continue;d['push'](makeFinding(b,'R1:'+g['id']+':'+i['id']+':'+n,'risk','Same-controller\x20arbitration\x20risk:\x20the\x20service\x20and\x20the\x20arbitration\x20service\x20are\x20controlled\x20by\x20the\x20same\x20EOA',{'severity':'high','path':[n,'eoa.permission','permission.core_binding',g['id'],i['id']],'pathEdges':edgeList(b,'permission.core_binding'),'roles':['neutral','system','merchant','arbitrator'],'detail':'EOA\x20'+n+'\x20controls\x20both\x20Service\x20'+g['id']+'\x20and\x20Arbitration\x20'+i['id']+'\x20as\x20owner/admin,\x20'+'and\x20the\x20two\x20are\x20attached\x20to\x20DIFFERENT\x20Permissions\x20(E33\x20only\x20forbids\x20the\x20same\x20Permission,\x20not\x20cross-group\x20arbitration).\x20'+'structurally\x20this\x20EOA\x20can\x20influence\x20both\x20the\x20arbitrated\x20service\x20and\x20the\x20ruling\x20outcome.','suggestion':'Verify\x20the\x20EOA\x27s\x20control\x20relationships;\x20require\x20disjoint\x20owner/admin\x20sets\x20between\x20the\x20service\x20and\x20the\x20arbitration\x20service,\x20or\x20remove\x20that\x20arbitration\x20service\x20from\x20the\x20selectable\x20list.'}));if(d['length']>=MAX_FINDINGS_PER_RULE)break o;}}}return d;}},R2={'id':'R2','kind':'risk','run'(a){const b=[];for(const c of typedNodes(a,'Service')){const f=root(c),g=out(a,c['id'],'service.order');if(g['length']===0x0)continue;let h=0x0n,i=0x0;for(const l of g){const m=root(a['graph']['nodes']['get'](l['to']));if(!m)continue;h+=big(m['amount']),i++;}if(i===0x0)continue;const j=big(f['compensation_fund']),k=h*0x3n;if(j>=k)continue;b['push'](makeFinding(a,'R2:'+c['id'],'risk','Payout\x20exposure:\x20compensation\x20fund\x20is\x20below\x20the\x203x\x20ceiling\x20of\x20windowed\x20order\x20amounts',{'severity':j<h?'high':'medium','path':[c['id'],'service.order','Order.amount','Service.compensation_fund'],'pathEdges':g,'roles':['neutral','system','merchant','buyer'],'detail':'Compensation\x20fund\x20'+j+'\x20base\x20units;\x20'+i+'\x20windowed\x20orders\x20total\x20'+h+';\x20'+('the\x20per-order\x20statutory\x20payout\x20cap\x20of\x203x\x20amount\x20gives\x20a\x20structural\x20total\x20exposure\x20of\x20'+k+'\x20(arb.move:302-321).'),'suggestion':'Top\x20up\x20compensation_fund\x20to\x20more\x20than\x203x\x20the\x20windowed\x20amount,\x20or\x20reduce\x20open\x20order\x20volume\x20within\x20the\x20window.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},CONTROL_TYPES=new Set(['Service','Machine','Treasury']),CONTROL_FANOUT_ALERT=0x3,R3={'id':'R3','kind':'risk','run'(a){const b=buildControlIndex(a),c=[];for(const [d,e]of b['objectsByEoa']){const f=[...e]['filter'](i=>CONTROL_TYPES['has'](a['graph']['nodes']['get'](i)?.['objectType']??''));if(f['length']<CONTROL_FANOUT_ALERT)continue;const g=f['filter'](i=>a['graph']['nodes']['get'](i)?.['objectType']==='Service'),h=g['reduce']((i,j)=>i+out(a,j,'service.order')['length'],0x0);c['push'](makeFinding(a,'R3:'+d,'risk','Permission\x20concentration:\x20a\x20single\x20EOA\x20controls\x20multiple\x20business-critical\x20objects',{'severity':f['length']>=0x5?'medium':'low','path':[d,'eoa.permission','permission.core_binding'],'pathEdges':edgeList(a,'eoa.permission')['concat'](edgeList(a,'permission.core_binding')),'roles':ROLES_RISK_NEUTRAL_MERCHANT,'detail':'EOA\x20'+d+'\x20controls\x20'+f['length']+'\x20Service/Machine/Treasury\x20objects\x20via\x20owner/admin\x20permissions\x20'+('('+g['length']+'\x20of\x20them\x20Services,\x20'+h+'\x20orders\x20visible\x20in\x20the\x20window);\x20business\x20scale\x20does\x20not\x20match\x20permission\x20dispersion.'),'suggestion':'Delegate\x20day-to-day\x20operations\x20to\x20dedicated\x20admin/entity\x20roles\x20and\x20keep\x20owner\x20for\x20emergencies\x20only;\x20avoid\x20attaching\x20core\x20objects\x20to\x20the\x20same\x20permission\x20group.'}));if(c['length']>=MAX_FINDINGS_PER_RULE)break;}return c;}},R4={'id':'R4','kind':'risk','run'(a){const b=[];p:for(const c of machineViews(a)){const d=new Map();for(const g of c['transitions']){if(!c['terminals']['has'](String(g['payload']?.['node']??'')))continue;const h=g['from']+'→'+g['to'],i=d['get'](h)??[];i['push'](g),d['set'](h,i);}for(const [j,k]of d){const l=new Set();let m=![];for(const n of k){if(str(n['payload']?.['namedOperator']))l['add']('name:'+n['payload']['namedOperator']);if(typeof n['payload']?.['permissionIndex']==='number')l['add']('perm:'+n['payload']['permissionIndex']);if(str(n['payload']?.['guard']))m=!![];}if(l['size']===0x1&&!m){const o=[...l][0x0];b['push'](makeFinding(a,'R4:'+c['machine']['id']+':'+j,'risk','Workflow\x20single\x20point:\x20the\x20only\x20Forward\x20before\x20a\x20terminal\x20state\x20has\x20a\x20single\x20operator\x20and\x20no\x20fallback\x20Guard',{'severity':'medium','path':[c['machine']['id'],'machine.node','wf.transition',j],'pathEdges':k,'roles':['neutral','system','merchant','collaborator'],'detail':'On\x20Machine\x20'+c['machine']['id']+',\x20path\x20'+j+'\x20toward\x20terminal\x20state\x20'+wfNodeName(k[0x0]['to'])+':\x20'+('the\x20only\x20operable\x20party\x20is\x20'+o+'\x20and\x20no\x20Forward\x20has\x20a\x20guard\x20fallback;\x20if\x20that\x20party\x20goes\x20offline\x20the\x20workflow\x20stalls.'),'suggestion':'Add\x20a\x20permissionIndex\x20alternative\x20or\x20attach\x20a\x20guard\x20auto-advance\x20condition\x20to\x20this\x20Forward\x20so\x20one\x20party\x20cannot\x20block\x20the\x20terminal\x20state.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break p;}}}return b;}},R5={'id':'R5','kind':'risk','run'(a){const b=[],c=new Set();for(const d of a['graph']['truncations']){if(!a['visibleNodes']['has'](d['nodeId']))continue;const e=d['nodeId']+'|'+d['schema'];if(c['has'](e))continue;c['add'](e),b['push']({'id':'R5:'+e,'kind':'risk','severity':'info','title':'Window\x20truncation:\x20affected\x20conclusions\x20are\x20lower\x20bounds\x20within\x20the\x20<=5200\x20FIFO/ring\x20window\x20only','path':[d['nodeId'],d['schema']],'confidence':'windowed','window':{'observed':d['observed'],'limit':d['limit']??WINDOW_LIMIT},'roles':['neutral','system','merchant','buyer','supplier','arbitrator','collaborator'],'detail':'Fanout\x20of\x20'+d['schema']+'\x20at\x20node\x20'+d['nodeId']+'\x20is\x20truncated\x20(observed\x20'+d['observed']+',\x20window\x20limit\x20'+(d['limit']??WINDOW_LIMIT)+');\x20'+'any\x20conclusion\x20relying\x20on\x20this\x20path\x20must\x20be\x20worded\x20as\x20\x22within\x20the\x20window\x20/\x20at\x20least\x22,\x20never\x20as\x20exhaustive\x20truth.','suggestion':'For\x20exhaustive\x20conclusions\x20switch\x20to\x20the\x20event\x20channel\x20(channel\x20D)\x20or\x20raise\x20perKindCaps\x20within\x20budget.'});if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},R6={'id':'R6','kind':'risk','run'(a){const b=[];for(const c of typedNodes(a,'Service')){const e=root(c);if(!bool(e['bPublished']))continue;if(big(e['setting_lock_duration'])!==0x0n)continue;b['push'](makeFinding(a,'R6:'+c['id'],'risk','Missing\x20setting\x20lock:\x20published\x20Service\x20has\x20setting_lock_duration=0',{'severity':'medium','path':[c['id'],'Service.setting_lock_duration'],'roles':ROLES_RISK_NEUTRAL_MERCHANT['concat']('buyer'),'detail':'Service\x20'+c['id']+'\x20is\x20published\x20but\x20setting_lock_duration=0:\x20order_allocators\x20/\x20rewards\x20/\x20arbitrations\x20/\x20machine\x20'+'and\x20compensation_fund\x20withdrawals\x20can\x20be\x20changed\x20instantly\x20(default\x20lock\x20is\x2030\x20days,\x20service.move:38);\x20buyers\x20face\x20instantly\x20mutable\x20terms.','suggestion':'Set\x20setting_lock_duration\x20after\x20publishing\x20(30\x20days\x20=\x202592000000\x20ms\x20at\x20minimum);\x20term\x20changes\x20must\x20go\x20through\x20a\x20waiting\x20period.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},OBJECT_USER_ROLES=['neutral','system','buyer','supplier'],R7={'id':'R7','kind':'risk','run'(a){const b=[];for(const c of typedNodes(a,'Treasury')){const d=asList(root(c)?.['external_withdraw_guard']);if(d['length']===0x0)continue;b['push'](makeFinding(a,'R7:treasury:'+c['id'],'risk','Object-user\x20CRITICAL:\x20Treasury\x20has\x20a\x20permission-free\x20external\x20release\x20path',{'severity':'critical','path':[c['id'],'Treasury.external_withdraw_guard'],'roles':OBJECT_USER_ROLES,'detail':'Treasury\x20'+c['id']+'\x20has\x20'+d['length']+'\x20external_withdraw_guard\x20entry/entries:\x20external_withdraw\x20needs\x20no\x20Treasury\x20'+'Permission\x20—\x20only\x20the\x20Guard\x27s\x20boolean\x20verdict\x20stands\x20between\x20an\x20external\x20caller\x20and\x20the\x20balance.\x20The\x20topology\x20performs\x20'+'no\x20Guard-bytecode\x20analysis,\x20so\x20the\x20Guard\x27s\x20strength\x20is\x20UNVERIFIABLE\x20here.\x20Move\x20truth\x20(protocol\x20140):\x20the\x20destination\x20is\x20'+'forced\x20to\x20the\x20transaction\x20sender\x20(abort\x20code\x2010\x20on\x20mismatch),\x20which\x20blocks\x20third-party\x20redirection\x20but\x20NOT\x20release\x20to\x20a\x20'+'caller\x20whose\x20transaction\x20satisfies\x20a\x20weak\x20Guard\x20(for\x20example,\x20a\x20constant-true\x20root\x20with\x20a\x20static\x20amount\x20slot).','suggestion':'Do\x20not\x20rely\x20on\x20or\x20transact\x20through\x20this\x20Treasury\x20until\x20the\x20owner\x20presents\x20the\x20full\x20Guard\x20definitions;\x20verify\x20the\x20predicate\x20'+'constrains\x20the\x20amount\x20slot;\x20require\x20a\x20testnet\x20regression\x20(recipient\x20!=\x20sender\x20must\x20abort\x20with\x20code\x2010).'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}for(const e of typedNodes(a,'Reward')){const f=asList(root(e)?.['guards']);if(f['length']===0x0)continue;b['push'](makeFinding(a,'R7:reward:'+e['id'],'risk','Object-user\x20CRITICAL:\x20Reward\x20has\x20a\x20permission-free\x20claim\x20path\x20with\x20an\x20unverifiable\x20payout\x20slot',{'severity':'critical','path':[e['id'],'Reward.guards'],'roles':OBJECT_USER_ROLES,'detail':'Reward\x20'+e['id']+'\x20has\x20'+f['length']+'\x20claim\x20guard\x20entry/entries:\x20claim()\x20needs\x20no\x20Permission,\x20and\x20with\x20a\x20'+'Recipient::GuardIdentifier\x20entry\x20the\x20payout\x20address\x20is\x20read\x20from\x20the\x20claim-time\x20passport\x20submission.\x20Whether\x20that\x20slot\x20'+'is\x20constrained\x20is\x20decided\x20inside\x20the\x20Guard\x20predicate,\x20which\x20the\x20topology\x20cannot\x20verify\x20—\x20a\x20guard\x20that\x20passes\x20without\x20'+'constraining\x20the\x20recipient\x20slot\x20lets\x20any\x20passing\x20party\x20fill\x20the\x20slot\x20with\x20their\x20own\x20address\x20and\x20claim\x20the\x20pool.','suggestion':'Do\x20not\x20treat\x20the\x20reward\x20pool\x20as\x20sound\x20until\x20the\x20owner\x20presents\x20the\x20Guard\x20definitions;\x20verify\x20the\x20predicate\x20binds\x20the\x20'+'recipient\x20slot\x20(Signer/entity),\x20or\x20confirm\x20the\x20entries\x20use\x20Entity/Signer\x20recipients\x20that\x20do\x20not\x20depend\x20on\x20submitted\x20slots.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},RATE_BASIS=0x2710n;function allocationStructuralIssues(a){const b=[];let c=0x0,d=![];for(const e of asList(a)){const f=e??{};let g=0x0n,h=![];for(const i of asList(f['sharing'])){const j=i??{},k=Number(j['mode']);if(k===0x2||j['mode']==='Surplus'){c++,d=!![];continue;}k===0x1||j['mode']==='Rate'?g+=big(j['sharing']):h=!![];}g!==0x0n&&g!==RATE_BASIS&&!d&&b['push']('Rate\x20allocation\x20totals\x20'+g+'\x20!=\x2010000\x20basis\x20points\x20with\x20no\x20Surplus\x20fallback;\x20payment\x20will\x20abort'),h&&(f['max']==null||big(f['max'])===0x0n)&&b['push']('Fixed-amount\x20(Amount)\x20allocation\x20Allocator\x20lacks\x20a\x20max\x20cap;\x20excess\x20transfer\x20is\x20possible\x20when\x20the\x20guard\x20triggers');}if(c>0x1)b['push'](c+'\x20Surplus\x20entries\x20(at\x20most\x201\x20is\x20legal);\x20surplus\x20ownership\x20is\x20ambiguous');return[...new Set(b)];}const A1={'id':'A1','kind':'arbitrage','run'(a){const b=[],c=(e,f,g,h)=>{const i=allocationStructuralIssues(f);if(i['length']===0x0||h['has'](e))return;h['add'](e),b['push'](makeFinding(a,'A1:'+e,'arbitrage','Allocation\x20structure\x20mismatch:\x20Rate/Surplus/max\x20configuration\x20has\x20triggerable\x20structural\x20defects',{'severity':'medium','path':[e,'allocators[].sharing'],'pathEdges':g,'roles':['neutral','system','merchant','buyer'],'detail':e+':\x20'+i['join'](';\x20')+'\x20(allocation.move:173-200).','suggestion':'Complete\x20Rate\x20groups\x20to\x2010000\x20or\x20configure\x20a\x20single\x20Surplus;\x20fixed-amount\x20Allocators\x20must\x20set\x20max;\x20run\x20the\x20allocation\x20precheck\x20before\x20going\x20live.'}));},d=new Set();for(const e of typedNodes(a,'Allocation')){c(e['id'],root(e)['allocators'],inc(a,e['id'],'order.allocation'),d);}for(const f of typedNodes(a,'Service')){const g=root(f)['order_allocators'];if(g?.['allocators'])c(f['id'],g['allocators'],edgeList(a,'service.order_allocator_guard'),d);}return b['slice'](0x0,MAX_FINDINGS_PER_RULE);}},DISCOUNT_FIXED=0x1,THIRTY_DAYS_MS=0x1en*0x18n*0x3cn*0x3cn*0x3e8n,A2={'id':'A2','kind':'arbitrage','run'(a){const b=[];for(const c of typedNodes(a,'Discount')){const e=root(c),f=big(e['time_end'])-big(e['time_start'])>=THIRTY_DAYS_MS;if(!bool(e['transferable'])||!f)continue;if(Number(e['discount_type'])!==DISCOUNT_FIXED)continue;if(e['benchmark']!=null&&e['benchmark']!=='0')continue;b['push'](makeFinding(a,'A2:'+c['id'],'arbitrage','Discount\x20combination:\x20transferable\x20+\x20long\x20validity\x20window\x20+\x20fixed-amount\x20discount\x20without\x20benchmark',{'severity':'low','path':[c['id'],'Discount.transferable/time_window/benchmark'],'roles':['neutral','system','merchant'],'detail':'Discount\x20'+c['id']+'\x20is\x20transferable,\x20valid\x20>=30\x20days,\x20is\x20a\x20fixed-amount\x20discount,\x20and\x20has\x20no\x20benchmark\x20price\x20check\x20(service.move:109-121);\x20'+'this\x20leaves\x20room\x20for\x20coupon\x20hoarding\x20and\x20resale\x20arbitrage.','suggestion':'Shorten\x20the\x20validity\x20window,\x20switch\x20to\x20RATES\x20proportional\x20discounts,\x20or\x20add\x20benchmark\x20Guards;\x20disable\x20transferable\x20if\x20needed.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},A3={'id':'A3','kind':'arbitrage','run'(a){const b=[];for(const e of typedNodes(a,'Arbitration')){const f=root(e),g=big(f['fee'])===0x0n&&!str(f['usage_guard']);g&&b['push'](makeFinding(a,'A3:'+e['id'],'arbitrage','Remedy\x20cost\x20structure:\x20zero\x20fee\x20+\x20no\x20usage\x20gate\x20gives\x20malicious\x20disputes\x20a\x20positive-expected-value\x20setup',{'severity':'medium','path':[e['id'],'Arbitration.fee','Arbitration.usage_guard'],'roles':['neutral','system','arbitrator','merchant','buyer'],'detail':'Arbitration\x20'+e['id']+'\x20has\x20fee=0\x20and\x20an\x20empty\x20usage_guard;\x20combined\x20with\x20the\x203x\x20amount\x20payout\x20cap,\x20single\x20claim,\x20'+'and\x2030-day\x20withdrawal\x20lock\x20rules\x20(arb.move:302-358,\x20order.move:86-96),\x20filing\x20a\x20malicious\x20dispute\x20carries\x20no\x20structural\x20upfront\x20cost.','suggestion':'Set\x20a\x20non-zero\x20fee\x20to\x20cover\x20adjudication\x20cost,\x20or\x20use\x20usage_guard\x20to\x20require\x20disputing\x20parties\x20to\x20hold\x20on-chain\x20participation\x20credentials.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}const c=new Map();for(const h of a['visibleNodes']){const i=a['graph']['nodes']['get'](h),j=i?.['raw']?.['type_raw'];if(typeof j!=='string'||!j['includes']('::payment::CoinWrapper<'))continue;const k=j['slice'](j['indexOf']('<')+0x1,j['lastIndexOf']('>'))['trim'](),l=c['get'](k)??[];l['push'](h),c['set'](k,l);}if(c['size']>0x0){const m=[...c['keys']()]['sort']();b['push']({'id':'A3:coinwrapper','kind':'arbitrage','severity':'info','title':'Cross-coin\x20escrow\x20review\x20point:\x20CoinWrapper<K>\x20escrow\x20objects\x20exist\x20in\x20the\x20graph','path':['payment::CoinWrapper'],'confidence':'exact','roles':['neutral','system','arbitrator','merchant'],'detail':'Visible\x20CoinWrapper\x20escrow\x20covers\x20coin\x20types:\x20'+m['join'](',\x20')+'\x20('+[...c['values']()]['reduce']((o,p)=>o+p['length'],0x0)+'\x20objects).\x20'+'v1\x20performs\x20no\x20market\x20valuation;\x20remedy/allocation\x20conclusions\x20across\x20coins\x20require\x20manual\x20review\x20of\x20coin\x20mismatch\x20and\x20depeg\x20risk.','suggestion':'Verify\x20the\x20escrow\x20coin\x20type\x20matches\x20the\x20service\x20coin\x20type\x20T;\x20add\x20independent\x20exchange-rate/oracle\x20evidence\x20before\x20concluding\x20cross-coin\x20cases.'});}return b['slice'](0x0,MAX_FINDINGS_PER_RULE);}},SCARCE_PRESENTERS=0x2;function demandGuardIds(a,b){const c=new Set();for(const d of out(a,b,'demand.guard'))c['add'](d['to']);return c;}function serviceGuardIds(a,b){const c=new Set();for(const f of out(a,b['id'],'service.buy_guard'))c['add'](f['to']);const d=out(a,b['id'],'service.machine')[0x0]?.['to'];if(d)for(const g of a['visibleEdges']){if(g['schema']==='wf.forward_guard'&&g['from']['startsWith'](d+'::node::'))c['add'](g['to']);}return c;}const O1={'id':'O1','kind':'opportunity','run'(a){const b=[],c=typedNodes(a,'Service');for(const d of typedNodes(a,'Demand')){const e=out(a,d['id'],'demand.presenter');if(e['length']>=SCARCE_PRESENTERS)continue;const f=demandGuardIds(a,d['id']),g=[];for(const i of c){const j=serviceGuardIds(a,i);if(f['size']===0x0||[...f]['every'](k=>j['has'](k)))g['push'](i['id']);}const h=e;b['push'](makeFinding(a,'O1:'+d['id'],'opportunity','Open\x20demand:\x20few\x20proposals,\x20with\x20structurally\x20capable\x20suppliers\x20present',{'severity':'info','path':[d['id'],'demand.presenter','demand.guard','Service'],'pathEdges':h['concat'](out(a,d['id'],'demand.guard')),'roles':['neutral','system','supplier'],'detail':'Demand\x20'+d['id']+'\x20currently\x20has\x20only\x20'+e['length']+'\x20proposal(s);\x20matched\x20by\x20Guard\x20structure\x20(no\x20Guard\x20bytecode\x20parsing)\x20to\x20'+(g['length']+'\x20candidate\x20Service(s):\x20'+(g['slice'](0x0,0x5)['join'](',\x20')||'(no\x20match\x20in\x20graph)')+'.'),'suggestion':'Candidate\x20suppliers\x20can\x20prepare\x20present\x20evidence\x20(proof\x20of\x20satisfying\x20the\x20demand\x20Guards);\x20the\x20opportunity\x20conclusion\x20is\x20structural\x20only\x20and\x20does\x20not\x20endorse\x20fulfillment\x20capability.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},O2={'id':'O2','kind':'opportunity','run'(a){const b=typedNodes(a,'Service'),c=typedNodes(a,'Demand');if(b['length']===0x0&&c['length']===0x0)return[];const d=b['filter'](f=>bool(root(f)['bPublished'])&&!bool(root(f)['bPaused']))['length'],e=c['filter'](f=>out(a,f['id'],'demand.presenter')['length']===0x0)['length'];return[makeFinding(a,'O2:graph','opportunity','Supply/demand\x20density:\x20in-graph\x20supply\x20and\x20open-demand\x20statistics',{'path':['Service','Demand','demand.presenter'],'pathEdges':edgeList(a,'demand.presenter'),'roles':['neutral','system','supplier','merchant'],'detail':'In\x20the\x20current\x20viewport:\x20'+b['length']+'\x20Service(s)\x20('+d+'\x20published\x20and\x20unpaused),\x20'+c['length']+'\x20Demand(s)\x20'+('('+e+'\x20open\x20demand(s)\x20without\x20proposals).\x20Open-demand/active-supply\x20ratio\x20=\x20')+((d>0x0?(e/d)['toFixed'](0x3):'n/a')+'.'),'suggestion':'A\x20high\x20ratio\x20indicates\x20scarce\x20supply;\x20use\x20category\x20exact-match\x20counts\x20(collectors\x20category_enumerated_count)\x20to\x20pick\x20an\x20entry\x20category.'})];}},O3={'id':'O3','kind':'opportunity','run'(a){const b=[];for(const c of machineViews(a)){const d=new Map();for(const g of c['transitions']){if(str(g['payload']?.['namedOperator'])||g['payload']?.['permissionIndex']!=null)continue;const h=String(g['payload']?.['forward']??g['payload']?.['prevNode']+'→'+g['payload']?.['node']);d['set'](wfNodeName(g['from'])+':'+h,g);}if(d['size']===0x0)continue;const f=[...d['values']()];b['push'](makeFinding(a,'O3:'+c['machine']['id'],'opportunity','Workflow\x20gaps:\x20key\x20Forwards\x20have\x20no\x20operator\x20binding\x20(guard/payment\x20passthrough\x20only)',{'path':[c['machine']['id'],'machine.node','wf.transition'],'pathEdges':f,'roles':['neutral','system','supplier','collaborator','merchant'],'detail':'Machine\x20'+c['machine']['id']+'\x20has\x20'+d['size']+'\x20Forward(s)\x20without\x20namedOperator/permissionIndex\x20binding:\x20'+([...d['keys']()]['slice'](0x0,0x8)['join'](',\x20')+'.\x20These\x20slots\x20can\x20only\x20be\x20satisfied\x20automatically\x20by\x20guards\x20or\x20advanced\x20directly\x20by\x20payment\x20transactions.'),'suggestion':'Suppliers/collaborators\x20can\x20take\x20over\x20these\x20operator\x20slots,\x20or\x20push\x20the\x20merchant\x20to\x20convert\x20implicit\x20passthrough\x20into\x20explicit\x20role\x20bindings.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}};function arbitrationCases(a,b){return inc(a,b,'arb.arbitration_service')['map'](c=>a['graph']['nodes']['get'](c['from']))['filter'](c=>!!c&&c['objectType']==='Arb'&&!!c['raw']);}const G1={'id':'G1','kind':'game','run'(a){const b=[];for(const e of typedNodes(a,'Arbitration')){const f=root(e),g=asList(f['voting_guard']),h=new Set(g['map'](l=>l['vote_weight']&&typeof l['vote_weight']==='object'?Object['keys'](l['vote_weight'])[0x0]:'unknown')),i=arbitrationCases(a,e['id']),j=new Map();let k=0x0;for(const l of i){for(const m of asList(root(l)['voted'])){const n=Number(m['weight']??0x0);j['set'](n,(j['get'](n)??0x0)+0x1),k++;}}b['push'](makeFinding(a,'G1:'+e['id'],'game','Voting\x20power\x20structure:\x20arbitration\x20voting\x20Guard\x20configuration\x20vs\x20actual\x20voting\x20weight\x20distribution',{'severity':'info','path':[e['id'],'arbitration.voting_guard','arb.arbitration_service','arb.voter'],'pathEdges':out(a,e['id'],'arbitration.voting_guard')['concat'](edgeList(a,'arb.voter')),'roles':['neutral','system','arbitrator','merchant','buyer'],'detail':'Arbitration\x20'+e['id']+':\x20voting_guard\x20'+(g['length']===0x0?'empty\x20=\x20open\x20to\x20all\x20members\x20(arbitration.move:48-59)':'weighted\x20('+[...h]['join']('/')+')')+';\x20'+(i['length']+'\x20case(s)\x20in\x20window,\x20'+k+'\x20actual\x20vote(s)')+(j['size']?',\x20weight\x20distribution\x20'+[...j['entries']()]['map'](([o,p])=>'w'+o+'x'+p)['join'](',\x20'):'')+'.','suggestion':'Open\x20voting\x20suits\x20high-frequency\x20low-stakes\x20cases;\x20high-stakes\x20cases\x20should\x20use\x20weighted\x20Guards;\x20this\x20describes\x20the\x20objective\x20situation\x20only\x20—\x20scoring\x20belongs\x20to\x20the\x20game\x20modules.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},G2={'id':'G2','kind':'game','run'(a){const b=[];n:for(const c of machineViews(a)){const d=out(a,c['machine']['id'],'machine.permission')[0x0]?.['to'],f=d?inc(a,d,'permission.entity')['map'](h=>({'eoa':h['to'],'bits':h['payload']?.['permIndices']??[]})):[],g=new Set();for(const h of c['transitions']){const i=String(h['payload']?.['forward']??h['payload']?.['prevNode']+'→'+h['payload']?.['node']),j=wfNodeName(h['from'])+':'+i;if(g['has'](j))continue;let k,l='';if(str(h['payload']?.['namedOperator']))k=0x1,l='namedOperator='+h['payload']['namedOperator'];else{if(h['payload']?.['permissionIndex']!=null){if(!d)continue;const m=Number(h['payload']['permissionIndex']);k=f['filter'](n=>n['bits']['includes'](m))['length'],l='permissionIndex='+m;if(k===0x0)continue;}else continue;}if(k!==0x1)continue;g['add'](j),b['push'](makeFinding(a,'G2:'+c['machine']['id']+':'+j,'game','Operator\x20replaceable\x20pool\x20=\x201:\x20hold-up\x20slot',{'severity':'low','path':[c['machine']['id'],'machine.node','wf.transition',j],'pathEdges':[h],'roles':['neutral','system','collaborator','merchant','supplier'],'detail':'Forward\x20'+j+'\x20('+l+')\x20on\x20Machine\x20'+c['machine']['id']+'\x20has\x20an\x20operable-party\x20pool\x20of\x20size\x201:\x20'+'that\x20party\x20holds\x20an\x20irreplaceable\x20bargaining\x20position\x20at\x20this\x20workflow\x20node\x20(machine.move\x20operation\x20precheck).','suggestion':'Add\x20an\x20alternative\x20entity\x20under\x20the\x20same\x20permissionIndex\x20or\x20a\x20namedOperator\x20backup;\x20sign\x20SLA/penalty\x20terms\x20covering\x20this\x20slot.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break n;}}return b;}},G3={'id':'G3','kind':'game','run'(a){const b=[];for(const c of typedNodes(a,'Arbitration')){const e=root(c),f=asList(e['voting_guard']);b['push'](makeFinding(a,'G3:'+c['id'],'game','Remedy\x20strategy\x20parameters:\x20structured\x20inputs\x20for\x20the\x20payoff/waiting\x20matrices',{'severity':'info','path':[c['id'],'Arbitration.fee/usage_guard/voting_guard'],'roles':['neutral','system','arbitrator','merchant','buyer'],'detail':'Arbitration\x20'+c['id']+':\x20fee='+big(e['fee'])+',\x20usage_guard='+(str(e['usage_guard'])??'none')+',\x20voting_guard='+f['length']+'.\x20'+'Global\x20structural\x20constants:\x20payout\x20cap\x203x\x20amount,\x2030-day\x20compensation\x20withdrawal\x20lock,\x20single\x20claim\x20per\x20payout,\x2030-day\x20withdraw/objection\x20window\x20'+'(arb.move:302-358,\x20order.move:86-96).','suggestion':'Feed\x20these\x20parameters\x20into\x20node-game/arbitration-game\x20payoff\x20and\x20waiting\x20matrices;\x20this\x20analyzer\x20does\x20not\x20score\x20or\x20rank.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},ANTI_CHEAT_ROLES=['neutral','system','merchant','buyer'];function projectOrderEvidence(a,b){const c=[];for(const d of typedNodes(a,'Service')){const f=[...b['controllers']['get'](d['id'])??[]];if(f['length']===0x0)continue;for(const g of out(a,d['id'],'service.order')){const h=a['graph']['nodes']['get'](g['to']);if(!h||h['kind']!=='object'||h['objectType']!=='Order'||!h['raw'])continue;const i=out(a,h['id'],'order.builder')[0x0]?.['to'];if(!i)continue;const j=orderCompletionInGraph(a['graph'],h['id'])['status'],k=String(root(h)?.['amount']??0x0),l=out(a,h['id'],'order.allocation')[0x0]?.['to']??null;for(const m of f){c['push']({'service':d['id'],'id':h['id'],'buyer':i,'seller':m,'amount':k,'status':j,'allocation':l});}}}return c;}function orderCheatEdges(a){return edgeList(a,'service.order')['concat'](edgeList(a,'eoa.permission'))['concat'](edgeList(a,'permission.core_binding'));}function shortRefs(a){const b=a['slice'](0x0,0x5)['join'](',\x20');return a['length']>0x5?b+'\x20and\x20'+a['length']+'\x20object(s)\x20in\x20total':b;}const AC1={'id':'AC1','kind':'risk','run'(a){const b=projectOrderEvidence(a,buildControlIndex(a)),c=detectFakeOrders(b)['find'](e=>e['code']==='self_buy');if(!c)return[];const d=c['refs']??[];return[makeFinding(a,'AC1:'+d['join'](','),'risk','Fake-order\x20suspicion:\x20windowed\x20order\x20buyers\x20are\x20the\x20selling\x20service\x27s\x20controlling\x20EOA\x20(self-trading)',{'severity':'high','path':['EOA','eoa.permission','permission.core_binding','Service','service.order','Order','order.builder'],'pathEdges':orderCheatEdges(a),'roles':ANTI_CHEAT_ROLES,'detail':d['length']+'\x20order(s)\x20visible\x20in\x20the\x20window\x20have\x20buyer\x20EOAs\x20that\x20also\x20control\x20the\x20selling\x20Service\x20as\x20owner/admin\x20'+('('+shortRefs(d)+'):\x20buyer\x20and\x20seller\x20sit\x20in\x20the\x20same\x20control\x20set,\x20funds\x20circulate\x20internally,\x20and\x20this\x20is\x20not\x20genuine\x20competitive\x20volume.'),'suggestion':'Exclude\x20these\x20orders\x20from\x20sales/reputation\x20statistics\x20and\x20re-verify\x20via\x20payment\x20allocation\x20legs\x20and\x20time\x20windows;\x20reduce\x20market\x20exposure\x20and\x20recommendation\x20weight\x20for\x20this\x20Service.'})];}},AC2={'id':'AC2','kind':'risk','run'(a){const b=projectOrderEvidence(a,buildControlIndex(a)),c=detectFakeOrders(b)['find'](e=>e['code']==='reciprocal_loop');if(!c)return[];const d=c['refs']??[];return[makeFinding(a,'AC2:'+d['join'](','),'risk','Wash-trading\x20suspicion:\x20reciprocal\x20buy/sell\x20role-swapping\x20fund\x20loops\x20in\x20the\x20window',{'severity':c['severity'],'path':['EOA-A','order.builder','Order@Service-B','service.order','EOA-B','order.builder','Order@Service-A'],'pathEdges':orderCheatEdges(a),'roles':ANTI_CHEAT_ROLES,'detail':d['length']+'\x20order(s)\x20in\x20the\x20window\x20form\x20a\x20buy/sell\x20swap:\x20control\x20set\x20A\x20buys\x20B\x27s\x20Service\x20while\x20control\x20set\x20B\x20buys\x20A\x27s\x20Service\x20'+('('+shortRefs(d)+').\x20The\x20two-way\x20volume\x20may\x20be\x20mutually\x20staged\x20wash\x20trading.'),'suggestion':'Investigate\x20links\x20between\x20the\x20two\x20control\x20sets\x20(devices/permissions/fund\x20flows);\x20exclude\x20mutually-purchased\x20orders\x20from\x20genuine\x20competitive\x20volume.'})];}},AC3={'id':'AC3','kind':'risk','run'(a){const b=projectOrderEvidence(a,buildControlIndex(a)),c=detectFakeOrders(b)['find'](e=>e['code']==='no_allocation');if(!c)return[];const d=c['refs']??[];return[makeFinding(a,'AC3:'+d['join'](','),'risk','Missing\x20fund\x20closure:\x20completed\x20positive-amount\x20orders\x20lack\x20an\x20Allocation\x20object',{'severity':c['severity'],'path':['Service','service.order','Order','order.allocation'],'pathEdges':orderCheatEdges(a),'roles':ANTI_CHEAT_ROLES,'detail':d['length']+'\x20completed\x20order(s)\x20in\x20the\x20window\x20(completion\x20authoritatively\x20judged\x20by\x20the\x20order-status\x20terminal\x20node\x20set)\x20with\x20amount>0\x20have\x20no\x20Allocation\x20'+('('+shortRefs(d)+').\x20order.move\x20L130\x20requires\x20positive-amount\x20orders\x20to\x20have\x20an\x20allocation\x20path;\x20its\x20absence\x20means\x20the\x20\x22transaction\x22\x20lacks\x20fund-closure\x20evidence.\x20')+'Zero-amount\x20orders\x20are\x20excluded\x20(no\x20fund\x20flow).','suggestion':'Review\x20original\x20payment\x20records;\x20completed\x20orders\x20without\x20payment\x20evidence\x20must\x20not\x20count\x20toward\x20reputation;\x20audit\x20contract\x20entry\x20points\x20that\x20complete\x20without\x20an\x20Allocation\x20path.'})];}},SHELL_COPY={'shell_no_arbitration':{'title':'Shell\x20merchant:\x20published\x20Service\x20has\x20no\x20arbitration\x20binding,\x20disputes\x20have\x20no\x20remedy\x20path','detail':'The\x20Service\x20is\x20published\x20but\x20arbitrations\x20is\x20empty:\x20buyers\x20have\x20no\x20selectable\x20arbitration\x20service\x20after\x20ordering\x20and\x20disputes\x20cannot\x20enter\x20adjudication.','suggestion':'Bind\x20at\x20least\x20one\x20Arbitration\x20in\x20a\x20different\x20group\x20than\x20the\x20shop\x20Permission\x20before\x20publishing;\x20shops\x20without\x20a\x20remedy\x20path\x20should\x20not\x20be\x20recommended.'},'shell_funded_no_arbitration':{'title':'Floating\x20payout\x20funds:\x20compensation\x20fund\x20is\x20funded\x20but\x20no\x20Arbitration\x20exists,\x20payouts\x20cannot\x20be\x20adjudicated\x20or\x20released','detail':'compensation_fund>0\x20with\x20no\x20Arbitration\x20at\x20all:\x20when\x20a\x20payout\x20triggers\x20there\x20is\x20no\x20one\x20to\x20adjudicate\x20and\x20no\x20path\x20to\x20release;\x20the\x20funding\x20is\x20marketing\x20theater.','suggestion':'Bind\x20an\x20arbitration\x20service\x20before\x20advertising\x20payout\x20guarantees;\x20marketplaces\x20should\x20flag\x20\x27fund\x20without\x20arbitration\x27\x20as\x20high\x20risk\x20and\x20limit\x20exposure.'},'shell_no_machine':{'title':'Shell\x20merchant:\x20published\x20Service\x20has\x20no\x20Machine\x20binding,\x20no\x20structured\x20fulfillment\x20workflow','detail':'The\x20Service\x20is\x20published\x20but\x20machine\x20is\x20empty:\x20no\x20frozen\x20workflow\x20template\x20exists,\x20and\x20delivery/completion\x20nodes\x20carry\x20no\x20on-chain\x20structural\x20constraints.','suggestion':'Bind\x20and\x20publish\x20a\x20Machine\x20before\x20opening;\x20published\x20shops\x20without\x20workflows\x20suit\x20only\x20instant\x20spot-delivery\x20categories.'}},AC4={'id':'AC4','kind':'risk','run'(a){const b=[];for(const c of typedNodes(a,'Service')){const e=root(c);if(!bool(e['bPublished']))continue;const f=e['arbitrations']!=null?asList(e['arbitrations'])['length']:out(a,c['id'],'service.arbitration')['length'],g=str(e['machine'])??out(a,c['id'],'service.machine')[0x0]?.['to']??null,h=detectShellMerchant({'object':c['id'],'arbitrations':Array(f)['fill']('x'),'compensation_fund':String(big(e['compensation_fund'])),'machine':g,'bPublished':!![]}),i=out(a,c['id'],'service.arbitration')['concat'](out(a,c['id'],'service.machine'));for(const j of h){const k=SHELL_COPY[j['code']];if(!k)continue;b['push'](makeFinding(a,'AC4:'+c['id']+':'+j['code'],'risk',k['title'],{'severity':j['severity'],'path':[c['id'],'Service.bPublished','Service.arbitrations','Service.machine','Service.compensation_fund'],'pathEdges':i,'roles':ANTI_CHEAT_ROLES,'detail':k['detail']+'\x20(object:\x20'+c['id']+')','suggestion':k['suggestion']}));if(b['length']>=MAX_FINDINGS_PER_RULE)return b;}}return b;}};export const DEFAULT_ANALYZERS=[R1,R2,R3,R4,R5,R6,R7,A1,A2,A3,O1,O2,O3,G1,G2,G3,AC1,AC2,AC3,AC4,PROPOSAL_GAP_ANALYZER];const registry=new Map(DEFAULT_ANALYZERS['map'](b=>[b['id'],b]));export function registerAnalyzer(a){registry['set'](a['id'],a);}export function getAnalyzer(a){return registry['get'](a);}export function listAnalyzers(){return[...registry['keys']()];}export function runAnalyzers(a,b){const c=b?.['only']?new Set(b['only']):undefined,d=[];for(const e of registry['values']()){if(c&&!c['has'](e['id']))continue;if(b?.['kinds']&&!b['kinds']['includes'](e['kind']))continue;try{d['push'](...e['run'](a));}catch{}}return d;}export function adaptNodeAnalyzer(a){return{'id':a['id'],'kind':a['kind'],'objectType':a['objectType'],'run'(b,c){const d=a['inspect'](b,c);return d['map']((e,f)=>({'id':a['id']+':'+b['id']+'#'+f,'kind':a['kind'],'severity':e['severity']??'info','title':e['title'],'path':[b['id']],'confidence':e['confidence']??'exact','roles':e['roles']??['neutral'],'detail':e['detail'],'suggestion':e['suggestion'],...e['ruleId']?{'ruleId':e['ruleId']}:{},...e['evidence']?{'evidence':e['evidence']}:{},...e['nativeRisk']!==undefined?{'nativeRisk':e['nativeRisk']}:{},...b['proposal']&&!e['confidence']?{'confidence':'derived'}:{},...b['proposal']?{'source':b['proposal']['provenance']==='external'?'external':'proposal'}:{}}));}};}export function runNodeAnalyzers(a,b){const c=[];for(const d of b){for(const e of a['visibleNodes']){const f=a['graph']['nodes']['get'](e);if(f?.['kind']!=='object'||d['objectType']!=='*'&&f['objectType']!==d['objectType']||!f['raw'])continue;try{c['push'](...d['run'](f,a));}catch{}}}return c;}
|
|
1
|
+
import{detectFakeOrders,detectShellMerchant}from'./anti-cheat.js';import{orderCompletionInGraph}from'./expand.js';import{PROPOSAL_GAP_ANALYZER}from'./proposal-graph.js';import{graphFindingPolicy}from'./policy.js';import{analyzeRewardClaimGuard}from'../../knowledge/recipient-constraint.js';import{beginPolicyRun,endPolicyRun}from'../../config/judgment.js';function root(a){const b=a?.['raw'],c=b?.['data']??b;return c&&typeof c==='object'?c:undefined;}function str(a){return typeof a==='string'&&a!=='0x0'?a:undefined;}function big(a){if(a==null)return 0x0n;try{return BigInt(typeof a==='number'?Math['trunc'](a):String(a));}catch{return 0x0n;}}function bool(a){return a===!![]||a===0x1||a==='1';}function asList(a){return Array['isArray'](a)?a:[];}function wfNodeName(a){const b=a['indexOf']('::node::');return b>=0x0?a['slice'](b+'::node::'['length']):a;}function wfMachineOf(a){const b=a['indexOf']('::node::');return b>=0x0?a['slice'](0x0,b):'';}export function findingWhere(a){const b=a['id'];if(b['startsWith']('R4:')){const c=b['slice'](0x3),d=c['indexOf'](':'),e=d>=0x0?c['slice'](0x0,d):c,g=d>=0x0?c['slice'](d+0x1):'';return e+':\x20'+g['split']('→')['map'](h=>wfNodeName(h['trim']()))['join']('\x20→\x20');}if(b['startsWith']('R7:treasury:'))return'Treasury\x20'+b['slice']('R7:treasury:'['length']);if(b['startsWith']('R7:reward:'))return'Reward\x20'+b['slice']('R7:reward:'['length']);if(b['startsWith']('R2:'))return b['slice'](0x3);if(b['startsWith']('R5:')){const [h,i]=b['slice'](0x3)['split']('|');return wfNodeName(h??'')+'\x20('+(i??'window')+')';}return a['title']??a['id'];}export function findingWhereResolved(a,b){const c=a['id'];if(c['startsWith']('R4:')){const d=c['slice'](0x3),e=d['indexOf'](':'),g=e>=0x0?d['slice'](0x0,e):d,h=e>=0x0?d['slice'](e+0x1):'',i=b['resolve'](g)['label'],j=l=>b['resolveWf'](l)?.['node']['label']??b['resolve'](l)['label'],k=h['split']('→')['map'](l=>j(l['trim']()))['join']('\x20→\x20');return i+':\x20'+k;}if(c['startsWith']('R7:treasury:'))return'Treasury\x20'+b['resolve'](c['slice']('R7:treasury:'['length']))['label'];if(c['startsWith']('R7:reward:'))return'Reward\x20'+b['resolve'](c['slice']('R7:reward:'['length']))['label'];if(c['startsWith']('R2:'))return b['resolve'](c['slice'](0x3))['label'];if(c['startsWith']('R5:')){const [l,m]=c['slice'](0x3)['split']('|');return b['resolve'](l??'')['label']+'\x20('+(m??'window')+')';}return a['title']??a['id'];}function typedNodes(a,b){const c=[];for(const d of a['visibleNodes']){const e=a['graph']['nodes']['get'](d);if(e?.['kind']==='object'&&e['objectType']===b&&e['raw']&&!e['proposal'])c['push'](e);}return c;}function edgeList(a,b){return a['visibleEdges']['filter'](c=>c['schema']===b);}function out(a,b,c){return a['visibleEdges']['filter'](d=>d['from']===b['toLowerCase']()&&d['schema']===c);}function inc(a,b,c){return a['visibleEdges']['filter'](d=>d['to']===b['toLowerCase']()&&d['schema']===c);}export const RETENTION_RANK={'complete':0x0,'event_full':0x0,'bounded_exact':0x1,'membership':0x1,'derived':0x2,'bounded_window':0x3,'event_degraded':0x3};const WINDOW_LIMIT=0x1450;export function pathConfidence(a,b){let c=0x0,d=![];for(const g of b){c=Math['max'](c,RETENTION_RANK[g['retention']]??0x0);if(g['retention']==='bounded_window'||g['retention']==='event_degraded'||g['truncated'])d=!![];}if(d){let h=0x0;for(const i of b){if(i['retention']!=='bounded_window'&&!i['truncated'])continue;const j=a['visibleEdges']['filter'](l=>l['schema']===i['schema']&&l['from']===i['from'])['length'];h=Math['max'](h,j);const k=a['graph']['truncations']['find'](l=>l['nodeId']===i['from']&&l['schema']===i['schema']);if(k)h=Math['max'](h,k['observed']);}return{'confidence':'windowed','window':{'observed':h||b['length'],'limit':WINDOW_LIMIT}};}const f=c===0x0?'exact':c===0x2?'derived':'bounded';return{'confidence':f};}function makeFinding(a,b,c,d,e){const {confidence:f,window:g}=pathConfidence(a,e['pathEdges']??[]),h=e['severity']??'info';return{'id':b,'kind':c,'severity':h,'title':d,'path':e['path'],'confidence':f,...g?{'window':g}:{},'roles':e['roles']??['neutral'],'detail':e['detail'],'suggestion':e['suggestion'],...e['amounts']?.['length']?{'amounts':e['amounts']}:{},...e['exposure']?{'exposure':e['exposure']}:{}};}const MAX_FINDINGS_PER_RULE=0x14,ROLE_OWNER_OR_ADMIN=0x1|0x2;export function buildControlIndex(a){const b=new Map(),c=new Map(),d=new Map(),f=(h,i,j)=>{const l=h['get'](i)??new Set();l['add'](j),h['set'](i,l);},g=new Map();for(const h of edgeList(a,'eoa.permission')){const i=typeof h['payload']?.['roleBits']==='number'?h['payload']['roleBits']:ROLE_OWNER_OR_ADMIN;if((i&ROLE_OWNER_OR_ADMIN)===0x0)continue;f(g,h['from'],h['to']);}for(const j of edgeList(a,'permission.core_binding')){const k=a['graph']['nodes']['get'](j['to']);if(!k||k['kind']!=='object')continue;f(d,j['to'],j['from']);for(const [l,m]of g){if(!m['has'](j['from']))continue;f(b,j['to'],l),f(c,l,j['to']);}}return{'controllers':b,'objectsByEoa':c,'permsOfObject':d};}function machineViews(a){const b=new Map();for(const d of edgeList(a,'wf.transition')){const f=wfMachineOf(d['from']);if(!f)continue;const g=b['get'](f)??[];g['push'](d),b['set'](f,g);}const c=[];for(const [h,i]of b){const j=a['graph']['nodes']['get'](h);if(!j||!a['visibleNodes']['has'](h))continue;const k=new Set([...(function*(){const l=new Set(i['map'](p=>String(p['payload']?.['node']??''))['filter'](Boolean)),o=new Set(i['map'](p=>String(p['payload']?.['prevNode']??''))['filter'](Boolean));for(const p of l)if(!o['has'](p))yield p;}())]);c['push']({'machine':j,'transitions':i,'terminals':k});}return c;}const ROLES_RISK_NEUTRAL_MERCHANT=['neutral','system','merchant'],R1={'id':'R1','kind':'risk','run'(b){const c=buildControlIndex(b),d=[],e=typedNodes(b,'Service'),f=typedNodes(b,'Arbitration');p:for(const g of e){const h=c['controllers']['get'](g['id']);if(!h)continue;for(const i of f){const j=c['controllers']['get'](i['id']);if(!j)continue;const k=c['permsOfObject']['get'](g['id']),l=c['permsOfObject']['get'](i['id']),m=[...k??[]]['some'](n=>l?.['has'](n));if(m)continue;for(const n of h){if(!j['has'](n))continue;const o=graphFindingPolicy('R1',{'eoa':n});if(!o['enabled'])continue;d['push'](makeFinding(b,'R1:'+g['id']+':'+i['id']+':'+n,'risk','Same-controller\x20arbitration\x20risk:\x20the\x20service\x20and\x20the\x20arbitration\x20service\x20are\x20controlled\x20by\x20the\x20same\x20EOA',{'severity':o['severity']??'high','path':[n,'eoa.permission','permission.core_binding',g['id'],i['id']],'pathEdges':edgeList(b,'permission.core_binding'),'roles':['neutral','system','merchant','arbitrator'],'detail':'EOA\x20'+n+'\x20controls\x20both\x20Service\x20'+g['id']+'\x20and\x20Arbitration\x20'+i['id']+'\x20as\x20owner/admin,\x20'+'and\x20the\x20two\x20are\x20attached\x20to\x20DIFFERENT\x20Permissions\x20(E33\x20only\x20forbids\x20the\x20same\x20Permission,\x20not\x20cross-group\x20arbitration).\x20'+'structurally\x20this\x20EOA\x20can\x20influence\x20both\x20the\x20arbitrated\x20service\x20and\x20the\x20ruling\x20outcome.','suggestion':'Verify\x20the\x20EOA\x27s\x20control\x20relationships;\x20require\x20disjoint\x20owner/admin\x20sets\x20between\x20the\x20service\x20and\x20the\x20arbitration\x20service,\x20or\x20remove\x20that\x20arbitration\x20service\x20from\x20the\x20selectable\x20list.',...o['exposure']?{'exposure':o['exposure']}:{}}));if(d['length']>=MAX_FINDINGS_PER_RULE)break p;}}}return d;}},R2={'id':'R2','kind':'risk','run'(a){const b=[];for(const c of typedNodes(a,'Service')){const f=root(c),g=out(a,c['id'],'service.order');if(g['length']===0x0)continue;let h=0x0n,i=0x0;for(const o of g){const p=root(a['graph']['nodes']['get'](o['to']));if(!p)continue;h+=big(p['amount']),i++;}if(i===0x0)continue;const j=big(f['compensation_fund']),k=h*0x3n;if(j>=k)continue;const l=c['coinType']?{'coin_type':c['coinType']}:{},m=j<h?'high':'medium',n=graphFindingPolicy('R2',{'r2_level':m});if(!n['enabled'])continue;b['push'](makeFinding(a,'R2:'+c['id'],'risk','Payout\x20exposure:\x20compensation\x20fund\x20is\x20below\x20the\x203x\x20ceiling\x20of\x20windowed\x20order\x20amounts',{'severity':n['severity']??m,'path':[c['id'],'service.order','Order.amount','Service.compensation_fund'],'pathEdges':g,'roles':['neutral','system','merchant','buyer'],'detail':'Compensation\x20fund\x20{fund};\x20'+i+'\x20windowed\x20orders\x20total\x20{amount};\x20'+'the\x20per-order\x20statutory\x20payout\x20cap\x20of\x203x\x20amount\x20gives\x20a\x20structural\x20total\x20exposure\x20of\x20{needed}.','suggestion':'Top\x20up\x20compensation_fund\x20to\x20more\x20than\x203x\x20the\x20windowed\x20amount,\x20or\x20reduce\x20open\x20order\x20volume\x20within\x20the\x20window.','amounts':[{'key':'fund','label':'Compensation\x20fund','raw':j['toString'](),...l},{'key':'amount','label':'Windowed\x20order\x20total','raw':h['toString'](),...l},{'key':'needed','label':'Structural\x20exposure\x20ceiling\x20(3x)','raw':k['toString'](),...l}],...n['exposure']?{'exposure':n['exposure']}:{}}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},CONTROL_TYPES=new Set(['Service','Machine','Treasury']),CONTROL_FANOUT_ALERT=0x3,R3={'id':'R3','kind':'risk','run'(a){const b=buildControlIndex(a),c=[];for(const [d,e]of b['objectsByEoa']){const f=[...e]['filter'](k=>CONTROL_TYPES['has'](a['graph']['nodes']['get'](k)?.['objectType']??''));if(f['length']<CONTROL_FANOUT_ALERT)continue;const g=f['filter'](k=>a['graph']['nodes']['get'](k)?.['objectType']==='Service'),h=g['reduce']((k,l)=>k+out(a,l,'service.order')['length'],0x0),i=f['length']>=0x5?'medium':'low',j=graphFindingPolicy('R3',{'r3_level':i});if(!j['enabled'])continue;c['push'](makeFinding(a,'R3:'+d,'risk','Permission\x20concentration:\x20a\x20single\x20EOA\x20controls\x20multiple\x20business-critical\x20objects',{'severity':j['severity']??i,'path':[d,'eoa.permission','permission.core_binding'],'pathEdges':edgeList(a,'eoa.permission')['concat'](edgeList(a,'permission.core_binding')),'roles':ROLES_RISK_NEUTRAL_MERCHANT,'detail':'EOA\x20'+d+'\x20controls\x20'+f['length']+'\x20Service/Machine/Treasury\x20objects\x20via\x20owner/admin\x20permissions\x20'+('('+g['length']+'\x20of\x20them\x20Services,\x20'+h+'\x20orders\x20visible\x20in\x20the\x20window);\x20business\x20scale\x20does\x20not\x20match\x20permission\x20dispersion.\x20')+('Controlled\x20objects:\x20'+f['slice'](0x0,0xa)['join'](',\x20')+(f['length']>0xa?',\x20and\x20'+(f['length']-0xa)+'\x20more':'')+'.'),'suggestion':'Delegate\x20day-to-day\x20operations\x20to\x20dedicated\x20admin/entity\x20roles\x20and\x20keep\x20owner\x20for\x20emergencies\x20only;\x20avoid\x20attaching\x20core\x20objects\x20to\x20the\x20same\x20permission\x20group.',...j['exposure']?{'exposure':j['exposure']}:{}}));if(c['length']>=MAX_FINDINGS_PER_RULE)break;}return c;}},R4={'id':'R4','kind':'risk','run'(a){const b=[];q:for(const c of machineViews(a)){const d=new Map();for(const g of c['transitions']){if(!c['terminals']['has'](String(g['payload']?.['node']??'')))continue;const h=g['from']+'→'+g['to'],i=d['get'](h)??[];i['push'](g),d['set'](h,i);}for(const [j,k]of d){const l=new Set();let m=![];for(const n of k){if(str(n['payload']?.['namedOperator']))l['add']('name:'+n['payload']['namedOperator']);if(typeof n['payload']?.['permissionIndex']==='number')l['add']('perm:'+n['payload']['permissionIndex']);if(str(n['payload']?.['guard']))m=!![];}if(l['size']===0x1&&!m){const o=[...l][0x0],p=graphFindingPolicy('R4',{'only':o});if(!p['enabled'])continue;b['push'](makeFinding(a,'R4:'+c['machine']['id']+':'+j,'risk','Workflow\x20single\x20point:\x20the\x20only\x20Forward\x20before\x20a\x20terminal\x20state\x20has\x20a\x20single\x20operator\x20and\x20no\x20fallback\x20Guard',{'severity':p['severity']??'medium','path':[c['machine']['id'],'machine.node','wf.transition',j],'pathEdges':k,'roles':['neutral','system','merchant','collaborator'],'detail':'On\x20Machine\x20'+c['machine']['id']+',\x20path\x20'+j+'\x20toward\x20terminal\x20state\x20'+wfNodeName(k[0x0]['to'])+':\x20'+('the\x20only\x20operable\x20party\x20is\x20'+o+'\x20and\x20no\x20Forward\x20has\x20a\x20guard\x20fallback;\x20if\x20that\x20party\x20goes\x20offline\x20the\x20workflow\x20stalls.'),'suggestion':'Add\x20a\x20permissionIndex\x20alternative\x20or\x20attach\x20a\x20guard\x20auto-advance\x20condition\x20to\x20this\x20Forward\x20so\x20one\x20party\x20cannot\x20block\x20the\x20terminal\x20state.',...p['exposure']?{'exposure':p['exposure']}:{}}));if(b['length']>=MAX_FINDINGS_PER_RULE)break q;}}}return b;}},R5={'id':'R5','kind':'risk','run'(a){const b=[],c=new Set();for(const d of a['graph']['truncations']){if(!a['visibleNodes']['has'](d['nodeId']))continue;const e=d['nodeId']+'|'+d['schema'];if(c['has'](e))continue;c['add'](e),b['push']({'id':'R5:'+e,'kind':'risk','severity':'info','title':'Window\x20truncation:\x20affected\x20conclusions\x20are\x20lower\x20bounds\x20within\x20the\x20<=5200\x20FIFO/ring\x20window\x20only','path':[d['nodeId'],d['schema']],'confidence':'windowed','window':{'observed':d['observed'],'limit':d['limit']??WINDOW_LIMIT},'roles':['neutral','system','merchant','buyer','supplier','arbitrator','collaborator'],'detail':'Fanout\x20of\x20'+d['schema']+'\x20at\x20node\x20'+d['nodeId']+'\x20is\x20truncated\x20(observed\x20'+d['observed']+',\x20window\x20limit\x20'+(d['limit']??WINDOW_LIMIT)+');\x20'+'any\x20conclusion\x20relying\x20on\x20this\x20path\x20must\x20be\x20worded\x20as\x20\x22within\x20the\x20window\x20/\x20at\x20least\x22,\x20never\x20as\x20exhaustive\x20truth.','suggestion':'For\x20exhaustive\x20conclusions\x20switch\x20to\x20the\x20event\x20channel\x20(channel\x20D)\x20or\x20raise\x20perKindCaps\x20within\x20budget.'});if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},R6={'id':'R6','kind':'risk','run'(a){const b=[];for(const c of typedNodes(a,'Service')){const e=root(c);if(!bool(e['bPublished']))continue;if(big(e['setting_lock_duration'])!==0x0n)continue;const f=graphFindingPolicy('R6',{});if(!f['enabled'])continue;b['push'](makeFinding(a,'R6:'+c['id'],'risk','Missing\x20setting\x20lock:\x20published\x20Service\x20has\x20setting_lock_duration=0',{'severity':f['severity']??'medium','path':[c['id'],'Service.setting_lock_duration'],'roles':ROLES_RISK_NEUTRAL_MERCHANT['concat']('buyer'),'detail':'Service\x20'+c['id']+'\x20is\x20published\x20but\x20setting_lock_duration=0:\x20order_allocators\x20/\x20rewards\x20/\x20arbitrations\x20/\x20machine\x20'+'and\x20compensation_fund\x20withdrawals\x20can\x20be\x20changed\x20instantly\x20(default\x20lock\x20is\x2030\x20days);\x20buyers\x20face\x20instantly\x20mutable\x20terms.','suggestion':'Set\x20setting_lock_duration\x20after\x20publishing\x20(30\x20days\x20=\x202592000000\x20ms\x20at\x20minimum);\x20term\x20changes\x20must\x20go\x20through\x20a\x20waiting\x20period.',...f['exposure']?{'exposure':f['exposure']}:{}}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},OBJECT_USER_ROLES=['neutral','system','buyer','supplier'],R7={'id':'R7','kind':'risk','run'(a){const b=[];for(const c of typedNodes(a,'Treasury')){const d=asList(root(c)?.['external_withdraw_guard']);if(d['length']===0x0)continue;const e=graphFindingPolicy('R7-treasury',{});if(!e['enabled'])continue;b['push'](makeFinding(a,'R7:treasury:'+c['id'],'risk','Object-user\x20CRITICAL:\x20Treasury\x20has\x20a\x20permission-free\x20external\x20release\x20path',{'severity':e['severity']??'critical','path':[c['id'],'Treasury.external_withdraw_guard'],'roles':OBJECT_USER_ROLES,'detail':'Treasury\x20'+c['id']+'\x20has\x20'+d['length']+'\x20external_withdraw_guard\x20entry/entries:\x20external_withdraw\x20needs\x20no\x20Treasury\x20'+'Permission\x20—\x20only\x20the\x20Guard\x27s\x20boolean\x20verdict\x20stands\x20between\x20an\x20external\x20caller\x20and\x20the\x20balance.\x20The\x20topology\x20performs\x20'+'no\x20Guard-bytecode\x20analysis,\x20so\x20the\x20Guard\x27s\x20strength\x20is\x20UNVERIFIABLE\x20here.\x20Move\x20truth\x20(protocol\x20140):\x20the\x20destination\x20is\x20'+'forced\x20to\x20the\x20transaction\x20sender\x20(abort\x20code\x2010\x20on\x20mismatch),\x20which\x20blocks\x20third-party\x20redirection\x20but\x20NOT\x20release\x20to\x20a\x20'+'caller\x20whose\x20transaction\x20satisfies\x20a\x20weak\x20Guard\x20(for\x20example,\x20a\x20constant-true\x20root\x20with\x20a\x20static\x20amount\x20slot).','suggestion':'Do\x20not\x20rely\x20on\x20or\x20transact\x20through\x20this\x20Treasury\x20until\x20the\x20owner\x20presents\x20the\x20full\x20Guard\x20definitions;\x20verify\x20the\x20predicate\x20'+'constrains\x20the\x20amount\x20slot;\x20require\x20a\x20testnet\x20regression\x20(recipient\x20!=\x20sender\x20must\x20abort\x20with\x20code\x2010).',...e['exposure']?{'exposure':e['exposure']}:{}}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}for(const f of typedNodes(a,'Reward')){const g=asList(root(f)?.['guards']);if(g['length']===0x0)continue;const h=g['map']((n,o)=>{const p=typeof n['guard']==='string'?n['guard']:'',q=p?a['graph']['nodes']['get'](p):undefined,s=q?.['raw']??undefined;return analyzeRewardClaimGuard({'entry_index':o,'guard':p,'recipient':n['recipient'],'guard_def':s?{...Array['isArray'](s['table'])?{'table':s['table']}:{},'root':s['root']}:undefined});}),i=h['some'](n=>n['viability']==='viable'),j=h['every'](n=>n['viability']==='blocked'),k=h['filter'](n=>n['viability']==='blocked')['length']+'\x20blocked,\x20'+(h['filter'](n=>n['viability']==='viable')['length']+'\x20viable,\x20')+(h['filter'](n=>n['viability']==='conditional')['length']+'\x20conditional,\x20')+(h['filter'](n=>n['viability']==='unverifiable')['length']+'\x20unverifiable'),l=h['map'](n=>'#'+n['entry_index']+'\x20'+n['viability']+'\x20—\x20'+n['reason'])['join']('\x20|\x20'),m=graphFindingPolicy('R7-reward',{'r7_slot_viability':i?'viable':j?'blocked':'unverifiable','r7_slot_audit':l});if(!m['enabled'])continue;b['push'](makeFinding(a,'R7:reward:'+f['id'],'risk',j?'Reward\x20claim\x20path\x20is\x20permission-free\x20but\x20every\x20payout\x20slot\x20is\x20provably\x20bound\x20(downgraded\x20hint)':'Object-user\x20CRITICAL:\x20Reward\x20has\x20a\x20permission-free\x20claim\x20path\x20with\x20an\x20unverifiable\x20payout\x20slot',{'severity':m['severity']??(j?'info':'critical'),'path':[f['id'],'Reward.guards'],'roles':OBJECT_USER_ROLES,'detail':'Reward\x20'+f['id']+'\x20has\x20'+g['length']+'\x20claim\x20guard\x20entry/entries:\x20claim()\x20needs\x20no\x20Permission,\x20and\x20with\x20a\x20'+'Recipient::GuardIdentifier\x20entry\x20the\x20payout\x20address\x20is\x20read\x20from\x20the\x20claim-time\x20passport\x20submission.\x20'+('Canonical\x20slot\x20audit\x20('+k+').\x20A\x20guard\x20that\x20passes\x20without\x20constraining\x20the\x20recipient\x20slot\x20lets\x20any\x20passing\x20')+'party\x20fill\x20the\x20slot\x20with\x20their\x20own\x20address\x20and\x20claim\x20the\x20pool.','suggestion':j?'Payout\x20slots\x20are\x20constraint-bound\x20per\x20the\x20guard\x20audit;\x20treat\x20this\x20as\x20an\x20informational\x20structure\x20note.':'Do\x20not\x20treat\x20the\x20reward\x20pool\x20as\x20sound\x20until\x20the\x20owner\x20presents\x20the\x20Guard\x20definitions;\x20verify\x20the\x20predicate\x20binds\x20the\x20'+'recipient\x20slot\x20(Signer/entity),\x20or\x20confirm\x20the\x20entries\x20use\x20Entity/Signer\x20recipients\x20that\x20do\x20not\x20depend\x20on\x20submitted\x20slots.',...m['exposure']?{'exposure':m['exposure']}:{}}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},RATE_BASIS=0x2710n;function allocationStructuralIssues(a){const b=[];let c=0x0,d=![];for(const e of asList(a)){const f=e??{};let g=0x0n,h=![];for(const i of asList(f['sharing'])){const j=i??{},k=Number(j['mode']);if(k===0x2||j['mode']==='Surplus'){c++,d=!![];continue;}k===0x1||j['mode']==='Rate'?g+=big(j['sharing']):h=!![];}g!==0x0n&&g!==RATE_BASIS&&!d&&b['push']('Rate\x20allocation\x20totals\x20'+g+'\x20!=\x2010000\x20basis\x20points\x20with\x20no\x20Surplus\x20fallback;\x20payment\x20will\x20abort'),h&&(f['max']==null||big(f['max'])===0x0n)&&b['push']('Fixed-amount\x20(Amount)\x20allocation\x20Allocator\x20lacks\x20a\x20max\x20cap;\x20excess\x20transfer\x20is\x20possible\x20when\x20the\x20guard\x20triggers');}if(c>0x1)b['push'](c+'\x20Surplus\x20entries\x20(at\x20most\x201\x20is\x20legal);\x20surplus\x20ownership\x20is\x20ambiguous');return[...new Set(b)];}const A1={'id':'A1','kind':'arbitrage','run'(a){const b=[],c=(e,f,g,h)=>{const i=allocationStructuralIssues(f);if(i['length']===0x0||h['has'](e))return;h['add'](e);const j=graphFindingPolicy('A1',{});if(!j['enabled'])return;b['push'](makeFinding(a,'A1:'+e,'arbitrage','Allocation\x20structure\x20mismatch:\x20Rate/Surplus/max\x20configuration\x20has\x20triggerable\x20structural\x20defects',{'severity':j['severity']??'medium','path':[e,'allocators[].sharing'],'pathEdges':g,'roles':['neutral','system','merchant','buyer'],'detail':e+':\x20'+i['join'](';\x20')+'.','suggestion':'Complete\x20Rate\x20groups\x20to\x2010000\x20or\x20configure\x20a\x20single\x20Surplus;\x20fixed-amount\x20Allocators\x20must\x20set\x20max;\x20run\x20the\x20allocation\x20precheck\x20before\x20going\x20live.',...j['exposure']?{'exposure':j['exposure']}:{}}));},d=new Set();for(const e of typedNodes(a,'Allocation')){c(e['id'],root(e)['allocators'],inc(a,e['id'],'order.allocation'),d);}for(const f of typedNodes(a,'Service')){const g=root(f)['order_allocators'];if(g?.['allocators'])c(f['id'],g['allocators'],edgeList(a,'service.order_allocator_guard'),d);}return b['slice'](0x0,MAX_FINDINGS_PER_RULE);}},DISCOUNT_FIXED=0x1,THIRTY_DAYS_MS=0x1en*0x18n*0x3cn*0x3cn*0x3e8n,A2={'id':'A2','kind':'arbitrage','run'(a){const b=[];for(const c of typedNodes(a,'Discount')){const e=root(c),f=big(e['time_end'])-big(e['time_start'])>=THIRTY_DAYS_MS;if(!bool(e['transferable'])||!f)continue;if(Number(e['discount_type'])!==DISCOUNT_FIXED)continue;if(e['benchmark']!=null&&e['benchmark']!=='0')continue;const g=graphFindingPolicy('A2',{});if(!g['enabled'])continue;b['push'](makeFinding(a,'A2:'+c['id'],'arbitrage','Discount\x20combination:\x20transferable\x20+\x20long\x20validity\x20window\x20+\x20fixed-amount\x20discount\x20without\x20benchmark',{'severity':g['severity']??'low','path':[c['id'],'Discount.transferable/time_window/benchmark'],'roles':['neutral','system','merchant'],'detail':'Discount\x20'+c['id']+'\x20is\x20transferable,\x20valid\x20>=30\x20days,\x20is\x20a\x20fixed-amount\x20discount,\x20and\x20has\x20no\x20benchmark\x20price\x20check;\x20'+'this\x20leaves\x20room\x20for\x20coupon\x20hoarding\x20and\x20resale\x20arbitrage.','suggestion':'Shorten\x20the\x20validity\x20window,\x20switch\x20to\x20RATES\x20proportional\x20discounts,\x20or\x20add\x20benchmark\x20Guards;\x20disable\x20transferable\x20if\x20needed.',...g['exposure']?{'exposure':g['exposure']}:{}}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},A3={'id':'A3','kind':'arbitrage','run'(a){const b=[];for(const e of typedNodes(a,'Arbitration')){const f=root(e),g=big(f['fee'])===0x0n&&!str(f['usage_guard']);if(g){const h=graphFindingPolicy('A3',{});h['enabled']&&b['push'](makeFinding(a,'A3:'+e['id'],'arbitrage','Remedy\x20cost\x20structure:\x20zero\x20fee\x20+\x20no\x20usage\x20gate\x20gives\x20malicious\x20disputes\x20a\x20positive-expected-value\x20setup',{'severity':h['severity']??'medium','path':[e['id'],'Arbitration.fee','Arbitration.usage_guard'],'roles':['neutral','system','arbitrator','merchant','buyer'],'detail':'Arbitration\x20'+e['id']+'\x20has\x20fee=0\x20and\x20an\x20empty\x20usage_guard;\x20combined\x20with\x20the\x203x\x20amount\x20payout\x20cap,\x20single\x20claim,\x20'+'and\x2030-day\x20withdrawal\x20lock\x20rules,\x20filing\x20a\x20malicious\x20dispute\x20carries\x20no\x20structural\x20upfront\x20cost.','suggestion':'Set\x20a\x20non-zero\x20fee\x20to\x20cover\x20adjudication\x20cost,\x20or\x20use\x20usage_guard\x20to\x20require\x20disputing\x20parties\x20to\x20hold\x20on-chain\x20participation\x20credentials.',...h['exposure']?{'exposure':h['exposure']}:{}}));}if(b['length']>=MAX_FINDINGS_PER_RULE)break;}const c=new Map();for(const i of a['visibleNodes']){const j=a['graph']['nodes']['get'](i),k=j?.['raw']?.['type_raw'];if(typeof k!=='string'||!k['includes']('::payment::CoinWrapper<'))continue;const l=k['slice'](k['indexOf']('<')+0x1,k['lastIndexOf']('>'))['trim'](),m=c['get'](l)??[];m['push'](i),c['set'](l,m);}if(c['size']>0x0){const o=[...c['keys']()]['sort']();b['push']({'id':'A3:coinwrapper','kind':'arbitrage','severity':'info','title':'Cross-coin\x20escrow\x20review\x20point:\x20CoinWrapper<K>\x20escrow\x20objects\x20exist\x20in\x20the\x20graph','path':['payment::CoinWrapper'],'confidence':'exact','roles':['neutral','system','arbitrator','merchant'],'detail':'Visible\x20CoinWrapper\x20escrow\x20covers\x20coin\x20types:\x20'+o['join'](',\x20')+'\x20('+[...c['values']()]['reduce']((p,q)=>p+q['length'],0x0)+'\x20objects).\x20'+'v1\x20performs\x20no\x20market\x20valuation;\x20remedy/allocation\x20conclusions\x20across\x20coins\x20require\x20manual\x20review\x20of\x20coin\x20mismatch\x20and\x20depeg\x20risk.','suggestion':'Verify\x20the\x20escrow\x20coin\x20type\x20matches\x20the\x20service\x20coin\x20type\x20T;\x20add\x20independent\x20exchange-rate/oracle\x20evidence\x20before\x20concluding\x20cross-coin\x20cases.'});}return b['slice'](0x0,MAX_FINDINGS_PER_RULE);}},SCARCE_PRESENTERS=0x2;function demandGuardIds(a,b){const c=new Set();for(const d of out(a,b,'demand.guard'))c['add'](d['to']);return c;}function serviceGuardIds(a,b){const c=new Set();for(const f of out(a,b['id'],'service.buy_guard'))c['add'](f['to']);const d=out(a,b['id'],'service.machine')[0x0]?.['to'];if(d)for(const g of a['visibleEdges']){if(g['schema']==='wf.forward_guard'&&g['from']['startsWith'](d+'::node::'))c['add'](g['to']);}return c;}const O1={'id':'O1','kind':'opportunity','run'(a){const b=[],c=typedNodes(a,'Service');for(const d of typedNodes(a,'Demand')){const e=out(a,d['id'],'demand.presenter');if(e['length']>=SCARCE_PRESENTERS)continue;const f=demandGuardIds(a,d['id']),g=[];for(const i of c){const j=serviceGuardIds(a,i);if(f['size']===0x0||[...f]['every'](k=>j['has'](k)))g['push'](i['id']);}const h=e;b['push'](makeFinding(a,'O1:'+d['id'],'opportunity','Open\x20demand:\x20few\x20proposals,\x20with\x20structurally\x20capable\x20suppliers\x20present',{'severity':'info','path':[d['id'],'demand.presenter','demand.guard','Service'],'pathEdges':h['concat'](out(a,d['id'],'demand.guard')),'roles':['neutral','system','supplier'],'detail':'Demand\x20'+d['id']+'\x20currently\x20has\x20only\x20'+e['length']+'\x20proposal(s);\x20matched\x20by\x20Guard\x20structure\x20(no\x20Guard\x20bytecode\x20parsing)\x20to\x20'+(g['length']+'\x20candidate\x20Service(s):\x20'+(g['slice'](0x0,0x5)['join'](',\x20')||'(no\x20match\x20in\x20graph)')+'.'),'suggestion':'Candidate\x20suppliers\x20can\x20prepare\x20present\x20evidence\x20(proof\x20of\x20satisfying\x20the\x20demand\x20Guards);\x20the\x20opportunity\x20conclusion\x20is\x20structural\x20only\x20and\x20does\x20not\x20endorse\x20fulfillment\x20capability.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},O2={'id':'O2','kind':'opportunity','run'(a){const b=typedNodes(a,'Service'),c=typedNodes(a,'Demand');if(b['length']===0x0&&c['length']===0x0)return[];const d=b['filter'](f=>bool(root(f)['bPublished'])&&!bool(root(f)['bPaused']))['length'],e=c['filter'](f=>out(a,f['id'],'demand.presenter')['length']===0x0)['length'];return[makeFinding(a,'O2:graph','opportunity','Supply/demand\x20density:\x20in-graph\x20supply\x20and\x20open-demand\x20statistics',{'path':['Service','Demand','demand.presenter'],'pathEdges':edgeList(a,'demand.presenter'),'roles':['neutral','system','supplier','merchant'],'detail':'In\x20the\x20current\x20viewport:\x20'+b['length']+'\x20Service(s)\x20('+d+'\x20published\x20and\x20unpaused),\x20'+c['length']+'\x20Demand(s)\x20'+('('+e+'\x20open\x20demand(s)\x20without\x20proposals).\x20Open-demand/active-supply\x20ratio\x20=\x20')+((d>0x0?(e/d)['toFixed'](0x3):'n/a')+'.'),'suggestion':'A\x20high\x20ratio\x20indicates\x20scarce\x20supply;\x20use\x20category\x20exact-match\x20counts\x20(collectors\x20category_enumerated_count)\x20to\x20pick\x20an\x20entry\x20category.'})];}},O3={'id':'O3','kind':'opportunity','run'(a){const b=[];for(const c of machineViews(a)){const d=new Map();for(const g of c['transitions']){if(str(g['payload']?.['namedOperator'])||g['payload']?.['permissionIndex']!=null)continue;const h=String(g['payload']?.['forward']??g['payload']?.['prevNode']+'→'+g['payload']?.['node']);d['set'](wfNodeName(g['from'])+':'+h,g);}if(d['size']===0x0)continue;const f=[...d['values']()];b['push'](makeFinding(a,'O3:'+c['machine']['id'],'opportunity','Workflow\x20gaps:\x20key\x20Forwards\x20have\x20no\x20operator\x20binding\x20(guard/payment\x20passthrough\x20only)',{'path':[c['machine']['id'],'machine.node','wf.transition'],'pathEdges':f,'roles':['neutral','system','supplier','collaborator','merchant'],'detail':'Machine\x20'+c['machine']['id']+'\x20has\x20'+d['size']+'\x20Forward(s)\x20without\x20namedOperator/permissionIndex\x20binding:\x20'+([...d['keys']()]['slice'](0x0,0x8)['join'](',\x20')+'.\x20These\x20slots\x20can\x20only\x20be\x20satisfied\x20automatically\x20by\x20guards\x20or\x20advanced\x20directly\x20by\x20payment\x20transactions.'),'suggestion':'Suppliers/collaborators\x20can\x20take\x20over\x20these\x20operator\x20slots,\x20or\x20push\x20the\x20merchant\x20to\x20convert\x20implicit\x20passthrough\x20into\x20explicit\x20role\x20bindings.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}};function arbitrationCases(a,b){return inc(a,b,'arb.arbitration_service')['map'](c=>a['graph']['nodes']['get'](c['from']))['filter'](c=>!!c&&c['objectType']==='Arb'&&!!c['raw']);}const G1={'id':'G1','kind':'game','run'(a){const b=[];for(const e of typedNodes(a,'Arbitration')){const f=root(e),g=asList(f['voting_guard']),h=new Set(g['map'](l=>l['vote_weight']&&typeof l['vote_weight']==='object'?Object['keys'](l['vote_weight'])[0x0]:'unknown')),i=arbitrationCases(a,e['id']),j=new Map();let k=0x0;for(const l of i){for(const m of asList(root(l)['voted'])){const n=Number(m['weight']??0x0);j['set'](n,(j['get'](n)??0x0)+0x1),k++;}}b['push'](makeFinding(a,'G1:'+e['id'],'game','Voting\x20power\x20structure:\x20arbitration\x20voting\x20Guard\x20configuration\x20vs\x20actual\x20voting\x20weight\x20distribution',{'severity':'info','path':[e['id'],'arbitration.voting_guard','arb.arbitration_service','arb.voter'],'pathEdges':out(a,e['id'],'arbitration.voting_guard')['concat'](edgeList(a,'arb.voter')),'roles':['neutral','system','arbitrator','merchant','buyer'],'detail':'Arbitration\x20'+e['id']+':\x20voting_guard\x20'+(g['length']===0x0?'empty\x20=\x20open\x20to\x20all\x20members':'weighted\x20('+[...h]['join']('/')+')')+';\x20'+(i['length']+'\x20case(s)\x20in\x20window,\x20'+k+'\x20actual\x20vote(s)')+(j['size']?',\x20weight\x20distribution\x20'+[...j['entries']()]['map'](([o,p])=>'w'+o+'x'+p)['join'](',\x20'):'')+'.','suggestion':'Open\x20voting\x20suits\x20high-frequency\x20low-stakes\x20cases;\x20high-stakes\x20cases\x20should\x20use\x20weighted\x20Guards;\x20this\x20describes\x20the\x20objective\x20situation\x20only\x20—\x20scoring\x20belongs\x20to\x20the\x20game\x20modules.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},G2={'id':'G2','kind':'game','run'(a){const b=[];o:for(const c of machineViews(a)){const d=out(a,c['machine']['id'],'machine.permission')[0x0]?.['to'],f=d?inc(a,d,'permission.entity')['map'](h=>({'eoa':h['to'],'bits':h['payload']?.['permIndices']??[]})):[],g=new Set();for(const h of c['transitions']){const i=String(h['payload']?.['forward']??h['payload']?.['prevNode']+'→'+h['payload']?.['node']),j=wfNodeName(h['from'])+':'+i;if(g['has'](j))continue;let k,l='';if(str(h['payload']?.['namedOperator']))k=0x1,l='namedOperator='+h['payload']['namedOperator'];else{if(h['payload']?.['permissionIndex']!=null){if(!d)continue;const n=Number(h['payload']['permissionIndex']);k=f['filter'](o=>o['bits']['includes'](n))['length'],l='permissionIndex='+n;if(k===0x0)continue;}else continue;}if(k!==0x1)continue;g['add'](j);const m=graphFindingPolicy('G2',{});if(!m['enabled'])continue;b['push'](makeFinding(a,'G2:'+c['machine']['id']+':'+j,'game','Operator\x20replaceable\x20pool\x20=\x201:\x20hold-up\x20slot',{'severity':m['severity']??'low','path':[c['machine']['id'],'machine.node','wf.transition',j],'pathEdges':[h],'roles':['neutral','system','collaborator','merchant','supplier'],'detail':'Forward\x20'+j+'\x20('+l+')\x20on\x20Machine\x20'+c['machine']['id']+'\x20has\x20an\x20operable-party\x20pool\x20of\x20size\x201:\x20'+'that\x20party\x20holds\x20an\x20irreplaceable\x20bargaining\x20position\x20at\x20this\x20workflow\x20node\x20(protocol\x20operation\x20precheck).','suggestion':'Add\x20an\x20alternative\x20entity\x20under\x20the\x20same\x20permissionIndex\x20or\x20a\x20namedOperator\x20backup;\x20sign\x20SLA/penalty\x20terms\x20covering\x20this\x20slot.',...m['exposure']?{'exposure':m['exposure']}:{}}));if(b['length']>=MAX_FINDINGS_PER_RULE)break o;}}return b;}},G3={'id':'G3','kind':'game','run'(a){const b=[];for(const c of typedNodes(a,'Arbitration')){const e=root(c),f=asList(e['voting_guard']);b['push'](makeFinding(a,'G3:'+c['id'],'game','Remedy\x20strategy\x20parameters:\x20structured\x20inputs\x20for\x20the\x20payoff/waiting\x20matrices',{'severity':'info','path':[c['id'],'Arbitration.fee/usage_guard/voting_guard'],'roles':['neutral','system','arbitrator','merchant','buyer'],'detail':'Arbitration\x20'+c['id']+':\x20fee='+big(e['fee'])+',\x20usage_guard='+(str(e['usage_guard'])??'none')+',\x20voting_guard='+f['length']+'.\x20'+'Global\x20structural\x20constants:\x20payout\x20cap\x203x\x20amount,\x2030-day\x20compensation\x20withdrawal\x20lock,\x20single\x20claim\x20per\x20payout,\x2030-day\x20withdraw/objection\x20window.','suggestion':'Feed\x20these\x20parameters\x20into\x20node-game/arbitration-game\x20payoff\x20and\x20waiting\x20matrices;\x20this\x20analyzer\x20does\x20not\x20score\x20or\x20rank.'}));if(b['length']>=MAX_FINDINGS_PER_RULE)break;}return b;}},ANTI_CHEAT_ROLES=['neutral','system','merchant','buyer'];function projectOrderEvidence(a,b){const c=[];for(const d of typedNodes(a,'Service')){const f=[...b['controllers']['get'](d['id'])??[]];if(f['length']===0x0)continue;for(const g of out(a,d['id'],'service.order')){const h=a['graph']['nodes']['get'](g['to']);if(!h||h['kind']!=='object'||h['objectType']!=='Order'||!h['raw'])continue;const i=out(a,h['id'],'order.builder')[0x0]?.['to'];if(!i)continue;const j=orderCompletionInGraph(a['graph'],h['id'])['status'],k=String(root(h)?.['amount']??0x0),l=out(a,h['id'],'order.allocation')[0x0]?.['to']??null;for(const m of f){c['push']({'service':d['id'],'id':h['id'],'buyer':i,'seller':m,'amount':k,'status':j,'allocation':l});}}}return c;}function orderCheatEdges(a){return edgeList(a,'service.order')['concat'](edgeList(a,'eoa.permission'))['concat'](edgeList(a,'permission.core_binding'));}function shortRefs(a){const b=a['slice'](0x0,0x5)['join'](',\x20');return a['length']>0x5?b+'\x20and\x20'+a['length']+'\x20object(s)\x20in\x20total':b;}const AC1={'id':'AC1','kind':'risk','run'(a){const b=projectOrderEvidence(a,buildControlIndex(a)),c=detectFakeOrders(b)['find'](f=>f['code']==='self_buy');if(!c)return[];const d=c['refs']??[],e=graphFindingPolicy('AC1',{});if(!e['enabled'])return[];return[makeFinding(a,'AC1:'+d['join'](','),'risk','Fake-order\x20suspicion:\x20windowed\x20order\x20buyers\x20are\x20the\x20selling\x20service\x27s\x20controlling\x20EOA\x20(self-trading)',{'severity':e['severity']??'high','path':['EOA','eoa.permission','permission.core_binding','Service','service.order','Order','order.builder'],'pathEdges':orderCheatEdges(a),'roles':ANTI_CHEAT_ROLES,'detail':d['length']+'\x20order(s)\x20visible\x20in\x20the\x20window\x20have\x20buyer\x20EOAs\x20that\x20also\x20control\x20the\x20selling\x20Service\x20as\x20owner/admin\x20'+('('+shortRefs(d)+'):\x20buyer\x20and\x20seller\x20sit\x20in\x20the\x20same\x20control\x20set,\x20funds\x20circulate\x20internally,\x20and\x20this\x20is\x20not\x20genuine\x20competitive\x20volume.'),'suggestion':'Exclude\x20these\x20orders\x20from\x20sales/reputation\x20statistics\x20and\x20re-verify\x20via\x20payment\x20allocation\x20legs\x20and\x20time\x20windows;\x20reduce\x20market\x20exposure\x20and\x20recommendation\x20weight\x20for\x20this\x20Service.',...e['exposure']?{'exposure':e['exposure']}:{}})];}},AC2={'id':'AC2','kind':'risk','run'(a){const b=projectOrderEvidence(a,buildControlIndex(a)),c=detectFakeOrders(b)['find'](f=>f['code']==='reciprocal_loop');if(!c)return[];const d=c['refs']??[],e=graphFindingPolicy('AC2',{'ac_signal_level':c['severity']});if(!e['enabled'])return[];return[makeFinding(a,'AC2:'+d['join'](','),'risk','Wash-trading\x20suspicion:\x20reciprocal\x20buy/sell\x20role-swapping\x20fund\x20loops\x20in\x20the\x20window',{'severity':e['severity']??c['severity'],'path':['EOA-A','order.builder','Order@Service-B','service.order','EOA-B','order.builder','Order@Service-A'],'pathEdges':orderCheatEdges(a),'roles':ANTI_CHEAT_ROLES,'detail':d['length']+'\x20order(s)\x20in\x20the\x20window\x20form\x20a\x20buy/sell\x20swap:\x20control\x20set\x20A\x20buys\x20B\x27s\x20Service\x20while\x20control\x20set\x20B\x20buys\x20A\x27s\x20Service\x20'+('('+shortRefs(d)+').\x20The\x20two-way\x20volume\x20may\x20be\x20mutually\x20staged\x20wash\x20trading.'),'suggestion':'Investigate\x20links\x20between\x20the\x20two\x20control\x20sets\x20(devices/permissions/fund\x20flows);\x20exclude\x20mutually-purchased\x20orders\x20from\x20genuine\x20competitive\x20volume.',...e['exposure']?{'exposure':e['exposure']}:{}})];}},AC3={'id':'AC3','kind':'risk','run'(a){const b=projectOrderEvidence(a,buildControlIndex(a)),c=detectFakeOrders(b)['find'](f=>f['code']==='no_allocation');if(!c)return[];const d=c['refs']??[],e=graphFindingPolicy('AC3',{'ac_signal_level':c['severity']});if(!e['enabled'])return[];return[makeFinding(a,'AC3:'+d['join'](','),'risk','Missing\x20fund\x20closure:\x20completed\x20positive-amount\x20orders\x20lack\x20an\x20Allocation\x20object',{'severity':e['severity']??c['severity'],'path':['Service','service.order','Order','order.allocation'],'pathEdges':orderCheatEdges(a),'roles':ANTI_CHEAT_ROLES,'detail':d['length']+'\x20completed\x20order(s)\x20in\x20the\x20window\x20(completion\x20authoritatively\x20judged\x20by\x20the\x20order-status\x20terminal\x20node\x20set)\x20with\x20amount>0\x20have\x20no\x20Allocation\x20'+('('+shortRefs(d)+').\x20Protocol\x20rules\x20require\x20positive-amount\x20orders\x20to\x20have\x20an\x20allocation\x20path;\x20its\x20absence\x20means\x20the\x20\x22transaction\x22\x20lacks\x20fund-closure\x20evidence.\x20')+'Zero-amount\x20orders\x20are\x20excluded\x20(no\x20fund\x20flow).','suggestion':'Review\x20original\x20payment\x20records;\x20completed\x20orders\x20without\x20payment\x20evidence\x20must\x20not\x20count\x20toward\x20reputation;\x20audit\x20contract\x20entry\x20points\x20that\x20complete\x20without\x20an\x20Allocation\x20path.',...e['exposure']?{'exposure':e['exposure']}:{}})];}},SHELL_COPY={'shell_no_arbitration':{'title':'Shell\x20merchant:\x20published\x20Service\x20has\x20no\x20arbitration\x20binding,\x20disputes\x20have\x20no\x20remedy\x20path','detail':'The\x20Service\x20is\x20published\x20but\x20arbitrations\x20is\x20empty:\x20buyers\x20have\x20no\x20selectable\x20arbitration\x20service\x20after\x20ordering\x20and\x20disputes\x20cannot\x20enter\x20adjudication.','suggestion':'Bind\x20at\x20least\x20one\x20Arbitration\x20in\x20a\x20different\x20group\x20than\x20the\x20shop\x20Permission\x20before\x20publishing;\x20shops\x20without\x20a\x20remedy\x20path\x20should\x20not\x20be\x20recommended.'},'shell_funded_no_arbitration':{'title':'Floating\x20payout\x20funds:\x20compensation\x20fund\x20is\x20funded\x20but\x20no\x20Arbitration\x20exists,\x20payouts\x20cannot\x20be\x20adjudicated\x20or\x20released','detail':'compensation_fund>0\x20with\x20no\x20Arbitration\x20at\x20all:\x20when\x20a\x20payout\x20triggers\x20there\x20is\x20no\x20one\x20to\x20adjudicate\x20and\x20no\x20path\x20to\x20release;\x20the\x20funding\x20is\x20marketing\x20theater.','suggestion':'Bind\x20an\x20arbitration\x20service\x20before\x20advertising\x20payout\x20guarantees;\x20marketplaces\x20should\x20flag\x20\x27fund\x20without\x20arbitration\x27\x20as\x20high\x20risk\x20and\x20limit\x20exposure.'},'shell_no_machine':{'title':'Shell\x20merchant:\x20published\x20Service\x20has\x20no\x20Machine\x20binding,\x20no\x20structured\x20fulfillment\x20workflow','detail':'The\x20Service\x20is\x20published\x20but\x20machine\x20is\x20empty:\x20no\x20frozen\x20workflow\x20template\x20exists,\x20and\x20delivery/completion\x20nodes\x20carry\x20no\x20on-chain\x20structural\x20constraints.','suggestion':'Bind\x20and\x20publish\x20a\x20Machine\x20before\x20opening;\x20published\x20shops\x20without\x20workflows\x20suit\x20only\x20instant\x20spot-delivery\x20categories.'}},AC4={'id':'AC4','kind':'risk','run'(a){const b=[];for(const c of typedNodes(a,'Service')){const e=root(c);if(!bool(e['bPublished']))continue;const f=e['arbitrations']!=null?asList(e['arbitrations'])['length']:out(a,c['id'],'service.arbitration')['length'],g=str(e['machine'])??out(a,c['id'],'service.machine')[0x0]?.['to']??null,h=detectShellMerchant({'object':c['id'],'arbitrations':Array(f)['fill']('x'),'compensation_fund':String(big(e['compensation_fund'])),'machine':g,'bPublished':!![]}),i=out(a,c['id'],'service.arbitration')['concat'](out(a,c['id'],'service.machine'));for(const j of h){const k=SHELL_COPY[j['code']];if(!k)continue;const l=graphFindingPolicy('AC4',{'ac_shell_code':j['code'],'ac_signal_level':j['severity']});if(!l['enabled'])continue;b['push'](makeFinding(a,'AC4:'+c['id']+':'+j['code'],'risk',k['title'],{'severity':l['severity']??j['severity'],'path':[c['id'],'Service.bPublished','Service.arbitrations','Service.machine','Service.compensation_fund'],'pathEdges':i,'roles':ANTI_CHEAT_ROLES,'detail':k['detail']+'\x20(object:\x20'+c['id']+')','suggestion':k['suggestion'],...l['exposure']?{'exposure':l['exposure']}:{}}));if(b['length']>=MAX_FINDINGS_PER_RULE)return b;}}return b;}};export const DEFAULT_ANALYZERS=[R1,R2,R3,R4,R5,R6,R7,A1,A2,A3,O1,O2,O3,G1,G2,G3,AC1,AC2,AC3,AC4,PROPOSAL_GAP_ANALYZER];const registry=new Map(DEFAULT_ANALYZERS['map'](b=>[b['id'],b]));export function registerAnalyzer(a){registry['set'](a['id'],a);}export function getAnalyzer(a){return registry['get'](a);}export function listAnalyzers(){return[...registry['keys']()];}export function runAnalyzers(a,b){const c=b?.['only']?new Set(b['only']):undefined,d=[];beginPolicyRun();try{for(const e of registry['values']()){if(c&&!c['has'](e['id']))continue;if(b?.['kinds']&&!b['kinds']['includes'](e['kind']))continue;try{d['push'](...e['run'](a));}catch{}}}finally{endPolicyRun();}return withFindingObjects(d);}const ADDRESS_RE=/\b0x[0-9a-fA-F]{40,64}\b/g;export function withFindingObjects(a){for(const b of a){const c=[],d=new Set(),e=g=>{const h=g['toLowerCase']();if(d['has'](h))return;d['add'](h),c['push'](h);};for(const g of b['path']){if(/^0x[0-9a-fA-F]{40,64}$/['test'](g['trim']()))e(g['trim']());}for(const h of b['detail']['matchAll'](ADDRESS_RE))e(h[0x0]);if(c['length']>0x0)b['objects']=c['slice'](0x0,0xc);}return a;}export function adaptNodeAnalyzer(a){return{'id':a['id'],'kind':a['kind'],'objectType':a['objectType'],'run'(b,c){const d=a['inspect'](b,c);return d['map']((e,f)=>({'id':a['id']+':'+b['id']+'#'+f,'kind':a['kind'],'severity':e['severity']??'info','title':e['title'],'path':[b['id']],'confidence':e['confidence']??'exact','roles':e['roles']??['neutral'],'detail':e['detail'],'suggestion':e['suggestion'],...e['ruleId']?{'ruleId':e['ruleId']}:{},...e['evidence']?{'evidence':e['evidence']}:{},...e['exposure']?{'exposure':e['exposure']}:{},...e['nativeRisk']!==undefined?{'nativeRisk':e['nativeRisk']}:{},...b['proposal']&&!e['confidence']?{'confidence':'derived'}:{},...b['proposal']?{'source':b['proposal']['provenance']==='external'?'external':'proposal'}:{}}));}};}export function runNodeAnalyzers(a,b){const c=[];beginPolicyRun();try{for(const d of b){for(const e of a['visibleNodes']){const f=a['graph']['nodes']['get'](e);if(f?.['kind']!=='object'||d['objectType']!=='*'&&f['objectType']!==d['objectType']||!f['raw'])continue;try{c['push'](...d['run'](f,a));}catch{}}}}finally{endPolicyRun();}return withFindingObjects(c);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{describe,it,expect}from'vitest';import{ENTRYPOINT}from'@wowok/wowok';import{buildViewport,runAnalyzers,runNodeAnalyzers,adaptNodeAnalyzer,listAnalyzers,registerAnalyzer,findingWhere}from'./index.js';describe('findingWhere',()=>{it('renders\x20R4\x20as\x20machine\x20+\x20node\x20names\x20(no\x20::node::\x20grammar,\x20no\x20R4:\x20prefix)',()=>{expect(findingWhere({'id':'R4:myshop_machine:myshop_machine::node::Order\x20Confirmed→myshop_machine::node::Order\x20Cancel'}))['toBe']('myshop_machine:\x20Order\x20Confirmed\x20→\x20Order\x20Cancel');}),it('renders\x20R7/R2\x20as\x20object\x20kind\x20+\x20name',()=>{expect(findingWhere({'id':'R7:reward:0x1f2e'}))['toBe']('Reward\x200x1f2e'),expect(findingWhere({'id':'R7:treasury:0xabc'}))['toBe']('Treasury\x200xabc'),expect(findingWhere({'id':'R2:0x14519d'}))['toBe']('0x14519d');}),it('falls\x20back\x20to\x20the\x20finding\x20title\x20for\x20unknown\x20id\x20shapes',()=>{expect(findingWhere({'id':'R1:weird','title':'Arb\x20permission\x20shared\x20with\x20the\x20merchant'}))['toBe']('Arb\x20permission\x20shared\x20with\x20the\x20merchant');});});const FAMILY={'eoa.permission':'R','permission.core_binding':'R','permission.entity':'W','service.order':'R','service.machine':'F','service.buy_guard':'F','machine.permission':'F','machine.node':'W','wf.transition':'W','wf.forward_guard':'W','order.allocation':'F','demand.guard':'R','demand.presenter':'R','arbitration.voting_guard':'F','arb.arbitration_service':'F','arb.voter':'S'};class GB{['nodes']=new Map();['edges']=[];['out']=new Map();['inc']=new Map();['truncations']=[];['eoa'](a){return this['nodes']['set'](a,{'id':a,'kind':'eoa','state':'fetched','origins':[],'depth':0x0}),this;}['obj'](a,b,c,d){return this['nodes']['set'](a,{'id':a,'kind':'object','objectType':b,'state':'fetched','origins':[],'depth':0x1,'raw':{'object':a,'type':b,...d?{'type_raw':d}:{},'data':c}}),this;}['edge'](a,b,c,d,f,g=![]){const h={'id':a+'|'+b+'→'+c+(d?.['forward']?'|'+d['forward']:''),'schema':a,'family':FAMILY[a]??'F','from':b,'to':c,'retention':f??(FAMILY[a]==='R'?'bounded_exact':'complete'),'evidence':'test','observedAt':0x1,...d?{'payload':d}:{},...g?{'truncated':!![]}:{}};return this['edges']['push'](h),(this['out']['get'](b)??this['out']['set'](b,[])['get'](b))['push'](h),(this['inc']['get'](c)??this['inc']['set'](c,[])['get'](c))['push'](h),h;}['trunc'](a,b,c){return this['truncations']['push']({'nodeId':a,'schema':b,'observed':c,'limit':0x1450}),this;}['build'](a='0xseed'){return{'network':ENTRYPOINT['Mainnet'],'seed':a,'builtAt':0x1,'nodes':this['nodes'],'edges':this['edges'],'out':this['out'],'inc':this['inc'],'gaps':[],'truncations':this['truncations'],'rpcReport':{'batches':0x0,'byChannel':{'objects':0x0,'keyedFields':0x0,'tables':0x0,'events':0x0},'dedupHits':0x0},'budgetExhausted':{}};}['vp'](a='0xseed',b='neutral'){return buildViewport(this['build'](a),a,b);}}const ids=a=>a['map'](b=>b['id']);describe('analyze\x20—\x20registry',()=>{it('ships\x20the\x2021\x20rules\x20(R1-7/A1-3/O1-3/G1-3\x20+\x20anti-cheat\x20AC1-4\x20+\x20proposal.gap)',()=>{expect(listAnalyzers()['sort']())['toEqual'](['R1','R2','R3','R4','R5','R6','R7','A1','A2','A3','O1','O2','O3','G1','G2','G3','AC1','AC2','AC3','AC4','proposal.gap']['sort']());}),it('is\x20fail-soft:\x20a\x20throwing\x20analyzer\x20never\x20aborts\x20the\x20suite',()=>{registerAnalyzer({'id':'__boom','kind':'risk','run':()=>{throw new Error('boom');}});const a=new GB()['obj']('0xs1','Service',{'bPublished':!![],'setting_lock_duration':'0'})['vp'](),b=runAnalyzers(a,{'only':['__boom','R6']});expect(ids(b))['toContain']('R6:0xs1'),expect(b['find'](c=>c['id']['startsWith']('__boom')))['toBeUndefined']();}),it('adapts\x20single-object\x20legacy\x20rules\x20through\x20the\x20NodeAnalyzer\x20bridge',()=>{const a=adaptNodeAnalyzer({'id':'legacy-lock','kind':'risk','objectType':'Service','inspect':e=>{const f=e['raw']['data']??{};return f['setting_lock_duration']==='0'?[{'title':'Lock','detail':'d','suggestion':'s','roles':['merchant']}]:[];}}),b=new GB()['obj']('0xs1','Service',{'bPublished':!![],'setting_lock_duration':'0'})['vp'](),c=runNodeAnalyzers(b,[a]);expect(c)['toHaveLength'](0x1),expect(c[0x0]['id'])['toBe']('legacy-lock:0xs1#0'),expect(c[0x0]['kind'])['toBe']('risk');});}),describe('analyze\x20—\x20risk\x20rules',()=>{it('R6\x20flags\x20published\x20services\x20without\x20a\x20setting\x20lock',()=>{const a=new GB()['obj']('0xs1','Service',{'bPublished':!![],'setting_lock_duration':'0'})['obj']('0xs2','Service',{'bPublished':!![],'setting_lock_duration':'2592000000'})['obj']('0xs3','Service',{'bPublished':![],'setting_lock_duration':'0'})['vp'](),b=runAnalyzers(a,{'only':['R6']});expect(ids(b))['toEqual'](['R6:0xs1']);}),it('R7\x20emits\x20CRITICAL\x20for\x20object\x20users\x20when\x20a\x20Treasury\x20has\x20mounted\x20external\x20withdraw\x20Guards',()=>{const a=new GB();a['obj']('0xt1','Treasury',{'external_withdraw_guard':[{'guard':'0xg1','identifier':0x0,'store_from_id':0x0}]}),a['obj']('0xt2','Treasury',{'external_withdraw_guard':[]});const b=runAnalyzers(a['vp'](),{'only':['R7']});expect(ids(b))['toEqual'](['R7:treasury:0xt1']),expect(b[0x0]['severity'])['toBe']('critical'),expect(b[0x0]['detail'])['toContain']('code\x2010');}),it('R7\x20emits\x20CRITICAL\x20for\x20object\x20users\x20when\x20a\x20Reward\x20has\x20mounted\x20claim\x20Guards',()=>{const a=new GB();a['obj']('0xr1','Reward',{'guards':[{'guard':'0xg1'}]}),a['obj']('0xr2','Reward',{'guards':[]});const b=runAnalyzers(a['vp'](),{'only':['R7']});expect(ids(b))['toEqual'](['R7:reward:0xr1']),expect(b[0x0]['severity'])['toBe']('critical'),expect(b[0x0]['detail'])['toContain']('GuardIdentifier');}),it('R2\x20measures\x20the\x20compensation\x20fund\x20against\x203x\x20windowed\x20order\x20volume',()=>{const a=new GB();a['obj']('0xs1','Service',{'bPublished':!![],'compensation_fund':'100'}),a['obj']('0xo1','Order',{'amount':'100'}),a['obj']('0xo2','Order',{'amount':'100'}),a['edge']('service.order','0xs1','0xo1',undefined,'bounded_window'),a['edge']('service.order','0xs1','0xo2',undefined,'bounded_window',!![]);const b=runAnalyzers(a['vp'](),{'only':['R2']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['severity'])['toBe']('high'),expect(b[0x0]['confidence'])['toBe']('windowed'),expect(b[0x0]['window']?.['limit'])['toBe'](0x1450);}),it('R1\x20flags\x20one\x20EOA\x20controlling\x20a\x20shop\x20and\x20an\x20arbitration\x20service\x20across\x20distinct\x20permissions',()=>{const a=new GB();a['eoa']('0xe1'),a['obj']('0xp1','Permission',{'owner':'0xe1'}),a['obj']('0xp2','Permission',{'owner':'0xe1'}),a['obj']('0xs1','Service',{}),a['obj']('0xa1','Arbitration',{'fee':'0'}),a['edge']('eoa.permission','0xe1','0xp1',{'roleBits':0x3}),a['edge']('eoa.permission','0xe1','0xp2',{'roleBits':0x3}),a['edge']('permission.core_binding','0xp1','0xs1'),a['edge']('permission.core_binding','0xp2','0xa1');const b=runAnalyzers(a['vp'](),{'only':['R1']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['severity'])['toBe']('high');const c=new GB();c['eoa']('0xe1')['obj']('0xp1','Permission',{})['obj']('0xs1','Service',{})['obj']('0xa1','Arbitration',{'fee':'0'}),c['edge']('eoa.permission','0xe1','0xp1',{'roleBits':0x3}),c['edge']('permission.core_binding','0xp1','0xs1'),c['edge']('permission.core_binding','0xp1','0xa1'),expect(runAnalyzers(c['vp'](),{'only':['R1']}))['toHaveLength'](0x0);}),it('R3\x20flags\x20concentrated\x20control\x20of\x20core\x20objects',()=>{const a=new GB();a['eoa']('0xe1')['obj']('0xp1','Permission',{}),a['obj']('0xs1','Service',{})['obj']('0xs2','Service',{})['obj']('0xm1','Machine',{}),a['edge']('eoa.permission','0xe1','0xp1',{'roleBits':0x1});for(const c of['0xs1','0xs2','0xm1'])a['edge']('permission.core_binding','0xp1',c);const b=runAnalyzers(a['vp'](),{'only':['R3']});expect(ids(b))['toEqual'](['R3:0xe1']);}),it('R4\x20flags\x20a\x20unique\x20operator\x20with\x20no\x20backup\x20guard\x20on\x20a\x20terminal-entering\x20forward',()=>{const a=new GB();a['obj']('0xm1','Machine',{'bPublished':!![]}),a['edge']('wf.transition','0xm1::node::paid','0xm1::node::delivered',{'node':'delivered','prevNode':'paid','forward':'go','namedOperator':'alice'});const b=runAnalyzers(a['vp'](),{'only':['R4']});expect(b)['toHaveLength'](0x1);const c=new GB();c['obj']('0xm1','Machine',{'bPublished':!![]}),c['edge']('wf.transition','0xm1::node::paid','0xm1::node::delivered',{'node':'delivered','prevNode':'paid','forward':'go','namedOperator':'alice','guard':'0xg1'}),expect(runAnalyzers(c['vp'](),{'only':['R4']}))['toHaveLength'](0x0);}),it('R5\x20reports\x20window\x20truncations\x20as\x20downgraded\x20meta\x20findings',()=>{const a=new GB()['obj']('0xs1','Service',{})['trunc']('0xs1','service.order',0x1450),b=runAnalyzers(a['vp'](),{'only':['R5']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['confidence'])['toBe']('windowed'),expect(b[0x0]['window'])['toEqual']({'observed':0x1450,'limit':0x1450});});}),describe('analyze\x20—\x20arbitrage\x20rules',()=>{it('A1\x20detects\x20rate-basis\x20mismatch,\x20surplus\x20duplication\x20and\x20missing\x20max',()=>{const a=new GB();a['obj']('0xal1','Allocation',{'allocators':[{'guard':'0xg1','max':null,'sharing':[{'who':'0xa','mode':0x0,'sharing':'100'}]},{'guard':'0xg2','sharing':[{'who':'0xb','mode':0x1,'sharing':'9000'}]},{'guard':'0xg3','sharing':[{'who':'0xc','mode':0x2}]},{'guard':'0xg4','sharing':[{'who':'0xd','mode':0x2}]}]});const b=runAnalyzers(a['vp'](),{'only':['A1']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('9000'),expect(b[0x0]['detail'])['toContain']('max'),expect(b[0x0]['detail'])['toContain']('Surplus');}),it('A2\x20flags\x20transferable\x20fixed\x20long-window\x20discounts\x20without\x20a\x20benchmark',()=>{const a=new GB();a['obj']('0xd1','Discount',{'discount_type':0x1,'benchmark':null,'transferable':!![],'time_start':'0','time_end':String(0x1fn*0x18n*0x3cn*0x3cn*0x3e8n)});const b=runAnalyzers(a['vp'](),{'only':['A2']});expect(b)['toHaveLength'](0x1);const c=new GB();c['obj']('0xd2','Discount',{'discount_type':0x1,'benchmark':null,'transferable':![],'time_start':'0','time_end':String(0x1fn*0x18n*0x3cn*0x3cn*0x3e8n)}),expect(runAnalyzers(c['vp'](),{'only':['A2']}))['toHaveLength'](0x0);}),it('A3\x20flags\x20zero-fee/no-usage-guard\x20arbitration\x20and\x20reports\x20CoinWrapper\x20custody',()=>{const a=new GB();a['obj']('0xa1','Arbitration',{'fee':'0','usage_guard':null,'voting_guard':[]}),a['obj']('0xcw1','Payment',{},'0x2::payment::CoinWrapper<0x2::wow::WOW>');const b=runAnalyzers(a['vp'](),{'only':['A3']});expect(ids(b)['sort']())['toEqual'](['A3:0xa1','A3:coinwrapper']),expect(b['find'](c=>c['id']==='A3:coinwrapper')['detail'])['toContain']('0x2::wow::WOW');});}),describe('analyze\x20—\x20opportunity\x20rules',()=>{it('O1\x20surfaces\x20scarce-presenter\x20demands\x20with\x20structurally\x20matching\x20services',()=>{const a=new GB();a['obj']('0xdm1','Demand',{'guards':[{'guard':'0xg1'}]}),a['edge']('demand.guard','0xdm1','0xg1'),a['obj']('0xs1','Service',{'bPublished':!![]}),a['obj']('0xm1','Machine',{}),a['edge']('service.machine','0xs1','0xm1'),a['edge']('wf.forward_guard','0xm1::node::paid','0xg1');const b=runAnalyzers(a['vp'](),{'only':['O1']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('0xs1'),a['eoa']('0u1')['eoa']('0u2'),a['edge']('demand.presenter','0xdm1','0u1',{'service':'0xs1'}),a['edge']('demand.presenter','0xdm1','0u2',{'service':'0xs1'}),expect(runAnalyzers(a['vp'](),{'only':['O1']}))['toHaveLength'](0x0);}),it('O2\x20reports\x20graph\x20supply/demand\x20density',()=>{const a=new GB();a['obj']('0xs1','Service',{'bPublished':!![],'bPaused':![]}),a['obj']('0xs2','Service',{'bPublished':![]}),a['obj']('0xd1','Demand',{});const b=runAnalyzers(a['vp'](),{'only':['O2']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('2\x20Service(s)'),expect(b[0x0]['detail'])['toContain']('1\x20open\x20demand(s)');}),it('O3\x20lists\x20operator-less\x20forwards\x20as\x20workflow\x20slots',()=>{const a=new GB();a['obj']('0xm1','Machine',{}),a['edge']('wf.transition','0xm1::node::paid','0xm1::node::done',{'node':'done','prevNode':'paid','forward':'auto','namedOperator':null,'permissionIndex':null,'guard':'0xg1'});const b=runAnalyzers(a['vp'](),{'only':['O3']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('paid:auto');});}),describe('analyze\x20—\x20game\x20rules',()=>{it('G1\x20reports\x20all-vote\x20vs\x20weighted\x20structures\x20plus\x20observed\x20case\x20weights',()=>{const a=new GB();a['obj']('0xa1','Arbitration',{'fee':'0','voting_guard':[]}),a['obj']('0xcase1','Arb',{'voted':[{'voter':'0u1','weight':0x1},{'voter':'0u2','weight':0x2}]}),a['edge']('arb.arbitration_service','0xcase1','0xa1');const b=runAnalyzers(a['vp'](),{'only':['G1']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('open\x20to\x20all\x20members'),expect(b[0x0]['detail'])['toContain']('w1x1'),expect(b[0x0]['detail'])['toContain']('w2x1');}),it('G2\x20marks\x20a\x20named-operator\x20forward\x20as\x20a\x20pool-of-one\x20hold-up\x20point',()=>{const a=new GB();a['obj']('0xm1','Machine',{}),a['edge']('wf.transition','0xm1::node::paid','0xm1::node::done',{'node':'done','prevNode':'paid','forward':'sign','namedOperator':'bob'});const b=runAnalyzers(a['vp'](),{'only':['G2']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['id'])['toContain']('paid:sign');}),it('G3\x20emits\x20the\x20relief\x20parameter\x20matrix\x20for\x20every\x20arbitration\x20service',()=>{const a=new GB();a['obj']('0xa1','Arbitration',{'fee':'5','usage_guard':'0xg1','voting_guard':[{'guard':'0xg2'}]});const b=runAnalyzers(a['vp'](),{'only':['G3']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('fee=5'),expect(b[0x0]['detail'])['toContain']('30-day');});}),describe('analyze\x20—\x20anti-cheat\x20rules\x20(AC1-AC4)',()=>{function a(c,d,e,f){c['eoa'](d),c['edge']('eoa.permission',d,e,{'roleBits':0x1|0x2}),c['edge']('permission.core_binding',e,f);}function b(c,d,e,f){c['obj'](e,'Order',f),c['edge']('service.order',d,e,undefined,'bounded_window'),c['edge']('order.builder',e,String(f['builder']));}it('AC1\x20flags\x20window\x20orders\x20whose\x20buyer\x20controls\x20the\x20selling\x20Service',()=>{const c=new GB();c['obj']('0xs1','Service',{'bPublished':!![],'machine':'0xm1'}),a(c,'0u1','0p1','0xs1'),b(c,'0xs1','0o1',{'builder':'0u1','service':'0xs1','amount':'100'});const d=runAnalyzers(c['vp'](),{'only':['AC1']});expect(d)['toHaveLength'](0x1),expect(d[0x0]['severity'])['toBe']('high'),expect(d[0x0]['confidence'])['toBe']('windowed'),expect(d[0x0]['id'])['toContain']('0o1');const e=new GB();e['obj']('0xs1','Service',{'bPublished':!![],'machine':'0xm1'}),a(e,'0u1','0p1','0xs1'),b(e,'0xs1','0o1',{'builder':'0u2','service':'0xs1','amount':'100'}),expect(runAnalyzers(e['vp'](),{'only':['AC1']}))['toEqual']([]);}),it('AC2\x20flags\x20reciprocal\x20buying\x20between\x20two\x20controlled\x20Services',()=>{const c=new GB();c['obj']('0xs1','Service',{'bPublished':!![],'machine':'0xm1'}),c['obj']('0xs2','Service',{'bPublished':!![],'machine':'0xm2'}),a(c,'0u1','0p1','0xs1'),a(c,'0u2','0p2','0xs2'),b(c,'0xs1','0o1',{'builder':'0u2','service':'0xs1','amount':'100'}),b(c,'0xs2','0o2',{'builder':'0u1','service':'0xs2','amount':'100'});const d=runAnalyzers(c['vp'](),{'only':['AC2']});expect(d)['toHaveLength'](0x1),expect(d[0x0]['severity'])['toBe']('medium'),expect(d[0x0]['id'])['toContain']('0o1'),expect(d[0x0]['id'])['toContain']('0o2');}),it('AC3\x20flags\x20completed\x20positive-amount\x20orders\x20without\x20Allocation,\x20but\x20not\x20zero-amount\x20orders',()=>{const c=new GB();c['obj']('0xs1','Service',{'bPublished':!![],'machine':'0xm1'}),a(c,'0u1','0p1','0xs1'),b(c,'0xs1','0opaid',{'builder':'0u9','service':'0xs1','amount':'100'}),b(c,'0xs1','0ofree',{'builder':'0u8','service':'0xs1','amount':'0'});const d=runAnalyzers(c['vp'](),{'only':['AC3']});expect(d)['toHaveLength'](0x1),expect(d[0x0]['id'])['toContain']('0opaid'),expect(d[0x0]['id'])['not']['toContain']('0ofree'),c['edge']('order.allocation','0opaid','0al1'),expect(runAnalyzers(c['vp'](),{'only':['AC3']}))['toEqual']([]);}),it('AC4\x20surfaces\x20shell-merchant\x20shapes\x20only\x20for\x20published\x20Services',()=>{const c=new GB();c['obj']('0xs1','Service',{'bPublished':!![],'arbitrations':[],'compensation_fund':'0'});const d=runAnalyzers(c['vp'](),{'only':['AC4']});expect(ids(d)['sort']())['toEqual'](['AC4:0xs1:shell_no_arbitration','AC4:0xs1:shell_no_machine']['sort']());const e=new GB();e['obj']('0xs2','Service',{'bPublished':!![],'arbitrations':[],'compensation_fund':'500'});const f=runAnalyzers(e['vp'](),{'only':['AC4']});expect(f['map'](h=>h['severity'])['sort']())['toEqual'](['high','low','medium']['sort']());const g=new GB();g['obj']('0xs3','Service',{'bPublished':![],'arbitrations':[],'compensation_fund':'500'}),expect(runAnalyzers(g['vp'](),{'only':['AC4']}))['toEqual']([]);});});
|
|
1
|
+
import{describe,it,expect}from'vitest';import{ENTRYPOINT}from'@wowok/wowok';import{buildViewport,runAnalyzers,runNodeAnalyzers,adaptNodeAnalyzer,listAnalyzers,registerAnalyzer,findingWhere}from'./index.js';describe('findingWhere',()=>{it('renders\x20R4\x20as\x20machine\x20+\x20node\x20names\x20(no\x20::node::\x20grammar,\x20no\x20R4:\x20prefix)',()=>{expect(findingWhere({'id':'R4:myshop_machine:myshop_machine::node::Order\x20Confirmed→myshop_machine::node::Order\x20Cancel'}))['toBe']('myshop_machine:\x20Order\x20Confirmed\x20→\x20Order\x20Cancel');}),it('renders\x20R7/R2\x20as\x20object\x20kind\x20+\x20name',()=>{expect(findingWhere({'id':'R7:reward:0x1f2e'}))['toBe']('Reward\x200x1f2e'),expect(findingWhere({'id':'R7:treasury:0xabc'}))['toBe']('Treasury\x200xabc'),expect(findingWhere({'id':'R2:0x14519d'}))['toBe']('0x14519d');}),it('falls\x20back\x20to\x20the\x20finding\x20title\x20for\x20unknown\x20id\x20shapes',()=>{expect(findingWhere({'id':'R1:weird','title':'Arb\x20permission\x20shared\x20with\x20the\x20merchant'}))['toBe']('Arb\x20permission\x20shared\x20with\x20the\x20merchant');});});const FAMILY={'eoa.permission':'R','permission.core_binding':'R','permission.entity':'W','service.order':'R','service.machine':'F','service.buy_guard':'F','machine.permission':'F','machine.node':'W','wf.transition':'W','wf.forward_guard':'W','order.allocation':'F','demand.guard':'R','demand.presenter':'R','arbitration.voting_guard':'F','arb.arbitration_service':'F','arb.voter':'S'};class GB{['nodes']=new Map();['edges']=[];['out']=new Map();['inc']=new Map();['truncations']=[];['eoa'](a){return this['nodes']['set'](a,{'id':a,'kind':'eoa','state':'fetched','origins':[],'depth':0x0}),this;}['obj'](a,b,c,d){return this['nodes']['set'](a,{'id':a,'kind':'object','objectType':b,'state':'fetched','origins':[],'depth':0x1,'raw':{'object':a,'type':b,...d?{'type_raw':d}:{},'data':c}}),this;}['edge'](a,b,c,d,f,g=![]){const h={'id':a+'|'+b+'→'+c+(d?.['forward']?'|'+d['forward']:''),'schema':a,'family':FAMILY[a]??'F','from':b,'to':c,'retention':f??(FAMILY[a]==='R'?'bounded_exact':'complete'),'observedAt':0x1,...d?{'payload':d}:{},...g?{'truncated':!![]}:{}};return this['edges']['push'](h),(this['out']['get'](b)??this['out']['set'](b,[])['get'](b))['push'](h),(this['inc']['get'](c)??this['inc']['set'](c,[])['get'](c))['push'](h),h;}['trunc'](a,b,c){return this['truncations']['push']({'nodeId':a,'schema':b,'observed':c,'limit':0x1450}),this;}['build'](a='0xseed'){return{'network':ENTRYPOINT['Mainnet'],'seed':a,'builtAt':0x1,'nodes':this['nodes'],'edges':this['edges'],'out':this['out'],'inc':this['inc'],'gaps':[],'truncations':this['truncations'],'rpcReport':{'batches':0x0,'byChannel':{'objects':0x0,'keyedFields':0x0,'tables':0x0,'events':0x0},'dedupHits':0x0},'budgetExhausted':{}};}['vp'](a='0xseed',b='neutral'){return buildViewport(this['build'](a),a,b);}}const ids=a=>a['map'](b=>b['id']);describe('analyze\x20—\x20registry',()=>{it('ships\x20the\x2021\x20rules\x20(R1-7/A1-3/O1-3/G1-3\x20+\x20anti-cheat\x20AC1-4\x20+\x20proposal.gap)',()=>{expect(listAnalyzers()['sort']())['toEqual'](['R1','R2','R3','R4','R5','R6','R7','A1','A2','A3','O1','O2','O3','G1','G2','G3','AC1','AC2','AC3','AC4','proposal.gap']['sort']());}),it('is\x20fail-soft:\x20a\x20throwing\x20analyzer\x20never\x20aborts\x20the\x20suite',()=>{registerAnalyzer({'id':'__boom','kind':'risk','run':()=>{throw new Error('boom');}});const a=new GB()['obj']('0xs1','Service',{'bPublished':!![],'setting_lock_duration':'0'})['vp'](),b=runAnalyzers(a,{'only':['__boom','R6']});expect(ids(b))['toContain']('R6:0xs1'),expect(b['find'](c=>c['id']['startsWith']('__boom')))['toBeUndefined']();}),it('adapts\x20single-object\x20legacy\x20rules\x20through\x20the\x20NodeAnalyzer\x20bridge',()=>{const a=adaptNodeAnalyzer({'id':'legacy-lock','kind':'risk','objectType':'Service','inspect':e=>{const f=e['raw']['data']??{};return f['setting_lock_duration']==='0'?[{'title':'Lock','detail':'d','suggestion':'s','roles':['merchant']}]:[];}}),b=new GB()['obj']('0xs1','Service',{'bPublished':!![],'setting_lock_duration':'0'})['vp'](),c=runNodeAnalyzers(b,[a]);expect(c)['toHaveLength'](0x1),expect(c[0x0]['id'])['toBe']('legacy-lock:0xs1#0'),expect(c[0x0]['kind'])['toBe']('risk');});}),describe('analyze\x20—\x20risk\x20rules',()=>{it('R6\x20flags\x20published\x20services\x20without\x20a\x20setting\x20lock',()=>{const a=new GB()['obj']('0xs1','Service',{'bPublished':!![],'setting_lock_duration':'0'})['obj']('0xs2','Service',{'bPublished':!![],'setting_lock_duration':'2592000000'})['obj']('0xs3','Service',{'bPublished':![],'setting_lock_duration':'0'})['vp'](),b=runAnalyzers(a,{'only':['R6']});expect(ids(b))['toEqual'](['R6:0xs1']);}),it('R7\x20emits\x20CRITICAL\x20for\x20object\x20users\x20when\x20a\x20Treasury\x20has\x20mounted\x20external\x20withdraw\x20Guards',()=>{const a=new GB();a['obj']('0xt1','Treasury',{'external_withdraw_guard':[{'guard':'0xg1','identifier':0x0,'store_from_id':0x0}]}),a['obj']('0xt2','Treasury',{'external_withdraw_guard':[]});const b=runAnalyzers(a['vp'](),{'only':['R7']});expect(ids(b))['toEqual'](['R7:treasury:0xt1']),expect(b[0x0]['severity'])['toBe']('critical'),expect(b[0x0]['detail'])['toContain']('code\x2010');}),it('R7\x20emits\x20CRITICAL\x20for\x20object\x20users\x20when\x20a\x20Reward\x20has\x20mounted\x20claim\x20Guards',()=>{const a=new GB();a['obj']('0xr1','Reward',{'guards':[{'guard':'0xg1'}]}),a['obj']('0xr2','Reward',{'guards':[]});const b=runAnalyzers(a['vp'](),{'only':['R7']});expect(ids(b))['toEqual'](['R7:reward:0xr1']),expect(b[0x0]['severity'])['toBe']('critical'),expect(b[0x0]['detail'])['toContain']('GuardIdentifier');}),it('R7\x20carries\x20drill-through\x20objects\x20—\x20the\x20FULL\x20reward\x20address\x20from\x20path/detail',()=>{const a='0x1a77893aaa0f0000000000000000000000000000000000000000000000aa1234',b=new GB();b['obj'](a,'Reward',{'guards':[{'guard':'0xg1'}]});const c=runAnalyzers(b['vp'](),{'only':['R7']});expect(c)['toHaveLength'](0x1),expect(c[0x0]['objects'])['toEqual']([a]);}),it('R2\x20measures\x20the\x20compensation\x20fund\x20against\x203x\x20windowed\x20order\x20volume',()=>{const a=new GB();a['obj']('0xs1','Service',{'bPublished':!![],'compensation_fund':'100'}),a['obj']('0xo1','Order',{'amount':'100'}),a['obj']('0xo2','Order',{'amount':'100'}),a['edge']('service.order','0xs1','0xo1',undefined,'bounded_window'),a['edge']('service.order','0xs1','0xo2',undefined,'bounded_window',!![]);const b=runAnalyzers(a['vp'](),{'only':['R2']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['severity'])['toBe']('high'),expect(b[0x0]['confidence'])['toBe']('windowed'),expect(b[0x0]['window']?.['limit'])['toBe'](0x1450),expect(b[0x0]['detail'])['toContain']('{fund}'),expect(b[0x0]['detail'])['not']['toContain']('base\x20units'),expect(b[0x0]['amounts']?.['map'](c=>c['key']))['toEqual'](['fund','amount','needed']),expect(b[0x0]['amounts']?.['every'](c=>c['raw']==='100'||c['raw']==='200'||c['raw']==='600'))['toBe'](!![]);}),it('R1\x20flags\x20one\x20EOA\x20controlling\x20a\x20shop\x20and\x20an\x20arbitration\x20service\x20across\x20distinct\x20permissions',()=>{const a=new GB();a['eoa']('0xe1'),a['obj']('0xp1','Permission',{'owner':'0xe1'}),a['obj']('0xp2','Permission',{'owner':'0xe1'}),a['obj']('0xs1','Service',{}),a['obj']('0xa1','Arbitration',{'fee':'0'}),a['edge']('eoa.permission','0xe1','0xp1',{'roleBits':0x3}),a['edge']('eoa.permission','0xe1','0xp2',{'roleBits':0x3}),a['edge']('permission.core_binding','0xp1','0xs1'),a['edge']('permission.core_binding','0xp2','0xa1');const b=runAnalyzers(a['vp'](),{'only':['R1']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['severity'])['toBe']('high');const c=new GB();c['eoa']('0xe1')['obj']('0xp1','Permission',{})['obj']('0xs1','Service',{})['obj']('0xa1','Arbitration',{'fee':'0'}),c['edge']('eoa.permission','0xe1','0xp1',{'roleBits':0x3}),c['edge']('permission.core_binding','0xp1','0xs1'),c['edge']('permission.core_binding','0xp1','0xa1'),expect(runAnalyzers(c['vp'](),{'only':['R1']}))['toHaveLength'](0x0);}),it('R3\x20flags\x20concentrated\x20control\x20of\x20core\x20objects',()=>{const a=new GB();a['eoa']('0xe1')['obj']('0xp1','Permission',{}),a['obj']('0xs1','Service',{})['obj']('0xs2','Service',{})['obj']('0xm1','Machine',{}),a['edge']('eoa.permission','0xe1','0xp1',{'roleBits':0x1});for(const c of['0xs1','0xs2','0xm1'])a['edge']('permission.core_binding','0xp1',c);const b=runAnalyzers(a['vp'](),{'only':['R3']});expect(ids(b))['toEqual'](['R3:0xe1']);}),it('R4\x20flags\x20a\x20unique\x20operator\x20with\x20no\x20backup\x20guard\x20on\x20a\x20terminal-entering\x20forward',()=>{const a=new GB();a['obj']('0xm1','Machine',{'bPublished':!![]}),a['edge']('wf.transition','0xm1::node::paid','0xm1::node::delivered',{'node':'delivered','prevNode':'paid','forward':'go','namedOperator':'alice'});const b=runAnalyzers(a['vp'](),{'only':['R4']});expect(b)['toHaveLength'](0x1);const c=new GB();c['obj']('0xm1','Machine',{'bPublished':!![]}),c['edge']('wf.transition','0xm1::node::paid','0xm1::node::delivered',{'node':'delivered','prevNode':'paid','forward':'go','namedOperator':'alice','guard':'0xg1'}),expect(runAnalyzers(c['vp'](),{'only':['R4']}))['toHaveLength'](0x0);}),it('R5\x20reports\x20window\x20truncations\x20as\x20downgraded\x20meta\x20findings',()=>{const a=new GB()['obj']('0xs1','Service',{})['trunc']('0xs1','service.order',0x1450),b=runAnalyzers(a['vp'](),{'only':['R5']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['confidence'])['toBe']('windowed'),expect(b[0x0]['window'])['toEqual']({'observed':0x1450,'limit':0x1450});});}),describe('analyze\x20—\x20arbitrage\x20rules',()=>{it('A1\x20detects\x20rate-basis\x20mismatch,\x20surplus\x20duplication\x20and\x20missing\x20max',()=>{const a=new GB();a['obj']('0xal1','Allocation',{'allocators':[{'guard':'0xg1','max':null,'sharing':[{'who':'0xa','mode':0x0,'sharing':'100'}]},{'guard':'0xg2','sharing':[{'who':'0xb','mode':0x1,'sharing':'9000'}]},{'guard':'0xg3','sharing':[{'who':'0xc','mode':0x2}]},{'guard':'0xg4','sharing':[{'who':'0xd','mode':0x2}]}]});const b=runAnalyzers(a['vp'](),{'only':['A1']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('9000'),expect(b[0x0]['detail'])['toContain']('max'),expect(b[0x0]['detail'])['toContain']('Surplus');}),it('A2\x20flags\x20transferable\x20fixed\x20long-window\x20discounts\x20without\x20a\x20benchmark',()=>{const a=new GB();a['obj']('0xd1','Discount',{'discount_type':0x1,'benchmark':null,'transferable':!![],'time_start':'0','time_end':String(0x1fn*0x18n*0x3cn*0x3cn*0x3e8n)});const b=runAnalyzers(a['vp'](),{'only':['A2']});expect(b)['toHaveLength'](0x1);const c=new GB();c['obj']('0xd2','Discount',{'discount_type':0x1,'benchmark':null,'transferable':![],'time_start':'0','time_end':String(0x1fn*0x18n*0x3cn*0x3cn*0x3e8n)}),expect(runAnalyzers(c['vp'](),{'only':['A2']}))['toHaveLength'](0x0);}),it('A3\x20flags\x20zero-fee/no-usage-guard\x20arbitration\x20and\x20reports\x20CoinWrapper\x20custody',()=>{const a=new GB();a['obj']('0xa1','Arbitration',{'fee':'0','usage_guard':null,'voting_guard':[]}),a['obj']('0xcw1','Payment',{},'0x2::payment::CoinWrapper<0x2::wow::WOW>');const b=runAnalyzers(a['vp'](),{'only':['A3']});expect(ids(b)['sort']())['toEqual'](['A3:0xa1','A3:coinwrapper']),expect(b['find'](c=>c['id']==='A3:coinwrapper')['detail'])['toContain']('0x2::wow::WOW');});}),describe('analyze\x20—\x20opportunity\x20rules',()=>{it('O1\x20surfaces\x20scarce-presenter\x20demands\x20with\x20structurally\x20matching\x20services',()=>{const a=new GB();a['obj']('0xdm1','Demand',{'guards':[{'guard':'0xg1'}]}),a['edge']('demand.guard','0xdm1','0xg1'),a['obj']('0xs1','Service',{'bPublished':!![]}),a['obj']('0xm1','Machine',{}),a['edge']('service.machine','0xs1','0xm1'),a['edge']('wf.forward_guard','0xm1::node::paid','0xg1');const b=runAnalyzers(a['vp'](),{'only':['O1']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('0xs1'),a['eoa']('0u1')['eoa']('0u2'),a['edge']('demand.presenter','0xdm1','0u1',{'service':'0xs1'}),a['edge']('demand.presenter','0xdm1','0u2',{'service':'0xs1'}),expect(runAnalyzers(a['vp'](),{'only':['O1']}))['toHaveLength'](0x0);}),it('O2\x20reports\x20graph\x20supply/demand\x20density',()=>{const a=new GB();a['obj']('0xs1','Service',{'bPublished':!![],'bPaused':![]}),a['obj']('0xs2','Service',{'bPublished':![]}),a['obj']('0xd1','Demand',{});const b=runAnalyzers(a['vp'](),{'only':['O2']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('2\x20Service(s)'),expect(b[0x0]['detail'])['toContain']('1\x20open\x20demand(s)');}),it('O3\x20lists\x20operator-less\x20forwards\x20as\x20workflow\x20slots',()=>{const a=new GB();a['obj']('0xm1','Machine',{}),a['edge']('wf.transition','0xm1::node::paid','0xm1::node::done',{'node':'done','prevNode':'paid','forward':'auto','namedOperator':null,'permissionIndex':null,'guard':'0xg1'});const b=runAnalyzers(a['vp'](),{'only':['O3']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('paid:auto');});}),describe('analyze\x20—\x20game\x20rules',()=>{it('G1\x20reports\x20all-vote\x20vs\x20weighted\x20structures\x20plus\x20observed\x20case\x20weights',()=>{const a=new GB();a['obj']('0xa1','Arbitration',{'fee':'0','voting_guard':[]}),a['obj']('0xcase1','Arb',{'voted':[{'voter':'0u1','weight':0x1},{'voter':'0u2','weight':0x2}]}),a['edge']('arb.arbitration_service','0xcase1','0xa1');const b=runAnalyzers(a['vp'](),{'only':['G1']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('open\x20to\x20all\x20members'),expect(b[0x0]['detail'])['toContain']('w1x1'),expect(b[0x0]['detail'])['toContain']('w2x1');}),it('G2\x20marks\x20a\x20named-operator\x20forward\x20as\x20a\x20pool-of-one\x20hold-up\x20point',()=>{const a=new GB();a['obj']('0xm1','Machine',{}),a['edge']('wf.transition','0xm1::node::paid','0xm1::node::done',{'node':'done','prevNode':'paid','forward':'sign','namedOperator':'bob'});const b=runAnalyzers(a['vp'](),{'only':['G2']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['id'])['toContain']('paid:sign');}),it('G3\x20emits\x20the\x20relief\x20parameter\x20matrix\x20for\x20every\x20arbitration\x20service',()=>{const a=new GB();a['obj']('0xa1','Arbitration',{'fee':'5','usage_guard':'0xg1','voting_guard':[{'guard':'0xg2'}]});const b=runAnalyzers(a['vp'](),{'only':['G3']});expect(b)['toHaveLength'](0x1),expect(b[0x0]['detail'])['toContain']('fee=5'),expect(b[0x0]['detail'])['toContain']('30-day');});}),describe('analyze\x20—\x20anti-cheat\x20rules\x20(AC1-AC4)',()=>{function a(c,d,e,f){c['eoa'](d),c['edge']('eoa.permission',d,e,{'roleBits':0x1|0x2}),c['edge']('permission.core_binding',e,f);}function b(c,d,e,f){c['obj'](e,'Order',f),c['edge']('service.order',d,e,undefined,'bounded_window'),c['edge']('order.builder',e,String(f['builder']));}it('AC1\x20flags\x20window\x20orders\x20whose\x20buyer\x20controls\x20the\x20selling\x20Service',()=>{const c=new GB();c['obj']('0xs1','Service',{'bPublished':!![],'machine':'0xm1'}),a(c,'0u1','0p1','0xs1'),b(c,'0xs1','0o1',{'builder':'0u1','service':'0xs1','amount':'100'});const d=runAnalyzers(c['vp'](),{'only':['AC1']});expect(d)['toHaveLength'](0x1),expect(d[0x0]['severity'])['toBe']('high'),expect(d[0x0]['confidence'])['toBe']('windowed'),expect(d[0x0]['id'])['toContain']('0o1');const e=new GB();e['obj']('0xs1','Service',{'bPublished':!![],'machine':'0xm1'}),a(e,'0u1','0p1','0xs1'),b(e,'0xs1','0o1',{'builder':'0u2','service':'0xs1','amount':'100'}),expect(runAnalyzers(e['vp'](),{'only':['AC1']}))['toEqual']([]);}),it('AC2\x20flags\x20reciprocal\x20buying\x20between\x20two\x20controlled\x20Services',()=>{const c=new GB();c['obj']('0xs1','Service',{'bPublished':!![],'machine':'0xm1'}),c['obj']('0xs2','Service',{'bPublished':!![],'machine':'0xm2'}),a(c,'0u1','0p1','0xs1'),a(c,'0u2','0p2','0xs2'),b(c,'0xs1','0o1',{'builder':'0u2','service':'0xs1','amount':'100'}),b(c,'0xs2','0o2',{'builder':'0u1','service':'0xs2','amount':'100'});const d=runAnalyzers(c['vp'](),{'only':['AC2']});expect(d)['toHaveLength'](0x1),expect(d[0x0]['severity'])['toBe']('medium'),expect(d[0x0]['id'])['toContain']('0o1'),expect(d[0x0]['id'])['toContain']('0o2');}),it('AC3\x20flags\x20completed\x20positive-amount\x20orders\x20without\x20Allocation,\x20but\x20not\x20zero-amount\x20orders',()=>{const c=new GB();c['obj']('0xs1','Service',{'bPublished':!![],'machine':'0xm1'}),a(c,'0u1','0p1','0xs1'),b(c,'0xs1','0opaid',{'builder':'0u9','service':'0xs1','amount':'100'}),b(c,'0xs1','0ofree',{'builder':'0u8','service':'0xs1','amount':'0'});const d=runAnalyzers(c['vp'](),{'only':['AC3']});expect(d)['toHaveLength'](0x1),expect(d[0x0]['id'])['toContain']('0opaid'),expect(d[0x0]['id'])['not']['toContain']('0ofree'),c['edge']('order.allocation','0opaid','0al1'),expect(runAnalyzers(c['vp'](),{'only':['AC3']}))['toEqual']([]);}),it('AC4\x20surfaces\x20shell-merchant\x20shapes\x20only\x20for\x20published\x20Services',()=>{const c=new GB();c['obj']('0xs1','Service',{'bPublished':!![],'arbitrations':[],'compensation_fund':'0'});const d=runAnalyzers(c['vp'](),{'only':['AC4']});expect(ids(d)['sort']())['toEqual'](['AC4:0xs1:shell_no_arbitration','AC4:0xs1:shell_no_machine']['sort']());const e=new GB();e['obj']('0xs2','Service',{'bPublished':!![],'arbitrations':[],'compensation_fund':'500'});const f=runAnalyzers(e['vp'](),{'only':['AC4']});expect(f['map'](h=>h['severity'])['sort']())['toEqual'](['high','low','medium']['sort']());const g=new GB();g['obj']('0xs3','Service',{'bPublished':![],'arbitrations':[],'compensation_fund':'500'}),expect(runAnalyzers(g['vp'](),{'only':['AC4']}))['toEqual']([]);});});
|
|
@@ -62,6 +62,7 @@ export interface EdgeSchema {
|
|
|
62
62
|
maxHops?: number;
|
|
63
63
|
label: string;
|
|
64
64
|
}
|
|
65
|
+
export declare const EDGE_ID_REPOSITORY_POLICY_GUARD = "repository.policy_guard";
|
|
65
66
|
export declare const EDGE_SCHEMAS: EdgeSchema[];
|
|
66
67
|
export declare const EDGE_SCHEMA_BY_ID: Map<string, EdgeSchema>;
|
|
67
68
|
export declare function outgoingSchemaIds(sourceType: string): string[];
|