ShibaSwap V2 SDK
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.
It offers:
- A lightweight bundle
- First-class support for
viem
- Full TypeScript typings
- ESM/CJS compatibility
- Support for quoting, trading, and managing NFT-based liquidity positions
Quick Start & Installation
# Recommended
pnpm add @shibaswap/v2-sdk viem
# Or with npm
npm install @shibaswap/v2-sdk viem
This installs the SDK along with the viem
Ethereum client for RPC interactions.
Imports & Initialization
Core Imports
import { getSwap, computePoolAddress, ChainId } from "@shibaswap/v2-sdk";
import { createPublicClient, http } from "viem";
getSwap
: fetches swap quotes and calldatacomputePoolAddress
: computes pool address using CREATE2ChainId
: enum of supported networksviem
: fast on-chain data querying
Client Setup
const client = createPublicClient({
chain: {
id: ChainId.ETHEREUM,
rpcUrls: { default: { http: ["https://mainnet.infura.io/v3/YOUR_KEY"] } }
},
transport: http(),
});
Quoting a Swap
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());
Compute & Inspect Pools
Compute Pool Address
import { computePoolAddress, FeeAmount } from "@shibaswap/v2-sdk";
const poolAddress = computePoolAddress({
factoryAddress: "0xYourShibaSwapV2Factory",
tokenA: USDC_TOKEN,
tokenB: WETH_TOKEN,
fee: FeeAmount.MEDIUM
});
Fetch Pool State
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]
});
Executing a Trade
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
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
- Increase: reuse
addCallParameters()
with sametokenId
- Decrease: use
removeCallParameters(position, options)
Collecting Fees
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
getSwap(params)
– fetch quote + calldatacomputePoolAddress({ factoryAddress, tokenA, tokenB, fee })
ChainId
– enum of supported networksNonfungiblePositionManager
,Position
,Pool
– liquidity abstractionsFeeAmount
– fee presets:LOW = 500
,MEDIUM = 3000
,HIGH = 10000
Build powerful DEX integrations with full control over trading and liquidity using ShibaSwap V2.