Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Policies

Policies are automated rules that govern what actions are allowed through the Grimoire Platform. Every action plan validated through the API is checked against your active policies.

What Policies Do

Policies let you define guardrails that are enforced automatically:

  • Limit trade sizes — reject swaps above a threshold
  • Restrict venues — only allow specific protocols
  • Require approval — flag large moves for manual review
  • Cap slippage — reject trades with excessive slippage
  • Control risk — enforce health factor minimums for lending positions

Policies are checked during validation (POST /v1/validate) and as part of the run flow (POST /v1/run).

Policy Rules

A policy contains one or more rules. Each rule specifies a condition that is evaluated against the action plan.

Example rules:

Rule CodeDescriptionExample Params
ALLOWED_CHAINSWhitelist of permitted chains{"chains": ["ethereum", "base"]}
ALLOWED_VENUESWhitelist of permitted venue adapters{"venues": ["uniswap_v3", "aave_v3"]}
ALLOWED_ACTIONSWhitelist of permitted action types{"actions": ["swap", "deposit"]}
ALLOWED_TOKENSWhitelist of permitted tokens{"tokens": ["USDC", "ETH"]}
MAX_ACTIONSMaximum number of actions per plan{"max": 5}
MAX_POSITION_SIZEMaximum value for any single action{"max": 50000}
MAX_LEVERAGEMaximum leverage ratio{"max": 3}
MAX_SLIPPAGEMaximum allowed slippage{"max": 0.01}
MAX_GASMaximum gas cost{"max": 0.05}
MAX_PRICE_IMPACTMaximum price impact{"max": 0.02}

Managing Policies

Create a Policy

Create Policy
curl -X POST https://api.grimoire.run/v1/partners/YOUR_PARTNER_ID/policies \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production Trading Limits",
    "rules": [
      {
        "code": "MAX_POSITION_SIZE",
        "phase": "preview",
        "params": { "max": 50000 }
      },
      {
        "code": "MAX_SLIPPAGE",
        "phase": "preview",
        "params": { "max": 0.01 }
      },
      {
        "code": "ALLOWED_VENUES",
        "phase": "compile",
        "params": { "venues": ["uniswap_v3", "aave_v3", "morpho_blue"] }
      }
    ]
  }'

Update a Policy

Update Policy
curl -X PUT https://api.grimoire.run/v1/partners/YOUR_PARTNER_ID/policies/POLICY_ID \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Trading Limits",
    "rules": [
      {
        "code": "MAX_POSITION_SIZE",
        "phase": "preview",
        "params": { "max": 100000 }
      }
    ]
  }'

Get a Policy

Get Policy
curl https://api.grimoire.run/v1/partners/YOUR_PARTNER_ID/policies/POLICY_ID \
  -H "x-api-key: YOUR_API_KEY"

List All Policies

List Policies
curl https://api.grimoire.run/v1/partners/YOUR_PARTNER_ID/policies \
  -H "x-api-key: YOUR_API_KEY"

Endpoints

MethodEndpointDescription
POST/v1/partners/{partnerId}/policiesCreate a new policy
PUT/v1/partners/{partnerId}/policies/{policyId}Update a policy
GET/v1/partners/{partnerId}/policies/{policyId}Get a specific policy
GET/v1/partners/{partnerId}/policiesList all policies

How Policy Evaluation Works

When an action plan is validated:

  1. All active policies for your partner account are loaded
  2. Each rule is evaluated against the action plan
  3. Results are returned per-rule with pass/fail and details
Policy Results
{
  "policy_result": {
    "version": "1",
    "passed_rules": ["ALLOWED_VENUES", "MAX_SLIPPAGE"],
    "failed_rules": ["MAX_POSITION_SIZE"]
  }
}