-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from AstarNetwork/feat/astar-tvl
feat: added TVL for Astar network
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |