Pool

Function Interface introduction

1. Create Pool

  • Contract Interface

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

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)

Last updated