@wowok/agent-mcp 3.1.4 → 3.1.6

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.
Files changed (152) hide show
  1. package/dist/evaluation/arbitration-game.js +1 -1
  2. package/dist/evaluation/builtins/graph-service.js +1 -1
  3. package/dist/graph/onchain/analyze.js +1 -1
  4. package/dist/graph/onchain/analyze.spec.js +1 -1
  5. package/dist/graph/onchain/extract.js +1 -1
  6. package/dist/graph/onchain/facts.d.ts +1 -0
  7. package/dist/graph/onchain/facts.js +1 -1
  8. package/dist/graph/onchain/fixtures.js +1 -1
  9. package/dist/graph/onchain/onchain.spec.js +1 -1
  10. package/dist/graph/onchain/strategy.js +1 -1
  11. package/dist/graph/onchain/strategy.spec.js +1 -1
  12. package/dist/harness/recover.js +1 -1
  13. package/dist/knowledge/alloc-audit-policy.spec.js +1 -1
  14. package/dist/knowledge/allocation-risk.js +1 -1
  15. package/dist/knowledge/arbitration-ledger.js +1 -1
  16. package/dist/knowledge/audit-rules.d.ts +1 -0
  17. package/dist/knowledge/audit-rules.js +1 -1
  18. package/dist/knowledge/baselines/rules/alloc_audit.json +20 -0
  19. package/dist/knowledge/baselines/rules/allocation.json +1 -19
  20. package/dist/knowledge/baselines/rules/arb.json +1 -1
  21. package/dist/knowledge/baselines/rules/guard.json +8 -8
  22. package/dist/knowledge/fund-layer.js +1 -1
  23. package/dist/knowledge/guard-design-patterns.d.ts +2 -1
  24. package/dist/knowledge/guard-design-patterns.js +1 -1
  25. package/dist/knowledge/guard-design-patterns.spec.d.ts +1 -0
  26. package/dist/knowledge/guard-design-patterns.spec.js +1 -0
  27. package/dist/knowledge/guard-lint.d.ts +1 -1
  28. package/dist/knowledge/guard-lint.js +1 -1
  29. package/dist/knowledge/guard-puzzle.js +1 -1
  30. package/dist/knowledge/guard-render.js +1 -1
  31. package/dist/knowledge/guard-risk.js +1 -1
  32. package/dist/knowledge/guard-translation.js +1 -1
  33. package/dist/knowledge/index.js +1 -1
  34. package/dist/knowledge/industry-registry.js +1 -1
  35. package/dist/knowledge/jsonrpc-enum.js +1 -1
  36. package/dist/knowledge/permission-ledger.js +1 -1
  37. package/dist/knowledge/recipient-constraint.js +1 -1
  38. package/dist/knowledge/safety-rules.extract-amount.spec.d.ts +1 -0
  39. package/dist/knowledge/safety-rules.extract-amount.spec.js +1 -0
  40. package/dist/knowledge/safety-rules.js +1 -1
  41. package/dist/knowledge/service-ledger.js +1 -1
  42. package/dist/knowledge/template-registry.js +1 -1
  43. package/dist/knowledge/template-scanner.js +1 -1
  44. package/dist/knowledge/tool-constraints.js +1 -1
  45. package/dist/knowledge/tools-reference.js +1 -1
  46. package/dist/knowledge/workflow-guidance.js +1 -1
  47. package/dist/monitor/MonitorLoop.js +1 -1
  48. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  49. package/dist/playbooks/service-build/pipeline-actions.d.ts +1 -1
  50. package/dist/playbooks/service-build/pipeline-actions.js +1 -1
  51. package/dist/playbooks/service-build/risk-aggregator.js +1 -1
  52. package/dist/role/derivation.d.ts +1 -1
  53. package/dist/role/derivation.js +1 -1
  54. package/dist/safety/confirm-gate.js +1 -1
  55. package/dist/schema/call/allocation.d.ts +7 -0
  56. package/dist/schema/call/allocation.js +1 -1
  57. package/dist/schema/call/arbitration.d.ts +4 -0
  58. package/dist/schema/call/arbitration.js +1 -1
  59. package/dist/schema/call/base.d.ts +48 -0
  60. package/dist/schema/call/base.js +1 -1
  61. package/dist/schema/call/bridge.d.ts +26 -0
  62. package/dist/schema/call/contact.d.ts +4 -0
  63. package/dist/schema/call/demand.d.ts +4 -0
  64. package/dist/schema/call/error-codes.d.ts +1 -1
  65. package/dist/schema/call/error-codes.js +1 -1
  66. package/dist/schema/call/guard.d.ts +12 -0
  67. package/dist/schema/call/handler.js +1 -1
  68. package/dist/schema/call/machine.d.ts +8 -0
  69. package/dist/schema/call/order.d.ts +4 -0
  70. package/dist/schema/call/order.js +1 -1
  71. package/dist/schema/call/payment.d.ts +4 -0
  72. package/dist/schema/call/permission.d.ts +4 -0
  73. package/dist/schema/call/personal.d.ts +4 -0
  74. package/dist/schema/call/progress.d.ts +4 -0
  75. package/dist/schema/call/proof.d.ts +8 -0
  76. package/dist/schema/call/repository.d.ts +4 -0
  77. package/dist/schema/call/repository.js +1 -1
  78. package/dist/schema/call/reward.d.ts +4 -0
  79. package/dist/schema/call/semantic-customer-advice.spec.js +1 -1
  80. package/dist/schema/call/semantic.d.ts +11 -0
  81. package/dist/schema/call/semantic.js +1 -1
  82. package/dist/schema/call/service.d.ts +14 -0
  83. package/dist/schema/call/service.js +1 -1
  84. package/dist/schema/call/treasury.d.ts +4 -0
  85. package/dist/schema/common/index.js +1 -1
  86. package/dist/schema/keeper/index.d.ts +5 -0
  87. package/dist/schema/local/index.d.ts +28 -0
  88. package/dist/schema/local/index.js +1 -1
  89. package/dist/schema/messenger/index.d.ts +5 -0
  90. package/dist/schema/messenger/index.js +1 -1
  91. package/dist/schema/operations.d.ts +83 -0
  92. package/dist/schema/query/bi.js +1 -1
  93. package/dist/schema/query/index.d.ts +16 -0
  94. package/dist/schema/query/index.js +1 -1
  95. package/dist/schema/schema-version.js +1 -1
  96. package/dist/schema/workflow/index.d.ts +2 -0
  97. package/dist/schema/workflow/index.js +1 -1
  98. package/dist/schema/workspace/index.d.ts +53 -0
  99. package/dist/schema/workspace/index.js +1 -1
  100. package/dist/schema-query-impl/index.js +1 -1
  101. package/dist/schemas/account_operation.output.json +25 -1
  102. package/dist/schemas/bridge_operation.output.json +25 -1
  103. package/dist/schemas/bridge_operation.schema.json +40 -0
  104. package/dist/schemas/guard2file.schema.json +8 -0
  105. package/dist/schemas/index.json +1 -1
  106. package/dist/schemas/keeper_operation.output.json +24 -1
  107. package/dist/schemas/local_history_operation.output.json +25 -1
  108. package/dist/schemas/local_info_operation.output.json +25 -1
  109. package/dist/schemas/local_mark_operation.output.json +25 -1
  110. package/dist/schemas/machineNode2file.schema.json +8 -0
  111. package/dist/schemas/messenger_operation.output.json +24 -1
  112. package/dist/schemas/messenger_operation.schema.json +2 -2
  113. package/dist/schemas/monitor_events.output.json +24 -1
  114. package/dist/schemas/monitor_subscription.output.json +24 -1
  115. package/dist/schemas/onchain_events.output.json +24 -1
  116. package/dist/schemas/onchain_operations.output.json +73 -3
  117. package/dist/schemas/onchain_operations.schema.json +3286 -821
  118. package/dist/schemas/onchain_operations_allocation.schema.json +12 -0
  119. package/dist/schemas/onchain_operations_arbitration.schema.json +18 -10
  120. package/dist/schemas/onchain_operations_contact.schema.json +8 -0
  121. package/dist/schemas/onchain_operations_demand.schema.json +8 -0
  122. package/dist/schemas/onchain_operations_gen_passport.schema.json +8 -0
  123. package/dist/schemas/onchain_operations_gen_proof.schema.json +8 -0
  124. package/dist/schemas/onchain_operations_guard.schema.json +2896 -596
  125. package/dist/schemas/onchain_operations_machine.schema.json +8 -0
  126. package/dist/schemas/onchain_operations_order.schema.json +10 -2
  127. package/dist/schemas/onchain_operations_payment.schema.json +8 -0
  128. package/dist/schemas/onchain_operations_permission.schema.json +8 -0
  129. package/dist/schemas/onchain_operations_personal.schema.json +8 -0
  130. package/dist/schemas/onchain_operations_progress.schema.json +8 -0
  131. package/dist/schemas/onchain_operations_proof.schema.json +8 -0
  132. package/dist/schemas/onchain_operations_repository.schema.json +14 -6
  133. package/dist/schemas/onchain_operations_reward.schema.json +8 -0
  134. package/dist/schemas/onchain_operations_service.schema.json +43 -10
  135. package/dist/schemas/onchain_operations_treasury.schema.json +8 -0
  136. package/dist/schemas/onchain_table_data.output.json +35 -12
  137. package/dist/schemas/query_toolkit.output.json +1179 -10
  138. package/dist/schemas/query_toolkit.schema.json +11 -11
  139. package/dist/schemas/workflow_operation.schema.json +8 -0
  140. package/dist/schemas/workspace_operation.output.json +181 -1
  141. package/dist/schemas/workspace_operation.schema.json +61 -2
  142. package/dist/tools/handlers/config.js +1 -1
  143. package/dist/tools/handlers/dispatch-expectations.js +1 -1
  144. package/dist/tools/handlers/dispatch-expectations.spec.d.ts +1 -0
  145. package/dist/tools/handlers/dispatch-expectations.spec.js +1 -0
  146. package/dist/tools/handlers/onchain.js +1 -1
  147. package/dist/tools/handlers/workflow.js +1 -1
  148. package/dist/tools/handlers/workspace.js +1 -1
  149. package/dist/tools/index.js +1 -1
  150. package/dist/tools/move-fn-index.gen.js +1 -1
  151. package/dist/tools/registry/business.js +1 -1
  152. package/package.json +2 -2
@@ -77,8 +77,8 @@
77
77
  "rx1_11_self_rep_false": "KERNEL — this Guard queries repository.data with a submitted Repository address (own rep=false).",
78
78
  "rx1_11_warning_tail": "KERNEL — final description tail appended when own rep=false (empty otherwise).",
79
79
  "rx1_11_evidence": "KERNEL — final evidence for the own rep=false vs to-be-confirmed branches.",
80
- "rx1_12_vague_count": "KERNEL — submitted entries with vague name descriptions (< 10 chars, bare identifiers, or empty).",
81
- "rx1_12_vague_csv": "KERNEL — vague entries rendered 'identifier=N, name=\"…\"', '; ' joined.",
80
+ "rx1_12_vague_count": "KERNEL — submitted entries with an EMPTY name (no data contract on any layer). Short identifier-style names are schema-conformant and NOT flagged (docs#46-1).",
81
+ "rx1_12_vague_csv": "KERNEL — unnamed entries rendered 'identifier=N, name=\"…\"', '; ' joined.",
82
82
  "rx1_13_detected": "KERNEL — a table Address constant's object_type equals the scene host object (circular reference pattern).",
83
83
  "rx1_13_identifier": "KERNEL — identifier of the circular-reference table entry.",
84
84
  "reentry_applicable": "KERNEL — the scene has a reentrancy spec (ALLOWED scenes stay silent).",
