@wowok/agent-mcp 2.4.3 → 2.5.0
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 +1392 -6
- package/dist/schema/project/index.js +426 -2
- 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 +1802 -313
- 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 +584 -70
- 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 +2 -1
- package/dist/schemas/onchain_operations_permission.schema.json +2 -1
- package/dist/schemas/onchain_operations_personal.schema.json +2 -1
- 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 +879 -0
- package/dist/schemas/project_operation.schema.json +473 -2
- 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 +258 -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 +55 -8
- 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,498 @@
|
|
|
1
|
+
import { isBuiltinTreasuryPermission, getBuiltinPermissionByIndex, findSceneByPermissionIndex, } from "./treasury-ledger.js";
|
|
2
|
+
export const SEMANTIC_TO_SCHEMA_RULES = [
|
|
3
|
+
{
|
|
4
|
+
id: "T-T-01",
|
|
5
|
+
pattern_name: "Create new Treasury",
|
|
6
|
+
semantic_intent: "Create a new Treasury with a Coin type T and associated Permission",
|
|
7
|
+
match_keywords: ["create", "new"],
|
|
8
|
+
schema_fields: ["object (TypeNamedObjectWithPermission)", "description"],
|
|
9
|
+
example_json: {
|
|
10
|
+
object: {
|
|
11
|
+
name: "myteam_treasury",
|
|
12
|
+
type_parameter: "0x2::wow::WOW",
|
|
13
|
+
permission: {
|
|
14
|
+
name: "myteam_treasury_permission",
|
|
15
|
+
description: "Permission for myteam treasury",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
description: "Team treasury for project X funding",
|
|
19
|
+
},
|
|
20
|
+
reverse_explanation: "object must be in OBJECT format (not STRING) for creation; type_parameter is the Coin type T; permission can be new or existing",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "T-T-02",
|
|
24
|
+
pattern_name: "Internal deposit (Permission path)",
|
|
25
|
+
semantic_intent: "Deposit funds to Treasury via Permission authorization",
|
|
26
|
+
match_keywords: ["deposit"],
|
|
27
|
+
schema_fields: ["object (string)", "deposit.coin", "deposit.payment_info"],
|
|
28
|
+
example_json: {
|
|
29
|
+
object: "myteam_treasury",
|
|
30
|
+
deposit: {
|
|
31
|
+
coin: { balance: "1000000000" },
|
|
32
|
+
payment_info: { remark: "Q3 budget allocation", index: 0 },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
reverse_explanation: "deposit.by_external_deposit_guard omitted → Permission path (TREASURY_DEPOSIT=252); coin can be {balance} or {coin_object}",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "T-T-03",
|
|
39
|
+
pattern_name: "Internal withdraw (Permission path, fixed amount)",
|
|
40
|
+
semantic_intent: "Withdraw fixed amount from Treasury via Permission authorization",
|
|
41
|
+
match_keywords: ["withdraw"],
|
|
42
|
+
schema_fields: ["object (string)", "withdraw.amount.fixed", "withdraw.recipient", "withdraw.payment_info"],
|
|
43
|
+
example_json: {
|
|
44
|
+
object: "myteam_treasury",
|
|
45
|
+
withdraw: {
|
|
46
|
+
amount: { fixed: "500000000" },
|
|
47
|
+
recipient: "0xRECIPIENT",
|
|
48
|
+
payment_info: { remark: "Vendor payment", index: 1 },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
reverse_explanation: "withdraw.amount.fixed → Permission path (TREASURY_WITHDRAW=254); amount is fixed u64; irreversible",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "T-T-04",
|
|
55
|
+
pattern_name: "External deposit (Guard + Passport path)",
|
|
56
|
+
semantic_intent: "External user deposits via preset Guard verification (no Permission needed)",
|
|
57
|
+
match_keywords: ["external deposit", "guard deposit"],
|
|
58
|
+
schema_fields: ["object (string)", "deposit.coin", "deposit.by_external_deposit_guard", "deposit.payment_info", "submission (Passport)"],
|
|
59
|
+
example_json: {
|
|
60
|
+
object: "myteam_treasury",
|
|
61
|
+
deposit: {
|
|
62
|
+
coin: { balance: "200000000" },
|
|
63
|
+
by_external_deposit_guard: "deposit_guard_v1",
|
|
64
|
+
payment_info: { remark: "External deposit via guard", index: 2 },
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
reverse_explanation: "deposit.by_external_deposit_guard present → Guard path (NO Permission check); Passport required via submission field; amount may split if coin > guard-specified",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "T-T-05",
|
|
71
|
+
pattern_name: "External withdraw (Guard + Passport path, amount from Guard)",
|
|
72
|
+
semantic_intent: "External user withdraws via preset Guard verification; amount determined by Guard table identifier",
|
|
73
|
+
match_keywords: ["external withdraw", "guard withdraw"],
|
|
74
|
+
schema_fields: ["object (string)", "withdraw.amount.by_external_withdraw_guard", "withdraw.recipient", "withdraw.payment_info", "submission (Passport)"],
|
|
75
|
+
example_json: {
|
|
76
|
+
object: "myteam_treasury",
|
|
77
|
+
withdraw: {
|
|
78
|
+
amount: { by_external_withdraw_guard: "withdraw_guard_v1" },
|
|
79
|
+
recipient: "0xRECIPIENT",
|
|
80
|
+
payment_info: { remark: "External withdraw via guard", index: 3 },
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
reverse_explanation: "withdraw.amount.by_external_withdraw_guard → Guard path (NO Permission check); amount comes from Guard table identifier (u8, required); irreversible",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "T-T-06",
|
|
87
|
+
pattern_name: "Manage external deposit/withdraw Guard (add/set/remove/clear)",
|
|
88
|
+
semantic_intent: "Add, set, remove, or clear external_deposit_guard / external_withdraw_guard lists",
|
|
89
|
+
match_keywords: ["guard add", "guard set", "guard remove", "guard clear"],
|
|
90
|
+
schema_fields: ["object (string)", "external_deposit_guard | external_withdraw_guard"],
|
|
91
|
+
example_json: {
|
|
92
|
+
object: "myteam_treasury",
|
|
93
|
+
external_deposit_guard: {
|
|
94
|
+
op: "add",
|
|
95
|
+
guards: [
|
|
96
|
+
{ guard: "deposit_guard_v1", identifier: 2, store_from_id: null },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
reverse_explanation: "op='add' (upsert) / 'set' (clear+add) / 'remove' (by guard address) / 'clear' (empty list); Permission index 255 (deposit) / 256 (withdraw) required",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "T-T-07",
|
|
104
|
+
pattern_name: "Receive CoinWrapper / owner_receive forward",
|
|
105
|
+
semantic_intent: "Receive CoinWrapper into balance, or forward received objects to Permission owner",
|
|
106
|
+
match_keywords: ["receive", "owner_receive", "forward"],
|
|
107
|
+
schema_fields: ["object (string)", "receive | owner_receive"],
|
|
108
|
+
example_json: {
|
|
109
|
+
object: "myteam_treasury",
|
|
110
|
+
receive: "recently",
|
|
111
|
+
},
|
|
112
|
+
reverse_explanation: "receive → TREASURY_RECEIVE=253, converts CoinWrapper to balance, writes Record; owner_receive → TREASURY_OWNER_RECEIVE=257, forwards to Permission.owner, no Record",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "T-T-08",
|
|
116
|
+
pattern_name: "Set UM / modify description",
|
|
117
|
+
semantic_intent: "Delegate User Manager (Contact object) or modify Treasury description",
|
|
118
|
+
match_keywords: ["um", "um_set", "um_none", "description", "delegate"],
|
|
119
|
+
schema_fields: ["object (string)", "um | description"],
|
|
120
|
+
example_json: {
|
|
121
|
+
object: "myteam_treasury",
|
|
122
|
+
um: "team_contact",
|
|
123
|
+
},
|
|
124
|
+
reverse_explanation: "um=address → TREASURY_UM=258 (um_set); um=null → TREASURY_UM=258 (um_none); description=string → TREASURY_DESCRIPTION=251",
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
export const SCHEMA_TO_SEMANTIC_RULES = [
|
|
128
|
+
{
|
|
129
|
+
element_type: "field",
|
|
130
|
+
type_name: "object",
|
|
131
|
+
semantic_explanation: "Treasury object reference. STRING=operate existing; OBJECT={name, type_parameter, permission}=create new",
|
|
132
|
+
constraints: ["type_parameter required at creation, immutable thereafter", "permission can be new (TypeNamedObject) or existing (string address)"],
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
element_type: "field",
|
|
136
|
+
type_name: "description",
|
|
137
|
+
semantic_explanation: "Human-readable description of Treasury purpose. Max 4000 chars (MAX_DESCRIPTION_LENGTH).",
|
|
138
|
+
constraints: ["<= 4000 chars", "Modifiable via TREASURY_DESCRIPTION (251)"],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
element_type: "field",
|
|
142
|
+
type_name: "deposit",
|
|
143
|
+
semantic_explanation: "Deposit operation. Two access paths: (1) Permission path (by_external_deposit_guard omitted, requires TREASURY_DEPOSIT=252); (2) Guard path (by_external_deposit_guard set, requires Passport, no Permission)",
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
element_type: "field",
|
|
147
|
+
type_name: "deposit.coin",
|
|
148
|
+
semantic_explanation: "Coin to deposit. {balance: string} for amount; {coin_object: string} for existing Coin object. Type T must match Treasury's type_parameter.",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
element_type: "field",
|
|
152
|
+
type_name: "deposit.by_external_deposit_guard",
|
|
153
|
+
semantic_explanation: "Guard address or name for external deposit path. Triggers Guard + Passport verification; bypasses Permission check.",
|
|
154
|
+
constraints: ["Guard must be in external_deposit_guard list (else E_EXTERNAL_DEPOSIT_GUARD_NOT_FOUND)", "Passport required"],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
element_type: "field",
|
|
158
|
+
type_name: "withdraw",
|
|
159
|
+
semantic_explanation: "Withdraw operation. Two access paths: (1) Permission path (amount.fixed, requires TREASURY_WITHDRAW=254); (2) Guard path (amount.by_external_withdraw_guard, requires Passport, no Permission)",
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
element_type: "field",
|
|
163
|
+
type_name: "withdraw.amount.fixed",
|
|
164
|
+
semantic_explanation: "Fixed u64 withdraw amount (Permission path). Irreversible. Recipient specified separately.",
|
|
165
|
+
constraints: ["Must be <= balance (else E_WITHDRAW_INSUFFICIENT_AMOUNT)", "u64 format"],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
element_type: "field",
|
|
169
|
+
type_name: "withdraw.amount.by_external_withdraw_guard",
|
|
170
|
+
semantic_explanation: "Guard address/name for external withdraw path. Amount determined by Guard table identifier (not caller-specified).",
|
|
171
|
+
constraints: ["Guard must be in external_withdraw_guard list", "Passport required", "Amount from Guard is authoritative"],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
element_type: "field",
|
|
175
|
+
type_name: "external_deposit_guard",
|
|
176
|
+
semantic_explanation: "Manage external_deposit_guard list. op: add (upsert) / set (clear+add) / remove (by address) / clear (empty). Requires TREASURY_EXTERNAL_DEPOSIT_GUARD=255.",
|
|
177
|
+
constraints: ["Max 100 guards (MAX_EXTERNAL_DEPOSIT_GUARD_COUNT)", "identifier is Option<u8> (None = no amount limit)", "store_from_id is Option<u8>"],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
element_type: "field",
|
|
181
|
+
type_name: "external_withdraw_guard",
|
|
182
|
+
semantic_explanation: "Manage external_withdraw_guard list. op: add/set/remove/clear. Requires TREASURY_EXTERNAL_WITHDRAW_GUARD=256.",
|
|
183
|
+
constraints: ["Max 200 guards (MAX_EXTERNAL_WITHDRAW_GUARD_COUNT)", "identifier is u8 (REQUIRED, not Option)", "store_from_id is Option<u8>"],
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
element_type: "field",
|
|
187
|
+
type_name: "receive",
|
|
188
|
+
semantic_explanation: "Receive CoinWrapper objects into balance. Requires TREASURY_RECEIVE=253. Writes Record(op=RECEIVE) to history.",
|
|
189
|
+
constraints: ["CoinWrapper type T must match Treasury's T", "'recently' resolves to all un-received CoinWrapper"],
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
element_type: "field",
|
|
193
|
+
type_name: "owner_receive",
|
|
194
|
+
semantic_explanation: "Unwrap received objects (CoinWrapper + others) and forward to Permission.owner. Requires TREASURY_OWNER_RECEIVE=257. Does NOT write to history.",
|
|
195
|
+
constraints: ["Irreversible (funds leave Treasury)", "Recipient is Permission.owner (resolved at tx time)"],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
element_type: "field",
|
|
199
|
+
type_name: "um",
|
|
200
|
+
semantic_explanation: "User Manager (Contact object address). um=address → um_set; um=null → um_none. Requires TREASURY_UM=258.",
|
|
201
|
+
constraints: ["Must be a Contact object (not user wallet)", "UM ≠ admin (no permission management)"],
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
element_type: "op",
|
|
205
|
+
type_name: "add",
|
|
206
|
+
semantic_explanation: "Upsert semantics: if guard exists, update identifier/store_from_id; else append (after count check)",
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
element_type: "op",
|
|
210
|
+
type_name: "set",
|
|
211
|
+
semantic_explanation: "Replace entire list: clear first, then add. Use when wholesale replacement is intended.",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
element_type: "op",
|
|
215
|
+
type_name: "remove",
|
|
216
|
+
semantic_explanation: "Remove specific guards by address. Count check uses MAX as upper bound (not subtractive).",
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
element_type: "op",
|
|
220
|
+
type_name: "clear",
|
|
221
|
+
semantic_explanation: "Empty the entire guard list. No count check needed.",
|
|
222
|
+
},
|
|
223
|
+
];
|
|
224
|
+
export const TREASURY_CONSTRAINT_RULES = [
|
|
225
|
+
{
|
|
226
|
+
id: "MC-T-01",
|
|
227
|
+
category: "structural",
|
|
228
|
+
rule: "description length <= MAX_DESCRIPTION_LENGTH (4000)",
|
|
229
|
+
applies_to: ["description"],
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
id: "MC-T-02",
|
|
233
|
+
category: "structural",
|
|
234
|
+
rule: "external_deposit_guard count <= MAX_EXTERNAL_DEPOSIT_GUARD_COUNT (100)",
|
|
235
|
+
applies_to: ["external_deposit_guard.guards"],
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: "MC-T-03",
|
|
239
|
+
category: "structural",
|
|
240
|
+
rule: "external_withdraw_guard count <= MAX_EXTERNAL_WITHDRAW_GUARD_COUNT (200)",
|
|
241
|
+
applies_to: ["external_withdraw_guard.guards"],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: "MC-T-04",
|
|
245
|
+
category: "structural",
|
|
246
|
+
rule: "external_withdraw_guard.identifier is u8 (REQUIRED, not Option<u8>)",
|
|
247
|
+
applies_to: ["external_withdraw_guard.guards[].identifier"],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: "MC-T-05",
|
|
251
|
+
category: "structural",
|
|
252
|
+
rule: "external_deposit_guard.identifier is Option<u8> (None means no amount limit)",
|
|
253
|
+
applies_to: ["external_deposit_guard.guards[].identifier"],
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: "MC-T-06",
|
|
257
|
+
category: "semantic",
|
|
258
|
+
rule: "Coin type T must match Treasury's type_parameter for all deposit/withdraw/receive operations",
|
|
259
|
+
applies_to: ["deposit.coin", "withdraw.amount.fixed", "receive"],
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
id: "MC-T-07",
|
|
263
|
+
category: "authority",
|
|
264
|
+
rule: "deposit via Permission path requires TREASURY_DEPOSIT (252); deposit via Guard path requires no Permission (Guard+Passport only)",
|
|
265
|
+
applies_to: ["deposit.by_external_deposit_guard"],
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "MC-T-08",
|
|
269
|
+
category: "authority",
|
|
270
|
+
rule: "withdraw.amount.fixed requires TREASURY_WITHDRAW (254); withdraw.amount.by_external_withdraw_guard requires no Permission",
|
|
271
|
+
applies_to: ["withdraw.amount"],
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
id: "MC-T-09",
|
|
275
|
+
category: "authority",
|
|
276
|
+
rule: "external_deposit_guard management requires TREASURY_EXTERNAL_DEPOSIT_GUARD (255); external_withdraw_guard management requires TREASURY_EXTERNAL_WITHDRAW_GUARD (256)",
|
|
277
|
+
applies_to: ["external_deposit_guard", "external_withdraw_guard"],
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
id: "MC-T-10",
|
|
281
|
+
category: "lifecycle",
|
|
282
|
+
rule: "withdraw (fixed) and external_withdraw are IRREVERSIBLE; verify recipient and amount before execution",
|
|
283
|
+
applies_to: ["withdraw.amount.fixed", "withdraw.amount.by_external_withdraw_guard"],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
id: "MC-T-11",
|
|
287
|
+
category: "lifecycle",
|
|
288
|
+
rule: "owner_receive forwards assets to Permission.owner and does NOT write to history; verify owner address is current",
|
|
289
|
+
applies_to: ["owner_receive"],
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
id: "MC-T-12",
|
|
293
|
+
category: "lifecycle",
|
|
294
|
+
rule: "um_set requires Contact object address (not user wallet); um_set vs um_none both use TREASURY_UM (258)",
|
|
295
|
+
applies_to: ["um"],
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
id: "MC-T-13",
|
|
299
|
+
category: "cross_object",
|
|
300
|
+
rule: "If Treasury is referenced by Allocator/Arbitration, TREASURY_RECEIVE (253) must be granted to a trusted operator for regular intake",
|
|
301
|
+
applies_to: ["receive"],
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
id: "MC-T-14",
|
|
305
|
+
category: "semantic",
|
|
306
|
+
rule: "external_deposit may split coin if value > guard-specified amount; excess refunded to sender",
|
|
307
|
+
applies_to: ["deposit.by_external_deposit_guard"],
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
id: "MC-T-15",
|
|
311
|
+
category: "semantic",
|
|
312
|
+
rule: "inflow/outflow are monotonic counters (never decrease); used for audit reconciliation: theoretical balance = inflow - outflow",
|
|
313
|
+
applies_to: ["(read-only audit fields)"],
|
|
314
|
+
},
|
|
315
|
+
];
|
|
316
|
+
export const TREASURY_TRANSLATION_VERSION = "1.0.0";
|
|
317
|
+
export function matchSemanticPattern(userIntent) {
|
|
318
|
+
const lower = userIntent.toLowerCase();
|
|
319
|
+
const matches = [];
|
|
320
|
+
if (lower.includes("create") || lower.includes("new")) {
|
|
321
|
+
matches.push(SEMANTIC_TO_SCHEMA_RULES[0]);
|
|
322
|
+
}
|
|
323
|
+
if (lower.includes("deposit")) {
|
|
324
|
+
if (lower.includes("external") || lower.includes("guard")) {
|
|
325
|
+
matches.push(SEMANTIC_TO_SCHEMA_RULES[3]);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
matches.push(SEMANTIC_TO_SCHEMA_RULES[1]);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (lower.includes("withdraw")) {
|
|
332
|
+
if (lower.includes("external") || lower.includes("guard")) {
|
|
333
|
+
matches.push(SEMANTIC_TO_SCHEMA_RULES[4]);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
matches.push(SEMANTIC_TO_SCHEMA_RULES[2]);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (lower.includes("guard add") || lower.includes("guard set") || lower.includes("guard remove") ||
|
|
340
|
+
lower.includes("guard clear")) {
|
|
341
|
+
matches.push(SEMANTIC_TO_SCHEMA_RULES[5]);
|
|
342
|
+
}
|
|
343
|
+
if (lower.includes("receive") ||
|
|
344
|
+
lower.includes("owner_receive") || lower.includes("forward")) {
|
|
345
|
+
matches.push(SEMANTIC_TO_SCHEMA_RULES[6]);
|
|
346
|
+
}
|
|
347
|
+
if (lower.includes("um") || lower.includes("delegate") || lower.includes("user manager") ||
|
|
348
|
+
lower.includes("description")) {
|
|
349
|
+
matches.push(SEMANTIC_TO_SCHEMA_RULES[7]);
|
|
350
|
+
}
|
|
351
|
+
if (matches.length === 0) {
|
|
352
|
+
return [...SEMANTIC_TO_SCHEMA_RULES];
|
|
353
|
+
}
|
|
354
|
+
return matches;
|
|
355
|
+
}
|
|
356
|
+
export function explainTreasuryCallData(data) {
|
|
357
|
+
const lines = [];
|
|
358
|
+
if (data.object === null || data.object === undefined) {
|
|
359
|
+
lines.push("Operation: INVALID (object field required)");
|
|
360
|
+
}
|
|
361
|
+
else if (typeof data.object === "string") {
|
|
362
|
+
lines.push(`Operation: OPERATE existing Treasury at ${data.object}`);
|
|
363
|
+
}
|
|
364
|
+
else if (typeof data.object === "object") {
|
|
365
|
+
const obj = data.object;
|
|
366
|
+
lines.push(`Operation: CREATE new Treasury`);
|
|
367
|
+
if (obj.name)
|
|
368
|
+
lines.push(` name: ${obj.name}`);
|
|
369
|
+
if (obj.type_parameter)
|
|
370
|
+
lines.push(` type_parameter (T): ${obj.type_parameter}`);
|
|
371
|
+
if (obj.permission) {
|
|
372
|
+
if (typeof obj.permission === "string") {
|
|
373
|
+
lines.push(` permission: existing ${obj.permission}`);
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
lines.push(` permission: new (TypeNamedObject)`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (data.description) {
|
|
381
|
+
lines.push(`- Set description: "${data.description}"`);
|
|
382
|
+
}
|
|
383
|
+
if (data.deposit) {
|
|
384
|
+
const d = data.deposit;
|
|
385
|
+
if (d.by_external_deposit_guard) {
|
|
386
|
+
lines.push(`- External deposit via guard: ${d.by_external_deposit_guard}`);
|
|
387
|
+
if (d.coin?.balance)
|
|
388
|
+
lines.push(` coin balance: ${d.coin.balance} (may split if > guard limit)`);
|
|
389
|
+
if (d.coin?.coin_object)
|
|
390
|
+
lines.push(` coin object: ${d.coin.coin_object}`);
|
|
391
|
+
lines.push(` ⚠️ No Permission check; Passport required`);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
lines.push(`- Internal deposit via Permission (TREASURY_DEPOSIT=252)`);
|
|
395
|
+
if (d.coin?.balance)
|
|
396
|
+
lines.push(` coin balance: ${d.coin.balance}`);
|
|
397
|
+
if (d.coin?.coin_object)
|
|
398
|
+
lines.push(` coin object: ${d.coin.coin_object}`);
|
|
399
|
+
}
|
|
400
|
+
if (d.payment_info?.remark)
|
|
401
|
+
lines.push(` payment remark: "${d.payment_info.remark}"`);
|
|
402
|
+
}
|
|
403
|
+
if (data.withdraw) {
|
|
404
|
+
const w = data.withdraw;
|
|
405
|
+
if (w.amount?.fixed) {
|
|
406
|
+
lines.push(`- Internal withdraw via Permission (TREASURY_WITHDRAW=254)`);
|
|
407
|
+
lines.push(` amount: ${w.amount.fixed} (fixed, IRREVERSIBLE)`);
|
|
408
|
+
}
|
|
409
|
+
else if (w.amount?.by_external_withdraw_guard) {
|
|
410
|
+
lines.push(`- External withdraw via guard: ${w.amount.by_external_withdraw_guard}`);
|
|
411
|
+
lines.push(` ⚠️ Amount determined by Guard table identifier (not caller-specified)`);
|
|
412
|
+
lines.push(` ⚠️ IRREVERSIBLE; No Permission check; Passport required`);
|
|
413
|
+
}
|
|
414
|
+
if (w.recipient)
|
|
415
|
+
lines.push(` recipient: ${w.recipient}`);
|
|
416
|
+
if (w.payment_info?.remark)
|
|
417
|
+
lines.push(` payment remark: "${w.payment_info.remark}"`);
|
|
418
|
+
}
|
|
419
|
+
if (data.receive) {
|
|
420
|
+
if (data.receive === "recently") {
|
|
421
|
+
lines.push(`- Receive all recently-received CoinWrapper (TREASURY_RECEIVE=253)`);
|
|
422
|
+
}
|
|
423
|
+
else if (Array.isArray(data.receive)) {
|
|
424
|
+
lines.push(`- Receive ${data.receive.length} CoinWrapper object(s) (TREASURY_RECEIVE=253)`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (data.external_deposit_guard) {
|
|
428
|
+
const g = data.external_deposit_guard;
|
|
429
|
+
if (g.op === "clear") {
|
|
430
|
+
lines.push(`- Clear external_deposit_guard list (TREASURY_EXTERNAL_DEPOSIT_GUARD=255)`);
|
|
431
|
+
}
|
|
432
|
+
else if (g.op === "remove") {
|
|
433
|
+
lines.push(`- Remove ${g.guards.length} guard(s) from external_deposit_guard (Permission 255)`);
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
const count = g.guards.length;
|
|
437
|
+
lines.push(`- ${g.op === "set" ? "Set (clear+add)" : "Add (upsert)"} ${count} external_deposit_guard(s) (Permission 255)`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (data.external_withdraw_guard) {
|
|
441
|
+
const g = data.external_withdraw_guard;
|
|
442
|
+
if (g.op === "clear") {
|
|
443
|
+
lines.push(`- Clear external_withdraw_guard list (TREASURY_EXTERNAL_WITHDRAW_GUARD=256)`);
|
|
444
|
+
}
|
|
445
|
+
else if (g.op === "remove") {
|
|
446
|
+
lines.push(`- Remove ${g.guards.length} guard(s) from external_withdraw_guard (Permission 256)`);
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
const count = g.guards.length;
|
|
450
|
+
lines.push(`- ${g.op === "set" ? "Set (clear+add)" : "Add (upsert)"} ${count} external_withdraw_guard(s) (Permission 256)`);
|
|
451
|
+
lines.push(` ⚠️ withdraw guard identifier is REQUIRED (u8, not Option)`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (data.owner_receive) {
|
|
455
|
+
if (data.owner_receive === "recently") {
|
|
456
|
+
lines.push(`- owner_receive: forward all recently-received objects to Permission.owner (TREASURY_OWNER_RECEIVE=257)`);
|
|
457
|
+
}
|
|
458
|
+
else if (Array.isArray(data.owner_receive)) {
|
|
459
|
+
lines.push(`- owner_receive: forward ${data.owner_receive.length} object(s) to Permission.owner (Permission 257)`);
|
|
460
|
+
}
|
|
461
|
+
lines.push(` ⚠️ IRREVERSIBLE; does NOT write to history`);
|
|
462
|
+
}
|
|
463
|
+
if (data.um !== undefined) {
|
|
464
|
+
if (data.um === null) {
|
|
465
|
+
lines.push(`- UM revoke (um_none, TREASURY_UM=258)`);
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
lines.push(`- UM set to ${data.um} (TREASURY_UM=258)`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return lines.join("\n");
|
|
472
|
+
}
|
|
473
|
+
export function explainField(fieldName) {
|
|
474
|
+
return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "field" && r.type_name === fieldName);
|
|
475
|
+
}
|
|
476
|
+
export function explainOp(opName) {
|
|
477
|
+
return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "op" && r.type_name === opName);
|
|
478
|
+
}
|
|
479
|
+
export function getConstraintsByCategory(category) {
|
|
480
|
+
return TREASURY_CONSTRAINT_RULES.filter(r => r.category === category);
|
|
481
|
+
}
|
|
482
|
+
export function explainTreasuryPermissionIndex(index) {
|
|
483
|
+
if (isBuiltinTreasuryPermission(index)) {
|
|
484
|
+
const entry = getBuiltinPermissionByIndex(index);
|
|
485
|
+
const scene = findSceneByPermissionIndex(index);
|
|
486
|
+
return `${entry?.name ?? "Unknown"} (${index}) — ${entry?.description ?? ""} [scene: ${scene?.id ?? "unknown"}]`;
|
|
487
|
+
}
|
|
488
|
+
if (index === -1) {
|
|
489
|
+
return `Reserved (no Permission index) — external operations use Guard + Passport instead`;
|
|
490
|
+
}
|
|
491
|
+
if (index >= 1000) {
|
|
492
|
+
return `Custom permission (${index}) — must be documented via Permission.remark; not used by Treasury builtin operations`;
|
|
493
|
+
}
|
|
494
|
+
if (index === 259 || index === 260) {
|
|
495
|
+
return `STALE index ${index} — was pre-fix SDK value; canonical post-fix indexes are 255-258. See R-T-01.`;
|
|
496
|
+
}
|
|
497
|
+
return `Index ${index} — not a Treasury builtin permission (range 250-258)`;
|
|
498
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type UtilRiskLevel = "CRITICAL" | "HIGH" | "MEDIUM" | "LOW" | "INFO";
|
|
2
|
+
export type UtilRiskCategory = "structural" | "semantic" | "lifecycle" | "cross_object" | "knowledge";
|
|
3
|
+
export type UtilStakeholder = "caller" | "system";
|
|
4
|
+
export interface UtilRisk {
|
|
5
|
+
id: string;
|
|
6
|
+
level: UtilRiskLevel;
|
|
7
|
+
category: UtilRiskCategory;
|
|
8
|
+
title: string;
|
|
9
|
+
description: string;
|
|
10
|
+
affected_stakeholders: UtilStakeholder[];
|
|
11
|
+
scenario: string;
|
|
12
|
+
mitigation: string;
|
|
13
|
+
evidence?: string;
|
|
14
|
+
related_move_error?: string;
|
|
15
|
+
auto_fixable: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface UtilRiskCheckContext {
|
|
18
|
+
uses_typo_function_name?: boolean;
|
|
19
|
+
assumes_stable_address_bytes?: boolean;
|
|
20
|
+
large_util_import?: boolean;
|
|
21
|
+
expects_util_events?: boolean;
|
|
22
|
+
bcs_manually_synced?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const UTIL_RISK_RULES: {
|
|
25
|
+
rule: UtilRisk;
|
|
26
|
+
check: (ctx: UtilRiskCheckContext) => UtilRisk | null;
|
|
27
|
+
}[];
|
|
28
|
+
export declare const UTIL_RISK_VERSION = "1.0.0";
|
|
29
|
+
export declare function checkUtilRisks(ctx: UtilRiskCheckContext): UtilRisk[];
|
|
30
|
+
export declare function getUtilRiskById(id: string): UtilRisk | undefined;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
const USER_ADDRESS_BYTE_MAX = 0x06;
|
|
2
|
+
const OBJECT_ADDRESS_BYTE = 0xf1;
|
|
3
|
+
const CHILD_OBJECT_ADDRESS_BYTE = 0xf0;
|
|
4
|
+
const R_U_01 = {
|
|
5
|
+
rule: {
|
|
6
|
+
id: "R-UTIL-01",
|
|
7
|
+
level: "LOW",
|
|
8
|
+
category: "semantic",
|
|
9
|
+
title: "is_chiild_object_address_byte has a typo ('chiild') — cannot be renamed post-publish",
|
|
10
|
+
description: "util.move:30 defines is_chiild_object_address_byte (note the 'chiild' typo). The " +
|
|
11
|
+
"function is already published on mainnet, so the name cannot be fixed without a " +
|
|
12
|
+
"breaking package upgrade. Callers must use the misspelled name exactly; SDK wrappers " +
|
|
13
|
+
"should expose a correctly-spelled alias and route to the typo function.",
|
|
14
|
+
affected_stakeholders: ["caller"],
|
|
15
|
+
scenario: "Caller writes is_child_object_address_byte; Move linker cannot resolve the symbol",
|
|
16
|
+
mitigation: "SDK should expose isChildObjectAddressByte as the public API and internally call the " +
|
|
17
|
+
"typo'd Move function. Document the typo so future maintainers don't 'fix' it.",
|
|
18
|
+
auto_fixable: false,
|
|
19
|
+
},
|
|
20
|
+
check: (ctx) => {
|
|
21
|
+
if (!ctx.uses_typo_function_name)
|
|
22
|
+
return null;
|
|
23
|
+
return { ...R_U_01.rule, evidence: "uses_typo_function_name=true (must use 'chiild')" };
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const R_U_02 = {
|
|
27
|
+
rule: {
|
|
28
|
+
id: "R-UTIL-02",
|
|
29
|
+
level: "MEDIUM",
|
|
30
|
+
category: "semantic",
|
|
31
|
+
title: "Address-byte thresholds are hardcoded — Wow protocol upgrades could invalidate them",
|
|
32
|
+
description: `util.move classifies addresses by first byte: user (≤ ${USER_ADDRESS_BYTE_MAX}), ` +
|
|
33
|
+
`object (${OBJECT_ADDRESS_BYTE}), child_object (${CHILD_OBJECT_ADDRESS_BYTE}). ` +
|
|
34
|
+
`These thresholds are hardcoded as Move constants, not configurable. If a future Wow ` +
|
|
35
|
+
`protocol upgrade changes the address byte layout (e.g. reserves a new prefix), Util ` +
|
|
36
|
+
`would silently misclassify addresses until the Move code is upgraded.`,
|
|
37
|
+
affected_stakeholders: ["caller", "system"],
|
|
38
|
+
scenario: "Wow protocol upgrade introduces a new address prefix; Util misclassifies it as user",
|
|
39
|
+
mitigation: "Track Wow protocol upgrades that touch address layout. When a change ships, upgrade " +
|
|
40
|
+
"util.move and the SDK in lockstep. Add a sync test that asserts the byte values.",
|
|
41
|
+
auto_fixable: false,
|
|
42
|
+
},
|
|
43
|
+
check: (ctx) => {
|
|
44
|
+
if (!ctx.assumes_stable_address_bytes)
|
|
45
|
+
return null;
|
|
46
|
+
return { ...R_U_02.rule, evidence: `assumes_stable_address_bytes=true (hardcoded ${USER_ADDRESS_BYTE_MAX}/${OBJECT_ADDRESS_BYTE}/${CHILD_OBJECT_ADDRESS_BYTE})` };
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const R_U_03 = {
|
|
50
|
+
rule: {
|
|
51
|
+
id: "R-UTIL-03",
|
|
52
|
+
level: "LOW",
|
|
53
|
+
category: "structural",
|
|
54
|
+
title: "util.ts is ~50KB — over-concentrated, hard to navigate",
|
|
55
|
+
description: "The SDK util.ts is ~50428 bytes, mixing BCS structure definitions, query condition " +
|
|
56
|
+
"builders, Guard query helpers, and address utilities. The size makes it hard to " +
|
|
57
|
+
"navigate and increases the risk of accidental circular imports. New contributors " +
|
|
58
|
+
"often import the wrong symbol because so many are exported from one file.",
|
|
59
|
+
affected_stakeholders: ["caller", "system"],
|
|
60
|
+
scenario: "Developer imports ProgressHistoryFindConditionsBCS and accidentally pulls in unrelated code",
|
|
61
|
+
mitigation: "Consider splitting util.ts into focused sub-modules (bcs.ts, query.ts, address.ts). " +
|
|
62
|
+
"Until then, prefer named imports over namespace imports to keep bundles lean.",
|
|
63
|
+
auto_fixable: false,
|
|
64
|
+
},
|
|
65
|
+
check: (ctx) => {
|
|
66
|
+
if (!ctx.large_util_import)
|
|
67
|
+
return null;
|
|
68
|
+
return { ...R_U_03.rule, evidence: "large_util_import=true (consider sub-modules)" };
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
const R_U_04 = {
|
|
72
|
+
rule: {
|
|
73
|
+
id: "R-UTIL-04",
|
|
74
|
+
level: "LOW",
|
|
75
|
+
category: "lifecycle",
|
|
76
|
+
title: "Util emits no events — tool-call observability is caller's responsibility",
|
|
77
|
+
description: "Util functions are pure: they neither emit nor consume events. Callers cannot rely on " +
|
|
78
|
+
"an event stream to trace Util invocations. For audit and debugging, the calling " +
|
|
79
|
+
"module must record its own log entries around Util calls.",
|
|
80
|
+
affected_stakeholders: ["caller"],
|
|
81
|
+
scenario: "Auditor expects Util-call events; none exist, the call chain is invisible",
|
|
82
|
+
mitigation: "Callers should emit their own events or write logs around Util calls when auditability " +
|
|
83
|
+
"is required. Treat Util as an opaque library function.",
|
|
84
|
+
auto_fixable: false,
|
|
85
|
+
},
|
|
86
|
+
check: (ctx) => {
|
|
87
|
+
if (!ctx.expects_util_events)
|
|
88
|
+
return null;
|
|
89
|
+
return { ...R_U_04.rule, evidence: "expects_util_events=true (none emitted)" };
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
const R_U_05 = {
|
|
93
|
+
rule: {
|
|
94
|
+
id: "R-UTIL-05",
|
|
95
|
+
level: "MEDIUM",
|
|
96
|
+
category: "cross_object",
|
|
97
|
+
title: "SDK BCS structures must stay in sync with Move structs — drift breaks queries",
|
|
98
|
+
description: "util.ts defines BCS structures for Progress History / Session / Forward / Record " +
|
|
99
|
+
"query conditions. These must match the Move struct layouts byte-for-byte. If a Move " +
|
|
100
|
+
"struct adds a field and the SDK BCS is not regenerated, query submissions will " +
|
|
101
|
+
"deserialize incorrectly on-chain, producing silent failures or aborts.",
|
|
102
|
+
affected_stakeholders: ["caller", "system"],
|
|
103
|
+
scenario: "Progress struct adds a field; SDK BCS is stale; queries return wrong results",
|
|
104
|
+
mitigation: "Generate BCS structures from Move source via codegen, or run a sync test that " +
|
|
105
|
+
"compares SDK BCS layouts against Move structs on every release.",
|
|
106
|
+
auto_fixable: false,
|
|
107
|
+
},
|
|
108
|
+
check: (ctx) => {
|
|
109
|
+
if (ctx.bcs_manually_synced === undefined)
|
|
110
|
+
return null;
|
|
111
|
+
if (!ctx.bcs_manually_synced)
|
|
112
|
+
return null;
|
|
113
|
+
return { ...R_U_05.rule, evidence: "bcs_manually_synced=true (drift risk)" };
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
export const UTIL_RISK_RULES = [
|
|
117
|
+
R_U_01,
|
|
118
|
+
R_U_02,
|
|
119
|
+
R_U_03,
|
|
120
|
+
R_U_04,
|
|
121
|
+
R_U_05,
|
|
122
|
+
];
|
|
123
|
+
export const UTIL_RISK_VERSION = "1.0.0";
|
|
124
|
+
export function checkUtilRisks(ctx) {
|
|
125
|
+
const risks = [];
|
|
126
|
+
for (const rule of UTIL_RISK_RULES) {
|
|
127
|
+
const r = rule.check(ctx);
|
|
128
|
+
if (r)
|
|
129
|
+
risks.push(r);
|
|
130
|
+
}
|
|
131
|
+
return risks;
|
|
132
|
+
}
|
|
133
|
+
export function getUtilRiskById(id) {
|
|
134
|
+
return UTIL_RISK_RULES.find(r => r.rule.id === id)?.rule;
|
|
135
|
+
}
|