Skip to content

Commit

Permalink
Merge pull request #2 from AstarNetwork/feat/astar-tvl
Browse files Browse the repository at this point in the history
feat: added TVL for Astar network
  • Loading branch information
hskang9 authored Jan 27, 2022
2 parents 3a3d23f + ae4dc65 commit 1c57c96
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions projects/astar-dapps-staking/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { ApiPromise, WsProvider } = require("@polkadot/api");

const ASTR_DECIMALS = 18;

async function tvl() {
const provider = new WsProvider("wss://astar.api.onfinality.io/public-ws");
const api = new ApiPromise({
provider,
});

await api.isReady;
const era = await api.query.dappsStaking.currentEra();
const result = await api.query.dappsStaking.eraRewardsAndStakes(era);
const tvl = result.unwrap().staked.valueOf();
const AstrLocked = tvl / 10 ** ASTR_DECIMALS;

return {
astar: AstrLocked,
};
}

module.exports = {
methodology:
"TVL considers ASTR tokens deposited to the Dapps-Staking program",
tvl,
};

0 comments on commit 1c57c96

Please sign in to comment.