@wowok/agent-mcp 3.0.5 → 3.1.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 (129) hide show
  1. package/README.md +25 -20
  2. package/dist/customer/account-events.js +1 -1
  3. package/dist/graph/onchain/dataplane.d.ts +2 -2
  4. package/dist/graph/onchain/edge-schema.js +1 -1
  5. package/dist/graph/onchain/expand.js +1 -1
  6. package/dist/graph/onchain/onchain.spec.js +1 -1
  7. package/dist/graph/onchain/sdk-batch.d.ts +7 -1
  8. package/dist/graph/onchain/sdk-batch.js +1 -1
  9. package/dist/graph/onchain/sdk-dataplane.d.ts +6 -3
  10. package/dist/graph/onchain/sdk-dataplane.js +1 -1
  11. package/dist/graph/onchain/types.d.ts +2 -2
  12. package/dist/index.js +1 -1
  13. package/dist/knowledge/account-marks.js +1 -1
  14. package/dist/knowledge/allocation-risk.js +1 -1
  15. package/dist/knowledge/allocation-templates.js +1 -1
  16. package/dist/knowledge/goal-completion.d.ts +12 -0
  17. package/dist/knowledge/goal-completion.js +1 -1
  18. package/dist/knowledge/guard-risk.js +1 -1
  19. package/dist/knowledge/index.d.ts +4 -0
  20. package/dist/knowledge/index.js +1 -1
  21. package/dist/knowledge/migration-preflight.js +1 -1
  22. package/dist/knowledge/payment-tracker.d.ts +63 -0
  23. package/dist/knowledge/payment-tracker.js +1 -0
  24. package/dist/knowledge/recipient-constraint.d.ts +160 -0
  25. package/dist/knowledge/recipient-constraint.js +1 -0
  26. package/dist/knowledge/safety-rules.d.ts +1 -1
  27. package/dist/knowledge/safety-rules.js +1 -1
  28. package/dist/knowledge/template-registry.js +1 -1
  29. package/dist/knowledge/tools-reference.js +1 -1
  30. package/dist/knowledge/workflow-guidance.js +1 -1
  31. package/dist/knowledge/workspace-lists.d.ts +4 -0
  32. package/dist/knowledge/workspace-lists.js +1 -1
  33. package/dist/monitor/MonitorLoop.js +1 -1
  34. package/dist/participation/arbitrator-interest.d.ts +2 -0
  35. package/dist/participation/arbitrator-interest.js +1 -1
  36. package/dist/participation/collaborator-interest.d.ts +2 -0
  37. package/dist/participation/collaborator-interest.js +1 -1
  38. package/dist/participation/customer-interest.d.ts +2 -0
  39. package/dist/participation/customer-interest.js +1 -1
  40. package/dist/participation/merchant-interest.d.ts +2 -0
  41. package/dist/participation/merchant-interest.js +1 -1
  42. package/dist/participation/supplier-interest.d.ts +2 -0
  43. package/dist/participation/supplier-interest.js +1 -1
  44. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  45. package/dist/playbooks/service-build/context-assembly.js +1 -1
  46. package/dist/playbooks/service-build/merchant-guide.d.ts +7 -0
  47. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  48. package/dist/playbooks/service-build/participation-radar.js +1 -1
  49. package/dist/playbooks/service-build/pipeline-actions.d.ts +2 -2
  50. package/dist/playbooks/service-build/pipeline-actions.js +1 -1
  51. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  52. package/dist/playbooks/service-build/risk-aggregator.js +1 -1
  53. package/dist/playbooks/service-build/topology-query.js +1 -1
  54. package/dist/relationship/derivation.js +1 -1
  55. package/dist/safety/confirm-gate.js +1 -1
  56. package/dist/schema/call/allocation.js +1 -1
  57. package/dist/schema/call/base.js +1 -1
  58. package/dist/schema/call/semantic.js +1 -1
  59. package/dist/schema/call/service.d.ts +6 -6
  60. package/dist/schema/call/service.js +1 -1
  61. package/dist/schema/common/index.js +1 -1
  62. package/dist/schema/evaluation/index.d.ts +4 -4
  63. package/dist/schema/evaluation/index.js +1 -1
  64. package/dist/schema/goal/index.d.ts +21 -21
  65. package/dist/schema/goal/planning.d.ts +6 -6
  66. package/dist/schema/industry-pack/index.d.ts +6 -6
  67. package/dist/schema/industry-pack/modes.d.ts +6 -6
  68. package/dist/schema/intent-radar/index.d.ts +16 -16
  69. package/dist/schema/local/index.js +1 -1
  70. package/dist/schema/messenger/index.d.ts +110 -8
  71. package/dist/schema/messenger/index.js +1 -1
  72. package/dist/schema/operations.d.ts +37 -29
  73. package/dist/schema/operations.js +1 -1
  74. package/dist/schema/persona/index.d.ts +155 -155
  75. package/dist/schema/query/bi.d.ts +26 -26
  76. package/dist/schema/query/bi.js +1 -1
  77. package/dist/schema/query/index.d.ts +15 -12
  78. package/dist/schema/query/index.js +1 -1
  79. package/dist/schema/schema-query/index.d.ts +1 -1
  80. package/dist/schema/schema-version.js +1 -1
  81. package/dist/schema/strategy-review/index.d.ts +1 -1
  82. package/dist/schema-query-impl/index.js +1 -1
  83. package/dist/schemas/bridge_operation.schema.json +14 -14
  84. package/dist/schemas/evaluation_operation.schema.json +7 -7
  85. package/dist/schemas/guard2file.schema.json +3 -3
  86. package/dist/schemas/index.json +1 -1
  87. package/dist/schemas/local_history_operation.schema.json +1 -1
  88. package/dist/schemas/machineNode2file.schema.json +3 -3
  89. package/dist/schemas/messenger_operation.output.json +266 -38
  90. package/dist/schemas/messenger_operation.schema.json +27 -3
  91. package/dist/schemas/onchain_events.schema.json +1 -1
  92. package/dist/schemas/onchain_operations.schema.json +75 -77
  93. package/dist/schemas/onchain_operations_allocation.schema.json +6 -6
  94. package/dist/schemas/onchain_operations_arbitration.schema.json +3 -3
  95. package/dist/schemas/onchain_operations_contact.schema.json +3 -3
  96. package/dist/schemas/onchain_operations_demand.schema.json +3 -3
  97. package/dist/schemas/onchain_operations_gen_passport.schema.json +3 -3
  98. package/dist/schemas/onchain_operations_gen_proof.schema.json +3 -3
  99. package/dist/schemas/onchain_operations_guard.schema.json +4 -4
  100. package/dist/schemas/onchain_operations_machine.schema.json +11 -11
  101. package/dist/schemas/onchain_operations_order.schema.json +3 -3
  102. package/dist/schemas/onchain_operations_payment.schema.json +4 -4
  103. package/dist/schemas/onchain_operations_permission.schema.json +3 -3
  104. package/dist/schemas/onchain_operations_personal.schema.json +3 -3
  105. package/dist/schemas/onchain_operations_progress.schema.json +3 -3
  106. package/dist/schemas/onchain_operations_proof.schema.json +3 -3
  107. package/dist/schemas/onchain_operations_repository.schema.json +3 -3
  108. package/dist/schemas/onchain_operations_reward.schema.json +3 -3
  109. package/dist/schemas/onchain_operations_service.schema.json +9 -11
  110. package/dist/schemas/onchain_operations_treasury.schema.json +5 -5
  111. package/dist/schemas/onchain_table_data.output.json +14 -14
  112. package/dist/schemas/query_toolkit.output.json +38 -13
  113. package/dist/schemas/query_toolkit.schema.json +39 -11
  114. package/dist/strategy/collectors.js +1 -1
  115. package/dist/tools/handlers/config.js +1 -1
  116. package/dist/tools/handlers/evaluation.js +1 -1
  117. package/dist/tools/handlers/messenger.js +1 -1
  118. package/dist/tools/handlers/onchain.js +1 -1
  119. package/dist/tools/handlers/permission.js +1 -1
  120. package/dist/tools/handlers/query.js +1 -1
  121. package/dist/tools/handlers/strategy-review.js +1 -1
  122. package/dist/tools/handlers/workflow.js +1 -1
  123. package/dist/tools/index.js +1 -1
  124. package/dist/tools/registry/onchain.js +1 -1
  125. package/dist/tools/registry/query.js +1 -1
  126. package/dist/tools/rules-hook.d.ts +2 -0
  127. package/dist/tools/rules-hook.js +1 -1
  128. package/dist/tools/shared.js +1 -1
  129. package/package.json +2 -2
