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

# Aggregator integration

> Integrate PropAMM like a pool: discover pairs, quote with one eth_call, fill with a push-payment swap.

`PropAMMVenue` merges every maker's ladder, best price first. Integrate it like a pool. No API, no signatures, no per-trade requests.

| Chain                                                   | `PropAMMVenue`                               |
| ------------------------------------------------------- | -------------------------------------------- |
| Base (8453), BNB Smart Chain (56), Base Sepolia (84532) | `0x00000035a8a58f704ab0D567D6c67A486428E35a` |

<Steps>
  <Step title="Discover pairs">
    ```solidity theme={null}
    function getPairs() external view returns (TokenPair[] memory);      // struct TokenPair { address token0; address token1; }, token0 < token1
    function isActive(address tokenIn, address tokenOut) external view returns (bool);
    ```

    | Function                      | Returns                                                                  |
    | ----------------------------- | ------------------------------------------------------------------------ |
    | `getPairs()`                  | advertised pairs; both directions are tradeable when a maker quotes them |
    | `isActive(tokenIn, tokenOut)` | `true` when any maker has depth for that direction now                   |

    Re-read `getPairs()` on `PairAdded`.
  </Step>

  <Step title="Quote">
    ```solidity theme={null}
    function quote(address tokenIn, address tokenOut, uint256 amountIn) external view returns (uint256 amountOut);
    function levels(address tokenIn, address tokenOut) external view returns (uint256[] memory cumSizes, uint256[] memory prices, uint256 earliestExpiry);
    function board(address mm, address tokenIn, address tokenOut) external view returns (uint256[] memory sizes, uint256[] memory prices, uint256 filled, uint256 remaining, uint256 expiresAt);
    ```

    | Function | Returns                                                                                                     |
    | -------- | ----------------------------------------------------------------------------------------------------------- |
    | `quote`  | exact `swap` output at this block, net of the protocol fee; reverts `Inactive()` if the size is not covered |
    | `levels` | merged ladder: cumulative sizes, price per segment, earliest expiry                                         |
    | `board`  | one maker's live ladder, filled and remaining size, expiry                                                  |

    Segment output is `floor(take * price / 1e18)`. Per-block caps are already applied in all three.
  </Step>

  <Step title="Swap">
    Push payment: transfer exactly `amountIn` to the venue, then call `swap` in the same transaction.

    ```solidity theme={null}
    function swap(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, address recipient, uint256 deadline) external returns (uint256 amountOut);
    function swapWithFee(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, address recipient, uint256 deadline, uint256 extraFeePpm, address feeReceiver) external returns (uint256 amountOut);
    ```

    | Parameter      | Meaning                                                  |
    | -------------- | -------------------------------------------------------- |
    | `amountIn`     | pushed amount; calldata byte offset 68 in both functions |
    | `minAmountOut` | checked on `recipient`'s balance change, after fees      |
    | `recipient`    | receives `tokenOut`; not zero, not the venue             |
    | `deadline`     | unix seconds; `0` disables                               |
    | `extraFeePpm`  | your fee, max `50_000` (5%)                              |
    | `feeReceiver`  | receives your fee in the same transaction                |

    A short push reverts. An over-push stays in the venue.
  </Step>

  <Step title="Refresh">
    Ladders can reprice every block, and per-block caps reset each block. Re-read each block, or on `AnchorCommitted`, `LadderCommitted`, `OffsetsCommitted`, `ControlsCommitted` and `MMFillExecuted` from the executor `0x000000fFA5f8Ae192Ab65204f9B7E062CbF4e05D`.
  </Step>
</Steps>

## Fees

| Step               | Formula                                                                     |
| ------------------ | --------------------------------------------------------------------------- |
| Protocol fee       | `gross * feeBps / 10_000`; `feeBps()` max 100; `quote` is already net of it |
| Your fee           | `net * extraFeePpm / 1_000_000`; `swapWithFee` only                         |
| Recipient receives | `net - yourFee`; `minAmountOut` is checked here                             |

## Reverts

| Revert                                | Selector     | Cause                                               | Action          |
| ------------------------------------- | ------------ | --------------------------------------------------- | --------------- |
| `Inactive()`                          | `0x2e8acb0d` | makers cannot cover the size, or `amountIn` is zero | route elsewhere |
| `InsufficientOutput(uint256,uint256)` | `0x2c19b8b8` | delivery below `minAmountOut`                       | refetch         |
| `DeadlinePassed()`                    | `0x70f65caa` | past `deadline`                                     | resubmit        |
| `BadRecipient()`                      | `0x67a2cc26` | `recipient` is zero or the venue                    | fix             |
| `ExtraFeeTooHigh(uint256)`            | `0x61539341` | `extraFeePpm` above 5%                              | fix             |
| `ZeroFeeReceiver()`                   | `0xb6802b7f` | fee set without `feeReceiver`                       | fix             |
| `FillLegFailed(address,bytes4,bytes)` | `0x33fd2c98` | a maker's provider reverted                         | retry           |

## Event

```solidity theme={null}
event PropAMMSwap(address indexed sender, address indexed receiver, address tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut, bytes32 indexed lane);
```

| Field                  | Value                                                                |
| ---------------------- | -------------------------------------------------------------------- |
| `topic0`               | `0x20198e5e9a55297673b83a909cf489803a8e65b9b3b28f0336d7786201d88ced` |
| `lane` for venue swaps | `0x38bac6022d372bf52947085f84474211d0d8687b830ca07361b408294b503b24` |
| emitted                | once per swap                                                        |
| `amountOut`            | measured delivery to `receiver`, after fees                          |

## Selectors

| Function                                                                       | Selector     |
| ------------------------------------------------------------------------------ | ------------ |
| `getPairs()`                                                                   | `0x767eb5ef` |
| `isActive(address,address)`                                                    | `0xae131deb` |
| `quote(address,address,uint256)`                                               | `0xb6466384` |
| `levels(address,address)`                                                      | `0x501dc709` |
| `board(address,address,address)`                                               | `0xa5588684` |
| `swap(address,address,uint256,uint256,address,uint256)`                        | `0x9908fc8b` |
| `swapWithFee(address,address,uint256,uint256,address,uint256,uint256,address)` | `0xc13993c2` |
| `feeBps()`                                                                     | `0x24a9d853` |

## Test on Base Sepolia

| Token    | Address                                      | Decimals |
| -------- | -------------------------------------------- | -------- |
| MockWETH | `0x8b414aD7005EeFd315aF2A16538885Eae229bab7` | 18       |
| MockUSDC | `0xAbbdbbbd6d56593A9c5656c06cB30D61E4a544Df` | 18       |
| MockDAI  | `0xa3Db3e064D74fF11e6E07b9869a67f1E4FCFEcFb` | 18       |

Pairs: `MockWETH/MockUSDC`, `MockDAI/MockUSDC`. Anyone can call `mint(address,uint256)`.
