Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add foxy market #289

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion adapters/zerolend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BlockData } from "./sdk/types";
import { getUserTVLByBlock } from "./sdk/tvl";
import { getUserStakeByBlock } from "./sdk/stake";
import { getUserLPByBlock } from "./sdk/lp";
import {getUserTVLFoxyByBlock} from './sdk/foxy'

module.exports = {
getUserTVLByBlock,
Expand Down Expand Up @@ -57,10 +58,15 @@ readBlocksFromCSV("hourly_blocks.csv")
for (let i = 0; i < resultLp.length; i++) {
allCsvRows.push(resultLp[i]);
}

const resultFoxy= await getUserTVLFoxyByBlock(block)
for (let i = 0; i < resultFoxy.length; i++) {
allCsvRows.push(resultFoxy[i])
}
} catch (error) {
console.error(`An error occurred for block ${block}:`, error);
}
}
}
await new Promise((resolve, reject) => {
const ws = fs.createWriteStream(`outputData.csv`, { flags: "w" });
write(allCsvRows, { headers: true })
Expand All @@ -69,6 +75,7 @@ readBlocksFromCSV("hourly_blocks.csv")
console.log(`CSV file has been written.`);
resolve;
});

});
})
.catch((err) => {
Expand Down
70 changes: 70 additions & 0 deletions adapters/zerolend/src/sdk/foxy.ts
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;
};
7 changes: 1 addition & 6 deletions adapters/zerolend/src/sdk/lp.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
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 Down
8 changes: 1 addition & 7 deletions adapters/zerolend/src/sdk/stake.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
BlockData,
IOmniStakingData,
IOmniStakingResponse,
ITVLResponse,
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 Down
12 changes: 4 additions & 8 deletions adapters/zerolend/src/sdk/tvl.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
BlockData,
ITVLData,
ITVLResponse,
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 Down Expand Up @@ -43,11 +39,11 @@ export const getUserTVLByBlock = async (
body: JSON.stringify({ query }),
headers: { "Content-Type": "application/json" },
});
const batch: ITVLResponse = await response.json();
const batch: ILPResponse = await response.json();

if (!batch.data || batch.data.userReserves.length == 0) break;

batch.data.userReserves.forEach((data: ITVLData) => {
batch.data.userReserves.forEach((data: IUserReserve) => {
const balance =
BigInt(data.currentATokenBalance) - BigInt(data.currentTotalDebt);

Expand Down
32 changes: 16 additions & 16 deletions adapters/zerolend/src/sdk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ export interface BlockData {
blockTimestamp: number;
}

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

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