Skip to content

Instantly share code, notes, and snippets.

@RaveenaBhasin
Last active April 4, 2023 11:36
Show Gist options
  • Select an option

  • Save RaveenaBhasin/41b4facc17093071a4185b175c60e6ea to your computer and use it in GitHub Desktop.

Select an option

Save RaveenaBhasin/41b4facc17093071a4185b175c60e6ea to your computer and use it in GitHub Desktop.
const fetch = require("node-fetch");
const query = `
query {
uniBorrows {
id
token0
token1
borrowToken0
borrowToken1
}
uniLends {
id
token0
token1
lentToken0
lentToken1
}
}
`;
// https://api.thegraph.com/subgraphs/name/raveenabhasin/tswap (for ethereum mainnet)
fetch("https://api.thegraph.com/subgraphs/name/raveenabhasin/tswap_arbitrum", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query }),
}).then((res) => res.json())
.then(({ data }) => {
let totalBorrowToken0 = 0;
let totalBorrowToken1 = 0;
let totalLentToken0 = 0;
let totalLentToken1 = 0;
data.uniBorrows.forEach((borrow) => {
totalBorrowToken0 += borrow.borrowToken0;
totalBorrowToken1 += borrow.borrowToken1;
});
data.uniLends.forEach((lend) => {
totalLentToken0 += lend.lentToken0;
totalLentToken1 += lend.lentToken1;
});
console.log("Total borrowToken0:", totalBorrowToken0);
console.log("Total borrowToken1:", totalBorrowToken1);
console.log("Total lentToken0:", totalLentToken0);
console.log("Total lentToken1:", totalLentToken1);
})
.catch((error) => console.error(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment