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

secta : dex : fix v2 pools calculation #163

Merged
merged 4 commits into from
May 23, 2024
Merged
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
5 changes: 0 additions & 5 deletions adapters/secta/block_numbers_secta.tsv

This file was deleted.

49 changes: 9 additions & 40 deletions adapters/secta/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ import BigNumber from "bignumber.js";
import { CHAINS, PROTOCOLS, AMM_TYPES, RPC_URLS } from "./sdk/config";
import {
getLPValueByUserAndPoolFromPositions,
getMintedAddresses,
getPositionAtBlock,
getPositionDetailsFromPosition,
getPositionsForAddressByPoolAtBlock,
getV2Pairs,
} from "./sdk/subgraphDetails";
import {
LiquidityMap,
TokenLiquidityInfo,
LiquidityInfo,
combineLiquidityInfoMaps,
} from "./sdk/liquidityTypes";
import { combineLiquidityInfoMaps } from "./sdk/liquidityTypes";

(BigInt.prototype as any).toJSON = function () {
return this.toString();
Expand All @@ -23,13 +16,9 @@ import stream from "stream";
import csv from "csv-parser";
import fs from "fs";
import path from "path";
import { format } from "fast-csv";
import { write } from "fast-csv";
import { pipeline as streamPipeline } from "stream";
import { captureRejectionSymbol } from "events";
import { getV2LpValue } from "./sdk/poolDetails";


interface LPValueDetails {
pool: string;
lpValue: string;
Expand Down Expand Up @@ -58,14 +47,11 @@ const readBlocksFromCSV = async (filePath: string): Promise<BlockData[]> => {

await new Promise<void>((resolve, reject) => {
fs.createReadStream(filePath)
.pipe(csv({ separator: "," })) // Specify the separator as '\t' for TSV files
.pipe(csv()) // Specify the separator as '\t' for TSV files
.on("data", (row) => {
//console.log(row);
const blockNumber = parseInt(row.number, 10);
const blockTimestamp = parseInt(row.timestamp, 10);
//console.log(`Maybe Data ${blockNumber} ${blockTimestamp}`);
if (!isNaN(blockNumber) && blockTimestamp) {
//console.log(`Valid Data`);
blocks.push({ blockNumber: blockNumber, blockTimestamp });
}
})
Expand All @@ -91,9 +77,8 @@ type OutputDataSchemaRow = {
usd_price: number;
};

export const getUserTVLByBlock = async (blocks: BlockData) => {
const { blockNumber, blockTimestamp } = blocks;
//console.log(`Getting tvl in block: ${blockNumber}`);
export const getUserTVLByBlock = async (block: BlockData) => {
const { blockNumber, blockTimestamp } = block;

const v3Positions = await getPositionsForAddressByPoolAtBlock(
blockNumber,
Expand All @@ -106,25 +91,8 @@ export const getUserTVLByBlock = async (blocks: BlockData) => {
let v3PositionsWithValue = v3Positions.map(getPositionDetailsFromPosition);
let v3LpValue = getLPValueByUserAndPoolFromPositions(v3PositionsWithValue);

let pairs = await getV2Pairs(
blockNumber,
CHAINS.LINEA,
PROTOCOLS.SECTA,
AMM_TYPES.SECTAV2
);
let mintedAddresses = await getMintedAddresses(
blockNumber,
CHAINS.LINEA,
PROTOCOLS.SECTA,
AMM_TYPES.SECTAV2
);

let v2LpValue = await getV2LpValue(
RPC_URLS[CHAINS.LINEA],
pairs,
mintedAddresses,
blockNumber
);
let pairs = await getV2Pairs(blockNumber, CHAINS.LINEA, PROTOCOLS.SECTA, AMM_TYPES.SECTAV2);
let v2LpValue = await getV2LpValue(pairs, blockNumber);

const combinedLpValue = combineLiquidityInfoMaps(v3LpValue, v2LpValue);

Expand Down Expand Up @@ -170,8 +138,9 @@ readBlocksFromCSV(path.resolve(__dirname, "../hourly_blocks.csv"))
const ws = fs.createWriteStream(`outputData.csv`, {
flags: "w",
});
write(allCsvRows, {headers: true})
.pipe(ws).on("finish", () => {
write(allCsvRows, { headers: true })
.pipe(ws)
.on("finish", () => {
console.log(`CSV file has been written.`);
});
})
Expand Down
Loading
Loading