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

# lifi.zap

> Enter or exit a protocol position through one routing edge

`lifi.zap` moves a token into or out of a protocol position, such as an ERC-4626 vault, an Aave market, a staking token or a wrapper. It consumes the resource on `amountIn` and produces a resource of the `resourceOut` token on `amountOut`, on the same chain.

The op runs exactly one **routing edge**: a catalog entry that turns one token into another through one protocol action, for example USDC → aEthUSDC through an Aave v3 deposit. It handles every edge type (`enter-position`, `exit-position`, `wrap`, `unwrap`, `mint`, `burn`). The [routing catalog](https://docs.li.fi/composer/protocols-and-chains.md) lists every edge.

## Ports

| Port | Kind | Meaning |
| - | - | - |
| `amountIn` | input resource | The tokens to move into or out of the position, on the flow's chain. |
| `recipient` | input handle (`address`), optional | Where the output goes, on edges that require it. See the rules below. |
| `amountOut` | output resource | The `resourceOut` tokens the edge produced. It carries no minimum: attach a [`slippage`](https://docs.li.fi/composer/composer-api/guards/slippage) guard. |

## Config

| Field | Type | Required | Meaning |
| - | - | - | - |
| `resourceOut` | resource | yes | The token to receive, on the flow's chain: the position token for a deposit, the underlying for a withdrawal. One routing edge must connect it to `amountIn`'s token. |

### Rules

* **One edge, no swap.** If no edge goes from `amountIn`'s token to `resourceOut`, the compile fails with `no_route_error`. Chain a [`lifi.swap`](https://docs.li.fi/composer/composer-api/ops/lifi-swap) to the edge's input token first, or let `sdk.route` plan up to two hops, with a swap only as the first hop (see [Deposit with a server-planned route](https://docs.li.fi/composer/composer-api/recipes/server-planned-route.md)).
* **No output floor.** No edge encodes a minimum output. Attach a [`slippage`](https://docs.li.fi/composer/composer-api/guards/slippage) guard to `amountOut`.
* **Deposit limits.** Some protocols cap a deposit or withdrawal, for example an ERC-4626 vault's `maxDeposit`. The routing catalog reports the caps as the edge's `inAmountMin` and `inAmountMax`, in the input token's base units. An amount outside them fails the compile's simulation.
* **`recipient` depends on the edge.** Most edges keep the output in the execution proxy, and binding the optional `recipient` input is an error. Edges marked `recipient: "required"` in the routing catalog, such as IPOR vault deposits, mint the output straight to `recipient`. On these, add `recipient: builder.context.sender` (or another address handle) to `bind`.

## Example

Deposit 1,000 USDC into Aave v3 (aEthUSDC) on Ethereum mainnet:

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

const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
// Aave v3 aEthUSDC receipt token on Ethereum mainnet
const A_ETH_USDC = '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c';

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

const builder = sdk.flow(1, {
  name: 'zap-usdc-into-aave',
  inputs: { amountIn: resources.erc20(USDC, 1) },
});

// One routing edge: USDC → aEthUSDC (Aave v3 enter-position).
builder.lifi.zap('zap', {
  bind: { amountIn: builder.inputs.amountIn },
  config: {
    resourceOut: resources.erc20(A_ETH_USDC, 1),
  },
  // No edge encodes a minimum, so the guard sets the output's floor.
  guards: [guards.slippage({ port: 'amountOut', bps: 100 })],
});

const result = await builder.compile({
  signer: '0xYourSignerAddress',
  inputs: {
    amountIn: materialisers.directDeposit({ amount: '1000000000' }), // 1,000 USDC
  },
  sweepTo: builder.context.sender,
});

console.log(result.outputs['zap.amountOut']?.amount.minimum?.value);
```

Full runnable recipe: [Swap and deposit](https://docs.li.fi/composer/composer-api/recipes/swap-and-deposit.md).

## Errors

| Error | Cause | Fix |
| - | - | - |
| `no_route_error` | No routing edge goes from `amountIn`'s token to `resourceOut`. | Check the [routing catalog](https://docs.li.fi/composer/protocols-and-chains.md); add a `lifi.swap` first or use `sdk.route`. |
| `simulation_revert` | The protocol rejected the deposit or withdrawal, for example because `amountIn` is outside the edge's `inAmountMin` / `inAmountMax`. | Adjust the amount. |
| `validation_error` about `recipient` | `recipient` is bound on an edge that keeps its output in the proxy, or missing on an edge that requires it. | Bind or remove `recipient` to match the edge. |

## Related

* [`lifi.swap`](https://docs.li.fi/composer/composer-api/ops/lifi-swap): swap to the edge's input token first.
* [Routing catalog](https://docs.li.fi/composer/protocols-and-chains.md): every edge a zap can run.
* [Swap and deposit](https://docs.li.fi/composer/composer-api/recipes/swap-and-deposit.md) and [Deposit with a server-planned route](https://docs.li.fi/composer/composer-api/recipes/server-planned-route.md): full recipes.


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