# Calling actions

> How to discover, simulate and execute each kind of Orbit action with the right argument shapes and the right amount units.
>
> Describes Orbit 0.1.8. Web page: https://dialectic-orbit-docs.vercel.app/0.1.8/reference/calling-actions/

This page is for agents that move money with Orbit 0.1.8: position changes, harvests, swaps, bridges and Hyperliquid perp orders. It gives the exact argument shape of each kind, a worked example, and the unit rules that caused most real-world mistakes. Tool replies win over this page: when a tool's `next`, `in_words` or refusal says something different, follow the tool.

## The pipeline in one line

Every write is **discover → (quote or prepare) → `simulate_action` → `execute_action`**.

- `simulate_action` builds the transaction, simulates it, runs the policy check against the signed mandate, and returns a `sim_receipt`.
- `execute_action` takes the `sim_receipt` for the **identical** `call`, re-checks policy with a fresh simulation, then signs and sends. A receipt for a different call is refused (`simulation_required`).
- Both take `safe` (the configured Safe name from `list_safes`) and `call` (an object whose `kind` is `manage_position`, `harvest`, `swap`, `bridge` or `raw`).
- The receipt is short-lived: its lifetime is in `sim_receipt.valid_for_s`. A receipt already past its lifetime when `execute_action` is called is refused (`simulation_stale`, with `age_s` and `valid_for_s`); nothing is sent, so simulate again and relay the new `in_words`. A receipt that runs out while `execute_action` is already working is renewed once.

`raw` calls exist for developer mode only; under a mandate they are never priceable and are always denied. Do not use them.

## Step 1: discover the exact action name

Rooted actions (positions and harvests) must be named exactly as the Safe's root names them.

```json
{ "tool": "list_actions", "arguments": { "safe": "base-safe", "kind": "management" } }
```

`kind` filters on `management`, `accounting`, `harvest` or `flashloan_management`; `protocol` filters by protocol. Each entry has:

