The ShibaSwap V2 SDK is a TypeScript/JavaScript library that provides everything needed to build on ShibaSwap’s V2 AMM—a fork of SushiSwap’s V3 built on top of Uniswap V3’s concentrated liquidity model.
The SDK offers a lightweight bundle with first-class support for viem, full TypeScript typings, ESM/CJS compatibility, and support for quoting, trading, and managing NFT-based liquidity positions.

Quick Start & Installation

Install the SDK along with the viem Ethereum client for RPC interactions:
# Recommended
pnpm add @shibaswap/v2-sdk viem

# Or with npm
npm install @shibaswap/v2-sdk viem

Imports & Initialization

Core Imports

import { getSwap, computePoolAddress, ChainId } from "@shibaswap/v2-sdk";
import { createPublicClient, http } from "viem";

Client Setup

const client = createPublicClient({
  chain: {
    id: ChainId.ETHEREUM,
    rpcUrls: { default: { http: ["https://mainnet.infura.io/v3/YOUR_KEY"] } }
  },
  transport: http(),
});

Quoting a Swap

Get swap quotes and calldata for token exchanges:
const { calldata, value, estimatedAmountOut } = await getSwap({
  client,
  chainId: ChainId.ETHEREUM,
  tokenIn: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // ETH
  tokenOut: "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE", // SHIB
  amount: 1n * 10n**18n,   // 1 ETH
  maxSlippage: 0.005       // 0.5%
});

console.log("Call Data:", calldata);
console.log("Value (wei):", value);
console.log("Estimated SHIB out:", estimatedAmountOut.toString());

Response Parameters

Compute & Inspect Pools

Compute Pool Address

Calculate the deterministic address for a specific token pair and fee tier:
import { computePoolAddress, FeeAmount } from "@shibaswap/v2-sdk";

const poolAddress = computePoolAddress({
  factoryAddress: "0xYourShibaSwapV2Factory",
  tokenA: USDC_TOKEN,
  tokenB: WETH_TOKEN,
  fee: FeeAmount.MEDIUM
});

Fetch Pool State

Retrieve current pool information:
const poolContract = new ethers.Contract(poolAddress, abi, client);
const [fee, liquidity, slot0] = await Promise.all([
  poolContract.fee(),
  poolContract.liquidity(),
  poolContract.slot0()
]);

console.log({
  fee,
  liquidity,
  sqrtPriceX96: slot0[0].toString(),
  tick: slot0[1]
});

Pool State Response

Executing a Trade

Execute swaps using the router contract:
import { ethers } from "ethers";
const signer = new ethers.Wallet(privateKey, client);
const router = new ethers.Contract("0xYourSwapRouterV2", RouterABI.abi, signer);

const tx = await router.exactInputSingle({
  tokenIn:  "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
  tokenOut: "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE",
  fee:      FeeAmount.MEDIUM,
  recipient,
  deadline: Math.floor(Date.now() / 1000) + 60 * 20,
  amountIn: 1n * 10n**18n,
  amountOutMinimum: estimatedAmountOut * (1 - 0.005),
  sqrtPriceLimitX96: 0
}, { value: 1n * 10n**18n });

console.log("Transaction Hash:", tx.hash);

Managing Liquidity Positions (NFT)

Minting a Position

Create new concentrated liquidity positions:
import {
  Pool,
  Position,
  NonfungiblePositionManager,
  MintOptions
} from "@shibaswap/v2-sdk";
import { Percent } from "@shibaswap/sdk-core";

// 1. Create pool
const pool = new Pool(token0, token1, poolFee, sqrtPriceX96, liquidity, tick);

// 2. Define position
const position = Position.fromAmounts({
  pool,
  tickLower,
  tickUpper,
  amount0,
  amount1,
  useFullPrecision: true
});

// 3. Mint
const mintOptions: MintOptions = {
  recipient,
  deadline: Math.floor(Date.now() / 1000) + 60 * 20,
  slippageTolerance: new Percent(50, 10_000)
};
const { calldata, value } = NonfungiblePositionManager.addCallParameters(position, mintOptions);

Increase / Decrease Liquidity

