Last active
April 4, 2023 11:36
-
-
Save RaveenaBhasin/41b4facc17093071a4185b175c60e6ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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