Skip to content

Commit

Permalink
changed after refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
olivblad committed May 2, 2024
1 parent 74d71bd commit e4160b5
Showing 1 changed file with 46 additions and 13 deletions.
59 changes: 46 additions & 13 deletions projects/atlendis-v2/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
const { GraphQLClient } = require("graphql-request");
const query = `
query tvl($chainId: Int!) {
query tvlAndBorrow($chainId: Int!) {
rcls(chainId: $chainId) {
id
address
address
tvl
token {
address
}
currentLoan {accruedInterests borrowedAmount }
currentLoan {
borrowedAmount
}
}
bulletLoans(chainId: $chainId) {
id
address
address
tvl
token {
address
}
issuedLoan {
borrowedAmount
}
}
}
`;
Expand All @@ -30,28 +33,58 @@ async function tvl(api) {
const chain = api.chain;
const graphQLClient = new GraphQLClient(atlendisUrl);
const chainId = supportedChains[chain];
const { rcls } = await graphQLClient.request(query, { chainId });
const tokensAndOwners = rcls.map((rcl) => [rcl.token.address, rcl.address]);
return api.sumTokens({ tokensAndOwners });
const { rcls, bulletLoans } = await graphQLClient.request(query, { chainId });
const balances = {};
for (let rcl of rcls) {
const poolTvl = rcl.tvl - rcl.currentLoan?.borrowedAmount || "0x00";
if (!balances[`${chain}:${rcl.token.address}`]) {
balances[`${chain}:${rcl.token.address}`] = poolTvl;
} else {
balances[`${chain}:${rcl.token.address}`] =
balances[`${chain}:${rcl.token.address}`] + poolTvl;
}
}
for (let loan of bulletLoans) {
const poolTvl = loan.tvl - loan.issuedLoan?.borrowedAmount || "0x00";
if (!balances[`${chain}:${loan.token.address}`]) {
balances[`${chain}:${loan.token.address}`] = poolTvl;
} else {
balances[`${chain}:${loan.token.address}`] =
balances[`${chain}:${loan.token.address}`] + poolTvl;
}
}
return balances;
}

async function borrowed(api) {
const chain = api.chain;
const graphQLClient = new GraphQLClient(atlendisUrl);
const chainId = supportedChains[chain];
const { rcls, bulletLoans } = await graphQLClient.request(query, { chainId });

const balances = {};
for (let rcl of rcls) {
if (rcl.currentLoan) {
api.add(rcl.token.address, rcl.currentLoan.borrowedAmount);
const { borrowedAmount } = rcl.currentLoan;
if (!balances[`${chain}:${rcl.token.address}`]) {
balances[`${chain}:${rcl.token.address}`] = borrowedAmount;
} else {
balances[`${chain}:${rcl.token.address}`] =
balances[`${chain}:${rcl.token.address}`] + borrowedAmount;
}
}
}

for (let loan of bulletLoans) {
if (loan.issuedLoan) {
api.add(loan.token.address, loan.tvl);
const { borrowedAmount } = loan.issuedLoan;
if (!balances[`${chain}:${loan.token.address}`]) {
balances[`${chain}:${loan.token.address}`] = borrowedAmount;
} else {
balances[`${chain}:${loan.token.address}`] =
balances[`${chain}:${loan.token.address}`] + borrowedAmount;
}
}
}
return balances;
}

module.exports = {
Expand Down

0 comments on commit e4160b5

Please sign in to comment.