@agenticprimitives/treasury-service-agent 0.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/dist/benchmarks/benchmark.d.ts +28 -0
  4. package/dist/benchmarks/benchmark.d.ts.map +1 -0
  5. package/dist/benchmarks/benchmark.js +26 -0
  6. package/dist/benchmarks/benchmark.js.map +1 -0
  7. package/dist/benchmarks/suite.d.ts +11 -0
  8. package/dist/benchmarks/suite.d.ts.map +1 -0
  9. package/dist/benchmarks/suite.js +166 -0
  10. package/dist/benchmarks/suite.js.map +1 -0
  11. package/dist/capabilities.d.ts +68 -0
  12. package/dist/capabilities.d.ts.map +1 -0
  13. package/dist/capabilities.js +68 -0
  14. package/dist/capabilities.js.map +1 -0
  15. package/dist/catalog-defi.d.ts +29 -0
  16. package/dist/catalog-defi.d.ts.map +1 -0
  17. package/dist/catalog-defi.js +79 -0
  18. package/dist/catalog-defi.js.map +1 -0
  19. package/dist/catalog.d.ts +86 -0
  20. package/dist/catalog.d.ts.map +1 -0
  21. package/dist/catalog.js +199 -0
  22. package/dist/catalog.js.map +1 -0
  23. package/dist/dispatch/delegation-authority.d.ts +58 -0
  24. package/dist/dispatch/delegation-authority.d.ts.map +1 -0
  25. package/dist/dispatch/delegation-authority.js +62 -0
  26. package/dist/dispatch/delegation-authority.js.map +1 -0
  27. package/dist/grant.d.ts +34 -0
  28. package/dist/grant.d.ts.map +1 -0
  29. package/dist/grant.js +40 -0
  30. package/dist/grant.js.map +1 -0
  31. package/dist/index.d.ts +45 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +37 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/intents/intent-types.d.ts +65 -0
  36. package/dist/intents/intent-types.d.ts.map +1 -0
  37. package/dist/intents/intent-types.js +44 -0
  38. package/dist/intents/intent-types.js.map +1 -0
  39. package/dist/intents/resolved-treasury-order.d.ts +38 -0
  40. package/dist/intents/resolved-treasury-order.d.ts.map +1 -0
  41. package/dist/intents/resolved-treasury-order.js +2 -0
  42. package/dist/intents/resolved-treasury-order.js.map +1 -0
  43. package/dist/intents/treasury-intent-resolver.d.ts +30 -0
  44. package/dist/intents/treasury-intent-resolver.d.ts.map +1 -0
  45. package/dist/intents/treasury-intent-resolver.js +113 -0
  46. package/dist/intents/treasury-intent-resolver.js.map +1 -0
  47. package/dist/payments/order-to-mandate.d.ts +31 -0
  48. package/dist/payments/order-to-mandate.d.ts.map +1 -0
  49. package/dist/payments/order-to-mandate.js +46 -0
  50. package/dist/payments/order-to-mandate.js.map +1 -0
  51. package/dist/plans.d.ts +27 -0
  52. package/dist/plans.d.ts.map +1 -0
  53. package/dist/plans.js +47 -0
  54. package/dist/plans.js.map +1 -0
  55. package/dist/plugins/defi-plugin.d.ts +54 -0
  56. package/dist/plugins/defi-plugin.d.ts.map +1 -0
  57. package/dist/plugins/defi-plugin.js +30 -0
  58. package/dist/plugins/defi-plugin.js.map +1 -0
  59. package/dist/profiles.d.ts +92 -0
  60. package/dist/profiles.d.ts.map +1 -0
  61. package/dist/profiles.js +60 -0
  62. package/dist/profiles.js.map +1 -0
  63. package/dist/receipt.d.ts +16 -0
  64. package/dist/receipt.d.ts.map +1 -0
  65. package/dist/receipt.js +16 -0
  66. package/dist/receipt.js.map +1 -0
  67. package/dist/risk/risk-policy.d.ts +44 -0
  68. package/dist/risk/risk-policy.d.ts.map +1 -0
  69. package/dist/risk/risk-policy.js +50 -0
  70. package/dist/risk/risk-policy.js.map +1 -0
  71. package/dist/schemas.d.ts +68 -0
  72. package/dist/schemas.d.ts.map +1 -0
  73. package/dist/schemas.js +24 -0
  74. package/dist/schemas.js.map +1 -0
  75. package/dist/solvers/broker.d.ts +24 -0
  76. package/dist/solvers/broker.d.ts.map +1 -0
  77. package/dist/solvers/broker.js +43 -0
  78. package/dist/solvers/broker.js.map +1 -0
  79. package/dist/solvers/digest.d.ts +5 -0
  80. package/dist/solvers/digest.d.ts.map +1 -0
  81. package/dist/solvers/digest.js +27 -0
  82. package/dist/solvers/digest.js.map +1 -0
  83. package/dist/solvers/plan-validation.d.ts +40 -0
  84. package/dist/solvers/plan-validation.d.ts.map +1 -0
  85. package/dist/solvers/plan-validation.js +66 -0
  86. package/dist/solvers/plan-validation.js.map +1 -0
  87. package/dist/solvers/quote-ranking.d.ts +47 -0
  88. package/dist/solvers/quote-ranking.d.ts.map +1 -0
  89. package/dist/solvers/quote-ranking.js +48 -0
  90. package/dist/solvers/quote-ranking.js.map +1 -0
  91. package/dist/solvers/solver-port.d.ts +104 -0
  92. package/dist/solvers/solver-port.d.ts.map +1 -0
  93. package/dist/solvers/solver-port.js +2 -0
  94. package/dist/solvers/solver-port.js.map +1 -0
  95. package/dist/strategy/strategy-controller.d.ts +36 -0
  96. package/dist/strategy/strategy-controller.d.ts.map +1 -0
  97. package/dist/strategy/strategy-controller.js +66 -0
  98. package/dist/strategy/strategy-controller.js.map +1 -0
  99. package/dist/strategy/strategy-definition.d.ts +55 -0
  100. package/dist/strategy/strategy-definition.d.ts.map +1 -0
  101. package/dist/strategy/strategy-definition.js +39 -0
  102. package/dist/strategy/strategy-definition.js.map +1 -0
  103. package/dist/strategy/triggers.d.ts +27 -0
  104. package/dist/strategy/triggers.d.ts.map +1 -0
  105. package/dist/strategy/triggers.js +22 -0
  106. package/dist/strategy/triggers.js.map +1 -0
  107. package/package.json +54 -0
