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

[stargate] add delay between calls #316

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adapters/stargate/hourly_blocks.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
number,timestamp
5154879,1717513197
11535322,1717513197
11537120,1730541599
20 changes: 10 additions & 10 deletions adapters/stargate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ const readBlocksFromCSV = async (filePath: string): Promise<BlockData[]> => {

readBlocksFromCSV(path.resolve(__dirname, "../hourly_blocks.csv"))
.then(async (blocks) => {
const streams = blocks.flatMap((block) => [
new PositionsStream(block, POSITIONS_V1_SUBGRAPH_URL),
new PositionsStream(block, POSITIONS_V2_SUBGRAPH_URL),
]);

mergeStreams(streams);
})
.catch((err) => {
console.error("Error reading CSV file:", err);
});
for (const block of blocks) {
// Sequentially process each stream for the block
const v2Stream = new PositionsStream(block, POSITIONS_V2_SUBGRAPH_URL);
const v1Stream = new PositionsStream(block, POSITIONS_V1_SUBGRAPH_URL);
await mergeStreams([v1Stream, v2Stream]);
}
})
.catch((err) => {
console.error("Error reading CSV file:", err);
});

function mergeStreams(positionStreams: PositionsStream[]) {
const csvWriteStream = fs.createWriteStream(`outputData.csv`, {
Expand Down
2 changes: 1 addition & 1 deletion adapters/stargate/src/sdk/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const POSITIONS_V2_SUBGRAPH_URL =

export const client = createPublicClient({
chain: linea,
transport: http(`https://linea-mainnet.infura.io/v3/${process.env.OPENBLOCK_LINEA_INFURA_API_KEY}`, {
transport: http(`https://rpc.linea.build`, {
retryCount: 5,
timeout: 60_000,
}),
Expand Down
2 changes: 2 additions & 0 deletions adapters/stargate/src/sdk/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { client } from "./config";
import { Position } from "./types";

const WHITELISTED_TOKEN_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
const FETCH_DELAY_MS = 5000

export const getTimestampAtBlock = async (blockNumber: number) => {
const block = await client.getBlock({
Expand All @@ -23,6 +24,7 @@ export class PositionsStream extends Readable {
}

async _read() {
await new Promise(resolve => setTimeout(resolve, FETCH_DELAY_MS));
const query = `
query {
farmPositions(
Expand Down
Loading