-
Notifications
You must be signed in to change notification settings - Fork 1
/
getPools.go
53 lines (40 loc) · 872 Bytes
/
getPools.go
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
package main
import (
"bytes"
"encoding/json"
"net/http"
)
type Pool struct {
ID string `json:"id"`
}
type PoolResponse struct {
Pools []Pool `json:"pools"`
}
type Data struct {
Data PoolResponse `json:"data"`
}
type Pools struct {
Pools []string
}
func getUniswapV3Pools() (Pools, error) {
s := struct {
Query string `json:"query"`
}{"{pools(where:{txCount_gt:50000}){id}}"}
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(s)
resp, err := http.Post("https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3", "application/json", b)
if err != nil {
return Pools{}, err
}
defer resp.Body.Close()
tmp := Data{}
err = json.NewDecoder(resp.Body).Decode(&tmp)
if err != nil {
return Pools{}, err
}
rtnPools := Pools{}
for _, pool := range tmp.Data.Pools {
rtnPools.Pools = append(rtnPools.Pools, pool.ID)
}
return rtnPools, nil
}