Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor triangle-mode #651

Open
wants to merge 137 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
724ffc9
Refactor triangle-mode
platonfloria May 17, 2024
59d3d9f
Refactoring
May 18, 2024
18a1b1c
Remove unused code
May 18, 2024
933a9db
Minor
May 18, 2024
2ac4d8f
Code reuse
May 18, 2024
1febfd3
Improve base.py
May 18, 2024
f27696a
Cleanup
May 18, 2024
6046648
Remove obsolete files
May 19, 2024
1b9b3b9
Rename
May 19, 2024
ef31800
Cleanup
May 19, 2024
3788b6a
Revamp all arb-mode classes and their associated tests
May 19, 2024
1f35119
Cleanup
May 19, 2024
b283882
Cleanup
May 19, 2024
77853b7
Minor
May 19, 2024
0ffa04e
Remove unused code
May 19, 2024
b1e1930
Cleanup
May 19, 2024
b33e5df
Cleanup
May 19, 2024
47f0b50
Cleanup
May 19, 2024
1826b93
Cleanup
May 19, 2024
6c04f6b
Fix test 042
May 19, 2024
10c5bdb
Cleanup
May 20, 2024
793a727
Cleanup
May 20, 2024
3879c39
Improve logging
May 20, 2024
df3e43c
Improve logging
May 20, 2024
d00012d
Change arb_opp from a tuple of 5 values to a dictionary of 3 values
May 20, 2024
16c2cb9
Cosmetic
May 20, 2024
0d617b3
Improve logging
May 20, 2024
6a61f8e
Imoprove logging
May 20, 2024
4feedb9
Remove the `run_data_validator` user-option and all associated code
May 20, 2024
7b13688
Get rid of the `NoArbAvailable` exception, which can never take place
May 20, 2024
c40a4a3
Cleanup
May 20, 2024
8afc7a5
Remove unused code
May 20, 2024
0e6dd90
handle curve direction triangle complete
NIXBNT May 20, 2024
719290f
amend logic triangle curves
NIXBNT May 20, 2024
1db0885
Remove the `T` dependency
May 21, 2024
ea6dd0d
Remove unused code
May 21, 2024
88c0270
Code reuse
May 21, 2024
f998731
Simplify `routerhandler._calc_balancer_out_given_in`
May 21, 2024
a75a588
Simplify function `routerhandler._get_output_trade_by_source_carbon`
May 21, 2024
9f09445
Cleanup function `routerhandler._calc_carbon_output`
May 21, 2024
39c2c1d
Cleanup
May 21, 2024
724e840
Improve logging
May 21, 2024
94da501
Improve function `build_pstart`
May 22, 2024
a12b0ce
Refactor the input `params` passed to function `optimize`
May 22, 2024
9f03cb8
Cosmetic
May 22, 2024
fe4eb9c
bugfix triangle complete when pair not found
NIXBNT May 23, 2024
c0d5ea0
Minor
May 24, 2024
93abd1d
Minor
May 24, 2024
2e64ec1
Cleanup
May 25, 2024
3cc0e08
Unify the code across the arb-mode classes
May 25, 2024
9d54e25
Cleanup
May 26, 2024
f3e45f1
Cleanup
May 26, 2024
37b804f
Merge pull request #675 from bancorprotocol/arb-mode-code-unification
barakman May 26, 2024
a6c3675
1. Refactor the order encoding/decoding, and unify all duplicated ver…
May 23, 2024
6e05557
Fix `routerhandler._calc_carbon_output`
May 23, 2024
6b42688
Allow the gas token as input to function `routerhandler._calc_carbon_…
May 23, 2024
38f8461
Cleanup
May 23, 2024
1513622
Add a test for overlapping strategies
May 23, 2024
6bd5aa3
Minor
May 23, 2024
afe30c9
Remove old test file
May 23, 2024
a9dac9d
Use 'int' instead of 'safe_int'
May 25, 2024
7ddc956
Cosmetic
May 25, 2024
eee7575
In `poolandtokens._carbon_to_cpc_dict`, rely on `utils.encodeOrder` i…
May 25, 2024
094a07f
Cosmetic
May 25, 2024
c216194
Cosmetic
May 25, 2024
fbc6432
Cleanup
May 25, 2024
5dcc3fa
Get rid of `num_format`
May 25, 2024
6fcb799
Cleanup
May 26, 2024
4fa7161
Simplify `pools_to_add_from_contracts` from a list of tuples of5 elem…
May 26, 2024
7015fe5
Reuse function `ArbitrageFinderBase.calculate_profit` in bot.py
May 27, 2024
f035652
Improve logging
May 27, 2024
fb7dedc
Fix the setting of `UNI_V2_FORKS` in `network.py`
May 27, 2024
373810b
Remove unused code
May 27, 2024
3df6cf3
Improve logging
May 27, 2024
0642a4d
Minor
May 27, 2024
65e3a5b
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 27, 2024
c33df25
Fix `base_triangle.get_params`
May 27, 2024
c65f6c4
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 27, 2024
9f76ecd
Fix `bot.calculate_profit`
May 27, 2024
4fcc4ce
Remoe redundant combos in `triangle_bancor_v3_two_hop.py`
May 27, 2024
9ebe05d
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 27, 2024
825b4cd
Fix `triangle_bancor_v3_two_hop.get_combos`
May 27, 2024
15efcc5
Cosmetic
May 27, 2024
3cb6a05
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 27, 2024
a403385
Improve `ArbitrageFinderTriangleBancor3TwoHop.get_combos`
May 27, 2024
d5c5817
Cosmetic
May 27, 2024
fe9c597
Improve `ArbitrageFinderBase`
May 27, 2024
a02c92c
Cosmetic
May 27, 2024
a15c976
Improve `ArbitrageFinderBase.get_profit`
May 27, 2024
5e16465
Add explicit `.curves` where needed
May 27, 2024
17e04f8
Fix price sorting in class `ArbitrageFinderBase`
May 27, 2024
2e0ada6
Minor
May 27, 2024
314efb1
Cleanup
May 27, 2024
63caa85
Fix syntax
May 27, 2024
785c0eb
Improve `ArbitrageFinderTriangleMulti.get_combos`
May 27, 2024
054fffe
Fix `ArbitrageFinderBase.sort_order`
May 27, 2024
e667c92
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 27, 2024
5fecd1e
Update version from 3.2.1 to 4.0.0
May 27, 2024
650912f
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 27, 2024
ae5f0ef
Cleanup
May 28, 2024
8efbf58
Improve function `remove_unmapped_uniswap_v2_pools`
May 28, 2024
7c58f59
Fix price construction
May 28, 2024
7b994d4
Generate a price-map for the optimizer based on the significance of t…
May 28, 2024
7dca9ff
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 28, 2024
daf21f9
Simplify the method for finding a reliable price
May 29, 2024
9a54634
Fix error in previous commit
May 29, 2024
053ffbd
Cosmetic
May 29, 2024
d605f16
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 29, 2024
fb740b9
Remove unused code
May 29, 2024
1650eeb
Fix tests
May 29, 2024
34fdc7d
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 29, 2024
032eea6
Fix command-line tests
May 29, 2024
69fa375
Fix tests
May 29, 2024
d42eba4
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 29, 2024
13c5eab
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
May 29, 2024
36c6d79
Merge branch 'triangle-mode-refactor' of https://github.com/bancorpro…
May 29, 2024
f4d6257
Merge pull request #672 from bancorprotocol/refactor-encode-decode-or…
barakman May 29, 2024
2bde90f
Remove commented code
May 29, 2024
1e5693c
Cosmetic
May 29, 2024
6c7e53a
Simplify function `_swap_token0_in`
May 29, 2024
51d9064
Remove unused code
May 30, 2024
8d071bb
Extend the test for function `_carbon_to_cpc_dict`
Jun 3, 2024
7ce4735
Semantic
Jun 3, 2024
14b4976
Remove unused code
Jun 4, 2024
4c4f61e
Remove unuwed code
Jun 4, 2024
5554986
Fix type hint
Jun 5, 2024
80939fe
Cleanup routerhandler.py
Jun 5, 2024
704deee
Cleanup
Jun 6, 2024
da55923
Fix tests
Jun 6, 2024
fe385fa
Retry arb transaction as long as it throws "max fee per gas less than…
Jun 10, 2024
d7fe8ec
Fix error handling
Jun 11, 2024
5e0f622
Cleanup
Jun 12, 2024
72e430a
Fix call to `connect_network` for Tenderly
Jun 15, 2024
81f9ae2
Fix the creation of the XFai-V0-Core contract
Jun 16, 2024
ab14bae
Merge branch 'develop' of https://github.com/bancorprotocol/fastlane-…
Jun 19, 2024
8a97131
Improve coding and performance in pairwise and triangle arb modes
Jun 19, 2024
6b78d8d
Get rid of the `randomizer` input argument, and attempt all profitabl…
Jul 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Merged pull requests

- Add Support for multiple Carbon deployments per-chain [\#379](https://github.com/bancorprotocol/fastlane-bot/issues/379)
- Add support for Fantom Network [\#369](https://github.com/bancorprotocol/fastlane-bot/issues/369)
- python main.py --arb\_mode=b3\_two\_hop --alchemy\_max\_block\_fetch=200 --loglevel=INFO --backdate\_pools=False --polling\_interval=0 --reorg\_delay=0 --run\_data\_validator=False --limit\_bancor3\_flashloan\_tokens=True --randomizer=2 --default\_min\_profit\_gas\_token=0.01 --exchanges=carbon\_v1,bancor\_v3,uniswap\_v3,uniswap\_v2,sushiswap\_v2,balancer,pancakeswap\_v2,pancakeswap\_v3 --flashloan\_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,0x514910771AF9Ca656af840dff83E8264EcF986CA" [\#367](https://github.com/bancorprotocol/fastlane-bot/issues/367)
- python main.py --arb\_mode=b3\_two\_hop --alchemy\_max\_block\_fetch=200 --loglevel=INFO --backdate\_pools=False --polling\_interval=0 --reorg\_delay=0 --run\_data\_validator=False --limit\_bancor3\_flashloan\_tokens=True --default\_min\_profit\_gas\_token=0.01 --exchanges=carbon\_v1,bancor\_v3,uniswap\_v3,uniswap\_v2,sushiswap\_v2,balancer,pancakeswap\_v2,pancakeswap\_v3 --flashloan\_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,0x514910771AF9Ca656af840dff83E8264EcF986CA" [\#367](https://github.com/bancorprotocol/fastlane-bot/issues/367)
- Minor optimization in multicaller [\#348](https://github.com/bancorprotocol/fastlane-bot/issues/348)
- Add Handling of Flashloan Fee [\#346](https://github.com/bancorprotocol/fastlane-bot/issues/346)
- support fusionx v3 on mantle [\#491](https://github.com/bancorprotocol/fastlane-bot/pull/491) ([NIXBNT](https://github.com/NIXBNT))
Expand Down
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,10 @@ You can configure the Fastlane Arbitrage Bot using the options in the `@click.op
- **Triangular**: This includes arbitrage trades between three liquidity pools that can create a triangular route, starting and ending in the same token. For example, USDC > ETH, ETH > LINK, LINK > USDC
- **Multi**: These modes can trade through multiple Carbon orders as a single trade.
- **arb_mode options**:
- **single**: Pairwise arbitrage between one Carbon curve and one other exchange curve.
- **multi** Pairwise arbitrage between **multiple** Carbon curves and one other exchange curve.
- **triangle**: Triangular arbitrage between one Carbon curve and two other exchange curves.
- **multi_triangle**: Triangular arbitrage between **multiple** Carbon curves and two other exchange curves.
- **multi_triangle**: Triangular arbitrage between multiple Carbon curves and two other exchange curves.
- **multi_triangle_complete**: Triangular arbitrage between multiple Carbon curves and two other exchange curves (experimental).
- **b3_two_hop**: Triangular arbitrage - the same as bancor_v3 mode but more gas-efficient.
- **multi_pairwise_pol**: Pairwise multi-mode that always routes through the Bancor protocol-owned liquidity contract.
- **multi_pairwise_bal**: Pairwise multi-mode that always routes through Balancer.
- **multi_pairwise_all**: **(Default)** Pairwise multi-mode that searches all available exchanges for pairwise arbitrage.
- **flashloan_tokens** (str): Tokens the bot can use for flash loans. Specify token addresses as a comma-separated string (e.g., 0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).
- **n_jobs** (int): The number of parallel jobs to run. The default, -1, will use all available cores for the process.
Expand All @@ -125,8 +122,6 @@ You can configure the Fastlane Arbitrage Bot using the options in the `@click.op
- **logging_path** (str): The path for log files. **Recommended not to modify.**
- **loglevel** (str): Logging level, which can be DEBUG, INFO, WARNING, or ERROR.
- **use_cached_events** (bool): **Testing option.** This option runs the bot using historical cached events.
- **run_data_validator** (bool): This option validates that pool data hasn't changed from the time an opportunity was found. This can be useful if the bot has slow cycles, for example if an arb mode takes a long time to run.
- **randomizer** (int): The bot will randomly select an opportunity from the number of opportunities specified in this configuration after sorting by profit. For example the default setting 3 means the bot will randomly pick one of the 3 most profitable opportunities it found in the randomizer.
- **limit_bancor3_flashloan_tokens** (bool): If True, this limits the flashloan tokens to tokens supported by Bancor V3.
- **default_min_profit_gas_token** (float): The minimum amount of expected profit, denominated in the gas token, to consider executing an arbitrage trade.
- **timeout** (int): **Testing option.** This will stop the bot after the specified amount of time has passed.
Expand All @@ -146,7 +141,7 @@ You can configure the Fastlane Arbitrage Bot using the options in the `@click.op
Specify options in the command line. For example:

