# IMaverickV2Factory

### Functions <a href="#functions" id="functions"></a>

#### deployParameters <a href="#deployparameters" id="deployparameters"></a>

Called by deployer library to initialize a pool.

```solidity
function deployParameters()
    external
    view
    returns (
        uint64 feeAIn,
        uint64 feeBIn,
        uint32 lookback,
        int32 activeTick,
        uint64 tokenAScale,
        uint64 tokenBScale,
        IERC20 tokenA,
        IERC20 tokenB,
        uint16 tickSpacing,
        uint8 kinds,
        address accessor
    );
```

#### create <a href="#create" id="create"></a>

Create a new MaverickV2Pool with symmetric swap fees.

```solidity
function create(
    uint64 fee,
    uint16 tickSpacing,
    uint32 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    int32 activeTick,
    uint8 kinds
) external returns (IMaverickV2Pool);
```

**Parameters**

| Name          | Type     | Description                                                                                                                                                        |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `fee`         | `uint64` | Fraction of the pool swap amount that is retained as an LP in D18 scale.                                                                                           |
| `tickSpacing` | `uint16` | Tick spacing of pool where 1.0001^tickSpacing is the bin width.                                                                                                    |
| `lookback`    | `uint32` | Pool lookback in second in D2 scale.                                                                                                                               |
| `tokenA`      | `IERC20` | Address of tokenA.                                                                                                                                                 |
| `tokenB`      | `IERC20` | Address of tokenB.                                                                                                                                                 |
| `activeTick`  | `int32`  | Tick position that contains the active bins.                                                                                                                       |
| `kinds`       | `uint8`  | 1-15 number to represent the active kinds 0b0001 = static; 0b0010 = right; 0b0100 = left; 0b1000 = both. E.g. a pool with all 4 modes will have kinds = b1111 = 15 |

#### create <a href="#create-1" id="create-1"></a>

Create a new MaverickV2Pool.

```solidity
function create(
    uint64 feeAIn,
    uint64 feeBIn,
    uint16 tickSpacing,
    uint32 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    int32 activeTick,
    uint8 kinds
) external returns (IMaverickV2Pool);
```

**Parameters**

| Name          | Type     | Description                                                                                                                                                        |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `feeAIn`      | `uint64` | Fraction of the pool swap amount for tokenA-input swaps that is retained as an LP in D18 scale.                                                                    |
| `feeBIn`      | `uint64` | Fraction of the pool swap amount for tokenB-input swaps that is retained as an LP in D18 scale.                                                                    |
| `tickSpacing` | `uint16` | Tick spacing of pool where 1.0001^tickSpacing is the bin width.                                                                                                    |
| `lookback`    | `uint32` | Pool lookback in second in D2 scale.                                                                                                                               |
| `tokenA`      | `IERC20` | Address of tokenA.                                                                                                                                                 |
| `tokenB`      | `IERC20` | Address of tokenB.                                                                                                                                                 |
| `activeTick`  | `int32`  | Tick position that contains the active bins.                                                                                                                       |
| `kinds`       | `uint8`  | 1-15 number to represent the active kinds 0b0001 = static; 0b0010 = right; 0b0100 = left; 0b1000 = both. e.g. a pool with all 4 modes will have kinds = b1111 = 15 |

#### createPermissioned <a href="#createpermissioned" id="createpermissioned"></a>

Create a new MaverickV2PoolPermissioned with symmetric swap fees.

```solidity
function createPermissioned(
    uint64 fee,
    uint16 tickSpacing,
    uint32 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    int32 activeTick,
    uint8 kinds,
    address accessor
) external returns (IMaverickV2Pool);
```

**Parameters**

| Name          | Type      | Description                                                                                                                                                        |
| ------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `fee`         | `uint64`  | Fraction of the pool swap amount that is retained as an LP in D18 scale.                                                                                           |
| `tickSpacing` | `uint16`  | Tick spacing of pool where 1.0001^tickSpacing is the bin width.                                                                                                    |
| `lookback`    | `uint32`  | Pool lookback in second in D2 scale.                                                                                                                               |
| `tokenA`      | `IERC20`  | Address of tokenA.                                                                                                                                                 |
| `tokenB`      | `IERC20`  | Address of tokenB.                                                                                                                                                 |
| `activeTick`  | `int32`   | Tick position that contains the active bins.                                                                                                                       |
| `kinds`       | `uint8`   | 1-15 number to represent the active kinds 0b0001 = static; 0b0010 = right; 0b0100 = left; 0b1000 = both. E.g. a pool with all 4 modes will have kinds = b1111 = 15 |
| `accessor`    | `address` | Only address that can access the pool's public write functions.                                                                                                    |

