-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateReadme.js
77 lines (69 loc) · 2.48 KB
/
updateReadme.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require('fs')
const axios = require('axios')
const { render } = require('mustache')
const template = require('./template')
const formatter = require('./formatter')
const { addTokenDayData } = require('./helper')
const API = 'https://api.thegraph.com/subgraphs/name/gafranslotteria/position-token'
const updateReadme = async () => {
try {
const res = await axios.post(API, {
query: `
{
positionToken(id: "1") {
maxSupply
totalMinted
totalBurned
totalHolders
totalTransactions
prices {
priceInBUSD
totalVolumeInBUSD
}
updatedTimestamp
}
positionTokenDayDatas(first: 8, orderBy: "createdBlockNumber", orderDirection: "desc") {
id
priceInBUSD
dailyVolumeInBUSD
}
}
`
}, {
headers: {
'Content-Type': 'application/json'
}
})
const positionToken = res.data.data?.positionToken
const positionTokenDayDatas = res.data.data?.positionTokenDayDatas
const dayDatas = formatter.formatTokenDayDatas(positionTokenDayDatas)
let data = {
price: formatter.formatPrice(positionToken?.prices.priceInBUSD),
marketCap: formatter.formatVolume(positionToken?.prices.priceInBUSD * (positionToken?.totalMinted - positionToken?.totalBurned)),
max_supply: formatter.formatNumber(positionToken?.maxSupply),
total_supply: formatter.formatNumber(positionToken?.totalMinted),
circulating_supply: formatter.formatNumber(positionToken?.totalMinted - positionToken?.totalBurned),
total_burn: formatter.formatNumber(positionToken?.totalBurned),
total_holders: Number(positionToken?.totalHolders).toLocaleString(),
total_transactions: Number(positionToken?.totalTransactions).toLocaleString(),
volume_24h: formatter.formatVolume(positionToken?.prices.totalVolumeInBUSD),
updated_at: formatter.formatTimestamp(positionToken?.updatedTimestamp),
}
data = addTokenDayData(data, dayDatas)
const output = render(template, data)
fs.readFile('./profile/README.md', 'utf-8', (err) => {
if (err) {
throw err
}
fs.writeFile('./profile/README.md', output, 'utf-8', (err) => {
if (err) {
throw err
}
})
console.log(`README was updated at: ${formatter.formatTimestamp(Date.now())}`)
})
} catch (err) {
throw err
}
}
updateReadme()