API to create and interact with a 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 daiusdc_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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dexsim-0.2.2.tar.gz.
File metadata
- Download URL: dexsim-0.2.2.tar.gz
- Upload date:
- Size: 291.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9d51c6fc9b3d4b3764c57efa57b4f557969226fabce1b63e6d86c7bc385c831
|
|
| MD5 |
46afdcf2fc2c2705243ee5198287634d
|
|
| BLAKE2b-256 |
3cd19ed0d689c32b83dbcb3aa3148e76ea30f4df45f05eab4828a459d5d5224b
|
Provenance
The following attestation bundles were made for dexsim-0.2.2.tar.gz:
Publisher:
release.yaml on simular-fi/dexsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dexsim-0.2.2.tar.gz -
Subject digest:
d9d51c6fc9b3d4b3764c57efa57b4f557969226fabce1b63e6d86c7bc385c831 - Sigstore transparency entry: 219237922
- Sigstore integration time:
-
Permalink:
simular-fi/dexsim@99ad4f141466b28a34e7d0e5c7f51119264e07af -
Branch / Tag:
refs/heads/main - Owner: https://github.com/simular-fi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@99ad4f141466b28a34e7d0e5c7f51119264e07af -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file dexsim-0.2.2-py3-none-any.whl.
File metadata
- Download URL: dexsim-0.2.2-py3-none-any.whl
- Upload date:
- Size: 300.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b787357ee0ddaad2e90ec926b9333a0d58f0cd31ba489ec444bdcf80e94ef2e4
|
|
| MD5 |
de7720a0085ab88adebe5fbdf4dfd808
|
|
| BLAKE2b-256 |
2d11bef1260be69d4227e7fd8a1b3da3e6f2c4475f57f958cf500f988a7d2145
|
Provenance
The following attestation bundles were made for dexsim-0.2.2-py3-none-any.whl:
Publisher:
release.yaml on simular-fi/dexsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dexsim-0.2.2-py3-none-any.whl -
Subject digest:
b787357ee0ddaad2e90ec926b9333a0d58f0cd31ba489ec444bdcf80e94ef2e4 - Sigstore transparency entry: 219237928
- Sigstore integration time:
-
Permalink:
simular-fi/dexsim@99ad4f141466b28a34e7d0e5c7f51119264e07af -
Branch / Tag:
refs/heads/main - Owner: https://github.com/simular-fi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@99ad4f141466b28a34e7d0e5c7f51119264e07af -
Trigger Event:
workflow_dispatch
-
Statement type: