From a4b7b0bcbbb351889ece82e96831dcb6746e108b Mon Sep 17 00:00:00 2001 From: byeongsu-hong Date: Mon, 26 Aug 2024 23:38:51 +0900 Subject: [PATCH 1/2] feat(mitosis): add miezETH vault and update subgraph url --- adapters/mitosis/src/index.ts | 101 ++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/adapters/mitosis/src/index.ts b/adapters/mitosis/src/index.ts index b58c01b5..ab46dff8 100644 --- a/adapters/mitosis/src/index.ts +++ b/adapters/mitosis/src/index.ts @@ -1,13 +1,11 @@ -import fs from 'fs'; +import fs from "fs"; import { write } from "fast-csv"; import csv from "csv-parser"; -const assetWhitelist = [ - 'miweETH', - 'miuniETH', -]; +const assetWhitelist = ["miezETH", "miweETH", "miuniETH"]; -const GRAPHQL_ENDPOINT = "https://api.goldsky.com/api/public/project_clxioqhjdzy1901wmgqmp2ygj/subgraphs/mitosis-linea-lxp/1.1.1/gn"; +const GRAPHQL_ENDPOINT = + "https://api.goldsky.com/api/public/project_clxioqhjdzy1901wmgqmp2ygj/subgraphs/mitosis-linea-lxp/1.1.2/gn"; const makeBalancesQuery = (blockNumber: number, next = "") => `query { tokenBalances( @@ -69,25 +67,35 @@ async function post(url: string, query: any): Promise<{ data: T }> { }); return response.json(); -}; +} -const toOutput = ({ blockNumber, blockTimestamp }: BlockData, { tokenBalances }: TokenBalancesResponse): OutputDataSchemaRow[] => - tokenBalances.map((v) => ({ - block_number: blockNumber, - timestamp: blockTimestamp, - user_address: v.account.id, - token_address: v.token.id, - token_balance: BigInt(v.value), - token_symbol: v.token.symbol, - usd_price: 0 - })).filter((v) => assetWhitelist.includes(v.token_symbol)); - -export const getUserTVLByBlock = async (blocks: BlockData): Promise => { +const toOutput = ( + { blockNumber, blockTimestamp }: BlockData, + { tokenBalances }: TokenBalancesResponse +): OutputDataSchemaRow[] => + tokenBalances + .map((v) => ({ + block_number: blockNumber, + timestamp: blockTimestamp, + user_address: v.account.id, + token_address: v.token.id, + token_balance: BigInt(v.value), + token_symbol: v.token.symbol, + usd_price: 0, + })) + .filter((v) => assetWhitelist.includes(v.token_symbol)); + +export const getUserTVLByBlock = async ( + blocks: BlockData +): Promise => { let next = ""; let output: OutputDataSchemaRow[] = []; while (true) { - const { data: resp } = await post(GRAPHQL_ENDPOINT, makeBalancesQuery(blocks.blockNumber, next)); + const { data: resp } = await post( + GRAPHQL_ENDPOINT, + makeBalancesQuery(blocks.blockNumber, next) + ); if (resp.tokenBalances.length === 0) break; output = output.concat(toOutput(blocks, resp)); @@ -103,17 +111,17 @@ const readBlocksFromCSV = async (filePath: string): Promise => { await new Promise((resolve, reject) => { fs.createReadStream(filePath) .pipe(csv()) // Specify the separator as '\t' for TSV files - .on('data', (row) => { + .on("data", (row) => { const blockNumber = parseInt(row.number, 10); const blockTimestamp = parseInt(row.timestamp, 10); if (!isNaN(blockNumber) && blockTimestamp) { blocks.push({ blockNumber: blockNumber, blockTimestamp }); } }) - .on('end', () => { + .on("end", () => { resolve(); }) - .on('error', (err) => { + .on("error", (err) => { reject(err); }); }); @@ -121,28 +129,29 @@ const readBlocksFromCSV = async (filePath: string): Promise => { return blocks; }; -readBlocksFromCSV('hourly_blocks.csv').then(async (blocks: any[]) => { - console.log(blocks); - const allCsvRows: any[] = []; - - for (const block of blocks) { - try { - const result = await getUserTVLByBlock(block); - allCsvRows.push(...result); - } catch (error) { - console.error(`An error occurred for block ${block}:`, error); +readBlocksFromCSV("hourly_blocks.csv") + .then(async (blocks: any[]) => { + console.log(blocks); + const allCsvRows: any[] = []; + + for (const block of blocks) { + try { + const result = await getUserTVLByBlock(block); + allCsvRows.push(...result); + } 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 }) - .pipe(ws) - .on("finish", () => { - console.log(`CSV file has been written.`); - resolve; - }); + await new Promise((resolve, reject) => { + const ws = fs.createWriteStream(`outputData.csv`, { flags: "w" }); + write(allCsvRows, { headers: true }) + .pipe(ws) + .on("finish", () => { + console.log(`CSV file has been written.`); + resolve; + }); + }); + }) + .catch((err) => { + console.error("Error reading CSV file:", err); }); - -}).catch((err) => { - console.error('Error reading CSV file:', err); -}); From c8eb42f7a4254167ddeb95bee285bc79960ef906 Mon Sep 17 00:00:00 2001 From: byeongsu-hong Date: Tue, 27 Aug 2024 00:18:42 +0900 Subject: [PATCH 2/2] feat(mitosis): support ezETH --- adapters/mitosis/hourly_blocks.csv | 2 ++ adapters/mitosis/src/index.ts | 2 +- adapters/mitosis/test/sample_output_data.csv | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/adapters/mitosis/hourly_blocks.csv b/adapters/mitosis/hourly_blocks.csv index c2339b72..13e3d1fb 100644 --- a/adapters/mitosis/hourly_blocks.csv +++ b/adapters/mitosis/hourly_blocks.csv @@ -9,3 +9,5 @@ number,timestamp 4881275,1716263772 4891275,1716233771 6653493,1720710200 +8635572,1724682125 +8635660,1724682301 diff --git a/adapters/mitosis/src/index.ts b/adapters/mitosis/src/index.ts index ab46dff8..d0a426b2 100644 --- a/adapters/mitosis/src/index.ts +++ b/adapters/mitosis/src/index.ts @@ -5,7 +5,7 @@ import csv from "csv-parser"; const assetWhitelist = ["miezETH", "miweETH", "miuniETH"]; const GRAPHQL_ENDPOINT = - "https://api.goldsky.com/api/public/project_clxioqhjdzy1901wmgqmp2ygj/subgraphs/mitosis-linea-lxp/1.1.2/gn"; + "https://api.goldsky.com/api/public/project_clxioqhjdzy1901wmgqmp2ygj/subgraphs/mitosis-linea-lxp/1.1.3/gn"; const makeBalancesQuery = (blockNumber: number, next = "") => `query { tokenBalances( diff --git a/adapters/mitosis/test/sample_output_data.csv b/adapters/mitosis/test/sample_output_data.csv index 9ae72039..029f5047 100644 --- a/adapters/mitosis/test/sample_output_data.csv +++ b/adapters/mitosis/test/sample_output_data.csv @@ -20,3 +20,17 @@ block_number,timestamp,user_address,token_address,token_balance,token_symbol,usd 6653493,1720710200,0xfffff9b1c2c387b1e3d19af292d91d913374f42b,0x3478de5e82431676c87113001bbeeb359cb5eaa5,9164866447070119,miweETH,0 6653493,1720710200,0x1206608fdc30925492b9afcd32aea0a9e579a03a,0x56ced49205e5d9b4d8d9b29f4abfbe7bb8b08768,3733150882302883,miuniETH,0 6653493,1720710200,0x13a4b4f78ab4b93ec1cecf963e19f26f4214578e,0x56ced49205e5d9b4d8d9b29f4abfbe7bb8b08768,33581033672474670,miuniETH,0 +8635572,1724682125,0xefad0d64546c5bf9019b5815f68535488d025c61,0x56ced49205e5d9b4d8d9b29f4abfbe7bb8b08768,263245513807494718,miuniETH,0 +8635572,1724682125,0xf6ccf8751fd02de2e14cdf0ff0aa36d6e7a1ab28,0x56ced49205e5d9b4d8d9b29f4abfbe7bb8b08768,27232824043906343,miuniETH,0 +8635572,1724682125,0xf6ceecf804eb2e0add76f1f8e00ca903fa30ffd5,0x56ced49205e5d9b4d8d9b29f4abfbe7bb8b08768,38992690497099636,miuniETH,0 +8635572,1724682125,0xb517d68a0a0ea0619423a03fc043537185431b83,0x96d6ce4e83db947ff6bd1ab0b377f23cd5d9ec2d,1000000000000000,miezETH,0 +8635660,1724682301,0x00000001b01122945d67cf7c972f1a2063ca4008,0x3478de5e82431676c87113001bbeeb359cb5eaa5,221020382526712301,miweETH,0 +8635660,1724682301,0x00000002d88f9b3f4eb303564817fff4adcde46f,0x3478de5e82431676c87113001bbeeb359cb5eaa5,515016007998652343,miweETH,0 +8635660,1724682301,0x0000000452bbfc5541279949e5e9400821a0c92d,0x3478de5e82431676c87113001bbeeb359cb5eaa5,164229002009667173,miweETH,0 +8635660,1724682301,0xfffc36c3134daaa997d499b0ee918dfff1d705c3,0x3478de5e82431676c87113001bbeeb359cb5eaa5,129504578905856451,miweETH,0 +8635660,1724682301,0xfffcbafd962feb657b5fd1f54bc2f58c18977752,0x3478de5e82431676c87113001bbeeb359cb5eaa5,0,miweETH,0 +8635660,1724682301,0xfffff9b1c2c387b1e3d19af292d91d913374f42b,0x3478de5e82431676c87113001bbeeb359cb5eaa5,9164866447070119,miweETH,0 +8635660,1724682301,0x1206608fdc30925492b9afcd32aea0a9e579a03a,0x56ced49205e5d9b4d8d9b29f4abfbe7bb8b08768,3733150882302883,miuniETH,0 +8635660,1724682301,0x13a4b4f78ab4b93ec1cecf963e19f26f4214578e,0x56ced49205e5d9b4d8d9b29f4abfbe7bb8b08768,33581033672474670,miuniETH,0 +8635660,1724682301,0x1429ae34844b7dc55e33817f8b42085b49afe453,0x56ced49205e5d9b4d8d9b29f4abfbe7bb8b08768,108294776457294118,miuniETH,0 +8635660,1724682301,0xb517d68a0a0ea0619423a03fc043537185431b83,0x96d6ce4e83db947ff6bd1ab0b377f23cd5d9ec2d,0,miezETH,0