Skip to content

Commit

Permalink
feat: Add adapter for Reya
Browse files Browse the repository at this point in the history
  • Loading branch information
rvaitkus23 committed Jul 29, 2024
1 parent 04702f4 commit a93f472
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions projects/helper/chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"rei",
"reichain",
"renec",
"reya",
"ripple",
"rollux",
"ronin",
Expand Down
51 changes: 51 additions & 0 deletions projects/reya/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const totalSupplyBalanceFetcher = async ({
address,
network,
}) => {
const response = await fetch(
`https://explorer.${network}.network/api/v2/tokens/${address}`,
);
if (response.status === 200) {
const data = await response.json();

const supplyString = data.total_supply;
const decimalsString = data.decimals;

if (!supplyString || !decimalsString) {
return null;
}
const decimalsInt = parseInt(decimalsString, 10);
const value = parseInt(supplyString, 10);
const divider = 10 ** decimalsInt;
const balance = value / divider;

return balance;
}
return null;
};

const coins = {
"usd-coin": "0x3B860c0b53f2e8bd5264AA7c3451d41263C933F2",
"WETH": "0x6B48C2e6A32077ec17e8Ba0d98fFc676dfab1A30",
}

async function tvl(api){
const fetchCoinBalance = async (coin) => {
const balance = await totalSupplyBalanceFetcher({ network: api.chain, address: coins[coin] });
return ({ coin, balance });
}

const fetchResults = await Promise.all(Object.keys(coins).map(fetchCoinBalance));
return fetchResults.reduce((acc, item) => {
if (!item) {
return acc;
}
return ({ ...acc, [item.coin]: item.balance })
}, {});
}

module.exports={
reya:{
tvl
}
}

0 comments on commit a93f472

Please sign in to comment.