```bash
poetry run python main.py --arb_mode=multi --polling_interval=12 --reorg_delay=10 --loglevel=INFO
poetry run python main.py --arb_mode=multi_pairwise_all --polling_interval=12 --reorg_delay=10 --loglevel=INFO
```

## Troubleshooting
Expand All @@ -172,18 +167,18 @@ The following examples are command-line inputs that start the bot with different
#### Bancor V3-focused arbitrage

```commandline
poetry run python main.py --arb_mode=b3_two_hop --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --limit_bancor3_flashloan_tokens=True --randomizer=2 --default_min_profit_gas_token=0.01 --exchanges=carbon_v1,bancor_v3,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,0x514910771AF9Ca656af840dff83E8264EcF986CA"
poetry run python main.py --arb_mode=b3_two_hop --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --limit_bancor3_flashloan_tokens=True --default_min_profit_gas_token=0.01 --exchanges=carbon_v1,bancor_v3,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,0x514910771AF9Ca656af840dff83E8264EcF986CA"
```

#### Carbon-focused pairwise arbitrage
```commandline
poetry run python main.py --arb_mode=multi --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
poetry run python main.py --arb_mode=multi_pairwise_all --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --default_min_profit_gas_token=0.01 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
```
#### Unfocused pairwise arbitrage
```commandline
poetry run python main.py --arb_mode=multi_pairwise_all --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
poetry run python main.py --arb_mode=multi_pairwise_all --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --default_min_profit_gas_token=0.01 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
```
#### Triangular Carbon-focused arbitrage
```commandline
poetry run python main.py --arb_mode=multi_triangle --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --run_data_validator=False --default_min_profit_gas_token=0.01 --randomizer=2 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
poetry run python main.py --arb_mode=multi_triangle --alchemy_max_block_fetch=200 --loglevel=INFO --backdate_pools=False --polling_interval=0 --reorg_delay=0 --default_min_profit_gas_token=0.01 --exchanges=bancor_v3,bancor_v2,carbon_v1,uniswap_v3,uniswap_v2,sushiswap_v2,balancer,pancakeswap_v2,pancakeswap_v3 --flashloan_tokens="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
```
Loading
Loading