> ## Documentation Index
> Fetch the complete documentation index at: https://docs.route.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# Delegated execution

> An owner signs a policy once; an agent (a bot, or Route itself for stop rules) trades within it.

Robinhood Chain, switched on per partner key. For Solana see [agent trades on Solana](https://docs.route.fun/solana/orders-and-agents.md#agent-trades).

The RouteDelegate contract checks every trade against the policy the owner signed: which tokens, how much per trade and in
total, a price floor per pair, the slippage cap, the minimum interval and the expiry. Output always goes to the policy's
recipient. Each trade pays its own gas from the input, unless Route sponsors gas for your key.

**1. Prepare**

[`POST /delegate/prepare`](https://docs.route.fun/api-reference/delegate-prepare) with `owner`, `agent`, `tokensIn` (each `token`, `maxPerTrade`,
`maxTotal`), `tokensOut` and `expiry`. Optional: `recipient`, `floors` (default: 10% under Route's price now, or set
`floorBps` 100 to 5000), `maxSlippageBps` (default 100, at most 300), `minInterval`. Returns the policy, `typedData`, and
the Permit2 `permits` and `approvals` each input token needs.

**2. Sign and register**

The owner signs `typedData` and each permit, then [`POST /delegate/policies`](https://docs.route.fun/api-reference/delegate-register) with
`{ "policy", "signature", "permits": [{ "message", "signature" }] }`. Returns the policy `hash`.

**3. Trade**

For each trade, the agent calls [`GET /delegate/quote?policy=&in=&out=&amountIn=`](https://docs.route.fun/api-reference/delegate-quote), signs the
returned `typedData` with the agent key, and sends [`POST /delegate/execute`](https://docs.route.fun/api-reference/delegate-execute) with
`{ "trade", "signature" }`. Route's relayer sends it and returns `tx`.

**4. Revoke**

[`DELETE /delegate/policies/<hash>`](https://docs.route.fun/api-reference/delegate-revoke) stops Route. The hard stop is `revoke(hash)` or
`bumpEpoch()` on RouteDelegate from the owner, or a Permit2 lockdown.

## Stop rules run by Route

A policy without an agent (`agent` left out) can carry up to 4 `rules` in `POST /delegate/policies`:
`{ "type": "stop", "tokenIn", "tokenOut", "amountIn", "triggerRate", "confirm" }`. Route sells `amountIn` when the rate falls to
`triggerRate` (output per input, raw units, 1e18 scale) or below in `confirm` distinct blocks (default 3). The pair's floor is the
worst price it may sell at.

## Rules

* Every input token needs a price floor; a pair without one cannot trade.
* `maxPerTrade` must be worth at least 20 gas fees. Expiry is at most 365 days out.
* The agent cannot be Route's relayer.
* [`GET /delegate/policies/<hash>`](https://docs.route.fun/api-reference/delegate-get) shows trades and how much of each `maxTotal` is spent.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.