Skip to main content

Python classes to aid rapid development of Uniswap V2 & V3 arbitrage bots on EVM-compatible blockchains

Project description

Overview

Degenbot is a set of Python classes that abstract many of the implementation details of Uniswap liquidity pools and their underlying ERC-20 tokens. It is an abstraction that uses web3.py for communication with an EVM blockchain.

These classes serve as a building blocks for the lessons published by BowTiedDevil on Degen Code.

The classes originally relied on Brownie, but have evolved to use web3.py more generally following Brownie's transition to "maintenance mode". The degenbot classes still operate when loaded within a Brownie console or when connected to a Python script with a connected chain object.

Prerequisites

Python version 3.10 or newer.

Installation

There are two ways to install degenbot, both require pip.

From PyPI

pip install degenbot will fetch the latest version from PyPI with dependencies.

From Source

Use git clone to create a local copy of this repo, then install with pip install -e /path/to/repo. This creates an editable installation that can be imported into a script or Python REPL using import degenbot.

Examples

The following snippets assume a connected Web3 instance with a working provider on Ethereum mainnet (chain ID #1), and the classes imported under the degenbot namespace.

Uniswap V2 Liquidity Pools

# Create `LiquidityPool` object from on-chain data at the given address and current chain height
>>> lp = degenbot.LiquidityPool('0xBb2b8038a1640196FbE3e38816F3e67Cba72D940')
• WBTC (Wrapped BTC)
• WETH (Wrapped Ether)
WBTC-WETH (V2, 0.30%)
• Token 0: WBTC - Reserves: 10732489743
• Token 1: WETH - Reserves: 2056834999904002274711

# Get information about the tokens held by the pool
>>> lp.token0.name
'Wrapped BTC'

>>> lp.token1.name
'Wrapped Ether'

>>> lp.fee_token0
Fraction(3, 1000)

>>> lp.fee_token1
Fraction(3, 1000)

# Predict the input and output values for swaps through the pool, accounting for fees
>>> lp.calculate_tokens_out_from_tokens_in(token_in=lp.token1, token_in_quantity=1*10**18)
5199789

>>> lp.calculate_tokens_in_from_tokens_out(token_out=lp.token0, token_out_quantity=5199789)
999999992817074189

# Update the current reserves from the live blockchain (`True` if updated reserves found, `False` otherwise)
>>> lp.update_reserves()
[WBTC-WETH (V2, 0.30%)]
WBTC: 10732455184
WETH: 2056841643098872755548
WBTC/WETH: 0.05217929741946638
WETH/WBTC: 19.164688860431703
True
       
>>> lp.reserves_token0
10732455184

>>> lp.reserves_token1
2056841643098872755548

Uniswap V3 Liquidity Pools

TBD

Uniswap Arbitrage

TBD

Local Forking With Anvil

TBD

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

degenbot-0.0.3.tar.gz (84.6 kB view details)

Uploaded Source

Built Distribution

degenbot-0.0.3-py3-none-any.whl (103.3 kB view details)

Uploaded Python 3

File details

Details for the file degenbot-0.0.3.tar.gz.

File metadata

  • Download URL: degenbot-0.0.3.tar.gz
  • Upload date:
  • Size: 84.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for degenbot-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ce4457fe609b6e8064175e347724e00d0d7bbddc19a273de67e488739ede7730
MD5 c3df8c94900e862f8e02f41881add850
BLAKE2b-256 82c1bc28660a6e1f72b07230c9b8c8a83af635f9070ef793908a987c32138201

See more details on using hashes here.

File details

Details for the file degenbot-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: degenbot-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 103.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for degenbot-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e1839c891f4666d7c4b3334315914f575b866105ba23ce12fc3156f4ce2987d9
MD5 eb0a60d0823aff6e58ad002409d6fa46
BLAKE2b-256 9cd68a27719db54178c4298f9c8edad993959ed129a02598e030c46dfdb6cc14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page