> For the complete documentation index, see [llms.txt](https://fastlane-labs.gitbook.io/polygon-fastlane/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fastlane-labs.gitbook.io/polygon-fastlane/searcher-guides/searcher-contract-integration/atlassolvercall.md).

# atlasSolverCall

## Solver Interface

Searchers need to implement the following interface in their smart contracts:

See ([Example Solver Repository](https://github.com/FastLane-Labs/atlas-solver-example))

```solidity
interface ISolverContract {
    function atlasSolverCall(
        address solverOpFrom,
        address executionEnvironment,
        address bidToken,
        uint256 bidAmount,
        bytes calldata solverOpData,
        bytes calldata extraReturnData
    )
        external payable;
}
```

<table><thead><tr><th>Name</th><th width="135">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>solverOpFrom</code></td><td>address</td><td>The address initiating the solver operation.</td></tr><tr><td><code>executionEnvironment</code></td><td>address</td><td>The address of the Execution Environment.</td></tr><tr><td><code>bidToken</code></td><td>address</td><td>The token used for bidding; use zero address to indicate POL</td></tr><tr><td><code>bidAmount</code></td><td>uint256</td><td>The amount of tokens bid in wei</td></tr><tr><td><code>solverOpData</code></td><td>bytes</td><td>The data associated with the solver operation.</td></tr><tr><td><code>extraReturnData</code></td><td>bytes</td><td>Additional data to return after execution.</td></tr><tr><td><code>payable</code></td><td>-</td><td>Indicates that ether can be sent with the call (if any).</td></tr></tbody></table>

{% hint style="warning" %}
The `bidAmount` will have to be transferred at the end of the solver call to the `executionEnvironment` address. We provide opinionated modifiers which can be easily used to get started.
{% endhint %}

## **Important Modifiers**

The [`SolverBase`](https://github.com/FastLane-Labs/atlas/blob/main/src/contracts/solver/SolverBase.sol) contract includes important modifiers that you should utilize in your `atlasSolverCall` function implementation:

### 1. `safetyFirst` Modifier:

```solidity
modifier safetyFirst(address executionEnvironment, address solverOpFrom) {
    if (msg.sender != _atlas) revert InvalidEntry();
    if (solverOpFrom != _owner) revert InvalidCaller();

    _;

    uint256 shortfall = IAtlas(_atlas).shortfall();

    if (shortfall < msg.value) shortfall = 0;
    else shortfall -= msg.value;

    if (msg.value > address(this).balance) {
        IWETH9(WETH_ADDRESS).withdraw(msg.value - address(this).balance);
    }

    IAtlas(_atlas).reconcile{ value: msg.value }(shortfall);
}
```

**This modifier:**

* Ensures that only the Atlas contract can call the function
* Verifies that the solver operation is from the authorized owner
* Handles any shortfall in the Atlas contract after the main function execution
* Unwraps WETH if necessary to cover the msg.value
* Reconciles the shortfall with the Atlas contract

### 2. `payBids` Modifier:

```solidity
modifier payBids(address executionEnvironment, address bidToken, uint256 bidAmount) {
    _;

    if (bidToken == address(0)) {
        // Pay bid in ETH
        if (bidAmount > address(this).balance) {
            IWETH9(WETH_ADDRESS).withdraw(bidAmount - address(this).balance);
        }
        SafeTransferLib.safeTransferETH(executionEnvironment, bidAmount);
    } else {
        // Pay bid in ERC20 (bidToken)
        SafeTransferLib.safeTransfer(bidToken, executionEnvironment, bidAmount);
    }
}
```

**This modifier:**

* Handles the payment of the solver's bid to the Execution Environment
* Supports payments in both POL (Native) and ERC20 tokens
* Unwraps WETH if necessary to cover ETH payments
* Uses [`SafeTransferLib`](https://github.com/Vectorized/solady/blob/main/src/utils/SafeTransferLib.sol) for secure token transfers

When inheriting from [`SolverBase`](https://github.com/FastLane-Labs/atlas/blob/main/src/contracts/solver/SolverBase.sol), it's crucial to use these modifiers correctly in your `atlasSolverCall` function implementation to ensure proper security checks and bid payments.
