Skip to content

Commit 05d7780

Browse files
authored
Merge pull request #10 from delta-hq/dylan/refactor
Refactor & add perps support
2 parents f16895b + f0765c7 commit 05d7780

File tree

7 files changed

+188
-357
lines changed

7 files changed

+188
-357
lines changed

.github/pull_request_template.md

+18-106
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,24 @@
1-
## Title:
2-
<!--please follow this pattern for PR title "protocol_name : protocol_category : other comments". Example - "uniswap: dex : tvl by user"-->
3-
- [ ] Pattern for PR title "protocol_name : protocol_category : other comments". Example - "uniswap: dex : tvl by user"
1+
# Protocol Checklist
42

5-
## Checklist before requesting a review
6-
1. **index.ts file**
3+
Welcome! Thank you for submitting a PR with your protocol data. The [README](../README.md) should serve as a general guide for you. But please follow this checklist to ensure you have everything.
74

8-
- [ ] **Contains function**
5+
- [ ] Read the [README](../README.md) and explore the other adapters (see `adapters/example`)
6+
- [ ] See the schema that we are requesting based on your protocol type (currently supporting, lending and perps)
7+
- [ ] Submit a PR with progress with a new folder containing your adapter (in `adapter/{protocol-name}`)
8+
- [ ] Build your adapter
9+
- [ ] Ensure your `package.json` has a `start` command that executes the proper code
10+
- [ ] Follow the schema/output format, standard input file format, and standard function inputs
11+
- [ ] Ensure the adapter runs and executes in the proper workflow (see: `How to execute this project?` in [README](../README.md))
12+
- [ ] QA your data
13+
- [ ] Notify our team when you are ready for a review!
914

10-
```export const getUserTVLByBlock = async (blocks: BlockData) => {
11-
const { blockNumber, blockTimestamp } = blocks
12-
// Retrieve data using block number and timestamp
13-
// YOUR LOGIC HERE
14-
15-
return csvRows
15+
## Protocol Notes
1616

17-
};
18-
```
19-
- [ ] **getUserTVLByBlock function takes input with this schema**
20-
21-
```
22-
interface BlockData {
23-
blockNumber: number;
24-
blockTimestamp: number;
25-
}
26-
```
27-
- [ ] **getUserTVLByBlock function returns output in this schema**
17+
### Adapter Logic Flow
18+
<!--- Please note the high level flow / architecture of your adapter -->
2819

29-
```
30-
const csvRows: OutputDataSchemaRow[] = [];
20+
### QA Notes
21+
<!--- Please provide any notes or unique cases from your QA -->
3122

32-
type OutputDataSchemaRow = {
33-
block_number: number; //block_number which was given as input
34-
timestamp: number; // block timestamp which was given an input, epoch format
35-
user_address: string; // wallet address, all lowercase
36-
token_address: string; // token address all lowercase
37-
token_balance: bigint; // token balance, raw amount. Please dont divide by decimals
38-
token_symbol: string; //token symbol should be empty string if it is not available
39-
usd_price: number; //assign 0 if not available
40-
};
41-
```
42-
- [ ] **contains function**
43-
44-
```
45-
const readBlocksFromCSV = async (filePath: string): Promise<BlockData[]> => {
46-
const blocks: BlockData[] = [];
47-
48-
await new Promise<void>((resolve, reject) => {
49-
fs.createReadStream(filePath)
50-
.pipe(csv()) // Specify the separator as '\t' for TSV files
51-
.on('data', (row) => {
52-
const blockNumber = parseInt(row.number, 10);
53-
const blockTimestamp = parseInt(row.timestamp, 10);
54-
if (!isNaN(blockNumber) && blockTimestamp) {
55-
blocks.push({ blockNumber: blockNumber, blockTimestamp });
56-
}
57-
})
58-
.on('end', () => {
59-
resolve();
60-
})
61-
.on('error', (err) => {
62-
reject(err);
63-
});
64-
});
65-
66-
return blocks;
67-
};
68-
69-
```
70-
- [ ] **has this code**
71-
72-
```
73-
readBlocksFromCSV('hourly_blocks.csv').then(async (blocks: any[]) => {
74-
console.log(blocks);
75-
const allCsvRows: any[] = [];
76-
77-
for (const block of blocks) {
78-
try {
79-
const result = await getUserTVLByBlock(block);
80-
allCsvRows.push(...result);
81-
} catch (error) {
82-
console.error(`An error occurred for block ${block}:`, error);
83-
}
84-
}
85-
await new Promise((resolve, reject) => {
86-
const ws = fs.createWriteStream(`outputData.csv`, { flags: 'w' });
87-
write(allCsvRows, { headers: true })
88-
.pipe(ws)
89-
.on("finish", () => {
90-
console.log(`CSV file has been written.`);
91-
resolve;
92-
});
93-
});
94-
95-
}).catch((err) => {
96-
console.error('Error reading CSV file:', err);
97-
});
98-
```
99-
- [ ] **Your code is handling Pagination to make sure all data for a given block is returned**
100-
101-
2. **Output data**
102-
- [ ] Created a folder test on the same level as src and put sample outputData.csv with 15-20 records generated by your code
103-
- [ ] Data is returned for underlying tokens only. Not for special tokens (lp/veTokens etc)
104-
- [ ] Follows the exact sequence mentioned in OutputDataSchemaRow . This is needed as we want same column ordering in output csv
105-
- Value of each field is :
106-
- [ ] block_number *is same as input block number. This signifies TVL is as of this block_number.*
107-
- [ ] timestamp is same as input timestamp. This signifies TVL is as of this timestamp. It is in epoch format.
108-
- [ ] user_address is in lowercase
109-
- [ ] token_address is in lowercase
110-
- [ ] token_balance is in raw amount. Please dont divide by decimals.
111-
- [ ] token_symbol value if present, empty string if value is not available.
112-
- [ ] usd_price if value is available, 0 if value is not available.
23+
### General Notes
24+
<!--- Please dictate anything we should know about your adapter -->

0 commit comments

Comments
 (0)