Skip to content

Commit

Permalink
Refactor for v0.0.1 release to PyPI
Browse files Browse the repository at this point in the history
Add LICENSE
Remove requirements.txt
Add dependencies and metadata to pyproject.toml
Restructure to "src" layout per https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/
  • Loading branch information
BowTiedDevil committed Oct 28, 2023
1 parent c6cae87 commit 6b2656d
Show file tree
Hide file tree
Showing 78 changed files with 375 additions and 385 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Byte-compiled / optimized / DLL files
__pycache__/
__pycache__
*.py[cod]
*$py.class

Expand Down Expand Up @@ -65,6 +65,9 @@ db.sqlite3-journal
instance/
.webassets-cache

# Ruff
.ruff_cache

# Scrapy stuff:
.scrapy

Expand All @@ -83,9 +86,7 @@ profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2022] [BowTiedDevil]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 0 additions & 31 deletions __init__.py

This file was deleted.

Empty file removed fork/__init__.py
Empty file.
37 changes: 36 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
[project]
name = "degenbot"
version = "0.0.1"
authors = [
{ name="BowTiedDevil", email="[email protected]" },
]
description = "Python classes to aid rapid development of Uniswap V2 & V3 arbitrage bots on EVM-compatible blockchains"
#readme = "README.md"
requires-python = ">=3.10"
dependencies = [
'eth-abi>=4.2.0,<5',
'eth-typing>=3.4.0,<4',
'eth-utils>=2.2.1,<3',
'hexbytes>=0.3.1,<1',
'pytest>=7.0,<8',
'scipy>=1.11.3,<1.12',
'ujson>=5.8.0',
'web3>=6.11.0,<7',
'websockets>=11.0.3,<13.0',
]
license = {text = "MIT"}
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
"Homepage" = "https://github.com/bowtieddevil/degenbot"
"Bug Tracker" = "https://github.com/BowTiedDevil/degenbot/issues"

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.mypy]
check_untyped_defs = true

[tool.ruff]
line-length = 79
line-length = 100
indent-width = 4
11 changes: 0 additions & 11 deletions requirements.txt

This file was deleted.

37 changes: 37 additions & 0 deletions src/degenbot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ruff: noqa: F401

from . import exceptions
from . import uniswap
from .arbitrage import (
ArbitrageCalculationResult,
FlashBorrowToLpSwap,
FlashBorrowToLpSwapNew,
FlashBorrowToLpSwapWithFuture,
FlashBorrowToRouterSwap,
UniswapLpCycle,
)
from .chainlink import ChainlinkPriceContract
from .config import get_web3, set_web3
from .fork import AnvilFork
from .functions import next_base_fee
from .logging import logger
from .manager import AllPools, AllTokens, Erc20TokenHelperManager
from .erc20_token import Erc20Token
from .transaction import UniswapTransaction
from .uniswap.managers import (
UniswapV2LiquidityPoolManager,
UniswapV3LiquidityPoolManager,
)
from .uniswap.v2_liquidity_pool import CamelotLiquidityPool, LiquidityPool
from .uniswap.v2_multi_liquidity_pool import MultiLiquidityPool
from .uniswap.v3_tick_lens import TickLens
from .uniswap.v3_liquidity_pool import V3LiquidityPool
from .uniswap.v3_dataclasses import (
UniswapV3BitmapAtWord,
UniswapV3LiquidityAtTick,
UniswapV3LiquidityEvent,
UniswapV3PoolExternalUpdate,
UniswapV3PoolSimulationResult,
UniswapV3PoolState,
)
from .uniswap.v3_snapshot import UniswapV3LiquiditySnapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .flash_borrow_to_lp_swap_new import FlashBorrowToLpSwapNew
from .flash_borrow_to_lp_swap_with_future import FlashBorrowToLpSwapWithFuture
from .flash_borrow_to_router_swap import FlashBorrowToRouterSwap
from .uniswap_lp_cycle import UniswapLpCycle
from .uniswap_lp_cycle import UniswapLpCycle, ArbitrageCalculationResult
33 changes: 33 additions & 0 deletions src/degenbot/arbitrage/arbitrage_dataclasses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import dataclasses
from typing import List, Tuple

from ..erc20_token import Erc20Token


@dataclasses.dataclass(slots=True, frozen=True)
class ArbitrageCalculationResult:
id: str
input_token: Erc20Token
profit_token: Erc20Token
input_amount: int
profit_amount: int
swap_amounts: List


@dataclasses.dataclass(slots=True, frozen=True)
class UniswapPoolSwapVector:
token_in: Erc20Token
token_out: Erc20Token
zero_for_one: bool


@dataclasses.dataclass(slots=True, frozen=True)
class UniswapV2PoolSwapAmounts:
amounts: Tuple[int, int]


@dataclasses.dataclass(slots=True, frozen=True)
class UniswapV3PoolSwapAmounts:
amount_specified: int
zero_for_one: bool
sqrt_price_limit_x96: int
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from ..config import get_web3
from ..logging import logger
from ..token import Erc20Token
from ..types import ArbitrageHelper
from ..uniswap.uniswap_managers import UniswapV2LiquidityPoolManager
from ..uniswap.v2.functions import get_v2_pools_from_token_path
from ..uniswap.v2.liquidity_pool import LiquidityPool
from ..erc20_token import Erc20Token
from ..baseclasses import ArbitrageHelper
from ..uniswap.managers import UniswapV2LiquidityPoolManager
from ..uniswap.v2_functions import get_v2_pools_from_token_path
from ..uniswap.v2_liquidity_pool import LiquidityPool


class FlashBorrowToLpSwap(ArbitrageHelper):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from scipy.optimize import minimize_scalar # type: ignore[import]

from ..token import Erc20Token
from ..types import ArbitrageHelper
from ..uniswap.v2.liquidity_pool import LiquidityPool
from ..erc20_token import Erc20Token
from ..baseclasses import ArbitrageHelper
from ..uniswap.v2_liquidity_pool import LiquidityPool

# TODO: improve arbitrage calculation for repaying with same token, instead of borrow A -> repay B

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import List, Optional, Tuple
from scipy.optimize import minimize_scalar # type: ignore[import]

from ..token import Erc20Token
from ..types import ArbitrageHelper
from ..uniswap.v2.liquidity_pool import LiquidityPool
from ..erc20_token import Erc20Token
from ..baseclasses import ArbitrageHelper
from ..uniswap.v2_liquidity_pool import LiquidityPool


class FlashBorrowToLpSwapWithFuture(ArbitrageHelper):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from eth_utils import to_checksum_address
from scipy import optimize # type: ignore[import]

from ..types import ArbitrageHelper
from ..token import Erc20Token
from ..baseclasses import ArbitrageHelper
from ..erc20_token import Erc20Token
from ..config import get_web3
from ..uniswap.v2.liquidity_pool import LiquidityPool
from ..uniswap.v2.functions import get_v2_pools_from_token_path
from ..uniswap.uniswap_managers import UniswapV2LiquidityPoolManager
from ..uniswap.v2_liquidity_pool import LiquidityPool
from ..uniswap.v2_functions import get_v2_pools_from_token_path
from ..uniswap.managers import UniswapV2LiquidityPoolManager
from ..logging import logger


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..types import ArbitrageHelper
from ..baseclasses import ArbitrageHelper


class LpSwapWithFuture(ArbitrageHelper):
Expand Down
Loading

0 comments on commit 6b2656d

Please sign in to comment.