Skip to content

Commit 2bf7a74

Browse files
authored
Merge pull request #19 from BootNodeDev/readme
chore(docs): update readme
2 parents f644816 + 7ad518d commit 2bf7a74

File tree

2 files changed

+115
-129
lines changed

2 files changed

+115
-129
lines changed

README.md

Lines changed: 114 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@
77
> Modern TypeScript SDK for integrating Uniswap V4 into your dapp.
88
> **Early version:** API may change rapidly.
99
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.
1111

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.
2113

2214
## Installation
2315

@@ -45,102 +37,91 @@ const uniDevKit = new UniDevKitV4({
4537
});
4638

4739
const pool = await uniDevKit.getPool({
48-
tokens: ["0xTokenA", "0xTokenB"],
40+
currencyA: "0xTokenA",
41+
currencyB: "0xTokenB",
4942
fee: 3000
5043
});
5144

5245
const quote = await uniDevKit.getQuote({
53-
pool,
54-
amountIn: "1000000000000000000"
46+
poolKey: pool.poolKey,
47+
amountIn: "1000000000000000000",
48+
zeroForOne: true
5549
});
5650
```
5751

5852
## Documentation
5953
Full API documentation with TypeDoc: [https://bootnodedev.github.io/uni-dev-kit](https://bootnodedev.github.io/uni-dev-kit)
6054

61-
## API Reference
62-
63-
### Index
64-
- [uniswap-dev-kit](#uniswap-dev-kit)
65-
- [Features](#features)
66-
- [Installation](#installation)
67-
- [Quick Start](#quick-start)
68-
- [Documentation](#documentation)
69-
- [API Reference](#api-reference)
70-
- [Index](#index)
71-
- [`getPool`](#getpool)
72-
- [`getQuote`](#getquote)
73-
- [`getTokens`](#gettokens)
74-
- [`getPosition`](#getposition)
75-
- [`getPoolKeyFromPoolId`](#getpoolkeyfrompoolid)
76-
- [`buildSwapCallData`](#buildswapcalldata)
77-
- [`buildAddLiquidityCallData`](#buildaddliquiditycalldata)
78-
- [`preparePermit2BatchCallData`](#preparepermit2batchcalldata)
79-
- [`buildRemoveLiquidityCallData`](#buildremoveliquiditycalldata)
80-
- [Basis Points Reference](#basis-points-reference)
81-
- [Useful Links](#useful-links)
82-
- [Development](#development)
83-
- [Scripts](#scripts)
84-
- [Contributing](#contributing)
85-
- [Release](#release)
86-
- [License](#license)
87-
88-
### `getPool`
89-
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+
9064
```ts
9165
const pool = await uniDevKit.getPool({
92-
tokens: [tokenA, tokenB],
66+
currencyA: "0xTokenA",
67+
currencyB: "0xTokenB",
9368
fee: 3000
9469
});
9570
```
9671

97-
### `getQuote`
98-
Simulate a swap to get `amountOut` and `sqrtPriceLimitX96`.
99-
```ts
100-
const quote = await uniDevKit.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.
10576

106-
### `getTokens`
107-
Retrieve token metadata.
10877
```ts
10978
const tokens = await uniDevKit.getTokens({
110-
addresses: ["0x...", "0x..."]
79+
addresses: ["0xTokenA", "0xTokenB"]
11180
});
11281
```
11382

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.
87+
11688
```ts
117-
const position = await uniDevKit.getPosition({
118-
tokenId: 123
89+
const quote = await uniDevKit.getQuote({
90+
poolKey: pool.poolKey,
91+
amountIn: "1000000000000000000",
92+
zeroForOne: true
11993
});
94+
// Returns { amountOut, estimatedGasUsed, timestamp }
12095
```
12196

122-
### `getPoolKeyFromPoolId`
123-
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.
101+
124102
```ts
125-
const poolKey = await uniDevKit.getPoolKeyFromPoolId({
126-
poolId: "0x..."
127-
});
103+
const position = await uniDevKit.getPositionDetails("123");
104+
// Returns { tokenId, tickLower, tickUpper, liquidity, poolKey }
128105
```
129106

130-
### `buildSwapCallData`
131-
Construct calldata for a Universal Router swap.
107+
### Swap Operations
108+
109+
#### `buildSwapCallData`
110+
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.
132113

