-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSwap.js
59 lines (43 loc) · 1.26 KB
/
getSwap.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
const axios = require(`axios`)
const {writeData} = require('./helpers')
const URL =`https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3`
const outputFilePrefix = "swapData"
//Function to get swap info for a particular pool address
const swapData = async(poolAddress)=>{
let query = `{
swaps(first:10,orderBy: timestamp, orderDirection: desc, where:
{ pool: "${poolAddress}" }
) {
pool {
token0 {
id
symbol
}
token1 {
id
symbol
}
}
sender
recipient
amount0
amount1
}
}`
const res = await axios.post(URL,{
query:query
})
const swaps = res.data.data.swaps
const currentTime = Date.now()
const timeStamp = `Data loaded at : ${currentTime}\n`
const outFileName = outputFilePrefix + "-"+poolAddress+".txt"
await writeData(timeStamp,outFileName)
for(let obj of swaps){
await writeData(JSON.stringify(obj)+"\n",outFileName)
}
}
const runner = async() =>{
swapData(`0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8`)
await new Promise(r => setTimeout(r, 300000));
}
runner()