Skip to content

Commit

Permalink
Merge pull request #17 from bancorprotocol/main_skl_flbot
Browse files Browse the repository at this point in the history
Merging DEVSKL from the old repo into the new repo
  • Loading branch information
mikewcasale authored Jul 26, 2023
2 parents 031ab40 + 2ab4fef commit 5ed5a1f
Show file tree
Hide file tree
Showing 130 changed files with 39,833 additions and 9,296 deletions.
14 changes: 7 additions & 7 deletions fastlane_bot/helpers/univ3calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
NOTE: this class is not part of the API of the Carbon protocol, and you must expect breaking
changes even in minor version updates. Use at your own risk.
"""
__VERSION__ = "1.4"
__DATE__ = "07/May/2023"
__VERSION__ = "1.4.1"
__DATE__ = "25/Jul/2023"

from math import sqrt
from dataclasses import dataclass, InitVar, asdict
Expand Down Expand Up @@ -39,12 +39,12 @@ class Univ3Calculator():
tkn0decv: InitVar[int] = None
tkn1decv: InitVar[int] = None
addrdec: InitVar[dict] = None
ADDRDEC = dict(
ADDRDEC = {
# only for testing
USDC = ("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 6),
WETH = ("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 18),
)

"USDC-eB48": ("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 6),
"WETH-6Cc2": ("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 18),
}
@classmethod
def from_dict(cls, d, fee_const, *, addrdec=None, tkn0decv=None, tkn1decv=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions fastlane_bot/modes/pairwise_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from fastlane_bot.modes.base_pairwise import ArbitrageFinderPairwiseBase
from fastlane_bot.tools.cpc import CPCContainer
from fastlane_bot.tools.optimizer import CPCArbOptimizer
from fastlane_bot.tools.optimizer import MargPOptimizer


class FindArbitrageMultiPairwise(ArbitrageFinderPairwiseBase):
Expand Down Expand Up @@ -162,7 +162,7 @@ def run_main_flow(
Run main flow to find arbitrage.
"""
CC_cc = CPCContainer(curves)
O = CPCArbOptimizer(CC_cc)
O = MargPOptimizer(CC_cc)
pstart = {
tkn0: CC_cc.bypairs(f"{tkn0}/{tkn1}")[0].p
} # this intentionally selects the non_carbon curve
Expand Down
5 changes: 3 additions & 2 deletions fastlane_bot/modes/pairwise_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from fastlane_bot.modes.base_pairwise import ArbitrageFinderPairwiseBase
from fastlane_bot.tools.cpc import CPCContainer
from fastlane_bot.tools.optimizer import CPCArbOptimizer
from fastlane_bot.tools.optimizer import MargPOptimizer


