Skip to content

Commit

Permalink
chore: secta - tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
jac0x committed Mar 26, 2024
1 parent 806fa4e commit b824833
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 191 deletions.
5 changes: 5 additions & 0 deletions adapters/secta/block_numbers_secta.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
block_timestamp number
1708904831 2518028
1708991231 2539628
1709077631 2561228
1709164031 2582828
100 changes: 7 additions & 93 deletions adapters/secta/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ import { pipeline as streamPipeline } from "stream";
import { captureRejectionSymbol } from "events";
import { getV2LpValue } from "./sdk/poolDetails";

//Uncomment the following lines to test the getPositionAtBlock function

// const position = getPositionAtBlock(
// 0, // block number 0 for latest block
// 2, // position id
// CHAINS.L2_CHAIN_ID, // chain id
// PROTOCOLS.PROTOCOL_NAME, // protocol
// AMM_TYPES.UNISWAPV3 // amm type
// );
// position.then((position) => {
// // print response
// const result = getPositionDetailsFromPosition(position);
// console.log(`${JSON.stringify(result,null, 4)}
// `)
// });

interface LPValueDetails {
pool: string;
Expand All @@ -60,79 +45,8 @@ interface OutputData {
[key: string]: UserLPData;
}

interface CSVRow {
user: string;
pool: string;
block: number;
position: number;
lpvalue: string;
}

const pipeline = promisify(stream.pipeline);

// Assuming you have the following functions and constants already defined
// getPositionsForAddressByPoolAtBlock, CHAINS, PROTOCOLS, AMM_TYPES, getPositionDetailsFromPosition, getLPValueByUserAndPoolFromPositions, BigNumber

// const readBlocksFromCSV = async (filePath: string): Promise<number[]> => {
// const blocks: number[] = [];
// await pipeline(
// fs.createReadStream(filePath),
// csv(),
// async function* (source) {
// for await (const chunk of source) {
// // Assuming each row in the CSV has a column 'block' with the block number
// if (chunk.block) blocks.push(parseInt(chunk.block, 10));
// }
// }
// );
// return blocks;
// };

// const getData = async () => {
// const snapshotBlocks = [
// 3116208, 3159408, 3202608, 3245808, 3289008, 3332208,
// 3375408, 3418608, 3461808, 3505008, 3548208, 3591408,
// 3634608, 3677808, 3721008, 3764208, 3807408, 3850608,
// 3893808, 3937008, 3980208, 3983003,
// ]; //await readBlocksFromCSV('src/sdk/L2_CHAIN_ID_chain_daily_blocks.csv');

// const csvRows: CSVRow[] = [];

// for (let block of snapshotBlocks) {
// const positions = await getPositionsForAddressByPoolAtBlock(
// block, "", "", CHAINS.L2_CHAIN_ID, PROTOCOLS.PROTOCOL_NAME, AMM_TYPES.UNISWAPV3
// );

// console.log(`Block: ${block}`);
// console.log("Positions: ", positions.length);

// // Assuming this part of the logic remains the same
// let positionsWithUSDValue = positions.map(getPositionDetailsFromPosition);
// let lpValueByUsers = getLPValueByUserAndPoolFromPositions(positionsWithUSDValue);

// lpValueByUsers.forEach((value, key) => {
// let positionIndex = 0; // Define how you track position index
// value.forEach((lpValue, poolKey) => {
// const lpValueStr = lpValue.toString();
// // Accumulate CSV row data
// csvRows.push({
// user: key,
// pool: poolKey,
// block,
// position: positions.length, // Adjust if you have a specific way to identify positions
// lpvalue: lpValueStr,
// });
// });
// });
// }

// // Write the CSV output to a file
// const ws = fs.createWriteStream('outputData.csv');
// write(csvRows, { headers: true }).pipe(ws).on('finish', () => {
// console.log("CSV file has been written.");
// });
// };

interface BlockData {
blockNumber: number;
blockTimestamp: number;
Expand Down Expand Up @@ -174,6 +88,7 @@ type OutputDataSchemaRow = {
token_address: string;
token_balance: bigint;
token_symbol: string;
usd_price: number;
};

export const getUserTVLByBlock = async (blocks: BlockData) => {
Expand All @@ -184,7 +99,7 @@ export const getUserTVLByBlock = async (blocks: BlockData) => {
blockNumber,
"",
"",
CHAINS.LINEA_ID,
CHAINS.LINEA,
PROTOCOLS.SECTA,
AMM_TYPES.SECTAV3
);
Expand All @@ -193,19 +108,19 @@ export const getUserTVLByBlock = async (blocks: BlockData) => {

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

let v2LpValue = await getV2LpValue(
RPC_URLS[CHAINS.LINEA_ID],
RPC_URLS[CHAINS.LINEA],
pairs,
mintedAddresses,
blockNumber
Expand All @@ -229,16 +144,15 @@ export const getUserTVLByBlock = async (blocks: BlockData) => {
.toNumber()
),
token_symbol: "",
usd_price: 0,
});
});
});

return csvRows;
};

/*readBlocksFromCSV(
path.resolve(__dirname, "../../block_numbers.tsv")
)
/*readBlocksFromCSV(path.resolve(__dirname, "../block_numbers_secta.tsv"))
.then(async (blocks) => {
console.log(blocks);
const allCsvRows: any[] = []; // Array to accumulate CSV rows for all blocks
Expand Down
22 changes: 12 additions & 10 deletions adapters/secta/src/sdk/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const enum CHAINS{
LINEA_ID = 59144,
export const enum CHAINS {
LINEA = 59144,
}
export const enum PROTOCOLS{
SECTA = 0,
Expand All @@ -11,15 +11,17 @@ export const enum AMM_TYPES{
}

export const SUBGRAPH_URLS = {
[CHAINS.LINEA_ID]: {
[CHAINS.LINEA]: {
[PROTOCOLS.SECTA]: {
[AMM_TYPES.SECTAV3]: "https://api.studio.thegraph.com/query/66239/secta-linea-exchange-v3/version/latest",
[AMM_TYPES.SECTAV3]:
"https://api.studio.thegraph.com/query/66239/secta-linea-exchange-v3/version/latest",
// "https://gateway-arbitrum.network.thegraph.com/api/3700f7806f624898da7631bb01f5253f/subgraphs/id/DQz9g5ZRSiprkXXCRwRSTjh6J5gsRMuhr8TymEo1pZe6",
[AMM_TYPES.SECTAV2]: "https://api.studio.thegraph.com/query/66239/secta-linea-exchange-v2/version/latest"
[AMM_TYPES.SECTAV2]:
"https://api.studio.thegraph.com/query/66239/secta-linea-exchange-v2/version/latest",
// "https://gateway-arbitrum.network.thegraph.com/api/3700f7806f624898da7631bb01f5253f/subgraphs/id/4YKqZQ3pH5wZ3seW2ojc1o5HxoJVYQ6UBdunW8ovJCBz",
}
}
}
},
},
};
export const RPC_URLS = {
[CHAINS.LINEA_ID]: "https://rpc.linea.build/"
}
[CHAINS.LINEA]: "https://rpc.linea.build/",
};
Loading

0 comments on commit b824833

Please sign in to comment.