forked from mentasuave01/Spookyswap-xBOO-pools-APR-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenPriceData.js
56 lines (43 loc) · 1.65 KB
/
tokenPriceData.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
//Create Fura Headers
import { furaHeaders } from "./furaHeaders.js";
///////////////////////////////////
//Create Fura Body
export async function fetchTokenPrice_FTM(tokenID) {
const id = (id) => JSON.stringify({
"operationName": "tokens",
"query": `fragment TokenFields on Token {\n id\n name\n symbol\n derivedETH\n }\n\n query tokens {\n tokens(where: {id: \"${id}\" }) {\n ...TokenFields\n }\n}\n`
});
const raw = id(tokenID)
var requestOptions = {
method: 'POST',
headers: furaHeaders,
body: raw,
redirect: 'follow'
};
const tokenCall = await fetch("https://api.fura.org/subgraphs/name/spookyswap", requestOptions)
.then(response => response.text())
.then(res => {
//console.log(res)
return JSON.parse(res);
})
.catch(error => console.log('error', error));
///////////////////////////////////////////////////////////
return tokenCall;
}
export async function fetchFTM_PriceUSD() {
const raw = JSON.stringify({ "operationName": "bundles", "variables": {}, "query": "query bundles {\n bundles(where: {id: 1}) {\n id\n ethPrice\n __typename\n }\n}\n" });
const requestOptions = {
method: 'POST',
headers: furaHeaders,
body: raw,
redirect: 'follow'
};
const tokenCall = await fetch("https://api.fura.org/subgraphs/name/spookyswap", requestOptions)
.then(response => response.text())
.then(res => {
//console.log(res)
return JSON.parse(res);
})
.catch(error => console.log('error', error));
return tokenCall;
}