@@ -1 +1 @@
1
- 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']},{'id':'T-A-02','name':'Standard\x203-way\x20Rate\x20split','description':'Three-way\x20split:\x20merchant\x20/\x20platform\x20/\x20logistics.\x20Pure\x20Rate\x20mode,\x20sum(rates)\x20MUST\x20equal\x2010000','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\x20Treasury\x20address','required':!![]},{'name':'platform_treasury','type':'address','description':'Platform\x20Treasury\x20address','required':!![]},{'name':'logistics_treasury','type':'address','description':'Logistics\x20Treasury\x20address\x20(set\x20to\x20platform_treasury\x20if\x20N/A)','required':!![]},{'name':'merchant_rate','type':'number','description':'Merchant\x20rate\x20in\x20basis\x20points\x20(e.g.\x208000\x20=\x2080%)','required':!![],'default':0x1f40},{'name':'platform_rate','type':'number','description':'Platform\x20rate\x20in\x20basis\x20points\x20(e.g.\x201000\x20=\x2010%)','required':!![],'default':0x3e8},{'name':'logistics_rate','type':'number','description':'Logistics\x20rate\x20in\x20basis\x20points\x20(e.g.\x201000\x20=\x2010%)','required':!![],'default':0x3e8},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion\x20+\x20service\x20binding)','required':!![]}],'body':a=>{const b=Number(a['merchant_rate']),c=Number(a['platform_rate']),d=Number(a['logistics_rate']),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+\x20platform='+c+'\x20+\x20logistics='+d+')'));return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'3-way\x20split:\x20merchant\x20'+b+'/10000,\x20platform\x20'+c+'/10000,\x20logistics\x20'+d+'/10000','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'},{'who':{'Entity':a['platform_treasury']},'sharing':String(c),'mode':'Rate'},{'who':{'Entity':a['logistics_treasury']},'sharing':String(d),'mode':'Rate'}],'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)','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','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)','fix\x20is\x20cached\x20as\x20refundAmount\x20at\x20allocator_add\x20time','Guard\x20must\x20verify\x20customer\x20refund\x20eligibility\x20(e.g.\x20order\x20status\x20=\x20Refunded)']},{'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;\x20passport::result_for_guard\x20hard-verifies\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)']},{'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)','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','required':!![]},{'name':'platform_treasury','type':'address','description':'Platform\x20Treasury\x20address','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\x20for\x20small\x20orders\x20(e.g.\x2010000\x20=\x20100%)','required':!![],'default':0x2710},{'name':'large_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20for\x20large\x20orders\x20(e.g.\x208000\x20=\x2080%)','required':!![],'default':0x1f40},{'name':'large_order_platform_rate','type':'number','description':'Platform\x20rate\x20for\x20large\x20orders\x20(e.g.\x202000\x20=\x2020%)','required':!![],'default':0x7d0}],'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=Number(a['small_order_merchant_rate']);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=Number(a['large_order_merchant_rate']),d=Number(a['large_order_platform_rate']),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+\x20platform='+d+')');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Tiered\x20by\x20order\x20amount:\x20small=100%\x20merchant,\x20large=80/20\x20merchant/platform','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':[{'who':{'Entity':a['merchant_treasury']},'sharing':String(c),'mode':'Rate'},{'who':{'Entity':a['platform_treasury']},'sharing':String(d),'mode':'Rate'}],'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)']},{'id':'T-A-06','name':'Dynamic\x20recipient\x20via\x20GuardIdentifier\x20(referrer\x20from\x20Passport)','description':'Single\x20Allocator\x20with\x203\x20Rate\x20sharing\x20items,\x20one\x20recipient\x20resolved\x20from\x20customer\x27s\x20Passport\x20table[0]','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','required':!![]},{'name':'platform_treasury','type':'address','description':'Platform\x20Treasury\x20address','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)\x20—\x20customer\x20submits\x20referrer\x20address\x20at\x20this\x20slot','required':!![],'default':0x0},{'name':'merchant_rate','type':'number','description':'Merchant\x20rate\x20in\x20basis\x20points\x20(e.g.\x208000\x20=\x2080%)','required':!![],'default':0x1f40},{'name':'platform_rate','type':'number','description':'Platform\x20rate\x20in\x20basis\x20points\x20(e.g.\x201000\x20=\x2010%)','required':!![],'default':0x3e8},{'name':'referrer_rate','type':'number','description':'Referrer\x20rate\x20in\x20basis\x20points\x20(e.g.\x201000\x20=\x2010%)','required':!![],'default':0x3e8}],'body':a=>{const b=Number(a['merchant_rate']),c=Number(a['platform_rate']),d=Number(a['referrer_rate']),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+\x20platform='+c+'\x20+\x20referrer='+d+')');const f=Number(a['passport_identifier']);if(f<0x0||f>0xff)throw new Error('T-A-06:\x20passport_identifier\x20MUST\x20be\x20u8\x20(0-255),\x20got\x20'+f);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Dynamic\x20recipient:\x20merchant\x20'+b+'/10000,\x20platform\x20'+c+'/10000,\x20referrer\x20'+d+'/10000\x20(from\x20Passport\x20identifier='+f+')','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'},{'who':{'Entity':a['platform_treasury']},'sharing':String(c),'mode':'Rate'},{'who':{'GuardIdentifier':f},'sharing':String(d),'mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-13:\x20Passport\x20table[identifier]\x20MUST\x20be\x20address\x20type\x20(else\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS=1)','Guard.is_identifier_address(guard,\x20identifier)\x20MUST\x20be\x20true\x20at\x20allocator_add\x20time\x20(else\x20allocator_add\x20fails)','Customer\x20must\x20submit\x20Passport\x20with\x20referrer\x20address\x20at\x20the\x20specified\x20identifier\x20slot','Guard\x20should\x20verify\x20Passport\x20completeness\x20before\x20alloc()\x20executes']},{'id':'T-A-07','name':'Refund\x20to\x20Order\x20(100%\x20to\x20Order\x20object,\x20not\x20personal\x20wallet)','description':'Single\x20Allocator,\x201\x20Rate=10000\x20sharing\x20to\x20Order\x20object\x20address.\x20Refund\x20funds\x20return\x20to\x20Order\x20for\x20downstream\x20handling.','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':'order_address','type':'address','description':'Order\x20object\x20address\x20(NOT\x20personal\x20wallet)\x20—\x20funds\x20flow\x20back\x20to\x20Order','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20customer\x20refund\x20request\x20and\x20eligibility)','required':!![]}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Refund\x20to\x20Order\x20(100%\x20to\x20Order\x20object\x20for\x20downstream\x20handling)','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['order_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['⚠️\x20who=Entity\x20MUST\x20be\x20Order\x20object\x20address\x20(not\x20personal\x20address)','Customer\x20due-diligence\x20rewards\x20this\x20configuration\x20(8-point\x20weight\x20in\x20customer/risk-assessment.ts)','Refund\x20funds\x20return\x20to\x20Order\x20for\x20downstream\x20handling\x20(e.g.\x20customer\x20withdrawal)','Guard\x20must\x20verify\x20customer\x20refund\x20eligibility\x20(e.g.\x20dispute\x20resolved\x20in\x20customer\x27s\x20favor)']},{'id':'T-A-08','name':'Arbitration\x20fees\x20split\x20(arbitrator\x2080%\x20/\x20platform\x2020%)','description':'Single\x20Allocator,\x202\x20Rate\x20sharing\x20items.\x20Triggered\x20by\x20Arbitration.fees_alloc\x20(permission\x20365)\x20or\x20fees_alloc_with_passport.','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','required':!![]},{'name':'platform_treasury','type':'address','description':'Platform\x20Treasury\x20address','required':!![]},{'name':'arbitrator_rate','type':'number','description':'Arbitrator\x20rate\x20in\x20basis\x20points\x20(e.g.\x208000\x20=\x2080%)','required':!![],'default':0x1f40},{'name':'platform_rate','type':'number','description':'Platform\x20rate\x20in\x20basis\x20points\x20(e.g.\x202000\x20=\x2020%)','required':!![],'default':0x7d0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20Arbitration\x20ruling\x20finalized)','required':!![]}],'body':a=>{const b=Number(a['arbitrator_rate']),c=Number(a['platform_rate']),d=b+c;if(d!==0x2710)throw new Error('T-A-08:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+d+'\x20(arbitrator='+b+'\x20+\x20platform='+c+')');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Arbitration\x20fees\x20split:\x20arbitrator\x20'+b+'/10000,\x20platform\x20'+c+'/10000','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['arbitrator_treasury']},'sharing':String(b),'mode':'Rate'},{'who':{'Entity':a['platform_treasury']},'sharing':String(c),'mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Triggered\x20by\x20Arbitration.fees_alloc\x20(permission\x20ARBITRATION_FEES_ALLOC=365)\x20or\x20fees_alloc_with_passport','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']},{'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)']},{'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']}];export const ALLOCATION_TEMPLATES_VERSION='1.0.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
+ 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']},{'id':'T-A-02','name':'Standard\x203-way\x20Rate\x20split','description':'Three-way\x20split:\x20merchant\x20/\x20platform\x20/\x20logistics.\x20Pure\x20Rate\x20mode,\x20sum(rates)\x20MUST\x20equal\x2010000','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\x20Treasury\x20address','required':!![]},{'name':'platform_treasury','type':'address','description':'Platform\x20Treasury\x20address','required':!![]},{'name':'logistics_treasury','type':'address','description':'Logistics\x20Treasury\x20address\x20(set\x20to\x20platform_treasury\x20if\x20N/A)','required':!![]},{'name':'merchant_rate','type':'number','description':'Merchant\x20rate\x20in\x20basis\x20points\x20(e.g.\x208000\x20=\x2080%)','required':!![],'default':0x1f40},{'name':'platform_rate','type':'number','description':'Platform\x20rate\x20in\x20basis\x20points\x20(e.g.\x201000\x20=\x2010%)','required':!![],'default':0x3e8},{'name':'logistics_rate','type':'number','description':'Logistics\x20rate\x20in\x20basis\x20points\x20(e.g.\x201000\x20=\x2010%)','required':!![],'default':0x3e8},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion\x20+\x20service\x20binding)','required':!![]}],'body':a=>{const b=Number(a['merchant_rate']),c=Number(a['platform_rate']),d=Number(a['logistics_rate']),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+\x20platform='+c+'\x20+\x20logistics='+d+')'));return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'3-way\x20split:\x20merchant\x20'+b+'/10000,\x20platform\x20'+c+'/10000,\x20logistics\x20'+d+'/10000','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'},{'who':{'Entity':a['platform_treasury']},'sharing':String(c),'mode':'Rate'},{'who':{'Entity':a['logistics_treasury']},'sharing':String(d),'mode':'Rate'}],'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)','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','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)','fix\x20is\x20cached\x20as\x20refundAmount\x20at\x20allocator_add\x20time','Guard\x20must\x20verify\x20customer\x20refund\x20eligibility\x20(e.g.\x20order\x20status\x20=\x20Refunded)']},{'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;\x20passport::result_for_guard\x20hard-verifies\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)']},{'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)','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','required':!![]},{'name':'platform_treasury','type':'address','description':'Platform\x20Treasury\x20address','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\x20for\x20small\x20orders\x20(e.g.\x2010000\x20=\x20100%)','required':!![],'default':0x2710},{'name':'large_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20for\x20large\x20orders\x20(e.g.\x208000\x20=\x2080%)','required':!![],'default':0x1f40},{'name':'large_order_platform_rate','type':'number','description':'Platform\x20rate\x20for\x20large\x20orders\x20(e.g.\x202000\x20=\x2020%)','required':!![],'default':0x7d0}],'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=Number(a['small_order_merchant_rate']);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=Number(a['large_order_merchant_rate']),d=Number(a['large_order_platform_rate']),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+\x20platform='+d+')');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Tiered\x20by\x20order\x20amount:\x20small=100%\x20merchant,\x20large=80/20\x20merchant/platform','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':[{'who':{'Entity':a['merchant_treasury']},'sharing':String(c),'mode':'Rate'},{'who':{'Entity':a['platform_treasury']},'sharing':String(d),'mode':'Rate'}],'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)']},{'id':'T-A-06','name':'Dynamic\x20recipient\x20via\x20GuardIdentifier\x20(referrer\x20from\x20Passport)','description':'Single\x20Allocator\x20with\x203\x20Rate\x20sharing\x20items,\x20one\x20recipient\x20resolved\x20from\x20customer\x27s\x20Passport\x20table[0]','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','required':!![]},{'name':'platform_treasury','type':'address','description':'Platform\x20Treasury\x20address','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)\x20—\x20customer\x20submits\x20referrer\x20address\x20at\x20this\x20slot','required':!![],'default':0x0},{'name':'merchant_rate','type':'number','description':'Merchant\x20rate\x20in\x20basis\x20points\x20(e.g.\x208000\x20=\x2080%)','required':!![],'default':0x1f40},{'name':'platform_rate','type':'number','description':'Platform\x20rate\x20in\x20basis\x20points\x20(e.g.\x201000\x20=\x2010%)','required':!![],'default':0x3e8},{'name':'referrer_rate','type':'number','description':'Referrer\x20rate\x20in\x20basis\x20points\x20(e.g.\x201000\x20=\x2010%)','required':!![],'default':0x3e8}],'body':a=>{const b=Number(a['merchant_rate']),c=Number(a['platform_rate']),d=Number(a['referrer_rate']),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+\x20platform='+c+'\x20+\x20referrer='+d+')');const f=Number(a['passport_identifier']);if(f<0x0||f>0xff)throw new Error('T-A-06:\x20passport_identifier\x20MUST\x20be\x20u8\x20(0-255),\x20got\x20'+f);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Dynamic\x20recipient:\x20merchant\x20'+b+'/10000,\x20platform\x20'+c+'/10000,\x20referrer\x20'+d+'/10000\x20(from\x20Passport\x20identifier='+f+')','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'},{'who':{'Entity':a['platform_treasury']},'sharing':String(c),'mode':'Rate'},{'who':{'GuardIdentifier':f},'sharing':String(d),'mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-13:\x20Passport\x20table[identifier]\x20MUST\x20be\x20address\x20type\x20(else\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS=1)','Guard.is_identifier_address(guard,\x20identifier)\x20MUST\x20be\x20true\x20at\x20allocator_add\x20time\x20(else\x20allocator_add\x20fails)','Customer\x20must\x20submit\x20Passport\x20with\x20referrer\x20address\x20at\x20the\x20specified\x20identifier\x20slot','Guard\x20should\x20verify\x20Passport\x20completeness\x20before\x20alloc()\x20executes']},{'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\x20allocator_add\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.']},{'id':'T-A-08','name':'Arbitration\x20fees\x20split\x20(arbitrator\x2080%\x20/\x20platform\x2020%)','description':'Single\x20Allocator,\x202\x20Rate\x20sharing\x20items.\x20Triggered\x20by\x20Arbitration.fees_alloc\x20(permission\x20365)\x20or\x20fees_alloc_with_passport.','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','required':!![]},{'name':'platform_treasury','type':'address','description':'Platform\x20Treasury\x20address','required':!![]},{'name':'arbitrator_rate','type':'number','description':'Arbitrator\x20rate\x20in\x20basis\x20points\x20(e.g.\x208000\x20=\x2080%)','required':!![],'default':0x1f40},{'name':'platform_rate','type':'number','description':'Platform\x20rate\x20in\x20basis\x20points\x20(e.g.\x202000\x20=\x2020%)','required':!![],'default':0x7d0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20Arbitration\x20ruling\x20finalized)','required':!![]}],'body':a=>{const b=Number(a['arbitrator_rate']),c=Number(a['platform_rate']),d=b+c;if(d!==0x2710)throw new Error('T-A-08:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+d+'\x20(arbitrator='+b+'\x20+\x20platform='+c+')');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Arbitration\x20fees\x20split:\x20arbitrator\x20'+b+'/10000,\x20platform\x20'+c+'/10000','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['arbitrator_treasury']},'sharing':String(b),'mode':'Rate'},{'who':{'Entity':a['platform_treasury']},'sharing':String(c),'mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Triggered\x20by\x20Arbitration.fees_alloc\x20(permission\x20ARBITRATION_FEES_ALLOC=365)\x20or\x20fees_alloc_with_passport','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']},{'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)']},{'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']},{'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']}];export const ALLOCATION_TEMPLATES_VERSION='1.0.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)};}}
@@ -12,6 +12,18 @@ export interface GoalCompletionDeps {
12
12
  prev_node: string;
13
13
  }[];
