Skip to content

Commit

Permalink
Fix eligibility bug
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
0xJohnnyGault committed Dec 20, 2023
1 parent ad0bda5 commit 769bb30
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 369 deletions.
24 changes: 5 additions & 19 deletions public/_footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,11 @@
<footer class="py-4 py-md-5 mt-5 bg-light">
<div class="container py-4 py-md-5 px-4 px-md-3">
<div class="row">
<div class="col-lg-3 mb-3">
<a class="d-inline-flex align-items-center mb-2 link-dark text-decoration-none" href="/">
<img src="/img/gogo-balloon.svg" width="50px" />
<span class="fs-5">GoGoPool</span>
</a>
<ul class="list-unstyled small text-muted">
<li class="mb-2">
Designed and built with 💖 by the
<a href="https://www.gogopool.com">GoGoPool team</a>.
</li>
</ul>
</div>
<div class="col-lg-3 mb-3"></div>
<div class="col-6 col-lg-2 offset-lg-1 mb-3">
<h5>Links</h5>
<ul class="list-unstyled">
<li class="mb-2"><a href="https://www.gogopool.com">Home</a></li>
<li class="mb-2">
<a href="https://gogopool.medium.com/">Blog</a>
</li>
<li class="mb-2">
<a href="https://www.gogopool.com">Swag Store</a>
</li>
<li class="mb-2"><a href="/">Home</a></li>
</ul>
</div>
<div class="col-6 col-lg-2 mb-3">
Expand All @@ -32,6 +15,9 @@ <h5>Projects</h5>
<li class="mb-2">
<a href="https://www.gogopool.com">GoGoPool</a>
</li>
<li class="mb-2">
<a href="https://github.com/multisig-labs/Panopticon">Panopticon</a>
</li>
</ul>
</div>
<div class="col-6 col-lg-2 mb-3">
Expand Down
8 changes: 6 additions & 2 deletions public/deployments/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
{ "fn": "getRewardsCycleTotalAmt", "formatter": "formatEther" },
{ "fn": "getInflationIntervalStartTime", "formatter": "unixToISO" },
{ "fn": "getInflationIntervalsElapsed" },
{ "fn": "getInflationAmt", "formatter": "formatInflationAmt" },
{
"fn": "getInflationAmt",
"formatter": "formatInflationAmt",
"desc": "Amount of GGP to be issued in next reward cycle"
},
{
"fn": "getClaimingContractDistribution",
"args": ["ClaimNodeOp"],
Expand Down Expand Up @@ -128,7 +132,7 @@
"fn": "getStakerCount",
"title": "Staker Count",
"desc": "",
"formatter": "bigToNumber"
"formatter": "formatNumber"
}
]
},
Expand Down
11 changes: 11 additions & 0 deletions public/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ <h1 class="mb-1 fw-semibold">
</div>
<h3 class="d-inline-block text-center"><a href="/home">Minipools</a></h3>
<a href="?status=3,4,5,6" class="d-inline-block">(finished)</a>
<span id="downloadMinipools">📥</span>
<div id="minipools"><div class="loader">Loading...</div></div>
</div>

<div class="container w-95 text-center mb-4 pb-4 alert alert-warning">
⚠️ These numbers are all estimates based on the information in the smart contracts, and may not be accurate.
<br />
Not Financial Advice, Do Your Own Research, WAGMI.
</div>

<div class="container w-95 text-center border border-5 rounded mb-4 pb-4">
<h3 class="text-center">NodeOps <span id="downloadNodeOps">📥</span></h3>
<div id="stakers"><div class="loader">Loading...</div></div>
Expand Down Expand Up @@ -89,6 +96,10 @@ <h3 class="text-center">Contracts</h3>
.querySelector("#downloadNodeOps")
.addEventListener("click", () => tableStakers.download("csv", "GoGoPool_NodeOps.csv"));

document
.querySelector("#downloadMinipools")
.addEventListener("click", () => tableMinipools.download("csv", "GoGoPool_Minipools.csv"));

GGP.refreshDataLoop(() => {
tableDashboard.blockRedraw();
tableMinipools.blockRedraw();
Expand Down
1 change: 0 additions & 1 deletion public/js/ggavax.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ggAVAX {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"User-Agent": "panopticon.fly.dev",
},
}
).then((res) => res.json());
Expand Down
92 changes: 60 additions & 32 deletions public/js/gogopool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { utils as ethersUtils, providers, Contract, constants, BigNumber } from "https://esm.sh/[email protected]";
import { Contract as MCContract, Provider as MCProvider } from "https://esm.sh/[email protected]";
import { MINIPOOL_STATUS_MAP, formatters, stripNumberKeys, bigToNumber } from "/js/utils.js";
import { minipoolTransformer } from "/js/transformers.js";
import { MINIPOOL_STATUS_MAP, formatters, transformerFns, unfuckEthersObj } from "/js/utils.js";
import { minipoolsTransformer } from "/js/transformers.js";

