Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.nexroute.io/llms.txt

Use this file to discover all available pages before exploring further.

The wrapper contract is a thin Solidity contract deployed by nexroute on each supported chain. It accepts a single calldata blob containing the user’s Permit2 authorisation, the aggregator swap calldata, and nexroute’s backrun calldata, and executes them atomically in one transaction. Use this shape when you want the simplest integration: no partner contract changes, no router modifications, just a single function call from the user’s transaction.

Interface

function execute(
    ISignatureTransfer.PermitTransferFrom calldata permit,
    bytes calldata signature,
    bytes calldata swapData,
    bytes calldata backrunData
) external;

function backrun(
    address baseToken,
    uint256 amountIn,
    bytes[] memory swaps
) external payable;

function sweep(address token) external;
execute is the entrypoint partners call. backrun is the function the wrapper invokes internally on delegatecall(backrunData). sweep exists so any dust trapped in the contract can be forwarded to the nexroute fee wallet.

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, backrunData) and submit it as the user’s transaction.

What you receive from nexroute

{
    "target": "0x...",
    "callData": "0x..."
}
FieldDescription
targetnot used in this shape; the wrapper invokes the backrun internally via delegatecall
callDatapass as the backrunData argument to execute(...); null when no arbitrage opportunity is found
When callData is null, no arbitrage opportunity was found. Either skip the wrapper entirely and submit the user’s swap directly, or call execute(...) with backrunData = "0x" so the wrapper’s internal delegatecall is a no-op.

Permit2 signature

The user signs the Permit2 typed-data domain. Domain values:
const domain = {
    name: "Permit2",
    chainId,
    verifyingContract: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
};
const types = {
    PermitTransferFrom: [
        { name: "permitted", type: "TokenPermissions" },
        { name: "spender", type: "address" },
        { name: "nonce", type: "uint256" },
        { name: "deadline", type: "uint256" },
    ],
    TokenPermissions: [
        { name: "token", type: "address" },
        { name: "amount", type: "uint256" },
    ],
};
const value = {
    permitted: { token: inputToken, amount: amountIn },
    spender: wrapperAddress,
    nonce,
    deadline,
};
const signature = await user.signTypedData(domain, types, value);
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

const wrapper = new ethers.Contract(wrapperAddress, wrapperAbi, provider);

const tx = await wrapper.connect(user).execute.populateTransaction(
    {
        permitted: { token: inputToken, amount: amountIn },
        nonce,
        deadline,
    },
    signature,
    swapData,    // aggregator calldata
    backrunData, // from nexroute backrun API
);

// submit `tx` through any RPC, or through a private relay for mempool privacy

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. Otherwise output tokens stay in the wrapper and are swept to the nexroute fee wallet.
  • The wrapper holds an allowance to the target aggregator only for the duration of the swap; allowance is revoked before the backrun runs.

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, delegatecall).

Deployments

Contract addresses per chain are published as part of integrator onboarding. Contact nexroute for current addresses on your target chain(s).