UniDevKit - v2.1.1
    Preparing search index...

    Class UniDevKitV4

    Main class for interacting with Uniswap V4 contracts. Provides a flexible and scalable way to interact with different chains and contracts without requiring multiple instances.

    Index

    Constructors

    Methods

    • Creates Position instances and generates V4PositionManager calldata for adding liquidity.

      This method uses Uniswap V3 SDK's Position.fromAmounts/fromAmount0/fromAmount1 to create positions, and V4PositionManager.addCallParameters to generate the mint calldata. It handles both existing pools and new pool creation, with support for Permit2 batch approvals and native currency handling. No blockchain calls are made - this is purely a calldata generation method.

      Parameters

      • args: BaseAddLiquidityArgs

      Returns Promise<BuildAddLiquidityCallDataResult>

      Promise - Calldata and value for the mint transaction

      Error if position creation fails or invalid parameters are provided

    • Generates V4PositionManager calldata for collecting accumulated fees from positions.

      This method uses V4PositionManager.collectCallParameters to create calldata for collecting fees earned by a liquidity position. It handles both currency0 and currency1 fee collection with proper recipient addressing. No blockchain calls are made - this is purely a calldata generation method.

      Parameters

      • args: BuildCollectFeesCallDataArgs

      Returns Promise<{ calldata: string; value: string }>

      Promise - Calldata and value for the collect transaction

      Error if position data is invalid or collection parameters are incorrect

    • Generates V4PositionManager calldata for removing liquidity from existing positions.

      This method uses V4PositionManager.removeCallParameters to create burn calldata for reducing or completely removing liquidity from a position. It calculates the appropriate amounts based on the liquidity percentage to remove. No blockchain calls are made - this is purely a calldata generation method.

      Parameters

      • args: BuildRemoveLiquidityCallDataArgs

      Returns Promise<{ calldata: string; value: string }>

      Promise - Calldata and value for the burn transaction

      Error if position data is invalid or removal parameters are incorrect

    • Generates Universal Router calldata for executing token swaps using Uniswap V4.

      This method uses the V4Planner from the Uniswap V4 SDK to build swap actions and parameters. It creates SWAP_EXACT_IN_SINGLE actions with settle and take operations, and optionally includes Permit2 signatures for token approvals. No blockchain calls are made - this is purely a calldata generation method that returns Universal Router calldata.

      Parameters

      Returns `0x${string}`

      Hex - Encoded Universal Router calldata ready for transaction execution

      Error if swap parameters are invalid or calldata generation fails

    • Returns the address of a specific contract.

      Parameters

      Returns `0x${string}`

      The address of the specified contract.

      Will throw an error if the contract address is not found.

    • Returns the FeeTier enum for accessing standard fee tiers.

      Returns typeof FeeTier

      The FeeTier enum containing LOWEST, LOW, MEDIUM, and HIGH fee tiers

    • Creates a Uniswap V4 Pool instance by fetching real-time pool state from the blockchain.

      This method uses multicall to efficiently fetch pool data from the V4StateView contract, calling getSlot0() and getLiquidity() in a single transaction. It then uses the Uniswap V4 SDK's Pool constructor with the live data to create a fully initialized pool instance.

      Parameters

      Returns Promise<Pool>

      Promise - A fully initialized Pool instance with current market state

      Error if pool data cannot be fetched or pool doesn't exist

    • Retrieves a complete Uniswap V4 position instance with pool and token information.

      This method fetches position details and builds a fully initialized Position instance using the Uniswap V4 SDK. It includes the pool state, token metadata, position liquidity data, and current pool tick, providing a comprehensive view of the position.

      Parameters

      • tokenId: string

        The NFT token ID of the position

      Returns Promise<GetPositionResponse>

      Promise - Complete position data including position instance, pool, tokens, pool ID, and current tick

      Error if position data cannot be fetched, position doesn't exist, or liquidity is 0

    • Retrieves basic position information without SDK instances.

      This method fetches raw position data from the blockchain and returns it without creating SDK instances. It's more efficient when you only need position metadata (tick range, liquidity, pool key) without requiring Position or Pool objects. Also fetches pool state (slot0 and liquidity) to avoid redundant calls when building full position instances.

      Use this method when:

      • Displaying position information in a UI
      • Checking if a position exists
      • Getting position metadata without SDK operations

      Use getPosition() instead when you need SDK instances for swaps, calculations, or other operations.

      Parameters

      • tokenId: string

        The NFT token ID of the position

      Returns Promise<GetPositionInfoResponse>

      Promise - Basic position information with pool state

      Error if position data cannot be fetched or position doesn't exist

    • Simulates a token swap using the V4 Quoter contract to get exact output amounts and gas estimates.

      This method uses client.simulateContract() to call V4Quoter.quoteExactInputSingle() and simulate the swap without executing it. It provides accurate pricing information and gas estimates for the transaction without requiring multicall since it's a single contract simulation.

      Parameters

      Returns Promise<QuoteResponse>

      Promise - Quote data with amount out, gas estimate, and timestamp

      Error if simulation fails or contract call reverts

    • Fetches tick information for a given pool key and tick from V4 StateView.

      This method uses client.readContract() to call V4StateView.getTickInfo() and retrieve tick data including liquidity and fee growth information. It first creates Token instances from the pool key currencies, computes the PoolId, and then reads the tick info from the blockchain.

      Parameters

      • args: GetTickInfoArgs

        Tick query parameters including pool key and tick index

      Returns Promise<TickInfoResponse>

      Promise - Tick information including liquidity and fee growth data

      Error if tick data cannot be fetched or contract call reverts

    • Fetches ERC20 token metadata and creates Currency instances using Uniswap SDK-Core.

      This method uses multicall to efficiently fetch symbol(), name(), and decimals() from multiple ERC20 tokens in a single transaction. For native currency (ETH), it creates an Ether instance using the chain ID. For ERC20 tokens, it creates Token instances with the fetched metadata.

      Parameters

      • args: GetTokensArgs

      Returns Promise<Currency[]>

      Promise<Currency[]> - Array of Currency instances (Token or Ether)

      Error if token data cannot be fetched from the blockchain

    • Prepares Permit2 batch approval data for multiple tokens using the Permit2 SDK.

      This method uses multicall to efficiently fetch allowance() data from the Permit2 contract for multiple tokens in a single transaction. It creates batch permit structures that allow the Universal Router to spend multiple tokens. Typically used for adding liquidity where multiple token approvals are needed. Use the returned toSign.values for signing.

      Parameters

      • args: PreparePermit2BatchDataArgs

      Returns Promise<PreparePermit2BatchDataResult>

      Promise - Structured permit data ready for signing

      Error if permit data generation fails or parameters are invalid

    • Prepares Permit2 single token approval data using the Permit2 SDK.

      This method creates a single permit structure that allows the Universal Router to spend one token. It's typically used for swaps where only one token approval is needed. No blockchain calls are made - this is purely a permit data generation method. Use the returned toSign.values for signing the permit data.

      Parameters

      • args: PreparePermit2DataArgs

      Returns Promise<PreparePermit2DataResult>

      Promise - Structured permit data ready for signing

      Error if permit data generation fails or parameters are invalid