You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Modern TypeScript SDK for integrating Uniswap V4 into your dapp.
8
8
> **Early version:** API may change rapidly.
9
9
10
-
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.
10
+
An abstraction layer built on top of the official Uniswap V4 SDK that simplifies integration by providing high-level methods for common operations. This library maintains compatibility with the official SDK's interfaces while reducing boilerplate and bundling related contract interactions.
11
11
12
-
## Features
13
-
14
-
- 🚀 Simple and intuitive API
15
-
- 🔄 Support for all major Uniswap V4 operations
16
-
- 💰 Native token support
17
-
- 🔒 Permit2 integration for gasless approvals
18
-
- 📊 Flexible liquidity management
19
-
- 🔍 Built-in quote simulation
20
-
- 🛠 TypeScript support
12
+
While the official SDK provides primitives for pool creation, position management, and swap execution, this SDK abstracts away the complexity of composing these primitives. Common workflows like adding liquidity or executing swaps are reduced to single method calls.
21
13
22
14
## Installation
23
15
@@ -45,102 +37,91 @@ const uniDevKit = new UniDevKitV4({
45
37
});
46
38
47
39
const pool =awaituniDevKit.getPool({
48
-
tokens: ["0xTokenA", "0xTokenB"],
40
+
currencyA: "0xTokenA",
41
+
currencyB: "0xTokenB",
49
42
fee: 3000
50
43
});
51
44
52
45
const quote =awaituniDevKit.getQuote({
53
-
pool,
54
-
amountIn: "1000000000000000000"
46
+
poolKey: pool.poolKey,
47
+
amountIn: "1000000000000000000",
48
+
zeroForOne: true
55
49
});
56
50
```
57
51
58
52
## Documentation
59
53
Full API documentation with TypeDoc: [https://bootnodedev.github.io/uni-dev-kit](https://bootnodedev.github.io/uni-dev-kit)
Retrieve a pool object from two tokens and a fee tier.
55
+
## Core Operations
56
+
57
+
### Pool Management
58
+
59
+
#### `getPool`
60
+
Fetches live pool state from the blockchain and instantiates a fully configured Pool object. Uses multicall to batch `V4StateView.getSlot0()` and `V4StateView.getLiquidity()` calls, and handles sorting token pairs to match the official SDK's conventions.
61
+
62
+
**Without this SDK:** Manually call V4StateView.getSlot0() and V4StateView.getLiquidity(), construct PoolKey, sort tokens, then instantiate Pool with the fetched data. This method encapsulates all of that logic.
63
+
90
64
```ts
91
65
const pool =awaituniDevKit.getPool({
92
-
tokens: [tokenA, tokenB],
66
+
currencyA: "0xTokenA",
67
+
currencyB: "0xTokenB",
93
68
fee: 3000
94
69
});
95
70
```
96
71
97
-
### `getQuote`
98
-
Simulate a swap to get `amountOut` and `sqrtPriceLimitX96`.
99
-
```ts
100
-
const quote =awaituniDevKit.getQuote({
101
-
pool,
102
-
amountIn: "1000000000000000000"
103
-
});
104
-
```
72
+
#### `getTokens`
73
+
Fetches ERC20 metadata for multiple tokens and returns Currency instances. Uses multicall to batch `symbol()`, `name()`, and `decimals()` calls across all tokens, and automatically handles native currency by instantiating Ether based on the chain ID.
74
+
75
+
**Without this SDK:** Call erc20Abi.symbol(), name(), and decimals() for each token, handle native currency separately, construct Token or Ether instances manually. This method handles all of that logic.
105
76
106
-
### `getTokens`
107
-
Retrieve token metadata.
108
77
```ts
109
78
const tokens =awaituniDevKit.getTokens({
110
-
addresses: ["0x...", "0x..."]
79
+
addresses: ["0xTokenA", "0xTokenB"]
111
80
});
112
81
```
113
82
114
-
### `getPosition`
115
-
Get details about a Uniswap V4 LP position.
83
+
#### `getQuote`
84
+
Simulates a swap through V4Quoter to get the expected amountOut and gas estimate. Returns structured data ready to use in your application.
85
+
86
+
**Without this SDK:** Manually construct quote parameters with poolKey, encode swap details, call V4Quoter contract, decode and structure the results yourself.
Retrieve the `PoolKey` object for a given pool ID.
97
+
#### `getPositionDetails`
98
+
Fetches position state from the PositionManager and decodes the tick range, liquidity, and pool key. Uses multicall to batch `V4PositionManager.getPoolAndPositionInfo()` and `V4PositionManager.getPositionLiquidity()` calls, and handles data decoding.
99
+
100
+
**Without this SDK:** Call getPoolAndPositionInfo() and getPositionLiquidity() separately, decode packed position data, extract tick bounds and pool key manually.
Generates Universal Router calldata for executing swaps. Encapsulates V4Planner usage to build swap actions, settle operations, and take operations. Supports Permit2 integration for gasless approvals.
111
+
112
+
**Without this SDK:** Instantiate V4Planner, call addAction(), addSettle(), and addTake() in sequence, manually encode Permit2 data if needed, construct command array and inputs array, encode Universal Router execute() call. This method wraps all of that complexity.
132
113
133
114
```ts
134
115
// Basic swap
135
-
const { calldata, value } =awaituniDevKit.buildSwapCallData({
const { calldata, value } =awaituniDevKit.buildSwapCallData({
159
-
tokenIn,
160
-
amountIn,
139
+
const { calldata, value } =uniDevKit.buildSwapCallData({
161
140
pool,
162
-
slippageTolerance: 50,
141
+
amountIn,
142
+
zeroForOne: true,
163
143
recipient,
144
+
amountOutMinimum,
164
145
permit2Signature: permitWithSignature
165
146
});
166
147
```
167
148
168
-
### `buildAddLiquidityCallData`
169
-
Build calldata to add liquidity to a pool.
149
+
### Liquidity Operations
150
+
151
+
#### `buildAddLiquidityCallData`
152
+
Generates V4PositionManager.mint() calldata with intelligent handling of pool creation vs. existing pools. Automatically constructs Position instances, calculates sqrtPriceX96 for new pools, handles native currency wrapping/unwrapping, and integrates with Permit2 for batch approvals.
153
+
154
+
**Without this SDK:** Check pool liquidity to determine if creating new pool, calculate sqrtPriceX96 manually for new pools, choose between Position.fromAmounts/fromAmount0/fromAmount1, handle native currency, construct V4PositionManager.addCallParameters with all edge cases, optionally prepare Permit2 batch data. This method handles all that complexity.
155
+
170
156
```ts
171
-
//Without permit
157
+
//Adding to existing pool
172
158
const { calldata, value } =awaituniDevKit.buildAddLiquidityCallData({
const { calldata, value } =awaituniDevKit.buildAddLiquidityCallData({
196
167
pool,
197
-
amount0: parseUnits("100", 6),
168
+
amount0: "100000000",
169
+
amount1: "50000000000000000",
198
170
recipient: "0x...",
199
-
permit2BatchSignature: permitWithSignature
200
-
});
201
-
202
-
const tx =awaitsendTransaction({
203
-
to: uniDevKit.getContractAddress('positionManager'),
204
-
data: calldata,
205
-
value
171
+
slippageTolerance: 50
206
172
});
207
173
```
208
174
209
-
### `preparePermit2BatchCallData`
210
-
Construct a Permit2 batch approval for gasless interactions.
175
+
#### `buildRemoveLiquidityCallData`
176
+
Generates V4PositionManager.burn() calldata for removing liquidity from positions. Automatically fetches current position state, handles liquidity percentage calculations, and applies slippage tolerance.
177
+
178
+
**Without this SDK:** Fetch position details from PositionManager, decode position data, calculate liquidity percentage, construct Position instance, call V4PositionManager.removeCallParameters with all parameters. This method encapsulates that workflow.
const{ calldata, value } =awaituniDevKit.buildRemoveLiquidityCallData({
182
+
liquidityPercentage: 10000, // 100%
183
+
tokenId: '123',
184
+
slippageTolerance: 50
216
185
});
217
186
```
218
187
219
-
### `buildRemoveLiquidityCallData`
220
-
Build calldata to remove liquidity from a pool.
188
+
#### `buildCollectFeesCallData`
189
+
Generates V4PositionManager.collect() calldata for collecting accrued fees from positions. Automatically fetches position details and constructs the collect parameters with proper recipient and hook data handling.
190
+
191
+
**Without this SDK:** Fetch position details from PositionManager, decode position data, construct Position instance, manually set up collect parameters with recipient and hook data, call V4PositionManager.collectCallParameters.
192
+
221
193
```ts
222
-
const { calldata, value } =awaituniDevKit.buildRemoveLiquidityCallData({
223
-
liquidityPercentage: 10_000, // 100%
194
+
const { calldata, value } =awaituniDevKit.buildCollectFeesCallData({
224
195
tokenId: '123',
225
-
slippageTolerance: 50, // 0.5%
196
+
recipient: "0x...",
226
197
});
198
+
```
199
+
200
+
### Permit2 Integration
201
+
202
+
#### `preparePermit2Data`
203
+
Prepares single-token Permit2 approval data for swaps. Returns structured data ready for EIP-712 signing.
227
204
228
-
const tx =awaitsendTransaction({
229
-
to: uniDevKit.getContractAddress('positionManager'),
Prepares batch Permit2 approval data for multiple tokens. Uses multicall to batch `Permit2.allowance()` calls across all tokens and returns structured data ready for EIP-712 signing. Used for adding liquidity to pools requiring multiple token approvals.
215
+
216
+
**Without this SDK:** Call Permit2.allowance() for each token, construct PermitBatch struct manually, fetch current block timestamp to calculate sigDeadline, use Permit2 SDK to prepare typed data with correct domain and values. This method handles all of that setup.
Throughout the library, percentages are represented in basis points (bps). For example, when setting a slippage tolerance of 0.5%, you would use `50` bps. Here's a quick reference:
0 commit comments