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

# Migrating to the BebopRouter contract

> Update a direct RFQ integration to use the BebopRouter smart contract.

Bebop has introduced the **BebopRouter** `0xBeb0009ACa35087ce7cCF11637E24dd1Aad3bf2A` contract, which now wraps BebopSettlement extending its functionality.

## Do you need to migrate?

With `Standard` approvals, no changes are required if your integration already reads these fields from the quote response. Confirm both:

* **Approvals.** You approve the `approvalTarget` from the quote response, not a hardcoded address. See [Token approvals](https://docs.bebop.xyz/core-concepts/token-approvals.md).
* **Broadcast.** You send the returned `tx` object as-is; `tx.to` already targets the correct contract.

If you hardcoded the BebopSettlement address anywhere (for approvals or as the transaction target), switch to reading `approvalTarget` and `tx` from the quote response.

## Reading the calldata

With `Standard` approvals, Bebop returns calldata ready to broadcast in `tx.data`. It calls the router's `swap` function:

```solidity theme={null}
function swap(
    int256 exactAmount,
    BebopRouterOrder calldata order,
    bytes calldata extraInfo,
    bytes calldata routerSignature,
    bytes calldata bebopPmmCalldata,
    Hook[] calldata hooks
)
```

| Parameter | Description |
| - | - |
| `exactAmount` | Fill mode. `> 0`: exactIn, you send exactly this amount of `fromToken`. `< 0`: exactOut, you want exactly `\|exactAmount\|` of `toToken` after fees. `== 0`: use whatever `fromToken` balance the router holds. |
| `order` | The signed order struct. `fromAmount` / `toAmount` define the quote ratio used for scaling. |
| `routerSignature` | The router signer's EIP-712 signature over the order. |
| `bebopPmmCalldata` | The raw `BebopSettlement.swapSingle` / `swapAggregate` calldata the router wraps. |

For a concrete reference, see this [example transaction](https://etherscan.io/tx/0x071db51c478baf95d51fb69c4c80e1e8fcc90f68fcce94b0b6ce8e51321dd810).

## Permit2 self-execution

BebopRouter supports Permit2 self-execution for ERC-20 sell tokens.

**1. Request a quote**

Add `gasless=false&approval_type=Permit2` to your quote request. Set `taker_address` to the user who owns the tokens, not your wrapper contract.

**2. Approve Permit2**

If needed, approve `quote.approvalTarget` on the sell token for at least `quote.toSign.permitted.amount`. For this flow, `approvalTarget` is the Permit2 contract.

**3. Sign the permit**

Have the taker sign `quote.toSign` as the EIP-712 message using the [Permit2 witness types](https://github.com/bebop-dex/bebop-rfqa/blob/cde98215e8522c36f410c4c75649a71208cb1f5b/test/BebopRouter.test.ts#L589-L617).
Use the domain `{ name: "Permit2", chainId: quote.chainId, verifyingContract: quote.approvalTarget }` without a `version`.
Keep `spender` as returned: it is BebopRouter, not your wrapper.

**4. Add the signature and submit**

The returned `tx.data` calls `settle` with an empty `userSignature`.
With an ethers v6 `Interface` for [BebopRouter](https://github.com/bebop-dex/bebop-rfqa/blob/cde98215e8522c36f410c4c75649a71208cb1f5b/contracts/BebopRouter.sol), replace that final argument:

```javascript theme={null}
const args = routerInterface
  .decodeFunctionData("settle", quote.tx.data)
  .toArray(true)

args[6] = userSignature
quote.tx.data = routerInterface.encodeFunctionData("settle", args)
```

Simulate the completed transaction before submission. Then broadcast the updated `quote.tx`, or call `quote.tx.to` from your wrapper with the updated calldata.


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