14
14
  }[]>;
15
+ pendingWrappers?(holder: string, network?: string): Promise<Array<{
16
+ wrapper_id: string;
17
+ payment: string;
18
+ amount: string;
19
+ plan: {
20
+ operation: string;
21
+ anyone_can_submit: boolean;
22
+ permission_index?: number;
23
+ settles_to: string;
24
+ steps: string[];
25
+ };
26
+ }>>;
15
27
  }
16
28
  type RuleFn = (goal: GoalRecord, network: string | undefined, deps: GoalCompletionDeps) => Promise<GoalCompletionVerdict>;
17
29
  export declare const GOAL_COMPLETION_RULES: Record<GoalType, RuleFn>;
@@ -1 +1 @@
1
- function normAddr(a){if(!a)return'';const b=a['startsWith']('0x')?a['slice'](0x2):a;return b['toLowerCase']();}function isEmptyAddr(a){return a===null||a===undefined||String(a)['trim']()==='';}function balanceIsZero(a){if(a===null||a===undefined)return![];try{return BigInt(String(a))===0x0n;}catch{return![];}}async function fetchRefs(a,b,c){if(a['length']===0x0)return{'objects':[]};try{const d=await c['queryObjects'](a['map'](g=>g['object']),b),f=new Map();for(const g of d??[]){if(!g)continue;const h=normAddr(g?.['object']);if(h)f['set'](h,g);if(typeof g?.['query_name']==='string')f['set'](normAddr(g['query_name']),g);}return{'objects':a['map'](i=>f['get'](normAddr(i['object'])))};}catch(i){return{'objects':a['map'](()=>undefined),'queryError':'chain\x20query\x20failed:\x20'+(i instanceof Error?i['message']:String(i))};}}function typeMatches(a,b){const c=b?.['type'];if(!c)return!![];return String(c)['toLowerCase']()===a['type']['toLowerCase']();}function refsOfType(a,b){return a['objects']['filter'](c=>c['type']['toLowerCase']()===b['toLowerCase']());}async function checkPublishService(a,b,c){const d=refsOfType(a,'Service'),e=[],f=[];if(d['length']===0x0)return{'complete':![],'evidence':e,'missing':['no\x20Service\x20object\x20registered\x20on\x20the\x20goal']};const {objects:g,queryError:h}=await fetchRefs(d,b,c);if(h)f['push'](h);let i=![];return g['forEach']((j,k)=>{const l=d[k];if(!j){if(!h)f['push']('Service\x20'+l['object']+'\x20not\x20found\x20on\x20chain');return;}if(!typeMatches(l,j)){f['push']('Service\x20'+l['object']+'\x20type\x20mismatch\x20(fetched:\x20'+(j?.['type']??'unknown')+')');return;}if(j['bPaused']!==![]){f['push']('Service\x20'+l['object']+'\x20is\x20paused\x20(bPaused='+String(j['bPaused'])+')');return;}e['push']('Service\x20'+l['object']+'\x20exists\x20and\x20is\x20not\x20paused');const m=Array['isArray'](j['sales'])?j['sales']:[];if(m['length']<0x1){f['push']('Service\x20'+l['object']+'\x20has\x20no\x20purchasable\x20items\x20(sales\x20is\x20empty)');return;}e['push']('Service\x20'+l['object']+'\x20has\x20'+m['length']+'\x20purchasable\x20item(s)');if(isEmptyAddr(j['machine'])){f['push']('Service\x20'+l['object']+'\x20has\x20no\x20Machine\x20bound');return;}e['push']('Service\x20'+l['object']+'\x20has\x20a\x20Machine\x20bound\x20('+j['machine']+')');if(isEmptyAddr(j['permission'])){f['push']('Service\x20'+l['object']+'\x20has\x20no\x20Permission\x20bound');return;}e['push']('Service\x20'+l['object']+'\x20has\x20a\x20Permission\x20bound\x20('+j['permission']+')'),i=!![];}),{'complete':i,'evidence':e,'missing':f};}async function checkPurchaseService(a,b,c){const d=refsOfType(a,'Order'),f=[],g=[];if(d['length']===0x0)return{'complete':![],'evidence':f,'missing':['no\x20Order\x20object\x20registered\x20on\x20the\x20goal']};const {objects:h,queryError:j}=await fetchRefs(d,b,c);if(j)g['push'](j);for(let k=0x0;k<h['length'];k++){const l=h[k],m=d[k];if(!l){if(!j)g['push']('Order\x20'+m['object']+'\x20not\x20found\x20on\x20chain');continue;}f['push']('Order\x20'+m['object']+'\x20exists');if(isEmptyAddr(l['progress'])){g['push']('Order\x20'+m['object']+'\x20has\x20no\x20Progress\x20object');continue;}const o=await fetchRefs([{'type':'Progress','object':String(l['progress'])}],b,c),q=o['objects'][0x0];if(o['queryError']){g['push'](o['queryError']);continue;}if(!q){g['push']('Progress\x20'+l['progress']+'\x20not\x20found\x20on\x20chain');continue;}const r=typeof q['current']==='string'?q['current']:'';let s=![];if(c['fetchMachineNodes']&&!isEmptyAddr(q['machine']))try{const v=await c['fetchMachineNodes'](String(q['machine']),b);if(v['length']===0x0)f['push']('Progress\x20'+l['progress']+'\x20exists\x20(node\x20\x27'+r+'\x27);\x20machine\x20topology\x20empty\x20—\x20terminal\x20check\x20skipped'),s=!![];else{const w=new Set();for(const y of v){for(const z of y['pairs']??[]){if(z['prev_node'])w['add'](z['prev_node']);}}const x=v['some'](A=>A['name']===r);if(x&&!w['has'](r))f['push']('Progress\x20is\x20at\x20terminal\x20node\x20\x27'+r+'\x27'),s=!![];else!x?g['push']('Progress\x20node\x20\x27'+r+'\x27\x20not\x20found\x20in\x20machine\x20topology'):g['push']('Progress\x20node\x20\x27'+r+'\x27\x20is\x20not\x20terminal\x20(has\x20outgoing\x20forwards)');}}catch(A){f['push']('Progress\x20'+l['progress']+'\x20exists\x20(node\x20\x27'+r+'\x27);\x20terminal\x20check\x20skipped:\x20'+(A instanceof Error?A['message']:String(A))),s=!![];}else f['push']('Progress\x20'+l['progress']+'\x20exists\x20(node\x20\x27'+r+'\x27)'),s=!![];if(!s)continue;if(isEmptyAddr(l['allocation']))return f['push']('Order\x20'+m['object']+'\x20has\x20no\x20allocation\x20(nothing\x20to\x20settle)'),{'complete':!![],'evidence':f,'missing':g};if(!isEmptyAddr(l['claimed_by']))return f['push']('Order\x20'+m['object']+'\x20allocation\x20claimed\x20by\x20'+l['claimed_by']),{'complete':!![],'evidence':f,'missing':g};const t=await fetchRefs([{'type':'Allocation','object':String(l['allocation'])}],b,c);if(t['queryError']){g['push'](t['queryError']);continue;}const u=t['objects'][0x0];if(!u){g['push']('Allocation\x20'+l['allocation']+'\x20not\x20found\x20on\x20chain');continue;}if(balanceIsZero(u['balance']))return f['push']('Allocation\x20'+l['allocation']+'\x20balance\x20is\x20zero\x20(settled)'),{'complete':!![],'evidence':f,'missing':g};g['push']('Allocation\x20'+l['allocation']+'\x20still\x20holds\x20balance\x20'+String(u['balance']));}return{'complete':![],'evidence':f,'missing':g};}async function checkPublishDemand(a,b,c){const d=refsOfType(a,'Demand'),e=[],f=[];if(d['length']===0x0)return{'complete':![],'evidence':e,'missing':['no\x20Demand\x20object\x20registered\x20on\x20the\x20goal']};const {objects:g,queryError:h}=await fetchRefs(d,b,c);if(h)f['push'](h);let i=![];return g['forEach']((j,k)=>{const l=d[k];if(!j){if(!h)f['push']('Demand\x20'+l['object']+'\x20not\x20found\x20on\x20chain');return;}e['push']('Demand\x20'+l['object']+'\x20exists');const m=Array['isArray'](j['rewards'])?j['rewards']:[];if(m['length']<0x1){f['push']('Demand\x20'+l['object']+'\x20has\x20no\x20rewards\x20bound');return;}e['push']('Demand\x20'+l['object']+'\x20has\x20'+m['length']+'\x20reward(s)\x20bound'),i=!![];}),{'complete':i,'evidence':e,'missing':f};}async function checkRunArbitration(a,b,c){const d=refsOfType(a,'Arbitration'),e=[],f=[];if(d['length']===0x0)return{'complete':![],'evidence':e,'missing':['no\x20Arbitration\x20object\x20registered\x20on\x20the\x20goal']};const {objects:g,queryError:h}=await fetchRefs(d,b,c);if(h)f['push'](h);let i=![];return g['forEach']((j,k)=>{const l=d[k];if(!j){if(!h)f['push']('Arbitration\x20'+l['object']+'\x20not\x20found\x20on\x20chain');return;}e['push']('Arbitration\x20'+l['object']+'\x20exists');if(j['bPaused']===!![]){f['push']('Arbitration\x20'+l['object']+'\x20is\x20paused');return;}e['push']('Arbitration\x20'+l['object']+'\x20is\x20not\x20paused');if(j['fee']===null||j['fee']===undefined){f['push']('Arbitration\x20'+l['object']+'\x20fee\x20not\x20configured');return;}if(j['balance']===null||j['balance']===undefined){f['push']('Arbitration\x20'+l['object']+'\x20balance\x20not\x20configured');return;}e['push']('Arbitration\x20'+l['object']+'\x20fee='+String(j['fee'])+'\x20balance='+String(j['balance'])),i=!![];}),{'complete':i,'evidence':e,'missing':f};}async function checkExistence(a,b,c){const d=[],e=[];if(a['objects']['length']===0x0)return{'complete':![],'evidence':d,'missing':['no\x20objects\x20registered\x20on\x20the\x20goal']};const {objects:f,queryError:g}=await fetchRefs(a['objects'],b,c);if(g)e['push'](g);return f['forEach']((h,j)=>{const k=a['objects'][j];if(!h){if(!g)e['push'](k['type']+'\x20'+k['object']+'\x20not\x20found\x20on\x20chain');return;}if(!typeMatches(k,h)){e['push'](k['type']+'\x20'+k['object']+'\x20type\x20mismatch\x20(fetched:\x20'+(h?.['type']??'unknown')+')');return;}d['push'](k['type']+'\x20'+k['object']+'\x20exists');}),{'complete':e['length']===0x0,'evidence':d,'missing':e};}export const GOAL_COMPLETION_RULES={'publish_service':checkPublishService,'purchase_service':checkPurchaseService,'publish_demand':checkPublishDemand,'run_arbitration':checkRunArbitration,'fulfill_order':checkExistence,'capture_demand':checkExistence,'collaborate_flow':checkExistence,'supply_suborder':checkExistence,'dispute_resolution':checkExistence,'manage_assets':checkExistence};function defaultDeps(){return{'queryObjects':async(a,b)=>{const {batchQueryObjectsByIds:c}=await import('../graph/onchain/sdk-batch.js');return c(a,b,![]);},'fetchMachineNodes':async(a,b)=>{const {fetchMachineNodes:c}=await import('../graph/onchain/sdk-batch.js');return c(a,b,![]);}};}export async function evaluateGoalCompletion(a,b,c){const d={...defaultDeps(),...c??{}},f=GOAL_COMPLETION_RULES[a['goal_type']]??checkExistence;try{return await f(a,b,d);}catch(g){return{'complete':![],'evidence':[],'missing':['completion\x20check\x20failed:\x20'+(g instanceof Error?g['message']:String(g))]};}}
1
+ function normAddr(a){if(!a)return'';const b=a['startsWith']('0x')?a['slice'](0x2):a;return b['toLowerCase']();}function isEmptyAddr(a){return a===null||a===undefined||String(a)['trim']()==='';}function balanceIsZero(a){if(a===null||a===undefined)return![];try{return BigInt(String(a))===0x0n;}catch{return![];}}async function fetchRefs(a,b,c){if(a['length']===0x0)return{'objects':[]};try{const d=await c['queryObjects'](a['map'](g=>g['object']),b),f=new Map();for(const g of d??[]){if(!g)continue;const h=normAddr(g?.['object']);if(h)f['set'](h,g);if(typeof g?.['query_name']==='string')f['set'](normAddr(g['query_name']),g);}return{'objects':a['map'](i=>f['get'](normAddr(i['object'])))};}catch(i){return{'objects':a['map'](()=>undefined),'queryError':'chain\x20query\x20failed:\x20'+(i instanceof Error?i['message']:String(i))};}}function typeMatches(a,b){const c=b?.['type'];if(!c)return!![];return String(c)['toLowerCase']()===a['type']['toLowerCase']();}function refsOfType(a,b){return a['objects']['filter'](c=>c['type']['toLowerCase']()===b['toLowerCase']());}async function checkPublishService(a,b,c){const d=refsOfType(a,'Service'),e=[],f=[];if(d['length']===0x0)return{'complete':![],'evidence':e,'missing':['no\x20Service\x20object\x20registered\x20on\x20the\x20goal']};const {objects:g,queryError:h}=await fetchRefs(d,b,c);if(h)f['push'](h);let i=![];return g['forEach']((j,k)=>{const l=d[k];if(!j){if(!h)f['push']('Service\x20'+l['object']+'\x20not\x20found\x20on\x20chain');return;}if(!typeMatches(l,j)){f['push']('Service\x20'+l['object']+'\x20type\x20mismatch\x20(fetched:\x20'+(j?.['type']??'unknown')+')');return;}if(j['bPaused']!==![]){f['push']('Service\x20'+l['object']+'\x20is\x20paused\x20(bPaused='+String(j['bPaused'])+')');return;}e['push']('Service\x20'+l['object']+'\x20exists\x20and\x20is\x20not\x20paused');const m=Array['isArray'](j['sales'])?j['sales']:[];if(m['length']<0x1){f['push']('Service\x20'+l['object']+'\x20has\x20no\x20purchasable\x20items\x20(sales\x20is\x20empty)');return;}e['push']('Service\x20'+l['object']+'\x20has\x20'+m['length']+'\x20purchasable\x20item(s)');if(isEmptyAddr(j['machine'])){f['push']('Service\x20'+l['object']+'\x20has\x20no\x20Machine\x20bound');return;}e['push']('Service\x20'+l['object']+'\x20has\x20a\x20Machine\x20bound\x20('+j['machine']+')');if(isEmptyAddr(j['permission'])){f['push']('Service\x20'+l['object']+'\x20has\x20no\x20Permission\x20bound');return;}e['push']('Service\x20'+l['object']+'\x20has\x20a\x20Permission\x20bound\x20('+j['permission']+')'),i=!![];}),{'complete':i,'evidence':e,'missing':f};}async function checkPurchaseService(a,b,c){const d=refsOfType(a,'Order'),f=[],g=[];if(d['length']===0x0)return{'complete':![],'evidence':f,'missing':['no\x20Order\x20object\x20registered\x20on\x20the\x20goal']};const {objects:h,queryError:j}=await fetchRefs(d,b,c);if(j)g['push'](j);for(let k=0x0;k<h['length'];k++){const l=h[k],m=d[k];if(!l){if(!j)g['push']('Order\x20'+m['object']+'\x20not\x20found\x20on\x20chain');continue;}f['push']('Order\x20'+m['object']+'\x20exists');if(isEmptyAddr(l['progress'])){g['push']('Order\x20'+m['object']+'\x20has\x20no\x20Progress\x20object');continue;}const o=await fetchRefs([{'type':'Progress','object':String(l['progress'])}],b,c),q=o['objects'][0x0];if(o['queryError']){g['push'](o['queryError']);continue;}if(!q){g['push']('Progress\x20'+l['progress']+'\x20not\x20found\x20on\x20chain');continue;}const r=typeof q['current']==='string'?q['current']:'';let s=![];if(c['fetchMachineNodes']&&!isEmptyAddr(q['machine']))try{const x=await c['fetchMachineNodes'](String(q['machine']),b);if(x['length']===0x0)f['push']('Progress\x20'+l['progress']+'\x20exists\x20(node\x20\x27'+r+'\x27);\x20machine\x20topology\x20empty\x20—\x20terminal\x20check\x20skipped'),s=!![];else{const y=new Set();for(const A of x){for(const B of A['pairs']??[]){if(B['prev_node'])y['add'](B['prev_node']);}}const z=x['some'](C=>C['name']===r);if(z&&!y['has'](r))f['push']('Progress\x20is\x20at\x20terminal\x20node\x20\x27'+r+'\x27'),s=!![];else!z?g['push']('Progress\x20node\x20\x27'+r+'\x27\x20not\x20found\x20in\x20machine\x20topology'):g['push']('Progress\x20node\x20\x27'+r+'\x27\x20is\x20not\x20terminal\x20(has\x20outgoing\x20forwards)');}}catch(C){f['push']('Progress\x20'+l['progress']+'\x20exists\x20(node\x20\x27'+r+'\x27);\x20terminal\x20check\x20skipped:\x20'+(C instanceof Error?C['message']:String(C))),s=!![];}else f['push']('Progress\x20'+l['progress']+'\x20exists\x20(node\x20\x27'+r+'\x27)'),s=!![];if(!s)continue;let t=![];if(c['pendingWrappers'])try{const D=await c['pendingWrappers'](m['object'],b);if(D['length']===0x0)f['push']('No\x20CoinWrapper\x20pending\x20at\x20Order\x20'+m['object']),t=!![];else for(const E of D){g['push']('CoinWrapper\x20'+E['wrapper_id']+'\x20(amount\x20'+E['amount']+')\x20awaits\x20extraction\x20at\x20Order\x20'+m['object']+':\x20'+('drive\x20'+E['plan']['operation']+(E['plan']['anyone_can_submit']?'\x20(anyone\x20may\x20submit)':'')+';\x20')+E['plan']['steps']['join']('\x20'));}}catch(F){g['push']('pending-wrapper\x20check\x20failed\x20for\x20Order\x20'+m['object']+':\x20'+(F instanceof Error?F['message']:String(F)));}else t=!![];if(!t)continue;if(isEmptyAddr(l['allocation']))return f['push']('Order\x20'+m['object']+'\x20has\x20no\x20allocation\x20(nothing\x20to\x20settle)'),{'complete':!![],'evidence':f,'missing':g};if(!isEmptyAddr(l['claimed_by']))return f['push']('Order\x20'+m['object']+'\x20allocation\x20claimed\x20by\x20'+l['claimed_by']),{'complete':!![],'evidence':f,'missing':g};const u=await fetchRefs([{'type':'Allocation','object':String(l['allocation'])}],b,c);if(u['queryError']){g['push'](u['queryError']);continue;}const v=u['objects'][0x0];if(!v){g['push']('Allocation\x20'+l['allocation']+'\x20not\x20found\x20on\x20chain');continue;}if(balanceIsZero(v['balance']))return f['push']('Allocation\x20'+l['allocation']+'\x20balance\x20is\x20zero\x20(settled)'),{'complete':!![],'evidence':f,'missing':g};g['push']('Allocation\x20'+l['allocation']+'\x20still\x20holds\x20balance\x20'+String(v['balance']));}return{'complete':![],'evidence':f,'missing':g};}async function checkPublishDemand(a,b,c){const d=refsOfType(a,'Demand'),e=[],f=[];if(d['length']===0x0)return{'complete':![],'evidence':e,'missing':['no\x20Demand\x20object\x20registered\x20on\x20the\x20goal']};const {objects:g,queryError:h}=await fetchRefs(d,b,c);if(h)f['push'](h);let i=![];return g['forEach']((j,k)=>{const l=d[k];if(!j){if(!h)f['push']('Demand\x20'+l['object']+'\x20not\x20found\x20on\x20chain');return;}e['push']('Demand\x20'+l['object']+'\x20exists');const m=Array['isArray'](j['rewards'])?j['rewards']:[];if(m['length']<0x1){f['push']('Demand\x20'+l['object']+'\x20has\x20no\x20rewards\x20bound');return;}e['push']('Demand\x20'+l['object']+'\x20has\x20'+m['length']+'\x20reward(s)\x20bound'),i=!![];}),{'complete':i,'evidence':e,'missing':f};}async function checkRunArbitration(a,b,c){const d=refsOfType(a,'Arbitration'),e=[],f=[];if(d['length']===0x0)return{'complete':![],'evidence':e,'missing':['no\x20Arbitration\x20object\x20registered\x20on\x20the\x20goal']};const {objects:g,queryError:h}=await fetchRefs(d,b,c);if(h)f['push'](h);let i=![];return g['forEach']((j,k)=>{const l=d[k];if(!j){if(!h)f['push']('Arbitration\x20'+l['object']+'\x20not\x20found\x20on\x20chain');return;}e['push']('Arbitration\x20'+l['object']+'\x20exists');if(j['bPaused']===!![]){f['push']('Arbitration\x20'+l['object']+'\x20is\x20paused');return;}e['push']('Arbitration\x20'+l['object']+'\x20is\x20not\x20paused');if(j['fee']===null||j['fee']===undefined){f['push']('Arbitration\x20'+l['object']+'\x20fee\x20not\x20configured');return;}if(j['balance']===null||j['balance']===undefined){f['push']('Arbitration\x20'+l['object']+'\x20balance\x20not\x20configured');return;}e['push']('Arbitration\x20'+l['object']+'\x20fee='+String(j['fee'])+'\x20balance='+String(j['balance'])),i=!![];}),{'complete':i,'evidence':e,'missing':f};}async function checkExistence(a,b,c){const d=[],e=[];if(a['objects']['length']===0x0)return{'complete':![],'evidence':d,'missing':['no\x20objects\x20registered\x20on\x20the\x20goal']};const {objects:f,queryError:g}=await fetchRefs(a['objects'],b,c);if(g)e['push'](g);return f['forEach']((h,j)=>{const k=a['objects'][j];if(!h){if(!g)e['push'](k['type']+'\x20'+k['object']+'\x20not\x20found\x20on\x20chain');return;}if(!typeMatches(k,h)){e['push'](k['type']+'\x20'+k['object']+'\x20type\x20mismatch\x20(fetched:\x20'+(h?.['type']??'unknown')+')');return;}d['push'](k['type']+'\x20'+k['object']+'\x20exists');}),{'complete':e['length']===0x0,'evidence':d,'missing':e};}export const GOAL_COMPLETION_RULES={'publish_service':checkPublishService,'purchase_service':checkPurchaseService,'publish_demand':checkPublishDemand,'run_arbitration':checkRunArbitration,'fulfill_order':checkExistence,'capture_demand':checkExistence,'collaborate_flow':checkExistence,'supply_suborder':checkExistence,'dispute_resolution':checkExistence,'manage_assets':checkExistence};function defaultDeps(){return{'queryObjects':async(a,b)=>{const {batchQueryObjectsByIds:c}=await import('../graph/onchain/sdk-batch.js');return c(a,b,![]);},'fetchMachineNodes':async(a,b)=>{const {fetchMachineNodes:c}=await import('../graph/onchain/sdk-batch.js');return c(a,b,![]);},'pendingWrappers':async(a,b)=>{const {pendingWrappersAt:c}=await import('./payment-tracker.js'),d=await c(a,{'network':b});return d['map'](e=>({'wrapper_id':e['wrapper_id'],'payment':e['payment'],'amount':e['amount'],'plan':{'operation':e['plan']['operation'],'anyone_can_submit':e['plan']['anyone_can_submit'],...e['plan']['permission_index']!=null?{'permission_index':e['plan']['permission_index']}:{},'settles_to':e['plan']['settles_to'],'steps':e['plan']['steps']}}));}};}export async function evaluateGoalCompletion(a,b,c){const d={...defaultDeps(),...c??{}},f=GOAL_COMPLETION_RULES[a['goal_type']]??checkExistence;try{return await f(a,b,d);}catch(g){return{'complete':![],'evidence':[],'missing':['completion\x20check\x20failed:\x20'+(g instanceof Error?g['message']:String(g))]};}}