@wowok/agent-mcp 3.2.1 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/communication/wts-attestation.d.ts +34 -0
- package/dist/communication/wts-attestation.js +1 -0
- package/dist/config/judgment.d.ts +25 -0
- package/dist/config/rule-engine.d.ts +10 -0
- package/dist/config/rule-engine.js +1 -1
- package/dist/evaluation/builtins/graph-service.spec.js +1 -1
- package/dist/evaluation/engine.js +1 -1
- package/dist/experience/realtime-feedback.js +1 -1
- package/dist/extensions/industry-pack.js +1 -1
- package/dist/graph/onchain/expand.js +1 -1
- package/dist/graph/onchain/exposure.js +1 -1
- package/dist/knowledge/allocation-risk.d.ts +2 -1
- package/dist/knowledge/allocation-risk.js +1 -1
- package/dist/knowledge/allocation-templates.js +1 -1
- package/dist/knowledge/audit-rules.js +1 -1
- package/dist/knowledge/baselines/rules/allocation.json +31 -1
- package/dist/knowledge/builtin-templates.d.ts +3 -1
- package/dist/knowledge/builtin-templates.js +1 -1
- package/dist/knowledge/entity-recipient-guard.d.ts +21 -0
- package/dist/knowledge/entity-recipient-guard.js +1 -0
- package/dist/knowledge/getting-started.js +1 -1
- package/dist/knowledge/guard-templates.js +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/industry-registry.js +1 -1
- package/dist/knowledge/jsonrpc-enum.js +1 -1
- package/dist/knowledge/machine-topology.d.ts +34 -0
- package/dist/knowledge/machine-topology.js +1 -1
- package/dist/knowledge/scenario-modes.d.ts +1 -0
- package/dist/knowledge/scenario-modes.js +1 -1
- package/dist/knowledge/strategy-manuals.js +1 -1
- package/dist/knowledge/template-loader.d.ts +21 -0
- package/dist/knowledge/template-loader.js +1 -1
- package/dist/knowledge/template-registry.js +1 -1
- package/dist/knowledge/template-scanner.js +1 -1
- package/dist/knowledge/tool-constraints.js +1 -1
- package/dist/knowledge/tools-reference.js +1 -1
- package/dist/knowledge/workflow-guidance.d.ts +4 -0
- package/dist/knowledge/workflow-guidance.js +1 -1
- package/dist/monitor/MonitorLoop.js +1 -1
- package/dist/playbooks/service-build/business-puzzle.js +1 -1
- package/dist/playbooks/service-build/index.d.ts +1 -0
- package/dist/playbooks/service-build/intent-analyzer.d.ts +1 -0
- package/dist/playbooks/service-build/intent-analyzer.js +1 -1
- package/dist/playbooks/service-build/machine-nodes.d.ts +1 -1
- package/dist/playbooks/service-build/machine-nodes.js +1 -1
- package/dist/playbooks/service-build/machine-panorama.js +1 -1
- package/dist/playbooks/service-build/object-panorama.d.ts +27 -1
- package/dist/playbooks/service-build/object-panorama.js +1 -1
- package/dist/playbooks/service-build/participation-radar.js +1 -1
- package/dist/playbooks/service-build/pipeline-actions.d.ts +4 -0
- package/dist/playbooks/service-build/pipeline-actions.js +1 -1
- package/dist/playbooks/service-build/relationship-profile.js +1 -1
- package/dist/playbooks/service-build/semantic-graph.d.ts +1 -0
- package/dist/playbooks/service-build/semantic-graph.js +1 -1
- package/dist/playbooks/service-build/service-panorama.js +1 -1
- package/dist/playbooks/service-build/service-quote.js +1 -1
- package/dist/review/index.js +1 -1
- package/dist/safety/confirm-gate.js +1 -1
- package/dist/schema/call/machine.d.ts +1 -0
- package/dist/schema/call/machine.js +1 -1
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.js +1 -1
- package/dist/schema/common/index.js +1 -1
- package/dist/schema/goal/planning.d.ts +7 -0
- package/dist/schema/goal/planning.js +1 -1
- package/dist/schema/industry-pack/index.d.ts +24 -0
- package/dist/schema/industry-pack/index.js +1 -1
- package/dist/schema/local/index.js +1 -1
- package/dist/schema/messenger/index.d.ts +20 -0
- package/dist/schema/messenger/index.js +1 -1
- package/dist/schema/operations.d.ts +2 -0
- package/dist/schema/persona/index.d.ts +110 -0
- package/dist/schema/query/bi.d.ts +2 -0
- package/dist/schema/query/bi.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema/utils/node-parser.js +1 -1
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/industry_pack_operation.output.json +109 -0
- package/dist/schemas/industry_pack_operation.schema.json +3 -1
- package/dist/schemas/messenger_operation.output.json +42 -4
- package/dist/schemas/onchain_operations.schema.json +5 -5
- package/dist/schemas/onchain_operations_machine.schema.json +2 -2
- package/dist/schemas/onchain_operations_service.schema.json +3 -3
- package/dist/schemas/onchain_table_data.output.json +5 -1
- package/dist/schemas/persona_operation.output.json +266 -0
- package/dist/schemas/persona_operation.schema.json +42 -0
- package/dist/schemas/query_toolkit.output.json +1 -1
- package/dist/schemas/query_toolkit.schema.json +5 -1
- package/dist/tools/handlers/benchmark-migration.d.ts +17 -0
- package/dist/tools/handlers/benchmark-migration.js +1 -1
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/industry-pack.js +1 -1
- package/dist/tools/handlers/messenger.js +1 -1
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/registry/business.js +1 -1
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EDGE_SCHEMAS,EDGE_SCHEMA_BY_ID}from'./edge-schema.js';import{extractCoinType,extractEventRefs,extractObjectEdges,extractReverseRefs,extractTableRefs,inferObjectType,REVERSE_GROUP_WILDCARD}from'./extract.js';import{mergeBudget}from'./dataplane.js';import{deriveOrderCompletion,terminalNamesOfEdges}from'./order-status.js';import{LINKER_RING_LIMIT as a83a}from'./sdk-batch.js';import{wowAddressKind}from'@wowok/wowok';function readStats(a){const b=a;if(b['stats'])return{'batches':b['stats']['batches'],'byChannel':{...b['stats']['byChannel']},'dedupHits':b['stats']['dedupHits']};if(b['batches'])return{'batches':Object['values'](b['batches'])['reduce']((c,d)=>c+d,0x0),'byChannel':{...b['batches']},'dedupHits':b['dedupHits']??0x0};return{'batches':0x0,'byChannel':{'objects':0x0,'keyedFields':0x0,'tables':0x0,'events':0x0},'dedupHits':0x0};}function isEoa(a){return wowAddressKind(a)==='user';}function isWfNodeId(a){return a['includes']('::node::');}class Gate{['wl'];constructor(a){this['wl']=a;}['allows'](a,b){if(this['wl']['deny']?.['includes'](a['id']))return![];const c=this['wl']['familyDepths']?.[a['family']];if(c!==undefined&&b>=c)return![];if(this['wl']['schemas'])return this['wl']['schemas']['includes'](a['id']);if(this['wl']['families']&&!this['wl']['families']['includes'](a['family']))return![];return!![];}['allowsTable'](a,b){if(a['read']['kind']!=='table')return![];if(this['wl']['deny']?.['includes'](a['id']))return![];const c=this['wl']['familyDepths']?.[a['family']];if(c!==undefined&&b>=c)return![];if(this['wl']['families']&&!this['wl']['families']['includes'](a['family']))return![];return!!this['wl']['tableEdges']?.['includes'](a['id']);}['allowsEvent'](a,b){if(a['read']['kind']!=='event')return![];if(this['wl']['deny']?.['includes'](a['id']))return![];const c=this['wl']['familyDepths']?.[a['family']];if(c!==undefined&&b>=c)return![];if(this['wl']['families']&&!this['wl']['families']['includes'](a['family']))return![];return!!this['wl']['eventEdges']?.['includes'](a['id']);}['effectiveMaxHops'](a){const b=a['maxHops'],c=this['wl']['schemaHops']?.[a['id']];if(b===undefined)return c;if(c===undefined)return b;return Math['min'](b,c);}}class GraphBuilder{['graph'];['edgeIds']=new Set();['budget'];['exhausted']={};constructor(a,b,c){this['budget']=c,this['graph']={'network':a,'seed':b,'builtAt':Date['now'](),'nodes':new Map(),'edges':[],'out':new Map(),'inc':new Map(),'gaps':[],'truncations':[],'rpcReport':{'batches':0x0,'byChannel':{'objects':0x0,'keyedFields':0x0,'tables':0x0,'events':0x0},'dedupHits':0x0},'budgetExhausted':{}};}['addSeed'](a){const b=inferObjectType(a),c={'id':a,'kind':isWfNodeId(a)?'wfnode':isEoa(a)?'eoa':'object','objectType':b??undefined,'state':'seed','origins':[],'depth':0x0};return this['graph']['nodes']['set'](a,c),c;}['addNode'](a,b,c){const d=this['graph']['nodes']['get'](a);if(d){if(c)d['origins']['push']({'via':c['schema'],'from':c['from'],'depth':b});return d;}if(this['graph']['nodes']['size']>=this['budget']['maxNodes'])return this['exhausted']['nodes']=!![],undefined;const e=isWfNodeId(a),f=e?undefined:inferObjectType(a),g={'id':a,'kind':e?'wfnode':isEoa(a)?'eoa':'object','objectType':f??undefined,'state':e?'stub':'seed','origins':c?[{'via':c['schema'],'from':c['from'],'depth':b}]:[],'depth':b};return this['graph']['nodes']['set'](a,g),g;}['addEdge'](a,b,c,d,e){const f=c['to'],g=c['key']?'|'+c['key']:'',h=a['id']+'|'+b+'→'+f+g;if(this['edgeIds']['has'](h))return;this['edgeIds']['add'](h);const i={'id':h,'schema':a['id'],'family':a['family'],'from':b,'to':f,'retention':a['retention'],'observedAt':d,'payload':c['payload'],'truncated':e||a['retention']==='bounded_window','key':c['key']};this['graph']['edges']['push'](i),pushMap(this['graph']['out'],b,i),pushMap(this['graph']['inc'],f,i);}['markTruncation'](a){this['graph']['truncations']['push'](a);}['finalize'](a){return this['graph']['rpcReport']=readStats(a),this['graph']['budgetExhausted']=this['exhausted'],this['graph'];}}function pushMap(a,b,c){const d=a['get'](b);if(d)d['push'](c);else a['set'](b,[c]);}export async function expandTopology(a,c){const d=c['seed']['toLowerCase'](),e=mergeBudget(c['budget']),f=new Gate(c['edges']??{}),h=new GraphBuilder(c['network'],d,e);h['addSeed'](d);const i=new Set(),j=new Set(),l=new Set(),m=new Map(),n=new Set();let o=new Set([d]);for(let p=0x0;p<=e['maxDepth'];p++){if(o['size']===0x0)break;if(h['exhausted']['nodes'])break;const q=Date['now'](),r=new Map(),t=(D,E)=>{const F=r['get'](D);if(F)return F;const G=new Map();r['set'](D,G);const H=h['graph']['nodes']['get'](D);if(H&&H['origins']['length']>0x0&&!E['has'](D)){E['add'](D);for(const I of H['origins']){if(!I['via']||!I['from']||E['has'](I['from']))continue;const J=t(I['from'],E);for(const [L,M]of J){if(M<(G['get'](L)??Infinity))G['set'](L,M);}const K=(J['get'](I['via'])??0x0)+0x1;if(K<(G['get'](I['via'])??Infinity))G['set'](I['via'],K);}E['delete'](D);}return G;},u=[...o]['filter'](D=>{const E=h['graph']['nodes']['get'](D);return E['kind']==='object'&&(E['state']==='seed'||E['state']==='stub')&&!i['has'](D);}),v=new Set();if(u['length']>0x0){const D=await a['getObjects'](u);if(readStats(a)['batches']>=e['maxRpcs'])h['exhausted']['rpcs']=!![];for(const E of u){const F=h['graph']['nodes']['get'](E),G=lookupMapLower(D,E);i['add'](E);if(!G){F['state']='error',F['error']='not_found_or_failed',h['graph']['gaps']['push'](E);continue;}F['state']='fetched',F['raw']=G,F['objectType']=String(G['type']??F['objectType']??inferObjectType(E)??''),F['coinType']=extractCoinType(G['type_raw']),v['add'](E);}}const w=[];for(const H of v){const I=h['graph']['nodes']['get'](H);if(!I['objectType']||!I['raw'])continue;for(const J of extractObjectEdges(I['objectType'],I['raw'])){const K=EDGE_SCHEMA_BY_ID['get'](J['schemaId']);if(!K||!f['allows'](K,p))continue;w['push']({'schema':K,'sourceId':H,'refs':J['refs'],'observed':J['refs']['length']});}}const x=[...v]['filter'](L=>{const M=h['graph']['nodes']['get'](L);return EDGE_SCHEMAS['some'](N=>N['source']===M['objectType']&&N['read']['kind']==='table');});for(const L of x){const M=h['graph']['nodes']['get'](L),N=EDGE_SCHEMAS['filter'](P=>P['source']===M['objectType']&&P['read']['kind']==='table'&&f['allowsTable'](P,p)),O=new Map();for(const P of N){const Q=P['read']['rowType'],R=O['get'](Q)??[];R['push'](P),O['set'](Q,R);}for(const [S,T]of O){const U=L+'|'+S;if(l['has'](U))continue;l['add'](U);const V=Math['max'](...T['map'](a0=>e['perKindCaps'][a0['id']]??e['maxFanoutPerNode']));let W,X=![];try{const a0=await a['getTable'](L,{'maxItems':V});if(readStats(a)['batches']>=e['maxRpcs'])h['exhausted']['rpcs']=!![];W=a0['items'],X=a0['truncated'];}catch{h['graph']['gaps']['push'](L+'#'+S);continue;}const Y=new Set(T['map'](a1=>a1['id'])),Z=extractTableRefs(S,L,W)['filter'](a1=>{const a2=EDGE_SCHEMA_BY_ID['get'](a1['schemaId']);return a2['read']['kind']==='derived'||Y['has'](a1['schemaId']);});for(const a1 of Z){const a2=EDGE_SCHEMA_BY_ID['get'](a1['schemaId']);let a3=a1['refs'];a2['family']==='M'&&M['coinType']&&(a3=a3['map'](a4=>({...a4,'payload':{'coinType':M['coinType'],...a4['payload']}}))),w['push']({'schema':a2,'sourceId':L,'refs':a3,'observed':a3['length']});}X&&h['markTruncation']({'nodeId':L,'schema':T[0x0]['id'],'observed':W['length'],'limit':V,'reason':'table_page'});}}const y=[...o]['filter'](a4=>{const a5=h['graph']['nodes']['get'](a4);return a5['kind']!=='wfnode'&&(a5['kind']==='eoa'||a5['state']==='fetched');}),z=new Map(),A=new Map();for(const a4 of y){const a5=h['graph']['nodes']['get'](a4);for(const a6 of EDGE_SCHEMAS){if(a6['read']['kind']!=='reverse'||!f['allows'](a6,p))continue;if(!sourceMatches(a6['source'],a5))continue;const a7=a6['read']['parent'],a8=a4+'|'+a7;if(j['has'](a8))continue;if(!z['has'](a7))z['set'](a7,[]);z['get'](a7)['push'](a4);const a9=a4+'|'+a7+'|schema',aa=A['get'](a9)??[];aa['push'](a6),A['set'](a9,aa);}}for(const [ab,ac]of z){for(const ae of ac)j['add'](ae+'|'+ab);let ad=new Map();try{ad=await a['getKeyedFields'](ab,ac);if(readStats(a)['batches']>=e['maxRpcs'])h['exhausted']['rpcs']=!![];}catch{h['graph']['gaps']['push']('reverse:'+ab);continue;}for(const af of ac){const ag=A['get'](af+'|'+ab+'|schema')??[],ah=lookupMapLower(ad,af);if(!ah)continue;const ai=extractReverseRefs(ab,ah['data']??ah);for(const aj of ag){const ak=aj['read'];for(const al of ai){if(al['schemaId']!==REVERSE_GROUP_WILDCARD&&al['schemaId']!==aj['id'])continue;let am=al['refs']['map'](an=>an['to']?an:{...an,'to':af});ak['kind']==='reverse'&&ak['filterType']&&(am=am['filter'](an=>inferObjectType(an['to'])===ak['filterType']));if(am['length']===0x0)continue;w['push']({'schema':aj,'sourceId':af,'refs':am,'observed':am['length']});}}}}for(const an of EDGE_SCHEMAS){const ao=an['read'];if(ao['kind']!=='event'||!f['allowsEvent'](an,p))continue;const ap=[...o]['filter'](ar=>{if(n['has'](ar+'|'+an['id']))return![];return sourceMatches(an['source'],h['graph']['nodes']['get'](ar));});if(ap['length']===0x0)continue;let aq=m['get'](ao['eventType']);if(!aq){aq={'events':[],'truncated':![],'failed':![]};try{const ar=await a['getEvents'](ao['eventType'],{'maxPages':e['maxEventPages']});if(readStats(a)['batches']>=e['maxRpcs'])h['exhausted']['rpcs']=!![];aq['events']=ar['events'],aq['truncated']=ar['truncated'],ar['truncated']&&ar['events']['length']===0x0&&(aq['failed']=!![],h['graph']['gaps']['push']('events:'+ao['eventType']));}catch{aq['failed']=!![],h['graph']['gaps']['push']('events:'+ao['eventType']);}m['set'](ao['eventType'],aq);}if(aq['failed']){for(const as of ap)n['add'](as+'|'+an['id']);continue;}if(aq['truncated']){h['exhausted']['eventPages']=!![];for(const at of ap){h['markTruncation']({'nodeId':at,'schema':an['id'],'observed':aq['events']['length'],'limit':e['maxEventPages'],'reason':'event_pages'});}}for(const au of ap){n['add'](au+'|'+an['id']);const av=extractEventRefs(ao,au,aq['events']);if(av['length']===0x0)continue;w['push']({'schema':an,'sourceId':au,'refs':av,'observed':av['length'],'truncated':aq['truncated']});}}const B=new Set(),C=new Map();for(const aw of w){const ax=e['perKindCaps'][aw['schema']['id']]??e['maxFanoutPerNode'],ay=C['get'](aw['sourceId'])??0x0,az=Math['max'](0x0,e['maxFanoutPerNode']-ay),aA=Math['min'](ax,az),aB=aw['refs']['slice'](0x0,aA);aw['refs']['length']>aA&&h['markTruncation']({'nodeId':aw['sourceId'],'schema':aw['schema']['id'],'observed':aw['refs']['length'],'limit':a83a,'reason':'fanout'});const aC=new Map();for(const aD of aB){const aE=aD['from']??aw['sourceId'],aF=isWfNodeId(aD['to'])?p:p+0x1,aG=h['graph']['nodes']['has'](aD['to']),aH=f['effectiveMaxHops'](aw['schema']);if(aH!==undefined){const aJ=(t(aE,new Set())['get'](aw['schema']['id'])??0x0)+0x1;if(aJ>aH&&!aG){aC['set'](aE,(aC['get'](aE)??0x0)+0x1);continue;}}if(aF>e['maxDepth']&&!aG){h['exhausted']['depth']=!![];continue;}const aI=h['addNode'](aD['to'],Math['min'](aF,e['maxDepth']),{'schema':aw['schema']['id'],'from':aE});if(!aI)break;h['addEdge'](aw['schema'],aE,aD,q,aw['truncated']===!![]||aw['refs']['length']>aA),C['set'](aw['sourceId'],ay+0x1);if(!isWfNodeId(aD['to'])&&aF<=e['maxDepth'])B['add'](aD['to']);}for(const [aK,aL]of aC){h['markTruncation']({'nodeId':aK,'schema':aw['schema']['id'],'observed':aL,'limit':f['effectiveMaxHops'](aw['schema'])??0x0,'reason':'schema_hops'});}}if(h['exhausted']['rpcs']){h['graph']['gaps']['push']('budget:maxRpcs');break;}o=B;}return h['finalize'](a);}function sourceMatches(a,b){if(a==='ANY')return!![];if(a==='EOA')return b['kind']==='eoa';return b['objectType']===a;}function lookupMapLower(a,b){const c=a['get'](b);if(c!==undefined)return c;for(const [d,e]of a)if(d['toLowerCase']()===b)return e;return undefined;}export function orderCompletionInGraph(a,b){const c=a['nodes']['get'](b['toLowerCase']()),d=c?.['raw']?.['data']??c?.['raw']??{},e=String(d['machine']??''),f=String(d['progress']??''),g=a['nodes']['get'](f['toLowerCase']()),h=String((g?.['raw']?.['data']??g?.['raw']??{})['current']??'');let i=null;if(e){const j=e['toLowerCase']()+'::node::',k=a['edges']['filter'](l=>l['schema']==='wf.transition'&&l['from']['startsWith'](j))['map'](l=>({'node':l['payload']?.['node'],'prev_node':l['payload']?.['prevNode']}));if(k['length']>0x0)i=terminalNamesOfEdges(k);}return deriveOrderCompletion({'machine':e||null,'progress':f||null,'currentNode':h||null,'terminalNames':i});}
|
|
1
|
+
import{EDGE_SCHEMAS,EDGE_SCHEMA_BY_ID}from'./edge-schema.js';import{extractCoinType,extractEventRefs,extractObjectEdges,extractReverseRefs,extractTableRefs,inferObjectType,REVERSE_GROUP_WILDCARD}from'./extract.js';import{mergeBudget}from'./dataplane.js';import{deriveOrderCompletion,terminalNamesOfEdges}from'./order-status.js';import{LINKER_RING_LIMIT as a84a}from'./sdk-batch.js';import{wowAddressKind}from'@wowok/wowok';function readStats(a){const b=a;if(b['stats'])return{'batches':b['stats']['batches'],'byChannel':{...b['stats']['byChannel']},'dedupHits':b['stats']['dedupHits']};if(b['batches'])return{'batches':Object['values'](b['batches'])['reduce']((c,d)=>c+d,0x0),'byChannel':{...b['batches']},'dedupHits':b['dedupHits']??0x0};return{'batches':0x0,'byChannel':{'objects':0x0,'keyedFields':0x0,'tables':0x0,'events':0x0},'dedupHits':0x0};}function isEoa(a){return wowAddressKind(a)==='user';}function isWfNodeId(a){return a['includes']('::node::');}class Gate{['wl'];constructor(a){this['wl']=a;}['allows'](a,b){if(this['wl']['deny']?.['includes'](a['id']))return![];const c=this['wl']['familyDepths']?.[a['family']];if(c!==undefined&&b>=c)return![];if(this['wl']['schemas'])return this['wl']['schemas']['includes'](a['id']);if(this['wl']['families']&&!this['wl']['families']['includes'](a['family']))return![];return!![];}['allowsTable'](a,b){if(a['read']['kind']!=='table')return![];if(this['wl']['deny']?.['includes'](a['id']))return![];const c=this['wl']['familyDepths']?.[a['family']];if(c!==undefined&&b>=c)return![];if(this['wl']['families']&&!this['wl']['families']['includes'](a['family']))return![];return!!this['wl']['tableEdges']?.['includes'](a['id']);}['allowsEvent'](a,b){if(a['read']['kind']!=='event')return![];if(this['wl']['deny']?.['includes'](a['id']))return![];const c=this['wl']['familyDepths']?.[a['family']];if(c!==undefined&&b>=c)return![];if(this['wl']['families']&&!this['wl']['families']['includes'](a['family']))return![];return!!this['wl']['eventEdges']?.['includes'](a['id']);}['effectiveMaxHops'](a){const b=a['maxHops'],c=this['wl']['schemaHops']?.[a['id']];if(b===undefined)return c;if(c===undefined)return b;return Math['min'](b,c);}}class GraphBuilder{['graph'];['edgeIds']=new Set();['budget'];['exhausted']={};constructor(a,b,c){this['budget']=c,this['graph']={'network':a,'seed':b,'builtAt':Date['now'](),'nodes':new Map(),'edges':[],'out':new Map(),'inc':new Map(),'gaps':[],'truncations':[],'rpcReport':{'batches':0x0,'byChannel':{'objects':0x0,'keyedFields':0x0,'tables':0x0,'events':0x0},'dedupHits':0x0},'budgetExhausted':{}};}['addSeed'](a){const b=inferObjectType(a),c={'id':a,'kind':isWfNodeId(a)?'wfnode':isEoa(a)?'eoa':'object','objectType':b??undefined,'state':'seed','origins':[],'depth':0x0};return this['graph']['nodes']['set'](a,c),c;}['addNode'](a,b,c){const d=this['graph']['nodes']['get'](a);if(d){if(c)d['origins']['push']({'via':c['schema'],'from':c['from'],'depth':b});return d;}if(this['graph']['nodes']['size']>=this['budget']['maxNodes'])return this['exhausted']['nodes']=!![],undefined;const e=isWfNodeId(a),f=e?undefined:inferObjectType(a),g={'id':a,'kind':e?'wfnode':isEoa(a)?'eoa':'object','objectType':f??undefined,'state':e?'stub':'seed','origins':c?[{'via':c['schema'],'from':c['from'],'depth':b}]:[],'depth':b};return this['graph']['nodes']['set'](a,g),g;}['addEdge'](a,b,c,d,e){const f=c['to'],g=c['key']?'|'+c['key']:'',h=a['id']+'|'+b+'→'+f+g;if(this['edgeIds']['has'](h))return;this['edgeIds']['add'](h);const i={'id':h,'schema':a['id'],'family':a['family'],'from':b,'to':f,'retention':a['retention'],'observedAt':d,'payload':c['payload'],'truncated':e||a['retention']==='bounded_window','key':c['key']};this['graph']['edges']['push'](i),pushMap(this['graph']['out'],b,i),pushMap(this['graph']['inc'],f,i);}['markTruncation'](a){this['graph']['truncations']['push'](a);}['finalize'](a){return this['graph']['rpcReport']=readStats(a),this['graph']['budgetExhausted']=this['exhausted'],this['graph'];}}function pushMap(a,b,c){const d=a['get'](b);if(d)d['push'](c);else a['set'](b,[c]);}export async function expandTopology(a,c){const d=c['seed']['toLowerCase'](),e=mergeBudget(c['budget']),f=new Gate(c['edges']??{}),h=new GraphBuilder(c['network'],d,e);h['addSeed'](d);const i=new Set(),j=new Set(),l=new Set(),m=new Map(),n=new Set();let o=new Set([d]);for(let p=0x0;p<=e['maxDepth'];p++){if(o['size']===0x0)break;if(h['exhausted']['nodes'])break;const q=Date['now'](),r=new Map(),t=(D,E)=>{const F=r['get'](D);if(F)return F;const G=new Map();r['set'](D,G);const H=h['graph']['nodes']['get'](D);if(H&&H['origins']['length']>0x0&&!E['has'](D)){E['add'](D);for(const I of H['origins']){if(!I['via']||!I['from']||E['has'](I['from']))continue;const J=t(I['from'],E);for(const [L,M]of J){if(M<(G['get'](L)??Infinity))G['set'](L,M);}const K=(J['get'](I['via'])??0x0)+0x1;if(K<(G['get'](I['via'])??Infinity))G['set'](I['via'],K);}E['delete'](D);}return G;},u=[...o]['filter'](D=>{const E=h['graph']['nodes']['get'](D);return E['kind']==='object'&&(E['state']==='seed'||E['state']==='stub')&&!i['has'](D);}),v=new Set();if(u['length']>0x0){const D=await a['getObjects'](u);if(readStats(a)['batches']>=e['maxRpcs'])h['exhausted']['rpcs']=!![];for(const E of u){const F=h['graph']['nodes']['get'](E),G=lookupMapLower(D,E);i['add'](E);if(!G){F['state']='error',F['error']='not_found_or_failed',h['graph']['gaps']['push'](E);continue;}F['state']='fetched',F['raw']=G,F['objectType']=String(G['type']??F['objectType']??inferObjectType(E)??''),F['coinType']=extractCoinType(G['type_raw']),v['add'](E);}}const w=[];for(const H of v){const I=h['graph']['nodes']['get'](H);if(!I['objectType']||!I['raw'])continue;for(const J of extractObjectEdges(I['objectType'],I['raw'])){const K=EDGE_SCHEMA_BY_ID['get'](J['schemaId']);if(!K||!f['allows'](K,p))continue;w['push']({'schema':K,'sourceId':H,'refs':J['refs'],'observed':J['refs']['length']});}}const x=[...v]['filter'](L=>{const M=h['graph']['nodes']['get'](L);return EDGE_SCHEMAS['some'](N=>N['source']===M['objectType']&&N['read']['kind']==='table');});for(const L of x){const M=h['graph']['nodes']['get'](L),N=EDGE_SCHEMAS['filter'](P=>P['source']===M['objectType']&&P['read']['kind']==='table'&&f['allowsTable'](P,p)),O=new Map();for(const P of N){const Q=P['read']['rowType'],R=O['get'](Q)??[];R['push'](P),O['set'](Q,R);}for(const [S,T]of O){const U=L+'|'+S;if(l['has'](U))continue;l['add'](U);const V=Math['max'](...T['map'](a0=>e['perKindCaps'][a0['id']]??e['maxFanoutPerNode']));let W,X=![];try{const a0=await a['getTable'](L,{'maxItems':V});if(readStats(a)['batches']>=e['maxRpcs'])h['exhausted']['rpcs']=!![];W=a0['items'],X=a0['truncated'];}catch{h['graph']['gaps']['push'](L+'#'+S);continue;}const Y=new Set(T['map'](a1=>a1['id'])),Z=extractTableRefs(S,L,W)['filter'](a1=>{const a2=EDGE_SCHEMA_BY_ID['get'](a1['schemaId']);return a2['read']['kind']==='derived'||Y['has'](a1['schemaId']);});for(const a1 of Z){const a2=EDGE_SCHEMA_BY_ID['get'](a1['schemaId']);let a3=a1['refs'];a2['family']==='M'&&M['coinType']&&(a3=a3['map'](a4=>({...a4,'payload':{'coinType':M['coinType'],...a4['payload']}}))),w['push']({'schema':a2,'sourceId':L,'refs':a3,'observed':a3['length']});}X&&h['markTruncation']({'nodeId':L,'schema':T[0x0]['id'],'observed':W['length'],'limit':V,'reason':'table_page'});}}const y=[...o]['filter'](a4=>{const a5=h['graph']['nodes']['get'](a4);return a5['kind']!=='wfnode'&&(a5['kind']==='eoa'||a5['state']==='fetched');}),z=new Map(),A=new Map();for(const a4 of y){const a5=h['graph']['nodes']['get'](a4);for(const a6 of EDGE_SCHEMAS){if(a6['read']['kind']!=='reverse'||!f['allows'](a6,p))continue;if(!sourceMatches(a6['source'],a5))continue;const a7=a6['read']['parent'],a8=a4+'|'+a7;if(j['has'](a8))continue;if(!z['has'](a7))z['set'](a7,[]);z['get'](a7)['push'](a4);const a9=a4+'|'+a7+'|schema',aa=A['get'](a9)??[];aa['push'](a6),A['set'](a9,aa);}}for(const [ab,ac]of z){for(const ae of ac)j['add'](ae+'|'+ab);let ad=new Map();try{ad=await a['getKeyedFields'](ab,ac);if(readStats(a)['batches']>=e['maxRpcs'])h['exhausted']['rpcs']=!![];}catch{h['graph']['gaps']['push']('reverse:'+ab);continue;}for(const af of ac){const ag=A['get'](af+'|'+ab+'|schema')??[],ah=lookupMapLower(ad,af);if(!ah)continue;const ai=extractReverseRefs(ab,ah['data']??ah);for(const aj of ag){const ak=aj['read'];for(const al of ai){if(al['schemaId']!==REVERSE_GROUP_WILDCARD&&al['schemaId']!==aj['id'])continue;let am=al['refs']['map'](an=>an['to']?an:{...an,'to':af});ak['kind']==='reverse'&&ak['filterType']&&(am=am['filter'](an=>inferObjectType(an['to'])===ak['filterType']));if(am['length']===0x0)continue;w['push']({'schema':aj,'sourceId':af,'refs':am,'observed':am['length']});}}}}for(const an of EDGE_SCHEMAS){const ao=an['read'];if(ao['kind']!=='event'||!f['allowsEvent'](an,p))continue;const ap=[...o]['filter'](ar=>{if(n['has'](ar+'|'+an['id']))return![];return sourceMatches(an['source'],h['graph']['nodes']['get'](ar));});if(ap['length']===0x0)continue;let aq=m['get'](ao['eventType']);if(!aq){aq={'events':[],'truncated':![],'failed':![]};try{const ar=await a['getEvents'](ao['eventType'],{'maxPages':e['maxEventPages']});if(readStats(a)['batches']>=e['maxRpcs'])h['exhausted']['rpcs']=!![];aq['events']=ar['events'],aq['truncated']=ar['truncated'],ar['truncated']&&ar['events']['length']===0x0&&(aq['failed']=!![],h['graph']['gaps']['push']('events:'+ao['eventType']));}catch{aq['failed']=!![],h['graph']['gaps']['push']('events:'+ao['eventType']);}m['set'](ao['eventType'],aq);}if(aq['failed']){for(const as of ap)n['add'](as+'|'+an['id']);continue;}if(aq['truncated']){h['exhausted']['eventPages']=!![];for(const at of ap){h['markTruncation']({'nodeId':at,'schema':an['id'],'observed':aq['events']['length'],'limit':e['maxEventPages'],'reason':'event_pages'});}}for(const au of ap){n['add'](au+'|'+an['id']);const av=extractEventRefs(ao,au,aq['events']);if(av['length']===0x0)continue;w['push']({'schema':an,'sourceId':au,'refs':av,'observed':av['length'],'truncated':aq['truncated']});}}const B=new Set(),C=new Map();for(const aw of w){const ax=e['perKindCaps'][aw['schema']['id']]??e['maxFanoutPerNode'],ay=C['get'](aw['sourceId'])??0x0,az=Math['max'](0x0,e['maxFanoutPerNode']-ay),aA=Math['min'](ax,az),aB=aw['refs']['slice'](0x0,aA);aw['refs']['length']>aA&&h['markTruncation']({'nodeId':aw['sourceId'],'schema':aw['schema']['id'],'observed':aw['refs']['length'],'limit':a84a,'reason':'fanout'});const aC=new Map();for(const aD of aB){const aE=aD['from']??aw['sourceId'],aF=isWfNodeId(aD['to'])?p:p+0x1,aG=h['graph']['nodes']['has'](aD['to']),aH=f['effectiveMaxHops'](aw['schema']);if(aH!==undefined){const aJ=(t(aE,new Set())['get'](aw['schema']['id'])??0x0)+0x1;if(aJ>aH&&!aG){aC['set'](aE,(aC['get'](aE)??0x0)+0x1);continue;}}if(aF>e['maxDepth']&&!aG){h['exhausted']['depth']=!![];continue;}const aI=h['addNode'](aD['to'],Math['min'](aF,e['maxDepth']),{'schema':aw['schema']['id'],'from':aE});if(!aI)break;h['addEdge'](aw['schema'],aE,aD,q,aw['truncated']===!![]||aw['refs']['length']>aA),C['set'](aw['sourceId'],ay+0x1);if(!isWfNodeId(aD['to'])&&aF<=e['maxDepth'])B['add'](aD['to']);}for(const [aK,aL]of aC){h['markTruncation']({'nodeId':aK,'schema':aw['schema']['id'],'observed':aL,'limit':f['effectiveMaxHops'](aw['schema'])??0x0,'reason':'schema_hops'});}}if(h['exhausted']['rpcs']){h['graph']['gaps']['push']('budget:maxRpcs');break;}o=B;}return h['finalize'](a);}function sourceMatches(a,b){if(a==='ANY')return!![];if(a==='EOA')return b['kind']==='eoa';return b['objectType']===a;}function lookupMapLower(a,b){const c=a['get'](b);if(c!==undefined)return c;for(const [d,e]of a)if(d['toLowerCase']()===b)return e;return undefined;}export function orderCompletionInGraph(a,b){const c=a['nodes']['get'](b['toLowerCase']()),d=c?.['raw']?.['data']??c?.['raw']??{},e=String(d['machine']??''),f=String(d['progress']??''),g=a['nodes']['get'](f['toLowerCase']()),h=String((g?.['raw']?.['data']??g?.['raw']??{})['current']??'');let i=null;if(e){const j=e['toLowerCase']()+'::node::',k=a['edges']['filter'](l=>l['schema']==='wf.transition'&&l['from']['startsWith'](j))['map'](l=>({'node':l['payload']?.['node'],'prev_node':l['payload']?.['prevNode']}));if(k['length']>0x0)i=terminalNamesOfEdges(k);}return deriveOrderCompletion({'machine':e||null,'progress':f||null,'currentNode':h||null,'terminalNames':i});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{applyExposureGate as
|
|
1
|
+
import{applyExposureGate as a87a}from'../../config/exposure.js';export{resolveViability,factRef,parseFactRef}from'../../config/exposure.js';export const EXPOSURE_ROLES={'buyer':'buyer','merchant':'merchant','supplier':'supplier','collaborator':'collaborator','arbitrator':'arbitrator','system':'system','neutral':'neutral'};export function applyExposureGate(a,b){return a87a(a,b);}export function lossParty(a,b){return{'role':a,'basis':b};}export function gainPath(a,b,c,d){return{'role':a,'path':b,'viability':c,'gate':d};}
|
|
@@ -61,9 +61,10 @@ export interface AllocationRiskCheckContext {
|
|
|
61
61
|
guard_conditions_mutually_exclusive?: boolean;
|
|
62
62
|
bound_order?: string;
|
|
63
63
|
order_already_has_allocation?: boolean;
|
|
64
|
+
builder_address?: string;
|
|
64
65
|
}
|
|
65
66
|
export declare function allocationRiskFacts(ctx: AllocationRiskCheckContext): Facts;
|
|
66
|
-
export declare const ALLOCATION_RISK_VERSION = "1.
|
|
67
|
+
export declare const ALLOCATION_RISK_VERSION = "1.2.0";
|
|
67
68
|
export declare function getAllRiskRules(): AllocationRiskRule[];
|
|
68
69
|
export interface AllocationRiskAssessment {
|
|
69
70
|
summary: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MAX_ALLOCATOR_COUNT,RATE_TOTAL_FULL,ALLOCATION_ERROR_CODES}from'./allocation-ledger.js';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{getJudgmentDoc,factoryRulePack}from'../config/judgment.js';import{evaluateRuleBook,evaluateCondition}from'../config/rule-engine.js';const AUTO_FIXABLE=new Set(['R-A-1-02#0','R-A-1-02#1','R-A-1-02#2','R-A-1-02#3','R-A-1-02#4','R-A-1-03#0','R-A-1-03#2','R-A-2-03#0','R-A-5-03#0']),RELATED_MOVE_ERROR={'R-A-1-01#0':'EALLOCATORS_EMPTY\x20(8)\x20/\x20ENO_ALLOCATOR\x20(3)','R-A-1-01#1':'ENO_ALLOCATOR\x20(3)','R-A-1-02#0':'ERATE_NOT_10000\x20(4)','R-A-1-02#1':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#2':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#3':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#4':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#5':'EMIXED_RATE_BASES\x20(17)','R-A-1-03#0':'EMULTIPLE_SURPLUS\x20(5)','R-A-1-03#1':'EAMOUNT_BELOW_THRESHOLD\x20(12)','R-A-1-03#2':'EAMOUNT_EXCEEDS_MAX\x20(13)','R-A-2-02#0':'ERECIPIENT_IDENTIFIER_NOT_ADDRESS\x20(1)','R-A-2-04#0':'ERECIPIENT_NOT_FOR_OBJECT\x20(15)','R-A-2-04#1':'ERECIPIENT_NOT_FOR_OBJECT\x20(15,\x20only\x20fires\x20when\x20a\x20binding\x20is\x20declared)','R-A-5-01#0':'E_ALLOCATION_ALREADY_SPECIFIED','R-A-5-02#0':'ENO_PAYMENT_INFO\x20(9)'},RELATED_GUARD_RISK={'R-A-2-01#0':'R-C3-06','R-A-3-04#0':'R-C3-06\x20(Signer\x20binding)\x20/\x20time-lock\x20patterns','R-A-4-01#0':'R-X1-05','R-A-4-03#0':'reentrancy\x20low'};export function allocationRiskFacts(b){const c=b['allocators_config'],d=!!c,e=d?c['allocators']:[];let f,g;if(d&&e['length']>0x0)for(let Z=0x0;Z<e['length'];Z++){if(e[Z]['sharing']['length']===0x0){f=Z,g=e[Z]['guard'];break;}}let h,j,k,l=![],n=![];if(d)for(let a0=0x0;a0<e['length'];a0++){const a1=e[a0],a2=a1['sharing']['some'](a9=>a9['mode']==='RateGross'),a3=a1['sharing']['filter'](a9=>a9['mode']==='Amount')['reduce']((a9,aa)=>a9+Number(aa['sharing']),0x0);if(a2&&a3>0x0)continue;const a4=a2&&a3===0x0&&a1['sharing']['some'](a9=>a9['mode']==='Rate'),a5=a1['sharing']['filter'](a9=>a9['mode']==='Rate'||a4&&a9['mode']==='RateGross');if(a5['length']===0x0)continue;const a6=a5['map'](a9=>Number(a9['sharing']));if(a6['some'](a9=>!Number['isFinite'](a9)))continue;const a7=a6['reduce']((a9,aa)=>a9+aa,0x0),a8=a1['sharing']['some'](a9=>a9['mode']==='Surplus');if(!a8&&a7!==RATE_TOTAL_FULL){h=a0,j=a1['guard'],k=a7,l=!![];break;}if(a8&&a7>RATE_TOTAL_FULL){h=a0,j=a1['guard'],k=a7,n=!![];break;}}let o,p,q,r,t,u,v=![],w,x;if(d)for(let a9=0x0;a9<e['length'];a9++){const aa=e[a9],ab=aa['sharing']['some'](ah=>ah['mode']==='Rate'),ad=aa['sharing']['filter'](ah=>ah['mode']==='RateGross');if(ad['length']===0x0)continue;const ae=aa['sharing']['filter'](ah=>ah['mode']==='Amount')['reduce']((ah,ai)=>ah+Number(ai['sharing']),0x0);if(ab){if(ae>0x0){v=!![],w=a9,x=aa['guard'];break;}continue;}const af=ad['map'](ah=>Number(ah['sharing']));if(af['some'](ah=>!Number['isFinite'](ah))||!Number['isFinite'](ae))continue;const ag=af['reduce']((ah,ai)=>ah+ai,0x0);if(ag>RATE_TOTAL_FULL){o='sum_exceeds_10000',p=a9,q=aa['guard'],r=ag,t=ae;break;}if(aa['max']!=null){const ah=Number(aa['max']);if(Number['isFinite'](ah)&&ae*RATE_TOTAL_FULL+ag*ah>ah*RATE_TOTAL_FULL){o='cap_fit',p=a9,q=aa['guard'],r=ag,t=ae,u=ah;break;}}else{if(ae>0x0&&ag>=RATE_TOTAL_FULL){o='fixed_full',p=a9,q=aa['guard'],r=ag,t=ae;break;}}}let y,z,A,B,C,D,E;if(d){const ai=Number(c['threshold']);for(let aj=0x0;aj<e['length'];aj++){const ak=e[aj],al=ak['sharing']['filter'](ao=>ao['mode']==='Surplus')['length'];if(al>0x1){y='multiple_surplus',z=aj,A=ak['guard'],B=al;break;}const am=ak['sharing']['filter'](ao=>ao['mode']==='Amount')['reduce']((ao,ap)=>ao+Number(ap['sharing']),0x0),an=ak['sharing']['some'](ao=>ao['mode']==='Rate'||ao['mode']==='Surplus');if(!an&&am>0x0&&am<ai){y='below_threshold',z=aj,A=ak['guard'],C=am,D=ai;break;}if(ak['max']!=null&&am>Number(ak['max'])){y='exceeds_max',z=aj,A=ak['guard'],C=am,E=Number(ak['max']);break;}}}let F=![],G,H,I;if(d)for(let ao=0x0;ao<e['length'];ao++){const ap=e[ao],aq=ap['sharing']['some'](as=>'Signer'in as['who']),ar=b['guard_signer_bindings']?.[ap['guard']]===!![];if(isUnboundSignerTheft({'recipient_is_signer':aq,'caller_identity_constrained':ar})){F=!![],G=ao,H=ap['guard'],I=ar;break;}}let J,K,L;if(d&&b['passport_identifier_types'])for(let as=0x0;as<e['length'];as++){const at=e[as],au=at['sharing']['find'](ax=>'GuardIdentifier'in ax['who']);if(!au)continue;const av=au['who']['GuardIdentifier'],aw=b['passport_identifier_types'][av];if(aw!==undefined&&aw!=='address'){J=av,K=aw,L=as;break;}}let M=![],N,O,P,Q;if(d){const ax=e['map'](az=>az['guard']),ay=new Set(ax);if(ay['size']!==ax['length']){const az=ax['filter']((aA,aB)=>ax['indexOf'](aA)!==aB);M=!![],N=ax['length'],O=ay['size'],P=az['join'](',\x20'),Q=az['join'](',');}}const R=b['payment_info_for_object']!==undefined,S=d&&e['some'](aA=>aA['sharing']['some'](aB=>'GuardIdentifier'in aB['who'])),T=!!b['payment_info_for_object'];let U=![],V,W;if(d&&b['referenced_treasuries_permissions']&&b['host_service_permission'])for(const aA of e){for(const aB of aA['sharing']){if(!(aB['who']!==null&&typeof aB['who']==='object'&&'Entity'in aB['who']))continue;const aC=aB['who']['Entity'],aD=b['referenced_treasuries_permissions'][aC];if(aD&&aD!==b['host_service_permission']){U=!![],V=aC,W=aD;break;}}if(U)break;}let X;if(b['trigger_source']==='standalone'&&d){const aE=[];for(const aF of e){const aG=b['guard_signer_bindings']?.[aF['guard']]===!![],aH=b['guard_has_time_lock']?.[aF['guard']]===!![];if(!aG&&!aH)aE['push'](aF['guard']);}X=aE;}let Y;if(d)for(let aI=0x0;aI<e['length'];aI++){const aJ=e[aI],aK=aJ['sharing']['length']>0x0&&aJ['sharing']['every'](aL=>aL['mode']==='Amount');if(aK){Y=aI;break;}}return{'allocators_config_present':d,'allocators_count':d?e['length']:undefined,'allocators_empty':d&&e['length']===0x0,'empty_sharing_allocator_index':f,'empty_sharing_allocator_guard':g,'rate_rule_index':h,'rate_rule_guard':j,'rate_rule_sum':k,'rate_rule_pure':l,'rate_rule_exceed':n,'rate_total_full':RATE_TOTAL_FULL,'rate_gross_branch':o,'rate_gross_index':p,'rate_gross_guard':q,'rate_gross_sum':r,'rate_gross_fix':t,'rate_gross_max':u,'mixed_rate_bases_present':v,'mixed_rate_bases_index':w,'mixed_rate_bases_guard':x,'amount_rule_branch':y,'amount_rule_index':z,'amount_rule_guard':A,'amount_rule_surplus_count':B,'amount_rule_amount_sum':C,'amount_rule_threshold':D,'amount_rule_max':E,'signer_theft_detected':F,'signer_theft_index':G,'signer_theft_guard':H,'signer_theft_guard_bound':I,'guard_id_bad_identifier':J,'guard_id_bad_type':K,'guard_id_bad_index':L,'duplicate_guards_present':M,'allocators_total':N,'allocators_unique':O,'duplicate_guards_csv_sp':P,'duplicate_guards_csv':Q,'for_object_anchor_known':R,'guard_identifier_recipient_present':S,'for_object_anchor_set':T,'for_object_anchor':R&&T?b['payment_info_for_object']??undefined:undefined,'host_service_published':b['host_service_published'],'treasury_perm_mismatch':U,'treasury_perm_entity':V,'treasury_perm_treasury':W,'host_service_permission':b['host_service_permission'],'allocation_create_op':b['operation_type']==='create','allocation_standalone':b['trigger_source']==='standalone','trigger_source_display':b['trigger_source']??'unknown','standalone_weak_guards_count':X?.['length'],'standalone_weak_guards_csv_sp':X?.['join'](',\x20'),'standalone_weak_guards_csv':X?.['join'](','),'has_fallback_allocator':b['has_fallback_allocator'],'guard_conditions_mutually_exclusive':b['guard_conditions_mutually_exclusive'],'has_fallback_allocator_display':String(b['has_fallback_allocator']??![]),'mutually_exclusive_display':String(b['guard_conditions_mutually_exclusive']??![]),'pure_amount_index':Y,'order_already_has_allocation':b['order_already_has_allocation'],'bound_order_display':b['bound_order']??'unknown','bound_order_paren_display':b['bound_order']??'(unknown)','has_payment_info':b['has_payment_info'],'operation_type':b['operation_type'],'max_allocator_count':MAX_ALLOCATOR_COUNT};}function allocationRuleBook(){const a=getJudgmentDoc()['rules']['domains']['allocation'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27allocation\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function firedCaseKey(a,b,c){const d=a['find'](e=>e['rule_id']===c);if(d)for(let e=0x0;e<d['cases']['length'];e++){if(evaluateCondition(d['cases'][e]['when'],b))return c+'#'+e;}return c+'#0';}function findingToAllocationRisk(a,b){const c=RELATED_MOVE_ERROR[b],d=RELATED_GUARD_RISK[b];return{'id':a['rule_id'],'level':a['level'],'category':a['dimension']??'structural','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'','evidence':a['evidence'],...c!==undefined?{'related_move_error':c}:{},...d!==undefined?{'related_guard_risk':d}:{},'auto_fixable':AUTO_FIXABLE['has'](b),...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export const ALLOCATION_RISK_VERSION='1.1.0';export function getAllRiskRules(){const a=factoryRulePack('allocation');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'category':b['dimension']??'structural','trigger':b['trigger']??'','check':c=>{const d=allocationRiskFacts(c),{findings:e}=evaluateRuleBook([b],d);return e['length']>0x0?findingToAllocationRisk(e[0x0],firedCaseKey([b],d,b['rule_id'])):null;}}));}export function assessAllocationRisks(a){const b=allocationRuleBook(),c=allocationRiskFacts(a),{findings:d}=evaluateRuleBook(b,c),e=d['map'](j=>findingToAllocationRisk(j,firedCaseKey(b,c,j['rule_id']))),f=e['length']===0x0?'low':e['some'](j=>j['level']==='critical')?'critical':e['some'](j=>j['level']==='high')?'high':e['some'](j=>j['level']==='medium')?'medium':'low',g={},h={};for(const j of e){g[j['category']]=(g[j['category']]??0x0)+0x1,h[j['level']]=(h[j['level']]??0x0)+0x1;}const i={};for(const k of e){for(const l of k['affected_stakeholders']){if(!i[l])i[l]=[];i[l]['push'](k['id']+':\x20'+k['mitigation']);}}return{'summary':'Assessed\x20'+e['length']+'\x20risk(s)\x20across\x20'+Object['keys'](g)['length']+'\x20categories','risks':e,'overall_risk':f,'risks_by_category':g,'risks_by_level':h,'stakeholder_advice':i,'needs_human_review':e['some'](m=>m['level']==='critical'||m['level']==='high'),'blocks_publish':e['some'](m=>m['level']==='critical')};}export{ALLOCATION_ERROR_CODES};
|
|
1
|
+
import{MAX_ALLOCATOR_COUNT,RATE_TOTAL_FULL,ALLOCATION_ERROR_CODES}from'./allocation-ledger.js';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{checkEntityRecipientsSync}from'./entity-recipient-guard.js';import{getJudgmentDoc,factoryRulePack}from'../config/judgment.js';import{evaluateRuleBook,evaluateCondition}from'../config/rule-engine.js';const AUTO_FIXABLE=new Set(['R-A-1-02#0','R-A-1-02#1','R-A-1-02#2','R-A-1-02#3','R-A-1-02#4','R-A-1-03#0','R-A-1-03#2','R-A-2-03#0','R-A-5-03#0']),RELATED_MOVE_ERROR={'R-A-1-01#0':'EALLOCATORS_EMPTY\x20(8)\x20/\x20ENO_ALLOCATOR\x20(3)','R-A-1-01#1':'ENO_ALLOCATOR\x20(3)','R-A-1-02#0':'ERATE_NOT_10000\x20(4)','R-A-1-02#1':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#2':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#3':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#4':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-02#5':'EMIXED_RATE_BASES\x20(17)','R-A-1-03#0':'EMULTIPLE_SURPLUS\x20(5)','R-A-1-03#1':'EAMOUNT_BELOW_THRESHOLD\x20(12)','R-A-1-03#2':'EAMOUNT_EXCEEDS_MAX\x20(13)','R-A-2-02#0':'ERECIPIENT_IDENTIFIER_NOT_ADDRESS\x20(1)','R-A-2-04#0':'ERECIPIENT_NOT_FOR_OBJECT\x20(15)','R-A-2-04#1':'ERECIPIENT_NOT_FOR_OBJECT\x20(15,\x20only\x20fires\x20when\x20a\x20binding\x20is\x20declared)','R-A-5-01#0':'E_ALLOCATION_ALREADY_SPECIFIED','R-A-5-02#0':'ENO_PAYMENT_INFO\x20(9)','R-RECIPIENT-03#0':'NO\x20chain\x20rejection\x20for\x20an\x20Entity\x20recipient\x20of\x20any\x20address\x20—\x20the\x20SDK\x20substitutes\x20the\x20default\x20local\x20account\x20before\x20the\x20address\x20reaches\x20Move,\x20and\x20allocation.move:250-255\x20swallows\x20Recipient::Entity\x20in\x20a\x20(_)\x20catch-all\x20at\x20declaration\x20while\x20allocation.move:451-453\x20/\x20:514\x20forwards\x20the\x20raw\x20address\x20straight\x20to\x20the\x20payout\x20constructor\x20(retracted\x202026-10-06:\x20there\x20is\x20no\x20ERECIPIENT_ZERO_ENTITY\x20constant;\x20grep\x20returns\x200\x20.move\x20hits)'},RELATED_GUARD_RISK={'R-A-2-01#0':'R-C3-06','R-A-3-04#0':'R-C3-06\x20(Signer\x20binding)\x20/\x20time-lock\x20patterns','R-A-4-01#0':'R-X1-05','R-A-4-03#0':'reentrancy\x20low'};export function allocationRiskFacts(b){const c=b['allocators_config'],d=!!c,e=d?c['allocators']:[];let f,g;if(d&&e['length']>0x0)for(let a1=0x0;a1<e['length'];a1++){if(e[a1]['sharing']['length']===0x0){f=a1,g=e[a1]['guard'];break;}}let h,j,k,l=![],n=![];if(d)for(let a2=0x0;a2<e['length'];a2++){const a3=e[a2],a4=a3['sharing']['some'](ab=>ab['mode']==='RateGross'),a5=a3['sharing']['filter'](ab=>ab['mode']==='Amount')['reduce']((ab,ad)=>ab+Number(ad['sharing']),0x0);if(a4&&a5>0x0)continue;const a6=a4&&a5===0x0&&a3['sharing']['some'](ab=>ab['mode']==='Rate'),a7=a3['sharing']['filter'](ab=>ab['mode']==='Rate'||a6&&ab['mode']==='RateGross');if(a7['length']===0x0)continue;const a8=a7['map'](ab=>Number(ab['sharing']));if(a8['some'](ab=>!Number['isFinite'](ab)))continue;const a9=a8['reduce']((ab,ad)=>ab+ad,0x0),aa=a3['sharing']['some'](ab=>ab['mode']==='Surplus');if(!aa&&a9!==RATE_TOTAL_FULL){h=a2,j=a3['guard'],k=a9,l=!![];break;}if(aa&&a9>RATE_TOTAL_FULL){h=a2,j=a3['guard'],k=a9,n=!![];break;}}let o,p,q,r,t,u,v=![],w,x;if(d)for(let ab=0x0;ab<e['length'];ab++){const ad=e[ab],ae=ad['sharing']['some'](aj=>aj['mode']==='Rate'),af=ad['sharing']['filter'](aj=>aj['mode']==='RateGross');if(af['length']===0x0)continue;const ag=ad['sharing']['filter'](aj=>aj['mode']==='Amount')['reduce']((aj,ak)=>aj+Number(ak['sharing']),0x0);if(ae){if(ag>0x0){v=!![],w=ab,x=ad['guard'];break;}continue;}const ah=af['map'](aj=>Number(aj['sharing']));if(ah['some'](aj=>!Number['isFinite'](aj))||!Number['isFinite'](ag))continue;const ai=ah['reduce']((aj,ak)=>aj+ak,0x0);if(ai>RATE_TOTAL_FULL){o='sum_exceeds_10000',p=ab,q=ad['guard'],r=ai,t=ag;break;}if(ad['max']!=null){const aj=Number(ad['max']);if(Number['isFinite'](aj)&&ag*RATE_TOTAL_FULL+ai*aj>aj*RATE_TOTAL_FULL){o='cap_fit',p=ab,q=ad['guard'],r=ai,t=ag,u=aj;break;}}else{if(ag>0x0&&ai>=RATE_TOTAL_FULL){o='fixed_full',p=ab,q=ad['guard'],r=ai,t=ag;break;}}}let y,z,A,B,C,D,E;if(d){const ak=Number(c['threshold']);for(let al=0x0;al<e['length'];al++){const am=e[al],an=am['sharing']['filter'](aq=>aq['mode']==='Surplus')['length'];if(an>0x1){y='multiple_surplus',z=al,A=am['guard'],B=an;break;}const ao=am['sharing']['filter'](aq=>aq['mode']==='Amount')['reduce']((aq,ar)=>aq+Number(ar['sharing']),0x0),ap=am['sharing']['some'](aq=>aq['mode']==='Rate'||aq['mode']==='Surplus');if(!ap&&ao>0x0&&ao<ak){y='below_threshold',z=al,A=am['guard'],C=ao,D=ak;break;}if(am['max']!=null&&ao>Number(am['max'])){y='exceeds_max',z=al,A=am['guard'],C=ao,E=Number(am['max']);break;}}}let F=![],G,H,I;if(d)for(let aq=0x0;aq<e['length'];aq++){const ar=e[aq],as=ar['sharing']['some'](au=>'Signer'in au['who']),at=b['guard_signer_bindings']?.[ar['guard']]===!![];if(isUnboundSignerTheft({'recipient_is_signer':as,'caller_identity_constrained':at})){F=!![],G=aq,H=ar['guard'],I=at;break;}}let J,K,L;if(d&&b['passport_identifier_types'])for(let au=0x0;au<e['length'];au++){const av=e[au],aw=av['sharing']['find'](az=>'GuardIdentifier'in az['who']);if(!aw)continue;const ax=aw['who']['GuardIdentifier'],ay=b['passport_identifier_types'][ax];if(ay!==undefined&&ay!=='address'){J=ax,K=ay,L=au;break;}}let M=![],N,O,P,Q;if(d){const az=e['map'](aB=>aB['guard']),aA=new Set(az);if(aA['size']!==az['length']){const aB=az['filter']((aC,aD)=>az['indexOf'](aC)!==aD);M=!![],N=az['length'],O=aA['size'],P=aB['join'](',\x20'),Q=aB['join'](',');}}const R=b['payment_info_for_object']!==undefined,S=d&&e['some'](aC=>aC['sharing']['some'](aD=>'GuardIdentifier'in aD['who'])),T=!!b['payment_info_for_object'];let U=![],V,W;if(d&&b['referenced_treasuries_permissions']&&b['host_service_permission'])for(const aC of e){for(const aD of aC['sharing']){if(!(aD['who']!==null&&typeof aD['who']==='object'&&'Entity'in aD['who']))continue;const aE=aD['who']['Entity'],aF=b['referenced_treasuries_permissions'][aE];if(aF&&aF!==b['host_service_permission']){U=!![],V=aE,W=aF;break;}}if(U)break;}let X;if(b['trigger_source']==='standalone'&&d){const aG=[];for(const aH of e){const aI=b['guard_signer_bindings']?.[aH['guard']]===!![],aJ=b['guard_has_time_lock']?.[aH['guard']]===!![];if(!aI&&!aJ)aG['push'](aH['guard']);}X=aG;}let Y;if(d)for(let aK=0x0;aK<e['length'];aK++){const aL=e[aK],aM=aL['sharing']['length']>0x0&&aL['sharing']['every'](aN=>aN['mode']==='Amount');if(aM){Y=aK;break;}}const Z=d?checkEntityRecipientsSync(c,{'builderAddress':b['builder_address']}):[],a0=Z['map'](aN=>'Allocator['+aN['allocator_index']+'].sharing['+aN['sharing_index']+']\x20('+aN['reason']+')');return{'allocators_config_present':d,'allocators_count':d?e['length']:undefined,'allocators_empty':d&&e['length']===0x0,'empty_sharing_allocator_index':f,'empty_sharing_allocator_guard':g,'rate_rule_index':h,'rate_rule_guard':j,'rate_rule_sum':k,'rate_rule_pure':l,'rate_rule_exceed':n,'rate_total_full':RATE_TOTAL_FULL,'rate_gross_branch':o,'rate_gross_index':p,'rate_gross_guard':q,'rate_gross_sum':r,'rate_gross_fix':t,'rate_gross_max':u,'mixed_rate_bases_present':v,'mixed_rate_bases_index':w,'mixed_rate_bases_guard':x,'amount_rule_branch':y,'amount_rule_index':z,'amount_rule_guard':A,'amount_rule_surplus_count':B,'amount_rule_amount_sum':C,'amount_rule_threshold':D,'amount_rule_max':E,'signer_theft_detected':F,'signer_theft_index':G,'signer_theft_guard':H,'signer_theft_guard_bound':I,'guard_id_bad_identifier':J,'guard_id_bad_type':K,'guard_id_bad_index':L,'entity_recipient_bad_count':Z['length'],'entity_recipient_bad_count_display':String(Z['length']),'entity_recipient_bad_rows_csv_sp':a0['length']>0x0?a0['join'](',\x20'):undefined,'entity_recipient_bad_rows_csv':a0['length']>0x0?a0['join'](','):undefined,'duplicate_guards_present':M,'allocators_total':N,'allocators_unique':O,'duplicate_guards_csv_sp':P,'duplicate_guards_csv':Q,'for_object_anchor_known':R,'guard_identifier_recipient_present':S,'for_object_anchor_set':T,'for_object_anchor':R&&T?b['payment_info_for_object']??undefined:undefined,'host_service_published':b['host_service_published'],'treasury_perm_mismatch':U,'treasury_perm_entity':V,'treasury_perm_treasury':W,'host_service_permission':b['host_service_permission'],'allocation_create_op':b['operation_type']==='create','allocation_standalone':b['trigger_source']==='standalone','trigger_source_display':b['trigger_source']??'unknown','standalone_weak_guards_count':X?.['length'],'standalone_weak_guards_csv_sp':X?.['join'](',\x20'),'standalone_weak_guards_csv':X?.['join'](','),'has_fallback_allocator':b['has_fallback_allocator'],'guard_conditions_mutually_exclusive':b['guard_conditions_mutually_exclusive'],'has_fallback_allocator_display':String(b['has_fallback_allocator']??![]),'mutually_exclusive_display':String(b['guard_conditions_mutually_exclusive']??![]),'pure_amount_index':Y,'order_already_has_allocation':b['order_already_has_allocation'],'bound_order_display':b['bound_order']??'unknown','bound_order_paren_display':b['bound_order']??'(unknown)','has_payment_info':b['has_payment_info'],'operation_type':b['operation_type'],'max_allocator_count':MAX_ALLOCATOR_COUNT};}function allocationRuleBook(){const a=getJudgmentDoc()['rules']['domains']['allocation'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27allocation\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function firedCaseKey(a,b,c){const d=a['find'](e=>e['rule_id']===c);if(d)for(let e=0x0;e<d['cases']['length'];e++){if(evaluateCondition(d['cases'][e]['when'],b))return c+'#'+e;}return c+'#0';}function findingToAllocationRisk(a,b){const c=RELATED_MOVE_ERROR[b],d=RELATED_GUARD_RISK[b];return{'id':a['rule_id'],'level':a['level'],'category':a['dimension']??'structural','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'','evidence':a['evidence'],...c!==undefined?{'related_move_error':c}:{},...d!==undefined?{'related_guard_risk':d}:{},'auto_fixable':AUTO_FIXABLE['has'](b),...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export const ALLOCATION_RISK_VERSION='1.2.0';export function getAllRiskRules(){const a=factoryRulePack('allocation');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'category':b['dimension']??'structural','trigger':b['trigger']??'','check':c=>{const d=allocationRiskFacts(c),{findings:e}=evaluateRuleBook([b],d);return e['length']>0x0?findingToAllocationRisk(e[0x0],firedCaseKey([b],d,b['rule_id'])):null;}}));}export function assessAllocationRisks(a){const b=allocationRuleBook(),c=allocationRiskFacts(a),{findings:d}=evaluateRuleBook(b,c),e=d['map'](j=>findingToAllocationRisk(j,firedCaseKey(b,c,j['rule_id']))),f=e['length']===0x0?'low':e['some'](j=>j['level']==='critical')?'critical':e['some'](j=>j['level']==='high')?'high':e['some'](j=>j['level']==='medium')?'medium':'low',g={},h={};for(const j of e){g[j['category']]=(g[j['category']]??0x0)+0x1,h[j['level']]=(h[j['level']]??0x0)+0x1;}const i={};for(const k of e){for(const l of k['affected_stakeholders']){if(!i[l])i[l]=[];i[l]['push'](k['id']+':\x20'+k['mitigation']);}}return{'summary':'Assessed\x20'+e['length']+'\x20risk(s)\x20across\x20'+Object['keys'](g)['length']+'\x20categories','risks':e,'overall_risk':f,'risks_by_category':g,'risks_by_level':h,'stakeholder_advice':i,'needs_human_review':e['some'](m=>m['level']==='critical'||m['level']==='high'),'blocks_publish':e['some'](m=>m['level']==='critical')};}export{ALLOCATION_ERROR_CODES};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function assert_declared_share(a,b,c,d){const e=c===undefined||c===null||c===''?d:c,f=Number(e);if(!Number['isInteger'](f))throw new Error('E-RATE-EXPLICIT:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20an\x20explicit\x20integer\x20number\x20of\x20basis\x20points\x20'+('(the\x20buyer\x20must\x20be\x20able\x20to\x20compute\x20it\x20pre-order;\x20never\x20an\x20implicit\x20remainder),\x20got\x20'+String(c)));if(f<0x0||f>0x2710)throw new Error('E-RATE-RANGE:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20within\x20[0,\x2010000],\x20got\x20'+f);return f;}function assert_explicit_recipient(a,b,c,d){if(d<=0x0)return;const e=typeof c==='string'?c['trim']():'';if(e['length']===0x0)throw new Error('E-RECIPIENT-UNDEFINED:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20a\x20non-empty\x20explicit\x20recipient\x20'+('because\x20its\x20rate\x20is\x20'+d+'\x20>\x200.\x20A\x20blank/omitted\x20recipient\x20silently\x20falls\x20back\x20to\x20')+'Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/w/local/index.ts:74-86),\x20'+'so\x20the\x20outflow\x20would\x20go\x20to\x20whoever\x20ran\x20the\x20deploy.');if(e['toLowerCase']()['startsWith']('0x')){const f=e['slice'](0x2);if(f['length']===0x0||!/^[0-9a-f]+$/['test'](f)||/^0+$/['test'](f))throw new Error('E-RECIPIENT-UNDEFINED:\x20'+a+':\x20'+b+'\x20looks\x20like\x20an\x20address\x20but\x20carries\x20no\x20'+('identity\x20(\x22'+e+'\x22).\x20Point\x20it\x20at\x20the\x20declared\x20recipient\x20Entity\x20(a\x20Treasury/Entity\x20address\x20the\x20')+'buyer\x20can\x20see\x20pre-order).');}}export const ALLOCATION_TEMPLATES=[{'id':'T-A-01','name':'Single\x20Rate\x20100%\x20to\x20Treasury','description':'Simplest\x20allocation\x20—\x20single\x20Allocator,\x20single\x20Rate=10000\x20sharing\x20to\x20one\x20Treasury/personal\x20address','applicable_scenes':['allocation_merchant_full_payment'],'industry_tags':['universal','retail','service'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(e.g.\x20\x270x2::wow::WOW\x27)','required':!![]},{'name':'recipient_address','type':'address','description':'Treasury\x20or\x20personal\x20wallet\x20address\x20to\x20receive\x20100%','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Single\x20Rate\x20100%\x20allocation'}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Single\x20Rate\x20100%\x20allocation','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['recipient_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['Simplest\x20configuration\x20—\x20no\x20multi-party\x20coordination','Guard\x20only\x20needs\x20to\x20verify\x20order\x20status,\x20no\x20complex\x20conditions','Suitable\x20for\x20solo\x20merchants\x20or\x20single-treasury\x20services','DIRECT-SALES\x20DEFAULT\x20SHAPE\x20(L2):\x20this\x20IS\x20the\x20default\x20payout\x20form\x20—\x20one\x20Rate\x2010000\x20leg\x20to\x20the\x20merchant\x27s\x20own\x20Entity.\x20No\x20platform\x20leg\x20exists,\x20and\x20nothing\x20is\x20left\x20over','If\x20the\x20merchant\x20declares\x20its\x20OWN\x20fee,\x20use\x20T-A-02\x20(an\x20explicit\x20fee\x20leg\x20to\x20an\x20explicit\x20non-empty\x20recipient)\x20instead\x20of\x20shrinking\x20this\x20leg\x20and\x20routing\x20the\x20difference\x20through\x20an\x20implicit\x20remainder\x20(L3)','A\x20BLANK\x20recipient_address\x20is\x20NOT\x20a\x20no-op:\x20it\x20resolves\x20to\x20Account.Instance().get_address(undefined),\x20the\x20logged-in/deploying\x20account\x20(ts-sdk/w/local/index.ts:74-86)\x20—\x20so\x20this\x20template\x20pays\x20whoever\x20ran\x20the\x20deploy']},{'id':'T-A-02','name':'Merchant\x20payout\x20+\x20optional\x20declared\x20fee\x20/\x20third-party\x20leg\x20(merchant\x20keeps\x20100%\x20by\x20default)','description':'DIRECT-SALES\x20split:\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20by\x20default\x20(one\x20Rate\x2010000\x20leg\x20to\x20its\x20own\x20Entity).\x20Optional\x20extra\x20legs\x20are\x20(a)\x20the\x20merchant\x27s\x20OWN\x20service\x20fee\x20—\x20only\x20when\x20the\x20merchant\x20IS\x20the\x20aggregator\x20—\x20and\x20(b)\x20a\x20genuine\x20third-party\x20payment\x20(logistics\x20provider,\x20arbitrator,\x20partner),\x20which\x20is\x20a\x20payment\x20for\x20a\x20service,\x20not\x20platform\x20extraction.\x20Pure\x20Rate\x20mode:\x20the\x20emitted\x20sharing\x20rows\x20MUST\x20sum\x20to\x20exactly\x2010000,\x20and\x20with\x20the\x20default\x20parameters\x20they\x20are\x20a\x20single\x2010000\x20row.\x20L3\x20fee\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20the\x20buyer\x20can\x20compute\x20BEFORE\x20ordering,\x20never\x20an\x20implicit\x20remainder\x20such\x20as\x20\x27order\x20total\x20-\x20segment\x20sums\x27;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20the\x20buyer\x20can\x20see\x20pre-order\x20(a\x20blank\x20recipient\x20is\x20NOT\x20a\x20no-op\x20—\x20it\x20falls\x20back\x20to\x20the\x20deploying\x20account,\x20ts-sdk/w/local/index.ts:74-86);\x20(3)\x20no\x20mandatory\x20transit\x20pool\x20on\x20the\x20payout\x20path,\x20and\x20the\x20fee\x20is\x20NEVER\x20taken\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all,\x20so\x20it\x20doubles\x20as\x20draining\x20the\x20pool).\x20WoWok\x20itself\x20takes\x20nothing.','applicable_scenes':['allocation_standard_three_way_split'],'industry_tags':['retail','ecommerce','logistics'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Entity\x20that\x20receives\x20its\x20own\x20sale\x20proceeds\x20—\x20the\x20direct-sales\x20destination.\x20Required\x20and\x20never\x20blank\x20(blank\x20silently\x20routes\x20the\x20payout\x20to\x20the\x20deploying\x20account,\x20ts-sdk/w/local/index.ts:74-86).','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20merchant_service_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20merchant_service_fee_bps\x20>\x200\x20—\x20leaving\x20it\x20blank\x20or\x20omitting\x20it\x20is\x20NOT\x20a\x20no-op:\x20the\x20share\x20silently\x20goes\x20to\x20Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/w/local/index.ts:74-86).\x20Pass\x20merchant_treasury\x20if\x20the\x20merchant\x20charges\x20itself.','required':![]},{'name':'third_party_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20third_party_rate\x20(e.g.\x20the\x20logistics\x20provider\x27s\x20own\x20Treasury).\x20MUST\x20be\x20explicit\x20and\x20non-empty\x20whenever\x20third_party_rate\x20>\x200\x20—\x20same\x20blank-fallback\x20hazard\x20as\x20merchant_fee_treasury.','required':![]},{'name':'merchant_rate','type':'number','description':'Merchant\x27s\x20own\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'merchant_service_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20in\x20basis\x20points.\x20KEEP\x20AT\x200\x20unless\x20the\x20merchant\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium\x20/\x20an\x20OTA\x20that\x20really\x20is\x20the\x20seller\x27s\x20counterparty).\x20WoWok\x20extracts\x20nothing\x20—\x20this\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20price,\x20never\x20a\x20platform\x20share.\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20before\x20ordering;\x20merchant_rate\x20+\x20merchant_service_fee_bps\x20+\x20third_party_rate\x20MUST\x20sum\x20to\x2010000.','required':![],'default':0x0},{'name':'third_party_rate','type':'number','description':'Rate\x20for\x20a\x20genuine\x20third-party\x20payment\x20(logistics\x20provider\x20/\x20arbitrator\x20/\x20supply-chain\x20partner),\x20default\x200.\x20Kept\x20expressible\x20on\x20purpose\x20—\x20a\x20real\x20provider\x20fee\x20is\x20a\x20payment\x20FOR\x20a\x20service\x20—\x20but\x20it\x20must\x20be\x20an\x20explicit\x20number\x20with\x20an\x20explicit\x20recipient,\x20exactly\x20like\x20the\x20merchant\x20fee.','required':![],'default':0x0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion\x20+\x20service\x20binding)','required':!![]}],'body':a=>{const b=assert_declared_share('T-A-02','merchant_rate',a['merchant_rate'],0x2710),c=assert_declared_share('T-A-02','merchant_service_fee_bps',a['merchant_service_fee_bps'],0x0),d=assert_declared_share('T-A-02','third_party_rate',a['third_party_rate'],0x0);assert_explicit_recipient('T-A-02','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-02','merchant_fee_treasury',a['merchant_fee_treasury'],c),assert_explicit_recipient('T-A-02','third_party_treasury',a['third_party_treasury'],d);const e=b+c+d;if(e!==0x2710)throw new Error('T-A-02:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+e+'\x20'+('(merchant='+b+'\x20+\x20merchant_service_fee='+c+'\x20+\x20third_party='+d+')'));const f=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&f['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(c),'mode':'Rate'}),d>0x0&&f['push']({'who':{'Entity':a['third_party_treasury']},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Direct-sales\x20payout\x20(platform\x20commission\x200):\x20merchant\x20'+b+'/10000'+(c>0x0?',\x20merchant\x27s\x20own\x20service\x20fee\x20'+c+'/10000':'')+(d>0x0?',\x20third\x20party\x20(e.g.\x20logistics)\x20'+d+'/10000':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':f,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode,\x20no\x20Surplus)\x20—\x20a\x20Rate\x20sum\x20<\x2010000\x20with\x20no\x20Surplus\x20recipient\x20leaves\x20residual\x20balance\x20that\x20ANYONE\x20passing\x20the\x20same\x20Guard\x20can\x20claim\x20repeatedly\x20(E-2\x20/\x20finding\x20T-04)','DEFAULT\x20PARAMETERS\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury:\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20and\x20the\x2010000\x20invariant\x20holds\x20by\x20construction','merchant_service_fee_bps\x20is\x20the\x20MERCHANT\x27s\x20own\x20fee\x20(merchant\x20IS\x20the\x20aggregator),\x20default\x200\x20—\x20WoWok\x20takes\x20no\x20platform\x20commission\x20and\x20there\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template','third_party_rate\x20is\x20a\x20real\x20provider\x20payment\x20(logistics\x20/\x20arbitrator\x20/\x20partner),\x20not\x20platform\x20extraction;\x20keep\x20it\x20expressible,\x20but\x20name\x20the\x20payee\x20explicitly','Never\x20express\x20a\x20fee\x20as\x20an\x20implicit\x20remainder\x20(\x27the\x20merchant\x20keeps\x20whatever\x20is\x20left\x27)\x20and\x20never\x20take\x20one\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all)','Treasury\x20Permission\x20should\x20match\x20Service\x20Permission\x20(R-A-3-02)','Guard\x20should\x20verify\x20order.service\x20binding\x20(query\x201563)\x20to\x20prevent\x20cross-project\x20bypass']},{'id':'T-A-03','name':'Refund-first\x20+\x20Surplus-to-merchant\x20(Amount\x20+\x20Surplus\x20hybrid)','description':'Single\x20Allocator\x20with\x202\x20sharing\x20items:\x20Amount=refund_value\x20to\x20customer,\x20Surplus\x20to\x20merchant.\x20No\x20fee\x20and\x20no\x20platform\x20leg:\x20the\x20Surplus\x20is\x20the\x20merchant\x27s\x20residual\x20of\x20a\x20mixed\x20refund/delivery\x20pool,\x20NOT\x20a\x20fee\x20mechanism','applicable_scenes':['allocation_refund_first_surplus_to_merchant'],'industry_tags':['retail','refund','customer_protection'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'customer_address','type':'address','description':'Customer\x20address\x20to\x20receive\x20refund\x20Amount','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20to\x20receive\x20Surplus','required':!![]},{'name':'refund_amount','type':'number','description':'Refund\x20amount\x20in\x20smallest\x20coin\x20unit\x20(e.g.\x20MIST\x20for\x20WOW)','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20refund\x20approval)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Refund-first\x20+\x20Surplus-to-merchant'}],'body':a=>{const b=Number(a['refund_amount']);if(b<=0x0)throw new Error('T-A-03:\x20refund_amount\x20MUST\x20be\x20>\x200,\x20got\x20'+b);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Refund-first\x20+\x20Surplus-to-merchant','threshold':String(b),'allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['customer_address']},'sharing':String(b),'mode':'Amount'},{'who':{'Entity':a['merchant_treasury']},'sharing':'0','mode':'Surplus'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-04:\x20at\x20most\x201\x20Surplus\x20per\x20Allocator\x20(✓\x20single\x20Surplus\x20here)','F-A-07:\x20threshold\x20=\x20refundAmount\x20(ensure\x20balance\x20covers\x20Amount)','the\x20fix\x20is\x20cached\x20as\x20refundAmount\x20when\x20the\x20Allocator\x20is\x20added','Guard\x20must\x20verify\x20customer\x20refund\x20eligibility\x20(e.g.\x20order\x20status\x20=\x20Refunded)','SURPLUS\x20IS\x20NOT\x20A\x20FEE:\x20Surplus\x20calls\x20balance::withdraw_all\x20(allocation.move:420),\x20so\x20a\x20fee\x20taken\x20that\x20way\x20doubles\x20as\x20draining\x20the\x20pool\x20(L3\x20constraint\x203).\x20A\x20declared\x20service\x20fee\x20belongs\x20on\x20the\x20purchase-side\x20allocation\x20(T-A-02)\x20as\x20an\x20explicit\x20Rate\x20leg,\x20never\x20here','The\x20Surplus\x20recipient\x20is\x20the\x20merchant\x20(the\x20counterparty\x20of\x20the\x20delivered\x20part),\x20not\x20an\x20unnamed\x20third\x20party\x20—\x20but\x20pin\x20refund_amount\x20to\x20the\x20refund\x20actually\x20owed,\x20or\x20a\x20smaller/empty\x20refund\x20lets\x20the\x20Surplus\x20leg\x20absorb\x20money\x20that\x20is\x20not\x20the\x20merchant\x27s']},{'id':'T-A-04','name':'Treasury\x20+\x20Personal\x20alternative\x20(caller-specified\x20guard,\x202\x20Allocators)','description':'2\x20Allocators\x20as\x20alternative\x20strategies:\x20caller\x20selects\x20Treasury\x20or\x20Personal\x20wallet\x20via\x20alloc_by_guard\x20(hard\x20verification\x20per\x20call)','applicable_scenes':['allocation_treasury_personal_alternatives'],'industry_tags':['universal','alternative','treasury'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'treasury_address','type':'address','description':'Treasury\x20address\x20(primary\x20recipient)','required':!![]},{'name':'personal_address','type':'address','description':'Personal\x20wallet\x20address\x20(alternative\x20recipient)','required':!![]},{'name':'treasury_guard','type':'address','description':'Guard\x20for\x20Treasury\x20path\x20(verifies\x20treasury\x20operational)','required':!![]},{'name':'personal_guard','type':'address','description':'Guard\x20for\x20Personal\x20path\x20(verifies\x20personal\x20wallet\x20active)\x20—\x20MUST\x20differ\x20from\x20treasury_guard','required':!![]}],'body':a=>{if(a['treasury_guard']===a['personal_guard'])throw new Error('T-A-04:\x20treasury_guard\x20and\x20personal_guard\x20MUST\x20be\x20different\x20addresses\x20(F-A-14:\x20allocators[].guard\x20must\x20be\x20unique)');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Treasury\x20/\x20Personal\x20alternative\x20(caller-specified\x20guard)','threshold':'0','allocators':[{'guard':a['treasury_guard'],'sharing':[{'who':{'Entity':a['treasury_address']},'sharing':'10000','mode':'Rate'}],'max':null},{'guard':a['personal_guard'],'sharing':[{'who':{'Entity':a['personal_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-14:\x20treasury_guard\x20!=\x20personal_guard\x20(Allocator\x20Guards\x20must\x20be\x20unique)','caller-specified\x20guard:\x20alloc_by_guard\x20explicitly\x20selects\x20an\x20Allocator;\x20the\x20Passport\x27s\x20guard\x20result\x20is\x20hard-verified\x20(failure\x20aborts\x20E_VERIFY_FAILED)','No\x20auto-fallback:\x20on\x20verification\x20failure\x20the\x20caller\x20must\x20switch\x20guard\x20and\x20retry','R-A-4-02:\x20if\x20the\x20caller\x27s\x20submitted\x20Passport\x20satisfies\x20both\x20Guards\x20simultaneously,\x20the\x20caller\x20may\x20freely\x20choose\x20between\x20the\x20two\x20paths\x20(mutual\x20exclusion\x20is\x20a\x20design\x20clarity\x20recommendation,\x20not\x20a\x20correctness\x20requirement)','Each\x20Allocator\x20sums\x20to\x2010000\x20INDEPENDENTLY\x20—\x20the\x20Rate-total\x20invariant\x20is\x20per\x20Allocator,\x20not\x20across\x20Allocators,\x20and\x20each\x20of\x20the\x20two\x20paths\x20pays\x20ONE\x20recipient\x20the\x20full\x20amount\x20(no\x20split,\x20no\x20platform\x20leg,\x20no\x20residual)']},{'id':'T-A-05','name':'Tiered\x20by\x20order\x20amount\x20(mutually\x20exclusive\x20Guard\x20conditions)','description':'2\x20Allocators\x20triggered\x20by\x20mutually\x20exclusive\x20Guard\x20conditions\x20(small\x20order\x20vs\x20large\x20order).\x20DIRECT-SALES\x20default:\x20BOTH\x20tiers\x20pay\x20the\x20merchant\x20100%\x20—\x20the\x20tier\x20selects\x20the\x20guard,\x20not\x20a\x20cut.\x20The\x20large\x20tier\x20may\x20add\x20the\x20merchant\x27s\x20OWN\x20declared\x20fee,\x20under\x20the\x20L3\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20computable\x20before\x20ordering,\x20never\x20an\x20implicit\x20remainder;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20(blank\x20silently\x20routes\x20it\x20to\x20the\x20deploying\x20account,\x20ts-sdk/w/local/index.ts:74-86);\x20(3)\x20no\x20mandatory\x20transit\x20pool,\x20and\x20never\x20a\x20Surplus\x20fee\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all).\x20No\x20platform\x20leg\x20exists\x20in\x20this\x20template.','applicable_scenes':['allocation_tiered_by_order_amount'],'industry_tags':['retail','tiered_pricing','volume_discount'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20(receives\x20the\x20full\x20sale\x20on\x20both\x20tiers\x20by\x20default)','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20large_order_merchant_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20that\x20fee\x20is\x20>\x200\x20—\x20blank\x20or\x20omitted\x20silently\x20pays\x20the\x20deploying\x20account\x20(ts-sdk/w/local/index.ts:74-86),\x20not\x20a\x20no-op.','required':![]},{'name':'small_order_guard','type':'address','description':'Guard\x20verifying\x20order.amount\x20<\x20threshold\x20(small\x20order\x20path)','required':!![]},{'name':'large_order_guard','type':'address','description':'Guard\x20verifying\x20order.amount\x20>=\x20threshold\x20(large\x20order\x20path)\x20—\x20MUST\x20differ\x20from\x20small_order_guard','required':!![]},{'name':'small_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20on\x20the\x20small-order\x20tier.\x20Default\x20(and\x20only)\x20value\x2010000\x20—\x20direct\x20sales:\x20no\x20platform\x20take.','required':![],'default':0x2710},{'name':'large_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20on\x20the\x20large-order\x20tier.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(there\x20is\x20no\x20platform\x20take\x20to\x20deduct).','required':![],'default':0x2710},{'name':'large_order_merchant_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20on\x20the\x20large-order\x20tier,\x20in\x20basis\x20points.\x20KEEP\x20AT\x200\x20unless\x20the\x20merchant\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium).\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20pre-order;\x20large_order_merchant_rate\x20+\x20large_order_merchant_fee_bps\x20MUST\x20sum\x20to\x2010000.\x20WoWok\x20takes\x20no\x20platform\x20commission.','required':![],'default':0x0}],'body':a=>{if(a['small_order_guard']===a['large_order_guard'])throw new Error('T-A-05:\x20small_order_guard\x20and\x20large_order_guard\x20MUST\x20be\x20different\x20addresses\x20(F-A-14)');const b=assert_declared_share('T-A-05','small_order_merchant_rate',a['small_order_merchant_rate'],0x2710);if(b!==0x2710)throw new Error('T-A-05:\x20small_order_merchant_rate\x20MUST\x20equal\x2010000\x20(pure\x20Rate,\x20no\x20Surplus\x20in\x20this\x20Allocator),\x20got\x20'+b);const c=assert_declared_share('T-A-05','large_order_merchant_rate',a['large_order_merchant_rate'],0x2710),d=assert_declared_share('T-A-05','large_order_merchant_fee_bps',a['large_order_merchant_fee_bps'],0x0);assert_explicit_recipient('T-A-05','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-05','merchant_fee_treasury',a['merchant_fee_treasury'],d);const e=c+d;if(e!==0x2710)throw new Error('T-A-05:\x20large_order\x20rates\x20MUST\x20sum\x20to\x2010000,\x20got\x20'+e+'\x20(merchant='+c+'\x20+\x20merchant_fee='+d+')');const f=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(c),'mode':'Rate'}];return d>0x0&&f['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Tiered\x20by\x20order\x20amount\x20(platform\x20commission\x200):\x20small=100%\x20merchant,\x20'+('large='+c+'/10000\x20merchant')+(d>0x0?'\x20+\x20'+d+'/10000\x20merchant\x27s\x20own\x20service\x20fee':''),'threshold':'0','allocators':[{'guard':a['small_order_guard'],'sharing':[{'who':{'Entity':a['merchant_treasury']},'sharing':'10000','mode':'Rate'}],'max':null},{'guard':a['large_order_guard'],'sharing':f,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Guard\x20conditions\x20MUST\x20be\x20mutually\x20exclusive\x20(R-A-4-02)','Sequence-sensitive:\x20strict\x20condition\x20(small\x20order)\x20first,\x20relaxed\x20condition\x20(large\x20order)\x20last','Guard\x20queries\x20order.amount\x20(query\x201561)\x20to\x20determine\x20which\x20Allocator\x20fires','If\x20neither\x20Guard\x20passes,\x20funds\x20are\x20silently\x20locked\x20(R-A-4-02)','DIRECT-SALES\x20DEFAULT:\x20both\x20tiers\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury\x20—\x20the\x20tier\x20picks\x20the\x20guard,\x20not\x20a\x20cut.\x20Each\x20Allocator\x20sums\x20to\x2010000\x20on\x20its\x20own','large_order_merchant_fee_bps\x20is\x20the\x20merchant\x27s\x20OWN\x20large-tier\x20fee\x20(default\x200),\x20only\x20for\x20a\x20merchant\x20that\x20IS\x20the\x20aggregator;\x20it\x20is\x20never\x20a\x20platform\x20take,\x20never\x20an\x20implicit\x20remainder,\x20and\x20its\x20recipient\x20must\x20be\x20explicit\x20and\x20non-empty']},{'id':'T-A-06','name':'Dynamic\x20recipient\x20via\x20GuardIdentifier\x20(referrer\x20from\x20Passport)','description':'Single\x20Allocator\x20whose\x20Rate\x20sharing\x20items\x20include\x20one\x20recipient\x20resolved\x20from\x20the\x20customer\x27s\x20Passport\x20table[identifier].\x20DIRECT-SALES\x20default:\x20merchant_rate\x2010000\x20and\x20every\x20optional\x20leg\x200,\x20so\x20the\x20emitted\x20template\x20is\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20the\x20merchant.\x20Two\x20optional\x20legs\x20may\x20be\x20switched\x20on,\x20each\x20under\x20the\x20L3\x20rule\x20(explicit\x20number\x20computable\x20pre-order;\x20explicit\x20non-empty\x20recipient\x20—\x20blank\x20silently\x20pays\x20the\x20deploying\x20account,\x20ts-sdk/w/local/index.ts:74-86;\x20no\x20mandatory\x20transit\x20pool,\x20never\x20a\x20Surplus\x20fee\x20leg):\x20the\x20merchant\x27s\x20OWN\x20service\x20fee\x20(only\x20when\x20the\x20merchant\x20IS\x20the\x20aggregator)\x20and\x20a\x20referral/reward\x20to\x20a\x20referrer\x20the\x20buyer\x20names.\x20There\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template.','applicable_scenes':['allocation_dynamic_recipient'],'industry_tags':['referral','affiliate','marketing'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20(default:\x20the\x20sole\x2010000\x20recipient)','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20merchant_service_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20that\x20fee\x20is\x20>\x200\x20—\x20blank\x20or\x20omitted\x20silently\x20pays\x20the\x20deploying\x20account\x20(ts-sdk/w/local/index.ts:74-86).\x20NEVER\x20route\x20the\x20merchant\x27s\x20own\x20fee\x20through\x20GuardIdentifier:\x20that\x20recipient\x20is\x20buyer-submitted,\x20not\x20merchant-declared.','required':![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(must\x20be\x20configured\x20with\x20identifier=0\x20as\x20address\x20type)','required':!![]},{'name':'passport_identifier','type':'number','description':'Passport\x20table\x20identifier\x20(u8,\x200-255)\x20carrying\x20the\x20referrer\x20address\x20the\x20buyer\x20submits\x20—\x20only\x20consulted\x20when\x20referrer_rate\x20>\x200\x20(default\x200)','required':![],'default':0x0},{'name':'merchant_rate','type':'number','description':'Merchant\x27s\x20own\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'merchant_service_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20in\x20basis\x20points,\x20default\x200.\x20Only\x20for\x20a\x20merchant\x20that\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium).\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20pre-order;\x20merchant_rate\x20+\x20merchant_service_fee_bps\x20+\x20referrer_rate\x20MUST\x20sum\x20to\x2010000.','required':![],'default':0x0},{'name':'referrer_rate','type':'number','description':'Referral\x20/\x20reward\x20rate\x20paid\x20to\x20the\x20referrer\x20the\x20BUYER\x20names\x20in\x20its\x20Passport,\x20default\x200.\x20This\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20acquisition\x20price,\x20not\x20a\x20platform\x20share\x20—\x20keep\x20it\x200\x20unless\x20the\x20merchant\x20actually\x20runs\x20a\x20referral\x20programme,\x20and\x20never\x20route\x20the\x20merchant\x27s\x20own\x20fee\x20here.','required':![],'default':0x0}],'body':a=>{const b=assert_declared_share('T-A-06','merchant_rate',a['merchant_rate'],0x2710),c=assert_declared_share('T-A-06','merchant_service_fee_bps',a['merchant_service_fee_bps'],0x0),d=assert_declared_share('T-A-06','referrer_rate',a['referrer_rate'],0x0),e=b+c+d;if(e!==0x2710)throw new Error('T-A-06:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+e+'\x20(merchant='+b+'\x20+\x20merchant_service_fee='+c+'\x20+\x20referrer='+d+')');assert_explicit_recipient('T-A-06','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-06','merchant_fee_treasury',a['merchant_fee_treasury'],c);const f=Number(a['passport_identifier']??0x0);if(f<0x0||f>0xff)throw new Error('T-A-06:\x20passport_identifier\x20MUST\x20be\x20u8\x20(0-255),\x20got\x20'+f);const g=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&g['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(c),'mode':'Rate'}),d>0x0&&g['push']({'who':{'GuardIdentifier':f},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Dynamic\x20recipient\x20(platform\x20commission\x200):\x20merchant\x20'+b+'/10000'+(c>0x0?',\x20merchant\x27s\x20own\x20service\x20fee\x20'+c+'/10000':'')+(d>0x0?',\x20referrer\x20'+d+'/10000\x20(from\x20Passport\x20identifier='+f+')':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':g,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['DEFAULT\x20PARAMETERS\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury;\x20to\x20exercise\x20the\x20GuardIdentifier\x20form\x20set\x20referrer_rate\x20>\x200\x20and\x20lower\x20merchant_rate\x20by\x20exactly\x20that\x20amount\x20(the\x20emitted\x20rows\x20must\x20still\x20total\x2010000)','F-A-13:\x20Passport\x20table[identifier]\x20MUST\x20be\x20address\x20type\x20(else\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS=1)','The\x20Guard\x20identifier\x20slot\x27s\x20address-type\x20check\x20MUST\x20pass\x20when\x20the\x20Allocator\x20is\x20added\x20(else\x20the\x20Allocator\x20add\x20fails)','Customer\x20must\x20submit\x20Passport\x20with\x20referrer\x20address\x20at\x20the\x20specified\x20identifier\x20slot','Guard\x20should\x20verify\x20Passport\x20completeness\x20before\x20alloc()\x20executes','The\x20GuardIdentifier\x20recipient\x20is\x20CHOSEN\x20BY\x20THE\x20BUYER\x20(the\x20submitted\x20address\x20bound\x20to\x20for_object),\x20so\x20the\x20Guard\x20—\x20not\x20the\x20template\x20—\x20is\x20what\x20makes\x20it\x20trustworthy:\x20bind\x20it\x20(e.g.\x20an\x20allow-listed\x20referrer)\x20before\x20enabling\x20a\x20non-zero\x20referrer_rate,\x20and\x20never\x20use\x20it\x20for\x20the\x20merchant\x27s\x20own\x20fee','merchant_service_fee_bps\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20fee,\x20default\x200,\x20and\x20requires\x20an\x20explicit\x20non-empty\x20recipient\x20—\x20there\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template']},{'id':'T-A-07','name':'Refund\x20to\x20the\x20submitted\x20Order\x20(100%\x20delivered\x20to\x20the\x20order\x20as\x20escrow)','description':'Single\x20Allocator,\x201\x20Rate=10000\x20sharing\x20whose\x20recipient\x20is\x20the\x20order\x20submitted\x20at\x20alloc\x20time\x20(Guard\x20table\x20identifier\x200).\x20The\x20funds\x20are\x20delivered\x20to\x20that\x20order\x20and\x20received\x20by\x20its\x20owner.','applicable_scenes':['allocation_refund_to_order'],'industry_tags':['refund','customer_protection','order_lifecycle'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20verifying\x20the\x20submitted\x20order\x20qualifies\x20(e.g.\x20order\x20at\x20the\x20refund\x20node,\x20order.service\x20==\x20host\x20service).\x20Its\x20table\x20needs\x20an\x20address-typed\x20b_submission\x20slot\x20at\x20identifier\x200.','required':!![]}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Refund\x20to\x20the\x20submitted\x20Order\x20(100%\x20delivered\x20to\x20the\x20order\x20as\x20escrow)','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'GuardIdentifier':0x0},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['The\x20Guard\x20table\x20MUST\x20have\x20an\x20address-typed\x20b_submission\x20slot\x20at\x20identifier\x200\x20carrying\x20the\x20submitted\x20order\x20(else\x20the\x20Allocator\x20add\x20fails\x20with\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS).','At\x20alloc\x20time\x20the\x20full\x20Rate\x20is\x20delivered\x20to\x20the\x20submitted\x20order\x20as\x20a\x20CoinWrapper\x20—\x20the\x20order\x20object\x20owns\x20it.\x20Its\x20owner\x20subsequently\x20receives\x20the\x20bare\x20coins\x20through\x20the\x20order\x27s\x20owner-receive\x20entry;\x20unrelated\x20addresses\x20cannot\x20intercept.','The\x20Guard\x20decides\x20which\x20submitted\x20orders\x20qualify:\x20node\x20state\x20plus\x20a\x20service-scope\x20binding\x20(order.service\x20==\x20host\x20service)\x20are\x20the\x20typical\x20conditions;\x20tightening\x20those\x20conditions\x20is\x20how\x20the\x20destination\x20is\x20controlled.','When\x20the\x20per-order\x20Allocation\x20is\x20created\x20through\x20the\x20Service\x20flow,\x20payment_info.for_object\x20is\x20set\x20to\x20the\x20order\x20the\x20allocation\x20belongs\x20to,\x20recording\x20the\x20business\x20context\x20auditors\x20can\x20query.','No\x20fee\x20leg\x20and\x20no\x20platform\x20leg:\x20a\x20refund\x20path\x20pays\x20the\x20order\x27s\x20owner\x20and\x20nothing\x20else.\x20A\x20declared\x20service\x20fee\x20belongs\x20on\x20the\x20purchase-side\x20allocation\x20(T-A-02)\x20as\x20an\x20explicit\x20Rate\x20leg\x20—\x20never\x20as\x20a\x20leg\x20here,\x20and\x20never\x20as\x20an\x20implicit\x20remainder\x20or\x20a\x20Surplus\x20drain']},{'id':'T-A-08','name':'Arbitration\x20fees\x20payout\x20(arbitrator\x20keeps\x20100%\x20by\x20default\x20/\x20optional\x20declared\x20operator\x20fee)','description':'Single\x20Allocator,\x20Rate\x20sharing\x20items\x20summing\x20to\x20exactly\x2010000.\x20Triggered\x20by\x20the\x20Arbitration\x20fees-distribution\x20operation\x20(permission\x20365),\x20with\x20or\x20without\x20a\x20Passport.\x20DIRECT-SALES\x20default:\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20fee\x20(single\x20Rate\x2010000\x20leg)\x20—\x20WoWok\x20takes\x20no\x20platform\x20commission.\x20An\x20optional\x20fee\x20for\x20the\x20arbitration\x20OPERATOR\x20(the\x20arbitrator\x27s\x20own\x20declared\x20service\x20price,\x20or\x20a\x20third\x20party\x20such\x20as\x20a\x20payments/escrow\x20provider)\x20is\x20allowed\x20only\x20under\x20the\x20L3\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20the\x20parties\x20can\x20compute\x20before\x20the\x20fee\x20is\x20charged,\x20never\x20an\x20implicit\x20remainder;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20visible\x20to\x20both\x20sides\x20beforehand\x20(blank\x20silently\x20routes\x20the\x20money\x20to\x20the\x20deploying\x20account,\x20ts-sdk/w/local/index.ts:74-86);\x20(3)\x20no\x20mandatory\x20transit\x20pool,\x20and\x20the\x20fee\x20is\x20NEVER\x20taken\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all,\x20so\x20it\x20doubles\x20as\x20draining\x20the\x20pool).','applicable_scenes':['allocation_arbitration_fees'],'industry_tags':['arbitration','dispute','fees'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(must\x20match\x20Arbitration\x20fee\x20Coin\x20type)','required':!![]},{'name':'arbitrator_treasury','type':'address','description':'Arbitrator\x20Treasury\x20address\x20—\x20default\x20sole\x2010000\x20recipient\x20of\x20the\x20dispute\x20fee','required':!![]},{'name':'arbitration_operator_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20arbitration_operator_fee_bps:\x20the\x20ARBITRATION\x20OPERATOR\x27s\x20own\x20fee\x20treasury\x20(the\x20arbitrator\x27s\x20declared\x20service\x20price)\x20or\x20a\x20genuine\x20third-party\x20treasury\x20(e.g.\x20an\x20escrow\x20/\x20payments\x20provider).\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20the\x20fee\x20is\x20>\x200\x20—\x20leaving\x20it\x20blank\x20or\x20omitting\x20it\x20is\x20NOT\x20a\x20no-op:\x20the\x20share\x20silently\x20goes\x20to\x20Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/w/local/index.ts:74-86).','required':![]},{'name':'arbitrator_rate','type':'number','description':'Arbitrator\x27s\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20dispute\x20fee\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'arbitration_operator_fee_bps','type':'number','description':'The\x20ARBITRATION\x20OPERATOR\x27s\x20(or\x20a\x20named\x20third\x20party\x27s)\x20own\x20fee\x20in\x20basis\x20points,\x20default\x200.\x20Explicit\x20number\x20both\x20sides\x20can\x20compute\x20before\x20the\x20fee\x20is\x20charged;\x20arbitrator_rate\x20+\x20arbitration_operator_fee_bps\x20MUST\x20sum\x20to\x2010000.\x20WoWok\x20extracts\x20nothing,\x20so\x20there\x20is\x20no\x20platform\x20share\x20here.','required':![],'default':0x0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20Arbitration\x20ruling\x20finalized)','required':!![]}],'body':a=>{const b=assert_declared_share('T-A-08','arbitrator_rate',a['arbitrator_rate'],0x2710),c=assert_declared_share('T-A-08','arbitration_operator_fee_bps',a['arbitration_operator_fee_bps'],0x0);assert_explicit_recipient('T-A-08','arbitrator_treasury',a['arbitrator_treasury'],b),assert_explicit_recipient('T-A-08','arbitration_operator_treasury',a['arbitration_operator_treasury'],c);const d=b+c;if(d!==0x2710)throw new Error('T-A-08:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+d+'\x20(arbitrator='+b+'\x20+\x20operator_fee='+c+')');const e=[{'who':{'Entity':a['arbitrator_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&e['push']({'who':{'Entity':a['arbitration_operator_treasury']},'sharing':String(c),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Arbitration\x20fees\x20(platform\x20commission\x200):\x20arbitrator\x20'+b+'/10000'+(c>0x0?',\x20arbitration\x20operator\x27s\x20own\x20fee\x20'+c+'/10000':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':e,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Triggered\x20by\x20the\x20Arbitration\x20fees-distribution\x20operation\x20(permission\x20ARBITRATION_FEES_ALLOC=365),\x20with\x20or\x20without\x20a\x20Passport','Independent\x20from\x20Service-order\x20Allocation\x20(this\x20Allocation\x20is\x20not\x20bound\x20to\x20Order)','payment_info\x20typically\x20reuses\x20Arbitration\x27s\x20payment_info','Caller\x20MUST\x20hold\x20ARBITRATION_FEES_ALLOC=365\x20permission','DIRECT-SALES\x20DEFAULT:\x20the\x20emitted\x20rows\x20are\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20arbitrator_treasury\x20—\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20dispute\x20fee,\x20and\x20the\x2010000\x20invariant\x20holds\x20by\x20construction','arbitration_operator_fee_bps\x20is\x20the\x20arbitration\x20OPERATOR\x27s\x20own\x20declared\x20fee\x20(or\x20a\x20named\x20third\x20party\x27s),\x20default\x200;\x20it\x20requires\x20an\x20explicit\x20non-empty\x20recipient\x20and\x20is\x20never\x20an\x20implicit\x20remainder\x20or\x20a\x20Surplus\x20drain.\x20There\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template']},{'id':'T-A-09','name':'Standalone\x20periodic\x20split\x20(investment\x20dividends\x20/\x20shared\x20income)','description':'Standalone\x20Allocation\x20with\x20single\x20Allocator,\x20N\x20Rate\x20sharing\x20items\x20to\x20beneficiary\x20wallets.\x20No\x20Service\x20context.\x20Guard\x20provides\x20time-based\x20or\x20signer-based\x20access\x20control.','applicable_scenes':['allocation_standalone_periodic_split'],'industry_tags':['standalone','investment','dividends','shared_income'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(e.g.\x20\x270x2::wow::WOW\x27\x20or\x20profit\x20token\x20type)','required':!![]},{'name':'beneficiaries','type':'address[]','description':'Array\x20of\x20beneficiary\x20wallet\x20addresses\x20(NOT\x20Treasury\x20objects\x20—\x20standalone\x20mode\x20has\x20no\x20Service\x20context)','required':!![]},{'name':'rates','type':'string[]','description':'Array\x20of\x20rates\x20in\x20basis\x20points\x20(e.g.\x20[\x275000\x27,\x273000\x27,\x272000\x27]\x20=\x2050%/30%/20%).\x20MUST\x20sum\x20to\x2010000.','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20—\x20MUST\x20bind\x20Signer\x20or\x20verify\x20time-based\x20trigger\x20(R-A-3-04:\x20standalone\x20has\x20no\x20Service-layer\x20access\x20control)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20periodic\x20split'}],'body':a=>{const b=a['beneficiaries'],c=a['rates']['map'](e=>Number(e));if(b['length']!==c['length'])throw new Error('T-A-09:\x20beneficiaries\x20('+b['length']+')\x20and\x20rates\x20('+c['length']+')\x20MUST\x20have\x20equal\x20length');if(b['length']===0x0)throw new Error('T-A-09:\x20at\x20least\x201\x20beneficiary\x20required');if(b['length']>0x64)throw new Error('T-A-09:\x20beneficiaries\x20count\x20'+b['length']+'\x20exceeds\x20MAX_SHARING_COUNT\x20(100)');const d=c['reduce']((e,f)=>e+f,0x0);if(d!==0x2710)throw new Error('T-A-09:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+d);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Standalone\x20periodic\x20split','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':b['map']((e,f)=>({'who':{'Entity':e},'sharing':String(c[f]),'mode':'Rate'})),'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode\x20(§0):\x20no\x20Service/Order/Arbitration\x20context\x20required','R-A-3-04:\x20Guard\x20MUST\x20bind\x20Signer\x20or\x20verify\x20time-based\x20trigger\x20—\x20no\x20Service-layer\x20access\x20control\x20exists','F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode,\x20no\x20Surplus)','Caller\x20lifecycle:\x20receive()\x20to\x20deposit\x20funds\x20→\x20alloc()\x20to\x20trigger\x20distribution','Guard\x20should\x20bind\x20context(Signer)==authorized\x20to\x20prevent\x20unauthorized\x20alloc()\x20calls','beneficiaries\x20are\x20personal\x20wallets,\x20NOT\x20Treasury\x20objects\x20(no\x20Service\x20context)','Every\x20rate\x20is\x20an\x20EXPLICIT\x20declared\x20share\x20to\x20an\x20EXPLICIT\x20non-empty\x20address:\x20nothing\x20here\x20is\x20an\x20implicit\x20platform\x20beneficiary\x20and\x20no\x20leg\x20is\x20left\x20unset\x20(blank\x20silently\x20binds\x20the\x20deploying\x20account,\x20ts-sdk/w/local/index.ts:74-86).\x20A\x20share\x20intended\x20for\x20a\x20third\x20party\x20is\x20the\x20payer\x27s\x20own\x20declared\x20price\x20and\x20must\x20be\x20named\x20on\x20both\x20sides']},{'id':'T-A-10','name':'Standalone\x20vesting\x20release\x20(time-locked\x20multi-stage\x20unlock)','description':'Standalone\x20Allocation\x20with\x20N\x20Allocators\x20(default\x203\x20stages),\x20each\x20triggered\x20by\x20a\x20time-locked\x20Guard.\x20Stages\x201..N-1\x20use\x20Amount\x20mode;\x20final\x20stage\x20uses\x20Surplus\x20to\x20drain\x20remaining\x20balance.\x20No\x20Service\x20context.','applicable_scenes':['allocation_standalone_vesting'],'industry_tags':['standalone','vesting','time_lock','team_tokens'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(vested\x20asset,\x20e.g.\x20locked\x20team\x20tokens)','required':!![]},{'name':'beneficiary_address','type':'address','description':'Single\x20beneficiary\x20wallet\x20address\x20(vesting\x20recipient)','required':!![]},{'name':'stage_1_guard','type':'address','description':'Guard\x20for\x20stage\x201\x20(verifies\x20context(Clock).timestamp\x20>=\x20stage_1_unlock)','required':!![]},{'name':'stage_1_amount','type':'number','description':'Amount\x20to\x20release\x20at\x20stage\x201\x20(smallest\x20coin\x20unit,\x20e.g.\x20MIST)','required':!![]},{'name':'stage_2_guard','type':'address','description':'Guard\x20for\x20stage\x202\x20(verifies\x20context(Clock).timestamp\x20>=\x20stage_2_unlock)\x20—\x20MUST\x20differ\x20from\x20stage_1_guard','required':!![]},{'name':'stage_2_amount','type':'number','description':'Amount\x20to\x20release\x20at\x20stage\x202\x20(smallest\x20coin\x20unit)','required':!![]},{'name':'stage_3_guard','type':'address','description':'Guard\x20for\x20stage\x203\x20(final\x20stage,\x20uses\x20Surplus\x20to\x20drain\x20remaining\x20balance)\x20—\x20MUST\x20differ\x20from\x20stage_1_guard\x20and\x20stage_2_guard','required':!![]},{'name':'max_cap','type':'number','description':'Maximum\x20cumulative\x20release\x20cap\x20(applied\x20to\x20stages\x201\x20and\x202\x20via\x20max\x20field).\x20Stage\x203\x20uses\x20Surplus\x20so\x20no\x20max\x20needed.','required':![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20vesting\x20release\x20(3-stage\x20time-locked)'}],'body':a=>{const b=[a['stage_1_guard'],a['stage_2_guard'],a['stage_3_guard']],c=new Set(b);if(c['size']!==b['length']){const h=b['filter']((j,k)=>b['indexOf'](j)!==k);throw new Error('T-A-10:\x20stage\x20guards\x20MUST\x20be\x20unique\x20(F-A-14),\x20duplicates:\x20'+h['join'](',\x20'));}const d=Number(a['stage_1_amount']),e=Number(a['stage_2_amount']);if(d<=0x0||e<=0x0)throw new Error('T-A-10:\x20stage_1_amount\x20and\x20stage_2_amount\x20MUST\x20be\x20>\x200,\x20got\x20stage1='+d+',\x20stage2='+e);const f=d+e,g=a['max_cap']!=null?Number(a['max_cap']):null;if(g!==null&&f>g)throw new Error('T-A-10:\x20stage_1_amount\x20+\x20stage_2_amount\x20('+f+')\x20MUST\x20be\x20<=\x20max_cap\x20('+g+')\x20—\x20F-A-08\x20(EAMOUNT_EXCEEDS_MAX)');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Standalone\x20vesting\x20release\x20(3-stage\x20time-locked)','threshold':'0','allocators':[{'guard':a['stage_1_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':String(d),'mode':'Amount'}],'max':g!=null?String(g):null},{'guard':a['stage_2_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':String(e),'mode':'Amount'}],'max':g!=null?String(g):null},{'guard':a['stage_3_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':'0','mode':'Surplus'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode\x20(§0):\x20no\x20Service/Order/Arbitration\x20context\x20required','R-A-3-04:\x20Guard\x20time-lock\x20MUST\x20be\x20enforced\x20—\x20no\x20Service-layer\x20access\x20control\x20exists','F-A-14:\x20stage_1_guard,\x20stage_2_guard,\x20stage_3_guard\x20MUST\x20be\x20unique\x20(duplicate\x20guards\x20are\x20dead\x20code)','F-A-04:\x20at\x20most\x201\x20Surplus\x20per\x20Allocator\x20(stage\x203\x20uses\x20Surplus\x20to\x20drain\x20remainder)','F-A-08:\x20stage_1_amount\x20+\x20stage_2_amount\x20MUST\x20be\x20<=\x20max_cap\x20(if\x20max_cap\x20provided)','R-A-4-01:\x20if\x20caller\x20calls\x20alloc()\x20before\x20stage\x20time-lock\x20expires,\x20alloc()\x20silently\x20returns\x20—\x20caller\x20should\x20check\x20balance==0\x20after\x20alloc()','R-A-4-02:\x20Guard\x20conditions\x20SHOULD\x20be\x20mutually\x20exclusive\x20by\x20timestamp\x20(e.g.\x20stage_1:\x20ts<stage_2_unlock,\x20stage_2:\x20stage_2_unlock<=ts<stage_3_unlock,\x20stage_3:\x20ts>=stage_3_unlock)','Caller\x20lifecycle:\x20receive()\x20to\x20deposit\x20locked\x20tokens\x20→\x20alloc()\x20at\x20each\x20vesting\x20milestone','Single\x20beneficiary\x20—\x20no\x20platform\x20leg.\x20The\x20stage-3\x20Surplus\x20is\x20this\x20contract\x27s\x20own\x20vesting\x20remainder,\x20NOT\x20a\x20fee:\x20Surplus\x20calls\x20balance::withdraw_all,\x20so\x20never\x20express\x20a\x20declared\x20fee\x20through\x20a\x20Surplus\x20leg\x20(L3\x20constraint\x203)']},{'id':'T-A-11','name':'Standalone\x20payroll\x20/\x20salary\x20distribution\x20(issuer\x20+\x20Repository\x20verified)','description':'Standalone\x20Allocation\x20for\x20periodic\x20payroll:\x20employees\x20receive\x20Rate\x20shares.\x20The\x20Guard\x20binds\x20the\x20issuer\x20Signer\x20identity\x20and\x20cross-checks\x20a\x20Repository\x20payroll\x20record\x20(period\x20and\x20amounts).\x20No\x20Service\x20context.','applicable_scenes':['allocation_standalone_payroll'],'industry_tags':['standalone','payroll','salary','compensation','hr'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20used\x20for\x20payroll\x20(e.g.\x20\x270x2::wow::WOW\x27)','required':!![]},{'name':'employees','type':'address[]','description':'Employee\x20wallet\x20addresses\x20(Recipient::Entity\x20recipients)','required':!![]},{'name':'rates','type':'string[]','description':'Per-employee\x20rates\x20in\x20basis\x20points\x20(e.g.\x20[\x276000\x27,\x274000\x27]).\x20MUST\x20sum\x20to\x2010000.','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20that\x20binds\x20Signer\x20==\x20issuer\x20AND\x20cross-checks\x20the\x20Repository\x20payroll\x20record\x20(both\x20required)','required':!![]},{'name':'payroll_period','type':'string','description':'Human-readable\x20period\x20label\x20(e.g.\x20\x272025-W26\x27)\x20—\x20recorded\x20in\x20the\x20Allocation\x20description\x20for\x20audit','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20payroll\x20distribution'}],'body':a=>{const b=a['employees'],c=a['rates']['map'](e=>Number(e));if(b['length']!==c['length'])throw new Error('T-A-11:\x20employees\x20('+b['length']+')\x20and\x20rates\x20('+c['length']+')\x20MUST\x20have\x20equal\x20length');if(b['length']===0x0)throw new Error('T-A-11:\x20at\x20least\x201\x20employee\x20required');if(b['length']>0x64)throw new Error('T-A-11:\x20employees\x20count\x20'+b['length']+'\x20exceeds\x20MAX_SHARING_COUNT\x20(100)');const d=c['reduce']((e,f)=>e+f,0x0);if(d!==0x2710)throw new Error('T-A-11:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+d);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':(a['description']??'Standalone\x20payroll\x20distribution')+'\x20—\x20period:\x20'+a['payroll_period'],'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':b['map']((e,f)=>({'who':{'Entity':e},'sharing':String(c[f]),'mode':'Rate'})),'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode:\x20no\x20Service/Order/Arbitration\x20context\x20required','RC-FIND-04:\x20the\x20Guard\x20MUST\x20bind\x20the\x20issuer\x20identity\x20(Signer\x20==\x20employer/admin,\x20or\x20a\x20Permission\x20member)\x20—\x20standalone\x20has\x20no\x20Service\x20access-control\x20layer','Repository\x20distinction:\x20the\x20Guard\x20MUST\x20cross-check\x20the\x20Repository\x20payroll\x20record\x20(period\x20hash,\x20amounts\x20and\x20recipients)\x20so\x20the\x20distribution\x20is\x20tied\x20to\x20auditable\x20work/payroll\x20data','Auditability:\x20the\x20Guard\x20rules\x20are\x20public\x20—\x20third\x20parties\x20verify\x20who\x20may\x20distribute\x20and\x20what\x20inputs\x20distinguish\x20a\x20valid\x20payroll','F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode)','Caller\x20lifecycle:\x20issuer\x20receive()\x20to\x20fund\x20payroll\x20→\x20alloc()\x20after\x20the\x20Repository\x20record\x20for\x20the\x20period\x20is\x20committed','Employees\x20are\x20personal\x20wallets\x20(Recipient::Entity),\x20never\x20Recipient::Signer','The\x20issuer/employer\x20is\x20the\x20payer\x20and\x20keeps\x20the\x20whole\x20payroll\x20pool\x20by\x20default:\x20there\x20is\x20no\x20platform\x20share\x20in\x20this\x20template.\x20Every\x20rate\x20is\x20an\x20explicit\x20per-employee\x20price\x20to\x20an\x20explicit\x20non-empty\x20address\x20(blank\x20silently\x20binds\x20the\x20deploying\x20account,\x20ts-sdk/w/local/index.ts:74-86),\x20and\x20sum(rates)\x20MUST\x20stay\x2010000\x20so\x20no\x20residual\x20stays\x20claimable']}];export const ALLOCATION_TEMPLATES_VERSION='1.1.0';export function getAllTemplates(){return[...ALLOCATION_TEMPLATES];}export function getTemplateById(a){return ALLOCATION_TEMPLATES['find'](b=>b['id']===a);}export function getTemplatesByScene(a){return ALLOCATION_TEMPLATES['filter'](b=>b['applicable_scenes']['includes'](a));}export function getTemplatesByIndustry(a){return ALLOCATION_TEMPLATES['filter'](b=>b['industry_tags']['includes'](a)||b['industry_tags']['includes']('universal'));}export function suggestTemplateForScene(a){const b=getTemplatesByScene(a);return b['length']>0x0?b[0x0]:undefined;}export function listTemplates(){return ALLOCATION_TEMPLATES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'scenes':a['applicable_scenes']}));}export function fillTemplate(a,b){const c=getTemplateById(a);if(!c)return{'ok':![],'error':'Template\x20'+a+'\x20not\x20found'};for(const d of c['params']){if(d['required']&&!(d['name']in b))return{'ok':![],'error':'Missing\x20required\x20param:\x20'+d['name']};}try{return{'ok':!![],'body':c['body'](b)};}catch(f){return{'ok':![],'error':f instanceof Error?f['message']:String(f)};}}
|
|
1
|
+
function assert_declared_share(a,b,c,d){const e=c===undefined||c===null||c===''?d:c,f=Number(e);if(!Number['isInteger'](f))throw new Error('E-RATE-EXPLICIT:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20an\x20explicit\x20integer\x20number\x20of\x20basis\x20points\x20'+('(the\x20buyer\x20must\x20be\x20able\x20to\x20compute\x20it\x20pre-order;\x20never\x20an\x20implicit\x20remainder),\x20got\x20'+String(c)));if(f<0x0||f>0x2710)throw new Error('E-RATE-RANGE:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20within\x20[0,\x2010000],\x20got\x20'+f);return f;}function assert_explicit_recipient(a,b,c,d){if(d<=0x0)return;const e=typeof c==='string'?c['trim']():'';if(e['length']===0x0)throw new Error('E-RECIPIENT-UNDEFINED:\x20'+a+':\x20'+b+'\x20MUST\x20be\x20a\x20non-empty\x20explicit\x20recipient\x20'+('because\x20its\x20rate\x20is\x20'+d+'\x20>\x200.\x20A\x20blank/omitted\x20recipient\x20silently\x20falls\x20back\x20to\x20')+'Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20'+'so\x20the\x20outflow\x20would\x20go\x20to\x20whoever\x20ran\x20the\x20deploy.');if(e['toLowerCase']()['startsWith']('0x')){const f=e['slice'](0x2);if(f['length']===0x0||!/^[0-9a-f]+$/['test'](f)||/^0+$/['test'](f))throw new Error('E-RECIPIENT-UNDEFINED:\x20'+a+':\x20'+b+'\x20looks\x20like\x20an\x20address\x20but\x20carries\x20no\x20'+('identity\x20(\x22'+e+'\x22).\x20Point\x20it\x20at\x20the\x20declared\x20recipient\x20Entity\x20(a\x20Treasury/Entity\x20address\x20the\x20')+'buyer\x20can\x20see\x20pre-order).');}}export const ALLOCATION_TEMPLATES=[{'id':'T-A-01','name':'Single\x20Rate\x20100%\x20to\x20Treasury','description':'Simplest\x20allocation\x20—\x20single\x20Allocator,\x20single\x20Rate=10000\x20sharing\x20to\x20one\x20Treasury/personal\x20address','applicable_scenes':['allocation_merchant_full_payment'],'industry_tags':['universal','retail','service'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(e.g.\x20\x270x2::wow::WOW\x27)','required':!![]},{'name':'recipient_address','type':'address','description':'Treasury\x20or\x20personal\x20wallet\x20address\x20to\x20receive\x20100%','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Single\x20Rate\x20100%\x20allocation'}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Single\x20Rate\x20100%\x20allocation','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['recipient_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['Simplest\x20configuration\x20—\x20no\x20multi-party\x20coordination','Guard\x20only\x20needs\x20to\x20verify\x20order\x20status,\x20no\x20complex\x20conditions','Suitable\x20for\x20solo\x20merchants\x20or\x20single-treasury\x20services','DIRECT-SALES\x20DEFAULT\x20SHAPE\x20(L2):\x20this\x20IS\x20the\x20default\x20payout\x20form\x20—\x20one\x20Rate\x2010000\x20leg\x20to\x20the\x20merchant\x27s\x20own\x20Entity.\x20No\x20platform\x20leg\x20exists,\x20and\x20nothing\x20is\x20left\x20over','If\x20the\x20merchant\x20declares\x20its\x20OWN\x20fee,\x20use\x20T-A-02\x20(an\x20explicit\x20fee\x20leg\x20to\x20an\x20explicit\x20non-empty\x20recipient)\x20instead\x20of\x20shrinking\x20this\x20leg\x20and\x20routing\x20the\x20difference\x20through\x20an\x20implicit\x20remainder\x20(L3)','A\x20BLANK\x20recipient_address\x20is\x20NOT\x20a\x20no-op:\x20it\x20resolves\x20to\x20Account.Instance().get_address(undefined),\x20the\x20logged-in/deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91)\x20—\x20so\x20this\x20template\x20pays\x20whoever\x20ran\x20the\x20deploy']},{'id':'T-A-02','name':'Merchant\x20payout\x20+\x20optional\x20declared\x20fee\x20/\x20third-party\x20leg\x20(merchant\x20keeps\x20100%\x20by\x20default)','description':'DIRECT-SALES\x20split:\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20by\x20default\x20(one\x20Rate\x2010000\x20leg\x20to\x20its\x20own\x20Entity).\x20Optional\x20extra\x20legs\x20are\x20(a)\x20the\x20merchant\x27s\x20OWN\x20service\x20fee\x20—\x20only\x20when\x20the\x20merchant\x20IS\x20the\x20aggregator\x20—\x20and\x20(b)\x20a\x20genuine\x20third-party\x20payment\x20(logistics\x20provider,\x20arbitrator,\x20partner),\x20which\x20is\x20a\x20payment\x20for\x20a\x20service,\x20not\x20platform\x20extraction.\x20Pure\x20Rate\x20mode:\x20the\x20emitted\x20sharing\x20rows\x20MUST\x20sum\x20to\x20exactly\x2010000,\x20and\x20with\x20the\x20default\x20parameters\x20they\x20are\x20a\x20single\x2010000\x20row.\x20L3\x20fee\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20the\x20buyer\x20can\x20compute\x20BEFORE\x20ordering,\x20never\x20an\x20implicit\x20remainder\x20such\x20as\x20\x27order\x20total\x20-\x20segment\x20sums\x27;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20the\x20buyer\x20can\x20see\x20pre-order\x20(a\x20blank\x20recipient\x20is\x20NOT\x20a\x20no-op\x20—\x20it\x20falls\x20back\x20to\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91);\x20(3)\x20no\x20mandatory\x20transit\x20pool\x20on\x20the\x20payout\x20path,\x20and\x20the\x20fee\x20is\x20NEVER\x20taken\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all,\x20so\x20it\x20doubles\x20as\x20draining\x20the\x20pool).\x20WoWok\x20itself\x20takes\x20nothing.','applicable_scenes':['allocation_standard_three_way_split'],'industry_tags':['retail','ecommerce','logistics'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Entity\x20that\x20receives\x20its\x20own\x20sale\x20proceeds\x20—\x20the\x20direct-sales\x20destination.\x20Required\x20and\x20never\x20blank\x20(blank\x20silently\x20routes\x20the\x20payout\x20to\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91).','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20merchant_service_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20merchant_service_fee_bps\x20>\x200\x20—\x20leaving\x20it\x20blank\x20or\x20omitting\x20it\x20is\x20NOT\x20a\x20no-op:\x20the\x20share\x20silently\x20goes\x20to\x20Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91).\x20Pass\x20merchant_treasury\x20if\x20the\x20merchant\x20charges\x20itself.','required':![]},{'name':'third_party_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20third_party_rate\x20(e.g.\x20the\x20logistics\x20provider\x27s\x20own\x20Treasury).\x20MUST\x20be\x20explicit\x20and\x20non-empty\x20whenever\x20third_party_rate\x20>\x200\x20—\x20same\x20blank-fallback\x20hazard\x20as\x20merchant_fee_treasury.','required':![]},{'name':'merchant_rate','type':'number','description':'Merchant\x27s\x20own\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'merchant_service_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20in\x20basis\x20points.\x20KEEP\x20AT\x200\x20unless\x20the\x20merchant\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium\x20/\x20an\x20OTA\x20that\x20really\x20is\x20the\x20seller\x27s\x20counterparty).\x20WoWok\x20extracts\x20nothing\x20—\x20this\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20price,\x20never\x20a\x20platform\x20share.\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20before\x20ordering;\x20merchant_rate\x20+\x20merchant_service_fee_bps\x20+\x20third_party_rate\x20MUST\x20sum\x20to\x2010000.','required':![],'default':0x0},{'name':'third_party_rate','type':'number','description':'Rate\x20for\x20a\x20genuine\x20third-party\x20payment\x20(logistics\x20provider\x20/\x20arbitrator\x20/\x20supply-chain\x20partner),\x20default\x200.\x20Kept\x20expressible\x20on\x20purpose\x20—\x20a\x20real\x20provider\x20fee\x20is\x20a\x20payment\x20FOR\x20a\x20service\x20—\x20but\x20it\x20must\x20be\x20an\x20explicit\x20number\x20with\x20an\x20explicit\x20recipient,\x20exactly\x20like\x20the\x20merchant\x20fee.','required':![],'default':0x0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20order\x20completion\x20+\x20service\x20binding)','required':!![]}],'body':a=>{const b=assert_declared_share('T-A-02','merchant_rate',a['merchant_rate'],0x2710),c=assert_declared_share('T-A-02','merchant_service_fee_bps',a['merchant_service_fee_bps'],0x0),d=assert_declared_share('T-A-02','third_party_rate',a['third_party_rate'],0x0);assert_explicit_recipient('T-A-02','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-02','merchant_fee_treasury',a['merchant_fee_treasury'],c),assert_explicit_recipient('T-A-02','third_party_treasury',a['third_party_treasury'],d);const e=b+c+d;if(e!==0x2710)throw new Error('T-A-02:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+e+'\x20'+('(merchant='+b+'\x20+\x20merchant_service_fee='+c+'\x20+\x20third_party='+d+')'));const f=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&f['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(c),'mode':'Rate'}),d>0x0&&f['push']({'who':{'Entity':a['third_party_treasury']},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Direct-sales\x20payout\x20(platform\x20commission\x200):\x20merchant\x20'+b+'/10000'+(c>0x0?',\x20merchant\x27s\x20own\x20service\x20fee\x20'+c+'/10000':'')+(d>0x0?',\x20third\x20party\x20(e.g.\x20logistics)\x20'+d+'/10000':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':f,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode,\x20no\x20Surplus)\x20—\x20a\x20Rate\x20sum\x20<\x2010000\x20with\x20no\x20Surplus\x20recipient\x20leaves\x20residual\x20balance\x20that\x20ANYONE\x20passing\x20the\x20same\x20Guard\x20can\x20claim\x20repeatedly\x20(E-2\x20/\x20finding\x20T-04)','DEFAULT\x20PARAMETERS\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury:\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20and\x20the\x2010000\x20invariant\x20holds\x20by\x20construction','merchant_service_fee_bps\x20is\x20the\x20MERCHANT\x27s\x20own\x20fee\x20(merchant\x20IS\x20the\x20aggregator),\x20default\x200\x20—\x20WoWok\x20takes\x20no\x20platform\x20commission\x20and\x20there\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template','third_party_rate\x20is\x20a\x20real\x20provider\x20payment\x20(logistics\x20/\x20arbitrator\x20/\x20partner),\x20not\x20platform\x20extraction;\x20keep\x20it\x20expressible,\x20but\x20name\x20the\x20payee\x20explicitly','Never\x20express\x20a\x20fee\x20as\x20an\x20implicit\x20remainder\x20(\x27the\x20merchant\x20keeps\x20whatever\x20is\x20left\x27)\x20and\x20never\x20take\x20one\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all)','Treasury\x20Permission\x20should\x20match\x20Service\x20Permission\x20(R-A-3-02)','Guard\x20should\x20verify\x20order.service\x20binding\x20(query\x201563)\x20to\x20prevent\x20cross-project\x20bypass']},{'id':'T-A-03','name':'Refund-first\x20+\x20Surplus-to-merchant\x20(Amount\x20+\x20Surplus\x20hybrid)','description':'Single\x20Allocator\x20with\x202\x20sharing\x20items:\x20Amount=refund_value\x20to\x20customer,\x20Surplus\x20to\x20merchant.\x20No\x20fee\x20and\x20no\x20platform\x20leg:\x20the\x20Surplus\x20is\x20the\x20merchant\x27s\x20residual\x20of\x20a\x20mixed\x20refund/delivery\x20pool,\x20NOT\x20a\x20fee\x20mechanism','applicable_scenes':['allocation_refund_first_surplus_to_merchant'],'industry_tags':['retail','refund','customer_protection'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'customer_address','type':'address','description':'Customer\x20address\x20to\x20receive\x20refund\x20Amount','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20to\x20receive\x20Surplus','required':!![]},{'name':'refund_amount','type':'number','description':'Refund\x20amount\x20in\x20smallest\x20coin\x20unit\x20(e.g.\x20MIST\x20for\x20WOW)','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20refund\x20approval)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Refund-first\x20+\x20Surplus-to-merchant'}],'body':a=>{const b=Number(a['refund_amount']);if(b<=0x0)throw new Error('T-A-03:\x20refund_amount\x20MUST\x20be\x20>\x200,\x20got\x20'+b);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Refund-first\x20+\x20Surplus-to-merchant','threshold':String(b),'allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'Entity':a['customer_address']},'sharing':String(b),'mode':'Amount'},{'who':{'Entity':a['merchant_treasury']},'sharing':'0','mode':'Surplus'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-04:\x20at\x20most\x201\x20Surplus\x20per\x20Allocator\x20(✓\x20single\x20Surplus\x20here)','F-A-07:\x20threshold\x20=\x20refundAmount\x20(ensure\x20balance\x20covers\x20Amount)','the\x20fix\x20is\x20cached\x20as\x20refundAmount\x20when\x20the\x20Allocator\x20is\x20added','Guard\x20must\x20verify\x20customer\x20refund\x20eligibility\x20(e.g.\x20order\x20status\x20=\x20Refunded)','SURPLUS\x20IS\x20NOT\x20A\x20FEE:\x20Surplus\x20calls\x20balance::withdraw_all\x20(allocation.move:420),\x20so\x20a\x20fee\x20taken\x20that\x20way\x20doubles\x20as\x20draining\x20the\x20pool\x20(L3\x20constraint\x203).\x20A\x20declared\x20service\x20fee\x20belongs\x20on\x20the\x20purchase-side\x20allocation\x20(T-A-02)\x20as\x20an\x20explicit\x20Rate\x20leg,\x20never\x20here','The\x20Surplus\x20recipient\x20is\x20the\x20merchant\x20(the\x20counterparty\x20of\x20the\x20delivered\x20part),\x20not\x20an\x20unnamed\x20third\x20party\x20—\x20but\x20pin\x20refund_amount\x20to\x20the\x20refund\x20actually\x20owed,\x20or\x20a\x20smaller/empty\x20refund\x20lets\x20the\x20Surplus\x20leg\x20absorb\x20money\x20that\x20is\x20not\x20the\x20merchant\x27s']},{'id':'T-A-04','name':'Treasury\x20+\x20Personal\x20alternative\x20(caller-specified\x20guard,\x202\x20Allocators)','description':'2\x20Allocators\x20as\x20alternative\x20strategies:\x20caller\x20selects\x20Treasury\x20or\x20Personal\x20wallet\x20via\x20alloc_by_guard\x20(hard\x20verification\x20per\x20call)','applicable_scenes':['allocation_treasury_personal_alternatives'],'industry_tags':['universal','alternative','treasury'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'treasury_address','type':'address','description':'Treasury\x20address\x20(primary\x20recipient)','required':!![]},{'name':'personal_address','type':'address','description':'Personal\x20wallet\x20address\x20(alternative\x20recipient)','required':!![]},{'name':'treasury_guard','type':'address','description':'Guard\x20for\x20Treasury\x20path\x20(verifies\x20treasury\x20operational)','required':!![]},{'name':'personal_guard','type':'address','description':'Guard\x20for\x20Personal\x20path\x20(verifies\x20personal\x20wallet\x20active)\x20—\x20MUST\x20differ\x20from\x20treasury_guard','required':!![]}],'body':a=>{if(a['treasury_guard']===a['personal_guard'])throw new Error('T-A-04:\x20treasury_guard\x20and\x20personal_guard\x20MUST\x20be\x20different\x20addresses\x20(F-A-14:\x20allocators[].guard\x20must\x20be\x20unique)');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Treasury\x20/\x20Personal\x20alternative\x20(caller-specified\x20guard)','threshold':'0','allocators':[{'guard':a['treasury_guard'],'sharing':[{'who':{'Entity':a['treasury_address']},'sharing':'10000','mode':'Rate'}],'max':null},{'guard':a['personal_guard'],'sharing':[{'who':{'Entity':a['personal_address']},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['F-A-14:\x20treasury_guard\x20!=\x20personal_guard\x20(Allocator\x20Guards\x20must\x20be\x20unique)','caller-specified\x20guard:\x20alloc_by_guard\x20explicitly\x20selects\x20an\x20Allocator;\x20the\x20Passport\x27s\x20guard\x20result\x20is\x20hard-verified\x20(failure\x20aborts\x20E_VERIFY_FAILED)','No\x20auto-fallback:\x20on\x20verification\x20failure\x20the\x20caller\x20must\x20switch\x20guard\x20and\x20retry','R-A-4-02:\x20if\x20the\x20caller\x27s\x20submitted\x20Passport\x20satisfies\x20both\x20Guards\x20simultaneously,\x20the\x20caller\x20may\x20freely\x20choose\x20between\x20the\x20two\x20paths\x20(mutual\x20exclusion\x20is\x20a\x20design\x20clarity\x20recommendation,\x20not\x20a\x20correctness\x20requirement)','Each\x20Allocator\x20sums\x20to\x2010000\x20INDEPENDENTLY\x20—\x20the\x20Rate-total\x20invariant\x20is\x20per\x20Allocator,\x20not\x20across\x20Allocators,\x20and\x20each\x20of\x20the\x20two\x20paths\x20pays\x20ONE\x20recipient\x20the\x20full\x20amount\x20(no\x20split,\x20no\x20platform\x20leg,\x20no\x20residual)']},{'id':'T-A-05','name':'Tiered\x20by\x20order\x20amount\x20(mutually\x20exclusive\x20Guard\x20conditions)','description':'2\x20Allocators\x20triggered\x20by\x20mutually\x20exclusive\x20Guard\x20conditions\x20(small\x20order\x20vs\x20large\x20order).\x20DIRECT-SALES\x20default:\x20BOTH\x20tiers\x20pay\x20the\x20merchant\x20100%\x20—\x20the\x20tier\x20selects\x20the\x20guard,\x20not\x20a\x20cut.\x20The\x20large\x20tier\x20may\x20add\x20the\x20merchant\x27s\x20OWN\x20declared\x20fee,\x20under\x20the\x20L3\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20computable\x20before\x20ordering,\x20never\x20an\x20implicit\x20remainder;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20(blank\x20silently\x20routes\x20it\x20to\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91);\x20(3)\x20no\x20mandatory\x20transit\x20pool,\x20and\x20never\x20a\x20Surplus\x20fee\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all).\x20No\x20platform\x20leg\x20exists\x20in\x20this\x20template.','applicable_scenes':['allocation_tiered_by_order_amount'],'industry_tags':['retail','tiered_pricing','volume_discount'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20(receives\x20the\x20full\x20sale\x20on\x20both\x20tiers\x20by\x20default)','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20large_order_merchant_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20that\x20fee\x20is\x20>\x200\x20—\x20blank\x20or\x20omitted\x20silently\x20pays\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20not\x20a\x20no-op.','required':![]},{'name':'small_order_guard','type':'address','description':'Guard\x20verifying\x20order.amount\x20<\x20threshold\x20(small\x20order\x20path)','required':!![]},{'name':'large_order_guard','type':'address','description':'Guard\x20verifying\x20order.amount\x20>=\x20threshold\x20(large\x20order\x20path)\x20—\x20MUST\x20differ\x20from\x20small_order_guard','required':!![]},{'name':'small_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20on\x20the\x20small-order\x20tier.\x20Default\x20(and\x20only)\x20value\x2010000\x20—\x20direct\x20sales:\x20no\x20platform\x20take.','required':![],'default':0x2710},{'name':'large_order_merchant_rate','type':'number','description':'Merchant\x20rate\x20on\x20the\x20large-order\x20tier.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(there\x20is\x20no\x20platform\x20take\x20to\x20deduct).','required':![],'default':0x2710},{'name':'large_order_merchant_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20on\x20the\x20large-order\x20tier,\x20in\x20basis\x20points.\x20KEEP\x20AT\x200\x20unless\x20the\x20merchant\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium).\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20pre-order;\x20large_order_merchant_rate\x20+\x20large_order_merchant_fee_bps\x20MUST\x20sum\x20to\x2010000.\x20WoWok\x20takes\x20no\x20platform\x20commission.','required':![],'default':0x0}],'body':a=>{if(a['small_order_guard']===a['large_order_guard'])throw new Error('T-A-05:\x20small_order_guard\x20and\x20large_order_guard\x20MUST\x20be\x20different\x20addresses\x20(F-A-14)');const b=assert_declared_share('T-A-05','small_order_merchant_rate',a['small_order_merchant_rate'],0x2710);if(b!==0x2710)throw new Error('T-A-05:\x20small_order_merchant_rate\x20MUST\x20equal\x2010000\x20(pure\x20Rate,\x20no\x20Surplus\x20in\x20this\x20Allocator),\x20got\x20'+b);const c=assert_declared_share('T-A-05','large_order_merchant_rate',a['large_order_merchant_rate'],0x2710),d=assert_declared_share('T-A-05','large_order_merchant_fee_bps',a['large_order_merchant_fee_bps'],0x0);assert_explicit_recipient('T-A-05','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-05','merchant_fee_treasury',a['merchant_fee_treasury'],d);const e=c+d;if(e!==0x2710)throw new Error('T-A-05:\x20large_order\x20rates\x20MUST\x20sum\x20to\x2010000,\x20got\x20'+e+'\x20(merchant='+c+'\x20+\x20merchant_fee='+d+')');const f=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(c),'mode':'Rate'}];return d>0x0&&f['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Tiered\x20by\x20order\x20amount\x20(platform\x20commission\x200):\x20small=100%\x20merchant,\x20'+('large='+c+'/10000\x20merchant')+(d>0x0?'\x20+\x20'+d+'/10000\x20merchant\x27s\x20own\x20service\x20fee':''),'threshold':'0','allocators':[{'guard':a['small_order_guard'],'sharing':[{'who':{'Entity':a['merchant_treasury']},'sharing':'10000','mode':'Rate'}],'max':null},{'guard':a['large_order_guard'],'sharing':f,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Guard\x20conditions\x20MUST\x20be\x20mutually\x20exclusive\x20(R-A-4-02)','Sequence-sensitive:\x20strict\x20condition\x20(small\x20order)\x20first,\x20relaxed\x20condition\x20(large\x20order)\x20last','Guard\x20queries\x20order.amount\x20(query\x201561)\x20to\x20determine\x20which\x20Allocator\x20fires','If\x20neither\x20Guard\x20passes,\x20funds\x20are\x20silently\x20locked\x20(R-A-4-02)','DIRECT-SALES\x20DEFAULT:\x20both\x20tiers\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury\x20—\x20the\x20tier\x20picks\x20the\x20guard,\x20not\x20a\x20cut.\x20Each\x20Allocator\x20sums\x20to\x2010000\x20on\x20its\x20own','large_order_merchant_fee_bps\x20is\x20the\x20merchant\x27s\x20OWN\x20large-tier\x20fee\x20(default\x200),\x20only\x20for\x20a\x20merchant\x20that\x20IS\x20the\x20aggregator;\x20it\x20is\x20never\x20a\x20platform\x20take,\x20never\x20an\x20implicit\x20remainder,\x20and\x20its\x20recipient\x20must\x20be\x20explicit\x20and\x20non-empty']},{'id':'T-A-06','name':'Dynamic\x20recipient\x20via\x20GuardIdentifier\x20(referrer\x20from\x20Passport)','description':'Single\x20Allocator\x20whose\x20Rate\x20sharing\x20items\x20include\x20one\x20recipient\x20resolved\x20from\x20the\x20customer\x27s\x20Passport\x20table[identifier].\x20DIRECT-SALES\x20default:\x20merchant_rate\x2010000\x20and\x20every\x20optional\x20leg\x200,\x20so\x20the\x20emitted\x20template\x20is\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20the\x20merchant.\x20Two\x20optional\x20legs\x20may\x20be\x20switched\x20on,\x20each\x20under\x20the\x20L3\x20rule\x20(explicit\x20number\x20computable\x20pre-order;\x20explicit\x20non-empty\x20recipient\x20—\x20blank\x20silently\x20pays\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91;\x20no\x20mandatory\x20transit\x20pool,\x20never\x20a\x20Surplus\x20fee\x20leg):\x20the\x20merchant\x27s\x20OWN\x20service\x20fee\x20(only\x20when\x20the\x20merchant\x20IS\x20the\x20aggregator)\x20and\x20a\x20referral/reward\x20to\x20a\x20referrer\x20the\x20buyer\x20names.\x20There\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template.','applicable_scenes':['allocation_dynamic_recipient'],'industry_tags':['referral','affiliate','marketing'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'merchant_treasury','type':'address','description':'Merchant\x20Treasury\x20address\x20(default:\x20the\x20sole\x2010000\x20recipient)','required':!![]},{'name':'merchant_fee_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20merchant_service_fee_bps.\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20that\x20fee\x20is\x20>\x200\x20—\x20blank\x20or\x20omitted\x20silently\x20pays\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91).\x20NEVER\x20route\x20the\x20merchant\x27s\x20own\x20fee\x20through\x20GuardIdentifier:\x20that\x20recipient\x20is\x20buyer-submitted,\x20not\x20merchant-declared.','required':![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(must\x20be\x20configured\x20with\x20identifier=0\x20as\x20address\x20type)','required':!![]},{'name':'passport_identifier','type':'number','description':'Passport\x20table\x20identifier\x20(u8,\x200-255)\x20carrying\x20the\x20referrer\x20address\x20the\x20buyer\x20submits\x20—\x20only\x20consulted\x20when\x20referrer_rate\x20>\x200\x20(default\x200)','required':![],'default':0x0},{'name':'merchant_rate','type':'number','description':'Merchant\x27s\x20own\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20merchant\x20keeps\x20the\x20whole\x20sale\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'merchant_service_fee_bps','type':'number','description':'The\x20MERCHANT\x27S\x20OWN\x20service\x20fee\x20in\x20basis\x20points,\x20default\x200.\x20Only\x20for\x20a\x20merchant\x20that\x20IS\x20the\x20aggregator\x20(chain\x20/\x20multi-supplier\x20orchestrator\x20/\x20consortium).\x20Explicit\x20number\x20the\x20buyer\x20can\x20compute\x20pre-order;\x20merchant_rate\x20+\x20merchant_service_fee_bps\x20+\x20referrer_rate\x20MUST\x20sum\x20to\x2010000.','required':![],'default':0x0},{'name':'referrer_rate','type':'number','description':'Referral\x20/\x20reward\x20rate\x20paid\x20to\x20the\x20referrer\x20the\x20BUYER\x20names\x20in\x20its\x20Passport,\x20default\x200.\x20This\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20acquisition\x20price,\x20not\x20a\x20platform\x20share\x20—\x20keep\x20it\x200\x20unless\x20the\x20merchant\x20actually\x20runs\x20a\x20referral\x20programme,\x20and\x20never\x20route\x20the\x20merchant\x27s\x20own\x20fee\x20here.','required':![],'default':0x0}],'body':a=>{const b=assert_declared_share('T-A-06','merchant_rate',a['merchant_rate'],0x2710),c=assert_declared_share('T-A-06','merchant_service_fee_bps',a['merchant_service_fee_bps'],0x0),d=assert_declared_share('T-A-06','referrer_rate',a['referrer_rate'],0x0),e=b+c+d;if(e!==0x2710)throw new Error('T-A-06:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+e+'\x20(merchant='+b+'\x20+\x20merchant_service_fee='+c+'\x20+\x20referrer='+d+')');assert_explicit_recipient('T-A-06','merchant_treasury',a['merchant_treasury'],b),assert_explicit_recipient('T-A-06','merchant_fee_treasury',a['merchant_fee_treasury'],c);const f=Number(a['passport_identifier']??0x0);if(f<0x0||f>0xff)throw new Error('T-A-06:\x20passport_identifier\x20MUST\x20be\x20u8\x20(0-255),\x20got\x20'+f);const g=[{'who':{'Entity':a['merchant_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&g['push']({'who':{'Entity':a['merchant_fee_treasury']},'sharing':String(c),'mode':'Rate'}),d>0x0&&g['push']({'who':{'GuardIdentifier':f},'sharing':String(d),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Dynamic\x20recipient\x20(platform\x20commission\x200):\x20merchant\x20'+b+'/10000'+(c>0x0?',\x20merchant\x27s\x20own\x20service\x20fee\x20'+c+'/10000':'')+(d>0x0?',\x20referrer\x20'+d+'/10000\x20(from\x20Passport\x20identifier='+f+')':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':g,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['DEFAULT\x20PARAMETERS\x20emit\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20merchant_treasury;\x20to\x20exercise\x20the\x20GuardIdentifier\x20form\x20set\x20referrer_rate\x20>\x200\x20and\x20lower\x20merchant_rate\x20by\x20exactly\x20that\x20amount\x20(the\x20emitted\x20rows\x20must\x20still\x20total\x2010000)','F-A-13:\x20Passport\x20table[identifier]\x20MUST\x20be\x20address\x20type\x20(else\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS=1)','The\x20Guard\x20identifier\x20slot\x27s\x20address-type\x20check\x20MUST\x20pass\x20when\x20the\x20Allocator\x20is\x20added\x20(else\x20the\x20Allocator\x20add\x20fails)','Customer\x20must\x20submit\x20Passport\x20with\x20referrer\x20address\x20at\x20the\x20specified\x20identifier\x20slot','Guard\x20should\x20verify\x20Passport\x20completeness\x20before\x20alloc()\x20executes','The\x20GuardIdentifier\x20recipient\x20is\x20CHOSEN\x20BY\x20THE\x20BUYER\x20(the\x20submitted\x20address\x20bound\x20to\x20for_object),\x20so\x20the\x20Guard\x20—\x20not\x20the\x20template\x20—\x20is\x20what\x20makes\x20it\x20trustworthy:\x20bind\x20it\x20(e.g.\x20an\x20allow-listed\x20referrer)\x20before\x20enabling\x20a\x20non-zero\x20referrer_rate,\x20and\x20never\x20use\x20it\x20for\x20the\x20merchant\x27s\x20own\x20fee','merchant_service_fee_bps\x20is\x20the\x20merchant\x27s\x20own\x20declared\x20fee,\x20default\x200,\x20and\x20requires\x20an\x20explicit\x20non-empty\x20recipient\x20—\x20there\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template']},{'id':'T-A-07','name':'Refund\x20to\x20the\x20submitted\x20Order\x20(100%\x20delivered\x20to\x20the\x20order\x20as\x20escrow)','description':'Single\x20Allocator,\x201\x20Rate=10000\x20sharing\x20whose\x20recipient\x20is\x20the\x20order\x20submitted\x20at\x20alloc\x20time\x20(Guard\x20table\x20identifier\x200).\x20The\x20funds\x20are\x20delivered\x20to\x20that\x20order\x20and\x20received\x20by\x20its\x20owner.','applicable_scenes':['allocation_refund_to_order'],'industry_tags':['refund','customer_protection','order_lifecycle'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20verifying\x20the\x20submitted\x20order\x20qualifies\x20(e.g.\x20order\x20at\x20the\x20refund\x20node,\x20order.service\x20==\x20host\x20service).\x20Its\x20table\x20needs\x20an\x20address-typed\x20b_submission\x20slot\x20at\x20identifier\x200.','required':!![]}],'body':a=>({'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Refund\x20to\x20the\x20submitted\x20Order\x20(100%\x20delivered\x20to\x20the\x20order\x20as\x20escrow)','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':[{'who':{'GuardIdentifier':0x0},'sharing':'10000','mode':'Rate'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}}),'notes':['The\x20Guard\x20table\x20MUST\x20have\x20an\x20address-typed\x20b_submission\x20slot\x20at\x20identifier\x200\x20carrying\x20the\x20submitted\x20order\x20(else\x20the\x20Allocator\x20add\x20fails\x20with\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS).','At\x20alloc\x20time\x20the\x20full\x20Rate\x20is\x20delivered\x20to\x20the\x20submitted\x20order\x20as\x20a\x20CoinWrapper\x20—\x20the\x20order\x20object\x20owns\x20it.\x20Its\x20owner\x20subsequently\x20receives\x20the\x20bare\x20coins\x20through\x20the\x20order\x27s\x20owner-receive\x20entry;\x20unrelated\x20addresses\x20cannot\x20intercept.','The\x20Guard\x20decides\x20which\x20submitted\x20orders\x20qualify:\x20node\x20state\x20plus\x20a\x20service-scope\x20binding\x20(order.service\x20==\x20host\x20service)\x20are\x20the\x20typical\x20conditions;\x20tightening\x20those\x20conditions\x20is\x20how\x20the\x20destination\x20is\x20controlled.','When\x20the\x20per-order\x20Allocation\x20is\x20created\x20through\x20the\x20Service\x20flow,\x20payment_info.for_object\x20is\x20set\x20to\x20the\x20order\x20the\x20allocation\x20belongs\x20to,\x20recording\x20the\x20business\x20context\x20auditors\x20can\x20query.','No\x20fee\x20leg\x20and\x20no\x20platform\x20leg:\x20a\x20refund\x20path\x20pays\x20the\x20order\x27s\x20owner\x20and\x20nothing\x20else.\x20A\x20declared\x20service\x20fee\x20belongs\x20on\x20the\x20purchase-side\x20allocation\x20(T-A-02)\x20as\x20an\x20explicit\x20Rate\x20leg\x20—\x20never\x20as\x20a\x20leg\x20here,\x20and\x20never\x20as\x20an\x20implicit\x20remainder\x20or\x20a\x20Surplus\x20drain']},{'id':'T-A-08','name':'Arbitration\x20fees\x20payout\x20(arbitrator\x20keeps\x20100%\x20by\x20default\x20/\x20optional\x20declared\x20operator\x20fee)','description':'Single\x20Allocator,\x20Rate\x20sharing\x20items\x20summing\x20to\x20exactly\x2010000.\x20Triggered\x20by\x20the\x20Arbitration\x20fees-distribution\x20operation\x20(permission\x20365),\x20with\x20or\x20without\x20a\x20Passport.\x20DIRECT-SALES\x20default:\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20fee\x20(single\x20Rate\x2010000\x20leg)\x20—\x20WoWok\x20takes\x20no\x20platform\x20commission.\x20An\x20optional\x20fee\x20for\x20the\x20arbitration\x20OPERATOR\x20(the\x20arbitrator\x27s\x20own\x20declared\x20service\x20price,\x20or\x20a\x20third\x20party\x20such\x20as\x20a\x20payments/escrow\x20provider)\x20is\x20allowed\x20only\x20under\x20the\x20L3\x20rule:\x20(1)\x20an\x20EXPLICIT\x20number\x20the\x20parties\x20can\x20compute\x20before\x20the\x20fee\x20is\x20charged,\x20never\x20an\x20implicit\x20remainder;\x20(2)\x20an\x20explicit\x20NON-EMPTY\x20recipient\x20Entity\x20visible\x20to\x20both\x20sides\x20beforehand\x20(blank\x20silently\x20routes\x20the\x20money\x20to\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91);\x20(3)\x20no\x20mandatory\x20transit\x20pool,\x20and\x20the\x20fee\x20is\x20NEVER\x20taken\x20via\x20a\x20Surplus\x20leg\x20(Surplus\x20calls\x20balance::withdraw_all,\x20so\x20it\x20doubles\x20as\x20draining\x20the\x20pool).','applicable_scenes':['allocation_arbitration_fees'],'industry_tags':['arbitration','dispute','fees'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(must\x20match\x20Arbitration\x20fee\x20Coin\x20type)','required':!![]},{'name':'arbitrator_treasury','type':'address','description':'Arbitrator\x20Treasury\x20address\x20—\x20default\x20sole\x2010000\x20recipient\x20of\x20the\x20dispute\x20fee','required':!![]},{'name':'arbitration_operator_treasury','type':'address','description':'Recipient\x20Entity\x20of\x20arbitration_operator_fee_bps:\x20the\x20ARBITRATION\x20OPERATOR\x27s\x20own\x20fee\x20treasury\x20(the\x20arbitrator\x27s\x20declared\x20service\x20price)\x20or\x20a\x20genuine\x20third-party\x20treasury\x20(e.g.\x20an\x20escrow\x20/\x20payments\x20provider).\x20MUST\x20be\x20an\x20explicit\x20NON-EMPTY\x20address\x20whenever\x20the\x20fee\x20is\x20>\x200\x20—\x20leaving\x20it\x20blank\x20or\x20omitting\x20it\x20is\x20NOT\x20a\x20no-op:\x20the\x20share\x20silently\x20goes\x20to\x20Account.Instance().get_address(undefined)\x20=\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91).','required':![]},{'name':'arbitrator_rate','type':'number','description':'Arbitrator\x27s\x20share\x20in\x20basis\x20points.\x20Default\x2010000\x20=\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20dispute\x20fee\x20(direct\x20sales:\x20no\x20platform\x20take).','required':![],'default':0x2710},{'name':'arbitration_operator_fee_bps','type':'number','description':'The\x20ARBITRATION\x20OPERATOR\x27s\x20(or\x20a\x20named\x20third\x20party\x27s)\x20own\x20fee\x20in\x20basis\x20points,\x20default\x200.\x20Explicit\x20number\x20both\x20sides\x20can\x20compute\x20before\x20the\x20fee\x20is\x20charged;\x20arbitrator_rate\x20+\x20arbitration_operator_fee_bps\x20MUST\x20sum\x20to\x2010000.\x20WoWok\x20extracts\x20nothing,\x20so\x20there\x20is\x20no\x20platform\x20share\x20here.','required':![],'default':0x0},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20(verifies\x20Arbitration\x20ruling\x20finalized)','required':!![]}],'body':a=>{const b=assert_declared_share('T-A-08','arbitrator_rate',a['arbitrator_rate'],0x2710),c=assert_declared_share('T-A-08','arbitration_operator_fee_bps',a['arbitration_operator_fee_bps'],0x0);assert_explicit_recipient('T-A-08','arbitrator_treasury',a['arbitrator_treasury'],b),assert_explicit_recipient('T-A-08','arbitration_operator_treasury',a['arbitration_operator_treasury'],c);const d=b+c;if(d!==0x2710)throw new Error('T-A-08:\x20sum(rates)\x20MUST\x20equal\x2010000,\x20got\x20'+d+'\x20(arbitrator='+b+'\x20+\x20operator_fee='+c+')');const e=[{'who':{'Entity':a['arbitrator_treasury']},'sharing':String(b),'mode':'Rate'}];return c>0x0&&e['push']({'who':{'Entity':a['arbitration_operator_treasury']},'sharing':String(c),'mode':'Rate'}),{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':'Arbitration\x20fees\x20(platform\x20commission\x200):\x20arbitrator\x20'+b+'/10000'+(c>0x0?',\x20arbitration\x20operator\x27s\x20own\x20fee\x20'+c+'/10000':''),'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':e,'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Triggered\x20by\x20the\x20Arbitration\x20fees-distribution\x20operation\x20(permission\x20ARBITRATION_FEES_ALLOC=365),\x20with\x20or\x20without\x20a\x20Passport','Independent\x20from\x20Service-order\x20Allocation\x20(this\x20Allocation\x20is\x20not\x20bound\x20to\x20Order)','payment_info\x20typically\x20reuses\x20Arbitration\x27s\x20payment_info','Caller\x20MUST\x20hold\x20ARBITRATION_FEES_ALLOC=365\x20permission','DIRECT-SALES\x20DEFAULT:\x20the\x20emitted\x20rows\x20are\x20a\x20single\x20Rate\x2010000\x20leg\x20to\x20arbitrator_treasury\x20—\x20the\x20arbitrator\x20keeps\x20the\x20whole\x20dispute\x20fee,\x20and\x20the\x2010000\x20invariant\x20holds\x20by\x20construction','arbitration_operator_fee_bps\x20is\x20the\x20arbitration\x20OPERATOR\x27s\x20own\x20declared\x20fee\x20(or\x20a\x20named\x20third\x20party\x27s),\x20default\x200;\x20it\x20requires\x20an\x20explicit\x20non-empty\x20recipient\x20and\x20is\x20never\x20an\x20implicit\x20remainder\x20or\x20a\x20Surplus\x20drain.\x20There\x20is\x20no\x20platform\x20leg\x20in\x20this\x20template']},{'id':'T-A-09','name':'Standalone\x20periodic\x20split\x20(investment\x20dividends\x20/\x20shared\x20income)','description':'Standalone\x20Allocation\x20with\x20single\x20Allocator,\x20N\x20Rate\x20sharing\x20items\x20to\x20beneficiary\x20wallets.\x20No\x20Service\x20context.\x20Guard\x20provides\x20time-based\x20or\x20signer-based\x20access\x20control.','applicable_scenes':['allocation_standalone_periodic_split'],'industry_tags':['standalone','investment','dividends','shared_income'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(e.g.\x20\x270x2::wow::WOW\x27\x20or\x20profit\x20token\x20type)','required':!![]},{'name':'beneficiaries','type':'address[]','description':'Array\x20of\x20beneficiary\x20wallet\x20addresses\x20(NOT\x20Treasury\x20objects\x20—\x20standalone\x20mode\x20has\x20no\x20Service\x20context)','required':!![]},{'name':'rates','type':'string[]','description':'Array\x20of\x20rates\x20in\x20basis\x20points\x20(e.g.\x20[\x275000\x27,\x273000\x27,\x272000\x27]\x20=\x2050%/30%/20%).\x20MUST\x20sum\x20to\x2010000.','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20object\x20address\x20—\x20MUST\x20bind\x20Signer\x20or\x20verify\x20time-based\x20trigger\x20(R-A-3-04:\x20standalone\x20has\x20no\x20Service-layer\x20access\x20control)','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20periodic\x20split'}],'body':a=>{const b=a['beneficiaries'],c=a['rates']['map'](e=>Number(e));if(b['length']!==c['length'])throw new Error('T-A-09:\x20beneficiaries\x20('+b['length']+')\x20and\x20rates\x20('+c['length']+')\x20MUST\x20have\x20equal\x20length');if(b['length']===0x0)throw new Error('T-A-09:\x20at\x20least\x201\x20beneficiary\x20required');if(b['length']>0x64)throw new Error('T-A-09:\x20beneficiaries\x20count\x20'+b['length']+'\x20exceeds\x20MAX_SHARING_COUNT\x20(100)');const d=c['reduce']((e,f)=>e+f,0x0);if(d!==0x2710)throw new Error('T-A-09:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+d);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Standalone\x20periodic\x20split','threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':b['map']((e,f)=>({'who':{'Entity':e},'sharing':String(c[f]),'mode':'Rate'})),'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode\x20(§0):\x20no\x20Service/Order/Arbitration\x20context\x20required','R-A-3-04:\x20Guard\x20MUST\x20bind\x20Signer\x20or\x20verify\x20time-based\x20trigger\x20—\x20no\x20Service-layer\x20access\x20control\x20exists','F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode,\x20no\x20Surplus)','Caller\x20lifecycle:\x20receive()\x20to\x20deposit\x20funds\x20→\x20alloc()\x20to\x20trigger\x20distribution','Guard\x20should\x20bind\x20context(Signer)==authorized\x20to\x20prevent\x20unauthorized\x20alloc()\x20calls','beneficiaries\x20are\x20personal\x20wallets,\x20NOT\x20Treasury\x20objects\x20(no\x20Service\x20context)','Every\x20rate\x20is\x20an\x20EXPLICIT\x20declared\x20share\x20to\x20an\x20EXPLICIT\x20non-empty\x20address:\x20nothing\x20here\x20is\x20an\x20implicit\x20platform\x20beneficiary\x20and\x20no\x20leg\x20is\x20left\x20unset\x20(blank\x20silently\x20binds\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91).\x20A\x20share\x20intended\x20for\x20a\x20third\x20party\x20is\x20the\x20payer\x27s\x20own\x20declared\x20price\x20and\x20must\x20be\x20named\x20on\x20both\x20sides']},{'id':'T-A-10','name':'Standalone\x20vesting\x20release\x20(time-locked\x20multi-stage\x20unlock)','description':'Standalone\x20Allocation\x20with\x20N\x20Allocators\x20(default\x203\x20stages),\x20each\x20triggered\x20by\x20a\x20time-locked\x20Guard.\x20Stages\x201..N-1\x20use\x20Amount\x20mode;\x20final\x20stage\x20uses\x20Surplus\x20to\x20drain\x20remaining\x20balance.\x20No\x20Service\x20context.','applicable_scenes':['allocation_standalone_vesting'],'industry_tags':['standalone','vesting','time_lock','team_tokens'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20(vested\x20asset,\x20e.g.\x20locked\x20team\x20tokens)','required':!![]},{'name':'beneficiary_address','type':'address','description':'Single\x20beneficiary\x20wallet\x20address\x20(vesting\x20recipient)','required':!![]},{'name':'stage_1_guard','type':'address','description':'Guard\x20for\x20stage\x201\x20(verifies\x20context(Clock).timestamp\x20>=\x20stage_1_unlock)','required':!![]},{'name':'stage_1_amount','type':'number','description':'Amount\x20to\x20release\x20at\x20stage\x201\x20(smallest\x20coin\x20unit,\x20e.g.\x20MIST)','required':!![]},{'name':'stage_2_guard','type':'address','description':'Guard\x20for\x20stage\x202\x20(verifies\x20context(Clock).timestamp\x20>=\x20stage_2_unlock)\x20—\x20MUST\x20differ\x20from\x20stage_1_guard','required':!![]},{'name':'stage_2_amount','type':'number','description':'Amount\x20to\x20release\x20at\x20stage\x202\x20(smallest\x20coin\x20unit)','required':!![]},{'name':'stage_3_guard','type':'address','description':'Guard\x20for\x20stage\x203\x20(final\x20stage,\x20uses\x20Surplus\x20to\x20drain\x20remaining\x20balance)\x20—\x20MUST\x20differ\x20from\x20stage_1_guard\x20and\x20stage_2_guard','required':!![]},{'name':'max_cap','type':'number','description':'Maximum\x20cumulative\x20release\x20cap\x20(applied\x20to\x20stages\x201\x20and\x202\x20via\x20max\x20field).\x20Stage\x203\x20uses\x20Surplus\x20so\x20no\x20max\x20needed.','required':![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20vesting\x20release\x20(3-stage\x20time-locked)'}],'body':a=>{const b=[a['stage_1_guard'],a['stage_2_guard'],a['stage_3_guard']],c=new Set(b);if(c['size']!==b['length']){const h=b['filter']((j,k)=>b['indexOf'](j)!==k);throw new Error('T-A-10:\x20stage\x20guards\x20MUST\x20be\x20unique\x20(F-A-14),\x20duplicates:\x20'+h['join'](',\x20'));}const d=Number(a['stage_1_amount']),e=Number(a['stage_2_amount']);if(d<=0x0||e<=0x0)throw new Error('T-A-10:\x20stage_1_amount\x20and\x20stage_2_amount\x20MUST\x20be\x20>\x200,\x20got\x20stage1='+d+',\x20stage2='+e);const f=d+e,g=a['max_cap']!=null?Number(a['max_cap']):null;if(g!==null&&f>g)throw new Error('T-A-10:\x20stage_1_amount\x20+\x20stage_2_amount\x20('+f+')\x20MUST\x20be\x20<=\x20max_cap\x20('+g+')\x20—\x20F-A-08\x20(EAMOUNT_EXCEEDS_MAX)');return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':a['description']??'Standalone\x20vesting\x20release\x20(3-stage\x20time-locked)','threshold':'0','allocators':[{'guard':a['stage_1_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':String(d),'mode':'Amount'}],'max':g!=null?String(g):null},{'guard':a['stage_2_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':String(e),'mode':'Amount'}],'max':g!=null?String(g):null},{'guard':a['stage_3_guard'],'sharing':[{'who':{'Entity':a['beneficiary_address']},'sharing':'0','mode':'Surplus'}],'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode\x20(§0):\x20no\x20Service/Order/Arbitration\x20context\x20required','R-A-3-04:\x20Guard\x20time-lock\x20MUST\x20be\x20enforced\x20—\x20no\x20Service-layer\x20access\x20control\x20exists','F-A-14:\x20stage_1_guard,\x20stage_2_guard,\x20stage_3_guard\x20MUST\x20be\x20unique\x20(duplicate\x20guards\x20are\x20dead\x20code)','F-A-04:\x20at\x20most\x201\x20Surplus\x20per\x20Allocator\x20(stage\x203\x20uses\x20Surplus\x20to\x20drain\x20remainder)','F-A-08:\x20stage_1_amount\x20+\x20stage_2_amount\x20MUST\x20be\x20<=\x20max_cap\x20(if\x20max_cap\x20provided)','R-A-4-01:\x20if\x20caller\x20calls\x20alloc()\x20before\x20stage\x20time-lock\x20expires,\x20alloc()\x20silently\x20returns\x20—\x20caller\x20should\x20check\x20balance==0\x20after\x20alloc()','R-A-4-02:\x20Guard\x20conditions\x20SHOULD\x20be\x20mutually\x20exclusive\x20by\x20timestamp\x20(e.g.\x20stage_1:\x20ts<stage_2_unlock,\x20stage_2:\x20stage_2_unlock<=ts<stage_3_unlock,\x20stage_3:\x20ts>=stage_3_unlock)','Caller\x20lifecycle:\x20receive()\x20to\x20deposit\x20locked\x20tokens\x20→\x20alloc()\x20at\x20each\x20vesting\x20milestone','Single\x20beneficiary\x20—\x20no\x20platform\x20leg.\x20The\x20stage-3\x20Surplus\x20is\x20this\x20contract\x27s\x20own\x20vesting\x20remainder,\x20NOT\x20a\x20fee:\x20Surplus\x20calls\x20balance::withdraw_all,\x20so\x20never\x20express\x20a\x20declared\x20fee\x20through\x20a\x20Surplus\x20leg\x20(L3\x20constraint\x203)']},{'id':'T-A-11','name':'Standalone\x20payroll\x20/\x20salary\x20distribution\x20(issuer\x20+\x20Repository\x20verified)','description':'Standalone\x20Allocation\x20for\x20periodic\x20payroll:\x20employees\x20receive\x20Rate\x20shares.\x20The\x20Guard\x20binds\x20the\x20issuer\x20Signer\x20identity\x20and\x20cross-checks\x20a\x20Repository\x20payroll\x20record\x20(period\x20and\x20amounts).\x20No\x20Service\x20context.','applicable_scenes':['allocation_standalone_payroll'],'industry_tags':['standalone','payroll','salary','compensation','hr'],'params':[{'name':'allocation_name','type':'string','description':'Local\x20name\x20for\x20the\x20new\x20Allocation\x20object','required':!![]},{'name':'coin_type','type':'string','description':'Coin<T>\x20type\x20string\x20used\x20for\x20payroll\x20(e.g.\x20\x270x2::wow::WOW\x27)','required':!![]},{'name':'employees','type':'address[]','description':'Employee\x20wallet\x20addresses\x20(Recipient::Entity\x20recipients)','required':!![]},{'name':'rates','type':'string[]','description':'Per-employee\x20rates\x20in\x20basis\x20points\x20(e.g.\x20[\x276000\x27,\x274000\x27]).\x20MUST\x20sum\x20to\x2010000.','required':!![]},{'name':'guard_address','type':'address','description':'Guard\x20that\x20binds\x20Signer\x20==\x20issuer\x20AND\x20cross-checks\x20the\x20Repository\x20payroll\x20record\x20(both\x20required)','required':!![]},{'name':'payroll_period','type':'string','description':'Human-readable\x20period\x20label\x20(e.g.\x20\x272025-W26\x27)\x20—\x20recorded\x20in\x20the\x20Allocation\x20description\x20for\x20audit','required':!![]},{'name':'description','type':'string','description':'Allocation\x20description','required':![],'default':'Standalone\x20payroll\x20distribution'}],'body':a=>{const b=a['employees'],c=a['rates']['map'](e=>Number(e));if(b['length']!==c['length'])throw new Error('T-A-11:\x20employees\x20('+b['length']+')\x20and\x20rates\x20('+c['length']+')\x20MUST\x20have\x20equal\x20length');if(b['length']===0x0)throw new Error('T-A-11:\x20at\x20least\x201\x20employee\x20required');if(b['length']>0x64)throw new Error('T-A-11:\x20employees\x20count\x20'+b['length']+'\x20exceeds\x20MAX_SHARING_COUNT\x20(100)');const d=c['reduce']((e,f)=>e+f,0x0);if(d!==0x2710)throw new Error('T-A-11:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(RATE_TOTAL_FULL),\x20got\x20'+d);return{'object':{'name':a['allocation_name'],'type_parameter':a['coin_type']},'allocators':{'description':(a['description']??'Standalone\x20payroll\x20distribution')+'\x20—\x20period:\x20'+a['payroll_period'],'threshold':'0','allocators':[{'guard':a['guard_address'],'sharing':b['map']((e,f)=>({'who':{'Entity':e},'sharing':String(c[f]),'mode':'Rate'})),'max':null}]},'coin':{'name':a['allocation_name']+'_coin'},'payment_info':{}};},'notes':['Standalone\x20mode:\x20no\x20Service/Order/Arbitration\x20context\x20required','RC-FIND-04:\x20the\x20Guard\x20MUST\x20bind\x20the\x20issuer\x20identity\x20(Signer\x20==\x20employer/admin,\x20or\x20a\x20Permission\x20member)\x20—\x20standalone\x20has\x20no\x20Service\x20access-control\x20layer','Repository\x20distinction:\x20the\x20Guard\x20MUST\x20cross-check\x20the\x20Repository\x20payroll\x20record\x20(period\x20hash,\x20amounts\x20and\x20recipients)\x20so\x20the\x20distribution\x20is\x20tied\x20to\x20auditable\x20work/payroll\x20data','Auditability:\x20the\x20Guard\x20rules\x20are\x20public\x20—\x20third\x20parties\x20verify\x20who\x20may\x20distribute\x20and\x20what\x20inputs\x20distinguish\x20a\x20valid\x20payroll','F-A-05:\x20sum(rates)\x20MUST\x20equal\x2010000\x20(pure\x20Rate\x20mode)','Caller\x20lifecycle:\x20issuer\x20receive()\x20to\x20fund\x20payroll\x20→\x20alloc()\x20after\x20the\x20Repository\x20record\x20for\x20the\x20period\x20is\x20committed','Employees\x20are\x20personal\x20wallets\x20(Recipient::Entity),\x20never\x20Recipient::Signer','The\x20issuer/employer\x20is\x20the\x20payer\x20and\x20keeps\x20the\x20whole\x20payroll\x20pool\x20by\x20default:\x20there\x20is\x20no\x20platform\x20share\x20in\x20this\x20template.\x20Every\x20rate\x20is\x20an\x20explicit\x20per-employee\x20price\x20to\x20an\x20explicit\x20non-empty\x20address\x20(blank\x20silently\x20binds\x20the\x20deploying\x20account,\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20and\x20sum(rates)\x20MUST\x20stay\x2010000\x20so\x20no\x20residual\x20stays\x20claimable']}];export const ALLOCATION_TEMPLATES_VERSION='1.1.0';export function getAllTemplates(){return[...ALLOCATION_TEMPLATES];}export function getTemplateById(a){return ALLOCATION_TEMPLATES['find'](b=>b['id']===a);}export function getTemplatesByScene(a){return ALLOCATION_TEMPLATES['filter'](b=>b['applicable_scenes']['includes'](a));}export function getTemplatesByIndustry(a){return ALLOCATION_TEMPLATES['filter'](b=>b['industry_tags']['includes'](a)||b['industry_tags']['includes']('universal'));}export function suggestTemplateForScene(a){const b=getTemplatesByScene(a);return b['length']>0x0?b[0x0]:undefined;}export function listTemplates(){return ALLOCATION_TEMPLATES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'scenes':a['applicable_scenes']}));}export function fillTemplate(a,b){const c=getTemplateById(a);if(!c)return{'ok':![],'error':'Template\x20'+a+'\x20not\x20found'};for(const d of c['params']){if(d['required']&&!(d['name']in b))return{'ok':![],'error':'Missing\x20required\x20param:\x20'+d['name']};}try{return{'ok':!![],'body':c['body'](b)};}catch(f){return{'ok':![],'error':f instanceof Error?f['message']:String(f)};}}
|