charli3_dendrite 0.2.0.dev116__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-0.2.0.dev116/LICENSE +21 -0
- charli3_dendrite-0.2.0.dev116/PKG-INFO +142 -0
- charli3_dendrite-0.2.0.dev116/README.md +122 -0
- charli3_dendrite-0.2.0.dev116/pyproject.toml +41 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/__init__.py +18 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/backend/__init__.py +97 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/backend/backend_base.py +186 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/backend/blockfrost.py +0 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/backend/dbsync/__init__.py +739 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/backend/dbsync/models.py +159 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/backend/utils.py +42 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dataclasses/__init__.py +1 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dataclasses/datums.py +171 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dataclasses/models.py +273 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/__init__.py +0 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/__init__.py +1 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/amm_base.py +516 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/amm_types.py +426 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/minswap.py +1124 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/muesli.py +334 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/spectrum.py +356 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/sundae.py +708 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/vyfi.py +330 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/amm/wingriders.py +406 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/core/__init__.py +1 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/core/base.py +250 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/core/errors.py +22 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/ob/__init__.py +0 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/ob/axo.py +693 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/ob/geniusyield.py +753 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/dexs/ob/ob_base.py +418 -0
- charli3_dendrite-0.2.0.dev116/src/charli3_dendrite/utility.py +169 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Charli3-Official and SteelSwap
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: charli3_dendrite
|
|
3
|
+
Version: 0.2.0.dev116
|
|
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: psycopg[binary,pool] (>=3.1.13,<4.0.0)
|
|
14
|
+
Requires-Dist: pycardano (==0.11.1)
|
|
15
|
+
Requires-Dist: pydantic (>=2.5.2,<3.0.0)
|
|
16
|
+
Requires-Dist: python-dotenv (==0.21.1)
|
|
17
|
+
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
<div align="center">
|
|
21
|
+
<h1 align="center">Charli3 Dendrite</h1>
|
|
22
|
+
<p align="center">Python SDK for interacting with Cardano DEXs</p>
|
|
23
|
+
<p>
|
|
24
|
+
<img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="Python version">
|
|
25
|
+
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License">
|
|
26
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome">
|
|
27
|
+
</p>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## Overview
|
|
31
|
+
|
|
32
|
+
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.
|
|
33
|
+
|
|
34
|
+
## Key Features
|
|
35
|
+
|
|
36
|
+
- 🔄 Multi-DEX Support: Integrate with Minswap, MuesliSwap, Spectrum, SundaeSwap, VyFi, GeniusYield, Axo, and WingRiders
|
|
37
|
+
- 💧 Liquidity Pool Data: Fetch and analyze pool information across different DEXs
|
|
38
|
+
- 💱 Swap Operations: Execute token swaps with ease
|
|
39
|
+
- 🧩 Flexible Asset Handling: Manage various asset types and pool states efficiently
|
|
40
|
+
- 🔗 On-chain Data Integration: Connect with Blockfrost or custom data providers
|
|
41
|
+
- 🛠Extensible Architecture: Easily add support for new DEXs and features
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
### Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Using pip
|
|
50
|
+
pip install charli3_dendrite
|
|
51
|
+
|
|
52
|
+
# Using Poetry
|
|
53
|
+
poetry add charli3_dendrite
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Supported DEXs
|
|
57
|
+
Charli3 Dendrite currently supports the following Cardano DEXs:
|
|
58
|
+
|
|
59
|
+
- Minswap
|
|
60
|
+
- MuesliSwap
|
|
61
|
+
- Spectrum
|
|
62
|
+
- SundaeSwap
|
|
63
|
+
- VyFi
|
|
64
|
+
- WingRiders
|
|
65
|
+
- GeniusYield
|
|
66
|
+
- Axo
|
|
67
|
+
|
|
68
|
+
## Upcoming DEXs
|
|
69
|
+
|
|
70
|
+
- CardanoSwaps
|
|
71
|
+
- Metadex
|
|
72
|
+
- CSwap
|
|
73
|
+
|
|
74
|
+
## Not Supported
|
|
75
|
+
|
|
76
|
+
- TeddySwap
|
|
77
|
+
- Cerra
|
|
78
|
+
- SaturnSwap
|
|
79
|
+
- Splash
|
|
80
|
+
|
|
81
|
+
Each DEX is implemented as a separate module within the `charli3 dendrite.dexs.amm` package.
|
|
82
|
+
## Core Components
|
|
83
|
+
### AbstractPoolState
|
|
84
|
+
The `AbstractPoolState` class in `amm_base.py` provides the base implementation for AMM (Automated Market Maker) pool states. It includes methods for:
|
|
85
|
+
|
|
86
|
+
- Extracting pool information
|
|
87
|
+
- Handling swap operations
|
|
88
|
+
- Calculating prices and TVL (Total Value Locked)
|
|
89
|
+
|
|
90
|
+
### AbstractPairState
|
|
91
|
+
The `AbstractPairState` class in `base.py` defines the interface for all pair states (both AMM and orderbook-based). It includes abstract methods that must be implemented by specific DEX classes.
|
|
92
|
+
### Assets
|
|
93
|
+
The `Assets` class in `models.py` represents a collection of assets (tokens) and their quantities. It provides utility methods for working with asset collections, including addition and subtraction operations.
|
|
94
|
+
## Configuration
|
|
95
|
+
Charli3 Dendrite can be configured using environment variables or a `.env` file. See `sample.env` for an example of the configuration options.
|
|
96
|
+
|
|
97
|
+
### Data Provider Configuration
|
|
98
|
+
|
|
99
|
+
Charli3 Dendrite supports multiple data providers to fetch on-chain data. Currently, it supports Blockfrost and DBSync, with plans to add Ogmios and Kupo in the future.
|
|
100
|
+
|
|
101
|
+
#### Blockfrost Configuration
|
|
102
|
+
|
|
103
|
+
Blockfrost is the default data provider for Charli3 Dendrite. To use Blockfrost, you need to set up your API key in the environment variables or `.env` file:
|
|
104
|
+
```
|
|
105
|
+
PROJECT_ID="your-blockfrost-project-id"
|
|
106
|
+
NETWORK="mainnet" # or "testnet" for the Cardano testnet
|
|
107
|
+
```
|
|
108
|
+
#### DBSync Configuration
|
|
109
|
+
Charli3 Dendrite also supports using a DBSync instance as a data provider. To configure DBSync, set the following environment variables:
|
|
110
|
+
```bash
|
|
111
|
+
DBSYNC_HOST="your-dbsync-host"
|
|
112
|
+
DBSYNC_PORT="your-dbsync-port"
|
|
113
|
+
DBSYNC_DB_NAME="your-dbsync-database-name"
|
|
114
|
+
DBSYNC_USER="your-dbsync-username"
|
|
115
|
+
DBSYNC_PASS="your-dbsync-password"
|
|
116
|
+
```
|
|
117
|
+
#### Future Plans: Ogmios and Kupo
|
|
118
|
+
We are planning to add support for Ogmios and Kupo as additional data providers in future releases. These will offer alternative ways to interact with the Cardano blockchain and may provide performance improvements or additional features.
|
|
119
|
+
Stay tuned for updates on the integration of these providers. Once implemented, they will be configurable in a similar manner to the existing providers.
|
|
120
|
+
### Wallet Configuration
|
|
121
|
+
Charli3 Dendrite supports wallet integration for performing transactions. You can configure a wallet using a mnemonic phrase:
|
|
122
|
+
```bash
|
|
123
|
+
WALLET_MNEMONIC="your wallet mnemonic phrase"
|
|
124
|
+
```
|
|
125
|
+
## Development
|
|
126
|
+
To set up the development environment:
|
|
127
|
+
|
|
128
|
+
1. Clone the repository
|
|
129
|
+
2. Install dependencies: `poetry install`
|
|
130
|
+
3. Set up pre-commit hooks: `pre-commit install`
|
|
131
|
+
|
|
132
|
+
## Running Tests
|
|
133
|
+
```bash
|
|
134
|
+
poetry run pytest --benchmark-disable -v --slow -n auto
|
|
135
|
+
```
|
|
136
|
+
For parallel test execution:
|
|
137
|
+
```bash
|
|
138
|
+
poetry run pytest -n auto
|
|
139
|
+
```
|
|
140
|
+
## Contributing
|
|
141
|
+
Contributions to Charli3 Dendrite are welcome! Please refer to the `CONTRIBUTING.md` file for guidelines on how to contribute to the project.
|
|
142
|
+
|
|
@@ -0,0 +1,122 @@
|
|
|
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 Blockfrost or custom data providers
|
|
22
|
+
- 🛠Extensible Architecture: Easily add support for new DEXs and features
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Using pip
|
|
31
|
+
pip install charli3_dendrite
|
|
32
|
+
|
|
33
|
+
# Using Poetry
|
|
34
|
+
poetry add charli3_dendrite
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Supported DEXs
|
|
38
|
+
Charli3 Dendrite currently supports the following Cardano DEXs:
|
|
39
|
+
|
|
40
|
+
- Minswap
|
|
41
|
+
- MuesliSwap
|
|
42
|
+
- Spectrum
|
|
43
|
+
- SundaeSwap
|
|
44
|
+
- VyFi
|
|
45
|
+
- WingRiders
|
|
46
|
+
- GeniusYield
|
|
47
|
+
- Axo
|
|
48
|
+
|
|
49
|
+
## Upcoming DEXs
|
|
50
|
+
|
|
51
|
+
- CardanoSwaps
|
|
52
|
+
- Metadex
|
|
53
|
+
- CSwap
|
|
54
|
+
|
|
55
|
+
## Not Supported
|
|
56
|
+
|
|
57
|
+
- TeddySwap
|
|
58
|
+
- Cerra
|
|
59
|
+
- SaturnSwap
|
|
60
|
+
- Splash
|
|
61
|
+
|
|
62
|
+
Each DEX is implemented as a separate module within the `charli3 dendrite.dexs.amm` package.
|
|
63
|
+
## Core Components
|
|
64
|
+
### AbstractPoolState
|
|
65
|
+
The `AbstractPoolState` class in `amm_base.py` provides the base implementation for AMM (Automated Market Maker) pool states. It includes methods for:
|
|
66
|
+
|
|
67
|
+
- Extracting pool information
|
|
68
|
+
- Handling swap operations
|
|
69
|
+
- Calculating prices and TVL (Total Value Locked)
|
|
70
|
+
|
|
71
|
+
### AbstractPairState
|
|
72
|
+
The `AbstractPairState` class in `base.py` defines the interface for all pair states (both AMM and orderbook-based). It includes abstract methods that must be implemented by specific DEX classes.
|
|
73
|
+
### Assets
|
|
74
|
+
The `Assets` class in `models.py` represents a collection of assets (tokens) and their quantities. It provides utility methods for working with asset collections, including addition and subtraction operations.
|
|
75
|
+
## Configuration
|
|
76
|
+
Charli3 Dendrite can be configured using environment variables or a `.env` file. See `sample.env` for an example of the configuration options.
|
|
77
|
+
|
|
78
|
+
### Data Provider Configuration
|
|
79
|
+
|
|
80
|
+
Charli3 Dendrite supports multiple data providers to fetch on-chain data. Currently, it supports Blockfrost and DBSync, with plans to add Ogmios and Kupo in the future.
|
|
81
|
+
|
|
82
|
+
#### Blockfrost Configuration
|
|
83
|
+
|
|
84
|
+
Blockfrost is the default data provider for Charli3 Dendrite. To use Blockfrost, you need to set up your API key in the environment variables or `.env` file:
|
|
85
|
+
```
|
|
86
|
+
PROJECT_ID="your-blockfrost-project-id"
|
|
87
|
+
NETWORK="mainnet" # or "testnet" for the Cardano testnet
|
|
88
|
+
```
|
|
89
|
+
#### DBSync Configuration
|
|
90
|
+
Charli3 Dendrite also supports using a DBSync instance as a data provider. To configure DBSync, set the following environment variables:
|
|
91
|
+
```bash
|
|
92
|
+
DBSYNC_HOST="your-dbsync-host"
|
|
93
|
+
DBSYNC_PORT="your-dbsync-port"
|
|
94
|
+
DBSYNC_DB_NAME="your-dbsync-database-name"
|
|
95
|
+
DBSYNC_USER="your-dbsync-username"
|
|
96
|
+
DBSYNC_PASS="your-dbsync-password"
|
|
97
|
+
```
|
|
98
|
+
#### Future Plans: Ogmios and Kupo
|
|
99
|
+
We are planning to add support for Ogmios and Kupo as additional data providers in future releases. These will offer alternative ways to interact with the Cardano blockchain and may provide performance improvements or additional features.
|
|
100
|
+
Stay tuned for updates on the integration of these providers. Once implemented, they will be configurable in a similar manner to the existing providers.
|
|
101
|
+
### Wallet Configuration
|
|
102
|
+
Charli3 Dendrite supports wallet integration for performing transactions. You can configure a wallet using a mnemonic phrase:
|
|
103
|
+
```bash
|
|
104
|
+
WALLET_MNEMONIC="your wallet mnemonic phrase"
|
|
105
|
+
```
|
|
106
|
+
## Development
|
|
107
|
+
To set up the development environment:
|
|
108
|
+
|
|
109
|
+
1. Clone the repository
|
|
110
|
+
2. Install dependencies: `poetry install`
|
|
111
|
+
3. Set up pre-commit hooks: `pre-commit install`
|
|
112
|
+
|
|
113
|
+
## Running Tests
|
|
114
|
+
```bash
|
|
115
|
+
poetry run pytest --benchmark-disable -v --slow -n auto
|
|
116
|
+
```
|
|
117
|
+
For parallel test execution:
|
|
118
|
+
```bash
|
|
119
|
+
poetry run pytest -n auto
|
|
120
|
+
```
|
|
121
|
+
## Contributing
|
|
122
|
+
Contributions to Charli3 Dendrite are welcome! Please refer to the `CONTRIBUTING.md` file for guidelines on how to contribute to the project.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "charli3_dendrite"
|
|
3
|
+
version = "0.2.0-dev116"
|
|
4
|
+
description = ""
|
|
5
|
+
authors = ["Elder Millenial <eldermillenial@protonmail.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
packages = [{include = "charli3_dendrite", from = "src"}]
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = "^3.10"
|
|
11
|
+
requests = "^2.31.0"
|
|
12
|
+
pydantic = "^2.5.2"
|
|
13
|
+
psycopg = {extras = ["binary", "pool"], version = "^3.1.13"}
|
|
14
|
+
python-dotenv = "0.21.1"
|
|
15
|
+
pycardano = "0.11.1"
|
|
16
|
+
blockfrost-python = "^0.5.3"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[tool.poetry.group.dev.dependencies]
|
|
20
|
+
black = "^23.11.0"
|
|
21
|
+
ruff = "^0.1.6"
|
|
22
|
+
pre-commit = "^3.5.0"
|
|
23
|
+
bump2version = "^1.0.1"
|
|
24
|
+
isort = "^5.13.2"
|
|
25
|
+
flake8 = "^6.1.0"
|
|
26
|
+
mypy = "^1.7.1"
|
|
27
|
+
pytest = "^7.4.3"
|
|
28
|
+
pytest-benchmark = "^4.0.0"
|
|
29
|
+
pytest-dependency = "^0.5.1"
|
|
30
|
+
pytest-xdist = "^3.6.1"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
[tool.poetry.group.devs.dependencies]
|
|
34
|
+
pytest-subtests = "^0.11.0"
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = ["poetry-core"]
|
|
38
|
+
build-backend = "poetry.core.masonry.api"
|
|
39
|
+
|
|
40
|
+
[tool.isort]
|
|
41
|
+
profile = "black"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# noqa
|
|
2
|
+
from charli3_dendrite.dexs.amm.minswap import MinswapCPPState
|
|
3
|
+
from charli3_dendrite.dexs.amm.minswap import MinswapDJEDiUSDStableState
|
|
4
|
+
from charli3_dendrite.dexs.amm.minswap import MinswapDJEDUSDCStableState
|
|
5
|
+
from charli3_dendrite.dexs.amm.minswap import MinswapDJEDUSDMStableState
|
|
6
|
+
from charli3_dendrite.dexs.amm.minswap import MinswapV2CPPState
|
|
7
|
+
from charli3_dendrite.dexs.amm.muesli import MuesliSwapCLPState
|
|
8
|
+
from charli3_dendrite.dexs.amm.muesli import MuesliSwapCPPState
|
|
9
|
+
from charli3_dendrite.dexs.amm.spectrum import SpectrumCPPState
|
|
10
|
+
from charli3_dendrite.dexs.amm.sundae import SundaeSwapCPPState
|
|
11
|
+
from charli3_dendrite.dexs.amm.sundae import SundaeSwapV3CPPState
|
|
12
|
+
from charli3_dendrite.dexs.amm.vyfi import VyFiCPPState
|
|
13
|
+
from charli3_dendrite.dexs.amm.wingriders import WingRidersCPPState
|
|
14
|
+
from charli3_dendrite.dexs.amm.wingriders import WingRidersSSPState
|
|
15
|
+
from charli3_dendrite.dexs.ob.axo import AxoOBMarketState
|
|
16
|
+
from charli3_dendrite.dexs.ob.geniusyield import GeniusYieldOrderBook
|
|
17
|
+
from charli3_dendrite.dexs.ob.geniusyield import GeniusYieldOrderState
|
|
18
|
+
from charli3_dendrite.utility import Assets
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Backend Management Module for Charli3 Dendrite.
|
|
2
|
+
|
|
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 backend,
|
|
5
|
+
as well as to set a default backend based on environment variables.
|
|
6
|
+
|
|
7
|
+
The module uses a global variable to store the current backend instance, which
|
|
8
|
+
can be accessed and modified using the provided functions. This approach allows
|
|
9
|
+
for easy switching between different backend implementations and provides a
|
|
10
|
+
convenient way to set up a default backend.
|
|
11
|
+
|
|
12
|
+
Typical usage:
|
|
13
|
+
from charli3_dendrite.backends import get_backend, set_backend
|
|
14
|
+
from charli3_dendrite.backend.custom_backend import CustomBackend
|
|
15
|
+
|
|
16
|
+
# Get the current backend (initializes a default if not set)
|
|
17
|
+
backend = get_backend()
|
|
18
|
+
|
|
19
|
+
# Set a custom backend
|
|
20
|
+
set_backend(CustomBackend())
|
|
21
|
+
|
|
22
|
+
Note: This module relies on environment variables for setting up the default backend.
|
|
23
|
+
Ensure that the necessary environment variables are set before using this module.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
import os
|
|
27
|
+
from typing import Optional
|
|
28
|
+
|
|
29
|
+
from dotenv import load_dotenv
|
|
30
|
+
|
|
31
|
+
from charli3_dendrite.backend.backend_base import AbstractBackend
|
|
32
|
+
from charli3_dendrite.backend.dbsync import DbsyncBackend
|
|
33
|
+
|
|
34
|
+
# Load environment variables from .env file
|
|
35
|
+
load_dotenv()
|
|
36
|
+
|
|
37
|
+
# Global variable to store the current backend instance
|
|
38
|
+
BACKEND: Optional[AbstractBackend] = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def get_backend() -> AbstractBackend:
|
|
42
|
+
"""Retrieve the current backend instance.
|
|
43
|
+
|
|
44
|
+
If no backend has been set, this function attempts to set a default backend
|
|
45
|
+
based on environment variables. If no default can be set, it raises a ValueError.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
AbstractBackend: The current backend instance.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
ValueError: If no backend has been set and no default can be determined.
|
|
52
|
+
"""
|
|
53
|
+
if BACKEND is None:
|
|
54
|
+
set_default_backend()
|
|
55
|
+
if BACKEND is None:
|
|
56
|
+
raise ValueError("Backend has not been set. Call set_backend() first.")
|
|
57
|
+
return BACKEND
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def set_backend(backend: AbstractBackend) -> None:
|
|
61
|
+
"""Set the global backend instance.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
backend (AbstractBackend): The backend instance to set as the global backend.
|
|
65
|
+
"""
|
|
66
|
+
global BACKEND # noqa: PLW0603
|
|
67
|
+
BACKEND = backend
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def set_default_backend() -> None:
|
|
71
|
+
"""Attempt to set a default backend based on environment variables.
|
|
72
|
+
|
|
73
|
+
This function checks for the presence of specific environment variables
|
|
74
|
+
to determine which backend to use as the default. Currently, it only
|
|
75
|
+
checks for DBSync-related variables, but can be extended to support
|
|
76
|
+
other backend types in the future.
|
|
77
|
+
"""
|
|
78
|
+
# Check for DBSync environment variables
|
|
79
|
+
dbsync_vars = [
|
|
80
|
+
"DBSYNC_USER",
|
|
81
|
+
"DBSYNC_PASS",
|
|
82
|
+
"DBSYNC_HOST",
|
|
83
|
+
"DBSYNC_PORT",
|
|
84
|
+
"DBSYNC_DB_NAME",
|
|
85
|
+
]
|
|
86
|
+
if all(env_var in os.environ for env_var in dbsync_vars):
|
|
87
|
+
set_backend(DbsyncBackend())
|
|
88
|
+
|
|
89
|
+
""" TODO: Add checks for other backend types here as needed
|
|
90
|
+
For example:
|
|
91
|
+
elif all(env_var in os.environ for env_var in other_backend_vars):
|
|
92
|
+
set_backend(OtherBackend())
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# Optional: Initialize the backend when the module is imported
|
|
97
|
+
set_default_backend()
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Abstract base class for Cardano blockchain backend implementations."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC
|
|
4
|
+
from abc import abstractmethod
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from pycardano import Address
|
|
8
|
+
|
|
9
|
+
from charli3_dendrite.dataclasses.models import BlockList
|
|
10
|
+
from charli3_dendrite.dataclasses.models import PoolStateList
|
|
11
|
+
from charli3_dendrite.dataclasses.models import ScriptReference
|
|
12
|
+
from charli3_dendrite.dataclasses.models import SwapTransactionList
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AbstractBackend(ABC):
|
|
16
|
+
"""Abstract base class for Cardano blockchain backend implementations.
|
|
17
|
+
|
|
18
|
+
This class defines the interface for interacting with various Cardano blockchain
|
|
19
|
+
data sources such as db-sync, Ogmios, or Kupo.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def get_pool_utxos( # noqa: PLR0913
|
|
24
|
+
self,
|
|
25
|
+
assets: list[str] | None = None,
|
|
26
|
+
addresses: list[str] | None = None,
|
|
27
|
+
limit: int = 1000,
|
|
28
|
+
page: int = 0,
|
|
29
|
+
historical: bool = True,
|
|
30
|
+
) -> PoolStateList:
|
|
31
|
+
"""Get UTXOs for specific assets or addresses.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
assets (Optional[List[str]]): List of asset IDs to filter by.
|
|
35
|
+
addresses (Optional[List[str]]): List of addresses to filter by.
|
|
36
|
+
limit (int): Maximum number of results to return.
|
|
37
|
+
page (int): Page number for pagination.
|
|
38
|
+
historical (bool): Whether to include historical data.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
PoolStateList: List of pool state objects.
|
|
42
|
+
"""
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def get_pool_in_tx(
|
|
47
|
+
self,
|
|
48
|
+
tx_hash: str,
|
|
49
|
+
assets: list[str] | None = None,
|
|
50
|
+
addresses: list[str] | None = None,
|
|
51
|
+
) -> PoolStateList:
|
|
52
|
+
"""Get pool state for a specific transaction.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
tx_hash (str): The transaction hash to query.
|
|
56
|
+
assets (Optional[List[str]]): List of asset IDs to filter by.
|
|
57
|
+
addresses (Optional[List[str]]): List of addresses to filter by.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
PoolStateList: List of pool state objects for the transaction.
|
|
61
|
+
"""
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
@abstractmethod
|
|
65
|
+
def last_block(self, last_n_blocks: int = 2) -> BlockList:
|
|
66
|
+
"""Get information about the last n blocks.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
last_n_blocks (int): Number of recent blocks to retrieve.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
BlockList: List of recent block information.
|
|
73
|
+
"""
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
@abstractmethod
|
|
77
|
+
def get_pool_utxos_in_block(self, block_no: int) -> PoolStateList:
|
|
78
|
+
"""Get pool UTXOs for a specific block.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
block_no (int): The block number to query.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
PoolStateList: List of pool state objects for the block.
|
|
85
|
+
"""
|
|
86
|
+
pass
|
|
87
|
+
|
|
88
|
+
@abstractmethod
|
|
89
|
+
def get_script_from_address(self, address: Address) -> ScriptReference:
|
|
90
|
+
"""Get script reference for a given address.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
address (Address): The address to query.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
ScriptReference: Script reference for the address.
|
|
97
|
+
"""
|
|
98
|
+
pass
|
|
99
|
+
|
|
100
|
+
@abstractmethod
|
|
101
|
+
def get_historical_order_utxos(
|
|
102
|
+
self,
|
|
103
|
+
stake_addresses: list[str],
|
|
104
|
+
after_time: datetime | int | None = None,
|
|
105
|
+
limit: int = 1000,
|
|
106
|
+
page: int = 0,
|
|
107
|
+
) -> SwapTransactionList:
|
|
108
|
+
"""Get historical order UTXOs for given stake addresses.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
stake_addresses (List[str]): List of stake addresses to query.
|
|
112
|
+
after_time (Optional[Union[datetime, int]]): Filter results after this time.
|
|
113
|
+
limit (int): Maximum number of results to return.
|
|
114
|
+
page (int): Page number for pagination.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
SwapTransactionList: List of swap transaction objects.
|
|
118
|
+
"""
|
|
119
|
+
pass
|
|
120
|
+
|
|
121
|
+
@abstractmethod
|
|
122
|
+
def get_order_utxos_by_block_or_tx( # noqa: PLR0913
|
|
123
|
+
self,
|
|
124
|
+
stake_addresses: list[str],
|
|
125
|
+
out_tx_hash: list[str] | None = None,
|
|
126
|
+
in_tx_hash: list[str] | None = None,
|
|
127
|
+
block_no: int | None = None,
|
|
128
|
+
after_block: int | None = None,
|
|
129
|
+
limit: int = 1000,
|
|
130
|
+
page: int = 0,
|
|
131
|
+
) -> SwapTransactionList:
|
|
132
|
+
"""Get order UTXOs by block or transaction.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
stake_addresses (List[str]): List of stake addresses to query.
|
|
136
|
+
out_tx_hash (Optional[List[str]]): List of transaction hashes to filter by.
|
|
137
|
+
in_tx_hash: list of input transaction hashes to filter by.
|
|
138
|
+
block_no (Optional[int]): Specific block number to query.
|
|
139
|
+
after_block (Optional[int]): Filter results after this block number.
|
|
140
|
+
limit (int): Maximum number of results to return.
|
|
141
|
+
page (int): Page number for pagination.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
SwapTransactionList: List of swap transaction objects.
|
|
145
|
+
"""
|
|
146
|
+
pass
|
|
147
|
+
|
|
148
|
+
@abstractmethod
|
|
149
|
+
def get_cancel_utxos( # noqa: PLR0913
|
|
150
|
+
self,
|
|
151
|
+
stake_addresses: list[str],
|
|
152
|
+
block_no: int | None = None,
|
|
153
|
+
after_time: datetime | int | None = None,
|
|
154
|
+
limit: int = 1000,
|
|
155
|
+
page: int = 0,
|
|
156
|
+
) -> SwapTransactionList:
|
|
157
|
+
"""Get cancelled order UTXOs.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
stake_addresses (List[str]): List of stake addresses to query.
|
|
161
|
+
block_no (Optional[int]): Specific block number to query.
|
|
162
|
+
after_time (Optional[Union[datetime, int]]): Filter results after this time.
|
|
163
|
+
limit (int): Maximum number of results to return.
|
|
164
|
+
page (int): Page number for pagination.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
SwapTransactionList: List of swap transaction objects for cancelled orders.
|
|
168
|
+
"""
|
|
169
|
+
pass
|
|
170
|
+
|
|
171
|
+
@abstractmethod
|
|
172
|
+
def get_datum_from_address(
|
|
173
|
+
self,
|
|
174
|
+
address: str,
|
|
175
|
+
asset: str | None = None,
|
|
176
|
+
) -> str | None:
|
|
177
|
+
"""Get datum from a given address.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
address: The address to query.
|
|
181
|
+
asset: Assets required to be in the UTxO.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
The datum associated with the address, if any.
|
|
185
|
+
"""
|
|
186
|
+
pass
|
|
File without changes
|