uniswap-v2-loader 5.0.10 → 5.0.11

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.
Files changed (3) hide show
  1. package/index.js +10 -1
  2. package/loader.js +21 -2
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -57,7 +57,15 @@ const load = (params = {}) => {
57
57
  method: 'eth_call',
58
58
  params: [{ to: factory, data: '0x574f2ba3' }, 'latest']
59
59
  })
60
- }).then(_ => _.json()).then(_ => Number(_.result))
60
+ }).then(
61
+ _ => {
62
+ if (_.ok) return _.json().then(_ => Number(_.result))
63
+ throw 'fail start'
64
+ },
65
+ _ => {
66
+ throw 'fetch failed'
67
+ }
68
+ )
61
69
  ).then(all_pairs_length => {
62
70
  const start_loading_from = pairs.length
63
71
  ? Math.max(from, pairs[pairs.length - 1].id + 1)
@@ -111,6 +119,7 @@ const load = (params = {}) => {
111
119
  }))
112
120
  ).then(() => pairs)
113
121
  })
122
+ .catch(() => new Promise(resolve => setTimeout(() => resolve(load(params)), 1000)))
114
123
  }
115
124
 
116
125
  module.exports.load = (params = {}) =>
package/loader.js CHANGED
@@ -9,7 +9,16 @@ const get_pairs_addresses = (key, factory, ids) => ids.length == 0
9
9
  method: 'eth_call',
10
10
  params: [{ to: factory, data: '0x1e3dd18b' + id.toString(16).padStart(64, '0') }, 'latest']
11
11
  })))
12
- }).then(_ => _.json()).then(responds => {
12
+ }).then(
13
+ _ => {
14
+ if (_.ok) return _.json()
15
+ throw 'respond not ok'
16
+ },
17
+ _ => {
18
+ throw 'failed fetch'
19
+ }
20
+ )
21
+ .then(responds => {
13
22
  responds.sort((a, b) => a.id - b.id)
14
23
  const addresses = []
15
24
  const failed_ids = []
@@ -22,6 +31,7 @@ const get_pairs_addresses = (key, factory, ids) => ids.length == 0
22
31
  ? addresses
23
32
  : get_pairs_addresses(key, factory, failed_ids).then(retried => [...addresses, ...retried])
24
33
  })
34
+ .catch(() => new Promise(resolve => setTimeout(() => resolve(get_pairs_addresses(key, factory, ids)), 1000)))
25
35
 
26
36
  const get_tokens = (key, addresses) => addresses.length == 0
27
37
  ? Promise.resolve({})
@@ -42,7 +52,15 @@ const get_tokens = (key, addresses) => addresses.length == 0
42
52
  params: [{ to: address, data: '0xd21220a7' }, 'latest']
43
53
  }
44
54
  ]))
45
- }).then(_ => _.json()).then(responds => {
55
+ }).then(
56
+ _ => {
57
+ if (_.ok) return _.json()
58
+ throw 'respond not ok'
59
+ },
60
+ _ => {
61
+ throw 'fetch failed'
62
+ }
63
+ ).then(responds => {
46
64
  responds.sort((a, b) => a.id - b.id)
47
65
  const tokens = {}
48
66
  const failed_addresses = []
@@ -64,6 +82,7 @@ const get_tokens = (key, addresses) => addresses.length == 0
64
82
  ? tokens
65
83
  : get_tokens(key, failed_addresses).then(retried => ({ ...tokens, ...retried }))
66
84
  })
85
+ .catch(() => new Promise(resolve => setTimeout(() => resolve(get_tokens(key, addresses)), 1000)))
67
86
 
68
87
  const main = ({ids, factory, key, multicall_size}, onpair) => {
69
88
  const chunks = []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uniswap-v2-loader",
3
- "version": "5.0.10",
3
+ "version": "5.0.11",
4
4
  "description": "Uniswap v2 protocol loader",
5
5
  "keywords": [
6
6
  "uniswap-v2",