Modify existing positions:
// Increase liquidity: reuse addCallParameters() with same tokenId
const { calldata: increaseCalldata, value: increaseValue } = 
  NonfungiblePositionManager.addCallParameters(position, mintOptions);

// Decrease liquidity: use removeCallParameters()
const { calldata: decreaseCalldata, value: decreaseValue } = 
  NonfungiblePositionManager.removeCallParameters(position, options);

Collecting Fees

Collect accumulated fees from your positions:
import { CollectOptions } from "@shibaswap/v2-sdk";

const collectOptions: CollectOptions = {
  tokenId,
  recipient,
  expectedCurrencyOwed0: CurrencyAmount.fromRawAmount(token0, owed0),
  expectedCurrencyOwed1: CurrencyAmount.fromRawAmount(token1, owed1)
};
const { calldata, value } = NonfungiblePositionManager.collectCallParameters(collectOptions);

Technical Reference

Exports from @shibaswap/v2-sdk

Core Functions

  • getSwap(params) – fetch quote + calldata
  • computePoolAddress({ factoryAddress, tokenA, tokenB, fee })

Constants

  • ChainId – enum of supported networks
  • FeeAmount – fee presets: LOW = 500, MEDIUM = 3000, HIGH = 10000

Liquidity Classes

  • NonfungiblePositionManager – NFT position management
  • Position – concentrated liquidity position abstraction
  • Pool – pool state and calculations

Utilities

  • Percent – percentage calculations
  • CurrencyAmount – token amount handling

Fee Amount Constants

enum FeeAmount {
  LOW = 500,      // 0.05%
  MEDIUM = 3000,  // 0.3%
  HIGH = 10000    // 1%
}

Supported Networks

enum ChainId {
  ETHEREUM = 1,
  POLYGON = 137,
  BSC = 56,
  // Add more networks as supported
}

Best Practices

1

Use proper error handling

Always wrap SDK calls in try-catch blocks and handle potential failures gracefully.
Check for insufficient liquidity, slippage exceeded, and deadline passed errors.
2

Implement slippage protection

Set appropriate slippage tolerance based on market conditions and token volatility.
Too low slippage may cause failed transactions, too high may result in poor execution.
3

Optimize gas usage

Batch operations when possible and use appropriate gas limits for complex transactions.
Position management operations typically require higher gas limits than simple swaps.
4

Monitor position health

Regularly check if your concentrated liquidity positions are still in range.
Out-of-range positions don’t earn fees and may suffer impermanent loss.

Integration Examples

React Hook Example

import { useState, useEffect } from 'react';
import { getSwap, ChainId } from '@shibaswap/v2-sdk';

function useSwapQuote(tokenIn: string, tokenOut: string, amount: bigint) {
  const [quote, setQuote] = useState(null);
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState(null);

  useEffect(() => {
    async function fetchQuote() {
      setLoading(true);
      try {
        const result = await getSwap({
          client,
          chainId: ChainId.ETHEREUM,
          tokenIn,
          tokenOut,
          amount,
          maxSlippage: 0.005
        });
        setQuote(result);
      } catch (err) {
        setError(err.message);
      } finally {
        setLoading(false);
      }
    }

    if (amount > 0n) {
      fetchQuote();
    }
  }, [tokenIn, tokenOut, amount]);

  return { quote, loading, error };
}

Position Management Hook

import { useContractWrite, usePrepareContractWrite } from 'wagmi';
import { NonfungiblePositionManager } from '@shibaswap/v2-sdk';

function useMintPosition(position: Position, options: MintOptions) {
  const { calldata, value } = NonfungiblePositionManager.addCallParameters(position, options);
  
  const { config } = usePrepareContractWrite({
    address: POSITION_MANAGER_ADDRESS,
    abi: POSITION_MANAGER_ABI,
    functionName: 'mint',
    args: [calldata],
    value
  });

  return useContractWrite(config);
}
Build powerful DEX integrations with full control over trading and liquidity using ShibaSwap V2 SDK. The SDK provides all the tools needed to create sophisticated DeFi applications with concentrated liquidity support.