uniswap-v2-loader 5.0.8 → 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 +19 -12
- package/package.json +1 -1
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
|
|
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
|
|
|
@@ -79,7 +86,7 @@ const load = (params = {}) => {
|
|
|
79
86
|
for (var i = start_loading_from; i < all_pairs_length; i++)
|
|
80
87
|
ids.push(i)
|
|
81
88
|
return require('./loader')({ ids, factory, key, multicall_size }, onpair)
|
|
82
|
-
|
|
89
|
+
.then(() => pairs)
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
const missed = []
|