> ## 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 price

> Convert a price into a pool's sqrtPriceX96 and a swap's limits, or read a pool's price back

`sauce price` turns a price into the numbers a swap program takes: a pool's `sqrtPriceX96`, `sqrtPriceLimitX96`, `priceLimit`, `maxAvgPrice` and `minAvgPrice`.

## Synopsis

```bash theme={null}
sauce price --chain <slug|id> <price> <quote> per <base> [--offline] [--json]
sauce price --chain <slug|id> <base> <quote> (<price> | --sqrt-price-x96 <value>) [--json]
sauce price --chain <slug|id> <base> <quote> --pool <address> [--json]
```

## Description

A price is how many `<quote>` tokens one `<base>` token is worth. `2700 USDC per WETH` and `WETH USDC 2700` are the same price. A token is a symbol the chain registers ([`sauce globals --tokens`](https://docs.eco.com/sauce-sdk/cli/globals)), or an address with its decimals (`0x…:18`). With an endpoint, an address alone works: its decimals are read from the token.

The first line states the price both ways round (`1 WETH = 2700 USDC, 1 USDC = 0.00037… WETH`), since a price written backwards is off by a large factor. Then the command prints the pair's order on the chain (token0 is the lower address), the pool's `sqrtPriceX96` at that price, and for each direction, selling the base token and then buying it:

| Number | Meaning |
| - | - |
| `sqrtPriceLimitX96` | The same number as a swap's limit: a floor when selling token0, a ceiling when selling token1 |
| `priceLimit` | Input base units paid per output base unit bought, times 1e18, rounded down: the price times 10^(18 + input decimals − output decimals). The distributed swap's `priceLimit`, as [`sauce pools`](https://docs.eco.com/sauce-sdk/cli/pools) prints it |
| `maxAvgPrice` | The same number, as the distributed swap's `maxAvgPrice`: `spent * 1e18 <= maxAvgPrice * bought` |
| `minAvgPrice` | The other way round: output base units received per input base unit, times 1e18, rounded up, for a check `out * 1e18 >= minAvgPrice * spent`. It is never a `maxAvgPrice` |

Uniswap V3 and V4 and their forks share this price format.

* `--sqrt-price-x96 <value>` reads a pool's `sqrtPriceX96` back into a price.
* `--pool <address>` reads the price now from that pool of the pair: a Uniswap V3, PancakeSwap V3 or Aerodrome Slipstream pool. The output names the pool's venue when the registry's factory made it.
* Without `--offline`, the command also reads the pair's price now from its deepest Uniswap V3 pool on the chain, and warns on stderr when the price given is 10 times or more away from it. When the price looks written the wrong way round, the warning says so and gives the command that reads it the right way.

The command sends nothing and works on every chain in the registry, preview chains included. With `--offline`, it reaches no network. The same conversion is in the TypeScript package as `sqrtPriceX96FromPrice` and `priceFromSqrtPriceX96`.

## Options

| Option | Description |
| - | - |
| `--chain <slug\|id>` | The chain the pool is on |
| `--sqrt-price-x96 <value>` | Read a pool's `sqrtPriceX96` as a price instead |
| `--pool <address>` | Read the price now from this V3-style pool of the pair. Needs an endpoint |
| `--rpc-url <url>` | Your own RPC endpoint for the chain. Default: a built-in public one |
| `--config <file>` | A file of your own endpoints: `{ "rpcUrls": { "<chain id>": "<url>" } }` |
| `--offline` | Read no chain: no endpoint, built-in ones included |
| `--json` | Print one JSON object instead of text |
| `-h, --help` | Show the help |
| `--no-update-check` | Print no notice of a newer `sauce`, and read no registry for one |

## Output

Text on stdout; the endpoint note and any warning on stderr.

With `--json`:

| Field | Contents |
| - | - |
| `chain`, `price` | The chain and the price as given or read |
| `means`, `inverse` | The price in words, both ways round |
| `base`, `quote` | Each token's symbol, address and decimals |
| `token0`, `token1` | The pair's order on the chain |
| `sqrtPriceX96` | The pool's price format |
| `pool` | With `--pool`: the pool's address, venue, factory contract, `sqrtPriceX96`, tick, liquidity, `feePpm` and tick spacing |
| `live` | Without `--offline` or `--pool`: the price now at the pair's deepest Uniswap V3 pool |
| `units` | What each number means, in words |
| `sell`, `buy` | Per direction: `tokenIn`, `tokenOut`, `zeroForOne`, `sqrtPriceLimitX96`, `limit` (`floor` or `ceiling`), `priceLimit`, `maxAvgPrice`, `minAvgPrice` |

Exit codes: `0` on success; `2` for a usage error.

## Examples

### Convert a price on Base

```bash theme={null}
sauce price --chain base 2700 USDC per WETH
```

```text theme={null}
2700 USDC per WETH on base: 1 WETH = 2700 USDC, 1 USDC = 0.00037037037037037 WETH
  token0  WETH  0x4200000000000000000000000000000000000006  18 decimals
  token1  USDC  0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913  6 decimals
sqrtPriceX96  4116816085950893928074568
Live: the Uniswap V3 pool 0x6c561B446416E1A00E8E93E221854d6eA4171372 (fee 0.3%) is at 2390.931757027768444344 USDC per WETH (sqrtPriceX96 3874031734669984742412863)

Selling WETH (WETH in, USDC out):
  sqrtPriceLimitX96  4116816085950893928074568  a floor: selling token0 lowers the price
  priceLimit         370370370370370370370370370  WETH units paid per USDC unit bought, times 1e18: the distributed swap's priceLimit
  maxAvgPrice        370370370370370370370370370  the same, as its maxAvgPrice: spent * 1e18 <= maxAvgPrice * bought
  minAvgPrice        2700000000  the other way round, USDC units received per WETH unit, times 1e18: a floor for out * 1e18 >= minAvgPrice * spent, never a maxAvgPrice
Buying WETH (USDC in, WETH out):
  sqrtPriceLimitX96  4116816085950893928074568  a ceiling: selling token1 raises the price
  priceLimit         2700000000  USDC units paid per WETH unit bought, times 1e18: the distributed swap's priceLimit
  maxAvgPrice        2700000000  the same, as its maxAvgPrice: spent * 1e18 <= maxAvgPrice * bought
  minAvgPrice        370370370370370370370370371  the other way round, WETH units received per USDC unit, times 1e18: a floor for out * 1e18 >= minAvgPrice * spent, never a maxAvgPrice
```

Buying WETH with USDC at 2700, the `priceLimit` is `2700000000`: 2700 × 10^(18 + 6 − 18). The `Live:` line is the pool's price at the time of the run.

### Catch a price written backwards

```bash theme={null}
sauce price --chain base 2700 WETH per USDC
```

```text theme={null}
the price given, 2700 WETH per USDC, is about 10^7 times off the Uniswap V3 pool 0x6c561B446416E1A00E8E93E221854d6eA4171372 (fee 0.3%), which is at 0.000418180515571872 WETH per USDC: it looks the wrong way round. For 2700 USDC per WETH, run `sauce price --chain base 2700 USDC per WETH`
2700 WETH per USDC on base: 1 USDC = 2700 WETH, 1 WETH = 0.00037037037037037 USDC
…
```

The first line is the warning on stderr. The numbers are still printed, for the price as given.

### Read a pool's price now

```bash theme={null}
sauce price --chain base WETH USDC --pool 0x6c561B446416E1A00E8E93E221854d6eA4171372 --json
```

```json theme={null}
{
  "chain": "base",
  "price": "2391.82592048331825887",
  "means": "2391.82592048331825887 USDC per WETH",
  "inverse": { "price": "0.000418090627514367", "means": "0.000418090627514367 WETH per USDC" },
  "base": { "symbol": "WETH", "address": "0x4200000000000000000000000000000000000006", "decimals": 18 },
  "quote": { "symbol": "USDC", "address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "decimals": 6 },
  "token0": "WETH",
  "token1": "USDC",
  "sqrtPriceX96": "3874756074414063313631848",
  "pool": {
    "address": "0x6c561B446416E1A00E8E93E221854d6eA4171372",
    "venue": "Uniswap V3",
    "contract": "UniswapV3.Factory",
    "factory": "0x33128a8fC17869897dcE68Ed026d694621f6FDfD",
    "sqrtPriceX96": "3874756074414063313631848",
    "tick": -198523,
    "liquidity": "39603939239103172466",
    "feePpm": 3000,
    "tickSpacing": 60,
    "readFrom": "base"
  },
  "units": { … },
  "sell": {
    "tokenIn": "WETH",
    "tokenOut": "USDC",
    "zeroForOne": true,
    "sqrtPriceLimitX96": "3874756074414063313631848",
    "limit": "floor",
    "priceLimit": "418090627514367419289459232",
    "maxAvgPrice": "418090627514367419289459232",
    "minAvgPrice": "2391825921"
  },
  "buy": {
    "tokenIn": "USDC",
    "tokenOut": "WETH",
    "zeroForOne": false,
    "sqrtPriceLimitX96": "3874756074414063313631848",
    "limit": "ceiling",
    "priceLimit": "2391825920",
    "maxAvgPrice": "2391825920",
    "minAvgPrice": "418090627514367419289459233"
  }
}
```

### Read a sqrtPriceX96 back, offline

```bash theme={null}
sauce price --chain base WETH USDC --sqrt-price-x96 3874756074414063313631848 --offline
```

```text theme={null}
2391.82592048331825887 USDC per WETH on base: 1 WETH = 2391.82592048331825887 USDC, 1 USDC = 0.000418090627514367 WETH
  token0  WETH  0x4200000000000000000000000000000000000006  18 decimals
  token1  USDC  0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913  6 decimals
sqrtPriceX96  3874756074414063313631848
…
```

## Next steps

* [`sauce pools`](https://docs.eco.com/sauce-sdk/cli/pools): every pool of a pair, with each pool's `priceLimit`.
* [Distributed swap](https://docs.eco.com/quickstarts/sauce/distributed-swap.md): a program that takes `priceLimit` and `maxAvgPrice`.
* [`sauce simulate`](https://docs.eco.com/sauce-sdk/cli/simulate): run a swap at the limits you chose.


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