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

# Request Zap Quotes

> Request quotes for complex DeFi operations using the DZap SDK

The DZap SDK provides functionality to request zap quotes for complex DeFi operations. This guide will walk you through the process of making a request using `getZapQuote`.

## How to Request Zap Quotes

To get started, here is a simple example of how to request a quote for zapping 1 USDC into a yield-bearing position on Arbitrum.

```typescript theme={null}
import { DZapClient } from "@dzapio/sdk";

const dZap = DZapClient.getInstance();

const zapQuoteRequest: ZapQuoteRequest = {
  srcChainId: 42161, // Arbitrum
  destChainId: 42161, // Same chain for simplicity
  account: userAccount,
  srcToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC
  destToken: "0x724dc807b04555b71ed48a6896b6F41593b8C637", // Aave USDC
  amount: "1000000", // 1 USDC (6 decimals)
  recipient: userAccount,
  slippage: 1, // 1% slippage
};

const zapQuote = await dZap.getZapQuote(zapQuoteRequest);
console.log("Zap quote:", zapQuote);
```

When you request zap quotes, you receive an object containing the essential information to determine the best path for complex DeFi operations. At this stage, transaction data is not included and must be requested separately using `buildZapTxn`.

## Zap Quote Request Parameters

The `getZapQuote` function expects a `ZapQuoteRequest` object, which specifies a desired zap operation and includes all the information needed to calculate the most efficient route.

### Request Parameters

| Parameter         | Type                           | Required | Description                                                                                                               |
| ----------------- | ------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------- |
| `srcChainId`      | number                         | yes      | Source chain ID where the operation begins                                                                                |
| `destChainId`     | number                         | yes      | Destination chain ID where the operation completes                                                                        |
| `srcToken`        | string                         | yes      | Source token contract address                                                                                             |
| `destToken`       | string                         | yes      | Destination token or protocol address                                                                                     |
| `slippage`        | number                         | yes      | Slippage tolerance as percentage                                                                                          |
| `amount`          | string                         | no       | Amount to zap in smallest token unit (not needed for NFTs)                                                                |
| `account`         | string                         | no       | User's wallet address                                                                                                     |
| `recipient`       | string                         | no       | Address to receive the final tokens/positions                                                                             |
| `refundee`        | string                         | no       | Address to receive refunds if the operation fails partway                                                                 |
| `permitData`      | string                         | no       | Pre-signed permit data for the source token                                                                               |
| `estimateGas`     | boolean                        | no       | Whether to include a gas estimate in the response                                                                         |
| `positionDetails` | ZapRouteRequestPositionDetails | no       | NFT position details for operations targeting an existing LP position (`{ nftId: string }`)                               |
| `poolDetails`     | ZapRouteRequestPoolDetails     | no       | Pool range details for concentrated-liquidity operations (`{ lowerTick: number; upperTick: number; metadata?: unknown }`) |
| `allowedBridges`  | string\[]                      | no       | Array of allowed bridge protocols for cross-chain operations                                                              |
| `allowedDexes`    | string\[]                      | no       | Array of allowed DEX protocols for swapping operations                                                                    |
| `integrator`      | ZapIntegratorConfig            | no       | Integrator fee configuration for earning fees on transactions                                                             |

<Note>
  `account`, `recipient`, and `refundee` are optional for quoting but become
  required when building the transaction with `buildZapTxn`.
</Note>

## Integrator Fee Configuration

The `integrator` field allows you to configure integrator fees for your transactions. This enables you to earn fees on transactions routed through your integration.

### ZapIntegratorConfig Type

```typescript theme={null}
type ZapIntegratorConfig = {
  id: string; // Unique integrator identifier
  feeBps: number; // Fee in basis points (1 bps = 0.01%)
  wallet: string; // Wallet address to receive integrator fees
};
```

### Example with Integrator Fee

```typescript theme={null}
const zapQuoteRequest: ZapQuoteRequest = {
  srcChainId: 42161,
  destChainId: 42161,
  account: userAccount,
  srcToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
  destToken: "0x724dc807b04555b71ed48a6896b6F41593b8C637",
  amount: "1000000",
  recipient: userAccount,
  slippage: 1,
  integrator: {
    id: "my-integration-id",
    feeBps: 10, // 0.1% fee
    wallet: "0x1234567890123456789012345678901234567890",
  },
};

const zapQuote = await dZap.getZapQuote(zapQuoteRequest);
```

