Skip to content

Commit

Permalink
Hack in nextRewardsAmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJohnnyGault committed Feb 13, 2024
1 parent 81cff6f commit 36418a1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
24 changes: 23 additions & 1 deletion public/ggavax.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ <h3 class="text-center">ggAVAX Delegations</h3>
<div class="container w-95 border border-5 rounded pb-3">
<h3 class="text-center">ggAVAX Stats</h3>
<div id="ggavax-stats" class="text-center"><div class="loader">Loading...</div></div>
<div>WAVAX Balance: <span id="wavax-balance"></span></div>
<div>Next Rewards Amt: <span id="next-rewards-amt"></span></div>
</div>

<style>
Expand All @@ -30,17 +32,21 @@ <h3 class="text-center">ggAVAX Stats</h3>
</style>

<script type="module">
import { utils as ethersUtils, BigNumber } from "https://esm.sh/[email protected]";
import { DEPLOYMENT } from "/deployments/selected.js";
import { GoGoPool } from "/js/gogopool.js";
import { ggAVAX } from "/js/ggavax.js";
import { ggAVAXDef, ggAVAXStatsDef } from "/js/tabulator.js";
import { formatters } from "/js/utils.js";

let GGAVAX, GGP;

async function initData() {
GGP = new GoGoPool(DEPLOYMENT);
GGAVAX = new ggAVAX(DEPLOYMENT);
await GGP.fetchContracts();
await Promise.all([GGP.fetchDashboardData(), GGAVAX.fetchCurrentDelegations()]);
await Promise.all([GGP.fetchDashboardData(), GGAVAX.fetchCurrentDelegations(), GGAVAX.fetchWavaxBalance()]);
console.log(GGP.dashboard);
}

await initData();
Expand All @@ -49,6 +55,10 @@ <h3 class="text-center">ggAVAX Stats</h3>

GGAVAX.refreshDataLoop(() => {
tableCurrentDelegations.updateOrAddData(GGAVAX.currentDelegations);
const wavaxEl = document.getElementById("wavax-balance");
wavaxEl.innerHTML = formatters.formatEther(GGAVAX.wavaxBalance);
const nextRewardsAmtEl = document.getElementById("next-rewards-amt");
nextRewardsAmtEl.innerHTML = formatters.formatEther(calcNextRewardAmt());
});

const tableStats = new Tabulator("#ggavax-stats", ggAVAXStatsDef);
Expand All @@ -57,6 +67,18 @@ <h3 class="text-center">ggAVAX Stats</h3>
// Reusing the GGP data, but just grabbing what we want for this page
const data = GGP.dashboardAsTabulatorData().filter((obj) => obj.contract === "TokenggAVAX");
tableStats.updateOrAddData(data);
const x = calcNextRewardAmt();
console.log(x);
});

// Ugh lame figure out better way
function calcNextRewardAmt() {
// uint256 nextRewardsAmt = (asset.balanceOf(address(this)) + stakingTotalAssets_) - totalReleasedAssets_ - lastRewardsAmt_;
const stakingTotalAssets = GGP.dashboardValue("TokenggAVAX", "stakingTotalAssets");
const totalReleasedAssets = GGP.dashboardValue("TokenggAVAX", "totalReleasedAssets");
const lastRewardsAmt = GGP.dashboardValue("TokenggAVAX", "lastRewardsAmt");

return BigNumber.from(GGAVAX.wavaxBalance).add(stakingTotalAssets).sub(totalReleasedAssets).sub(lastRewardsAmt);
}
</script>
{{end}}
16 changes: 16 additions & 0 deletions public/js/ggavax.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ggAVAX {
currentDelegations;
wavaxBalance;

constructor() {}

Expand All @@ -18,9 +19,24 @@ class ggAVAX {
return this.currentDelegations;
}

async fetchWavaxBalance() {
const response = await fetch(
`https://glacier-api.avax.network/v1/chains/43114/addresses/0xA25EaF2906FA1a3a13EdAc9B9657108Af7B703e3/balances:listErc20?pageSize=10&contractAddresses=0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7&currency=usd`,
{
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
}
).then((res) => res.json());
this.wavaxBalance = response.erc20TokenBalances[0].balance;
return this.wavaxBalance;
}

refreshDataLoop(fn) {
const poll = async () => {
await this.fetchCurrentDelegations();
await this.fetchWavaxBalance();
fn();
setTimeout(poll, 30000);
};
Expand Down
4 changes: 4 additions & 0 deletions public/js/gogopool.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ class GoGoPool {
return cycle.value.toNumber();
}

dashboardValue(contract, metric) {
return this.dashboard.find((obj) => obj.contract === contract).metrics.find((obj) => obj.fn === metric).rawValue;
}

// Reformat data shape to fit Tabulator table
dashboardAsTabulatorData() {
this.dashboardData = [];
Expand Down

0 comments on commit 36418a1

Please sign in to comment.