Skip to content

Instantly share code, notes, and snippets.

@togosh
Last active September 12, 2021 02:22
Show Gist options
  • Save togosh/39819905093205e19c698b4f02f0a8b3 to your computer and use it in GitHub Desktop.
Save togosh/39819905093205e19c698b4f02f0a8b3 to your computer and use it in GitHub Desktop.
Payout Per Tshare of HEX
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
test();
async function test(){
var {dailyPayoutHEX, totalTshares } = await get_dailyDataUpdate(622);
var payoutPerTshareHEX = (dailyPayoutHEX / totalTshares);
console.log("HEX Payout Per Tshare: " + payoutPerTshareHEX);
}
async function get_dailyDataUpdate(currentDay){
console.log("get_dailyDataUpdate");
return await fetch('https://api.thegraph.com/subgraphs/name/codeakk/hex', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: `
query {
dailyDataUpdates(
first: 1,
orderDirection: desc,
orderBy: timestamp,
where: {
endDay: ` + currentDay + `,
}
) {
id
payout
shares
payoutPerTShare
endDay
}
}`
}),
})
.then(res => res.json())
.then(res => {
if (Object.keys(res.data.dailyDataUpdates).length <= 0){
console.log("get_dailyDataUpdate - Data Missing - Day #: " + currentDay);
return {
success: false
};
}
var payout = res.data.dailyDataUpdates[0].payout;
payout = payout.substring(0, payout.length - 8) + "." + payout.substring(payout.length - 8);
var totalTshares = res.data.dailyDataUpdates[0].shares;
if (totalTshares == 0) {
totalTshares = "0";
} else {
totalTshares = totalTshares.substring(0, totalTshares.length - 12) + "." + totalTshares.substring(totalTshares.length - 12);
}
return {
dailyPayoutHEX: parseFloat(payout),
totalTshares: parseFloat(totalTshares),
success: true
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment