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

MYX Finance : DEX : tvl by user #135

Merged
merged 4 commits into from
May 20, 2024
Merged

MYX Finance : DEX : tvl by user #135

merged 4 commits into from
May 20, 2024

Conversation

marvin6en
Copy link
Contributor

@marvin6en marvin6en commented May 16, 2024

Title:

  • Pattern for PR title "protocol_name : protocol_category : other comments". Example - "uniswap: dex : tvl by user"

Checklist before requesting a review

  1. index.ts file

    • Contains function

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

        ``` 
            interface BlockData {
                blockNumber: number;
                blockTimestamp: number;
            }
        ```
      
    • 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
            };
            ```
      
    • 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;
            };
      
        ```
      
    • 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);
        });
      
  2. Output data

    • Data is returned for underlying tokens only. Not for special tokens (lp/veTokens etc)
    • Follows the exact sequence mentioned in OutputDataSchemaRow . This is needed as we want same column ordering in output csv
    • Value of each field is :
      • block_number is same as input block number. This signifies TVL is as of this block_number.
      • timestamp is same as input timestamp. This signifies TVL is as of this timestamp. It is in epoch format.
      • user_address is in lowercase
      • token_address is in lowercase
      • token_balance is in raw amount. Please dont divide by decimals.
      • token_symbol value if present, empty string if value is not available.
      • usd_price if value is available, 0 if value is not available.

@marvin6en
Copy link
Contributor Author

@marvin6en saw the repo.

looks like currently the adapter is returning the lp address and lp balance?

we will need them to be on underlying token asset level :

eg : btc - usdc pair -> btc and usdc separately.

and sum up these underlying token balance, to get the total balance of each asset.

token balances will need bigINT (raw number)

@0xroll Already updated as requested✅

@marvin6en marvin6en changed the title add myx adapter myx: dex : tvl by user May 16, 2024
@marvin6en marvin6en changed the title myx: dex : tvl by user MYX Finance: DEX : tvl by user May 16, 2024


const getData = async () => {
const snapshotBlocks = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocks should be received as input parameter.

@nitish-91
Copy link
Contributor

@marvin6en You have marked everything on the checklist but i dont see the code taking

  1. block data as input
  2. having getUserTVLByBlock function.
    and many more. Can you please look at the index file of existing protocols and include the differences

@marvin6en
Copy link
Contributor Author

@marvin6en You have marked everything on the checklist but i dont see the code taking

  1. block data as input
  2. having getUserTVLByBlock function.
    and many more. Can you please look at the index file of existing protocols and include the differences

@nitish-91 It has been fixed, please check again

@marvin6en marvin6en changed the title MYX Finance: DEX : tvl by user MYX Finance : DEX : tvl by user May 16, 2024
snapshotsMap.forEach((userPositionSnapshotMap => {
userPositionSnapshotMap.forEach((positionSnapshot) => {
userPositionSnapshotsAtBlockData.push({
user_address: positionSnapshot.recipient,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this return multiple block numbers for 1 block input?

Same question for timestamp as well
@marvin6en

Copy link
Contributor Author

@marvin6en marvin6en May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at line 55-58,Already filtered based on blocknumber

@nitish-91 nitish-91 merged commit 628db1c into delta-hq:main May 20, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants