@icgio/icg-utils 1.7.65 → 1.7.67

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.
@@ -12,7 +12,7 @@ const sort_keys = require('./utils.js').sort_keys
12
12
 
13
13
  const Limiter = require('./rate-limiter.js')
14
14
 
15
- const dex_rate = require('./dex-rate/dex-rate.js')
15
+ const dex_rate = require('./dex-rate.js')
16
16
 
17
17
  let limiter = new Limiter({
18
18
  max_concurrent: 1,
@@ -208,6 +208,32 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
208
208
  console.error(error)
209
209
  }
210
210
  })
211
+ } else if (exchange === 'bitmart') {
212
+ let pair = cur + '_USDT'
213
+ let url = `https://api-cloud.bitmart.com/spot/v1/symbols/book?symbol=${pair}`
214
+ limiter.process(needle.get, url, (err, res, body) => {
215
+ try {
216
+ const asks = body.data.sells
217
+ const bids = body.data.buys
218
+ let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
219
+ result[cur] = {
220
+ USD: rate,
221
+ USDT: rate,
222
+ }
223
+ let result_length = _.keys(result).length
224
+ if (result_length === length) {
225
+ for (let stable of stablecoins) {
226
+ result[stable] = {
227
+ USD: 1,
228
+ USDT: 1,
229
+ }
230
+ }
231
+ cb(result)
232
+ }
233
+ } catch (error) {
234
+ console.error(error)
235
+ }
236
+ })
211
237
  } else if (exchange === 'gate') {
212
238
  let pair = cur + '_USDT'
213
239
  let url = `https://api.gateio.ws/api/v4/spot/order_book?currency_pair=${pair}`
@@ -287,11 +313,10 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
287
313
  }
288
314
  })
