Skip to content

Commit 013bdee

Browse files
committed
Initial commit
0 parents  commit 013bdee

File tree

16 files changed

+27268
-0
lines changed

16 files changed

+27268
-0
lines changed

.env.example

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

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
.env
3+
coverage
4+
coverage.json
5+
typechain
6+
7+
#Hardhat files
8+
cache
9+
artifacts
10+
11+
output/*.json

.vscode/launch.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "pwa-node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
// "program": "${workspaceFolder}\\scripts\\querypairs.js"
15+
"program": "${workspaceFolder}\\scripts\\querytokens.js"
16+
}
17+
]
18+
}

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Basic Sample Hardhat Project
2+
3+
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts.
4+
5+
Try running some of the following tasks:
6+
7+
```shell
8+
npx hardhat accounts
9+
npx hardhat compile
10+
npx hardhat clean
11+
npx hardhat test
12+
npx hardhat node
13+
node scripts/sample-script.js
14+
npx hardhat help
15+
```

appconfigs.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"network": "mumbai",
3+
"dex": "quickswap",
4+
"pairsChunkSize": 1000,
5+
"cooldownMs": 1000,
6+
"tokensChunkSize": 10,
7+
"quickswapFactoryMumbai": "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32",
8+
"outputPath": "./output"
9+
}

contracts/UniswapV2Query.sol

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
pragma solidity ^0.8.0;
2+
3+
import "@openzeppelin/contracts/access/Ownable.sol";
4+
5+
interface IUniswapV2Factory {
6+
function getPair(address tokenA, address tokenB) external view returns (address pair);
7+
function allPairs(uint256) external view returns (address pair);
8+
function allPairsLength() external view returns (uint256);
9+
}
10+
11+
interface IUniswapV2Pair {
12+
function token0() external view returns (address);
13+
function token1() external view returns (address);
14+
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
15+
}
16+
17+
interface IERC20 {
18+
function name() external view returns (string memory);
19+
function symbol() external view returns (string memory);
20+
function decimals() external view returns (uint8);
21+
function totalSupply() external view returns (uint);
22+
function balanceOf(address owner) external view returns (uint);
23+
function allowance(address owner, address spender) external view returns (uint);
24+
}
25+
26+
contract UniswapV2Query is Ownable {
27+
28+
struct Token {
29+
address address_;
30+
string symbol;
31+
string name;
32+
uint8 decimals;
33+
}
34+
35+
function getPairsLenght(address factoryAddr) external onlyOwner view returns (uint256) {
36+
IUniswapV2Factory factory = IUniswapV2Factory(factoryAddr);
37+
return factory.allPairsLength();
38+
}
39+
40+
function getPairsByRange(address factoryAddr, uint256 fromIndex, uint256 toIndex) external onlyOwner view returns (address[3][] memory) {
41+
require(fromIndex <= toIndex, "fromIndex cannot be greater than toIndex");
42+
IUniswapV2Factory factory = IUniswapV2Factory(factoryAddr);
43+
uint256 _length = factory.allPairsLength();
44+
require (toIndex < _length, "toIndex cannot be greater than all pairs length");
45+
uint256 quantity = (toIndex - fromIndex) + 1;
46+
address[3][] memory result = new address[3][](quantity);
47+
for (uint256 i = 0; i < quantity; i++) {
48+
IUniswapV2Pair pair = IUniswapV2Pair(factory.allPairs(fromIndex + i));
49+
result[i][0] = pair.token0();
50+
result[i][1] = pair.token1();
51+
result[i][2] = address(pair);
52+
}
53+
return result;
54+
}
55+
56+
function getERC20Token(address address_) public onlyOwner view returns (Token memory) {
57+
Token memory result;
58+
IERC20 token = IERC20(address_);
59+
result.address_ = address_;
60+
try token.symbol() returns (string memory s) {
61+
result.symbol = s;
62+
} catch { }
63+
try token.name() returns (string memory n) {
64+
result.name = n;
65+
} catch { }
66+
try token.decimals() returns (uint8 d) {
67+
result.decimals = d;
68+
} catch { }
69+
return result;
70+
}
71+
72+
function getERC20Tokens(address[] calldata tokens) external onlyOwner view returns (Token[] memory) {
73+
Token[] memory result = new Token[](tokens.length);
74+
for (uint256 i = 0; i < tokens.length; i++) {
75+
result[i] = getERC20Token(tokens[i]);
76+
}
77+
return result;
78+
}
79+
}

hardhat.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require("@nomiclabs/hardhat-waffle");
2+
require("dotenv").config();
3+
const configs = require('./appconfigs.json');
4+
5+
// This is a sample Hardhat task. To learn how to create your own go to
6+
// https://hardhat.org/guides/create-task.html
7+
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
8+
const accounts = await hre.ethers.getSigners();
9+
10+
for (const account of accounts) {
11+
console.log(account.address);
12+
}
13+
});
14+
15+
// You need to export an object to set up your config
16+
// Go to https://hardhat.org/config/ to learn more
17+
18+
/**
19+
* @type import('hardhat/config').HardhatUserConfig
20+
*/
21+
module.exports = {
22+
solidity: {
23+
compilers: [
24+
{ version: "0.8.0" }
25+
]
26+
},
27+
networks: {
28+
mumbai: {
29+
url: process.env[`PROVIDER_URL_${configs.network.toUpperCase()}`],
30+
accounts: [process.env.ACCOUNT_KEY]
31+
}
32+
}
33+
};

output/.keepdir

Whitespace-only changes.

0 commit comments

Comments
 (0)