@wowok/agent-mcp 3.3.8 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/dist/chain-semantics/field-capability.js +1 -1
  2. package/dist/chain-semantics/freeze-map.js +1 -1
  3. package/dist/chain-semantics/fund-flow.js +1 -1
  4. package/dist/chain-semantics/guard-verbs.js +1 -1
  5. package/dist/chain-semantics/object-graph.js +1 -1
  6. package/dist/composition/audit.js +1 -1
  7. package/dist/composition/compile.d.ts +3 -2
  8. package/dist/composition/compile.js +1 -1
  9. package/dist/composition/inflight.d.ts +6 -0
  10. package/dist/composition/inflight.js +1 -1
  11. package/dist/composition/materialize.d.ts +4 -0
  12. package/dist/composition/materialize.js +1 -1
  13. package/dist/composition/param-disclosure.d.ts +61 -0
  14. package/dist/composition/param-disclosure.js +1 -0
  15. package/dist/composition/plan.d.ts +11 -1
  16. package/dist/composition/plan.js +1 -1
  17. package/dist/customer/account-events.js +1 -1
  18. package/dist/data/api/api.spec.js +1 -1
  19. package/dist/data/api/cli.js +1 -1
  20. package/dist/data/api/server.d.ts +1 -0
  21. package/dist/data/api/server.js +1 -1
  22. package/dist/data/projection/store.d.ts +2 -1
  23. package/dist/data/projection/store.js +1 -1
  24. package/dist/data/projection/types.d.ts +10 -0
  25. package/dist/data/sync/cdc.js +1 -1
  26. package/dist/data/sync/cdc.spec.js +1 -1
  27. package/dist/data/sync/store.d.ts +5 -0
  28. package/dist/data/sync/store.js +1 -1
  29. package/dist/data/sync/types.d.ts +2 -0
  30. package/dist/evaluation/builtins/graph-service.spec.js +1 -1
  31. package/dist/evaluation/engine.js +1 -1
  32. package/dist/evaluation/guard-scan.js +1 -1
  33. package/dist/experience/realtime-feedback.js +1 -1
  34. package/dist/extensions/business-modules.js +1 -1
  35. package/dist/extensions/industry-pack.js +1 -1
  36. package/dist/extensions/modes.js +1 -1
  37. package/dist/graph/onchain/expand.js +1 -1
  38. package/dist/graph/onchain/exposure.js +1 -1
  39. package/dist/harness/recover.js +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/knowledge/allocation-risk.js +1 -1
  42. package/dist/knowledge/allocation-templates.js +1 -1
  43. package/dist/knowledge/allocator-rail-verifier.js +1 -1
  44. package/dist/knowledge/arb-fund-facts.d.ts +1 -0
  45. package/dist/knowledge/arb-fund-facts.js +1 -1
  46. package/dist/knowledge/arbitration-ledger.js +1 -1
  47. package/dist/knowledge/arbitration-risk.d.ts +1 -0
  48. package/dist/knowledge/arbitration-risk.js +1 -1
  49. package/dist/knowledge/audit-rules.js +1 -1
  50. package/dist/knowledge/baselines/rules/allocation.json +6 -6
  51. package/dist/knowledge/baselines/rules/arb.json +2 -2
  52. package/dist/knowledge/baselines/rules/guard.json +11 -11
  53. package/dist/knowledge/baselines/rules/order.json +1 -1
  54. package/dist/knowledge/baselines/rules/plan.json +1 -1
  55. package/dist/knowledge/baselines/semantic-facts.js +1 -1
  56. package/dist/knowledge/builtin-templates.d.ts +14 -1
  57. package/dist/knowledge/builtin-templates.js +1 -1
  58. package/dist/knowledge/catalog-facts.d.ts +4 -0
  59. package/dist/knowledge/catalog-facts.js +1 -0
  60. package/dist/knowledge/commission-landing.js +1 -1
  61. package/dist/knowledge/component-schema.d.ts +64 -0
  62. package/dist/knowledge/component-schema.js +1 -0
  63. package/dist/knowledge/entity-recipient-guard.js +1 -1
  64. package/dist/knowledge/event-semantics.js +1 -1
  65. package/dist/knowledge/fee-param-bindings.d.ts +26 -0
  66. package/dist/knowledge/fee-param-bindings.js +1 -0
  67. package/dist/knowledge/fund-layer.js +1 -1
  68. package/dist/knowledge/getting-started.d.ts +2 -2
  69. package/dist/knowledge/getting-started.js +1 -1
  70. package/dist/knowledge/guard-anchor-reach.js +1 -1
  71. package/dist/knowledge/guard-design-patterns.js +1 -1
  72. package/dist/knowledge/guard-ledger.js +1 -1
  73. package/dist/knowledge/guard-lint.d.ts +1 -0
  74. package/dist/knowledge/guard-lint.js +1 -1
  75. package/dist/knowledge/guard-puzzle.js +1 -1
  76. package/dist/knowledge/guard-risk.js +1 -1
  77. package/dist/knowledge/guard-templates.d.ts +1 -1
  78. package/dist/knowledge/guard-templates.js +1 -1
  79. package/dist/knowledge/guard-translation.js +1 -1
  80. package/dist/knowledge/index.js +1 -1
  81. package/dist/knowledge/industry-registry.js +1 -1
  82. package/dist/knowledge/industry-strategy.js +1 -1
  83. package/dist/knowledge/jsonrpc-enum.d.ts +14 -3
  84. package/dist/knowledge/jsonrpc-enum.js +1 -1
  85. package/dist/knowledge/knob-docs.d.ts +5 -0
  86. package/dist/knowledge/knob-docs.js +1 -0
  87. package/dist/knowledge/machine-templates.js +1 -1
  88. package/dist/knowledge/machine-topology.js +1 -1
  89. package/dist/knowledge/machine-translation.js +1 -1
  90. package/dist/knowledge/onchain-constants.d.ts +2 -0
  91. package/dist/knowledge/onchain-constants.js +1 -1
  92. package/dist/knowledge/order-ledger.js +1 -1
  93. package/dist/knowledge/param-schema.d.ts +70 -0
  94. package/dist/knowledge/param-schema.js +1 -0
  95. package/dist/knowledge/param-tiers.d.ts +25 -0
  96. package/dist/knowledge/param-tiers.js +1 -0
  97. package/dist/knowledge/passport-ledger.d.ts +1 -1
  98. package/dist/knowledge/passport-ledger.js +1 -1
  99. package/dist/knowledge/pattern-resolutions.d.ts +106 -0
  100. package/dist/knowledge/pattern-resolutions.js +1 -0
  101. package/dist/knowledge/projection.spec.js +1 -1
  102. package/dist/knowledge/safety-rules.js +1 -1
  103. package/dist/knowledge/scenario-modes.d.ts +1 -0
  104. package/dist/knowledge/scenario-modes.js +1 -1
  105. package/dist/knowledge/scenario-topology.js +1 -1
  106. package/dist/knowledge/service-allocation-semantics.js +1 -1
  107. package/dist/knowledge/service-ledger.js +1 -1
  108. package/dist/knowledge/service-templates.js +1 -1
  109. package/dist/knowledge/strategy-manuals.d.ts +1 -1
  110. package/dist/knowledge/strategy-manuals.js +1 -1
  111. package/dist/knowledge/template-loader.d.ts +101 -1
  112. package/dist/knowledge/template-loader.js +1 -1
  113. package/dist/knowledge/template-nav.d.ts +7 -0
  114. package/dist/knowledge/template-nav.js +1 -0
  115. package/dist/knowledge/template-registry.js +1 -1
  116. package/dist/knowledge/template-scanner.d.ts +33 -0
  117. package/dist/knowledge/template-scanner.js +1 -1
  118. package/dist/knowledge/template-test-profiles.d.ts +17 -0
  119. package/dist/knowledge/template-test-profiles.js +1 -0
  120. package/dist/knowledge/template-validation.d.ts +1 -0
  121. package/dist/knowledge/template-validation.js +1 -1
  122. package/dist/knowledge/tools-reference.js +1 -1
  123. package/dist/knowledge/treasury-templates.js +1 -1
  124. package/dist/knowledge/workflow-guidance.js +1 -1
  125. package/dist/monitor/MonitorLoop.js +1 -1
  126. package/dist/participation/time-window.d.ts +37 -0
  127. package/dist/participation/time-window.js +1 -0
  128. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  129. package/dist/playbooks/service-build/machine-panorama.d.ts +1 -0
  130. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  131. package/dist/playbooks/service-build/merchant-guide.d.ts +4 -1
  132. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  133. package/dist/playbooks/service-build/migration-planner.js +1 -1
  134. package/dist/playbooks/service-build/object-panorama.js +1 -1
  135. package/dist/playbooks/service-build/participation-radar.d.ts +1 -0
  136. package/dist/playbooks/service-build/participation-radar.js +1 -1
  137. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  138. package/dist/playbooks/service-build/service-panorama.d.ts +1 -0
  139. package/dist/playbooks/service-build/service-panorama.js +1 -1
  140. package/dist/playbooks/service-build/service-quote.js +1 -1
  141. package/dist/playbooks/service-build/service-quote.spec.js +1 -1
  142. package/dist/playbooks/service-build/workflow-design-assessment.js +1 -1
  143. package/dist/relationship/registry.js +1 -1
  144. package/dist/review/index.js +1 -1
  145. package/dist/runtime/instance-registry.d.ts +7 -1
  146. package/dist/runtime/instance-registry.js +1 -1
  147. package/dist/safety/confirm-gate.js +1 -1
  148. package/dist/schema/benchmark-migration/index.d.ts +2 -0
  149. package/dist/schema/benchmark-migration/index.js +1 -1
  150. package/dist/schema/call/allocation.js +1 -1
  151. package/dist/schema/call/arbitration.js +1 -1
  152. package/dist/schema/call/base.d.ts +8 -0
  153. package/dist/schema/call/base.js +1 -1
  154. package/dist/schema/call/bridge.d.ts +2 -0
  155. package/dist/schema/call/error-codes.d.ts +1 -1
  156. package/dist/schema/call/error-codes.js +1 -1
  157. package/dist/schema/call/guard.js +1 -1
  158. package/dist/schema/call/handler.js +1 -1
  159. package/dist/schema/call/machine.js +1 -1
  160. package/dist/schema/call/semantic.js +1 -1
  161. package/dist/schema/call/service.d.ts +3 -3
  162. package/dist/schema/call/service.js +1 -1
  163. package/dist/schema/common/index.js +1 -1
  164. package/dist/schema/evaluation/index.d.ts +8 -0
  165. package/dist/schema/evaluation/index.js +1 -1
  166. package/dist/schema/goal/planning.d.ts +1 -0
  167. package/dist/schema/goal/planning.js +1 -1
  168. package/dist/schema/industry-pack/index.d.ts +29 -0
  169. package/dist/schema/industry-pack/index.js +1 -1
  170. package/dist/schema/local/index.d.ts +20 -0
  171. package/dist/schema/local/index.js +1 -1
  172. package/dist/schema/messenger/index.d.ts +2 -0
  173. package/dist/schema/messenger/index.js +1 -1
  174. package/dist/schema/operations.d.ts +1 -1
  175. package/dist/schema/operations.js +1 -1
  176. package/dist/schema/query/bi.d.ts +106 -0
  177. package/dist/schema/query/bi.js +1 -1
  178. package/dist/schema/query/index.d.ts +5 -5
  179. package/dist/schema/query/index.js +1 -1
  180. package/dist/schema/schema-version.js +1 -1
  181. package/dist/schema/watch/index.js +1 -1
  182. package/dist/schema-query-impl/index.js +1 -1
  183. package/dist/schemas/account_operation.output.json +4 -2
  184. package/dist/schemas/benchmark_migration_operation.output.json +3 -3
  185. package/dist/schemas/benchmark_migration_operation.schema.json +16 -2
  186. package/dist/schemas/bridge_operation.output.json +4 -2
  187. package/dist/schemas/bridge_operation.schema.json +5 -5
  188. package/dist/schemas/evaluation_operation.output.json +16 -0
  189. package/dist/schemas/guard2file.schema.json +1 -1
  190. package/dist/schemas/index.json +1 -1
  191. package/dist/schemas/industry_pack_operation.output.json +150 -1
  192. package/dist/schemas/industry_pack_operation.schema.json +9 -3
  193. package/dist/schemas/keeper_operation.output.json +2 -2
  194. package/dist/schemas/local_cache_operation.output.json +4 -2
  195. package/dist/schemas/local_history_operation.output.json +4 -2
  196. package/dist/schemas/local_info_operation.output.json +4 -2
  197. package/dist/schemas/local_mark_operation.output.json +4 -2
  198. package/dist/schemas/machineNode2file.schema.json +1 -1
  199. package/dist/schemas/messenger_operation.output.json +13 -2
  200. package/dist/schemas/messenger_operation.schema.json +41 -34
  201. package/dist/schemas/monitor_events.output.json +2 -2
  202. package/dist/schemas/monitor_subscription.output.json +2 -2
  203. package/dist/schemas/onchain_events.output.json +14 -14
  204. package/dist/schemas/onchain_operations.output.json +13 -10
  205. package/dist/schemas/onchain_operations.schema.json +124 -99
  206. package/dist/schemas/onchain_operations_allocation.schema.json +7 -6
  207. package/dist/schemas/onchain_operations_arbitration.schema.json +7 -6
  208. package/dist/schemas/onchain_operations_contact.schema.json +4 -3
  209. package/dist/schemas/onchain_operations_demand.schema.json +4 -3
  210. package/dist/schemas/onchain_operations_gen_passport.schema.json +4 -3
  211. package/dist/schemas/onchain_operations_gen_proof.schema.json +1 -1
  212. package/dist/schemas/onchain_operations_guard.schema.json +7 -6
  213. package/dist/schemas/onchain_operations_machine.schema.json +9 -7
  214. package/dist/schemas/onchain_operations_order.schema.json +6 -4
  215. package/dist/schemas/onchain_operations_payment.schema.json +2 -2
  216. package/dist/schemas/onchain_operations_permission.schema.json +19 -15
  217. package/dist/schemas/onchain_operations_personal.schema.json +17 -14
  218. package/dist/schemas/onchain_operations_progress.schema.json +6 -4
  219. package/dist/schemas/onchain_operations_proof.schema.json +4 -3
  220. package/dist/schemas/onchain_operations_repository.schema.json +9 -7
  221. package/dist/schemas/onchain_operations_reward.schema.json +5 -4
  222. package/dist/schemas/onchain_operations_service.schema.json +15 -12
  223. package/dist/schemas/onchain_operations_treasury.schema.json +4 -3
  224. package/dist/schemas/onchain_table_data.output.json +18 -13
  225. package/dist/schemas/onchain_table_data.schema.json +13 -13
  226. package/dist/schemas/query_toolkit.output.json +301 -33
  227. package/dist/schemas/query_toolkit.schema.json +6 -6
  228. package/dist/schemas/watch_operation.output.json +3 -3
  229. package/dist/schemas/workflow_operation.schema.json +3 -2
  230. package/dist/schemas/wowok_buildin_info.schema.json +1 -1
  231. package/dist/task/playbook.js +1 -1
  232. package/dist/tools/handlers/benchmark-migration.d.ts +1 -0
  233. package/dist/tools/handlers/benchmark-migration.js +1 -1
  234. package/dist/tools/handlers/config.js +1 -1
  235. package/dist/tools/handlers/evaluation.js +1 -1
  236. package/dist/tools/handlers/evaluation.spec.js +1 -1
  237. package/dist/tools/handlers/industry-pack.js +1 -1
  238. package/dist/tools/handlers/messenger.js +1 -1
  239. package/dist/tools/handlers/onchain.d.ts +4 -0
  240. package/dist/tools/handlers/onchain.js +1 -1
  241. package/dist/tools/index.js +1 -1
  242. package/dist/tools/registry/business.js +1 -1
  243. package/dist/tools/registry/onchain.js +1 -1
  244. package/dist/tools/registry/query.js +1 -1
  245. package/dist/tools/sanitize-output.js +1 -1
  246. package/dist/tools/sanitize-output.spec.js +1 -1
  247. package/dist/tools/types.d.ts +1 -0
  248. package/dist/tools/upgrade-check.d.ts +22 -0
  249. package/dist/tools/upgrade-check.js +1 -1
  250. package/dist/tools/wrap.d.ts +1 -1
  251. package/dist/tools/wrap.js +1 -1
  252. package/package.json +7 -6
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{McpServer}from'@modelcontextprotocol/server';import{serveStdio}from'@modelcontextprotocol/server/stdio';import{readFileSync}from'fs';const packageJson=JSON['parse'](readFileSync(new URL('../package.json',import.meta.url),'utf-8'));import{OnchainOperationsSchema,WipOperationsSchema,WatchQueryOperationsSchema,AccountOperationSchema,LocalMarkOperationSchema,LocalInfoOperationSchema,LocalHistoryOperationSchema,ProtocolInfoQuerySchema,CallOutputSchema,MessengerOperationInputSchema,MessengerOperationOutputSchema,createServerConfig,createCapabilitiesConfig}from'./schema/index.js';import{areSchemasAvailable,getSchemaIndex}from'./schema-query-impl/index.js';import{listServices}from'./config/index.js';import{registerAllTools,SUB_TOOL_COUNT}from'./tools/index.js';import{computeSrcDistStaleness}from'./tools/upgrade-check.js';import{monitorLoop}from'./monitor/MonitorLoop.js';import{scanDefaultIndustryPacks}from'./extensions/index.js';import{pinInstance}from'./runtime/instance-registry.js';import{fileURLToPath}from'url';process['on']('unhandledRejection',(a,b)=>{const c=a instanceof Error?a['name']+':\x20'+a['message']+'\x0a'+(a['stack']??''):String(a);console['error']('[unhandledRejection]\x20'+new Date()['toISOString']()),console['error']('\x20\x20reason:\x20'+c);}),process['on']('uncaughtException',a=>{console['error']('[uncaughtException]\x20'+new Date()['toISOString']()),console['error']('\x20\x20name:\x20'+a['name']),console['error']('\x20\x20message:\x20'+a['message']),console['error']('\x20\x20stack:\x20'+(a['stack']??''));}),process['on']('beforeExit',a=>{console['error']('[beforeExit]\x20'+new Date()['toISOString']()+'\x20code='+a+'\x20—\x20event\x20loop\x20empty,\x20process\x20would\x20exit'),console['error']('\x20\x20active\x20handles:\x20'+(process['_getActiveHandles']?.()?.['length']??'?')),console['error']('\x20\x20active\x20requests:\x20'+(process['_getActiveRequests']?.()?.['length']??'?'));}),process['on']('exit',a=>{console['error']('[exit]\x20'+new Date()['toISOString']()+'\x20code='+a+'\x20—\x20process\x20exiting');});let shuttingDown=![],serverHandle=null;async function shutdown(a){if(shuttingDown)return;shuttingDown=!![],console['error']('[shutdown]\x20'+new Date()['toISOString']()+'\x20—\x20'+a);keepaliveTimer&&(clearInterval(keepaliveTimer),keepaliveTimer=null);const b=(c,d,e)=>{if(!c)return Promise['resolve']();return Promise['race']([c['catch'](()=>undefined),new Promise(f=>setTimeout(()=>{console['error']('[shutdown]\x20'+e+'\x20timed\x20out\x20after\x20'+d+'ms\x20—\x20forcing\x20exit'),f();},d))]);};await b(monitorLoop['stop'](),0xbb8,'monitorLoop.stop()'),await b(serverHandle?.['close'](),0x1388,'handle.close()'),process['exit'](0x0);}process['stdin']['on']('end',()=>{void shutdown('stdin\x20end\x20—\x20MCP\x20client\x20closed\x20stdin\x20(host\x20exited\x20or\x20restarted)');}),process['stdin']['on']('close',()=>{void shutdown('stdin\x20close\x20—\x20stdin\x20stream\x20closed');});let keepaliveTimer=null;function startKeepalive(){if(keepaliveTimer)return;keepaliveTimer=setInterval(()=>{const a=process['memoryUsage'](),b=Math['round'](a['heapUsed']/0x400/0x400),c=Math['round'](a['heapTotal']/0x400/0x400),d=Math['round'](a['rss']/0x400/0x400),e=b>0x4b0?'WARNING':b>0x320?'INFO':'DEBUG';console['error']('[memory\x20'+e+']\x20heap='+b+'MB/'+c+'MB\x20rss='+d+'MB');},0xea60);}startKeepalive();const SERVER_DESCRIPTION='WoWok\x20MCP\x20Server\x20-\x20Making\x20It\x20Easy\x20for\x20AI\x20Agents\x20to\x20Communicate,\x20Collaborate,\x20Trade,\x20and\x20Trust.\x0a\x0a##\x20CRITICAL:\x20Unified\x20Single-Tool\x20Architecture\x0a\x0aThis\x20server\x20exposes\x20exactly\x20ONE\x20MCP\x20tool:\x20`wowok`.\x20All\x20'+SUB_TOOL_COUNT+'\x20sub-tools\x20are\x20dispatched\x20internally\x20by\x20the\x20`wowok`\x20handler.\x0a\x0a###\x20START\x20HERE:\x20WoWok\x20Skills\x20(recommended)\x0aRole-based\x20playbooks\x20(onboarding,\x20building,\x20buying,\x20fulfillment,\x20arbitration,\x20governance)\x20sit\x20ON\x20TOP\x20of\x20this\x20MCP\x20and\x20tell\x20you\x20WHEN\x20and\x20in\x20what\x20ORDER\x20to\x20use\x20its\x20'+SUB_TOOL_COUNT+'\x20sub-tools\x20—\x20they\x20materially\x20reduce\x20failed\x20calls.\x20One\x20command\x20installs\x20them\x20into\x20every\x20detected\x20AI\x20client\x20and\x20registers\x20this\x20MCP\x20server:\x20`npm\x20install\x20-g\x20@wowok/skills`\x20(verify\x20with\x20`wowok-skills\x20doctor`).\x20Fetch\x20machine-readable\x20orientation\x20plus\x20best-effort\x20detection\x20of\x20whether\x20skills\x20are\x20installed\x20on\x20this\x20machine\x20with\x20`wowok({\x20tool:\x20\x22wowok_buildin_info\x22,\x20data:\x20{\x20info:\x20\x22getting\x20started\x22\x20}\x20})`.\x0aCOLD\x20START:\x20the\x20FIRST\x20call\x20after\x20server\x20boot\x20can\x20take\x20~20\x20seconds\x20(server\x20bootstraps\x20via\x20npx).\x20Wait\x20for\x20it\x20—\x20a\x20timed-out\x20first\x20response\x20is\x20startup\x20latency,\x20not\x20a\x20failure;\x20never\x20retry\x20a\x20write\x20transaction\x20because\x20of\x20it.\x0a\x0a###\x20Call\x20Format\x0a```\x0awowok({\x20tool:\x20\x22<sub-tool-name>\x22,\x20data:\x20{<sub-tool\x20parameters>}\x20})\x0a```\x0a\x0aAccepted\x20aliases\x20(deprecated):\x20`tool_name`/`name`\x20for\x20`tool`,\x20`args`/`params`\x20for\x20`data`.\x20Inline\x20params\x20(e.g.\x20`{\x20tool:\x20\x22schema_query\x22,\x20action:\x20\x22list\x22\x20}`)\x20are\x20also\x20auto-wrapped\x20into\x20`data`.\x0a\x0a###\x20Schema-Gated\x20Execution\x20(Self-Correcting)\x0aIf\x20your\x20parameters\x20don\x27t\x20match\x20the\x20sub-tool\x27s\x20schema,\x20the\x20response\x20includes:\x0a-\x20`result.status\x20=\x20\x22schema_mismatch\x22`\x0a-\x20`result.errors`\x20=\x20specific\x20validation\x20errors\x0a-\x20`schema.input`\x20=\x20the\x20correct\x20JSON\x20schema\x20for\x20the\x20sub-tool\x0a-\x20`schema.tool`\x20=\x20which\x20sub-tool\x20this\x20schema\x20belongs\x20to\x0a\x0aRead\x20the\x20schema,\x20fix\x20your\x20params,\x20and\x20retry.\x20CACHE\x20the\x20schema\x20in\x20your\x20context\x20for\x20future\x20calls\x20to\x20the\x20SAME\x20sub-tool\x20—\x20you\x20should\x20only\x20need\x20to\x20see\x20each\x20sub-tool\x27s\x20schema\x20once\x20per\x20conversation.\x20No\x20separate\x20`schema_query`\x20call\x20is\x20needed\x20for\x20parameter\x20correction.\x0a\x0a###\x20Unified\x20Response\x20Envelope\x0a```\x0a{\x0a\x20\x20\x22result\x22:\x20{\x20\x22status\x22:\x20\x22success|error|schema_mismatch\x22,\x20\x22data\x22:\x20<sub-tool\x20output>,\x20\x22errors\x22:\x20[...]\x20},\x0a\x20\x20\x22schema\x22:\x20null\x20|\x20{\x20\x22input\x22:\x20<JSON\x20schema>,\x20\x22tool\x22:\x20\x22<sub-tool-name>\x22\x20}\x0a}\x0a```\x0a\x0a##\x20CRITICAL:\x20Schema\x20Discovery\x20Rule\x0a\x0aWhen\x20the\x20current\x20context\x20does\x20not\x20contain\x20a\x20sub-tool\x27s\x20input/output\x20schema,\x20or\x20when\x20you\x20are\x20uncertain\x20whether\x20the\x20schema\x20you\x20have\x20is\x20complete\x20and\x20up-to-date,\x20you\x20MUST\x20query\x20it\x20first\x20before\x20calling\x20the\x20sub-tool.\x20Use\x20`wowok({\x20tool:\x20\x22schema_query\x22,\x20data:\x20{\x20action:\x20\x22get\x22,\x20name:\x20\x22<sub-tool>\x22\x20}\x20})'+'`'+'\x20for\x20operational\x20sub-tool\x20schemas\x20or\x20`wowok({\x20tool:\x20\x22wowok_buildin_info\x22,\x20data:\x20{\x20info:\x20\x22...\x22\x20}\x20})`\x20for\x20protocol\x20constants\x20and\x20reference\x20data.\x20Never\x20guess\x20schema\x20parameters,\x20query\x20instruction\x20IDs,\x20or\x20type\x20codes\x20—\x20always\x20retrieve\x20them\x20from\x20the\x20live\x20server.\x0a\x0a##\x20CRITICAL:\x20Global\x20Unread\x20Messenger\x20Check\x20(every\x20conversation)\x0a\x0aAt\x20the\x20START\x20of\x20EVERY\x20conversation\x20—\x20before\x20answering\x20the\x20user\x27s\x20request,\x20regardless\x20of\x20what\x20it\x20is\x20about\x20—\x20check\x20for\x20unread\x20Messenger\x20messages\x20and\x20IMMEDIATELY\x20and\x20PROMINENTLY\x20remind\x20the\x20user\x20to\x20read\x20them:\x0a\x0a```\x0awowok({\x20tool:\x20\x22messenger_operation\x22,\x20data:\x20{\x20operation:\x20\x22watch_conversations\x22,\x20filter:\x20{\x20unreadOnly:\x20true,\x20previewMessageCount:\x200,\x20skipAutoMarkViewed:\x20true\x20}\x20}\x20})\x0a```\x0a\x0aIf\x20the\x20result\x20contains\x20any\x20conversation\x20with\x20`unreadCount\x20>\x200`,\x20surface\x20a\x20prominent\x20reminder\x20at\x20the\x20TOP\x20of\x20your\x20response\x20(do\x20not\x20wait\x20for\x20the\x20user\x20to\x20ask),\x20listing\x20each\x20peer\x20with\x20unread\x20messages\x20and\x20the\x20count.\x20Use\x20`skipAutoMarkViewed:\x20true`\x20so\x20merely\x20checking\x20does\x20not\x20mark\x20them\x20read.\x20If\x20there\x20are\x20none,\x20do\x20not\x20mention\x20the\x20check.\x0a\x0a##\x20CRITICAL:\x20Upgrade\x20&\x20Client\x20Install\x20Reminder\x20(every\x20conversation)\x0a\x0aAt\x20the\x20START\x20of\x20EVERY\x20conversation\x20—\x20together\x20with\x20the\x20unread\x20Messenger\x20check\x20—\x20call:\x0a\x0a```\x0awowok({\x20tool:\x20\x22wowok_buildin_info\x22,\x20data:\x20{\x20info:\x20\x22upgrade_check\x22\x20}\x20})\x0a```\x0a\x0aThen,\x20based\x20on\x20the\x20returned\x20`result.reminder`:\x0a-\x20If\x20`reminder.type\x20===\x20\x22upgrade\x22`\x20AND\x20`reminder.due\x20===\x20true`:\x20IMMEDIATELY\x20remind\x20the\x20user\x20to\x20upgrade\x20(do\x20not\x20wait\x20for\x20them\x20to\x20ask).\x20Use\x20the\x20benefit-focused\x20wording\x20below,\x20filling\x20in\x20the\x20current/latest\x20versions\x20from\x20`result.mcp`\x20/\x20`result.sdk`.\x0a-\x20If\x20`reminder.type\x20===\x20\x22install_client\x22`\x20AND\x20`reminder.due\x20===\x20true`:\x20remind\x20the\x20user\x20to\x20install\x20the\x20WoWok\x20desktop\x20client\x20(this\x20fires\x20at\x20most\x20once\x20per\x20week\x20—\x20the\x20reminder\x20state\x20is\x20persisted\x20automatically).\x0a-\x20If\x20`reminder.type\x20===\x20\x22none\x22`\x20or\x20`reminder.due\x20===\x20false`:\x20do\x20NOT\x20mention\x20upgrades\x20or\x20the\x20client.\x0a\x0aUpgrade\x20wording\x20(paraphrase\x20naturally,\x20keep\x20it\x20short\x20and\x20benefit-driven;\x20adapt\x20to\x20the\x20user\x27s\x20language):\x0a\x20\x20\x22A\x20newer\x20WoWok\x20version\x20is\x20available\x20(current\x20vX\x20→\x20latest\x20vY).\x20Upgrade\x20for\x20more\x20features\x20and\x20improvements.\x20Run:\x20npm\x20install\x20-g\x20@wowok/agent-mcp@latest\x22\x0a\x0aClient\x20install\x20wording:\x0a\x20\x20\x22The\x20WoWok\x20desktop\x20client\x20is\x20not\x20installed\x20yet.\x20It\x20provides\x20wallet\x20management,\x20encrypted\x20Messenger,\x20project\x20management\x20and\x20more.\x20Download\x20it\x20at\x20https://download.wowok.net\x20to\x20get\x20started.\x22\x0a\x0aIf\x20the\x20upgrade_check\x20itself\x20fails\x20(offline\x20/\x20registry\x20unreachable),\x20skip\x20the\x20reminder\x20—\x20never\x20fabricate\x20version\x20numbers.\x0a\x0a##\x20Token\x20System\x20Overview\x0a\x0a###\x20Default\x20Platform\x20Token:\x20WOW\x0a-\x20Token\x20Type:\x200x2::wow::WOW\x0a-\x20Precision:\x201_000_000_000\x20(9\x20decimal\x20places)\x0a-\x20This\x20is\x20the\x20default\x20token\x20for\x20all\x20operations\x20unless\x20specified\x20otherwise\x0a\x0a###\x20Multi-Token\x20Support\x0aThe\x20platform\x20supports\x20ANY\x20token\x20(e.g.,\x20USDT,\x20USDC,\x20custom\x20tokens).\x20To\x20use\x20non-WOW\x20tokens:\x0a1.\x20Use\x20query_toolkit\x20with\x20query_type=\x27token_list\x27\x20to\x20query\x20available\x20tokens\x20and\x20their\x20precision\x20info\x0a2.\x20Use\x20the\x20token\x27s\x20full\x20type\x20string\x20(e.g.,\x20\x270x2::usdt::USDT\x27)\x20in\x20token_type\x20parameter\x0a3.\x20Each\x20token\x20has\x20its\x20own\x20precision\x20-\x20always\x20verify\x20before\x20operations\x0a\x0a###\x20Token\x20Precision\x20Handling\x0aDifferent\x20tokens\x20have\x20different\x20precisions.\x20ALWAYS\x20query\x20to\x20verify:\x0a-\x20WOW\x20(default):\x201_000_000_000\x20(9\x20decimals)\x0a-\x20Other\x20tokens:\x20Use\x20query_toolkit\x20with\x20query_type=\x27token_list\x27\x20to\x20get\x20actual\x20precision\x0a-\x20Never\x20assume\x20a\x20token\x27s\x20decimal\x20places\x20-\x20always\x20query\x20first\x0a\x0a##\x20CRITICAL:\x20Token\x20Amount\x20Handling\x0a\x0a###\x20Amount\x20Input\x20Rules\x0a1.\x20WITH\x20currency\x20unit\x20(e.g.,\x20\x272WOW\x27,\x20\x2710.5WOW\x27,\x20\x27100USDT\x27):\x0a\x20\x20\x20-\x20Auto-converted\x20using\x20token\x27s\x20precision:\x202WOW\x20->\x202_000_000_000\x0a\x20\x20\x20-\x20Use\x20for:\x20All\x20on-chain\x20token\x20operations\x0a\x20\x20\x20-\x20MUST\x20match\x20the\x20token_type\x20parameter\x0a\x0a2.\x20WITHOUT\x20currency\x20unit\x20(e.g.,\x20\x272\x27,\x20\x27100\x27):\x0a\x20\x20\x20-\x20Used\x20as-is:\x202\x20->\x202\x0a\x20\x20\x20-\x20Use\x20for:\x20Regular\x20numeric\x20parameters\x20(counts,\x20indices,\x20etc.)\x0a\x0a###\x20Multi-Token\x20Operation\x20Examples\x0a-\x20Create\x20USDT-priced\x20Service:\x20token_type=\x270x2::usdt::USDT\x27,\x20amount=\x27100USDT\x27\x0a-\x20Allocate\x20USDC\x20rewards:\x20token_type=\x270x2::usdc::USDC\x27,\x20amount=\x27500USDC\x27\x0a-\x20WOW\x20remains\x20default:\x20omit\x20token_type\x20or\x20use\x20\x270x2::wow::WOW\x27\x0a\x0a###\x20Security\x20Warning\x0aToken\x20amounts\x20are\x20HIGHLY\x20SENSITIVE.\x20Always:\x0a-\x20Confirm\x20user\x27s\x20intent\x20before\x20executing\x20transfers\x0a-\x20Verify\x20token\x20type\x20and\x20amount\x20format\x20(with/without\x20unit)\x0a-\x20Query\x20token\x20precision\x20if\x20unsure\x0a-\x20Double-check\x20large\x20amount\x20transactions\x0a-\x20Never\x20assume\x20decimal\x20places\x20-\x20use\x20explicit\x20token\x20unit\x0a\x0a##\x20Sub-tool\x20Selection\x20Guide\x0a\x0aAll\x20sub-tools\x20are\x20called\x20via\x20`wowok({\x20tool:\x20\x22<sub-tool>\x22,\x20data:\x20{...}\x20})`.\x20The\x20table\x20below\x20helps\x20pick\x20the\x20correct\x20`tool`\x20value.\x0a\x0a|\x20User\x20Intent\x20|\x20Correct\x20Sub-tool\x20|\x20Wrong\x20Sub-tool\x20(Avoid)\x20|\x0a|------------|------------------|------------------------|\x0a|\x20Create\x20service\x20listing\x20|\x20onchain_operations\x20(service)\x20|\x20query_toolkit\x20|\x0a|\x20Send\x20coins\x20to\x20address\x20|\x20onchain_operations\x20(payment)\x20|\x20account_operation\x20|\x0a|\x20Check\x20my\x20balance\x20|\x20query_toolkit\x20(account_balance)\x20|\x20onchain_operations\x20|\x0a|\x20Manage\x20local\x20wallet\x20|\x20account_operation\x20|\x20onchain_operations\x20|\x0a|\x20Export\x20Guard\x20for\x20edit\x20|\x20guard2file\x20|\x20query_toolkit\x20|\x0a|\x20Send/Watch\x20encrypted\x20message\x20|\x20messenger_operation\x20|\x20onchain_operations\x20|\x0a|\x20Create\x20workflow\x20template\x20|\x20onchain_operations\x20(machine)\x20|\x20wip_file\x20|\x0a|\x20Store\x20my\x20phone\x20number\x20|\x20local_info_operation\x20|\x20onchain_operations\x20|\x0a|\x20Buy\x20service\x20(create\x20order)\x20|\x20onchain_operations\x20(order)\x20|\x20onchain_operations\x20(service)\x20|\x0a|\x20Manage\x20my\x20orders\x20|\x20onchain_operations\x20(order)\x20|\x20query_toolkit\x20|\x0a|\x20Apply\x20for\x20arbitration\x20|\x20onchain_operations\x20(order)\x20|\x20onchain_operations\x20(arbitration)\x20|\x0a|\x20Create\x20reward\x20pool\x20for\x20marketing\x20|\x20onchain_operations\x20(reward)\x20|\x20onchain_operations\x20(treasury)\x20|\x0a|\x20Claim\x20rewards\x20from\x20pool\x20|\x20onchain_operations\x20(reward)\x20|\x20query_toolkit\x20|\x0a|\x20Create\x20fund\x20allocation\x20plan\x20|\x20onchain_operations\x20(allocation)\x20|\x20onchain_operations\x20(treasury)\x20|\x0a|\x20Execute\x20fund\x20distribution\x20|\x20onchain_operations\x20(allocation)\x20|\x20onchain_operations\x20(payment)\x20|\x0a|\x20Post\x20service\x20demand\x20with\x20reward\x20|\x20onchain_operations\x20(demand)\x20|\x20onchain_operations\x20(service)\x20|\x0a|\x20Submit\x20solution\x20for\x20demand\x20|\x20onchain_operations\x20(demand)\x20|\x20onchain_operations\x20(order)\x20|\x0a|\x20Create\x20team\x20treasury\x20|\x20onchain_operations\x20(treasury)\x20|\x20onchain_operations\x20(allocation)\x20|\x0a|\x20Deposit/Withdraw\x20from\x20treasury\x20|\x20onchain_operations\x20(treasury)\x20|\x20onchain_operations\x20(payment)\x20|\x0a|\x20Create\x20access\x20control\x20rules\x20|\x20onchain_operations\x20(permission)\x20|\x20onchain_operations\x20(guard)\x20|\x0a|\x20Create\x20validation\x20rules\x20(Guard)\x20|\x20onchain_operations\x20(guard)\x20|\x20onchain_operations\x20(permission)\x20|\x0a|\x20Export\x20Guard\x20for\x20editing\x20|\x20guard2file\x20|\x20query_toolkit\x20|\x0a|\x20Export\x20Machine\x20nodes\x20for\x20editing\x20|\x20machineNode2file\x20|\x20query_toolkit\x20|\x0a|\x20Query\x20token\x20list\x20and\x20precision\x20|\x20query_toolkit\x20(token_list)\x20|\x20wowok_buildin_info\x20|\x0a|\x20Watch\x20on-chain\x20events\x20|\x20onchain_events\x20|\x20query_toolkit\x20|\x0a|\x20Generate\x20WIP\x20promise\x20file\x20|\x20wip_file\x20(generate)\x20|\x20messenger_operation\x20|\x0a|\x20Sign\x20WIP\x20file\x20|\x20wip_file\x20(sign)\x20|\x20account_operation\x20(signData)\x20|\x0a|\x20Verify\x20WIP\x20file\x20integrity\x20|\x20wip_file\x20(verify)\x20|\x20query_toolkit\x20|\x0a|\x20Send\x20encrypted\x20file\x20via\x20messenger\x20|\x20messenger_operation\x20(send_file)\x20|\x20wip_file\x20|\x0a|\x20Generate\x20Witness\x20Timestamped\x20Sequence\x20(WTS)\x20|\x20messenger_operation\x20(generate_wts)\x20|\x20wip_file\x20|\x0a|\x20Query\x20protocol\x20constants\x20|\x20wowok_buildin_info\x20|\x20query_toolkit\x20|\x0a|\x20Query\x20sub-tool\x20schemas\x20|\x20schema_query\x20|\x20wowok_buildin_info\x20|\x0a|\x20Cross-chain\x20bridge\x20(WOW<->EVM)\x20|\x20bridge_operation\x20|\x20onchain_operations\x20|\x0a|\x20On-chain\x20business\x20intelligence\x20(panoramas,\x20review\x20packs)\x20|\x20query_toolkit\x20|\x20onchain_operations\x20|\x0a|\x20Runtime\x20service\x20toggles\x20|\x20config_operation\x20|\x20—\x20|\x0a|\x20Query\x20dynamic\x20table\x20data\x20/\x20table\x20items\x20|\x20onchain_table_data\x20|\x20query_toolkit\x20|\x0a|\x20Business\x20evaluation\x20(match/game/evidence)\x20|\x20evaluation_operation\x20|\x20query_toolkit\x20|\x0a|\x20Set\x20user\x20persona\x20/\x20preferences\x20|\x20persona_operation\x20|\x20local_info_operation\x20|\x0a|\x20Match\x20business\x20intent\x20to\x20chain\x20events\x20|\x20intent_radar\x20|\x20onchain_events\x20|\x0a|\x20Manage\x20employee\x20KPI\x20/\x20liability\x20|\x20employee_operation\x20|\x20onchain_operations\x20|\x0a|\x20Scaffold\x20/\x20register\x20industry\x20pack\x20|\x20industry_pack_operation\x20|\x20persona_operation\x20|\x0a|\x20Read\x20/\x20write\x20local\x20workspace\x20files\x20|\x20workspace_operation\x20|\x20local_info_operation\x20|\x0a|\x20List\x20local-account\x20actionable\x20progress\x20/\x20advance\x20forward\x20|\x20workflow_operation\x20|\x20onchain_operations\x20|\x0a|\x20List\x20Permissions\x20related\x20to\x20local\x20accounts\x20|\x20permission_operation\x20|\x20query_toolkit\x20|\x0a|\x20Ask\x20the\x20user\x20to\x20choose\x20between\x20concrete\x20business\x20options\x20(plans/pricing/guard\x20strength/accounts)\x20|\x20ask_user\x20|\x20onchain_operations\x20/\x20prose\x20questions\x20|\x0a\x0a##\x20Sub-tool\x20Categories\x0a\x0a###\x20LOCAL\x20ONLY\x20(Never\x20touch\x20blockchain):\x0a-\x20account_operation\x0a-\x20local_mark_operation\x0a-\x20local_info_operation\x0a-\x20persona_operation\x0a-\x20employee_operation\x0a-\x20industry_pack_operation\x0a-\x20workspace_operation\x0a\x0a###\x20ON-CHAIN\x20(Blockchain\x20transactions):\x0a-\x20onchain_operations\x0a-\x20workflow_operation\x20(operate\x20advances/holds\x20progress\x20on-chain;\x20list\x20is\x20read-only)\x0a-\x20messenger_operation\x20(some\x20operations)\x0a-\x20wip_file\x20(sign\x20operation)\x0a-\x20bridge_operation\x0a\x0a###\x20QUERY\x20(Read-only):\x0a-\x20query_toolkit\x0a-\x20onchain_events\x0a-\x20onchain_table_data\x0a-\x20wowok_buildin_info\x0a-\x20schema_query\x0a-\x20guard2file\x0a-\x20machineNode2file\x0a-\x20evaluation_operation\x0a-\x20intent_radar\x0a-\x20permission_operation\x0a\x0a###\x20WORKFLOW\x20&\x20ANALYTICS:\x0a-\x20config_operation\x0a';function buildServer(){const a=new McpServer(createServerConfig(packageJson,SERVER_DESCRIPTION),createCapabilitiesConfig());return registerAllTools(a),a;}export{OnchainOperationsSchema,WipOperationsSchema,WatchQueryOperationsSchema,AccountOperationSchema,LocalMarkOperationSchema,LocalInfoOperationSchema,LocalHistoryOperationSchema,ProtocolInfoQuerySchema,CallOutputSchema,MessengerOperationInputSchema,MessengerOperationOutputSchema};async function main(){{const f=pinInstance(packageJson['version'],fileURLToPath(import.meta.url));console['error']('Instance\x20pinned:\x20pid='+process['pid']+'\x20v'+packageJson['version']+'\x20('+f['length']+'\x20other\x20generation(s)\x20live)');for(const g of f)console['error']('[version-reconcile]\x20'+g);}if(areSchemasAvailable()){const h=getSchemaIndex();h&&console['error']('Schema\x20system\x20ready:\x20'+(h['tools']?.['length']||0x0)+'\x20tools,\x20'+(h['operations']?.['length']||0x0)+'\x20operations');}else console['error']('Schema\x20files\x20not\x20available.\x20Run\x20\x27npm\x20run\x20generate:schemas\x27\x20to\x20generate\x20them.');const a=process['env']['WOWOK_DIST_STALENESS']==='enforce';try{const i=await import('path'),j=i['dirname'](fileURLToPath(import.meta.url)),k=i['resolve'](j,'../../../ts-sdk/packages/wowok'),l=[{'label':'SDK','stale':computeSrcDistStaleness(i['join'](k,'src'),i['join'](k,'dist')),'rebuild':'cd\x20ts-sdk/packages/wowok\x20&&\x20pnpm\x20build'},{'label':'MCP','stale':computeSrcDistStaleness(i['join'](j,'..','src'),i['join'](j,'..','dist'),{'srcExt':'.ts','distExt':'.js'}),'rebuild':'cd\x20agent/mcp\x20&&\x20pnpm\x20build'}];for(const m of l){if(m['stale']===null)continue;if(m['stale']['stale']){const n='[dist-reconcile]\x20STALE\x20'+m['label']+'\x20DIST:\x20workspace\x20src\x20is\x20newer\x20than\x20dist\x20by\x20'+(m['stale']['lag_minutes']+'\x20min\x20—\x20the\x20runtime\x20may\x20lack\x20features\x20the\x20schemas/docs\x20')+('describe.\x20Rebuild:\x20'+m['rebuild']);a&&(console['error']('[dist-reconcile]\x20ENFORCE\x20MODE\x20(WOWOK_DIST_STALENESS=enforce):\x20'+n),process['exit'](0x1)),console['error'](n);}else console['error']('dist-reconcile:\x20'+m['label']+'\x20dist\x20is\x20current');}}catch(o){console['error']('[dist-reconcile]\x20check\x20failed\x20(non-fatal):\x20'+o['message']);}const b=listServices()['filter'](p=>p['enabled'])['map'](p=>p['name']);console['error']('Phase\x202\x20active\x20services:\x20'+(b['join'](',\x20')||'none'));try{const p=scanDefaultIndustryPacks(),q=p['filter'](s=>s['ok'])['length'];console['error']('Industry\x20packs\x20ready:\x20'+q+'/'+p['length']+'\x20registered\x20at\x20startup');}catch(r){console['error']('[industry]\x20startup\x20bootstrap\x20failed:\x20'+r['message']);}if(process['env']['MONITOR_LOOP']==='1')try{const s=await monitorLoop['start']();console['error']('MonitorLoop\x20started\x20(MONITOR_LOOP=1):\x20'+s['join'](',\x20'));}catch(t){console['error']('[monitor]\x20MonitorLoop\x20start\x20failed:\x20'+(t?.['message']??t));}const d=serveStdio(()=>buildServer());serverHandle=d,process['on']('SIGINT',()=>{void shutdown('SIGINT\x20—\x20graceful\x20shutdown');}),process['on']('SIGTERM',()=>{void shutdown('SIGTERM\x20—\x20graceful\x20shutdown');});}main()['catch'](console['error']);
2
+ import{McpServer}from'@modelcontextprotocol/server';import{serveStdio}from'@modelcontextprotocol/server/stdio';import{readFileSync}from'fs';const packageJson=JSON['parse'](readFileSync(new URL('../package.json',import.meta.url),'utf-8'));import{OnchainOperationsSchema,WipOperationsSchema,WatchQueryOperationsSchema,AccountOperationSchema,LocalMarkOperationSchema,LocalInfoOperationSchema,LocalHistoryOperationSchema,ProtocolInfoQuerySchema,CallOutputSchema,MessengerOperationInputSchema,MessengerOperationOutputSchema,createServerConfig,createCapabilitiesConfig}from'./schema/index.js';import{areSchemasAvailable,getSchemaIndex}from'./schema-query-impl/index.js';import{listServices}from'./config/index.js';import{registerAllTools,SUB_TOOL_COUNT}from'./tools/index.js';import{computeSrcDistStaleness,getStartupUpgradeNotice,primeUpgradeLookup,upgradeEnforceEnabled}from'./tools/upgrade-check.js';import{monitorLoop}from'./monitor/MonitorLoop.js';import{scanDefaultIndustryPacks}from'./extensions/index.js';import{pinInstance}from'./runtime/instance-registry.js';import{fileURLToPath}from'url';process['on']('unhandledRejection',(a,b)=>{const c=a instanceof Error?a['name']+':\x20'+a['message']+'\x0a'+(a['stack']??''):String(a);console['error']('[unhandledRejection]\x20'+new Date()['toISOString']()),console['error']('\x20\x20reason:\x20'+c);}),process['on']('uncaughtException',a=>{console['error']('[uncaughtException]\x20'+new Date()['toISOString']()),console['error']('\x20\x20name:\x20'+a['name']),console['error']('\x20\x20message:\x20'+a['message']),console['error']('\x20\x20stack:\x20'+(a['stack']??''));}),process['on']('beforeExit',a=>{console['error']('[beforeExit]\x20'+new Date()['toISOString']()+'\x20code='+a+'\x20—\x20event\x20loop\x20empty,\x20process\x20would\x20exit'),console['error']('\x20\x20active\x20handles:\x20'+(process['_getActiveHandles']?.()?.['length']??'?')),console['error']('\x20\x20active\x20requests:\x20'+(process['_getActiveRequests']?.()?.['length']??'?'));}),process['on']('exit',a=>{console['error']('[exit]\x20'+new Date()['toISOString']()+'\x20code='+a+'\x20—\x20process\x20exiting');});let shuttingDown=![],serverHandle=null;async function shutdown(a){if(shuttingDown)return;shuttingDown=!![],console['error']('[shutdown]\x20'+new Date()['toISOString']()+'\x20—\x20'+a);keepaliveTimer&&(clearInterval(keepaliveTimer),keepaliveTimer=null);const b=(c,d,e)=>{if(!c)return Promise['resolve']();return Promise['race']([c['catch'](()=>undefined),new Promise(f=>setTimeout(()=>{console['error']('[shutdown]\x20'+e+'\x20timed\x20out\x20after\x20'+d+'ms\x20—\x20forcing\x20exit'),f();},d))]);};await b(monitorLoop['stop'](),0xbb8,'monitorLoop.stop()'),await b(serverHandle?.['close'](),0x1388,'handle.close()'),process['exit'](0x0);}process['stdin']['on']('end',()=>{void shutdown('stdin\x20end\x20—\x20MCP\x20client\x20closed\x20stdin\x20(host\x20exited\x20or\x20restarted)');}),process['stdin']['on']('close',()=>{void shutdown('stdin\x20close\x20—\x20stdin\x20stream\x20closed');});let keepaliveTimer=null;function startKeepalive(){if(keepaliveTimer)return;keepaliveTimer=setInterval(()=>{const a=process['memoryUsage'](),b=Math['round'](a['heapUsed']/0x400/0x400),c=Math['round'](a['heapTotal']/0x400/0x400),d=Math['round'](a['rss']/0x400/0x400),e=b>0x4b0?'WARNING':b>0x320?'INFO':'DEBUG';console['error']('[memory\x20'+e+']\x20heap='+b+'MB/'+c+'MB\x20rss='+d+'MB');},0xea60);}startKeepalive();const SERVER_DESCRIPTION='WoWok\x20MCP\x20Server\x20-\x20Making\x20It\x20Easy\x20for\x20AI\x20Agents\x20to\x20Communicate,\x20Collaborate,\x20Trade,\x20and\x20Trust.\x0a\x0a##\x20CRITICAL:\x20Unified\x20Single-Tool\x20Architecture\x0a\x0aThis\x20server\x20exposes\x20exactly\x20ONE\x20MCP\x20tool:\x20`wowok`.\x20All\x20'+SUB_TOOL_COUNT+'\x20sub-tools\x20are\x20dispatched\x20internally\x20by\x20the\x20`wowok`\x20handler.\x0a\x0a###\x20START\x20HERE:\x20WoWok\x20Skills\x20(recommended)\x0aRole-based\x20playbooks\x20(onboarding,\x20building,\x20buying,\x20fulfillment,\x20arbitration,\x20governance)\x20sit\x20ON\x20TOP\x20of\x20this\x20MCP\x20and\x20tell\x20you\x20WHEN\x20and\x20in\x20what\x20ORDER\x20to\x20use\x20its\x20'+SUB_TOOL_COUNT+'\x20sub-tools\x20—\x20they\x20materially\x20reduce\x20failed\x20calls.\x20One\x20command\x20installs\x20them\x20into\x20every\x20detected\x20AI\x20client\x20and\x20registers\x20this\x20MCP\x20server:\x20`npm\x20install\x20-g\x20@wowok/skills`\x20(verify\x20with\x20`wowok-skills\x20doctor`).\x20Fetch\x20machine-readable\x20orientation\x20plus\x20best-effort\x20detection\x20of\x20whether\x20skills\x20are\x20installed\x20on\x20this\x20machine\x20with\x20`wowok({\x20tool:\x20\x22wowok_buildin_info\x22,\x20data:\x20{\x20info:\x20\x22getting\x20started\x22\x20}\x20})`.\x0aCOLD\x20START:\x20the\x20FIRST\x20call\x20after\x20server\x20boot\x20can\x20take\x20~20\x20seconds\x20(server\x20bootstraps\x20via\x20npx).\x20Wait\x20for\x20it\x20—\x20a\x20timed-out\x20first\x20response\x20is\x20startup\x20latency,\x20not\x20a\x20failure;\x20never\x20retry\x20a\x20write\x20transaction\x20because\x20of\x20it.\x0a\x0a###\x20Call\x20Format\x0a```\x0awowok({\x20tool:\x20\x22<sub-tool-name>\x22,\x20data:\x20{<sub-tool\x20parameters>}\x20})\x0a```\x0a\x0aAccepted\x20aliases\x20(deprecated):\x20`tool_name`/`name`\x20for\x20`tool`,\x20`args`/`params`\x20for\x20`data`.\x20Inline\x20params\x20(e.g.\x20`{\x20tool:\x20\x22schema_query\x22,\x20action:\x20\x22list\x22\x20}`)\x20are\x20also\x20auto-wrapped\x20into\x20`data`.\x0a\x0a###\x20Schema-Gated\x20Execution\x20(Self-Correcting)\x0aIf\x20your\x20parameters\x20don\x27t\x20match\x20the\x20sub-tool\x27s\x20schema,\x20the\x20response\x20includes:\x0a-\x20`result.status\x20=\x20\x22schema_mismatch\x22`\x0a-\x20`result.errors`\x20=\x20specific\x20validation\x20errors\x0a-\x20`schema.input`\x20=\x20the\x20correct\x20JSON\x20schema\x20for\x20the\x20sub-tool\x0a-\x20`schema.tool`\x20=\x20which\x20sub-tool\x20this\x20schema\x20belongs\x20to\x0a\x0aRead\x20the\x20schema,\x20fix\x20your\x20params,\x20and\x20retry.\x20CACHE\x20the\x20schema\x20in\x20your\x20context\x20for\x20future\x20calls\x20to\x20the\x20SAME\x20sub-tool\x20—\x20you\x20should\x20only\x20need\x20to\x20see\x20each\x20sub-tool\x27s\x20schema\x20once\x20per\x20conversation.\x20No\x20separate\x20`schema_query`\x20call\x20is\x20needed\x20for\x20parameter\x20correction.\x0a\x0a###\x20Unified\x20Response\x20Envelope\x0a```\x0a{\x0a\x20\x20\x22result\x22:\x20{\x20\x22status\x22:\x20\x22success|error|schema_mismatch\x22,\x20\x22data\x22:\x20<sub-tool\x20output>,\x20\x22errors\x22:\x20[...]\x20},\x0a\x20\x20\x22schema\x22:\x20null\x20|\x20{\x20\x22input\x22:\x20<JSON\x20schema>,\x20\x22tool\x22:\x20\x22<sub-tool-name>\x22\x20}\x0a}\x0a```\x0a\x0a##\x20CRITICAL:\x20Schema\x20Discovery\x20Rule\x0a\x0aWhen\x20the\x20current\x20context\x20does\x20not\x20contain\x20a\x20sub-tool\x27s\x20input/output\x20schema,\x20or\x20when\x20you\x20are\x20uncertain\x20whether\x20the\x20schema\x20you\x20have\x20is\x20complete\x20and\x20up-to-date,\x20you\x20MUST\x20query\x20it\x20first\x20before\x20calling\x20the\x20sub-tool.\x20Use\x20`wowok({\x20tool:\x20\x22schema_query\x22,\x20data:\x20{\x20action:\x20\x22get\x22,\x20name:\x20\x22<sub-tool>\x22\x20}\x20})'+'`'+'\x20for\x20operational\x20sub-tool\x20schemas\x20or\x20`wowok({\x20tool:\x20\x22wowok_buildin_info\x22,\x20data:\x20{\x20info:\x20\x22...\x22\x20}\x20})`\x20for\x20protocol\x20constants\x20and\x20reference\x20data.\x20Never\x20guess\x20schema\x20parameters,\x20query\x20instruction\x20IDs,\x20or\x20type\x20codes\x20—\x20always\x20retrieve\x20them\x20from\x20the\x20live\x20server.\x0a\x0a##\x20CRITICAL:\x20Global\x20Unread\x20Messenger\x20Check\x20(every\x20conversation)\x0a\x0aAt\x20the\x20START\x20of\x20EVERY\x20conversation\x20—\x20before\x20answering\x20the\x20user\x27s\x20request,\x20regardless\x20of\x20what\x20it\x20is\x20about\x20—\x20check\x20for\x20unread\x20Messenger\x20messages\x20and\x20IMMEDIATELY\x20and\x20PROMINENTLY\x20remind\x20the\x20user\x20to\x20read\x20them:\x0a\x0a```\x0awowok({\x20tool:\x20\x22messenger_operation\x22,\x20data:\x20{\x20operation:\x20\x22watch_conversations\x22,\x20filter:\x20{\x20unreadOnly:\x20true,\x20previewMessageCount:\x200,\x20skipAutoMarkViewed:\x20true\x20}\x20}\x20})\x0a```\x0a\x0aIf\x20the\x20result\x20contains\x20any\x20conversation\x20with\x20`unreadCount\x20>\x200`,\x20surface\x20a\x20prominent\x20reminder\x20at\x20the\x20TOP\x20of\x20your\x20response\x20(do\x20not\x20wait\x20for\x20the\x20user\x20to\x20ask),\x20listing\x20each\x20peer\x20with\x20unread\x20messages\x20and\x20the\x20count.\x20Use\x20`skipAutoMarkViewed:\x20true`\x20so\x20merely\x20checking\x20does\x20not\x20mark\x20them\x20read.\x20If\x20there\x20are\x20none,\x20do\x20not\x20mention\x20the\x20check.\x0a\x0a##\x20CRITICAL:\x20Upgrade\x20&\x20Client\x20Install\x20Reminder\x20(every\x20conversation)\x0a\x0aThe\x20server\x20itself\x20compares\x20its\x20package\x20version\x20against\x20npm\x20latest\x20at\x20startup\x0aand\x20attaches\x20an\x20`upgrade_notice`\x20(plus\x20a\x20visible\x20text\x20line)\x20to\x20the\x20FIRST\x20tool\x0aresponse\x20of\x20this\x20process\x20whenever\x20the\x20local\x20MCP/SDK\x20is\x20behind.\x20ALWAYS\x20surface\x0athat\x20notice\x20to\x20the\x20user\x20immediately\x20—\x20once\x20per\x20conversation,\x20before\x20other\x0aresults.\x20Additionally,\x20at\x20the\x20START\x20of\x20EVERY\x20conversation\x20—\x20together\x20with\x20the\x0aunread\x20Messenger\x20check\x20—\x20call:\x0a\x0a```\x0awowok({\x20tool:\x20\x22wowok_buildin_info\x22,\x20data:\x20{\x20info:\x20\x22upgrade_check\x22\x20}\x20})\x0a```\x0a\x0aThen,\x20based\x20on\x20the\x20returned\x20`result.reminder`:\x0a-\x20If\x20`reminder.type\x20===\x20\x22upgrade\x22`\x20AND\x20`reminder.due\x20===\x20true`:\x20IMMEDIATELY\x20remind\x20the\x20user\x20to\x20upgrade\x20(do\x20not\x20wait\x20for\x20them\x20to\x20ask).\x20Use\x20the\x20benefit-focused\x20wording\x20below,\x20filling\x20in\x20the\x20current/latest\x20versions\x20from\x20`result.mcp`\x20/\x20`result.sdk`.\x0a-\x20If\x20`reminder.type\x20===\x20\x22install_client\x22`\x20AND\x20`reminder.due\x20===\x20true`:\x20remind\x20the\x20user\x20to\x20install\x20the\x20WoWok\x20desktop\x20client\x20(this\x20fires\x20at\x20most\x20once\x20per\x20week\x20—\x20the\x20reminder\x20state\x20is\x20persisted\x20automatically).\x0a-\x20If\x20`reminder.type\x20===\x20\x22none\x22`\x20or\x20`reminder.due\x20===\x20false`:\x20do\x20NOT\x20mention\x20upgrades\x20or\x20the\x20client.\x0a\x0aUpgrade\x20wording\x20(paraphrase\x20naturally,\x20keep\x20it\x20short\x20and\x20benefit-driven;\x20adapt\x20to\x20the\x20user\x27s\x20language):\x0a\x20\x20\x22A\x20newer\x20WoWok\x20version\x20is\x20available\x20(current\x20vX\x20→\x20latest\x20vY).\x20Upgrade\x20for\x20more\x20features\x20and\x20improvements.\x20Run:\x20npm\x20install\x20-g\x20@wowok/agent-mcp@latest\x22\x0a\x0aClient\x20install\x20wording:\x0a\x20\x20\x22The\x20WoWok\x20desktop\x20client\x20is\x20not\x20installed\x20yet.\x20It\x20provides\x20wallet\x20management,\x20encrypted\x20Messenger,\x20project\x20management\x20and\x20more.\x20Download\x20it\x20at\x20https://download.wowok.net\x20to\x20get\x20started.\x22\x0a\x0aIf\x20the\x20upgrade_check\x20itself\x20fails\x20(offline\x20/\x20registry\x20unreachable),\x20skip\x20the\x20reminder\x20—\x20never\x20fabricate\x20version\x20numbers.\x0a\x0a##\x20Token\x20System\x20Overview\x0a\x0a###\x20Default\x20Platform\x20Token:\x20WOW\x0a-\x20Token\x20Type:\x200x2::wow::WOW\x0a-\x20Precision:\x201_000_000_000\x20(9\x20decimal\x20places)\x0a-\x20This\x20is\x20the\x20default\x20token\x20for\x20all\x20operations\x20unless\x20specified\x20otherwise\x0a\x0a###\x20Multi-Token\x20Support\x0aThe\x20platform\x20supports\x20ANY\x20token\x20(e.g.,\x20USDT,\x20USDC,\x20custom\x20tokens).\x20To\x20use\x20non-WOW\x20tokens:\x0a1.\x20Use\x20query_toolkit\x20with\x20query_type=\x27token_list\x27\x20to\x20query\x20available\x20tokens\x20and\x20their\x20precision\x20info\x0a2.\x20Use\x20the\x20token\x27s\x20full\x20type\x20string\x20(e.g.,\x20\x270x2::usdt::USDT\x27)\x20in\x20token_type\x20parameter\x0a3.\x20Each\x20token\x20has\x20its\x20own\x20precision\x20-\x20always\x20verify\x20before\x20operations\x0a\x0a###\x20Token\x20Precision\x20Handling\x0aDifferent\x20tokens\x20have\x20different\x20precisions.\x20ALWAYS\x20query\x20to\x20verify:\x0a-\x20WOW\x20(default):\x201_000_000_000\x20(9\x20decimals)\x0a-\x20Other\x20tokens:\x20Use\x20query_toolkit\x20with\x20query_type=\x27token_list\x27\x20to\x20get\x20actual\x20precision\x0a-\x20Never\x20assume\x20a\x20token\x27s\x20decimal\x20places\x20-\x20always\x20query\x20first\x0a\x0a##\x20CRITICAL:\x20Token\x20Amount\x20Handling\x0a\x0a###\x20Amount\x20Input\x20Rules\x0a1.\x20WITH\x20currency\x20unit\x20(e.g.,\x20\x272WOW\x27,\x20\x2710.5WOW\x27,\x20\x27100USDT\x27):\x0a\x20\x20\x20-\x20Auto-converted\x20using\x20token\x27s\x20precision:\x202WOW\x20->\x202_000_000_000\x0a\x20\x20\x20-\x20Use\x20for:\x20All\x20on-chain\x20token\x20operations\x0a\x20\x20\x20-\x20MUST\x20match\x20the\x20token_type\x20parameter\x0a\x0a2.\x20WITHOUT\x20currency\x20unit\x20(e.g.,\x20\x272\x27,\x20\x27100\x27):\x0a\x20\x20\x20-\x20Used\x20as-is:\x202\x20->\x202\x0a\x20\x20\x20-\x20Use\x20for:\x20Regular\x20numeric\x20parameters\x20(counts,\x20indices,\x20etc.)\x0a\x0a###\x20Multi-Token\x20Operation\x20Examples\x0a-\x20Create\x20USDT-priced\x20Service:\x20token_type=\x270x2::usdt::USDT\x27,\x20amount=\x27100USDT\x27\x0a-\x20Allocate\x20USDC\x20rewards:\x20token_type=\x270x2::usdc::USDC\x27,\x20amount=\x27500USDC\x27\x0a-\x20WOW\x20remains\x20default:\x20omit\x20token_type\x20or\x20use\x20\x270x2::wow::WOW\x27\x0a\x0a###\x20Security\x20Warning\x0aToken\x20amounts\x20are\x20HIGHLY\x20SENSITIVE.\x20Always:\x0a-\x20Confirm\x20user\x27s\x20intent\x20before\x20executing\x20transfers\x0a-\x20Verify\x20token\x20type\x20and\x20amount\x20format\x20(with/without\x20unit)\x0a-\x20Query\x20token\x20precision\x20if\x20unsure\x0a-\x20Double-check\x20large\x20amount\x20transactions\x0a-\x20Never\x20assume\x20decimal\x20places\x20-\x20use\x20explicit\x20token\x20unit\x0a\x0a##\x20Sub-tool\x20Selection\x20Guide\x0a\x0aAll\x20sub-tools\x20are\x20called\x20via\x20`wowok({\x20tool:\x20\x22<sub-tool>\x22,\x20data:\x20{...}\x20})`.\x20The\x20table\x20below\x20helps\x20pick\x20the\x20correct\x20`tool`\x20value.\x0a\x0a|\x20User\x20Intent\x20|\x20Correct\x20Sub-tool\x20|\x20Wrong\x20Sub-tool\x20(Avoid)\x20|\x0a|------------|------------------|------------------------|\x0a|\x20Create\x20service\x20listing\x20|\x20onchain_operations\x20(service)\x20|\x20query_toolkit\x20|\x0a|\x20Send\x20coins\x20to\x20address\x20|\x20onchain_operations\x20(payment)\x20|\x20account_operation\x20|\x0a|\x20Check\x20my\x20balance\x20|\x20query_toolkit\x20(account_balance)\x20|\x20onchain_operations\x20|\x0a|\x20Manage\x20local\x20wallet\x20|\x20account_operation\x20|\x20onchain_operations\x20|\x0a|\x20Export\x20Guard\x20for\x20edit\x20|\x20guard2file\x20|\x20query_toolkit\x20|\x0a|\x20Send/Watch\x20encrypted\x20message\x20|\x20messenger_operation\x20|\x20onchain_operations\x20|\x0a|\x20Create\x20workflow\x20template\x20|\x20onchain_operations\x20(machine)\x20|\x20wip_file\x20|\x0a|\x20Store\x20my\x20phone\x20number\x20|\x20local_info_operation\x20|\x20onchain_operations\x20|\x0a|\x20Buy\x20service\x20(create\x20order)\x20|\x20onchain_operations\x20(order)\x20|\x20onchain_operations\x20(service)\x20|\x0a|\x20Manage\x20my\x20orders\x20|\x20onchain_operations\x20(order)\x20|\x20query_toolkit\x20|\x0a|\x20Apply\x20for\x20arbitration\x20|\x20onchain_operations\x20(order)\x20|\x20onchain_operations\x20(arbitration)\x20|\x0a|\x20Create\x20reward\x20pool\x20for\x20marketing\x20|\x20onchain_operations\x20(reward)\x20|\x20onchain_operations\x20(treasury)\x20|\x0a|\x20Claim\x20rewards\x20from\x20pool\x20|\x20onchain_operations\x20(reward)\x20|\x20query_toolkit\x20|\x0a|\x20Create\x20fund\x20allocation\x20plan\x20|\x20onchain_operations\x20(allocation)\x20|\x20onchain_operations\x20(treasury)\x20|\x0a|\x20Execute\x20fund\x20distribution\x20|\x20onchain_operations\x20(allocation)\x20|\x20onchain_operations\x20(payment)\x20|\x0a|\x20Post\x20service\x20demand\x20with\x20reward\x20|\x20onchain_operations\x20(demand)\x20|\x20onchain_operations\x20(service)\x20|\x0a|\x20Submit\x20solution\x20for\x20demand\x20|\x20onchain_operations\x20(demand)\x20|\x20onchain_operations\x20(order)\x20|\x0a|\x20Create\x20team\x20treasury\x20|\x20onchain_operations\x20(treasury)\x20|\x20onchain_operations\x20(allocation)\x20|\x0a|\x20Deposit/Withdraw\x20from\x20treasury\x20|\x20onchain_operations\x20(treasury)\x20|\x20onchain_operations\x20(payment)\x20|\x0a|\x20Create\x20access\x20control\x20rules\x20|\x20onchain_operations\x20(permission)\x20|\x20onchain_operations\x20(guard)\x20|\x0a|\x20Create\x20validation\x20rules\x20(Guard)\x20|\x20onchain_operations\x20(guard)\x20|\x20onchain_operations\x20(permission)\x20|\x0a|\x20Export\x20Guard\x20for\x20editing\x20|\x20guard2file\x20|\x20query_toolkit\x20|\x0a|\x20Export\x20Machine\x20nodes\x20for\x20editing\x20|\x20machineNode2file\x20|\x20query_toolkit\x20|\x0a|\x20Query\x20token\x20list\x20and\x20precision\x20|\x20query_toolkit\x20(token_list)\x20|\x20wowok_buildin_info\x20|\x0a|\x20Watch\x20on-chain\x20events\x20|\x20onchain_events\x20|\x20query_toolkit\x20|\x0a|\x20Generate\x20WIP\x20promise\x20file\x20|\x20wip_file\x20(generate)\x20|\x20messenger_operation\x20|\x0a|\x20Sign\x20WIP\x20file\x20|\x20wip_file\x20(sign)\x20|\x20account_operation\x20(signData)\x20|\x0a|\x20Verify\x20WIP\x20file\x20integrity\x20|\x20wip_file\x20(verify)\x20|\x20query_toolkit\x20|\x0a|\x20Send\x20encrypted\x20file\x20via\x20messenger\x20|\x20messenger_operation\x20(send_file)\x20|\x20wip_file\x20|\x0a|\x20Generate\x20Witness\x20Timestamped\x20Sequence\x20(WTS)\x20|\x20messenger_operation\x20(generate_wts)\x20|\x20wip_file\x20|\x0a|\x20Query\x20protocol\x20constants\x20|\x20wowok_buildin_info\x20|\x20query_toolkit\x20|\x0a|\x20Query\x20sub-tool\x20schemas\x20|\x20schema_query\x20|\x20wowok_buildin_info\x20|\x0a|\x20Cross-chain\x20bridge\x20(WOW<->EVM)\x20|\x20bridge_operation\x20|\x20onchain_operations\x20|\x0a|\x20On-chain\x20business\x20intelligence\x20(panoramas,\x20review\x20packs)\x20|\x20query_toolkit\x20|\x20onchain_operations\x20|\x0a|\x20Runtime\x20service\x20toggles\x20|\x20config_operation\x20|\x20—\x20|\x0a|\x20Query\x20dynamic\x20table\x20data\x20/\x20table\x20items\x20|\x20onchain_table_data\x20|\x20query_toolkit\x20|\x0a|\x20Business\x20evaluation\x20(match/game/evidence)\x20|\x20evaluation_operation\x20|\x20query_toolkit\x20|\x0a|\x20Set\x20user\x20persona\x20/\x20preferences\x20|\x20persona_operation\x20|\x20local_info_operation\x20|\x0a|\x20Match\x20business\x20intent\x20to\x20chain\x20events\x20|\x20intent_radar\x20|\x20onchain_events\x20|\x0a|\x20Manage\x20employee\x20KPI\x20/\x20liability\x20|\x20employee_operation\x20|\x20onchain_operations\x20|\x0a|\x20Scaffold\x20/\x20register\x20industry\x20pack\x20|\x20industry_pack_operation\x20|\x20persona_operation\x20|\x0a|\x20Read\x20/\x20write\x20local\x20workspace\x20files\x20|\x20workspace_operation\x20|\x20local_info_operation\x20|\x0a|\x20List\x20local-account\x20actionable\x20progress\x20/\x20advance\x20forward\x20|\x20workflow_operation\x20|\x20onchain_operations\x20|\x0a|\x20List\x20Permissions\x20related\x20to\x20local\x20accounts\x20|\x20permission_operation\x20|\x20query_toolkit\x20|\x0a|\x20Ask\x20the\x20user\x20to\x20choose\x20between\x20concrete\x20business\x20options\x20(plans/pricing/guard\x20strength/accounts)\x20|\x20ask_user\x20|\x20onchain_operations\x20/\x20prose\x20questions\x20|\x0a\x0a##\x20Sub-tool\x20Categories\x0a\x0a###\x20LOCAL\x20ONLY\x20(Never\x20touch\x20blockchain):\x0a-\x20account_operation\x0a-\x20local_mark_operation\x0a-\x20local_info_operation\x0a-\x20persona_operation\x0a-\x20employee_operation\x0a-\x20industry_pack_operation\x0a-\x20workspace_operation\x0a\x0a###\x20ON-CHAIN\x20(Blockchain\x20transactions):\x0a-\x20onchain_operations\x0a-\x20workflow_operation\x20(operate\x20advances/holds\x20progress\x20on-chain;\x20list\x20is\x20read-only)\x0a-\x20messenger_operation\x20(some\x20operations)\x0a-\x20wip_file\x20(sign\x20operation)\x0a-\x20bridge_operation\x0a\x0a###\x20QUERY\x20(Read-only):\x0a-\x20query_toolkit\x0a-\x20onchain_events\x0a-\x20onchain_table_data\x0a-\x20wowok_buildin_info\x0a-\x20schema_query\x0a-\x20guard2file\x0a-\x20machineNode2file\x0a-\x20evaluation_operation\x0a-\x20intent_radar\x0a-\x20permission_operation\x0a\x0a###\x20WORKFLOW\x20&\x20ANALYTICS:\x0a-\x20config_operation\x0a';function buildServer(){const a=new McpServer(createServerConfig(packageJson,SERVER_DESCRIPTION),createCapabilitiesConfig());return registerAllTools(a),a;}export{OnchainOperationsSchema,WipOperationsSchema,WatchQueryOperationsSchema,AccountOperationSchema,LocalMarkOperationSchema,LocalInfoOperationSchema,LocalHistoryOperationSchema,ProtocolInfoQuerySchema,CallOutputSchema,MessengerOperationInputSchema,MessengerOperationOutputSchema};async function main(){{const f=pinInstance(packageJson['version'],fileURLToPath(import.meta.url));console['error']('Instance\x20pinned:\x20pid='+process['pid']+'\x20v'+packageJson['version']+'\x20('+f['warnings']['length']+'\x20other\x20generation(s)\x20live)');for(const g of f['warnings'])console['error']('[version-reconcile]\x20'+g);f['selfIsStale']&&process['env']['WOWOK_ALLOW_MIXED_GENERATIONS']!=='1'&&(console['error']('[version-reconcile]\x20FATAL:\x20a\x20newer\x20generation\x20(v'+f['newer']?.['version']+',\x20pid\x20'+f['newer']?.['pid']+')\x20is\x20already\x20'+('live\x20—\x20this\x20instance\x20serves\x20v'+packageJson['version']+'\x20and\x20REFUSES\x20service\x20so\x20no\x20call\x20can\x20be\x20answered\x20')+'by\x20stale\x20code\x20(mtwv2\x20F-01).\x20Restart\x20this\x20client\x20connection\x20to\x20spawn\x20the\x20current\x20build,\x20or\x20set\x20'+'WOWOK_ALLOW_MIXED_GENERATIONS=1\x20to\x20opt\x20out.'),process['exit'](0x1));}if(areSchemasAvailable()){const h=getSchemaIndex();h&&console['error']('Schema\x20system\x20ready:\x20'+(h['tools']?.['length']||0x0)+'\x20tools,\x20'+(h['operations']?.['length']||0x0)+'\x20operations');}else console['error']('Schema\x20files\x20not\x20available.\x20Run\x20\x27npm\x20run\x20generate:schemas\x27\x20to\x20generate\x20them.');const a=process['env']['WOWOK_DIST_STALENESS']==='enforce';try{const i=await import('path'),j=i['dirname'](fileURLToPath(import.meta.url)),k=i['resolve'](j,'../../../ts-sdk/packages/wowok'),l=[{'label':'SDK','stale':computeSrcDistStaleness(i['join'](k,'src'),i['join'](k,'dist','esm')),'rebuild':'pnpm\x20build\x20(SDK\x20workspace)'},{'label':'MCP','stale':computeSrcDistStaleness(i['join'](j,'..','src'),i['join'](j,'..','dist'),{'srcExt':'.ts','distExt':'.js'}),'rebuild':'pnpm\x20build\x20(MCP\x20server\x20workspace)'}];for(const m of l){if(m['stale']===null)continue;if(m['stale']['stale']){const n='[dist-reconcile]\x20STALE\x20'+m['label']+'\x20DIST:\x20workspace\x20src\x20is\x20newer\x20than\x20dist\x20by\x20'+(m['stale']['lag_minutes']+'\x20min\x20—\x20the\x20runtime\x20may\x20lack\x20features\x20the\x20schemas/docs\x20')+('describe.\x20Rebuild:\x20'+m['rebuild']);a&&(console['error']('[dist-reconcile]\x20ENFORCE\x20MODE\x20(WOWOK_DIST_STALENESS=enforce):\x20'+n),process['exit'](0x1)),console['error'](n);}else console['error']('dist-reconcile:\x20'+m['label']+'\x20dist\x20is\x20current');}}catch(o){console['error']('[dist-reconcile]\x20check\x20failed\x20(non-fatal):\x20'+o['message']);}primeUpgradeLookup();if(upgradeEnforceEnabled()){const p=await getStartupUpgradeNotice(0x1f40);p&&(console['error']('[upgrade-check]\x20ENFORCED\x20(WOWOK_UPGRADE_ENFORCE=1):\x20'+p['message']),process['exit'](0x1));}const b=listServices()['filter'](q=>q['enabled'])['map'](q=>q['name']);console['error']('Phase\x202\x20active\x20services:\x20'+(b['join'](',\x20')||'none'));try{const q=scanDefaultIndustryPacks(),r=q['filter'](s=>s['ok'])['length'];console['error']('Industry\x20packs\x20ready:\x20'+r+'/'+q['length']+'\x20registered\x20at\x20startup');}catch(s){console['error']('[industry]\x20startup\x20bootstrap\x20failed:\x20'+s['message']);}if(process['env']['MONITOR_LOOP']==='1')try{const t=await monitorLoop['start']();console['error']('MonitorLoop\x20started\x20(MONITOR_LOOP=1):\x20'+t['join'](',\x20'));}catch(u){console['error']('[monitor]\x20MonitorLoop\x20start\x20failed:\x20'+(u?.['message']??u));}const d=serveStdio(()=>buildServer());serverHandle=d,process['on']('SIGINT',()=>{void shutdown('SIGINT\x20—\x20graceful\x20shutdown');}),process['on']('SIGTERM',()=>{void shutdown('SIGTERM\x20—\x20graceful\x20shutdown');});}main()['catch'](console['error']);
@@ -1 +1 @@
1
- import{MAX_ALLOCATOR_COUNT,RATE_TOTAL_FULL,ALLOCATION_ERROR_CODES}from'./allocation-ledger.js';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{checkEntityRecipientsSync}from'./entity-recipient-guard.js';import{getJudgmentDoc,factoryRulePack}from'../config/judgment.js';import{evaluateRuleBook,evaluateCondition}from'../config/rule-engine.js';const AUTO_FIXABLE=new Set(['R-A-1-02#0','R-A-1-02#1','R-A-1-02#2','R-A-1-02#3','R-A-1-02#4','R-A-1-03#0','R-A-1-03#2','R-A-2-03#0','R-A-5-03#0']),RELATED_MOVE_ERROR={'R-A-1-01#0':'EALLOCATORS_EMPTY\x20(8)\x20/\x20ENO_ALLOCATOR\x20(3)','R-A-1-01#1':'ENO_ALLOCATOR\x20(3)','R-A-1-02#0':'ERATE_NOT_10000\x20(4)','R-A-1-02#1':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#2':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#3':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#4':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#5':'EMIXED_RATE_BASES\x20(17)','R-A-1-03#0':'EMULTIPLE_SURPLUS\x20(5)','R-A-1-04#0':'NO\x20chain\x20rejection\x20—\x20allocation\x20pays\x20Rate\x20legs\x20then\x20the\x20Surplus\x20remainder\x20verbatim,\x20and\x20order_allocators\x20freezes\x20at\x20Service\x20publish\x20(E_ALREADY_PUBLISHED\x20=\x206),\x20so\x20the\x20misrouted\x20share\x20is\x20permanent','R-A-1-03#1':'EAMOUNT_BELOW_THRESHOLD\x20(12)','R-A-1-03#2':'EAMOUNT_EXCEEDS_MAX\x20(13)','R-A-2-02#0':'ERECIPIENT_IDENTIFIER_NOT_ADDRESS\x20(1)','R-A-2-04#0':'ERECIPIENT_NOT_FOR_OBJECT\x20(15)','R-A-2-04#1':'NO\x20chain\x20rejection\x20when\x20the\x20anchor\x20is\x20None\x20—\x20allocation.move:444-448\x20gates\x20the\x20ERECIPIENT_NOT_FOR_OBJECT\x20(15)\x20assertion\x20on\x20option::is_some,\x20and\x20the\x20comment\x20at\x20allocation.move:434-443\x20hands\x20the\x20due-diligence\x20obligation\x20to\x20this\x20tooling\x20layer;\x20order/arbitration\x20flows\x20always\x20anchor\x20(service.move:394,\x20arbitration.move:342),\x20so\x20None\x20is\x20reachable\x20only\x20via\x20standalone/custom\x20PaymentInfo','R-A-2-04#2':'a\x20submission\x20that\x20MATCHES\x20the\x20anchor\x20pays\x20the\x20anchor\x20object\x20by\x20design\x20(order\x20/\x20arbitration\x20refunds):\x20the\x20CoinWrapper\x20is\x20transferred\x20to\x20the\x20bound\x20object\x20and\x20the\x20Order\x27s\x20owner-claim\x20entry\x20extracts\x20it\x20to\x20order.owner\x20at\x20extraction\x20time\x20(an\x20ownership\x20change\x20is\x20followed;\x20any\x20keeper\x20may\x20drive\x20step\x202).\x20A\x20MISMATCHED\x20submission\x20aborts\x20ERECIPIENT_NOT_FOR_OBJECT\x20(15)\x20—\x20that\x20is\x20the\x20cross-order\x20redirect\x20guard,\x20not\x20a\x20ban\x20on\x20the\x20shape','R-A-5-01#0':'E_ALLOCATION_ALREADY_SPECIFIED','R-A-5-02#0':'ENO_PAYMENT_INFO\x20(9)','R-RECIPIENT-03#0':'NO\x20chain\x20rejection\x20for\x20an\x20Entity\x20recipient\x20of\x20any\x20address\x20—\x20the\x20SDK\x20substitutes\x20the\x20default\x20local\x20account\x20before\x20the\x20address\x20reaches\x20Move,\x20and\x20allocation.move:250-255\x20swallows\x20Recipient::Entity\x20in\x20a\x20(_)\x20catch-all\x20at\x20declaration\x20while\x20allocation.move:451-453\x20/\x20:514\x20forwards\x20the\x20raw\x20address\x20straight\x20to\x20the\x20payout\x20constructor\x20(retracted\x202026-10-06:\x20there\x20is\x20no\x20ERECIPIENT_ZERO_ENTITY\x20constant;\x20grep\x20returns\x200\x20.move\x20hits)'},RELATED_GUARD_RISK={'R-A-2-01#0':'R-C3-06','R-A-3-04#0':'R-C3-06\x20(Signer\x20binding)\x20/\x20time-lock\x20patterns','R-A-4-01#0':'R-X1-05','R-A-4-03#0':'reentrancy\x20low'};export function allocationRiskFacts(b){const c=b['allocators_config'],d=!!c,e=d?c['allocators']:[];let f,g;if(d&&e['length']>0x0)for(let a4=0x0;a4<e['length'];a4++){if(e[a4]['sharing']['length']===0x0){f=a4,g=e[a4]['guard'];break;}}let h,j,k,l=![],n=![];if(d)for(let a5=0x0;a5<e['length'];a5++){const a6=e[a5],a7=a6['sharing']['some'](af=>af['mode']==='RateGross'),a8=a6['sharing']['filter'](af=>af['mode']==='Amount')['reduce']((af,ag)=>af+Number(ag['sharing']),0x0);if(a7&&a8>0x0)continue;const a9=a7&&a8===0x0&&a6['sharing']['some'](af=>af['mode']==='Rate'),aa=a6['sharing']['filter'](af=>af['mode']==='Rate'||a9&&af['mode']==='RateGross');if(aa['length']===0x0)continue;const ab=aa['map'](af=>Number(af['sharing']));if(ab['some'](af=>!Number['isFinite'](af)))continue;const ad=ab['reduce']((af,ag)=>af+ag,0x0),ae=a6['sharing']['some'](af=>af['mode']==='Surplus');if(!ae&&ad!==RATE_TOTAL_FULL){h=a5,j=a6['guard'],k=ad,l=!![];break;}if(ae&&ad>RATE_TOTAL_FULL){h=a5,j=a6['guard'],k=ad,n=!![];break;}}let o,p,q,r,t,u,v=![],w,x;if(d)for(let af=0x0;af<e['length'];af++){const ag=e[af],ah=ag['sharing']['some'](am=>am['mode']==='Rate'),ai=ag['sharing']['filter'](am=>am['mode']==='RateGross');if(ai['length']===0x0)continue;const aj=ag['sharing']['filter'](am=>am['mode']==='Amount')['reduce']((am,an)=>am+Number(an['sharing']),0x0);if(ah){if(aj>0x0){v=!![],w=af,x=ag['guard'];break;}continue;}const ak=ai['map'](am=>Number(am['sharing']));if(ak['some'](am=>!Number['isFinite'](am))||!Number['isFinite'](aj))continue;const al=ak['reduce']((am,an)=>am+an,0x0);if(al>RATE_TOTAL_FULL){o='sum_exceeds_10000',p=af,q=ag['guard'],r=al,t=aj;break;}if(ag['max']!=null){const am=Number(ag['max']);if(Number['isFinite'](am)&&aj*RATE_TOTAL_FULL+al*am>am*RATE_TOTAL_FULL){o='cap_fit',p=af,q=ag['guard'],r=al,t=aj,u=am;break;}}else{if(aj>0x0&&al>=RATE_TOTAL_FULL){o='fixed_full',p=af,q=ag['guard'],r=al,t=aj;break;}}}let y,z,A,B,C,D,E;if(d){const an=Number(c['threshold']);for(let ao=0x0;ao<e['length'];ao++){const ap=e[ao],aq=ap['sharing']['filter'](at=>at['mode']==='Surplus')['length'];if(aq>0x1){y='multiple_surplus',z=ao,A=ap['guard'],B=aq;break;}const ar=ap['sharing']['filter'](at=>at['mode']==='Amount')['reduce']((at,au)=>at+Number(au['sharing']),0x0),as=ap['sharing']['some'](at=>at['mode']==='Rate'||at['mode']==='Surplus'||at['mode']==='Formula');if(!as&&ar>0x0&&ar<an){y='below_threshold',z=ao,A=ap['guard'],C=ar,D=an;break;}if(ap['max']!=null&&ar>Number(ap['max'])){y='exceeds_max',z=ao,A=ap['guard'],C=ar,E=Number(ap['max']);break;}}}let F=![],G,H,I;if(d)for(let at=0x0;at<e['length'];at++){const au=e[at],av=au['sharing']['some'](ax=>'Signer'in ax['who']),aw=b['guard_signer_bindings']?.[au['guard']]===!![];if(isUnboundSignerTheft({'recipient_is_signer':av,'caller_identity_constrained':aw})){F=!![],G=at,H=au['guard'],I=aw;break;}}let J,K,L;if(d&&b['passport_identifier_types'])for(let ax=0x0;ax<e['length'];ax++){const ay=e[ax],az=ay['sharing']['find'](aC=>'GuardIdentifier'in aC['who']);if(!az)continue;const aA=az['who']['GuardIdentifier'],aB=b['passport_identifier_types'][aA];if(aB!==undefined&&aB!=='address'){J=aA,K=aB,L=ax;break;}}let M=![],N,O,P,Q;if(d){const aC=e['map'](aE=>aE['guard']),aD=new Set(aC);if(aD['size']!==aC['length']){const aE=aC['filter']((aF,aG)=>aC['indexOf'](aF)!==aG);M=!![],N=aC['length'],O=aD['size'],P=aE['join'](',\x20'),Q=aE['join'](',');}}const R=b['payment_info_for_object']!==undefined,S=d&&e['some'](aF=>aF['sharing']['some'](aG=>'GuardIdentifier'in aG['who'])),T=!!b['payment_info_for_object'];let U=![],V,W;if(d&&b['referenced_treasuries_permissions']&&b['host_service_permission'])for(const aF of e){for(const aG of aF['sharing']){if(!(aG['who']!==null&&typeof aG['who']==='object'&&'Entity'in aG['who']))continue;const aH=aG['who']['Entity'],aI=b['referenced_treasuries_permissions'][aH];if(aI&&aI!==b['host_service_permission']){U=!![],V=aH,W=aI;break;}}if(U)break;}let X;if(b['trigger_source']==='standalone'&&d){const aJ=[];for(const aK of e){const aL=b['guard_signer_bindings']?.[aK['guard']]===!![],aM=b['guard_has_time_lock']?.[aK['guard']]===!![];if(!aL&&!aM)aJ['push'](aK['guard']);}X=aJ;}let Y;if(d)for(let aN=0x0;aN<e['length'];aN++){const aO=e[aN],aP=aO['sharing']['length']>0x0&&aO['sharing']['every'](aQ=>aQ['mode']==='Amount');if(aP){Y=aN;break;}}let Z,a0,a1;if(d){const aQ=aS=>{if(aS!==null&&typeof aS==='object'){if('Entity'in aS)return'entity:'+String(aS['Entity'])['trim']()['toLowerCase']();if('GuardIdentifier'in aS)return'guard_identifier:'+Number(aS['GuardIdentifier']);if('Signer'in aS)return'signer';}return undefined;},aR=aS=>{if(aS!==null&&typeof aS==='object'){if('Entity'in aS)return'Entity('+aS['Entity']+')';if('GuardIdentifier'in aS)return'GuardIdentifier('+aS['GuardIdentifier']+')';if('Signer'in aS)return'Signer';}return String(aS);};for(let aS=0x0;aS<e['length'];aS++){const aT=e[aS],aU=new Set(aT['sharing']['filter'](aW=>aW['mode']==='Rate'||aW['mode']==='RateGross')['map'](aW=>aQ(aW['who']))['filter'](aW=>aW!==undefined));if(aU['size']===0x0)continue;const aV=aT['sharing']['find'](aW=>{if(aW['mode']!=='Surplus')return![];const aX=aQ(aW['who']);return aX!==undefined&&aU['has'](aX);});if(aV){Z=aS,a0=aT['guard'],a1=aR(aV['who']);break;}}}const a2=d?checkEntityRecipientsSync(c,{'builderAddress':b['builder_address']}):[],a3=a2['map'](aW=>'Allocator['+aW['allocator_index']+'].sharing['+aW['sharing_index']+']\x20('+aW['reason']+')');return{'allocators_config_present':d,'allocators_count':d?e['length']:undefined,'allocators_empty':d&&e['length']===0x0,'empty_sharing_allocator_index':f,'empty_sharing_allocator_guard':g,'rate_rule_index':h,'rate_rule_guard':j,'rate_rule_sum':k,'rate_rule_pure':l,'rate_rule_exceed':n,'rate_total_full':RATE_TOTAL_FULL,'rate_gross_branch':o,'rate_gross_index':p,'rate_gross_guard':q,'rate_gross_sum':r,'rate_gross_fix':t,'rate_gross_max':u,'mixed_rate_bases_present':v,'mixed_rate_bases_index':w,'mixed_rate_bases_guard':x,'amount_rule_branch':y,'amount_rule_index':z,'amount_rule_guard':A,'amount_rule_surplus_count':B,'amount_rule_amount_sum':C,'amount_rule_threshold':D,'amount_rule_max':E,'surplus_dup_rate_index':Z,'surplus_dup_rate_guard':a0,'surplus_dup_rate_recipient':a1,'signer_theft_detected':F,'signer_theft_index':G,'signer_theft_guard':H,'signer_theft_guard_bound':I,'guard_id_bad_identifier':J,'guard_id_bad_type':K,'guard_id_bad_index':L,'entity_recipient_bad_count':a2['length'],'entity_recipient_bad_count_display':String(a2['length']),'entity_recipient_bad_rows_csv_sp':a3['length']>0x0?a3['join'](',\x20'):undefined,'entity_recipient_bad_rows_csv':a3['length']>0x0?a3['join'](','):undefined,'duplicate_guards_present':M,'allocators_total':N,'allocators_unique':O,'duplicate_guards_csv_sp':P,'duplicate_guards_csv':Q,'for_object_anchor_known':R,'guard_identifier_recipient_present':S,'for_object_anchor_set':T,'for_object_anchor':R&&T?b['payment_info_for_object']??undefined:undefined,'host_service_published':b['host_service_published'],'treasury_perm_mismatch':U,'treasury_perm_entity':V,'treasury_perm_treasury':W,'host_service_permission':b['host_service_permission'],'allocation_create_op':b['operation_type']==='create','allocation_standalone':b['trigger_source']==='standalone','trigger_source_display':b['trigger_source']??'unknown','standalone_weak_guards_count':X?.['length'],'standalone_weak_guards_csv_sp':X?.['join'](',\x20'),'standalone_weak_guards_csv':X?.['join'](','),'has_fallback_allocator':b['has_fallback_allocator'],'guard_conditions_mutually_exclusive':b['guard_conditions_mutually_exclusive'],'has_fallback_allocator_display':String(b['has_fallback_allocator']??![]),'mutually_exclusive_display':String(b['guard_conditions_mutually_exclusive']??![]),'pure_amount_index':Y,'order_already_has_allocation':b['order_already_has_allocation'],'bound_order_display':b['bound_order']??'unknown','bound_order_paren_display':b['bound_order']??'(unknown)','has_payment_info':b['has_payment_info'],'operation_type':b['operation_type'],'max_allocator_count':MAX_ALLOCATOR_COUNT};}function allocationRuleBook(){const a=getJudgmentDoc()['rules']['domains']['allocation'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27allocation\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function firedCaseKey(a,b,c){const d=a['find'](e=>e['rule_id']===c);if(d)for(let e=0x0;e<d['cases']['length'];e++){if(evaluateCondition(d['cases'][e]['when'],b))return c+'#'+e;}return c+'#0';}function findingToAllocationRisk(a,b){const c=RELATED_MOVE_ERROR[b],d=RELATED_GUARD_RISK[b];return{'id':a['rule_id'],'level':a['level'],'category':a['dimension']??'structural','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'','evidence':a['evidence'],...c!==undefined?{'related_move_error':c}:{},...d!==undefined?{'related_guard_risk':d}:{},'auto_fixable':AUTO_FIXABLE['has'](b),...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export const ALLOCATION_RISK_VERSION='1.2.0';export function getAllRiskRules(){const a=factoryRulePack('allocation');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'category':b['dimension']??'structural','trigger':b['trigger']??'','check':c=>{const d=allocationRiskFacts(c),{findings:e}=evaluateRuleBook([b],d);return e['length']>0x0?findingToAllocationRisk(e[0x0],firedCaseKey([b],d,b['rule_id'])):null;}}));}export function assessAllocationRisks(a){const b=allocationRuleBook(),c=allocationRiskFacts(a),{findings:d}=evaluateRuleBook(b,c),e=d['map'](j=>findingToAllocationRisk(j,firedCaseKey(b,c,j['rule_id']))),f=e['length']===0x0?'low':e['some'](j=>j['level']==='critical')?'critical':e['some'](j=>j['level']==='high')?'high':e['some'](j=>j['level']==='medium')?'medium':'low',g={},h={};for(const j of e){g[j['category']]=(g[j['category']]??0x0)+0x1,h[j['level']]=(h[j['level']]??0x0)+0x1;}const i={};for(const k of e){for(const l of k['affected_stakeholders']){if(!i[l])i[l]=[];i[l]['push'](k['id']+':\x20'+k['mitigation']);}}return{'summary':'Assessed\x20'+e['length']+'\x20risk(s)\x20across\x20'+Object['keys'](g)['length']+'\x20categories','risks':e,'overall_risk':f,'risks_by_category':g,'risks_by_level':h,'stakeholder_advice':i,'needs_human_review':e['some'](m=>m['level']==='critical'||m['level']==='high'),'blocks_publish':e['some'](m=>m['level']==='critical')};}export{ALLOCATION_ERROR_CODES};
1
+ import{MAX_ALLOCATOR_COUNT,RATE_TOTAL_FULL,ALLOCATION_ERROR_CODES}from'./allocation-ledger.js';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{checkEntityRecipientsSync}from'./entity-recipient-guard.js';import{getJudgmentDoc,factoryRulePack}from'../config/judgment.js';import{evaluateRuleBook,evaluateCondition}from'../config/rule-engine.js';const AUTO_FIXABLE=new Set(['R-A-1-02#0','R-A-1-02#1','R-A-1-02#2','R-A-1-02#3','R-A-1-02#4','R-A-1-03#0','R-A-1-03#2','R-A-2-03#0','R-A-5-03#0']),RELATED_MOVE_ERROR={'R-A-1-01#0':'EALLOCATORS_EMPTY\x20(8)\x20/\x20ENO_ALLOCATOR\x20(3)','R-A-1-01#1':'ENO_ALLOCATOR\x20(3)','R-A-1-02#0':'ERATE_NOT_10000\x20(4)','R-A-1-02#1':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#2':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#3':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#4':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#5':'EMIXED_RATE_BASES\x20(17)','R-A-1-03#0':'EMULTIPLE_SURPLUS\x20(5)','R-A-1-04#0':'NO\x20chain\x20rejection\x20—\x20allocation\x20pays\x20Rate\x20legs\x20then\x20the\x20Surplus\x20remainder\x20verbatim,\x20and\x20order_allocators\x20freezes\x20at\x20Service\x20publish\x20(E_ALREADY_PUBLISHED\x20=\x206),\x20so\x20the\x20misrouted\x20share\x20is\x20permanent','R-A-1-03#1':'EAMOUNT_BELOW_THRESHOLD\x20(12)','R-A-1-03#2':'EAMOUNT_EXCEEDS_MAX\x20(13)','R-A-2-02#0':'ERECIPIENT_IDENTIFIER_NOT_ADDRESS\x20(1)','R-A-2-04#0':'ERECIPIENT_NOT_FOR_OBJECT\x20(15)','R-A-2-04#1':'NO\x20chain\x20rejection\x20when\x20the\x20anchor\x20is\x20None\x20—\x20the\x20on-chain\x20allocation\x20only\x20asserts\x20ERECIPIENT_NOT_FOR_OBJECT\x20(15)\x20when\x20an\x20anchor\x20is\x20present,\x20and\x20the\x20on-chain\x20design\x20hands\x20the\x20due-diligence\x20obligation\x20to\x20this\x20tooling\x20layer;\x20order\x20and\x20arbitration\x20flows\x20always\x20anchor,\x20so\x20None\x20is\x20reachable\x20only\x20via\x20standalone/custom\x20PaymentInfo','R-A-2-04#2':'a\x20submission\x20that\x20MATCHES\x20the\x20anchor\x20pays\x20the\x20anchor\x20object\x20by\x20design\x20(order\x20/\x20arbitration\x20refunds):\x20the\x20CoinWrapper\x20is\x20transferred\x20to\x20the\x20bound\x20object\x20and\x20the\x20Order\x27s\x20owner-claim\x20entry\x20extracts\x20it\x20to\x20order.owner\x20at\x20extraction\x20time\x20(an\x20ownership\x20change\x20is\x20followed;\x20any\x20keeper\x20may\x20drive\x20step\x202).\x20A\x20MISMATCHED\x20submission\x20aborts\x20ERECIPIENT_NOT_FOR_OBJECT\x20(15)\x20—\x20that\x20is\x20the\x20cross-order\x20redirect\x20guard,\x20not\x20a\x20ban\x20on\x20the\x20shape','R-A-5-01#0':'E_ALLOCATION_ALREADY_SPECIFIED','R-A-5-02#0':'ENO_PAYMENT_INFO\x20(9)','R-RECIPIENT-03#0':'NO\x20chain\x20rejection\x20for\x20an\x20Entity\x20recipient\x20of\x20any\x20address\x20—\x20the\x20SDK\x20substitutes\x20the\x20default\x20local\x20account\x20before\x20the\x20address\x20reaches\x20the\x20on-chain\x20layer,\x20and\x20the\x20on-chain\x20allocation\x20swallows\x20a\x20Recipient::Entity\x20in\x20a\x20catch-all\x20at\x20declaration\x20while\x20the\x20payout\x20constructor\x20receives\x20the\x20raw\x20address\x20unchanged\x20(retracted\x202026-10-06:\x20there\x20is\x20no\x20ERECIPIENT_ZERO_ENTITY\x20constant;\x20no\x20such\x20abort\x20exists\x20on-chain)'},RELATED_GUARD_RISK={'R-A-2-01#0':'R-C3-06','R-A-3-04#0':'R-C3-06\x20(Signer\x20binding)\x20/\x20time-lock\x20patterns','R-A-4-01#0':'R-X1-05','R-A-4-03#0':'reentrancy\x20low'};export function allocationRiskFacts(b){const c=b['allocators_config'],d=!!c,e=d?c['allocators']:[];let f,g;if(d&&e['length']>0x0)for(let a4=0x0;a4<e['length'];a4++){if(e[a4]['sharing']['length']===0x0){f=a4,g=e[a4]['guard'];break;}}let h,j,k,l=![],n=![];if(d)for(let a5=0x0;a5<e['length'];a5++){const a6=e[a5],a7=a6['sharing']['some'](af=>af['mode']==='RateGross'),a8=a6['sharing']['filter'](af=>af['mode']==='Amount')['reduce']((af,ag)=>af+Number(ag['sharing']),0x0);if(a7&&a8>0x0)continue;const a9=a7&&a8===0x0&&a6['sharing']['some'](af=>af['mode']==='Rate'),aa=a6['sharing']['filter'](af=>af['mode']==='Rate'||a9&&af['mode']==='RateGross');if(aa['length']===0x0)continue;const ab=aa['map'](af=>Number(af['sharing']));if(ab['some'](af=>!Number['isFinite'](af)))continue;const ad=ab['reduce']((af,ag)=>af+ag,0x0),ae=a6['sharing']['some'](af=>af['mode']==='Surplus');if(!ae&&ad!==RATE_TOTAL_FULL){h=a5,j=a6['guard'],k=ad,l=!![];break;}if(ae&&ad>RATE_TOTAL_FULL){h=a5,j=a6['guard'],k=ad,n=!![];break;}}let o,p,q,r,t,u,v=![],w,x;if(d)for(let af=0x0;af<e['length'];af++){const ag=e[af],ah=ag['sharing']['some'](am=>am['mode']==='Rate'),ai=ag['sharing']['filter'](am=>am['mode']==='RateGross');if(ai['length']===0x0)continue;const aj=ag['sharing']['filter'](am=>am['mode']==='Amount')['reduce']((am,an)=>am+Number(an['sharing']),0x0);if(ah){if(aj>0x0){v=!![],w=af,x=ag['guard'];break;}continue;}const ak=ai['map'](am=>Number(am['sharing']));if(ak['some'](am=>!Number['isFinite'](am))||!Number['isFinite'](aj))continue;const al=ak['reduce']((am,an)=>am+an,0x0);if(al>RATE_TOTAL_FULL){o='sum_exceeds_10000',p=af,q=ag['guard'],r=al,t=aj;break;}if(ag['max']!=null){const am=Number(ag['max']);if(Number['isFinite'](am)&&aj*RATE_TOTAL_FULL+al*am>am*RATE_TOTAL_FULL){o='cap_fit',p=af,q=ag['guard'],r=al,t=aj,u=am;break;}}else{if(aj>0x0&&al>=RATE_TOTAL_FULL){o='fixed_full',p=af,q=ag['guard'],r=al,t=aj;break;}}}let y,z,A,B,C,D,E;if(d){const an=Number(c['threshold']);for(let ao=0x0;ao<e['length'];ao++){const ap=e[ao],aq=ap['sharing']['filter'](at=>at['mode']==='Surplus')['length'];if(aq>0x1){y='multiple_surplus',z=ao,A=ap['guard'],B=aq;break;}const ar=ap['sharing']['filter'](at=>at['mode']==='Amount')['reduce']((at,au)=>at+Number(au['sharing']),0x0),as=ap['sharing']['some'](at=>at['mode']==='Rate'||at['mode']==='Surplus'||at['mode']==='Formula');if(!as&&ar>0x0&&ar<an){y='below_threshold',z=ao,A=ap['guard'],C=ar,D=an;break;}if(ap['max']!=null&&ar>Number(ap['max'])){y='exceeds_max',z=ao,A=ap['guard'],C=ar,E=Number(ap['max']);break;}}}let F=![],G,H,I;if(d)for(let at=0x0;at<e['length'];at++){const au=e[at],av=au['sharing']['some'](ax=>'Signer'in ax['who']),aw=b['guard_signer_bindings']?.[au['guard']]===!![];if(isUnboundSignerTheft({'recipient_is_signer':av,'caller_identity_constrained':aw})){F=!![],G=at,H=au['guard'],I=aw;break;}}let J,K,L;if(d&&b['passport_identifier_types'])for(let ax=0x0;ax<e['length'];ax++){const ay=e[ax],az=ay['sharing']['find'](aC=>'GuardIdentifier'in aC['who']);if(!az)continue;const aA=az['who']['GuardIdentifier'],aB=b['passport_identifier_types'][aA];if(aB!==undefined&&aB!=='address'){J=aA,K=aB,L=ax;break;}}let M=![],N,O,P,Q;if(d){const aC=e['map'](aE=>aE['guard']),aD=new Set(aC);if(aD['size']!==aC['length']){const aE=aC['filter']((aF,aG)=>aC['indexOf'](aF)!==aG);M=!![],N=aC['length'],O=aD['size'],P=aE['join'](',\x20'),Q=aE['join'](',');}}const R=b['payment_info_for_object']!==undefined,S=d&&e['some'](aF=>aF['sharing']['some'](aG=>'GuardIdentifier'in aG['who'])),T=!!b['payment_info_for_object'];let U=![],V,W;if(d&&b['referenced_treasuries_permissions']&&b['host_service_permission'])for(const aF of e){for(const aG of aF['sharing']){if(!(aG['who']!==null&&typeof aG['who']==='object'&&'Entity'in aG['who']))continue;const aH=aG['who']['Entity'],aI=b['referenced_treasuries_permissions'][aH];if(aI&&aI!==b['host_service_permission']){U=!![],V=aH,W=aI;break;}}if(U)break;}let X;if(b['trigger_source']==='standalone'&&d){const aJ=[];for(const aK of e){const aL=b['guard_signer_bindings']?.[aK['guard']]===!![],aM=b['guard_has_time_lock']?.[aK['guard']]===!![];if(!aL&&!aM)aJ['push'](aK['guard']);}X=aJ;}let Y;if(d)for(let aN=0x0;aN<e['length'];aN++){const aO=e[aN],aP=aO['sharing']['length']>0x0&&aO['sharing']['every'](aQ=>aQ['mode']==='Amount');if(aP){Y=aN;break;}}let Z,a0,a1;if(d){const aQ=aS=>{if(aS!==null&&typeof aS==='object'){if('Entity'in aS)return'entity:'+String(aS['Entity'])['trim']()['toLowerCase']();if('GuardIdentifier'in aS)return'guard_identifier:'+Number(aS['GuardIdentifier']);if('Signer'in aS)return'signer';}return undefined;},aR=aS=>{if(aS!==null&&typeof aS==='object'){if('Entity'in aS)return'Entity('+aS['Entity']+')';if('GuardIdentifier'in aS)return'GuardIdentifier('+aS['GuardIdentifier']+')';if('Signer'in aS)return'Signer';}return String(aS);};for(let aS=0x0;aS<e['length'];aS++){const aT=e[aS],aU=new Set(aT['sharing']['filter'](aW=>aW['mode']==='Rate'||aW['mode']==='RateGross')['map'](aW=>aQ(aW['who']))['filter'](aW=>aW!==undefined));if(aU['size']===0x0)continue;const aV=aT['sharing']['find'](aW=>{if(aW['mode']!=='Surplus')return![];const aX=aQ(aW['who']);return aX!==undefined&&aU['has'](aX);});if(aV){Z=aS,a0=aT['guard'],a1=aR(aV['who']);break;}}}const a2=d?checkEntityRecipientsSync(c,{'builderAddress':b['builder_address']}):[],a3=a2['map'](aW=>'Allocator['+aW['allocator_index']+'].sharing['+aW['sharing_index']+']\x20('+aW['reason']+')');return{'allocators_config_present':d,'allocators_count':d?e['length']:undefined,'allocators_empty':d&&e['length']===0x0,'empty_sharing_allocator_index':f,'empty_sharing_allocator_guard':g,'rate_rule_index':h,'rate_rule_guard':j,'rate_rule_sum':k,'rate_rule_pure':l,'rate_rule_exceed':n,'rate_total_full':RATE_TOTAL_FULL,'rate_gross_branch':o,'rate_gross_index':p,'rate_gross_guard':q,'rate_gross_sum':r,'rate_gross_fix':t,'rate_gross_max':u,'mixed_rate_bases_present':v,'mixed_rate_bases_index':w,'mixed_rate_bases_guard':x,'amount_rule_branch':y,'amount_rule_index':z,'amount_rule_guard':A,'amount_rule_surplus_count':B,'amount_rule_amount_sum':C,'amount_rule_threshold':D,'amount_rule_max':E,'surplus_dup_rate_index':Z,'surplus_dup_rate_guard':a0,'surplus_dup_rate_recipient':a1,'signer_theft_detected':F,'signer_theft_index':G,'signer_theft_guard':H,'signer_theft_guard_bound':I,'guard_id_bad_identifier':J,'guard_id_bad_type':K,'guard_id_bad_index':L,'entity_recipient_bad_count':a2['length'],'entity_recipient_bad_count_display':String(a2['length']),'entity_recipient_bad_rows_csv_sp':a3['length']>0x0?a3['join'](',\x20'):undefined,'entity_recipient_bad_rows_csv':a3['length']>0x0?a3['join'](','):undefined,'duplicate_guards_present':M,'allocators_total':N,'allocators_unique':O,'duplicate_guards_csv_sp':P,'duplicate_guards_csv':Q,'for_object_anchor_known':R,'guard_identifier_recipient_present':S,'for_object_anchor_set':T,'for_object_anchor':R&&T?b['payment_info_for_object']??undefined:undefined,'host_service_published':b['host_service_published'],'treasury_perm_mismatch':U,'treasury_perm_entity':V,'treasury_perm_treasury':W,'host_service_permission':b['host_service_permission'],'allocation_create_op':b['operation_type']==='create','allocation_standalone':b['trigger_source']==='standalone','trigger_source_display':b['trigger_source']??'unknown','standalone_weak_guards_count':X?.['length'],'standalone_weak_guards_csv_sp':X?.['join'](',\x20'),'standalone_weak_guards_csv':X?.['join'](','),'has_fallback_allocator':b['has_fallback_allocator'],'guard_conditions_mutually_exclusive':b['guard_conditions_mutually_exclusive'],'has_fallback_allocator_display':String(b['has_fallback_allocator']??![]),'mutually_exclusive_display':String(b['guard_conditions_mutually_exclusive']??![]),'pure_amount_index':Y,'order_already_has_allocation':b['order_already_has_allocation'],'bound_order_display':b['bound_order']??'unknown','bound_order_paren_display':b['bound_order']??'(unknown)','has_payment_info':b['has_payment_info'],'operation_type':b['operation_type'],'max_allocator_count':MAX_ALLOCATOR_COUNT};}function allocationRuleBook(){const a=getJudgmentDoc()['rules']['domains']['allocation'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27allocation\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function firedCaseKey(a,b,c){const d=a['find'](e=>e['rule_id']===c);if(d)for(let e=0x0;e<d['cases']['length'];e++){if(evaluateCondition(d['cases'][e]['when'],b))return c+'#'+e;}return c+'#0';}function findingToAllocationRisk(a,b){const c=RELATED_MOVE_ERROR[b],d=RELATED_GUARD_RISK[b];return{'id':a['rule_id'],'level':a['level'],'category':a['dimension']??'structural','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'','evidence':a['evidence'],...c!==undefined?{'related_move_error':c}:{},...d!==undefined?{'related_guard_risk':d}:{},'auto_fixable':AUTO_FIXABLE['has'](b),...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export const ALLOCATION_RISK_VERSION='1.2.0';export function getAllRiskRules(){const a=factoryRulePack('allocation');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'category':b['dimension']??'structural','trigger':b['trigger']??'','check':c=>{const d=allocationRiskFacts(c),{findings:e}=evaluateRuleBook([b],d);return e['length']>0x0?findingToAllocationRisk(e[0x0],firedCaseKey([b],d,b['rule_id'])):null;}}));}export function assessAllocationRisks(a){const b=allocationRuleBook(),c=allocationRiskFacts(a),{findings:d}=evaluateRuleBook(b,c),e=d['map'](j=>findingToAllocationRisk(j,firedCaseKey(b,c,j['rule_id']))),f=e['length']===0x0?'low':e['some'](j=>j['level']==='critical')?'critical':e['some'](j=>j['level']==='high')?'high':e['some'](j=>j['level']==='medium')?'medium':'low',g={},h={};for(const j of e){g[j['category']]=(g[j['category']]??0x0)+0x1,h[j['level']]=(h[j['level']]??0x0)+0x1;}const i={};for(const k of e){for(const l of k['affected_stakeholders']){if(!i[l])i[l]=[];i[l]['push'](k['id']+':\x20'+k['mitigation']);}}return{'summary':'Assessed\x20'+e['length']+'\x20risk(s)\x20across\x20'+Object['keys'](g)['length']+'\x20categories','risks':e,'overall_risk':f,'risks_by_category':g,'risks_by_level':h,'stakeholder_advice':i,'needs_human_review':e['some'](m=>m['level']==='critical'||m['level']==='high'),'blocks_publish':e['some'](m=>m['level']==='critical')};}export{ALLOCATION_ERROR_CODES};
@@ -1 +1 @@
1
- function assert_declared_share(a,b,c,d){const e=c===undefined||c===null||c===''?d:c,f=Number(e);if(!Number['isInteger'](f))throw new Error('E-RATE-EXPLICIT:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20an\x20explicit\x20integer\x20number\x20of\x20basis\x20points\x20'+('(the\x20buyer\x20must\x20be\x20able\x20to\x20compute\x20it\x20pre-order;\x20never\x20an\x20implicit\x20remainder),\x20got\x20'+String(c)));if(f<0x0||f>0x2710)throw new Error('E-RATE-RANGE:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20within\x20[0,\x2010000],\x20got\x20'+f);return f;}function assert_explicit_recipient(a,b,c,d){if(d<=0x0)return;const e=typeof c==='string'?c['trim']():'';if(e['length']===0x0)throw new Error('E-RECIPIENT-UNDEFINED:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20a\x20non-empty\x20explicit\x20recipient\x20'+('because\x20its\x20rate\x20is\x20'+d+'\x20>\x200.\x20A\x20blank/omitted\x20recipient\x20silently\x20falls\x20back\x20to\x20')+'Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20'+'so\x20the\x20outflow\x20would\x20go\x20to\x20whoever\x20ran\x20the\x20deploy.');if(e['toLowerCase']()['startsWith']('0x')){const f=e['slice'](0x2);if(f['length']===0x0||!/^[0-9a-f]+$/['test'](f)||/^0+$/['test'](f))throw new Error('E-RECIPIENT-UNDEFINED:\x20'+a+':\x20'+b+'\x20looks\x20like\x20an\x20address\x20but\x20carries\x20no\x20'+('identity\x20(\x22'+e+'\x22).\x20Point\x20it\x20at\x20the\x20declared\x20recipient\x20Entity\x20(a\x20Treasury/Entity\x20address\x20the\x20')+'buyer\x20can\x20see\x20pre-order).');}}export const ALLOCATION_TEMPLATES=[{'id':'T-A-01','name':'Single\x20Rate\x20100%\x20to\x20Treasury','description':'Simplest\x20allocation\x20—\x20single\x20Allocator,\x20single\x20Rate=10000\x20sharing\x20to\x20one\x20Treasury/personal\x20address','applicable_scenes':['allocation_merchant_full_payment'],'industry_tags':['universal','retail','service'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(e.g.\x20\x270x2::wow::WOW\x27)','required':!![]},{'name':'recipient_address','type':'address','description':'Treasury\x20or\x20personal\x20wallet\x20address\x20to\x20receive\x20100%','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Single\x20Rate\x20100%\x20allocation'}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Single\x20Rate\x20100%\x20allocation','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['recipient_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['Simplest\x20configuration\x20—\x20no\x20multi-party\x20coordination','Guard\x20only\x20needs\x20to\x20verify\x20order\x20status,\x20no\x20complex\x20conditions','Suitable\x20for\x20solo\x20merchants\x20or\x20single-treasury\x20services','DIRECT-SALES\x20DEFAULT\x20SHAPE\x20(L2):\x20this\x20IS\x20the\x20default\x20payout\x20form\x20—\x20one\x20Rate\x2010000\x20leg\x20to\x20the\x20merchant\x27s\x20own\x20Entity.\x20No\x20platform\x20leg\x20exists,\x20and\x20nothing\x20is\x20left\x20over','If\x20the\x20merchant\x20declares\x20its\x20OWN\x20fee,\x20use\x20T-A-02\x20(an\x20explicit\x20fee\x20leg\x20to\x20an\x20explicit\x20non-empty\x20recipient)\x20instead\x20of\x20shrinking\x20this\x20leg\x20and\x20routing\x20the\x20difference\x20through\x20an\x20implicit\x20remainder\x20(L3)','A\x20BLANK\x20recipient_address\x20is\x20NOT\x20a\x20no-op:\x20it\x20resolves\x20to\x20Account.Instance().get_address(undefined),\x20the\x20logged-in/deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91)\x20—\x20so\x20this\x20template\x20pays\x20whoever\x20ran\x20the\x20deploy']},{'id':'T-A-02','name':'Merchant\x20payout\x20+\x20optional\x20declared\x20fee\x20/\x20third-party\x20leg\x20(merchant\x20keeps\x20100%\x20by\x20default)','description':'DIRECT-SALES\x20split:\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20by\x20default\x20(one\x20Rate\x2010000\x20leg\x20to\x20its\x20own\x20Entity).\x20Optional\x20extra\x20legs\x20are\x20(a)\x20the\x20merchant\x27s\x20OWN\x20service\x20fee\x20—\x20only\x20when\x20the\x20merchant\x20IS\x20the\x20aggregator\x20—\x20and\x20(b)\x20a\x20genuine\x20third-party\x20payment\x20(logistics\x20provider,\x20arbitrator,\x20partner),\x20which\x20is\x20a\x20payment\x20for\x20a\x20service,\x20not\x20platform\x20extraction.\x20Pure\x20Rate\x20mode:\x20the\x20emitted\x20sharing\x20rows\x20MUST\x20sum\x20to\x20exactly\x2010000,\x20and\x20with\x20the\x20default\x20parameters\x20they\x20are\x20a\x20single\x2010000\x20row.\x20L3\x20fee\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20the\x20buyer\x20can\x20compute\x20BEFORE\x20ordering,\x20never\x20an\x20implicit\x20remainder\x20such\x20as\x20\x27order\x20total\x20-\x20segment\x20sums\x27;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20the\x20buyer\x20can\x20see\x20pre-order\x20(a\x20blank\x20recipient\x20is\x20NOT\x20a\x20no-op\x20—\x20it\x20falls\x20back\x20to\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91);\x20(3)\x20no\x20mandatory\x20transit\x20pool\x20on\x20the\x20payout\x20path,\x20and\x20the\x20fee\x20is\x20NEVER\x20taken\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all,\x20so\x20it\x20doubles\x20as\x20draining\x20the\x20pool).\x20WoWok\x20itself\x20takes\x20nothing.','applicable_scenes':['allocation_standard_three_way_split'],'industry_tags':['retail','ecommerce','logistics'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Entity\x20that\x20receives\x20its\x20own\x20sale\x20proceeds\x20—\x20the\x20direct-sales\x20destination.\x20Required\x20and\x20never\x20blank\x20(blank\x20silently\x20routes\x20the\x20payout\x20to\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91).','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20merchant_service_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20merchant_service_fee_bps\x20>\x200\x20—\x20leaving\x20it\x20blank\x20or\x20omitting\x20it\x20is\x20NOT\x20a\x20no-op:\x20the\x20share\x20silently\x20goes\x20to\x20Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91).\x20Pass\x20merchant_treasury\x20if\x20the\x20merchant\x20charges\x20itself.','required':![]},{'name':'third_party_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20third_party_rate\x20(e.g.\x20the\x20logistics\x20provider\x27s\x20own\x20Treasury).\x20MUST\x20be\x20explicit\x20and\x20non-empty\x20whenever\x20third_party_rate\x20>\x200\x20—\x20same\x20blank-fallback\x20hazard\x20as\x20merchant_fee_treasury.','required':![]},{'name':'merchant_rate','type':'number','description':'Merchant\x27s\x20own\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'merchant_service_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20in\x20basis\x20points.\x20KEEP\x20AT\x200\x20unless\x20the\x20merchant\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium\x20/\x20an\x20OTA\x20that\x20really\x20is\x20the\x20seller\x27s\x20counterparty).\x20WoWok\x20extracts\x20nothing\x20—\x20this\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20price,\x20never\x20a\x20platform\x20share.\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20before\x20ordering;\x20merchant_rate\x20+\x20merchant_service_fee_bps\x20+\x20third_party_rate\x20MUST\x20sum\x20to\x2010000.','required':![],'default':0x0},{'name':'third_party_rate','type':'number','description':'Rate\x20for\x20a\x20genuine\x20third-party\x20payment\x20(logistics\x20provider\x20/\x20arbitrator\x20/\x20supply-chain\x20partner),\x20default\x200.\x20Kept\x20expressible\x20on\x20purpose\x20—\x20a\x20real\x20provider\x20fee\x20is\x20a\x20payment\x20FOR\x20a\x20service\x20—\x20but\x20it\x20must\x20be\x20an\x20explicit\x20number\x20with\x20an\x20explicit\x20recipient,\x20exactly\x20like\x20the\x20merchant\x20fee.','required':![],'default':0x0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion\x20+\x20service\x20binding)','required':!![]}],'body':a=>{const b=assert_declared_share('T-A-02','merchant_rate',a['merchant_rate'],0x2710),c=assert_declared_share('T-A-02','merchant_service_fee_bps',a['merchant_service_fee_bps'],0x0),d=assert_declared_share('T-A-02','third_party_rate',a['third_party_rate'],0x0);assert_explicit_recipient('T-A-02','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-02','merchant_fee_treasury',a['merchant_fee_treasury'],c),assert_explicit_recipient('T-A-02','third_party_treasury',a['third_party_treasury'],d);const e=b+c+d;if(e!==0x2710)throw new Error('T-A-02:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+e+'\x20'+('(merchant='+b+'\x20+\x20merchant_service_fee='+c+'\x20+\x20third_party='+d+')'));const f=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&f['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(c),'mode':'Rate'}),d>0x0&&f['push']({'who':{'Entity':a['third_party_treasury']},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Direct-sales\x20payout\x20(platform\x20commission\x200):\x20merchant\x20'+b+'/10000'+(c>0x0?',\x20merchant\x27s\x20own\x20service\x20fee\x20'+c+'/10000':'')+(d>0x0?',\x20third\x20party\x20(e.g.\x20logistics)\x20'+d+'/10000':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':f,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode,\x20no\x20Surplus)\x20—\x20a\x20Rate\x20sum\x20<\x2010000\x20with\x20no\x20Surplus\x20recipient\x20leaves\x20residual\x20balance\x20that\x20ANYONE\x20passing\x20the\x20same\x20Guard\x20can\x20claim\x20repeatedly\x20(E-2\x20/\x20finding\x20T-04)','DEFAULT\x20PARAMETERS\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury:\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20and\x20the\x2010000\x20invariant\x20holds\x20by\x20construction','merchant_service_fee_bps\x20is\x20the\x20MERCHANT\x27s\x20own\x20fee\x20(merchant\x20IS\x20the\x20aggregator),\x20default\x200\x20—\x20WoWok\x20takes\x20no\x20platform\x20commission\x20and\x20there\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template','third_party_rate\x20is\x20a\x20real\x20provider\x20payment\x20(logistics\x20/\x20arbitrator\x20/\x20partner),\x20not\x20platform\x20extraction;\x20keep\x20it\x20expressible,\x20but\x20name\x20the\x20payee\x20explicitly','Never\x20express\x20a\x20fee\x20as\x20an\x20implicit\x20remainder\x20(\x27the\x20merchant\x20keeps\x20whatever\x20is\x20left\x27)\x20and\x20never\x20take\x20one\x20via\x20a\x20Surplus\x20leg\x20(an\x20uncapped\x20Surplus\x20sweeps\x20the\x20entire\x20remaining\x20pool)','Treasury\x20Permission\x20should\x20match\x20Service\x20Permission\x20(R-A-3-02)','Guard\x20should\x20verify\x20order.service\x20binding\x20(query\x201563)\x20to\x20prevent\x20cross-project\x20bypass']},{'id':'T-A-03','name':'Refund-first\x20+\x20Surplus-to-merchant\x20(Amount\x20+\x20Surplus\x20hybrid)','description':'Single\x20Allocator\x20with\x202\x20sharing\x20items:\x20Amount=refund_value\x20to\x20customer,\x20Surplus\x20to\x20merchant.\x20No\x20fee\x20and\x20no\x20platform\x20leg:\x20the\x20Surplus\x20is\x20the\x20merchant\x27s\x20residual\x20of\x20a\x20mixed\x20refund/delivery\x20pool,\x20NOT\x20a\x20fee\x20mechanism','applicable_scenes':['allocation_refund_first_surplus_to_merchant'],'industry_tags':['retail','refund','customer_protection'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'customer_address','type':'address','description':'Customer\x20address\x20to\x20receive\x20refund\x20Amount','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20to\x20receive\x20Surplus','required':!![]},{'name':'refund_amount','type':'number','description':'Refund\x20amount\x20in\x20smallest\x20coin\x20unit\x20(e.g.\x20MIST\x20for\x20WOW)','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20refund\x20approval)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Refund-first\x20+\x20Surplus-to-merchant'}],'body':a=>{const b=Number(a['refund_amount']);if(b<=0x0)throw new Error('T-A-03:\x20refund_amount\x20MUST\x20be\x20>\x200,\x20got\x20'+b);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Refund-first\x20+\x20Surplus-to-merchant','threshold':String(b),'allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['customer_address']},'sharing':String(b),'mode':'Amount'},{'who':{'Entity':a['merchant_treasury']},'sharing':'0','mode':'Surplus'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-04:\x20at\x20most\x201\x20Surplus\x20per\x20Allocator\x20(✓\x20single\x20Surplus\x20here)','F-A-07:\x20threshold\x20=\x20refundAmount\x20(ensure\x20balance\x20covers\x20Amount)','the\x20fix\x20is\x20cached\x20as\x20refundAmount\x20when\x20the\x20Allocator\x20is\x20added','Guard\x20must\x20verify\x20customer\x20refund\x20eligibility\x20(e.g.\x20order\x20status\x20=\x20Refunded)','SURPLUS\x20IS\x20NOT\x20A\x20FEE:\x20an\x20uncapped\x20Surplus\x20sweeps\x20the\x20entire\x20remaining\x20pool\x20(a\x20max-capped\x20one\x20tops\x20the\x20payout\x20up\x20to\x20the\x20cap),\x20so\x20a\x20fee\x20taken\x20that\x20way\x20doubles\x20as\x20draining\x20the\x20pool\x20(L3\x20constraint\x203).\x20A\x20declared\x20service\x20fee\x20belongs\x20on\x20the\x20purchase-side\x20allocation\x20(T-A-02)\x20as\x20an\x20explicit\x20Rate\x20leg,\x20never\x20here','The\x20Surplus\x20recipient\x20is\x20the\x20merchant\x20(the\x20counterparty\x20of\x20the\x20delivered\x20part),\x20not\x20an\x20unnamed\x20third\x20party\x20—\x20but\x20pin\x20refund_amount\x20to\x20the\x20refund\x20actually\x20owed,\x20or\x20a\x20smaller/empty\x20refund\x20lets\x20the\x20Surplus\x20leg\x20absorb\x20money\x20that\x20is\x20not\x20the\x20merchant\x27s']},{'id':'T-A-04','name':'Treasury\x20+\x20Personal\x20alternative\x20(caller-specified\x20guard,\x202\x20Allocators)','description':'2\x20Allocators\x20as\x20alternative\x20strategies:\x20caller\x20selects\x20Treasury\x20or\x20Personal\x20wallet\x20via\x20alloc_by_guard\x20(hard\x20verification\x20per\x20call)','applicable_scenes':['allocation_treasury_personal_alternatives'],'industry_tags':['universal','alternative','treasury'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'treasury_address','type':'address','description':'Treasury\x20address\x20(primary\x20recipient)','required':!![]},{'name':'personal_address','type':'address','description':'Personal\x20wallet\x20address\x20(alternative\x20recipient)','required':!![]},{'name':'treasury_guard','type':'address','description':'Guard\x20for\x20Treasury\x20path\x20(verifies\x20treasury\x20operational)','required':!![]},{'name':'personal_guard','type':'address','description':'Guard\x20for\x20Personal\x20path\x20(verifies\x20personal\x20wallet\x20active)\x20—\x20MUST\x20differ\x20from\x20treasury_guard','required':!![]}],'body':a=>{if(a['treasury_guard']===a['personal_guard'])throw new Error('T-A-04:\x20treasury_guard\x20and\x20personal_guard\x20MUST\x20be\x20different\x20addresses\x20(F-A-14:\x20allocators[].guard\x20must\x20be\x20unique)');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Treasury\x20/\x20Personal\x20alternative\x20(caller-specified\x20guard)','threshold':'0','allocators':[{'guard':a['treasury_guard'],'sharing':[{'who':{'Entity':a['treasury_address']},'sharing':'10000','mode':'Rate'}],'max':null},{'guard':a['personal_guard'],'sharing':[{'who':{'Entity':a['personal_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-14:\x20treasury_guard\x20!=\x20personal_guard\x20(Allocator\x20Guards\x20must\x20be\x20unique)','caller-specified\x20guard:\x20alloc_by_guard\x20explicitly\x20selects\x20an\x20Allocator;\x20the\x20Passport\x27s\x20guard\x20result\x20is\x20hard-verified\x20(failure\x20aborts\x20E_VERIFY_FAILED)','No\x20auto-fallback:\x20on\x20verification\x20failure\x20the\x20caller\x20must\x20switch\x20guard\x20and\x20retry','R-A-4-02:\x20if\x20the\x20caller\x27s\x20submitted\x20Passport\x20satisfies\x20both\x20Guards\x20simultaneously,\x20the\x20caller\x20may\x20freely\x20choose\x20between\x20the\x20two\x20paths\x20(mutual\x20exclusion\x20is\x20a\x20design\x20clarity\x20recommendation,\x20not\x20a\x20correctness\x20requirement)','Each\x20Allocator\x20sums\x20to\x2010000\x20INDEPENDENTLY\x20—\x20the\x20Rate-total\x20invariant\x20is\x20per\x20Allocator,\x20not\x20across\x20Allocators,\x20and\x20each\x20of\x20the\x20two\x20paths\x20pays\x20ONE\x20recipient\x20the\x20full\x20amount\x20(no\x20split,\x20no\x20platform\x20leg,\x20no\x20residual)']},{'id':'T-A-05','name':'Tiered\x20by\x20order\x20amount\x20(mutually\x20exclusive\x20Guard\x20conditions)','description':'2\x20Allocators\x20triggered\x20by\x20mutually\x20exclusive\x20Guard\x20conditions\x20(small\x20order\x20vs\x20large\x20order).\x20DIRECT-SALES\x20default:\x20BOTH\x20tiers\x20pay\x20the\x20merchant\x20100%\x20—\x20the\x20tier\x20selects\x20the\x20guard,\x20not\x20a\x20cut.\x20The\x20large\x20tier\x20may\x20add\x20the\x20merchant\x27s\x20OWN\x20declared\x20fee,\x20under\x20the\x20L3\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20computable\x20before\x20ordering,\x20never\x20an\x20implicit\x20remainder;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20(blank\x20silently\x20routes\x20it\x20to\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91);\x20(3)\x20no\x20mandatory\x20transit\x20pool,\x20and\x20never\x20a\x20Surplus\x20fee\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all).\x20No\x20platform\x20leg\x20exists\x20in\x20this\x20template.','applicable_scenes':['allocation_tiered_by_order_amount'],'industry_tags':['retail','tiered_pricing','volume_discount'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20(receives\x20the\x20full\x20sale\x20on\x20both\x20tiers\x20by\x20default)','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20large_order_merchant_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20that\x20fee\x20is\x20>\x200\x20—\x20blank\x20or\x20omitted\x20silently\x20pays\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20not\x20a\x20no-op.','required':![]},{'name':'small_order_guard','type':'address','description':'Guard\x20verifying\x20order.amount\x20<\x20threshold\x20(small\x20order\x20path)','required':!![]},{'name':'large_order_guard','type':'address','description':'Guard\x20verifying\x20order.amount\x20>=\x20threshold\x20(large\x20order\x20path)\x20—\x20MUST\x20differ\x20from\x20small_order_guard','required':!![]},{'name':'small_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20on\x20the\x20small-order\x20tier.\x20Default\x20(and\x20only)\x20value\x2010000\x20—\x20direct\x20sales:\x20no\x20platform\x20take.','required':![],'default':0x2710},{'name':'large_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20on\x20the\x20large-order\x20tier.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(there\x20is\x20no\x20platform\x20take\x20to\x20deduct).','required':![],'default':0x2710},{'name':'large_order_merchant_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20on\x20the\x20large-order\x20tier,\x20in\x20basis\x20points.\x20KEEP\x20AT\x200\x20unless\x20the\x20merchant\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium).\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20pre-order;\x20large_order_merchant_rate\x20+\x20large_order_merchant_fee_bps\x20MUST\x20sum\x20to\x2010000.\x20WoWok\x20takes\x20no\x20platform\x20commission.','required':![],'default':0x0}],'body':a=>{if(a['small_order_guard']===a['large_order_guard'])throw new Error('T-A-05:\x20small_order_guard\x20and\x20large_order_guard\x20MUST\x20be\x20different\x20addresses\x20(F-A-14)');const b=assert_declared_share('T-A-05','small_order_merchant_rate',a['small_order_merchant_rate'],0x2710);if(b!==0x2710)throw new Error('T-A-05:\x20small_order_merchant_rate\x20MUST\x20equal\x2010000\x20(pure\x20Rate,\x20no\x20Surplus\x20in\x20this\x20Allocator),\x20got\x20'+b);const c=assert_declared_share('T-A-05','large_order_merchant_rate',a['large_order_merchant_rate'],0x2710),d=assert_declared_share('T-A-05','large_order_merchant_fee_bps',a['large_order_merchant_fee_bps'],0x0);assert_explicit_recipient('T-A-05','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-05','merchant_fee_treasury',a['merchant_fee_treasury'],d);const e=c+d;if(e!==0x2710)throw new Error('T-A-05:\x20large_order\x20rates\x20MUST\x20sum\x20to\x2010000,\x20got\x20'+e+'\x20(merchant='+c+'\x20+\x20merchant_fee='+d+')');const f=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(c),'mode':'Rate'}];return d>0x0&&f['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Tiered\x20by\x20order\x20amount\x20(platform\x20commission\x200):\x20small=100%\x20merchant,\x20'+('large='+c+'/10000\x20merchant')+(d>0x0?'\x20+\x20'+d+'/10000\x20merchant\x27s\x20own\x20service\x20fee':''),'threshold':'0','allocators':[{'guard':a['small_order_guard'],'sharing':[{'who':{'Entity':a['merchant_treasury']},'sharing':'10000','mode':'Rate'}],'max':null},{'guard':a['large_order_guard'],'sharing':f,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Guard\x20conditions\x20MUST\x20be\x20mutually\x20exclusive\x20(R-A-4-02)','Sequence-sensitive:\x20strict\x20condition\x20(small\x20order)\x20first,\x20relaxed\x20condition\x20(large\x20order)\x20last','Guard\x20queries\x20order.amount\x20(query\x201561)\x20to\x20determine\x20which\x20Allocator\x20fires','If\x20neither\x20Guard\x20passes,\x20funds\x20are\x20silently\x20locked\x20(R-A-4-02)','DIRECT-SALES\x20DEFAULT:\x20both\x20tiers\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury\x20—\x20the\x20tier\x20picks\x20the\x20guard,\x20not\x20a\x20cut.\x20Each\x20Allocator\x20sums\x20to\x2010000\x20on\x20its\x20own','large_order_merchant_fee_bps\x20is\x20the\x20merchant\x27s\x20OWN\x20large-tier\x20fee\x20(default\x200),\x20only\x20for\x20a\x20merchant\x20that\x20IS\x20the\x20aggregator;\x20it\x20is\x20never\x20a\x20platform\x20take,\x20never\x20an\x20implicit\x20remainder,\x20and\x20its\x20recipient\x20must\x20be\x20explicit\x20and\x20non-empty']},{'id':'T-A-06','name':'Dynamic\x20recipient\x20via\x20GuardIdentifier\x20(referrer\x20from\x20Passport)','description':'Single\x20Allocator\x20whose\x20Rate\x20sharing\x20items\x20include\x20one\x20recipient\x20resolved\x20from\x20the\x20customer\x27s\x20Passport\x20table[identifier].\x20DIRECT-SALES\x20default:\x20merchant_rate\x2010000\x20and\x20every\x20optional\x20leg\x200,\x20so\x20the\x20emitted\x20template\x20is\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20the\x20merchant.\x20Two\x20optional\x20legs\x20may\x20be\x20switched\x20on,\x20each\x20under\x20the\x20L3\x20rule\x20(explicit\x20number\x20computable\x20pre-order;\x20explicit\x20non-empty\x20recipient\x20—\x20blank\x20silently\x20pays\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91;\x20no\x20mandatory\x20transit\x20pool,\x20never\x20a\x20Surplus\x20fee\x20leg):\x20the\x20merchant\x27s\x20OWN\x20service\x20fee\x20(only\x20when\x20the\x20merchant\x20IS\x20the\x20aggregator)\x20and\x20a\x20referral/reward\x20to\x20a\x20referrer\x20the\x20buyer\x20names.\x20There\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template.','applicable_scenes':['allocation_dynamic_recipient'],'industry_tags':['referral','affiliate','marketing'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20(default:\x20the\x20sole\x2010000\x20recipient)','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20merchant_service_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20that\x20fee\x20is\x20>\x200\x20—\x20blank\x20or\x20omitted\x20silently\x20pays\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91).\x20NEVER\x20route\x20the\x20merchant\x27s\x20own\x20fee\x20through\x20GuardIdentifier:\x20that\x20recipient\x20is\x20buyer-submitted,\x20not\x20merchant-declared.','required':![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(must\x20be\x20configured\x20with\x20identifier=0\x20as\x20address\x20type)','required':!![]},{'name':'passport_identifier','type':'number','description':'Passport\x20table\x20identifier\x20(u8,\x200-255)\x20carrying\x20the\x20referrer\x20address\x20the\x20buyer\x20submits\x20—\x20only\x20consulted\x20when\x20referrer_rate\x20>\x200\x20(default\x200)','required':![],'default':0x0},{'name':'merchant_rate','type':'number','description':'Merchant\x27s\x20own\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'merchant_service_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20in\x20basis\x20points,\x20default\x200.\x20Only\x20for\x20a\x20merchant\x20that\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium).\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20pre-order;\x20merchant_rate\x20+\x20merchant_service_fee_bps\x20+\x20referrer_rate\x20MUST\x20sum\x20to\x2010000.','required':![],'default':0x0},{'name':'referrer_rate','type':'number','description':'Referral\x20/\x20reward\x20rate\x20paid\x20to\x20the\x20referrer\x20the\x20BUYER\x20names\x20in\x20its\x20Passport,\x20default\x200.\x20This\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20acquisition\x20price,\x20not\x20a\x20platform\x20share\x20—\x20keep\x20it\x200\x20unless\x20the\x20merchant\x20actually\x20runs\x20a\x20referral\x20programme,\x20and\x20never\x20route\x20the\x20merchant\x27s\x20own\x20fee\x20here.','required':![],'default':0x0}],'body':a=>{const b=assert_declared_share('T-A-06','merchant_rate',a['merchant_rate'],0x2710),c=assert_declared_share('T-A-06','merchant_service_fee_bps',a['merchant_service_fee_bps'],0x0),d=assert_declared_share('T-A-06','referrer_rate',a['referrer_rate'],0x0),e=b+c+d;if(e!==0x2710)throw new Error('T-A-06:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+e+'\x20(merchant='+b+'\x20+\x20merchant_service_fee='+c+'\x20+\x20referrer='+d+')');assert_explicit_recipient('T-A-06','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-06','merchant_fee_treasury',a['merchant_fee_treasury'],c);const f=Number(a['passport_identifier']??0x0);if(f<0x0||f>0xff)throw new Error('T-A-06:\x20passport_identifier\x20MUST\x20be\x20u8\x20(0-255),\x20got\x20'+f);const g=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&g['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(c),'mode':'Rate'}),d>0x0&&g['push']({'who':{'GuardIdentifier':f},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Dynamic\x20recipient\x20(platform\x20commission\x200):\x20merchant\x20'+b+'/10000'+(c>0x0?',\x20merchant\x27s\x20own\x20service\x20fee\x20'+c+'/10000':'')+(d>0x0?',\x20referrer\x20'+d+'/10000\x20(from\x20Passport\x20identifier='+f+')':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':g,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['DEFAULT\x20PARAMETERS\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury;\x20to\x20exercise\x20the\x20GuardIdentifier\x20form\x20set\x20referrer_rate\x20>\x200\x20and\x20lower\x20merchant_rate\x20by\x20exactly\x20that\x20amount\x20(the\x20emitted\x20rows\x20must\x20still\x20total\x2010000)','F-A-13:\x20Passport\x20table[identifier]\x20MUST\x20be\x20address\x20type\x20(else\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS=1)','The\x20Guard\x20identifier\x20slot\x27s\x20address-type\x20check\x20MUST\x20pass\x20when\x20the\x20Allocator\x20is\x20added\x20(else\x20the\x20Allocator\x20add\x20fails)','Customer\x20must\x20submit\x20Passport\x20with\x20referrer\x20address\x20at\x20the\x20specified\x20identifier\x20slot','Guard\x20should\x20verify\x20Passport\x20completeness\x20before\x20alloc()\x20executes','The\x20GuardIdentifier\x20recipient\x20is\x20CHOSEN\x20BY\x20THE\x20BUYER\x20(the\x20submitted\x20address\x20bound\x20to\x20for_object),\x20so\x20the\x20Guard\x20—\x20not\x20the\x20template\x20—\x20is\x20what\x20makes\x20it\x20trustworthy:\x20bind\x20it\x20(e.g.\x20an\x20allow-listed\x20referrer)\x20before\x20enabling\x20a\x20non-zero\x20referrer_rate,\x20and\x20never\x20use\x20it\x20for\x20the\x20merchant\x27s\x20own\x20fee','merchant_service_fee_bps\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20fee,\x20default\x200,\x20and\x20requires\x20an\x20explicit\x20non-empty\x20recipient\x20—\x20there\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template']},{'id':'T-A-07','name':'Refund\x20to\x20the\x20submitted\x20Order\x20(100%\x20delivered\x20to\x20the\x20order\x20as\x20escrow)','description':'Single\x20Allocator,\x201\x20Rate=10000\x20sharing\x20whose\x20recipient\x20is\x20the\x20order\x20submitted\x20at\x20alloc\x20time\x20(Guard\x20table\x20identifier\x200).\x20The\x20funds\x20are\x20delivered\x20to\x20that\x20order\x20and\x20received\x20by\x20its\x20owner.','applicable_scenes':['allocation_refund_to_order'],'industry_tags':['refund','customer_protection','order_lifecycle'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20verifying\x20the\x20submitted\x20order\x20qualifies\x20(e.g.\x20order\x20at\x20the\x20refund\x20node,\x20order.service\x20==\x20host\x20service).\x20Its\x20table\x20needs\x20an\x20address-typed\x20b_submission\x20slot\x20at\x20identifier\x200.','required':!![]}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Refund\x20to\x20the\x20submitted\x20Order\x20(100%\x20delivered\x20to\x20the\x20order\x20as\x20escrow)','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'GuardIdentifier':0x0},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['The\x20Guard\x20table\x20MUST\x20have\x20an\x20address-typed\x20b_submission\x20slot\x20at\x20identifier\x200\x20carrying\x20the\x20submitted\x20order\x20(else\x20the\x20Allocator\x20add\x20fails\x20with\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS).','At\x20alloc\x20time\x20the\x20full\x20Rate\x20is\x20delivered\x20to\x20the\x20submitted\x20order\x20as\x20a\x20CoinWrapper\x20—\x20the\x20order\x20object\x20owns\x20it.\x20Its\x20owner\x20subsequently\x20receives\x20the\x20bare\x20coins\x20through\x20the\x20order\x27s\x20owner-receive\x20entry;\x20unrelated\x20addresses\x20cannot\x20intercept.','The\x20Guard\x20decides\x20which\x20submitted\x20orders\x20qualify:\x20node\x20state\x20plus\x20a\x20service-scope\x20binding\x20(order.service\x20==\x20host\x20service)\x20are\x20the\x20typical\x20conditions;\x20tightening\x20those\x20conditions\x20is\x20how\x20the\x20destination\x20is\x20controlled.','When\x20the\x20per-order\x20Allocation\x20is\x20created\x20through\x20the\x20Service\x20flow,\x20payment_info.for_object\x20is\x20set\x20to\x20the\x20order\x20the\x20allocation\x20belongs\x20to,\x20recording\x20the\x20business\x20context\x20auditors\x20can\x20query.','No\x20fee\x20leg\x20and\x20no\x20platform\x20leg:\x20a\x20refund\x20path\x20pays\x20the\x20order\x27s\x20owner\x20and\x20nothing\x20else.\x20A\x20declared\x20service\x20fee\x20belongs\x20on\x20the\x20purchase-side\x20allocation\x20(T-A-02)\x20as\x20an\x20explicit\x20Rate\x20leg\x20—\x20never\x20as\x20a\x20leg\x20here,\x20and\x20never\x20as\x20an\x20implicit\x20remainder\x20or\x20a\x20Surplus\x20drain']},{'id':'T-A-08','name':'Arbitration\x20fees\x20payout\x20(arbitrator\x20keeps\x20100%\x20by\x20default\x20/\x20optional\x20declared\x20operator\x20fee)','description':'Single\x20Allocator,\x20Rate\x20sharing\x20items\x20summing\x20to\x20exactly\x2010000.\x20Triggered\x20by\x20the\x20Arbitration\x20fees-distribution\x20operation\x20(permission\x20365),\x20with\x20or\x20without\x20a\x20Passport.\x20DIRECT-SALES\x20default:\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20fee\x20(single\x20Rate\x2010000\x20leg)\x20—\x20WoWok\x20takes\x20no\x20platform\x20commission.\x20An\x20optional\x20fee\x20for\x20the\x20arbitration\x20OPERATOR\x20(the\x20arbitrator\x27s\x20own\x20declared\x20service\x20price,\x20or\x20a\x20third\x20party\x20such\x20as\x20a\x20payments/escrow\x20provider)\x20is\x20allowed\x20only\x20under\x20the\x20L3\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20the\x20parties\x20can\x20compute\x20before\x20the\x20fee\x20is\x20charged,\x20never\x20an\x20implicit\x20remainder;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20visible\x20to\x20both\x20sides\x20beforehand\x20(blank\x20silently\x20routes\x20the\x20money\x20to\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91);\x20(3)\x20no\x20mandatory\x20transit\x20pool,\x20and\x20the\x20fee\x20is\x20NEVER\x20taken\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all,\x20so\x20it\x20doubles\x20as\x20draining\x20the\x20pool).','applicable_scenes':['allocation_arbitration_fees'],'industry_tags':['arbitration','dispute','fees'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(must\x20match\x20Arbitration\x20fee\x20Coin\x20type)','required':!![]},{'name':'arbitrator_treasury','type':'address','description':'Arbitrator\x20Treasury\x20address\x20—\x20default\x20sole\x2010000\x20recipient\x20of\x20the\x20dispute\x20fee','required':!![]},{'name':'arbitration_operator_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20arbitration_operator_fee_bps:\x20the\x20ARBITRATION\x20OPERATOR\x27s\x20own\x20fee\x20treasury\x20(the\x20arbitrator\x27s\x20declared\x20service\x20price)\x20or\x20a\x20genuine\x20third-party\x20treasury\x20(e.g.\x20an\x20escrow\x20/\x20payments\x20provider).\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20the\x20fee\x20is\x20>\x200\x20—\x20leaving\x20it\x20blank\x20or\x20omitting\x20it\x20is\x20NOT\x20a\x20no-op:\x20the\x20share\x20silently\x20goes\x20to\x20Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91).','required':![]},{'name':'arbitrator_rate','type':'number','description':'Arbitrator\x27s\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20dispute\x20fee\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'arbitration_operator_fee_bps','type':'number','description':'The\x20ARBITRATION\x20OPERATOR\x27s\x20(or\x20a\x20named\x20third\x20party\x27s)\x20own\x20fee\x20in\x20basis\x20points,\x20default\x200.\x20Explicit\x20number\x20both\x20sides\x20can\x20compute\x20before\x20the\x20fee\x20is\x20charged;\x20arbitrator_rate\x20+\x20arbitration_operator_fee_bps\x20MUST\x20sum\x20to\x2010000.\x20WoWok\x20extracts\x20nothing,\x20so\x20there\x20is\x20no\x20platform\x20share\x20here.','required':![],'default':0x0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20Arbitration\x20ruling\x20finalized)','required':!![]}],'body':a=>{const b=assert_declared_share('T-A-08','arbitrator_rate',a['arbitrator_rate'],0x2710),c=assert_declared_share('T-A-08','arbitration_operator_fee_bps',a['arbitration_operator_fee_bps'],0x0);assert_explicit_recipient('T-A-08','arbitrator_treasury',a['arbitrator_treasury'],b),assert_explicit_recipient('T-A-08','arbitration_operator_treasury',a['arbitration_operator_treasury'],c);const d=b+c;if(d!==0x2710)throw new Error('T-A-08:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+d+'\x20(arbitrator='+b+'\x20+\x20operator_fee='+c+')');const e=[{'who':{'Entity':a['arbitrator_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&e['push']({'who':{'Entity':a['arbitration_operator_treasury']},'sharing':String(c),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Arbitration\x20fees\x20(platform\x20commission\x200):\x20arbitrator\x20'+b+'/10000'+(c>0x0?',\x20arbitration\x20operator\x27s\x20own\x20fee\x20'+c+'/10000':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':e,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Triggered\x20by\x20the\x20Arbitration\x20fees-distribution\x20operation\x20(permission\x20ARBITRATION_FEES_ALLOC=365),\x20with\x20or\x20without\x20a\x20Passport','Independent\x20from\x20Service-order\x20Allocation\x20(this\x20Allocation\x20is\x20not\x20bound\x20to\x20Order)','payment_info\x20typically\x20reuses\x20Arbitration\x27s\x20payment_info','Caller\x20MUST\x20hold\x20ARBITRATION_FEES_ALLOC=365\x20permission','DIRECT-SALES\x20DEFAULT:\x20the\x20emitted\x20rows\x20are\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20arbitrator_treasury\x20—\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20dispute\x20fee,\x20and\x20the\x2010000\x20invariant\x20holds\x20by\x20construction','arbitration_operator_fee_bps\x20is\x20the\x20arbitration\x20OPERATOR\x27s\x20own\x20declared\x20fee\x20(or\x20a\x20named\x20third\x20party\x27s),\x20default\x200;\x20it\x20requires\x20an\x20explicit\x20non-empty\x20recipient\x20and\x20is\x20never\x20an\x20implicit\x20remainder\x20or\x20a\x20Surplus\x20drain.\x20There\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template']},{'id':'T-A-09','name':'Standalone\x20periodic\x20split\x20(investment\x20dividends\x20/\x20shared\x20income)','description':'Standalone\x20Allocation\x20with\x20single\x20Allocator,\x20N\x20Rate\x20sharing\x20items\x20to\x20beneficiary\x20wallets.\x20No\x20Service\x20context.\x20Guard\x20provides\x20time-based\x20or\x20signer-based\x20access\x20control.','applicable_scenes':['allocation_standalone_periodic_split'],'industry_tags':['standalone','investment','dividends','shared_income'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(e.g.\x20\x270x2::wow::WOW\x27\x20or\x20profit\x20token\x20type)','required':!![]},{'name':'beneficiaries','type':'address[]','description':'Array\x20of\x20beneficiary\x20wallet\x20addresses\x20(NOT\x20Treasury\x20objects\x20—\x20standalone\x20mode\x20has\x20no\x20Service\x20context)','required':!![]},{'name':'rates','type':'string[]','description':'Array\x20of\x20rates\x20in\x20basis\x20points\x20(e.g.\x20[\x275000\x27,\x273000\x27,\x272000\x27]\x20=\x2050%/30%/20%).\x20MUST\x20sum\x20to\x2010000.','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20—\x20MUST\x20bind\x20Signer\x20or\x20verify\x20time-based\x20trigger\x20(R-A-3-04:\x20standalone\x20has\x20no\x20Service-layer\x20access\x20control)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20periodic\x20split'}],'body':a=>{const b=a['beneficiaries'],c=a['rates']['map'](e=>Number(e));if(b['length']!==c['length'])throw new Error('T-A-09:\x20beneficiaries\x20('+b['length']+')\x20and\x20rates\x20('+c['length']+')\x20MUST\x20have\x20equal\x20length');if(b['length']===0x0)throw new Error('T-A-09:\x20at\x20least\x201\x20beneficiary\x20required');if(b['length']>0x64)throw new Error('T-A-09:\x20beneficiaries\x20count\x20'+b['length']+'\x20exceeds\x20MAX_SHARING_COUNT\x20(100)');const d=c['reduce']((e,f)=>e+f,0x0);if(d!==0x2710)throw new Error('T-A-09:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+d);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Standalone\x20periodic\x20split','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':b['map']((e,f)=>({'who':{'Entity':e},'sharing':String(c[f]),'mode':'Rate'})),'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode\x20(§0):\x20no\x20Service/Order/Arbitration\x20context\x20required','R-A-3-04:\x20Guard\x20MUST\x20bind\x20Signer\x20or\x20verify\x20time-based\x20trigger\x20—\x20no\x20Service-layer\x20access\x20control\x20exists','F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode,\x20no\x20Surplus)','Caller\x20lifecycle:\x20receive()\x20to\x20deposit\x20funds\x20→\x20alloc()\x20to\x20trigger\x20distribution','Guard\x20should\x20bind\x20context(Signer)==authorized\x20to\x20prevent\x20unauthorized\x20alloc()\x20calls','beneficiaries\x20are\x20personal\x20wallets,\x20NOT\x20Treasury\x20objects\x20(no\x20Service\x20context)','Every\x20rate\x20is\x20an\x20EXPLICIT\x20declared\x20share\x20to\x20an\x20EXPLICIT\x20non-empty\x20address:\x20nothing\x20here\x20is\x20an\x20implicit\x20platform\x20beneficiary\x20and\x20no\x20leg\x20is\x20left\x20unset\x20(blank\x20silently\x20binds\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91).\x20A\x20share\x20intended\x20for\x20a\x20third\x20party\x20is\x20the\x20payer\x27s\x20own\x20declared\x20price\x20and\x20must\x20be\x20named\x20on\x20both\x20sides']},{'id':'T-A-10','name':'Standalone\x20vesting\x20release\x20(time-locked\x20multi-stage\x20unlock)','description':'Standalone\x20Allocation\x20with\x20N\x20Allocators\x20(default\x203\x20stages),\x20each\x20triggered\x20by\x20a\x20time-locked\x20Guard.\x20Stages\x201..N-1\x20use\x20Amount\x20mode;\x20final\x20stage\x20uses\x20Surplus\x20to\x20drain\x20remaining\x20balance.\x20No\x20Service\x20context.','applicable_scenes':['allocation_standalone_vesting'],'industry_tags':['standalone','vesting','time_lock','team_tokens'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(vested\x20asset,\x20e.g.\x20locked\x20team\x20tokens)','required':!![]},{'name':'beneficiary_address','type':'address','description':'Single\x20beneficiary\x20wallet\x20address\x20(vesting\x20recipient)','required':!![]},{'name':'stage_1_guard','type':'address','description':'Guard\x20for\x20stage\x201\x20(verifies\x20context(Clock).timestamp\x20>=\x20stage_1_unlock)','required':!![]},{'name':'stage_1_amount','type':'number','description':'Amount\x20to\x20release\x20at\x20stage\x201\x20(smallest\x20coin\x20unit,\x20e.g.\x20MIST)','required':!![]},{'name':'stage_2_guard','type':'address','description':'Guard\x20for\x20stage\x202\x20(verifies\x20context(Clock).timestamp\x20>=\x20stage_2_unlock)\x20—\x20MUST\x20differ\x20from\x20stage_1_guard','required':!![]},{'name':'stage_2_amount','type':'number','description':'Amount\x20to\x20release\x20at\x20stage\x202\x20(smallest\x20coin\x20unit)','required':!![]},{'name':'stage_3_guard','type':'address','description':'Guard\x20for\x20stage\x203\x20(final\x20stage,\x20uses\x20Surplus\x20to\x20drain\x20remaining\x20balance)\x20—\x20MUST\x20differ\x20from\x20stage_1_guard\x20and\x20stage_2_guard','required':!![]},{'name':'max_cap','type':'number','description':'Maximum\x20cumulative\x20release\x20cap\x20(applied\x20to\x20stages\x201\x20and\x202\x20via\x20max\x20field).\x20Stage\x203\x20uses\x20Surplus\x20so\x20no\x20max\x20needed.','required':![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20vesting\x20release\x20(3-stage\x20time-locked)'}],'body':a=>{const b=[a['stage_1_guard'],a['stage_2_guard'],a['stage_3_guard']],c=new Set(b);if(c['size']!==b['length']){const h=b['filter']((j,k)=>b['indexOf'](j)!==k);throw new Error('T-A-10:\x20stage\x20guards\x20MUST\x20be\x20unique\x20(F-A-14),\x20duplicates:\x20'+h['join'](',\x20'));}const d=Number(a['stage_1_amount']),e=Number(a['stage_2_amount']);if(d<=0x0||e<=0x0)throw new Error('T-A-10:\x20stage_1_amount\x20and\x20stage_2_amount\x20MUST\x20be\x20>\x200,\x20got\x20stage1='+d+',\x20stage2='+e);const f=d+e,g=a['max_cap']!=null?Number(a['max_cap']):null;if(g!==null&&f>g)throw new Error('T-A-10:\x20stage_1_amount\x20+\x20stage_2_amount\x20('+f+')\x20MUST\x20be\x20<=\x20max_cap\x20('+g+')\x20—\x20F-A-08\x20(EAMOUNT_EXCEEDS_MAX)');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Standalone\x20vesting\x20release\x20(3-stage\x20time-locked)','threshold':'0','allocators':[{'guard':a['stage_1_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':String(d),'mode':'Amount'}],'max':g!=null?String(g):null},{'guard':a['stage_2_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':String(e),'mode':'Amount'}],'max':g!=null?String(g):null},{'guard':a['stage_3_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':'0','mode':'Surplus'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode\x20(§0):\x20no\x20Service/Order/Arbitration\x20context\x20required','R-A-3-04:\x20Guard\x20time-lock\x20MUST\x20be\x20enforced\x20—\x20no\x20Service-layer\x20access\x20control\x20exists','F-A-14:\x20stage_1_guard,\x20stage_2_guard,\x20stage_3_guard\x20MUST\x20be\x20unique\x20(duplicate\x20guards\x20are\x20dead\x20code)','F-A-04:\x20at\x20most\x201\x20Surplus\x20per\x20Allocator\x20(stage\x203\x20uses\x20Surplus\x20to\x20drain\x20remainder)','F-A-08:\x20stage_1_amount\x20+\x20stage_2_amount\x20MUST\x20be\x20<=\x20max_cap\x20(if\x20max_cap\x20provided)','R-A-4-01:\x20if\x20caller\x20calls\x20alloc()\x20before\x20stage\x20time-lock\x20expires,\x20alloc()\x20silently\x20returns\x20—\x20caller\x20should\x20check\x20balance==0\x20after\x20alloc()','R-A-4-02:\x20Guard\x20conditions\x20SHOULD\x20be\x20mutually\x20exclusive\x20by\x20timestamp\x20(e.g.\x20stage_1:\x20ts<stage_2_unlock,\x20stage_2:\x20stage_2_unlock<=ts<stage_3_unlock,\x20stage_3:\x20ts>=stage_3_unlock)','Caller\x20lifecycle:\x20receive()\x20to\x20deposit\x20locked\x20tokens\x20→\x20alloc()\x20at\x20each\x20vesting\x20milestone','Single\x20beneficiary\x20—\x20no\x20platform\x20leg.\x20The\x20stage-3\x20Surplus\x20is\x20this\x20contract\x27s\x20own\x20vesting\x20remainder,\x20NOT\x20a\x20fee:\x20Surplus\x20calls\x20balance::withdraw_all,\x20so\x20never\x20express\x20a\x20declared\x20fee\x20through\x20a\x20Surplus\x20leg\x20(L3\x20constraint\x203)']},{'id':'T-A-11','name':'Standalone\x20payroll\x20/\x20salary\x20distribution\x20(issuer\x20+\x20Repository\x20verified)','description':'Standalone\x20Allocation\x20for\x20periodic\x20payroll:\x20employees\x20receive\x20Rate\x20shares.\x20The\x20Guard\x20binds\x20the\x20issuer\x20Signer\x20identity\x20and\x20cross-checks\x20a\x20Repository\x20payroll\x20record\x20(period\x20and\x20amounts).\x20No\x20Service\x20context.','applicable_scenes':['allocation_standalone_payroll'],'industry_tags':['standalone','payroll','salary','compensation','hr'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20used\x20for\x20payroll\x20(e.g.\x20\x270x2::wow::WOW\x27)','required':!![]},{'name':'employees','type':'address[]','description':'Employee\x20wallet\x20addresses\x20(Recipient::Entity\x20recipients)','required':!![]},{'name':'rates','type':'string[]','description':'Per-employee\x20rates\x20in\x20basis\x20points\x20(e.g.\x20[\x276000\x27,\x274000\x27]).\x20MUST\x20sum\x20to\x2010000.','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20that\x20binds\x20Signer\x20==\x20issuer\x20AND\x20cross-checks\x20the\x20Repository\x20payroll\x20record\x20(both\x20required)','required':!![]},{'name':'payroll_period','type':'string','description':'Human-readable\x20period\x20label\x20(e.g.\x20\x272025-W26\x27)\x20—\x20recorded\x20in\x20the\x20Allocation\x20description\x20for\x20audit','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20payroll\x20distribution'}],'body':a=>{const b=a['employees'],c=a['rates']['map'](e=>Number(e));if(b['length']!==c['length'])throw new Error('T-A-11:\x20employees\x20('+b['length']+')\x20and\x20rates\x20('+c['length']+')\x20MUST\x20have\x20equal\x20length');if(b['length']===0x0)throw new Error('T-A-11:\x20at\x20least\x201\x20employee\x20required');if(b['length']>0x64)throw new Error('T-A-11:\x20employees\x20count\x20'+b['length']+'\x20exceeds\x20MAX_SHARING_COUNT\x20(100)');const d=c['reduce']((e,f)=>e+f,0x0);if(d!==0x2710)throw new Error('T-A-11:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+d);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':(a['description']??'Standalone\x20payroll\x20distribution')+'\x20—\x20period:\x20'+a['payroll_period'],'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':b['map']((e,f)=>({'who':{'Entity':e},'sharing':String(c[f]),'mode':'Rate'})),'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode:\x20no\x20Service/Order/Arbitration\x20context\x20required','RC-FIND-04:\x20the\x20Guard\x20MUST\x20bind\x20the\x20issuer\x20identity\x20(Signer\x20==\x20employer/admin,\x20or\x20a\x20Permission\x20member)\x20—\x20standalone\x20has\x20no\x20Service\x20access-control\x20layer','Repository\x20distinction:\x20the\x20Guard\x20MUST\x20cross-check\x20the\x20Repository\x20payroll\x20record\x20(period\x20hash,\x20amounts\x20and\x20recipients)\x20so\x20the\x20distribution\x20is\x20tied\x20to\x20auditable\x20work/payroll\x20data','Auditability:\x20the\x20Guard\x20rules\x20are\x20public\x20—\x20third\x20parties\x20verify\x20who\x20may\x20distribute\x20and\x20what\x20inputs\x20distinguish\x20a\x20valid\x20payroll','F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode)','Caller\x20lifecycle:\x20issuer\x20receive()\x20to\x20fund\x20payroll\x20→\x20alloc()\x20after\x20the\x20Repository\x20record\x20for\x20the\x20period\x20is\x20committed','Employees\x20are\x20personal\x20wallets\x20(Recipient::Entity),\x20never\x20Recipient::Signer','The\x20issuer/employer\x20is\x20the\x20payer\x20and\x20keeps\x20the\x20whole\x20payroll\x20pool\x20by\x20default:\x20there\x20is\x20no\x20platform\x20share\x20in\x20this\x20template.\x20Every\x20rate\x20is\x20an\x20explicit\x20per-employee\x20price\x20to\x20an\x20explicit\x20non-empty\x20address\x20(blank\x20silently\x20binds\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20and\x20sum(rates)\x20MUST\x20stay\x2010000\x20so\x20no\x20residual\x20stays\x20claimable']}];export const ALLOCATION_TEMPLATES_VERSION='1.1.0';export function getAllTemplates(){return[...ALLOCATION_TEMPLATES];}export function getTemplateById(a){return ALLOCATION_TEMPLATES['find'](b=>b['id']===a);}export function getTemplatesByScene(a){return ALLOCATION_TEMPLATES['filter'](b=>b['applicable_scenes']['includes'](a));}export function getTemplatesByIndustry(a){return ALLOCATION_TEMPLATES['filter'](b=>b['industry_tags']['includes'](a)||b['industry_tags']['includes']('universal'));}export function suggestTemplateForScene(a){const b=getTemplatesByScene(a);return b['length']>0x0?b[0x0]:undefined;}export function listTemplates(){return ALLOCATION_TEMPLATES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'scenes':a['applicable_scenes']}));}export function fillTemplate(a,b){const c=getTemplateById(a);if(!c)return{'ok':![],'error':'Template\x20'+a+'\x20not\x20found'};for(const d of c['params']){if(d['required']&&!(d['name']in b))return{'ok':![],'error':'Missing\x20required\x20param:\x20'+d['name']};}try{return{'ok':!![],'body':c['body'](b)};}catch(f){return{'ok':![],'error':f instanceof Error?f['message']:String(f)};}}
1
+ function assert_declared_share(a,b,c,d){const e=c===undefined||c===null||c===''?d:c,f=Number(e);if(!Number['isInteger'](f))throw new Error('E-RATE-EXPLICIT:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20an\x20explicit\x20integer\x20number\x20of\x20basis\x20points\x20'+('(the\x20buyer\x20must\x20be\x20able\x20to\x20compute\x20it\x20pre-order;\x20never\x20an\x20implicit\x20remainder),\x20got\x20'+String(c)));if(f<0x0||f>0x2710)throw new Error('E-RATE-RANGE:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20within\x20[0,\x2010000],\x20got\x20'+f);return f;}function assert_explicit_recipient(a,b,c,d){if(d<=0x0)return;const e=typeof c==='string'?c['trim']():'';if(e['length']===0x0)throw new Error('E-RECIPIENT-UNDEFINED:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20a\x20non-empty\x20explicit\x20recipient\x20'+('because\x20its\x20rate\x20is\x20'+d+'\x20>\x200.\x20A\x20blank/omitted\x20recipient\x20silently\x20falls\x20back\x20to\x20')+'the\x20deploying\x20account,\x20'+'so\x20the\x20outflow\x20would\x20go\x20to\x20whoever\x20ran\x20the\x20deploy.');if(e['toLowerCase']()['startsWith']('0x')){const f=e['slice'](0x2);if(f['length']===0x0||!/^[0-9a-f]+$/['test'](f)||/^0+$/['test'](f))throw new Error('E-RECIPIENT-UNDEFINED:\x20'+a+':\x20'+b+'\x20looks\x20like\x20an\x20address\x20but\x20carries\x20no\x20'+('identity\x20(\x22'+e+'\x22).\x20Point\x20it\x20at\x20the\x20declared\x20recipient\x20Entity\x20(a\x20Treasury/Entity\x20address\x20the\x20')+'buyer\x20can\x20see\x20pre-order).');}}export const ALLOCATION_TEMPLATES=[{'id':'T-A-01','name':'Single\x20Rate\x20100%\x20to\x20Treasury','description':'Simplest\x20allocation\x20—\x20single\x20Allocator,\x20single\x20Rate=10000\x20sharing\x20to\x20one\x20Treasury/personal\x20address','applicable_scenes':['allocation_merchant_full_payment'],'industry_tags':['universal','retail','service'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(e.g.\x20\x270x2::wow::WOW\x27)','required':!![]},{'name':'recipient_address','type':'address','description':'Treasury\x20or\x20personal\x20wallet\x20address\x20to\x20receive\x20100%','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Single\x20Rate\x20100%\x20allocation'}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Single\x20Rate\x20100%\x20allocation','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['recipient_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['Simplest\x20configuration\x20—\x20no\x20multi-party\x20coordination','Guard\x20only\x20needs\x20to\x20verify\x20order\x20status,\x20no\x20complex\x20conditions','Suitable\x20for\x20solo\x20merchants\x20or\x20single-treasury\x20services','DIRECT-SALES\x20DEFAULT\x20SHAPE\x20(L2):\x20this\x20IS\x20the\x20default\x20payout\x20form\x20—\x20one\x20Rate\x2010000\x20leg\x20to\x20the\x20merchant\x27s\x20own\x20Entity.\x20No\x20platform\x20leg\x20exists,\x20and\x20nothing\x20is\x20left\x20over','If\x20the\x20merchant\x20declares\x20its\x20OWN\x20fee,\x20use\x20T-A-02\x20(an\x20explicit\x20fee\x20leg\x20to\x20an\x20explicit\x20non-empty\x20recipient)\x20instead\x20of\x20shrinking\x20this\x20leg\x20and\x20routing\x20the\x20difference\x20through\x20an\x20implicit\x20remainder\x20(L3)','A\x20BLANK\x20recipient_address\x20is\x20NOT\x20a\x20no-op:\x20it\x20resolves\x20to\x20the\x20deploying\x20account\x20—\x20so\x20this\x20template\x20pays\x20whoever\x20ran\x20the\x20deploy']},{'id':'T-A-02','name':'Merchant\x20payout\x20+\x20optional\x20declared\x20fee\x20/\x20third-party\x20leg\x20(merchant\x20keeps\x20100%\x20by\x20default)','description':'DIRECT-SALES\x20split:\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20by\x20default\x20(one\x20Rate\x2010000\x20leg\x20to\x20its\x20own\x20Entity).\x20Optional\x20extra\x20legs\x20are\x20(a)\x20the\x20merchant\x27s\x20OWN\x20service\x20fee\x20—\x20only\x20when\x20the\x20merchant\x20IS\x20the\x20aggregator\x20—\x20and\x20(b)\x20a\x20genuine\x20third-party\x20payment\x20(logistics\x20provider,\x20arbitrator,\x20partner),\x20which\x20is\x20a\x20payment\x20for\x20a\x20service,\x20not\x20platform\x20extraction.\x20Pure\x20Rate\x20mode:\x20the\x20emitted\x20sharing\x20rows\x20MUST\x20sum\x20to\x20exactly\x2010000,\x20and\x20with\x20the\x20default\x20parameters\x20they\x20are\x20a\x20single\x2010000\x20row.\x20L3\x20fee\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20the\x20buyer\x20can\x20compute\x20BEFORE\x20ordering,\x20never\x20an\x20implicit\x20remainder\x20such\x20as\x20\x27order\x20total\x20-\x20segment\x20sums\x27;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20the\x20buyer\x20can\x20see\x20pre-order\x20(a\x20blank\x20recipient\x20is\x20NOT\x20a\x20no-op\x20—\x20it\x20falls\x20back\x20to\x20the\x20deploying\x20account);\x20(3)\x20no\x20mandatory\x20transit\x20pool\x20on\x20the\x20payout\x20path,\x20and\x20the\x20fee\x20is\x20NEVER\x20taken\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all,\x20so\x20it\x20doubles\x20as\x20draining\x20the\x20pool).\x20WoWok\x20itself\x20takes\x20nothing.','applicable_scenes':['allocation_standard_three_way_split'],'industry_tags':['retail','ecommerce','logistics'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Entity\x20that\x20receives\x20its\x20own\x20sale\x20proceeds\x20—\x20the\x20direct-sales\x20destination.\x20Required\x20and\x20never\x20blank\x20(blank\x20silently\x20routes\x20the\x20payout\x20to\x20the\x20deploying\x20account).','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20merchant_service_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20merchant_service_fee_bps\x20>\x200\x20—\x20leaving\x20it\x20blank\x20or\x20omitting\x20it\x20is\x20NOT\x20a\x20no-op:\x20the\x20share\x20silently\x20goes\x20to\x20the\x20deploying\x20account.\x20Pass\x20merchant_treasury\x20if\x20the\x20merchant\x20charges\x20itself.','required':![]},{'name':'third_party_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20third_party_rate\x20(e.g.\x20the\x20logistics\x20provider\x27s\x20own\x20Treasury).\x20MUST\x20be\x20explicit\x20and\x20non-empty\x20whenever\x20third_party_rate\x20>\x200\x20—\x20same\x20blank-fallback\x20hazard\x20as\x20merchant_fee_treasury.','required':![]},{'name':'merchant_rate','type':'number','description':'Merchant\x27s\x20own\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'merchant_service_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20in\x20basis\x20points.\x20KEEP\x20AT\x200\x20unless\x20the\x20merchant\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium\x20/\x20an\x20OTA\x20that\x20really\x20is\x20the\x20seller\x27s\x20counterparty).\x20WoWok\x20extracts\x20nothing\x20—\x20this\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20price,\x20never\x20a\x20platform\x20share.\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20before\x20ordering;\x20merchant_rate\x20+\x20merchant_service_fee_bps\x20+\x20third_party_rate\x20MUST\x20sum\x20to\x2010000.','required':![],'default':0x0},{'name':'third_party_rate','type':'number','description':'Rate\x20for\x20a\x20genuine\x20third-party\x20payment\x20(logistics\x20provider\x20/\x20arbitrator\x20/\x20supply-chain\x20partner),\x20default\x200.\x20Kept\x20expressible\x20on\x20purpose\x20—\x20a\x20real\x20provider\x20fee\x20is\x20a\x20payment\x20FOR\x20a\x20service\x20—\x20but\x20it\x20must\x20be\x20an\x20explicit\x20number\x20with\x20an\x20explicit\x20recipient,\x20exactly\x20like\x20the\x20merchant\x20fee.','required':![],'default':0x0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion\x20+\x20service\x20binding)','required':!![]}],'body':a=>{const b=assert_declared_share('T-A-02','merchant_rate',a['merchant_rate'],0x2710),c=assert_declared_share('T-A-02','merchant_service_fee_bps',a['merchant_service_fee_bps'],0x0),d=assert_declared_share('T-A-02','third_party_rate',a['third_party_rate'],0x0);assert_explicit_recipient('T-A-02','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-02','merchant_fee_treasury',a['merchant_fee_treasury'],c),assert_explicit_recipient('T-A-02','third_party_treasury',a['third_party_treasury'],d);const e=b+c+d;if(e!==0x2710)throw new Error('T-A-02:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+e+'\x20'+('(merchant='+b+'\x20+\x20merchant_service_fee='+c+'\x20+\x20third_party='+d+')'));const f=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&f['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(c),'mode':'Rate'}),d>0x0&&f['push']({'who':{'Entity':a['third_party_treasury']},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Direct-sales\x20payout\x20(platform\x20commission\x200):\x20merchant\x20'+b+'/10000'+(c>0x0?',\x20merchant\x27s\x20own\x20service\x20fee\x20'+c+'/10000':'')+(d>0x0?',\x20third\x20party\x20(e.g.\x20logistics)\x20'+d+'/10000':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':f,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode,\x20no\x20Surplus)\x20—\x20a\x20Rate\x20sum\x20<\x2010000\x20with\x20no\x20Surplus\x20recipient\x20leaves\x20residual\x20balance\x20that\x20ANYONE\x20passing\x20the\x20same\x20Guard\x20can\x20claim\x20repeatedly\x20(E-2\x20/\x20finding\x20T-04)','DEFAULT\x20PARAMETERS\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury:\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20and\x20the\x2010000\x20invariant\x20holds\x20by\x20construction','merchant_service_fee_bps\x20is\x20the\x20MERCHANT\x27s\x20own\x20fee\x20(merchant\x20IS\x20the\x20aggregator),\x20default\x200\x20—\x20WoWok\x20takes\x20no\x20platform\x20commission\x20and\x20there\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template','third_party_rate\x20is\x20a\x20real\x20provider\x20payment\x20(logistics\x20/\x20arbitrator\x20/\x20partner),\x20not\x20platform\x20extraction;\x20keep\x20it\x20expressible,\x20but\x20name\x20the\x20payee\x20explicitly','Never\x20express\x20a\x20fee\x20as\x20an\x20implicit\x20remainder\x20(\x27the\x20merchant\x20keeps\x20whatever\x20is\x20left\x27)\x20and\x20never\x20take\x20one\x20via\x20a\x20Surplus\x20leg\x20(an\x20uncapped\x20Surplus\x20sweeps\x20the\x20entire\x20remaining\x20pool)','Treasury\x20Permission\x20should\x20match\x20Service\x20Permission\x20(R-A-3-02)','Guard\x20should\x20verify\x20order.service\x20binding\x20(query\x201563)\x20to\x20prevent\x20cross-project\x20bypass']},{'id':'T-A-03','name':'Refund-first\x20+\x20Surplus-to-merchant\x20(Amount\x20+\x20Surplus\x20hybrid)','description':'Single\x20Allocator\x20with\x202\x20sharing\x20items:\x20Amount=refund_value\x20to\x20customer,\x20Surplus\x20to\x20merchant.\x20No\x20fee\x20and\x20no\x20platform\x20leg:\x20the\x20Surplus\x20is\x20the\x20merchant\x27s\x20residual\x20of\x20a\x20mixed\x20refund/delivery\x20pool,\x20NOT\x20a\x20fee\x20mechanism','applicable_scenes':['allocation_refund_first_surplus_to_merchant'],'industry_tags':['retail','refund','customer_protection'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'customer_address','type':'address','description':'Customer\x20address\x20to\x20receive\x20refund\x20Amount','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20to\x20receive\x20Surplus','required':!![]},{'name':'refund_amount','type':'number','description':'Refund\x20amount\x20in\x20smallest\x20coin\x20unit\x20(e.g.\x20MIST\x20for\x20WOW)','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20refund\x20approval)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Refund-first\x20+\x20Surplus-to-merchant'}],'body':a=>{const b=Number(a['refund_amount']);if(b<=0x0)throw new Error('T-A-03:\x20refund_amount\x20MUST\x20be\x20>\x200,\x20got\x20'+b);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Refund-first\x20+\x20Surplus-to-merchant','threshold':String(b),'allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['customer_address']},'sharing':String(b),'mode':'Amount'},{'who':{'Entity':a['merchant_treasury']},'sharing':'0','mode':'Surplus'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-04:\x20at\x20most\x201\x20Surplus\x20per\x20Allocator\x20(✓\x20single\x20Surplus\x20here)','F-A-07:\x20threshold\x20=\x20refundAmount\x20(ensure\x20balance\x20covers\x20Amount)','the\x20fix\x20is\x20cached\x20as\x20refundAmount\x20when\x20the\x20Allocator\x20is\x20added','Guard\x20must\x20verify\x20customer\x20refund\x20eligibility\x20(e.g.\x20order\x20status\x20=\x20Refunded)','SURPLUS\x20IS\x20NOT\x20A\x20FEE:\x20an\x20uncapped\x20Surplus\x20sweeps\x20the\x20entire\x20remaining\x20pool\x20(a\x20max-capped\x20one\x20tops\x20the\x20payout\x20up\x20to\x20the\x20cap),\x20so\x20a\x20fee\x20taken\x20that\x20way\x20doubles\x20as\x20draining\x20the\x20pool\x20(L3\x20constraint\x203).\x20A\x20declared\x20service\x20fee\x20belongs\x20on\x20the\x20purchase-side\x20allocation\x20(T-A-02)\x20as\x20an\x20explicit\x20Rate\x20leg,\x20never\x20here','The\x20Surplus\x20recipient\x20is\x20the\x20merchant\x20(the\x20counterparty\x20of\x20the\x20delivered\x20part),\x20not\x20an\x20unnamed\x20third\x20party\x20—\x20but\x20pin\x20refund_amount\x20to\x20the\x20refund\x20actually\x20owed,\x20or\x20a\x20smaller/empty\x20refund\x20lets\x20the\x20Surplus\x20leg\x20absorb\x20money\x20that\x20is\x20not\x20the\x20merchant\x27s']},{'id':'T-A-04','name':'Treasury\x20+\x20Personal\x20alternative\x20(caller-specified\x20guard,\x202\x20Allocators)','description':'2\x20Allocators\x20as\x20alternative\x20strategies:\x20caller\x20selects\x20Treasury\x20or\x20Personal\x20wallet\x20via\x20alloc_by_guard\x20(hard\x20verification\x20per\x20call)','applicable_scenes':['allocation_treasury_personal_alternatives'],'industry_tags':['universal','alternative','treasury'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'treasury_address','type':'address','description':'Treasury\x20address\x20(primary\x20recipient)','required':!![]},{'name':'personal_address','type':'address','description':'Personal\x20wallet\x20address\x20(alternative\x20recipient)','required':!![]},{'name':'treasury_guard','type':'address','description':'Guard\x20for\x20Treasury\x20path\x20(verifies\x20treasury\x20operational)','required':!![]},{'name':'personal_guard','type':'address','description':'Guard\x20for\x20Personal\x20path\x20(verifies\x20personal\x20wallet\x20active)\x20—\x20MUST\x20differ\x20from\x20treasury_guard','required':!![]}],'body':a=>{if(a['treasury_guard']===a['personal_guard'])throw new Error('T-A-04:\x20treasury_guard\x20and\x20personal_guard\x20MUST\x20be\x20different\x20addresses\x20(F-A-14:\x20allocators[].guard\x20must\x20be\x20unique)');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Treasury\x20/\x20Personal\x20alternative\x20(caller-specified\x20guard)','threshold':'0','allocators':[{'guard':a['treasury_guard'],'sharing':[{'who':{'Entity':a['treasury_address']},'sharing':'10000','mode':'Rate'}],'max':null},{'guard':a['personal_guard'],'sharing':[{'who':{'Entity':a['personal_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-14:\x20treasury_guard\x20!=\x20personal_guard\x20(Allocator\x20Guards\x20must\x20be\x20unique)','caller-specified\x20guard:\x20alloc_by_guard\x20explicitly\x20selects\x20an\x20Allocator;\x20the\x20Passport\x27s\x20guard\x20result\x20is\x20hard-verified\x20(failure\x20aborts\x20E_VERIFY_FAILED)','No\x20auto-fallback:\x20on\x20verification\x20failure\x20the\x20caller\x20must\x20switch\x20guard\x20and\x20retry','R-A-4-02:\x20if\x20the\x20caller\x27s\x20submitted\x20Passport\x20satisfies\x20both\x20Guards\x20simultaneously,\x20the\x20caller\x20may\x20freely\x20choose\x20between\x20the\x20two\x20paths\x20(mutual\x20exclusion\x20is\x20a\x20design\x20clarity\x20recommendation,\x20not\x20a\x20correctness\x20requirement)','Each\x20Allocator\x20sums\x20to\x2010000\x20INDEPENDENTLY\x20—\x20the\x20Rate-total\x20invariant\x20is\x20per\x20Allocator,\x20not\x20across\x20Allocators,\x20and\x20each\x20of\x20the\x20two\x20paths\x20pays\x20ONE\x20recipient\x20the\x20full\x20amount\x20(no\x20split,\x20no\x20platform\x20leg,\x20no\x20residual)']},{'id':'T-A-05','name':'Tiered\x20by\x20order\x20amount\x20(mutually\x20exclusive\x20Guard\x20conditions)','description':'2\x20Allocators\x20triggered\x20by\x20mutually\x20exclusive\x20Guard\x20conditions\x20(small\x20order\x20vs\x20large\x20order).\x20DIRECT-SALES\x20default:\x20BOTH\x20tiers\x20pay\x20the\x20merchant\x20100%\x20—\x20the\x20tier\x20selects\x20the\x20guard,\x20not\x20a\x20cut.\x20The\x20large\x20tier\x20may\x20add\x20the\x20merchant\x27s\x20OWN\x20declared\x20fee,\x20under\x20the\x20L3\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20computable\x20before\x20ordering,\x20never\x20an\x20implicit\x20remainder;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20(blank\x20silently\x20routes\x20it\x20to\x20the\x20deploying\x20account);\x20(3)\x20no\x20mandatory\x20transit\x20pool,\x20and\x20never\x20a\x20Surplus\x20fee\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all).\x20No\x20platform\x20leg\x20exists\x20in\x20this\x20template.','applicable_scenes':['allocation_tiered_by_order_amount'],'industry_tags':['retail','tiered_pricing','volume_discount'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20(receives\x20the\x20full\x20sale\x20on\x20both\x20tiers\x20by\x20default)','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20large_order_merchant_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20that\x20fee\x20is\x20>\x200\x20—\x20blank\x20or\x20omitted\x20silently\x20pays\x20the\x20deploying\x20account,\x20not\x20a\x20no-op.','required':![]},{'name':'small_order_guard','type':'address','description':'Guard\x20verifying\x20order.amount\x20<\x20threshold\x20(small\x20order\x20path)','required':!![]},{'name':'large_order_guard','type':'address','description':'Guard\x20verifying\x20order.amount\x20>=\x20threshold\x20(large\x20order\x20path)\x20—\x20MUST\x20differ\x20from\x20small_order_guard','required':!![]},{'name':'small_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20on\x20the\x20small-order\x20tier.\x20Default\x20(and\x20only)\x20value\x2010000\x20—\x20direct\x20sales:\x20no\x20platform\x20take.','required':![],'default':0x2710},{'name':'large_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20on\x20the\x20large-order\x20tier.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(there\x20is\x20no\x20platform\x20take\x20to\x20deduct).','required':![],'default':0x2710},{'name':'large_order_merchant_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20on\x20the\x20large-order\x20tier,\x20in\x20basis\x20points.\x20KEEP\x20AT\x200\x20unless\x20the\x20merchant\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium).\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20pre-order;\x20large_order_merchant_rate\x20+\x20large_order_merchant_fee_bps\x20MUST\x20sum\x20to\x2010000.\x20WoWok\x20takes\x20no\x20platform\x20commission.','required':![],'default':0x0}],'body':a=>{if(a['small_order_guard']===a['large_order_guard'])throw new Error('T-A-05:\x20small_order_guard\x20and\x20large_order_guard\x20MUST\x20be\x20different\x20addresses\x20(F-A-14)');const b=assert_declared_share('T-A-05','small_order_merchant_rate',a['small_order_merchant_rate'],0x2710);if(b!==0x2710)throw new Error('T-A-05:\x20small_order_merchant_rate\x20MUST\x20equal\x2010000\x20(pure\x20Rate,\x20no\x20Surplus\x20in\x20this\x20Allocator),\x20got\x20'+b);const c=assert_declared_share('T-A-05','large_order_merchant_rate',a['large_order_merchant_rate'],0x2710),d=assert_declared_share('T-A-05','large_order_merchant_fee_bps',a['large_order_merchant_fee_bps'],0x0);assert_explicit_recipient('T-A-05','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-05','merchant_fee_treasury',a['merchant_fee_treasury'],d);const e=c+d;if(e!==0x2710)throw new Error('T-A-05:\x20large_order\x20rates\x20MUST\x20sum\x20to\x2010000,\x20got\x20'+e+'\x20(merchant='+c+'\x20+\x20merchant_fee='+d+')');const f=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(c),'mode':'Rate'}];return d>0x0&&f['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Tiered\x20by\x20order\x20amount\x20(platform\x20commission\x200):\x20small=100%\x20merchant,\x20'+('large='+c+'/10000\x20merchant')+(d>0x0?'\x20+\x20'+d+'/10000\x20merchant\x27s\x20own\x20service\x20fee':''),'threshold':'0','allocators':[{'guard':a['small_order_guard'],'sharing':[{'who':{'Entity':a['merchant_treasury']},'sharing':'10000','mode':'Rate'}],'max':null},{'guard':a['large_order_guard'],'sharing':f,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Guard\x20conditions\x20MUST\x20be\x20mutually\x20exclusive\x20(R-A-4-02)','Sequence-sensitive:\x20strict\x20condition\x20(small\x20order)\x20first,\x20relaxed\x20condition\x20(large\x20order)\x20last','Guard\x20queries\x20order.amount\x20(query\x201561)\x20to\x20determine\x20which\x20Allocator\x20fires','If\x20neither\x20Guard\x20passes,\x20funds\x20are\x20silently\x20locked\x20(R-A-4-02)','DIRECT-SALES\x20DEFAULT:\x20both\x20tiers\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury\x20—\x20the\x20tier\x20picks\x20the\x20guard,\x20not\x20a\x20cut.\x20Each\x20Allocator\x20sums\x20to\x2010000\x20on\x20its\x20own','large_order_merchant_fee_bps\x20is\x20the\x20merchant\x27s\x20OWN\x20large-tier\x20fee\x20(default\x200),\x20only\x20for\x20a\x20merchant\x20that\x20IS\x20the\x20aggregator;\x20it\x20is\x20never\x20a\x20platform\x20take,\x20never\x20an\x20implicit\x20remainder,\x20and\x20its\x20recipient\x20must\x20be\x20explicit\x20and\x20non-empty']},{'id':'T-A-06','name':'Dynamic\x20recipient\x20via\x20GuardIdentifier\x20(referrer\x20from\x20Passport)','description':'Single\x20Allocator\x20whose\x20Rate\x20sharing\x20items\x20include\x20one\x20recipient\x20resolved\x20from\x20the\x20customer\x27s\x20Passport\x20table[identifier].\x20DIRECT-SALES\x20default:\x20merchant_rate\x2010000\x20and\x20every\x20optional\x20leg\x200,\x20so\x20the\x20emitted\x20template\x20is\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20the\x20merchant.\x20Two\x20optional\x20legs\x20may\x20be\x20switched\x20on,\x20each\x20under\x20the\x20L3\x20rule\x20(explicit\x20number\x20computable\x20pre-order;\x20explicit\x20non-empty\x20recipient\x20—\x20blank\x20silently\x20pays\x20the\x20deploying\x20account;\x20no\x20mandatory\x20transit\x20pool,\x20never\x20a\x20Surplus\x20fee\x20leg):\x20the\x20merchant\x27s\x20OWN\x20service\x20fee\x20(only\x20when\x20the\x20merchant\x20IS\x20the\x20aggregator)\x20and\x20a\x20referral/reward\x20to\x20a\x20referrer\x20the\x20buyer\x20names.\x20There\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template.','applicable_scenes':['allocation_dynamic_recipient'],'industry_tags':['referral','affiliate','marketing'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20(default:\x20the\x20sole\x2010000\x20recipient)','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20merchant_service_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20that\x20fee\x20is\x20>\x200\x20—\x20blank\x20or\x20omitted\x20silently\x20pays\x20the\x20deploying\x20account.\x20NEVER\x20route\x20the\x20merchant\x27s\x20own\x20fee\x20through\x20GuardIdentifier:\x20that\x20recipient\x20is\x20buyer-submitted,\x20not\x20merchant-declared.','required':![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(must\x20be\x20configured\x20with\x20identifier=0\x20as\x20address\x20type)','required':!![]},{'name':'passport_identifier','type':'number','description':'Passport\x20table\x20identifier\x20(u8,\x200-255)\x20carrying\x20the\x20referrer\x20address\x20the\x20buyer\x20submits\x20—\x20only\x20consulted\x20when\x20referrer_rate\x20>\x200\x20(default\x200)','required':![],'default':0x0},{'name':'merchant_rate','type':'number','description':'Merchant\x27s\x20own\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'merchant_service_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20in\x20basis\x20points,\x20default\x200.\x20Only\x20for\x20a\x20merchant\x20that\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium).\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20pre-order;\x20merchant_rate\x20+\x20merchant_service_fee_bps\x20+\x20referrer_rate\x20MUST\x20sum\x20to\x2010000.','required':![],'default':0x0},{'name':'referrer_rate','type':'number','description':'Referral\x20/\x20reward\x20rate\x20paid\x20to\x20the\x20referrer\x20the\x20BUYER\x20names\x20in\x20its\x20Passport,\x20default\x200.\x20This\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20acquisition\x20price,\x20not\x20a\x20platform\x20share\x20—\x20keep\x20it\x200\x20unless\x20the\x20merchant\x20actually\x20runs\x20a\x20referral\x20programme,\x20and\x20never\x20route\x20the\x20merchant\x27s\x20own\x20fee\x20here.','required':![],'default':0x0}],'body':a=>{const b=assert_declared_share('T-A-06','merchant_rate',a['merchant_rate'],0x2710),c=assert_declared_share('T-A-06','merchant_service_fee_bps',a['merchant_service_fee_bps'],0x0),d=assert_declared_share('T-A-06','referrer_rate',a['referrer_rate'],0x0),e=b+c+d;if(e!==0x2710)throw new Error('T-A-06:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+e+'\x20(merchant='+b+'\x20+\x20merchant_service_fee='+c+'\x20+\x20referrer='+d+')');assert_explicit_recipient('T-A-06','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-06','merchant_fee_treasury',a['merchant_fee_treasury'],c);const f=Number(a['passport_identifier']??0x0);if(f<0x0||f>0xff)throw new Error('T-A-06:\x20passport_identifier\x20MUST\x20be\x20u8\x20(0-255),\x20got\x20'+f);const g=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&g['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(c),'mode':'Rate'}),d>0x0&&g['push']({'who':{'GuardIdentifier':f},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Dynamic\x20recipient\x20(platform\x20commission\x200):\x20merchant\x20'+b+'/10000'+(c>0x0?',\x20merchant\x27s\x20own\x20service\x20fee\x20'+c+'/10000':'')+(d>0x0?',\x20referrer\x20'+d+'/10000\x20(from\x20Passport\x20identifier='+f+')':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':g,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['DEFAULT\x20PARAMETERS\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury;\x20to\x20exercise\x20the\x20GuardIdentifier\x20form\x20set\x20referrer_rate\x20>\x200\x20and\x20lower\x20merchant_rate\x20by\x20exactly\x20that\x20amount\x20(the\x20emitted\x20rows\x20must\x20still\x20total\x2010000)','F-A-13:\x20Passport\x20table[identifier]\x20MUST\x20be\x20address\x20type\x20(else\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS=1)','The\x20Guard\x20identifier\x20slot\x27s\x20address-type\x20check\x20MUST\x20pass\x20when\x20the\x20Allocator\x20is\x20added\x20(else\x20the\x20Allocator\x20add\x20fails)','Customer\x20must\x20submit\x20Passport\x20with\x20referrer\x20address\x20at\x20the\x20specified\x20identifier\x20slot','Guard\x20should\x20verify\x20Passport\x20completeness\x20before\x20alloc()\x20executes','The\x20GuardIdentifier\x20recipient\x20is\x20CHOSEN\x20BY\x20THE\x20BUYER\x20(the\x20submitted\x20address\x20bound\x20to\x20for_object),\x20so\x20the\x20Guard\x20—\x20not\x20the\x20template\x20—\x20is\x20what\x20makes\x20it\x20trustworthy:\x20bind\x20it\x20(e.g.\x20an\x20allow-listed\x20referrer)\x20before\x20enabling\x20a\x20non-zero\x20referrer_rate,\x20and\x20never\x20use\x20it\x20for\x20the\x20merchant\x27s\x20own\x20fee','merchant_service_fee_bps\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20fee,\x20default\x200,\x20and\x20requires\x20an\x20explicit\x20non-empty\x20recipient\x20—\x20there\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template']},{'id':'T-A-07','name':'Refund\x20to\x20the\x20submitted\x20Order\x20(100%\x20delivered\x20to\x20the\x20order\x20as\x20escrow)','description':'Single\x20Allocator,\x201\x20Rate=10000\x20sharing\x20whose\x20recipient\x20is\x20the\x20order\x20submitted\x20at\x20alloc\x20time\x20(Guard\x20table\x20identifier\x200).\x20The\x20funds\x20are\x20delivered\x20to\x20that\x20order\x20and\x20received\x20by\x20its\x20owner.','applicable_scenes':['allocation_refund_to_order'],'industry_tags':['refund','customer_protection','order_lifecycle'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20verifying\x20the\x20submitted\x20order\x20qualifies\x20(e.g.\x20order\x20at\x20the\x20refund\x20node,\x20order.service\x20==\x20host\x20service).\x20Its\x20table\x20needs\x20an\x20address-typed\x20b_submission\x20slot\x20at\x20identifier\x200.','required':!![]}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Refund\x20to\x20the\x20submitted\x20Order\x20(100%\x20delivered\x20to\x20the\x20order\x20as\x20escrow)','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'GuardIdentifier':0x0},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['The\x20Guard\x20table\x20MUST\x20have\x20an\x20address-typed\x20b_submission\x20slot\x20at\x20identifier\x200\x20carrying\x20the\x20submitted\x20order\x20(else\x20the\x20Allocator\x20add\x20fails\x20with\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS).','At\x20alloc\x20time\x20the\x20full\x20Rate\x20is\x20delivered\x20to\x20the\x20submitted\x20order\x20as\x20a\x20CoinWrapper\x20—\x20the\x20order\x20object\x20owns\x20it.\x20Its\x20owner\x20subsequently\x20receives\x20the\x20bare\x20coins\x20through\x20the\x20order\x27s\x20owner-receive\x20entry;\x20unrelated\x20addresses\x20cannot\x20intercept.','The\x20Guard\x20decides\x20which\x20submitted\x20orders\x20qualify:\x20node\x20state\x20plus\x20a\x20service-scope\x20binding\x20(order.service\x20==\x20host\x20service)\x20are\x20the\x20typical\x20conditions;\x20tightening\x20those\x20conditions\x20is\x20how\x20the\x20destination\x20is\x20controlled.','When\x20the\x20per-order\x20Allocation\x20is\x20created\x20through\x20the\x20Service\x20flow,\x20payment_info.for_object\x20is\x20set\x20to\x20the\x20order\x20the\x20allocation\x20belongs\x20to,\x20recording\x20the\x20business\x20context\x20auditors\x20can\x20query.','No\x20fee\x20leg\x20and\x20no\x20platform\x20leg:\x20a\x20refund\x20path\x20pays\x20the\x20order\x27s\x20owner\x20and\x20nothing\x20else.\x20A\x20declared\x20service\x20fee\x20belongs\x20on\x20the\x20purchase-side\x20allocation\x20(T-A-02)\x20as\x20an\x20explicit\x20Rate\x20leg\x20—\x20never\x20as\x20a\x20leg\x20here,\x20and\x20never\x20as\x20an\x20implicit\x20remainder\x20or\x20a\x20Surplus\x20drain']},{'id':'T-A-08','name':'Arbitration\x20fees\x20payout\x20(arbitrator\x20keeps\x20100%\x20by\x20default\x20/\x20optional\x20declared\x20operator\x20fee)','description':'Single\x20Allocator,\x20Rate\x20sharing\x20items\x20summing\x20to\x20exactly\x2010000.\x20Triggered\x20by\x20the\x20Arbitration\x20fees-distribution\x20operation\x20(permission\x20365),\x20with\x20or\x20without\x20a\x20Passport.\x20DIRECT-SALES\x20default:\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20fee\x20(single\x20Rate\x2010000\x20leg)\x20—\x20WoWok\x20takes\x20no\x20platform\x20commission.\x20An\x20optional\x20fee\x20for\x20the\x20arbitration\x20OPERATOR\x20(the\x20arbitrator\x27s\x20own\x20declared\x20service\x20price,\x20or\x20a\x20third\x20party\x20such\x20as\x20a\x20payments/escrow\x20provider)\x20is\x20allowed\x20only\x20under\x20the\x20L3\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20the\x20parties\x20can\x20compute\x20before\x20the\x20fee\x20is\x20charged,\x20never\x20an\x20implicit\x20remainder;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20visible\x20to\x20both\x20sides\x20beforehand\x20(blank\x20silently\x20routes\x20the\x20money\x20to\x20the\x20deploying\x20account);\x20(3)\x20no\x20mandatory\x20transit\x20pool,\x20and\x20the\x20fee\x20is\x20NEVER\x20taken\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all,\x20so\x20it\x20doubles\x20as\x20draining\x20the\x20pool).','applicable_scenes':['allocation_arbitration_fees'],'industry_tags':['arbitration','dispute','fees'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(must\x20match\x20Arbitration\x20fee\x20Coin\x20type)','required':!![]},{'name':'arbitrator_treasury','type':'address','description':'Arbitrator\x20Treasury\x20address\x20—\x20default\x20sole\x2010000\x20recipient\x20of\x20the\x20dispute\x20fee','required':!![]},{'name':'arbitration_operator_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20arbitration_operator_fee_bps:\x20the\x20ARBITRATION\x20OPERATOR\x27s\x20own\x20fee\x20treasury\x20(the\x20arbitrator\x27s\x20declared\x20service\x20price)\x20or\x20a\x20genuine\x20third-party\x20treasury\x20(e.g.\x20an\x20escrow\x20/\x20payments\x20provider).\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20the\x20fee\x20is\x20>\x200\x20—\x20leaving\x20it\x20blank\x20or\x20omitting\x20it\x20is\x20NOT\x20a\x20no-op:\x20the\x20share\x20silently\x20goes\x20to\x20the\x20deploying\x20account.','required':![]},{'name':'arbitrator_rate','type':'number','description':'Arbitrator\x27s\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20dispute\x20fee\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'arbitration_operator_fee_bps','type':'number','description':'The\x20ARBITRATION\x20OPERATOR\x27s\x20(or\x20a\x20named\x20third\x20party\x27s)\x20own\x20fee\x20in\x20basis\x20points,\x20default\x200.\x20Explicit\x20number\x20both\x20sides\x20can\x20compute\x20before\x20the\x20fee\x20is\x20charged;\x20arbitrator_rate\x20+\x20arbitration_operator_fee_bps\x20MUST\x20sum\x20to\x2010000.\x20WoWok\x20extracts\x20nothing,\x20so\x20there\x20is\x20no\x20platform\x20share\x20here.','required':![],'default':0x0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20Arbitration\x20ruling\x20finalized)','required':!![]}],'body':a=>{const b=assert_declared_share('T-A-08','arbitrator_rate',a['arbitrator_rate'],0x2710),c=assert_declared_share('T-A-08','arbitration_operator_fee_bps',a['arbitration_operator_fee_bps'],0x0);assert_explicit_recipient('T-A-08','arbitrator_treasury',a['arbitrator_treasury'],b),assert_explicit_recipient('T-A-08','arbitration_operator_treasury',a['arbitration_operator_treasury'],c);const d=b+c;if(d!==0x2710)throw new Error('T-A-08:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+d+'\x20(arbitrator='+b+'\x20+\x20operator_fee='+c+')');const e=[{'who':{'Entity':a['arbitrator_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&e['push']({'who':{'Entity':a['arbitration_operator_treasury']},'sharing':String(c),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Arbitration\x20fees\x20(platform\x20commission\x200):\x20arbitrator\x20'+b+'/10000'+(c>0x0?',\x20arbitration\x20operator\x27s\x20own\x20fee\x20'+c+'/10000':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':e,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Triggered\x20by\x20the\x20Arbitration\x20fees-distribution\x20operation\x20(permission\x20ARBITRATION_FEES_ALLOC=365),\x20with\x20or\x20without\x20a\x20Passport','Independent\x20from\x20Service-order\x20Allocation\x20(this\x20Allocation\x20is\x20not\x20bound\x20to\x20Order)','payment_info\x20typically\x20reuses\x20Arbitration\x27s\x20payment_info','Caller\x20MUST\x20hold\x20ARBITRATION_FEES_ALLOC=365\x20permission','DIRECT-SALES\x20DEFAULT:\x20the\x20emitted\x20rows\x20are\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20arbitrator_treasury\x20—\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20dispute\x20fee,\x20and\x20the\x2010000\x20invariant\x20holds\x20by\x20construction','arbitration_operator_fee_bps\x20is\x20the\x20arbitration\x20OPERATOR\x27s\x20own\x20declared\x20fee\x20(or\x20a\x20named\x20third\x20party\x27s),\x20default\x200;\x20it\x20requires\x20an\x20explicit\x20non-empty\x20recipient\x20and\x20is\x20never\x20an\x20implicit\x20remainder\x20or\x20a\x20Surplus\x20drain.\x20There\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template']},{'id':'T-A-09','name':'Standalone\x20periodic\x20split\x20(investment\x20dividends\x20/\x20shared\x20income)','description':'Standalone\x20Allocation\x20with\x20single\x20Allocator,\x20N\x20Rate\x20sharing\x20items\x20to\x20beneficiary\x20wallets.\x20No\x20Service\x20context.\x20Guard\x20provides\x20time-based\x20or\x20signer-based\x20access\x20control.','applicable_scenes':['allocation_standalone_periodic_split'],'industry_tags':['standalone','investment','dividends','shared_income'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(e.g.\x20\x270x2::wow::WOW\x27\x20or\x20profit\x20token\x20type)','required':!![]},{'name':'beneficiaries','type':'address[]','description':'Array\x20of\x20beneficiary\x20wallet\x20addresses\x20(NOT\x20Treasury\x20objects\x20—\x20standalone\x20mode\x20has\x20no\x20Service\x20context)','required':!![]},{'name':'rates','type':'string[]','description':'Array\x20of\x20rates\x20in\x20basis\x20points\x20(e.g.\x20[\x275000\x27,\x273000\x27,\x272000\x27]\x20=\x2050%/30%/20%).\x20MUST\x20sum\x20to\x2010000.','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20—\x20MUST\x20bind\x20Signer\x20or\x20verify\x20time-based\x20trigger\x20(R-A-3-04:\x20standalone\x20has\x20no\x20Service-layer\x20access\x20control)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20periodic\x20split'}],'body':a=>{const b=a['beneficiaries'],c=a['rates']['map'](e=>Number(e));if(b['length']!==c['length'])throw new Error('T-A-09:\x20beneficiaries\x20('+b['length']+')\x20and\x20rates\x20('+c['length']+')\x20MUST\x20have\x20equal\x20length');if(b['length']===0x0)throw new Error('T-A-09:\x20at\x20least\x201\x20beneficiary\x20required');if(b['length']>0x64)throw new Error('T-A-09:\x20beneficiaries\x20count\x20'+b['length']+'\x20exceeds\x20MAX_SHARING_COUNT\x20(100)');const d=c['reduce']((e,f)=>e+f,0x0);if(d!==0x2710)throw new Error('T-A-09:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+d);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Standalone\x20periodic\x20split','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':b['map']((e,f)=>({'who':{'Entity':e},'sharing':String(c[f]),'mode':'Rate'})),'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode\x20(§0):\x20no\x20Service/Order/Arbitration\x20context\x20required','R-A-3-04:\x20Guard\x20MUST\x20bind\x20Signer\x20or\x20verify\x20time-based\x20trigger\x20—\x20no\x20Service-layer\x20access\x20control\x20exists','F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode,\x20no\x20Surplus)','Caller\x20lifecycle:\x20receive()\x20to\x20deposit\x20funds\x20→\x20alloc()\x20to\x20trigger\x20distribution','Guard\x20should\x20bind\x20context(Signer)==authorized\x20to\x20prevent\x20unauthorized\x20alloc()\x20calls','beneficiaries\x20are\x20personal\x20wallets,\x20NOT\x20Treasury\x20objects\x20(no\x20Service\x20context)','Every\x20rate\x20is\x20an\x20EXPLICIT\x20declared\x20share\x20to\x20an\x20EXPLICIT\x20non-empty\x20address:\x20nothing\x20here\x20is\x20an\x20implicit\x20platform\x20beneficiary\x20and\x20no\x20leg\x20is\x20left\x20unset\x20(blank\x20silently\x20binds\x20the\x20deploying\x20account).\x20A\x20share\x20intended\x20for\x20a\x20third\x20party\x20is\x20the\x20payer\x27s\x20own\x20declared\x20price\x20and\x20must\x20be\x20named\x20on\x20both\x20sides']},{'id':'T-A-10','name':'Standalone\x20vesting\x20release\x20(time-locked\x20multi-stage\x20unlock)','description':'Standalone\x20Allocation\x20with\x20N\x20Allocators\x20(default\x203\x20stages),\x20each\x20triggered\x20by\x20a\x20time-locked\x20Guard.\x20Stages\x201..N-1\x20use\x20Amount\x20mode;\x20final\x20stage\x20uses\x20Surplus\x20to\x20drain\x20remaining\x20balance.\x20No\x20Service\x20context.','applicable_scenes':['allocation_standalone_vesting'],'industry_tags':['standalone','vesting','time_lock','team_tokens'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(vested\x20asset,\x20e.g.\x20locked\x20team\x20tokens)','required':!![]},{'name':'beneficiary_address','type':'address','description':'Single\x20beneficiary\x20wallet\x20address\x20(vesting\x20recipient)','required':!![]},{'name':'stage_1_guard','type':'address','description':'Guard\x20for\x20stage\x201\x20(verifies\x20context(Clock).timestamp\x20>=\x20stage_1_unlock)','required':!![]},{'name':'stage_1_amount','type':'number','description':'Amount\x20to\x20release\x20at\x20stage\x201\x20(smallest\x20coin\x20unit,\x20e.g.\x20MIST)','required':!![]},{'name':'stage_2_guard','type':'address','description':'Guard\x20for\x20stage\x202\x20(verifies\x20context(Clock).timestamp\x20>=\x20stage_2_unlock)\x20—\x20MUST\x20differ\x20from\x20stage_1_guard','required':!![]},{'name':'stage_2_amount','type':'number','description':'Amount\x20to\x20release\x20at\x20stage\x202\x20(smallest\x20coin\x20unit)','required':!![]},{'name':'stage_3_guard','type':'address','description':'Guard\x20for\x20stage\x203\x20(final\x20stage,\x20uses\x20Surplus\x20to\x20drain\x20remaining\x20balance)\x20—\x20MUST\x20differ\x20from\x20stage_1_guard\x20and\x20stage_2_guard','required':!![]},{'name':'max_cap','type':'number','description':'Maximum\x20cumulative\x20release\x20cap\x20(applied\x20to\x20stages\x201\x20and\x202\x20via\x20max\x20field).\x20Stage\x203\x20uses\x20Surplus\x20so\x20no\x20max\x20needed.','required':![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20vesting\x20release\x20(3-stage\x20time-locked)'}],'body':a=>{const b=[a['stage_1_guard'],a['stage_2_guard'],a['stage_3_guard']],c=new Set(b);if(c['size']!==b['length']){const h=b['filter']((j,k)=>b['indexOf'](j)!==k);throw new Error('T-A-10:\x20stage\x20guards\x20MUST\x20be\x20unique\x20(F-A-14),\x20duplicates:\x20'+h['join'](',\x20'));}const d=Number(a['stage_1_amount']),e=Number(a['stage_2_amount']);if(d<=0x0||e<=0x0)throw new Error('T-A-10:\x20stage_1_amount\x20and\x20stage_2_amount\x20MUST\x20be\x20>\x200,\x20got\x20stage1='+d+',\x20stage2='+e);const f=d+e,g=a['max_cap']!=null?Number(a['max_cap']):null;if(g!==null&&f>g)throw new Error('T-A-10:\x20stage_1_amount\x20+\x20stage_2_amount\x20('+f+')\x20MUST\x20be\x20<=\x20max_cap\x20('+g+')\x20—\x20F-A-08\x20(EAMOUNT_EXCEEDS_MAX)');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Standalone\x20vesting\x20release\x20(3-stage\x20time-locked)','threshold':'0','allocators':[{'guard':a['stage_1_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':String(d),'mode':'Amount'}],'max':g!=null?String(g):null},{'guard':a['stage_2_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':String(e),'mode':'Amount'}],'max':g!=null?String(g):null},{'guard':a['stage_3_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':'0','mode':'Surplus'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode\x20(§0):\x20no\x20Service/Order/Arbitration\x20context\x20required','R-A-3-04:\x20Guard\x20time-lock\x20MUST\x20be\x20enforced\x20—\x20no\x20Service-layer\x20access\x20control\x20exists','F-A-14:\x20stage_1_guard,\x20stage_2_guard,\x20stage_3_guard\x20MUST\x20be\x20unique\x20(duplicate\x20guards\x20are\x20dead\x20code)','F-A-04:\x20at\x20most\x201\x20Surplus\x20per\x20Allocator\x20(stage\x203\x20uses\x20Surplus\x20to\x20drain\x20remainder)','F-A-08:\x20stage_1_amount\x20+\x20stage_2_amount\x20MUST\x20be\x20<=\x20max_cap\x20(if\x20max_cap\x20provided)','R-A-4-01:\x20if\x20caller\x20calls\x20alloc()\x20before\x20stage\x20time-lock\x20expires,\x20alloc()\x20silently\x20returns\x20—\x20caller\x20should\x20check\x20balance==0\x20after\x20alloc()','R-A-4-02:\x20Guard\x20conditions\x20SHOULD\x20be\x20mutually\x20exclusive\x20by\x20timestamp\x20(e.g.\x20stage_1:\x20ts<stage_2_unlock,\x20stage_2:\x20stage_2_unlock<=ts<stage_3_unlock,\x20stage_3:\x20ts>=stage_3_unlock)','Caller\x20lifecycle:\x20receive()\x20to\x20deposit\x20locked\x20tokens\x20→\x20alloc()\x20at\x20each\x20vesting\x20milestone','Single\x20beneficiary\x20—\x20no\x20platform\x20leg.\x20The\x20stage-3\x20Surplus\x20is\x20this\x20contract\x27s\x20own\x20vesting\x20remainder,\x20NOT\x20a\x20fee:\x20Surplus\x20calls\x20balance::withdraw_all,\x20so\x20never\x20express\x20a\x20declared\x20fee\x20through\x20a\x20Surplus\x20leg\x20(L3\x20constraint\x203)']},{'id':'T-A-11','name':'Standalone\x20payroll\x20/\x20salary\x20distribution\x20(issuer\x20+\x20Repository\x20verified)','description':'Standalone\x20Allocation\x20for\x20periodic\x20payroll:\x20employees\x20receive\x20Rate\x20shares.\x20The\x20Guard\x20binds\x20the\x20issuer\x20Signer\x20identity\x20and\x20cross-checks\x20a\x20Repository\x20payroll\x20record\x20(period\x20and\x20amounts).\x20No\x20Service\x20context.','applicable_scenes':['allocation_standalone_payroll'],'industry_tags':['standalone','payroll','salary','compensation','hr'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20used\x20for\x20payroll\x20(e.g.\x20\x270x2::wow::WOW\x27)','required':!![]},{'name':'employees','type':'address[]','description':'Employee\x20wallet\x20addresses\x20(Recipient::Entity\x20recipients)','required':!![]},{'name':'rates','type':'string[]','description':'Per-employee\x20rates\x20in\x20basis\x20points\x20(e.g.\x20[\x276000\x27,\x274000\x27]).\x20MUST\x20sum\x20to\x2010000.','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20that\x20binds\x20Signer\x20==\x20issuer\x20AND\x20cross-checks\x20the\x20Repository\x20payroll\x20record\x20(both\x20required)','required':!![]},{'name':'payroll_period','type':'string','description':'Human-readable\x20period\x20label\x20(e.g.\x20\x272025-W26\x27)\x20—\x20recorded\x20in\x20the\x20Allocation\x20description\x20for\x20audit','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20payroll\x20distribution'}],'body':a=>{const b=a['employees'],c=a['rates']['map'](e=>Number(e));if(b['length']!==c['length'])throw new Error('T-A-11:\x20employees\x20('+b['length']+')\x20and\x20rates\x20('+c['length']+')\x20MUST\x20have\x20equal\x20length');if(b['length']===0x0)throw new Error('T-A-11:\x20at\x20least\x201\x20employee\x20required');if(b['length']>0x64)throw new Error('T-A-11:\x20employees\x20count\x20'+b['length']+'\x20exceeds\x20MAX_SHARING_COUNT\x20(100)');const d=c['reduce']((e,f)=>e+f,0x0);if(d!==0x2710)throw new Error('T-A-11:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+d);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':(a['description']??'Standalone\x20payroll\x20distribution')+'\x20—\x20period:\x20'+a['payroll_period'],'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':b['map']((e,f)=>({'who':{'Entity':e},'sharing':String(c[f]),'mode':'Rate'})),'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode:\x20no\x20Service/Order/Arbitration\x20context\x20required','RC-FIND-04:\x20the\x20Guard\x20MUST\x20bind\x20the\x20issuer\x20identity\x20(Signer\x20==\x20employer/admin,\x20or\x20a\x20Permission\x20member)\x20—\x20standalone\x20has\x20no\x20Service\x20access-control\x20layer','Repository\x20distinction:\x20the\x20Guard\x20MUST\x20cross-check\x20the\x20Repository\x20payroll\x20record\x20(period\x20hash,\x20amounts\x20and\x20recipients)\x20so\x20the\x20distribution\x20is\x20tied\x20to\x20auditable\x20work/payroll\x20data','Auditability:\x20the\x20Guard\x20rules\x20are\x20public\x20—\x20third\x20parties\x20verify\x20who\x20may\x20distribute\x20and\x20what\x20inputs\x20distinguish\x20a\x20valid\x20payroll','F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode)','Caller\x20lifecycle:\x20issuer\x20receive()\x20to\x20fund\x20payroll\x20→\x20alloc()\x20after\x20the\x20Repository\x20record\x20for\x20the\x20period\x20is\x20committed','Employees\x20are\x20personal\x20wallets\x20(Recipient::Entity),\x20never\x20Recipient::Signer','The\x20issuer/employer\x20is\x20the\x20payer\x20and\x20keeps\x20the\x20whole\x20payroll\x20pool\x20by\x20default:\x20there\x20is\x20no\x20platform\x20share\x20in\x20this\x20template.\x20Every\x20rate\x20is\x20an\x20explicit\x20per-employee\x20price\x20to\x20an\x20explicit\x20non-empty\x20address\x20(blank\x20silently\x20binds\x20the\x20deploying\x20account),\x20and\x20sum(rates)\x20MUST\x20stay\x2010000\x20so\x20no\x20residual\x20stays\x20claimable']}];export const ALLOCATION_TEMPLATES_VERSION='1.1.0';export function getAllTemplates(){return[...ALLOCATION_TEMPLATES];}export function getTemplateById(a){return ALLOCATION_TEMPLATES['find'](b=>b['id']===a);}export function getTemplatesByScene(a){return ALLOCATION_TEMPLATES['filter'](b=>b['applicable_scenes']['includes'](a));}export function getTemplatesByIndustry(a){return ALLOCATION_TEMPLATES['filter'](b=>b['industry_tags']['includes'](a)||b['industry_tags']['includes']('universal'));}export function suggestTemplateForScene(a){const b=getTemplatesByScene(a);return b['length']>0x0?b[0x0]:undefined;}export function listTemplates(){return ALLOCATION_TEMPLATES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'scenes':a['applicable_scenes']}));}export function fillTemplate(a,b){const c=getTemplateById(a);if(!c)return{'ok':![],'error':'Template\x20'+a+'\x20not\x20found'};for(const d of c['params']){if(d['required']&&!(d['name']in b))return{'ok':![],'error':'Missing\x20required\x20param:\x20'+d['name']};}try{return{'ok':!![],'body':c['body'](b)};}catch(f){return{'ok':![],'error':f instanceof Error?f['message']:String(f)};}}