forked from goosedefi/goose-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandler.js
More file actions
59 lines (53 loc) · 1.58 KB
/
handler.js
File metadata and controls
59 lines (53 loc) · 1.58 KB
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
var express = require("express");
var app = express();
const Web3 = require("web3");
const eggABI = require("./abi/eggToken.json");
const BigNumber = require("bignumber.js");
const { getTVL } = require("./getTVL.js")
const web3 = new Web3('https://bsc-dataseed.binance.org/');
const contract = new web3.eth.Contract(eggABI, '0x50d809c74e0b8e49e7b4c65bb3109abe3ff4c1c1');
app.get('/totalSupply', async (req, res) => {
try {
const totalSupply = await contract.methods.totalSupply().call();
const burnt = await contract.methods.balanceOf('0x000000000000000000000000000000000000dead').call();
const circ = new BigNumber(totalSupply).minus(new BigNumber(burnt));
res.json({
data: circ.shiftedBy(-18).toNumber().toString()
})
} catch (e) {
console.log(e)
res.json({
error: e
})
}
})
app.get('/circulatingSupply', async (req, res) => {
try {
const totalSupply = await contract.methods.totalSupply().call();
const burnt = await contract.methods.balanceOf('0x000000000000000000000000000000000000dead').call();
const circ = new BigNumber(totalSupply).minus(new BigNumber(burnt));
return success(circ.shiftedBy(-18).toNumber().toString());
res.json({
data: circ.shiftedBy(-18).toNumber().toString()
})
} catch (e) {
console.log(e)
res.json({
error: e
})
}
})
app.get('/tvl', async (req, res) => {
try {
const TVL = await getTVL()
res.json({
data: TVL.toString()
})
} catch (e) {
console.log(e)
res.json({
error: e
})
}
})
app.listen(8080)