<Note>
  Integrator fees are optional and only need to be included if you want to earn
  fees on transactions. The fee is deducted from the input amount and sent to
  the specified integrator wallet.
</Note>

## Understanding the Response

The response contains detailed information about the zap route:

```typescript theme={null}
type ZapQuoteResponse = {
  approvalData: {
    callTo: string; // Token contract address to call for approval
    approveTo: string; // Address to approve for spending
    amount: string; // Amount to approve in token units
  }[]; // One entry per token that needs approval; empty if none needed
  dust: ZapPathOutput[]; // Any leftover/unswept amounts from the route
  output: ZapPathOutput[]; // Final output amount(s) of the whole zap
  path: ZapPath[]; // Array of steps in the zap operation
};

type ZapPathOutput = {
  asset: ZapPathAsset; // Asset details
  amount: string; // Output amount in token units
  amountUSD: string; // USD value of output
  minAmount: string; // Minimum guaranteed return amount
};

type ZapPath = {
  action: string; // Type of action (swap, deposit, stake, etc.)
  protocol: {
    name: string; // Protocol name
    id: string; // Protocol identifier
    icon: string; // Protocol icon URL
  };
  input: Array<{
    amount: string; // Input amount in token units
    amountUSD: string; // USD value of input
    asset: ZapPathAsset; // Asset details
  }>;
  output: ZapPathOutput[];
  fee: ZapFee[]; // Fees for this step
  estimatedDuration: number; // Time estimate in seconds
};

type ZapPathAsset = {
  chainId: number;
  address: string;
  symbol: string;
  logo: string;
  decimals: number;
  price: string;
  type: string;
  name: string;
  provider?: { id: string; name: string; icon: string };
  underlyingTokens?: {
    chainId: number;
    address: string;
    name?: string;
    symbol: string;
    decimals: number;
    logo?: string | null;
  }[];
};
```

### Key Response Fields

* **`approvalData`** - Array of token approvals required before executing (empty array if none needed)
* **`output`** - The final output amount(s) of the whole zap (top-level, not per-step)
* **`dust`** - Any leftover/unswept amounts produced by the route
* **`path`** - Array of steps that will be executed in the zap operation
* **`path[].action`** - The type of operation (swap, deposit, withdraw, etc.)
* **`path[].protocol`** - Information about the protocol used for this step
* **`path[].input/output`** - Detailed asset information including amounts and USD values (each `output` entry includes `minAmount`, the minimum guaranteed return)
* **`path[].fee`** - Fee breakdown for each step
* **`path[].estimatedDuration`** - Expected time for this step to complete

## Working with Zap Quote Results

```typescript theme={null}
const zapQuote = await dZap.getZapQuote(zapQuoteRequest);

// Check if approval is needed (approvalData is an array, one entry per token)
if (zapQuote.approvalData.length > 0) {
  console.log("Approval required:");
  zapQuote.approvalData.forEach((approval) => {
    console.log(`Approve ${approval.amount} tokens to ${approval.approveTo}`);
  });
}

// Examine the path
console.log("Zap will execute", zapQuote.path.length, "steps:");

zapQuote.path.forEach((step, index) => {
  console.log(`\nStep ${index + 1}: ${step.action}`);
  console.log(`Protocol: ${step.protocol.name}`);

  // Show input details
  step.input.forEach((input, inputIndex) => {
    console.log(
      `Input ${inputIndex + 1}: ${input.amount} ${input.asset.symbol} ($${
        input.amountUSD
      })`
    );
  });

  // Show output details
  step.output.forEach((output, outputIndex) => {
    console.log(
      `Output ${outputIndex + 1}: ${output.amount} ${output.asset.symbol} ($${
        output.amountUSD
      })`
    );
    if (output.minAmount) {
      console.log(`Minimum return: ${output.minAmount} ${output.asset.symbol}`);
    }
  });

  console.log(`Estimated duration: ${step.estimatedDuration}s`);

  // Show fees if any
  if (step.fee.length > 0) {
    const stepFees = step.fee.reduce(
      (acc, fee) => acc + parseFloat(fee.amountUSD),
      0
    );
    console.log(`Step fees: $${stepFees.toFixed(5)}`);
  }
});

// Calculate total fees across all steps
const totalFees = zapQuote.path.reduce((acc, step) => {
  return (
    acc +
    step.fee.reduce(
      (stepTotal, fee) => stepTotal + parseFloat(fee.amountUSD),
      0
    )
  );
}, 0);

// Calculate total duration
const totalDuration = zapQuote.path.reduce(
  (acc, step) => acc + step.estimatedDuration,
  0
);

console.log(`\nSummary:`);
zapQuote.output.forEach((out) => {
  console.log(`Expected output: ${out.amount} ${out.asset.symbol} ($${out.amountUSD})`);
});
console.log(`Total fees: $${totalFees.toFixed(5)}`);
console.log(`Total duration: ${totalDuration}s`);
```