#### createPermissioned <a href="#createpermissioned-1" id="createpermissioned-1"></a>

Create a new MaverickV2PoolPermissioned.

```solidity
function createPermissioned(
    uint64 feeAIn,
    uint64 feeBIn,
    uint16 tickSpacing,
    uint32 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    int32 activeTick,
    uint8 kinds,
    address accessor
) external returns (IMaverickV2Pool);
```

**Parameters**

| Name          | Type      | Description                                                                                                                                                        |
| ------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `feeAIn`      | `uint64`  | Fraction of the pool swap amount for tokenA-input swaps that is retained as an LP in D18 scale.                                                                    |
| `feeBIn`      | `uint64`  | Fraction of the pool swap amount for tokenB-input swaps that is retained as an LP in D18 scale.                                                                    |
| `tickSpacing` | `uint16`  | Tick spacing of pool where 1.0001^tickSpacing is the bin width.                                                                                                    |
| `lookback`    | `uint32`  | Pool lookback in second in D2 scale.                                                                                                                               |
| `tokenA`      | `IERC20`  | Address of tokenA.                                                                                                                                                 |
| `tokenB`      | `IERC20`  | Address of tokenB.                                                                                                                                                 |
| `activeTick`  | `int32`   | Tick position that contains the active bins.                                                                                                                       |
| `kinds`       | `uint8`   | 1-15 number to represent the active kinds 0b0001 = static; 0b0010 = right; 0b0100 = left; 0b1000 = both. E.g. a pool with all 4 modes will have kinds = b1111 = 15 |
| `accessor`    | `address` | only address that can access the pool's public write functions.                                                                                                    |

#### updateProtocolFeeRatioForPool <a href="#updateprotocolfeeratioforpool" id="updateprotocolfeeratioforpool"></a>

Update the protocol fee ratio for a pool. Can be called permissionlessly allowing any user to sync the pool protocol fee value with the factory protocol fee value.

```solidity
function updateProtocolFeeRatioForPool(IMaverickV2Pool pool) external;
```

**Parameters**

| Name   | Type              | Description                   |
| ------ | ----------------- | ----------------------------- |
| `pool` | `IMaverickV2Pool` | The pool for which to update. |

#### updateProtocolLendingFeeRateForPool <a href="#updateprotocollendingfeerateforpool" id="updateprotocollendingfeerateforpool"></a>

Update the protocol lending fee rate for a pool. Can be called permissionlessly allowing any user to sync the pool protocol lending fee rate value with the factory value.

```solidity
function updateProtocolLendingFeeRateForPool(IMaverickV2Pool pool) external;
```

**Parameters**

| Name   | Type              | Description                   |
| ------ | ----------------- | ----------------------------- |
| `pool` | `IMaverickV2Pool` | The pool for which to update. |

#### claimProtocolFeeForPool <a href="#claimprotocolfeeforpool" id="claimprotocolfeeforpool"></a>

Claim protocol fee for a pool and transfer it to the protocolFeeReceiver.

```solidity
function claimProtocolFeeForPool(IMaverickV2Pool pool, bool isTokenA) external;
```

**Parameters**

| Name       | Type              | Description                                                                      |
| ---------- | ----------------- | -------------------------------------------------------------------------------- |
| `pool`     | `IMaverickV2Pool` | The pool from which to claim the protocol fee.                                   |
| `isTokenA` | `bool`            | A boolean indicating whether tokenA (true) or tokenB (false) is being collected. |

#### claimProtocolFeeForPool <a href="#claimprotocolfeeforpool-1" id="claimprotocolfeeforpool-1"></a>

Claim protocol fee for a pool and transfer it to the protocolFeeReceiver.

```solidity
function claimProtocolFeeForPool(IMaverickV2Pool pool) external;
```

**Parameters**

| Name   | Type              | Description                                    |
| ------ | ----------------- | ---------------------------------------------- |
| `pool` | `IMaverickV2Pool` | The pool from which to claim the protocol fee. |

#### isFactoryPool <a href="#isfactorypool" id="isfactorypool"></a>

