Skip to content

Commit

Permalink
fixed the bigint and added sample output data
Browse files Browse the repository at this point in the history
  • Loading branch information
deadshotryker committed Aug 20, 2024
1 parent 05388e6 commit b682e1a
Show file tree
Hide file tree
Showing 7 changed files with 193,088 additions and 24 deletions.
46 changes: 28 additions & 18 deletions adapters/zerolend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { write } from "fast-csv";
import fs from "fs";
import csv from "csv-parser";
import { BlockData } from "./sdk/types";
import { getUserTVLByBlock } from "./sdk/tvl";
import { BlockData, OutputDataSchemaRow } from "./sdk/types";
import { getUserTVLLegacyByBlock } from "./sdk/tvl";
import { getUserStakeByBlock } from "./sdk/stake";
import { getUserLPByBlock } from "./sdk/lp";
import { getUserTVLFoxyByBlock } from "./sdk/foxy";

module.exports = {
getUserTVLByBlock,
};

const readBlocksFromCSV = async (filePath: string): Promise<BlockData[]> => {
const blocks: BlockData[] = [];

Expand Down Expand Up @@ -38,21 +34,13 @@ const readBlocksFromCSV = async (filePath: string): Promise<BlockData[]> => {
readBlocksFromCSV("hourly_blocks.csv")
.then(async (blocks: BlockData[]) => {
console.log(blocks);
const allCsvRows: any[] = []; // Array to accumulate CSV rows for all blocks
let allCsvRows: OutputDataSchemaRow[] = []; // Array to accumulate CSV rows for all blocks

for (const block of blocks) {
try {
const resultTvlFoxy = await getUserTVLFoxyByBlock(block);
allCsvRows.push(...resultTvlFoxy);

const resultStake = await getUserStakeByBlock(block);
allCsvRows.push(...resultStake);

const resultLp = await getUserLPByBlock(block);
allCsvRows.push(...resultLp);

const resultTvlLegacy = await getUserTVLByBlock(block);
allCsvRows.push(...resultTvlLegacy);
const data = await getUserTVLByBlock(block);
allCsvRows = allCsvRows.concat(data);
console.log(data);
} catch (error) {
console.error(`An error occurred for block ${block}:`, error);
}
Expand All @@ -70,3 +58,25 @@ readBlocksFromCSV("hourly_blocks.csv")
.catch((err) => {
console.error("Error reading CSV file:", err);
});

const getUserTVLByBlock = async (block: BlockData): Promise<any> => {
let allCsvRows: OutputDataSchemaRow[] = []; // Array to accumulate CSV rows for all blocks

const resultTvlFoxy = await getUserTVLFoxyByBlock(block);
allCsvRows = allCsvRows.concat(resultTvlFoxy);

const resultStake = await getUserStakeByBlock(block);
allCsvRows = allCsvRows.concat(resultStake);

const resultLp = await getUserLPByBlock(block);
allCsvRows = allCsvRows.concat(resultLp);

const resultTvlLegacy = await getUserTVLLegacyByBlock(block);
allCsvRows = allCsvRows.concat(resultTvlLegacy);

return allCsvRows;
};

module.exports = {
getUserTVLByBlock,
};
2 changes: 1 addition & 1 deletion adapters/zerolend/src/sdk/foxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const getUserTVLFoxyByBlock = async (
timestamp,
user_address: data.user.id,
token_address: remapFoxy(data.reserve.underlyingAsset),
token_balance: Number(balance),
token_balance: BigInt(balance),
token_symbol: data.reserve.symbol,
usd_price: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion adapters/zerolend/src/sdk/lp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const getUserLPByBlock = async (
timestamp,
user_address: data.id,
token_address: tokenAddress,
token_balance: Math.floor(Number(data.balance_omni_lp) / 1e18),
token_balance: BigInt(data.balance_omni_lp),
token_symbol: symbol,
usd_price: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion adapters/zerolend/src/sdk/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const getUserStakeByBlock = async (
timestamp,
user_address: data.id,
token_address: tokenAddress,
token_balance: Math.floor(Number(data.balance_omni) / 1e18),
token_balance: BigInt(data.balance_omni),
token_symbol: symbol,
usd_price: 0,
});
Expand Down
4 changes: 2 additions & 2 deletions adapters/zerolend/src/sdk/tvl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
const queryURL =
"https://api.goldsky.com/api/public/project_clsk1wzatdsls01wchl2e4n0y/subgraphs/zerolend-linea/1.0.0/gn";

export const getUserTVLByBlock = async (
export const getUserTVLLegacyByBlock = async (
blocks: BlockData
): Promise<OutputDataSchemaRow[]> => {
const timestamp = blocks.blockTimestamp;
Expand Down Expand Up @@ -58,7 +58,7 @@ export const getUserTVLByBlock = async (
timestamp,
user_address: data.user.id,
token_address: data.reserve.underlyingAsset,
token_balance: Number(balance),
token_balance: BigInt(balance),
token_symbol: data.reserve.symbol,
usd_price: 0,
});
Expand Down
2 changes: 1 addition & 1 deletion adapters/zerolend/src/sdk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type OutputDataSchemaRow = {
timestamp: number;
user_address: string;
token_address: string;
token_balance: number;
token_balance: bigint;
token_symbol: string;
usd_price: number;
};
Expand Down
Loading

0 comments on commit b682e1a

Please sign in to comment.