Skip to content

Commit

Permalink
mev
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJohnnyGault committed Mar 1, 2024
1 parent af70046 commit 83f53e1
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 20 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ require (
github.com/stretchr/testify v1.7.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
)

replace github.com/multisig-labs/panopticon/pkg => ./pkg
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20220708220712-1185a9018129 h1:vucSRfWwTsoXro7P+3Cjlr6flUMtzCwzlvkxEQtHHB0=
golang.org/x/net v0.0.0-20220708220712-1185a9018129/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
24 changes: 21 additions & 3 deletions public/ggavax.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ <h3 class="text-center">ggAVAX Delegations</h3>
<div id="ggavax" class="text-center"><div class="loader">Loading...</div></div>
</div>
<br />
<div class="container w-95 border border-5 rounded pb-3">
<h3 class="text-center">ggAVAX MEV</h3>
<div id="mev" class="text-center"><div class="loader">Loading...</div></div>
</div>
<br />
<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>
Expand All @@ -36,7 +41,7 @@ <h3 class="text-center">ggAVAX Stats</h3>
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 { ggAVAXDef, ggAVAXStatsDef, ggAVAXMEVDef } from "/js/tabulator.js";
import { formatters } from "/js/utils.js";

let GGAVAX, GGP;
Expand All @@ -45,15 +50,28 @@ <h3 class="text-center">ggAVAX Stats</h3>
GGP = new GoGoPool(DEPLOYMENT);
GGAVAX = new ggAVAX(DEPLOYMENT);
await GGP.fetchContracts();
await Promise.all([GGP.fetchDashboardData(), GGAVAX.fetchCurrentDelegations(), GGAVAX.fetchWavaxBalance()]);
await Promise.all([
GGP.fetchDashboardData(),
GGAVAX.fetchCurrentDelegations(),
GGAVAX.fetchCurrentMEV(),
GGAVAX.fetchWavaxBalance(),
]);
}

await initData();

const tableCurrentDelegations = new Tabulator("#ggavax", ggAVAXDef);
const tableCurrentMEV = new Tabulator("#mev", ggAVAXMEVDef);

GGAVAX.refreshDataLoop(() => {
tableCurrentDelegations.updateOrAddData(GGAVAX.currentDelegations);
if (GGAVAX.currentDelegations && GGAVAX.currentDelegations.length > 0) {
tableCurrentDelegations.updateOrAddData(GGAVAX.currentDelegations);
}

if (GGAVAX.currentMEV && GGAVAX.currentMEV.length > 0) {
tableCurrentMEV.updateOrAddData(GGAVAX.currentMEV);
}

const wavaxEl = document.getElementById("wavax-balance");
wavaxEl.innerHTML = formatters.formatEther(GGAVAX.wavaxBalance);
const nextRewardsAmtEl = document.getElementById("next-rewards-amt");
Expand Down
27 changes: 25 additions & 2 deletions public/js/ggavax.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
class ggAVAX {
currentDelegations;
currentMEV;
wavaxBalance;

constructor() {}

async fetchCurrentDelegations() {
const timestamp = Math.floor(Date.now() / 1000);
const startTimestamp = Math.floor(Date.now() / 1000) - 15 * 24 * 60 * 60;
const endTimestamp = Math.floor(Date.now() / 1000);
const response = await fetch(
`https://glacier-api.avax.network/v1/networks/mainnet/blockchains/p-chain/transactions:listStaking?addresses=avax10f8305248c0wsfsdempdtpx7lpkc30vwzl9y9q&txTypes=AddDelegatorTx&startTimestamp=1&endTimestamp=${timestamp}&pageSize=100`,
`https://glacier-api.avax.network/v1/networks/mainnet/blockchains/p-chain/transactions:listStaking?addresses=avax10f8305248c0wsfsdempdtpx7lpkc30vwzl9y9q&txTypes=AddDelegatorTx&startTimestamp=${startTimestamp}&endTimestamp=${endTimestamp}&pageSize=100`,
{
headers: {
Accept: "application/json",
Expand All @@ -19,6 +21,27 @@ class ggAVAX {
return this.currentDelegations;
}

async fetchCurrentMEV() {
const startTimestamp = Math.floor(Date.now() / 1000) - 15 * 24 * 60 * 60;
const endTimestamp = Math.floor(Date.now() / 1000);
const url = (nextPageParamAndToken) =>
`https://glacier-api.avax.network/v1/networks/mainnet/blockchains/p-chain/transactions:listStaking?addresses=avax10f8305248c0wsfsdempdtpx7lpkc30vwzl9y9q&txTypes=AddValidatorTx&txTypes=AddPermissionlessValidatorTx&startTimestamp=${startTimestamp}&endTimestamp=${endTimestamp}&pageSize=100${nextPageParamAndToken}`;

const txs = [];
let nextPageParamAndToken = "";
let i = 0;
do {
const response = await fetch(url(nextPageParamAndToken)).then((res) => res.json());
txs.push(...response.transactions);
nextPageParamAndToken = response.nextPageToken ? `&pageToken=${response.nextPageToken}` : "";
i++;
} while (nextPageParamAndToken && i < 10);

// MEV Nodes run 14 days
this.currentMEV = txs.filter((t) => t.endTimestamp - t.startTimestamp === 14 * 24 * 60 * 60);
return this.currentMEV;
}

async fetchWavaxBalance() {
const response = await fetch(
`https://glacier-api.avax.network/v1/chains/43114/addresses/0xA25EaF2906FA1a3a13EdAc9B9657108Af7B703e3/balances:listErc20?pageSize=10&contractAddresses=0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7&currency=usd`,
Expand Down
23 changes: 23 additions & 0 deletions public/js/tabulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ const ggAVAXStatsDef = {
],
};

const ggAVAXMEVDef = {
data: [], // Filled in later by JS
index: "startTimestamp",
height: 300, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
layout: "fitColumns", //fit columns to width of table (optional)
groupBy: 1,
groupHeader: function (value, count, data, group) {
return `Validating<span style="color:#00d; margin-left:10px;"">(${count} nodes)</span>`;
},
initialSort: [{ column: "endTimestamp", dir: "asc" }],
responsiveLayout: "collapse",
responsiveLayoutCollapseStartOpen: false,
selectable: true,
clipboard: "copy",
clipboardCopyRowRange: "selected",
columns: [
{ width: 20, formatter: "responsiveCollapse", headerSort: false },
{ title: "Period Ends", field: "endTimestamp", formatter: formatDurationHumanUntil },
{ title: "Node", field: "nodeId", formatter: formatNodeIdLink },
],
};

// Definitions for Tabulator tables
const pandasiaDef = {
data: [], // Filled in later by JS
Expand Down Expand Up @@ -530,6 +552,7 @@ export {
contractsDef,
ggAVAXDef,
ggAVAXStatsDef,
ggAVAXMEVDef,
pandasiaDef,
pandasiaAirdropsDef,
pandasiaUsersDef,
Expand Down

0 comments on commit 83f53e1

Please sign in to comment.