Bool indicating whether the pool was deployed from this factory.

```solidity
function isFactoryPool(IMaverickV2Pool pool) external view returns (bool);
```

#### protocolFeeReceiver <a href="#protocolfeereceiver" id="protocolfeereceiver"></a>

Address that receives the protocol fee when users call `claimProtocolFeeForPool`.

```solidity
function protocolFeeReceiver() external view returns (address);
```

#### isFactoryPoolPermissioned <a href="#isfactorypoolpermissioned" id="isfactorypoolpermissioned"></a>

Bool indicating whether the pool was deployed from this factory.

```solidity
function isFactoryPoolPermissioned(IMaverickV2Pool pool) external view returns (bool);
```

#### lookupPermissioned <a href="#lookuppermissioned" id="lookuppermissioned"></a>

Lookup a pool for given parameters.

```solidity
function lookupPermissioned(
    uint256 feeAIn,
    uint256 feeBIn,
    uint256 tickSpacing,
    uint256 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    uint8 kinds,
    address accessor
) external view returns (IMaverickV2Pool);
```

#### lookupPermissioned <a href="#lookuppermissioned-1" id="lookuppermissioned-1"></a>

Lookup a pool for given parameters.

```solidity
function lookupPermissioned(IERC20 _tokenA, IERC20 _tokenB, address accessor, uint256 startIndex, uint256 endIndex)
    external
    view
    returns (IMaverickV2Pool[] memory pools);
```

#### lookupPermissioned <a href="#lookuppermissioned-2" id="lookuppermissioned-2"></a>

Lookup a pool for given parameters.

```solidity
function lookupPermissioned(uint256 startIndex, uint256 endIndex)
    external
    view
    returns (IMaverickV2Pool[] memory pools);
```

#### lookup <a href="#lookup" id="lookup"></a>

Lookup a pool for given parameters.

```solidity
function lookup(
    uint256 feeAIn,
    uint256 feeBIn,
    uint256 tickSpacing,
    uint256 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    uint8 kinds
) external view returns (IMaverickV2Pool);
```

#### lookup <a href="#lookup-1" id="lookup-1"></a>

Lookup a pool for given parameters.

```solidity
function lookup(IERC20 _tokenA, IERC20 _tokenB, uint256 startIndex, uint256 endIndex)
    external
    view
    returns (IMaverickV2Pool[] memory pools);
```

#### lookup <a href="#lookup-2" id="lookup-2"></a>

Lookup a pool for given parameters.

```solidity
function lookup(uint256 startIndex, uint256 endIndex) external view returns (IMaverickV2Pool[] memory pools);
```

#### owner <a href="#owner" id="owner"></a>

Get the current factory owner.

```solidity
function owner() external view returns (address);
```

#### protocolFeeRatioD3 <a href="#protocolfeeratiod3" id="protocolfeeratiod3"></a>

Proportion of protocol fee to collect on each swap. Value is in 3-decimal format with a maximum value of 0.25e3.

```solidity
function protocolFeeRatioD3() external view returns (uint8);
```

#### protocolLendingFeeRateD18 <a href="#protocollendingfeerated18" id="protocollendingfeerated18"></a>

Fee rate charged by the protocol for flashloans. Value is in 18-decimal format with a maximum value of 0.02e18.

```solidity
function protocolLendingFeeRateD18() external view returns (uint256);
```

#### poolAddress <a href="#pooladdress" id="pooladdress"></a>

Address of a permissionless pool.

```solidity
function poolAddress(
    uint256 feeAIn,
    uint256 feeBIn,
    uint256 tickSpacing,
    uint256 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    uint8 kinds
) external view returns (IMaverickV2Pool pool);
```

#### poolAddress <a href="#pooladdress-1" id="pooladdress-1"></a>

Address of a permissioned pool.

```solidity
function poolAddress(
    uint256 feeAIn,
    uint256 feeBIn,
    uint256 tickSpacing,
    uint256 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    uint8 kinds,
    address accessor
) external view returns (IMaverickV2Pool pool);
```

### Events <a href="#events" id="events"></a>

#### PoolCreated <a href="#poolcreated" id="poolcreated"></a>

```solidity
event PoolCreated(
    IMaverickV2Pool poolAddress,
    uint8 protocolFeeRatio,
    uint256 feeAIn,
    uint256 feeBIn,
    uint256 tickSpacing,
    uint256 lookback,
    int32 activeTick,
    IERC20 tokenA,
    IERC20 tokenB,
    uint8 kinds,
    address accessor
);
```

