Skip to content

Commit 7b69459

Browse files
committed
Implemented failover in querypairs script
1 parent fdec756 commit 7b69459

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
PROVIDER_URL_MUMBAI="your_mumbai_provider_url"
1+
PROVIDER_URL_POLYGON="your_provider_url"
22
ACCOUNT_KEY="your_account_key"
3-
UV2QUERY_ADDRESS_MUMBAI="query_contract_address"
3+
UV2QUERY_ADDRESS_POLYGON="query_contract_address"

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@ Choose a consistent network name across the two configuration files.
99
### .env
1010

1111
```text
12-
PROVIDER_URL_MUMBAI="https://polygon-mumbai.g.alchemy.com/v2/..."
12+
PROVIDER_URL_POLYGON="https://polygon-mainnet.g.alchemy.com/v2/..."
1313
ACCOUNT_KEY="5fa...9f39"
14-
UV2QUERY_ADDRESS_MUMBAI="0x460...7e67"
14+
UV2QUERY_ADDRESS_POLYGON="0x460...7e67"
1515
```
1616

1717
### appconfigs.json
1818

1919
```json
2020
{
21-
"network": "mumbai",
21+
"network": "polygon",
2222
"dex": "quickswap",
23-
"pairsChunkSize": 1000,
24-
"cooldownMs": 1000,
23+
"pairsChunkSize": 500,
24+
"cooldownMs": 2000,
25+
"cooldownAfterFailSec": 3,
2526
"tokensChunkSize": 10,
26-
"quickswapFactoryMumbai": "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32",
27+
"quickswapFactoryPolygon": "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32",
2728
"outputPath": "./output"
2829
}
2930
```
3031

3132
## Usage
3233

33-
- Deploy the contract: `npx hardhat run .\scripts\deploy.js --network mumbai`.
34+
- Deploy the contract: `npx hardhat run .\scripts\deploy.js --network polygon`.
3435

3536
- Set all needed configuration values.
3637

appconfigs.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
2-
"network": "mumbai",
2+
"network": "polygon",
33
"dex": "quickswap",
4-
"pairsChunkSize": 1000,
5-
"cooldownMs": 1000,
4+
"pairsChunkSize": 500,
5+
"cooldownMs": 2000,
6+
"cooldownAfterFailSec": 3,
67
"tokensChunkSize": 10,
78
"quickswapFactoryMumbai": "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32",
9+
"quickswapFactoryPolygon": "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32",
810
"outputPath": "./output"
911
}

scripts/querypairs.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const dex = configs.dex;
1010
const dexDescr = `${dex} (${network})`;
1111
const uv2queryAddress = process.env[`UV2QUERY_ADDRESS_${network.toUpperCase()}`];
1212
const factoryAddress = configs[`${dex}Factory${utils.toTitleCase(network)}`]
13-
const cooldownMs = configs.cooldownMs;
1413

1514
async function main() {
1615
const account = utils.connectAccount(network, process.env.ACCOUNT_KEY);
@@ -23,9 +22,22 @@ async function main() {
2322
for (let r = 0; r < ranges.length; r++) {
2423
const from = ranges[r][0];
2524
const to = ranges[r][1];
26-
console.log(`Getting pairs from ${from} to ${to}`);
27-
const pairsChunk = await uv2query.getPairsByRange(factoryAddress, from, to);
28-
await utils.sleep(cooldownMs);
25+
console.log(`[${[r]}] Getting pairs from ${from} to ${to}`);
26+
let succeeded = false;
27+
let pairsChunk;
28+
try {
29+
pairsChunk = await uv2query.getPairsByRange(factoryAddress, from, to);
30+
succeeded = true;
31+
} catch {
32+
console.log(`ERROR: failed to get pairs for range ${[r]}`);
33+
console.log(`Cooling down for ${configs.cooldownAfterFailSec} sec`);
34+
await utils.sleep(configs.cooldownAfterFailSec * 1000);
35+
r--;
36+
continue;
37+
}
38+
if (succeeded) {
39+
await utils.sleep(configs.cooldownMs);
40+
}
2941
for (let c = 0; c < pairsChunk.length; c++) {
3042
pairs.push({
3143
address: pairsChunk[c][0],

0 commit comments

Comments
 (0)