Skip to content

Commit

Permalink
formatted the foxy data
Browse files Browse the repository at this point in the history
  • Loading branch information
deadshotryker committed Aug 19, 2024
1 parent 754c29c commit 05388e6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 28 deletions.
7 changes: 5 additions & 2 deletions adapters/zerolend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ readBlocksFromCSV("hourly_blocks.csv")

for (const block of blocks) {
try {
const resultTvl = await getUserTVLByBlock(block);
allCsvRows.push(...resultTvl);
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);
} catch (error) {
console.error(`An error occurred for block ${block}:`, error);
}
Expand Down
19 changes: 14 additions & 5 deletions adapters/zerolend/src/sdk/foxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { BlockData, IUserReserve, ILPResponse, OutputDataSchemaRow } from "./types";

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";
Expand All @@ -13,6 +17,12 @@ export const getUserTVLFoxyByBlock = async (

let lastAddress = "0x0000000000000000000000000000000000000000";

const remapFoxy = (addr: string) =>
addr == "0x5fbdf89403270a1846f5ae7d113a989f850d1566"
? "0x000000000000000000000000000000000000foxy"
: addr;

console.log("working on foxy data");
do {
const query = `{
userReserves(
Expand All @@ -39,8 +49,7 @@ export const getUserTVLFoxyByBlock = async (
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) => {
Expand All @@ -52,7 +61,7 @@ export const getUserTVLFoxyByBlock = async (
block_number: blocks.blockNumber,
timestamp,
user_address: data.user.id,
token_address: data.reserve.underlyingAsset,
token_address: remapFoxy(data.reserve.underlyingAsset),
token_balance: Number(balance),
token_symbol: data.reserve.symbol,
usd_price: 0,
Expand Down
12 changes: 9 additions & 3 deletions adapters/zerolend/src/sdk/lp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { BlockData, IOmniStakingData, IOmniStakingResponse, OutputDataSchemaRow } from "./types";
import {
BlockData,
IOmniStakingData,
IOmniStakingResponse,
OutputDataSchemaRow,
} from "./types";

const queryURL =
"https://api.goldsky.com/api/public/project_clsk1wzatdsls01wchl2e4n0y/subgraphs/zerolend-omnistaking/1.0.2/gn";
Expand All @@ -15,6 +20,7 @@ export const getUserLPByBlock = async (

let lastAddress = "0x0000000000000000000000000000000000000000";

console.log("working on LP stakers data");
do {
const query = `{
tokenBalances(
Expand All @@ -23,8 +29,8 @@ export const getUserLPByBlock = async (
) {
id
balance_omni_lp
}
}`;
}
}`;

const response = await fetch(queryURL, {
method: "POST",
Expand Down
9 changes: 7 additions & 2 deletions adapters/zerolend/src/sdk/stake.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { BlockData, IOmniStakingData, IOmniStakingResponse, OutputDataSchemaRow } from "./types";
import {
BlockData,
IOmniStakingData,
IOmniStakingResponse,
OutputDataSchemaRow,
} from "./types";

const queryURL =
"https://api.goldsky.com/api/public/project_clsk1wzatdsls01wchl2e4n0y/subgraphs/zerolend-omnistaking/1.0.2/gn";
Expand All @@ -14,7 +19,7 @@ export const getUserStakeByBlock = async (
const rows: OutputDataSchemaRow[] = [];

let lastAddress = "0x0000000000000000000000000000000000000000";

console.log("working on ZERO stakers data");
do {
const query = `{
tokenBalances(
Expand Down
9 changes: 7 additions & 2 deletions adapters/zerolend/src/sdk/tvl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { BlockData, IUserReserve, ILPResponse, OutputDataSchemaRow } from "./types";

import {
BlockData,
IUserReserve,
ILPResponse,
OutputDataSchemaRow,
} from "./types";

const queryURL =
"https://api.goldsky.com/api/public/project_clsk1wzatdsls01wchl2e4n0y/subgraphs/zerolend-linea/1.0.0/gn";
Expand All @@ -13,6 +17,7 @@ export const getUserTVLByBlock = async (

let lastAddress = "0x0000000000000000000000000000000000000000";

console.log("working on legacy lending pool data");
do {
const query = `{
userReserves(
Expand Down
28 changes: 14 additions & 14 deletions adapters/zerolend/src/sdk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ export interface BlockData {
}

export interface ILPResponse {
data: {
userReserves: IUserReserve[];
};
data: {
userReserves: IUserReserve[];
};
}

export interface IUserReserve {
user: {
id: string;
};
currentTotalDebt: string;
currentATokenBalance: string;
reserve: {
underlyingAsset: string;
symbol: string;
name: string;
};
liquidityRate: "0";
user: {
id: string;
};
currentTotalDebt: string;
currentATokenBalance: string;
reserve: {
underlyingAsset: string;
symbol: string;
name: string;
};
liquidityRate: "0";
}

0 comments on commit 05388e6

Please sign in to comment.