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

# Partner Executor Contract

> A public Solidity reference for executing AKKA partner quotes through your own contract.

Use this reference only when your integration executes the transaction returned by
`GET /partner/v1/{chainId}/quote` through a partner-owned smart contract. If an EOA
sends the returned transaction directly, you do not need an executor contract.

This source is published here so integrators do not need access to AKKA's private
contract repository. It is an integration example, not a production deployment or
an audited library. Your team must review, test, deploy, own, and monitor its adapted
version.

## Execution model

* Set the quote request's `payer` to the executor contract address.
* The executor must be the address that calls `quote.tx.to`.
* For ERC-20 input, the user approves the executor; the executor pulls the exact
  input amount and grants the allowlisted AKKA Router an exact, per-call approval.
* For native input, forward exactly `quote.tx.value`.
* The output recipient is already encoded in `quote.tx.data`; do not modify the
  returned calldata.
* Allowlist only active router addresses returned by `GET /partner/v1/chains`, and
  validate their published bytecode hashes before enabling them.

## Solidity reference

The example targets Solidity `0.8.20` and OpenZeppelin Contracts 5.x.

```solidity AkkaPartnerExecutor.sol theme={null}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/// @notice Reference adapter for partners that execute AKKA calldata through
/// their own contract. This is an integration example, not an AKKA deployment.
/// The partner must audit it and configure the exact AKKA Router addresses it
/// is willing to call.
contract AkkaPartnerExecutor is Ownable, ReentrancyGuard {
    using SafeERC20 for IERC20;

    mapping(address router => bool allowed) public allowedRouter;

    error RouterNotAllowed();
    error RouterCallFailed(bytes reason);
    error InvalidNativeValue();

    event RouterPermissionSet(address indexed router, bool allowed);

    constructor(address owner_) Ownable(owner_) {}

    receive() external payable {}

    function setRouterAllowed(address router, bool allowed) external onlyOwner {
        allowedRouter[router] = allowed;
        emit RouterPermissionSet(router, allowed);
    }

    /// @notice Pull ERC-20 input from the user, approve the allowlisted AKKA
    /// Router for exactly this call, and execute partner API `tx.data`.
    /// The output recipient is already encoded in the calldata.
    function executeERC20(
        address router,
        IERC20 tokenIn,
        uint256 amountIn,
        bytes calldata routerCalldata
    ) external nonReentrant returns (bytes memory result) {
        if (!allowedRouter[router]) revert RouterNotAllowed();

        uint256 balanceBefore = tokenIn.balanceOf(address(this));
        tokenIn.safeTransferFrom(msg.sender, address(this), amountIn);
        tokenIn.forceApprove(router, amountIn);
        (bool ok, bytes memory returnData) = router.call(routerCalldata);
        tokenIn.forceApprove(router, 0);
        if (!ok) revert RouterCallFailed(returnData);

        uint256 balanceAfter = tokenIn.balanceOf(address(this));
        if (balanceAfter > balanceBefore) {
            tokenIn.safeTransfer(msg.sender, balanceAfter - balanceBefore);
        }
        return returnData;
    }

    /// @notice Execute a native-input partner quote. `msg.value` must equal
    /// the `tx.value` returned by the partner API.
    function executeNative(
        address router,
        bytes calldata routerCalldata,
        uint256 expectedValue
    ) external payable nonReentrant returns (bytes memory result) {
        if (!allowedRouter[router]) revert RouterNotAllowed();
        if (msg.value != expectedValue) revert InvalidNativeValue();

        (bool ok, bytes memory returnData) = router.call{value: msg.value}(routerCalldata);
        if (!ok) revert RouterCallFailed(returnData);
        return returnData;
    }
}
```

## Before production

At minimum, partners should add tests for router allowlisting, fee-on-transfer and
non-standard tokens relevant to their product, native-value mismatches, refund
behavior, malicious-token callbacks, paused execution, and router upgrades. Use a
multisig or governed role for router permissions and define an emergency process to
disable a router immediately.

AKKA does not deploy this executor for partners. A contract is optional, and when a
partner chooses this model, its deployment, audit, upgrades, and operational controls
remain the partner's responsibility.
