Skip to main content

API to create and interact with Uniswap based decentralized exchange

Project description

DEXsim

An API to create and interact with a local version of Uniswap v3. This library use a pre-deployed version of Uniswap v3 along with a set of pre-deployed pools. It's intended for use in agent-based modeling or other simulation environments. It's also a useful tool in learning about how Uniswap works.

Under the covers, dexsim is built on Simular that uses a production-grade EVM. Uniswap v3 is deployed from a snapshot from the main Ethereun chain. However, it does not include any state other than currently supported pools.

The pools are only deployed, not initialized with an starting price. You can set the starting price via the configuration file described below.

Install

> pip install dexsim

Getting started

The following pools can be configured and used:

pool fee pool name
usdc/dai 100 (0.01) usdc_dai_100
usdc/dai 500 (0.05) usdc_dai_500
usdc/weth 500 (0.05) usdc_weth_500
dai/weth 500 (0.05) dai_weth_500
wbtc/weth 500 (0.05) wbtc_weth_500
wbtc/dai 500 (0.05) wbtc_dai_500
wbtc/usdc 500 (0.05) wbtc_usdc_500

The pools must be initialized with a starting price via the YAML configuration file. You only need to configure the pools you intend to use. Here's an example of the file format:

Example config file: example.yaml

simulator:
  pools:
    usdc_dai_100: [1, 1]
    usdc_weth_500: [5000, 1]

This configures 2 pools with there exchange prices:

  • usdc_dai_100 = 1 usdc for 1 dai
  • usdc_weth_500 = 5000 usdc for 1 weth.

Here's an example of creating and using the pools:

from dexsim import DEX

# Create the Unswap DEX based on the configuration file
dex = DEX('./example.yaml')
assert 2 == dex.total_number_of_pools()
assert (5000, 0.0002) == dex.pools.usdc_weth_500.exchange_rates()

# create a wallet for Bob
bob = dex.create_wallet()

# mint some ERC20 tokens for bob
dex.pools.usdc_weth_500.mint_tokens(10000, 2, bob)

# mint a liquidity position for bob in the price range of $4900 - $5100 by 
# providing 10_000 usdc and 2 weth.  
# Note the prices are specified in terms of the y token (weth)
_, _, _, nft_id = dex.pools.usdc_weth_500.mint_liquidity_position(
        10000, 2, 1 / 4900, 1 / 5100, bob
    )

See tests/ for several examples of use.

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

dexsim-0.2.1.tar.gz (290.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dexsim-0.2.1-py3-none-any.whl (299.6 kB view details)

Uploaded Python 3

File details

Details for the file dexsim-0.2.1.tar.gz.

File metadata

  • Download URL: dexsim-0.2.1.tar.gz
  • Upload date:
  • Size: 290.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dexsim-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d1d087ea54223ed631a69063b0e8d05d228cdc2709b1b3a2bcabf9c1a9e6bea1
MD5 556b4ef7dcb1e7d9b3eca62096b9b377
BLAKE2b-256 d9872e3b0d535e7ba286c5d4d729d75e38972d17735b86eb780ece5383dafce9

See more details on using hashes here.

Provenance

The following attestation bundles were made for dexsim-0.2.1.tar.gz:

Publisher: release.yaml on simular-fi/dexsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dexsim-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dexsim-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 299.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dexsim-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8de1cacd478487ff25a75c26b14a8ab2c24ce89298ce875a9e0f70de76d65c6a
MD5 fbbfbb02a52be8b9ab11d3e8c80c73a1
BLAKE2b-256 1fd5effd1ce55c4849f31e98757542e162290181ebde6a13c8b7cab07cc47c5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for dexsim-0.2.1-py3-none-any.whl:

Publisher: release.yaml on simular-fi/dexsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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