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

# UniswapV3Adapter

> UniswapV3Adapter implements ISwapRouter on top of Uniswap V3 SwapRouter02.

UniswapV3Adapter implements ISwapRouter on top of Uniswap V3 SwapRouter02. Its `quote` reads a pool TWAP (or spot when the pool lacks history) and is the slippage reference for Zap, PositionRouter, FeeCollector, and CreatorFeeRouter. It is never a collateral price. An owner sets the default fee tier, a per-pair fee, and the TWAP window, with two-step ownership transfer.

`UniswapV3Adapter` lets you:

* Quote a multi-hop swap against pool TWAPs
* Execute an exact-input multi-hop swap
* Read the fee tier used for any pair
* Let the owner tune fee tiers and the TWAP window

This contract is not deployed on a listed network yet. Watch [Addresses](/resources/addresses).

| Network                 | Address      |
| ----------------------- | ------------ |
| Robinhood Chain testnet | Not deployed |

The source code is [`src/periphery/UniswapV3Adapter.sol`](https://github.com/stockline-xyz/contracts/blob/main/src/periphery/UniswapV3Adapter.sol) on GitHub. The ABI is [`/abis/UniswapV3Adapter.json`](/abis/UniswapV3Adapter.json).

## Write methods

### setOwner

```solidity theme={"system"}
function setOwner(address owner_) external
```

Proposes a new owner. The new owner must call `acceptOwner`. Owner only. Reverts with ZeroAddress for the zero address.

<Warning>
  Owner only.
</Warning>

**Input parameters**

| Name    | Type      | Description         |
| ------- | --------- | ------------------- |
| owner\_ | `address` | The proposed owner. |

### acceptOwner

```solidity theme={"system"}
function acceptOwner() external
```

Completes the ownership transfer. Only the pending owner can call it (NotOwner otherwise).

### setDefaultFee

```solidity theme={"system"}
function setDefaultFee(uint24 fee) external
```

Sets the fee tier used when a pair has no specific fee. Owner only. Reverts with InvalidFee for 0.

<Warning>
  Owner only.
</Warning>

**Input parameters**

| Name | Type     | Description                      |
| ---- | -------- | -------------------------------- |
| fee  | `uint24` | Fee tier in hundredths of a bip. |

### setTwapWindow

```solidity theme={"system"}
function setTwapWindow(uint32 window) external
```

Sets the TWAP lookback used by `quote`. A window of 0 makes `quote` use spot. Owner only.

<Warning>
  Owner only. A 0 window makes quotes easy to manipulate within a block.
</Warning>

**Input parameters**

| Name   | Type     | Description |
| ------ | -------- | ----------- |
| window | `uint32` | Seconds.    |

### setPairFee

```solidity theme={"system"}
function setPairFee(
    address tokenA,
    address tokenB,
    uint24 fee
) external
```

Sets the fee tier for one pair. Owner only. Reverts with InvalidPath for zero or identical tokens and InvalidFee for 0.

<Warning>
  Owner only.
</Warning>

**Input parameters**

| Name   | Type      | Description                      |
| ------ | --------- | -------------------------------- |
| tokenA | `address` | One token.                       |
| tokenB | `address` | The other token.                 |
| fee    | `uint24`  | Fee tier in hundredths of a bip. |

### swapExactTokensForTokens

```solidity theme={"system"}
function swapExactTokensForTokens(
    uint256 amountIn,
    uint256 amountOutMin,
    address[] memory path,
    address to
) external nonReentrant returns (uint256 amountOut)
```

Pulls `amountIn` of the first path token from the caller and swaps it through SwapRouter02 to `to`. Reverts with the same path errors as `quote`, ZeroAddress for a zero recipient, and ZeroAmount if the output is 0. SwapRouter02 reverts if the output is below `amountOutMin`.

<Warning>
  The caller must approve the adapter for `amountIn` of the input token.
</Warning>

**Input parameters**

| Name         | Type        | Description                           |
| ------------ | ----------- | ------------------------------------- |
| amountIn     | `uint256`   | Input amount.                         |
| amountOutMin | `uint256`   | Minimum acceptable output.            |
| path         | `address[]` | Token addresses from input to output. |
| to           | `address`   | Recipient of the output.              |

**Return values**

| Type      | Description                         |
| --------- | ----------------------------------- |
| `uint256` | amountOut: Output amount delivered. |

## Read methods

### quote

```solidity theme={"system"}
function quote(
    uint256 amountIn,
    address[] memory path
) external view returns (uint256 amountOut)
```

Returns the expected output of swapping `amountIn` along `path` using each hop's TWAP over `twapWindow`, or spot if the window is 0 or the pool cannot observe that far back. Reverts with InvalidPath for fewer than two hops or repeated tokens, ZeroAddress for a zero hop, ZeroAmount for a zero input or output, and NoPool if a hop has no pool at the configured fee.

**Input parameters**

| Name     | Type        | Description                                     |
| -------- | ----------- | ----------------------------------------------- |
| amountIn | `uint256`   | Input amount in the first token's native units. |
| path     | `address[]` | Token addresses from input to output.           |

**Return values**

| Type      | Description                                                  |
| --------- | ------------------------------------------------------------ |
| `uint256` | amountOut: Expected output in the last token's native units. |

### feeOf

```solidity theme={"system"}
function feeOf(address tokenA, address tokenB) public view returns (uint24 fee)
```

Returns the fee tier for a pair: the configured pair fee if set, else `defaultFee`. Order of the two tokens does not matter.

**Input parameters**

| Name   | Type      | Description      |
| ------ | --------- | ---------------- |
| tokenA | `address` | One token.       |
| tokenB | `address` | The other token. |

**Return values**

| Type     | Description                                                     |
| -------- | --------------------------------------------------------------- |
| `uint24` | fee: Fee tier in hundredths of a bip (for example 3000 = 0.3%). |

## Events

### OwnerPending

```solidity theme={"system"}
event OwnerPending(address indexed owner)
```

Fires when a new owner is proposed.

### OwnerSet

```solidity theme={"system"}
event OwnerSet(address indexed owner)
```

Fires when the pending owner accepts.

### DefaultFeeSet

```solidity theme={"system"}
event DefaultFeeSet(uint24 fee)
```

Fires when the default fee tier changes.

### TwapWindowSet

```solidity theme={"system"}
event TwapWindowSet(uint32 window)
```

Fires when the TWAP window changes.

### PairFeeSet

```solidity theme={"system"}
event PairFeeSet(
    address indexed tokenA,
    address indexed tokenB,
    uint24 fee
)
```

Fires when a pair fee is set.

## Errors

### ZeroAddress

```solidity theme={"system"}
error ZeroAddress()
```

A constructor address, path hop, or recipient was zero.

### NotOwner

```solidity theme={"system"}
error NotOwner()
```

The caller is not the owner (or not the pending owner for acceptOwner).

### ZeroAmount

```solidity theme={"system"}
error ZeroAmount()
```

The input or output amount was zero.

### InvalidPath

```solidity theme={"system"}
error InvalidPath()
```

The path has fewer than two hops, repeats a token, or a pair uses zero or identical tokens.

### InvalidFee

```solidity theme={"system"}
error InvalidFee()
```

A fee tier was 0.

### NoPool

```solidity theme={"system"}
error NoPool(
    address tokenA,
    address tokenB,
    uint24 fee
)
```

No Uniswap V3 pool exists for the pair at the configured fee.