// Hard-code reward cycle amounts
const REWARDS_TOTAL_NODEOP_POOL_AMT = {
Expand Down Expand Up @@ -252,8 +252,9 @@ class GoGoPool {

const promises = this.statusesToFetch.map((s) => this.contracts.MinipoolManager.contract.getMinipools(s, 0, 0));
const results = await Promise.all(promises);
this.minipoolsData = await minipoolTransformer(results.flat());
console.log("Minipools", this.minipoolsData);
this.minipoolsData = await minipoolsTransformer(results.flat());

// console.log("Minipools", this.minipoolsData);
return this.minipoolsData;
}

Expand All @@ -265,37 +266,50 @@ class GoGoPool {
await this.until((_) => this.isLoaded);

let allStakers = await this.contracts.Staking.contract.getStakers(0, 0);
// console.log("All Stakers", allStakers);
let eligibleStakers = allStakers
.filter((s) => s.rewardsStartTime.gt(0) && s.avaxValidatingHighWater.gt(0))
.map((s) => Object.assign({}, s)) // ethers gives us weird obj, make it a normal one
.map(stripNumberKeys); // ethers obj has redundant keys like "1": ..., "2": ... Get rid of them for God's sake

// For each ELIGIBLE staker we want to call a couple funcs, so mush them all together for speed into batches
const calls = [];
const fns = [
["Staking", "getMinimumGGPStake"],
["Staking", "getEffectiveRewardsRatio"],
["Staking", "getCollateralizationRatio"],
["Staking", "getEffectiveGGPStaked"],
["TokenGGP", "balanceOf"],
allStakers = allStakers.map(unfuckEthersObj);
console.log("allStakers", allStakers);

let eligibleStakers = allStakers.filter((s) => s.rewardsStartTime > 0 && s.avaxValidatingHighWater > 0);
// console.log("eligibleStakers (pre enrichment)", eligibleStakers);

// Define similiar structure as used in dashboard.js. Consolidate somehow, someday.
const ethAsFloat = (v) => parseFloat(ethersUtils.formatEther(v || 0));
const enrichments = [
{
contract: "Staking",
metrics: [
{ fn: "getMinimumGGPStake", formatter: ethAsFloat },
{ fn: "getEffectiveRewardsRatio", formatter: ethAsFloat },
{ fn: "getCollateralizationRatio", formatter: ethAsFloat },
{ fn: "getEffectiveGGPStaked", formatter: ethAsFloat },
],
},
{
contract: "TokenGGP",
metrics: [{ fn: "balanceOf", formatter: ethAsFloat }],
},
{
contract: "ClaimNodeOp",
metrics: [{ fn: "isEligible" }],
},
];

// For each ELIGIBLE staker we want to call a couple contract funcs, so mush them all together for speed into batches
const calls = [];
for (const s of eligibleStakers) {
for (const [contractName, method] of fns) {
try {
const c = this.contracts[contractName].mccontract;
// Un-label the addr argh
const addr = s.stakerAddrHex || s.stakerAddr;
calls.push(c[method].call(this, addr));
} catch (err) {
console.error("error calling fn", fn, err);
for (const enrichment of enrichments) {
const c = this.contracts[enrichment.contract].mccontract;
for (const metric of enrichment.metrics) {
try {
calls.push(c[metric.fn].call(this, s.stakerAddr));
} catch (err) {
console.log("error calling enrichment:", enrichment, err);
}
}
}
}

let results = [];

for (let batch of this.getBatch(calls)) {
try {
results = results.concat(await this.multicallProvider.tryAll(batch));
Expand All @@ -308,18 +322,32 @@ class GoGoPool {
}
}

console.log("results", results);

const metrics = enrichments.map((e) => e.metrics).flat();
console.log(metrics);

// Now add the results of the batch to each staker
const l = fns.length;
const idFn = (v) => v;
const l = metrics.length;
for (const [index, s] of eligibleStakers.entries()) {
fns.forEach((fnName, i) => {
s[fnName[1]] = results[index * l + i];
metrics.forEach((metric, i) => {
const rawValue = results[index * l + i];
s[metric.fn] = (metric.formatter || idFn).call(this, rawValue);
});
}

// Convert BigNums to numbers (taking into account AVAX/GGP which are in Wei)
eligibleStakers = eligibleStakers.map(bigToNumber);
console.log("eligibleStakers", eligibleStakers);

// So, I still want to show recently created minipool owners in the list, but since they are not yet eligible
// we will nerf their rewards to zero
eligibleStakers.forEach((s) => {
if (!s.isEligible) {
s.getEffectiveGGPStaked = 0;
s.getEffectiveRewardsRatio = 0;
}
});

// REWARDS CALCULATIONS
// Should probably extract this to a generic JS class for reuse

Expand Down
3 changes: 3 additions & 0 deletions public/js/pandasia.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { providers, Contract } from "https://esm.sh/[email protected]";
import { unfuckEthersObj } from "/js/utils.js";

class Pandasia {
trees;
Expand Down Expand Up @@ -87,6 +88,8 @@ class Pandasia {
});
// wait for all the addresses to resolve
pChainAddresses = await Promise.all(pChainAddresses);
// TODO convert the hex bytes into bech32 addr "P-avax1blahblah..."

// zip them together
const users = addresses.map((address, i) => {
return {
Expand Down
Loading

0 comments on commit 769bb30

Please sign in to comment.