289
315
  } else if (exchange === 'pancakeswap') {
290
- let pair = cur + 'USDT'
291
- dex_rate(pair).then((res) => {
316
+ dex_rate(cur, (res) => {
292
317
  result[cur] = {
293
- USD: res[pair],
294
- USDT: res[pair],
318
+ USD: res[cur],
319
+ USDT: res[cur],
295
320
  }
296
321
  let result_length = _.keys(result).length
297
322
  if (result_length === length) {
@@ -372,8 +397,10 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
372
397
  // console.log(res)
373
398
  // },
374
399
  // {
400
+ // AICB: 'bitmart',
375
401
  // ENIX: 'mexc',
376
402
  // FREN: 'pancakeswap',
403
+ // RWX: 'pancakeswap',
377
404
  // DMC: 'gate',
378
405
  // XERT: 'xt',
379
406
  // DFI: 'coinstore',
@@ -0,0 +1,33 @@
1
+ const _ = require('lodash')
2
+
3
+ const needle = require('needle')
4
+
5
+ const token_dict = {
6
+ FREN: {
7
+ address: '0xe6a768464b042a6d029394db1fdef360cb60bbeb',
8
+ network: 'bsc',
9
+ },
10
+ RWX: {
11
+ address: '0xb0a1c87b890fe171371f81a59f7ed4636e82595d',
12
+ network: 'bsc',
13
+ },
14
+ USDT: {
15
+ address: '0x55d398326f99059fF775485246999027B3197955',
16
+ network: 'bsc',
17
+ },
18
+ }
19
+
20
+ let dex_rate = function (cur, cb) {
21
+ const { address, network } = token_dict[cur]
22
+ const url = `https://api.geckoterminal.com/api/v2/simple/networks/${network}/token_price/${address}`
23
+ needle.get(url, (res, error, body) => {
24
+ if (body && body.data && body.data.id) {
25
+ let rate = parseFloat(body.data.attributes.token_prices[address])
26
+ cb({
27
+ [cur]: rate,
28
+ })
29
+ }
30
+ })
31
+ }
32
+
33
+ module.exports = dex_rate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.7.65",
3
+ "version": "1.7.67",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -30,7 +30,6 @@
30
30
  "needle": "^3.2.0",
31
31
  "nodemailer": "^4.7.0",
32
32
  "qrcode-terminal": "^0.12.0",
33
- "web3": "^1.10.0",
34
33
  "websocket": "^1.0.33",
35
34
  "winston": "^2.4.5",
36
35
  "ws": "^8.13.0"
@@ -1,26 +0,0 @@
1
- const _ = require('lodash')
2
-
3
- const Web3 = require('web3')
4
- const toBN = Web3.utils.toBN
5
- const web3_bsc = new Web3('https://bsc-dataseed.binance.org/')
6
-
7
- const router_abi = require('./router-abi.js')
8
-
9
- const router_contract = new web3_bsc.eth.Contract(router_abi, '0x10ED43C718714eb63d5aA57B78B54704E256024E')
10
- const USDT_address = '0x55d398326f99059fF775485246999027B3197955'
11
- const FREN_address = '0xe6a768464b042a6d029394db1fdef360cb60bbeb'
12
- const WBNB_address = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
13
-
14
- const routes_dict = {
15
- FRENUSDT: [FREN_address, WBNB_address, USDT_address],
16
- }
17
-
18
- let dex_rate = async function (pair) {
19
- let route = routes_dict[pair]
20
- let rate = _.last(await router_contract.methods.getAmountsOut(toBN(1e18), route).call()) / 1e18
21
- return {
22
- [pair]: rate,
23
- }
24
- }
25
-
26
- module.exports = dex_rate
@@ -1,328 +0,0 @@
1
- module.exports = [
2
- {
3
- inputs: [
4
- { internalType: 'address', name: '_factory', type: 'address' },
5
- { internalType: 'address', name: '_WETH', type: 'address' },
6
- ],
7
- stateMutability: 'nonpayable',
8
- type: 'constructor',
9
- },
10
- { inputs: [], name: 'WETH', outputs: [{ internalType: 'address', name: '', type: 'address' }], stateMutability: 'view', type: 'function' },
11
- {
12
- inputs: [
13
- { internalType: 'address', name: 'tokenA', type: 'address' },
14
- { internalType: 'address', name: 'tokenB', type: 'address' },
15
- { internalType: 'uint256', name: 'amountADesired', type: 'uint256' },
16
- { internalType: 'uint256', name: 'amountBDesired', type: 'uint256' },
17
- { internalType: 'uint256', name: 'amountAMin', type: 'uint256' },
18
- { internalType: 'uint256', name: 'amountBMin', type: 'uint256' },
19
- { internalType: 'address', name: 'to', type: 'address' },
20
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
21
- ],
22
- name: 'addLiquidity',
23
- outputs: [
24
- { internalType: 'uint256', name: 'amountA', type: 'uint256' },
25
- { internalType: 'uint256', name: 'amountB', type: 'uint256' },
26
- { internalType: 'uint256', name: 'liquidity', type: 'uint256' },
27
- ],
28
- stateMutability: 'nonpayable',
29
- type: 'function',
30
- },
31
- {
32
- inputs: [
33
- { internalType: 'address', name: 'token', type: 'address' },
34
- { internalType: 'uint256', name: 'amountTokenDesired', type: 'uint256' },
35
- { internalType: 'uint256', name: 'amountTokenMin', type: 'uint256' },
36
- { internalType: 'uint256', name: 'amountETHMin', type: 'uint256' },
37
- { internalType: 'address', name: 'to', type: 'address' },
38
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
39
- ],
40
- name: 'addLiquidityETH',
41
- outputs: [
42
- { internalType: 'uint256', name: 'amountToken', type: 'uint256' },
43
- { internalType: 'uint256', name: 'amountETH', type: 'uint256' },
44
- { internalType: 'uint256', name: 'liquidity', type: 'uint256' },
45
- ],
46
- stateMutability: 'payable',
47
- type: 'function',
48
- },
49
- { inputs: [], name: 'factory', outputs: [{ internalType: 'address', name: '', type: 'address' }], stateMutability: 'view', type: 'function' },
50
- {
51
- inputs: [
52
- { internalType: 'uint256', name: 'amountOut', type: 'uint256' },
53
- { internalType: 'uint256', name: 'reserveIn', type: 'uint256' },
54
- { internalType: 'uint256', name: 'reserveOut', type: 'uint256' },
55
- ],
56
- name: 'getAmountIn',
57
- outputs: [{ internalType: 'uint256', name: 'amountIn', type: 'uint256' }],
58
- stateMutability: 'pure',
59
- type: 'function',
60
- },
61
- {
62
- inputs: [
63
- { internalType: 'uint256', name: 'amountIn', type: 'uint256' },
64
- { internalType: 'uint256', name: 'reserveIn', type: 'uint256' },
65
- { internalType: 'uint256', name: 'reserveOut', type: 'uint256' },
66
- ],
67
- name: 'getAmountOut',
68
- outputs: [{ internalType: 'uint256', name: 'amountOut', type: 'uint256' }],
69
- stateMutability: 'pure',
70
- type: 'function',
71
- },
72
- {
73
- inputs: [
74
- { internalType: 'uint256', name: 'amountOut', type: 'uint256' },
75
- { internalType: 'address[]', name: 'path', type: 'address[]' },
76
- ],
77
- name: 'getAmountsIn',
78
- outputs: [{ internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }],
79
- stateMutability: 'view',
80
- type: 'function',
81
- },
82
- {
83
- inputs: [
84
- { internalType: 'uint256', name: 'amountIn', type: 'uint256' },
85
- { internalType: 'address[]', name: 'path', type: 'address[]' },
86
- ],
87
- name: 'getAmountsOut',
88
- outputs: [{ internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }],
89
- stateMutability: 'view',
90
- type: 'function',
91
- },
92
- {
93
- inputs: [
94
- { internalType: 'uint256', name: 'amountA', type: 'uint256' },
95
- { internalType: 'uint256', name: 'reserveA', type: 'uint256' },
96
- { internalType: 'uint256', name: 'reserveB', type: 'uint256' },
97
- ],
98
- name: 'quote',
99
- outputs: [{ internalType: 'uint256', name: 'amountB', type: 'uint256' }],
100
- stateMutability: 'pure',
101
- type: 'function',
102
- },
103
- {
104
- inputs: [
105
- { internalType: 'address', name: 'tokenA', type: 'address' },
106
- { internalType: 'address', name: 'tokenB', type: 'address' },
107
- { internalType: 'uint256', name: 'liquidity', type: 'uint256' },
108
- { internalType: 'uint256', name: 'amountAMin', type: 'uint256' },
109
- { internalType: 'uint256', name: 'amountBMin', type: 'uint256' },
110
- { internalType: 'address', name: 'to', type: 'address' },
111
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
112
- ],
113
- name: 'removeLiquidity',
114
- outputs: [
115
- { internalType: 'uint256', name: 'amountA', type: 'uint256' },
116
- { internalType: 'uint256', name: 'amountB', type: 'uint256' },
117
- ],
118
- stateMutability: 'nonpayable',
119
- type: 'function',
120
- },
121
- {
122
- inputs: [
123
- { internalType: 'address', name: 'token', type: 'address' },
124
- { internalType: 'uint256', name: 'liquidity', type: 'uint256' },
125
- { internalType: 'uint256', name: 'amountTokenMin', type: 'uint256' },
126
- { internalType: 'uint256', name: 'amountETHMin', type: 'uint256' },
127
- { internalType: 'address', name: 'to', type: 'address' },
128
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
129
- ],
130
- name: 'removeLiquidityETH',
131
- outputs: [
132
- { internalType: 'uint256', name: 'amountToken', type: 'uint256' },
133
- { internalType: 'uint256', name: 'amountETH', type: 'uint256' },
134
- ],
135
- stateMutability: 'nonpayable',
136
- type: 'function',
137
- },
138
- {
139
- inputs: [
140
- { internalType: 'address', name: 'token', type: 'address' },
141
- { internalType: 'uint256', name: 'liquidity', type: 'uint256' },
142
- { internalType: 'uint256', name: 'amountTokenMin', type: 'uint256' },
143
- { internalType: 'uint256', name: 'amountETHMin', type: 'uint256' },
144
- { internalType: 'address', name: 'to', type: 'address' },
145
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
146
- ],
147
- name: 'removeLiquidityETHSupportingFeeOnTransferTokens',
148
- outputs: [{ internalType: 'uint256', name: 'amountETH', type: 'uint256' }],
149
- stateMutability: 'nonpayable',
150
- type: 'function',
151
- },
152
- {
153
- inputs: [
154
- { internalType: 'address', name: 'token', type: 'address' },
155
- { internalType: 'uint256', name: 'liquidity', type: 'uint256' },
156
- { internalType: 'uint256', name: 'amountTokenMin', type: 'uint256' },
157
- { internalType: 'uint256', name: 'amountETHMin', type: 'uint256' },
158
- { internalType: 'address', name: 'to', type: 'address' },
159
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
160
- { internalType: 'bool', name: 'approveMax', type: 'bool' },
161
- { internalType: 'uint8', name: 'v', type: 'uint8' },
162
- { internalType: 'bytes32', name: 'r', type: 'bytes32' },
163
- { internalType: 'bytes32', name: 's', type: 'bytes32' },
164
- ],
165
- name: 'removeLiquidityETHWithPermit',
166
- outputs: [
167
- { internalType: 'uint256', name: 'amountToken', type: 'uint256' },
168
- { internalType: 'uint256', name: 'amountETH', type: 'uint256' },
169
- ],
170
- stateMutability: 'nonpayable',
171
- type: 'function',
172
- },
173
- {
174
- inputs: [
175
- { internalType: 'address', name: 'token', type: 'address' },
176
- { internalType: 'uint256', name: 'liquidity', type: 'uint256' },
177
- { internalType: 'uint256', name: 'amountTokenMin', type: 'uint256' },
178
- { internalType: 'uint256', name: 'amountETHMin', type: 'uint256' },
179
- { internalType: 'address', name: 'to', type: 'address' },
180
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
181
- { internalType: 'bool', name: 'approveMax', type: 'bool' },
182
- { internalType: 'uint8', name: 'v', type: 'uint8' },
183
- { internalType: 'bytes32', name: 'r', type: 'bytes32' },
184
- { internalType: 'bytes32', name: 's', type: 'bytes32' },
185
- ],
186
- name: 'removeLiquidityETHWithPermitSupportingFeeOnTransferTokens',
187
- outputs: [{ internalType: 'uint256', name: 'amountETH', type: 'uint256' }],
188
- stateMutability: 'nonpayable',
189
- type: 'function',
190
- },
191
- {
192
- inputs: [
193
- { internalType: 'address', name: 'tokenA', type: 'address' },
194
- { internalType: 'address', name: 'tokenB', type: 'address' },
195
- { internalType: 'uint256', name: 'liquidity', type: 'uint256' },
196
- { internalType: 'uint256', name: 'amountAMin', type: 'uint256' },
197
- { internalType: 'uint256', name: 'amountBMin', type: 'uint256' },
198
- { internalType: 'address', name: 'to', type: 'address' },
199
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
200
- { internalType: 'bool', name: 'approveMax', type: 'bool' },
201
- { internalType: 'uint8', name: 'v', type: 'uint8' },
202
- { internalType: 'bytes32', name: 'r', type: 'bytes32' },
203
- { internalType: 'bytes32', name: 's', type: 'bytes32' },
204
- ],
205
- name: 'removeLiquidityWithPermit',
206
- outputs: [
207
- { internalType: 'uint256', name: 'amountA', type: 'uint256' },
208
- { internalType: 'uint256', name: 'amountB', type: 'uint256' },
209
- ],
210
- stateMutability: 'nonpayable',
211
- type: 'function',
212
- },
213
- {
214
- inputs: [
215
- { internalType: 'uint256', name: 'amountOut', type: 'uint256' },
216
- { internalType: 'address[]', name: 'path', type: 'address[]' },
217
- { internalType: 'address', name: 'to', type: 'address' },
218
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
219
- ],
220
- name: 'swapETHForExactTokens',
221
- outputs: [{ internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }],
222
- stateMutability: 'payable',
223
- type: 'function',
224
- },
225
- {
226
- inputs: [
227
- { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' },
228
- { internalType: 'address[]', name: 'path', type: 'address[]' },
229
- { internalType: 'address', name: 'to', type: 'address' },
230
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
231
- ],
232
- name: 'swapExactETHForTokens',
233
- outputs: [{ internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }],
234
- stateMutability: 'payable',
235
- type: 'function',
236
- },
237
- {
238
- inputs: [
239
- { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' },
240
- { internalType: 'address[]', name: 'path', type: 'address[]' },
241
- { internalType: 'address', name: 'to', type: 'address' },
242
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
243
- ],
244
- name: 'swapExactETHForTokensSupportingFeeOnTransferTokens',
245
- outputs: [],
246
- stateMutability: 'payable',
247
- type: 'function',
248
- },
249
- {
250
- inputs: [
251
- { internalType: 'uint256', name: 'amountIn', type: 'uint256' },
252
- { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' },
253
- { internalType: 'address[]', name: 'path', type: 'address[]' },
254
- { internalType: 'address', name: 'to', type: 'address' },
255
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
256
- ],
257
- name: 'swapExactTokensForETH',
258
- outputs: [{ internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }],
259
- stateMutability: 'nonpayable',
260
- type: 'function',
261
- },
262
- {
263
- inputs: [
264
- { internalType: 'uint256', name: 'amountIn', type: 'uint256' },
265
- { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' },
266
- { internalType: 'address[]', name: 'path', type: 'address[]' },
267
- { internalType: 'address', name: 'to', type: 'address' },
268
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
269
- ],
270
- name: 'swapExactTokensForETHSupportingFeeOnTransferTokens',
271
- outputs: [],
272
- stateMutability: 'nonpayable',
273
- type: 'function',
274
- },
275
- {
276
- inputs: [
277
- { internalType: 'uint256', name: 'amountIn', type: 'uint256' },
278
- { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' },
279
- { internalType: 'address[]', name: 'path', type: 'address[]' },
280
- { internalType: 'address', name: 'to', type: 'address' },
281
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
282
- ],
283
- name: 'swapExactTokensForTokens',
284
- outputs: [{ internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }],
285
- stateMutability: 'nonpayable',
286
- type: 'function',
287
- },
288
- {
289
- inputs: [
290
- { internalType: 'uint256', name: 'amountIn', type: 'uint256' },
291
- { internalType: 'uint256', name: 'amountOutMin', type: 'uint256' },
292
- { internalType: 'address[]', name: 'path', type: 'address[]' },
293
- { internalType: 'address', name: 'to', type: 'address' },
294
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
295
- ],
296
- name: 'swapExactTokensForTokensSupportingFeeOnTransferTokens',
297
- outputs: [],
298
- stateMutability: 'nonpayable',
299
- type: 'function',
300
- },
301
- {
302
- inputs: [
303
- { internalType: 'uint256', name: 'amountOut', type: 'uint256' },
304
- { internalType: 'uint256', name: 'amountInMax', type: 'uint256' },
305
- { internalType: 'address[]', name: 'path', type: 'address[]' },
306
- { internalType: 'address', name: 'to', type: 'address' },
307
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
308
- ],
309
- name: 'swapTokensForExactETH',
310
- outputs: [{ internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }],
311
- stateMutability: 'nonpayable',
312
- type: 'function',
313
- },
314
- {
315
- inputs: [
316
- { internalType: 'uint256', name: 'amountOut', type: 'uint256' },
317
- { internalType: 'uint256', name: 'amountInMax', type: 'uint256' },
318
- { internalType: 'address[]', name: 'path', type: 'address[]' },
319
- { internalType: 'address', name: 'to', type: 'address' },
320
- { internalType: 'uint256', name: 'deadline', type: 'uint256' },
321
- ],
322
- name: 'swapTokensForExactTokens',
323
- outputs: [{ internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' }],
324
- stateMutability: 'nonpayable',
325
- type: 'function',
326
- },
327
- { stateMutability: 'payable', type: 'receive' },
328
- ]