uniswap-v2-loader 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -45
- package/calp-dark.svg +3 -0
- package/calp-light.svg +3 -0
- package/default_cache_filename.js +2 -2
- package/index.js +2 -1
- package/package.json +1 -1
- package/debug.js +0 -3
package/README.md
CHANGED
|
@@ -1,61 +1,123 @@
|
|
|
1
|
-
#
|
|
1
|
+
# <picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="./calp-dark.svg">
|
|
3
|
+
<img alt="calp.pro icon" src="./calp-light.svg" height="32" style="vertical-align: middle;">
|
|
4
|
+
</picture> uniswap-v2-loader
|
|
5
|
+
<br>
|
|
6
|
+
<br>
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
**Fast DeFi AMM pools loader.** Optimized for **Multi-core CPUs** with **viem** multicall and smart **disk-cache**.
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
### Popular Uniswap V2 based protocols
|
|
11
|
+
| Protocol | Factory Address |
|
|
12
|
+
| :--- | :--- |
|
|
13
|
+
| **Uniswap V2** | `0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f` |
|
|
14
|
+
| **SushiSwap** | `0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac` |
|
|
15
|
+
| **PancakeSwap** | `0x1097053Fd2ea711dad45caCcc45EfF7548fCB362` |
|
|
16
|
+
| **ShibaSwap** | `0x115934131916C8b277DD010Ee02de363c09d037c` |
|
|
17
|
+
| **DefiSwap** | `0x9DEB29c9a4c7A88a3C0257393b7f3335338D9A9D` |
|
|
18
|
+
| **EtherVista** | `0x9a27cb5ae0B2cEe0bb71f9A85C0D60f3920757B4` |
|
|
19
|
+
| **Balancer V2** | `0xBA12222222228d8Ba445958a75a0704d566BF2C8` |
|
|
8
20
|
|
|
9
|
-
|
|
10
|
-
|
|
21
|
+
|
|
22
|
+
### CLI
|
|
23
|
+
```bash
|
|
11
24
|
npm i -g uniswap-v2-loader
|
|
12
|
-
uniswap-v2-loader
|
|
25
|
+
uniswap-v2-loader --help
|
|
26
|
+
Options:
|
|
27
|
+
--key
|
|
28
|
+
--factory
|
|
29
|
+
--filename
|
|
30
|
+
--multicall_size
|
|
31
|
+
--from
|
|
32
|
+
--to
|
|
33
|
+
--workers
|
|
34
|
+
--update_timeout
|
|
13
35
|
```
|
|
14
36
|
|
|
15
|
-
|
|
16
37
|
## API Reference
|
|
38
|
+
|
|
17
39
|
### `load(params)`
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
High-performance parallel fetcher for liquidity pairs. Efficiently synchronizes state with local disk cache and executes multi-threaded RPC requests.
|
|
41
|
+
|
|
42
|
+
**Parameters**
|
|
43
|
+
| Name | Type | Description | Default |
|
|
44
|
+
| :--- | :--- | :--- | :--- |
|
|
45
|
+
| `from` | `number` | Start loading from this pair index. | `0` |
|
|
46
|
+
| `to` | `number` | End index (exclusive). Required for range loading. | `undefined` |
|
|
47
|
+
| `filename` | `string` | Local CSV cache path. Supports OS-standard locations. | *Auto-detected* |
|
|
48
|
+
| `factory` | `string` | Smart contract factory address. | `Uniswap V2` |
|
|
49
|
+
| `key` | `string` | Alchemy/RPC API Key (priority over ENV). | `process.env.KEY` |
|
|
50
|
+
| `multicall_size` | `number` | RPC batch size per multicall request. | `50` |
|
|
51
|
+
| `workers` | `number` | Number of parallel worker threads. | `CPU - 1` |
|
|
52
|
+
| `progress` | `function` | Progress callback: `(current, total) => {}`. | `undefined` |
|
|
53
|
+
|
|
54
|
+
**Returns**: `Promise<Pair[]>`
|
|
55
|
+
|
|
56
|
+
**Example Response**
|
|
57
|
+
```json
|
|
58
|
+
[
|
|
59
|
+
{
|
|
60
|
+
"id": 0,
|
|
61
|
+
"pair": "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc",
|
|
62
|
+
"token0": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eb48",
|
|
63
|
+
"token1": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### Smart Cross-Platform Caching
|
|
71
|
+
The loader automatically identifies the optimal persistent storage path for your operating system to ensure zero-configuration caching:
|
|
72
|
+
- **Linux:** `$XDG_CACHE_HOME` or `~/.cache/`
|
|
73
|
+
- **macOS:** `~/Library/Caches/`
|
|
74
|
+
- **Windows:** `%LOCALAPPDATA%` or `AppData/Local/`
|
|
75
|
+
|
|
76
|
+
Cache files are named following the pattern `${package_name}_{factory_address}.csv`.
|
|
77
|
+
|
|
78
|
+
---
|
|
29
79
|
|
|
30
80
|
### `onupdate(callback, params)`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
81
|
+
Continuous synchronization engine. Performs initial load and subsequently polls for new pairs.
|
|
82
|
+
|
|
83
|
+
**Parameters**
|
|
84
|
+
| Name | Type | Description | Default |
|
|
85
|
+
| :--- | :--- | :--- | :--- |
|
|
86
|
+
| `callback` | `function` | Invoked with updated `Pair[]` array. | **Required** |
|
|
87
|
+
| `params` | `object` | All options from `load()` plus `update_timeout`. | - |
|
|
88
|
+
| `update_timeout` | `number` | Polling interval in milliseconds. | `5000` |
|
|
89
|
+
|
|
90
|
+
**Returns**: `function` (Stop/Unsubscribe function)
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### Schema: `Pair`
|
|
95
|
+
Standardized liquidity pool object.
|
|
96
|
+
|
|
97
|
+
| Property | Type | Description |
|
|
98
|
+
| :--- | :--- | :--- |
|
|
99
|
+
| `id` | `number` | Global index of the pair in the factory. |
|
|
100
|
+
| `pair` | `string` | Ethereum address of the liquidity pool. |
|
|
101
|
+
| `token0` | `string` | Address of the first asset. |
|
|
102
|
+
| `token1` | `string` | Address of the second asset. |
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Usage Example
|
|
46
107
|
```javascript
|
|
47
108
|
const { load, onupdate } = require('uniswap-v2-loader')
|
|
109
|
+
const rl = require('readline')
|
|
48
110
|
|
|
49
|
-
// Load initial set
|
|
50
|
-
load({to: 10}).then(pairs =>
|
|
51
|
-
pairs.forEach(({id, pair}) => console.log(`ID: ${id} | Pair: ${pair}`))
|
|
52
|
-
)
|
|
53
111
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
112
|
+
load({
|
|
113
|
+
factory: '0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac', // SushiSwap
|
|
114
|
+
to: 1000,
|
|
115
|
+
progress: (c, t) => {
|
|
116
|
+
rl.cursorTo(process.stdout, 0)
|
|
117
|
+
rl.clearLine(process.stdout, 0)
|
|
118
|
+
process.stdout.write(`Loaded: ${c} / ${t} (${(c/t*100).toFixed(2)}%)`)
|
|
119
|
+
}
|
|
120
|
+
}).then(pairs => {
|
|
121
|
+
console.log(`\nSuccessfully loaded ${pairs.length} SushiSwap pairs`)
|
|
57
122
|
})
|
|
58
|
-
|
|
59
|
-
// Stop monitoring if needed
|
|
60
|
-
// unsubscribe()
|
|
61
123
|
```
|
package/calp-dark.svg
ADDED
package/calp-light.svg
ADDED
|
@@ -4,7 +4,7 @@ const os = require('os')
|
|
|
4
4
|
const home = os.homedir()
|
|
5
5
|
const pkg = require('./package.json')
|
|
6
6
|
|
|
7
|
-
module.exports = path.join(
|
|
7
|
+
module.exports = (factory) => path.join(
|
|
8
8
|
...(process.platform === 'win32'
|
|
9
9
|
? (env.LOCALAPPDATA || env.APPDATA)
|
|
10
10
|
? [env.LOCALAPPDATA || env.APPDATA]
|
|
@@ -15,5 +15,5 @@ module.exports = path.join(
|
|
|
15
15
|
? [env.XDG_CACHE_HOME]
|
|
16
16
|
: [home, '.cache']
|
|
17
17
|
),
|
|
18
|
-
pkg.name
|
|
18
|
+
`${pkg.name}_${factory.toLowerCase()}.csv`
|
|
19
19
|
)
|
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const load = (params = {}) => {
|
|
|
13
13
|
var {
|
|
14
14
|
key = debug_key,
|
|
15
15
|
factory = uniswap_v2_factory,
|
|
16
|
-
filename
|
|
16
|
+
filename,
|
|
17
17
|
multicall_size = 50,
|
|
18
18
|
from = 0,
|
|
19
19
|
to,
|
|
@@ -21,6 +21,7 @@ const load = (params = {}) => {
|
|
|
21
21
|
workers = max_workers,
|
|
22
22
|
pairs,
|
|
23
23
|
} = params
|
|
24
|
+
filename ??= default_cache_filename(factory)
|
|
24
25
|
const client = createPublicClient({
|
|
25
26
|
chain: mainnet,
|
|
26
27
|
transport: http('https://eth-mainnet.g.alchemy.com/v2/' + key)
|
package/package.json
CHANGED
package/debug.js
DELETED