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

# band

> Revert the transaction if an output moves more than a tolerance away from its simulated value, in either direction

The `band` guard keeps an op's output within a two-sided range around its simulated value. It adds two on-chain checks:

* `output ≥ simulated × (10000 − bps) / 10000`, rounded down
* `output ≤ simulated × (10000 + bps) / 10000`, rounded up

If the output at execution falls outside that range, the transaction reverts. The compile result reports no minimum for the guarded port.

## When to use it

Use `band` where a move in either direction is a problem, above all the pool price a liquidity deposit sees. A deposit that executes after the price moved, for example after a sandwich trade, adds liquidity at a worse ratio, and a floor alone can't catch that.

The Uniswap deposit ops expose the price they read just before the deposit for this guard:

| Op | Port | Value |
| - | - | - |
| `uniswapV2.addLiquidity` | `poolPrice` | The pair's price, `reserve1 × 2^112 / reserve0`. Another user's liquidity add leaves it unchanged; only a swap moves it. |
| `uniswapV3.mint`, `uniswapV3.increaseLiquidity` | `sqrtPriceX96` | The pool's square-root price. A band of N bps on `sqrtPriceX96` allows about 2N bps of price movement, so halve the tolerance you want on the price. |

These ops have no other price protection. Pair the `band` guard with a [`slippage`](https://docs.li.fi/composer/composer-api/guards/slippage) guard on `liquidity`, which floors the LP amount the deposit mints.

## Config

| Field | Type | Description |
| - | - | - |
| `port` | string | The op's output port to check: a `resource_output` or a `handle`. |
| `bps` | integer | Tolerance in basis points on each side of the simulated value. `50` is 0.5%. |

## Example

Add 1,000 USDC and 0.25 WETH to the Uniswap V2 USDC/WETH pair on Ethereum. The transaction reverts if the pool price moved more than 0.5% either way, or if the deposit mints less than 99.5% of the simulated LP amount:

```ts theme={"system"}
import { createComposeSdk, guards, materialisers, resources } from '@lifi/composer-sdk';

// Ethereum mainnet
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const UNISWAP_V2_ROUTER = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D';
const UNISWAP_V2_FACTORY = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';
const USDC_WETH_PAIR = '0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc';

const sdk = createComposeSdk({
  baseUrl: 'https://composer.li.quest',
  apiKey: process.env.LIFI_API_KEY!,
});

const builder = sdk.flow(1, {
  name: 'uniswap-v2-add-liquidity',
  inputs: {
    usdcIn: resources.erc20(USDC, 1),
    wethIn: resources.erc20(WETH, 1),
  },
});

builder.uniswapV2.addLiquidity('add-liquidity', {
  bind: { tokenA: builder.inputs.usdcIn, tokenB: builder.inputs.wethIn },
  config: {
    router: UNISWAP_V2_ROUTER,
    factory: UNISWAP_V2_FACTORY,
    pair: USDC_WETH_PAIR,
  },
  guards: [
    // Revert unless the pool price read before the deposit is within ±0.5%
    // of the simulated price, in either direction.
    guards.band({ port: 'poolPrice', bps: 50 }),
    // Revert unless the deposit mints at least 99.5% of the simulated LP amount.
    guards.slippage({ port: 'liquidity', bps: 50 }),
  ],
});

await builder.compile({
  signer: '0xYourSignerAddress',
  inputs: {
    usdcIn: materialisers.directDeposit({ amount: '1000000000' }), // 1,000 USDC
    wethIn: materialisers.directDeposit({ amount: '250000000000000000' }), // 0.25 WETH
  },
  sweepTo: builder.context.sender,
  // The LP token has no price, so the default price-impact check would read
  // the deposit as a total loss. 0 skips it; the two guards are the protection.
  maxPriceImpactBps: 0,
});
```

The unused side of the deposit comes back as a residual and is swept to the sender with the LP tokens. For a full Uniswap walkthrough, including V3 positions, see [Add liquidity on Uniswap](https://docs.li.fi/composer/composer-api/recipes/uniswap-liquidity.md).


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