-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.js
63 lines (59 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const AirSwap = require('./exchanges/AirSwap.js')
const BambooRelay = require('./exchanges/BambooRelay.js')
const Bancor = require('./exchanges/Bancor.js')
const DDEX = require('./exchanges/DDEX.js')
const Eth2Dai = require('./exchanges/Eth2Dai.js')
const Ethfinex = require('./exchanges/Ethfinex.js')
const Forkdelta = require('./exchanges/Forkdelta.js')
const IDEX = require('./exchanges/IDEX.js')
const Kyber = require('./exchanges/Kyber.js')
const RadarRelay = require('./exchanges/RadarRelay.js')
const SaturnNetwork = require('./exchanges/Saturn.js')
const Uniswap = require('./exchanges/Uniswap.js')
const Switcheo = require('./exchanges/Switcheo.js')
const { sortBids, sortAsks } = require('./helpers')
const { DDEX_TAKER_FEE } = require('./constants')
// given a token symbol and amount, return offers from all dexes
// sorted descending by best price
module.exports = {
main(symbol, amount, direction, decimals) {
if (direction !== 'BUY' && direction !== 'SELL') {
throw new Error(`must specify BUY or SELL. you specified "${direction}"`)
}
const dexes = [
new AirSwap(),
new Bancor(decimals),
new BambooRelay(),
new DDEX(),
new Eth2Dai(),
new Ethfinex(),
new Forkdelta(),
new IDEX(),
new Kyber(),
new RadarRelay(),
new SaturnNetwork('eth'),
new Uniswap(),
new Switcheo(),
]
const promises = dexes.map(dex =>
dex.computePrice(symbol, amount, direction === 'SELL', dex.name === 'DDEX' ? DDEX_TAKER_FEE : 0),
)
return Promise.all(promises).then(results => {
const sortedResults = direction === 'BUY' ? results.sort(sortAsks) : results.sort(sortBids)
return sortedResults
})
},
AirSwap,
BambooRelay,
Bancor,
DDEX,
Eth2Dai,
Ethfinex,
Forkdelta,
IDEX,
Kyber,
RadarRelay,
SaturnNetwork,
Uniswap,
Switcheo,
}