Skip to content

Commit 0af8ad2

Browse files
authored
Merge pull request #3 from BootNodeDev/feat/usePool
feat: getPool/useGetPool
2 parents dd42969 + c6a6dc8 commit 0af8ad2

28 files changed

+2305
-303
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7-
branches: [main]
7+
branches: ["*"]
88

99
jobs:
1010
build-and-test:

README.md

Lines changed: 137 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,99 @@
44
[![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)
55
[![Docs](https://img.shields.io/badge/docs-typedoc-blue)](https://bootnodedev.github.io/uni-dev-kit)
66

7-
A modern TypeScript library for integrating Uniswap V4 into your dapp.
7+
> Modern TypeScript SDK for integrating Uniswap V4 into your dapp.
8+
> **Early version:** API may change rapidly.
89
9-
## Installation
10+
---
11+
12+
## Install
1013

1114
```bash
1215
pnpm install uniswap-dev-kit
16+
# or
17+
npm install uniswap-dev-kit
1318
```
1419

1520
## Quick Start
1621

17-
### 1. Configure and create an SDK instance
22+
### 1. Configure and create SDK instances
1823

1924
```ts
20-
import { createInstance } from 'uniswap-dev-kit';
25+
import { createInstance } from "uniswap-dev-kit";
2126

22-
const config = {
27+
// Create instance for Ethereum mainnet
28+
createInstance({
2329
chainId: 1,
24-
rpcUrl: 'https://eth.llamarpc.com',
30+
rpcUrl: "https://eth.llamarpc.com",
2531
contracts: {
26-
poolManager: '0x...',
27-
positionDescriptor: '0x...',
28-
positionManager: '0x...',
29-
quoter: '0x...',
30-
stateView: '0x...',
31-
universalRouter: '0x...',
32-
permit2: '0x...'
32+
poolManager: "0x...",
33+
positionDescriptor: "0x...",
34+
positionManager: "0x...",
35+
quoter: "0x...",
36+
stateView: "0x...",
37+
universalRouter: "0x...",
38+
permit2: "0x..."
3339
}
34-
};
40+
});
3541

36-
createInstance(config);
42+
// Create instance for another chain (e.g., Base)
43+
createInstance({
44+
chainId: 8453,
45+
rpcUrl: "https://mainnet.base.org",
46+
contracts: {
47+
// Base Uniswap V4 contract addresses...
48+
}
49+
});
3750
```
3851

39-
### 2. Use the getQuote function (vanilla JS/TS)
52+
The SDK automatically manages multiple instances based on chainId. When using hooks or utilities, just specify the chainId to use the corresponding instance:
4053

4154
```ts
42-
import { getQuote } from 'uniswap-dev-kit';
43-
import { parseEther } from 'viem';
44-
45-
const quote = await getQuote({
46-
tokens: [
47-
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
48-
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" // WETH
49-
],
50-
feeTier: 3000,
51-
tickSpacing: 60,
52-
amountIn: parseEther("1"), // 1 ETH in wei
53-
zeroForOne: true
54-
});
55+
// Will use Ethereum mainnet instance
56+
const ethPool = await getPool({ tokens: [...] }, 1);
57+
58+
// Will use Base instance
59+
const basePool = await getPool({ tokens: [...] }, 8453);
60+
61+
// If you only have one instance, chainId is optional
62+
const singleChainPool = await getPool({ tokens: [...] });
63+
```
64+
65+
### 2. Get a quote (vanilla JS/TS)
66+
67+
```ts
68+
import { getQuote } from "uniswap-dev-kit";
69+
import { parseEther } from "viem";
70+
71+
const quote = await getQuote(
72+
{
73+
tokens: [
74+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
75+
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
76+
],
77+
feeTier: 3000,
78+
tickSpacing: 60,
79+
amountIn: parseEther("1"),
80+
},
81+
1,
82+
{
83+
enabled: true,
84+
staleTime: 30000,
85+
gcTime: 300000,
86+
retry: 3,
87+
onSuccess: (data) => console.log("Quote received:", data),
88+
},
89+
);
5590
console.log(quote.amountOut);
5691
```
5792

58-
**Parameters of getQuote:**
59-
- `tokens`: `[tokenA, tokenB]` (addresses)
60-
- `feeTier`: pool fee (e.g. 3000)
61-
- `tickSpacing`: pool tick spacing (e.g. 60)
62-
- `amountIn`: amount to swap (bigint, e.g. `parseEther("1")`)
63-
- `zeroForOne`: swap direction (true: tokenA→tokenB)
64-
- `hooks` and `hookData`: optional
93+
### 3. Use in React (with hooks)
6594

66-
### 3. Use the useGetQuote hook (React)
95+
#### Get a quote
6796

6897
```tsx
69-
import { useGetQuote } from 'uniswap-dev-kit';
70-
import { parseEther } from 'viem';
98+
import { useGetQuote } from "uniswap-dev-kit";
99+
import { parseEther } from "viem";
71100

72101
function QuoteComponent() {
73102
const { data, isLoading, error } = useGetQuote({
@@ -80,7 +109,8 @@ function QuoteComponent() {
80109
tickSpacing: 60,
81110
amountIn: parseEther("1"),
82111
zeroForOne: true
83-
}
112+
},
113+
chainId: 1
84114
});
85115

86116
if (isLoading) return <span>Loading...</span>;
@@ -89,10 +119,74 @@ function QuoteComponent() {
89119
}
90120
```
91121

92-
## Documentation
122+
#### Get a pool
123+
124+
```tsx
125+
import { useGetPool } from "uniswap-dev-kit";
126+
127+
function PoolComponent() {
128+
const { data, isLoading, error } = useGetPool({
129+
params: {
130+
tokens: [
131+
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
132+
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
133+
],
134+
fee: 3000,
135+
},
136+
chainId: 1
137+
});
138+
139+
if (isLoading) return <span>Loading...</span>;
140+
if (error) return <span>Error: {error.message}</span>;
141+
return <span>Pool: {JSON.stringify(data)}</span>;
142+
}
143+
```
144+
145+
---
146+
147+
## API Reference
148+
149+
See [full TypeDoc documentation](https://bootnodedev.github.io/uni-dev-kit) for all methods, types, and advanced usage.
150+
151+
---
152+
153+
## Development
154+
155+
### Scripts
156+
157+
- `pnpm build` — Build the library
158+
- `pnpm test` — Run all tests
159+
- `pnpm lint` — Lint code with Biome
160+
- `pnpm format` — Format code with Biome
161+
- `pnpm docs` — Generate API docs with TypeDoc
162+
163+
### Contributing
164+
165+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
166+
167+
### Release
168+
169+
- Releases are automated with [semantic-release](https://semantic-release.gitbook.io/semantic-release/).
170+
- Versioning: [semver](https://semver.org/)
171+
172+
---
173+
174+
## FAQ
175+
176+
- **Which React versions are supported?**
177+
React 18+ (see peerDependencies)
178+
- **Does it work in Node and browser?**
179+
Yes, but hooks are React-only.
180+
- **Can I use my own ABIs?**
181+
Yes, but Uniswap V4 ABIs are included.
182+
183+
---
184+
185+
## License
93186

94-
See [API Documentation](https://bootnodedev.github.io/uni-dev-kit) for full API reference.
187+
MIT
95188

96189
---
97190

98-
> This is an early version. API and features will evolve rapidly.
191+
> Feedback, issues, and PRs welcome.
192+
> [API Docs](https://bootnodedev.github.io/uni-dev-kit)[Open an Issue](https://github.com/BootNodeDev/uni-dev-kit/issues)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
"@uniswap/sdk-core": "^7.7.2",
8484
"@uniswap/v3-sdk": "^3.25.2",
8585
"@uniswap/v4-sdk": "^1.21.4",
86-
"ethers": "^6.0.0",
86+
"ethers": "^5.7.2",
87+
"jsbi": "^3.2.5",
8788
"viem": "^2.29.2",
8889
"wagmi": "^2.15.2"
8990
}

0 commit comments

Comments
 (0)