Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
264 changes: 135 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,205 +1,211 @@
# uniswap-dev-kit

[![CI](https://github.com/BootNodeDev/uni-dev-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/BootNodeDev/uni-dev-kit/actions/workflows/ci.yml)
[![Release](https://github.com/BootNodeDev/uni-dev-kit/actions/workflows/release.yml/badge.svg)](https://github.com/BootNodeDev/uni-dev-kit/actions/workflows/release.yml)
[![Docs](https://img.shields.io/badge/docs-typedoc-blue)](https://bootnodedev.github.io/uni-dev-kit)

> Modern TypeScript SDK for integrating Uniswap V4 into your dapp.
> **Early version:** API may change rapidly.

A developer-friendly library for interacting with Uniswap V4 contracts. This library provides a simple and flexible interface for common operations like adding liquidity, swapping tokens, and managing positions.

## Features

- 🚀 Full TypeScript support
- 🔄 Multi-chain support out of the box
- 📦 Zero dependencies (except peer deps)
- 🔍 Comprehensive error handling
- 🧪 Fully tested
- 📚 Well documented
- 🚀 Simple and intuitive API
- 🔄 Support for all major Uniswap V4 operations
- 💰 Native token support
- 🔒 Permit2 integration for gasless approvals
- 📊 Flexible liquidity management
- 🔍 Built-in quote simulation
- 🛠 TypeScript support

## Install
## Installation

```bash
pnpm install uniswap-dev-kit
# or
npm install uniswap-dev-kit
# or
yarn add uniswap-dev-kit
```

## Quick Start

### 1. Configure and create SDK instances

```ts
import { UniDevKitV4 } from "uniswap-dev-kit";
import { UniDevKitV4 } from 'uniswap-dev-kit';

// Create instance for Ethereum mainnet
const ethInstance = new UniDevKitV4({
const uniDevKit = new UniDevKitV4({
chainId: 1,
rpcUrl: "https://eth.llamarpc.com",
contracts: {
poolManager: "0x...",
positionDescriptor: "0x...",
positionManager: "0x...",
positionDescriptor: "0x...",
quoter: "0x...",
stateView: "0x...",
universalRouter: "0x...",
permit2: "0x..."
universalRouter: "0x..."
}
});

// Create instance for another chain (e.g., Base)
const baseInstance = new UniDevKitV4({
chainId: 8453,
rpcUrl: "https://mainnet.base.org",
contracts: {
// Base Uniswap V4 contract addresses...
}
const pool = await uniDevKit.getPool({
tokens: ["0xTokenA", "0xTokenB"],
fee: 3000
});

const quote = await uniDevKit.getQuote({
pool,
amountIn: "1000000000000000000"
});
```

### 2. Get a quote
## Documentation
Full API documentation with TypeDoc: [https://bootnodedev.github.io/uni-dev-kit](https://bootnodedev.github.io/uni-dev-kit)

## API Reference

### Index
- [uniswap-dev-kit](#uniswap-dev-kit)
- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Documentation](#documentation)
- [API Reference](#api-reference)
- [Index](#index)
- [`getPool`](#getpool)
- [`getQuote`](#getquote)
- [`getTokens`](#gettokens)
- [`getPosition`](#getposition)
- [`getPoolKeyFromPoolId`](#getpoolkeyfrompoolid)
- [`buildSwapCallData`](#buildswapcalldata)
- [`buildAddLiquidityCallData`](#buildaddliquiditycalldata)
- [`preparePermit2BatchCallData`](#preparepermit2batchcalldata)
- [Useful Links](#useful-links)
- [Development](#development)
- [Scripts](#scripts)
- [Contributing](#contributing)
- [Release](#release)
- [License](#license)

### `getPool`
Retrieve a pool object from two tokens and a fee tier.
```ts
import { parseEther } from "viem";

const quote = await ethInstance.getQuote({
tokens: [
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
],
feeTier: 3000,
amountIn: parseEther("1"),
zeroForOne: true
const pool = await uniDevKit.getPool({
tokens: [tokenA, tokenB],
fee: 3000
});
console.log(quote.amountOut);
```

### 3. Get a pool

### `getQuote`
Simulate a swap to get `amountOut` and `sqrtPriceLimitX96`.
```ts
const pool = await ethInstance.getPool({
tokens: [
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
],
feeTier: 3000
const quote = await uniDevKit.getQuote({
pool,
amountIn: "1000000000000000000"
});
console.log(pool.liquidity.toString());
```

### 4. Get a position

### `getTokens`
Retrieve token metadata.
```ts
const position = await ethInstance.getPosition({
tokenId: "123"
});
console.log({
token0: position.token0.symbol,
token1: position.token1.symbol,
liquidity: position.position.liquidity.toString()
const tokens = await uniDevKit.getTokens({
addresses: ["0x...", "0x..."]
});
```

## Advanced Usage

### Error Handling
### `getPosition`
Get details about a Uniswap V4 LP position.
```ts
const position = await uniDevKit.getPosition({
tokenId: 123
});
```

All SDK functions include comprehensive error handling:
### `getPoolKeyFromPoolId`
Retrieve the `PoolKey` object for a given pool ID.
```ts
const poolKey = await uniDevKit.getPoolKeyFromPoolId({
poolId: "0x..."
});
```

### `buildSwapCallData`
Construct calldata and value for a Universal Router swap.
```ts
try {
const quote = await ethInstance.getQuote({
tokens: [token0, token1],
feeTier: 3000,
amountIn: parseEther("1"),
zeroForOne: true
});
} catch (error) {
// Handle specific error types
if (error.message.includes("insufficient liquidity")) {
// Handle liquidity error
} else if (error.message.includes("invalid pool")) {
// Handle pool error
}
}
const { calldata, value } = await uniDevKit.buildSwapCallData({
tokenIn,
tokenOut,
amountIn: "1000000000000000000",
recipient,
slippageBips: 50
});
```

### Using with React
### `buildAddLiquidityCallData`
Build calldata to add liquidity to a pool.
```ts
// Without permit
const { calldata, value } = await uniDevKit.buildAddLiquidityCallData({
pool,
amount0: "100000000",
amount1: "50000000000000000",
recipient: "0x...",
slippageTolerance: 50
});

You can use the SDK with React Query for data fetching:
// With Permit2 batch approval
const permitData = await uniDevKit.preparePermit2BatchData({
tokens: [pool.token0.address, pool.token1.address],
spender: uniDevKit.getContractAddress('positionManager'),
owner: userAddress
});

```tsx
import { useQuery } from '@tanstack/react-query';
import { UniDevKitV4 } from 'uniswap-dev-kit';
const signature = await signer.signTypedData(
permitData.toSign.domain,
permitData.toSign.types,
permitData.toSign.values
);

// Create instance once
const sdk = new UniDevKitV4({
chainId: 1,
rpcUrl: "https://eth.llamarpc.com",
contracts: {
// ... contract addresses
}
const permitWithSignature = permitData.buildPermit2BatchDataWithSignature(signature);

const { calldata, value } = await uniDevKit.buildAddLiquidityCallData({
pool,
amount0: parseUnits("100", 6),
recipient: "0x...",
permit2BatchSignature: permitWithSignature
});

// Simple hook for quotes
function useQuote() {
return useQuery({
queryKey: ['quote'],
queryFn: () => sdk.getQuote({
tokens: [
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
],
feeTier: 3000,
amountIn: parseEther("1"),
zeroForOne: true
})
});
}
const tx = await sendTransaction({
to: uniDevKit.getContractAddress('positionManager'),
data: calldata,
value
});
```

---

## API Reference

See [full TypeDoc documentation](https://bootnodedev.github.io/uni-dev-kit) for all methods, types, and advanced usage.
### `preparePermit2BatchCallData`
Construct a Permit2 batch approval for gasless interactions.
```ts
const permitData = await uniDevKit.preparePermit2BatchCallData({
tokens: [tokenA.address, tokenB.address],
spender: uniDevKit.getContractAddress('positionManager'),
owner: userAddress
});
```

---
## Useful Links
- [Uniswap V4 Docs](https://docs.uniswap.org/contracts/v4/overview)

## Development

### Scripts

- `pnpm build` — Build the library
- `pnpm test` — Run all tests
- `pnpm lint` — Lint code with Biome
- `pnpm format` — Format code with Biome
- `pnpm docs` — Generate API docs with TypeDoc

### Contributing
## Contributing

See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.

### Release
## Release

- Releases are automated with [semantic-release](https://semantic-release.gitbook.io/semantic-release/).
- Versioning: [semver](https://semver.org/)

---

## FAQ

- **Does it work in Node and browser?**
Yes, works in both environments.
- **Can I use my own ABIs?**
Yes, but Uniswap V4 ABIs are included.

---

## License

MIT

---

> Feedback, issues, and PRs welcome.
> [API Docs](https://bootnodedev.github.io/uni-dev-kit) • [Open an Issue](https://github.com/BootNodeDev/uni-dev-kit/issues)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uniswap-dev-kit",
"version": "1.0.8",
"version": "1.0.9",
"description": "A modern TypeScript library for integrating Uniswap into your dapp.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Loading