charli3_dendrite 0.2.0.dev116__py3-none-any.whl

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.
@@ -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