133114
```ts
134115
// Basic swap
135-
const { calldata, value } = await uniDevKit.buildSwapCallData({
136-
tokenIn: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
137-
amountIn: parseUnits("100", 6), // 100 USDC
138-
pool: pool,
139-
slippageTolerance: 50, // 0.5%
140-
recipient: "0x..."
116+
const { calldata, value } = uniDevKit.buildSwapCallData({
117+
pool,
118+
amountIn: "1000000000000000000",
119+
zeroForOne: true,
120+
recipient: "0x...",
121+
amountOutMinimum: "900000000000000000"
141122
});
142123

143-
// Swap with permit2
124+
// With Permit2
144125
const permitData = await uniDevKit.preparePermit2Data({
145126
token: tokenIn,
146127
spender: uniDevKit.getContractAddress('universalRouter'),
@@ -155,95 +136,100 @@ const signature = await signer._signTypedData(
155136

156137
const permitWithSignature = permitData.buildPermit2DataWithSignature(signature);
157138

158-
const { calldata, value } = await uniDevKit.buildSwapCallData({
159-
tokenIn,
160-
amountIn,
139+
const { calldata, value } = uniDevKit.buildSwapCallData({
161140
pool,
162-
slippageTolerance: 50,
141+
amountIn,
142+
zeroForOne: true,
163143
recipient,
144+
amountOutMinimum,
164145
permit2Signature: permitWithSignature
165146
});
166147
```
167148

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+
170156
```ts
171-
// Without permit
157+
// Adding to existing pool
172158
const { calldata, value } = await uniDevKit.buildAddLiquidityCallData({
173159
pool,
174160
amount0: "100000000",
175-
amount1: "50000000000000000",
176161
recipient: "0x...",
177162
slippageTolerance: 50
178163
});
179164

180-
// With Permit2 batch approval
181-
const permitData = await uniDevKit.preparePermit2BatchData({
182-
tokens: [pool.token0.address, pool.token1.address],
183-
spender: uniDevKit.getContractAddress('positionManager'),
184-
owner: userAddress
185-
});
186-
187-
const signature = await signer.signTypedData(
188-
permitData.toSign.domain,
189-
permitData.toSign.types,
190-
permitData.toSign.values
191-
);
192-
193-
const permitWithSignature = permitData.buildPermit2BatchDataWithSignature(signature);
194-
165+
// Creating new pool (both amounts required)
195166
const { calldata, value } = await uniDevKit.buildAddLiquidityCallData({
196167
pool,
197-
amount0: parseUnits("100", 6),
168+
amount0: "100000000",
169+
amount1: "50000000000000000",
198170
recipient: "0x...",
199-
permit2BatchSignature: permitWithSignature
200-
});
201-
202-
const tx = await sendTransaction({
203-
to: uniDevKit.getContractAddress('positionManager'),
204-
data: calldata,
205-
value
171+
slippageTolerance: 50
206172
});
207173
```
208174

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.
179+
211180
```ts
212-
const permitData = await uniDevKit.preparePermit2BatchCallData({
213-
tokens: [tokenA.address, tokenB.address],
214-
spender: uniDevKit.getContractAddress('positionManager'),
215-
owner: userAddress
181+
const { calldata, value } = await uniDevKit.buildRemoveLiquidityCallData({
182+
liquidityPercentage: 10000, // 100%
183+
tokenId: '123',
184+
slippageTolerance: 50
216185
});
217186
```
218187

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+
221193
```ts
222-
const { calldata, value } = await uniDevKit.buildRemoveLiquidityCallData({
223-
liquidityPercentage: 10_000, // 100%
194+
const { calldata, value } = await uniDevKit.buildCollectFeesCallData({
224195
tokenId: '123',
225-
slippageTolerance: 50, // 0.5%
196+
recipient: "0x...",
226197
});
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.
227204

228-
const tx = await sendTransaction({
229-
to: uniDevKit.getContractAddress('positionManager'),
230-
data: calldata,
231-
value
205+
```ts
206+
const permitData = await uniDevKit.preparePermit2Data({
207+
token: tokenIn,
208+
spender: uniDevKit.getContractAddress('universalRouter'),
209+
owner: userAddress
232210
});
233211
```
234212

235-
#### Basis Points Reference
213+
#### `preparePermit2BatchData`
214+
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.
217+
218+
```ts
219+
const permitData = await uniDevKit.preparePermit2BatchData({
220+
tokens: [tokenA.address, tokenB.address],
221+
spender: uniDevKit.getContractAddress('positionManager'),
222+
owner: userAddress
223+
});
236224

237-
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:
225+
const signature = await signer._signTypedData(
226+
permitData.toSign.domain,
227+
permitData.toSign.types,
228+
permitData.toSign.values
229+
);
238230

239-
| Basis Points (bps) | Fraction | Percentage |
240-
|:------------------:|:--------:|:----------:|
241-
| 1 | 1/10_000 | 0.01% |
242-
| 10 | 10/10_000 | 0.1% |
243-
| 100 | 100/10_000 | 1% |
244-
| 500 | 500/10_000 | 5% |
245-
| 1000 | 1000/10_000 | 10% |
246-
| 10_000 | 10_000/10_000 | 100% |
231+
const permitWithSignature = permitData.buildPermit2BatchDataWithSignature(signature);
232+
```
247233

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "uniswap-dev-kit",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "A modern TypeScript library for integrating Uniswap into your dapp.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)