package/dist/grant.js ADDED
@@ -0,0 +1,40 @@
1
+ export class TreasuryScopeError extends Error {
2
+ }
3
+ /** Validate + normalize a scope. Fail-closed: an empty skill allowlist is rejected (a grant that lets a
4
+ * host do nothing is almost certainly a mistake; the caller must be explicit). */
5
+ export function buildTreasuryScope(scope) {
6
+ if (!scope.allowedSkillIds || scope.allowedSkillIds.length === 0) {
7
+ throw new TreasuryScopeError('a treasury scope needs a non-empty allowedSkillIds allowlist');
8
+ }
9
+ if (scope.notBefore !== undefined && scope.notAfter !== undefined && scope.notAfter <= scope.notBefore) {
10
+ throw new TreasuryScopeError('notAfter must be after notBefore');
11
+ }
12
+ return {
13
+ ...scope,
14
+ allowedSkillIds: [...new Set(scope.allowedSkillIds)],
15
+ };
16
+ }
17
+ /** Lower a scope into abstract caveat terms (only the constraints that are set). The ceremony maps each
18
+ * `kind` to a `delegation` enforcer; the resulting grant is monotonic (it can only narrow these). */
19
+ export function treasuryScopeToCaveatTerms(scope) {
20
+ const terms = [{ kind: 'allowed-skills', value: [...new Set(scope.allowedSkillIds)] }];
21
+ if (scope.networks?.length)
22
+ terms.push({ kind: 'allowed-networks', value: scope.networks });
23
+ if (scope.maxValuePerTx !== undefined)
24
+ terms.push({ kind: 'value-per-tx', value: scope.maxValuePerTx });
25
+ if (scope.maxTotalValue !== undefined)
26
+ terms.push({ kind: 'value-total', value: scope.maxTotalValue });
27
+ if (scope.allowedAssetTypes?.length)
28
+ terms.push({ kind: 'allowed-asset-types', value: scope.allowedAssetTypes });
29
+ if (scope.allowedTargets?.length)
30
+ terms.push({ kind: 'allowed-targets', value: scope.allowedTargets });
31
+ if (scope.notBefore !== undefined || scope.notAfter !== undefined) {
32
+ terms.push({ kind: 'time-window', value: { notBefore: scope.notBefore, notAfter: scope.notAfter } });
33
+ }
34
+ return terms;
35
+ }
36
+ /** Is a skill within the scope's allowlist? (Pure check the host can use before invoking.) */
37
+ export function skillInScope(scope, skillId) {
38
+ return scope.allowedSkillIds.includes(skillId);
39
+ }
40
+ //# sourceMappingURL=grant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grant.js","sourceRoot":"","sources":["../src/grant.ts"],"names":[],"mappings":"AAgCA,MAAM,OAAO,kBAAmB,SAAQ,KAAK;CAAG;AAEhD;mFACmF;AACnF,MAAM,UAAU,kBAAkB,CAAC,KAA6B;IAC9D,IAAI,CAAC,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjE,MAAM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,cAAc,EAAE,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC;IACvG,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAClE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACvG,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,YAAY,CAAC,KAA6B,EAAE,OAAe;IACzE,OAAO,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,45 @@
1
+ export { TREASURY_CAPABILITIES, ASSET_TYPE } from './capabilities.js';
2
+ export type { TreasuryCapabilityId, AssetType } from './capabilities.js';
3
+ export type { NetworkId, AccountRef, AssetRef, AssetAmount, AccountQuery, BalanceResult, TransferInput, TransferResult, SignInput, SignResult, SwapQuoteInput, SwapExecuteInput, RawTxInput, } from './schemas.js';
4
+ export { objectSchema } from './schemas.js';
5
+ export { readPlan, authedReadPlan, signPlan, spendPlan, adminPlan, } from './plans.js';
6
+ export type { SpendPlanOpts } from './plans.js';
7
+ export { SKILL_VERSION, ALL_TREASURY_SKILLS, serviceInfo, networkList, networkStatus, accountList, accountBalance, accountActivity, marketDataPrice, marketDataOhlcv, signMessage, signTypedData, txSimulate, txSend, transferNative, transferToken, swapQuote, swapExecute, perpPositions, perpOpen, perpClose, predictionMarkets, predictionBet, delegationGrant, delegationRevoke, entitlementCheck, entitlementIssue, entitlementConsume, } from './catalog.js';
8
+ export { TREASURY_PROFILES, readonlyProfile, paymentsProfile, marketsProfile, administrationProfile, portfolioProfile, yieldProfile, crossChainProfile, fullProfile, } from './profiles.js';
9
+ export type { TreasuryProfileId } from './profiles.js';
10
+ export { DEFI_SKILLS, portfolioSnapshot, portfolioValue, portfolioExposure, portfolioRebalance, lendingPosition, lendingSupply, lendingRepay, lendingWithdraw, lendingBorrow, stakingPosition, stakingStake, stakingUnstake, stakingClaim, liquidityPosition, liquidityAdd, liquidityRemove, liquidityCollectFees, vaultPosition, vaultDeposit, vaultWithdraw, vaultMigrate, bridgeQuote, bridgeStatus, bridgeExecute, bridgeRecover, } from './catalog-defi.js';
11
+ export { installPlugin, validatePluginManifest, PluginManifestError } from './plugins/defi-plugin.js';
12
+ export type { PrimitiveProvider, DeFiPluginManifest, PrimitiveCapabilityAssertion, AssertionContext, PluginHealth, DeFiPrimitivePlugin, ProviderSink, InstalledPlugin, } from './plugins/defi-plugin.js';
13
+ export { evaluateRisk, aggregateExposure } from './risk/risk-policy.js';
14
+ export type { RiskPolicy, ExposureState, RiskBreach, RiskVerdict } from './risk/risk-policy.js';
15
+ export { evaluateTriggers } from './strategy/triggers.js';
16
+ export type { TriggerCondition, TriggerContext } from './strategy/triggers.js';
17
+ export { createRun, canTransition, transitionRun, emergencyStop, StrategyTransitionError, } from './strategy/strategy-definition.js';
18
+ export type { StrategyMandate, StrategyDefinition, StrategyStatus, StrategyRunState } from './strategy/strategy-definition.js';
19
+ export { StrategyController, requireQuorum } from './strategy/strategy-controller.js';
20
+ export type { ProposedRun, RunControlContext, RunDecision } from './strategy/strategy-controller.js';
21
+ export { runBenchmark, runBenchmarks } from './benchmarks/benchmark.js';
22
+ export type { Benchmark, BenchmarkCase, CaseResult, BenchmarkResult } from './benchmarks/benchmark.js';
23
+ export { treasuryBenchmarks, intentBench, planBench, safetyBench, authorityBench, defiBench, recoveryBench, accountingBench, } from './benchmarks/suite.js';
24
+ export { buildTreasuryPaymentMandate } from './payments/order-to-mandate.js';
25
+ export type { BuildTreasuryMandateArgs, Hex32 } from './payments/order-to-mandate.js';
26
+ export { createDelegationAuthority, dispatchUnderDelegation, DelegationDispatchError } from './dispatch/delegation-authority.js';
27
+ export type { DelegationAuthorityDeps, DelegationVerifier, DispatchUnderDelegationArgs, } from './dispatch/delegation-authority.js';
28
+ export { buildTreasuryScope, treasuryScopeToCaveatTerms, skillInScope, TreasuryScopeError, } from './grant.js';
29
+ export type { TreasuryAuthorityScope, CaveatTerm } from './grant.js';
30
+ export { summarizeTreasuryReceipt } from './receipt.js';
31
+ export type { TreasurySummary } from './receipt.js';
32
+ export { treasuryConstraint, buildTreasuryConstraintSet, buildTreasuryIntent } from './intents/intent-types.js';
33
+ export type { TreasuryIntentKind, AllocationTarget, TreasuryObjective, DesiredOutcome, AcceptanceCondition, TreasuryIntentPayload, TreasuryIntent, TreasuryConstraintInput, BuildTreasuryIntentArgs, } from './intents/intent-types.js';
34
+ export type { CanonicalConstraints, OrderVariable, OrderStep, OrderPaymentRef, ResolvedTreasuryOrder, } from './intents/resolved-treasury-order.js';
35
+ export { TreasuryIntentResolver } from './intents/treasury-intent-resolver.js';
36
+ export type { TreasuryResolution, TreasuryResolverOptions } from './intents/treasury-intent-resolver.js';
37
+ export { structuralDigest, stableStringify } from './solvers/digest.js';
38
+ export type { PlanKind, AssetEffect, TreasuryPlanStep, ExpectedOutcome, FeeEstimate, GasEstimate, RiskDisclosure, QuoteSignals, StateAnchor, TreasuryExecutionPlan, TreasuryPlanQuote, SolverContext, SolverSupport, TreasurySolver, } from './solvers/solver-port.js';
39
+ export { scoreQuote, rankQuotes, buildSelectionReceipt, DEFAULT_RANK_WEIGHTS } from './solvers/quote-ranking.js';
40
+ export type { RankWeights, ScoreBreakdown, RankedQuote, SelectionReceipt } from './solvers/quote-ranking.js';
41
+ export { validatePlanQuote, requiresSimulation, commitSimulation, validatePreSign, } from './solvers/plan-validation.js';
42
+ export type { ValidationResult, ValidatePlanQuoteContext, PreSignFields, SimulationCommitment } from './solvers/plan-validation.js';
43
+ export { SolverBroker } from './solvers/broker.js';
44
+ export type { SolveOptions, SolveResult } from './solvers/broker.js';
45
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACtE,YAAY,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEzE,YAAY,EACV,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EACzE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,GACnG,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EACL,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,GACzD,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EACL,aAAa,EAAE,mBAAmB,EAClC,WAAW,EAAE,WAAW,EAAE,aAAa,EACvC,WAAW,EAAE,cAAc,EAAE,eAAe,EAC5C,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,aAAa,EAC1B,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,aAAa,EAC7B,SAAS,EAAE,WAAW,EACtB,aAAa,EAAE,QAAQ,EAAE,SAAS,EAClC,iBAAiB,EAAE,aAAa,EAChC,eAAe,EAAE,gBAAgB,EACjC,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,GACvD,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,iBAAiB,EACjB,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,qBAAqB,EACvE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,GAC/D,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,i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,YAAY,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAGzG,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACxE,YAAY,EACV,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAClG,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,aAAa,EAAE,aAAa,EACjG,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACjH,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7G,OAAO,EACL,iBAAiB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,GACzE,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpI,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ // @agenticprimitives/treasury-service-agent — intent-native DeFi Treasury Agent (specs 283/284).
2
+ // Skill catalog + profiles + authority-scope/receipt helpers (283 baseline) + the intent layer (284 PR-C:
3
+ // TreasuryIntent + resolver + ResolvedTreasuryOrder). Built on @agenticprimitives/service-agent +
4
+ // intent-marketplace + intent-resolver.
5
+ export { TREASURY_CAPABILITIES, ASSET_TYPE } from './capabilities.js';
6
+ export { objectSchema } from './schemas.js';
7
+ export { readPlan, authedReadPlan, signPlan, spendPlan, adminPlan, } from './plans.js';
8
+ export { SKILL_VERSION, ALL_TREASURY_SKILLS, serviceInfo, networkList, networkStatus, accountList, accountBalance, accountActivity, marketDataPrice, marketDataOhlcv, signMessage, signTypedData, txSimulate, txSend, transferNative, transferToken, swapQuote, swapExecute, perpPositions, perpOpen, perpClose, predictionMarkets, predictionBet, delegationGrant, delegationRevoke, entitlementCheck, entitlementIssue, entitlementConsume, } from './catalog.js';
9
+ export { TREASURY_PROFILES, readonlyProfile, paymentsProfile, marketsProfile, administrationProfile, portfolioProfile, yieldProfile, crossChainProfile, fullProfile, } from './profiles.js';
10
+ // ── DeFi family catalog (spec 284 PR-E) ──
11
+ export { DEFI_SKILLS, portfolioSnapshot, portfolioValue, portfolioExposure, portfolioRebalance, lendingPosition, lendingSupply, lendingRepay, lendingWithdraw, lendingBorrow, stakingPosition, stakingStake, stakingUnstake, stakingClaim, liquidityPosition, liquidityAdd, liquidityRemove, liquidityCollectFees, vaultPosition, vaultDeposit, vaultWithdraw, vaultMigrate, bridgeQuote, bridgeStatus, bridgeExecute, bridgeRecover, } from './catalog-defi.js';
12
+ // ── DeFi provider plugin contract (spec 284 PR-E) ──
13
+ export { installPlugin, validatePluginManifest, PluginManifestError } from './plugins/defi-plugin.js';
14
+ // ── risk engine (spec 284 PR-F) ──
15
+ export { evaluateRisk, aggregateExposure } from './risk/risk-policy.js';
16
+ // ── strategy controller + lifecycle (spec 284 PR-F) ──
17
+ export { evaluateTriggers } from './strategy/triggers.js';
18
+ export { createRun, canTransition, transitionRun, emergencyStop, StrategyTransitionError, } from './strategy/strategy-definition.js';
19
+ export { StrategyController, requireQuorum } from './strategy/strategy-controller.js';
20
+ // ── benchmark suite (spec 284 PR-F) ──
21
+ export { runBenchmark, runBenchmarks } from './benchmarks/benchmark.js';
22
+ export { treasuryBenchmarks, intentBench, planBench, safetyBench, authorityBench, defiBench, recoveryBench, accountingBench, } from './benchmarks/suite.js';
23
+ // ── payments binding: resolved order → PaymentMandate (spec 284 + 243) ──
24
+ export { buildTreasuryPaymentMandate } from './payments/order-to-mandate.js';
25
+ // ── delegation-backed dispatch: scoped grant → real caveat authority + on-chain validity (spec 284 host + 285) ──
26
+ export { createDelegationAuthority, dispatchUnderDelegation, DelegationDispatchError } from './dispatch/delegation-authority.js';
27
+ export { buildTreasuryScope, treasuryScopeToCaveatTerms, skillInScope, TreasuryScopeError, } from './grant.js';
28
+ export { summarizeTreasuryReceipt } from './receipt.js';
29
+ // ── intent layer (spec 284 PR-C) ──
30
+ export { treasuryConstraint, buildTreasuryConstraintSet, buildTreasuryIntent } from './intents/intent-types.js';
31
+ export { TreasuryIntentResolver } from './intents/treasury-intent-resolver.js';
32
+ // ── solver broker + plan validation (spec 284 PR-D) ──
33
+ export { structuralDigest, stableStringify } from './solvers/digest.js';
34
+ export { scoreQuote, rankQuotes, buildSelectionReceipt, DEFAULT_RANK_WEIGHTS } from './solvers/quote-ranking.js';
35
+ export { validatePlanQuote, requiresSimulation, commitSimulation, validatePreSign, } from './solvers/plan-validation.js';
36
+ export { SolverBroker } from './solvers/broker.js';
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,0GAA0G;AAC1G,kGAAkG;AAClG,wCAAwC;AACxC,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAOtE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EACL,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,GACzD,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,aAAa,EAAE,mBAAmB,EAClC,WAAW,EAAE,WAAW,EAAE,aAAa,EACvC,WAAW,EAAE,cAAc,EAAE,eAAe,EAC5C,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,aAAa,EAC1B,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,aAAa,EAC7B,SAAS,EAAE,WAAW,EACtB,aAAa,EAAE,Q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AAc,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,GACnH,MAAM,uBAAuB,CAAC;AAE/B,2EAA2E;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAG7E,mHAAmH;AACnH,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAKjI,OAAO,EACL,kBAAkB,EAAE,0BAA0B,EAAE,YAAY,EAAE,kBAAkB,GACjF,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAGxD,qCAAqC;AACrC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAQhH,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAG/E,wDAAwD;AACxD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAMxE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEjH,OAAO,EACL,iBAAiB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,GACzE,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { Address } from '@agenticprimitives/types';
2
+ import type { Constraint, ConstraintSet, ConstraintSource, ConstraintStrength, Intent, AssumptionSet, VisibilityTier } from '@agenticprimitives/intent-marketplace';
3
+ import type { AssetAmount, AssetRef } from '../schemas.js';
4
+ /** The treasury intent kinds (spec 284). */
5
+ export type TreasuryIntentKind = 'transfer' | 'swap' | 'bridge' | 'target-allocation' | 'yield-allocation' | 'debt-management' | 'liquidity-management' | 'perpetual-position' | 'prediction-order' | 'strategy-run';
6
+ export interface AllocationTarget {
7
+ asset?: string;
8
+ category?: string;
9
+ percentageBps: number;
10
+ }
11
+ export interface TreasuryObjective {
12
+ summary?: string;
13
+ targets?: AllocationTarget[];
14
+ deadline?: number;
15
+ }
16
+ export interface DesiredOutcome {
17
+ asset: AssetRef;
18
+ minAmount?: string;
19
+ note?: string;
20
+ }
21
+ export interface AcceptanceCondition {
22
+ code: string;
23
+ value: unknown;
24
+ }
25
+ /** Domain economic payload of a treasury intent. NOTE: constraints are NOT here — they go to the spine
26
+ * `ConstraintSet` (see buildTreasuryIntent). A `type` (not `interface`) so it satisfies the
27
+ * `Intent<TPayload extends Record<string, unknown>>` constraint. */
28
+ export type TreasuryIntentPayload = {
29
+ kind: TreasuryIntentKind;
30
+ portfolioId: string;
31
+ objective: TreasuryObjective;
32
+ inputs?: AssetAmount[];
33
+ desiredOutputs?: DesiredOutcome[];
34
+ acceptance: AcceptanceCondition[];
35
+ validUntil: number;
36
+ idempotencyKey: string;
37
+ };
38
+ /** A treasury intent = the spine Intent specialized to the treasury payload. */
39
+ export type TreasuryIntent = Intent<TreasuryIntentPayload>;
40
+ /** A treasury constraint expressed at the domain level; lowered to a spine `Constraint` with provenance. */
41
+ export interface TreasuryConstraintInput {
42
+ /** e.g. "maximum-slippage-bps", "maximum-protocol-exposure-bps", "bridging-allowed". */
43
+ code: string;
44
+ value: number | string | boolean;
45
+ source: ConstraintSource;
46
+ strength?: ConstraintStrength;
47
+ rationale?: string;
48
+ }
49
+ /** Lower one domain constraint to a spine `Constraint` (range for numbers, enum for bool/string). */
50
+ export declare function treasuryConstraint(input: TreasuryConstraintInput): Constraint;
51
+ /** Build a spine ConstraintSet from domain constraints (splits hard/soft). */
52
+ export declare function buildTreasuryConstraintSet(inputs: TreasuryConstraintInput[]): ConstraintSet;
53
+ export interface BuildTreasuryIntentArgs {
54
+ id: string;
55
+ expressedBy: Address;
56
+ addressedTo?: Address[];
57
+ payload: TreasuryIntentPayload;
58
+ constraints?: TreasuryConstraintInput[];
59
+ assumptions?: AssumptionSet;
60
+ visibility?: VisibilityTier;
61
+ now?: () => string;
62
+ }
63
+ /** Construct a `TreasuryIntent` — places domain constraints into the spine `hasConstraintSet`. */
64
+ export declare function buildTreasuryIntent(args: BuildTreasuryIntentArgs): TreasuryIntent;
65
+ //# sourceMappingURL=intent-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent-types.d.ts","sourceRoot":"","sources":["../../src/intents/intent-types.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EACV,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,EAAE,aAAa,EAAO,cAAc,EAC5G,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE3D,4CAA4C;AAC5C,MAAM,MAAM,kBAAkB,GAC1B,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,mBAAmB,GAAG,kBAAkB,GACzE,iBAAiB,GAAG,sBAAsB,GAAG,oBAAoB,GAAG,kBAAkB,GAAG,cAAc,CAAC;AAE5G,MAAM,WAAW,gBAAgB;IAAG,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE;AAC9F,MAAM,WAAW,iBAAiB;IAAG,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE;AACxG,MAAM,WAAW,cAAc;IAAG,KAAK,EAAE,QAAQ,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE;AACtF,MAAM,WAAW,mBAAmB;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE;AAErE;;qEAEqE;AACr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F"}
@@ -0,0 +1,44 @@
1
+ const toVariable = (code) => code.replace(/-([a-z])/g, (_m, c) => c.toUpperCase());
2
+ /** Lower one domain constraint to a spine `Constraint` (range for numbers, enum for bool/string). */
3
+ export function treasuryConstraint(input) {
4
+ const variable = toVariable(input.code);
5
+ const domain = typeof input.value === 'number'
6
+ ? { kind: 'range', min: 0, max: input.value, unit: input.code.endsWith('-bps') ? 'bps' : 'unit' }
7
+ : { kind: 'enum', values: [String(input.value)] };
8
+ return {
9
+ id: `c:${variable}`,
10
+ variable,
11
+ domain,
12
+ source: input.source,
13
+ // policy-imposed constraints are ALWAYS hard (a policy ceiling can't be downgraded to a preference).
14
+ strength: input.source === 'policy-imposed' ? 'hard' : (input.strength ?? 'hard'),
15
+ rationale: input.rationale,
16
+ };
17
+ }
18
+ /** Build a spine ConstraintSet from domain constraints (splits hard/soft). */
19
+ export function buildTreasuryConstraintSet(inputs) {
20
+ const constraints = inputs.map(treasuryConstraint);
21
+ return {
22
+ hardConstraints: constraints.filter((c) => c.strength === 'hard'),
23
+ softConstraints: constraints.filter((c) => c.strength === 'soft'),
24
+ };
25
+ }
26
+ /** Construct a `TreasuryIntent` — places domain constraints into the spine `hasConstraintSet`. */
27
+ export function buildTreasuryIntent(args) {
28
+ const now = args.now ?? (() => new Date(0).toISOString());
29
+ return {
30
+ id: args.id,
31
+ direction: 'give', // a treasury intent commits/spends value to reach an outcome
32
+ object: `treasury:${args.payload.kind}`,
33
+ intentType: args.payload.kind,
34
+ expressedBy: args.expressedBy,
35
+ addressedTo: args.addressedTo ?? [],
36
+ hasConstraintSet: buildTreasuryConstraintSet(args.constraints ?? []),
37
+ hasAssumptionSet: args.assumptions,
38
+ visibility: args.visibility ?? 'PrivateCommitment',
39
+ status: 'expressed',
40
+ payload: args.payload,
41
+ createdAt: now(),
42
+ };
43
+ }
44
+ //# sourceMappingURL=intent-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent-types.js","sourceRoot":"","sources":["../../src/intents/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EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;QACjE,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;KAClE,CAAC;AACJ,CAAC;AAaD,kGAAkG;AAClG,MAAM,UAAU,mBAAmB,CAAC,IAA6B;IAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1D,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,SAAS,EAAE,MAAM,EAA0B,6DAA6D;QACxG,MAAM,EAAE,YAAY,IAAI,CAAC,OAAO,CAAC,IAAI,EAAS;QAC9C,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;QAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;QACnC,gBAAgB,EAAE,0BAA0B,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;QACpE,gBAAgB,EAAE,IAAI,CAAC,WAAW;QAClC,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,mBAAmB;QAClD,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,SAAS,EAAE,GAAG,EAAE;KACjB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { ResolvedOrder } from '@agenticprimitives/intent-resolver';
2
+ import type { Constraint, NamedAssumption } from '@agenticprimitives/intent-marketplace';
3
+ import type { AcceptanceCondition, TreasuryIntent } from './intent-types.js';
4
+ /** Canonicalized constraints after normalization (policy-imposed forced hard; deduped by variable). */
5
+ export interface CanonicalConstraints {
6
+ hard: Constraint[];
7
+ soft: Constraint[];
8
+ }
9
+ /** A free variable a solver may bind (e.g. chosen rail, quote, slippage actually used). */
10
+ export interface OrderVariable {
11
+ name: string;
12
+ description?: string;
13
+ }
14
+ /** A normalized order step placeholder (the solver fills `capability`/`inputs`; PR-C leaves steps empty). */
15
+ export interface OrderStep {
16
+ stepId: string;
17
+ capability?: string;
18
+ chain?: string;
19
+ inputs?: Record<string, unknown>;
20
+ dependsOn?: string[];
21
+ }
22
+ export interface OrderPaymentRef {
23
+ obligationId?: string;
24
+ asset?: string;
25
+ amount?: string;
26
+ }
27
+ export interface ResolvedTreasuryOrder extends ResolvedOrder<TreasuryIntent> {
28
+ canonicalConstraints: CanonicalConstraints;
29
+ expandedAssumptions: NamedAssumption[];
30
+ steps: OrderStep[];
31
+ variables: OrderVariable[];
32
+ dependencies: string[];
33
+ payments: OrderPaymentRef[];
34
+ assumptions: NamedAssumption[];
35
+ failurePolicies: string[];
36
+ acceptanceConditions: AcceptanceCondition[];
37
+ }
38
+ //# sourceMappingURL=resolved-treasury-order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolved-treasury-order.d.ts","sourceRoot":"","sources":["../../src/intents/resolved-treasury-order.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE7E,uGAAuG;AACvG,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,IAAI,EAAE,UAAU,EAAE,CAAC;CACpB;AAED,2FAA2F;AAC3F,MAAM,WAAW,aAAa;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE;AAErE,6GAA6G;AAC7G,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAAG,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;AAE3F,MAAM,WAAW,qBAAsB,SAAQ,aAAa,CAAC,cAAc,CAAC;IAC1E,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,mBAAmB,EAAE,eAAe,EAAE,CAAC;IAEvC,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,oBAAoB,EAAE,mBAAmB,EAAE,CAAC;CAC7C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=resolved-treasury-order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolved-treasury-order.js","sourceRoot":"","sources":["../../src/intents/resolved-treasury-order.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ import type { IIntentResolver } from '@agenticprimitives/intent-resolver';
2
+ import type { Address } from '@agenticprimitives/types';
3
+ import type { ResolutionReceipt } from '@agenticprimitives/intent-marketplace';
4
+ import type { TreasuryIntent } from './intent-types.js';
5
+ import type { ResolvedTreasuryOrder } from './resolved-treasury-order.js';
6
+ /** The full resolution result — ALWAYS carries a receipt (RR-INV-04); `order` is null unless `resolved`. */
7
+ export interface TreasuryResolution {
8
+ status: 'resolved' | 'needs-confirmation' | 'rejected';
9
+ receipt: ResolutionReceipt;
10
+ order: ResolvedTreasuryOrder | null;
11
+ }
12
+ export interface TreasuryResolverOptions {
13
+ resolverAgentId: Address;
14
+ version?: string;
15
+ policyVersion?: string;
16
+ /** ISO clock for receipt timestamps (injected; no ambient Date). */
17
+ now?: () => string;
18
+ /** Unix-seconds clock for the validUntil check. */
19
+ nowSeconds?: () => number;
20
+ /** Variables of inferred constraints the caller has already confirmed (clears the gate for them). */
21
+ confirmedVariables?: string[];
22
+ /** Below this, resolution requires confirmation. Default 1.0 (any unconfirmed inference gates). */
23
+ minConfidence?: number;
24
+ }
25
+ export declare class TreasuryIntentResolver implements IIntentResolver<TreasuryIntent, TreasuryResolution> {
26
+ private readonly opts;
27
+ constructor(opts: TreasuryResolverOptions);
28
+ resolve(intent: TreasuryIntent): Promise<TreasuryResolution>;
29
+ }
30
+ //# sourceMappingURL=treasury-intent-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treasury-intent-resolver.d.ts","sourceRoot":"","sources":["../../src/intents/treasury-intent-resolver.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAc,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAwB,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAOhG,4GAA4G;AAC5G,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,UAAU,GAAG,oBAAoB,GAAG,UAAU,CAAC;IACvD,OAAO,EAAE,iBAAiB,CAAC;IAC3B,KAAK,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC;IAC1B,qGAAqG;IACrG,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,mGAAmG;IACnG,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAqBD,qBAAa,sBAAuB,YAAW,eAAe,CAAC,cAAc,EAAE,kBAAkB,CAAC;IACpF,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,uBAAuB;IAEpD,OAAO,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAoFnE"}
@@ -0,0 +1,113 @@
1
+ const KINDS = new Set([
2
+ 'transfer', 'swap', 'bridge', 'target-allocation', 'yield-allocation',
3
+ 'debt-management', 'liquidity-management', 'perpetual-position', 'prediction-order', 'strategy-run',
4
+ ]);
5
+ const PRECEDENCE = { 'policy-imposed': 3, 'user-asserted': 2, 'llm-inferred': 1 };
6
+ /** Dedupe by variable: highest-precedence source wins; ties on a range take the tighter max. */
7
+ function canonicalize(hard, soft) {
8
+ const pick = (list) => {
9
+ const byVar = new Map();
10
+ for (const c of list) {
11
+ const cur = byVar.get(c.variable);
12
+ if (!cur) {
13
+ byVar.set(c.variable, c);
14
+ continue;
15
+ }
16
+ if (PRECEDENCE[c.source] > PRECEDENCE[cur.source]) {
17
+ byVar.set(c.variable, c);
18
+ continue;
19
+ }
20
+ if (PRECEDENCE[c.source] === PRECEDENCE[cur.source] && c.domain.kind === 'range' && cur.domain.kind === 'range') {
21
+ if (Number(c.domain.max) < Number(cur.domain.max))
22
+ byVar.set(c.variable, c); // tighter ceiling wins
23
+ }
24
+ }
25
+ return [...byVar.values()];
26
+ };
27
+ return { hard: pick(hard), soft: pick(soft) };
28
+ }
29
+ export class TreasuryIntentResolver {
30
+ opts;
31
+ constructor(opts) {
32
+ this.opts = opts;
33
+ }
34
+ async resolve(intent) {
35
+ const now = this.opts.now ?? (() => new Date(0).toISOString());
36
+ const nowSeconds = this.opts.nowSeconds ?? (() => 0);
37
+ const minConfidence = this.opts.minConfidence ?? 1.0;
38
+ const confirmed = new Set(this.opts.confirmedVariables ?? []);
39
+ const payload = intent.payload;
40
+ // ── structural validation (fail-closed) ──
41
+ const policyChecks = [];
42
+ const reject = (name, rationale) => {
43
+ policyChecks.push({ name, passed: false, rationale });
44
+ };
45
+ if (!payload)
46
+ reject('payload-present', 'intent has no treasury payload');
47
+ if (payload && !payload.idempotencyKey)
48
+ reject('idempotency-key-present', 'non-read treasury intent needs an idempotencyKey');
49
+ if (payload && !KINDS.has(payload.kind))
50
+ reject('known-kind', `unknown treasury intent kind: ${payload.kind}`);
51
+ // NEW-TSA-3: `validUntil <= now` is FALSE for NaN / undefined / non-numeric — a garbage validUntil would
52
+ // pass the not-expired check and yield a never-expiring order (EXT-ENT-1 NaN class). Require a finite,
53
+ // in-window value (fail-closed, ADR-0013).
54
+ if (payload && (!Number.isFinite(payload.validUntil) || payload.validUntil <= nowSeconds()))
55
+ reject('not-expired', `intent expired or invalid validUntil (validUntil ${payload.validUntil}, now ${nowSeconds()})`);
56
+ const canonical = canonicalize(intent.hasConstraintSet.hardConstraints, intent.hasConstraintSet.softConstraints);
57
+ // ── confirmation gate (RR-INV-01): inferred HARD constraints must be confirmed ──
58
+ const inferredHard = canonical.hard.filter((c) => c.source === 'llm-inferred');
59
+ const inferredHardUnconfirmed = inferredHard.filter((c) => !confirmed.has(c.variable));
60
+ const totalHard = canonical.hard.length;
61
+ const confidence = totalHard === 0 ? 1 : 1 - inferredHardUnconfirmed.length / totalHard;
62
+ const structurallyOk = policyChecks.every((c) => c.passed);
63
+ policyChecks.push({ name: 'inferred-constraints-confirmed', passed: inferredHardUnconfirmed.length === 0, rationale: inferredHardUnconfirmed.map((c) => c.variable).join(', ') || undefined });
64
+ const requiresUserConfirmation = inferredHardUnconfirmed.length > 0 || confidence < minConfidence;
65
+ const riskFlags = inferredHardUnconfirmed.length > 0 ? ['unconfirmed-inferred-hard-constraints'] : [];
66
+ // ── expand assumptions → validation requirements ──
67
+ const assumptionSet = intent.hasAssumptionSet;
68
+ const expandedAssumptions = assumptionSet?.namedAssumptions ?? [];
69
+ const validationRequirements = [
70
+ ...(assumptionSet?.requiredValidations ?? []),
71
+ ...expandedAssumptions.filter((a) => a.trustLevel === 'asserted').map((a) => `verify-assumption:${a.name}`),
72
+ ];
73
+ const status = !structurallyOk ? 'rejected' : requiresUserConfirmation ? 'needs-confirmation' : 'resolved';
74
+ const receipt = {
75
+ id: `rr:${intent.id}`,
76
+ type: 'ResolutionReceipt',
77
+ version: '1.0',
78
+ inputRefs: { sourceIntentRef: intent.id, contextRefs: [] },
79
+ resolver: {
80
+ agentId: this.opts.resolverAgentId,
81
+ agentClass: 'resolver',
82
+ version: this.opts.version ?? '1.0.0',
83
+ policyVersion: this.opts.policyVersion ?? 'treasury-resolver-1',
84
+ },
85
+ outputIntentRef: intent.id,
86
+ constraintSetRef: `cs:${intent.id}`,
87
+ assumptionSetRef: assumptionSet ? `as:${intent.id}` : undefined,
88
+ confidence,
89
+ unresolvedAmbiguities: inferredHardUnconfirmed.length > 0 ? inferredHardUnconfirmed.map((c) => c.variable) : undefined,
90
+ requiresUserConfirmation,
91
+ policyChecks,
92
+ riskFlags,
93
+ createdAt: now(),
94
+ };
95
+ const order = status !== 'resolved' || !payload ? null : {
96
+ resolvedFromIntentId: intent.id,
97
+ canonicalConstraints: canonical,
98
+ expandedAssumptions,
99
+ validationRequirements,
100
+ source: intent,
101
+ // ERC-7683-shaped order surface — the solver (PR-D) fills the concrete step DAG.
102
+ steps: [],
103
+ variables: [],
104
+ dependencies: [],
105
+ payments: (payload.inputs ?? []).map((i) => ({ asset: i.asset.address ?? i.asset.type, amount: i.amount })),
106
+ assumptions: expandedAssumptions,
107
+ failurePolicies: [],
108
+ acceptanceConditions: payload.acceptance,
109
+ };
110
+ return { status, receipt, order };
111
+ }
112
+ }
113
+ //# sourceMappingURL=treasury-intent-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treasury-intent-resolver.js","sourceRoot":"","sources":["../../src/intents/treasury-intent-resolver.ts"],"names":[],"mappings":"AAaA,MAAM,KAAK,GAAG,IAAI,GAAG,CAAqB;IACxC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,kBAAkB;IACrE,iBAAiB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,cAAc;CACpG,CAAC,CAAC;AAuBH,MAAM,UAAU,GAAyC,EAAE,gBAAgB,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC;AAExH,gGAAgG;AAChG,SAAS,YAAY,CAAC,IAAkB,EAAE,IAAkB;IAC1D,MAAM,IAAI,GAAG,CAAC,IAAkB,EAAgB,EAAE;QAChD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC5C,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YAClC,IAAI,CAAC,GAAG,EAAE,CAAC;gBAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;gBAAC,SAAS;YAAC,CAAC;YACjD,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;gBAAC,SAAS;YAAC,CAAC;YAC1F,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,I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M,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YAC3G,WAAW,EAAE,mBAAmB;YAChC,eAAe,EAAE,EAAE;YACnB,oBAAoB,EAAE,OAAO,CAAC,UAAU;SACzC,CAAC;QAEF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,31 @@
1
+ import { type AssetRef, type PaymentMandate, type PaymentMandateMode, type PaymentRail } from '@agenticprimitives/payments';
2
+ import type { Address } from '@agenticprimitives/types';
3
+ import type { ResolvedTreasuryOrder } from '../intents/resolved-treasury-order.js';
4
+ export type Hex32 = `0x${string}`;
5
+ export interface BuildTreasuryMandateArgs {
6
+ /** A RESOLVED order (only produced when resolution passed the confirmation gate). */
7
+ order: ResolvedTreasuryOrder;
8
+ payer: Address;
9
+ payee: Address;
10
+ /** Defaults to the payer (the treasury authorizes its own spend). */
11
+ granter?: Address;
12
+ asset: AssetRef;
13
+ chain: number;
14
+ /** Exact charge amount (smallest unit). */
15
+ amount: bigint;
16
+ /** If set, the mandate is a RANGE policy [0, maxAmount] instead of exact (e.g. slippage headroom). */
17
+ maxAmount?: bigint;
18
+ rail?: PaymentRail;
19
+ mode?: PaymentMandateMode;
20
+ nonce: bigint;
21
+ validFrom: number;
22
+ expiresAt: number;
23
+ maxRedemptions?: number;
24
+ /** keccak of the human reason / order digest — computed by the host. */
25
+ reasonHash: Hex32;
26
+ delegationRef?: Hex32;
27
+ }
28
+ /** Build an UNSIGNED PaymentMandate bound to the resolved order's intent. Fail-closed: throws if the order
29
+ * carries no intent id (nothing to bind to) or the validity window is inverted. */
30
+ export declare function buildTreasuryPaymentMandate(args: BuildTreasuryMandateArgs): PaymentMandate;
31
+ //# sourceMappingURL=order-to-mandate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-to-mandate.d.ts","sourceRoot":"","sources":["../../src/payments/order-to-mandate.ts"],"names":[],"mappings":"AAMA,OAAO,EAEc,KAAK,QAAQ,EAA2B,KAAK,cAAc,EAAE,KAAK,kBAAkB,EACvG,KAAK,WAAW,EACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAO,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAEnF,MAAM,MAAM,KAAK,GAAG,KAAK,MAAM,EAAE,CAAC;AAElC,MAAM,WAAW,wBAAwB;IACvC,qFAAqF;IACrF,KAAK,EAAE,qBAAqB,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,qEAAqE;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,sGAAsG;IACtG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,UAAU,EAAE,KAAK,CAAC;IAClB,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB;AAED;oFACoF;AACpF,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,wBAAwB,GAAG,cAAc,CAqC1F"}
@@ -0,0 +1,46 @@
1
+ // Bind a resolved treasury order → a payments PaymentMandate (spec 284 + spec 243). The mandate is the
2
+ // payer's bounded spend authority for the obligation the order represents; it is CONTEXT-BOUND to the
3
+ // order's intent (ContextBinding.intentId, satisfying PMT-3.1) so the receipt later links intent → order →
4
+ // settlement. Returns an UNSIGNED mandate (signature '0x') — the host signs it via the connect-treasury /
5
+ // payments signing path. Pure + injectable: nonce + validity + reasonHash are supplied (no ambient
6
+ // Date/randomness), so the result is deterministic + unit-testable.
7
+ import { assertContextBindingValid, computeMandateId, } from '@agenticprimitives/payments';
8
+ /** Build an UNSIGNED PaymentMandate bound to the resolved order's intent. Fail-closed: throws if the order
9
+ * carries no intent id (nothing to bind to) or the validity window is inverted. */
10
+ export function buildTreasuryPaymentMandate(args) {
11
+ const intentId = args.order.resolvedFromIntentId;
12
+ if (!intentId)
13
+ throw new Error('[treasury/order-to-mandate] resolved order has no intent id to bind to');
14
+ if (args.expiresAt <= args.validFrom)
15
+ throw new Error('[treasury/order-to-mandate] expiresAt must be after validFrom');
16
+ const rail = args.rail ?? 'x402';
17
+ const amountPolicy = args.maxAmount !== undefined
18
+ ? { kind: 'range', minAmount: 0n, maxAmount: args.maxAmount, asset: args.asset, chain: args.chain }
19
+ : { kind: 'exact', amount: args.amount, asset: args.asset, chain: args.chain };
20
+ const kind = args.order.source.payload?.kind;
21
+ const mandateConstraints = {
22
+ maxAggregateAmount: args.maxAmount ?? args.amount,
23
+ ...(kind ? { categories: [kind] } : {}),
24
+ };
25
+ const contextBinding = { intentId, chain: args.chain, asset: args.asset, nonce: args.nonce, validFrom: args.validFrom, expiresAt: args.expiresAt };
26
+ assertContextBindingValid(contextBinding); // PMT-3.1 — intentId present
27
+ return {
28
+ mandateId: computeMandateId({ payer: args.payer, nonce: args.nonce, rail, chain: args.chain }),
29
+ payer: args.payer,
30
+ payee: args.payee,
31
+ granter: args.granter ?? args.payer,
32
+ rail,
33
+ amountPolicy,
34
+ mandateConstraints,
35
+ nonce: args.nonce,
36
+ maxRedemptions: args.maxRedemptions ?? 1,
37
+ validFrom: args.validFrom,
38
+ expiresAt: args.expiresAt,
39
+ contextBinding,
40
+ delegationRef: args.delegationRef,
41
+ mode: args.mode ?? 'closed',
42
+ reasonHash: args.reasonHash,
43
+ signature: '0x',
44
+ };
45
+ }
46
+ //# sourceMappingURL=order-to-mandate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-to-mandate.js","sourceRoot":"","sources":["../../src/payments/order-to-mandate.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,sGAAsG;AACtG,2GAA2G;AAC3G,0GAA0G;AAC1G,mGAAmG;AACnG,oEAAoE;AACpE,OAAO,EACL,yBAAyB,EAAE,gBAAgB,GAG5C,MAAM,6BAA6B,CAAC;AA8BrC;oFACoF;AACpF,MAAM,UAAU,2BAA2B,CAAC,IAA8B;IACxE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IACjD,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;IACzG,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAEvH,MAAM,IAAI,GAAgB,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC;IAC9C,MAAM,YAAY,GAAiB,IAAI,CAAC,SAAS,KAAK,SAAS;QAC7D,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;QACnG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAEjF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,E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 import { type PrimitivePlan } from '@agenticprimitives/service-agent';
2
+ /** Public read: a single provider step, output passthrough. No authority gates (public data). */
3
+ export declare function readPlan(id: string, capability: string, args: Record<string, unknown>): PrimitivePlan;
4
+ /** Authenticated read: caller-entitlement gate, then the read. (Reading a managed account's state.) */
5
+ export declare function authedReadPlan(id: string, capability: string, args: Record<string, unknown>, action: string, resource: string | undefined): PrimitivePlan;
6
+ /** Signing: full gating (entitlement ∩ delegation ∩ policy), then a provider signature. No ledger. */
7
+ export declare function signPlan(id: string, args: Record<string, unknown>, action: string, resource: string | undefined): PrimitivePlan;
8
+ export interface SpendPlanOpts {
9
+ id: string;
10
+ /** The value-moving provider capability (transfer/swap/perp/prediction/raw-tx). */
11
+ capability: string;
12
+ action: string;
13
+ resource: string | undefined;
14
+ stepArgs: Record<string, unknown>;
15
+ /** Ledger reservation args — reserve precedes execute, finalize follows settle (double-spend guard). */
16
+ ledger: {
17
+ accountId: string;
18
+ asset: string;
19
+ amount: string;
20
+ idempotencyKey: string;
21
+ };
22
+ }
23
+ /** Value-moving skill: full gating → ledger.reserve → provider execute → ledger.finalize → output. */
24
+ export declare function spendPlan(opts: SpendPlanOpts): PrimitivePlan;
25
+ /** Admin/manage skill (delegation mint/revoke, entitlement issue/consume): full gating, no ledger. */
26
+ export declare function adminPlan(id: string, capability: string, args: Record<string, unknown>, action: string, resource: string | undefined): PrimitivePlan;
27
+ //# sourceMappingURL=plans.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAG1F,iGAAiG;AACjG,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAErG;AAED,uGAAuG;AACvG,wBAAgB,cAAc,CAAC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