| Field | Use |
| --- | --- |
| `qualified_name` | The action id. Copy it **exactly**, character for character. Format `<protocol>.<action>.<label>`; the label is the position's label and **can contain spaces** (for example `hyperliquid.deposit_usdc_for_perp.Hyperliquid USDC funding and withdrawal`). |
| `kind` | The module's instruction type: `management` goes in a `manage_position` call; `harvest` goes in a `harvest` call. It does not say what the action does (Hyperliquid orders, cancels, closes and account transfers are `harvest`); the reply's `kind_meaning` says so. Only an entry with `claims_rewards: true` claims rewards. |
| `params` | The input slots: each has `name` and `kind` (`uint256`, `address`, ...). Pass every slot by this `name`. |
| `amount_units` | The unit rule for amount params (base units; see [Units](#units)). |
| `claims_rewards` | Present on a reward-claim harvest: call it with no params. |

Rules:

- **Never guess or reconstruct an id.** An id that is not in the root is refused with `data.code: "unknown_action"` (message starts "unknown action `...`: not in machine ...'s rootfile"). It is sent as JSON-RPC error -32602, so some hosts show only "invalid params". If you see "invalid params" right after naming an action, call `list_actions` and copy the name.
- **Absence from `list_actions` is not a verdict on swaps or bridges.** They are not rooted actions and never appear there. The reply's `not_listed_here` block says where each is checked: a swap by `get_swap_quote` → `executable`, a USDC bridge route by `get_setup_bridge_eligibility`.
- Pass numeric params as **decimal strings** (`"20000000"`, not `20000000`). As of 0.1.8 a JSON number is accepted but passes through floating point, so a large base-unit amount (above about 9 × 10^15) is rounded without warning.

`preview_action` resolves an action and its params into the on-chain instruction and merkle proof without simulating or sending. Use it to inspect or debug an encoding. It takes `action` and `params` (not `mgmt_action`):

```json
{ "tool": "preview_action",
  "arguments": { "safe": "base-safe", "action": "<qualified_name>", "params": { "amount_to_deposit": "20000000" } } }
```

## Field names differ by kind

This is the most common argument mistake. A tool's top-level arguments refuse unknown fields. Inside `call` (and a bridge `order`), a wrongly named field is silently ignored, not refused: the call then fails for the real field it lacks (for example, `params` on a `manage_position` is dropped and the action fails for a missing slot). Use the names in this table.

| Call | Action field | Params field |
| --- | --- | --- |
| `kind: "manage_position"` | `mgmt_action` | `mgmt_params` |
| `kind: "harvest"` | `action` | `params` |
| `preview_action` (tool) | `action` | `params` |
| `get_position_value` (tool) | `action` (an accounting action) | `params` |

## Position change (`manage_position`)

Deposit, withdraw, supply, borrow, repay: any `management` action from `list_actions`.

```json
{ "tool": "simulate_action",
  "arguments": {
    "safe": "base-safe",
    "call": {
      "kind": "manage_position",
      "mgmt_action": "<qualified_name from list_actions>",
      "mgmt_params": { "amount_to_deposit": "20000000" }
    }
  } }
```

This deposits **20 USDC** (6 decimals, so 20 × 10^6 base units). `"20"` would be 0.00002 USDC.

- `acct_action` and `acct_params` are optional. Leave them out: Orbit uses the root's paired accounting instruction for the position.
- **To exit a position in full**, prefer a decrease action whose name ends in `_relative` and takes `bps_to_redeem`, with `"bps_to_redeem": "10000"`. It redeems the whole holding at execution time. Otherwise read the balance fresh (`get_balances` with `"fresh": true`) and withdraw that amount.
- A failed simulation restates the amount it read. If it says you are moving a tiny amount, your units are wrong.

## Harvest (`harvest`)

Harvests are receive-only actions (claims, and on HyperEVM the transfers between the Safe and its Hyperliquid account).

```json
{ "tool": "simulate_action",
  "arguments": {
    "safe": "base-safe",
    "call": { "kind": "harvest", "action": "<harvest qualified_name>", "params": {} }
  } }
```

- An action with `claims_rewards: true` takes **no params**: Orbit fills the claim for this Safe and pays it only to the Safe. A reply with `nothing_to_claim: true` is an answer, not a failure.
- Leave `swap_orders` out. No Orbit tool builds one and a `quote_id` is not accepted there. To convert harvested tokens, harvest first, then swap.
- Harvest amount params use the same base-unit rule as `mgmt_params`.

## Swap (`swap`)

Three calls, in one persistent session, promptly:

```json
{ "tool": "get_swap_quote",
  "arguments": { "safe": "base-safe", "input_token": "USDC", "output_token": "WETH", "amount": "50" } }
```

- Tokens: a 0x address, or a symbol when exactly one of the Safe's tokens on that chain has it (otherwise the refusal lists candidates). HyperEVM's `USD₮0` can be named `USD₮0` or `USDT0`, and only at its listed address; any other token calling itself that is not picked by name.
- `amount: "max"` quotes the Safe's whole balance of the input token, read when quoting. A zero amount, or a swap of a token into itself, is refused.
- Amount: `amount` in **token units** (`"50"` is 50 USDC) **or** `amount_raw` in base units (`"50000000"`). Never both. Older fields (`input_amount`, `input_amount_raw`, `input_amount_human`) still work but cannot be combined with the new ones.
- `slippage_bps` is optional; its default is stated in the tool's argument schema, and `min_out` shows the floor the tolerance produces.
- Read `executable`. When it is `false`, do not simulate: `missing_feed_routes` or `balance_note` says why.
- Tell the user `output.expected_out_human` and `output.min_out_human` with `output.symbol`. The raw `expected_out` and `min_out` are output-token base units.

```json
{ "tool": "simulate_action",
  "arguments": { "safe": "base-safe", "call": { "kind": "swap", "quote_id": "q_..." } } }
```

```json
{ "tool": "execute_action",
  "arguments": {
    "safe": "base-safe",
    "call": { "kind": "swap", "quote_id": "q_..." },
    "sim_receipt": "<sim_receipt object or its id>",
    "idempotency_key": "swap-usdc-weth-2026-11-17-01"
  } }
```

- The quote lives for the `expires_in_s` in its reply (set by `[mcp] quote_ttl_s` in the config). If it expires between simulate and execute, Orbit re-quotes once with the same parameters: the result has `requoted: true`, and when `min_out_changed` is true you must tell the user the new minimum from `notes.requote`.
- A stale quote at simulate is refused with `quote_stale`; an unknown id with `quote_not_found` (usually a quote from another process). Re-quote.
- Swaps and bridges always simulate on the local fork, or on Tenderly if you pass `backend: "tenderly"`. A requested `eth_call` is overridden, with a note. The on-chain `minOutputAmount` floor and the module's swap loss cap still bind. The simulation's `policy.swap_constraints` shows the swap-loss limit and the module's swap fee (`swap_fee_rate_pct`), which is charged on the output on top of that limit; relay its `swap_fee_note`.

## Bridge (`bridge`)

Moves tokens between the owner's own Safes on different networks. Not a rooted action.

1. **USDC uses [Circle CCTP](https://developers.circle.com/cctp), `bridge_id: 3`.** Check the route first:

```json
{ "tool": "get_setup_bridge_eligibility",
  "arguments": { "source_safe": "base-safe", "safe": "hyperevm-safe" } }
```

An unavailable route comes back as an **error**, not `false`. Tell the owner the USDC route is not set up.

2. Simulate:

```json
{ "tool": "simulate_action",
  "arguments": {
    "safe": "base-safe",
    "call": { "kind": "bridge", "order": {
      "bridge_id": 3, "dest_chain": "hyperevm",
      "input_token": "USDC", "output_token": "USDC",
      "amount": "10", "min_output": "10"
    } }
  } }
```

- `amount` and `min_output` are **token units** (`"10"` is 10 USDC). Base-unit forms are `amount_raw` and `min_output_raw`.
- `dest_chain` is the network's config name: `base`, `mainnet`, `hyperevm`.
- `recipient`, when left out, is a matching `[[safes.<name>.bridge_intents]]` recipient in the config, else the Safe configured on `dest_chain`, else this Safe's own address.
- CCTP: `min_output` equal to `amount` requests a 1:1 self-claim (no fee); a lower floor sets the difference as a forwarding fee budget. `cctp_finality` is `standard` (default) or `fast` (needs a fee budget).
- **Other tokens use [Across](https://docs.across.to/), `bridge_id: 1`.** A relayer takes a fee, so `min_output` must sit below `amount` by enough for it, within the Safe's bridge loss cap. A floor equal to the amount is unlikely to fill; unfilled money returns on the source network after the fill deadline (optional `fill_deadline_offset_s`; its default is described in the `bridge` order's argument schema, and the tracked transfer records `fill_deadline_unix`). The eligibility tool does not cover Across: the simulation is the route check.
- `bridge_id: 2` (LayerZero) is refused.

3. Relay `in_words`, then `execute_action` with the same `call`.

**A successful bridge execution means the money left, not that it arrived.** The simulation only validates the source-chain send; settlement is decided by a destination-chain event. Follow it in `health_check` → `reliability.bridge_transfers` (CCTP) or `list_incomplete_operations` by `disposition` (Across). Any Orbit that starts claims a ready CCTP transfer; there is nothing to sign.

## Hyperliquid perp order (HyperEVM Safe)

Never encode an order's size or price by hand.

```json
{ "tool": "prepare_perp_order",
  "arguments": { "safe": "hyperevm-safe", "market": "ETH", "side": "buy",
                 "size_usd": "25", "order_type": "limit", "limit_price": "3000" } }
```

- `market`: the coin (`ETH`), the package label, or the position id. `side`: `buy` (long) or `sell` (short).
- Size: `size` in coins **or** `size_usd` in USDC notional.
- `order_type: "limit"` needs `limit_price` (USDC). `order_type: "market"` needs `slippage_bps` (unless the package declares one), which only the owner chooses: ask, never pick one.
- To close, pass `"close_position": true` instead of a side (without a size it closes the whole position).
- An order under Hyperliquid's opening minimum is not a refusal with a `code`: the reply is `ready: false` with `state: "below_minimum"`, and `in_words` states the minimum and the smallest size that clears it. Its other "cannot prepare" answers use the same shape, so branch on `state`. It rounds size and price to the market's steps, saying so.
- It returns `in_words` and a `call`. Pass that `call` **unchanged**:

```json
{ "tool": "simulate_action",
  "arguments": { "safe": "hyperevm-safe", "backend": "fork", "call": "<call from prepare_perp_order>" } }
```

Use `"backend": "fork"`: Orbit reads the order's CoreWriter intent only from fork receipt logs. Without it the order can be refused as `core_order_unverified` (nothing was sent; relay its message and `workaround_text`).

Then `execute_action` with the same `call`, the receipt and an `idempotency_key`.

- **A successful order is enqueued at Hyperliquid, not filled.** Relay `core_order.status_line` and check the position, not the HyperEVM transaction.
- One open order per market slot. A prepared order reserves nothing: send or drop it before preparing another on the same market.
- No Hyperliquid signer is needed to open, close or cancel through the module. A signer is needed only for leverage and margin changes and for stop-loss / take-profit (`protect_position`).
- Funds must be in the Safe's Hyperliquid trading account first (`hyperliquid.deposit_usdc_for_perp.<label>`, a harvest action). While a transfer is still settling, increases are refused; wait and retry.

## Units

Units caused the most expensive real mistake: an agent passed `"10"` in `mgmt_params` for 10 USDC, which is 0.00001 USDC, got a value-loss refusal, and read it as "venue blocked" for days.

| Where | Unit | 10 USDC is | Notes |
| --- | --- | --- | --- |
| `mgmt_params` amount slots (`manage_position`) | **base units** of the action's token | `"10000000"` | `list_actions` → `amount_units` says so. Token `decimals` are in `get_balances`. Non-amount `uint` params (price, size, index) keep their own scale. |
| harvest `params` amount slots | **base units** | `"10000000"` | Same rule as `mgmt_params`. |
| `hyperliquid.deposit_usdc_for_perp` → `usdc_amount` | USDC base units (6 decimals) | `"10000000"` | Harvest action, Safe to Hyperliquid account. |
| `hyperliquid.transfer_usdc_perp_to_spot` / `transfer_usdc_spot_to_perp` → `transfer_amount` | 6 decimals | `"10000000"` | Inside the Hyperliquid account. |
| `hyperliquid.withdraw_usdc_to_evm` withdraw amount | **8 decimals** (HyperCore USDC) | `"1000000000"` | 100× the 6-decimal figure. It moves USDC from the **spot** balance. The current package names the slot `withdraw_amount_core_usdc`; older packages named it `withdraw_amount_wei`, with the same unit. |
| HYPE spot sale (`sell_spot`) `limit_px` / `sz` | price 6 decimals / size 2 decimals | price 1 USDC = `"1000000"`; 1.5 HYPE = `"150"` | Owner picks the lowest price. |
| `get_swap_quote` `amount` | **token units** | `"10"` | `amount_raw` for base units. |
| bridge `order.amount`, `order.min_output` | **token units** | `"10"` | `amount_raw` / `min_output_raw` for base units. |
| `prepare_perp_order` `size_usd`, `limit_price` | USDC (token units) | `"10"` | Orbit converts to the order's wire format. |
| Swap quote `expected_out`, `min_out` (reply) | output-token base units | | Quote `*_human` fields to the user. |
| Mandate caps (`per_tx`, `daily_deployment`, ...) | accounting-currency units | `"10"` | Human figures, not base units. |

When unsure, simulate: `in_words` restates the amounts in token units. If it says something other than what the user asked for, stop and fix the units.

## What simulate returns, and what to read

Read these before calling `execute_action`:

| Field | Meaning | Do |
| --- | --- | --- |
| `in_words` | One verdict line, then what the action does in plain words (amounts, symbols, side, leverage, a dollar value when priced). | Relay it to the person before executing. |
| `restatement_verdict` | The verdict line alone: "Ready to send." or "Won't go through: ...". | Same sentence that opens `in_words`. |
| `ready_to_execute` | `true` only when execute would proceed. | Execute only on `true`. |
| `next` | What to do now, in one line. | Follow it; on `false` relay it. |
| `policy` | The mandate verdict: `verdict` `allow` / `needs_review` / `deny`, with `rule`, `explanation`, `remediation`; `policy_is_primary`; for bridges `settlement`. | `deny`: relay and stop. `needs_review`: executing will queue it for the owner. |
| `sim_receipt` | `id` and `valid_for_s` (its lifetime in seconds). | Pass it (or its `id`) to `execute_action` promptly. |
| `success`, `error` | Whether the simulated transaction succeeded; the decoded revert on failure. | |
| `refusal` | The module refused on chain: `code`, `status_for_the_user`, `next`. | Relay `status_for_the_user` as written, follow `next`, never paste the raw error. |
| `operating_mode` | `OPEN`, `FENCED`, `WALLED` or `UNKNOWN`. | Outside `WALLED` the chain does not check position-change losses (`FENCED` still checks swaps and bridges; `OPEN` checks neither); the mandate is the binding limit. |
| `ran_on`, `backend` | Where it ran. `ran_on: "fork"` is a practice copy. | Never report a practice run as money moved. |
| `fidelity_note`, `sim_backend_fallback_from` | The fork failed and a lighter backend answered. | Relay the note. |

## What "executed" means

`execute_action` returns either a review or a send:

- **`status: "pending_confirmation"`** with `pending_id`: the action is above a review threshold and is queued for the owner. Relay `approve_hint`. Under `veto_window` it runs at the deadline unless the owner objects; under `explicit_approval` it waits for an approval (`record_review_outcome` with the owner's genuine quoted reply, or the owner page). Track it with `get_confirmation`.
- Otherwise `status` is the send's outcome:

| `status` | Meaning | Do |
| --- | --- | --- |
| `success` | Mined and succeeded on the source chain. | Report it. For a bridge or a Hyperliquid order, say it was sent, not that it arrived or filled. |
| `reverted` | Mined and failed. | Relay the decoded error; do not resend unchanged. |
| `pending` | Sent, not mined yet. | Follow `next`. Retry only with the **same** `idempotency_key`. |
| `unknown_broadcast` | Orbit could not establish the outcome; it may still land. | Never resend under a new key. Check `list_incomplete_operations`. |
| `dropped` | The chain does not have it. | Follow `next`. |

The `idempotency_key` is yours to choose. Reusing a key returns or continues the original send; a new key is a new send.

"Executed" is not "settled": a successful swap or position change is final on that chain, but a bridge settles only when the destination event is seen, a Hyperliquid order is only enqueued, and a queued-vault withdrawal request pays out when the request settles.

## See also

- [Refusals and recovery](https://dialectic-orbit-docs.vercel.app/0.1.8/reference/refusals/) for every refusal code.
- [Permissions and limits](https://dialectic-orbit-docs.vercel.app/0.1.8/concepts/permissions-and-limits/) for what the mandate and module check.
- [Bridging](https://dialectic-orbit-docs.vercel.app/0.1.8/using/bridging/) and [Hyperliquid perps](https://dialectic-orbit-docs.vercel.app/0.1.8/using/hyperliquid-perps/) for the full workflows.
- Guides: `get_guide` with `name: "orbit-portfolio"` and `name: "orbit-hyperliquid-perps"`.
