Skip to main content
The wrapper contract is a thin Solidity contract that you deploy yourself, on each chain you use. It accepts the user’s Permit2 authorisation, the aggregator swap calldata, and nexroute’s backrun call (contract and calldata), and executes them atomically in one transaction. This page describes one suggested implementation. You are free to design your own wrapper. Use this shape when you want the simplest integration: no changes to your existing contracts or router, just a single function call from the user’s transaction.

Interface

execute is the entrypoint partners call. It handles the Permit2 pull, the aggregator swap, and the backrun atomically.

Flow

  1. Get aggregator swap calldata. Set receiver = user so output tokens go directly to the end user, not the wrapper.
  2. Ask nexroute for a backrun via the backrun API.
  3. Have the user sign a Permit2 PermitTransferFrom typed-data message with spender = <wrapper address>, permitted.token = <input token>, permitted.amount = <amount in>.
  4. ABI-encode execute(permit, signature, swapData, backrunContract, backrunData) and submit it as the user’s transaction.

What you receive from nexroute

A JSON-RPC envelope from the eth_backrun API. The fields used by this shape: When the JSON-RPC result is null, no arbitrage opportunity was found. Either skip the wrapper entirely and submit the user’s swap directly, or call execute(...) with backrunContract = address(0) and backrunData = "0x" so the wrapper skips the backrun.

Permit2 signature

The user signs the Permit2 typed-data domain. Domain values:
The user must have approved Permit2 (0x000000000022D473030F116dDEE9F6B43aC78BA3) for the input token at least once. After that, every Embedded transaction is one off-chain signature.

Building the execute call

Submission

The resulting transaction can be submitted through any RPC. For mempool privacy, submit through a private relay.

Invariants

  • Permit2 spender must equal the wrapper contract address.
  • The aggregator swap calldata must set receiver = user. If the swap sends its output back to its caller instead, the output lands in the wrapper.
  • The wrapper holds an allowance to the target aggregator only for the duration of the swap; allowance is revoked before the backrun runs.
  • The wrapper calls backrunContract with a plain call after the swap, never a delegatecall, and ignores its result: nexroute’s code never runs as the wrapper, and a failed backrun cannot revert the user’s swap.

Failure modes

  • Permit2 signature invalid or expired: revert before any funds move.
  • Aggregator swap reverts: revert; Permit2 pull is rolled back atomically. User loses only gas.
  • Backrun reverts: caught silently. User swap still completes. User pays gas for the failed attempt.

Gas

Approximate execute gas cost: 200k–350k depending on the depth of the backrun arbitrage path. The wrapper itself adds roughly 60k–80k over a direct aggregator call (Permit2 pull, approval, revoke, backrun call).

Deployment

You deploy and own the wrapper, on each chain you use. Have it reviewed as you would any contract your users sign a permit for.