# Kodiak Island Factory

## Deploying New Islands

```solidity
function deployVault(
    address tokenA,
    address tokenB,
    uint24 uniFee,
    address manager,
    address managerTreasury,
    uint16 managerFee,
    int24 lowerTick,
    int24 upperTick
) external returns (address island)
```

Creates a new Kodiak Island using these parameters. Get the tokens and fee tier for the pool you want to deploy the island for.

Deployment process - The tokens are sorted and the kodiak pool is fetched, if the kodiak pool does not exist it throws an error.

**Parameters:**

* `tokenA`: First token in the pool pair
* `tokenB`: Second token in the pool pair
* `uniFee`: Underlying pool fee tier (eg: 100, 500, 3000, 10000)
* `manager`: Manager address (0x0 for unmanaged/permisionless islands)
* `managerTreasury`: The address that will receive the manager's fee share
* `managerFee`: Manager fee in basis points (0 - 10000)
* `lowerTick`: lower tick of the island's position
* `upperTick`: upper tick of the islnad's position

**Returns**:

* island (address): The address of the newly deployed KodiakIsland vault.

**Deployment** **Process**:

* The function sorts the tokens (tokenA, tokenB) to ensure consistent ordering.
* It fetches the corresponding Kodiak V3 pool address using the provided tokens and fee tier.
* It validates that the Kodiak V3 pool exists and that the provided ticks align with the pool's tick spacing.
* It clones the islandImplementation contract to create a new KodiakIsland vault.
* It initializes the new vault with the provided parameters.
* It adds the deployer to the list of deployers and the island to the list of islands deployed by the manager.

**Emits**: `IslandCreated` on successful deployment

```solidity
event IslandCreated(address indexed uniPool, address indexed manager, address indexed island, address implementation);
```

### Requirements for deploying a permissionless Island

1. The `manager` address must be set to zero address.
2. The `managerTreasury` must be set to zero address.
3. The `managerFee` must be set to 0.
4. The deployed island refers the `managerFee` and `managerTreasury` from the factory for permissionless islands

## Querying Deployed Islands and related data

**Get All Deployers**

```solidity
function getDeployers() public view returns (address[] memory)
```

Returns array of all addresses that have deployed at least one island.

Returns:

* `address[]`: Array of deployer addresses

**Get Islands by Deployer**

```solidity
function getIslands(address deployer) public view returns (address[] memory islands)
```

Returns array of all islands deployed by a specific address.

Parameters:

* `deployer`: Address to query islands for

Returns:

* `islands`: Array of island addresses deployed by specified deployer
* Returns empty array if no islands deployed

**Count Functions**

```solidity
function numIslands() public view returns (uint256)
```

Returns total number of islands deployed through factory.

```solidity
function numDeployers() public view returns (uint256)
```

Returns total number of unique deployer addresses.

```solidity
function numIslands(address deployer) public view returns (uint256)
```

Returns number of islands deployed by specific address.

Parameters:

* `deployer`: Address to query island count for

## Factory Management

Only the factory owner can call these functions.

**Set Island Implementation**

```solidity
function setIslandImplementation(address _implementation) external
```

Updates the implementation contract used for new island deployments.

Parameters:

* `_implementation`: Address of new implementation contract
  * Must be non-zero address
  * Must be a valid KodiakIsland contract

Requirements:

* Caller must be factory owner
* Implementation address cannot be zero

Emits: `UpdateIslandImplementation(address implementation)`

**Set Treasury**

```solidity
function setTreasury(address _treasury) external
```

Updates the treasury address that receives protocol fees.

Parameters:

* `_treasury`: New treasury address
  * Must be non-zero address
  * Will receive protocol fees from permissionless islands

Requirements:

* Caller must be factory owner
* Treasury address cannot be zero

Emits: `TreasurySet(address treasury)`

**Set Island Fee**

```solidity
function setIslandFee(uint16 _islandFee) external
```

Updates the protocol fee for permissionless islands.

Parameters:

* `_islandFee`: New protocol fee in basis points
  * Must be between 0-2000 (0-20%)
  * Applied to all permissionless islands

Requirements:

* Caller must be factory owner
* Fee cannot exceed 2000 (20%)

Emits: `IslandFeeSet(uint16 islandFee)`

## ABI

```json
[
        {
            "type": "function",
            "name": "deployVault",
            "inputs": [
                {
                    "name": "tokenA",
                    "type": "address",
                    "internalType": "address"
                },
                {
                    "name": "tokenB",
                    "type": "address",
                    "internalType": "address"
                },
                {
                    "name": "uniFee",
                    "type": "uint24",
                    "internalType": "uint24"
                },
                {
                    "name": "manager",
                    "type": "address",
                    "internalType": "address"
                },
                {
                    "name": "managerTreasury",
                    "type": "address",
                    "internalType": "address"
                },
                {
                    "name": "managerFee",
                    "type": "uint16",
                    "internalType": "uint16"
                },
                {
                    "name": "lowerTick",
                    "type": "int24",
                    "internalType": "int24"
                },
                {
                    "name": "upperTick",
                    "type": "int24",
                    "internalType": "int24"
                }
            ],
            "outputs": [
                {
                    "name": "island",
                    "type": "address",
                    "internalType": "address"
                }
            ],
            "stateMutability": "nonpayable"
        },
        {
            "type": "function",
            "name": "islandFee",
            "inputs": [],
            "outputs": [
                {
                    "name": "",
                    "type": "uint16",
                    "internalType": "uint16"
                }
            ],
            "stateMutability": "view"
        },
        {
            "type": "function",
            "name": "islandImplementation",
            "inputs": [],
            "outputs": [
                {
                    "name": "",
                    "type": "address",
                    "internalType": "address"
                }
            ],
            "stateMutability": "view"
        },
        {
            "type": "function",
            "name": "setIslandImplementation",
            "inputs": [
                {
                    "name": "newImplementation",
                    "type": "address",
                    "internalType": "address"
                }
            ],
            "outputs": [],
            "stateMutability": "nonpayable"
        },
        {
            "type": "function",
            "name": "treasury",
            "inputs": [],
            "outputs": [
                {
                    "name": "",
                    "type": "address",
                    "internalType": "address"
                }
            ],
            "stateMutability": "view"
        },
        {
            "type": "event",
            "name": "IslandCreated",
            "inputs": [
                {
                    "name": "uniPool",
                    "type": "address",
                    "indexed": true,
                    "internalType": "address"
                },
                {
                    "name": "manager",
                    "type": "address",
                    "indexed": true,
                    "internalType": "address"
                },
                {
                    "name": "island",
                    "type": "address",
                    "indexed": true,
                    "internalType": "address"
                },
                {
                    "name": "implementation",
                    "type": "address",
                    "indexed": false,
                    "internalType": "address"
                }
            ],
            "anonymous": false
        },
        {
            "type": "event",
            "name": "IslandFeeSet",
            "inputs": [
                {
                    "name": "fee",
                    "type": "uint16",
                    "indexed": false,
                    "internalType": "uint16"
                }
            ],
            "anonymous": false
        },
        {
            "type": "event",
            "name": "TreasurySet",
            "inputs": [
                {
                    "name": "treasury",
                    "type": "address",
                    "indexed": true,
                    "internalType": "address"
                }
            ],
            "anonymous": false
        },
        {
            "type": "event",
            "name": "UpdateIslandImplementation",
            "inputs": [
                {
                    "name": "newImplementation",
                    "type": "address",
                    "indexed": false,
                    "internalType": "address"
                }
            ],
            "anonymous": false
        }
    ]
```