class FindArbitrageSinglePairwise(ArbitrageFinderPairwiseBase):
Expand Down Expand Up @@ -58,7 +58,7 @@ def find_arbitrage(self, candidates: List[Any] = None, ops: Tuple = None, best_p

for curve_combo in curve_combos:
CC_cc = CPCContainer(curve_combo)
O = CPCArbOptimizer(CC_cc)
O = MargPOptimizer(CC_cc)
src_token = tkn1
try:
pstart = {tkn0: CC_cc.bypairs(f"{tkn0}/{tkn1}")[0].p}
Expand All @@ -68,6 +68,7 @@ def find_arbitrage(self, candidates: List[Any] = None, ops: Tuple = None, best_p
trade_instructions_dic = r.trade_instructions(O.TIF_DICTS)
trade_instructions = r.trade_instructions()
except Exception as e:
print("[FindArbitrageSinglePairwise] Exception: ", e)
continue

# Get the candidate ids
Expand Down
4 changes: 2 additions & 2 deletions fastlane_bot/modes/triangle_bancor_v3_two_hop.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from fastlane_bot.modes.base_triangle import ArbitrageFinderTriangleBase
from fastlane_bot.tools.cpc import CPCContainer, T, ConstantProductCurve
from fastlane_bot.tools.optimizer import CPCArbOptimizer
from fastlane_bot.tools.optimizer import MargPOptimizer


class ArbitrageFinderTriangleBancor3TwoHop(ArbitrageFinderTriangleBase):
Expand Down Expand Up @@ -292,7 +292,7 @@ def run_main_flow(

# Instantiate the container and optimizer objects
CC_cc = CPCContainer(miniverse)
O = CPCArbOptimizer(CC_cc)
O = MargPOptimizer(CC_cc)

# Perform the optimization
r = O.margp_optimizer(src_token)
Expand Down
6 changes: 3 additions & 3 deletions fastlane_bot/modes/triangle_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from fastlane_bot.modes.base_triangle import ArbitrageFinderTriangleBase
from fastlane_bot.tools.cpc import CPCContainer
from fastlane_bot.tools.optimizer import CPCArbOptimizer
from fastlane_bot.tools.optimizer import MargPOptimizer


class ArbitrageFinderTriangleMulti(ArbitrageFinderTriangleBase):
Expand Down Expand Up @@ -38,7 +38,7 @@ def find_arbitrage(self, candidates: List[Any] = None, ops: Tuple = None, best_p

r = None
CC_cc = CPCContainer(miniverse)
O = CPCArbOptimizer(CC_cc)
O = MargPOptimizer(CC_cc)
try:
r = O.margp_optimizer(src_token)
trade_instructions_df = r.trade_instructions(O.TIF_DFAGGR)
Expand Down Expand Up @@ -80,7 +80,7 @@ def find_arbitrage(self, candidates: List[Any] = None, ops: Tuple = None, best_p

# Rerun main flow with the new set of curves
CC_cc = CPCContainer(new_curves)
O = CPCArbOptimizer(CC_cc)
O = MargPOptimizer(CC_cc)
r = O.margp_optimizer(src_token)
profit_src = -r.result
trade_instructions_df = r.trade_instructions(O.TIF_DFAGGR)
Expand Down
4 changes: 2 additions & 2 deletions fastlane_bot/modes/triangle_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from fastlane_bot.modes.base_triangle import ArbitrageFinderTriangleBase
from fastlane_bot.tools.cpc import CPCContainer
from fastlane_bot.tools.optimizer import CPCArbOptimizer
from fastlane_bot.tools.optimizer import MargPOptimizer


class ArbitrageFinderTriangleSingle(ArbitrageFinderTriangleBase):
Expand Down Expand Up @@ -38,7 +38,7 @@ def find_arbitrage(self, candidates: List[Any] = None, ops: Tuple = None, best_p

# Instantiate the container and optimizer objects
CC_cc = CPCContainer(miniverse)
O = CPCArbOptimizer(CC_cc)
O = MargPOptimizer(CC_cc)

try:
# Perform the optimization
Expand Down
4 changes: 2 additions & 2 deletions fastlane_bot/modes/triangle_single_bancor3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from fastlane_bot.modes.base_triangle import ArbitrageFinderTriangleBase
from fastlane_bot.tools.cpc import CPCContainer, T, ConstantProductCurve
from fastlane_bot.tools.optimizer import CPCArbOptimizer
from fastlane_bot.tools.optimizer import MargPOptimizer


class ArbitrageFinderTriangleSingleBancor3(ArbitrageFinderTriangleBase):
Expand Down Expand Up @@ -295,7 +295,7 @@ def run_main_flow(

# Instantiate the container and optimizer objects
CC_cc = CPCContainer(miniverse)
O = CPCArbOptimizer(CC_cc)
O = MargPOptimizer(CC_cc)

# Perform the optimization
r = O.margp_optimizer(src_token)
Expand Down
Empty file added fastlane_bot/tests/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions fastlane_bot/tests/nbtest/_data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# NBTest Data

All data referred to by NBTest notebooks is stored in this directory. It is copied into the respective directory in the test area by the `run_tests` script. Currently the data will be accessed differently in the notebooks and in the actual tests.

- **Notebooks**. In the notebooks the data can be accessed via a relative path `_data\mydata.csv`.

- **Tests**. In the actual tests the data must be imported via the relative path `fastlane_bot/tests/nbtest/_data/mydata.csv`


Example

try:
with open("_data/mydata.csv", "r") as f:
data = f.read()
except:
with open("fastlane_bot/tests/nbtest/_data/mydata.csv", "r") as f:
data = f.read()


Loading

0 comments on commit 5ed5a1f

Please sign in to comment.