# DexSwapperUManager

[Git Source](https://github.com/Ion-Protocol/nucleus-boring-vault/blob/cc0b494b83e17b9b169a73b96050d2810b690477/src/micro-managers/DexSwapperUManager.sol)

**Inherits:** UManager

Required Merkle Root Leaves

* ERC20 approves with `router` spender.
* IUniswapV3Router.exactInput(params), with all desired paths.

## State Variables

### MAX\_SLIPPAGE

```solidity
uint256 internal constant MAX_SLIPPAGE = 0.1e4;
```

### allowedSlippage

Slippage check enforced after swaps.

```solidity
uint16 public allowedSlippage = 0.0005e4;
```

### router

The UniswapV3 Router.

```solidity
IUniswapV3Router internal immutable router;
```

### balancerVault

The BalancerVault this uManager works with.

```solidity
BalancerVault internal immutable balancerVault;
```

### priceRouter

The PriceRouter contract used to check slippage.

```solidity
PriceRouter internal immutable priceRouter;
```

## Functions

### constructor

```solidity
constructor(
    address _owner,
    address _manager,
    address _boringVault,
    address _router,
    address _balancerVault,
    address _priceRouter
)
    UManager(_owner, _manager, _boringVault);
```

### setAllowedSlippage

Sets the maximum allowed slippage during a swap.

*Callable by MULTISIG\_ROLE.*

```solidity
function setAllowedSlippage(uint16 _allowedSlippage) external requiresAuth;
```

### swapWithUniswapV3

Performs a swap using the UniswapV3 Router, and enforces a slippage check.

*Callable by STRATEGIST\_ROLE.*

```solidity
function swapWithUniswapV3(
    bytes32[][] calldata manageProofs,
    address[] calldata decodersAndSanitizers,
    ERC20[] memory path,
    uint24[] memory fees,
    uint256 amountIn,
    uint256 amountOutMinimum,
    uint256 deadline
)
    external
    requiresAuth
    enforceRateLimit;
```

**Parameters**

| Name                    | Type          | Description                                                                                                            |
| ----------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `manageProofs`          | `bytes32[][]` | 2 manage proofs, the first one for the ERC20 approval, and the second for the router exactInput call                   |
| `decodersAndSanitizers` | `address[]`   | 2 DecodersAndSanitizers one that implements ERC20 approve, and one that implements IUniswapV3Router.exactInput(params) |
| `path`                  | `ERC20[]`     | the ERC20 token swap path                                                                                              |
| `fees`                  | `uint24[]`    | the fees to specify which pools to swap with                                                                           |
| `amountIn`              | `uint256`     | the amount of path\[0] to swap                                                                                         |
| `amountOutMinimum`      | `uint256`     | the minimum amount of path\[path.length - 1] to get out from the swap                                                  |
| `deadline`              | `uint256`     | the swap deadline                                                                                                      |

### swapWithBalancerV2

Performs a swap using the BalancerV2 Vault, and enforces a slippage check.

*Callable by STRATEGIST\_ROLE.*

```solidity
function swapWithBalancerV2(
    bytes32[][] calldata manageProofs,
    address[] calldata decodersAndSanitizers,
    DecoderCustomTypes.SingleSwap calldata singleSwap,
    DecoderCustomTypes.FundManagement calldata funds,
    uint256 limit,
    uint256 deadline
)
    external
    requiresAuth
    enforceRateLimit;
```

**Parameters**

| Name                    | Type                                | Description                                                                                             |
| ----------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `manageProofs`          | `bytes32[][]`                       | 2 manage proofs, the first one for the ERC20 approval, and the second for the swap                      |
| `decodersAndSanitizers` | `address[]`                         | 2 DecodersAndSanitizers one that implements ERC20 approve, and one that implements BalancerV2Vault.swap |
| `singleSwap`            | `DecoderCustomTypes.SingleSwap`     | the swap data                                                                                           |
| `funds`                 | `DecoderCustomTypes.FundManagement` | the fund management data                                                                                |
| `limit`                 | `uint256`                           | the maximum amount of assetIn to swap, or the minimum amount of assets out to receive                   |
| `deadline`              | `uint256`                           | the swap deadline                                                                                       |

### swapWithCurve

Performs a swap using a Curve pool, and enforces a slippage check.

*Callable by STRATEGIST\_ROLE.*

```solidity
function swapWithCurve(
    bytes32[][] memory manageProofs,
    address[] memory decodersAndSanitizers,
    CurveInfo memory info,
    uint256 i,
    uint256 j,
    uint256 dx,
    uint256 min_dy
)
    external
    requiresAuth
    enforceRateLimit;
```

**Parameters**

| Name                    | Type          | Description                                                                                           |
| ----------------------- | ------------- | ----------------------------------------------------------------------------------------------------- |
| `manageProofs`          | `bytes32[][]` | 2 manage proofs, the first one for the ERC20 approval, and the second for the swap                    |
| `decodersAndSanitizers` | `address[]`   | 2 DecodersAndSanitizers one that implements ERC20 approve, and one that implements CurvePool.exchange |
| `info`                  | `CurveInfo`   | the Curve pool info                                                                                   |
| `i`                     | `uint256`     | the index of the token to swap from                                                                   |
| `j`                     | `uint256`     | the index of the token to swap to                                                                     |
| `dx`                    | `uint256`     | the amount of token i to swap                                                                         |
| `min_dy`                | `uint256`     | the minimum amount of token j to receive                                                              |

## Events

### SlippageUpdated

```solidity
event SlippageUpdated(uint16 oldSlippage, uint16 newSlippage);
```

## Errors

### DexSwapperUManager\_\_Slippage

```solidity
error DexSwapperUManager__Slippage();
```

### DexSwapperUManager\_\_NewSlippageTooLarge

```solidity
error DexSwapperUManager__NewSlippageTooLarge();
```

### DexSwapperUManager\_\_UniswapV3BadPathOrFees

```solidity
error DexSwapperUManager__UniswapV3BadPathOrFees();
```

## Structs

### CurveInfo

Data needed to swap in a Curve pool

*This was made into a struct to prevent stack too deep errors.*

```solidity
struct CurveInfo {
    address pool;
    ERC20 assetIn;
    ERC20 assetOut;
    bytes4 selector;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nucleusearn.io/nucleus-architecture/smart-contracts/contracts/micro-managers/dexswapperumanager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
