-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1ba5a4
commit a98c596
Showing
6 changed files
with
100 additions
and
38 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
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,70 @@ | ||
import { BlockData, IUserReserve, ILPResponse, OutputDataSchemaRow } from "./types"; | ||
|
||
|
||
const queryURL = | ||
"https://api.goldsky.com/api/public/project_clsk1wzatdsls01wchl2e4n0y/subgraphs/zerolend-linea-foxy/1.0.0/gn"; | ||
|
||
export const getUserTVLFoxyByBlock = async ( | ||
blocks: BlockData | ||
): Promise<OutputDataSchemaRow[]> => { | ||
const timestamp = blocks.blockTimestamp; | ||
const first = 1000; | ||
const rows: OutputDataSchemaRow[] = []; | ||
|
||
let lastAddress = "0x0000000000000000000000000000000000000000"; | ||
|
||
do { | ||
const query = `{ | ||
userReserves( | ||
first: ${first} | ||
where: {user_gt: "${lastAddress}"} | ||
) { | ||
user { | ||
id | ||
} | ||
currentTotalDebt | ||
currentATokenBalance | ||
reserve { | ||
underlyingAsset | ||
symbol | ||
name | ||
} | ||
liquidityRate | ||
} | ||
}`; | ||
|
||
const response = await fetch(queryURL, { | ||
method: "POST", | ||
body: JSON.stringify({ query }), | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
const batch: ILPResponse = await response.json(); | ||
console.log(batch); | ||
|
||
if (!batch.data || batch.data.userReserves.length == 0) break; | ||
|
||
batch.data.userReserves.forEach((data: IUserReserve) => { | ||
const balance = | ||
BigInt(data.currentATokenBalance) - BigInt(data.currentTotalDebt); | ||
|
||
if (balance !== 0n) | ||
rows.push({ | ||
block_number: blocks.blockNumber, | ||
timestamp, | ||
user_address: data.user.id, | ||
token_address: data.reserve.underlyingAsset, | ||
token_balance: Number(balance), | ||
token_symbol: data.reserve.symbol, | ||
usd_price: 0, | ||
}); | ||
|
||
lastAddress = data.user.id; | ||
}); | ||
|
||
console.log( | ||
`Processed ${rows.length} rows. Last address is ${lastAddress}` | ||
); | ||
} while (true); | ||
|
||
return rows; | ||
}; |
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
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
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
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