charli3_dendrite 1.1.0.dev1__tar.gz → 1.1.1.dev0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- charli3_dendrite-1.1.1.dev0/PKG-INFO +223 -0
- charli3_dendrite-1.1.1.dev0/README.md +202 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/pyproject.toml +12 -1
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/backend/__init__.py +46 -15
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/backend/backend_base.py +26 -7
- charli3_dendrite-1.1.1.dev0/src/charli3_dendrite/backend/blockfrost/__init__.py +394 -0
- charli3_dendrite-1.1.1.dev0/src/charli3_dendrite/backend/blockfrost/models.py +47 -0
- charli3_dendrite-1.1.1.dev0/src/charli3_dendrite/backend/ogmios_kupo/__init__.py +564 -0
- charli3_dendrite-1.1.1.dev0/src/charli3_dendrite/backend/ogmios_kupo/models.py +84 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dataclasses/datums.py +4 -5
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/amm_base.py +7 -6
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/amm_types.py +1 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/minswap.py +1 -1
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/muesli.py +1 -1
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/spectrum.py +103 -43
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/sundae.py +11 -1
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/vyfi.py +1 -1
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/wingriders.py +1 -1
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/core/base.py +1 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/core/errors.py +3 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/ob/axo.py +2 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/ob/geniusyield.py +2 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/ob/ob_base.py +2 -0
- charli3_dendrite-1.1.0.dev1/PKG-INFO +0 -142
- charli3_dendrite-1.1.0.dev1/README.md +0 -122
- charli3_dendrite-1.1.0.dev1/src/charli3_dendrite/backend/blockfrost.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/LICENSE +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/__init__.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/backend/dbsync/__init__.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/backend/dbsync/models.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/backend/utils.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dataclasses/__init__.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dataclasses/models.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/__init__.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/amm/__init__.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/core/__init__.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/dexs/ob/__init__.py +0 -0
- {charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/utility.py +0 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: charli3_dendrite
|
|
3
|
+
Version: 1.1.1.dev0
|
|
4
|
+
Summary:
|
|
5
|
+
Author: Elder Millenial
|
|
6
|
+
Author-email: eldermillenial@protonmail.com
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Dist: blockfrost-python (>=0.5.3,<0.6.0)
|
|
13
|
+
Requires-Dist: ogmios (==1.1.1)
|
|
14
|
+
Requires-Dist: psycopg[binary,pool] (>=3.1.13,<4.0.0)
|
|
15
|
+
Requires-Dist: pycardano (==0.11.1)
|
|
16
|
+
Requires-Dist: pydantic (>=2.5.2,<3.0.0)
|
|
17
|
+
Requires-Dist: python-dotenv (==0.21.1)
|
|
18
|
+
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
<div align="center">
|
|
22
|
+
<h1 align="center">Charli3 Dendrite</h1>
|
|
23
|
+
<p align="center">Python SDK for interacting with Cardano DEXs</p>
|
|
24
|
+
<p>
|
|
25
|
+
<img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="Python version">
|
|
26
|
+
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License">
|
|
27
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome">
|
|
28
|
+
</p>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
## Overview
|
|
32
|
+
|
|
33
|
+
Charli3 Dendrite is a powerful Python SDK designed for seamless interaction with multiple Decentralized Exchanges (DEXs) on the Cardano blockchain. It provides a unified interface for developers to access various DEX functionalities, simplifying the process of building applications in the Cardano ecosystem.
|
|
34
|
+
|
|
35
|
+
## Key Features
|
|
36
|
+
|
|
37
|
+
- 🔄 Multi-DEX Support: Integrate with Minswap, MuesliSwap, Spectrum, SundaeSwap, VyFi, GeniusYield, Axo, and WingRiders
|
|
38
|
+
- 💧 Liquidity Pool Data: Fetch and analyze pool information across different DEXs
|
|
39
|
+
- 💱 Swap Operations: Execute token swaps with ease
|
|
40
|
+
- 🧩 Flexible Asset Handling: Manage various asset types and pool states efficiently
|
|
41
|
+
- 🔗 On-chain Data Integration: Connect with DB-sync, BlockFrost, and Ogmios/Kupo
|
|
42
|
+
- 🛠 Extensible Architecture: Easily add support for new DEXs and features
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Using pip
|
|
49
|
+
pip install charli3_dendrite
|
|
50
|
+
|
|
51
|
+
# Using Poetry
|
|
52
|
+
poetry add charli3_dendrite
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Supported DEXs
|
|
56
|
+
Charli3 Dendrite currently supports the following Cardano DEXs:
|
|
57
|
+
|
|
58
|
+
- Minswap
|
|
59
|
+
- MuesliSwap
|
|
60
|
+
- Spectrum
|
|
61
|
+
- SundaeSwap
|
|
62
|
+
- VyFi
|
|
63
|
+
- WingRiders
|
|
64
|
+
- GeniusYield
|
|
65
|
+
- Axo
|
|
66
|
+
|
|
67
|
+
### Not Yet Implemented
|
|
68
|
+
|
|
69
|
+
- CardanoSwaps
|
|
70
|
+
- Metadex
|
|
71
|
+
- CSwap
|
|
72
|
+
- TeddySwap
|
|
73
|
+
- Cerra
|
|
74
|
+
- SaturnSwap
|
|
75
|
+
- Splash
|
|
76
|
+
|
|
77
|
+
Each DEX is implemented as a separate module within the `charli3_dendrite.dexs.amm` package.
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
Charli3 Dendrite can be configured using environment variables or a `.env` file. See `sample.env` for an example of the configuration options.
|
|
81
|
+
|
|
82
|
+
### Backend Configuration
|
|
83
|
+
|
|
84
|
+
Charli3 Dendrite supports multiple backend options for interacting with the Cardano blockchain:
|
|
85
|
+
|
|
86
|
+
#### DBSync Configuration
|
|
87
|
+
|
|
88
|
+
To use a DBSync instance as the blockchain connection, set the following environment variables:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
DBSYNC_HOST="your-dbsync-host"
|
|
92
|
+
DBSYNC_PORT="your-dbsync-port"
|
|
93
|
+
DBSYNC_DB_NAME="your-dbsync-database-name"
|
|
94
|
+
DBSYNC_USER="your-dbsync-username"
|
|
95
|
+
DBSYNC_PASS="your-dbsync-password"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### BlockFrost Configuration
|
|
99
|
+
|
|
100
|
+
To use BlockFrost as the backend, set the following environment variables:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
BLOCKFROST_PROJECT_ID="your-blockfrost-project-id"
|
|
104
|
+
CARDANO_NETWORK="mainnet" # or "testnet" for the Cardano testnet
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### Ogmios/Kupo Configuration
|
|
108
|
+
|
|
109
|
+
To use Ogmios and Kupo as the backend, set the following environment variables:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
OGMIOS_URL="ws://your-ogmios-url:port"
|
|
113
|
+
KUPO_URL="http://your-kupo-url:port"
|
|
114
|
+
CARDANO_NETWORK="mainnet" # or "testnet" for the Cardano testnet
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The backend will be automatically selected based on the available environment variables. If multiple backend configurations are present, the priority order is: DBSync, BlockFrost, Ogmios/Kupo.
|
|
118
|
+
|
|
119
|
+
### Backend Limitations
|
|
120
|
+
|
|
121
|
+
While Charli3 Dendrite supports multiple backends, it's important to note that the BlockFrost and Ogmios/Kupo backends have some limitations compared to the DBSync backend:
|
|
122
|
+
|
|
123
|
+
- **BlockFrost Backend**: Due to limitations in the BlockFrost API, the following methods are not implemented:
|
|
124
|
+
- `get_historical_order_utxos`
|
|
125
|
+
- `get_order_utxos_by_block_or_tx`
|
|
126
|
+
- `get_cancel_utxos`
|
|
127
|
+
- `get_axo_target`
|
|
128
|
+
|
|
129
|
+
- **Ogmios/Kupo Backend**: The Ogmios/Kupo backend also has limitations due to the nature of these services:
|
|
130
|
+
- `get_historical_order_utxos`
|
|
131
|
+
- `get_order_utxos_by_block_or_tx`
|
|
132
|
+
- `get_cancel_utxos`
|
|
133
|
+
|
|
134
|
+
These methods will raise a `NotImplementedError` when called using the BlockFrost or Ogmios/Kupo backends. If your application requires these functionalities, consider using the DBSync backend.
|
|
135
|
+
|
|
136
|
+
## Usage
|
|
137
|
+
|
|
138
|
+
### Retrieving Orders and Pool Data
|
|
139
|
+
|
|
140
|
+
To retrieve orders and pool data, first configure the global backend:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from charli3_dendrite.backend import set_backend, get_backend
|
|
144
|
+
from charli3_dendrite.backend.dbsync import DbsyncBackend
|
|
145
|
+
from charli3_dendrite.backend.blockfrost import BlockFrostBackend
|
|
146
|
+
from charli3_dendrite.backend.ogmios_kupo import OgmiosKupoBackend
|
|
147
|
+
from pycardano import Network
|
|
148
|
+
|
|
149
|
+
# Choose one of the following backends:
|
|
150
|
+
# set_backend(DbsyncBackend())
|
|
151
|
+
# set_backend(BlockFrostBackend("your-project-id"))
|
|
152
|
+
set_backend(OgmiosKupoBackend("ws://ogmios-url:port", "http://kupo-url:port", Network.MAINNET))
|
|
153
|
+
|
|
154
|
+
backend = get_backend()
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The `AbstractBackend` interface offers methods for interacting with the Cardano blockchain, regardless of the underlying data source. This abstraction allows seamless switching between different backends without changing your application code.
|
|
158
|
+
|
|
159
|
+
To retrieve pool information, use the `pool_selector` method provided by each DEX's state class:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from charli3_dendrite import VyFiCPPState
|
|
163
|
+
|
|
164
|
+
selector = VyFiCPPState.pool_selector()
|
|
165
|
+
result = backend.get_pool_utxos(
|
|
166
|
+
limit=100000,
|
|
167
|
+
historical=False,
|
|
168
|
+
**selector.model_dump(),
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
To process and parse the retrieved results (`list[PoolStateInfo]`), the following approach can be utilized:
|
|
172
|
+
```python
|
|
173
|
+
pool_data = {}
|
|
174
|
+
total_tvl = 0
|
|
175
|
+
for pool in result:
|
|
176
|
+
d = dex.model_validate(pool.model_dump())
|
|
177
|
+
try:
|
|
178
|
+
logger.info("Get TVL %s", d.tvl)
|
|
179
|
+
logger.info("Price %s", d.price)
|
|
180
|
+
logger.info("Token name of asset A: %s", d.unit_a)
|
|
181
|
+
logger.info("Token name of asset B: %s", d.unit_b)
|
|
182
|
+
except NoAssetsError:
|
|
183
|
+
pass
|
|
184
|
+
except InvalidLPError:
|
|
185
|
+
pass
|
|
186
|
+
except InvalidPoolError:
|
|
187
|
+
pass
|
|
188
|
+
except Exception as e:
|
|
189
|
+
logger.debug(f"{dex.__name__}: {e}")
|
|
190
|
+
```
|
|
191
|
+
This approach is applicable across all supported DEXs. For example, the following list of AbstractPoolState subclasses can be defined to support various DEX states:
|
|
192
|
+
```python
|
|
193
|
+
DEXS: list[AbstractPoolState] = [
|
|
194
|
+
GeniusYieldOrderState,
|
|
195
|
+
MinswapCPPState,
|
|
196
|
+
MinswapV2CPPState,
|
|
197
|
+
MinswapDJEDiUSDStableState,
|
|
198
|
+
MinswapDJEDUSDCStableState,
|
|
199
|
+
MinswapDJEDUSDMStableState,
|
|
200
|
+
MuesliSwapCPPState,
|
|
201
|
+
SpectrumCPPState,
|
|
202
|
+
SundaeSwapCPPState,
|
|
203
|
+
SundaeSwapV3CPPState,
|
|
204
|
+
VyFiCPPState,
|
|
205
|
+
WingRidersCPPState,
|
|
206
|
+
WingRidersSSPState,
|
|
207
|
+
]
|
|
208
|
+
```
|
|
209
|
+
## Development
|
|
210
|
+
To set up the development environment:
|
|
211
|
+
|
|
212
|
+
1. Clone the repository
|
|
213
|
+
2. Install dependencies: `poetry install`
|
|
214
|
+
3. Set up pre-commit hooks: `pre-commit install`
|
|
215
|
+
|
|
216
|
+
## Running Tests
|
|
217
|
+
```bash
|
|
218
|
+
poetry run pytest --benchmark-disable -v --slow -n auto
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Contributing
|
|
222
|
+
Contributions to Charli3 Dendrite are welcome! Please refer to the `CONTRIBUTING.md` file for guidelines on how to contribute to the project.
|
|
223
|
+
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1 align="center">Charli3 Dendrite</h1>
|
|
3
|
+
<p align="center">Python SDK for interacting with Cardano DEXs</p>
|
|
4
|
+
<p>
|
|
5
|
+
<img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="Python version">
|
|
6
|
+
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License">
|
|
7
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome">
|
|
8
|
+
</p>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Charli3 Dendrite is a powerful Python SDK designed for seamless interaction with multiple Decentralized Exchanges (DEXs) on the Cardano blockchain. It provides a unified interface for developers to access various DEX functionalities, simplifying the process of building applications in the Cardano ecosystem.
|
|
14
|
+
|
|
15
|
+
## Key Features
|
|
16
|
+
|
|
17
|
+
- 🔄 Multi-DEX Support: Integrate with Minswap, MuesliSwap, Spectrum, SundaeSwap, VyFi, GeniusYield, Axo, and WingRiders
|
|
18
|
+
- 💧 Liquidity Pool Data: Fetch and analyze pool information across different DEXs
|
|
19
|
+
- 💱 Swap Operations: Execute token swaps with ease
|
|
20
|
+
- 🧩 Flexible Asset Handling: Manage various asset types and pool states efficiently
|
|
21
|
+
- 🔗 On-chain Data Integration: Connect with DB-sync, BlockFrost, and Ogmios/Kupo
|
|
22
|
+
- 🛠 Extensible Architecture: Easily add support for new DEXs and features
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Using pip
|
|
29
|
+
pip install charli3_dendrite
|
|
30
|
+
|
|
31
|
+
# Using Poetry
|
|
32
|
+
poetry add charli3_dendrite
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Supported DEXs
|
|
36
|
+
Charli3 Dendrite currently supports the following Cardano DEXs:
|
|
37
|
+
|
|
38
|
+
- Minswap
|
|
39
|
+
- MuesliSwap
|
|
40
|
+
- Spectrum
|
|
41
|
+
- SundaeSwap
|
|
42
|
+
- VyFi
|
|
43
|
+
- WingRiders
|
|
44
|
+
- GeniusYield
|
|
45
|
+
- Axo
|
|
46
|
+
|
|
47
|
+
### Not Yet Implemented
|
|
48
|
+
|
|
49
|
+
- CardanoSwaps
|
|
50
|
+
- Metadex
|
|
51
|
+
- CSwap
|
|
52
|
+
- TeddySwap
|
|
53
|
+
- Cerra
|
|
54
|
+
- SaturnSwap
|
|
55
|
+
- Splash
|
|
56
|
+
|
|
57
|
+
Each DEX is implemented as a separate module within the `charli3_dendrite.dexs.amm` package.
|
|
58
|
+
|
|
59
|
+
## Configuration
|
|
60
|
+
Charli3 Dendrite can be configured using environment variables or a `.env` file. See `sample.env` for an example of the configuration options.
|
|
61
|
+
|
|
62
|
+
### Backend Configuration
|
|
63
|
+
|
|
64
|
+
Charli3 Dendrite supports multiple backend options for interacting with the Cardano blockchain:
|
|
65
|
+
|
|
66
|
+
#### DBSync Configuration
|
|
67
|
+
|
|
68
|
+
To use a DBSync instance as the blockchain connection, set the following environment variables:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
DBSYNC_HOST="your-dbsync-host"
|
|
72
|
+
DBSYNC_PORT="your-dbsync-port"
|
|
73
|
+
DBSYNC_DB_NAME="your-dbsync-database-name"
|
|
74
|
+
DBSYNC_USER="your-dbsync-username"
|
|
75
|
+
DBSYNC_PASS="your-dbsync-password"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### BlockFrost Configuration
|
|
79
|
+
|
|
80
|
+
To use BlockFrost as the backend, set the following environment variables:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
BLOCKFROST_PROJECT_ID="your-blockfrost-project-id"
|
|
84
|
+
CARDANO_NETWORK="mainnet" # or "testnet" for the Cardano testnet
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Ogmios/Kupo Configuration
|
|
88
|
+
|
|
89
|
+
To use Ogmios and Kupo as the backend, set the following environment variables:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
OGMIOS_URL="ws://your-ogmios-url:port"
|
|
93
|
+
KUPO_URL="http://your-kupo-url:port"
|
|
94
|
+
CARDANO_NETWORK="mainnet" # or "testnet" for the Cardano testnet
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The backend will be automatically selected based on the available environment variables. If multiple backend configurations are present, the priority order is: DBSync, BlockFrost, Ogmios/Kupo.
|
|
98
|
+
|
|
99
|
+
### Backend Limitations
|
|
100
|
+
|
|
101
|
+
While Charli3 Dendrite supports multiple backends, it's important to note that the BlockFrost and Ogmios/Kupo backends have some limitations compared to the DBSync backend:
|
|
102
|
+
|
|
103
|
+
- **BlockFrost Backend**: Due to limitations in the BlockFrost API, the following methods are not implemented:
|
|
104
|
+
- `get_historical_order_utxos`
|
|
105
|
+
- `get_order_utxos_by_block_or_tx`
|
|
106
|
+
- `get_cancel_utxos`
|
|
107
|
+
- `get_axo_target`
|
|
108
|
+
|
|
109
|
+
- **Ogmios/Kupo Backend**: The Ogmios/Kupo backend also has limitations due to the nature of these services:
|
|
110
|
+
- `get_historical_order_utxos`
|
|
111
|
+
- `get_order_utxos_by_block_or_tx`
|
|
112
|
+
- `get_cancel_utxos`
|
|
113
|
+
|
|
114
|
+
These methods will raise a `NotImplementedError` when called using the BlockFrost or Ogmios/Kupo backends. If your application requires these functionalities, consider using the DBSync backend.
|
|
115
|
+
|
|
116
|
+
## Usage
|
|
117
|
+
|
|
118
|
+
### Retrieving Orders and Pool Data
|
|
119
|
+
|
|
120
|
+
To retrieve orders and pool data, first configure the global backend:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from charli3_dendrite.backend import set_backend, get_backend
|
|
124
|
+
from charli3_dendrite.backend.dbsync import DbsyncBackend
|
|
125
|
+
from charli3_dendrite.backend.blockfrost import BlockFrostBackend
|
|
126
|
+
from charli3_dendrite.backend.ogmios_kupo import OgmiosKupoBackend
|
|
127
|
+
from pycardano import Network
|
|
128
|
+
|
|
129
|
+
# Choose one of the following backends:
|
|
130
|
+
# set_backend(DbsyncBackend())
|
|
131
|
+
# set_backend(BlockFrostBackend("your-project-id"))
|
|
132
|
+
set_backend(OgmiosKupoBackend("ws://ogmios-url:port", "http://kupo-url:port", Network.MAINNET))
|
|
133
|
+
|
|
134
|
+
backend = get_backend()
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The `AbstractBackend` interface offers methods for interacting with the Cardano blockchain, regardless of the underlying data source. This abstraction allows seamless switching between different backends without changing your application code.
|
|
138
|
+
|
|
139
|
+
To retrieve pool information, use the `pool_selector` method provided by each DEX's state class:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from charli3_dendrite import VyFiCPPState
|
|
143
|
+
|
|
144
|
+
selector = VyFiCPPState.pool_selector()
|
|
145
|
+
result = backend.get_pool_utxos(
|
|
146
|
+
limit=100000,
|
|
147
|
+
historical=False,
|
|
148
|
+
**selector.model_dump(),
|
|
149
|
+
)
|
|
150
|
+
```
|
|
151
|
+
To process and parse the retrieved results (`list[PoolStateInfo]`), the following approach can be utilized:
|
|
152
|
+
```python
|
|
153
|
+
pool_data = {}
|
|
154
|
+
total_tvl = 0
|
|
155
|
+
for pool in result:
|
|
156
|
+
d = dex.model_validate(pool.model_dump())
|
|
157
|
+
try:
|
|
158
|
+
logger.info("Get TVL %s", d.tvl)
|
|
159
|
+
logger.info("Price %s", d.price)
|
|
160
|
+
logger.info("Token name of asset A: %s", d.unit_a)
|
|
161
|
+
logger.info("Token name of asset B: %s", d.unit_b)
|
|
162
|
+
except NoAssetsError:
|
|
163
|
+
pass
|
|
164
|
+
except InvalidLPError:
|
|
165
|
+
pass
|
|
166
|
+
except InvalidPoolError:
|
|
167
|
+
pass
|
|
168
|
+
except Exception as e:
|
|
169
|
+
logger.debug(f"{dex.__name__}: {e}")
|
|
170
|
+
```
|
|
171
|
+
This approach is applicable across all supported DEXs. For example, the following list of AbstractPoolState subclasses can be defined to support various DEX states:
|
|
172
|
+
```python
|
|
173
|
+
DEXS: list[AbstractPoolState] = [
|
|
174
|
+
GeniusYieldOrderState,
|
|
175
|
+
MinswapCPPState,
|
|
176
|
+
MinswapV2CPPState,
|
|
177
|
+
MinswapDJEDiUSDStableState,
|
|
178
|
+
MinswapDJEDUSDCStableState,
|
|
179
|
+
MinswapDJEDUSDMStableState,
|
|
180
|
+
MuesliSwapCPPState,
|
|
181
|
+
SpectrumCPPState,
|
|
182
|
+
SundaeSwapCPPState,
|
|
183
|
+
SundaeSwapV3CPPState,
|
|
184
|
+
VyFiCPPState,
|
|
185
|
+
WingRidersCPPState,
|
|
186
|
+
WingRidersSSPState,
|
|
187
|
+
]
|
|
188
|
+
```
|
|
189
|
+
## Development
|
|
190
|
+
To set up the development environment:
|
|
191
|
+
|
|
192
|
+
1. Clone the repository
|
|
193
|
+
2. Install dependencies: `poetry install`
|
|
194
|
+
3. Set up pre-commit hooks: `pre-commit install`
|
|
195
|
+
|
|
196
|
+
## Running Tests
|
|
197
|
+
```bash
|
|
198
|
+
poetry run pytest --benchmark-disable -v --slow -n auto
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Contributing
|
|
202
|
+
Contributions to Charli3 Dendrite are welcome! Please refer to the `CONTRIBUTING.md` file for guidelines on how to contribute to the project.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "charli3_dendrite"
|
|
3
|
-
version = "1.1.
|
|
3
|
+
version = "1.1.1-dev0"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = ["Elder Millenial <eldermillenial@protonmail.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -14,6 +14,7 @@ psycopg = {extras = ["binary", "pool"], version = "^3.1.13"}
|
|
|
14
14
|
python-dotenv = "0.21.1"
|
|
15
15
|
pycardano = "0.11.1"
|
|
16
16
|
blockfrost-python = "^0.5.3"
|
|
17
|
+
ogmios = "1.1.1"
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
[tool.poetry.group.dev.dependencies]
|
|
@@ -28,6 +29,9 @@ pytest = "^7.4.3"
|
|
|
28
29
|
pytest-benchmark = "^4.0.0"
|
|
29
30
|
pytest-dependency = "^0.5.1"
|
|
30
31
|
pytest-xdist = "^3.6.1"
|
|
32
|
+
mkdocs = "^1.6.0"
|
|
33
|
+
mkdocs-material = "^9.5.32"
|
|
34
|
+
mkdocstrings = {extras = ["python"], version = "^0.25.2"}
|
|
31
35
|
|
|
32
36
|
|
|
33
37
|
[tool.poetry.group.devs.dependencies]
|
|
@@ -39,3 +43,10 @@ build-backend = "poetry.core.masonry.api"
|
|
|
39
43
|
|
|
40
44
|
[tool.isort]
|
|
41
45
|
profile = "black"
|
|
46
|
+
|
|
47
|
+
[tool.mypy]
|
|
48
|
+
plugins = [ "pydantic.mypy"]
|
|
49
|
+
|
|
50
|
+
[[tool.mypy.overrides]]
|
|
51
|
+
module = ["pycardano","pycardano.*", "dotenv", "nox"]
|
|
52
|
+
ignore_missing_imports = true
|
{charli3_dendrite-1.1.0.dev1 → charli3_dendrite-1.1.1.dev0}/src/charli3_dendrite/backend/__init__.py
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"""Backend Management Module for Charli3 Dendrite.
|
|
2
2
|
|
|
3
3
|
This module provides a centralized system for managing the backend used throughout
|
|
4
|
-
the Charli3 Dendrite application. It includes functions to get and set the global
|
|
5
|
-
as well as to set a default backend based on environment variables.
|
|
4
|
+
the Charli3 Dendrite application. It includes functions to get and set the global
|
|
5
|
+
backend, as well as to set a default backend based on environment variables.
|
|
6
6
|
|
|
7
7
|
The module uses a global variable to store the current backend instance, which
|
|
8
8
|
can be accessed and modified using the provided functions. This approach allows
|
|
@@ -23,13 +23,17 @@ Note: This module relies on environment variables for setting up the default bac
|
|
|
23
23
|
Ensure that the necessary environment variables are set before using this module.
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
|
+
import logging
|
|
26
27
|
import os
|
|
27
28
|
from typing import Optional
|
|
28
29
|
|
|
29
|
-
from dotenv import load_dotenv
|
|
30
|
+
from dotenv import load_dotenv # type: ignore
|
|
31
|
+
from pycardano import Network # type: ignore
|
|
30
32
|
|
|
31
33
|
from charli3_dendrite.backend.backend_base import AbstractBackend
|
|
34
|
+
from charli3_dendrite.backend.blockfrost import BlockFrostBackend
|
|
32
35
|
from charli3_dendrite.backend.dbsync import DbsyncBackend
|
|
36
|
+
from charli3_dendrite.backend.ogmios_kupo import OgmiosKupoBackend
|
|
33
37
|
|
|
34
38
|
# Load environment variables from .env file
|
|
35
39
|
load_dotenv()
|
|
@@ -71,9 +75,8 @@ def set_default_backend() -> None:
|
|
|
71
75
|
"""Attempt to set a default backend based on environment variables.
|
|
72
76
|
|
|
73
77
|
This function checks for the presence of specific environment variables
|
|
74
|
-
to determine which backend to use as the default.
|
|
75
|
-
|
|
76
|
-
other backend types in the future.
|
|
78
|
+
to determine which backend to use as the default. It checks for DBSync-related
|
|
79
|
+
variables first, then for Blockfrost, and finally for Ogmios and Kupo variables.
|
|
77
80
|
"""
|
|
78
81
|
# Check for DBSync environment variables
|
|
79
82
|
dbsync_vars = [
|
|
@@ -85,13 +88,41 @@ def set_default_backend() -> None:
|
|
|
85
88
|
]
|
|
86
89
|
if all(env_var in os.environ for env_var in dbsync_vars):
|
|
87
90
|
set_backend(DbsyncBackend())
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
set_backend(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
# Check for Blockfrost environment variables
|
|
94
|
+
if "BLOCKFROST_PROJECT_ID" in os.environ:
|
|
95
|
+
set_backend(
|
|
96
|
+
BlockFrostBackend(
|
|
97
|
+
project_id=os.environ["BLOCKFROST_PROJECT_ID"],
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
# Check for Ogmios and Kupo environment variables
|
|
103
|
+
ogmios_kupo_vars = [
|
|
104
|
+
"OGMIOS_URL",
|
|
105
|
+
"KUPO_URL",
|
|
106
|
+
"CARDANO_NETWORK",
|
|
107
|
+
]
|
|
108
|
+
if all(env_var in os.environ for env_var in ogmios_kupo_vars):
|
|
109
|
+
network = (
|
|
110
|
+
Network.MAINNET
|
|
111
|
+
if os.environ["CARDANO_NETWORK"].upper() == "MAINNET"
|
|
112
|
+
else Network.TESTNET
|
|
113
|
+
)
|
|
114
|
+
set_backend(
|
|
115
|
+
OgmiosKupoBackend(
|
|
116
|
+
ogmios_url=os.environ["OGMIOS_URL"],
|
|
117
|
+
kupo_url=os.environ["KUPO_URL"],
|
|
118
|
+
network=network,
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
return
|
|
122
|
+
|
|
123
|
+
# If no backend can be set, log a warning
|
|
124
|
+
logging.warning("No default backend could be set. Please set a backend manually.")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# Initialize the backend when the module is imported
|
|
97
128
|
set_default_backend()
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
from abc import ABC
|
|
4
4
|
from abc import abstractmethod
|
|
5
5
|
from datetime import datetime
|
|
6
|
+
from typing import Optional
|
|
6
7
|
|
|
7
|
-
from pycardano import Address
|
|
8
|
+
from pycardano import Address # type: ignore
|
|
8
9
|
|
|
10
|
+
from charli3_dendrite.dataclasses.models import Assets
|
|
9
11
|
from charli3_dendrite.dataclasses.models import BlockList
|
|
10
12
|
from charli3_dendrite.dataclasses.models import PoolStateList
|
|
11
13
|
from charli3_dendrite.dataclasses.models import ScriptReference
|
|
@@ -20,10 +22,10 @@ class AbstractBackend(ABC):
|
|
|
20
22
|
"""
|
|
21
23
|
|
|
22
24
|
@abstractmethod
|
|
23
|
-
def get_pool_utxos(
|
|
25
|
+
def get_pool_utxos(
|
|
24
26
|
self,
|
|
27
|
+
addresses: list[str],
|
|
25
28
|
assets: list[str] | None = None,
|
|
26
|
-
addresses: list[str] | None = None,
|
|
27
29
|
limit: int = 1000,
|
|
28
30
|
page: int = 0,
|
|
29
31
|
historical: bool = True,
|
|
@@ -46,8 +48,8 @@ class AbstractBackend(ABC):
|
|
|
46
48
|
def get_pool_in_tx(
|
|
47
49
|
self,
|
|
48
50
|
tx_hash: str,
|
|
51
|
+
addresses: list[str],
|
|
49
52
|
assets: list[str] | None = None,
|
|
50
|
-
addresses: list[str] | None = None,
|
|
51
53
|
) -> PoolStateList:
|
|
52
54
|
"""Get pool state for a specific transaction.
|
|
53
55
|
|
|
@@ -119,7 +121,7 @@ class AbstractBackend(ABC):
|
|
|
119
121
|
pass
|
|
120
122
|
|
|
121
123
|
@abstractmethod
|
|
122
|
-
def get_order_utxos_by_block_or_tx(
|
|
124
|
+
def get_order_utxos_by_block_or_tx(
|
|
123
125
|
self,
|
|
124
126
|
stake_addresses: list[str],
|
|
125
127
|
out_tx_hash: list[str] | None = None,
|
|
@@ -146,7 +148,7 @@ class AbstractBackend(ABC):
|
|
|
146
148
|
pass
|
|
147
149
|
|
|
148
150
|
@abstractmethod
|
|
149
|
-
def get_cancel_utxos(
|
|
151
|
+
def get_cancel_utxos(
|
|
150
152
|
self,
|
|
151
153
|
stake_addresses: list[str],
|
|
152
154
|
block_no: int | None = None,
|
|
@@ -173,7 +175,7 @@ class AbstractBackend(ABC):
|
|
|
173
175
|
self,
|
|
174
176
|
address: str,
|
|
175
177
|
asset: str | None = None,
|
|
176
|
-
) ->
|
|
178
|
+
) -> Optional[ScriptReference]:
|
|
177
179
|
"""Get datum from a given address.
|
|
178
180
|
|
|
179
181
|
Args:
|
|
@@ -184,3 +186,20 @@ class AbstractBackend(ABC):
|
|
|
184
186
|
The datum associated with the address, if any.
|
|
185
187
|
"""
|
|
186
188
|
pass
|
|
189
|
+
|
|
190
|
+
@abstractmethod
|
|
191
|
+
def get_axo_target(
|
|
192
|
+
self,
|
|
193
|
+
assets: Assets,
|
|
194
|
+
block_time: datetime | None = None,
|
|
195
|
+
) -> str | None:
|
|
196
|
+
"""Get the target address for the given assets.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
assets: The assets to query.
|
|
200
|
+
block_time: The block time to query.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
The target address for the assets, if any.
|
|
204
|
+
"""
|
|
205
|
+
pass
|