# Pool

## Function Interface introduction

### 1. Create Pool

* Contract Interface

```solidity
function createPool(
    address tokenA,
    address tokenB,
    uint24 fee
) external override returns (address pool) {
    require(tokenA != tokenB);
    (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
    require(token0 != address(0));
    int24 tickSpacing = feeAmountTickSpacing[fee];
    TickSpacingExtraInfo memory info = feeAmountTickSpacingExtraInfo[fee];
    require(tickSpacing != 0 && info.enabled, 'fee is not available yet');
    if (info.whitelistRequested) {
        require(_whiteListAddresses[msg.sender], 'user should be in the white list for this fee tier');
    }
    require(getPool[token0][token1][fee] == address(0));
    pool = IKuramaV3PoolDeployer(poolDeployer).deploy(address(this), token0, token1, fee, tickSpacing);
    getPool[token0][token1][fee] = pool;
    // populate mapping in the reverse direction, deliberate choice to avoid the cost of comparing addresses
    getPool[token1][token0][fee] = pool;
    emit PoolCreated(token0, token1, fee, tickSpacing, pool);
}
```

* Param Explanation
  * **tokenA** (`address`): The contract address of the first token in the token pair for which liquidity is being provided.
  * **tokenB**(`address`): The contract address of the second token in the pair.
  * **fee** (`uint24`): The fee tier of the pool to which liquidity is being added. Fees are typically specified in basis points (e.g., 500 for a 0.05% fee).

## Example code

Note: This is just a simplified code example, offering an approach for integration. It demonstrates how to combine the swap method with multicall, where specific executable code requires additional information to be supplemented.Before do swap, you can do quote simulate to calculate `amountInputMaximum` or `amountOutputMimimum`

```solidity
const publicClient = createPublicClient({chain: testnet, transport: http()})

const multicallContract = getContract({
    address: multicallAddress,
    abi: multicallABI,
    publicClient,
})


const encodePathBytes = "example bytes"
const amountOut = 1000000

const quoteCallData = {
    abi: quoteABI,
    functionName: 'quoteExactInputSingle',
    args: [
        target: swapRouterAddress,
        gasLimit: 1000000000,
        callData： paramBytes,
    ]
}

const multicallData0 = {
    abi: multicallABI,
    functionName: 'multicall',
    args: [
        target: swapRouterAddress,
        gasLimit: 1000000000,
        callData： encode(quoteCallData),
    ]
}
const result = this.multicallContract.simulate.multicall(multicallData0)

const recipient = "example recipient"
const deadline = example_deadline
const amountInputMaximum = result.data * (1 + slippage) // preswap result + slippage

const args = [{
    abi: swapRouterABI,
    functionName: 'exactInputSingle',
    args: [
        {
            path: encodePathBytes,
            recipient,
            deadline,
            amountOut,
            amountInputMaximum,
        }
    ]
}]

const paramBytes = encodeParams(args)

const callData = {
    abi: multicallABI,
    functionName: 'multicall',
    args: [
        target: swapRouterAddress,
        gasLimit: 1000000000,
        callData： paramBytes,
    ]
}
const sendParam = {
    account,
    to: multicallAddress,
    data: callData,
    value: x // depend on is need warp,
    gas: gasLimit,
}

publicClient.sendTransaction(sendParam)
```


---

# 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://glowswap.gitbook.io/glowswap-docs/developer/pool.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.
