From 83f53e194c313a55095861005534657762f131dc Mon Sep 17 00:00:00 2001 From: Johnny Gault Date: Fri, 1 Mar 2024 12:51:17 -0800 Subject: [PATCH] mev --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- public/ggavax.html | 24 +++++++++++++++++++++--- public/js/ggavax.js | 27 +++++++++++++++++++++++++-- public/js/tabulator.js | 23 +++++++++++++++++++++++ 5 files changed, 84 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 77b29b0..b63473e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 912c6c3..840ed60 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/public/ggavax.html b/public/ggavax.html index c605442..7aac8e2 100644 --- a/public/ggavax.html +++ b/public/ggavax.html @@ -14,6 +14,11 @@

ggAVAX Delegations

Loading...

+
+

ggAVAX MEV

+
Loading...
+
+

ggAVAX Stats

Loading...
@@ -36,7 +41,7 @@

ggAVAX Stats

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; @@ -45,15 +50,28 @@

ggAVAX Stats

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"); diff --git a/public/js/ggavax.js b/public/js/ggavax.js index 39a83bb..7d1ecb0 100644 --- a/public/js/ggavax.js +++ b/public/js/ggavax.js @@ -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", @@ -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¤cy=usd`, diff --git a/public/js/tabulator.js b/public/js/tabulator.js index 2bf96ba..08d2777 100644 --- a/public/js/tabulator.js +++ b/public/js/tabulator.js @@ -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(${count} nodes)`; + }, + 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 @@ -530,6 +552,7 @@ export { contractsDef, ggAVAXDef, ggAVAXStatsDef, + ggAVAXMEVDef, pandasiaDef, pandasiaAirdropsDef, pandasiaUsersDef,