- Liquidity Pools in src/Pool.hxx and Pool.cxx
- Simple Arbitrage Logic defined in src/ArbitrageStrategy.cxx
- Used GTest to add test cases for various scenarios
- Used Google Benchmark to benchmark async calculation and synchronous calculation
- CMake v3.23
- Clang v13.0
- C++20 std
chmod u+x build.sh && ./build.sh
# remove existing build, make build directory and cd inside
rm -rf build && mkdir build && cd build
# init cmake from CMakeLists in project root
cmake -DCMAKEBUILD_TYPE=Relase ..
# build
cmake --build .
Main program takes in user input to set the X and Y values of the two pools and calculates the amount of eth required and profit to make the arbitrage.
❯ ./build/bin/Main
Enter the ETH quantity for Pool A (X_1):
89
Enter the DAI quantity for Pool A (Y_1):
536375
Enter the ETH quantity for Pool B (X_2):
45
Enter the DAI quantity for Pool B (Y_2):
346361
Calculating async call
You will need: 7.57786 ETH; and you will profit: 0.000272033
./build/bin/TestMain
./build/bin/ArbitrageStrategyBenchmark
- Two Uniswap Pools, A and B
- Constant Product Formula:
X_1 * Y_1 = K_1
X_2 * Y_2 = K_2
- Swap fee 0.3%
- added to reserves
- Define data structs of pool status
- add / remove / swap
- maintains status data in-memory
- Define arbitrage calculation logic
- trigger calc in NON-BLOCKING mode
- find how many ETH we need for an arbitrage calculation
- find out profit from trade
- Simulate user's swap transactions (e.g. 100 DAI to ETH in Pool A)
- Testing using GTest
- Benchmark non-blocking calculation
- Benchmarking using Google Benchmark to run benchmark both synchronously and asynchronously
status()
- shows current token quantities and k
add()
- adds token to pool
remove()
- removes token from pool
swap()
- swaps one token for another in a pool
- fee of 0.3% applied
calculate_async()
- return ETH required & potential profit
type: TokenType -> ETH / DAI / LP