Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 123c7ba

Browse files
committed
Update Arb Mode tests to increase coverage & optimize several existing tests
1 parent 108c113 commit 123c7ba

10 files changed

+761
-323
lines changed

fastlane_bot/modes/pairwise_multi_all.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def find_arbitrage(self, candidates: List[Any] = None, ops: Tuple = None, best_p
3131
candidates = []
3232

3333
all_tokens, combos = self.get_combos(self.CCm, self.flashloan_tokens)
34-
34+
if self.result == self.AO_TOKENS:
35+
return all_tokens, combos
3536
#print(f"combos = {combos}")
3637

3738
candidates = []

fastlane_bot/modes/pairwise_multi_pol.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def find_arbitrage(self, candidates: List[Any] = None, ops: Tuple = None, best_p
2828
"""
2929

3030
all_tokens, combos = self.get_combos_pol(self.CCm, self.flashloan_tokens)
31+
if self.result == self.AO_TOKENS:
32+
return all_tokens, combos
3133

3234
candidates = []
3335
self.ConfigObj.logger.debug(
@@ -191,7 +193,7 @@ def get_combos_pol(self,
191193
"""
192194

193195
bancor_pol_tkns = CCm.byparams(exchange="bancor_pol").tokens()
194-
bancor_pol_tkns = [tkn for tkn in bancor_pol_tkns if tkn not in [T.ETH, T.WETH]]
196+
bancor_pol_tkns = set([tkn for tkn in bancor_pol_tkns if tkn not in [T.ETH, T.WETH]])
195197

196198
combos = [
197199
(tkn0, tkn1)

resources/NBTest/NBTest_039_TestMultiMode.ipynb

Lines changed: 27 additions & 88 deletions
Large diffs are not rendered by default.

resources/NBTest/NBTest_039_TestMultiMode.py

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -169,40 +169,28 @@ def init_bot(mgr: Manager) -> CarbonBot:
169169
)
170170
all_tokens, combos = finder2.find_arbitrage()
171171

172-
assert type(all_tokens) == set, f"[TestMultiMode] all_tokens is wrong data type. Expected set, found: {type(all_tokens)}"
173-
assert type(combos) == list, f"[TestMultiMode] combos is wrong data type. Expected list, found: {type(combos)}"
174-
assert len(all_tokens) > 100, f"[TestMultiMode] Using wrong dataset, expected at least 100 tokens, found {len(all_tokens)}"
175-
assert len(combos) > 1000, f"[TestMultiMode] Using wrong dataset, expected at least 100 combos, found {len(combos)}"
172+
assert type(all_tokens) == set, f"[NBTest 039 TestMultiMode] all_tokens is wrong data type. Expected set, found: {type(all_tokens)}"
173+
assert type(combos) == list, f"[NBTest 039 TestMultiMode] combos is wrong data type. Expected list, found: {type(combos)}"
174+
assert len(all_tokens) >= 236, f"[NBTest 039 TestMultiMode] Using wrong dataset, expected at least 236 tokens, found {len(all_tokens)}"
175+
assert len(combos) >= 1410, f"[NBTest 039 TestMultiMode] Using wrong dataset, expected at least 1410 combos, found {len(combos)}"
176176
# -
177177

178178
# ## Test_Expected_Output
179179

180-
arb_finder = bot._get_arb_finder("multi")
181-
finder = arb_finder(
182-
flashloan_tokens=flashloan_tokens,
183-
CCm=CCm,
184-
mode="bothin",
185-
result=bot.AO_CANDIDATES,
186-
ConfigObj=bot.ConfigObj,
187-
)
188-
r = finder.find_arbitrage()
189-
assert len(r) >= 25, f"[TestMultiMode] Expected at least 25 arbs, found {len(r)}"
190-
191-
192-
# ## Test_Multiple_Curves_Used
193-
194180
# +
195-
arb_finder = bot._get_arb_finder("multi")
181+
arb_finder = bot._get_arb_finder("multi_pairwise_pol")
196182
finder = arb_finder(
197183
flashloan_tokens=flashloan_tokens,
198184
CCm=CCm,
199185
mode="bothin",
200186
result=bot.AO_CANDIDATES,
201187
ConfigObj=bot.ConfigObj,
202188
)
189+
203190
r = finder.find_arbitrage()
204-
multi_carbon_count = 0
205191

192+
multi_carbon_count = 0
193+
carbon_wrong_direction_count = 0
206194
for arb in r:
207195
(
208196
best_profit,
@@ -213,32 +201,18 @@ def init_bot(mgr: Manager) -> CarbonBot:
213201
) = arb
214202
if len(best_trade_instructions_dic) > 2:
215203
multi_carbon_count += 1
216-
217-
assert multi_carbon_count > 0, f"[TestMultiMode] Not finding arbs with multiple Carbon curves."
218-
# -
219-
220-
# ## Test_Single_Direction_Carbon_Curves
221-
222-
# +
223-
arb_finder = bot._get_arb_finder("multi")
224-
finder = arb_finder(
225-
flashloan_tokens=flashloan_tokens,
226-
CCm=CCm,
227-
mode="bothin",
228-
result=bot.AO_CANDIDATES,
229-
ConfigObj=bot.ConfigObj,
230-
)
231-
src_token="0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
232-
wrong_direction_cids = ['4083388403051261561560495289181218537493-0', '4083388403051261561560495289181218537579-0', '4083388403051261561560495289181218537610-0', '4083388403051261561560495289181218537629-0', '4083388403051261561560495289181218537639-0', '4083388403051261561560495289181218537755-0']
233-
curves_before = [ConstantProductCurve(k=2290523503.4460173, x=273.1073125047371, x_act=0.07743961144774403, y_act=1814.6001096442342, pair='0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', cid='0x8d7ac7e77704f3ac75534d5500159a7a4b7e6e23dbdca7d9a8085bdea0348d0c', fee=0.0005, descr='uniswap_v3 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 500', constr='pkpp', params={'exchange': 'uniswap_v3', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17675876, 'L': 47859.413948}), ConstantProductCurve(k=3675185.41145277, x=11.059038979187497, x_act=0, y_act=1385.267061, pair='0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', cid='4083388403051261561560495289181218537493-0', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 1385.267061, 'yint': 1385.267061, 'A': 0.722593217276426, 'B': 172.62676501631972, 'pa': 30049.999999999647, 'pb': 29799.999999999665}), ConstantProductCurve(k=29672.782767383174, x=1.0315213950985431, x_act=0, y_act=3651.804716, pair='0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', cid='4083388403051261561560495289181218537579-0', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 3651.804716, 'yint': 3651.804716, 'A': 21.199636119827687, 'B': 145.79437574886072, 'pa': 27886.999999999643, 'pb': 21255.999999999985}), ConstantProductCurve(k=6.863635116394053e+16, x=1525337.9097739116, x_act=0, y_act=4499.746836, pair='0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', cid='4083388403051261561560495289181218537610-0', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 4499.746836, 'yint': 4499.746836, 'A': 0, 'B': 171.7556317853946, 'pa': 29499.99999999976, 'pb': 29499.99999999976}), ConstantProductCurve(k=143046.70577155304, x=2.1824671097293846, x_act=0, y_act=5742.51191, pair='0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', cid='4083388403051261561560495289181218537629-0', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 5742.51191, 'yint': 6413.595264, 'A': 16.957530991696217, 'B': 158.11388300841884, 'pa': 30649.99999999968, 'pb': 24999.99999999996}), ConstantProductCurve(k=5459975.623181331, x=437148.88403306017, x_act=0, y_act=0.50315999, pair='0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', cid='4083388403051261561560495289181218537629-1', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 0.50315999, 'yint': 0.50315999, 'A': 0.0002153330778227767, 'B': 0.005129891760425664, 'pa': 2.8571428571428076e-05, 'pb': 2.631578947368312e-05}), ConstantProductCurve(k=443607.9519434853, x=3.85826034424969, x_act=0, y_act=9876.976514, pair='0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', cid='4083388403051261561560495289181218537639-0', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 9876.976514, 'yint': 9876.976514, 'A': 14.829426635724872, 'B': 157.79733838059485, 'pa': 29799.999999999665, 'pb': 24899.999999999953}), ConstantProductCurve(k=5324.625267368582, x=12680.839210183807, x_act=0, y_act=0.01198047, pair='0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', cid='4083388403051261561560495289181218537639-1', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 0.01198047, 'yint': 0.01198047, 'A': 0.00016418343273514376, 'B': 0.0055901699437491455, 'pa': 3.311258278145614e-05, 'pb': 3.124999999999633e-05}), ConstantProductCurve(k=3316749913763783.5, x=331674.9583747572, x_act=0, y_act=1000.0, pair='0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', cid='4083388403051261561560495289181218537755-0', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 1000.0, 'yint': 1000.0, 'A': 0, 'B': 173.63754485997586, 'pa': 30149.999999999825, 'pb': 30149.999999999825})]
234-
curves_expected_after = [ConstantProductCurve(k=2290523503.4460173, x=273.1073125047371, x_act=0.07743961144774403, y_act=1814.6001096442342, pair='0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', cid='0x8d7ac7e77704f3ac75534d5500159a7a4b7e6e23dbdca7d9a8085bdea0348d0c', fee=0.0005, descr='uniswap_v3 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 500', constr='pkpp', params={'exchange': 'uniswap_v3', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17675876, 'L': 47859.413948}), ConstantProductCurve(k=5459975.623181331, x=437148.88403306017, x_act=0, y_act=0.50315999, pair='0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', cid='4083388403051261561560495289181218537629-1', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 0.50315999, 'yint': 0.50315999, 'A': 0.0002153330778227767, 'B': 0.005129891760425664, 'pa': 2.8571428571428076e-05, 'pb': 2.631578947368312e-05}), ConstantProductCurve(k=5324.625267368582, x=12680.839210183807, x_act=0, y_act=0.01198047, pair='0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', cid='4083388403051261561560495289181218537639-1', fee=0.002, descr='carbon_v1 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 0.002', constr='carb', params={'exchange': 'carbon_v1', 'tknx_dec': 8, 'tkny_dec': 6, 'tknx_addr': '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'tkny_addr': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'blocklud': 17674427, 'y': 0.01198047, 'yint': 0.01198047, 'A': 0.00016418343273514376, 'B': 0.0055901699437491455, 'pa': 3.311258278145614e-05, 'pb': 3.124999999999633e-05})]
235-
test_process_wrong_direction_pools = finder.process_wrong_direction_pools(curve_combo=curves_before, wrong_direction_cids=wrong_direction_cids)
236-
O, profit_src, r, trade_instructions_df = finder.run_main_flow(curves=curves_expected_after, src_token="0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", tkn0="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", tkn1="0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599")
237-
238-
assert len(curves_before) - len(wrong_direction_cids) == len(test_process_wrong_direction_pools), f"[TestMultiMode] Wrong direction CIDs not removed correctly, started with {len(curves_before)}, removing {len(wrong_direction_cids)}, expected {len(curves_before) - len(wrong_direction_cids)} got {len(test_process_wrong_direction_pools)}"
239-
for curve in test_process_wrong_direction_pools:
240-
assert curve.cid not in wrong_direction_cids, f"[TestMultiMode] Failed to remove curve {curve.cid} from list of wrong direction pools"
241-
assert iseq(profit_src, 2.905623487869935e-05)
204+
carbon_tkn_in = None
205+
for trade in best_trade_instructions_dic:
206+
if "-" in trade["cid"]:
207+
if carbon_tkn_in is None:
208+
carbon_tkn_in = trade["tknin"]
209+
else:
210+
if trade["tknin"] not in carbon_tkn_in:
211+
carbon_wrong_direction_count += 1
212+
213+
assert len(r) >= 36, f"[NBTest 039 TestMultiMode] Expected at least 27 arbs, found {len(r)}"
214+
assert multi_carbon_count > 0, f"[NBTest 039 TestMultiMode] Not finding arbs with multiple Carbon curves."
215+
assert carbon_wrong_direction_count == 0, f"[NBTest 039 TestMultiMode] Expected all Carbon curves to have the same tkn in and tkn out. Mixing is currently not supported."
242216
# -
243217

244218

0 commit comments

Comments
 (0)