Skip to main content

Policies

Policies are rule-based controls that govern transaction execution. They can allow, deny, or require approval for intents based on flexible criteria.

Policy Structure

Policy Rules

Agentic Wallet supports 11 rule types:

Spending Limits

Example:
Behavior:
  • maxLamportsPerTx: Hard limit, transaction denied if exceeded
  • maxLamportsPerDay: Cumulative daily limit, resets at UTC midnight
  • requireApprovalAboveLamports: Moves to approval_gate status if exceeded

Address Controls

Address Allowlist

Only allow transfers to specific addresses.

Address Blocklist

Deny transfers to specific addresses.

Program and Token Controls

Program Allowlist

Restrict which Solana programs can be invoked.

Token Allowlist

Restrict token transfers to specific mints.

Protocol Allowlist

Restricts execution to specific protocol adapters.

Rate Limiting

Example:
Limits to 10 transactions per 60-second rolling window.

Time Windows

Only allow transactions during UTC business hours (9 AM - 5 PM).

Slippage Control

Reject swaps with slippage exceeding 100 basis points (1%).

Protocol Risk Rules

Example:
Checks:
  • maxSlippageBps: Protocol-specific slippage limit
  • maxPoolConcentrationBps: Reject if pool is too concentrated
  • allowedPools: Whitelist specific liquidity pools
  • allowedPrograms: Restrict program IDs for this protocol
  • oracleDeviationBps: Compare quoted price vs oracle, require approval if deviation exceeds threshold

Portfolio Risk Rules

Example:
Checks:
  • maxDailyLossLamports: Deny if projected loss exceeds limit
  • maxDrawdownLamports: Deny if drawdown from high-water mark exceeds limit
  • maxExposureBpsPerToken: Require approval if token concentration > limit (in bps)
  • maxExposureBpsPerProtocol: Require approval if protocol exposure > limit
Portfolio risk checks require the caller to compute projected values and pass them in the evaluation request.

Policy Evaluation

Policies are evaluated before transaction execution:

Evaluation Response

Example:

Evaluation Flow

Risk Tier Deduction

Critical tier automatically triggers require_approval.

Policy Versioning

Policies use incremental versioning:

Listing Versions

Returns all historical versions of a policy.

Retrieving Specific Version

Returns version 3 of the policy.

Policy Migration

Migrate policies to new versions with transformations:

Migration Modes

Validate and normalize existing rules without adding new ones.
Add default protocol_risk and portfolio_risk rules if missing:

Approval Gates

When a policy returns require_approval, the transaction enters approval_gate status:

Manual Approval

Approving resumes the pipeline from the approval gate. Rejecting moves the transaction to failed status.

Pending Approvals

List all transactions awaiting approval:

Compatibility Check

Validate rule compatibility before creating policies:
Response:

Policy State Management

The policy evaluator maintains state for stateful rules:
Persisted state:
  • rateLimitEvents: Rolling window of transaction timestamps per wallet/agent
  • dailySpendByWallet: Cumulative spending per wallet per day (keyed by walletId:YYYY-MM-DD)

Best Practices

  1. Always set spending limits for autonomous wallets
  2. Use address allowlists for high-value recipient addresses
  3. Combine multiple rule types for defense in depth
  4. Set rate limits to prevent runaway execution
  5. Use time windows for scheduled operations
  6. Enable protocol_risk rules for DeFi operations
  7. Monitor approval queue length
  1. Start with strict policies and relax as needed
  2. Use requireApprovalAboveLamports for human oversight
  3. Test policies with paper trades before live execution
  4. Version policies on every change for audit trail
  5. Document policy intent in the name field
  6. Combine protocol_allowlist with protocol_risk for granular control
  1. Never disable all policies on production wallets
  2. Use program_allowlist to prevent malicious contract calls
  3. Set conservative oracle deviation thresholds
  4. Implement portfolio exposure limits
  5. Require approval for critical risk tier operations
  6. Audit policy changes and maintain version history

Source Code Reference

Policy functionality is implemented in:
  • services/policy-engine/src/engine/policy-evaluator.ts - Evaluation engine (services/policy-engine/src/engine/policy-evaluator.ts:1)
  • services/policy-engine/src/index.ts - Policy API (services/policy-engine/src/index.ts:1)
  • packages/common/src/schemas/policy.ts - Rule type definitions (packages/common/src/schemas/policy.ts:1)