This project demonstrates how to use Hardhat and Solidity to create and deploy an arbitrage scanner to scrape data from multiple decentralized exchanges in a single RPC call. This gives you the ability to scrape and store large amounts of data allowing for arbitrage route analysis with minimal RPC calls.
Please see .example.env file and recreate a .env in the same format.
Note
The project will not run properly without a valid Infura API key and seed phrase in .env file. Seed phrase wallet can be random, it does NOT need a balance.
yarn
npx hardhat test-
ArbUtils Library: manages decoding of exchange data. Deployment
-
DecimalUtils Library: manages token decimal calculations and normalizing exchange rates. Deployment
-
SlippageUtils Library: manages calculation of slippage. Deployment
-
QuickswapV3Utils Library: manages interactions with QuickswapV3 contracts. Deployment
-
UniswapV2Utils Library: manages interactions with UniswapV2 contracts. Deployment
-
UniswapV3Utils Library: manages interactions with UniswapV3 contracts. Deployment
-
ArbitrageScanner: contract that we interact with. Deployment
You may interact with these contracts already deployed on Polygon, or you may extend these contracts by adding additional exchange protocols and re-deploying them on the EVM network(s) of your choice.
Try running some of the following tasks:
Get UniswapV2 pair counts, pair addresses, token addresses
npx hardhat run scripts/scrapers/scrapeV2PairCounts.ts --network polygonnpx hardhat run scripts/scrapers/scrapeV2PairAddresses.ts --network polygon Get normalized exchange rate(s) using a base asset and an array of potential pairs.
npx hh run scripts/exchange-rates/getExchangeRate.ts --network polygon npx hh run scripts/exchange-rates/getMultipleExchangeRates.ts --network polygon Validate prospective tokens by checking their liquidity vs other assets of your choice.
npx hh run scripts/validator/validateTokens.ts --network polygon Simulate the results of a multi-hop, multi-exchange trade path.
npx hh run scripts/simulate-trade/simulateTrade.ts --network polygon The scanner contract allows for multiple exchanges to be added. At deployment, the following exchanges were loaded.
| DexId | Exchange | Fee |
|---|---|---|
| 0 | QuickswapV2 | 25 |
| 1 | QuickswapV3 | 3000* |
| 2 | UniswapV3 | 500, 3000, 10000 |
Note
QuickswapV3 has dynamic fees. Number used is a placeholder.
To add an exchange, you'd simply call this method on your contract:
function setDexValues(
uint256[] memory _dexIds,
address[] memory _factories,
address[] memory _routers,
uint8[] memory _protocols
) public onlyOwner {
for (uint256 i = 0; i < _dexIds.length; i++) {
factories[_dexIds[i]] = _factories[i];
routers[_dexIds[i]] = _routers[i];
protocol[_dexIds[i]] = _protocols[i];
}
}You could also deploy additional libraries to support additional exchange protocols and then add those protocols to the ArbitrageScanner contract.