Simple script that will create a list of token pairs where the base pair is USDC. Iterate through the token pairs to find prices for a given token pair across DEXs. Then perform an arbitrage via an atomic transaction if the arbitrage is profitable after taking gas into consideration. The trade size is 100 USDC by default.
Once the program iterates through the full list of token pairs, it will terminate.
This trade is not currently profitable because it runs on mainnet and gas costs are far higher than the arbitrage profit (although the arb does exist).
Importantly, this program will lose money when it tries to execute an arb where the total gas required is higher than the gas limit. The trade will revert on-chain when it reaches the gas limit and hasn't finished executing. In practice this doesn't happen (on mainnet) because the spread is never higher than the gas cost, so no trade gets executed.
- Update pip if you haven't already
pip install --upgrade pip
- Run
pip install -r requirements.txt
, the main library here that enables our service iseulith-web3
- Configure wallet details in
config.py
(lines 26 & 27) - Copy/paste your refresh token in
config.py
on line 30 - you need to get the refresh token from us if you aren't already a client. - (optional) Set the network you wish to send transactions to, default is mainnet (line 29). The other base URLs are in the docs.
- Fund your wallet with USDC to do the trade and ETH to pay for gas. In reality, the gas cost is much higher than the arb, so it will not execute without adjustments. For testing, you might do arbs of size $1 USDC and budget $30 in Eth for gas, then remove the gas check just to see some executions.
- Run
python3 test_small_usdc_trades.py
; keep in mind web3.py needspython -v 3.9
or older
Run the code and see how it works!
We're providing you with infrastructure and some foundation code to build your own strategies. We do not trade ourselves (it would be a conflict of interest), and so we haven't done the reserach and improvements required to make this code profitable - that is your job.
Here are the areas of improvement we'd suggest looking at first:
- Dynamic gas pricing (or gas price predictions) - price gas accurately for each trade to balance getting filled and making a profit
- Better handling of gas usage limits - right now it's a constant determined by which aggregator is used (see get_gas_usage_given_aggregator() in master_trading_code). A better way to do it would be to simulate the txn (for which we have an endpoint) and then cache the gas usage to asynchronously update per new block.
- Run on other networks (we support all EVM networks), for other token pairs (we support all ERC20 and ERC721 tokens on all EVM networks), it takes us 1 hour to add another token standard, and across other DEXs
- Add a "flash swap" with
ew3.v0.start_uni_swap
or flash loan withew3.v0.start_flash_loan
- Use our optimized uniswap integration and your own DEX integrations instead of the aggregagor to optimize gas and avoid (or reduce) swap path variance
- There's lots more you can do with the product, but that's where we'd look at first around improving this code / trade
This is for us to do with this code, so you know what's coming.
- Add Google sheet logging option/file for ease of use
- Clean up code
- Add testing harness
- Add better documentation & comments to master_trading_code
- Keep funds in wallet instead of toolkit
- Better exception handling in master_trading_code
- Better naming