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

# Settlement (swapExactIn)

> Implement the atomic settlement function RialtoRouter calls when your pool wins.

## Runtime behavior

RialtoRouter settles a winning leg by calling swapExactIn through a generic
RawCall action:

1. Input delivery. For ERC20 input, the router approves your contract for exactly
   amountIn immediately before the call, so you pull it with
   transferFrom(router, you, amountIn). The router revokes the approval to 0 right
   after. For native-ETH input, the router calls `swapExactIn{value: amountIn}`, so
   the function is payable.
2. Honor the amountIn parameter. It is the authoritative input amount for this
   fill. Pull and price against exactly the amountIn passed in; do not assume a
   fixed or pre-agreed size.
3. Output delivery. Send the output token to to, which is the RialtoRouter
   address. The router measures its own balance delta of the output token and
   requires received >= amountOutMin, reverting the whole swap otherwise.
4. deadline. Unix seconds. Enforcing it on your side is optional, since Rialto
   already bounds the swap's validity window. Treat 0 as no deadline.
5. Refunds. If you pull less than amountIn, the router refunds the unspent input,
   but the cleanest contract pulls and uses exactly amountIn.

## Parameters

| Param        | Type    | Meaning                                                 |
| ------------ | ------- | ------------------------------------------------------- |
| zeroForOne   | bool    | Same convention as the quote.                           |
| amountIn     | uint256 | Exact input to pull, router-supplied and authoritative. |
| amountOutMin | uint256 | Revert if you cannot deliver at least this.             |
| to           | address | Recipient of the output, always the RialtoRouter.       |
| deadline     | uint256 | Unix-seconds expiry.                                    |
| returns      | uint256 | Actual output delivered.                                |

## Approval and transfer pattern (ERC20)

```solidity theme={null}
// Router, before the call:    IERC20(tokenIn).approve(you, amountIn);
// You, inside swapExactIn:     IERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
//                              ... your pricing/inventory logic ...
//                              IERC20(tokenOut).transfer(to, amountOut);   // to == router
// Router, after the call:      IERC20(tokenIn).approve(you, 0);
```

## Native ETH

Native ETH is optional and advanced; most propAMM pairs are ERC20/ERC20, for
example WETH/USDC. If you want a native-ETH side, accept msg.value on input and
send ETH to to on output. Pick one convention across all your pairs, either
ETH/token everywhere or WETH/token everywhere, and represent native ETH with the
0xEeee...EEeE sentinel. Confirm the wiring with Rialto.
