uniswap-v2-loader 5.0.9 → 5.0.10
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 +5 -10
- package/bin/uniswap-v2-loader +33 -10
- package/index.js +18 -12
- package/package.json +1 -1
- package/10.csv +0 -10
- package/7.csv +0 -7
- package/8.csv +0 -8
- package/9.csv +0 -9
package/README.md
CHANGED
|
@@ -18,16 +18,11 @@
|
|
|
18
18
|
|
|
19
19
|
## CLI
|
|
20
20
|
```bash
|
|
21
|
-
npm i -g uniswap-v2-loader
|
|
22
|
-
uniswap-v2-loader --
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
--filename
|
|
27
|
-
--multicall_size
|
|
28
|
-
--from
|
|
29
|
-
--to
|
|
30
|
-
--workers
|
|
21
|
+
> npm i -g uniswap-v2-loader
|
|
22
|
+
> uniswap-v2-loader --from=1 --to=3
|
|
23
|
+
|
|
24
|
+
2,0x12ede161c702d1494612d19f05992f43aa6a26fb,0x06af07097c9eeb7fd685c692751d5c66db49c215,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
25
|
+
3,0xa478c2975ab1ea89e8196811f51a7b7ade33eb11,0x6b175474e89094c44da98b954eedeac495271d0f,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
31
26
|
```
|
|
32
27
|
|
|
33
28
|
## API Reference
|
package/bin/uniswap-v2-loader
CHANGED
|
@@ -2,15 +2,6 @@
|
|
|
2
2
|
const { load } = require('../index')
|
|
3
3
|
const rl = require('readline')
|
|
4
4
|
|
|
5
|
-
const progress = (c, t) => {
|
|
6
|
-
const total_len = t.toString().length
|
|
7
|
-
const cur = c.toString().padStart(total_len)
|
|
8
|
-
const pct = (c / t * 100 | 0).toString().padStart(3)
|
|
9
|
-
rl.cursorTo(process.stdout, 0)
|
|
10
|
-
rl.clearLine(process.stdout, 0)
|
|
11
|
-
process.stdout.write(`Loaded: ${cur} / ${t} (${pct}%)`)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
5
|
const options = [
|
|
15
6
|
'key',
|
|
16
7
|
'factory',
|
|
@@ -21,7 +12,7 @@ const options = [
|
|
|
21
12
|
'workers',
|
|
22
13
|
]
|
|
23
14
|
|
|
24
|
-
const params = {
|
|
15
|
+
const params = {}
|
|
25
16
|
var i = 2
|
|
26
17
|
while (arg = process.argv[i]) {
|
|
27
18
|
if (arg == '-h' || arg == '--help') {
|
|
@@ -45,8 +36,40 @@ while (arg = process.argv[i]) {
|
|
|
45
36
|
process.exit(22)
|
|
46
37
|
}
|
|
47
38
|
}
|
|
39
|
+
if (option == 'from' || option == 'to') {
|
|
40
|
+
value = Number(value)
|
|
41
|
+
if (isNaN(value) || value < 0 || !Number.isInteger(value)) {
|
|
42
|
+
console.log(`"${option}" should be a numeric index of pair at factory.`)
|
|
43
|
+
process.exit(22)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (option == 'workers') {
|
|
47
|
+
value = Number(value)
|
|
48
|
+
if (isNaN(value) || value < 0 || !Number.isInteger(value)) {
|
|
49
|
+
console.log(`"workers" should be a numeric and positive integer.`)
|
|
50
|
+
process.exit(22)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (option == 'multicall_size') {
|
|
54
|
+
value = Number(value)
|
|
55
|
+
if (isNaN(value) || value < 1 || !Number.isInteger(value)) {
|
|
56
|
+
console.log(`"multicall_size" should be a numeric. Not less then 1 request.`)
|
|
57
|
+
process.exit(22)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
48
60
|
params[option] = value
|
|
49
61
|
i++
|
|
50
62
|
}
|
|
51
63
|
|
|
64
|
+
params.progress = params.filename
|
|
65
|
+
? (c, t, pair) => {
|
|
66
|
+
const total_left = t.toString().length
|
|
67
|
+
const cur = c.toString().padStart(total_left)
|
|
68
|
+
const pct = String(Math.round(100 * c / t)).padStart(3)
|
|
69
|
+
rl.cursorTo(process.stdout, 0)
|
|
70
|
+
rl.clearLine(process.stdout, 0)
|
|
71
|
+
process.stdout.write(`Loaded: ${cur} / ${t} (${pct}%)`)
|
|
72
|
+
}
|
|
73
|
+
: (c, t, _) => console.log(`${_.id},${_.pair},${_.token0},${_.token1}`)
|
|
74
|
+
|
|
52
75
|
load(params)
|
package/index.js
CHANGED
|
@@ -20,6 +20,7 @@ const load = (params = {}) => {
|
|
|
20
20
|
pairs,
|
|
21
21
|
} = params
|
|
22
22
|
filename ??= default_cache_filename(factory)
|
|
23
|
+
workers = Math.min(workers, max_workers)
|
|
23
24
|
|
|
24
25
|
pairs ??= fs.existsSync(filename)
|
|
25
26
|
? fs.readFileSync(filename).toString().trim().split('\n')
|
|
@@ -37,8 +38,14 @@ const load = (params = {}) => {
|
|
|
37
38
|
}, [])
|
|
38
39
|
: []
|
|
39
40
|
|
|
40
|
-
if (to && pairs.length >= to)
|
|
41
|
+
if (to >= 0 && pairs.length >= to) {
|
|
42
|
+
if (progress)
|
|
43
|
+
for (var i = from; i < to; i++)
|
|
44
|
+
progress(pairs[i].id, to, pairs[i])
|
|
41
45
|
|
|
46
|
+
return Promise.resolve(pairs.slice(0, to))
|
|
47
|
+
}
|
|
48
|
+
|
|
42
49
|
return (to
|
|
43
50
|
? Promise.resolve(to)
|
|
44
51
|
: fetch('https://eth-mainnet.g.alchemy.com/v2/' + key, {
|
|
@@ -53,24 +60,24 @@ const load = (params = {}) => {
|
|
|
53
60
|
}).then(_ => _.json()).then(_ => Number(_.result))
|
|
54
61
|
).then(all_pairs_length => {
|
|
55
62
|
const start_loading_from = pairs.length
|
|
56
|
-
? Math.max(from
|
|
63
|
+
? Math.max(from, pairs[pairs.length - 1].id + 1)
|
|
57
64
|
: 0
|
|
58
65
|
|
|
59
66
|
var next_pair_order = pairs.length
|
|
60
67
|
? pairs[pairs.length - 1].id + 1
|
|
61
68
|
: 0
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
|
|
70
|
+
if (progress)
|
|
71
|
+
for (var i = from; i < start_loading_from; i++)
|
|
72
|
+
progress(pairs[i].id, all_pairs_length, pairs[i])
|
|
64
73
|
|
|
65
74
|
const onpair = pair => {
|
|
66
75
|
pairs[pair.id] = pair
|
|
67
|
-
if (progress) progress(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
next_pair_order++
|
|
73
|
-
}
|
|
76
|
+
if (progress) progress(pair.id, all_pairs_length, pair)
|
|
77
|
+
var _
|
|
78
|
+
while (_ = pairs[next_pair_order]) {
|
|
79
|
+
fs.appendFileSync(filename, `${_.id},${_.pair},${_.token0},${_.token1}\n`)
|
|
80
|
+
next_pair_order++
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
|
|
@@ -80,7 +87,6 @@ const load = (params = {}) => {
|
|
|
80
87
|
ids.push(i)
|
|
81
88
|
return require('./loader')({ ids, factory, key, multicall_size }, onpair)
|
|
82
89
|
.then(() => pairs)
|
|
83
|
-
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
const missed = []
|
package/package.json
CHANGED
package/10.csv
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
0,0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
2
|
-
1,0x3139ffc91b99aa94da8a2dc13f1fc36f9bdc98ee,0x8e870d67f660d95d5be530380d0ec0bd388289e1,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
3
|
-
2,0x12ede161c702d1494612d19f05992f43aa6a26fb,0x06af07097c9eeb7fd685c692751d5c66db49c215,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
4
|
-
3,0xa478c2975ab1ea89e8196811f51a7b7ade33eb11,0x6b175474e89094c44da98b954eedeac495271d0f,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
5
|
-
4,0x07f068ca326a469fc1d87d85d448990c8cba7df9,0x408e41876cccdc0f92210600ef50372656052a38,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
6
|
-
5,0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5,0x6b175474e89094c44da98b954eedeac495271d0f,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
7
|
-
6,0xce407cd7b95b39d3b4d53065e711e713dd5c5999,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0xfa3e941d1f6b7b10ed84a0c211bfa8aee907965e
|
|
8
|
-
7,0x33c2d48bc95fb7d0199c5c693e7a9f527145a9af,0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c,0x6b175474e89094c44da98b954eedeac495271d0f
|
|
9
|
-
8,0xb6909b960dbbe7392d405429eb2b3649752b4838,0x0d8775f648430679a709e98d2b0cb6250d2887ef,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
10
|
-
9,0x30eb5e15476e6a80f4f3cd8479749b4881dab1b8,0x39aa39c021dfbae8fac545936693ac917d5e7563,0x5d3a536e4d6dbd6114cc1ead35777bab948e3643
|
package/7.csv
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
0,0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
2
|
-
1,0x3139ffc91b99aa94da8a2dc13f1fc36f9bdc98ee,0x8e870d67f660d95d5be530380d0ec0bd388289e1,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
3
|
-
2,0x12ede161c702d1494612d19f05992f43aa6a26fb,0x06af07097c9eeb7fd685c692751d5c66db49c215,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
4
|
-
3,0xa478c2975ab1ea89e8196811f51a7b7ade33eb11,0x6b175474e89094c44da98b954eedeac495271d0f,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
5
|
-
4,0x07f068ca326a469fc1d87d85d448990c8cba7df9,0x408e41876cccdc0f92210600ef50372656052a38,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
6
|
-
5,0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5,0x6b175474e89094c44da98b954eedeac495271d0f,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
7
|
-
6,0xce407cd7b95b39d3b4d53065e711e713dd5c5999,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0xfa3e941d1f6b7b10ed84a0c211bfa8aee907965e
|
package/8.csv
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
0,0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
2
|
-
1,0x3139ffc91b99aa94da8a2dc13f1fc36f9bdc98ee,0x8e870d67f660d95d5be530380d0ec0bd388289e1,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
3
|
-
2,0x12ede161c702d1494612d19f05992f43aa6a26fb,0x06af07097c9eeb7fd685c692751d5c66db49c215,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
4
|
-
3,0xa478c2975ab1ea89e8196811f51a7b7ade33eb11,0x6b175474e89094c44da98b954eedeac495271d0f,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
5
|
-
4,0x07f068ca326a469fc1d87d85d448990c8cba7df9,0x408e41876cccdc0f92210600ef50372656052a38,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
6
|
-
5,0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5,0x6b175474e89094c44da98b954eedeac495271d0f,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
7
|
-
6,0xce407cd7b95b39d3b4d53065e711e713dd5c5999,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0xfa3e941d1f6b7b10ed84a0c211bfa8aee907965e
|
|
8
|
-
7,0x33c2d48bc95fb7d0199c5c693e7a9f527145a9af,0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c,0x6b175474e89094c44da98b954eedeac495271d0f
|
package/9.csv
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
0,0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
2
|
-
1,0x3139ffc91b99aa94da8a2dc13f1fc36f9bdc98ee,0x8e870d67f660d95d5be530380d0ec0bd388289e1,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
3
|
-
2,0x12ede161c702d1494612d19f05992f43aa6a26fb,0x06af07097c9eeb7fd685c692751d5c66db49c215,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
4
|
-
3,0xa478c2975ab1ea89e8196811f51a7b7ade33eb11,0x6b175474e89094c44da98b954eedeac495271d0f,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|
|
5
|
-
4,0x07f068ca326a469fc1d87d85d448990c8cba7df9,0x408e41876cccdc0f92210600ef50372656052a38,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
6
|
-
5,0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5,0x6b175474e89094c44da98b954eedeac495271d0f,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
|
|
7
|
-
6,0xce407cd7b95b39d3b4d53065e711e713dd5c5999,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0xfa3e941d1f6b7b10ed84a0c211bfa8aee907965e
|
|
8
|
-
7,0x33c2d48bc95fb7d0199c5c693e7a9f527145a9af,0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c,0x6b175474e89094c44da98b954eedeac495271d0f
|
|
9
|
-
8,0xb6909b960dbbe7392d405429eb2b3649752b4838,0x0d8775f648430679a709e98d2b0cb6250d2887ef,0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
|