#### SetFactoryProtocolFeeRatio <a href="#setfactoryprotocolfeeratio" id="setfactoryprotocolfeeratio"></a>

```solidity
event SetFactoryProtocolFeeRatio(uint8 protocolFeeRatioD3);
```

#### SetFactoryProtocolLendingFeeRate <a href="#setfactoryprotocollendingfeerate" id="setfactoryprotocollendingfeerate"></a>

```solidity
event SetFactoryProtocolLendingFeeRate(uint256 lendingFeeRateD18);
```

#### SetFactoryProtocolFeeReceiver <a href="#setfactoryprotocolfeereceiver" id="setfactoryprotocolfeereceiver"></a>

```solidity
event SetFactoryProtocolFeeReceiver(address receiver);
```

### Errors <a href="#errors" id="errors"></a>

#### FactoryInvalidProtocolFeeRatio <a href="#factoryinvalidprotocolfeeratio" id="factoryinvalidprotocolfeeratio"></a>

```solidity
error FactoryInvalidProtocolFeeRatio(uint8 protocolFeeRatioD3);
```

#### FactoryInvalidLendingFeeRate <a href="#factoryinvalidlendingfeerate" id="factoryinvalidlendingfeerate"></a>

```solidity
error FactoryInvalidLendingFeeRate(uint256 protocolLendingFeeRateD18);
```

#### FactoryProtocolFeeOnRenounce <a href="#factoryprotocolfeeonrenounce" id="factoryprotocolfeeonrenounce"></a>

```solidity
error FactoryProtocolFeeOnRenounce(uint8 protocolFeeRatioD3);
```

#### FactorAlreadyInitialized <a href="#factoralreadyinitialized" id="factoralreadyinitialized"></a>

```solidity
error FactorAlreadyInitialized();
```

#### FactorNotInitialized <a href="#factornotinitialized" id="factornotinitialized"></a>

```solidity
error FactorNotInitialized();
```

#### FactoryInvalidTokenOrder <a href="#factoryinvalidtokenorder" id="factoryinvalidtokenorder"></a>

```solidity
error FactoryInvalidTokenOrder(IERC20 _tokenA, IERC20 _tokenB);
```

#### FactoryInvalidFee <a href="#factoryinvalidfee" id="factoryinvalidfee"></a>

```solidity
error FactoryInvalidFee();
```

#### FactoryInvalidKinds <a href="#factoryinvalidkinds" id="factoryinvalidkinds"></a>

```solidity
error FactoryInvalidKinds(uint8 kinds);
```

#### FactoryInvalidTickSpacing <a href="#factoryinvalidtickspacing" id="factoryinvalidtickspacing"></a>

```solidity
error FactoryInvalidTickSpacing(uint256 tickSpacing);
```

#### FactoryInvalidLookback <a href="#factoryinvalidlookback" id="factoryinvalidlookback"></a>

```solidity
error FactoryInvalidLookback(uint256 lookback);
```

#### FactoryInvalidTokenDecimals <a href="#factoryinvalidtokendecimals" id="factoryinvalidtokendecimals"></a>

```solidity
error FactoryInvalidTokenDecimals(uint8 decimalsA, uint8 decimalsB);
```

#### FactoryPoolAlreadyExists <a href="#factorypoolalreadyexists" id="factorypoolalreadyexists"></a>

```solidity
error FactoryPoolAlreadyExists(
    uint256 feeAIn,
    uint256 feeBIn,
    uint256 tickSpacing,
    uint256 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    uint8 kinds,
    address accessor
);
```

#### FactoryAccessorMustBeNonZero <a href="#factoryaccessormustbenonzero" id="factoryaccessormustbenonzero"></a>

```solidity
error FactoryAccessorMustBeNonZero();
```

### Structs <a href="#structs" id="structs"></a>

#### DeployParameters <a href="#deployparameters-1" id="deployparameters-1"></a>

```solidity
struct DeployParameters {
    uint64 feeAIn;
    uint64 feeBIn;
    uint32 lookback;
    int32 activeTick;
    uint64 tokenAScale;
    uint64 tokenBScale;
    IERC20 tokenA;
    IERC20 tokenB;
    uint16 tickSpacing;
    uint8 kinds;
    address accessor;
}
```

<br>
