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

# sauce actions

> Lower a JSON actions document to SauceScript for a chain and print the source, main's parameters and the bytecode

`sauce actions` converts a JSON actions document to a SauceScript program for one chain and prints the program, `main`'s parameters and the bytecode.

## Synopsis

```bash theme={null}
sauce actions <file | -> [--chain <slug|id>] [--json]
```

## Description

An actions document is JSON, `{ "version": 1, "actions": [ … ] }`, where each action is one protocol operation: a swap, a lending supply, a bridge, a token approval. The document's tokens are registry symbols (`"USDC"`) or addresses, and its contracts are namespace references (`"UniswapV3.Factory"`) or addresses. A pool may be given by its factory's key (`factory` and `fee`) instead of its address; the program then reads the pool from the factory when it runs. A `recipient`, `onBehalfOf` or `owner` is an address, or `"pot"` for the executing Pot.

`sauce actions` compiles the document for the chain `--chain` names, else for the document's `chainId`. Each name becomes the program's global of that name on that chain, so a document with no `chainId` compiles for every chain where its names exist. A name the chain lacks is refused with its path in the document (`actions[1].tokenIn`).

An action of type `argument` becomes a parameter of `main`, in the order the document declares it. Give its value with `--args` when you simulate, build or run the document.

`sauce compile`, `sauce simulate`, `sauce tx` and `sauce run` take an actions document wherever they take a `.sauce.ts` file, with the same flags. Its cook runs on the Pot that `--owner` or `--pot` names. `sauce actions` shows what those commands compile.

## Options

| Option | Description |
| - | - |
| `--chain <slug\|id>` | The chain to compile for. Default: the document's `chainId` |
| `--json` | Print JSON: the document, the source, the bytecode and `main`'s parameters |
| `-h, --help` | Show the help |
| `--no-update-check` | Print no notice of a newer `sauce`, and read no registry for one |

## Output

Without `--json`, stdout carries the SauceScript the document lowers to, then a comment with `main`'s signature and a comment with the bytecode and its size.

With `--json`, stdout carries the object [`sauce compile --json`](https://docs.eco.com/sauce-sdk/cli/compile#output) prints (`bytecode`, `size`, `entryParams`, `defines`, `contracts`, `compiler`, `engine`), plus:

| Field | Contents |
| - | - |
| `document` | The parsed document |
| `source` | The SauceScript it lowers to |
| `bindings` | The ABI bindings the program calls through |
| `parameters` | The names of the `argument` actions, in order |

Exit codes: `0` when the document compiles, `1` when it is refused for the chain, `2` for a usage error, such as a document with no `chainId` and no `--chain`.

## Examples

### Lower a swap for Base

```json swap.json theme={null}
{
  "version": 1,
  "actions": [
    { "type": "argument", "name": "amount" },
    {
      "type": "uniswapV3Swap",
      "tokenIn": "USDC",
      "tokenOut": "WETH",
      "factory": "UniswapV3.Factory",
      "fee": 500,
      "amountOutMin": "1",
      "recipient": "pot"
    }
  ]
}
```

The document takes the amount to sell as an input, swaps that much USDC for WETH in the Uniswap V3 pool the factory keys at a 0.05% fee, and keeps the WETH in the Pot.

```bash theme={null}
sauce actions swap.json --chain base
```

```text theme={null}
// swap.json, lowered for base (chain 8453)
import { uniswapV3 } from "@sauce/router";

function main(a_amount: Uint256): void {
  let t_out0 = a_amount;
  const pool0 = UniswapV3.Factory.getPool(USDC, WETH, 500);
  require(pool0 != 0, "actions[1]: no pool under that key");
  uniswapV3(pool0, USDC, WETH, t_out0, 0, 1, pot);
}

// main(a_amount: Uint256): pass the arguments in this order
// bytecode, 444 bytes: 0xa50201dcd1514702000eb19000b6…
```

The `argument` action became `main`'s parameter `a_amount`. The swap is a call into `@sauce/router`.

### Print the lowering as JSON

```bash theme={null}
sauce actions swap.json --chain base --json
```

```json theme={null}
{
  "chain": "base",
  "chainId": 8453,
  "target": "evm",
  "bytecode": "0xa50201dcd151…",
  "size": 444,
  "payload": null,
  "entryEncoding": "abi-v1",
  "entryParams": [{ "name": "a_amount", "type": "Uint256" }],
  "defines": [
    { "name": "USDC", "value": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "source": "chain", "kind": "token", "chain": "base" },
    { "name": "WETH", "value": "0x4200000000000000000000000000000000000006", "source": "chain", "kind": "token", "chain": "base" }
  ],
  "contracts": [
    {
      "reference": "UniswapV3.Factory",
      "contract": "UniswapV3.Factory",
      "chain": "base",
      "address": "0x33128a8fC17869897dcE68Ed026d694621f6FDfD"
    }
  ],
  "document": { "version": 1, "actions": [ … ] },
  "source": "// swap.json, lowered for base (chain 8453)\n…",
  "bindings": [],
  "parameters": ["amount"]
}
```

The output is trimmed: `returnType`, `compiler` and `engine` are left out.

### Simulate the document

The simulation needs the release's engine deployed on the chain: `sauce pot --chain base --owner <address>` reports whether it is.

```bash theme={null}
sauce simulate swap.json --chain base --owner 0x1111111111111111111111111111111111111111 \
  --assume-balance USDC:1000 --args 1000000000
```

Simulated on Base at block 53157167 through a public endpoint. Nothing was signed or sent:

```text theme={null}
The cook succeeds from 0x1111111111111111111111111111111111111111: gas used 190422 for the cook, after the Pot's deploy (1. below), returns 0x
Left in the Pot, not in the owner's wallet:
  0.431160686756004019 WETH
…
What moved, in order:
  [1] wallet 0x1111…1111 -> Pot 0x6c91…D3Fe      0.00000374478538635 ETH    the cook's value
  [2] Pot                -> Kitchen 0x1984…506b  0.00000374478538635 ETH    the Kitchen's fee
  [3] 0xd0b5…F224        -> Pot                  0.431160686756004019 WETH
  [4] Pot                -> 0xd0b5…F224          1000 USDC
```

`--args 1000000000` is 1,000 USDC in base units. [`sauce simulate`](https://docs.eco.com/sauce-sdk/cli/simulate) describes the rest of the report.

### A name the chain lacks

```bash theme={null}
sauce actions swap.json --chain kava
```

```text theme={null}
sauce actions: swap.json does not compile for kava:
  actions[1].factory: no "UniswapV3.Factory" on Kava (chain 2222): UniswapV3 is not deployed there (it is on ethereum, optimism, bsc, polygon, base, arbitrum, celo, arc, avalanche, monad) — give the contract's address there instead
  actions[1].tokenIn: no token "USDC" on Kava (chain 2222), which registers no token symbols — give its address there instead
  actions[1].tokenOut: no token "WETH" on Kava (chain 2222), which registers no token symbols — give its address there instead
```

The command exits `1` and lists every refused name with its path.

## Next steps

* [`sauce compile`](https://docs.eco.com/sauce-sdk/cli/compile): the same report for a `.sauce.ts` program.
* [`sauce simulate`](https://docs.eco.com/sauce-sdk/cli/simulate) and [`sauce run`](https://docs.eco.com/sauce-sdk/cli/run): run a document as you run a program.
* [Actions from TypeScript](https://docs.eco.com/sauce-sdk/typescript/actions.md): `parseProgram`, `compileProgram` and the document schema.
* [Swap and supply with an actions document](https://docs.eco.com/quickstarts/sauce/actions-swap-supply.md).


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