delta-hq / l2-lxp-liquidity-reward

5 stars 85 forks source link

dodo: dex : tvl by user #252

Closed xxamxx closed 4 months ago

xxamxx commented 4 months ago

Title:

Checklist before requesting a review

  1. index.ts file

    • [x] Contains function

      ```export const getUserTVLByBlock = async (blocks: BlockData) => {
          const { blockNumber, blockTimestamp } = blocks
              //    Retrieve data using block number and timestamp
              // YOUR LOGIC HERE
      
          return csvRows
      
      };
      ``` 
      • [x] getUserTVLByBlock function takes input with this schema

            interface BlockData {
                blockNumber: number;
                blockTimestamp: number;
            }
      • [x] getUserTVLByBlock function returns output in this schema

        ```
        const csvRows: OutputDataSchemaRow[] = [];
        
        type OutputDataSchemaRow = {
            block_number: number;  //block_number which was given as input
            timestamp: number;     // block timestamp which was given an input, epoch format
            user_address: string;   // wallet address, all lowercase
            token_address: string;  // token address all lowercase
            token_balance: bigint;  // token balance, raw amount. Please dont divide by decimals
            token_symbol: string; //token symbol should be empty string if it is not available
            usd_price: number; //assign 0 if not available
        };
        ```
      • [x] contains function

            const readBlocksFromCSV = async (filePath: string): Promise<BlockData[]> => {
            const blocks: BlockData[] = [];
        
            await new Promise<void>((resolve, reject) => {
                fs.createReadStream(filePath)
                .pipe(csv()) // Specify the separator as '\t' for TSV files
                .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', () => {
                    resolve();
                })
                .on('error', (err) => {
                    reject(err);
                });
            });
        
            return blocks;
            };
        
      • [x] has this code

        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;
                });
        });
        
        }).catch((err) => {
        console.error('Error reading CSV file:', err);
        });
      • [x] Your code is handling Pagination to make sure all data for a given block is returned
  2. Output data

    • [x] Created a folder test on the same level as src and put sample outputData.csv with 15-20 records generated by your code
    • [x] Data is returned for underlying tokens only. Not for special tokens (lp/veTokens etc)
    • [x] Follows the exact sequence mentioned in OutputDataSchemaRow . This is needed as we want same column ordering in output csv
    • Value of each field is :
      • [x] block_number is same as input block number. This signifies TVL is as of this block_number.
      • [x] timestamp is same as input timestamp. This signifies TVL is as of this timestamp. It is in epoch format.
      • [x] user_address is in lowercase
      • [x] token_address is in lowercase
      • [x] token_balance is in raw amount. Please dont divide by decimals.
      • [x] token_symbol value if present, empty string if value is not available.
      • [x] usd_price if value is available, 0 if value is not available.
0xroll commented 4 months ago

hey @xxamxx

does this remove inactive liquidity? (positions that are not in range)

xxamxx commented 4 months ago

@0xroll how define inactive liquidity"?

0xroll commented 4 months ago

@xxamxx are there any pools with concentrated liquidity model in here?

xxamxx commented 4 months ago

@0xroll yes we have. have any problem with that?

0xroll commented 4 months ago

@xxamxx yes, we need to remove inactive liquidity (for uniswap clmm they are identified as out of range)

xxamxx commented 4 months ago

@0xroll we have not this problem, we have a concentrated liquidity function, but not through the Tick structure but through algorithms.reading is more similar to AMM, and you can read it directly through base reserve and quote reserve.

0xroll commented 4 months ago

@xxamxx can users provide liquidity that "does nothing?" (eg: adding weth liquidity priced at 10,000 usdc/weth)

xxamxx commented 4 months ago

@0xroll "does nothing" it's mean no swap? that's yes, we may have this liquidity and i can filter that.

0xroll commented 4 months ago

@0xroll "does nothing" it's mean no swap? that's yes, we may have this liquidity and i can filter that.

using uniswap v3 as an example here.

if someone provides a liquidity that is out of range (eg, current ETH price is 3.5k but he priced it at 5k) , this liquidity is basicially not providing any EV, just sitting on the contract "doing nothing".

im not that familiar with how dodo works, if there is something similar to this then yes it should be removed

xxamxx commented 4 months ago

@0xroll i got it!we have not for that, please merge this pr.

xxamxx commented 4 months ago

@0xroll thank you

0xroll commented 4 months ago

@xxamxx

hey, can you make sure those code are in there. those that in this checklist. you commented them out

artvirsnieks commented 3 months ago

Hello, I am interested in the concentrated liquidity pools protocol.