@@ -728,16 +728,16 @@
728
728
  {
729
729
  "rule_id": "R-X1-12",
730
730
  "dimension": "submission_forgery",
731
- "trigger": "Guard table contains b_submission=true entries with vague name descriptions or missing binding_constraint",
731
+ "trigger": "Guard table contains b_submission=true entries with NO name (empty)",
732
732
  "cases": [
733
733
  {
734
734
  "when": { "field": "rx1_12_vague_count", "op": "gt", "value": 0 },
735
735
  "level": "medium",
736
- "title": "Submitted data entry description is vague (retained_submission risk: caller may submit wrong data)",
737
- "description": "Guard table has ${rx1_12_vague_count} b_submission=true entries with vague name descriptions.\nThe name of a submission entry is the only data contract between the Guard and the caller.\nIf the name description is unclear (e.g. only 'addr' / 'order_id'), the caller may:\n - Submit a wrong-typed object address (e.g. submit a Service address instead of an Order address)\n - Submit a wrong value (e.g. inconsistent amount units)\n - Confuse submission slots of different Guards in multi-Guard scenarios\nVague submission entries are 'retained' in the table but provide no effective data constraints, equivalent to the Guard accepting arbitrary data without validating its semantic correctness.",
738
- "scenario": "Caller submits wrong data due to vague name description; the Guard passes verification but the business logic is wrong",
739
- "mitigation": "1) Each submission entry's name should be a complete natural-language description (e.g. 'The order ID that identifies the target Order for verification');\n2) Avoid Technical identifiers as name (e.g. 'order_id' should become 'Order ID, used to query progress status');\n3) Add failure_conditions in binding_hint to clarify failure scenarios;\n4) Consider adding type validation logic in root (e.g. query the submitted object's objectType and match with expectation)",
740
- "evidence": "Vague entries: ${rx1_12_vague_csv}",
736
+ "title": "Submitted data entry has no name (retained_submission risk: caller may submit wrong data)",
737
+ "description": "Guard table has ${rx1_12_vague_count} b_submission=true entries with an EMPTY name.\nAn unnamed submission entry has no data contract on any layer: the caller sees neither a field identifier (table name) nor a human explanation (Guard description).\nThe caller may:\n - Submit a wrong-typed object address (e.g. submit a Service address instead of an Order address)\n - Submit a wrong value (e.g. inconsistent amount units)\n - Confuse submission slots of different Guards in multi-Guard scenarios\nNote: SHORT identifier-style names (e.g. 'order_id', 'delivery_node') are schema-conformant and are NOT a risk — do not rename them to natural-language sentences; table names are limited to 64 BCS characters and the SDK rejects longer values.",
738
+ "scenario": "Caller submits wrong data because no layer explains what the field expects; the Guard passes verification but the business logic is wrong",
739
+ "mitigation": "1) Give every submission entry a short identifier name (e.g. 'order_id', 'delivery_node') — max 64 BCS characters;\n2) Explain what each submitted field means (expected type, expected object role) in the Guard's 'description' field — that is the human-readable data contract, not the name;\n3) Add failure_conditions in binding_hint to clarify failure scenarios;\n4) Consider adding type validation logic in root (e.g. query the submitted object's objectType and match with expectation)",
740
+ "evidence": "Unnamed entries: ${rx1_12_vague_csv}",
741
741
  "stakeholders": ["customer", "provider"]
742
742
  }
743
743
  ]
@@ -1 +1 @@
1
- import{GasTokenType,WOW_DECIMALS,MAINNET_BRIDGE_CONFIG,formatUnits,parseToUnits,extractGenericTypeArg}from'@wowok/wowok';const GAS_TOKENS=[{'type':GasTokenType,'symbol':'WOW','decimals':WOW_DECIMALS,'name':'Wowok\x20Token','description':'Default\x20platform\x20gas\x20token\x20for\x20all\x20WoWok\x20operations.\x201\x20WOW\x20=\x2010^'+WOW_DECIMALS+'\x20MIST.\x20Available\x20on\x20testnet\x20and\x20mainnet.'}],TESTNET_TOKENS=[];function buildMainnetTokensFromSDK(){const a=MAINNET_BRIDGE_CONFIG?.['tokens'];if(!Array['isArray'](a))return[];const b=new Set();return a['filter'](c=>{if(b['has'](c['wowTypeTag']))return![];return b['add'](c['wowTypeTag']),!![];})['map'](c=>{const d=c['wowTypeTag']['split']('::')['pop']()??c['symbol'];return{'type':c['wowTypeTag'],'symbol':d,'decimals':c['wowDecimals'],'name':c['symbol']+'\x20(Bridge)','description':c['description']??'Bridge\x20token\x20on\x20WOW\x20mainnet.\x20'+c['wowDecimals']+'\x20decimals.'};});}export const OFFICIAL_TOKEN_REGISTRY={'gas':GAS_TOKENS,'testnet':TESTNET_TOKENS,'mainnet':buildMainnetTokensFromSDK()};export function getRegistryForNetwork(a){return[...OFFICIAL_TOKEN_REGISTRY['gas'],...a==='testnet'?OFFICIAL_TOKEN_REGISTRY['testnet']:[],...a==='mainnet'?OFFICIAL_TOKEN_REGISTRY['mainnet']:[]];}export function findInRegistryByType(a,b){const c=OFFICIAL_TOKEN_REGISTRY['gas']['find'](e=>e['type']===a);if(c)return c;const d=getRegistryForNetwork(b);return d['find'](e=>e['type']===a);}export function findInRegistryBySymbol(a,b){const c=a['toLowerCase'](),d=OFFICIAL_TOKEN_REGISTRY['gas']['filter'](g=>g['symbol']['toLowerCase']()===c),e=getRegistryForNetwork(b),f=e['filter'](g=>g['symbol']['toLowerCase']()===c&&!d['some'](h=>h['type']===g['type']));return[...d,...f];}export async function resolveTokenByType(a,b){const c=findInRegistryByType(a,b);if(c)return{'type':c['type'],'symbol':c['symbol'],'decimals':c['decimals'],'name':c['name'],'source':'registry','verified':!![]};const d=b!==undefined,e=cacheNet(b)+'::'+a;if(d){const f=RESOLUTION_CACHE['get'](e);if(f)return f;}try{const {TokenInfo:g}=await import('@wowok/wowok'),h=g['Instance'](),i=await h['fetch'](a,undefined,b);if(i){const j={'type':i['type'],'symbol':i['symbol']??'','decimals':i['decimals'],'name':i['name']??'','source':'cache','verified':![]};if(d)RESOLUTION_CACHE['set'](e,j);return j;}}catch{}return undefined;}export async function resolveTokensBySymbol(a,b,c){const d=[],e=findInRegistryBySymbol(a,b);for(const f of e){d['push']({'type':f['type'],'symbol':f['symbol'],'decimals':f['decimals'],'name':f['name'],'source':'registry','verified':!![]});}try{const {query_local_token_list:g}=await import('@wowok/wowok'),h=await g({'symbol':a},b);for(const i of h){if(d['some'](j=>j['type']===i['type']))continue;d['push']({'type':i['type'],'symbol':i['symbol']??'','decimals':i['decimals']??0x0,'name':i['name']??'','source':'cache','verified':![]});}}catch{}return c&&d['sort']((j,k)=>{if(j['type']===c)return-0x1;if(k['type']===c)return 0x1;if(j['verified']&&!k['verified'])return-0x1;if(!j['verified']&&k['verified'])return 0x1;return 0x0;}),d;}const AMOUNT_WITH_SYMBOL=/^(\d+(?:\.\d+)?)\s*([A-Za-z][A-Za-z0-9]*)$/;export function isAmountWithSymbol(a){if(typeof a!=='string')return![];const b=a['match'](AMOUNT_WITH_SYMBOL);if(!b)return![];const c=b[0x2];return c['length']>=0x2&&c['length']<=0xa;}export async function parseAmount(a,b,c){const d=a,e=await resolveTokenByType(b,c),f=e!==undefined,g=e?.['decimals']??0x9,h=e?.['symbol']??'',i=e?.['source']??'onchain',j=e?.['verified']??![];if(typeof a==='string'){const m=a['match'](AMOUNT_WITH_SYMBOL);if(m){const n=m[0x1],o=m[0x2];if(!f){const q=await resolveTokensBySymbol(o,c);if(q['length']>0x0){const r=q['length']>0x1?'MULTIPLE\x20issuers':'an\x20issuer';throw new Error('TOKEN\x20CHOICE\x20REQUIRED:\x20\x22'+a+'\x22\x20uses\x20symbol\x20\x22'+o+'\x22\x20which\x20matches\x20'+r+'\x20'+('on\x20this\x20network'+(q['length']>0x1?'\x20('+q['length']+'\x20candidates\x20—\x20the\x20bare\x20symbol\x20is\x20ambiguous)':'')+'.\x20')+'The\x20operation\x20is\x20REFUSED\x20until\x20you\x20present\x20these\x20candidates\x20to\x20the\x20USER\x20and\x20let\x20the\x20user\x20choose\x20'+'(the\x20user\x20may\x20answer\x20by\x20the\x20candidate\x20NUMBER,\x20e.g.\x20\x222\x22,\x20or\x20by\x20pasting\x20the\x20full\x20type).\x20'+'Then\x20re-issue\x20the\x20operation\x20with\x20the\x20chosen\x20token\x27s\x20FULL\x20type\x20string\x20in\x20type_parameter\x20'+'(package::module::Name)\x20—\x20a\x20bare\x20symbol\x20cannot\x20identify\x20the\x20issuer,\x20and\x20you\x20must\x20NEVER\x20guess\x20one.\x0a'+('\x20\x20Candidates\x20for\x20symbol\x20\x22'+o+'\x22:\x0a')+formatTokenCandidates(q)+'\x0a'+'\x20\x20After\x20choosing,\x20also\x20verify\x20the\x20WOW\x20network\x20selection\x20is\x20correct.');}throw new Error('MISSING\x20TOKEN\x20INFO:\x20cannot\x20convert\x20\x22'+a+'\x22\x20for\x20token\x20type\x20'+b+'\x20—\x20'+'the\x20token\x27s\x20precision\x20(decimals)\x20could\x20not\x20be\x20resolved\x20from\x20the\x20official\x20'+('registry,\x20local\x20cache,\x20or\x20on-chain\x20metadata,\x20and\x20no\x20token\x20with\x20symbol\x20\x22'+o+'\x22\x20')+'is\x20known\x20on\x20this\x20network.\x20Converting\x20a\x20unit\x20value\x20without\x20decimals\x20would\x20forge\x20a\x20'+'wrong\x20on-chain\x20amount\x20and\x20risk\x20asset\x20loss,\x20so\x20the\x20operation\x20is\x20REFUSED.\x20'+precisionUnknownGuidance(b,c));}if(h&&o['toLowerCase']()!==h['toLowerCase']()){const s=await resolveTokensBySymbol(o,c);if(s['length']>0x0){const t=s['length']>0x1?'multiple\x20issuers':'an\x20issuer';throw new Error('TOKEN\x20CHOICE\x20REQUIRED:\x20the\x20amount\x20\x22'+a+'\x22\x20uses\x20symbol\x20\x22'+o+'\x22,\x20but\x20the\x20operation\x27s\x20'+('token\x20is\x20currently\x20\x22'+h+'\x22\x20(type:\x20'+b+').\x20\x22'+o+'\x22\x20matches\x20'+t+'\x20on\x20this\x20')+('network'+(s['length']>0x1?'\x20('+s['length']+'\x20candidates\x20—\x20the\x20bare\x20symbol\x20is\x20ambiguous)':'')+'.\x20')+'Present\x20these\x20candidates\x20to\x20the\x20USER\x20and\x20let\x20the\x20user\x20choose\x20(the\x20user\x20may\x20answer\x20by\x20the\x20candidate\x20'+'NUMBER,\x20e.g.\x20\x222\x22,\x20or\x20by\x20pasting\x20the\x20full\x20type),\x20then\x20re-issue\x20with\x20the\x20chosen\x20token\x27s\x20FULL\x20type\x20in\x20'+'type_parameter\x20(package::module::Name)\x20—\x20never\x20guess\x20an\x20issuer.\x20The\x20operation\x20was\x20NOT\x20executed.\x0a'+('\x20\x20Candidates\x20for\x20symbol\x20\x22'+o+'\x22:\x0a')+formatTokenCandidates(s)+'\x0a'+('\x20\x20If\x20\x22'+h+'\x22\x20('+b+')\x20was\x20intended\x20instead,\x20write\x20the\x20amount\x20with\x20that\x20symbol\x20(e.g.\x20\x22'+n+h+'\x22).'));}throw new Error('Amount\x20symbol\x20\x22'+o+'\x22\x20does\x20not\x20match\x20the\x20resolved\x20token\x20symbol\x20\x22'+h+'\x22\x20'+('(token\x20type:\x20'+b+'),\x20and\x20no\x20token\x20with\x20symbol\x20\x22'+o+'\x22\x20is\x20known\x20on\x20this\x20network.\x20')+('Either\x20write\x20the\x20amount\x20with\x20the\x20correct\x20symbol\x20(e.g.\x20\x22'+n+h+'\x22),\x20or\x20—\x20if\x20a\x20')+'DIFFERENT\x20token\x20was\x20intended\x20—\x20provide\x20that\x20token\x27s\x20FULL\x20type\x20in\x20package::module::Name\x20form\x20in\x20'+'type_parameter\x20(a\x20bare\x20symbol\x20cannot\x20be\x20resolved).\x20'+knownTokenSuggestions(c));}const p=parseToUnits(n,g);return{'smallestUnit':p,'displayAmount':n+'\x20'+o,'originalInput':d,'tokenType':b,'tokenSymbol':h||o,'decimals':g,'converted':!![],'source':i,'verified':j,'precision_known':!![]};}}if(typeof a==='number'&&!Number['isSafeInteger'](a))throw new Error('Amount\x20'+a+'\x20is\x20outside\x20the\x20safe\x20integer\x20range\x20(±2^53\x20=\x20±9007199254740991):\x20'+'JS\x20numbers\x20lose\x20integer\x20precision\x20beyond\x20this\x20point.\x20Pass\x20the\x20raw\x20u64\x20as\x20a\x20NUMERIC\x20'+'STRING\x20(e.g.\x20\x229000000000000000000\x22)\x20or\x20a\x20display\x20string\x20with\x20the\x20token\x20symbol\x20'+'(e.g.\x20\x222.5WOW\x22).');if(typeof a==='string'&&!/^\d+$/['test'](a['trim']()))throw new Error('Invalid\x20raw\x20amount:\x20\x22'+a+'\x22.\x20Smallest-unit\x20amounts\x20must\x20be\x20non-negative\x20integer\x20'+'strings\x20(e.g.\x20\x222500000000\x22).\x20Decimal\x20unit\x20values\x20must\x20carry\x20the\x20token\x20symbol\x20'+'(e.g.\x20\x222.5WOW\x22)\x20so\x20the\x20Fund\x20Processing\x20Layer\x20can\x20convert\x20them\x20with\x20the\x20token\x27s\x20decimals.');let k;try{k=BigInt(a);}catch{throw new Error('Invalid\x20amount:\x20\x22'+a+'\x22.\x20Expected\x20a\x20number,\x20a\x20numeric\x20string\x20(smallest\x20unit),\x20'+'or\x20a\x20display-format\x20string\x20like\x20\x222.5WOW\x22\x20(matching\x20the\x20token\x27s\x20symbol).');}const l=f?formatUnits(k,g):k['toString']()+'\x20raw\x20smallest\x20units\x20(token\x20precision\x20unknown)';return{'smallestUnit':k,'displayAmount':f&&h?l+'\x20'+h:l,'originalInput':d,'tokenType':b,'tokenSymbol':h,'decimals':g,'converted':![],'source':i,'verified':j,'precision_known':f};}function formatTokenCandidates(a,b){return a['map']((d,e)=>{const f=d['verified']?'\x20[VERIFIED\x20—\x20official\x20registry]':'\x20[UNVERIFIED\x20—\x20on-chain\x20metadata]',g=d['name']?'\x20\x22'+d['name']+'\x22':'',h=b&&d['type']===b?'\x20\x20<--\x20USED\x20BY\x20THIS\x20OPERATION\x20(the\x20pinned\x20token\x20—\x20verify\x20before\x20approving)':'';return'\x20\x20\x20\x20\x20\x20'+(e+0x1)+'.\x20'+(d['symbol']??'')+g+'\x20—\x20full\x20type:\x20'+d['type']+'\x20('+(d['decimals']??'?')+'\x20decimals'+f+(d['source']?',\x20source:\x20'+d['source']:'')+')'+h;})['join']('\x0a');}export function generateFundConfirmation(a,b=[]){const c=b['length']>0x0,d=a[0x0]?.['tokenType'],e=['MONEY\x20TRANSACTION\x20CONFIRMATION\x20REQUIRED',''];for(const f of a){const g=f['verified']?'VERIFIED\x20—\x20official\x20registry':'UNVERIFIED\x20—\x20cache/on-chain\x20metadata',h=f['tokenSymbol']||'(no\x20symbol)';e['push']('\x20\x20•\x20'+f['context']+':\x20'+f['displayAmount']),e['push']('\x20\x20\x20\x20\x20\x20token:\x20'+h+'\x20—\x20full\x20type:\x20'+f['tokenType']),e['push']('\x20\x20\x20\x20\x20\x20decimals:\x20'+f['decimals']+'\x20(1\x20'+h+'\x20=\x2010^'+f['decimals']+'\x20raw\x20units);\x20'+('raw\x20amount:\x20'+f['smallestUnit']+';\x20'+g+';\x20source:\x20'+f['source'])),f['converted']&&e['push']('\x20\x20\x20\x20\x20\x20(input\x20was\x20a\x20display\x20amount\x20—\x20converted\x20to\x20smallest\x20units\x20with\x20the\x20token\x27s\x20decimals)');}if(c){e['push']('','TOKEN\x20CANDIDATES\x20—\x20multiple\x20on-chain\x20issuers\x20share\x20the\x20same\x20symbol.','The\x20token\x20this\x20operation\x20is\x20actually\x20pinned\x20to\x20is\x20marked','\x22<--\x20USED\x20BY\x20THIS\x20OPERATION\x22.\x20Verify\x20it\x20is\x20the\x20intended\x20issuer','BEFORE\x20approving.\x20If\x20it\x20is\x20wrong,\x20do\x20NOT\x20approve\x20—\x20re-issue\x20the','operation\x20with\x20the\x20chosen\x20token\x27s\x20FULL\x20type\x20string','(package::module::Name)\x20in\x20type_parameter;\x20a\x20bare\x20symbol\x20can\x20never','identify\x20the\x20issuer.');for(const i of b){e['push']('\x20\x20Symbol\x20\x22'+i['symbol']+'\x22\x20matches\x20these\x20tokens:'),e['push'](formatTokenCandidates(i['candidates'],d));}}return e['push']('','This\x20operation\x20involves\x20money.\x20Please\x20confirm\x20before\x20proceeding.'),{'requiresConfirmation':!![],'reason':c?'Money\x20transaction\x20—\x20user\x20must\x20verify\x20the\x20pinned\x20token\x20among\x20same-symbol\x20candidates\x20before\x20approving':'Money\x20transaction\x20requires\x20user\x20confirmation','fields':a,'ambiguities':b,'message':e['join']('\x0a')};}function extractTokenType(a,b,c){if(a?.['object']&&typeof a['object']==='object'&&a['object']['type_parameter'])return a['object']['type_parameter'];if(b==='payment'&&a?.['type_parameter'])return a['type_parameter'];if(c)return c;return GasTokenType;}function isFixedAmount(a){return a?.['type']==='Fixed';}function isAmountModeSharing(a){return a?.['mode']==='Amount';}const MONETARY_FIELDS={'service':[{'path':'sales.sales.price','context':'Service\x20sale\x20price'},{'path':'compensation_fund_add.balance','context':'Service\x20compensation\x20fund\x20deposit'},{'path':'order_new.buy.total_pay.balance','context':'Order\x20payment\x20amount'},{'path':'discount.discount_value','context':'Discount\x20value'},{'path':'order_allocators.threshold','context':'Service\x20order\x20allocation\x20threshold'},{'path':'order_allocators.allocators.sharing.sharing','context':'Service\x20order\x20allocation\x20sharing\x20amount\x20(Amount\x20mode)','filter':isAmountModeSharing},{'path':'order_allocators.allocators.max','context':'Service\x20order\x20allocation\x20cap'}],'arbitration':[{'path':'dispute.fee.balance','context':'Arbitration\x20dispute\x20fee'},{'path':'fee','context':'Arbitration\x20fee'},{'path':'arbitration.indemnity','context':'Arbitration\x20verdict\x20indemnity'}],'reward':[{'path':'coin_add.balance','context':'Reward\x20coin\x20add'},{'path':'guard_add.amount.value','context':'Reward\x20guard\x20fixed\x20amount','filter':isFixedAmount}],'treasury':[{'path':'deposit.coin.balance','context':'Treasury\x20deposit\x20amount'},{'path':'withdraw.amount.fixed','context':'Treasury\x20withdrawal\x20amount'}],'payment':[{'path':'revenue.amount.balance','context':'Payment\x20amount'}],'allocation':[{'path':'coin.balance','context':'Allocation\x20funding\x20amount'},{'path':'allocators.threshold','context':'Allocation\x20threshold'},{'path':'allocators.allocators.sharing.sharing','context':'Allocation\x20sharing\x20amount\x20(Amount\x20mode)','filter':isAmountModeSharing},{'path':'allocators.allocators.max','context':'Allocation\x20cap'}]};function getNestedValue(a,b){const c=b['split']('.');let d=a;for(const e of c){if(d==null)return undefined;d=d[e];}return d;}function resolveMonetaryLeaves(a,b){const c=b['split']('.'),d=[],e=(f,g,h)=>{if(f==null)return;const j=c[g];if(g===c['length']-0x1){f[j]!=null&&d['push']({'parent':f,'key':j,'displayPath':h+j});return;}const k=f[j];if(Array['isArray'](k))for(let l=0x0;l<k['length'];l++){e(k[l],g+0x1,''+h+j+'['+l+'].');}else e(k,g+0x1,''+h+j+'.');};return e(a,0x0,''),d;}export async function processFundOperation(a,b,c,d){const e={'convertedData':a,'warnings':[],'errors':[],'confirmation':null},f=MONETARY_FIELDS[b];if(!f)return e;const g=extractTokenType(a,b,d?.['objectTokenType']),h=[],i=[],j=new Map();for(const k of f){const l=resolveMonetaryLeaves(a,k['path']);for(const m of l){if(k['filter']&&!k['filter'](m['parent']))continue;await processSingleField(m['parent'],m['key'],m['displayPath'],k['context'],g,c,e,h,i,j);}}if(h['length']>0x0){e['confirmation']=generateFundConfirmation(h,i);const n=h['length'],o=h['some'](q=>!q['verified']),p=i['length']>0x0;p&&e['warnings']['push']('TOKEN\x20CANDIDATES:\x20'+i['length']+'\x20token\x20symbol(s)\x20have\x20multiple\x20on-chain\x20issuers.\x20'+'The\x20confirmation\x20message\x20lists\x20every\x20candidate\x20with\x20full\x20details\x20and\x20marks\x20the\x20token\x20'+'pinned\x20by\x20this\x20operation.\x20Present\x20the\x20list\x20to\x20the\x20USER\x20and\x20verify\x20the\x20pinned\x20issuer\x20is\x20'+'the\x20intended\x20one\x20before\x20approving;\x20if\x20it\x20is\x20wrong,\x20do\x20NOT\x20proceed\x20—\x20re-issue\x20with\x20the\x20'+'chosen\x20token\x27s\x20FULL\x20type\x20string\x20(package::module::Name)\x20in\x20type_parameter.'),o&&e['warnings']['push']('UNVERIFIED\x20TOKEN:\x20some\x20monetary\x20fields\x20use\x20tokens\x20not\x20in\x20the\x20official\x20registry.\x20'+'Precision\x20was\x20resolved\x20from\x20cache/on-chain.\x20Verify\x20the\x20token\x20type\x20before\x20proceeding.'),e['warnings']['push']('MONEY\x20CONFIRMATION:\x20'+n+'\x20monetary\x20field(s)\x20require\x20user\x20confirmation.\x20'+('Token\x20type:\x20'+g+'.\x20Use\x20env.confirmed=true\x20after\x20user\x20consent.'));}return e;}async function processSingleField(a,b,c,d,e,f,g,h,i,j){const k=a[b];if(k==null)return;try{const l=await parseAmount(k,e,f);if(!l['precision_known']){g['errors']['push']('FUND\x20INPUT\x20BLOCKED\x20at\x20'+c+':\x20MISSING\x20TOKEN\x20INFO\x20for\x20'+e+'\x20—\x20'+('precision\x20(decimals)\x20could\x20not\x20be\x20resolved.\x20The\x20value\x20'+JSON['stringify'](k)+'\x20was\x20')+'NOT\x20converted,\x20confirmed,\x20or\x20submitted;\x20no\x20on-chain\x20action\x20was\x20taken.\x20'+precisionUnknownGuidance(e,f));return;}l['converted']&&(a[b]=l['smallestUnit']['toString']());h['push']({'path':c,'displayAmount':l['displayAmount'],'tokenType':l['tokenType'],'tokenSymbol':l['tokenSymbol'],'decimals':l['decimals'],'smallestUnit':l['smallestUnit']['toString'](),'verified':l['verified'],'source':l['source'],'converted':l['converted'],'context':d});if(l['tokenSymbol']){const m=l['tokenSymbol']['toLowerCase']();let n=j['get'](m);if(!n){const o=await resolveTokensBySymbol(l['tokenSymbol'],f,e);o['length']>0x1&&(n=o,j['set'](m,n),i['push']({'symbol':l['tokenSymbol'],'candidates':n['map'](p=>({'type':p['type'],'symbol':p['symbol'],'name':p['name'],'decimals':p['decimals'],'source':p['source'],'verified':p['verified']}))}));}}}catch(p){g['errors']['push']('FUND\x20INPUT\x20BLOCKED\x20at\x20'+c+':\x20'+p['message']);}}export function generateSkillsHint(a){if(!a||!a['requiresConfirmation'])return null;const b=a['ambiguities']['length']>0x0;if(b)return'SKILLS\x20HINT:\x20This\x20money\x20transaction\x20uses\x20a\x20token\x20symbol\x20shared\x20by\x20multiple\x20'+'on-chain\x20issuers.\x20The\x20confirmation\x20message\x20lists\x20ALL\x20candidates\x20with\x20full\x20'+'details\x20and\x20marks\x20the\x20token\x20pinned\x20by\x20this\x20operation.\x20Present\x20the\x20list\x20to\x20'+'the\x20user,\x20verify\x20the\x20pinned\x20issuer\x20is\x20the\x20intended\x20one,\x20and\x20proceed\x20only\x20'+'after\x20explicit\x20consent\x20(env.confirmed=true).\x20If\x20the\x20pinned\x20token\x20is\x20wrong,\x20'+'do\x20NOT\x20proceed\x20—\x20the\x20user\x20must\x20re-issue\x20with\x20the\x20chosen\x20token\x27s\x20FULL\x20type\x20'+'string\x20in\x20type_parameter;\x20never\x20guess\x20an\x20issuer\x20from\x20the\x20bare\x20symbol.';return'SKILLS\x20HINT:\x20This\x20money\x20transaction\x20requires\x20user\x20confirmation.\x20'+'If\x20the\x20wowok-safety\x20skill\x20is\x20installed,\x20it\x20provides\x20R1-R10\x20confirmation\x20'+'dialogue\x20scripts.\x20Otherwise,\x20present\x20the\x20confirmation\x20message\x20to\x20the\x20user\x20'+'and\x20proceed\x20only\x20after\x20explicit\x20consent\x20(env.confirmed=true).';}export async function formatChainValue(a,b,c){let d;try{d=BigInt(a)['toString']();}catch{d=String(a);}const e=await resolveTokenByType(b,c);if(e&&typeof e['decimals']==='number'){let f=d;try{f=formatUnits(BigInt(d),e['decimals']);}catch{}const g=e['symbol']||'',h=g?f+'\x20'+g+'\x20(decimals:\x20'+e['decimals']+';\x201\x20'+g+'\x20=\x2010^'+e['decimals']+'\x20raw\x20units;\x20raw:\x20'+d+')':f+'\x20(decimals:\x20'+e['decimals']+';\x201\x20unit\x20=\x2010^'+e['decimals']+'\x20raw\x20units;\x20raw:\x20'+d+')';return{'raw':d,'display':f,'symbol':g||undefined,'decimals':e['decimals'],'token_type':b,'precision_known':!![],'text':h};}return{'raw':d,'display':d,'token_type':b,'precision_known':![],'text':d+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20token\x20precision\x20unavailable\x20for\x20'+b+';\x20'+'this\x20is\x20the\x20true\x20on-chain\x20RAW\x20value,\x20NOT\x20a\x20unit\x20value,\x20and\x20its\x20magnitude\x20cannot\x20be\x20'+'verified\x20(unit\x20=\x20raw\x20/\x2010^N\x20once\x20decimals\x20N\x20are\x20known).\x20'+precisionUnknownRawSuffix()+'\x20'+precisionUnknownGuidance(b,c)};}export function registryDisplayHint(a,b){if(!a)return undefined;const c=findInRegistryByType(a,b);if(!c)return undefined;return{'decimals':c['decimals'],'symbol':c['symbol']};}const RESOLUTION_CACHE=new Map(),OBJECT_TYPE_CACHE=new Map();function cacheNet(a){return a??'default';}function isCacheableObjectRef(a){return/^0x[0-9a-fA-F]{20,}$/['test'](a);}export function clearFundResolutionCaches(){RESOLUTION_CACHE['clear'](),OBJECT_TYPE_CACHE['clear']();}export function knownTokenSuggestions(a){const b=getRegistryForNetwork(a)['map'](c=>c['symbol']+'\x20('+c['type']+',\x20'+c['decimals']+'\x20decimals)');return b['length']>0x0?'Known\x20tokens\x20on\x20this\x20network:\x20'+b['join'](';\x20')+'.':'No\x20officially-known\x20tokens\x20on\x20this\x20network.';}function precisionUnknownGuidance(a,b){const c=b?'network\x20'+b:'the\x20currently\x20selected\x20network';return'To\x20recover:\x20(1)\x20provide\x20the\x20token\x27s\x20FULL\x20type\x20in\x20package::module::Name\x20form\x20'+'(e.g.\x200xFULLPACKAGEID::usdt::USDT\x20—\x20a\x20bare\x20symbol\x20such\x20as\x20\x22USDT\x22\x20cannot\x20be\x20resolved)\x20'+'in\x20type_parameter,\x20so\x20the\x20on-chain\x20coin\x20metadata\x20can\x20be\x20looked\x20up;\x20'+('(2)\x20verify\x20the\x20WOW\x20NETWORK\x20selection\x20is\x20correct\x20—\x20the\x20token\x20may\x20not\x20exist\x20on\x20'+c+';\x20')+'(3)\x20retry,\x20as\x20the\x20on-chain\x20metadata\x20lookup\x20may\x20have\x20failed\x20transiently.\x20'+knownTokenSuggestions(b);}function precisionUnknownRawSuffix(){return'Magnitude\x20cannot\x20be\x20verified\x20—\x20verify\x20the\x20token\x20type\x20and\x20WOW\x20network,\x20then\x20re-run.';}export function formatAmountText(a,b,c){let d;try{d=BigInt(a)['toString']();}catch{d=String(a);}if(b===undefined)return d+'\x20smallest\x20units\x20(token\x20precision\x20unknown)';let e=d;try{e=formatUnits(BigInt(d),b);}catch{}return c?e+'\x20'+c+'\x20(decimals:\x20'+b+';\x20raw:\x20'+d+')':e+'\x20(decimals:\x20'+b+';\x20raw:\x20'+d+')';}export async function convertTokenValue(a,b,c){const d=await resolveTokenByType(a,c),f=d?.['decimals'],g=d?.['symbol']||undefined,h={'token_type':a,'symbol':g,'decimals':f};if(b['raw']!==undefined){let j;try{j=BigInt(b['raw'])['toString']();}catch{return{...h,'precision_known':f!==undefined,'direction':'raw_to_unit','input':String(b['raw']),'output':'','error':'Invalid\x20raw\x20value:\x20\x22'+String(b['raw'])+'\x22\x20—\x20expected\x20a\x20non-negative\x20integer\x20(u64\x20smallest\x20units).','text':'Cannot\x20convert:\x20invalid\x20raw\x20value\x20\x22'+String(b['raw'])+'\x22.'};}if(f===undefined)return{...h,'precision_known':![],'direction':'raw_to_unit','input':j,'output':j,'text':j+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20token\x20precision\x20unavailable\x20for\x20'+a+';\x20'+'this\x20is\x20the\x20true\x20on-chain\x20RAW\x20value,\x20NOT\x20a\x20unit\x20value,\x20and\x20its\x20magnitude\x20cannot\x20'+'be\x20verified\x20(unit\x20=\x20raw\x20/\x2010^N\x20once\x20decimals\x20N\x20are\x20known).\x20'+precisionUnknownRawSuffix()};let k=j;try{k=formatUnits(BigInt(j),f);}catch{}return{...h,'precision_known':!![],'direction':'raw_to_unit','input':j,'output':k,'text':g?j+'\x20raw\x20=\x20'+k+'\x20'+g+'\x20(decimals:\x20'+f+';\x201\x20'+g+'\x20=\x2010^'+f+'\x20raw\x20units)':j+'\x20raw\x20=\x20'+k+'\x20(decimals:\x20'+f+';\x201\x20unit\x20=\x2010^'+f+'\x20raw\x20units)'};}const i=String(b['unit']??'')['trim']();if(f===undefined)return{...h,'precision_known':![],'direction':'unit_to_raw','input':i,'output':'','error':'MISSING\x20TOKEN\x20INFO:\x20cannot\x20convert\x20\x22'+i+'\x22\x20to\x20raw\x20units\x20for\x20token\x20type\x20'+a+'\x20—\x20'+'token\x20precision\x20(decimals)\x20is\x20unavailable.\x20Guessing\x20decimals\x20would\x20forge\x20a\x20wrong\x20on-chain\x20'+'value\x20and\x20risk\x20asset\x20loss,\x20so\x20the\x20conversion\x20is\x20REFUSED.\x20'+precisionUnknownGuidance(a,c),'text':'Cannot\x20convert\x20\x22'+i+'\x22\x20to\x20raw\x20units:\x20token\x20precision\x20unknown\x20for\x20'+a+'.'};try{const l=parseToUnits(i,f);return{...h,'precision_known':!![],'direction':'unit_to_raw','input':i,'output':l['toString'](),'text':g?i+'\x20'+g+'\x20=\x20'+l['toString']()+'\x20raw\x20smallest\x20units\x20(decimals:\x20'+f+';\x201\x20'+g+'\x20=\x2010^'+f+'\x20raw\x20units)':i+'\x20=\x20'+l['toString']()+'\x20raw\x20smallest\x20units\x20(decimals:\x20'+f+';\x201\x20unit\x20=\x2010^'+f+'\x20raw\x20units)'};}catch(m){const n=m instanceof Error?m['message']:String(m);return{...h,'precision_known':!![],'direction':'unit_to_raw','input':i,'output':'','error':n,'text':'Cannot\x20convert\x20\x22'+i+'\x22\x20to\x20raw\x20units:\x20'+n};}}export const TOKEN_GENERIC_OBJECT_TYPES=['Treasury','Allocation','Arbitration','Arb','Payment','Reward','Service'];export const extractGenericTokenType=extractGenericTypeArg;export async function resolveObjectTokenType(a,b){if(!a||typeof a!=='string')return undefined;const c=isCacheableObjectRef(a)&&b!==undefined,d=cacheNet(b)+'::'+a;if(c){const e=OBJECT_TYPE_CACHE['get'](d);if(e)return e;}try{const {query_object_token_type:f}=await import('@wowok/wowok'),[g]=await f({'objects':[a],'network':b});if(!g?.['object'])return undefined;const h={'tokenType':g['coin_type'],'objectType':g['object_type'],'typeRaw':g['type_raw']};if(c)OBJECT_TYPE_CACHE['set'](d,h);return h;}catch{return undefined;}}export async function resolveOperationObjectTokenType(a,b,c){if(!a)return undefined;if(a['object']&&typeof a['object']==='object'&&typeof a['object']['type_parameter']==='string')return a['object']['type_parameter'];if(b==='payment'&&typeof a['type_parameter']==='string')return a['type_parameter'];if(typeof a['object']==='string'&&a['object']['length']>0x0){const d=await resolveObjectTokenType(a['object'],c);return d?.['tokenType'];}return undefined;}const RECEIVE_TOKEN_FIELDS={'treasury':['receive'],'allocation':['received_coins'],'reward':['receive'],'service':['compensation_fund_receive'],'arbitration':['receive']},COIN_PARAM_FIELDS={'treasury':['deposit.coin'],'allocation':['coin'],'reward':['coin_add'],'arbitration':['dispute.fee'],'service':['compensation_fund_add','order_new.buy.total_pay']};export async function validateOperationTokenMatch(a,b,c,d){const e={'errors':[],'warnings':[],'objectTokenType':c};if(!a||!c)return e;const f=typeof a['object']==='string'?a['object']:'the\x20target\x20object',g=(h,i)=>'TOKEN\x20TYPE\x20MISMATCH\x20('+i+'):\x20'+f+'\x20only\x20accepts\x20'+c+'\x20'+('(its\x20generic\x20token\x20type\x20is\x20fixed\x20and\x20immutable),\x20but\x20'+h+'\x20was\x20provided.\x20')+('Use\x20'+c+'\x20for\x20this\x20operation,\x20or\x20target\x20a\x20different\x20object.');for(const h of RECEIVE_TOKEN_FIELDS[b]??[]){const i=a[h];i&&typeof i==='object'&&typeof i['token_type']==='string'&&i['token_type']!==c&&e['errors']['push'](g(i['token_type'],'field\x20\x27'+h+'.token_type\x27'));}for(const j of COIN_PARAM_FIELDS[b]??[]){const k=getNestedValue(a,j);if(k&&typeof k==='object'&&typeof k['coin']==='string'){const l=k['coin'],m=await resolveObjectTokenType(l,d);if(m?.['tokenType'])m['tokenType']!==c&&e['errors']['push'](g(m['tokenType'],'coin\x20\x27'+l+'\x27\x20at\x20\x27'+j+'\x27'));else m===undefined&&e['warnings']['push']('Could\x20not\x20resolve\x20coin\x20object\x20\x27'+l+'\x27\x20('+j+')\x20to\x20verify\x20its\x20token\x20type\x20'+('matches\x20'+c+'.\x20The\x20on-chain\x20type\x20check\x20will\x20reject\x20a\x20mismatch\x20at\x20execution.'));}}return e;}const OBJECT_MONEY_FIELDS={'Treasury':['balance','inflow','outflow'],'Allocation':['balance'],'Arbitration':['fee','balance'],'Reward':['balance'],'Service':['compensation_fund'],'Payment':['amount'],'Arb':['fee']};export async function annotateObjectMonetaryFields(a,b){if(!a||typeof a!=='object'||typeof a['type']!=='string')return;let c=extractGenericTokenType(a['type_raw']);const d={},e=async(h,j,k)=>{if(j===null||j===undefined)return;if(typeof j!=='string'&&typeof j!=='number'&&typeof j!=='bigint')return;d[h]=k?await formatChainValue(j,k,b):{'raw':String(j),'display':String(j),'token_type':'','precision_known':![],'text':String(j)+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20token\x20type\x20could\x20not\x20be\x20determined\x20'+'for\x20this\x20field;\x20this\x20is\x20the\x20true\x20raw\x20value,\x20not\x20a\x20unit\x20value.\x20'+precisionUnknownRawSuffix()};};if(!c&&(a['type']==='Order'||a['type']==='Discount')&&typeof a['service']==='string')try{const h=await resolveObjectTokenType(a['service'],b);c=h?.['tokenType'];}catch{}const f=0x0,g=async(k,l,m)=>{await e(m+'threshold',k,c);if(!Array['isArray'](l))return;for(let n=0x0;n<l['length'];n++){const o=l[n];await e(m+'allocators['+n+'].fix',o?.['fix'],c);o?.['max']!==null&&o?.['max']!==undefined&&await e(m+'allocators['+n+'].max',o['max'],c);if(Array['isArray'](o?.['sharing']))for(let p=0x0;p<o['sharing']['length'];p++){o['sharing'][p]?.['mode']===f&&await e(m+'allocators['+n+'].sharing['+p+'].sharing',o['sharing'][p]['sharing'],c);}}};for(const j of OBJECT_MONEY_FIELDS[a['type']]??[]){await e(j,a[j],c);}switch(a['type']){case'Service':if(Array['isArray'](a['sales']))for(let k=0x0;k<a['sales']['length'];k++){await e('sales['+k+'].price',a['sales'][k]?.['price'],c);}await g(a['order_allocators']?.['threshold'],a['order_allocators']?.['allocators'],'order_allocators.');break;case'Allocation':await g(a['threshold'],a['allocators'],'');break;case'Order':await e('amount',a['amount'],c);if(Array['isArray'](a['items']))for(let l=0x0;l<a['items']['length'];l++){await e('items['+l+'].price',a['items'][l]?.['price'],c);}break;case'Payment':if(Array['isArray'](a['record']))for(let m=0x0;m<a['record']['length'];m++){await e('record['+m+'].amount',a['record'][m]?.['amount'],c);}break;case'Reward':if(Array['isArray'](a['guards']))for(let n=0x0;n<a['guards']['length'];n++){const o=a['guards'][n]?.['amount'];o&&typeof o==='object'&&o['type']===0x1&&await e('guards['+n+'].amount.value',o['value'],c);}break;case'Arb':await e('indemnity.amount',a['indemnity']?.['amount'],c);break;case'Discount':await e('benchmark',a['benchmark'],c);a['discount_type']===0x1&&await e('off',a['off'],c);break;}Object['keys'](d)['length']>0x0&&(a['_money_display']=d);}const TABLE_ITEM_MONEY_FIELDS={'TableItem_TreasuryHistory':['amount'],'TableItem_RewardRecord':['total']};export async function resolveParentObjectTokenType(a,b){const c=await resolveObjectTokenType(a,b);if(!c)return undefined;if(c['objectType']&&TOKEN_GENERIC_OBJECT_TYPES['includes'](c['objectType']))return c['tokenType'];return undefined;}export async function annotateTableItemMonetaryFields(a,b,c){if(!a||typeof a!=='object'||typeof a['type']!=='string')return;const d={},e=async(f,g)=>{if(g===null||g===undefined)return;if(typeof g!=='string'&&typeof g!=='number'&&typeof g!=='bigint')return;d[f]=b?await formatChainValue(g,b,c):{'raw':String(g),'display':String(g),'token_type':'','precision_known':![],'text':String(g)+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20parent\x20object\x20token\x20type\x20could\x20not\x20'+'be\x20resolved;\x20this\x20is\x20the\x20true\x20raw\x20value,\x20not\x20a\x20unit\x20value.\x20'+precisionUnknownRawSuffix()};};for(const f of TABLE_ITEM_MONEY_FIELDS[a['type']]??[]){await e(f,a[f]);}if(a['type']==='TableItem_RewardRecord'&&Array['isArray'](a['record']))for(let g=0x0;g<a['record']['length'];g++){await e('record['+g+'].amount',a['record'][g]?.['amount']);}Object['keys'](d)['length']>0x0&&(a['_money_display']=d);}const MONEY_EVENTS={'TreasuryEvent':{'tokenSource':'object','fields':['amount']},'RewardClaimEvent':{'tokenSource':'object','fields':['amount','total','balance_left']},'RewardFundEvent':{'tokenSource':'object','fields':['amount','balance']},'AllocationEvent':{'tokenSource':'object','fields':['amount']},'NewPaymentEvent':{'tokenSource':'object','fields':['amount'],'arrayFields':[['record','amount']]},'NewOrderEvent':{'tokenSource':'service','fields':['amount']},'ArbEvent':{'tokenSource':'object','fields':[],'optionFields':['indemnity_amount']}};export async function annotateEventMonetaryFields(a,b){if(!a||typeof a!=='object'||typeof a['type']!=='string')return;const c=a['type']['includes']('::')?a['type']['split']('::')['pop']():a['type'],d=c?MONEY_EVENTS[c]:undefined;if(!d)return;const e=a['parsedJson_raw']??{},g=m=>a[m]??e[m];let h;const j=g(d['tokenSource']);if(typeof j==='string'&&j)try{h=(await resolveObjectTokenType(j,b))?.['tokenType'];}catch{}const k={},l=async(m,n)=>{if(n===null||n===undefined)return;if(typeof n!=='string'&&typeof n!=='number'&&typeof n!=='bigint')return;k[m]=h?await formatChainValue(n,h,b):{'raw':String(n),'display':String(n),'token_type':'','precision_known':![],'text':String(n)+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20owning\x20object\x20token\x20type\x20could\x20not\x20'+'be\x20resolved;\x20this\x20is\x20the\x20true\x20raw\x20value,\x20not\x20a\x20unit\x20value.\x20'+precisionUnknownRawSuffix()};};for(const m of d['fields']){await l(m,g(m));}for(const n of d['optionFields']??[]){const o=g(n);o!==null&&o!==undefined&&await l(n,o);}for(const [p,q]of d['arrayFields']??[]){const r=g(p);if(Array['isArray'](r))for(let s=0x0;s<r['length'];s++){await l(p+'['+s+'].'+q,r[s]?.[q]);}}Object['keys'](k)['length']>0x0&&(a['_money_display']=k);}export async function annotateEventsMonetaryFields(a,b){if(!Array['isArray'](a))return;for(const c of a){try{await annotateEventMonetaryFields(c,b);}catch{}}}export async function annotateBalanceChanges(a,b){if(!Array['isArray'](a))return;for(const c of a){try{const d=c?.['coin_type'],e=c?.['amount'];if(typeof d!=='string'||!d)continue;if(typeof e!=='string'&&typeof e!=='number'&&typeof e!=='bigint')continue;c['_money_display']={'amount':await formatChainValue(e,d,b)};}catch{}}}export async function prepareFundOperation(a,b,c){const d=await resolveOperationObjectTokenType(a,b,c),e=await validateOperationTokenMatch(a,b,d,c),f=await processFundOperation(a,b,c,{'objectTokenType':d});return{...f,'warnings':[...e['warnings'],...f['warnings']],'matchErrors':e['errors'],'blockingErrors':[...e['errors'],...f['errors']],'objectTokenType':d};}
1
+ import{GasTokenType,WOW_DECIMALS,MAINNET_BRIDGE_CONFIG,formatUnits,parseToUnits,extractGenericTypeArg}from'@wowok/wowok';const GAS_TOKENS=[{'type':GasTokenType,'symbol':'WOW','decimals':WOW_DECIMALS,'name':'Wowok\x20Token','description':'Default\x20platform\x20gas\x20token\x20for\x20all\x20WoWok\x20operations.\x201\x20WOW\x20=\x2010^'+WOW_DECIMALS+'\x20MIST.\x20Available\x20on\x20testnet\x20and\x20mainnet.'}],TESTNET_TOKENS=[];function buildMainnetTokensFromSDK(){const a=MAINNET_BRIDGE_CONFIG?.['tokens'];if(!Array['isArray'](a))return[];const b=new Set();return a['filter'](c=>{if(b['has'](c['wowTypeTag']))return![];return b['add'](c['wowTypeTag']),!![];})['map'](c=>{const d=c['wowTypeTag']['split']('::')['pop']()??c['symbol'];return{'type':c['wowTypeTag'],'symbol':d,'decimals':c['wowDecimals'],'name':c['symbol']+'\x20(Bridge)','description':c['description']??'Bridge\x20token\x20on\x20WOW\x20mainnet.\x20'+c['wowDecimals']+'\x20decimals.'};});}export const OFFICIAL_TOKEN_REGISTRY={'gas':GAS_TOKENS,'testnet':TESTNET_TOKENS,'mainnet':buildMainnetTokensFromSDK()};export function getRegistryForNetwork(a){return[...OFFICIAL_TOKEN_REGISTRY['gas'],...a==='testnet'?OFFICIAL_TOKEN_REGISTRY['testnet']:[],...a==='mainnet'?OFFICIAL_TOKEN_REGISTRY['mainnet']:[]];}export function findInRegistryByType(a,b){const c=OFFICIAL_TOKEN_REGISTRY['gas']['find'](e=>e['type']===a);if(c)return c;const d=getRegistryForNetwork(b);return d['find'](e=>e['type']===a);}export function findInRegistryBySymbol(a,b){const c=a['toLowerCase'](),d=OFFICIAL_TOKEN_REGISTRY['gas']['filter'](g=>g['symbol']['toLowerCase']()===c),e=getRegistryForNetwork(b),f=e['filter'](g=>g['symbol']['toLowerCase']()===c&&!d['some'](h=>h['type']===g['type']));return[...d,...f];}export async function resolveTokenByType(a,b){const c=findInRegistryByType(a,b);if(c)return{'type':c['type'],'symbol':c['symbol'],'decimals':c['decimals'],'name':c['name'],'source':'registry','verified':!![]};const d=b!==undefined,e=cacheNet(b)+'::'+a;if(d){const f=RESOLUTION_CACHE['get'](e);if(f)return f;}try{const {TokenInfo:g}=await import('@wowok/wowok'),h=g['Instance'](),i=await h['fetch'](a,undefined,b);if(i){const j={'type':i['type'],'symbol':i['symbol']??'','decimals':i['decimals'],'name':i['name']??'','source':'cache','verified':![]};if(d)RESOLUTION_CACHE['set'](e,j);return j;}}catch{}return undefined;}export async function resolveTokensBySymbol(a,b,c){const d=[],e=findInRegistryBySymbol(a,b);for(const f of e){d['push']({'type':f['type'],'symbol':f['symbol'],'decimals':f['decimals'],'name':f['name'],'source':'registry','verified':!![]});}try{const {query_local_token_list:g}=await import('@wowok/wowok'),h=await g({'symbol':a},b);for(const i of h){if(d['some'](j=>j['type']===i['type']))continue;d['push']({'type':i['type'],'symbol':i['symbol']??'','decimals':i['decimals']??0x0,'name':i['name']??'','source':'cache','verified':![]});}}catch{}return c&&d['sort']((j,k)=>{if(j['type']===c)return-0x1;if(k['type']===c)return 0x1;if(j['verified']&&!k['verified'])return-0x1;if(!j['verified']&&k['verified'])return 0x1;return 0x0;}),d;}const AMOUNT_WITH_SYMBOL=/^(\d+(?:\.\d+)?)\s*([A-Za-z][A-Za-z0-9]*)$/;export function isAmountWithSymbol(a){if(typeof a!=='string')return![];const b=a['match'](AMOUNT_WITH_SYMBOL);if(!b)return![];const c=b[0x2];return c['length']>=0x2&&c['length']<=0xa;}export async function parseAmount(a,b,c){const d=a,e=await resolveTokenByType(b,c),f=e!==undefined,g=e?.['decimals']??0x9,h=e?.['symbol']??'',i=e?.['source']??'onchain',j=e?.['verified']??![];if(typeof a==='string'){const m=a['match'](AMOUNT_WITH_SYMBOL);if(m){const n=m[0x1],o=m[0x2];if(!f){const q=await resolveTokensBySymbol(o,c);if(q['length']>0x0){const r=q['length']>0x1?'MULTIPLE\x20issuers':'an\x20issuer';throw new Error('TOKEN\x20CHOICE\x20REQUIRED:\x20\x22'+a+'\x22\x20uses\x20symbol\x20\x22'+o+'\x22\x20which\x20matches\x20'+r+'\x20'+('on\x20this\x20network'+(q['length']>0x1?'\x20('+q['length']+'\x20candidates\x20—\x20the\x20bare\x20symbol\x20is\x20ambiguous)':'')+'.\x20')+'The\x20operation\x20is\x20REFUSED\x20until\x20you\x20present\x20these\x20candidates\x20to\x20the\x20USER\x20and\x20let\x20the\x20user\x20choose\x20'+'(the\x20user\x20may\x20answer\x20by\x20the\x20candidate\x20NUMBER,\x20e.g.\x20\x222\x22,\x20or\x20by\x20pasting\x20the\x20full\x20type).\x20'+'Then\x20re-issue\x20the\x20operation\x20with\x20the\x20chosen\x20token\x27s\x20FULL\x20type\x20string\x20in\x20type_parameter\x20'+'(package::module::Name)\x20—\x20a\x20bare\x20symbol\x20cannot\x20identify\x20the\x20issuer,\x20and\x20you\x20must\x20NEVER\x20guess\x20one.\x0a'+('\x20\x20Candidates\x20for\x20symbol\x20\x22'+o+'\x22:\x0a')+formatTokenCandidates(q)+'\x0a'+'\x20\x20After\x20choosing,\x20also\x20verify\x20the\x20WOW\x20network\x20selection\x20is\x20correct.');}throw new Error('MISSING\x20TOKEN\x20INFO:\x20cannot\x20convert\x20\x22'+a+'\x22\x20for\x20token\x20type\x20'+b+'\x20—\x20'+'the\x20token\x27s\x20precision\x20(decimals)\x20could\x20not\x20be\x20resolved\x20from\x20the\x20official\x20'+('registry,\x20local\x20cache,\x20or\x20on-chain\x20metadata,\x20and\x20no\x20token\x20with\x20symbol\x20\x22'+o+'\x22\x20')+'is\x20known\x20on\x20this\x20network.\x20Converting\x20a\x20unit\x20value\x20without\x20decimals\x20would\x20forge\x20a\x20'+'wrong\x20on-chain\x20amount\x20and\x20risk\x20asset\x20loss,\x20so\x20the\x20operation\x20is\x20REFUSED.\x20'+precisionUnknownGuidance(b,c));}if(h&&o['toLowerCase']()!==h['toLowerCase']()){const s=await resolveTokensBySymbol(o,c);if(s['length']>0x0){const t=s['length']>0x1?'multiple\x20issuers':'an\x20issuer';throw new Error('TOKEN\x20CHOICE\x20REQUIRED:\x20the\x20amount\x20\x22'+a+'\x22\x20uses\x20symbol\x20\x22'+o+'\x22,\x20but\x20the\x20operation\x27s\x20'+('token\x20is\x20currently\x20\x22'+h+'\x22\x20(type:\x20'+b+').\x20\x22'+o+'\x22\x20matches\x20'+t+'\x20on\x20this\x20')+('network'+(s['length']>0x1?'\x20('+s['length']+'\x20candidates\x20—\x20the\x20bare\x20symbol\x20is\x20ambiguous)':'')+'.\x20')+'Present\x20these\x20candidates\x20to\x20the\x20USER\x20and\x20let\x20the\x20user\x20choose\x20(the\x20user\x20may\x20answer\x20by\x20the\x20candidate\x20'+'NUMBER,\x20e.g.\x20\x222\x22,\x20or\x20by\x20pasting\x20the\x20full\x20type),\x20then\x20re-issue\x20with\x20the\x20chosen\x20token\x27s\x20FULL\x20type\x20in\x20'+'type_parameter\x20(package::module::Name)\x20—\x20never\x20guess\x20an\x20issuer.\x20The\x20operation\x20was\x20NOT\x20executed.\x0a'+('\x20\x20Candidates\x20for\x20symbol\x20\x22'+o+'\x22:\x0a')+formatTokenCandidates(s)+'\x0a'+('\x20\x20If\x20\x22'+h+'\x22\x20('+b+')\x20was\x20intended\x20instead,\x20write\x20the\x20amount\x20with\x20that\x20symbol\x20(e.g.\x20\x22'+n+h+'\x22).'));}throw new Error('Amount\x20symbol\x20\x22'+o+'\x22\x20does\x20not\x20match\x20the\x20resolved\x20token\x20symbol\x20\x22'+h+'\x22\x20'+('(token\x20type:\x20'+b+'),\x20and\x20no\x20token\x20with\x20symbol\x20\x22'+o+'\x22\x20is\x20known\x20on\x20this\x20network.\x20')+('Either\x20write\x20the\x20amount\x20with\x20the\x20correct\x20symbol\x20(e.g.\x20\x22'+n+h+'\x22),\x20or\x20—\x20if\x20a\x20')+'DIFFERENT\x20token\x20was\x20intended\x20—\x20provide\x20that\x20token\x27s\x20FULL\x20type\x20in\x20package::module::Name\x20form\x20in\x20'+'type_parameter\x20(a\x20bare\x20symbol\x20cannot\x20be\x20resolved).\x20'+knownTokenSuggestions(c));}const p=parseToUnits(n,g);return{'smallestUnit':p,'displayAmount':n+'\x20'+o,'originalInput':d,'tokenType':b,'tokenSymbol':h||o,'decimals':g,'converted':!![],'source':i,'verified':j,'precision_known':!![]};}}if(typeof a==='number'&&!Number['isSafeInteger'](a))throw new Error('Amount\x20'+a+'\x20is\x20outside\x20the\x20safe\x20integer\x20range\x20(±2^53\x20=\x20±9007199254740991):\x20'+'JS\x20numbers\x20lose\x20integer\x20precision\x20beyond\x20this\x20point.\x20Pass\x20the\x20raw\x20u64\x20as\x20a\x20NUMERIC\x20'+'STRING\x20(e.g.\x20\x229000000000000000000\x22)\x20or\x20a\x20display\x20string\x20with\x20the\x20token\x20symbol\x20'+'(e.g.\x20\x222.5WOW\x22).');if(typeof a==='string'&&!/^\d+$/['test'](a['trim']()))throw new Error('Invalid\x20raw\x20amount:\x20\x22'+a+'\x22.\x20Smallest-unit\x20amounts\x20must\x20be\x20non-negative\x20integer\x20'+'strings\x20(e.g.\x20\x222500000000\x22).\x20Decimal\x20unit\x20values\x20must\x20carry\x20the\x20token\x20symbol\x20'+'(e.g.\x20\x222.5WOW\x22)\x20so\x20the\x20Fund\x20Processing\x20Layer\x20can\x20convert\x20them\x20with\x20the\x20token\x27s\x20decimals.');let k;try{k=BigInt(a);}catch{throw new Error('Invalid\x20amount:\x20\x22'+a+'\x22.\x20Expected\x20a\x20number,\x20a\x20numeric\x20string\x20(smallest\x20unit),\x20'+'or\x20a\x20display-format\x20string\x20like\x20\x222.5WOW\x22\x20(matching\x20the\x20token\x27s\x20symbol).');}const l=f?formatUnits(k,g):k['toString']()+'\x20raw\x20smallest\x20units\x20(token\x20precision\x20unknown)';return{'smallestUnit':k,'displayAmount':f&&h?l+'\x20'+h:l,'originalInput':d,'tokenType':b,'tokenSymbol':h,'decimals':g,'converted':![],'source':i,'verified':j,'precision_known':f};}function formatTokenCandidates(a,b){return a['map']((d,e)=>{const f=d['verified']?'\x20[VERIFIED\x20—\x20official\x20registry]':'\x20[UNVERIFIED\x20—\x20on-chain\x20metadata]',g=d['name']?'\x20\x22'+d['name']+'\x22':'',h=b&&d['type']===b?'\x20\x20<--\x20USED\x20BY\x20THIS\x20OPERATION\x20(the\x20pinned\x20token\x20—\x20verify\x20before\x20approving)':'';return'\x20\x20\x20\x20\x20\x20'+(e+0x1)+'.\x20'+(d['symbol']??'')+g+'\x20—\x20full\x20type:\x20'+d['type']+'\x20('+(d['decimals']??'?')+'\x20decimals'+f+(d['source']?',\x20source:\x20'+d['source']:'')+')'+h;})['join']('\x0a');}export function generateFundConfirmation(a,b=[]){const c=b['length']>0x0,d=a[0x0]?.['tokenType'],e=['MONEY\x20TRANSACTION\x20CONFIRMATION\x20REQUIRED',''];for(const f of a){const g=f['verified']?'VERIFIED\x20—\x20official\x20registry':'UNVERIFIED\x20—\x20cache/on-chain\x20metadata',h=f['tokenSymbol']||'(no\x20symbol)';e['push']('\x20\x20•\x20'+f['context']+':\x20'+f['displayAmount']),e['push']('\x20\x20\x20\x20\x20\x20token:\x20'+h+'\x20—\x20full\x20type:\x20'+f['tokenType']),e['push']('\x20\x20\x20\x20\x20\x20decimals:\x20'+f['decimals']+'\x20(1\x20'+h+'\x20=\x2010^'+f['decimals']+'\x20raw\x20units);\x20'+('raw\x20amount:\x20'+f['smallestUnit']+';\x20'+g+';\x20source:\x20'+f['source'])),f['converted']&&e['push']('\x20\x20\x20\x20\x20\x20(input\x20was\x20a\x20display\x20amount\x20—\x20converted\x20to\x20smallest\x20units\x20with\x20the\x20token\x27s\x20decimals)');}if(c){e['push']('','TOKEN\x20CANDIDATES\x20—\x20multiple\x20on-chain\x20issuers\x20share\x20the\x20same\x20symbol.','The\x20token\x20this\x20operation\x20is\x20actually\x20pinned\x20to\x20is\x20marked','\x22<--\x20USED\x20BY\x20THIS\x20OPERATION\x22.\x20Verify\x20it\x20is\x20the\x20intended\x20issuer','BEFORE\x20approving.\x20If\x20it\x20is\x20wrong,\x20do\x20NOT\x20approve\x20—\x20re-issue\x20the','operation\x20with\x20the\x20chosen\x20token\x27s\x20FULL\x20type\x20string','(package::module::Name)\x20in\x20type_parameter;\x20a\x20bare\x20symbol\x20can\x20never','identify\x20the\x20issuer.');for(const i of b){e['push']('\x20\x20Symbol\x20\x22'+i['symbol']+'\x22\x20matches\x20these\x20tokens:'),e['push'](formatTokenCandidates(i['candidates'],d));}}return e['push']('','This\x20operation\x20involves\x20money.\x20Please\x20confirm\x20before\x20proceeding.'),{'requiresConfirmation':!![],'reason':c?'Money\x20transaction\x20—\x20user\x20must\x20verify\x20the\x20pinned\x20token\x20among\x20same-symbol\x20candidates\x20before\x20approving':'Money\x20transaction\x20requires\x20user\x20confirmation','fields':a,'ambiguities':b,'message':e['join']('\x0a')};}function extractTokenType(a,b,c){if(a?.['object']&&typeof a['object']==='object'&&a['object']['type_parameter'])return a['object']['type_parameter'];if(b==='payment'&&a?.['type_parameter'])return a['type_parameter'];if(c)return c;return GasTokenType;}function isFixedAmount(a){return a?.['type']==='Fixed';}function isFixedDiscount(a){const b=a?.['discount_type'];return b===0x1||b==='FIXED';}function isRatesDiscount(a){const b=a?.['discount_type'];return b===0x0||b==='RATES';}function isAmountModeSharing(a){return a?.['mode']==='Amount';}const MONETARY_FIELDS={'service':[{'path':'sales.sales.price','context':'Service\x20sale\x20price'},{'path':'compensation_fund_add.balance','context':'Service\x20compensation\x20fund\x20deposit'},{'path':'order_new.buy.total_pay.balance','context':'Order\x20payment\x20amount'},{'path':'discount.discount_value','context':'Discount\x20fixed\x20deduction\x20(FIXED\x20type,\x20base\x20units)','filter':isFixedDiscount},{'path':'order_allocators.threshold','context':'Service\x20order\x20allocation\x20threshold'},{'path':'order_allocators.allocators.sharing.sharing','context':'Service\x20order\x20allocation\x20sharing\x20amount\x20(Amount\x20mode)','filter':isAmountModeSharing},{'path':'order_allocators.allocators.max','context':'Service\x20order\x20allocation\x20cap'}],'arbitration':[{'path':'dispute.fee.balance','context':'Arbitration\x20dispute\x20fee'},{'path':'fee','context':'Arbitration\x20fee'},{'path':'arbitration.indemnity','context':'Arbitration\x20verdict\x20indemnity'}],'reward':[{'path':'coin_add.balance','context':'Reward\x20coin\x20add'},{'path':'guard_add.amount.value','context':'Reward\x20guard\x20fixed\x20amount','filter':isFixedAmount}],'treasury':[{'path':'deposit.coin.balance','context':'Treasury\x20deposit\x20amount'},{'path':'withdraw.amount.fixed','context':'Treasury\x20withdrawal\x20amount'}],'payment':[{'path':'revenue.amount.balance','context':'Payment\x20amount'}],'allocation':[{'path':'coin.balance','context':'Allocation\x20funding\x20amount'},{'path':'allocators.threshold','context':'Allocation\x20threshold'},{'path':'allocators.allocators.sharing.sharing','context':'Allocation\x20sharing\x20amount\x20(Amount\x20mode)','filter':isAmountModeSharing},{'path':'allocators.allocators.max','context':'Allocation\x20cap'}]};function getNestedValue(a,b){const c=b['split']('.');let d=a;for(const e of c){if(d==null)return undefined;d=d[e];}return d;}function resolveMonetaryLeaves(a,b){const c=b['split']('.'),d=[],e=(f,g,h)=>{if(f==null)return;const j=c[g];if(g===c['length']-0x1){f[j]!=null&&d['push']({'parent':f,'key':j,'displayPath':h+j});return;}const k=f[j];if(Array['isArray'](k))for(let l=0x0;l<k['length'];l++){e(k[l],g+0x1,''+h+j+'['+l+'].');}else e(k,g+0x1,''+h+j+'.');};return e(a,0x0,''),d;}export async function processFundOperation(a,b,c,d){const e={'convertedData':a,'warnings':[],'errors':[],'confirmation':null},f=MONETARY_FIELDS[b];if(!f)return e;const g=extractTokenType(a,b,d?.['objectTokenType']),h=[],i=[],j=new Map();for(const k of f){const l=resolveMonetaryLeaves(a,k['path']);for(const m of l){if(k['filter']&&!k['filter'](m['parent']))continue;await processSingleField(m['parent'],m['key'],m['displayPath'],k['context'],g,c,e,h,i,j);}}for(const n of resolveMonetaryLeaves(a,'discount.discount_value')){if(isRatesDiscount(n['parent'])){const o=n['parent']['discount_value'],p=typeof o==='number'?(o/0x64)['toString']():o;e['warnings']['push']('DISCOUNT\x20RATE:\x20discount.discount_value\x20'+o+'\x20is\x20a\x20per-10000\x20rate\x20(off),\x20NOT\x20a\x20token\x20amount\x20—\x20'+(o+'/10000\x20of\x20the\x20order\x20total\x20is\x20deducted\x20('+p+'%\x20off;\x2010000\x20=\x20100%\x20off,\x20and\x20a\x20value\x20above\x2010000\x20is\x20rejected\x20for\x20RATES).'));}}if(h['length']>0x0){e['confirmation']=generateFundConfirmation(h,i);const q=h['length'],r=h['some'](t=>!t['verified']),s=i['length']>0x0;s&&e['warnings']['push']('TOKEN\x20CANDIDATES:\x20'+i['length']+'\x20token\x20symbol(s)\x20have\x20multiple\x20on-chain\x20issuers.\x20'+'The\x20confirmation\x20message\x20lists\x20every\x20candidate\x20with\x20full\x20details\x20and\x20marks\x20the\x20token\x20'+'pinned\x20by\x20this\x20operation.\x20Present\x20the\x20list\x20to\x20the\x20USER\x20and\x20verify\x20the\x20pinned\x20issuer\x20is\x20'+'the\x20intended\x20one\x20before\x20approving;\x20if\x20it\x20is\x20wrong,\x20do\x20NOT\x20proceed\x20—\x20re-issue\x20with\x20the\x20'+'chosen\x20token\x27s\x20FULL\x20type\x20string\x20(package::module::Name)\x20in\x20type_parameter.'),r&&e['warnings']['push']('UNVERIFIED\x20TOKEN:\x20some\x20monetary\x20fields\x20use\x20tokens\x20not\x20in\x20the\x20official\x20registry.\x20'+'Precision\x20was\x20resolved\x20from\x20cache/on-chain.\x20Verify\x20the\x20token\x20type\x20before\x20proceeding.'),e['warnings']['push']('MONEY\x20CONFIRMATION:\x20'+q+'\x20monetary\x20field(s)\x20require\x20user\x20confirmation.\x20'+('Token\x20type:\x20'+g+'.\x20Use\x20env.confirmed=true\x20after\x20user\x20consent.'));}return e;}async function processSingleField(a,b,c,d,e,f,g,h,i,j){const k=a[b];if(k==null)return;try{const l=await parseAmount(k,e,f);if(!l['precision_known']){g['errors']['push']('FUND\x20INPUT\x20BLOCKED\x20at\x20'+c+':\x20MISSING\x20TOKEN\x20INFO\x20for\x20'+e+'\x20—\x20'+('precision\x20(decimals)\x20could\x20not\x20be\x20resolved.\x20The\x20value\x20'+JSON['stringify'](k)+'\x20was\x20')+'NOT\x20converted,\x20confirmed,\x20or\x20submitted;\x20no\x20on-chain\x20action\x20was\x20taken.\x20'+precisionUnknownGuidance(e,f));return;}l['converted']&&(a[b]=l['smallestUnit']['toString']());h['push']({'path':c,'displayAmount':l['displayAmount'],'tokenType':l['tokenType'],'tokenSymbol':l['tokenSymbol'],'decimals':l['decimals'],'smallestUnit':l['smallestUnit']['toString'](),'verified':l['verified'],'source':l['source'],'converted':l['converted'],'context':d});if(l['tokenSymbol']){const m=l['tokenSymbol']['toLowerCase']();let n=j['get'](m);if(!n){const o=await resolveTokensBySymbol(l['tokenSymbol'],f,e);o['length']>0x1&&(n=o,j['set'](m,n),i['push']({'symbol':l['tokenSymbol'],'candidates':n['map'](p=>({'type':p['type'],'symbol':p['symbol'],'name':p['name'],'decimals':p['decimals'],'source':p['source'],'verified':p['verified']}))}));}}}catch(p){g['errors']['push']('FUND\x20INPUT\x20BLOCKED\x20at\x20'+c+':\x20'+p['message']);}}export function generateSkillsHint(a){if(!a||!a['requiresConfirmation'])return null;const b=a['ambiguities']['length']>0x0;if(b)return'SKILLS\x20HINT:\x20This\x20money\x20transaction\x20uses\x20a\x20token\x20symbol\x20shared\x20by\x20multiple\x20'+'on-chain\x20issuers.\x20The\x20confirmation\x20message\x20lists\x20ALL\x20candidates\x20with\x20full\x20'+'details\x20and\x20marks\x20the\x20token\x20pinned\x20by\x20this\x20operation.\x20Present\x20the\x20list\x20to\x20'+'the\x20user,\x20verify\x20the\x20pinned\x20issuer\x20is\x20the\x20intended\x20one,\x20and\x20proceed\x20only\x20'+'after\x20explicit\x20consent\x20(env.confirmed=true).\x20If\x20the\x20pinned\x20token\x20is\x20wrong,\x20'+'do\x20NOT\x20proceed\x20—\x20the\x20user\x20must\x20re-issue\x20with\x20the\x20chosen\x20token\x27s\x20FULL\x20type\x20'+'string\x20in\x20type_parameter;\x20never\x20guess\x20an\x20issuer\x20from\x20the\x20bare\x20symbol.';return'SKILLS\x20HINT:\x20This\x20money\x20transaction\x20requires\x20user\x20confirmation.\x20'+'If\x20the\x20wowok-safety\x20skill\x20is\x20installed,\x20it\x20provides\x20R1-R10\x20confirmation\x20'+'dialogue\x20scripts.\x20Otherwise,\x20present\x20the\x20confirmation\x20message\x20to\x20the\x20user\x20'+'and\x20proceed\x20only\x20after\x20explicit\x20consent\x20(env.confirmed=true).';}export async function formatChainValue(a,b,c){let d;try{d=BigInt(a)['toString']();}catch{d=String(a);}const e=await resolveTokenByType(b,c);if(e&&typeof e['decimals']==='number'){let f=d;try{f=formatUnits(BigInt(d),e['decimals']);}catch{}const g=e['symbol']||'',h=g?f+'\x20'+g+'\x20(decimals:\x20'+e['decimals']+';\x201\x20'+g+'\x20=\x2010^'+e['decimals']+'\x20raw\x20units;\x20raw:\x20'+d+')':f+'\x20(decimals:\x20'+e['decimals']+';\x201\x20unit\x20=\x2010^'+e['decimals']+'\x20raw\x20units;\x20raw:\x20'+d+')';return{'raw':d,'display':f,'symbol':g||undefined,'decimals':e['decimals'],'token_type':b,'precision_known':!![],'text':h};}return{'raw':d,'display':d,'token_type':b,'precision_known':![],'text':d+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20token\x20precision\x20unavailable\x20for\x20'+b+';\x20'+'this\x20is\x20the\x20true\x20on-chain\x20RAW\x20value,\x20NOT\x20a\x20unit\x20value,\x20and\x20its\x20magnitude\x20cannot\x20be\x20'+'verified\x20(unit\x20=\x20raw\x20/\x2010^N\x20once\x20decimals\x20N\x20are\x20known).\x20'+precisionUnknownRawSuffix()+'\x20'+precisionUnknownGuidance(b,c)};}export function registryDisplayHint(a,b){if(!a)return undefined;const c=findInRegistryByType(a,b);if(!c)return undefined;return{'decimals':c['decimals'],'symbol':c['symbol']};}const RESOLUTION_CACHE=new Map(),OBJECT_TYPE_CACHE=new Map();function cacheNet(a){return a??'default';}function isCacheableObjectRef(a){return/^0x[0-9a-fA-F]{20,}$/['test'](a);}export function clearFundResolutionCaches(){RESOLUTION_CACHE['clear'](),OBJECT_TYPE_CACHE['clear']();}export function knownTokenSuggestions(a){const b=getRegistryForNetwork(a)['map'](c=>c['symbol']+'\x20('+c['type']+',\x20'+c['decimals']+'\x20decimals)');return b['length']>0x0?'Known\x20tokens\x20on\x20this\x20network:\x20'+b['join'](';\x20')+'.':'No\x20officially-known\x20tokens\x20on\x20this\x20network.';}function precisionUnknownGuidance(a,b){const c=b?'network\x20'+b:'the\x20currently\x20selected\x20network';return'To\x20recover:\x20(1)\x20provide\x20the\x20token\x27s\x20FULL\x20type\x20in\x20package::module::Name\x20form\x20'+'(e.g.\x200xFULLPACKAGEID::usdt::USDT\x20—\x20a\x20bare\x20symbol\x20such\x20as\x20\x22USDT\x22\x20cannot\x20be\x20resolved)\x20'+'in\x20type_parameter,\x20so\x20the\x20on-chain\x20coin\x20metadata\x20can\x20be\x20looked\x20up;\x20'+('(2)\x20verify\x20the\x20WOW\x20NETWORK\x20selection\x20is\x20correct\x20—\x20the\x20token\x20may\x20not\x20exist\x20on\x20'+c+';\x20')+'(3)\x20retry,\x20as\x20the\x20on-chain\x20metadata\x20lookup\x20may\x20have\x20failed\x20transiently.\x20'+knownTokenSuggestions(b);}function precisionUnknownRawSuffix(){return'Magnitude\x20cannot\x20be\x20verified\x20—\x20verify\x20the\x20token\x20type\x20and\x20WOW\x20network,\x20then\x20re-run.';}export function formatAmountText(a,b,c){let d;try{d=BigInt(a)['toString']();}catch{d=String(a);}if(b===undefined)return d+'\x20smallest\x20units\x20(token\x20precision\x20unknown)';let e=d;try{e=formatUnits(BigInt(d),b);}catch{}return c?e+'\x20'+c+'\x20(decimals:\x20'+b+';\x20raw:\x20'+d+')':e+'\x20(decimals:\x20'+b+';\x20raw:\x20'+d+')';}export async function convertTokenValue(a,b,c){const d=await resolveTokenByType(a,c),f=d?.['decimals'],g=d?.['symbol']||undefined,h={'token_type':a,'symbol':g,'decimals':f};if(b['raw']!==undefined){let j;try{j=BigInt(b['raw'])['toString']();}catch{return{...h,'precision_known':f!==undefined,'direction':'raw_to_unit','input':String(b['raw']),'output':'','error':'Invalid\x20raw\x20value:\x20\x22'+String(b['raw'])+'\x22\x20—\x20expected\x20a\x20non-negative\x20integer\x20(u64\x20smallest\x20units).','text':'Cannot\x20convert:\x20invalid\x20raw\x20value\x20\x22'+String(b['raw'])+'\x22.'};}if(f===undefined)return{...h,'precision_known':![],'direction':'raw_to_unit','input':j,'output':j,'text':j+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20token\x20precision\x20unavailable\x20for\x20'+a+';\x20'+'this\x20is\x20the\x20true\x20on-chain\x20RAW\x20value,\x20NOT\x20a\x20unit\x20value,\x20and\x20its\x20magnitude\x20cannot\x20'+'be\x20verified\x20(unit\x20=\x20raw\x20/\x2010^N\x20once\x20decimals\x20N\x20are\x20known).\x20'+precisionUnknownRawSuffix()};let k=j;try{k=formatUnits(BigInt(j),f);}catch{}return{...h,'precision_known':!![],'direction':'raw_to_unit','input':j,'output':k,'text':g?j+'\x20raw\x20=\x20'+k+'\x20'+g+'\x20(decimals:\x20'+f+';\x201\x20'+g+'\x20=\x2010^'+f+'\x20raw\x20units)':j+'\x20raw\x20=\x20'+k+'\x20(decimals:\x20'+f+';\x201\x20unit\x20=\x2010^'+f+'\x20raw\x20units)'};}const i=String(b['unit']??'')['trim']();if(f===undefined)return{...h,'precision_known':![],'direction':'unit_to_raw','input':i,'output':'','error':'MISSING\x20TOKEN\x20INFO:\x20cannot\x20convert\x20\x22'+i+'\x22\x20to\x20raw\x20units\x20for\x20token\x20type\x20'+a+'\x20—\x20'+'token\x20precision\x20(decimals)\x20is\x20unavailable.\x20Guessing\x20decimals\x20would\x20forge\x20a\x20wrong\x20on-chain\x20'+'value\x20and\x20risk\x20asset\x20loss,\x20so\x20the\x20conversion\x20is\x20REFUSED.\x20'+precisionUnknownGuidance(a,c),'text':'Cannot\x20convert\x20\x22'+i+'\x22\x20to\x20raw\x20units:\x20token\x20precision\x20unknown\x20for\x20'+a+'.'};try{const l=parseToUnits(i,f);return{...h,'precision_known':!![],'direction':'unit_to_raw','input':i,'output':l['toString'](),'text':g?i+'\x20'+g+'\x20=\x20'+l['toString']()+'\x20raw\x20smallest\x20units\x20(decimals:\x20'+f+';\x201\x20'+g+'\x20=\x2010^'+f+'\x20raw\x20units)':i+'\x20=\x20'+l['toString']()+'\x20raw\x20smallest\x20units\x20(decimals:\x20'+f+';\x201\x20unit\x20=\x2010^'+f+'\x20raw\x20units)'};}catch(m){const n=m instanceof Error?m['message']:String(m);return{...h,'precision_known':!![],'direction':'unit_to_raw','input':i,'output':'','error':n,'text':'Cannot\x20convert\x20\x22'+i+'\x22\x20to\x20raw\x20units:\x20'+n};}}export const TOKEN_GENERIC_OBJECT_TYPES=['Treasury','Allocation','Arbitration','Arb','Payment','Reward','Service'];export const extractGenericTokenType=extractGenericTypeArg;export async function resolveObjectTokenType(a,b){if(!a||typeof a!=='string')return undefined;const c=isCacheableObjectRef(a)&&b!==undefined,d=cacheNet(b)+'::'+a;if(c){const e=OBJECT_TYPE_CACHE['get'](d);if(e)return e;}try{const {query_object_token_type:f}=await import('@wowok/wowok'),[g]=await f({'objects':[a],'network':b});if(!g?.['object'])return undefined;const h={'tokenType':g['coin_type'],'objectType':g['object_type'],'typeRaw':g['type_raw']};if(c)OBJECT_TYPE_CACHE['set'](d,h);return h;}catch{return undefined;}}export async function resolveOperationObjectTokenType(a,b,c){if(!a)return undefined;if(a['object']&&typeof a['object']==='object'&&typeof a['object']['type_parameter']==='string')return a['object']['type_parameter'];if(b==='payment'&&typeof a['type_parameter']==='string')return a['type_parameter'];if(typeof a['object']==='string'&&a['object']['length']>0x0){const d=await resolveObjectTokenType(a['object'],c);return d?.['tokenType'];}return undefined;}const RECEIVE_TOKEN_FIELDS={'treasury':['receive'],'allocation':['received_coins'],'reward':['receive'],'service':['compensation_fund_receive'],'arbitration':['receive']},COIN_PARAM_FIELDS={'treasury':['deposit.coin'],'allocation':['coin'],'reward':['coin_add'],'arbitration':['dispute.fee'],'service':['compensation_fund_add','order_new.buy.total_pay']};export async function validateOperationTokenMatch(a,b,c,d){const e={'errors':[],'warnings':[],'objectTokenType':c};if(!a||!c)return e;const f=typeof a['object']==='string'?a['object']:'the\x20target\x20object',g=(h,i)=>'TOKEN\x20TYPE\x20MISMATCH\x20('+i+'):\x20'+f+'\x20only\x20accepts\x20'+c+'\x20'+('(its\x20generic\x20token\x20type\x20is\x20fixed\x20and\x20immutable),\x20but\x20'+h+'\x20was\x20provided.\x20')+('Use\x20'+c+'\x20for\x20this\x20operation,\x20or\x20target\x20a\x20different\x20object.');for(const h of RECEIVE_TOKEN_FIELDS[b]??[]){const i=a[h];i&&typeof i==='object'&&typeof i['token_type']==='string'&&i['token_type']!==c&&e['errors']['push'](g(i['token_type'],'field\x20\x27'+h+'.token_type\x27'));}for(const j of COIN_PARAM_FIELDS[b]??[]){const k=getNestedValue(a,j);if(k&&typeof k==='object'&&typeof k['coin']==='string'){const l=k['coin'],m=await resolveObjectTokenType(l,d);if(m?.['tokenType'])m['tokenType']!==c&&e['errors']['push'](g(m['tokenType'],'coin\x20\x27'+l+'\x27\x20at\x20\x27'+j+'\x27'));else m===undefined&&e['warnings']['push']('Could\x20not\x20resolve\x20coin\x20object\x20\x27'+l+'\x27\x20('+j+')\x20to\x20verify\x20its\x20token\x20type\x20'+('matches\x20'+c+'.\x20The\x20on-chain\x20type\x20check\x20will\x20reject\x20a\x20mismatch\x20at\x20execution.'));}}return e;}const OBJECT_MONEY_FIELDS={'Treasury':['balance','inflow','outflow'],'Allocation':['balance'],'Arbitration':['fee','balance'],'Reward':['balance'],'Service':['compensation_fund'],'Payment':['amount'],'Arb':['fee']};export async function annotateObjectMonetaryFields(a,b){if(!a||typeof a!=='object'||typeof a['type']!=='string')return;let c=extractGenericTokenType(a['type_raw']);const d={},e=async(h,j,k)=>{if(j===null||j===undefined)return;if(typeof j!=='string'&&typeof j!=='number'&&typeof j!=='bigint')return;d[h]=k?await formatChainValue(j,k,b):{'raw':String(j),'display':String(j),'token_type':'','precision_known':![],'text':String(j)+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20token\x20type\x20could\x20not\x20be\x20determined\x20'+'for\x20this\x20field;\x20this\x20is\x20the\x20true\x20raw\x20value,\x20not\x20a\x20unit\x20value.\x20'+precisionUnknownRawSuffix()};};if(!c&&(a['type']==='Order'||a['type']==='Discount')&&typeof a['service']==='string')try{const h=await resolveObjectTokenType(a['service'],b);c=h?.['tokenType'];}catch{}const f=0x0,g=async(k,l,m)=>{await e(m+'threshold',k,c);if(!Array['isArray'](l))return;for(let n=0x0;n<l['length'];n++){const o=l[n];await e(m+'allocators['+n+'].fix',o?.['fix'],c);o?.['max']!==null&&o?.['max']!==undefined&&await e(m+'allocators['+n+'].max',o['max'],c);if(Array['isArray'](o?.['sharing']))for(let p=0x0;p<o['sharing']['length'];p++){o['sharing'][p]?.['mode']===f&&await e(m+'allocators['+n+'].sharing['+p+'].sharing',o['sharing'][p]['sharing'],c);}}};for(const j of OBJECT_MONEY_FIELDS[a['type']]??[]){await e(j,a[j],c);}switch(a['type']){case'Service':if(Array['isArray'](a['sales']))for(let k=0x0;k<a['sales']['length'];k++){await e('sales['+k+'].price',a['sales'][k]?.['price'],c);}await g(a['order_allocators']?.['threshold'],a['order_allocators']?.['allocators'],'order_allocators.');break;case'Allocation':await g(a['threshold'],a['allocators'],'');break;case'Order':await e('amount',a['amount'],c);if(Array['isArray'](a['items']))for(let l=0x0;l<a['items']['length'];l++){await e('items['+l+'].price',a['items'][l]?.['price'],c);}break;case'Payment':if(Array['isArray'](a['record']))for(let m=0x0;m<a['record']['length'];m++){await e('record['+m+'].amount',a['record'][m]?.['amount'],c);}break;case'Reward':if(Array['isArray'](a['guards']))for(let n=0x0;n<a['guards']['length'];n++){const o=a['guards'][n]?.['amount'];o&&typeof o==='object'&&o['type']===0x1&&await e('guards['+n+'].amount.value',o['value'],c);}break;case'Arb':await e('indemnity.amount',a['indemnity']?.['amount'],c);break;case'Discount':await e('benchmark',a['benchmark'],c);a['discount_type']===0x1&&await e('off',a['off'],c);break;}Object['keys'](d)['length']>0x0&&(a['_money_display']=d);}const TABLE_ITEM_MONEY_FIELDS={'TableItem_TreasuryHistory':['amount'],'TableItem_RewardRecord':['total']};export async function resolveParentObjectTokenType(a,b){const c=await resolveObjectTokenType(a,b);if(!c)return undefined;if(c['objectType']&&TOKEN_GENERIC_OBJECT_TYPES['includes'](c['objectType']))return c['tokenType'];return undefined;}export async function annotateTableItemMonetaryFields(a,b,c){if(!a||typeof a!=='object'||typeof a['type']!=='string')return;const d={},e=async(f,g)=>{if(g===null||g===undefined)return;if(typeof g!=='string'&&typeof g!=='number'&&typeof g!=='bigint')return;d[f]=b?await formatChainValue(g,b,c):{'raw':String(g),'display':String(g),'token_type':'','precision_known':![],'text':String(g)+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20parent\x20object\x20token\x20type\x20could\x20not\x20'+'be\x20resolved;\x20this\x20is\x20the\x20true\x20raw\x20value,\x20not\x20a\x20unit\x20value.\x20'+precisionUnknownRawSuffix()};};for(const f of TABLE_ITEM_MONEY_FIELDS[a['type']]??[]){await e(f,a[f]);}if(a['type']==='TableItem_RewardRecord'&&Array['isArray'](a['record']))for(let g=0x0;g<a['record']['length'];g++){await e('record['+g+'].amount',a['record'][g]?.['amount']);}Object['keys'](d)['length']>0x0&&(a['_money_display']=d);}const MONEY_EVENTS={'TreasuryEvent':{'tokenSource':'object','fields':['amount']},'RewardClaimEvent':{'tokenSource':'object','fields':['amount','total','balance_left']},'RewardFundEvent':{'tokenSource':'object','fields':['amount','balance']},'AllocationEvent':{'tokenSource':'object','fields':['amount']},'NewPaymentEvent':{'tokenSource':'object','fields':['amount'],'arrayFields':[['record','amount']]},'NewOrderEvent':{'tokenSource':'service','fields':['amount']},'ArbEvent':{'tokenSource':'object','fields':[],'optionFields':['indemnity_amount']}};export async function annotateEventMonetaryFields(a,b){if(!a||typeof a!=='object'||typeof a['type']!=='string')return;const c=a['type']['includes']('::')?a['type']['split']('::')['pop']():a['type'],d=c?MONEY_EVENTS[c]:undefined;if(!d)return;const e=a['parsedJson_raw']??{},g=m=>a[m]??e[m];let h;const j=g(d['tokenSource']);if(typeof j==='string'&&j)try{h=(await resolveObjectTokenType(j,b))?.['tokenType'];}catch{}const k={},l=async(m,n)=>{if(n===null||n===undefined)return;if(typeof n!=='string'&&typeof n!=='number'&&typeof n!=='bigint')return;k[m]=h?await formatChainValue(n,h,b):{'raw':String(n),'display':String(n),'token_type':'','precision_known':![],'text':String(n)+'\x20raw\x20smallest\x20units\x20—\x20RISK:\x20owning\x20object\x20token\x20type\x20could\x20not\x20'+'be\x20resolved;\x20this\x20is\x20the\x20true\x20raw\x20value,\x20not\x20a\x20unit\x20value.\x20'+precisionUnknownRawSuffix()};};for(const m of d['fields']){await l(m,g(m));}for(const n of d['optionFields']??[]){const o=g(n);o!==null&&o!==undefined&&await l(n,o);}for(const [p,q]of d['arrayFields']??[]){const r=g(p);if(Array['isArray'](r))for(let s=0x0;s<r['length'];s++){await l(p+'['+s+'].'+q,r[s]?.[q]);}}Object['keys'](k)['length']>0x0&&(a['_money_display']=k);}export async function annotateEventsMonetaryFields(a,b){if(!Array['isArray'](a))return;for(const c of a){try{await annotateEventMonetaryFields(c,b);}catch{}}}export async function annotateBalanceChanges(a,b){if(!Array['isArray'](a))return;for(const c of a){try{const d=c?.['coin_type'],e=c?.['amount'];if(typeof d!=='string'||!d)continue;if(typeof e!=='string'&&typeof e!=='number'&&typeof e!=='bigint')continue;c['_money_display']={'amount':await formatChainValue(e,d,b)};}catch{}}}export async function prepareFundOperation(a,b,c){const d=await resolveOperationObjectTokenType(a,b,c),e=await validateOperationTokenMatch(a,b,d,c),f=await processFundOperation(a,b,c,{'objectTokenType':d});return{...f,'warnings':[...e['warnings'],...f['warnings']],'matchErrors':e['errors'],'blockingErrors':[...e['errors'],...f['errors']],'objectTokenType':d};}
@@ -24,6 +24,7 @@ export interface VerifierLevelGuidance {
24
24
  recommendation: "avoid" | "use_with_justification" | "recommended" | "default";
25
25
  }
26
26
  export declare const VERIFIER_LEVEL_GUIDANCE: VerifierLevelGuidance[];
27
+ export declare const GUARD_SCHEMA_NOTES: string[];
27
28
  export declare function getGuardDesignPattern(id: string): GuardDesignPattern | undefined;
28
29
  export declare function searchGuardDesignPatterns(query: string): GuardDesignPattern[];
29
30
  export declare function getPatternsByHost(host: GuardHostObject): GuardDesignPattern[];
@@ -34,4 +35,4 @@ export declare function suggestPatternForRequirement(requirement: string): {
34
35
  best: GuardDesignPattern;
35
36
  alternatives: GuardDesignPattern[];
36
37
  };
37
- export declare const GUARD_DESIGN_PATTERNS_VERSION = 2;
38
+ export declare const GUARD_DESIGN_PATTERNS_VERSION = 4;
@@ -1 +1 @@
1
- export const GUARD_DESIGN_PATTERNS=[{'id':'pattern.identity_check_single','business_requirement':'Only\x20the\x20author\x20can\x20purchase\x20this\x20service\x20(strict\x20single-identity)','data_source':'SystemContext','host':'service_buy_guard','verifier_level':'level1_strict_single','logic_summary':'logic_equal[context(Signer),\x20identifier[N](fixed_address)]','key_queries':[],'mitigated_risks':['R-C4-04'],'notes':['Maximally\x20secure\x20but\x20maximally\x20inconvenient','If\x20address\x20is\x20unavailable\x20(key\x20loss,\x20rotation),\x20Guard\x20permanently\x20blocks','Avoid\x20unless\x20role\x20is\x20permanently\x20tied\x20to\x20one\x20address']},{'id':'pattern.identity_check_allowlist','business_requirement':'Customer\x20must\x20be\x20in\x20an\x20allowlist\x20to\x20purchase','data_source':'SystemContext','host':'service_buy_guard','verifier_level':'level2_identity_set','logic_summary':'vec_contains_address[identifier[N](allowlist_vec),\x20context(Signer)]','key_queries':[],'mitigated_risks':['R-C4-04'],'notes':['Allowlist\x20stored\x20as\x20Address\x20vector\x20in\x20table\x20constant']},{'id':'pattern.identity_check_order_holder','business_requirement':'Only\x20order\x20owner\x20or\x20agent\x20can\x20perform\x20operation','data_source':'OnChainConstant','host':'machine_forward','verifier_level':'level2_identity_set','logic_summary':'logic_or[logic_equal[query(1562\x20order.owner),\x20context(Signer)],\x20query(1567\x20order.agent\x20has,\x20Signer)]','key_queries':['order.owner','order.agent\x20has'],'mitigated_risks':['R-C4-04','R-C3-06'],'notes':['1562\x20returns\x20Address\x20→\x20wrap\x20in\x20logic_equal','1567\x20returns\x20Bool\x20→\x20use\x20directly\x20as\x20logic_or\x20child','Recommended\x20Level\x202\x20alternative\x20to\x20Level\x201\x20strict\x20binding']},{'id':'pattern.identity_check_service_provider_dynamic','business_requirement':'Verify\x20caller\x20is\x20service\x27s\x20current\x20permission\x20owner\x20(survives\x20permission\x20rotation)','data_source':'SubmittedObject','host':'machine_forward','verifier_level':'level2_identity_set','logic_summary':'logic_and[logic_equal[query(1488\x20service.permission),\x20identifier[N](submitted_perm)],\x20logic_or[logic_equal[query(1002\x20permission.owner),\x20context(Signer)],\x20query(1004\x20permission.admin\x20has,\x20Signer)]]','key_queries':['service.permission','permission.owner','permission.admin\x20has'],'mitigated_risks':['R-C4-04','R-C3-05'],'notes':['Dynamic\x20permission\x20address\x20(RECOMMENDED)\x20—\x20survives\x20Service\x20permission\x20rotation','Caller\x20submits\x20permission\x20address;\x20Guard\x20verifies\x20match\x20then\x20checks\x20identity','More\x20complex\x20than\x20static\x20but\x20far\x20more\x20robust']},{'id':'pattern.time_lock_progress','business_requirement':'Customer\x20must\x20wait\x20N\x20hours\x20before\x20completing\x20(time-lock)','data_source':'WitnessDerived','host':'machine_forward','verifier_level':'none','logic_summary':'logic_as_u256_ge[context(Clock),\x20calc_number_add[query(1272\x20progress.current_time,\x20witness=OrderProgress),\x20identifier[N](duration_ms)]]','key_queries':['progress.current_time'],'witness_types':['OrderProgress'],'mitigated_risks':[],'notes':['Use\x20convert_witness=100\x20(OrderProgress)\x20to\x20derive\x20Progress\x20from\x20submitted\x20Order\x20ID','Duration\x20in\x20milliseconds\x20—\x20test\x20with\x20small\x20values\x20first']},{'id':'pattern.time_lock_absolute','business_requirement':'Operation\x20allowed\x20only\x20after\x20a\x20fixed\x20timestamp','data_source':'SystemContext','host':'service_buy_guard','verifier_level':'none','logic_summary':'logic_as_u256_ge[context(Clock),\x20identifier[N](release_timestamp)]','key_queries':[],'mitigated_risks':[],'notes':['Useful\x20for\x20pre-sale\x20windows,\x20embargo\x20periods']},{'id':'pattern.repository_data_check','business_requirement':'External\x20data\x20must\x20match\x20expected\x20value\x20(e.g.,\x20weather,\x20price\x20feed)','data_source':'OnChainConstant','host':'machine_forward','verifier_level':'none','logic_summary':'logic_equal[query(1167\x20repository.data,\x20policy,\x20key),\x20identifier[N](expected_value)]','key_queries':['repository.data'],'mitigated_risks':[],'notes':['Repository\x20address\x20declared\x20as\x20table\x20constant','Timestamp\x20keys\x20may\x20need\x20convert_number_address','quote_guard\x20context:\x20fails\x20in\x20gen_passport\x20(impack_list\x20empty),\x20works\x20in\x20on-chain\x20business\x20operations\x20(see\x20R-X1-10)']},{'id':'pattern.repository_quote_guard_subscription','business_requirement':'Repository\x20data\x20access\x20requires\x20payment\x20proof\x20(subscription\x20revenue\x20model)','data_source':'SubmittedObject','host':'repository_write','verifier_level':'level3_scene_combined','logic_summary':'Repository\x20policy\x20sets\x20quote_guard\x20(a\x20standalone\x20repository-backed\x20guard:\x20immutable\x20+\x20rep=true).\x20'+'When\x20a\x20Guard\x20queries\x20this\x20Repository\x27s\x20data\x20(query\x201167),\x20check_repository_quote_guard\x20verifies\x20'+'the\x20quote_guard\x20is\x20in\x20impack_list.\x20The\x20quote_guard\x20itself\x20verifies\x20a\x20submitted\x20Payment\x20'+'(payment.info.for\x20matches\x20Repository,\x20payment.amount\x20meets\x20subscription\x20price).\x20'+'User\x20submits\x20Payment\x20via\x20Passport\x20→\x20quote_guard\x20verified\x20→\x20added\x20to\x20impack_list\x20→\x20query\x201167\x20passes.','key_queries':['repository.data','payment.info.for','payment.amount'],'mitigated_risks':['R-X1-10'],'applicable_industries':['subscription','travel','rental','education'],'notes':['VERIFIED:\x20passport.rs#L545-612\x20(check_repository_quote_guard),\x20passport.rs#L758-769\x20(trigger\x20at\x20query_id==1167)','Repository.owner_receive<T>\x20accepts\x20Payment\x20as\x20subscription\x20revenue','quote_guard\x20must\x20be\x20a\x20standalone\x20repository-backed\x20guard:\x20immutable=true,\x20relies\x20empty,\x20rep=true','VERIFIER-EVIDENCE\x20DESIGN:\x20user\x20submits\x20valid\x20Payment,\x20quote_guard\x20verifies\x20Payment\x20fields\x20—\x20no\x20object-linker\x20binding\x20needed','gen_passport\x20context:\x20quote_guard\x20fails\x20(impack_list\x20empty)\x20—\x20only\x20use\x20for\x20on-chain\x20business\x20operations','Business\x20model:\x20data\x20provider\x20publishes\x20weather/market/oracle\x20data\x20to\x20Repository,\x20'+'users\x20pay\x20subscription\x20to\x20access\x20data\x20in\x20their\x20Machine\x20flows','MODE\x20A\x20(direct\x20payment\x20verify)\x20—\x20four\x20verifiable\x20elements\x20on\x20the\x20submitted\x20Payment:\x20'+'1)\x20amount:\x20logic_as_u256_ge[payment.amount,\x20N]\x20(>=\x20subscription\x20price);\x20'+'2)\x20subscription\x20type:\x20payment.info.remark\x20/\x20payment.info.index\x20encodes\x20the\x20tier/plan;\x20'+'3)\x20fixed\x20recipient:\x20payment.record.recipient\x20must\x20equal\x20the\x20designated\x20payee\x20(Treasury/owner\x20address);\x20'+'4)\x20occurrence\x20time:\x20payment.time\x20within\x20the\x20validity\x20window\x20(logic_as_u256_ge/le\x20vs\x20context(Clock))','Payment\x20is\x20freeze_object\x20after\x20creation\x20—\x20all\x20four\x20elements\x20are\x20tamper-proof\x20evidence','For\x20a\x20LOWER\x20user-cost\x20variant\x20(no\x20per-user\x20payment\x20submission),\x20see\x20pattern.repository_whitelist_sync\x20(Mode\x20B)']},{'id':'pattern.repository_whitelist_sync','business_requirement':'Entitlement\x20check\x20via\x20a\x20synced\x20allowlist\x20Repository\x20instead\x20of\x20per-user\x20payment\x20submission\x20(low-friction\x20entitlements:\x20memberships,\x20authorizations,\x20paid-user\x20lists)','data_source':'OnChainConstant','host':'machine_forward','verifier_level':'none','logic_summary':'Off-chain\x20collector\x20gathers\x20eligible\x20users\x20(transfers\x20/\x20Payments\x20to\x20the\x20designated\x20receiving\x20address\x20or\x20object,\x20'+'Service\x20orders,\x20or\x20any\x20off-chain\x20record)\x20and\x20syncs\x20the\x20list\x20into\x20a\x20dedicated\x20Repository\x20object\x20'+'(entries\x20may\x20carry\x20a\x20validity\x20window,\x20e.g.\x20authorized\x20time\x20period).\x20'+'The\x20consuming\x20Guard\x20checks\x20membership\x20via\x20query\x201166/1167\x20(repository.data)\x20keyed\x20by\x20the\x20caller:\x20'+'vec_contains_address-style\x20logic_or\x20over\x20[repository.data(key=Signer)]\x20or\x20logic_equal[repository.data(...),\x20identifier[N](expected)].\x20'+'Repository\x20writes\x20go\x20through\x20the\x20id-keyed\x20data\x20write\x20operations\x20(batch\x20up\x20to\x20100\x20entries\x20per\x20tx).','key_queries':['repository.data'],'mitigated_risks':['R-X1-10'],'applicable_industries':['subscription','travel','rental','education'],'notes':['MODE\x20B\x20(whitelist\x20sync)\x20—\x20user-cost\x20optimization\x20of\x20Mode\x20A\x20(pattern.repository_quote_guard_subscription):\x20'+'users\x20do\x20NOT\x20submit\x20a\x20Payment\x20at\x20verification\x20time;\x20the\x20operator\x20proves\x20eligibility\x20off-chain\x20and\x20syncs\x20the\x20roster','TRADE-OFF:\x20eventual\x20consistency\x20—\x20the\x20roster\x20updates\x20at\x20the\x20collector\x27s\x20sync\x20frequency\x20(slight\x20delay),\x20'+'vs\x20Mode\x20A\x27s\x20instant\x20per-payment\x20proof.\x20Choose\x20by\x20business:\x20high-frequency\x20low-value\x20→\x20Mode\x20B;\x20'+'high-value\x20instant\x20entitlement\x20→\x20Mode\x20A','Entry\x20shape:\x20key\x20=\x20user\x20address\x20(or\x20derived\x20id),\x20value\x20=\x20expiry\x20timestamp\x20/\x20tier\x20/\x20scope;\x20'+'time-window\x20enforcement\x20compares\x20entry\x20value\x20against\x20context(Clock)\x20in\x20the\x20Guard','VERIFIED:\x20id-keyed\x20data\x20writes\x20(batch\x20≤100),\x20guard-ins.ts\x201166/1167\x20(repository.data\x20queries),\x20'+'standalone-guard\x20marking\x20(1167\x20marks\x20query-only\x20repositories)','The\x20collector\x20can\x20source\x20eligibility\x20from:\x20transfers\x20or\x20Payments\x20to\x20a\x20fixed\x20receiving\x20address/object,\x20'+'Service\x20orders\x20(order.service\x20==\x20designated\x20service),\x20or\x20external\x20off-chain\x20records','Repository\x20access\x20economics\x20stay\x20OUT\x20of\x20this\x20pattern\x20(K3\x2010\x20§5\x20D5\x20ruling:\x20reuse\x20Reward/Allocation\x20'+'outside\x20the\x20Repository\x20for\x20payment;\x20the\x20Repository\x20here\x20is\x20the\x20roster,\x20not\x20the\x20payment\x20rail)']},{'id':'pattern.supply_chain_suborder_verification','business_requirement':'Sub-service\x20purchase\x20requires\x20ownership\x20of\x20main\x20service\x20order\x20(supply\x20chain\x20milestone\x20unlock)','data_source':'SubmittedObject','host':'service_buy_guard','verifier_level':'level2_identity_set','logic_summary':'Sub-service\x20buy_guard\x20verifies\x20submitted\x20main\x20Order:\x20'+'logic_and[logic_equal[query(order.owner),\x20context(Signer)],\x20logic_equal[query(order.service),\x20identifier[N](main_service_address)]].\x20'+'User\x20submits\x20main\x20Order\x20via\x20Passport\x20(b_submission=true),\x20buy_guard\x20verifies\x20ownership\x20+\x20service\x20match.','key_queries':['order.owner','order.service'],'mitigated_risks':['R-C3-05'],'applicable_industries':['travel','rental','education','freelance'],'notes':['VERIFIER-EVIDENCE\x20DESIGN:\x20user\x20submits\x20main\x20Order\x20as\x20evidence,\x20buy_guard\x20verifies\x20order.owner==Signer\x20AND\x20order.service==main_service','Each\x20milestone\x20=\x20one\x20sub-order\x20with\x20its\x20own\x20Service\x20+\x20buy_guard\x20referencing\x20the\x20main\x20order','Main\x20flow\x20can\x20branch\x20to\x20different\x20sub-services\x20based\x20on\x20Machine\x20node\x20progression','No\x20parent_order\x20field\x20needed\x20—\x20relationship\x20verified\x20via\x20buy_guard\x20querying\x20submitted\x20Order\x20fields','Enables\x20supply\x20chain\x20composition:\x20main\x20service\x20→\x20multiple\x20sub-services\x20with\x20conditional\x20access']},{'id':'pattern.payment_exception_compensation','business_requirement':'Exception\x20branch\x20triggers\x20compensation\x20Payment\x20(e.g.,\x20delivery\x20delay\x20>\x2030min\x20auto-compensates\x20customer)','data_source':'SubmittedObject','host':'machine_forward','verifier_level':'level3_scene_combined','logic_summary':'Exception\x20forward\x20guard\x20verifies\x204-dimensional\x20anti-reuse\x20binding:\x20logic_and['+'logic_equal[query(payment.info.for),\x20identifier[N](order_address)],\x20'+'logic_equal[query(payment.info.guard),\x20identifier[N](this_guard_address)],\x20'+'logic_as_u256_ge[query(payment.amount),\x20identifier[N](compensation_amount)],\x20'+'logic_as_u256_equal[query(payment.info.index),\x20query(progress.history\x20count)],\x20'+'logic_string_nocase_equal[query(payment.info.remark),\x20query(progress.current)]].\x20'+'Treasury\x20withdraws\x20to\x20customer\x20with\x20PaymentInfo(for_object=order,\x20for_guard=this,\x20index=history_count_at_creation,\x20remark=node_name).\x20'+'Customer\x20submits\x20Payment\x20via\x20Passport;\x20guard\x20verifies\x20index\x20matches\x20current\x20unique\x20step\x20(progress.history\x20count,\x20U64,\x20monotonically\x20increasing\x20—\x20unique\x20even\x20in\x20cycles)\x20AND\x20remark\x20matches\x20current\x20node\x20name\x20(progress.current,\x20String\x20—\x20may\x20repeat\x20across\x20cycles\x20but\x20bound\x20to\x20this\x20step\x20by\x20index).','key_queries':['payment.info.for','payment.info.guard','payment.info.index','payment.info.remark','payment.amount','progress.history\x20count','progress.current'],'mitigated_risks':[],'applicable_industries':['rental','travel','general','freelance'],'notes':['VERIFIED:\x20PaymentInfo\x20(for_object,\x20for_guard,\x20remark,\x20index),\x20payment_info_with_guard','VERIFIED:\x20withdraw\x20creates\x20the\x20Payment\x20as\x20a\x20fresh\x20singleton\x20object\x20from\x20the\x20withdrawn\x20object\x20set','Payment\x20is\x20freeze_object\x20(immutable)\x20—\x20cannot\x20be\x20modified\x20after\x20creation','VERIFIED\x20INDEX\x20QUERY:\x20progress.history\x20count\x20(id\x201273,\x20U64)\x20—\x20guard-ins.ts#L1228-1237.\x20Each\x20accomplished\x20forward\x20pushes\x20a\x20new\x20History\x20entry;\x20the\x20history\x20length\x20returns\x20the\x20current\x20session\x20id.\x20This\x20count\x20is\x20the\x20unique\x20monotonically\x20increasing\x20step\x20index\x20—\x20even\x20in\x20cycles,\x20each\x20entry\x20has\x20a\x20different\x20count.','VERIFIED\x20NODE\x20NAME\x20QUERY:\x20progress.current\x20(id\x201253,\x20String)\x20—\x20guard-ins.ts#L1025-1032.\x20Returns\x20the\x20current\x20node\x20name.\x20A\x20node\x20CAN\x20be\x20entered\x20multiple\x20times\x20in\x20cycles,\x20so\x20node\x20name\x20alone\x20is\x20NOT\x20unique\x20—\x20it\x20MUST\x20be\x20paired\x20with\x20progress.history\x20count\x20for\x20uniqueness.','DESIGN\x20INTENT\x20(USER):\x20to\x20validate\x20index\x20(U64\x20type),\x20use\x20progress.history\x20count\x20(unique,\x20non-repeating);\x20to\x20validate\x20node\x20name\x20(may\x20repeat\x20in\x20cycles),\x20store\x20it\x20in\x20PaymentInfo.remark\x20and\x20do\x20string\x20comparison\x20with\x20progress.current.','ANTI-REUSE\x204-DIMENSIONAL\x20BINDING:\x20for_object\x20(Order)\x20+\x20for_guard\x20(Guard)\x20+\x20index\x20(unique\x20step\x20via\x20progress.history\x20count)\x20+\x20remark\x20(node\x20name\x20via\x20progress.current).\x20Same\x20Payment\x20cannot\x20be\x20reused\x20in\x20other\x20contexts\x20—\x20at\x20least\x20one\x20field\x20will\x20mismatch.','VERIFIER-EVIDENCE\x20DESIGN:\x20customer\x20submits\x20Payment,\x20guard\x20verifies\x20binding\x20fields\x20match\x20current\x20context','Enables\x20user-friendly\x20exception\x20handling:\x20delay\x20→\x20auto-compensation\x20→\x20friendly\x20branch\x20flow','No\x20object-linker\x20binding\x20registration\x20needed\x20—\x20guard\x20only\x20verifies\x20submitted\x20Payment\x27s\x20field\x20accuracy']},{'id':'pattern.verifier_evidence_philosophy','business_requirement':'Guard\x20design\x20philosophy:\x20verifier\x20provides\x20evidence,\x20guard\x20verifies\x20logic\x20+\x20data\x20accuracy\x20(NOT\x20data\x20discovery)','data_source':'SubmittedObject','host':'gen_passport','verifier_level':'none','logic_summary':'Guard\x20is\x20a\x20PURE\x20VERIFICATION\x20engine.\x20Participants\x20submit\x20evidence\x20(Payment,\x20Order,\x20Proof,\x20etc.)\x20'+'via\x20Passport\x20submissions\x20(b_submission=true).\x20Guard\x20verifies:\x20(1)\x20logic\x20completeness,\x20(2)\x20data\x20usage\x20accuracy.\x20'+'Guard\x20does\x20NOT\x20discover/fetch\x20objects\x20via\x20object-linker\x20binding.\x20object-linker\x20binding\x20is\x20for\x20object\x20lifecycle\x20bookkeeping,\x20'+'NOT\x20for\x20guard\x20data\x20discovery.','key_queries':[],'mitigated_risks':['R-C3-05','R-C3-06'],'notes':['CORE\x20PRINCIPLE:\x20Guard\x20only\x20validates\x20submitted\x20evidence\x20—\x20it\x20never\x20fetches\x20data\x20on\x20its\x20own','For\x20Payment\x20verification:\x20user\x20submits\x20valid\x20Payment\x20→\x20guard\x20checks\x20for_object/for_guard/index\x20match','For\x20multi-order\x20verification:\x20verifier\x20submits\x20Order\x20data\x20→\x20guard\x20checks\x20service/owner\x20relationships','For\x20Repository\x20access:\x20user\x20submits\x20Payment\x20→\x20quote_guard\x20verifies\x20→\x20impack_list\x20updated\x20→\x20data\x20query\x20passes','Type\x203\x20(SubmittedObject)\x20data\x20source\x20class\x20embodies\x20this\x20philosophy\x20—\x20b_submission=true\x20entries','This\x20pattern\x20is\x20foundational\x20for\x20all\x20guard\x20designs\x20—\x20always\x20prefer\x20verifier-evidence\x20over\x20complex\x20object\x20discovery']},{'id':'pattern.progress_state_check','business_requirement':'Specific\x20forward\x20has\x20been\x20accomplished\x20(customer\x20confirms\x20delivery)','data_source':'WitnessDerived','host':'reward_claim','verifier_level':'none','logic_summary':'logic_equal[query_progress_history_find(...).accomplished,\x20identifier[N](true)]','key_queries':['progress.current','progress.current_time'],'witness_types':['OrderProgress'],'mitigated_risks':[],'notes':['Chain\x20query_progress_history_find\x20→\x20query_progress_history_session_forward_find']},{'id':'pattern.reward_one_time_claim','business_requirement':'User\x20can\x20only\x20claim\x20reward\x20once\x20(no\x20prior\x20claims)','data_source':'OnChainConstant','host':'reward_claim','verifier_level':'none','logic_summary':'logic_equal[query_reward_record_count(recipient=Signer),\x20identifier[N](0)]','key_queries':['reward.record_count'],'mitigated_risks':[],'notes':['Record\x20count\x20check\x20prevents\x20double-claim']},{'id':'pattern.reward_multi_condition','business_requirement':'Order\x20payment\x20>\x20threshold\x20AND\x20reached\x20\x27complete\x27\x20to\x20claim\x20reward','data_source':'WitnessDerived','host':'reward_claim','verifier_level':'none','logic_summary':'logic_and[logic_as_u256_gt[query(order.amount),\x20threshold],\x20logic_equal[query(progress.current),\x20\x27complete\x27],\x20logic_equal[query(order.service),\x20identifier[N](expected_service)]]','key_queries':['order.amount','progress.current','order.service'],'witness_types':['OrderProgress'],'mitigated_risks':['R-C3-05'],'notes':['Multi-condition:\x20amount\x20+\x20progress\x20state\x20+\x20service\x20match']},{'id':'pattern.arbitration_voting_weight','business_requirement':'Vote\x20weight\x20equals\x20reputation\x20score\x20(dynamic\x20weight\x20from\x20Passport)','data_source':'SubmittedObject','host':'arbitration_voting','verifier_level':'none','logic_summary':'GuardIdentifier\x20extracts\x20numeric\x20value\x20from\x20Passport\x20submission','key_queries':[],'mitigated_risks':['R-C3-02'],'notes':['Table\x20needs\x20numeric\x20submission\x20entry\x20at\x20referenced\x20index','Weight\x20must\x20come\x20from\x20on-chain\x20EntityRegistrar,\x20not\x20submission','BINDING_01:\x20voting_guard\x20GuardIdentifier\x20must\x20be\x20numeric\x20(U8-U256)','C-9\x20VERIFIED:\x20voting\x20is\x20OPTIONAL\x20—\x20voting_deadline\x20is\x20Option\x20'+'(None\x20=\x20open-ended\x20voting;\x20arbitration\x20can\x20proceed\x20whenever\x20the\x20arbiter\x20decides).\x20'+'NO\x20minimum\x20voter\x20quorum\x20is\x20required\x20on-chain:\x20the\x20arbiter\x20may\x20rule\x20with\x20any\x20number\x20'+'of\x20votes\x20(including\x20zero).\x20MAX_ARBITRATOR_VOTING=520\x20is\x20only\x20an\x20upper\x20bound.\x20'+'Open\x20voting\x20(empty\x20voting_guard)\x20gives\x20every\x20vote\x20weight\x201\x20(the\x20vote\x20handler\x20asserts\x20the\x20guard\x20is\x20empty).']},{'id':'pattern.arbitration_membership_check','business_requirement':'Only\x20premium\x20members\x20can\x20file\x20disputes','data_source':'OnChainConstant','host':'arbitration_usage','verifier_level':'none','logic_summary':'logic_and[query(entity\x20exists),\x20logic_as_u256_ge[query(entity\x20tier),\x20identifier[N](premium_tier)]]','key_queries':['entity.registrar','entity.linker'],'mitigated_risks':[],'notes':['ENTITY_REGISTRAR_ADDRESS\x20(0xaab)\x20/\x20ENTITY_LINKER_ADDRESS\x20(0xaaa)\x20must\x20be\x20in\x20table']},{'id':'pattern.scene_allocator_entity_recipient','business_requirement':'Service\x20allocator\x20with\x20sharing.who=Entity\x20—\x20no\x20Signer\x20binding\x20needed','data_source':'OnChainConstant','host':'service_allocator_guard','verifier_level':'level3_scene_combined','logic_summary':'Scene\x20verifies\x20fund\x20flow\x20safety\x20—\x20Guard\x20only\x20validates\x20allocation\x20rules','key_queries':['service.permission','order.amount'],'mitigated_risks':['R-C3-06'],'notes':['Funds\x20flow\x20to\x20fixed\x20Treasury/address\x20regardless\x20of\x20caller','sharing.who=Entity\x20already\x20guarantees\x20recipient\x20safety','No\x20Signer\x20binding\x20required\x20—\x20R-C3-06\x20safe']},{'id':'pattern.scene_machine_forward_operator','business_requirement':'Machine\x20forward\x20with\x20permissionIndex/namedOperator\x20already\x20verifies\x20operator','data_source':'OnChainConstant','host':'machine_forward','verifier_level':'level3_scene_combined','logic_summary':'Forward\x27s\x20permissionIndex/namedOperator\x20verifies\x20operator\x20—\x20Guard\x20only\x20validates\x20submitted\x20data','key_queries':[],'mitigated_risks':[],'notes':['Scene\x20verifies\x20operator\x20permission\x20via\x20permissionIndex/namedOperator','Signer\x20binding\x20only\x20needed\x20if\x20submitted\x20data\x20must\x20belong\x20to\x20operator','Evaluate\x20scene\x20before\x20adding\x20Signer\x20binding']},{'id':'pattern.fund_flow_refund_freeform','business_requirement':'Refund\x20/\x20cancellation\x20fund-release\x20defined\x20purely\x20by\x20game\x20conditions\x20—\x20NOT\x20bound\x20to\x20any\x20Machine\x20node','data_source':'SubmittedObject','host':'service_allocator_guard','verifier_level':'level2_identity_set','logic_summary':'An\x20allocator\x20Guard\x20whose\x20root\x20encodes\x20refund\x20conditions\x20ARBITRARILY:\x20'+'buyer\x20signature\x20(logic_equal[Signer,\x20buyer]),\x20timeout\x20(logic_as_u256_ge[Clock,\x20deadline]),\x20'+'evidence\x20state\x20(query\x20any\x20on-chain\x20object:\x20order\x20fields,\x20repository\x20data,\x20payment\x20proofs),\x20'+'arbitration\x20outcome,\x20or\x20any\x20logic_and/or\x20combination.\x20No\x20progress/current-node\x20query\x20required.','key_queries':['order.owner','order.service','order.amount'],'mitigated_risks':['R-C3-06'],'notes':['C-2\x20RESOLUTION:\x20Machine-node-triggered\x20refund\x20(\x27at\x20cancelled\x20node\x20→\x20release\x27)\x20is\x20only\x20ONE\x20application\x20pattern.\x20'+'Guard+Allocator\x20is\x20a\x20GENERAL\x20game\x20primitive:\x20the\x20refund\x20condition\x20tree\x20is\x20fully\x20free-form.\x20'+'Move\x20layer\x20needs\x20NO\x20change\x20—\x20Guard\x20roots\x20accept\x20arbitrary\x20logic\x20over\x20any\x20queryable\x20state.','GAME-THEORETIC\x20READING:\x20both\x20parties\x20should\x20evaluate\x20the\x20refund\x20Guard\x20BEFORE\x20transacting\x20—\x20'+'who\x20can\x20trigger\x20it,\x20under\x20which\x20conditions,\x20with\x20what\x20evidence.\x20Use\x20the\x20analyze_guard_semantics\x20'+'query\x20action\x20to\x20render\x20+\x20lint\x20any\x20Guard\x20and\x20reason\x20about\x20each\x20party\x27s\x20leverage.','Condition\x20dimensions\x20freely\x20composable:\x20identity\x20(Signer/Entity),\x20time\x20(Clock),\x20'+'counterparty\x20evidence\x20(submitted\x20Payment/Order/Proof),\x20shared\x20data\x20(Repository),\x20'+'workflow\x20state\x20(Progress\x20—\x20optional,\x20only\x20when\x20a\x20Machine\x20exists)','Multi-tier\x20refund:\x20multiple\x20allocators\x20with\x20first-match-wins\x20order\x20encode\x20graduated\x20policies\x20'+'(full\x20refund\x20pre-delivery,\x20partial\x20refund\x20post-milestone,\x20no\x20refund\x20post-acceptance)\x20as\x20SEPARATE\x20Guards']},{'id':'pattern.fund_flow_profit_share_freeform','business_requirement':'Revenue/profit\x20sharing\x20among\x20partners\x20triggered\x20by\x20verifiable\x20contribution\x20conditions\x20—\x20not\x20by\x20workflow\x20nodes','data_source':'OnChainConstant','host':'service_allocator_guard','verifier_level':'level3_scene_combined','logic_summary':'Allocator\x20sharing\x20(who+ratio)\x20defines\x20the\x20SPLIT;\x20the\x20Guard\x20defines\x20WHEN\x20the\x20split\x20executes.\x20'+'The\x20WHEN\x20is\x20free-form:\x20period\x20boundary\x20(Clock\x20vs\x20interval),\x20contribution\x20proof\x20(submitted\x20evidence),\x20'+'performance\x20threshold\x20(Repository\x20metric),\x20or\x20counterparty\x20co-signature.','key_queries':['repository.data','payment.amount'],'mitigated_risks':['R-C3-06'],'applicable_industries':['freelance','subscription','education'],'notes':['C-2\x20RESOLUTION:\x20profit-sharing\x20is\x20an\x20application\x20pattern\x20of\x20the\x20same\x20Guard+Allocator\x20primitive\x20—\x20'+'the\x20trigger\x20condition\x20tree\x20is\x20arbitrary\x20game\x20logic,\x20not\x20a\x20workflow\x20artifact.','sharing.who=Entity\x20recipients\x20make\x20the\x20split\x20caller-safe\x20(funds\x20flow\x20to\x20fixed\x20addresses)\x20—\x20'+'Guard\x20then\x20only\x20gates\x20TIMING/CONDITIONS,\x20not\x20identity\x20(R-C3-06\x20safe\x20by\x20scene)','Periodic\x20settlement:\x20logic_as_u256_ge[Clock,\x20identifier[N](period_start)]\x20+\x20'+'logic_as_u256_equal[calc_number_mod[Clock,\x20interval],\x200]-style\x20windows,\x20'+'or\x20a\x20Repository-held\x20settlement\x20cursor\x20updated\x20after\x20each\x20allocation\x20run']},{'id':'pattern.permission_guard_entity_time_window','business_requirement':'Delegate\x20a\x20permission\x20index\x20to\x20a\x20Guard\x20object\x20address\x20—\x20authorization\x20that\x20self-enforces\x20and\x20self-expires\x20(time-windowed\x20delegation)','data_source':'SystemContext','host':'machine_forward','verifier_level':'none','logic_summary':'The\x20entity\x20table\x20accepts\x20\x27user/guard\x20address\x20&\x20permission_index\x20list\x27\x20—\x20'+'a\x20Guard\x27s\x20OWN\x20ADDRESS\x20can\x20hold\x20a\x20permission\x20index.\x20The\x20delegated\x20Guard\x20then\x20encodes\x20'+'temporal\x20+\x20contextual\x20conditions:\x20logic_and[logic_as_u256_ge[Clock,\x20valid_from],\x20'+'logic_as_u256_le[Clock,\x20valid_until],\x20<scene\x20conditions>].\x20'+'Callers\x20satisfying\x20the\x20Guard\x20act\x20with\x20the\x20delegated\x20permission\x20index.','key_queries':[],'mitigated_risks':[],'notes':['C-8\x20VERIFIED:\x20entity\x20table\x20comment\x20—\x20\x27user/guard\x20address\x20&\x20permission_index\x20list\x27\x20'+'(guard\x20addresses\x20are\x20first-class\x20permission\x20entities,\x20same\x20as\x20user\x20addresses)','TIME\x20WINDOW:\x20Guard\x20roots\x20compose\x20context(Clock)\x20freely\x20—\x20valid_from/valid_until\x20bounds,\x20'+'recurring\x20windows\x20(mod\x20arithmetic),\x20or\x20deadline-before\x20(authorize\x20only\x20until\x20expiry)','SELF-EXPIRING\x20DELEGATION:\x20after\x20valid_until\x20the\x20Guard\x20fails\x20for\x20everyone\x20—\x20no\x20on-chain\x20'+'revocation\x20transaction\x20needed,\x20no\x20trust\x20in\x20the\x20delegate\x20to\x20stop\x20acting','SCENARIO\x20COMBINATION\x20(scenario\x20layer):\x20temporary\x20operator\x20(holiday\x20cover),\x20seasonal\x20service\x20window,\x20'+'trial-period\x20customer\x20privileges,\x20contractor\x20time-boxed\x20access,\x20emergency-break-glass\x20with\x20auto-expiry','Design\x20tip:\x20combine\x20with\x20scene\x20conditions\x20(order\x20state,\x20submitted\x20evidence)\x20—\x20'+'time\x20bounds\x20rarely\x20stand\x20alone']}];export const VERIFIER_LEVEL_GUIDANCE=[{'level':'level1_strict_single','pattern':'logic_equal[context(Signer),\x20identifier[N](fixed_address)]','when_to_use':'Role\x20permanently\x20tied\x20to\x20one\x20address\x20AND\x20designer\x20accepts\x20lock-in\x20risk','risk_rules':['R-C4-04'],'recommendation':'avoid'},{'level':'level2_identity_set','pattern':'logic_or\x20of\x20multiple\x20identity\x20checks','when_to_use':'Role-based\x20access\x20—\x20multiple\x20authorized\x20identities','risk_rules':['R-C4-04\x20(suppressed)'],'recommendation':'recommended'},{'level':'level3_scene_combined','pattern':'Scene\x20itself\x20verifies\x20identity\x20—\x20no\x20Signer\x20binding\x20needed','when_to_use':'Scene\x27s\x20host\x20object\x20already\x20verifies\x20operator\x20(e.g.,\x20Machine\x20forward,\x20sharing.who=Entity)','risk_rules':[],'recommendation':'default'},{'level':'none','pattern':'No\x20Signer\x20binding\x20required','when_to_use':'Resource\x20flow\x20matters\x20more\x20than\x20caller\x20identity','risk_rules':[],'recommendation':'default'}];export function getGuardDesignPattern(a){return GUARD_DESIGN_PATTERNS['find'](b=>b['id']===a);}export function searchGuardDesignPatterns(a){const b=a['toLowerCase']();return GUARD_DESIGN_PATTERNS['filter'](c=>{if(c['business_requirement']['toLowerCase']()['includes'](b))return!![];if(c['logic_summary']['toLowerCase']()['includes'](b))return!![];if(c['key_queries']['some'](d=>d['toLowerCase']()['includes'](b)))return!![];return![];});}export function getPatternsByHost(a){return GUARD_DESIGN_PATTERNS['filter'](b=>b['host']===a);}export function getPatternsByIndustry(a){return GUARD_DESIGN_PATTERNS['filter'](b=>b['applicable_industries']?.['includes'](a));}export function getPatternsByDataSourceClass(a){return GUARD_DESIGN_PATTERNS['filter'](b=>b['data_source']===a);}export function getVerifierLevelGuidance(a){return VERIFIER_LEVEL_GUIDANCE['find'](b=>b['level']===a);}export function suggestPatternForRequirement(a){const b=searchGuardDesignPatterns(a);if(b['length']===0x0){const e=GUARD_DESIGN_PATTERNS[0x0];return{'best':e,'alternatives':[]};}const [c,...d]=b;return{'best':c,'alternatives':d};}export const GUARD_DESIGN_PATTERNS_VERSION=0x2;
1
+ export const GUARD_DESIGN_PATTERNS=[{'id':'pattern.identity_check_single','business_requirement':'Only\x20the\x20author\x20can\x20purchase\x20this\x20service\x20(strict\x20single-identity)','data_source':'SystemContext','host':'service_buy_guard','verifier_level':'level1_strict_single','logic_summary':'logic_equal[context(Signer),\x20identifier[N](fixed_address)]','key_queries':[],'mitigated_risks':['R-C4-04'],'notes':['Maximally\x20secure\x20but\x20maximally\x20inconvenient','If\x20address\x20is\x20unavailable\x20(key\x20loss,\x20rotation),\x20Guard\x20permanently\x20blocks','Avoid\x20unless\x20role\x20is\x20permanently\x20tied\x20to\x20one\x20address']},{'id':'pattern.identity_check_allowlist','business_requirement':'Customer\x20must\x20be\x20in\x20an\x20allowlist\x20to\x20purchase','data_source':'SystemContext','host':'service_buy_guard','verifier_level':'level2_identity_set','logic_summary':'vec_contains_address[identifier[N](allowlist_vec),\x20context(Signer)]','key_queries':[],'mitigated_risks':['R-C4-04'],'notes':['Allowlist\x20stored\x20as\x20Address\x20vector\x20in\x20table\x20constant']},{'id':'pattern.identity_check_order_holder','business_requirement':'Only\x20order\x20owner\x20or\x20agent\x20can\x20perform\x20operation','data_source':'OnChainConstant','host':'machine_forward','verifier_level':'level2_identity_set','logic_summary':'logic_or[logic_equal[query(1562\x20order.owner),\x20context(Signer)],\x20query(1567\x20order.agent\x20has,\x20Signer)]','key_queries':['order.owner','order.agent\x20has'],'mitigated_risks':['R-C4-04','R-C3-06'],'notes':['1562\x20returns\x20Address\x20→\x20wrap\x20in\x20logic_equal','1567\x20returns\x20Bool\x20→\x20use\x20directly\x20as\x20logic_or\x20child','Recommended\x20Level\x202\x20alternative\x20to\x20Level\x201\x20strict\x20binding']},{'id':'pattern.identity_check_service_provider_dynamic','business_requirement':'Verify\x20caller\x20is\x20service\x27s\x20current\x20permission\x20owner\x20(survives\x20permission\x20rotation)','data_source':'SubmittedObject','host':'machine_forward','verifier_level':'level2_identity_set','logic_summary':'logic_and[logic_equal[query(1488\x20service.permission),\x20identifier[N](submitted_perm)],\x20logic_or[logic_equal[query(1002\x20permission.owner),\x20context(Signer)],\x20query(1004\x20permission.admin\x20has,\x20Signer)]]','key_queries':['service.permission','permission.owner','permission.admin\x20has'],'mitigated_risks':['R-C4-04','R-C3-05'],'notes':['Dynamic\x20permission\x20address\x20(RECOMMENDED)\x20—\x20survives\x20Service\x20permission\x20rotation','Caller\x20submits\x20permission\x20address;\x20Guard\x20verifies\x20match\x20then\x20checks\x20identity','More\x20complex\x20than\x20static\x20but\x20far\x20more\x20robust']},{'id':'pattern.time_lock_progress','business_requirement':'Customer\x20must\x20wait\x20N\x20hours\x20before\x20completing\x20(time-lock)','data_source':'WitnessDerived','host':'machine_forward','verifier_level':'none','logic_summary':'logic_as_u256_greater_or_equal[context(Clock),\x20calc_number_add[query(1272\x20progress.current_time,\x20witness=OrderProgress),\x20identifier[N](duration_ms)]]','key_queries':['progress.current_time'],'witness_types':['OrderProgress'],'mitigated_risks':[],'notes':['Use\x20convert_witness=100\x20(OrderProgress)\x20to\x20derive\x20Progress\x20from\x20submitted\x20Order\x20ID','Duration\x20in\x20milliseconds\x20—\x20test\x20with\x20small\x20values\x20first']},{'id':'pattern.time_lock_absolute','business_requirement':'Operation\x20allowed\x20only\x20after\x20a\x20fixed\x20timestamp','data_source':'SystemContext','host':'service_buy_guard','verifier_level':'none','logic_summary':'logic_as_u256_greater_or_equal[context(Clock),\x20identifier[N](release_timestamp)]','key_queries':[],'mitigated_risks':[],'notes':['Useful\x20for\x20pre-sale\x20windows,\x20embargo\x20periods']},{'id':'pattern.repository_data_check','business_requirement':'External\x20data\x20must\x20match\x20expected\x20value\x20(e.g.,\x20weather,\x20price\x20feed)','data_source':'OnChainConstant','host':'machine_forward','verifier_level':'none','logic_summary':'logic_equal[query(1167\x20repository.data,\x20policy,\x20key),\x20identifier[N](expected_value)]','key_queries':['repository.data'],'mitigated_risks':[],'notes':['Repository\x20address\x20declared\x20as\x20table\x20constant','Timestamp\x20keys\x20may\x20need\x20convert_number_address','quote_guard\x20context:\x20fails\x20in\x20gen_passport\x20(impack_list\x20empty),\x20works\x20in\x20on-chain\x20business\x20operations\x20(see\x20R-X1-10)']},{'id':'pattern.repository_quote_guard_subscription','business_requirement':'Repository\x20data\x20access\x20requires\x20payment\x20proof\x20(subscription\x20revenue\x20model)','data_source':'SubmittedObject','host':'repository_write','verifier_level':'level3_scene_combined','logic_summary':'Repository\x20policy\x20sets\x20quote_guard\x20(a\x20standalone\x20repository-backed\x20guard:\x20immutable\x20+\x20rep=true).\x20'+'When\x20a\x20Guard\x20queries\x20this\x20Repository\x27s\x20data\x20(query\x201167),\x20check_repository_quote_guard\x20verifies\x20'+'the\x20quote_guard\x20is\x20in\x20impack_list.\x20The\x20quote_guard\x20itself\x20verifies\x20a\x20submitted\x20Payment\x20'+'(payment.info.for\x20matches\x20Repository,\x20payment.amount\x20meets\x20subscription\x20price).\x20'+'User\x20submits\x20Payment\x20via\x20Passport\x20→\x20quote_guard\x20verified\x20→\x20added\x20to\x20impack_list\x20→\x20query\x201167\x20passes.','key_queries':['repository.data','payment.info.for','payment.amount'],'mitigated_risks':['R-X1-10'],'applicable_industries':['subscription','travel','rental','education'],'notes':['VERIFIED:\x20passport.rs#L545-612\x20(check_repository_quote_guard),\x20passport.rs#L758-769\x20(trigger\x20at\x20query_id==1167)','Repository.owner_receive<T>\x20accepts\x20Payment\x20as\x20subscription\x20revenue','quote_guard\x20must\x20be\x20a\x20standalone\x20repository-backed\x20guard:\x20immutable=true,\x20relies\x20empty,\x20rep=true','VERIFIER-EVIDENCE\x20DESIGN:\x20user\x20submits\x20valid\x20Payment,\x20quote_guard\x20verifies\x20Payment\x20fields\x20—\x20no\x20object-linker\x20binding\x20needed','gen_passport\x20context:\x20quote_guard\x20fails\x20(impack_list\x20empty)\x20—\x20only\x20use\x20for\x20on-chain\x20business\x20operations','Business\x20model:\x20data\x20provider\x20publishes\x20weather/market/oracle\x20data\x20to\x20Repository,\x20'+'users\x20pay\x20subscription\x20to\x20access\x20data\x20in\x20their\x20Machine\x20flows','MODE\x20A\x20(direct\x20payment\x20verify)\x20—\x20four\x20verifiable\x20elements\x20on\x20the\x20submitted\x20Payment:\x20'+'1)\x20amount:\x20logic_as_u256_greater_or_equal[payment.amount,\x20N]\x20(>=\x20subscription\x20price);\x20'+'2)\x20subscription\x20type:\x20payment.info.remark\x20/\x20payment.info.index\x20encodes\x20the\x20tier/plan;\x20'+'3)\x20fixed\x20recipient:\x20payment.record.recipient\x20must\x20equal\x20the\x20designated\x20payee\x20(Treasury/owner\x20address);\x20'+'4)\x20occurrence\x20time:\x20payment.time\x20within\x20the\x20validity\x20window\x20(logic_as_u256_greater_or_equal\x20/\x20logic_as_u256_lesser_or_equal\x20vs\x20context(Clock))','Payment\x20is\x20freeze_object\x20after\x20creation\x20—\x20all\x20four\x20elements\x20are\x20tamper-proof\x20evidence','For\x20a\x20LOWER\x20user-cost\x20variant\x20(no\x20per-user\x20payment\x20submission),\x20see\x20pattern.repository_whitelist_sync\x20(Mode\x20B)']},{'id':'pattern.repository_whitelist_sync','business_requirement':'Entitlement\x20check\x20via\x20a\x20synced\x20allowlist\x20Repository\x20instead\x20of\x20per-user\x20payment\x20submission\x20(low-friction\x20entitlements:\x20memberships,\x20authorizations,\x20paid-user\x20lists)','data_source':'OnChainConstant','host':'machine_forward','verifier_level':'none','logic_summary':'Off-chain\x20collector\x20gathers\x20eligible\x20users\x20(transfers\x20/\x20Payments\x20to\x20the\x20designated\x20receiving\x20address\x20or\x20object,\x20'+'Service\x20orders,\x20or\x20any\x20off-chain\x20record)\x20and\x20syncs\x20the\x20list\x20into\x20a\x20dedicated\x20Repository\x20object\x20'+'(entries\x20may\x20carry\x20a\x20validity\x20window,\x20e.g.\x20authorized\x20time\x20period).\x20'+'The\x20consuming\x20Guard\x20checks\x20membership\x20via\x20query\x201166/1167\x20(repository.data)\x20keyed\x20by\x20the\x20caller:\x20'+'vec_contains_address-style\x20logic_or\x20over\x20[repository.data(key=Signer)]\x20or\x20logic_equal[repository.data(...),\x20identifier[N](expected)].\x20'+'Repository\x20writes\x20go\x20through\x20the\x20id-keyed\x20data\x20write\x20operations\x20(batch\x20up\x20to\x20100\x20entries\x20per\x20tx).','key_queries':['repository.data'],'mitigated_risks':['R-X1-10'],'applicable_industries':['subscription','travel','rental','education'],'notes':['MODE\x20B\x20(whitelist\x20sync)\x20—\x20user-cost\x20optimization\x20of\x20Mode\x20A\x20(pattern.repository_quote_guard_subscription):\x20'+'users\x20do\x20NOT\x20submit\x20a\x20Payment\x20at\x20verification\x20time;\x20the\x20operator\x20proves\x20eligibility\x20off-chain\x20and\x20syncs\x20the\x20roster','TRADE-OFF:\x20eventual\x20consistency\x20—\x20the\x20roster\x20updates\x20at\x20the\x20collector\x27s\x20sync\x20frequency\x20(slight\x20delay),\x20'+'vs\x20Mode\x20A\x27s\x20instant\x20per-payment\x20proof.\x20Choose\x20by\x20business:\x20high-frequency\x20low-value\x20→\x20Mode\x20B;\x20'+'high-value\x20instant\x20entitlement\x20→\x20Mode\x20A','Entry\x20shape:\x20key\x20=\x20user\x20address\x20(or\x20derived\x20id),\x20value\x20=\x20expiry\x20timestamp\x20/\x20tier\x20/\x20scope;\x20'+'time-window\x20enforcement\x20compares\x20entry\x20value\x20against\x20context(Clock)\x20in\x20the\x20Guard','VERIFIED:\x20id-keyed\x20data\x20writes\x20(batch\x20≤100),\x20guard-ins.ts\x201166/1167\x20(repository.data\x20queries),\x20'+'standalone-guard\x20marking\x20(1167\x20marks\x20query-only\x20repositories)','The\x20collector\x20can\x20source\x20eligibility\x20from:\x20transfers\x20or\x20Payments\x20to\x20a\x20fixed\x20receiving\x20address/object,\x20'+'Service\x20orders\x20(order.service\x20==\x20designated\x20service),\x20or\x20external\x20off-chain\x20records','Repository\x20access\x20economics\x20stay\x20OUT\x20of\x20this\x20pattern\x20(K3\x2010\x20§5\x20D5\x20ruling:\x20reuse\x20Reward/Allocation\x20'+'outside\x20the\x20Repository\x20for\x20payment;\x20the\x20Repository\x20here\x20is\x20the\x20roster,\x20not\x20the\x20payment\x20rail)']},{'id':'pattern.supply_chain_suborder_verification','business_requirement':'Sub-service\x20purchase\x20requires\x20ownership\x20of\x20main\x20service\x20order\x20(supply\x20chain\x20milestone\x20unlock)','data_source':'SubmittedObject','host':'service_buy_guard','verifier_level':'level2_identity_set','logic_summary':'Sub-service\x20buy_guard\x20verifies\x20submitted\x20main\x20Order:\x20'+'logic_and[logic_equal[query(order.owner),\x20context(Signer)],\x20logic_equal[query(order.service),\x20identifier[N](main_service_address)]].\x20'+'User\x20submits\x20main\x20Order\x20via\x20Passport\x20(b_submission=true),\x20buy_guard\x20verifies\x20ownership\x20+\x20service\x20match.','key_queries':['order.owner','order.service'],'mitigated_risks':['R-C3-05'],'applicable_industries':['travel','rental','education','freelance'],'notes':['VERIFIER-EVIDENCE\x20DESIGN:\x20user\x20submits\x20main\x20Order\x20as\x20evidence,\x20buy_guard\x20verifies\x20order.owner==Signer\x20AND\x20order.service==main_service','Each\x20milestone\x20=\x20one\x20sub-order\x20with\x20its\x20own\x20Service\x20+\x20buy_guard\x20referencing\x20the\x20main\x20order','Main\x20flow\x20can\x20branch\x20to\x20different\x20sub-services\x20based\x20on\x20Machine\x20node\x20progression','No\x20parent_order\x20field\x20needed\x20—\x20relationship\x20verified\x20via\x20buy_guard\x20querying\x20submitted\x20Order\x20fields','Enables\x20supply\x20chain\x20composition:\x20main\x20service\x20→\x20multiple\x20sub-services\x20with\x20conditional\x20access']},{'id':'pattern.payment_exception_compensation','business_requirement':'Exception\x20branch\x20triggers\x20compensation\x20Payment\x20(e.g.,\x20delivery\x20delay\x20>\x2030min\x20auto-compensates\x20customer)','data_source':'SubmittedObject','host':'machine_forward','verifier_level':'level3_scene_combined','logic_summary':'Exception\x20forward\x20guard\x20verifies\x204-dimensional\x20anti-reuse\x20binding:\x20logic_and['+'logic_equal[query(payment.info.for),\x20identifier[N](order_address)],\x20'+'logic_equal[query(payment.info.guard),\x20identifier[N](this_guard_address)],\x20'+'logic_as_u256_greater_or_equal[query(payment.amount),\x20identifier[N](compensation_amount)],\x20'+'logic_as_u256_equal[query(payment.info.index),\x20query(progress.history\x20count)],\x20'+'logic_string_nocase_equal[query(payment.info.remark),\x20query(progress.current)]].\x20'+'Treasury\x20withdraws\x20to\x20customer\x20with\x20PaymentInfo(for_object=order,\x20for_guard=this,\x20index=history_count_at_creation,\x20remark=node_name).\x20'+'Customer\x20submits\x20Payment\x20via\x20Passport;\x20guard\x20verifies\x20index\x20matches\x20current\x20unique\x20step\x20(progress.history\x20count,\x20U64,\x20monotonically\x20increasing\x20—\x20unique\x20even\x20in\x20cycles)\x20AND\x20remark\x20matches\x20current\x20node\x20name\x20(progress.current,\x20String\x20—\x20may\x20repeat\x20across\x20cycles\x20but\x20bound\x20to\x20this\x20step\x20by\x20index).','key_queries':['payment.info.for','payment.info.guard','payment.info.index','payment.info.remark','payment.amount','progress.history\x20count','progress.current'],'mitigated_risks':[],'applicable_industries':['rental','travel','general','freelance'],'notes':['VERIFIED:\x20PaymentInfo\x20(for_object,\x20for_guard,\x20remark,\x20index),\x20payment_info_with_guard','VERIFIED:\x20withdraw\x20creates\x20the\x20Payment\x20as\x20a\x20fresh\x20singleton\x20object\x20from\x20the\x20withdrawn\x20object\x20set','Payment\x20is\x20freeze_object\x20(immutable)\x20—\x20cannot\x20be\x20modified\x20after\x20creation','VERIFIED\x20INDEX\x20QUERY:\x20progress.history\x20count\x20(id\x201273,\x20U64)\x20—\x20guard-ins.ts#L1228-1237.\x20Each\x20accomplished\x20forward\x20pushes\x20a\x20new\x20History\x20entry;\x20the\x20history\x20length\x20returns\x20the\x20current\x20session\x20id.\x20This\x20count\x20is\x20the\x20unique\x20monotonically\x20increasing\x20step\x20index\x20—\x20even\x20in\x20cycles,\x20each\x20entry\x20has\x20a\x20different\x20count.','VERIFIED\x20NODE\x20NAME\x20QUERY:\x20progress.current\x20(id\x201253,\x20String)\x20—\x20guard-ins.ts#L1025-1032.\x20Returns\x20the\x20current\x20node\x20name.\x20A\x20node\x20CAN\x20be\x20entered\x20multiple\x20times\x20in\x20cycles,\x20so\x20node\x20name\x20alone\x20is\x20NOT\x20unique\x20—\x20it\x20MUST\x20be\x20paired\x20with\x20progress.history\x20count\x20for\x20uniqueness.','DESIGN\x20INTENT\x20(USER):\x20to\x20validate\x20index\x20(U64\x20type),\x20use\x20progress.history\x20count\x20(unique,\x20non-repeating);\x20to\x20validate\x20node\x20name\x20(may\x20repeat\x20in\x20cycles),\x20store\x20it\x20in\x20PaymentInfo.remark\x20and\x20do\x20string\x20comparison\x20with\x20progress.current.','ANTI-REUSE\x204-DIMENSIONAL\x20BINDING:\x20for_object\x20(Order)\x20+\x20for_guard\x20(Guard)\x20+\x20index\x20(unique\x20step\x20via\x20progress.history\x20count)\x20+\x20remark\x20(node\x20name\x20via\x20progress.current).\x20Same\x20Payment\x20cannot\x20be\x20reused\x20in\x20other\x20contexts\x20—\x20at\x20least\x20one\x20field\x20will\x20mismatch.','VERIFIER-EVIDENCE\x20DESIGN:\x20customer\x20submits\x20Payment,\x20guard\x20verifies\x20binding\x20fields\x20match\x20current\x20context','Enables\x20user-friendly\x20exception\x20handling:\x20delay\x20→\x20auto-compensation\x20→\x20friendly\x20branch\x20flow','No\x20object-linker\x20binding\x20registration\x20needed\x20—\x20guard\x20only\x20verifies\x20submitted\x20Payment\x27s\x20field\x20accuracy']},{'id':'pattern.verifier_evidence_philosophy','business_requirement':'Guard\x20design\x20philosophy:\x20verifier\x20provides\x20evidence,\x20guard\x20verifies\x20logic\x20+\x20data\x20accuracy\x20(NOT\x20data\x20discovery)','data_source':'SubmittedObject','host':'gen_passport','verifier_level':'none','logic_summary':'Guard\x20is\x20a\x20PURE\x20VERIFICATION\x20engine.\x20Participants\x20submit\x20evidence\x20(Payment,\x20Order,\x20Proof,\x20etc.)\x20'+'via\x20Passport\x20submissions\x20(b_submission=true).\x20Guard\x20verifies:\x20(1)\x20logic\x20completeness,\x20(2)\x20data\x20usage\x20accuracy.\x20'+'Guard\x20does\x20NOT\x20discover/fetch\x20objects\x20via\x20object-linker\x20binding.\x20object-linker\x20binding\x20is\x20for\x20object\x20lifecycle\x20bookkeeping,\x20'+'NOT\x20for\x20guard\x20data\x20discovery.','key_queries':[],'mitigated_risks':['R-C3-05','R-C3-06'],'notes':['CORE\x20PRINCIPLE:\x20Guard\x20only\x20validates\x20submitted\x20evidence\x20—\x20it\x20never\x20fetches\x20data\x20on\x20its\x20own','For\x20Payment\x20verification:\x20user\x20submits\x20valid\x20Payment\x20→\x20guard\x20checks\x20for_object/for_guard/index\x20match','For\x20multi-order\x20verification:\x20verifier\x20submits\x20Order\x20data\x20→\x20guard\x20checks\x20service/owner\x20relationships','For\x20Repository\x20access:\x20user\x20submits\x20Payment\x20→\x20quote_guard\x20verifies\x20→\x20impack_list\x20updated\x20→\x20data\x20query\x20passes','Type\x203\x20(SubmittedObject)\x20data\x20source\x20class\x20embodies\x20this\x20philosophy\x20—\x20b_submission=true\x20entries','This\x20pattern\x20is\x20foundational\x20for\x20all\x20guard\x20designs\x20—\x20always\x20prefer\x20verifier-evidence\x20over\x20complex\x20object\x20discovery']},{'id':'pattern.progress_state_check','business_requirement':'Specific\x20forward\x20has\x20been\x20accomplished\x20(customer\x20confirms\x20delivery)','data_source':'WitnessDerived','host':'reward_claim','verifier_level':'none','logic_summary':'logic_equal[query_progress_history_find(...).accomplished,\x20identifier[N](true)]','key_queries':['progress.current','progress.current_time'],'witness_types':['OrderProgress'],'mitigated_risks':[],'notes':['Chain\x20query_progress_history_find\x20→\x20query_progress_history_session_forward_find']},{'id':'pattern.reward_one_time_claim','business_requirement':'User\x20can\x20only\x20claim\x20reward\x20once\x20(no\x20prior\x20claims)','data_source':'OnChainConstant','host':'reward_claim','verifier_level':'none','logic_summary':'logic_equal[query_reward_record_count(object=<reward>,\x20recipient=Signer,\x20where={}),\x20identifier[N](0)]','key_queries':['reward.record_count'],'mitigated_risks':[],'notes':['Record\x20count\x20check\x20prevents\x20double-claim','SCHEMA:\x20\x27where\x27\x20is\x20REQUIRED\x20even\x20when\x20empty\x20—\x20pass\x20where:\x20{}\x20or\x20the\x20call\x20is\x20rejected\x20by\x20input\x20validation']},{'id':'pattern.reward_multi_condition','business_requirement':'Order\x20payment\x20>\x20threshold\x20AND\x20reached\x20\x27complete\x27\x20to\x20claim\x20reward','data_source':'WitnessDerived','host':'reward_claim','verifier_level':'none','logic_summary':'logic_and[logic_as_u256_greater[query(order.amount),\x20threshold],\x20logic_equal[query(progress.current),\x20\x27complete\x27],\x20logic_equal[query(order.service),\x20identifier[N](expected_service)]]','key_queries':['order.amount','progress.current','order.service'],'witness_types':['OrderProgress'],'mitigated_risks':['R-C3-05'],'notes':['Multi-condition:\x20amount\x20+\x20progress\x20state\x20+\x20service\x20match']},{'id':'pattern.arbitration_voting_weight','business_requirement':'Vote\x20weight\x20equals\x20reputation\x20score\x20(dynamic\x20weight\x20from\x20Passport)','data_source':'SubmittedObject','host':'arbitration_voting','verifier_level':'none','logic_summary':'GuardIdentifier\x20extracts\x20numeric\x20value\x20from\x20Passport\x20submission','key_queries':[],'mitigated_risks':['R-C3-02'],'notes':['Table\x20needs\x20numeric\x20submission\x20entry\x20at\x20referenced\x20index','Weight\x20must\x20come\x20from\x20on-chain\x20EntityRegistrar,\x20not\x20submission','BINDING_01:\x20voting_guard\x20GuardIdentifier\x20must\x20be\x20numeric\x20(U8-U256)','C-9\x20VERIFIED:\x20voting\x20is\x20OPTIONAL\x20—\x20voting_deadline\x20is\x20Option\x20'+'(None\x20=\x20open-ended\x20voting;\x20arbitration\x20can\x20proceed\x20whenever\x20the\x20arbiter\x20decides).\x20'+'NO\x20minimum\x20voter\x20quorum\x20is\x20required\x20on-chain:\x20the\x20arbiter\x20may\x20rule\x20with\x20any\x20number\x20'+'of\x20votes\x20(including\x20zero).\x20MAX_ARBITRATOR_VOTING=520\x20is\x20only\x20an\x20upper\x20bound.\x20'+'Open\x20voting\x20(empty\x20voting_guard)\x20gives\x20every\x20vote\x20weight\x201\x20(the\x20vote\x20handler\x20asserts\x20the\x20guard\x20is\x20empty).']},{'id':'pattern.arbitration_membership_check','business_requirement':'Only\x20premium\x20members\x20can\x20file\x20disputes','data_source':'OnChainConstant','host':'arbitration_usage','verifier_level':'none','logic_summary':'logic_and[query(entity\x20exists),\x20logic_as_u256_greater_or_equal[query(entity\x20tier),\x20identifier[N](premium_tier)]]','key_queries':['entity.registrar','entity.linker'],'mitigated_risks':[],'notes':['ENTITY_REGISTRAR_ADDRESS\x20(0xaab)\x20/\x20ENTITY_LINKER_ADDRESS\x20(0xaaa)\x20must\x20be\x20in\x20table']},{'id':'pattern.scene_allocator_entity_recipient','business_requirement':'Service\x20allocator\x20with\x20sharing.who=Entity\x20—\x20no\x20Signer\x20binding\x20needed','data_source':'OnChainConstant','host':'service_allocator_guard','verifier_level':'level3_scene_combined','logic_summary':'Scene\x20verifies\x20fund\x20flow\x20safety\x20—\x20Guard\x20only\x20validates\x20allocation\x20rules','key_queries':['service.permission','order.amount'],'mitigated_risks':['R-C3-06'],'notes':['Funds\x20flow\x20to\x20fixed\x20Treasury/address\x20regardless\x20of\x20caller','sharing.who=Entity\x20already\x20guarantees\x20recipient\x20safety','No\x20Signer\x20binding\x20required\x20—\x20R-C3-06\x20safe']},{'id':'pattern.scene_machine_forward_operator','business_requirement':'Machine\x20forward\x20with\x20permissionIndex/namedOperator\x20already\x20verifies\x20operator','data_source':'OnChainConstant','host':'machine_forward','verifier_level':'level3_scene_combined','logic_summary':'Forward\x27s\x20permissionIndex/namedOperator\x20verifies\x20operator\x20—\x20Guard\x20only\x20validates\x20submitted\x20data','key_queries':[],'mitigated_risks':[],'notes':['Scene\x20verifies\x20operator\x20permission\x20via\x20permissionIndex/namedOperator','Signer\x20binding\x20only\x20needed\x20if\x20submitted\x20data\x20must\x20belong\x20to\x20operator','Evaluate\x20scene\x20before\x20adding\x20Signer\x20binding']},{'id':'pattern.fund_flow_refund_freeform','business_requirement':'Refund\x20/\x20cancellation\x20fund-release\x20defined\x20purely\x20by\x20game\x20conditions\x20—\x20NOT\x20bound\x20to\x20any\x20Machine\x20node','data_source':'SubmittedObject','host':'service_allocator_guard','verifier_level':'level2_identity_set','logic_summary':'An\x20allocator\x20Guard\x20whose\x20root\x20encodes\x20refund\x20conditions\x20ARBITRARILY:\x20'+'buyer\x20signature\x20(logic_equal[Signer,\x20buyer]),\x20timeout\x20(logic_as_u256_greater_or_equal[Clock,\x20deadline]),\x20'+'evidence\x20state\x20(query\x20any\x20on-chain\x20object:\x20order\x20fields,\x20repository\x20data,\x20payment\x20proofs),\x20'+'arbitration\x20outcome,\x20or\x20any\x20logic_and/or\x20combination.\x20No\x20progress/current-node\x20query\x20required.','key_queries':['order.owner','order.service','order.amount'],'mitigated_risks':['R-C3-06'],'notes':['C-2\x20RESOLUTION:\x20Machine-node-triggered\x20refund\x20(\x27at\x20cancelled\x20node\x20→\x20release\x27)\x20is\x20only\x20ONE\x20application\x20pattern.\x20'+'Guard+Allocator\x20is\x20a\x20GENERAL\x20game\x20primitive:\x20the\x20refund\x20condition\x20tree\x20is\x20fully\x20free-form.\x20'+'Move\x20layer\x20needs\x20NO\x20change\x20—\x20Guard\x20roots\x20accept\x20arbitrary\x20logic\x20over\x20any\x20queryable\x20state.','GAME-THEORETIC\x20READING:\x20both\x20parties\x20should\x20evaluate\x20the\x20refund\x20Guard\x20BEFORE\x20transacting\x20—\x20'+'who\x20can\x20trigger\x20it,\x20under\x20which\x20conditions,\x20with\x20what\x20evidence.\x20Use\x20the\x20analyze_guard_semantics\x20'+'query\x20action\x20to\x20render\x20+\x20lint\x20any\x20Guard\x20and\x20reason\x20about\x20each\x20party\x27s\x20leverage.','Condition\x20dimensions\x20freely\x20composable:\x20identity\x20(Signer/Entity),\x20time\x20(Clock),\x20'+'counterparty\x20evidence\x20(submitted\x20Payment/Order/Proof),\x20shared\x20data\x20(Repository),\x20'+'workflow\x20state\x20(Progress\x20—\x20optional,\x20only\x20when\x20a\x20Machine\x20exists)','Multi-tier\x20refund:\x20multiple\x20allocators\x20with\x20first-match-wins\x20order\x20encode\x20graduated\x20policies\x20'+'(full\x20refund\x20pre-delivery,\x20partial\x20refund\x20post-milestone,\x20no\x20refund\x20post-acceptance)\x20as\x20SEPARATE\x20Guards']},{'id':'pattern.fund_flow_profit_share_freeform','business_requirement':'Revenue/profit\x20sharing\x20among\x20partners\x20triggered\x20by\x20verifiable\x20contribution\x20conditions\x20—\x20not\x20by\x20workflow\x20nodes','data_source':'OnChainConstant','host':'service_allocator_guard','verifier_level':'level3_scene_combined','logic_summary':'Allocator\x20sharing\x20(who+ratio)\x20defines\x20the\x20SPLIT;\x20the\x20Guard\x20defines\x20WHEN\x20the\x20split\x20executes.\x20'+'The\x20WHEN\x20is\x20free-form:\x20period\x20boundary\x20(Clock\x20vs\x20interval),\x20contribution\x20proof\x20(submitted\x20evidence),\x20'+'performance\x20threshold\x20(Repository\x20metric),\x20or\x20counterparty\x20co-signature.','key_queries':['repository.data','payment.amount'],'mitigated_risks':['R-C3-06'],'applicable_industries':['freelance','subscription','education'],'notes':['C-2\x20RESOLUTION:\x20profit-sharing\x20is\x20an\x20application\x20pattern\x20of\x20the\x20same\x20Guard+Allocator\x20primitive\x20—\x20'+'the\x20trigger\x20condition\x20tree\x20is\x20arbitrary\x20game\x20logic,\x20not\x20a\x20workflow\x20artifact.','sharing.who=Entity\x20recipients\x20make\x20the\x20split\x20caller-safe\x20(funds\x20flow\x20to\x20fixed\x20addresses)\x20—\x20'+'Guard\x20then\x20only\x20gates\x20TIMING/CONDITIONS,\x20not\x20identity\x20(R-C3-06\x20safe\x20by\x20scene)','Periodic\x20settlement:\x20logic_as_u256_greater_or_equal[Clock,\x20identifier[N](period_start)]\x20+\x20'+'logic_as_u256_equal[calc_number_mod[Clock,\x20interval],\x200]-style\x20windows,\x20'+'or\x20a\x20Repository-held\x20settlement\x20cursor\x20updated\x20after\x20each\x20allocation\x20run']},{'id':'pattern.permission_guard_entity_time_window','business_requirement':'Delegate\x20a\x20permission\x20index\x20to\x20a\x20Guard\x20object\x20address\x20—\x20authorization\x20that\x20self-enforces\x20and\x20self-expires\x20(time-windowed\x20delegation)','data_source':'SystemContext','host':'machine_forward','verifier_level':'none','logic_summary':'The\x20entity\x20table\x20accepts\x20\x27user/guard\x20address\x20&\x20permission_index\x20list\x27\x20—\x20'+'a\x20Guard\x27s\x20OWN\x20ADDRESS\x20can\x20hold\x20a\x20permission\x20index.\x20The\x20delegated\x20Guard\x20then\x20encodes\x20'+'temporal\x20+\x20contextual\x20conditions:\x20logic_and[logic_as_u256_greater_or_equal[Clock,\x20valid_from],\x20'+'logic_as_u256_lesser_or_equal[Clock,\x20valid_until],\x20<scene\x20conditions>].\x20'+'Callers\x20satisfying\x20the\x20Guard\x20act\x20with\x20the\x20delegated\x20permission\x20index.','key_queries':[],'mitigated_risks':[],'notes':['C-8\x20VERIFIED:\x20entity\x20table\x20comment\x20—\x20\x27user/guard\x20address\x20&\x20permission_index\x20list\x27\x20'+'(guard\x20addresses\x20are\x20first-class\x20permission\x20entities,\x20same\x20as\x20user\x20addresses)','TIME\x20WINDOW:\x20Guard\x20roots\x20compose\x20context(Clock)\x20freely\x20—\x20valid_from/valid_until\x20bounds,\x20'+'recurring\x20windows\x20(mod\x20arithmetic),\x20or\x20deadline-before\x20(authorize\x20only\x20until\x20expiry)','SELF-EXPIRING\x20DELEGATION:\x20after\x20valid_until\x20the\x20Guard\x20fails\x20for\x20everyone\x20—\x20no\x20on-chain\x20'+'revocation\x20transaction\x20needed,\x20no\x20trust\x20in\x20the\x20delegate\x20to\x20stop\x20acting','SCENARIO\x20COMBINATION\x20(scenario\x20layer):\x20temporary\x20operator\x20(holiday\x20cover),\x20seasonal\x20service\x20window,\x20'+'trial-period\x20customer\x20privileges,\x20contractor\x20time-boxed\x20access,\x20emergency-break-glass\x20with\x20auto-expiry','Design\x20tip:\x20combine\x20with\x20scene\x20conditions\x20(order\x20state,\x20submitted\x20evidence)\x20—\x20'+'time\x20bounds\x20rarely\x20stand\x20alone']},{'id':'pattern.allocator_order_anchor','business_requirement':'Bind\x20an\x20allocator\x27s\x20Guard\x20to\x20the\x20paying\x20order\x20when\x20every\x20recipient\x20is\x20a\x20fixed\x20address\x20(Entity/Signer)\x20—\x20the\x20Guard\x20would\x20otherwise\x20read\x20no\x20order\x20at\x20all','data_source':'OnChainConstant','host':'service_allocator_guard','verifier_level':'level3_scene_combined','logic_summary':'Entity/Signer\x20rows\x20are\x20not\x20resolved\x20from\x20submissions,\x20so\x20an\x20allocator\x20paying\x20only\x20them\x20gives\x20its\x20Guard\x20nothing\x20to\x20'+'constrain.\x20Add\x20a\x20{GuardIdentifier:\x200}\x20row\x20with\x20Rate\x200\x20(or\x20Surplus\x20when\x20the\x20allocator\x20has\x20no\x20other\x20Surplus\x20row):\x20'+'the\x20row\x20pays\x20nothing,\x20and\x20the\x20Guard\x27s\x20Identifier\x20slot\x20now\x20resolves\x20to\x20the\x20paying\x20order,\x20so\x20order.*\x20queries\x20bind.','key_queries':['order.service','order.owner'],'notes':['VERIFIED\x20on\x20a\x20standalone\x20Allocation:\x20the\x20zero-share\x20anchor\x20row\x20is\x20accepted\x20by\x20order_allocators\x20(Move\x20asserts\x20no\x20Rate>0\x20minimum).','Confirm\x20Rate\x200\x20on\x20the\x20real\x20Service\x20with\x20a\x20dry-run\x20before\x20publishing\x20—\x20published\x20allocators\x20cannot\x20change.','The\x20anchor\x20row\x20also\x20makes\x20recipient-constraint\x20audits\x20meaningful:\x20the\x20Guard\x27s\x20binding\x20target\x20exists.']},{'id':'pattern.allocation_staged_release','business_requirement':'Pay\x20an\x20order\x20out\x20in\x20stages\x20(milestones),\x20or\x20hold\x20a\x20share\x20back\x20(deposit,\x20warranty,\x20quality\x20reserve)\x20behind\x20a\x20time\x20window\x20/\x20dispute\x20state','data_source':'SystemContext','host':'service_allocator_guard','verifier_level':'level3_scene_combined','logic_summary':'An\x20Allocation\x20can\x20be\x20triggered\x20MANY\x20times\x20and\x20the\x20contract\x20keeps\x20no\x20\x27already\x20paid\x27\x20flag,\x20so\x20every\x20staged\x20allocator\x20'+'needs\x20its\x20own\x20not-yet-paid\x20condition:\x20escrow\x20balance\x20still\x20equals\x20the\x20order\x20amount,\x20or\x20a\x20state/time\x20only\x20one\x20stage\x20'+'satisfies.\x20A\x20holdback\x20is\x20an\x20allocator\x20whose\x20Guard\x20adds\x20a\x20time\x20window\x20(progress.current_time\x20+\x20duration)\x20and,\x20for\x20'+'dispute\x20awareness,\x20a\x20condition\x20on\x20order.dispute\x20count\x20or\x20on\x20the\x20arb.status\x20of\x20a\x20submitted\x20Arb.','key_queries':['progress.current_time','order.dispute','arb.status'],'notes':['REPLAY\x20TEST\x20MANDATORY:\x20trigger\x20the\x20same\x20allocator\x20twice\x20and\x20expect\x20the\x20second\x20call\x20to\x20fail\x20with\x20abort\x20code\x207\x20(insufficient\x20balance).','VERIFIED:\x20time-window\x20holdbacks.\x20INFERENCE:\x20dispute-aware\x20conditions\x20—\x20dry-run\x20no-dispute\x20/\x20open\x20/\x20lost\x20/\x20won\x20before\x20publishing.','Never\x20pay\x20the\x20held\x20share\x20from\x20the\x20same\x20Guard\x20that\x20pays\x20the\x20main\x20share\x20—\x20a\x20Guard\x20that\x20also\x20fires\x20while\x20a\x20warranty\x20is\x20open\x20leaves\x20the\x20buyer\x20no\x20leverage.']},{'id':'pattern.commission_holdback','business_requirement':'Commission\x20or\x20bonus\x20that\x20should\x20depend\x20on\x20the\x20order\x20staying\x20undisputed\x20—\x20there\x20is\x20NO\x20clawback\x20once\x20an\x20allocation\x20has\x20run','data_source':'SystemContext','host':'service_allocator_guard','verifier_level':'level3_scene_combined','logic_summary':'Once\x20an\x20allocation\x20runs,\x20the\x20money\x20is\x20in\x20the\x20recipients\x27\x20wallets\x20—\x20Payments\x20are\x20final\x20and\x20only\x20the\x20merchant-funded\x20'+'compensation\x20fund\x20remains.\x20Pay\x20a\x20contested\x20commission\x20from\x20a\x20LATER\x20allocator\x20behind\x20a\x20time\x20window\x20and\x20a\x20dispute\x20'+'condition\x20(see\x20pattern.allocation_staged_release),\x20never\x20from\x20the\x20settlement\x20allocator.','key_queries':['order.dispute','progress.current_time'],'notes':['VERIFIED:\x20no\x20recall/clawback\x20path\x20exists\x20on\x20Payments.\x20INFERENCE:\x20the\x20holdback\x20variant\x20—\x20dry-run\x20before\x20publishing.']},{'id':'pattern.reward_rule_replacement','business_requirement':'Keep\x20the\x20option\x20to\x20replace\x20a\x20Reward\x20rule\x20later\x20(payout\x20is\x20fixed\x20when\x20its\x20Guard\x20is\x20added)','data_source':'OnChainConstant','host':'reward_claim','verifier_level':'none','logic_summary':'Give\x20every\x20reward\x20guard_add\x20an\x20expiration_time\x20if\x20the\x20rule\x20may\x20need\x20replacement\x20—\x20without\x20one\x20the\x20rule\x20is\x20permanent.\x20'+'Replace\x20later\x20via\x20guard_remove_expired:\x20true,\x20then\x20guard_add\x20the\x20new\x20rule.','key_queries':[],'notes':['SCHEMA\x20READING:\x20confirm\x20the\x20guard_remove_expired\x20sequence\x20on\x20a\x20test\x20Reward\x20before\x20promising\x20it\x20to\x20users.','Do\x20not\x20set\x20the\x20top-level\x20guard_expiration_time\x20unless\x20you\x20promise\x20claimants\x20no\x20new\x20rules\x20before\x20that\x20time.']},{'id':'pattern.buy_guard_blocklist','business_requirement':'Refuse\x20certain\x20buyers\x20at\x20purchase\x20time\x20via\x20a\x20mutable\x20list\x20—\x20without\x20redeploying\x20the\x20Guard\x20or\x20the\x20Service','data_source':'SubmittedObject','host':'service_buy_guard','verifier_level':'none','logic_summary':'buy_guard\x20reads\x20on-chain\x20state\x20at\x20purchase\x20time.\x20Bind\x20a\x20Guard\x20that\x20fails\x20when\x20the\x20signer\x20is\x20listed\x20in\x20a\x20Repository\x20'+'policy:\x20context_signer\x20as\x20the\x20key\x20+\x20repository.data\x20has\x20with\x20logic_not.\x20Editing\x20the\x20list\x20needs\x20no\x20new\x20Guard\x20and\x20no\x20new\x20Service.','key_queries':['repository.data'],'notes':['VERIFIED:\x20buy_guard\x20state-read.\x20INFERENCE:\x20the\x20Repository\x20blocklist\x20—\x20dry-run\x20before\x20publishing.','LIMITS:\x20stops\x20NEW\x20orders\x20only\x20—\x20existing\x20orders\x20and\x20their\x20allocations\x20are\x20untouched;\x20the\x20Messenger\x20blacklist\x20does\x20not\x20affect\x20the\x20chain;\x20restrict\x20who\x20can\x20write\x20the\x20Repository\x20policy.']},{'id':'pattern.referral_anti_self_purchase','business_requirement':'Referral\x20commissions\x20where\x20the\x20buyer\x20must\x20not\x20be\x20their\x20own\x20referrer\x20—\x20nothing\x20on-chain\x20checks\x20order.agents','data_source':'SubmittedObject','host':'service_allocator_guard','verifier_level':'level3_scene_combined','logic_summary':'agents\x20on\x20an\x20order\x20is\x20filled\x20by\x20the\x20buyer\x20at\x20purchase\x20time\x20and\x20anti_cheat\x20does\x20not\x20read\x20it.\x20Add\x20to\x20the\x20commission\x20'+'allocator\x27s\x20Guard:\x20the\x20referrer\x20is\x20an\x20agent\x20of\x20the\x20order\x20(order.agent\x20has)\x20AND\x20is\x20not\x20the\x20order\x27s\x20owner\x20(order.owner).','key_queries':['order.agent','order.owner'],'notes':['VERIFIED:\x20the\x20anti-cheat\x20gap.\x20INFERENCE:\x20the\x20Guard\x20condition\x20—\x20source-derived,\x20untested;\x20dry-run\x20before\x20publishing.','Blocks\x20the\x20same-address\x20case\x20only.\x20The\x20commission\x20recipient\x20must\x20be\x20an\x20Entity\x20(or\x20Signer)\x20—\x20a\x20GuardIdentifier\x20recipient\x20is\x20the\x20order\x20itself.']},{'id':'pattern.multi_party_recourse','business_requirement':'Multi-party\x20services\x20(hotels,\x20carriers,\x20subcontractors):\x20pay\x20a\x20third\x20party\x20from\x20the\x20order\x20without\x20losing\x20recourse\x20when\x20THEY\x20fail','data_source':'SystemContext','host':'service_allocator_guard','verifier_level':'none','logic_summary':'Only\x20the\x20paying\x20order\x20and\x20the\x20Service\x20it\x20bought\x20from\x20take\x20part\x20in\x20an\x20arbitration,\x20and\x20the\x20payout\x20comes\x20from\x20that\x20'+'Service\x27s\x20compensation\x20fund\x20(capped\x20at\x203x\x20the\x20order\x20amount).\x20A\x20third\x20party\x20who\x20is\x20only\x20an\x20allocation\x20recipient\x20cannot\x20'+'be\x20named,\x20notified\x20or\x20heard\x20in\x20a\x20dispute.\x20Cover\x20it\x20in\x20advance:\x20hold\x20their\x20share\x20behind\x20a\x20time\x20window\x20and\x20a\x20no-dispute\x20'+'condition\x20(see\x20pattern.allocation_staged_release),\x20or\x20buy\x20their\x20part\x20as\x20its\x20own\x20order\x20from\x20their\x20Service\x20so\x20you\x20hold\x20'+'the\x20customer\x20rights\x20against\x20them.','key_queries':['order.dispute','progress.current_time'],'notes':['VERIFIED:\x20two-tier\x20orders.\x20INFERENCE:\x20downstream\x20recourse\x20via\x20holdback\x20—\x20dry-run\x20before\x20publishing.']}];export const VERIFIER_LEVEL_GUIDANCE=[{'level':'level1_strict_single','pattern':'logic_equal[context(Signer),\x20identifier[N](fixed_address)]','when_to_use':'Role\x20permanently\x20tied\x20to\x20one\x20address\x20AND\x20designer\x20accepts\x20lock-in\x20risk','risk_rules':['R-C4-04'],'recommendation':'avoid'},{'level':'level2_identity_set','pattern':'logic_or\x20of\x20multiple\x20identity\x20checks','when_to_use':'Role-based\x20access\x20—\x20multiple\x20authorized\x20identities','risk_rules':['R-C4-04\x20(suppressed)'],'recommendation':'recommended'},{'level':'level3_scene_combined','pattern':'Scene\x20itself\x20verifies\x20identity\x20—\x20no\x20Signer\x20binding\x20needed','when_to_use':'Scene\x27s\x20host\x20object\x20already\x20verifies\x20operator\x20(e.g.,\x20Machine\x20forward,\x20sharing.who=Entity)','risk_rules':[],'recommendation':'default'},{'level':'none','pattern':'No\x20Signer\x20binding\x20required','when_to_use':'Resource\x20flow\x20matters\x20more\x20than\x20caller\x20identity','risk_rules':[],'recommendation':'default'}];export const GUARD_SCHEMA_NOTES=['logic_not\x20takes\x20exactly\x20ONE\x20child\x20under\x20\x27node\x27\x20(not\x20\x27nodes\x27).','logic_and\x20/\x20logic_or\x20accept\x202-8\x20child\x20nodes\x20(MAX_MULTI_OPERANDS)\x20—\x20nest\x20extra\x20conditions\x20inside\x20another\x20logic_and/logic_or.','query_reward_record_count\x20/\x20query_reward_record_exists\x20/\x20query_reward_record_find\x20require\x20\x27where\x27\x20even\x20when\x20empty\x20—\x20pass\x20where:\x20{}\x20or\x20input\x20validation\x20rejects\x20the\x20call.','Node\x20type\x20names\x20have\x20no\x20abbreviations:\x20logic_as_u256_greater\x20/\x20logic_as_u256_lesser\x20/\x20logic_as_u256_greater_or_equal\x20/\x20logic_as_u256_lesser_or_equal\x20(never\x20gt/lt/ge/le).','context()\x20enum\x20values\x20are\x20exactly:\x20Signer,\x20Clock,\x20Guard.','repository.data\x20cannot\x20be\x20compared\x20with\x20an\x20Address\x20directly\x20—\x20Repository\x20values\x20are\x20stored\x20as\x20U256;\x20use\x20\x27repository.data\x20has\x27\x20for\x20membership\x20or\x20compare\x20the\x20value\x20as\x20a\x20NUMBER.','Whole-repository\x20\x27repository.data\x20count\x27\x20returns\x20the\x20table\x20size,\x20not\x20per-key\x20matches.\x20For\x20per-key\x20totals\x20the\x20Guard\x20CAN\x20count/sum\x20matches\x20itself\x20via\x20\x27repository.data\x20count\x20where\x27\x20/\x20\x27repository.data\x20sum\x20where\x27\x20(predicate-filtered,\x20candidate\x20list\x20max\x20100);\x20only\x20use\x20the\x20trusted-role-writes-total\x20fallback\x20when\x20candidates\x20cannot\x20be\x20enumerated.','Verify\x20field\x20paths\x20against\x20the\x20live\x20schema\x20via\x20schema_query\x20(action=\x27get\x27,\x20name=\x27call_guard_*\x27)\x20instead\x20of\x20trusting\x20memory.'];export function getGuardDesignPattern(a){return GUARD_DESIGN_PATTERNS['find'](b=>b['id']===a);}export function searchGuardDesignPatterns(a){const b=a['toLowerCase']();return GUARD_DESIGN_PATTERNS['filter'](c=>{if(c['business_requirement']['toLowerCase']()['includes'](b))return!![];if(c['logic_summary']['toLowerCase']()['includes'](b))return!![];if(c['key_queries']['some'](d=>d['toLowerCase']()['includes'](b)))return!![];return![];});}export function getPatternsByHost(a){return GUARD_DESIGN_PATTERNS['filter'](b=>b['host']===a);}export function getPatternsByIndustry(a){return GUARD_DESIGN_PATTERNS['filter'](b=>b['applicable_industries']?.['includes'](a));}export function getPatternsByDataSourceClass(a){return GUARD_DESIGN_PATTERNS['filter'](b=>b['data_source']===a);}export function getVerifierLevelGuidance(a){return VERIFIER_LEVEL_GUIDANCE['find'](b=>b['level']===a);}export function suggestPatternForRequirement(a){const b=searchGuardDesignPatterns(a);if(b['length']===0x0){const e=GUARD_DESIGN_PATTERNS[0x0];return{'best':e,'alternatives':[]};}const [c,...d]=b;return{'best':c,'alternatives':d};}export const GUARD_DESIGN_PATTERNS_VERSION=0x4;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import{describe,it,expect}from'vitest';import{GUARD_DESIGN_PATTERNS,GUARD_SCHEMA_NOTES}from'./guard-design-patterns.js';import{SCHEMA_TO_SEMANTIC_RULES}from'./guard-translation.js';const NODE_TOKEN_RE=/\b((?:logic|calc|vec|convert|query)_[a-z0-9_]+)\s*[\[(]/g,ALIAS_RE=/\blogic_as_u256_(gt|lt|eq|ge|le)\b/,nodeTypeNames=new Set(SCHEMA_TO_SEMANTIC_RULES['filter'](a=>a['element_type']==='node')['map'](a=>a['type_name'])),witnessTypeNames=new Set(SCHEMA_TO_SEMANTIC_RULES['filter'](a=>a['element_type']==='witness')['map'](a=>a['type_name']));function extractTokens(...a){const b=new Set();for(const c of a){if(!c)continue;for(const d of c['matchAll'](NODE_TOKEN_RE))b['add'](d[0x1]);}return[...b];}describe('guard\x20design\x20patterns\x20vs\x20schema\x20(docs#43-a\x20CI\x20check)',()=>{it('every\x20node\x20token\x20in\x20logic_summary/notes\x20exists\x20in\x20the\x20schema',()=>{const a=[];for(const b of GUARD_DESIGN_PATTERNS){for(const c of extractTokens(b['logic_summary'],...b['notes']??[])){!nodeTypeNames['has'](c)&&a['push'](b['id']+':\x20\x27'+c+'\x27\x20is\x20not\x20a\x20schema\x20node\x20type');}}expect(a)['toEqual']([]);}),it('every\x20witness_types\x20entry\x20maps\x20to\x20a\x20schema\x20witness\x20type\x20(Type*\x20prefix)',()=>{const a=[];for(const b of GUARD_DESIGN_PATTERNS){for(const c of b['witness_types']??[]){!witnessTypeNames['has']('Type'+c)&&a['push'](b['id']+':\x20witness\x20\x27'+c+'\x27\x20has\x20no\x20Type'+c+'\x20in\x20the\x20schema');}}expect(a)['toEqual']([]);}),it('no\x20abbreviated\x20comparator\x20aliases\x20in\x20logic_summary\x20or\x20notes',()=>{const a=GUARD_DESIGN_PATTERNS['filter'](b=>ALIAS_RE['test'](b['logic_summary'])||(b['notes']??[])['some'](c=>ALIAS_RE['test'](c)))['map'](b=>b['id']);expect(a)['toEqual']([]);}),it('GUARD_SCHEMA_NOTES\x20covers\x20the\x20known\x20gotchas\x20(where\x20required,\x20child\x20cap,\x20no\x20aliases)',()=>{expect(GUARD_SCHEMA_NOTES['length'])['toBeGreaterThanOrEqual'](0x3);const a=GUARD_SCHEMA_NOTES['join']('\x20');expect(a)['toContain']('where:\x20{}'),expect(a)['toContain']('MAX_MULTI_OPERANDS'),expect(a)['toContain']('logic_as_u256_greater_or_equal');});});
@@ -69,7 +69,7 @@ export declare function autoFixGuard(json: GuardJsonInput): {
69
69
  fixed: GuardJsonInput;
70
70
  actions: AutoFixAction[];
71
71
  };
72
- export declare function lintGuard(json: GuardJsonInput, options?: {
72
+ export declare function lintGuard(input: GuardJsonInput, options?: {
73
73
  auto_fix?: boolean;
74
74
  }): Promise<GuardLintResult>;
75
75
  export declare function isGuardReady(json: GuardJsonInput): Promise<boolean>;