@wowok/agent-mcp 2.7.3 → 2.7.5
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/evaluation/builtins/arbitration-score.d.ts +1 -1
- package/dist/evaluation/builtins/arbitration-score.js +1 -1
- package/dist/index.js +1 -1
- package/dist/knowledge/arbitration-ledger.js +1 -1
- package/dist/knowledge/demand-confirm.js +1 -1
- package/dist/knowledge/demand-risk.js +1 -1
- package/dist/knowledge/demand-translation.js +1 -1
- package/dist/knowledge/guard-design-patterns.js +1 -1
- package/dist/knowledge/index.d.ts +2 -2
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/onchain-constants.d.ts +2 -2
- package/dist/knowledge/onchain-constants.js +1 -1
- package/dist/knowledge/payment-risk.js +1 -1
- package/dist/knowledge/permission-context.d.ts +11 -0
- package/dist/knowledge/permission-context.js +1 -1
- package/dist/knowledge/personal-risk.js +1 -1
- package/dist/knowledge/progress-ledger.js +1 -1
- package/dist/knowledge/progress-risk.js +1 -1
- package/dist/knowledge/progress-templates.js +1 -1
- package/dist/knowledge/progress-translation.js +1 -1
- package/dist/knowledge/registrar-risk.js +1 -1
- package/dist/knowledge/registrar-translation.js +1 -1
- package/dist/knowledge/reward-ledger.js +1 -1
- package/dist/knowledge/reward-translation.js +1 -1
- package/dist/knowledge/tools-reference.js +1 -1
- package/dist/knowledge/treasury-context.d.ts +1 -1
- package/dist/knowledge/treasury-context.js +1 -1
- package/dist/knowledge/treasury-ledger.js +1 -1
- package/dist/knowledge/treasury-risk.js +1 -1
- package/dist/knowledge/util-confirm.js +1 -1
- package/dist/knowledge/util-risk.js +1 -1
- package/dist/knowledge/util-translation.d.ts +3 -2
- package/dist/knowledge/util-translation.js +1 -1
- package/dist/knowledge/workflow-guidance.d.ts +64 -0
- package/dist/knowledge/workflow-guidance.js +1 -1
- package/dist/project/evaluation.js +1 -1
- package/dist/project/graph-builder.d.ts +2 -2
- package/dist/project/graph-builder.js +1 -1
- package/dist/project/semantic-assembler.d.ts +2 -2
- package/dist/project/semantic-assembler.js +1 -1
- package/dist/schema/evaluation/index.d.ts +1 -1
- package/dist/schema/evaluation/index.js +1 -1
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +1 -1
- package/dist/schema/operations.d.ts +251 -2
- package/dist/schema/operations.js +1 -1
- package/dist/schema/permission/index.d.ts +121 -0
- package/dist/schema/permission/index.js +1 -0
- package/dist/schema/query/index.d.ts +223 -22
- package/dist/schema/query/index.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema/workflow/index.d.ts +161 -0
- package/dist/schema/workflow/index.js +1 -0
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/evaluation_operation.schema.json +2 -2
- package/dist/schemas/index.json +13 -1
- package/dist/schemas/onchain_table_data.output.json +821 -5
- package/dist/schemas/onchain_table_data.schema.json +154 -1
- package/dist/schemas/permission_operation.output.json +173 -0
- package/dist/schemas/permission_operation.schema.json +39 -0
- package/dist/schemas/query_toolkit.output.json +15 -15
- package/dist/schemas/workflow_operation.output.json +164 -0
- package/dist/schemas/workflow_operation.schema.json +116 -0
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/evaluation.js +1 -1
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/handlers/permission.d.ts +2 -0
- package/dist/tools/handlers/permission.js +1 -0
- package/dist/tools/handlers/query.js +1 -1
- package/dist/tools/handlers/workflow.d.ts +2 -0
- package/dist/tools/handlers/workflow.js +1 -0
- package/dist/tools/handlers/workspace.d.ts +2 -0
- package/dist/tools/handlers/workspace.js +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/shared.js +1 -1
- package/package.json +2 -2
|
@@ -27,7 +27,7 @@ export interface TreasuryContextBundle {
|
|
|
27
27
|
rendering_hints: TreasuryRenderingHints;
|
|
28
28
|
}
|
|
29
29
|
export interface TreasuryCrossObjectRef {
|
|
30
|
-
object: "Permission" | "Guard" | "Passport" | "Payment" | "CoinWrapper" | "Contact" | "Allocator" | "Arbitration" | "Service" | "Registrar" | "Clock";
|
|
30
|
+
object: "Permission" | "Guard" | "Passport" | "Payment" | "CoinWrapper" | "Contact" | "Allocator" | "Arbitration" | "Service" | "Registrar" | "Clock" | "ObjectLinkerCore";
|
|
31
31
|
field: string;
|
|
32
32
|
description: string;
|
|
33
33
|
collaboration_type: "dependency" | "referenced_by" | "parallel_design";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{USER_DEFINED_PERM_INDEX_START,MAX_ADMIN_COUNT,MAX_PERM_FOR_ENTITY,MAX_ENTITY_COUNT}from'@wowok/wowok';import{findSceneById,findSceneByPermissionIndex,inferSceneFromIntent,getActiveBuiltinPermissions,getReservedBuiltinPermissions}from'./treasury-ledger.js';import{getTemplatesByScene}from'./treasury-templates.js';import{matchSemanticPattern}from'./treasury-translation.js';import{getAllTreasuryRiskRules,assessTreasuryRisks}from'./treasury-risk.js';import{initPuzzleFromIntent,checkPuzzleCompleteness,MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,MAX_DESCRIPTION_LENGTH}from'./treasury-puzzle.js';import{TREASURY_PUBLISH_CHECKLIST,TREASURY_CONFIRMATION_QUESTIONS}from'./treasury-confirm.js';export const TREASURY_CONTEXT_VERSION='1.0.0';export function buildTreasuryContext(a){const b=a['max_length']??0xfa0;let c;if(a['intent'])c=inferSceneFromIntent(a['intent']);else a['target_permission_index']!==undefined&&(c=findSceneByPermissionIndex(a['target_permission_index']));!c&&a['intent']&&(c=findSceneById('treasury_fund_collection'));let d;if(c){const q=getTemplatesByScene(c['id']);if(q['length']>0x0)d=q[0x0];}let e;if(a['intent']){const r=matchSemanticPattern(a['intent']);if(r['length']>0x0)e=r[0x0];}let f,g;a['mode']==='initial_design'&&a['intent']&&(f=initPuzzleFromIntent({'rule_sentence':a['intent']}),g=checkPuzzleCompleteness(f));const h=filterRiskRules(a['mode'],a['stakeholder'],c);let i;if((a['mode']==='pre_publish'||a['mode']==='mid_design_review')&&a['treasury_json']){const s={'object':typeof a['treasury_json']['object']==='string'?a['treasury_json']['object']:null,'description':a['treasury_json']['description'],'deposit':a['treasury_json']['deposit']?{'coin_balance':a['treasury_json']['deposit']['coin']?.['balance'],'coin_object':a['treasury_json']['deposit']['coin']?.['coin_object'],'by_external_deposit_guard':a['treasury_json']['deposit']['by_external_deposit_guard']}:undefined,'withdraw':a['treasury_json']['withdraw']?{'amount_fixed':a['treasury_json']['withdraw']['amount']?.['fixed'],'amount_by_external_withdraw_guard':a['treasury_json']['withdraw']['amount']?.['by_external_withdraw_guard'],'recipient':a['treasury_json']['withdraw']['recipient']}:undefined,'external_deposit_guard':a['treasury_json']['external_deposit_guard'],'external_withdraw_guard':a['treasury_json']['external_withdraw_guard'],'owner_receive':a['treasury_json']['owner_receive'],'um':a['treasury_json']['um'],'type_parameter':a['type_parameter'],'shared_with_service':a['shared_with_service'],'shared_with_allocator':a['shared_with_allocator'],'shared_with_arbitration':a['shared_with_arbitration'],'current_permission_indexes_granted':a['current_permission_indexes_granted']};i=assessTreasuryRisks(s);}const j=filterChecklist(a['mode']),k=filterQuestions(a['mode']),l=c?c['builtin_indexes']['filter'](t=>t['active']):getActiveBuiltinPermissions(),m=getReservedBuiltinPermissions(),n=buildCrossObjectRefs(a['mode'],c),o=buildOnchainConstraints(),p=buildRenderingHints(a['mode'],b,!!a['treasury_json']?.['withdraw'],!!a['treasury_json']?.['external_deposit_guard']||!!a['treasury_json']?.['external_withdraw_guard'],!!a['shared_with_service']||!!a['shared_with_allocator']||!!a['shared_with_arbitration']);return{'version':TREASURY_CONTEXT_VERSION,'mode':a['mode'],'stakeholder_perspective':a['stakeholder'],'matched_scene':c,'matched_template':d,'matched_pattern':e,'puzzle_state':f,'puzzle_completeness':g,'relevant_risks':h,'risk_assessment':i,'relevant_checklist':j,'relevant_questions':k,'relevant_builtin_permissions':l,'reserved_builtin_permissions':m,'cross_object_refs':n,'onchain_constraints':o,'rendering_hints':p};}function filterRiskRules(a,b,c){let d=getAllTreasuryRiskRules();if(a==='initial_design')return d['filter'](e=>e['category']==='structural'||e['category']==='authority');if(a==='pre_publish')return d;if(a==='stakeholder_review'&&b){if(b==='owner')return d['filter'](e=>e['category']==='authority'||e['category']==='lifecycle');if(b==='admin')return d['filter'](e=>e['category']==='structural'||e['category']==='semantic');if(b==='depositor')return d['filter'](e=>e['id']==='R-T-2-02'||e['id']==='R-T-2-03'||e['category']==='structural');if(b==='withdrawer')return d['filter'](e=>e['id']==='R-T-4-01'||e['id']==='R-T-4-02'||e['id']==='R-T-3-01');if(b==='external_operator')return d['filter'](e=>e['id']==='R-T-2-01'||e['id']==='R-T-2-03'||e['id']==='R-T-4-02');if(b==='system')return d['filter'](e=>e['category']==='cross_object'||e['id']==='R-T-0-01');}if(a==='cross_object_check')return d['filter'](e=>e['category']==='cross_object');return d;}function filterChecklist(a){if(a==='initial_design')return TREASURY_PUBLISH_CHECKLIST['filter'](b=>['C-T-01','C-T-02','C-T-03','C-T-10']['includes'](b['id']));return TREASURY_PUBLISH_CHECKLIST;}function filterQuestions(a){if(a==='pre_publish')return TREASURY_CONFIRMATION_QUESTIONS;if(a==='post_publish_modify')return TREASURY_CONFIRMATION_QUESTIONS['filter'](b=>b['id']!=='QT1');return[];}function buildCrossObjectRefs(a,b){const c=[];return c['push']({'object':'Permission','field':'permission','description':'All\x20Treasury\x20write\x20operations\x20(except\x20external_deposit/withdraw)\x20require\x20Permission\x20authorization\x20via\x20indexes\x20250-258','collaboration_type':'dependency'}),c['push']({'object':'Registrar','field':'registrar','description':'Tracks\x20affiliation\x20between\x20Treasury,\x20Permission,\x20and\x20UM\x20(Contact)\x20objects','collaboration_type':'dependency'}),c['push']({'object':'Clock','field':'clock','description':'Provides\x20timestamp\x20for\x20Record\x20entries\x20in\x20history\x20ParentTable','collaboration_type':'dependency'}),(b?.['id']==='treasury_external_ops'||b?.['id']==='treasury_guard_protection'||a==='cross_object_check')&&(c['push']({'object':'Guard','field':'external_deposit_guard\x20/\x20external_withdraw_guard','description':'Guard\x20objects\x20referenced\x20by\x20external_*_guard\x20lists;\x20provide\x20programmable\x20access\x20rules\x20for\x20external\x20deposit/withdraw','collaboration_type':'dependency'}),c['push']({'object':'Passport','field':'passport','description':'Required\x20for\x20every\x20external_deposit\x20/\x20external_withdraw\x20call;\x20carries\x20submission\x20values\x20verified\x20by\x20Guard','collaboration_type':'dependency'})),c['push']({'object':'Allocator','field':'sharing.who=Entity','description':'Allocator\x20can\x20reference\x20Treasury\x20address\x20as\x20fund\x20split\x20target;\x20Treasury.receive\x20(253)\x20converts\x20CoinWrapper\x20to\x20balance','collaboration_type':'referenced_by'}),c['push']({'object':'Arbitration','field':'fees_transfer','description':'Arbitration.fees_transfer\x20sends\x20Payment\x20to\x20Treasury\x20address;\x20Treasury.receive\x20(253)\x20required\x20to\x20intake','collaboration_type':'referenced_by'}),c['push']({'object':'Service','field':'compensation_fund\x20(parallel\x20design)','description':'Service.compensation_fund\x20is\x20a\x20parallel\x20design\x20(NOT\x20a\x20Treasury\x20object);\x20both\x20are\x20Balance<T>\x20containers\x20but\x20implementation-independent','collaboration_type':'parallel_design'}),c['push']({'object':'Contact','field':'um','description':'Optional\x20UM\x20(User\x20Manager)\x20Contact\x20object;\x20manages\x20user-tier\x20information\x20via\x20Registrar\x20affiliation','collaboration_type':'dependency'}),c['push']({'object':'Payment','field':'history\x20ParentTable','description':'Every\x20deposit/withdraw/receive\x20creates\x20a\x20Payment\x20object;\x20Payment\x20address\x20is\x20the\x20key\x20in\x20history\x20ParentTable','collaboration_type':'dependency'}),c['push']({'object':'CoinWrapper','field':'receive','description':'CoinWrapper\x20is\x20the\x20received\x20form\x20of\x20coins;\x20Treasury.receive\x20(253)\x20unwraps\x20CoinWrapper\x20to\x20balance','collaboration_type':'dependency'}),c;}function buildOnchainConstraints(){return[{'name':'MAX_EXTERNAL_DEPOSIT_GUARD_COUNT','value':MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,'description':'Maximum\x20external_deposit_guard\x20entries\x20(Treasury-specific,\x20not\x20yet\x20in\x20onchain-constants.ts)'},{'name':'MAX_EXTERNAL_WITHDRAW_GUARD_COUNT','value':MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,'description':'Maximum\x20external_withdraw_guard\x20entries\x20(Treasury-specific,\x20not\x20yet\x20in\x20onchain-constants.ts)'},{'name':'MAX_DESCRIPTION_LENGTH','value':MAX_DESCRIPTION_LENGTH,'description':'Maximum\x20description\x20length\x20(shared\x20across\x20all\x20objects)'},{'name':'USER_DEFINED_PERM_INDEX_START','value':USER_DEFINED_PERM_INDEX_START,'description':'Custom\x20permission\x20indexes\x20must\x20be\x20>=\x20this\x20value'},{'name':'MAX_ENTITY_COUNT','value':MAX_ENTITY_COUNT,'description':'Maximum\x20entities\x20per\x20Permission\x20(shared)'},{'name':'MAX_PERM_FOR_ENTITY','value':MAX_PERM_FOR_ENTITY,'description':'Maximum\x20permission\x20indexes\x20per\x20entity\x20(shared)'},{'name':'MAX_ADMIN_COUNT','value':MAX_ADMIN_COUNT,'description':'Maximum\x20admins\x20per\x20Permission\x20(shared)'}];}function buildRenderingHints(a,b,c,d,e){return{'include_puzzle_template':a==='initial_design','include_risk_details':a==='pre_publish'||a==='stakeholder_review'||a==='mid_design_review','include_questions':a==='pre_publish','include_irreversibility_warning':c,'include_external_guard_warning':d,'include_cross_object_warning':e||a==='cross_object_check','max_length':b};}export function buildPromptFromTreasuryContext(a){const b=[],d=a['rendering_hints'];b['push']('═══\x20Treasury\x20Context\x20(mode:\x20'+a['mode']+')\x20═══'),b['push']('');a['stakeholder_perspective']&&(b['push']('Stakeholder\x20perspective:\x20'+a['stakeholder_perspective']),b['push'](''));a['matched_scene']&&(b['push']('Scene:\x20'+a['matched_scene']['name']),b['push']('Scene\x20ID:\x20'+a['matched_scene']['id']),b['push']('Permission\x20range:\x20'+a['matched_scene']['permission_index_range']),b['push'](''));a['matched_template']&&(b['push']('Suggested\x20template:\x20'+a['matched_template']['id']+'\x20—\x20'+a['matched_template']['name']),b['push'](''));if(d['include_puzzle_template']&&a['puzzle_completeness']){const e=a['puzzle_completeness'];b['push']('─\x20Puzzle\x20Completeness\x20──────────────'),b['push']('Complete:\x20'+(e['complete']?'YES':'NO')),e['missing']['length']>0x0&&b['push']('Missing:\x20'+e['missing']['join'](',\x20')),b['push']('Next:\x20'+e['next_step']),b['push']('');}if(d['include_risk_details']&&a['relevant_risks']['length']>0x0){b['push']('─\x20Relevant\x20Risk\x20Rules\x20('+a['relevant_risks']['length']+')\x20──────────────');for(const f of a['relevant_risks']['slice'](0x0,0x8)){b['push']('\x20\x20'+f['id']+'\x20—\x20'+f['trigger']);}a['relevant_risks']['length']>0x8&&b['push']('\x20\x20...\x20and\x20'+(a['relevant_risks']['length']-0x8)+'\x20more'),b['push']('');}if(a['risk_assessment']){b['push']('─\x20Risk\x20Assessment\x20──────────────'),b['push']('Overall:\x20'+a['risk_assessment']['overall_risk']),b['push']('Detected:\x20'+a['risk_assessment']['risks']['length']+'\x20risk(s)');for(const g of a['risk_assessment']['risks']['slice'](0x0,0x5)){b['push']('\x20\x20['+g['level']+']\x20'+g['id']+':\x20'+g['title']);}b['push']('');}if(a['relevant_builtin_permissions']['length']>0x0){b['push']('─\x20Builtin\x20Treasury\x20Permissions\x20(active:\x20'+a['relevant_builtin_permissions']['length']+')\x20──────────────');for(const i of a['relevant_builtin_permissions']){b['push']('\x20\x20['+i['index']+']\x20'+i['name']+':\x20'+i['description']);}b['push']('');}if(a['reserved_builtin_permissions']['length']>0x0){b['push']('─\x20Reserved\x20(no\x20Permission\x20index)\x20──────────────');for(const j of a['reserved_builtin_permissions']){b['push']('\x20\x20'+j['name']+':\x20'+j['description']);}b['push']('');}d['include_irreversibility_warning']&&(b['push']('⚠️\x20WITHDRAW\x20OPERATION\x20DETECTED\x20—\x20IRREVERSIBLE'),b['push']('\x20\x20-\x20withdraw\x20(fixed)\x20and\x20external_withdraw\x20cannot\x20be\x20undone'),b['push']('\x20\x20-\x20verify\x20recipient\x20address\x20twice'),b['push']('\x20\x20-\x20ensure\x20balance\x20sufficiency'),b['push'](''));d['include_external_guard_warning']&&(b['push']('⚠️\x20EXTERNAL\x20GUARD\x20MANAGEMENT\x20—\x20Verify\x20Guard\x20table\x20fields'),b['push']('\x20\x20-\x20identifier\x20must\x20be\x20number-type\x20(u8/u16/u32/u64/u128/u256)'),b['push']('\x20\x20-\x20store_from_id\x20must\x20be\x20address-compatible'),b['push']('\x20\x20-\x20external_withdraw_guard.identifier\x20is\x20REQUIRED\x20(u8,\x20not\x20Option)'),b['push']('\x20\x20-\x20external_deposit_guard.identifier\x20is\x20Option<u8>\x20(None\x20=\x20no\x20amount\x20limit)'),b['push'](''));d['include_cross_object_warning']&&(b['push']('⚠️\x20CROSS-OBJECT\x20COLLABORATION\x20—\x20Verify\x20consistency'),b['push']('\x20\x20-\x20If\x20shared\x20with\x20Service:\x20verify\x20Permission\x20indexes\x20250-258\x20(Treasury)\x20and\x20300-320\x20(Service)\x20align'),b['push']('\x20\x20-\x20If\x20referenced\x20by\x20Allocator/Arbitration:\x20TREASURY_RECEIVE\x20(253)\x20must\x20be\x20granted\x20for\x20CoinWrapper\x20intake'),b['push'](''));if(a['cross_object_refs']['length']>0x0){b['push']('─\x20Cross-Object\x20References\x20('+a['cross_object_refs']['length']+')\x20──────────────');for(const k of a['cross_object_refs']['slice'](0x0,0x6)){b['push']('\x20\x20['+k['collaboration_type']+']\x20'+k['object']+'.'+k['field']),b['push']('\x20\x20\x20\x20'+k['description']);}a['cross_object_refs']['length']>0x6&&b['push']('\x20\x20...\x20and\x20'+(a['cross_object_refs']['length']-0x6)+'\x20more'),b['push']('');}if(a['onchain_constraints']['length']>0x0){b['push']('─\x20On-chain\x20Constraints\x20──────────────');for(const l of a['onchain_constraints']){b['push']('\x20\x20'+l['name']+'\x20=\x20'+l['value']+'\x20—\x20'+l['description']);}b['push']('');}if(d['include_questions']&&a['relevant_questions']['length']>0x0){b['push']('─\x20Confirmation\x20Questions\x20──────────────');for(const m of a['relevant_questions']){const n=m['requires_explicit_yes']?'\x20⚠️':'';b['push']('\x20\x20'+m['id']+n+':\x20'+m['question']);}b['push']('');}return b['join']('\x0a');}export function getTreasuryContextSummary(a){const b=['mode='+a['mode'],'scene='+(a['matched_scene']?.['id']??'none'),'risks='+a['relevant_risks']['length'],'permissions='+a['relevant_builtin_permissions']['length']];if(a['stakeholder_perspective'])b['push']('stakeholder='+a['stakeholder_perspective']);if(a['risk_assessment'])b['push']('overall_risk='+a['risk_assessment']['overall_risk']);if(a['matched_template'])b['push']('template='+a['matched_template']['id']);return b['join'](',\x20');}
|
|
1
|
+
import{USER_DEFINED_PERM_INDEX_START,MAX_ADMIN_COUNT,MAX_PERM_FOR_ENTITY,MAX_ENTITY_COUNT}from'@wowok/wowok';import{findSceneById,findSceneByPermissionIndex,inferSceneFromIntent,getActiveBuiltinPermissions,getReservedBuiltinPermissions}from'./treasury-ledger.js';import{getTemplatesByScene}from'./treasury-templates.js';import{matchSemanticPattern}from'./treasury-translation.js';import{getAllTreasuryRiskRules,assessTreasuryRisks}from'./treasury-risk.js';import{initPuzzleFromIntent,checkPuzzleCompleteness,MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,MAX_DESCRIPTION_LENGTH}from'./treasury-puzzle.js';import{TREASURY_PUBLISH_CHECKLIST,TREASURY_CONFIRMATION_QUESTIONS}from'./treasury-confirm.js';export const TREASURY_CONTEXT_VERSION='1.0.0';export function buildTreasuryContext(a){const b=a['max_length']??0xfa0;let c;if(a['intent'])c=inferSceneFromIntent(a['intent']);else a['target_permission_index']!==undefined&&(c=findSceneByPermissionIndex(a['target_permission_index']));!c&&a['intent']&&(c=findSceneById('treasury_fund_collection'));let d;if(c){const q=getTemplatesByScene(c['id']);if(q['length']>0x0)d=q[0x0];}let e;if(a['intent']){const r=matchSemanticPattern(a['intent']);if(r['length']>0x0)e=r[0x0];}let f,g;a['mode']==='initial_design'&&a['intent']&&(f=initPuzzleFromIntent({'rule_sentence':a['intent']}),g=checkPuzzleCompleteness(f));const h=filterRiskRules(a['mode'],a['stakeholder'],c);let i;if((a['mode']==='pre_publish'||a['mode']==='mid_design_review')&&a['treasury_json']){const s={'object':typeof a['treasury_json']['object']==='string'?a['treasury_json']['object']:null,'description':a['treasury_json']['description'],'deposit':a['treasury_json']['deposit']?{'coin_balance':a['treasury_json']['deposit']['coin']?.['balance'],'coin_object':a['treasury_json']['deposit']['coin']?.['coin_object'],'by_external_deposit_guard':a['treasury_json']['deposit']['by_external_deposit_guard']}:undefined,'withdraw':a['treasury_json']['withdraw']?{'amount_fixed':a['treasury_json']['withdraw']['amount']?.['fixed'],'amount_by_external_withdraw_guard':a['treasury_json']['withdraw']['amount']?.['by_external_withdraw_guard'],'recipient':a['treasury_json']['withdraw']['recipient']}:undefined,'external_deposit_guard':a['treasury_json']['external_deposit_guard'],'external_withdraw_guard':a['treasury_json']['external_withdraw_guard'],'owner_receive':a['treasury_json']['owner_receive'],'um':a['treasury_json']['um'],'type_parameter':a['type_parameter'],'shared_with_service':a['shared_with_service'],'shared_with_allocator':a['shared_with_allocator'],'shared_with_arbitration':a['shared_with_arbitration'],'current_permission_indexes_granted':a['current_permission_indexes_granted']};i=assessTreasuryRisks(s);}const j=filterChecklist(a['mode']),k=filterQuestions(a['mode']),l=c?c['builtin_indexes']['filter'](t=>t['active']):getActiveBuiltinPermissions(),m=getReservedBuiltinPermissions(),n=buildCrossObjectRefs(a['mode'],c),o=buildOnchainConstraints(),p=buildRenderingHints(a['mode'],b,!!a['treasury_json']?.['withdraw'],!!a['treasury_json']?.['external_deposit_guard']||!!a['treasury_json']?.['external_withdraw_guard'],!!a['shared_with_service']||!!a['shared_with_allocator']||!!a['shared_with_arbitration']);return{'version':TREASURY_CONTEXT_VERSION,'mode':a['mode'],'stakeholder_perspective':a['stakeholder'],'matched_scene':c,'matched_template':d,'matched_pattern':e,'puzzle_state':f,'puzzle_completeness':g,'relevant_risks':h,'risk_assessment':i,'relevant_checklist':j,'relevant_questions':k,'relevant_builtin_permissions':l,'reserved_builtin_permissions':m,'cross_object_refs':n,'onchain_constraints':o,'rendering_hints':p};}function filterRiskRules(a,b,c){let d=getAllTreasuryRiskRules();if(a==='initial_design')return d['filter'](e=>e['category']==='structural'||e['category']==='authority');if(a==='pre_publish')return d;if(a==='stakeholder_review'&&b){if(b==='owner')return d['filter'](e=>e['category']==='authority'||e['category']==='lifecycle');if(b==='admin')return d['filter'](e=>e['category']==='structural'||e['category']==='semantic');if(b==='depositor')return d['filter'](e=>e['id']==='R-T-2-02'||e['id']==='R-T-2-03'||e['category']==='structural');if(b==='withdrawer')return d['filter'](e=>e['id']==='R-T-4-01'||e['id']==='R-T-4-02'||e['id']==='R-T-3-01');if(b==='external_operator')return d['filter'](e=>e['id']==='R-T-2-01'||e['id']==='R-T-2-03'||e['id']==='R-T-4-02');if(b==='system')return d['filter'](e=>e['category']==='cross_object'||e['id']==='R-T-0-01');}if(a==='cross_object_check')return d['filter'](e=>e['category']==='cross_object');return d;}function filterChecklist(a){if(a==='initial_design')return TREASURY_PUBLISH_CHECKLIST['filter'](b=>['C-T-01','C-T-02','C-T-03','C-T-10']['includes'](b['id']));return TREASURY_PUBLISH_CHECKLIST;}function filterQuestions(a){if(a==='pre_publish')return TREASURY_CONFIRMATION_QUESTIONS;if(a==='post_publish_modify')return TREASURY_CONFIRMATION_QUESTIONS['filter'](b=>b['id']!=='QT1');return[];}function buildCrossObjectRefs(a,b){const c=[];return c['push']({'object':'Permission','field':'permission','description':'All\x20Treasury\x20write\x20operations\x20(except\x20external_deposit/withdraw)\x20require\x20Permission\x20authorization\x20via\x20indexes\x20250-258','collaboration_type':'dependency'}),c['push']({'object':'ObjectLinkerCore','field':'object_linker','description':'Tracks\x20object-linker\x20core\x20bindings\x20between\x20Treasury,\x20Permission,\x20and\x20UM\x20(Contact)\x20objects','collaboration_type':'dependency'}),c['push']({'object':'Clock','field':'clock','description':'Provides\x20timestamp\x20for\x20Record\x20entries\x20in\x20history\x20ParentTable','collaboration_type':'dependency'}),(b?.['id']==='treasury_external_ops'||b?.['id']==='treasury_guard_protection'||a==='cross_object_check')&&(c['push']({'object':'Guard','field':'external_deposit_guard\x20/\x20external_withdraw_guard','description':'Guard\x20objects\x20referenced\x20by\x20external_*_guard\x20lists;\x20provide\x20programmable\x20access\x20rules\x20for\x20external\x20deposit/withdraw','collaboration_type':'dependency'}),c['push']({'object':'Passport','field':'passport','description':'Required\x20for\x20every\x20external_deposit\x20/\x20external_withdraw\x20call;\x20carries\x20submission\x20values\x20verified\x20by\x20Guard','collaboration_type':'dependency'})),c['push']({'object':'Allocator','field':'sharing.who=Entity','description':'Allocator\x20can\x20reference\x20Treasury\x20address\x20as\x20fund\x20split\x20target;\x20Treasury.receive\x20(253)\x20converts\x20CoinWrapper\x20to\x20balance','collaboration_type':'referenced_by'}),c['push']({'object':'Arbitration','field':'fees_transfer','description':'Arbitration.fees_transfer\x20sends\x20Payment\x20to\x20Treasury\x20address;\x20Treasury.receive\x20(253)\x20required\x20to\x20intake','collaboration_type':'referenced_by'}),c['push']({'object':'Service','field':'compensation_fund\x20(parallel\x20design)','description':'Service.compensation_fund\x20is\x20a\x20parallel\x20design\x20(NOT\x20a\x20Treasury\x20object);\x20both\x20are\x20Balance<T>\x20containers\x20but\x20implementation-independent','collaboration_type':'parallel_design'}),c['push']({'object':'Contact','field':'um','description':'Optional\x20UM\x20(User\x20Manager)\x20Contact\x20object;\x20manages\x20user-tier\x20information\x20via\x20object_linker::affiliation_core','collaboration_type':'dependency'}),c['push']({'object':'Payment','field':'history\x20ParentTable','description':'Every\x20deposit/withdraw/receive\x20creates\x20a\x20Payment\x20object;\x20Payment\x20address\x20is\x20the\x20key\x20in\x20history\x20ParentTable','collaboration_type':'dependency'}),c['push']({'object':'CoinWrapper','field':'receive','description':'CoinWrapper\x20is\x20the\x20received\x20form\x20of\x20coins;\x20Treasury.receive\x20(253)\x20unwraps\x20CoinWrapper\x20to\x20balance','collaboration_type':'dependency'}),c;}function buildOnchainConstraints(){return[{'name':'MAX_EXTERNAL_DEPOSIT_GUARD_COUNT','value':MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,'description':'Maximum\x20external_deposit_guard\x20entries\x20(Treasury-specific,\x20not\x20yet\x20in\x20onchain-constants.ts)'},{'name':'MAX_EXTERNAL_WITHDRAW_GUARD_COUNT','value':MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,'description':'Maximum\x20external_withdraw_guard\x20entries\x20(Treasury-specific,\x20not\x20yet\x20in\x20onchain-constants.ts)'},{'name':'MAX_DESCRIPTION_LENGTH','value':MAX_DESCRIPTION_LENGTH,'description':'Maximum\x20description\x20length\x20(shared\x20across\x20all\x20objects)'},{'name':'USER_DEFINED_PERM_INDEX_START','value':USER_DEFINED_PERM_INDEX_START,'description':'Custom\x20permission\x20indexes\x20must\x20be\x20>=\x20this\x20value'},{'name':'MAX_ENTITY_COUNT','value':MAX_ENTITY_COUNT,'description':'Maximum\x20entities\x20per\x20Permission\x20(shared)'},{'name':'MAX_PERM_FOR_ENTITY','value':MAX_PERM_FOR_ENTITY,'description':'Maximum\x20permission\x20indexes\x20per\x20entity\x20(shared)'},{'name':'MAX_ADMIN_COUNT','value':MAX_ADMIN_COUNT,'description':'Maximum\x20admins\x20per\x20Permission\x20(shared)'}];}function buildRenderingHints(a,b,c,d,e){return{'include_puzzle_template':a==='initial_design','include_risk_details':a==='pre_publish'||a==='stakeholder_review'||a==='mid_design_review','include_questions':a==='pre_publish','include_irreversibility_warning':c,'include_external_guard_warning':d,'include_cross_object_warning':e||a==='cross_object_check','max_length':b};}export function buildPromptFromTreasuryContext(a){const b=[],d=a['rendering_hints'];b['push']('═══\x20Treasury\x20Context\x20(mode:\x20'+a['mode']+')\x20═══'),b['push']('');a['stakeholder_perspective']&&(b['push']('Stakeholder\x20perspective:\x20'+a['stakeholder_perspective']),b['push'](''));a['matched_scene']&&(b['push']('Scene:\x20'+a['matched_scene']['name']),b['push']('Scene\x20ID:\x20'+a['matched_scene']['id']),b['push']('Permission\x20range:\x20'+a['matched_scene']['permission_index_range']),b['push'](''));a['matched_template']&&(b['push']('Suggested\x20template:\x20'+a['matched_template']['id']+'\x20—\x20'+a['matched_template']['name']),b['push'](''));if(d['include_puzzle_template']&&a['puzzle_completeness']){const e=a['puzzle_completeness'];b['push']('─\x20Puzzle\x20Completeness\x20──────────────'),b['push']('Complete:\x20'+(e['complete']?'YES':'NO')),e['missing']['length']>0x0&&b['push']('Missing:\x20'+e['missing']['join'](',\x20')),b['push']('Next:\x20'+e['next_step']),b['push']('');}if(d['include_risk_details']&&a['relevant_risks']['length']>0x0){b['push']('─\x20Relevant\x20Risk\x20Rules\x20('+a['relevant_risks']['length']+')\x20──────────────');for(const f of a['relevant_risks']['slice'](0x0,0x8)){b['push']('\x20\x20'+f['id']+'\x20—\x20'+f['trigger']);}a['relevant_risks']['length']>0x8&&b['push']('\x20\x20...\x20and\x20'+(a['relevant_risks']['length']-0x8)+'\x20more'),b['push']('');}if(a['risk_assessment']){b['push']('─\x20Risk\x20Assessment\x20──────────────'),b['push']('Overall:\x20'+a['risk_assessment']['overall_risk']),b['push']('Detected:\x20'+a['risk_assessment']['risks']['length']+'\x20risk(s)');for(const g of a['risk_assessment']['risks']['slice'](0x0,0x5)){b['push']('\x20\x20['+g['level']+']\x20'+g['id']+':\x20'+g['title']);}b['push']('');}if(a['relevant_builtin_permissions']['length']>0x0){b['push']('─\x20Builtin\x20Treasury\x20Permissions\x20(active:\x20'+a['relevant_builtin_permissions']['length']+')\x20──────────────');for(const i of a['relevant_builtin_permissions']){b['push']('\x20\x20['+i['index']+']\x20'+i['name']+':\x20'+i['description']);}b['push']('');}if(a['reserved_builtin_permissions']['length']>0x0){b['push']('─\x20Reserved\x20(no\x20Permission\x20index)\x20──────────────');for(const j of a['reserved_builtin_permissions']){b['push']('\x20\x20'+j['name']+':\x20'+j['description']);}b['push']('');}d['include_irreversibility_warning']&&(b['push']('⚠️\x20WITHDRAW\x20OPERATION\x20DETECTED\x20—\x20IRREVERSIBLE'),b['push']('\x20\x20-\x20withdraw\x20(fixed)\x20and\x20external_withdraw\x20cannot\x20be\x20undone'),b['push']('\x20\x20-\x20verify\x20recipient\x20address\x20twice'),b['push']('\x20\x20-\x20ensure\x20balance\x20sufficiency'),b['push'](''));d['include_external_guard_warning']&&(b['push']('⚠️\x20EXTERNAL\x20GUARD\x20MANAGEMENT\x20—\x20Verify\x20Guard\x20table\x20fields'),b['push']('\x20\x20-\x20identifier\x20must\x20be\x20number-type\x20(u8/u16/u32/u64/u128/u256)'),b['push']('\x20\x20-\x20store_from_id\x20must\x20be\x20address-compatible'),b['push']('\x20\x20-\x20external_withdraw_guard.identifier\x20is\x20REQUIRED\x20(u8,\x20not\x20Option)'),b['push']('\x20\x20-\x20external_deposit_guard.identifier\x20is\x20Option<u8>\x20(None\x20=\x20no\x20amount\x20limit)'),b['push'](''));d['include_cross_object_warning']&&(b['push']('⚠️\x20CROSS-OBJECT\x20COLLABORATION\x20—\x20Verify\x20consistency'),b['push']('\x20\x20-\x20If\x20shared\x20with\x20Service:\x20verify\x20Permission\x20indexes\x20250-258\x20(Treasury)\x20and\x20300-320\x20(Service)\x20align'),b['push']('\x20\x20-\x20If\x20referenced\x20by\x20Allocator/Arbitration:\x20TREASURY_RECEIVE\x20(253)\x20must\x20be\x20granted\x20for\x20CoinWrapper\x20intake'),b['push'](''));if(a['cross_object_refs']['length']>0x0){b['push']('─\x20Cross-Object\x20References\x20('+a['cross_object_refs']['length']+')\x20──────────────');for(const k of a['cross_object_refs']['slice'](0x0,0x6)){b['push']('\x20\x20['+k['collaboration_type']+']\x20'+k['object']+'.'+k['field']),b['push']('\x20\x20\x20\x20'+k['description']);}a['cross_object_refs']['length']>0x6&&b['push']('\x20\x20...\x20and\x20'+(a['cross_object_refs']['length']-0x6)+'\x20more'),b['push']('');}if(a['onchain_constraints']['length']>0x0){b['push']('─\x20On-chain\x20Constraints\x20──────────────');for(const l of a['onchain_constraints']){b['push']('\x20\x20'+l['name']+'\x20=\x20'+l['value']+'\x20—\x20'+l['description']);}b['push']('');}if(d['include_questions']&&a['relevant_questions']['length']>0x0){b['push']('─\x20Confirmation\x20Questions\x20──────────────');for(const m of a['relevant_questions']){const n=m['requires_explicit_yes']?'\x20⚠️':'';b['push']('\x20\x20'+m['id']+n+':\x20'+m['question']);}b['push']('');}return b['join']('\x0a');}export function getTreasuryContextSummary(a){const b=['mode='+a['mode'],'scene='+(a['matched_scene']?.['id']??'none'),'risks='+a['relevant_risks']['length'],'permissions='+a['relevant_builtin_permissions']['length']];if(a['stakeholder_perspective'])b['push']('stakeholder='+a['stakeholder_perspective']);if(a['risk_assessment'])b['push']('overall_risk='+a['risk_assessment']['overall_risk']);if(a['matched_template'])b['push']('template='+a['matched_template']['id']);return b['join'](',\x20');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const TREASURY_PERMISSIONS=[{'index':0xfa,'name':'TREASURY_NEW','description':'Create\x20new\x20Treasury','governed_operation':'treasury::new','active':!![]},{'index':0xfb,'name':'TREASURY_DESCRIPTION','description':'Modify\x20Treasury\x20description','governed_operation':'treasury::description_set','active':!![]},{'index':0xfc,'name':'TREASURY_DEPOSIT','description':'Internal\x20deposit\x20(Permission\x20path)','governed_operation':'treasury::deposit','active':!![]},{'index':0xfd,'name':'TREASURY_RECEIVE','description':'Receive\x20CoinWrapper\x20into\x20balance','governed_operation':'treasury::receive','active':!![]},{'index':0xfe,'name':'TREASURY_WITHDRAW','description':'Internal\x20withdraw\x20(Permission\x20path,\x20fixed\x20amount)','governed_operation':'treasury::withdraw','active':!![]},{'index':0xff,'name':'TREASURY_EXTERNAL_DEPOSIT_GUARD','description':'Manage\x20external\x20deposit\x20Guard\x20list\x20(add/remove/clear)','governed_operation':'treasury::external_deposit_guard_add/remove/clear','active':!![]},{'index':0x100,'name':'TREASURY_EXTERNAL_WITHDRAW_GUARD','description':'Manage\x20external\x20withdraw\x20Guard\x20list\x20(add/remove/clear)','governed_operation':'treasury::external_withdraw_guard_add/remove/clear','active':!![]},{'index':0x101,'name':'TREASURY_OWNER_RECEIVE','description':'Owner\x20receive\x20(unwrap\x20received\x20objects,\x20send\x20to\x20Permission\x20owner)','governed_operation':'treasury::owner_receive\x20/\x20owner_receive_object','active':!![]},{'index':0x102,'name':'TREASURY_UM','description':'Set\x20UM\x20(User\x20Manager\x20=\x20Contact\x20object)','governed_operation':'treasury::um_set\x20/\x20um_none','active':!![]},{'index':-0x1,'name':'TREASURY_EXTERNAL_DEPOSIT_RESERVED','description':'RESERVED\x20—\x20external_deposit\x20uses\x20Guard\x20+\x20Passport,\x20does\x20NOT\x20call\x20permission::check','governed_operation':'treasury::external_deposit\x20(Guard\x20path)','active':![]},{'index':-0x1,'name':'TREASURY_EXTERNAL_WITHDRAW_RESERVED','description':'RESERVED\x20—\x20external_withdraw\x20uses\x20Guard\x20+\x20Passport,\x20does\x20NOT\x20call\x20permission::check','governed_operation':'treasury::external_withdraw\x20(Guard\x20path)','active':![]}];export const TREASURY_SCENES=[{'id':'treasury_fund_collection','name':'Team\x20fund\x20collection\x20(internal\x20deposit\x20+\x20receive)','coin_type_category':'generic','permission_index_range':'250-254','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>[0xfa,0xfb,0xfc,0xfd,0xfe]['includes'](a['index'])),'owner_operations':['um_set\x20(258)','owner_receive\x20(257)','permission\x20transfer'],'admin_operations':['description_set\x20(251)'],'permission_index_operations':['treasury::deposit\x20(252)','treasury::receive\x20(253)'],'external_operations':[],'guard_list_mutable_after_publish':!![],'common_patterns':['Owner-only\x20deposit:\x20TREASURY_DEPOSIT\x20(252)\x20granted\x20to\x20team\x20finance','Receive\x20automation:\x20TREASURY_RECEIVE\x20(253)\x20for\x20CoinWrapper\x20intake','No\x20external\x20Guard:\x20all\x20deposits\x20via\x20Permission\x20path','inflow\x20accumulates\x20total\x20team\x20contributions'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Allocator.sharing.who=Entity\x20→\x20Treasury\x20address\x20(fund\x20inflow)','Treasury.receive\x20(253)\x20converts\x20CoinWrapper\x20to\x20balance'],'recommended_templates':['T-T-01','T-T-06']},{'id':'treasury_external_ops','name':'External\x20deposit\x20/\x20withdraw\x20with\x20Guard\x20protection','coin_type_category':'generic','permission_index_range':'255-256','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>[0xff,0x100]['includes'](a['index'])),'owner_operations':['external_deposit_guard_add/remove/clear\x20(255)','external_withdraw_guard_add/remove/clear\x20(256)'],'admin_operations':[],'permission_index_operations':['treasury::external_deposit_guard_*\x20(255)','treasury::external_withdraw_guard_*\x20(256)'],'external_operations':['treasury::external_deposit\x20(Guard\x20+\x20Passport,\x20no\x20Permission)','treasury::external_withdraw\x20(Guard\x20+\x20Passport,\x20no\x20Permission)'],'guard_list_mutable_after_publish':!![],'common_patterns':['Whitelist\x20external\x20deposit:\x20external_deposit_guard\x20with\x20identifier=None','Capped\x20external\x20withdraw:\x20external_withdraw_guard\x20with\x20identifier=amount\x20field','Pair\x20external\x20ops\x20with\x20Guard\x20for\x20zero-Permission\x20external\x20access','store_from_id\x20tracks\x20order/business\x20ID\x20for\x20audit\x20trail'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Guard\x20object\x20referenced\x20by\x20external_deposit_guard\x20/\x20external_withdraw_guard','Passport\x20object\x20required\x20for\x20every\x20external_deposit\x20/\x20external_withdraw\x20call'],'recommended_templates':['T-T-03','T-T-04']},{'id':'treasury_guard_protection','name':'Guard-protected\x20Treasury\x20(asymmetric\x20identifier\x20design)','coin_type_category':'generic','permission_index_range':'255-256','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>[0xff,0x100]['includes'](a['index'])),'owner_operations':['external_deposit_guard\x20management\x20(255)','external_withdraw_guard\x20management\x20(256)'],'admin_operations':[],'permission_index_operations':['treasury::external_deposit_guard_add\x20(255)','treasury::external_withdraw_guard_add\x20(256)'],'external_operations':['external_deposit\x20via\x20Guard\x20(identifier:\x20Option<u8>\x20—\x20None\x20means\x20no\x20amount\x20limit)','external_withdraw\x20via\x20Guard\x20(identifier:\x20u8\x20—\x20REQUIRED,\x20no\x20None\x20option)'],'guard_list_mutable_after_publish':!![],'common_patterns':['Asymmetric\x20identifier:\x20deposit\x20optional,\x20withdraw\x20required','Deposit\x20amount\x20from\x20Coin\x20itself;\x20withdraw\x20amount\x20from\x20Guard\x20submission','upsert\x20semantics:\x20add\x20updates\x20existing\x20guard,\x20else\x20appends','external_deposit\x20splits\x20coin\x20if\x20value\x20>\x20guard-specified\x20amount'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Guard\x20table\x20item\x20value\x20type\x20must\x20be\x20number\x20(is_number_type)\x20for\x20identifier','Guard\x20table\x20item\x20value\x20type\x20must\x20be\x20address-compatible\x20for\x20store_from_id'],'recommended_templates':['T-T-03']},{'id':'treasury_permission_sharing','name':'Treasury\x20shared\x20with\x20Service\x20via\x20common\x20Permission','coin_type_category':'generic','permission_index_range':'250-258','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>a['active']),'owner_operations':['um_set\x20(258)','owner_receive\x20(257)'],'admin_operations':['description_set\x20(251)'],'permission_index_operations':['treasury::deposit\x20(252)\x20+\x20service::publish\x20(311)\x20on\x20same\x20Permission','treasury::withdraw\x20(254)\x20+\x20service::compensation_fund_withdraw\x20(315)'],'external_operations':[],'guard_list_mutable_after_publish':!![],'common_patterns':['Shared\x20Permission:\x20Treasury\x20+\x20Service\x20reference\x20same\x20Permission\x20object','Unified\x20admin\x20list:\x20single\x20admin\x20team\x20manages\x20both\x20Service\x20and\x20Treasury','Simplifies\x20key\x20management:\x20one\x20Permission\x20object\x20per\x20business\x20unit'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Service.compensation_fund\x20(parallel\x20design,\x20NOT\x20a\x20Treasury)','Service.order_allocator\x20→\x20Treasury\x20as\x20Entity\x20target'],'recommended_templates':['T-T-04','T-T-05']},{'id':'treasury_um_delegation','name':'UM\x20delegation\x20(User\x20Manager\x20=\x20Contact\x20object)','coin_type_category':'generic','permission_index_range':'258','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>a['index']===0x102),'owner_operations':['um_set\x20(258)','um_none\x20(258)'],'admin_operations':[],'permission_index_operations':['treasury::um_set\x20(258)','treasury::um_none\x20(258)'],'external_operations':[],'guard_list_mutable_after_publish':!![],'common_patterns':['Owner-only\x20UM:\x20TREASURY_UM\x20(258)\x20restricted\x20to\x20owner\x20(assert_owner)','UM\x20is\x20a\x20Contact\x20object\x20address,\x20not\x20a\x20regular\x20user\x20address','UM\x20≠\x20admin:\x20UM\x20is\x20for\x20contact\x20management,\x20not\x20permission\x20management','um_none\x20revokes\x20UM\x20and\x20disaffiliates\x20from\x20Registrar'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Contact\x20object\x20referenced\x20by\x20Treasury.um','Registrar.affiliation\x20/\x20disaffiliation\x20tracks\x20UM-Treasury\x20binding'],'recommended_templates':['T-T-01']},{'id':'treasury_owner_receive','name':'Owner\x20receive\x20(unwrap\x20&\x20forward\x20to\x20Permission\x20owner)','coin_type_category':'generic','permission_index_range':'257','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>a['index']===0x101),'owner_operations':['owner_receive\x20(257)','owner_receive_object\x20(257)'],'admin_operations':[],'permission_index_operations':['treasury::owner_receive\x20(257)','treasury::owner_receive_object\x20(257)'],'external_operations':[],'guard_list_mutable_after_publish':!![],'common_patterns':['Forward\x20received\x20assets:\x20CoinWrapper\x20unwrapped,\x20sent\x20to\x20Permission.owner','Does\x20NOT\x20write\x20to\x20history\x20(direct\x20forward,\x20no\x20Record\x20entry)','Used\x20when\x20Treasury\x20should\x20not\x20retain\x20received\x20assets','owner_receive_object\x20handles\x20non-coin\x20objects\x20too'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Permission.owner\x20is\x20the\x20recipient\x20(resolved\x20at\x20tx\x20time)','Received\x20objects\x20come\x20from\x20Allocator\x20/\x20Arbitration.fees_transfer\x20/\x20external\x20deposits'],'recommended_templates':['T-T-06']}];export const TREASURY_LEDGER_VERSION='1.0.0';export function getScenesByHostObject(a){return TREASURY_SCENES;}export function findSceneById(a){return TREASURY_SCENES['find'](b=>b['id']===a);}export function findSceneByPermissionIndex(a){for(const b of TREASURY_SCENES){if(b['builtin_indexes']['some'](c=>c['index']===a&&c['active']))return b;}return undefined;}export function getBuiltinPermissionByIndex(a){return TREASURY_PERMISSIONS['find'](b=>b['index']===a&&b['active']);}export function isBuiltinTreasuryPermission(a){return getBuiltinPermissionByIndex(a)!==undefined;}export function getActiveBuiltinPermissions(){return TREASURY_PERMISSIONS['filter'](a=>a['active']);}export function getReservedBuiltinPermissions(){return TREASURY_PERMISSIONS['filter'](a=>!a['active']);}export function inferSceneFromIntent(a){const b=a['toLowerCase']();if(b['includes']('um')||b['includes']('delegate')||b['includes']('user\x20manager'))return findSceneById('treasury_um_delegation');if(b['includes']('owner_receive')||b['includes']('owner\x20receive')||b['includes']('forward'))return findSceneById('treasury_owner_receive');if(b['includes']('external')||b['includes']('guard')){if(b['includes']('deposit'))return findSceneById('treasury_external_ops');if(b['includes']('withdraw'))return findSceneById('treasury_external_ops');return findSceneById('treasury_guard_protection');}if(b['includes']('service')||b['includes']('share'))return findSceneById('treasury_permission_sharing');if(b['includes']('deposit')||b['includes']('receive')||b['includes']('fund')||b['includes']('collect'))return findSceneById('treasury_fund_collection');return undefined;}export function getTreasuryScenesCount(){return TREASURY_SCENES['length'];}export function getMoveFunctionsForPermissionIndex(a){const b={0xfa:['treasury::new','treasury::new_with_passport'],0xfb:['treasury::description_set','treasury::description_set_with_passport'],0xfc:['treasury::deposit','treasury::deposit_with_passport'],0xfd:['treasury::receive','treasury::receive_with_passport'],0xfe:['treasury::withdraw','treasury::withdraw_with_passport'],0xff:['treasury::external_deposit_guard_add','treasury::external_deposit_guard_add_with_passport','treasury::external_deposit_guard_remove','treasury::external_deposit_guard_remove_with_passport','treasury::external_deposit_guard_clear','treasury::external_deposit_guard_clear_with_passport'],0x100:['treasury::external_withdraw_guard_add','treasury::external_withdraw_guard_add_with_passport','treasury::external_withdraw_guard_remove','treasury::external_withdraw_guard_remove_with_passport','treasury::external_withdraw_guard_clear','treasury::external_withdraw_guard_clear_with_passport'],0x101:['treasury::owner_receive','treasury::owner_receive_object'],0x102:['treasury::um_set','treasury::um_set_with_passport','treasury::um_none','treasury::um_none_with_passport']};return b[a]??[];}
|
|
1
|
+
export const TREASURY_PERMISSIONS=[{'index':0xfa,'name':'TREASURY_NEW','description':'Create\x20new\x20Treasury','governed_operation':'treasury::new','active':!![]},{'index':0xfb,'name':'TREASURY_DESCRIPTION','description':'Modify\x20Treasury\x20description','governed_operation':'treasury::description_set','active':!![]},{'index':0xfc,'name':'TREASURY_DEPOSIT','description':'Internal\x20deposit\x20(Permission\x20path)','governed_operation':'treasury::deposit','active':!![]},{'index':0xfd,'name':'TREASURY_RECEIVE','description':'Receive\x20CoinWrapper\x20into\x20balance','governed_operation':'treasury::receive','active':!![]},{'index':0xfe,'name':'TREASURY_WITHDRAW','description':'Internal\x20withdraw\x20(Permission\x20path,\x20fixed\x20amount)','governed_operation':'treasury::withdraw','active':!![]},{'index':0xff,'name':'TREASURY_EXTERNAL_DEPOSIT_GUARD','description':'Manage\x20external\x20deposit\x20Guard\x20list\x20(add/remove/clear)','governed_operation':'treasury::external_deposit_guard_add/remove/clear','active':!![]},{'index':0x100,'name':'TREASURY_EXTERNAL_WITHDRAW_GUARD','description':'Manage\x20external\x20withdraw\x20Guard\x20list\x20(add/remove/clear)','governed_operation':'treasury::external_withdraw_guard_add/remove/clear','active':!![]},{'index':0x101,'name':'TREASURY_OWNER_RECEIVE','description':'Owner\x20receive\x20(unwrap\x20received\x20objects,\x20send\x20to\x20Permission\x20owner)','governed_operation':'treasury::owner_receive\x20/\x20owner_receive_object','active':!![]},{'index':0x102,'name':'TREASURY_UM','description':'Set\x20UM\x20(User\x20Manager\x20=\x20Contact\x20object)','governed_operation':'treasury::um_set\x20/\x20um_none','active':!![]},{'index':-0x1,'name':'TREASURY_EXTERNAL_DEPOSIT_RESERVED','description':'RESERVED\x20—\x20external_deposit\x20uses\x20Guard\x20+\x20Passport,\x20does\x20NOT\x20call\x20permission::check','governed_operation':'treasury::external_deposit\x20(Guard\x20path)','active':![]},{'index':-0x1,'name':'TREASURY_EXTERNAL_WITHDRAW_RESERVED','description':'RESERVED\x20—\x20external_withdraw\x20uses\x20Guard\x20+\x20Passport,\x20does\x20NOT\x20call\x20permission::check','governed_operation':'treasury::external_withdraw\x20(Guard\x20path)','active':![]}];export const TREASURY_SCENES=[{'id':'treasury_fund_collection','name':'Team\x20fund\x20collection\x20(internal\x20deposit\x20+\x20receive)','coin_type_category':'generic','permission_index_range':'250-254','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>[0xfa,0xfb,0xfc,0xfd,0xfe]['includes'](a['index'])),'owner_operations':['um_set\x20(258)','owner_receive\x20(257)','permission\x20transfer'],'admin_operations':['description_set\x20(251)'],'permission_index_operations':['treasury::deposit\x20(252)','treasury::receive\x20(253)'],'external_operations':[],'guard_list_mutable_after_publish':!![],'common_patterns':['Owner-only\x20deposit:\x20TREASURY_DEPOSIT\x20(252)\x20granted\x20to\x20team\x20finance','Receive\x20automation:\x20TREASURY_RECEIVE\x20(253)\x20for\x20CoinWrapper\x20intake','No\x20external\x20Guard:\x20all\x20deposits\x20via\x20Permission\x20path','inflow\x20accumulates\x20total\x20team\x20contributions'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Allocator.sharing.who=Entity\x20→\x20Treasury\x20address\x20(fund\x20inflow)','Treasury.receive\x20(253)\x20converts\x20CoinWrapper\x20to\x20balance'],'recommended_templates':['T-T-01','T-T-06']},{'id':'treasury_external_ops','name':'External\x20deposit\x20/\x20withdraw\x20with\x20Guard\x20protection','coin_type_category':'generic','permission_index_range':'255-256','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>[0xff,0x100]['includes'](a['index'])),'owner_operations':['external_deposit_guard_add/remove/clear\x20(255)','external_withdraw_guard_add/remove/clear\x20(256)'],'admin_operations':[],'permission_index_operations':['treasury::external_deposit_guard_*\x20(255)','treasury::external_withdraw_guard_*\x20(256)'],'external_operations':['treasury::external_deposit\x20(Guard\x20+\x20Passport,\x20no\x20Permission)','treasury::external_withdraw\x20(Guard\x20+\x20Passport,\x20no\x20Permission)'],'guard_list_mutable_after_publish':!![],'common_patterns':['Whitelist\x20external\x20deposit:\x20external_deposit_guard\x20with\x20identifier=None','Capped\x20external\x20withdraw:\x20external_withdraw_guard\x20with\x20identifier=amount\x20field','Pair\x20external\x20ops\x20with\x20Guard\x20for\x20zero-Permission\x20external\x20access','store_from_id\x20tracks\x20order/business\x20ID\x20for\x20audit\x20trail'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Guard\x20object\x20referenced\x20by\x20external_deposit_guard\x20/\x20external_withdraw_guard','Passport\x20object\x20required\x20for\x20every\x20external_deposit\x20/\x20external_withdraw\x20call'],'recommended_templates':['T-T-03','T-T-04']},{'id':'treasury_guard_protection','name':'Guard-protected\x20Treasury\x20(asymmetric\x20identifier\x20design)','coin_type_category':'generic','permission_index_range':'255-256','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>[0xff,0x100]['includes'](a['index'])),'owner_operations':['external_deposit_guard\x20management\x20(255)','external_withdraw_guard\x20management\x20(256)'],'admin_operations':[],'permission_index_operations':['treasury::external_deposit_guard_add\x20(255)','treasury::external_withdraw_guard_add\x20(256)'],'external_operations':['external_deposit\x20via\x20Guard\x20(identifier:\x20Option<u8>\x20—\x20None\x20means\x20no\x20amount\x20limit)','external_withdraw\x20via\x20Guard\x20(identifier:\x20u8\x20—\x20REQUIRED,\x20no\x20None\x20option)'],'guard_list_mutable_after_publish':!![],'common_patterns':['Asymmetric\x20identifier:\x20deposit\x20optional,\x20withdraw\x20required','Deposit\x20amount\x20from\x20Coin\x20itself;\x20withdraw\x20amount\x20from\x20Guard\x20submission','upsert\x20semantics:\x20add\x20updates\x20existing\x20guard,\x20else\x20appends','external_deposit\x20splits\x20coin\x20if\x20value\x20>\x20guard-specified\x20amount'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Guard\x20table\x20item\x20value\x20type\x20must\x20be\x20number\x20(is_number_type)\x20for\x20identifier','Guard\x20table\x20item\x20value\x20type\x20must\x20be\x20address-compatible\x20for\x20store_from_id'],'recommended_templates':['T-T-03']},{'id':'treasury_permission_sharing','name':'Treasury\x20shared\x20with\x20Service\x20via\x20common\x20Permission','coin_type_category':'generic','permission_index_range':'250-258','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>a['active']),'owner_operations':['um_set\x20(258)','owner_receive\x20(257)'],'admin_operations':['description_set\x20(251)'],'permission_index_operations':['treasury::deposit\x20(252)\x20+\x20service::publish\x20(311)\x20on\x20same\x20Permission','treasury::withdraw\x20(254)\x20+\x20service::compensation_fund_withdraw\x20(315)'],'external_operations':[],'guard_list_mutable_after_publish':!![],'common_patterns':['Shared\x20Permission:\x20Treasury\x20+\x20Service\x20reference\x20same\x20Permission\x20object','Unified\x20admin\x20list:\x20single\x20admin\x20team\x20manages\x20both\x20Service\x20and\x20Treasury','Simplifies\x20key\x20management:\x20one\x20Permission\x20object\x20per\x20business\x20unit'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Service.compensation_fund\x20(parallel\x20design,\x20NOT\x20a\x20Treasury)','Service.order_allocator\x20→\x20Treasury\x20as\x20Entity\x20target'],'recommended_templates':['T-T-04','T-T-05']},{'id':'treasury_um_delegation','name':'UM\x20delegation\x20(User\x20Manager\x20=\x20Contact\x20object)','coin_type_category':'generic','permission_index_range':'258','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>a['index']===0x102),'owner_operations':['um_set\x20(258)','um_none\x20(258)'],'admin_operations':[],'permission_index_operations':['treasury::um_set\x20(258)','treasury::um_none\x20(258)'],'external_operations':[],'guard_list_mutable_after_publish':!![],'common_patterns':['Owner-only\x20UM:\x20TREASURY_UM\x20(258)\x20restricted\x20to\x20owner\x20(assert_owner)','UM\x20is\x20a\x20Contact\x20object\x20address,\x20not\x20a\x20regular\x20user\x20address','UM\x20≠\x20admin:\x20UM\x20is\x20for\x20contact\x20management,\x20not\x20permission\x20management','um_none\x20revokes\x20UM\x20and\x20disaffiliates\x20from\x20Registrar'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Contact\x20object\x20referenced\x20by\x20Treasury.um','object_linker::affiliation_core\x20/\x20disaffiliation\x20tracks\x20UM-Treasury\x20binding'],'recommended_templates':['T-T-01']},{'id':'treasury_owner_receive','name':'Owner\x20receive\x20(unwrap\x20&\x20forward\x20to\x20Permission\x20owner)','coin_type_category':'generic','permission_index_range':'257','builtin_indexes':TREASURY_PERMISSIONS['filter'](a=>a['index']===0x101),'owner_operations':['owner_receive\x20(257)','owner_receive_object\x20(257)'],'admin_operations':[],'permission_index_operations':['treasury::owner_receive\x20(257)','treasury::owner_receive_object\x20(257)'],'external_operations':[],'guard_list_mutable_after_publish':!![],'common_patterns':['Forward\x20received\x20assets:\x20CoinWrapper\x20unwrapped,\x20sent\x20to\x20Permission.owner','Does\x20NOT\x20write\x20to\x20history\x20(direct\x20forward,\x20no\x20Record\x20entry)','Used\x20when\x20Treasury\x20should\x20not\x20retain\x20received\x20assets','owner_receive_object\x20handles\x20non-coin\x20objects\x20too'],'irreversibility':{'deposit':'reversible','withdraw':'irreversible','external_deposit':'reversible','external_withdraw':'irreversible','owner_receive':'irreversible'},'cross_object_collaboration':['Permission.owner\x20is\x20the\x20recipient\x20(resolved\x20at\x20tx\x20time)','Received\x20objects\x20come\x20from\x20Allocator\x20/\x20Arbitration.fees_transfer\x20/\x20external\x20deposits'],'recommended_templates':['T-T-06']}];export const TREASURY_LEDGER_VERSION='1.0.0';export function getScenesByHostObject(a){return TREASURY_SCENES;}export function findSceneById(a){return TREASURY_SCENES['find'](b=>b['id']===a);}export function findSceneByPermissionIndex(a){for(const b of TREASURY_SCENES){if(b['builtin_indexes']['some'](c=>c['index']===a&&c['active']))return b;}return undefined;}export function getBuiltinPermissionByIndex(a){return TREASURY_PERMISSIONS['find'](b=>b['index']===a&&b['active']);}export function isBuiltinTreasuryPermission(a){return getBuiltinPermissionByIndex(a)!==undefined;}export function getActiveBuiltinPermissions(){return TREASURY_PERMISSIONS['filter'](a=>a['active']);}export function getReservedBuiltinPermissions(){return TREASURY_PERMISSIONS['filter'](a=>!a['active']);}export function inferSceneFromIntent(a){const b=a['toLowerCase']();if(b['includes']('um')||b['includes']('delegate')||b['includes']('user\x20manager'))return findSceneById('treasury_um_delegation');if(b['includes']('owner_receive')||b['includes']('owner\x20receive')||b['includes']('forward'))return findSceneById('treasury_owner_receive');if(b['includes']('external')||b['includes']('guard')){if(b['includes']('deposit'))return findSceneById('treasury_external_ops');if(b['includes']('withdraw'))return findSceneById('treasury_external_ops');return findSceneById('treasury_guard_protection');}if(b['includes']('service')||b['includes']('share'))return findSceneById('treasury_permission_sharing');if(b['includes']('deposit')||b['includes']('receive')||b['includes']('fund')||b['includes']('collect'))return findSceneById('treasury_fund_collection');return undefined;}export function getTreasuryScenesCount(){return TREASURY_SCENES['length'];}export function getMoveFunctionsForPermissionIndex(a){const b={0xfa:['treasury::new','treasury::new_with_passport'],0xfb:['treasury::description_set','treasury::description_set_with_passport'],0xfc:['treasury::deposit','treasury::deposit_with_passport'],0xfd:['treasury::receive','treasury::receive_with_passport'],0xfe:['treasury::withdraw','treasury::withdraw_with_passport'],0xff:['treasury::external_deposit_guard_add','treasury::external_deposit_guard_add_with_passport','treasury::external_deposit_guard_remove','treasury::external_deposit_guard_remove_with_passport','treasury::external_deposit_guard_clear','treasury::external_deposit_guard_clear_with_passport'],0x100:['treasury::external_withdraw_guard_add','treasury::external_withdraw_guard_add_with_passport','treasury::external_withdraw_guard_remove','treasury::external_withdraw_guard_remove_with_passport','treasury::external_withdraw_guard_clear','treasury::external_withdraw_guard_clear_with_passport'],0x101:['treasury::owner_receive','treasury::owner_receive_object'],0x102:['treasury::um_set','treasury::um_set_with_passport','treasury::um_none','treasury::um_none_with_passport']};return b[a]??[];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,MAX_DESCRIPTION_LENGTH}from'./treasury-puzzle.js';const R_T_1_01={'id':'R-T-1-01','category':'structural','trigger':'Description\x20length\x20exceeds\x20MAX_DESCRIPTION_LENGTH\x20(4000)','check':a=>{if(!a['description'])return null;if(a['description']['length']>MAX_DESCRIPTION_LENGTH)return{'id':'R-T-1-01','level':'HIGH','category':'structural','title':'Description\x20length\x20exceeds\x20limit','description':'Description\x20length\x20'+a['description']['length']+'\x20exceeds\x20MAX_DESCRIPTION_LENGTH\x20'+MAX_DESCRIPTION_LENGTH,'affected_stakeholders':['owner','admin'],'scenario':'Setting\x20a\x20description\x20longer\x20than\x204000\x20characters','mitigation':'Truncate\x20description\x20to\x20fit\x20within\x204000\x20characters','evidence':'length='+a['description']['length']};return null;}},R_T_1_02={'id':'R-T-1-02','category':'structural','trigger':'external_deposit_guard\x20count\x20exceeds\x20MAX_EXTERNAL_DEPOSIT_GUARD_COUNT\x20(100)','check':a=>{if(!a['external_deposit_guard']||a['external_deposit_guard']['op']!=='add')return null;const b=a['current_external_deposit_guard_count']??0x0,c=a['external_deposit_guard']['guards']['length'];if(b+c>MAX_EXTERNAL_DEPOSIT_GUARD_COUNT)return{'id':'R-T-1-02','level':'HIGH','category':'structural','title':'external_deposit_guard\x20count\x20exceeds\x20limit','description':'Adding\x20'+c+'\x20guards\x20to\x20existing\x20'+b+'\x20would\x20exceed\x20MAX_EXTERNAL_DEPOSIT_GUARD_COUNT\x20'+MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,'affected_stakeholders':['owner'],'scenario':'Adding\x20too\x20many\x20external\x20deposit\x20guards','mitigation':'Remove\x20unused\x20guards\x20before\x20adding\x20new\x20ones,\x20or\x20use\x20\x27set\x27\x20to\x20replace\x20the\x20list','evidence':'current='+b+',\x20adding='+c+',\x20limit='+MAX_EXTERNAL_DEPOSIT_GUARD_COUNT};return null;}},R_T_1_03={'id':'R-T-1-03','category':'structural','trigger':'external_withdraw_guard\x20count\x20exceeds\x20MAX_EXTERNAL_WITHDRAW_GUARD_COUNT\x20(200)','check':a=>{if(!a['external_withdraw_guard']||a['external_withdraw_guard']['op']!=='add')return null;const b=a['current_external_withdraw_guard_count']??0x0,c=a['external_withdraw_guard']['guards']['length'];if(b+c>MAX_EXTERNAL_WITHDRAW_GUARD_COUNT)return{'id':'R-T-1-03','level':'HIGH','category':'structural','title':'external_withdraw_guard\x20count\x20exceeds\x20limit','description':'Adding\x20'+c+'\x20guards\x20to\x20existing\x20'+b+'\x20would\x20exceed\x20MAX_EXTERNAL_WITHDRAW_GUARD_COUNT\x20'+MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,'affected_stakeholders':['owner'],'scenario':'Adding\x20too\x20many\x20external\x20withdraw\x20guards','mitigation':'Remove\x20unused\x20guards\x20before\x20adding\x20new\x20ones,\x20or\x20use\x20\x27set\x27\x20to\x20replace\x20the\x20list','evidence':'current='+b+',\x20adding='+c+',\x20limit='+MAX_EXTERNAL_WITHDRAW_GUARD_COUNT};return null;}},R_T_1_04={'id':'R-T-1-04','category':'structural','trigger':'external_withdraw_guard.identifier\x20is\x20missing\x20(required\x20u8,\x20not\x20Option)','check':a=>{if(!a['external_withdraw_guard'])return null;if(a['external_withdraw_guard']['op']!=='add'&&a['external_withdraw_guard']['op']!=='set')return null;for(const b of a['external_withdraw_guard']['guards']){if(b['identifier']===undefined||b['identifier']===null)return{'id':'R-T-1-04','level':'HIGH','category':'structural','title':'external_withdraw_guard.identifier\x20missing','description':'Guard\x20'+b['guard']+'\x20missing\x20required\x20identifier.\x20AmountFromWithdrawGuard.identifier\x20is\x20u8\x20(not\x20Option<u8>);\x20withdraw\x20amount\x20must\x20come\x20from\x20Guard\x20table.','affected_stakeholders':['owner','external_operator'],'scenario':'Configuring\x20external\x20withdraw\x20guard\x20without\x20amount\x20source','mitigation':'Set\x20identifier\x20to\x20the\x20Guard\x20table\x20index\x20that\x20provides\x20the\x20withdraw\x20amount\x20(must\x20be\x20a\x20number-type\x20field)','evidence':'guard='+b['guard']+',\x20identifier=undefined'};}return null;}},R_T_2_01={'id':'R-T-2-01','category':'semantic','trigger':'External\x20operation\x20(deposit/withdraw)\x20requested\x20without\x20corresponding\x20guard\x20configured','check':a=>{if(a['deposit']?.['by_external_deposit_guard']){const b=a['deposit']['by_external_deposit_guard'];if((a['current_external_deposit_guard_count']??0x0)===0x0)return{'id':'R-T-2-01','level':'MEDIUM','category':'semantic','title':'External\x20deposit\x20guard\x20list\x20is\x20empty','description':'Requesting\x20external_deposit\x20via\x20guard\x20'+b+',\x20but\x20Treasury\x20has\x20no\x20external_deposit_guard\x20configured.\x20Operation\x20will\x20abort\x20with\x20E_EXTERNAL_DEPOSIT_GUARD_NOT_FOUND.','affected_stakeholders':['external_operator','owner'],'scenario':'External\x20deposit\x20attempted\x20before\x20guard_add','mitigation':'Call\x20external_deposit_guard_add\x20(Permission\x20index\x20255)\x20first\x20to\x20register\x20guard\x20'+b,'evidence':'guard='+b+',\x20current_count=0'};}if(a['withdraw']?.['amount_by_external_withdraw_guard']){const c=a['withdraw']['amount_by_external_withdraw_guard'];if((a['current_external_withdraw_guard_count']??0x0)===0x0)return{'id':'R-T-2-01','level':'MEDIUM','category':'semantic','title':'External\x20withdraw\x20guard\x20list\x20is\x20empty','description':'Requesting\x20external_withdraw\x20via\x20guard\x20'+c+',\x20but\x20Treasury\x20has\x20no\x20external_withdraw_guard\x20configured.\x20Operation\x20will\x20abort\x20with\x20E_EXTERNAL_WITHDRAW_GUARD_NOT_FOUND.','affected_stakeholders':['external_operator','owner'],'scenario':'External\x20withdraw\x20attempted\x20before\x20guard_add','mitigation':'Call\x20external_withdraw_guard_add\x20(Permission\x20index\x20256)\x20first\x20to\x20register\x20guard\x20'+c,'evidence':'guard='+c+',\x20current_count=0'};}return null;}},R_T_2_02={'id':'R-T-2-02','category':'semantic','trigger':'External\x20operation\x20paired\x20with\x20Permission\x20path\x20(confused\x20access\x20control)','check':a=>{if(a['deposit']?.['by_external_deposit_guard']&&a['current_permission_indexes_granted']?.['includes'](0xfc))return{'id':'R-T-2-02','level':'LOW','category':'semantic','title':'Both\x20Permission\x20deposit\x20and\x20external\x20deposit\x20guard\x20configured','description':'Treasury\x20has\x20both\x20TREASURY_DEPOSIT\x20(252)\x20granted\x20and\x20external_deposit_guard\x20configured.\x20While\x20not\x20an\x20error,\x20mixing\x20access\x20paths\x20complicates\x20audit.','affected_stakeholders':['owner','admin'],'scenario':'Hybrid\x20internal+external\x20deposit\x20setup','mitigation':'Document\x20which\x20path\x20each\x20depositor\x20should\x20use;\x20consider\x20splitting\x20into\x20separate\x20Treasury\x20objects\x20for\x20clarity','evidence':'has_perm_252=true,\x20has_external_deposit_guard=true'};return null;}},R_T_2_03={'id':'R-T-2-03','category':'semantic','trigger':'external_deposit\x20amount\x20exceeds\x20guard-specified\x20value\x20(split-and-refund\x20path)','check':a=>{if(!a['deposit']?.['by_external_deposit_guard']||!a['deposit']?.['coin_balance'])return null;return{'id':'R-T-2-03','level':'LOW','category':'semantic','title':'External\x20deposit\x20may\x20trigger\x20split-and-refund','description':'If\x20coin\x20value\x20('+a['deposit']['coin_balance']+')\x20exceeds\x20guard-specified\x20amount,\x20the\x20excess\x20will\x20be\x20split\x20and\x20refunded\x20to\x20sender.\x20Verify\x20intent.','affected_stakeholders':['external_operator'],'scenario':'External\x20deposit\x20with\x20coin\x20value\x20>\x20guard\x20limit','mitigation':'Pre-split\x20the\x20coin\x20to\x20exact\x20guard-specified\x20amount,\x20or\x20accept\x20the\x20refund\x20behavior','evidence':'coin_balance='+a['deposit']['coin_balance']};}},R_T_3_01={'id':'R-T-3-01','category':'authority','trigger':'Same\x20address\x20holds\x20both\x20TREASURY_DEPOSIT\x20(252)\x20and\x20TREASURY_WITHDRAW\x20(254)','check':a=>{if(!a['current_permission_indexes_granted'])return null;const b=a['current_permission_indexes_granted']['includes'](0xfc),c=a['current_permission_indexes_granted']['includes'](0xfe);if(b&&c)return{'id':'R-T-3-01','level':'MEDIUM','category':'authority','title':'Deposit\x20and\x20withdraw\x20permissions\x20both\x20present\x20(review\x20separation)','description':'Both\x20TREASURY_DEPOSIT\x20(252)\x20and\x20TREASURY_WITHDRAW\x20(254)\x20are\x20granted.\x20Verify\x20they\x20are\x20assigned\x20to\x20different\x20entities\x20to\x20enforce\x20separation\x20of\x20duties.','affected_stakeholders':['owner','depositor','withdrawer'],'scenario':'Single\x20role\x20can\x20both\x20add\x20and\x20remove\x20funds','mitigation':'Assign\x20252\x20to\x20depositor\x20role,\x20254\x20to\x20withdrawer\x20role;\x20use\x20separate\x20Permission\x20objects\x20if\x20needed','evidence':'has_252=true,\x20has_254=true'};return null;}},R_T_3_02={'id':'R-T-3-02','category':'authority','trigger':'TREASURY_EXTERNAL_DEPOSIT_GUARD\x20(255)\x20granted\x20to\x20non-owner\x20(admin-level\x20risk)','check':a=>{if(!a['current_permission_indexes_granted']?.['includes'](0xff))return null;return{'id':'R-T-3-02','level':'MEDIUM','category':'authority','title':'External\x20deposit\x20guard\x20management\x20permission\x20granted','description':'TREASURY_EXTERNAL_DEPOSIT_GUARD\x20(255)\x20is\x20granted.\x20Managing\x20external_deposit_guard\x20list\x20controls\x20who\x20can\x20externally\x20deposit.\x20Verify\x20assignment\x20scope.','affected_stakeholders':['owner','admin'],'scenario':'Guard\x20management\x20delegated\x20to\x20operator','mitigation':'Restrict\x20255\x20to\x20owner/admin\x20only;\x20guard\x20list\x20changes\x20affect\x20external\x20access\x20policy','evidence':'has_perm_255=true'};}},R_T_3_03={'id':'R-T-3-03','category':'authority','trigger':'TREASURY_EXTERNAL_WITHDRAW_GUARD\x20(256)\x20granted\x20—\x20high-impact\x20permission','check':a=>{if(!a['current_permission_indexes_granted']?.['includes'](0x100))return null;return{'id':'R-T-3-03','level':'HIGH','category':'authority','title':'External\x20withdraw\x20guard\x20management\x20permission\x20granted','description':'TREASURY_EXTERNAL_WITHDRAW_GUARD\x20(256)\x20is\x20granted.\x20Managing\x20external_withdraw_guard\x20list\x20controls\x20who\x20can\x20externally\x20withdraw\x20(irreversible).\x20Tightly\x20restrict.','affected_stakeholders':['owner','withdrawer'],'scenario':'External\x20withdraw\x20guard\x20management\x20delegated','mitigation':'Restrict\x20256\x20to\x20owner\x20only;\x20consider\x20multi-sig\x20for\x20production\x20Treasury','evidence':'has_perm_256=true'};}},R_T_4_01={'id':'R-T-4-01','category':'lifecycle','trigger':'Internal\x20withdraw\x20(fixed\x20amount)\x20—\x20irreversible\x20fund\x20operation','check':a=>{if(!a['withdraw']?.['amount_fixed'])return null;return{'id':'R-T-4-01','level':'CRITICAL','category':'lifecycle','title':'Internal\x20withdraw\x20is\x20irreversible','description':'Fixed\x20withdraw\x20of\x20'+a['withdraw']['amount_fixed']+'\x20to\x20'+(a['withdraw']['recipient']??'recipient')+'.\x20Once\x20executed,\x20funds\x20cannot\x20be\x20recovered\x20without\x20recipient\x20cooperation.','affected_stakeholders':['owner','withdrawer'],'scenario':'Permission-authorized\x20withdraw\x20(254)','mitigation':'1)\x20Verify\x20recipient\x20address\x20twice.\x202)\x20Confirm\x20amount.\x203)\x20Check\x20balance\x20sufficiency.\x204)\x20Record\x20Payment\x20object\x20for\x20audit.','evidence':'amount='+a['withdraw']['amount_fixed']+',\x20recipient='+(a['withdraw']['recipient']??'?')};}},R_T_4_02={'id':'R-T-4-02','category':'lifecycle','trigger':'External\x20withdraw\x20(via\x20guard)\x20—\x20irreversible\x20fund\x20operation','check':a=>{if(!a['withdraw']?.['amount_by_external_withdraw_guard'])return null;return{'id':'R-T-4-02','level':'CRITICAL','category':'lifecycle','title':'External\x20withdraw\x20is\x20irreversible','description':'External\x20withdraw\x20via\x20guard\x20'+a['withdraw']['amount_by_external_withdraw_guard']+'\x20to\x20'+(a['withdraw']['recipient']??'recipient')+'.\x20Amount\x20determined\x20by\x20Guard\x20table\x20identifier;\x20verify\x20Guard\x20rules\x20before\x20execution.','affected_stakeholders':['owner','external_operator','withdrawer'],'scenario':'Guard-authorized\x20external\x20withdraw','mitigation':'1)\x20Verify\x20Guard\x20rules\x20match\x20business\x20intent.\x202)\x20Verify\x20recipient.\x203)\x20Ensure\x20Guard\x20identifier\x20points\x20to\x20correct\x20amount\x20field.\x204)\x20Test\x20on\x20testnet\x20first.','evidence':'guard='+a['withdraw']['amount_by_external_withdraw_guard']+',\x20recipient='+(a['withdraw']['recipient']??'?')};}},R_T_4_03={'id':'R-T-4-03','category':'lifecycle','trigger':'UM\x20set\x20or\x20revoked\x20—\x20affiliation\x20change','check':a=>{if(a['um']===undefined)return null;if(a['um']===null)return{'id':'R-T-4-03','level':'LOW','category':'lifecycle','title':'UM\x20revocation','description':'Revoking\x20UM\x20disaffiliates\x20Contact\x20from\x20Treasury\x20via\x20Registrar.\x20Existing\x20contact\x20bindings\x20become\x20orphaned.','affected_stakeholders':['owner'],'scenario':'Owner\x20revokes\x20UM\x20(um_none)','mitigation':'Verify\x20no\x20active\x20business\x20process\x20depends\x20on\x20UM\x20before\x20revoking','evidence':'um=null'};return{'id':'R-T-4-03','level':'LOW','category':'lifecycle','title':'UM\x20delegation','description':'Setting\x20UM\x20to\x20'+a['um']+'.\x20UM\x20(Contact\x20object)\x20gains\x20affiliation\x20with\x20Treasury\x20via\x20Registrar.','affected_stakeholders':['owner'],'scenario':'Owner\x20delegates\x20UM\x20(um_set)','mitigation':'Verify\x20UM\x20address\x20is\x20a\x20valid\x20Contact\x20object\x20(not\x20a\x20user\x20wallet)','evidence':'um='+a['um']};}},R_T_5_01={'id':'R-T-5-01','category':'cross_object','trigger':'Treasury\x20shared\x20with\x20Service\x20via\x20common\x20Permission\x20—\x20verify\x20alignment','check':a=>{if(!a['shared_with_service'])return null;return{'id':'R-T-5-01','level':'MEDIUM','category':'cross_object','title':'Treasury-Service\x20Permission\x20sharing\x20—\x20verify\x20index\x20alignment','description':'Treasury\x20and\x20Service\x20share\x20a\x20Permission\x20object.\x20Ensure\x20Treasury\x20indexes\x20(250-258)\x20and\x20Service\x20indexes\x20(300-320)\x20are\x20assigned\x20to\x20intended\x20entities;\x20cross-object\x20admin\x20changes\x20affect\x20both.','affected_stakeholders':['owner','admin'],'scenario':'Single\x20Permission\x20for\x20both\x20Treasury\x20and\x20Service','mitigation':'Document\x20which\x20entities\x20hold\x20which\x20indexes\x20across\x20both\x20objects;\x20review\x20admin\x20list\x20changes\x20for\x20cross-impact','evidence':'shared_with_service=true'};}},R_T_5_02={'id':'R-T-5-02','category':'cross_object','trigger':'Treasury\x20referenced\x20by\x20Allocator/Arbitration\x20—\x20receive\x20(253)\x20must\x20be\x20granted','check':a=>{if(!a['shared_with_allocator']&&!a['shared_with_arbitration'])return null;const b=a['current_permission_indexes_granted']?.['includes'](0xfd);if(!b)return{'id':'R-T-5-02','level':'HIGH','category':'cross_object','title':'Treasury\x20referenced\x20by\x20Allocator/Arbitration\x20but\x20TREASURY_RECEIVE\x20(253)\x20not\x20granted','description':'Allocator/Arbitration\x20will\x20send\x20CoinWrapper/Payment\x20to\x20Treasury,\x20but\x20no\x20entity\x20has\x20TREASURY_RECEIVE\x20(253)\x20to\x20call\x20treasury::receive\x20and\x20convert\x20to\x20balance.\x20Funds\x20will\x20accumulate\x20as\x20received\x20objects\x20without\x20entering\x20balance.','affected_stakeholders':['owner','system'],'scenario':'Revenue\x20collection\x20setup\x20without\x20receive\x20permission','mitigation':'Grant\x20TREASURY_RECEIVE\x20(253)\x20to\x20a\x20trusted\x20operator\x20(or\x20owner)\x20who\x20will\x20regularly\x20call\x20receive\x20to\x20convert\x20CoinWrapper\x20to\x20balance','evidence':'shared_allocator='+a['shared_with_allocator']+',\x20shared_arbitration='+a['shared_with_arbitration']+',\x20has_253=false'};return null;}},R_T_0_01={'id':'R-T-0-01','category':'structural','trigger':'Permission\x20index\x20in\x20259-260\x20range\x20detected\x20(regression\x20check\x20for\x20R-T-01)','check':a=>{if(!a['current_permission_indexes_granted'])return null;const b=a['current_permission_indexes_granted']['filter'](c=>c===0x103||c===0x104);if(b['length']>0x0)return{'id':'R-T-0-01','level':'CRITICAL','category':'structural','title':'Stale\x20Treasury\x20permission\x20index\x20259/260\x20detected\x20(R-T-01\x20regression)','description':'Permission\x20indexes\x20259/260\x20are\x20no\x20longer\x20valid\x20Treasury\x20indexes\x20(SDK\x20fixed\x20to\x20use\x20255-258\x20matching\x20Move).\x20Found:\x20'+b['join'](',\x20'),'affected_stakeholders':['owner','admin','system'],'scenario':'SDK\x20regression\x20reintroducing\x20off-by-2\x20divergence','mitigation':'Use\x20canonical\x20indexes:\x20255=EXTERNAL_DEPOSIT_GUARD,\x20256=EXTERNAL_WITHDRAW_GUARD,\x20257=OWNER_RECEIVE,\x20258=UM','evidence':'stale_indexes='+b['join'](',')};return null;}},ALL_RULES=[R_T_1_01,R_T_1_02,R_T_1_03,R_T_1_04,R_T_2_01,R_T_2_02,R_T_2_03,R_T_3_01,R_T_3_02,R_T_3_03,R_T_4_01,R_T_4_02,R_T_4_03,R_T_5_01,R_T_5_02,R_T_0_01];export const TREASURY_RISK_VERSION='1.0.0';export function getAllTreasuryRiskRules(){return[...ALL_RULES];}export function getTreasuryRiskRulesCount(){return ALL_RULES['length'];}export function getTreasuryRiskRulesByCategory(a){return ALL_RULES['filter'](b=>b['category']===a);}export function assessTreasuryRisks(a){const b=[];for(const f of ALL_RULES){const g=f['check'](a);if(g)b['push'](g);}const c=b['length']===0x0?'LOW':b['some'](h=>h['level']==='CRITICAL')?'CRITICAL':b['some'](h=>h['level']==='HIGH')?'HIGH':b['some'](h=>h['level']==='MEDIUM')?'MEDIUM':'LOW',d={};for(const h of b){d[h['category']]=(d[h['category']]??0x0)+0x1;}const e={};for(const i of b){for(const j of i['affected_stakeholders']){if(!e[j])e[j]=[];e[j]['push'](i['id']+':\x20'+i['mitigation']);}}return{'summary':'Assessed\x20'+b['length']+'\x20risk(s)\x20across\x20'+Object['keys'](d)['length']+'\x20categories','risks':b,'overall_risk':c,'risks_by_category':d,'stakeholder_advice':e,'needs_human_review':b['some'](k=>k['level']==='CRITICAL'||k['level']==='HIGH')};}
|
|
1
|
+
import{MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,MAX_DESCRIPTION_LENGTH}from'./treasury-puzzle.js';const R_T_1_01={'id':'R-T-1-01','category':'structural','trigger':'Description\x20length\x20exceeds\x20MAX_DESCRIPTION_LENGTH\x20(4000)','check':a=>{if(!a['description'])return null;if(a['description']['length']>MAX_DESCRIPTION_LENGTH)return{'id':'R-T-1-01','level':'HIGH','category':'structural','title':'Description\x20length\x20exceeds\x20limit','description':'Description\x20length\x20'+a['description']['length']+'\x20exceeds\x20MAX_DESCRIPTION_LENGTH\x20'+MAX_DESCRIPTION_LENGTH,'affected_stakeholders':['owner','admin'],'scenario':'Setting\x20a\x20description\x20longer\x20than\x204000\x20characters','mitigation':'Truncate\x20description\x20to\x20fit\x20within\x204000\x20characters','evidence':'length='+a['description']['length']};return null;}},R_T_1_02={'id':'R-T-1-02','category':'structural','trigger':'external_deposit_guard\x20count\x20exceeds\x20MAX_EXTERNAL_DEPOSIT_GUARD_COUNT\x20(100)','check':a=>{if(!a['external_deposit_guard']||a['external_deposit_guard']['op']!=='add')return null;const b=a['current_external_deposit_guard_count']??0x0,c=a['external_deposit_guard']['guards']['length'];if(b+c>MAX_EXTERNAL_DEPOSIT_GUARD_COUNT)return{'id':'R-T-1-02','level':'HIGH','category':'structural','title':'external_deposit_guard\x20count\x20exceeds\x20limit','description':'Adding\x20'+c+'\x20guards\x20to\x20existing\x20'+b+'\x20would\x20exceed\x20MAX_EXTERNAL_DEPOSIT_GUARD_COUNT\x20'+MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,'affected_stakeholders':['owner'],'scenario':'Adding\x20too\x20many\x20external\x20deposit\x20guards','mitigation':'Remove\x20unused\x20guards\x20before\x20adding\x20new\x20ones,\x20or\x20use\x20\x27set\x27\x20to\x20replace\x20the\x20list','evidence':'current='+b+',\x20adding='+c+',\x20limit='+MAX_EXTERNAL_DEPOSIT_GUARD_COUNT};return null;}},R_T_1_03={'id':'R-T-1-03','category':'structural','trigger':'external_withdraw_guard\x20count\x20exceeds\x20MAX_EXTERNAL_WITHDRAW_GUARD_COUNT\x20(200)','check':a=>{if(!a['external_withdraw_guard']||a['external_withdraw_guard']['op']!=='add')return null;const b=a['current_external_withdraw_guard_count']??0x0,c=a['external_withdraw_guard']['guards']['length'];if(b+c>MAX_EXTERNAL_WITHDRAW_GUARD_COUNT)return{'id':'R-T-1-03','level':'HIGH','category':'structural','title':'external_withdraw_guard\x20count\x20exceeds\x20limit','description':'Adding\x20'+c+'\x20guards\x20to\x20existing\x20'+b+'\x20would\x20exceed\x20MAX_EXTERNAL_WITHDRAW_GUARD_COUNT\x20'+MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,'affected_stakeholders':['owner'],'scenario':'Adding\x20too\x20many\x20external\x20withdraw\x20guards','mitigation':'Remove\x20unused\x20guards\x20before\x20adding\x20new\x20ones,\x20or\x20use\x20\x27set\x27\x20to\x20replace\x20the\x20list','evidence':'current='+b+',\x20adding='+c+',\x20limit='+MAX_EXTERNAL_WITHDRAW_GUARD_COUNT};return null;}},R_T_1_04={'id':'R-T-1-04','category':'structural','trigger':'external_withdraw_guard.identifier\x20is\x20missing\x20(required\x20u8,\x20not\x20Option)','check':a=>{if(!a['external_withdraw_guard'])return null;if(a['external_withdraw_guard']['op']!=='add'&&a['external_withdraw_guard']['op']!=='set')return null;for(const b of a['external_withdraw_guard']['guards']){if(b['identifier']===undefined||b['identifier']===null)return{'id':'R-T-1-04','level':'HIGH','category':'structural','title':'external_withdraw_guard.identifier\x20missing','description':'Guard\x20'+b['guard']+'\x20missing\x20required\x20identifier.\x20AmountFromWithdrawGuard.identifier\x20is\x20u8\x20(not\x20Option<u8>);\x20withdraw\x20amount\x20must\x20come\x20from\x20Guard\x20table.','affected_stakeholders':['owner','external_operator'],'scenario':'Configuring\x20external\x20withdraw\x20guard\x20without\x20amount\x20source','mitigation':'Set\x20identifier\x20to\x20the\x20Guard\x20table\x20index\x20that\x20provides\x20the\x20withdraw\x20amount\x20(must\x20be\x20a\x20number-type\x20field)','evidence':'guard='+b['guard']+',\x20identifier=undefined'};}return null;}},R_T_2_01={'id':'R-T-2-01','category':'semantic','trigger':'External\x20operation\x20(deposit/withdraw)\x20requested\x20without\x20corresponding\x20guard\x20configured','check':a=>{if(a['deposit']?.['by_external_deposit_guard']){const b=a['deposit']['by_external_deposit_guard'];if((a['current_external_deposit_guard_count']??0x0)===0x0)return{'id':'R-T-2-01','level':'MEDIUM','category':'semantic','title':'External\x20deposit\x20guard\x20list\x20is\x20empty','description':'Requesting\x20external_deposit\x20via\x20guard\x20'+b+',\x20but\x20Treasury\x20has\x20no\x20external_deposit_guard\x20configured.\x20Operation\x20will\x20abort\x20with\x20E_EXTERNAL_DEPOSIT_GUARD_NOT_FOUND.','affected_stakeholders':['external_operator','owner'],'scenario':'External\x20deposit\x20attempted\x20before\x20guard_add','mitigation':'Call\x20external_deposit_guard_add\x20(Permission\x20index\x20255)\x20first\x20to\x20register\x20guard\x20'+b,'evidence':'guard='+b+',\x20current_count=0'};}if(a['withdraw']?.['amount_by_external_withdraw_guard']){const c=a['withdraw']['amount_by_external_withdraw_guard'];if((a['current_external_withdraw_guard_count']??0x0)===0x0)return{'id':'R-T-2-01','level':'MEDIUM','category':'semantic','title':'External\x20withdraw\x20guard\x20list\x20is\x20empty','description':'Requesting\x20external_withdraw\x20via\x20guard\x20'+c+',\x20but\x20Treasury\x20has\x20no\x20external_withdraw_guard\x20configured.\x20Operation\x20will\x20abort\x20with\x20E_EXTERNAL_WITHDRAW_GUARD_NOT_FOUND.','affected_stakeholders':['external_operator','owner'],'scenario':'External\x20withdraw\x20attempted\x20before\x20guard_add','mitigation':'Call\x20external_withdraw_guard_add\x20(Permission\x20index\x20256)\x20first\x20to\x20register\x20guard\x20'+c,'evidence':'guard='+c+',\x20current_count=0'};}return null;}},R_T_2_02={'id':'R-T-2-02','category':'semantic','trigger':'External\x20operation\x20paired\x20with\x20Permission\x20path\x20(confused\x20access\x20control)','check':a=>{if(a['deposit']?.['by_external_deposit_guard']&&a['current_permission_indexes_granted']?.['includes'](0xfc))return{'id':'R-T-2-02','level':'LOW','category':'semantic','title':'Both\x20Permission\x20deposit\x20and\x20external\x20deposit\x20guard\x20configured','description':'Treasury\x20has\x20both\x20TREASURY_DEPOSIT\x20(252)\x20granted\x20and\x20external_deposit_guard\x20configured.\x20While\x20not\x20an\x20error,\x20mixing\x20access\x20paths\x20complicates\x20audit.','affected_stakeholders':['owner','admin'],'scenario':'Hybrid\x20internal+external\x20deposit\x20setup','mitigation':'Document\x20which\x20path\x20each\x20depositor\x20should\x20use;\x20consider\x20splitting\x20into\x20separate\x20Treasury\x20objects\x20for\x20clarity','evidence':'has_perm_252=true,\x20has_external_deposit_guard=true'};return null;}},R_T_2_03={'id':'R-T-2-03','category':'semantic','trigger':'external_deposit\x20amount\x20exceeds\x20guard-specified\x20value\x20(split-and-refund\x20path)','check':a=>{if(!a['deposit']?.['by_external_deposit_guard']||!a['deposit']?.['coin_balance'])return null;return{'id':'R-T-2-03','level':'LOW','category':'semantic','title':'External\x20deposit\x20may\x20trigger\x20split-and-refund','description':'If\x20coin\x20value\x20('+a['deposit']['coin_balance']+')\x20exceeds\x20guard-specified\x20amount,\x20the\x20excess\x20will\x20be\x20split\x20and\x20refunded\x20to\x20sender.\x20Verify\x20intent.','affected_stakeholders':['external_operator'],'scenario':'External\x20deposit\x20with\x20coin\x20value\x20>\x20guard\x20limit','mitigation':'Pre-split\x20the\x20coin\x20to\x20exact\x20guard-specified\x20amount,\x20or\x20accept\x20the\x20refund\x20behavior','evidence':'coin_balance='+a['deposit']['coin_balance']};}},R_T_3_01={'id':'R-T-3-01','category':'authority','trigger':'Same\x20address\x20holds\x20both\x20TREASURY_DEPOSIT\x20(252)\x20and\x20TREASURY_WITHDRAW\x20(254)','check':a=>{if(!a['current_permission_indexes_granted'])return null;const b=a['current_permission_indexes_granted']['includes'](0xfc),c=a['current_permission_indexes_granted']['includes'](0xfe);if(b&&c)return{'id':'R-T-3-01','level':'MEDIUM','category':'authority','title':'Deposit\x20and\x20withdraw\x20permissions\x20both\x20present\x20(review\x20separation)','description':'Both\x20TREASURY_DEPOSIT\x20(252)\x20and\x20TREASURY_WITHDRAW\x20(254)\x20are\x20granted.\x20Verify\x20they\x20are\x20assigned\x20to\x20different\x20entities\x20to\x20enforce\x20separation\x20of\x20duties.','affected_stakeholders':['owner','depositor','withdrawer'],'scenario':'Single\x20role\x20can\x20both\x20add\x20and\x20remove\x20funds','mitigation':'Assign\x20252\x20to\x20depositor\x20role,\x20254\x20to\x20withdrawer\x20role;\x20use\x20separate\x20Permission\x20objects\x20if\x20needed','evidence':'has_252=true,\x20has_254=true'};return null;}},R_T_3_02={'id':'R-T-3-02','category':'authority','trigger':'TREASURY_EXTERNAL_DEPOSIT_GUARD\x20(255)\x20granted\x20to\x20non-owner\x20(admin-level\x20risk)','check':a=>{if(!a['current_permission_indexes_granted']?.['includes'](0xff))return null;return{'id':'R-T-3-02','level':'MEDIUM','category':'authority','title':'External\x20deposit\x20guard\x20management\x20permission\x20granted','description':'TREASURY_EXTERNAL_DEPOSIT_GUARD\x20(255)\x20is\x20granted.\x20Managing\x20external_deposit_guard\x20list\x20controls\x20who\x20can\x20externally\x20deposit.\x20Verify\x20assignment\x20scope.','affected_stakeholders':['owner','admin'],'scenario':'Guard\x20management\x20delegated\x20to\x20operator','mitigation':'Restrict\x20255\x20to\x20owner/admin\x20only;\x20guard\x20list\x20changes\x20affect\x20external\x20access\x20policy','evidence':'has_perm_255=true'};}},R_T_3_03={'id':'R-T-3-03','category':'authority','trigger':'TREASURY_EXTERNAL_WITHDRAW_GUARD\x20(256)\x20granted\x20—\x20high-impact\x20permission','check':a=>{if(!a['current_permission_indexes_granted']?.['includes'](0x100))return null;return{'id':'R-T-3-03','level':'HIGH','category':'authority','title':'External\x20withdraw\x20guard\x20management\x20permission\x20granted','description':'TREASURY_EXTERNAL_WITHDRAW_GUARD\x20(256)\x20is\x20granted.\x20Managing\x20external_withdraw_guard\x20list\x20controls\x20who\x20can\x20externally\x20withdraw\x20(irreversible).\x20Tightly\x20restrict.','affected_stakeholders':['owner','withdrawer'],'scenario':'External\x20withdraw\x20guard\x20management\x20delegated','mitigation':'Restrict\x20256\x20to\x20owner\x20only;\x20consider\x20multi-sig\x20for\x20production\x20Treasury','evidence':'has_perm_256=true'};}},R_T_4_01={'id':'R-T-4-01','category':'lifecycle','trigger':'Internal\x20withdraw\x20(fixed\x20amount)\x20—\x20irreversible\x20fund\x20operation','check':a=>{if(!a['withdraw']?.['amount_fixed'])return null;return{'id':'R-T-4-01','level':'CRITICAL','category':'lifecycle','title':'Internal\x20withdraw\x20is\x20irreversible','description':'Fixed\x20withdraw\x20of\x20'+a['withdraw']['amount_fixed']+'\x20to\x20'+(a['withdraw']['recipient']??'recipient')+'.\x20Once\x20executed,\x20funds\x20cannot\x20be\x20recovered\x20without\x20recipient\x20cooperation.','affected_stakeholders':['owner','withdrawer'],'scenario':'Permission-authorized\x20withdraw\x20(254)','mitigation':'1)\x20Verify\x20recipient\x20address\x20twice.\x202)\x20Confirm\x20amount.\x203)\x20Check\x20balance\x20sufficiency.\x204)\x20Record\x20Payment\x20object\x20for\x20audit.','evidence':'amount='+a['withdraw']['amount_fixed']+',\x20recipient='+(a['withdraw']['recipient']??'?')};}},R_T_4_02={'id':'R-T-4-02','category':'lifecycle','trigger':'External\x20withdraw\x20(via\x20guard)\x20—\x20irreversible\x20fund\x20operation','check':a=>{if(!a['withdraw']?.['amount_by_external_withdraw_guard'])return null;return{'id':'R-T-4-02','level':'CRITICAL','category':'lifecycle','title':'External\x20withdraw\x20is\x20irreversible','description':'External\x20withdraw\x20via\x20guard\x20'+a['withdraw']['amount_by_external_withdraw_guard']+'\x20to\x20'+(a['withdraw']['recipient']??'recipient')+'.\x20Amount\x20determined\x20by\x20Guard\x20table\x20identifier;\x20verify\x20Guard\x20rules\x20before\x20execution.','affected_stakeholders':['owner','external_operator','withdrawer'],'scenario':'Guard-authorized\x20external\x20withdraw','mitigation':'1)\x20Verify\x20Guard\x20rules\x20match\x20business\x20intent.\x202)\x20Verify\x20recipient.\x203)\x20Ensure\x20Guard\x20identifier\x20points\x20to\x20correct\x20amount\x20field.\x204)\x20Test\x20on\x20testnet\x20first.','evidence':'guard='+a['withdraw']['amount_by_external_withdraw_guard']+',\x20recipient='+(a['withdraw']['recipient']??'?')};}},R_T_4_03={'id':'R-T-4-03','category':'lifecycle','trigger':'UM\x20set\x20or\x20revoked\x20—\x20object-linker\x20core\x20binding\x20change','check':a=>{if(a['um']===undefined)return null;if(a['um']===null)return{'id':'R-T-4-03','level':'LOW','category':'lifecycle','title':'UM\x20revocation','description':'Revoking\x20UM\x20disaffiliates\x20Contact\x20from\x20Treasury\x20via\x20object_linker::disaffiliation_core.\x20Existing\x20contact\x20bindings\x20become\x20orphaned.','affected_stakeholders':['owner'],'scenario':'Owner\x20revokes\x20UM\x20(um_none)','mitigation':'Verify\x20no\x20active\x20business\x20process\x20depends\x20on\x20UM\x20before\x20revoking','evidence':'um=null'};return{'id':'R-T-4-03','level':'LOW','category':'lifecycle','title':'UM\x20delegation','description':'Setting\x20UM\x20to\x20'+a['um']+'.\x20UM\x20(Contact\x20object)\x20gains\x20binding\x20with\x20Treasury\x20via\x20object_linker::affiliation_core.','affected_stakeholders':['owner'],'scenario':'Owner\x20delegates\x20UM\x20(um_set)','mitigation':'Verify\x20UM\x20address\x20is\x20a\x20valid\x20Contact\x20object\x20(not\x20a\x20user\x20wallet)','evidence':'um='+a['um']};}},R_T_5_01={'id':'R-T-5-01','category':'cross_object','trigger':'Treasury\x20shared\x20with\x20Service\x20via\x20common\x20Permission\x20—\x20verify\x20alignment','check':a=>{if(!a['shared_with_service'])return null;return{'id':'R-T-5-01','level':'MEDIUM','category':'cross_object','title':'Treasury-Service\x20Permission\x20sharing\x20—\x20verify\x20index\x20alignment','description':'Treasury\x20and\x20Service\x20share\x20a\x20Permission\x20object.\x20Ensure\x20Treasury\x20indexes\x20(250-258)\x20and\x20Service\x20indexes\x20(300-320)\x20are\x20assigned\x20to\x20intended\x20entities;\x20cross-object\x20admin\x20changes\x20affect\x20both.','affected_stakeholders':['owner','admin'],'scenario':'Single\x20Permission\x20for\x20both\x20Treasury\x20and\x20Service','mitigation':'Document\x20which\x20entities\x20hold\x20which\x20indexes\x20across\x20both\x20objects;\x20review\x20admin\x20list\x20changes\x20for\x20cross-impact','evidence':'shared_with_service=true'};}},R_T_5_02={'id':'R-T-5-02','category':'cross_object','trigger':'Treasury\x20referenced\x20by\x20Allocator/Arbitration\x20—\x20receive\x20(253)\x20must\x20be\x20granted','check':a=>{if(!a['shared_with_allocator']&&!a['shared_with_arbitration'])return null;const b=a['current_permission_indexes_granted']?.['includes'](0xfd);if(!b)return{'id':'R-T-5-02','level':'HIGH','category':'cross_object','title':'Treasury\x20referenced\x20by\x20Allocator/Arbitration\x20but\x20TREASURY_RECEIVE\x20(253)\x20not\x20granted','description':'Allocator/Arbitration\x20will\x20send\x20CoinWrapper/Payment\x20to\x20Treasury,\x20but\x20no\x20entity\x20has\x20TREASURY_RECEIVE\x20(253)\x20to\x20call\x20treasury::receive\x20and\x20convert\x20to\x20balance.\x20Funds\x20will\x20accumulate\x20as\x20received\x20objects\x20without\x20entering\x20balance.','affected_stakeholders':['owner','system'],'scenario':'Revenue\x20collection\x20setup\x20without\x20receive\x20permission','mitigation':'Grant\x20TREASURY_RECEIVE\x20(253)\x20to\x20a\x20trusted\x20operator\x20(or\x20owner)\x20who\x20will\x20regularly\x20call\x20receive\x20to\x20convert\x20CoinWrapper\x20to\x20balance','evidence':'shared_allocator='+a['shared_with_allocator']+',\x20shared_arbitration='+a['shared_with_arbitration']+',\x20has_253=false'};return null;}},R_T_0_01={'id':'R-T-0-01','category':'structural','trigger':'Permission\x20index\x20in\x20259-260\x20range\x20detected\x20(regression\x20check\x20for\x20R-T-01)','check':a=>{if(!a['current_permission_indexes_granted'])return null;const b=a['current_permission_indexes_granted']['filter'](c=>c===0x103||c===0x104);if(b['length']>0x0)return{'id':'R-T-0-01','level':'CRITICAL','category':'structural','title':'Stale\x20Treasury\x20permission\x20index\x20259/260\x20detected\x20(R-T-01\x20regression)','description':'Permission\x20indexes\x20259/260\x20are\x20no\x20longer\x20valid\x20Treasury\x20indexes\x20(SDK\x20fixed\x20to\x20use\x20255-258\x20matching\x20Move).\x20Found:\x20'+b['join'](',\x20'),'affected_stakeholders':['owner','admin','system'],'scenario':'SDK\x20regression\x20reintroducing\x20off-by-2\x20divergence','mitigation':'Use\x20canonical\x20indexes:\x20255=EXTERNAL_DEPOSIT_GUARD,\x20256=EXTERNAL_WITHDRAW_GUARD,\x20257=OWNER_RECEIVE,\x20258=UM','evidence':'stale_indexes='+b['join'](',')};return null;}},ALL_RULES=[R_T_1_01,R_T_1_02,R_T_1_03,R_T_1_04,R_T_2_01,R_T_2_02,R_T_2_03,R_T_3_01,R_T_3_02,R_T_3_03,R_T_4_01,R_T_4_02,R_T_4_03,R_T_5_01,R_T_5_02,R_T_0_01];export const TREASURY_RISK_VERSION='1.0.0';export function getAllTreasuryRiskRules(){return[...ALL_RULES];}export function getTreasuryRiskRulesCount(){return ALL_RULES['length'];}export function getTreasuryRiskRulesByCategory(a){return ALL_RULES['filter'](b=>b['category']===a);}export function assessTreasuryRisks(a){const b=[];for(const f of ALL_RULES){const g=f['check'](a);if(g)b['push'](g);}const c=b['length']===0x0?'LOW':b['some'](h=>h['level']==='CRITICAL')?'CRITICAL':b['some'](h=>h['level']==='HIGH')?'HIGH':b['some'](h=>h['level']==='MEDIUM')?'MEDIUM':'LOW',d={};for(const h of b){d[h['category']]=(d[h['category']]??0x0)+0x1;}const e={};for(const i of b){for(const j of i['affected_stakeholders']){if(!e[j])e[j]=[];e[j]['push'](i['id']+':\x20'+i['mitigation']);}}return{'summary':'Assessed\x20'+b['length']+'\x20risk(s)\x20across\x20'+Object['keys'](d)['length']+'\x20categories','risks':b,'overall_risk':c,'risks_by_category':d,'stakeholder_advice':e,'needs_human_review':b['some'](k=>k['level']==='CRITICAL'||k['level']==='HIGH')};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const UTIL_CONFIRM_VERSION='1.0.0';function checkTypo(a){const b=!!a['uses_typo_function_name'];return{'id':'C-UTIL-01','severity':b?'info':'info','title':'Typo\x27d\x20function\x20name\x20is\x20handled\x20(is_chiild_object_address_byte)','description':'util.move\x20defines\x20is_chiild_object_address_byte\x20with\x20a\x20\x27chiild\x27\x20typo;\x20it\x20cannot\x20be\x20renamed\x20post-publish.\x20The\x20SDK\x20should\x20expose\x20a\x20correct\x20alias.','passed':!![],'evidence':b?'uses_typo_function_name=true\x20(must\x20use\x20\x27chiild\x27)':'typo\x20handled\x20via\x20alias'};}function checkAddressBytes(a){const b=!!a['assumes_stable_address_bytes'];return{'id':'C-UTIL-02','severity':b?'warn':'info','title':'Address-byte\x20thresholds\x20are\x20hardcoded','description':'util.move\x20classifies\x20addresses\x20by\x20first\x20byte\x20(user\
|
|
1
|
+
export const UTIL_CONFIRM_VERSION='1.0.0';function checkTypo(a){const b=!!a['uses_typo_function_name'];return{'id':'C-UTIL-01','severity':b?'info':'info','title':'Typo\x27d\x20function\x20name\x20is\x20handled\x20(is_chiild_object_address_byte)','description':'util.move\x20defines\x20is_chiild_object_address_byte\x20with\x20a\x20\x27chiild\x27\x20typo;\x20it\x20cannot\x20be\x20renamed\x20post-publish.\x20The\x20SDK\x20should\x20expose\x20a\x20correct\x20alias.','passed':!![],'evidence':b?'uses_typo_function_name=true\x20(must\x20use\x20\x27chiild\x27)':'typo\x20handled\x20via\x20alias'};}function checkAddressBytes(a){const b=!!a['assumes_stable_address_bytes'];return{'id':'C-UTIL-02','severity':b?'warn':'info','title':'Address-byte\x20thresholds\x20are\x20hardcoded','description':'util.move\x20classifies\x20addresses\x20by\x20first\x20byte\x20(user\x200x00,\x20object\x200xf1\x20or\x200x10..0x24,\x20child\x20unified\x20with\x20object).\x20A\x20Wow\x20protocol\x20upgrade\x20could\x20invalidate\x20them.','passed':!b,'evidence':b?'assumes_stable_address_bytes=true':'upgrade\x20coupling\x20understood','fix_hint':'Track\x20Wow\x20address-layout\x20upgrades;\x20ship\x20util.move\x20+\x20SDK\x20in\x20lockstep.'};}function checkBcs(a){const b=a['bcs_manually_synced']===!![];return{'id':'C-UTIL-03','severity':b?'warn':'info','title':'SDK\x20BCS\x20structures\x20stay\x20in\x20sync\x20with\x20Move\x20structs','description':'util.ts\x20defines\x20BCS\x20query\x20structures\x20that\x20must\x20match\x20Move\x20layouts\x20byte-for-byte;\x20drift\x20breaks\x20queries\x20silently.','passed':!b,'evidence':b?'bcs_manually_synced=true\x20(drift\x20risk)':'BCS\x20sync\x20safe','fix_hint':'Generate\x20BCS\x20from\x20Move\x20via\x20codegen,\x20or\x20run\x20a\x20layout\x20sync\x20test.'};}export function preCheckUtilCall(a){return[checkTypo(a),checkAddressBytes(a),checkBcs(a)];}export function canProceedUtilCall(a){const b=preCheckUtilCall(a);return{'canProceed':b['every'](c=>c['severity']!=='block'||c['passed']),'blockers':b['filter'](c=>c['severity']==='block'&&!c['passed']),'warnings':b['filter'](c=>c['severity']==='warn'&&!c['passed']),'info':b['filter'](c=>c['severity']==='info')};}export function formatUtilCallSummary(a){const {canProceed:b,warnings:c}=canProceedUtilCall(a),d=[b?'✓\x20Util\x20call\x20pre-check\x20PASSED':'✗\x20Util\x20call\x20pre-check\x20FAILED',''];return c['length']>0x0&&(d['push']('WARNINGS:'),c['forEach'](e=>d['push']('\x20\x20['+e['id']+']\x20'+e['title']+'\x20—\x20'+(e['evidence']??'')))),d['join']('\x0a');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const USER_ADDRESS_BYTE=0x0,OBJECT_ADDRESS_BYTE=0xf1,TYPED_OBJECT_BYTE_MIN=0x10,TYPED_OBJECT_BYTE_MAX=0x24,R_U_01={'rule':{'id':'R-UTIL-01','level':'LOW','category':'semantic','title':'is_chiild_object_address_byte\x20has\x20a\x20typo\x20(\x27chiild\x27)\x20—\x20cannot\x20be\x20renamed\x20post-publish','description':'util.move:30\x20defines\x20is_chiild_object_address_byte\x20(note\x20the\x20\x27chiild\x27\x20typo).\x20The\x20'+'function\x20is\x20already\x20published\x20on\x20mainnet,\x20so\x20the\x20name\x20cannot\x20be\x20fixed\x20without\x20a\x20'+'breaking\x20package\x20upgrade.\x20Callers\x20must\x20use\x20the\x20misspelled\x20name\x20exactly;\x20SDK\x20wrappers\x20'+'should\x20expose\x20a\x20correctly-spelled\x20alias\x20and\x20route\x20to\x20the\x20typo\x20function.','affected_stakeholders':['caller'],'scenario':'Caller\x20writes\x20is_child_object_address_byte;\x20Move\x20linker\x20cannot\x20resolve\x20the\x20symbol','mitigation':'SDK\x20should\x20expose\x20isChildObjectAddressByte\x20as\x20the\x20public\x20API\x20and\x20internally\x20call\x20the\x20'+'typo\x27d\x20Move\x20function.\x20Document\x20the\x20typo\x20so\x20future\x20maintainers\x20don\x27t\x20\x27fix\x27\x20it.','auto_fixable':![]},'check':a=>{if(!a['uses_typo_function_name'])return null;return{...R_U_01['rule'],'evidence':'uses_typo_function_name=true\x20(must\x20use\x20\x27chiild\x27)'};}},R_U_02={'rule':{'id':'R-UTIL-02','level':'MEDIUM','category':'semantic','title':'Address-byte\x20thresholds\x20are\x20hardcoded\x20—\x20Wow\x20protocol\x20upgrades\x20could\x20invalidate\x20them','description':'util.move\x20classifies\x20addresses\x20by\x20first\x20byte:\x20user\x20('+USER_ADDRESS_BYTE+'),\x20'+('object\x20('+OBJECT_ADDRESS_BYTE+'\x20for\x20regular/child,\x20or\x20'+TYPED_OBJECT_BYTE_MIN+'..'+TYPED_OBJECT_BYTE_MAX+'\x20for\x20typed\x20business\x20objects).\x20')+'These\x20thresholds\x20are\x20hardcoded\x20as\x20Move\x20constants,\x20not\x20configurable.\x20If\x20a\x20future\x20Wow\x20'+'protocol\x20upgrade\x20changes\x20the\x20address\x20byte\x20layout\x20(e.g.\x20reserves\x20a\x20new\x20prefix),\x20Util\x20'+'would\x20silently\x20misclassify\x20addresses\x20until\x20the\x20Move\x20code\x20is\x20upgraded.','affected_stakeholders':['caller','system'],'scenario':'Wow\x20protocol\x20upgrade\x20introduces\x20a\x20new\x20address\x20prefix;\x20Util\x20misclassifies\x20it\x20as\x20user','mitigation':'Track\x20Wow\x20protocol\x20upgrades\x20that\x20touch\x20address\x20layout.\x20When\x20a\x20change\x20ships,\x20upgrade\x20'+'util.move\x20and\x20the\x20SDK\x20in\x20lockstep.\x20Add\x20a\x20sync\x20test\x20that\x20asserts\x20the\x20byte\x20values.','auto_fixable':![]},'check':a=>{if(!a['assumes_stable_address_bytes'])return null;return{...R_U_02['rule'],'evidence':'assumes_stable_address_bytes=true\x20(hardcoded\x20'+USER_ADDRESS_BYTE+'/'+OBJECT_ADDRESS_BYTE+'/'+TYPED_OBJECT_BYTE_MIN+'..'+TYPED_OBJECT_BYTE_MAX+')'};}},R_U_03={'rule':{'id':'R-UTIL-03','level':'LOW','category':'structural','title':'util.ts\x20is\x20~50KB\x20—\x20over-concentrated,\x20hard\x20to\x20navigate','description':'The\x20SDK\x20util.ts\x20is\x20~50428\x20bytes,\x20mixing\x20BCS\x20structure\x20definitions,\x20query\x20condition\x20'+'builders,\x20Guard\x20query\x20helpers,\x20and\x20address\x20utilities.\x20The\x20size\x20makes\x20it\x20hard\x20to\x20'+'navigate\x20and\x20increases\x20the\x20risk\x20of\x20accidental\x20circular\x20imports.\x20New\x20contributors\x20'+'often\x20import\x20the\x20wrong\x20symbol\x20because\x20so\x20many\x20are\x20exported\x20from\x20one\x20file.','affected_stakeholders':['caller','system'],'scenario':'Developer\x20imports\x20ProgressHistoryFindConditionsBCS\x20and\x20accidentally\x20pulls\x20in\x20unrelated\x20code','mitigation':'Consider\x20splitting\x20util.ts\x20into\x20focused\x20sub-modules\x20(bcs.ts,\x20query.ts,\x20address.ts).\x20'+'Until\x20then,\x20prefer\x20named\x20imports\x20over\x20namespace\x20imports\x20to\x20keep\x20bundles\x20lean.','auto_fixable':![]},'check':a=>{if(!a['large_util_import'])return null;return{...R_U_03['rule'],'evidence':'large_util_import=true\x20(consider\x20sub-modules)'};}},R_U_04={'rule':{'id':'R-UTIL-04','level':'LOW','category':'lifecycle','title':'Util\x20emits\x20no\x20events\x20—\x20tool-call\x20observability\x20is\x20caller\x27s\x20responsibility','description':'Util\x20functions\x20are\x20pure:\x20they\x20neither\x20emit\x20nor\x20consume\x20events.\x20Callers\x20cannot\x20rely\x20on\x20'+'an\x20event\x20stream\x20to\x20trace\x20Util\x20invocations.\x20For\x20audit\x20and\x20debugging,\x20the\x20calling\x20'+'module\x20must\x20record\x20its\x20own\x20log\x20entries\x20around\x20Util\x20calls.','affected_stakeholders':['caller'],'scenario':'Auditor\x20expects\x20Util-call\x20events;\x20none\x20exist,\x20the\x20call\x20chain\x20is\x20invisible','mitigation':'Callers\x20should\x20emit\x20their\x20own\x20events\x20or\x20write\x20logs\x20around\x20Util\x20calls\x20when\x20auditability\x20'+'is\x20required.\x20Treat\x20Util\x20as\x20an\x20opaque\x20library\x20function.','auto_fixable':![]},'check':a=>{if(!a['expects_util_events'])return null;return{...R_U_04['rule'],'evidence':'expects_util_events=true\x20(none\x20emitted)'};}},R_U_05={'rule':{'id':'R-UTIL-05','level':'MEDIUM','category':'cross_object','title':'SDK\x20BCS\x20structures\x20must\x20stay\x20in\x20sync\x20with\x20Move\x20structs\x20—\x20drift\x20breaks\x20queries','description':'util.ts\x20defines\x20BCS\x20structures\x20for\x20Progress\x20History\x20/\x20Session\x20/\x20Forward\x20/\x20Record\x20'+'query\x20conditions.\x20These\x20must\x20match\x20the\x20Move\x20struct\x20layouts\x20byte-for-byte.\x20If\x20a\x20Move\x20'+'struct\x20adds\x20a\x20field\x20and\x20the\x20SDK\x20BCS\x20is\x20not\x20regenerated,\x20query\x20submissions\x20will\x20'+'deserialize\x20incorrectly\x20on-chain,\x20producing\x20silent\x20failures\x20or\x20aborts.','affected_stakeholders':['caller','system'],'scenario':'Progress\x20struct\x20adds\x20a\x20field;\x20SDK\x20BCS\x20is\x20stale;\x20queries\x20return\x20wrong\x20results','mitigation':'Generate\x20BCS\x20structures\x20from\x20Move\x20source\x20via\x20codegen,\x20or\x20run\x20a\x20sync\x20test\x20that\x20'+'compares\x20SDK\x20BCS\x20layouts\x20against\x20Move\x20structs\x20on\x20every\x20release.','auto_fixable':![]},'check':a=>{if(a['bcs_manually_synced']===undefined)return null;if(!a['bcs_manually_synced'])return null;return{...R_U_05['rule'],'evidence':'bcs_manually_synced=true\x20(drift\x20risk)'};}};export const UTIL_RISK_RULES=[R_U_01,R_U_02,R_U_03,R_U_04,R_U_05];export const UTIL_RISK_VERSION='1.0.0';export function checkUtilRisks(a){const b=[];for(const c of UTIL_RISK_RULES){const d=c['check'](a);if(d)b['push'](d);}return b;}export function getUtilRiskById(a){return UTIL_RISK_RULES['find'](b=>b['rule']['id']===a)?.['rule'];}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare const UTIL_TRANSLATION_VERSION = "1.0.0";
|
|
2
2
|
export declare const UTIL_ADDRESS_BYTES: {
|
|
3
|
-
readonly
|
|
3
|
+
readonly USER: 0;
|
|
4
4
|
readonly OBJECT: 241;
|
|
5
|
-
readonly
|
|
5
|
+
readonly TYPED_OBJECT_MIN: 16;
|
|
6
|
+
readonly TYPED_OBJECT_MAX: 36;
|
|
6
7
|
};
|
|
7
8
|
export interface SemanticToUtilSchemaRule {
|
|
8
9
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const UTIL_TRANSLATION_VERSION='1.0.0';export const UTIL_ADDRESS_BYTES={'
|
|
1
|
+
export const UTIL_TRANSLATION_VERSION='1.0.0';export const UTIL_ADDRESS_BYTES={'USER':0x0,'OBJECT':0xf1,'TYPED_OBJECT_MIN':0x10,'TYPED_OBJECT_MAX':0x24};export const SEMANTIC_TO_UTIL_SCHEMA_RULES=[{'id':'P-UTIL-01','pattern_name':'Classify\x20address','semantic_intent':'Determine\x20whether\x20an\x20address\x20is\x20a\x20user,\x20object,\x20or\x20child-object.','match_keywords':['is\x20user\x20address','is\x20object\x20address','classify\x20address'],'example':{'addr':'0x...'}}];export const UTIL_FIELD_TRANSLATIONS=[{'field_name':'first_byte','value_type':'u8','semantic':'Address\x20classification\x20byte:\x20user\x200x00,\x20object\x200xf1\x20(regular/child)\x20or\x200x10..0x24\x20(typed\x20business).','format_example':'0xf1\x20(object)','validation_rules':['hardcoded\x20in\x20util.move']}];export const UTIL_CONSTRAINT_RULES=[{'id':'UTIL_C_01','name':'typo\x20function','description':'is_chiild_object_address_byte\x20has\x20a\x20\x27chiild\x27\x20typo;\x20cannot\x20rename\x20post-publish.','related_field':'first_byte'},{'id':'UTIL_C_02','name':'address-byte\x20stability','description':'byte\x20thresholds\x20are\x20hardcoded;\x20Wow\x20upgrade\x20could\x20invalidate\x20them.','related_field':'first_byte'},{'id':'UTIL_C_03','name':'BCS\x20sync','description':'SDK\x20BCS\x20structures\x20must\x20match\x20Move\x20layouts\x20byte-for-byte.','related_field':'first_byte'}];export function explainUtil(a){const b=[];let c='unknown';if(a['first_byte']!==undefined){if(a['first_byte']===UTIL_ADDRESS_BYTES['USER'])c='user\x20address';else{if(a['first_byte']===UTIL_ADDRESS_BYTES['OBJECT'])c='object\x20address\x20(regular/child)';else{if(a['first_byte']>=UTIL_ADDRESS_BYTES['TYPED_OBJECT_MIN']&&a['first_byte']<=UTIL_ADDRESS_BYTES['TYPED_OBJECT_MAX'])c='typed\x20business\x20object\x20address';else b['push']('first\x20byte\x200x'+a['first_byte']['toString'](0x10)+'\x20not\x20in\x20known\x20classification\x20range');}}}return{'summary':'Util\x20address\x20classification:\x20'+c+'.','classification':c,'warnings':b};}
|
|
@@ -21,7 +21,14 @@ export interface GuidanceInput {
|
|
|
21
21
|
current: string;
|
|
22
22
|
nodes: ParsedMachineNode[];
|
|
23
23
|
caller?: string;
|
|
24
|
+
callerAddress?: string;
|
|
24
25
|
orderHolderAddresses?: string[];
|
|
26
|
+
progressNamedOperator?: {
|
|
27
|
+
name: string;
|
|
28
|
+
operators: string[];
|
|
29
|
+
}[];
|
|
30
|
+
permissionContext?: PermissionContext;
|
|
31
|
+
orderContext?: OrderContext;
|
|
25
32
|
permissionDescription?: string;
|
|
26
33
|
nameResolver?: NameResolver;
|
|
27
34
|
}
|
|
@@ -114,3 +121,60 @@ export declare function mergeGuidanceIntoOutput<T extends {
|
|
|
114
121
|
content: any[];
|
|
115
122
|
structuredContent: any;
|
|
116
123
|
}>(output: T, enrichment: EnrichResult | undefined): T;
|
|
124
|
+
export interface LocalAccountInfo {
|
|
125
|
+
address: string;
|
|
126
|
+
name?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface PermissionContext {
|
|
129
|
+
admin: Set<string>;
|
|
130
|
+
table: Map<string, Set<number>>;
|
|
131
|
+
}
|
|
132
|
+
export interface OrderContext {
|
|
133
|
+
builder: string;
|
|
134
|
+
agent: Set<string>;
|
|
135
|
+
}
|
|
136
|
+
export declare const ENTITY_PERMISSION_OBJECT_ID = "0xaad";
|
|
137
|
+
export declare const ENTITY_PERMISSION_ROLES: {
|
|
138
|
+
readonly OWNER: 1;
|
|
139
|
+
readonly ADMIN: 2;
|
|
140
|
+
readonly ENTITY: 4;
|
|
141
|
+
};
|
|
142
|
+
export interface EntityPermissionItem {
|
|
143
|
+
role: number;
|
|
144
|
+
permission: string;
|
|
145
|
+
time: number;
|
|
146
|
+
}
|
|
147
|
+
export interface EntityPermissionContext {
|
|
148
|
+
items: EntityPermissionItem[];
|
|
149
|
+
byPermission: Map<string, number>;
|
|
150
|
+
}
|
|
151
|
+
export declare function fetchEntityPermission(entityAddr: string, network?: string, noCache?: boolean): Promise<EntityPermissionContext | undefined>;
|
|
152
|
+
export declare const ENTITY_CONTACT_OBJECT_ID = "0xaa9";
|
|
153
|
+
export interface EntityContactItem {
|
|
154
|
+
contact: string;
|
|
155
|
+
time: number;
|
|
156
|
+
}
|
|
157
|
+
export interface EntityContactContext {
|
|
158
|
+
items: EntityContactItem[];
|
|
159
|
+
byContact: Map<string, number>;
|
|
160
|
+
}
|
|
161
|
+
export declare function fetchEntityContact(entityAddr: string, network?: string, noCache?: boolean): Promise<EntityContactContext | undefined>;
|
|
162
|
+
export declare const OBJECT_LINKER_CORE_OBJECT_ID = "0xaae";
|
|
163
|
+
export declare const OBJECT_LINKER_TX_OBJECT_ID = "0xaaf";
|
|
164
|
+
export interface ObjectLinkerItem {
|
|
165
|
+
who: string;
|
|
166
|
+
time: number;
|
|
167
|
+
}
|
|
168
|
+
export interface ObjectLinkerContext {
|
|
169
|
+
items: ObjectLinkerItem[];
|
|
170
|
+
byWho: Map<string, number>;
|
|
171
|
+
}
|
|
172
|
+
export declare function fetchObjectLinkerCore(targetAddr: string, network?: string, noCache?: boolean): Promise<ObjectLinkerContext | undefined>;
|
|
173
|
+
export declare function fetchObjectLinkerTx(targetAddr: string, network?: string, noCache?: boolean): Promise<ObjectLinkerContext | undefined>;
|
|
174
|
+
export declare function fetchPermissionContext(permAddr: string, network?: string, noCache?: boolean): Promise<PermissionContext | undefined>;
|
|
175
|
+
export declare function fetchOrderContext(orderAddr: string, network?: string, noCache?: boolean): Promise<OrderContext | undefined>;
|
|
176
|
+
export declare function listLocalAccounts(): Promise<LocalAccountInfo[]>;
|
|
177
|
+
export declare function accountCanExecuteForward(f: ParsedForward, account: string, progressNamedOperator: {
|
|
178
|
+
name: string;
|
|
179
|
+
operators: string[];
|
|
180
|
+
}[], orderCtx: OrderContext | undefined, permCtx: PermissionContext | undefined): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{query_objects,query_table,LocalMark,GetLocalNamesByAddresses}from'@wowok/wowok';import{REPOSITORY_PERMISSIONS,REWARD_PERMISSIONS,MACHINE_PERMISSIONS,PROGRESS_PERMISSIONS,TREASURY_PERMISSIONS,SERVICE_PERMISSIONS,ARBITRATION_PERMISSIONS,DEMAND_PERMISSIONS,CONTACT_PERMISSIONS}from'./permission-ledger.js';const BUILTIN_PERMISSION_MAP=new Map();for(const entry of[...REPOSITORY_PERMISSIONS,...REWARD_PERMISSIONS,...MACHINE_PERMISSIONS,...PROGRESS_PERMISSIONS,...TREASURY_PERMISSIONS,...SERVICE_PERMISSIONS,...ARBITRATION_PERMISSIONS,...DEMAND_PERMISSIONS,...CONTACT_PERMISSIONS]){BUILTIN_PERMISSION_MAP['set'](entry['index'],entry['name']);}export function resolvePermissionRole(a,b){if(a===undefined||a===null)return'unknown\x20role';if(b){const d=/([A-Za-z][A-Za-z0-9_]*)\s*=\s*(\d+)/g;let e;while((e=d['exec'](b))!==null){if(Number(e[0x2])===a)return e[0x1]+'\x20(permission\x20'+a+')';}}const c=BUILTIN_PERMISSION_MAP['get'](a);if(c)return c+'\x20(permission\x20'+a+')';return'permission\x20'+a;}export async function fetchMachineNodes(a,b,c){const d=await query_objects({'objects':[a],'no_cache':c,'network':b}),e=d?.['objects']?.[0x0],f=e?.['object']??(typeof a==='string'&&a['startsWith']('0x')?a:undefined);if(!f)return[];const g=await query_table({'parent':f,'no_cache':c,'network':b}),h=(g?.['items']??[])['map'](j=>j?.['object'])['filter'](j=>typeof j==='string');if(h['length']===0x0)return[];const i=await query_objects({'objects':h,'no_cache':c,'network':b});return(i?.['objects']??[])['filter'](j=>j?.['type']==='TableItem_MachineNode')['map'](j=>{const k=j?.['data']??j,l=typeof k?.['name']==='string'?k['name']:'',m=Array['isArray'](k?.['value'])?k['value']:Array['isArray'](k?.['pairs'])?k['pairs']:[];if(!l)return null;return{'name':l,'pairs':m['map'](n=>({'prev_node':String(n?.['prev_node']??''),'threshold':Number(n?.['threshold']??0x0),'forwards':Array['isArray'](n?.['forwards'])?n['forwards']['map'](q=>{const r=typeof q?.['guard']==='object'&&q?.['guard']!==null?q['guard']['guard']??undefined:typeof q?.['guard']==='string'?q['guard']:undefined;return{'name':String(q?.['name']??''),'weight':Number(q?.['weight']??0x0),'namedOperator':q?.['namedOperator']!==undefined&&q?.['namedOperator']!==null?String(q['namedOperator']):undefined,'permissionIndex':q?.['permissionIndex']!==undefined&&q?.['permissionIndex']!==null?Number(q['permissionIndex']):undefined,'guard':r};}):[]}))};})['filter'](j=>j!==null);}const COMPLETE_RE=/(^|_)(completed?|done|finished|received|delivered|accepted|confirmed|finalized|success|approved)(_|$)/i,REFUND_RE=/(^|_)(cancel(led)?|refund(ed)?|return(ed|_approved)?)(_|$)/i,EXCEPTION_RE=/(^|_)(interrupt(ed)?|exception|dispute(d)?|fail(ed)?|abort(ed)?|reject(ed)?)(_|$)/i;function classifyNode(a){if(COMPLETE_RE['test'](a))return'complete';if(REFUND_RE['test'](a))return'refund';if(EXCEPTION_RE['test'](a))return'exception';return'advance';}function businessMeaning(a,b){switch(b){case'complete':return'Service/deliverable\x20accepted\x20at\x20\x22'+a+'\x22\x20—\x20triggers\x20settlement\x20allocation\x20(funds\x20released\x20to\x20the\x20provider)';case'refund':return'Order\x20cancelled/returned\x20at\x20\x22'+a+'\x22\x20—\x20triggers\x20refund\x20allocation\x20(funds\x20back\x20to\x20the\x20customer)';case'exception':return'Exception\x20path\x20at\x20\x22'+a+'\x22\x20—\x20typically\x20routes\x20to\x20arbitration\x20or\x20partial-refund\x20handling';default:return'Progress\x20to\x20\x22'+a+'\x22';}}function shortAddr(a){if(!a)return undefined;if(a['length']>0xe)return a['slice'](0x0,0x8)+'...'+a['slice'](-0x4);return a;}function callerIsOrderHolder(a,b){if(!a||!b?.['length'])return![];const d=a['toLowerCase']();return b['some'](e=>e?.['toLowerCase']()===d);}function resolveOperator(a,b,c,d){if(a['namedOperator']===''){const e=b?.[0x0];return{'kind':'order_holder','role_name':'order\x20holder\x20(customer)','account_name':d?d(e):shortAddr(e)};}if(typeof a['namedOperator']==='string'&&a['namedOperator']['length']>0x0)return{'kind':'named_operator','named_operator':a['namedOperator'],'role_name':'named\x20operator\x20\x22'+a['namedOperator']+'\x22'};if(a['permissionIndex']!==undefined&&a['permissionIndex']!==null)return{'kind':'permission_index','permission_index':a['permissionIndex'],'role_name':resolvePermissionRole(a['permissionIndex'],c)};return{'kind':'order_holder','role_name':'unknown\x20operator'};}function gainsRisksFor(a,b,c){if(!c)return{'gains':[],'risks':[]};if(b)switch(a){case'complete':return{'gains':['Flow\x20advances','Settlement\x20triggered\x20(funds\x20released)'],'risks':['Funds\x20released\x20to\x20provider','Refund\x20leverage\x20lost\x20—\x20confirm\x20only\x20if\x20service\x20verified']};case'refund':return{'gains':['Funds\x20returned\x20to\x20you'],'risks':['If\x20service\x20was\x20already\x20rendered,\x20cancellation\x20may\x20be\x20disputed']};case'exception':return{'gains':['Avoids\x20stalemate'],'risks':['May\x20trigger\x20arbitration\x20/\x20reputation\x20impact']};default:return{'gains':['Flow\x20advances'],'risks':[]};}switch(a){case'complete':return{'gains':['Settlement\x20triggered\x20—\x20funds\x20released\x20to\x20provider'],'risks':[]};case'refund':return{'gains':['Clean\x20closure'],'risks':['Lost\x20revenue\x20for\x20this\x20order']};case'exception':return{'gains':['Avoids\x20stalemate'],'risks':['May\x20trigger\x20arbitration\x20/\x20compensation\x20fund']};default:return{'gains':['Flow\x20advances'],'risks':[]};}}function consistencyFor(a,b,c,d,e){let f;if(!e)f=a==='exception'?0x2d:0x32;else b?f=a==='refund'?0x46:a==='complete'?0x37:a==='exception'?0x23:0x32:f=a==='complete'?0x4b:a==='refund'?0x1e:a==='exception'?0x23:0x32;if(e&&c)f+=0x14;if(d)f-=0xa;return Math['max'](0x0,Math['min'](0x64,f));}export function buildWorkflowGuidance(a){const b=[];for(const i of a['nodes']){for(const j of i['pairs']){if(j['prev_node']!==a['current'])continue;for(const k of j['forwards']){if(!k['name'])continue;const l=resolveOperator(k,a['orderHolderAddresses'],a['permissionDescription'],a['nameResolver']),m=callerIsOrderHolder(a['caller'],a['orderHolderAddresses']);let n=![];if(l['kind']==='order_holder'&&a['caller']){const u=a['caller']['toLowerCase']();n=!!a['orderHolderAddresses']?.['some'](v=>v?.['toLowerCase']()===u)||u===(l['account_name']??'')['toLowerCase']();}else{if(l['kind']==='named_operator')n=!![];else l['kind']==='permission_index'&&(n=!![]);}const p=classifyNode(i['name']),q=!!a['caller'],{gains:r,risks:s}=gainsRisksFor(p,m,q),t=consistencyFor(p,m,n,!!k['guard'],q);b['push']({'next_node':i['name'],'forward':k['name'],'weight':k['weight'],'operator':l,'guard':k['guard'],'business_meaning':businessMeaning(i['name'],p),'gains':r,'risks':s,'consistency':t,'recommended':![]});}}}if(b['length']===0x0)return{'current_node':a['current'],'caller':a['caller'],'options':[],'note':'Node\x20\x22'+a['current']+'\x22\x20has\x20no\x20outgoing\x20forwards\x20—\x20it\x20is\x20a\x20terminal\x20node\x20(or\x20the\x20workflow\x20is\x20stuck).\x20No\x20further\x20progress\x20operation\x20is\x20available\x20here.'};b['sort']((v,w)=>w['consistency']-v['consistency']);const c=b[0x0];b[0x0]={...c,'recommended':!![]};const d=[];for(const v of b){v!==c&&v['consistency']>0x0&&v['forward']!==c['forward']&&d['push']('Choosing\x20\x22'+v['forward']+'\x20→\x20'+v['next_node']+'\x22\x20forfeits\x20the\x20faster/more\x20aligned\x20path\x20\x22'+c['forward']+'\x20→\x20'+c['next_node']+'\x22');}const e=[],g=b['filter'](w=>w['operator']['kind']==='order_holder'&&w['forward']!==c['forward']&&c['forward']!==w['forward']),h=b['filter'](w=>w['operator']['account_name']&&w['operator']['account_name']!==a['caller']);return h['length']>0x0&&!b['some'](w=>w['recommended']&&w['operator']['account_name']===a['caller'])&&e['push']('The\x20recommended\x20action\x20is\x20executed\x20by\x20another\x20account\x20('+h[0x0]['operator']['account_name']+');\x20switch\x20the\x20signing\x20account\x20(env.account)\x20before\x20operating.'),{'current_node':a['current'],'caller':a['caller'],'options':b,'recommendation':{'best':c['forward']+'\x20→\x20'+c['next_node'],'rationale':'Highest\x20consistency\x20('+c['consistency']+'/100)\x20with\x20the\x20caller\x27s\x20interests.\x20Gains:\x20'+(c['gains']['join'](';\x20')||'none')+'.\x20Risks:\x20'+(c['risks']['join'](';\x20')||'none')+'.\x20Operator:\x20'+(c['operator']['role_name']??c['operator']['kind'])+(c['operator']['account_name']?'\x20('+c['operator']['account_name']+')':'')+'.'+(c['guard']?'\x20Guard\x20to\x20satisfy:\x20'+c['guard']+'.':''),'caveat':d['length']?d['join']('.\x20'):undefined},'note':e['length']?e['join']('\x20'):undefined};}export function buildWorkflowReceipt(a){const b=a['current']===a['targetNode'],c={'account':a['callerName'],'action':a['callerName']+'\x20executed\x20'+a['forward']+'\x20(→\x20'+a['targetNode']+')','forward':a['forward'],'target_node':a['targetNode'],'op':a['op'],'migrated':b,'current_node':a['current']};if(!b){const e=a['nodes']['filter'](j=>j['name']===a['targetNode'])['flatMap'](j=>j['pairs'])['find'](j=>j['prev_node']===a['current']),g=a['session']?.['slice'](-0x1)[0x0],h=g?.['threshold']??e?.['threshold']??0x0,i=g?.['weights']??0x0;if(h>0x0){c['threshold']=h,c['accumulated_weight']=i,c['remaining']=Math['max'](0x0,h-i);const j=new Set((g?.['forwards']??[])['filter'](l=>l?.['accomplished']!==![])['map'](l=>l?.['forward'])['filter'](l=>!!l)),k=[];for(const l of e?.['forwards']??[]){if(!l['name']||j['has'](l['name']))continue;k['push']({'forward':l['name'],'operator':resolveOperator(l,a['orderHolderAddresses'],a['permissionDescription'],a['nameResolver'])});}if(k['length'])c['waiting_on']=k;c['note']='Node\x20did\x20not\x20migrate:\x20threshold\x20'+h+',\x20accumulated\x20weight\x20'+i+',\x20remaining\x20'+Math['max'](0x0,h-i)+'.\x20'+(k['length']?'Waiting\x20for:\x20'+k['map'](m=>m['forward']+'\x20('+(m['operator']['role_name']??m['operator']['kind'])+')')['join'](';\x20'):'All\x20forwards\x20on\x20this\x20pair\x20are\x20accomplished\x20—\x20the\x20node\x20should\x20migrate\x20on\x20the\x20next\x20operation.');}else c['note']='Node\x20did\x20not\x20migrate\x20(threshold\x200)\x20—\x20no\x20further\x20weight\x20cooperation\x20required;\x20verify\x20the\x20operation\x20outcome.';}const d=buildWorkflowGuidance({'current':a['current'],'nodes':a['nodes'],'caller':a['caller'],'orderHolderAddresses':a['orderHolderAddresses'],'permissionDescription':a['permissionDescription'],'nameResolver':a['nameResolver']});if(d['options']['length']>0x0)c['next_guidance']=d;return c;}function operatorText(a){const b=[a['role_name']??a['kind']];if(a['account_name'])b['push'](a['account_name']);return b['join']('\x20/\x20');}export function renderGuidanceText(a){const b=['[WORKFLOW\x20GUIDANCE]\x20current\x20node:\x20\x22'+a['current_node']+'\x22'+(a['caller']?'\x20(caller:\x20'+a['caller']+')':'')];if(a['options']['length']===0x0)return b['push']('\x20\x20•\x20'+(a['note']??'No\x20reachable\x20next\x20nodes.')),b['join']('\x0a');for(const c of a['options']){const d=['\x22'+c['forward']+'\x22\x20→\x20\x22'+c['next_node']+'\x22','operator:\x20'+operatorText(c['operator']),'weight:\x20'+c['weight'],'consistency:\x20'+c['consistency']+'/100'+(c['recommended']?'\x20[RECOMMENDED]':'')];if(c['guard'])d['push']('guard:\x20'+c['guard']);d['push']('meaning:\x20'+c['business_meaning']);if(c['gains']['length'])d['push']('gains:\x20'+c['gains']['join'](';\x20'));if(c['risks']['length'])d['push']('risks:\x20'+c['risks']['join'](';\x20'));b['push']('\x20\x20•\x20'+d['join']('\x20|\x20'));}if(a['recommendation']?.['best']){b['push']('\x20\x20RECOMMENDED:\x20'+a['recommendation']['best']+'.\x20'+(a['recommendation']['rationale']??''));if(a['recommendation']['caveat'])b['push']('\x20\x20CAVEAT\x20(opportunity\x20cost):\x20'+a['recommendation']['caveat']);}if(a['note'])b['push']('\x20\x20NOTE:\x20'+a['note']);return b['push']('\x20\x20(AI\x20recommendation\x20only\x20—\x20the\x20account\x20decides;\x20switch\x20env.account\x20if\x20another\x20operator\x20must\x20act.)'),b['join']('\x0a');}export function renderReceiptText(a){const b=['[WORKFLOW\x20RECEIPT]\x20'+a['action']];b['push']('\x20\x20•\x20node\x20migrated:\x20'+(a['migrated']?'yes\x20→\x20current:\x20\x22'+a['current_node']+'\x22':'no\x20→\x20current:\x20\x22'+a['current_node']+'\x22'));if(!a['migrated']){a['threshold']!==undefined&&a['threshold']>0x0&&(b['push']('\x20\x20•\x20threshold:\x20'+a['threshold']+'\x20|\x20accumulated\x20weight:\x20'+(a['accumulated_weight']??0x0)+'\x20|\x20remaining:\x20'+(a['remaining']??0x0)),a['waiting_on']?.['length']&&b['push']('\x20\x20•\x20waiting\x20on:\x20'+a['waiting_on']['map'](c=>'\x22'+c['forward']+'\x22\x20('+operatorText(c['operator'])+')')['join'](';\x20')));if(a['note'])b['push']('\x20\x20•\x20note:\x20'+a['note']);}return a['next_guidance']&&a['next_guidance']['options']['length']>0x0&&b['push'](renderGuidanceText(a['next_guidance'])),b['join']('\x0a');}async function makeNameResolver(a){const b=[...new Set(a['filter'](d=>!!d))],c=new Map();if(b['length'])try{const d=await GetLocalNamesByAddresses(b);for(const e of d){const f=e?.['account']??e?.['local_mark'];if(f)c['set'](e['address']['toLowerCase'](),f);}}catch{}return g=>{if(!g)return undefined;const h=c['get'](g['toLowerCase']());return h??shortAddr(g);};}export async function enrichWorkflowGuidance(a){try{let b;if(a['progressRef']['startsWith']('0x'))b=a['progressRef'];else b=await LocalMark['Instance']()['get_address'](a['progressRef'])??undefined;if(!b)return undefined;const c=await query_objects({'objects':[b],'no_cache':a['noCache'],'network':a['network']}),d=c?.['objects']?.[0x0],e=d?.['data']??d;if((d?.['type']??e?.['type'])!=='Progress')return undefined;const f=e['current']??'',g=e['machine'],h=Array['isArray'](e['session'])?e['session']:[],i=(Array['isArray'](e['namedOperator'])?e['namedOperator']['find'](q=>q?.['name']==='')?.['operators']:undefined)??[];if(!g)return undefined;const j=await fetchMachineNodes(g,a['network'],a['noCache']);let k;try{const q=await query_objects({'objects':[g],'no_cache':a['noCache'],'network':a['network']}),r=q?.['objects']?.[0x0],s=r?.['data']??r,t=s?.['permission'];if(t){const u=await query_objects({'objects':[t],'no_cache':a['noCache'],'network':a['network']}),v=u?.['objects']?.[0x0];k=(v?.['data']??v)?.['description']??undefined;}}catch{}const l=await makeNameResolver([a['accountName'],...i]),m={'current':f,'nodes':j,'caller':a['accountName'],'orderHolderAddresses':i,'permissionDescription':k,'nameResolver':l},n=buildWorkflowGuidance(m);let o;a['operate']?.['forward']&&a['operate']?.['next_node_name']&&(o=buildWorkflowReceipt({...m,'callerName':a['accountName']??b,'forward':a['operate']['forward'],'targetNode':a['operate']['next_node_name'],'op':a['operate']['op'],'session':h}));const p=[o?renderReceiptText(o):undefined,n['options']['length']?renderGuidanceText(n):undefined]['filter'](w=>!!w)['join']('\x0a\x0a');return{'guidance':n,'receipt':o,'text':p};}catch{return undefined;}}export function mergeGuidanceIntoOutput(a,b){if(!b)return a;try{const c=a?.['structuredContent'];if(c&&typeof c==='object'){const d=c['semantic'];if(d&&typeof d==='object'){if(b['guidance'])d['workflow_guidance']=b['guidance'];if(b['receipt'])d['workflow_receipt']=b['receipt'];}}b['text']&&Array['isArray'](a?.['content'])&&a['content'][0x0]?.['text']!==undefined&&(a['content'][0x0]['text']=b['text']+'\x0a\x0a'+a['content'][0x0]['text']);}catch{}return a;}
|
|
1
|
+
import{query_objects,query_table,query_account_list,LocalMark,GetLocalNamesByAddresses,bcs,deriveDynamicFieldID}from'@wowok/wowok';import{REPOSITORY_PERMISSIONS,REWARD_PERMISSIONS,MACHINE_PERMISSIONS,PROGRESS_PERMISSIONS,TREASURY_PERMISSIONS,SERVICE_PERMISSIONS,ARBITRATION_PERMISSIONS,DEMAND_PERMISSIONS,CONTACT_PERMISSIONS}from'./permission-ledger.js';const BUILTIN_PERMISSION_MAP=new Map();for(const entry of[...REPOSITORY_PERMISSIONS,...REWARD_PERMISSIONS,...MACHINE_PERMISSIONS,...PROGRESS_PERMISSIONS,...TREASURY_PERMISSIONS,...SERVICE_PERMISSIONS,...ARBITRATION_PERMISSIONS,...DEMAND_PERMISSIONS,...CONTACT_PERMISSIONS]){BUILTIN_PERMISSION_MAP['set'](entry['index'],entry['name']);}export function resolvePermissionRole(a,b){if(a===undefined||a===null)return'unknown\x20role';if(b){const d=/([A-Za-z][A-Za-z0-9_]*)\s*=\s*(\d+)/g;let e;while((e=d['exec'](b))!==null){if(Number(e[0x2])===a)return e[0x1]+'\x20(permission\x20'+a+')';}}const c=BUILTIN_PERMISSION_MAP['get'](a);if(c)return c+'\x20(permission\x20'+a+')';return'permission\x20'+a;}export async function fetchMachineNodes(a,b,c){const d=await query_objects({'objects':[a],'no_cache':c,'network':b}),e=d?.['objects']?.[0x0],f=e?.['object']??(typeof a==='string'&&a['startsWith']('0x')?a:undefined);if(!f)return[];const g=await query_table({'parent':f,'no_cache':c,'network':b}),h=(g?.['items']??[])['map'](j=>j?.['object'])['filter'](j=>typeof j==='string');if(h['length']===0x0)return[];const i=await query_objects({'objects':h,'no_cache':c,'network':b});return(i?.['objects']??[])['filter'](j=>j?.['type']==='TableItem_MachineNode')['map'](j=>{const k=j?.['data']??j,l=typeof k?.['name']==='string'?k['name']:'',m=Array['isArray'](k?.['value'])?k['value']:Array['isArray'](k?.['pairs'])?k['pairs']:[];if(!l)return null;return{'name':l,'pairs':m['map'](n=>({'prev_node':String(n?.['prev_node']??''),'threshold':Number(n?.['threshold']??0x0),'forwards':Array['isArray'](n?.['forwards'])?n['forwards']['map'](q=>{const r=typeof q?.['guard']==='object'&&q?.['guard']!==null?q['guard']['guard']??undefined:typeof q?.['guard']==='string'?q['guard']:undefined;return{'name':String(q?.['name']??''),'weight':Number(q?.['weight']??0x0),'namedOperator':q?.['namedOperator']!==undefined&&q?.['namedOperator']!==null?String(q['namedOperator']):undefined,'permissionIndex':q?.['permissionIndex']!==undefined&&q?.['permissionIndex']!==null?Number(q['permissionIndex']):undefined,'guard':r};}):[]}))};})['filter'](j=>j!==null);}const COMPLETE_RE=/(^|_)(completed?|done|finished|received|delivered|accepted|confirmed|finalized|success|approved)(_|$)/i,REFUND_RE=/(^|_)(cancel(led)?|refund(ed)?|return(ed|_approved)?)(_|$)/i,EXCEPTION_RE=/(^|_)(interrupt(ed)?|exception|dispute(d)?|fail(ed)?|abort(ed)?|reject(ed)?)(_|$)/i;function classifyNode(a){if(COMPLETE_RE['test'](a))return'complete';if(REFUND_RE['test'](a))return'refund';if(EXCEPTION_RE['test'](a))return'exception';return'advance';}function businessMeaning(a,b){switch(b){case'complete':return'Service/deliverable\x20accepted\x20at\x20\x22'+a+'\x22\x20—\x20triggers\x20settlement\x20allocation\x20(funds\x20released\x20to\x20the\x20provider)';case'refund':return'Order\x20cancelled/returned\x20at\x20\x22'+a+'\x22\x20—\x20triggers\x20refund\x20allocation\x20(funds\x20back\x20to\x20the\x20customer)';case'exception':return'Exception\x20path\x20at\x20\x22'+a+'\x22\x20—\x20typically\x20routes\x20to\x20arbitration\x20or\x20partial-refund\x20handling';default:return'Progress\x20to\x20\x22'+a+'\x22';}}function shortAddr(a){if(!a)return undefined;if(a['length']>0xe)return a['slice'](0x0,0x8)+'...'+a['slice'](-0x4);return a;}function callerIsOrderHolder(a,b){if(!a||!b?.['length'])return![];const d=a['toLowerCase']();return b['some'](e=>e?.['toLowerCase']()===d);}function resolveOperator(a,b,c,d){if(a['namedOperator']===''){const e=b?.[0x0];return{'kind':'order_holder','role_name':'order\x20holder\x20(customer)','account_name':d?d(e):shortAddr(e)};}if(typeof a['namedOperator']==='string'&&a['namedOperator']['length']>0x0)return{'kind':'named_operator','named_operator':a['namedOperator'],'role_name':'named\x20operator\x20\x22'+a['namedOperator']+'\x22'};if(a['permissionIndex']!==undefined&&a['permissionIndex']!==null)return{'kind':'permission_index','permission_index':a['permissionIndex'],'role_name':resolvePermissionRole(a['permissionIndex'],c)};return{'kind':'order_holder','role_name':'unknown\x20operator'};}function gainsRisksFor(a,b,c){if(!c)return{'gains':[],'risks':[]};if(b)switch(a){case'complete':return{'gains':['Flow\x20advances','Settlement\x20triggered\x20(funds\x20released)'],'risks':['Funds\x20released\x20to\x20provider','Refund\x20leverage\x20lost\x20—\x20confirm\x20only\x20if\x20service\x20verified']};case'refund':return{'gains':['Funds\x20returned\x20to\x20you'],'risks':['If\x20service\x20was\x20already\x20rendered,\x20cancellation\x20may\x20be\x20disputed']};case'exception':return{'gains':['Avoids\x20stalemate'],'risks':['May\x20trigger\x20arbitration\x20/\x20reputation\x20impact']};default:return{'gains':['Flow\x20advances'],'risks':[]};}switch(a){case'complete':return{'gains':['Settlement\x20triggered\x20—\x20funds\x20released\x20to\x20provider'],'risks':[]};case'refund':return{'gains':['Clean\x20closure'],'risks':['Lost\x20revenue\x20for\x20this\x20order']};case'exception':return{'gains':['Avoids\x20stalemate'],'risks':['May\x20trigger\x20arbitration\x20/\x20compensation\x20fund']};default:return{'gains':['Flow\x20advances'],'risks':[]};}}function consistencyFor(a,b,c,d,e){let f;if(!e)f=a==='exception'?0x2d:0x32;else b?f=a==='refund'?0x46:a==='complete'?0x37:a==='exception'?0x23:0x32:f=a==='complete'?0x4b:a==='refund'?0x1e:a==='exception'?0x23:0x32;if(e&&c)f+=0x14;if(d)f-=0xa;return Math['max'](0x0,Math['min'](0x64,f));}export function buildWorkflowGuidance(a){const b=[];for(const i of a['nodes']){for(const j of i['pairs']){if(j['prev_node']!==a['current'])continue;for(const k of j['forwards']){if(!k['name'])continue;const l=resolveOperator(k,a['orderHolderAddresses'],a['permissionDescription'],a['nameResolver']),m=callerIsOrderHolder(a['callerAddress']??a['caller'],a['orderHolderAddresses']);let n=![];a['callerAddress']&&(n=accountCanExecuteForward(k,a['callerAddress'],a['progressNamedOperator']??[],a['orderContext'],a['permissionContext']));const p=classifyNode(i['name']),q=!!a['caller'],{gains:r,risks:s}=gainsRisksFor(p,m,q),t=consistencyFor(p,m,n,!!k['guard'],q);b['push']({'next_node':i['name'],'forward':k['name'],'weight':k['weight'],'operator':l,'guard':k['guard'],'business_meaning':businessMeaning(i['name'],p),'gains':r,'risks':s,'consistency':t,'recommended':![]});}}}if(b['length']===0x0)return{'current_node':a['current'],'caller':a['caller'],'options':[],'note':'Node\x20\x22'+a['current']+'\x22\x20has\x20no\x20outgoing\x20forwards\x20—\x20it\x20is\x20a\x20terminal\x20node\x20(or\x20the\x20workflow\x20is\x20stuck).\x20No\x20further\x20progress\x20operation\x20is\x20available\x20here.'};b['sort']((u,v)=>v['consistency']-u['consistency']);const c=b[0x0];b[0x0]={...c,'recommended':!![]};const d=[];for(const u of b){u!==c&&u['consistency']>0x0&&u['forward']!==c['forward']&&d['push']('Choosing\x20\x22'+u['forward']+'\x20→\x20'+u['next_node']+'\x22\x20forfeits\x20the\x20faster/more\x20aligned\x20path\x20\x22'+c['forward']+'\x20→\x20'+c['next_node']+'\x22');}const e=[],g=b['filter'](v=>v['operator']['kind']==='order_holder'&&v['forward']!==c['forward']&&c['forward']!==v['forward']),h=b['filter'](v=>v['operator']['account_name']&&v['operator']['account_name']!==a['caller']);return h['length']>0x0&&!b['some'](v=>v['recommended']&&v['operator']['account_name']===a['caller'])&&e['push']('The\x20recommended\x20action\x20is\x20executed\x20by\x20another\x20account\x20('+h[0x0]['operator']['account_name']+');\x20switch\x20the\x20signing\x20account\x20(env.account)\x20before\x20operating.'),{'current_node':a['current'],'caller':a['caller'],'options':b,'recommendation':{'best':c['forward']+'\x20→\x20'+c['next_node'],'rationale':'Highest\x20consistency\x20('+c['consistency']+'/100)\x20with\x20the\x20caller\x27s\x20interests.\x20Gains:\x20'+(c['gains']['join'](';\x20')||'none')+'.\x20Risks:\x20'+(c['risks']['join'](';\x20')||'none')+'.\x20Operator:\x20'+(c['operator']['role_name']??c['operator']['kind'])+(c['operator']['account_name']?'\x20('+c['operator']['account_name']+')':'')+'.'+(c['guard']?'\x20Guard\x20to\x20satisfy:\x20'+c['guard']+'.':''),'caveat':d['length']?d['join']('.\x20'):undefined},'note':e['length']?e['join']('\x20'):undefined};}export function buildWorkflowReceipt(a){const b=a['current']===a['targetNode'],c={'account':a['callerName'],'action':a['callerName']+'\x20executed\x20'+a['forward']+'\x20(→\x20'+a['targetNode']+')','forward':a['forward'],'target_node':a['targetNode'],'op':a['op'],'migrated':b,'current_node':a['current']};if(!b){const e=a['nodes']['filter'](j=>j['name']===a['targetNode'])['flatMap'](j=>j['pairs'])['find'](j=>j['prev_node']===a['current']),g=a['session']?.['slice'](-0x1)[0x0],h=g?.['threshold']??e?.['threshold']??0x0,i=g?.['weights']??0x0;if(h>0x0){c['threshold']=h,c['accumulated_weight']=i,c['remaining']=Math['max'](0x0,h-i);const j=new Set((g?.['forwards']??[])['filter'](l=>l?.['accomplished']!==![])['map'](l=>l?.['forward'])['filter'](l=>!!l)),k=[];for(const l of e?.['forwards']??[]){if(!l['name']||j['has'](l['name']))continue;k['push']({'forward':l['name'],'operator':resolveOperator(l,a['orderHolderAddresses'],a['permissionDescription'],a['nameResolver'])});}if(k['length'])c['waiting_on']=k;c['note']='Node\x20did\x20not\x20migrate:\x20threshold\x20'+h+',\x20accumulated\x20weight\x20'+i+',\x20remaining\x20'+Math['max'](0x0,h-i)+'.\x20'+(k['length']?'Waiting\x20for:\x20'+k['map'](m=>m['forward']+'\x20('+(m['operator']['role_name']??m['operator']['kind'])+')')['join'](';\x20'):'All\x20forwards\x20on\x20this\x20pair\x20are\x20accomplished\x20—\x20the\x20node\x20should\x20migrate\x20on\x20the\x20next\x20operation.');}else c['note']='Node\x20did\x20not\x20migrate\x20(threshold\x200)\x20—\x20no\x20further\x20weight\x20cooperation\x20required;\x20verify\x20the\x20operation\x20outcome.';}const d=buildWorkflowGuidance({'current':a['current'],'nodes':a['nodes'],'caller':a['caller'],'orderHolderAddresses':a['orderHolderAddresses'],'permissionDescription':a['permissionDescription'],'nameResolver':a['nameResolver']});if(d['options']['length']>0x0)c['next_guidance']=d;return c;}function operatorText(a){const b=[a['role_name']??a['kind']];if(a['account_name'])b['push'](a['account_name']);return b['join']('\x20/\x20');}export function renderGuidanceText(a){const b=['[WORKFLOW\x20GUIDANCE]\x20current\x20node:\x20\x22'+a['current_node']+'\x22'+(a['caller']?'\x20(caller:\x20'+a['caller']+')':'')];if(a['options']['length']===0x0)return b['push']('\x20\x20•\x20'+(a['note']??'No\x20reachable\x20next\x20nodes.')),b['join']('\x0a');for(const c of a['options']){const d=['\x22'+c['forward']+'\x22\x20→\x20\x22'+c['next_node']+'\x22','operator:\x20'+operatorText(c['operator']),'weight:\x20'+c['weight'],'consistency:\x20'+c['consistency']+'/100'+(c['recommended']?'\x20[RECOMMENDED]':'')];if(c['guard'])d['push']('guard:\x20'+c['guard']);d['push']('meaning:\x20'+c['business_meaning']);if(c['gains']['length'])d['push']('gains:\x20'+c['gains']['join'](';\x20'));if(c['risks']['length'])d['push']('risks:\x20'+c['risks']['join'](';\x20'));b['push']('\x20\x20•\x20'+d['join']('\x20|\x20'));}if(a['recommendation']?.['best']){b['push']('\x20\x20RECOMMENDED:\x20'+a['recommendation']['best']+'.\x20'+(a['recommendation']['rationale']??''));if(a['recommendation']['caveat'])b['push']('\x20\x20CAVEAT\x20(opportunity\x20cost):\x20'+a['recommendation']['caveat']);}if(a['note'])b['push']('\x20\x20NOTE:\x20'+a['note']);return b['push']('\x20\x20(AI\x20recommendation\x20only\x20—\x20the\x20account\x20decides;\x20switch\x20env.account\x20if\x20another\x20operator\x20must\x20act.)'),b['join']('\x0a');}export function renderReceiptText(a){const b=['[WORKFLOW\x20RECEIPT]\x20'+a['action']];b['push']('\x20\x20•\x20node\x20migrated:\x20'+(a['migrated']?'yes\x20→\x20current:\x20\x22'+a['current_node']+'\x22':'no\x20→\x20current:\x20\x22'+a['current_node']+'\x22'));if(!a['migrated']){a['threshold']!==undefined&&a['threshold']>0x0&&(b['push']('\x20\x20•\x20threshold:\x20'+a['threshold']+'\x20|\x20accumulated\x20weight:\x20'+(a['accumulated_weight']??0x0)+'\x20|\x20remaining:\x20'+(a['remaining']??0x0)),a['waiting_on']?.['length']&&b['push']('\x20\x20•\x20waiting\x20on:\x20'+a['waiting_on']['map'](c=>'\x22'+c['forward']+'\x22\x20('+operatorText(c['operator'])+')')['join'](';\x20')));if(a['note'])b['push']('\x20\x20•\x20note:\x20'+a['note']);}return a['next_guidance']&&a['next_guidance']['options']['length']>0x0&&b['push'](renderGuidanceText(a['next_guidance'])),b['join']('\x0a');}async function makeNameResolver(a){const b=[...new Set(a['filter'](d=>!!d))],c=new Map();if(b['length'])try{const d=await GetLocalNamesByAddresses(b);for(const e of d){const f=e?.['account']??e?.['local_mark'];if(f)c['set'](e['address']['toLowerCase'](),f);}}catch{}return g=>{if(!g)return undefined;const h=c['get'](g['toLowerCase']());return h??shortAddr(g);};}export async function enrichWorkflowGuidance(a){try{let b;if(a['progressRef']['startsWith']('0x'))b=a['progressRef'];else b=await LocalMark['Instance']()['get_address'](a['progressRef'])??undefined;if(!b)return undefined;const c=await query_objects({'objects':[b],'no_cache':a['noCache'],'network':a['network']}),d=c?.['objects']?.[0x0],e=d?.['data']??d;if((d?.['type']??e?.['type'])!=='Progress')return undefined;const f=e['current']??'',g=e['machine'],h=Array['isArray'](e['session'])?e['session']:[],i=(Array['isArray'](e['namedOperator'])?e['namedOperator']['find'](u=>u?.['name']==='')?.['operators']:undefined)??[];if(!g)return undefined;const j=await fetchMachineNodes(g,a['network'],a['noCache']);let k,l;try{const u=await query_objects({'objects':[g],'no_cache':a['noCache'],'network':a['network']}),v=u?.['objects']?.[0x0],w=v?.['data']??v,x=w?.['permission'];if(x){const y=await query_objects({'objects':[x],'no_cache':a['noCache'],'network':a['network']}),z=y?.['objects']?.[0x0];k=(z?.['data']??z)?.['description']??undefined,l=await fetchPermissionContext(x,a['network'],a['noCache']);}}catch{}const m=(Array['isArray'](e['namedOperator'])?e['namedOperator']:[])['map'](A=>({'name':String(A?.['name']??''),'operators':(A?.['operators']??[])['map'](B=>String(B))}));let n;e['task']&&(n=await fetchOrderContext(e['task'],a['network'],a['noCache']));let o;try{o=await LocalMark['Instance']()['get_address'](a['accountName'])??undefined;}catch{o=undefined;}const p=await makeNameResolver([a['accountName'],...i]),q={'current':f,'nodes':j,'caller':a['accountName'],'callerAddress':o,'orderHolderAddresses':i,'progressNamedOperator':m,'permissionContext':l,'orderContext':n,'permissionDescription':k,'nameResolver':p},r=buildWorkflowGuidance(q);let s;a['operate']?.['forward']&&a['operate']?.['next_node_name']&&(s=buildWorkflowReceipt({...q,'callerName':a['accountName']??b,'forward':a['operate']['forward'],'targetNode':a['operate']['next_node_name'],'op':a['operate']['op'],'session':h}));const t=[s?renderReceiptText(s):undefined,r['options']['length']?renderGuidanceText(r):undefined]['filter'](A=>!!A)['join']('\x0a\x0a');return{'guidance':r,'receipt':s,'text':t};}catch{return undefined;}}export function mergeGuidanceIntoOutput(a,b){if(!b)return a;try{const c=a?.['structuredContent'];if(c&&typeof c==='object'){const d=c['semantic'];if(d&&typeof d==='object'){if(b['guidance'])d['workflow_guidance']=b['guidance'];if(b['receipt'])d['workflow_receipt']=b['receipt'];}}b['text']&&Array['isArray'](a?.['content'])&&a['content'][0x0]?.['text']!==undefined&&(a['content'][0x0]['text']=b['text']+'\x0a\x0a'+a['content'][0x0]['text']);}catch{}return a;}export const ENTITY_PERMISSION_OBJECT_ID='0xaad';export const ENTITY_PERMISSION_ROLES={'OWNER':0x1,'ADMIN':0x2,'ENTITY':0x4};export async function fetchEntityPermission(a,b,c){try{const e=bcs['Address']['serialize'](a)['toBytes'](),f=deriveDynamicFieldID(ENTITY_PERMISSION_OBJECT_ID,'address',e),g=await query_objects({'objects':[f],'no_cache':c,'network':b}),h=g?.['objects']?.[0x0],i=h?.['data']??h,j=[],k=new Map(),l=Array['isArray'](i?.['items'])?i['items']:[];for(const m of l){const n=Number(m?.['role']??0x0),o=String(m?.['permission']??'')['toLowerCase'](),p=Number(m?.['time']??0x0);o&&(j['push']({'role':n,'permission':o,'time':p}),k['set'](o,(k['get'](o)??0x0)|n));}return{'items':j,'byPermission':k};}catch{return undefined;}}export const ENTITY_CONTACT_OBJECT_ID='0xaa9';export async function fetchEntityContact(a,b,c){try{const e=bcs['Address']['serialize'](a)['toBytes'](),f=deriveDynamicFieldID(ENTITY_CONTACT_OBJECT_ID,'address',e),g=await query_objects({'objects':[f],'no_cache':c,'network':b}),h=g?.['objects']?.[0x0],i=h?.['data']??h,j=[],k=new Map(),l=Array['isArray'](i?.['items'])?i['items']:[];for(const m of l){const n=String(m?.['contact']??'')['toLowerCase'](),o=Number(m?.['time']??0x0);n&&(j['push']({'contact':n,'time':o}),k['set'](n,o));}return{'items':j,'byContact':k};}catch{return undefined;}}export const OBJECT_LINKER_CORE_OBJECT_ID='0xaae';export const OBJECT_LINKER_TX_OBJECT_ID='0xaaf';async function fetchObjectLinker(a,b,c,e){try{const f=bcs['Address']['serialize'](b)['toBytes'](),g=deriveDynamicFieldID(a,'address',f),h=await query_objects({'objects':[g],'no_cache':e,'network':c}),i=h?.['objects']?.[0x0],j=i?.['data']??i,k=[],l=new Map(),m=Array['isArray'](j?.['items'])?j['items']:[];for(const n of m){const o=String(n?.['who']??'')['toLowerCase'](),p=Number(n?.['time']??0x0);o&&(k['push']({'who':o,'time':p}),l['set'](o,p));}return{'items':k,'byWho':l};}catch{return undefined;}}export async function fetchObjectLinkerCore(a,b,c){return fetchObjectLinker(OBJECT_LINKER_CORE_OBJECT_ID,a,b,c);}export async function fetchObjectLinkerTx(a,b,c){return fetchObjectLinker(OBJECT_LINKER_TX_OBJECT_ID,a,b,c);}export async function fetchPermissionContext(a,b,c){try{const e=await query_objects({'objects':[a],'no_cache':c,'network':b}),f=e?.['objects']?.[0x0],g=f?.['data']??f,h=new Set((g?.['admin']??[])['map'](l=>String(l)['toLowerCase']())),i=new Map(),j=await query_table({'parent':a,'no_cache':c,'network':b}),k=(j?.['items']??[])['map'](l=>l?.['object'])['filter'](l=>typeof l==='string');if(k['length']>0x0){const l=await query_objects({'objects':k,'no_cache':c,'network':b});for(const m of l?.['objects']??[]){const n=m?.['data']??m,p=n?.['address'],q=n?.['perm'];p!=null&&Array['isArray'](q)&&i['set'](String(p)['toLowerCase'](),new Set(q['map'](r=>Number(r))));}}return{'admin':h,'table':i};}catch{return undefined;}}export async function fetchOrderContext(a,b,c){try{const e=await query_objects({'objects':[a],'no_cache':c,'network':b}),f=e?.['objects']?.[0x0];if((f?.['type']??f?.['data']?.['type'])!=='Order')return undefined;const g=f?.['data']??f;return{'builder':String(g?.['builder']??''),'agent':new Set((g?.['agent']??[])['map'](h=>String(h)['toLowerCase']()))};}catch{return undefined;}}export async function listLocalAccounts(){try{const a=await query_account_list({'suspended':![]});return(a??[])['filter'](b=>b?.['address'])['map'](b=>({'address':String(b['address']),'name':b['name']??undefined}));}catch{return[];}}export function accountCanExecuteForward(a,b,c,d,e){const g=b['toLowerCase']();if(a['namedOperator']!==undefined&&a['namedOperator']!==null){if(a['namedOperator']===''){if(d&&(g===d['builder']['toLowerCase']()||d['agent']['has'](g)))return!![];}else{if(a['namedOperator']['length']>0x0){const h=c['find'](i=>i?.['name']===a['namedOperator']);if(h?.['operators']?.['some'](i=>String(i)['toLowerCase']()===g))return!![];}}}if(a['permissionIndex']!==undefined&&a['permissionIndex']!==null&&e){if(e['admin']['has'](g))return!![];const i=e['table']['get'](g);if(i?.['has'](a['permissionIndex']))return!![];}return![];}
|