Skip to content

Commit

Permalink
Merge pull request #316 from delta-hq/stargate-fix
Browse files Browse the repository at this point in the history
[stargate] add delay between calls
  • Loading branch information
0xroll authored Nov 2, 2024
2 parents f5f8be2 + 4d6cfa1 commit 9d7d5e2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
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

0 comments on commit 9d7d5e2

Please sign in to comment.