-
Notifications
You must be signed in to change notification settings - Fork 0
/
dino.js
45 lines (40 loc) · 1.36 KB
/
dino.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
const fs = require('fs')
const fetch = async (browser) => {
const page = await browser.newPage()
await page.goto('https://dinoswap.exchange/jurassicpools')
const result = await new Promise((resolve, reject) => {
page.on('console', async (msg) => {
try {
const [a1, a2] = msg.args()
const name = await a1.jsonValue()
const pools = await a2.jsonValue()
if (
name === 'POOLS' &&
pools.find((p) => p.sousId === 1 && p.contractAddress['137'] === '0x52e7b0C6fB33D3d404b07006b006c8A8D6049C55')
) {
resolve(pools)
}
} catch (err) {}
})
setTimeout(() => {
reject('timeout')
}, 10000)
})
await page.close()
if (result.length > 1) return result
return null
}
module.exports = async (browser) => {
const newPools = await fetch(browser)
if (!newPools) return
let currentPools = []
try {
currentPools = JSON.parse(fs.readFileSync('./pools-dino.json').toString())
} catch (e) {}
const newContractAddressList = newPools.map((p) => p.contractAddress['137']).filter(Boolean)
for (const pool of currentPools.filter((p) => p.contractAddress['137'])) {
if (newContractAddressList.includes(pool.contractAddress['137'])) continue
newPools.push({ ...pool, isFinished: true })
}
fs.writeFileSync('./pools-dino.json', JSON.stringify(newPools, null, 2))
}