Skip to content

Commit

Permalink
added a staking/validator page
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 committed Jan 29, 2024
1 parent 62f5b49 commit e3f1268
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<a href="./consensus.html">Consensus</a> <span class="flexible-filler"></span>
<a href="./audit.html">Audit</a> <span class="flexible-filler"></span>
<a href="./wallet.html">Wallet</a> <span class="flexible-filler"></span>
<a href="./staking.html">Staking</a>
</div>
<div id="outer-div">
<div id="banner" style="boarder:1px"></div>
Expand Down
25 changes: 25 additions & 0 deletions staking.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Staking</title>
<link rel="stylesheet" href="./main.css">
</head>
<body>
<div id="links" style="text-align: center;font-size: 20px;display: flex;justify-content: space-between;">
<span class="flexible-filler"></span>
<a href="./index.html">Basics</a> <span class="flexible-filler"></span>
<a href="./zevm.html">zEVM</a> <span class="flexible-filler"></span>
<a href="./zetaclients.html">ZetaClients</a> <span class="flexible-filler"></span>
<a href="./crosschain.html">Cross-Chain Module</a> <span class="flexible-filler"></span>
<a href="./consensus.html">Consensus</a> <span class="flexible-filler"></span>
<a href="./wallet.html">Wallet</a> <span class="flexible-filler"></span>
<a href="./audit.html">Audit</a>
</div>

<div id="entry"></div>

<script src="./tag.js"></script>
<script type="module" src="./staking.js"></script>
</body>
</html>
82 changes: 82 additions & 0 deletions staking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
AddressExplorerByChainID,
bitcoinChainID,
esploraAPIURL,
evmURL,
nodeURL,
RPCByChainID,
externalChainIDs,
makeTableElement2, makeTableElement
} from './common.js';
import './web3.min.js';
import {convertbits, decode, encode} from "./bech32.js";


class StakingPage {
constructor() {
}

async initialize() {

}

async render() {
const entry = document.getElementById("entry");
entry.appendChild(H1("Distribution params"));
const res2 = await fetch(`${nodeURL}/cosmos/distribution/v1beta1/params`);
const data2 = await res2.json();
console.log("data2", data2);
entry.appendChild(makeTableElement(data2.params));

entry.appendChild(H1("Staking Info"));
const res = await fetch(`${nodeURL}/zeta-chain/emissions/list_addresses`);
const addresses = await res.json();
const rows = [];
for (const name in addresses) {
console.log(name, addresses[name]);
const addr = addresses[name];
// const res2 = await fetch(`${nodeURL}/cosmos/emissions/show_available_emissions/${addr}`);
const res2 = await fetch(`${nodeURL}/cosmos/bank/v1beta1/balances/${addr}/by_denom?denom=azeta`);
const amount = await res2.json();
console.log("amount", amount);
rows.push({
name: name,
address: addr,
amount: `${amount.balance.amount}`
});
}
entry.appendChild(makeTableElement2(rows, ["name", "address", "amount"]));

entry.appendChild(H1("Validator Voting Power"));
const res3 = await fetch(`${nodeURL}/cosmos/staking/v1beta1/validators`);
const data = await res3.json();
console.log("data", data);
const rows2 = [];
for (let i=0; i<data.validators.length; i++) {
const val = data.validators[i];
const d = decode(val.operator_address, "bech32");
const a = convertbits(d.data, 5, 8, false);
const valAddress = encode("zeta", convertbits(a, 8, 5, true), "bech32");
const row = {
"moniker": val.description.moniker,
"address": valAddress,
"jailed": val.jailed,
"status": val.status,
"tokens": parseFloat(val.tokens)/1e18,
"delegator_share": parseFloat(val.delegator_shares)/parseFloat(val.tokens),
"update_time": val.commission.update_time
};
rows2.push( row);
console.log("val", i, row);
}
rows2.sort((a,b)=>{return -a.tokens+b.tokens;});
console.log(rows2);
entry.appendChild(makeTableElement2(rows2, ["moniker", "address", "jailed", "status", "tokens", "delegator_share", "update_time"]));
}
}


const page = new StakingPage();
await page.initialize();

await page.render();

0 comments on commit e3f1268

Please sign in to comment.