Policy Evaluation Flow
All spend-capable intents pass through policy evaluation before signing. This ensures that even autonomous agents operate within defined safety boundaries.1
Intent Submission
Agent or client submits transaction intent:
2
Schema Validation
Gateway validates request against Zod schemas in
packages/common3
Transaction Creation
Transaction-engine creates transaction record in
pending status4
Build & Simulate
Protocol adapter builds transaction, RPC pool simulates execution
5
Policy Evaluation
Transaction transitions to
policy_eval status:6
Rule Evaluation
Policy engine loads all active policies for wallet and evaluates each rule
7
Decision Output
Policy engine returns one of three decisions:
allow: Proceed to signingdeny: Reject transaction immediatelyrequire_approval: Pause at approval gate
8
Signing or Approval Gate
- If
allow: Transaction proceeds tosigningstatus - If
deny: Transaction fails withstatus=failed - If
require_approval: Transaction pauses atapproval_gatestatus
Read-only intents like
query_balance and query_positions skip policy evaluation and signing, confirming immediately after simulation.Policy Decision Types
The policy engine returns structured decisions:Allow
Transaction proceeds to signing without human intervention.- All policy rules passed
- Risk tier is acceptable
- No approval thresholds exceeded
Deny
Transaction rejected immediately, never reaches signing stage.- At least one policy rule failed with hard constraint
- Transaction fails with
errorCode: "POLICY_VIOLATION" - Reason strings explain which rule(s) failed
Require Approval
Transaction pauses at approval gate, waiting for operator decision.- Transaction meets soft thresholds requiring human review
- Status becomes
approval_gate - Operator must call
/approveor/rejectendpoint
Risk Tier Classification
The policy engine automatically assigns a risk tier to each intent:Low
Standard transfers, balance queries
Medium
Swaps, staking, lending operations
High
Large amounts (> 2 SOL)
Critical
Flash loans, CPI calls, custom instructions
Policy Rule Types
Policies consist of arrays of typed rules. Each rule evaluates independently, and the most restrictive decision wins.Spending Limit
Controls transaction amounts and daily spend:maxLamportsPerTx: Deny if transaction exceeds this amountmaxLamportsPerDay: Track daily spend per wallet, deny if cumulative spend exceeds limitrequireApprovalAboveLamports: Require approval if amount at or above threshold
- Spending tracked per wallet per UTC day (
YYYY-MM-DD) - State persisted in
services/policy-engine/data/policy-evaluator-snapshot.json - Spending only incremented after
allowdecision
Address Allowlist
Restrict transactions to approved destination addresses:- If
destinationfield present, must be in allowlist - Deny if destination not in list
- Allow if no destination (e.g., staking operations)
Address Blocklist
Block transactions to specific addresses:- Deny if
destinationis in blocklist - Allow otherwise
Program Allowlist
Restrict which Solana programs can be invoked:- Transaction builder extracts all program IDs from transaction
- Deny if any program ID not in allowlist
- Useful for restricting to known safe programs
Token Allowlist
Restrict which SPL tokens can be transferred:- If
tokenMintpresent, must be in allowlist - Deny if token mint not allowed
- Allow if no token mint (native SOL transfers)
Protocol Allowlist
Restrict which protocol adapters can be used:- Check
protocolfield in intent - Deny if protocol not in allowlist
- Useful for limiting agents to specific DeFi protocols
Rate Limit
Limit transaction frequency per wallet/agent:- Track transaction timestamps per
walletId:agentIdkey - Sliding window: filter events older than
windowSeconds - Deny if count exceeds
maxTxin current window - Add current transaction to event log
Time Window
Restrict transactions to specific UTC hours:- Extract UTC hour from transaction timestamp
- Allow if hour within range (inclusive)
- Handle wrap-around:
startHourUtc=22, endHourUtc=6means 10 PM to 6 AM - Useful for business-hours-only execution
Max Slippage
Limit slippage tolerance for swaps:- Check
slippageBpsfield in intent - Deny if slippage exceeds
maxBps - Protects against sandwich attacks and excessive MEV
Protocol Risk
Granular controls per protocol:- Only applies to intents with matching
protocolfield maxSlippageBps: Protocol-specific slippage limitmaxPoolConcentrationBps: Limit concentration risk in liquidity poolsallowedPools: Whitelist of pool addressesallowedPrograms: Whitelist of program IDs for this protocoloracleDeviationBps: Require approval if quoted price deviates from oracle by this amount
Portfolio Risk
Portfolio-wide risk controls:maxDrawdownLamports: Deny if projected drawdown exceeds limitmaxDailyLossLamports: Deny if projected daily loss exceeds limitmaxExposureBpsPerToken: Require approval if token exposure exceeds percentagemaxExposureBpsPerProtocol: Require approval if protocol exposure exceeds percentage
Portfolio risk rules require transaction-engine to provide projected risk metrics in the evaluation request. These are computed from position tracking and current market data.
Approval Gate Workflow
When a policy returnsrequire_approval, the transaction enters the approval gate:
1
Transaction Paused
Transaction status becomes
approval_gate:2
List Pending Approvals
Operator queries pending approvals:
3
Review Transaction
Operator reviews transaction details, policy reasons, and risk tier
4
Approve or Reject
Operator makes decision:Approve:Reject:
5
Execution Continues or Fails
- If approved: Transaction proceeds to
signingstatus - If rejected: Transaction fails with
status=failed
CLI Approval Commands
Policy Versioning
Policies support versioning for safe updates:Version History
Policy Migration
Migrate between policy versions with safety checks:safe: Only migrate if target version is more restrictiveforce: Migrate regardless of restrictivenessdry-run: Simulate migration without applying
Compatibility Check
Test rule compatibility before creating policy:Policy versioning is automatic. Every
PUT /api/v1/policies/:policyId creates a new version while preserving old versions for audit purposes.Policy Evaluation Testing
Test policy decisions without submitting real transactions:Best Practices
1
Layer Multiple Rule Types
Combine spending limits, allowlists, and rate limits for defense in depth
2
Start Restrictive
Begin with tight limits and loosen gradually based on agent behavior
3
Use Approval Thresholds
Set
requireApprovalAboveLamports rather than hard denials for large amounts4
Monitor Policy Decisions
Query audit events to track policy denials and approvals
5
Test Before Deployment
Use
policy evaluate and strategy backtest to validate policies6
Version Control Policies
Keep policy definitions in source control, track changes
7
Protocol-Specific Rules
Use
protocol_risk rules for fine-grained DeFi controls8
Rate Limit Autonomous Agents
Always attach rate limit rules to autonomous agents
Related Pages
Security Overview
Trust boundaries and protection layers
Key Management
Private key isolation and storage