@wowok/agent-mcp 2.4.3 → 2.5.1
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/runtime.d.ts +4 -0
- package/dist/config/runtime.js +29 -5
- package/dist/harness/auto-escalation.d.ts +27 -0
- package/dist/harness/auto-escalation.js +68 -0
- package/dist/index.js +21 -0
- package/dist/knowledge/allocation-confirm.d.ts +115 -0
- package/dist/knowledge/allocation-confirm.js +534 -0
- package/dist/knowledge/allocation-context.d.ts +58 -0
- package/dist/knowledge/allocation-context.js +249 -0
- package/dist/knowledge/allocation-ledger.d.ts +67 -0
- package/dist/knowledge/allocation-ledger.js +463 -0
- package/dist/knowledge/allocation-puzzle.d.ts +135 -0
- package/dist/knowledge/allocation-puzzle.js +298 -0
- package/dist/knowledge/allocation-risk.d.ts +78 -0
- package/dist/knowledge/allocation-risk.js +568 -0
- package/dist/knowledge/allocation-templates.d.ts +38 -0
- package/dist/knowledge/allocation-templates.js +970 -0
- package/dist/knowledge/allocation-translation.d.ts +72 -0
- package/dist/knowledge/allocation-translation.js +585 -0
- package/dist/knowledge/arb-risk.d.ts +37 -0
- package/dist/knowledge/arb-risk.js +210 -0
- package/dist/knowledge/arbitration-confirm.d.ts +135 -0
- package/dist/knowledge/arbitration-confirm.js +559 -0
- package/dist/knowledge/arbitration-context.d.ts +81 -0
- package/dist/knowledge/arbitration-context.js +505 -0
- package/dist/knowledge/arbitration-ledger.d.ts +62 -0
- package/dist/knowledge/arbitration-ledger.js +521 -0
- package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
- package/dist/knowledge/arbitration-puzzle.js +304 -0
- package/dist/knowledge/arbitration-risk.d.ts +112 -0
- package/dist/knowledge/arbitration-risk.js +433 -0
- package/dist/knowledge/arbitration-templates.d.ts +38 -0
- package/dist/knowledge/arbitration-templates.js +276 -0
- package/dist/knowledge/arbitration-translation.d.ts +91 -0
- package/dist/knowledge/arbitration-translation.js +487 -0
- package/dist/knowledge/bridge-risk.d.ts +36 -0
- package/dist/knowledge/bridge-risk.js +263 -0
- package/dist/knowledge/contact-risk.d.ts +32 -0
- package/dist/knowledge/contact-risk.js +200 -0
- package/dist/knowledge/demand-confirm.d.ts +32 -0
- package/dist/knowledge/demand-confirm.js +206 -0
- package/dist/knowledge/demand-risk.d.ts +30 -0
- package/dist/knowledge/demand-risk.js +240 -0
- package/dist/knowledge/demand-translation.d.ts +55 -0
- package/dist/knowledge/demand-translation.js +354 -0
- package/dist/knowledge/deployment-scanner.d.ts +63 -0
- package/dist/knowledge/deployment-scanner.js +762 -0
- package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
- package/dist/knowledge/examples-scanner-cli.js +26 -0
- package/dist/knowledge/examples-scanner.d.ts +121 -0
- package/dist/knowledge/examples-scanner.js +825 -0
- package/dist/knowledge/flywheel-loop.d.ts +3 -0
- package/dist/knowledge/flywheel-loop.js +32 -3
- package/dist/knowledge/glossary.js +3 -1
- package/dist/knowledge/guard-confirm.d.ts +86 -0
- package/dist/knowledge/guard-confirm.js +406 -0
- package/dist/knowledge/guard-context.d.ts +56 -0
- package/dist/knowledge/guard-context.js +287 -0
- package/dist/knowledge/guard-design-patterns.d.ts +37 -0
- package/dist/knowledge/guard-design-patterns.js +257 -0
- package/dist/knowledge/guard-puzzle.js +3 -2
- package/dist/knowledge/guard-risk.d.ts +1 -1
- package/dist/knowledge/guard-risk.js +12 -14
- package/dist/knowledge/guard-templates.js +1 -1
- package/dist/knowledge/guard-translation.js +6 -5
- package/dist/knowledge/index.d.ts +342 -0
- package/dist/knowledge/index.js +344 -0
- package/dist/knowledge/machine-confirm.d.ts +102 -0
- package/dist/knowledge/machine-confirm.js +559 -0
- package/dist/knowledge/machine-context.d.ts +160 -0
- package/dist/knowledge/machine-context.js +812 -0
- package/dist/knowledge/machine-ledger.d.ts +41 -0
- package/dist/knowledge/machine-ledger.js +315 -0
- package/dist/knowledge/machine-puzzle.d.ts +206 -0
- package/dist/knowledge/machine-puzzle.js +494 -0
- package/dist/knowledge/machine-risk.d.ts +75 -0
- package/dist/knowledge/machine-risk.js +644 -0
- package/dist/knowledge/machine-templates.d.ts +92 -0
- package/dist/knowledge/machine-templates.js +1592 -0
- package/dist/knowledge/machine-topology.d.ts +57 -0
- package/dist/knowledge/machine-topology.js +234 -0
- package/dist/knowledge/machine-translation.d.ts +96 -0
- package/dist/knowledge/machine-translation.js +513 -0
- package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
- package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
- package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
- package/dist/knowledge/mcp-schema-audit.js +772 -0
- package/dist/knowledge/onchain-constants.d.ts +4 -0
- package/dist/knowledge/onchain-constants.js +35 -0
- package/dist/knowledge/order-confirm.d.ts +115 -0
- package/dist/knowledge/order-confirm.js +573 -0
- package/dist/knowledge/order-context.d.ts +66 -0
- package/dist/knowledge/order-context.js +390 -0
- package/dist/knowledge/order-ledger.d.ts +69 -0
- package/dist/knowledge/order-ledger.js +341 -0
- package/dist/knowledge/order-puzzle.d.ts +159 -0
- package/dist/knowledge/order-puzzle.js +255 -0
- package/dist/knowledge/order-risk.d.ts +66 -0
- package/dist/knowledge/order-risk.js +653 -0
- package/dist/knowledge/order-templates.d.ts +50 -0
- package/dist/knowledge/order-templates.js +368 -0
- package/dist/knowledge/order-translation.d.ts +78 -0
- package/dist/knowledge/order-translation.js +550 -0
- package/dist/knowledge/passport-confirm.d.ts +130 -0
- package/dist/knowledge/passport-confirm.js +531 -0
- package/dist/knowledge/passport-context.d.ts +59 -0
- package/dist/knowledge/passport-context.js +306 -0
- package/dist/knowledge/passport-ledger.d.ts +48 -0
- package/dist/knowledge/passport-ledger.js +282 -0
- package/dist/knowledge/passport-puzzle.d.ts +108 -0
- package/dist/knowledge/passport-puzzle.js +333 -0
- package/dist/knowledge/passport-risk.d.ts +70 -0
- package/dist/knowledge/passport-risk.js +450 -0
- package/dist/knowledge/passport-templates.d.ts +40 -0
- package/dist/knowledge/passport-templates.js +568 -0
- package/dist/knowledge/passport-translation.d.ts +68 -0
- package/dist/knowledge/passport-translation.js +516 -0
- package/dist/knowledge/payment-risk.d.ts +33 -0
- package/dist/knowledge/payment-risk.js +182 -0
- package/dist/knowledge/permission-confirm.d.ts +110 -0
- package/dist/knowledge/permission-confirm.js +426 -0
- package/dist/knowledge/permission-context.d.ts +58 -0
- package/dist/knowledge/permission-context.js +224 -0
- package/dist/knowledge/permission-ledger.d.ts +38 -0
- package/dist/knowledge/permission-ledger.js +403 -0
- package/dist/knowledge/permission-puzzle.d.ts +122 -0
- package/dist/knowledge/permission-puzzle.js +173 -0
- package/dist/knowledge/permission-risk.d.ts +76 -0
- package/dist/knowledge/permission-risk.js +411 -0
- package/dist/knowledge/permission-templates.d.ts +38 -0
- package/dist/knowledge/permission-templates.js +234 -0
- package/dist/knowledge/permission-translation.d.ts +57 -0
- package/dist/knowledge/permission-translation.js +350 -0
- package/dist/knowledge/personal-risk.d.ts +36 -0
- package/dist/knowledge/personal-risk.js +212 -0
- package/dist/knowledge/progress-confirm.d.ts +108 -0
- package/dist/knowledge/progress-confirm.js +456 -0
- package/dist/knowledge/progress-context.d.ts +123 -0
- package/dist/knowledge/progress-context.js +452 -0
- package/dist/knowledge/progress-ledger.d.ts +63 -0
- package/dist/knowledge/progress-ledger.js +327 -0
- package/dist/knowledge/progress-puzzle.d.ts +82 -0
- package/dist/knowledge/progress-puzzle.js +219 -0
- package/dist/knowledge/progress-risk.d.ts +74 -0
- package/dist/knowledge/progress-risk.js +461 -0
- package/dist/knowledge/progress-templates.d.ts +38 -0
- package/dist/knowledge/progress-templates.js +228 -0
- package/dist/knowledge/progress-translation.d.ts +52 -0
- package/dist/knowledge/progress-translation.js +401 -0
- package/dist/knowledge/proof-confirm.d.ts +31 -0
- package/dist/knowledge/proof-confirm.js +187 -0
- package/dist/knowledge/proof-risk.d.ts +33 -0
- package/dist/knowledge/proof-risk.js +207 -0
- package/dist/knowledge/proof-translation.d.ts +52 -0
- package/dist/knowledge/proof-translation.js +283 -0
- package/dist/knowledge/registrar-risk.d.ts +34 -0
- package/dist/knowledge/registrar-risk.js +217 -0
- package/dist/knowledge/repository-confirm.d.ts +36 -0
- package/dist/knowledge/repository-confirm.js +242 -0
- package/dist/knowledge/repository-risk.d.ts +40 -0
- package/dist/knowledge/repository-risk.js +312 -0
- package/dist/knowledge/repository-translation.d.ts +58 -0
- package/dist/knowledge/repository-translation.js +422 -0
- package/dist/knowledge/resource-risk.d.ts +32 -0
- package/dist/knowledge/resource-risk.js +157 -0
- package/dist/knowledge/reward-confirm.d.ts +113 -0
- package/dist/knowledge/reward-confirm.js +496 -0
- package/dist/knowledge/reward-context.d.ts +127 -0
- package/dist/knowledge/reward-context.js +504 -0
- package/dist/knowledge/reward-ledger.d.ts +96 -0
- package/dist/knowledge/reward-ledger.js +502 -0
- package/dist/knowledge/reward-puzzle.d.ts +97 -0
- package/dist/knowledge/reward-puzzle.js +288 -0
- package/dist/knowledge/reward-risk.d.ts +84 -0
- package/dist/knowledge/reward-risk.js +545 -0
- package/dist/knowledge/reward-translation.d.ts +58 -0
- package/dist/knowledge/reward-translation.js +501 -0
- package/dist/knowledge/safety-rules.js +11 -3
- package/dist/knowledge/scenario-modes.d.ts +53 -0
- package/dist/knowledge/scenario-modes.js +302 -0
- package/dist/knowledge/service-confirm.d.ts +152 -0
- package/dist/knowledge/service-confirm.js +699 -0
- package/dist/knowledge/service-context.d.ts +66 -0
- package/dist/knowledge/service-context.js +403 -0
- package/dist/knowledge/service-ledger.d.ts +71 -0
- package/dist/knowledge/service-ledger.js +609 -0
- package/dist/knowledge/service-puzzle.d.ts +158 -0
- package/dist/knowledge/service-puzzle.js +236 -0
- package/dist/knowledge/service-risk.d.ts +108 -0
- package/dist/knowledge/service-risk.js +615 -0
- package/dist/knowledge/service-templates.d.ts +39 -0
- package/dist/knowledge/service-templates.js +418 -0
- package/dist/knowledge/service-translation.d.ts +103 -0
- package/dist/knowledge/service-translation.js +622 -0
- package/dist/knowledge/tools-reference.d.ts +17 -0
- package/dist/knowledge/tools-reference.js +151 -0
- package/dist/knowledge/treasury-confirm.d.ts +133 -0
- package/dist/knowledge/treasury-confirm.js +512 -0
- package/dist/knowledge/treasury-context.d.ts +64 -0
- package/dist/knowledge/treasury-context.js +363 -0
- package/dist/knowledge/treasury-ledger.d.ts +42 -0
- package/dist/knowledge/treasury-ledger.js +300 -0
- package/dist/knowledge/treasury-puzzle.d.ts +163 -0
- package/dist/knowledge/treasury-puzzle.js +216 -0
- package/dist/knowledge/treasury-risk.d.ts +86 -0
- package/dist/knowledge/treasury-risk.js +440 -0
- package/dist/knowledge/treasury-templates.d.ts +38 -0
- package/dist/knowledge/treasury-templates.js +316 -0
- package/dist/knowledge/treasury-translation.d.ts +78 -0
- package/dist/knowledge/treasury-translation.js +498 -0
- package/dist/knowledge/util-risk.d.ts +30 -0
- package/dist/knowledge/util-risk.js +135 -0
- package/dist/project/business-puzzle.d.ts +47 -0
- package/dist/project/business-puzzle.js +372 -0
- package/dist/project/deployment-doc.d.ts +61 -0
- package/dist/project/deployment-doc.js +432 -0
- package/dist/project/risk-aggregator.d.ts +50 -0
- package/dist/project/risk-aggregator.js +280 -0
- package/dist/project/substep-trace.d.ts +130 -0
- package/dist/project/substep-trace.js +332 -0
- package/dist/schema/call/allocation.d.ts +34 -34
- package/dist/schema/call/arbitration.d.ts +141 -141
- package/dist/schema/call/base.d.ts +386 -386
- package/dist/schema/call/base.js +3 -3
- package/dist/schema/call/bridge-handler.d.ts +5 -2
- package/dist/schema/call/bridge.d.ts +159 -159
- package/dist/schema/call/contact.d.ts +110 -110
- package/dist/schema/call/demand.d.ts +76 -76
- package/dist/schema/call/handler.d.ts +2 -3
- package/dist/schema/call/handler.js +1 -1
- package/dist/schema/call/machine.d.ts +58 -58
- package/dist/schema/call/order.d.ts +98 -110
- package/dist/schema/call/permission-handler.d.ts +5 -0
- package/dist/schema/call/permission-handler.js +54 -0
- package/dist/schema/call/permission.d.ts +108 -108
- package/dist/schema/call/personal.d.ts +14 -14
- package/dist/schema/call/progress.d.ts +57 -72
- package/dist/schema/call/progress.js +7 -4
- package/dist/schema/call/proof.d.ts +18 -18
- package/dist/schema/call/proof.js +12 -7
- package/dist/schema/call/repository.d.ts +154 -154
- package/dist/schema/call/reward.d.ts +55 -55
- package/dist/schema/call/service.d.ts +231 -231
- package/dist/schema/call/treasury.d.ts +93 -93
- package/dist/schema/config/index.d.ts +178 -5
- package/dist/schema/config/index.js +52 -1
- package/dist/schema/local/index.d.ts +3554 -836
- package/dist/schema/local/index.js +2 -1
- package/dist/schema/messenger/index.d.ts +162 -162
- package/dist/schema/operations.d.ts +1058 -1074
- package/dist/schema/operations.js +7 -1
- package/dist/schema/project/index.d.ts +1412 -6
- package/dist/schema/project/index.js +441 -3
- package/dist/schema/query/index.d.ts +672 -672
- package/dist/schema/schema-query/index.d.ts +23 -3
- package/dist/schema/schema-query/index.js +13 -2
- package/dist/schema/sync-layer4.d.ts +21 -0
- package/dist/schema/sync-layer4.js +261 -0
- package/dist/schema/trust/index.d.ts +26 -26
- package/dist/schemas/account_operation.output.json +718 -0
- package/dist/schemas/config_operation.output.json +173 -0
- package/dist/schemas/index.json +9 -1
- package/dist/schemas/local_info_operation.output.json +718 -0
- package/dist/schemas/local_mark_operation.output.json +718 -0
- package/dist/schemas/onchain_operations.output.json +3 -2
- package/dist/schemas/onchain_operations.schema.json +1809 -336
- package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
- package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
- package/dist/schemas/onchain_operations_contact.schema.json +2 -1
- package/dist/schemas/onchain_operations_demand.schema.json +2 -1
- package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
- package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
- package/dist/schemas/onchain_operations_guard.schema.json +578 -579
- package/dist/schemas/onchain_operations_machine.schema.json +2 -1
- package/dist/schemas/onchain_operations_order.schema.json +13 -9
- package/dist/schemas/onchain_operations_payment.schema.json +0 -514
- package/dist/schemas/onchain_operations_permission.schema.json +0 -514
- package/dist/schemas/onchain_operations_personal.schema.json +0 -514
- package/dist/schemas/onchain_operations_progress.schema.json +14 -10
- package/dist/schemas/onchain_operations_proof.schema.json +699 -0
- package/dist/schemas/onchain_operations_repository.schema.json +2 -1
- package/dist/schemas/onchain_operations_reward.schema.json +2 -1
- package/dist/schemas/onchain_operations_service.schema.json +2 -1
- package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
- package/dist/schemas/onchain_table_data.schema.json +32 -1
- package/dist/schemas/project_operation.output.json +918 -0
- package/dist/schemas/project_operation.schema.json +474 -3
- package/dist/schemas/query_toolkit.output.json +14906 -6
- package/dist/schemas/schema_query.output.json +38 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/handlers/config.d.ts +1 -1
- package/dist/tools/handlers/config.js +21 -18
- package/dist/tools/handlers/file-export.d.ts +2 -2
- package/dist/tools/handlers/local.d.ts +3 -30
- package/dist/tools/handlers/local.js +14 -3
- package/dist/tools/handlers/messenger.d.ts +1 -1
- package/dist/tools/handlers/messenger.js +2 -1
- package/dist/tools/handlers/onchain.d.ts +1 -1
- package/dist/tools/handlers/onchain.js +24 -22
- package/dist/tools/handlers/project.d.ts +1 -1
- package/dist/tools/handlers/project.js +262 -18
- package/dist/tools/handlers/query.d.ts +4 -4
- package/dist/tools/handlers/schema-query.d.ts +1 -1
- package/dist/tools/handlers/schema-query.js +21 -20
- package/dist/tools/handlers/trust.d.ts +1 -1
- package/dist/tools/handlers/trust.js +2 -2
- package/dist/tools/handlers/wip.d.ts +1 -1
- package/dist/tools/handlers/wip.js +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +96 -25
- package/dist/tools/rules-hook.d.ts +1 -1
- package/dist/tools/rules-hook.js +3 -2
- package/dist/tools/shared.d.ts +13 -22
- package/dist/tools/types.d.ts +5 -5
- package/dist/tools/wrap.d.ts +10 -2
- package/dist/tools/wrap.js +212 -0
- package/package.json +3 -3
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { MAX_SHARING_COUNT, MAX_ALLOCATOR_COUNT } from "@wowok/wowok";
|
|
2
|
+
export { MAX_ALLOCATOR_COUNT };
|
|
3
|
+
export const ALLOCATION_MAX_SHARING_COUNT = MAX_SHARING_COUNT;
|
|
4
|
+
export const ALLOCATION_MODE_AMOUNT = 0;
|
|
5
|
+
export const ALLOCATION_MODE_RATE = 1;
|
|
6
|
+
export const ALLOCATION_MODE_SURPLUS = 2;
|
|
7
|
+
export const RATE_TOTAL_FULL = 10000;
|
|
8
|
+
export const ALLOCATION_ERROR_CODES = {
|
|
9
|
+
ERECIPIENT_IDENTIFIER_NOT_ADDRESS: 1,
|
|
10
|
+
EALLOCATOR_COUNT_EXCEEDED: 2,
|
|
11
|
+
ENO_ALLOCATOR: 3,
|
|
12
|
+
ERATE_NOT_10000: 4,
|
|
13
|
+
EMULTIPLE_SURPLUS: 5,
|
|
14
|
+
ERATE_EXCEEDS_10000: 6,
|
|
15
|
+
EINSUFFICIENT_BALANCE: 7,
|
|
16
|
+
EALLOCATORS_EMPTY: 8,
|
|
17
|
+
ENO_PAYMENT_INFO: 9,
|
|
18
|
+
ESHARING_COUNT_EXCEEDED: 10,
|
|
19
|
+
ESHARING_MODE_INVALID: 11,
|
|
20
|
+
EAMOUNT_BELOW_THRESHOLD: 12,
|
|
21
|
+
EAMOUNT_EXCEEDS_MAX: 13,
|
|
22
|
+
};
|
|
23
|
+
export const ORDER_ALLOCATION_ALREADY_SPECIFIED = "E_ALLOCATION_ALREADY_SPECIFIED";
|
|
24
|
+
export const ALLOCATION_SCENES = [
|
|
25
|
+
{
|
|
26
|
+
id: "allocation_standard_three_way_split",
|
|
27
|
+
name: "Standard three-way split (merchant / platform / logistics)",
|
|
28
|
+
trigger_source: "service_order_allocators",
|
|
29
|
+
distribution_strategy: "pure_rate",
|
|
30
|
+
coin_type_note: "All three Treasury objects must use the same Coin<T> type as the Allocation",
|
|
31
|
+
typical_allocator_count: 1,
|
|
32
|
+
sharing_who_types: ["Entity"],
|
|
33
|
+
modes_used: ["Rate"],
|
|
34
|
+
guard_requirement: "required",
|
|
35
|
+
non_zero_threshold: false,
|
|
36
|
+
uses_max: false,
|
|
37
|
+
common_patterns: [
|
|
38
|
+
"Single Allocator, 3 Rate sharing items, sum(rates) === 10000",
|
|
39
|
+
"Each sharing.who=Entity points to a Treasury address",
|
|
40
|
+
"Guard verifies order.service binding (query 1563) to prevent cross-project bypass",
|
|
41
|
+
"Guard verifies progress.current_node === 'Complete'",
|
|
42
|
+
],
|
|
43
|
+
dependencies: ["Service", "Treasury", "Guard", "Order", "Progress", "Machine", "Payment"],
|
|
44
|
+
key_constraints: [
|
|
45
|
+
"F-A-05: sum(rates) === 10000 (pure Rate mode)",
|
|
46
|
+
"Treasury Permission should match Service Permission (R-A-12)",
|
|
47
|
+
"order_allocators immutable after Service publish (R-A-10)",
|
|
48
|
+
],
|
|
49
|
+
recommended_templates: ["T-A-02"],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "allocation_merchant_full_payment",
|
|
53
|
+
name: "Merchant full payment (single recipient, 100%)",
|
|
54
|
+
trigger_source: "service_order_allocators",
|
|
55
|
+
distribution_strategy: "pure_rate",
|
|
56
|
+
coin_type_note: "Simplest configuration — single Treasury or personal address",
|
|
57
|
+
typical_allocator_count: 1,
|
|
58
|
+
sharing_who_types: ["Entity"],
|
|
59
|
+
modes_used: ["Rate"],
|
|
60
|
+
guard_requirement: "single_relaxed",
|
|
61
|
+
non_zero_threshold: false,
|
|
62
|
+
uses_max: false,
|
|
63
|
+
common_patterns: [
|
|
64
|
+
"Single Allocator, 1 Rate sharing = 10000",
|
|
65
|
+
"Guard only verifies order status (no complex conditions)",
|
|
66
|
+
"who=Entity can be either Treasury or personal wallet",
|
|
67
|
+
],
|
|
68
|
+
dependencies: ["Service", "Guard", "Order", "Payment"],
|
|
69
|
+
key_constraints: [
|
|
70
|
+
"Simplest allocation configuration",
|
|
71
|
+
"No multi-party coordination required",
|
|
72
|
+
],
|
|
73
|
+
recommended_templates: ["T-A-01"],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "allocation_refund_first_surplus_to_merchant",
|
|
77
|
+
name: "Refund first + surplus to merchant (Amount + Surplus hybrid)",
|
|
78
|
+
trigger_source: "service_order_allocators",
|
|
79
|
+
distribution_strategy: "amount_plus_surplus",
|
|
80
|
+
coin_type_note: "Refund amount must match Coin<T> precision",
|
|
81
|
+
typical_allocator_count: 1,
|
|
82
|
+
sharing_who_types: ["Entity"],
|
|
83
|
+
modes_used: ["Amount", "Surplus"],
|
|
84
|
+
guard_requirement: "required",
|
|
85
|
+
non_zero_threshold: true,
|
|
86
|
+
uses_max: false,
|
|
87
|
+
common_patterns: [
|
|
88
|
+
"Single Allocator, 2 sharing items",
|
|
89
|
+
"sharing[0]: Amount=refund_value, who=Entity(customer_address)",
|
|
90
|
+
"sharing[1]: Surplus, who=Entity(merchant_treasury)",
|
|
91
|
+
"fix = refund_value (cached Amount sum)",
|
|
92
|
+
"threshold = refund_value (ensure sufficient balance for Amount)",
|
|
93
|
+
],
|
|
94
|
+
dependencies: ["Service", "Treasury", "Guard", "Order", "Payment"],
|
|
95
|
+
key_constraints: [
|
|
96
|
+
"F-A-04: at most 1 Surplus per Allocator",
|
|
97
|
+
"F-A-07: fix >= threshold (Amount sum must cover threshold)",
|
|
98
|
+
"fix must precisely match the refund amount",
|
|
99
|
+
],
|
|
100
|
+
recommended_templates: ["T-A-03"],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "allocation_treasury_personal_alternatives",
|
|
104
|
+
name: "Treasury + Personal alternative strategies (caller-specified guard)",
|
|
105
|
+
trigger_source: "service_order_allocators",
|
|
106
|
+
distribution_strategy: "first_match_alternatives",
|
|
107
|
+
coin_type_note: "Both target addresses must accept the same Coin<T>",
|
|
108
|
+
typical_allocator_count: 2,
|
|
109
|
+
sharing_who_types: ["Entity"],
|
|
110
|
+
modes_used: ["Rate"],
|
|
111
|
+
guard_requirement: "multiple_unique",
|
|
112
|
+
non_zero_threshold: false,
|
|
113
|
+
uses_max: false,
|
|
114
|
+
common_patterns: [
|
|
115
|
+
"2 Allocators, each with 1 Rate=10000 sharing",
|
|
116
|
+
"Allocator[0]: guard=guard_treasury, who=Entity(treasury_address)",
|
|
117
|
+
"Allocator[1]: guard=guard_personal, who=Entity(personal_address)",
|
|
118
|
+
"Two Guard objects must be different addresses (R-A-11)",
|
|
119
|
+
"caller-specified guard: caller selects Treasury or Personal path via alloc_by_guard; passport::result_for_guard hard-validates (failure aborts with E_VERIFY_FAILED; caller must switch guard and retry)",
|
|
120
|
+
],
|
|
121
|
+
dependencies: ["Service", "Treasury", "Guard", "Order", "Payment"],
|
|
122
|
+
key_constraints: [
|
|
123
|
+
"F-A-14: allocators[].guard must be unique",
|
|
124
|
+
"Treasury Permission should match Service Permission (R-A-12)",
|
|
125
|
+
"Guard A and Guard B may share root/table but must differ in description",
|
|
126
|
+
],
|
|
127
|
+
recommended_templates: ["T-A-04"],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: "allocation_tiered_by_order_amount",
|
|
131
|
+
name: "Tiered split by order amount (multi-Allocator amount-threshold switch)",
|
|
132
|
+
trigger_source: "service_order_allocators",
|
|
133
|
+
distribution_strategy: "tiered_by_amount",
|
|
134
|
+
coin_type_note: "Amount threshold uses Coin<T> smallest unit (e.g. MIST for WOW)",
|
|
135
|
+
typical_allocator_count: 2,
|
|
136
|
+
sharing_who_types: ["Entity"],
|
|
137
|
+
modes_used: ["Rate"],
|
|
138
|
+
guard_requirement: "multiple_unique",
|
|
139
|
+
non_zero_threshold: false,
|
|
140
|
+
uses_max: false,
|
|
141
|
+
common_patterns: [
|
|
142
|
+
"2 Allocators triggered by mutually exclusive Guard conditions",
|
|
143
|
+
"Allocator[0]: guard verifies order.amount < threshold, Rate=10000 to merchant",
|
|
144
|
+
"Allocator[1]: guard verifies order.amount >= threshold, Rate=8000/2000 split",
|
|
145
|
+
"caller-specified guard: caller selects the matching Allocator based on order amount; allocator order is irrelevant",
|
|
146
|
+
"Guard queries order.amount (query 1561)",
|
|
147
|
+
],
|
|
148
|
+
dependencies: ["Service", "Treasury", "Guard", "Order", "Payment"],
|
|
149
|
+
key_constraints: [
|
|
150
|
+
"Guard conditions must be mutually exclusive (R-A-4-02 design clarity)",
|
|
151
|
+
"Caller must select correct guard based on order.amount (no auto-fallback)",
|
|
152
|
+
],
|
|
153
|
+
recommended_templates: ["T-A-05"],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "allocation_dynamic_recipient",
|
|
157
|
+
name: "Multi-role split with dynamic recipient (GuardIdentifier)",
|
|
158
|
+
trigger_source: "service_order_allocators",
|
|
159
|
+
distribution_strategy: "dynamic_recipient",
|
|
160
|
+
coin_type_note: "Passport table must contain address-typed entry at the referenced identifier",
|
|
161
|
+
typical_allocator_count: 1,
|
|
162
|
+
sharing_who_types: ["Entity", "GuardIdentifier"],
|
|
163
|
+
modes_used: ["Rate"],
|
|
164
|
+
guard_requirement: "required",
|
|
165
|
+
non_zero_threshold: false,
|
|
166
|
+
uses_max: false,
|
|
167
|
+
common_patterns: [
|
|
168
|
+
"Single Allocator, 3 Rate sharing items",
|
|
169
|
+
"sharing[0]: Rate=8000, who=Entity(merchant_treasury)",
|
|
170
|
+
"sharing[1]: Rate=1000, who=Entity(platform_treasury)",
|
|
171
|
+
"sharing[2]: Rate=1000, who=GuardIdentifier(0) — resolves from Passport table",
|
|
172
|
+
"Customer submits Passport with referrer address at identifier=0",
|
|
173
|
+
],
|
|
174
|
+
dependencies: ["Service", "Treasury", "Guard", "Passport", "Order", "Payment"],
|
|
175
|
+
key_constraints: [
|
|
176
|
+
"F-A-13: Passport table[identifier] must be address type (else ERECIPIENT_IDENTIFIER_NOT_ADDRESS)",
|
|
177
|
+
"Guard must verify Passport completeness",
|
|
178
|
+
"Customer order must include Passport with referrer address",
|
|
179
|
+
],
|
|
180
|
+
recommended_templates: ["T-A-06"],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: "allocation_arbitration_fees",
|
|
184
|
+
name: "Arbitration fees split (arbitrator / platform)",
|
|
185
|
+
trigger_source: "arbitration_fees",
|
|
186
|
+
distribution_strategy: "pure_rate",
|
|
187
|
+
coin_type_note: "Coin<T> must match Arbitration's fee Coin type",
|
|
188
|
+
typical_allocator_count: 1,
|
|
189
|
+
sharing_who_types: ["Entity"],
|
|
190
|
+
modes_used: ["Rate"],
|
|
191
|
+
guard_requirement: "required",
|
|
192
|
+
non_zero_threshold: false,
|
|
193
|
+
uses_max: false,
|
|
194
|
+
common_patterns: [
|
|
195
|
+
"Triggered by Arbitration.fees_alloc (permission 365) or fees_alloc_with_passport",
|
|
196
|
+
"Single Allocator, 2 Rate sharing items: 8000 arbitrator / 2000 platform",
|
|
197
|
+
"payment_info reuses Arbitration's payment_info",
|
|
198
|
+
"Caller must hold ARBITRATION_FEES_ALLOC=365 permission",
|
|
199
|
+
],
|
|
200
|
+
dependencies: ["Arbitration", "Treasury", "Guard", "Payment"],
|
|
201
|
+
key_constraints: [
|
|
202
|
+
"Independent from Service-order Allocation",
|
|
203
|
+
"Requires ARBITRATION_FEES_ALLOC=365 permission",
|
|
204
|
+
],
|
|
205
|
+
recommended_templates: ["T-A-08"],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: "allocation_refund_to_order",
|
|
209
|
+
name: "Refund Allocator (100% to Order object)",
|
|
210
|
+
trigger_source: "service_order_allocators",
|
|
211
|
+
distribution_strategy: "refund_to_order",
|
|
212
|
+
coin_type_note: "who=Entity must be the Order object address (NOT a personal wallet)",
|
|
213
|
+
typical_allocator_count: 1,
|
|
214
|
+
sharing_who_types: ["Entity"],
|
|
215
|
+
modes_used: ["Rate"],
|
|
216
|
+
guard_requirement: "required",
|
|
217
|
+
non_zero_threshold: false,
|
|
218
|
+
uses_max: false,
|
|
219
|
+
common_patterns: [
|
|
220
|
+
"Single Allocator, 1 Rate=10000 sharing",
|
|
221
|
+
"who=Entity(order_address) — funds flow back to Order, not personal wallet",
|
|
222
|
+
"Guard verifies customer refund request and eligibility",
|
|
223
|
+
"Customer-side risk assessment adds 8-point weight (customer/risk-assessment.ts)",
|
|
224
|
+
],
|
|
225
|
+
dependencies: ["Service", "Guard", "Order", "Payment"],
|
|
226
|
+
key_constraints: [
|
|
227
|
+
"who=Entity MUST be Order object address (not personal address)",
|
|
228
|
+
"Customer due-diligence rewards this configuration (8-point weight)",
|
|
229
|
+
"Refund funds return to Order for downstream handling",
|
|
230
|
+
],
|
|
231
|
+
recommended_templates: ["T-A-07"],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: "allocation_max_capped_retain",
|
|
235
|
+
name: "Max-capped allocation (retain residual balance)",
|
|
236
|
+
trigger_source: "service_order_allocators",
|
|
237
|
+
distribution_strategy: "max_capped",
|
|
238
|
+
coin_type_note: "max field uses Coin<T> smallest unit",
|
|
239
|
+
typical_allocator_count: 1,
|
|
240
|
+
sharing_who_types: ["Entity"],
|
|
241
|
+
modes_used: ["Amount", "Rate"],
|
|
242
|
+
guard_requirement: "required",
|
|
243
|
+
non_zero_threshold: true,
|
|
244
|
+
uses_max: true,
|
|
245
|
+
common_patterns: [
|
|
246
|
+
"Single Allocator with max field set",
|
|
247
|
+
"max triple role: Amount cap + Rate base + Surplus cap",
|
|
248
|
+
"Amount sharing consumes fix; Rate sharing uses (max - fix) as base",
|
|
249
|
+
"Residual balance remains in Allocation for subsequent alloc() calls",
|
|
250
|
+
],
|
|
251
|
+
dependencies: ["Service", "Treasury", "Guard", "Order", "Payment"],
|
|
252
|
+
key_constraints: [
|
|
253
|
+
"F-A-08: Amount sum <= max (EAMOUNT_EXCEEDS_MAX)",
|
|
254
|
+
"max - fix becomes Rate base (NOT balance - fix)",
|
|
255
|
+
"Residual balance may be claimed by re-triggering alloc()",
|
|
256
|
+
],
|
|
257
|
+
recommended_templates: [],
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
id: "allocation_multi_node_trigger",
|
|
261
|
+
name: "Multi-Machine-node triggered allocation (Complete / Refund / Lost)",
|
|
262
|
+
trigger_source: "service_order_allocators",
|
|
263
|
+
distribution_strategy: "multi_node_trigger",
|
|
264
|
+
coin_type_note: "All Allocators share the same Allocation's Coin<T>",
|
|
265
|
+
typical_allocator_count: 3,
|
|
266
|
+
sharing_who_types: ["Entity"],
|
|
267
|
+
modes_used: ["Rate"],
|
|
268
|
+
guard_requirement: "multiple_unique",
|
|
269
|
+
non_zero_threshold: false,
|
|
270
|
+
uses_max: false,
|
|
271
|
+
common_patterns: [
|
|
272
|
+
"3 Allocators mapped to Machine terminal nodes (Complete/Refund/Lost)",
|
|
273
|
+
"Each Allocator's Guard verifies progress.current_node == <node_name>",
|
|
274
|
+
"Mutually exclusive Guard conditions (only one terminal node active at a time)",
|
|
275
|
+
"Machine.required_allocators[] describes each trigger_node mapping",
|
|
276
|
+
],
|
|
277
|
+
dependencies: ["Service", "Treasury", "Guard", "Order", "Progress", "Machine", "Payment"],
|
|
278
|
+
key_constraints: [
|
|
279
|
+
"Guard conditions must be mutually exclusive",
|
|
280
|
+
"Sequence-sensitive: business-flow order",
|
|
281
|
+
"Machine.required_allocators[trigger_node] must map to Allocator indices",
|
|
282
|
+
],
|
|
283
|
+
recommended_templates: [],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
id: "allocation_standalone_periodic_split",
|
|
287
|
+
name: "Standalone periodic split (investment dividends / shared income)",
|
|
288
|
+
trigger_source: "standalone",
|
|
289
|
+
distribution_strategy: "periodic_split",
|
|
290
|
+
coin_type_note: "Coin<T> must match the asset being distributed (e.g. profit token)",
|
|
291
|
+
typical_allocator_count: 1,
|
|
292
|
+
sharing_who_types: ["Entity"],
|
|
293
|
+
modes_used: ["Rate"],
|
|
294
|
+
guard_requirement: "required",
|
|
295
|
+
non_zero_threshold: false,
|
|
296
|
+
uses_max: false,
|
|
297
|
+
common_patterns: [
|
|
298
|
+
"Single Allocator, N Rate sharing items, sum(rates) === 10000",
|
|
299
|
+
"Each sharing.who=Entity points to a beneficiary wallet (not Treasury)",
|
|
300
|
+
"Guard verifies time-based trigger (e.g. context(Clock).timestamp >= next_release) or signer authorization",
|
|
301
|
+
"User calls receive() to deposit funds, then alloc() to trigger distribution",
|
|
302
|
+
"No Service/Order/Progress/Machine context required",
|
|
303
|
+
],
|
|
304
|
+
dependencies: ["Treasury", "Guard", "Payment"],
|
|
305
|
+
key_constraints: [
|
|
306
|
+
"F-A-05: sum(rates) === 10000 (pure Rate mode)",
|
|
307
|
+
"R-A-3-04: standalone mode has no Service-layer access control — Guard + Passport MUST be sufficient",
|
|
308
|
+
"Caller is fully responsible for receive → alloc lifecycle (no auto-trigger)",
|
|
309
|
+
"Guard should bind Signer to prevent unauthorized alloc() calls",
|
|
310
|
+
],
|
|
311
|
+
recommended_templates: ["T-A-09"],
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
id: "allocation_standalone_vesting",
|
|
315
|
+
name: "Standalone vesting release (time-locked multi-stage unlock)",
|
|
316
|
+
trigger_source: "standalone",
|
|
317
|
+
distribution_strategy: "time_locked_vesting",
|
|
318
|
+
coin_type_note: "Coin<T> must match the vested asset (e.g. locked team tokens)",
|
|
319
|
+
typical_allocator_count: 3,
|
|
320
|
+
sharing_who_types: ["Entity"],
|
|
321
|
+
modes_used: ["Amount", "Rate", "Surplus"],
|
|
322
|
+
guard_requirement: "multiple_unique",
|
|
323
|
+
non_zero_threshold: true,
|
|
324
|
+
uses_max: true,
|
|
325
|
+
common_patterns: [
|
|
326
|
+
"N Allocators, each mapped to a vesting stage (e.g. 25% at month 12, 25% at month 24, 50% surplus at month 36)",
|
|
327
|
+
"Each Allocator's Guard verifies context(Clock).timestamp >= stage_unlock_time",
|
|
328
|
+
"Amount sharing per stage with max field capping the cumulative release",
|
|
329
|
+
"Final Allocator uses Surplus to drain remaining balance after last vesting stage",
|
|
330
|
+
"Mutually exclusive Guard conditions (only one stage active at a time, based on timestamp)",
|
|
331
|
+
"User calls receive() to deposit locked tokens, then alloc() at each vesting milestone",
|
|
332
|
+
],
|
|
333
|
+
dependencies: ["Treasury", "Guard", "Passport", "Payment"],
|
|
334
|
+
key_constraints: [
|
|
335
|
+
"F-A-04: at most 1 Surplus per Allocator (final stage uses Surplus to drain remainder)",
|
|
336
|
+
"F-A-08: Amount sum <= max (EAMOUNT_EXCEEDS_MAX)",
|
|
337
|
+
"R-A-3-04: standalone mode has no Service-layer access control — Guard time-lock MUST be enforced",
|
|
338
|
+
"Guard conditions must be mutually exclusive by timestamp (R-A-4-02)",
|
|
339
|
+
"Caller must wait for time-lock expiry before alloc() succeeds; otherwise alloc() silently returns (R-A-4-01)",
|
|
340
|
+
],
|
|
341
|
+
recommended_templates: ["T-A-10"],
|
|
342
|
+
},
|
|
343
|
+
];
|
|
344
|
+
export const ALLOCATION_LEDGER_VERSION = "1.0.0";
|
|
345
|
+
export function getScenesByTriggerSource(source) {
|
|
346
|
+
return ALLOCATION_SCENES.filter(s => s.trigger_source === source);
|
|
347
|
+
}
|
|
348
|
+
export function getScenesByMode(mode) {
|
|
349
|
+
return ALLOCATION_SCENES.filter(s => s.modes_used.includes(mode));
|
|
350
|
+
}
|
|
351
|
+
export function getScenesByStrategy(strategy) {
|
|
352
|
+
return ALLOCATION_SCENES.filter(s => s.distribution_strategy === strategy);
|
|
353
|
+
}
|
|
354
|
+
export function findSceneById(id) {
|
|
355
|
+
return ALLOCATION_SCENES.find(s => s.id === id);
|
|
356
|
+
}
|
|
357
|
+
export function inferSceneFromIntent(intent) {
|
|
358
|
+
const lower = intent.toLowerCase();
|
|
359
|
+
if (lower.includes("arbitration") || lower.includes("fees_alloc")) {
|
|
360
|
+
return findSceneById("allocation_arbitration_fees");
|
|
361
|
+
}
|
|
362
|
+
if (lower.includes("standalone") || lower.includes("periodic split") ||
|
|
363
|
+
lower.includes("investment dividend") || lower.includes("shared income") || lower.includes("dividend")) {
|
|
364
|
+
return findSceneById("allocation_standalone_periodic_split");
|
|
365
|
+
}
|
|
366
|
+
if (lower.includes("vesting") || lower.includes("time-lock") || lower.includes("unlock period") ||
|
|
367
|
+
lower.includes("locked release") || lower.includes("token unlock")) {
|
|
368
|
+
return findSceneById("allocation_standalone_vesting");
|
|
369
|
+
}
|
|
370
|
+
if (lower.includes("refund")) {
|
|
371
|
+
if (lower.includes("order") || lower.includes("100%")) {
|
|
372
|
+
return findSceneById("allocation_refund_to_order");
|
|
373
|
+
}
|
|
374
|
+
if (lower.includes("surplus") || lower.includes("merchant")) {
|
|
375
|
+
return findSceneById("allocation_refund_first_surplus_to_merchant");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (lower.includes("alternative") || lower.includes("priority") || (lower.includes("treasury") && lower.includes("personal"))) {
|
|
379
|
+
return findSceneById("allocation_treasury_personal_alternatives");
|
|
380
|
+
}
|
|
381
|
+
if (lower.includes("tiered") || lower.includes("threshold switch")) {
|
|
382
|
+
return findSceneById("allocation_tiered_by_order_amount");
|
|
383
|
+
}
|
|
384
|
+
if (lower.includes("dynamic recipient") || lower.includes("referrer") || lower.includes("guardidentifier")) {
|
|
385
|
+
return findSceneById("allocation_dynamic_recipient");
|
|
386
|
+
}
|
|
387
|
+
if (lower.includes("retain") || lower.includes("max")) {
|
|
388
|
+
return findSceneById("allocation_max_capped_retain");
|
|
389
|
+
}
|
|
390
|
+
if (lower.includes("multi-node") || lower.includes("multi machine") || lower.includes("multi_node")) {
|
|
391
|
+
return findSceneById("allocation_multi_node_trigger");
|
|
392
|
+
}
|
|
393
|
+
const roleCount = (intent.match(/%/g) || []).length;
|
|
394
|
+
if (roleCount <= 1) {
|
|
395
|
+
return findSceneById("allocation_merchant_full_payment");
|
|
396
|
+
}
|
|
397
|
+
if (roleCount >= 2) {
|
|
398
|
+
return findSceneById("allocation_standard_three_way_split");
|
|
399
|
+
}
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
export function getAllScenes() {
|
|
403
|
+
return [...ALLOCATION_SCENES];
|
|
404
|
+
}
|
|
405
|
+
export function getScenesCount() {
|
|
406
|
+
return ALLOCATION_SCENES.length;
|
|
407
|
+
}
|
|
408
|
+
export function allocationModeToNumber(mode) {
|
|
409
|
+
switch (mode) {
|
|
410
|
+
case "Amount": return ALLOCATION_MODE_AMOUNT;
|
|
411
|
+
case "Rate": return ALLOCATION_MODE_RATE;
|
|
412
|
+
case "Surplus": return ALLOCATION_MODE_SURPLUS;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
export function allocationModeFromNumber(n) {
|
|
416
|
+
switch (n) {
|
|
417
|
+
case ALLOCATION_MODE_AMOUNT: return "Amount";
|
|
418
|
+
case ALLOCATION_MODE_RATE: return "Rate";
|
|
419
|
+
case ALLOCATION_MODE_SURPLUS: return "Surplus";
|
|
420
|
+
default: throw new Error(`Invalid AllocationMode number: ${n}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
export function getRecipientType(who) {
|
|
424
|
+
if ("GuardIdentifier" in who)
|
|
425
|
+
return "GuardIdentifier";
|
|
426
|
+
if ("Entity" in who)
|
|
427
|
+
return "Entity";
|
|
428
|
+
return "Signer";
|
|
429
|
+
}
|
|
430
|
+
export function isSignerRecipient(who) {
|
|
431
|
+
return "Signer" in who;
|
|
432
|
+
}
|
|
433
|
+
export function isEntityRecipient(who) {
|
|
434
|
+
return "Entity" in who;
|
|
435
|
+
}
|
|
436
|
+
export function isGuardIdentifierRecipient(who) {
|
|
437
|
+
return "GuardIdentifier" in who;
|
|
438
|
+
}
|
|
439
|
+
export function getErrorName(code) {
|
|
440
|
+
for (const [name, c] of Object.entries(ALLOCATION_ERROR_CODES)) {
|
|
441
|
+
if (c === code)
|
|
442
|
+
return name;
|
|
443
|
+
}
|
|
444
|
+
return undefined;
|
|
445
|
+
}
|
|
446
|
+
export function getErrorDescription(code) {
|
|
447
|
+
const descriptions = {
|
|
448
|
+
1: "GuardIdentifier resolved value is not an address type",
|
|
449
|
+
2: "Allocator count exceeds MAX_ALLOCATOR_COUNT (100)",
|
|
450
|
+
3: "No Allocator in the allocators vector",
|
|
451
|
+
4: "Pure Rate mode sum != 10000 (no Surplus to absorb remainder)",
|
|
452
|
+
5: "Multiple Surplus sharing in a single Allocator",
|
|
453
|
+
6: "Rate + Surplus sum > 10000",
|
|
454
|
+
7: "balance < threshold (insufficient balance to trigger alloc)",
|
|
455
|
+
8: "allocators.allocators is empty",
|
|
456
|
+
9: "payment_info is None when alloc() is called",
|
|
457
|
+
10: "sharing count exceeds MAX_SHARING_COUNT (100)",
|
|
458
|
+
11: "sharing mode is not 0 (Amount) / 1 (Rate) / 2 (Surplus)",
|
|
459
|
+
12: "Amount sum (fix) < threshold",
|
|
460
|
+
13: "Amount sum (fix) > max",
|
|
461
|
+
};
|
|
462
|
+
return descriptions[code];
|
|
463
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { type AllocationMode, type Recipient, type TriggerSource } from "./allocation-ledger.js";
|
|
2
|
+
export interface AllocationIntentPuzzle {
|
|
3
|
+
action: "create" | "operate" | "query";
|
|
4
|
+
host_context: TriggerSource;
|
|
5
|
+
trigger_condition: string;
|
|
6
|
+
distribution_goal: string;
|
|
7
|
+
failure_conditions: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface AllocationBindingPuzzle {
|
|
10
|
+
coin_type: string;
|
|
11
|
+
host_service?: string;
|
|
12
|
+
host_arbitration?: string;
|
|
13
|
+
bound_order?: string;
|
|
14
|
+
trigger_node?: string;
|
|
15
|
+
guard_objects: string[];
|
|
16
|
+
payment_info_source: "service" | "arbitration" | "custom";
|
|
17
|
+
}
|
|
18
|
+
export interface AllocatorConfig {
|
|
19
|
+
guard: string;
|
|
20
|
+
sharing: {
|
|
21
|
+
who: Recipient;
|
|
22
|
+
sharing: string | bigint;
|
|
23
|
+
mode: AllocationMode;
|
|
24
|
+
}[];
|
|
25
|
+
fix?: string | bigint;
|
|
26
|
+
max?: string | bigint | null;
|
|
27
|
+
}
|
|
28
|
+
export interface AllocatorsConfig {
|
|
29
|
+
description: string;
|
|
30
|
+
threshold: string | bigint;
|
|
31
|
+
allocators: AllocatorConfig[];
|
|
32
|
+
}
|
|
33
|
+
export interface PaymentInfoConfig {
|
|
34
|
+
for_object: string;
|
|
35
|
+
source?: "service" | "arbitration" | "custom";
|
|
36
|
+
}
|
|
37
|
+
export interface AllocationDataSourcePuzzle {
|
|
38
|
+
allocators_config: AllocatorsConfig;
|
|
39
|
+
payment_info: PaymentInfoConfig;
|
|
40
|
+
coin_source: "order_payment" | "arbitration_fees" | "external_deposit";
|
|
41
|
+
}
|
|
42
|
+
export type AllocationOperation = {
|
|
43
|
+
type: "create";
|
|
44
|
+
name: string;
|
|
45
|
+
allocators: AllocatorsConfig;
|
|
46
|
+
coin: string;
|
|
47
|
+
payment_info: PaymentInfoConfig;
|
|
48
|
+
} | {
|
|
49
|
+
type: "receive";
|
|
50
|
+
received_coins: "recently" | {
|
|
51
|
+
received: {
|
|
52
|
+
id: string;
|
|
53
|
+
payment: string;
|
|
54
|
+
}[];
|
|
55
|
+
token_type: string;
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
type: "alloc_by_guard";
|
|
59
|
+
guard: string;
|
|
60
|
+
passport?: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: "query_balance";
|
|
63
|
+
} | {
|
|
64
|
+
type: "query_allocators";
|
|
65
|
+
} | {
|
|
66
|
+
type: "query_payment_history";
|
|
67
|
+
};
|
|
68
|
+
export interface AllocationOperationPuzzle {
|
|
69
|
+
operations: AllocationOperation[];
|
|
70
|
+
}
|
|
71
|
+
export interface AllocationLogicPuzzle {
|
|
72
|
+
alloc_flow: {
|
|
73
|
+
step: 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
74
|
+
action: "pre_check" | "guard_lookup" | "rate_base_calc" | "sharing_distribution" | "surplus_distribution" | "recipient_resolution" | "payment_creation";
|
|
75
|
+
description: string;
|
|
76
|
+
}[];
|
|
77
|
+
guard_matching_strategy: "caller_specified_guard" | "all_match";
|
|
78
|
+
recipient_resolution_rules: {
|
|
79
|
+
recipient_type: "GuardIdentifier" | "Entity" | "Signer";
|
|
80
|
+
resolution_source: "passport_table" | "static_address" | "tx_sender";
|
|
81
|
+
safety_level: "safe" | "dangerous" | "safe_with_guard_binding";
|
|
82
|
+
}[];
|
|
83
|
+
}
|
|
84
|
+
export interface AllocationConstraintChecklist {
|
|
85
|
+
F_A_01_allocator_count_le_100: boolean;
|
|
86
|
+
F_A_02_sharing_count_le_100: boolean;
|
|
87
|
+
F_A_03_sharing_mode_valid: boolean;
|
|
88
|
+
F_A_04_at_most_1_surplus_per_allocator: boolean;
|
|
89
|
+
F_A_05_pure_rate_sum_eq_10000: boolean;
|
|
90
|
+
F_A_06_rate_plus_surplus_sum_le_10000: boolean;
|
|
91
|
+
F_A_07_amount_sum_ge_threshold: boolean;
|
|
92
|
+
F_A_08_amount_sum_le_max: boolean;
|
|
93
|
+
F_A_09_balance_ge_threshold_at_alloc: boolean;
|
|
94
|
+
F_A_10_payment_info_present: boolean;
|
|
95
|
+
F_A_11_allocators_not_empty: boolean;
|
|
96
|
+
F_A_12_order_at_most_1_allocation: boolean;
|
|
97
|
+
F_A_13_guard_identifier_is_address: boolean;
|
|
98
|
+
F_A_14_guard_addresses_unique: boolean;
|
|
99
|
+
F_A_15_order_allocators_immutable_after_publish: boolean;
|
|
100
|
+
}
|
|
101
|
+
export type AllocationPuzzleDimension = "A" | "B" | "C" | "D" | "E" | "F";
|
|
102
|
+
export interface AllocationPuzzle {
|
|
103
|
+
intent?: AllocationIntentPuzzle;
|
|
104
|
+
binding?: AllocationBindingPuzzle;
|
|
105
|
+
data_source?: AllocationDataSourcePuzzle;
|
|
106
|
+
operations?: AllocationOperationPuzzle;
|
|
107
|
+
logic?: AllocationLogicPuzzle;
|
|
108
|
+
constraints?: AllocationConstraintChecklist;
|
|
109
|
+
}
|
|
110
|
+
export interface AllocationPuzzleCompleteness {
|
|
111
|
+
dimensions: AllocationPuzzleDimension[];
|
|
112
|
+
missing: AllocationPuzzleDimension[];
|
|
113
|
+
missing_details: {
|
|
114
|
+
dimension: AllocationPuzzleDimension;
|
|
115
|
+
reason: string;
|
|
116
|
+
}[];
|
|
117
|
+
complete: boolean;
|
|
118
|
+
next_step: string;
|
|
119
|
+
}
|
|
120
|
+
export declare function initPuzzleFromIntent(intent: Partial<AllocationIntentPuzzle>): AllocationPuzzle;
|
|
121
|
+
export declare function checkPuzzleCompleteness(puzzle: AllocationPuzzle): AllocationPuzzleCompleteness;
|
|
122
|
+
export interface AllocationConstraintViolation {
|
|
123
|
+
constraint_id: string;
|
|
124
|
+
severity: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
|
|
125
|
+
message: string;
|
|
126
|
+
current_value?: string | number;
|
|
127
|
+
limit?: string | number;
|
|
128
|
+
related_move_error?: string;
|
|
129
|
+
}
|
|
130
|
+
export declare function validateConstraints(puzzle: AllocationPuzzle): AllocationConstraintViolation[];
|
|
131
|
+
export declare function generateConfirmationText(puzzle: AllocationPuzzle): string;
|
|
132
|
+
export declare function buildDefaultAllocFlow(): AllocationLogicPuzzle["alloc_flow"];
|
|
133
|
+
export declare function buildDefaultRecipientRules(): AllocationLogicPuzzle["recipient_resolution_rules"];
|
|
134
|
+
export declare function buildDefaultLogicPuzzle(): AllocationLogicPuzzle;
|
|
135
|
+
export declare const ALLOCATION_PUZZLE_VERSION = "1.0.0";
|