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

fix: integrate contract query #8

Merged
merged 10 commits into from
Jun 27, 2024
Merged

Conversation

CarlWiles
Copy link
Contributor

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);
        });
        ```
      
    • Your code is handling Pagination to make sure all data for a given block is returned

  2. Output data

    • Created a folder test on the same level as src and put sample outputData.csv with 15-20 records generated by your code
    • 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.

@melotik
Copy link
Contributor

melotik commented Jun 26, 2024

@CarlWiles could you resolve the conflicts in your branch? Thanks!

Copy link
Contributor

@melotik melotik left a comment

Choose a reason for hiding this comment

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

I am getting a response and there is data there. I think there are some issues with the decimals (maybe on converting the exchange rate?):

protocol,date,block_number,user_address,market,supply_token,borrow_token
RhoMarkets,1719322991,6913571,0xf874afa0b950270dc702740904d103822307f028,0xad3d07d431b85b525d81372802504fa18dbd554c,0.046775996935733383,0.23387994345100485

This first row is off by 1 decimal 0.023388326781754284
image

adapters/rhomarkets/src/sdk/config.ts Outdated Show resolved Hide resolved
adapters/rhomarkets/src/sdk/index.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@melotik melotik left a comment

Choose a reason for hiding this comment

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

lgtm, nice work @CarlWiles

@melotik melotik merged commit f16895b into delta-hq:main Jun 27, 2024
1 check passed
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