## Advanced Examples

### Cross-Chain Liquidity Provision

```typescript theme={null}
// Bridge USDC from Ethereum to Arbitrum and provide liquidity to Uniswap V3
const crossChainLpQuote = await dZap.getZapQuote({
  srcChainId: 8453, // Base
  destChainId: 42161, // Arbitrum
  account: userAddress,
  srcToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Ethereum
  destToken: "0xC6962004f452bE9203591991D15f6b388e09E8D0", // Uniswap V3 ETH/USDC LP
  amount: "1000000000", // 1000 USDC
  recipient: userAddress,
  slippage: 2, // Higher slippage for cross-chain
});

console.log("Cross-chain LP quote received:");
crossChainLpQuote.output.forEach((out) => {
  console.log(`Expected LP tokens: ${out.amount} ${out.asset.symbol}`);
});
console.log(`Steps required: ${crossChainLpQuote.path.length}`);
```

## Bundling Multiple Actions

Use `getZapBundleQuote` to quote several zap actions (e.g. multiple deposits, or a swap plus a deposit) in a single request. It returns the same `ZapQuoteResponse` shape as `getZapQuote`.

```typescript theme={null}
import type { ZapBundleRequest } from "@dzapio/sdk";

const bundleRequest: ZapBundleRequest = {
  account: userAccount,
  recipient: userAccount,
  refundee: userAccount,
  slippage: 1,
  actions: [
    {
      action: "swap",
      srcChainId: 42161,
      srcToken: { address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", amount: "1000000" },
      destToken: "0x724dc807b04555b71ed48a6896b6F41593b8C637",
    },
  ],
};

const bundleQuote = await dZap.getZapBundleQuote(bundleRequest);
```

| Parameter        | Type                | Required | Description                                                                                                                                                 |
| ---------------- | ------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `actions`        | ZapBundleAction\[]  | yes      | The actions to bundle (each with its own `action`, `srcToken`, `srcChainId`, optional `destToken`/`destChainId`/`positionDetails`/`poolDetails`/`protocol`) |
| `account`        | string              | yes      | User's wallet address                                                                                                                                       |
| `recipient`      | string              | yes      | Address to receive the final tokens/positions                                                                                                               |
| `refundee`       | string              | yes      | Address to receive refunds if an action fails partway                                                                                                       |
| `slippage`       | number              | yes      | Slippage tolerance as percentage                                                                                                                            |
| `quotesOnly`     | boolean             | no       | If `true`, skip building executable transaction steps                                                                                                       |
| `estimateGas`    | boolean             | no       | Whether to include a gas estimate in the response                                                                                                           |
| `integrator`     | ZapIntegratorConfig | no       | Integrator fee configuration                                                                                                                                |
| `allowedDexes`   | string\[]           | no       | Array of allowed DEX protocols                                                                                                                              |
| `allowedBridges` | string\[]           | no       | Array of allowed bridge protocols                                                                                                                           |

`ZapBundleSrcToken` is `{ address: string; amount?: string }`, `srcToken` on each action accepts either a single object or an array of them.

## Next Steps

Once you have received a zap quote, you can proceed to:

1. [Execute the zap transaction](/sdk/zap/execute-zap) on the blockchain
2. [Track the status](/sdk/zap/status-tracking) of your zap

<Note>
  Before executing zaps, tokens typically require approval to allow the DZap
  contracts to spend them on your behalf. Learn more about gas-optimized
  approval mechanisms in the [Approval Mechanisms](/sdk/approval-mechanisms)
  section.
</Note>
