decibel-python-sdk 0.1.0__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.
Files changed (53) hide show
  1. decibel/__init__.py +247 -0
  2. decibel/_base.py +726 -0
  3. decibel/_constants.py +164 -0
  4. decibel/_fee_pay.py +301 -0
  5. decibel/_gas_price_manager.py +262 -0
  6. decibel/_order_status.py +138 -0
  7. decibel/_order_types.py +109 -0
  8. decibel/_pagination.py +82 -0
  9. decibel/_subaccount_types.py +43 -0
  10. decibel/_transaction_builder.py +325 -0
  11. decibel/_utils.py +432 -0
  12. decibel/_version.py +1 -0
  13. decibel/abi/__init__.py +23 -0
  14. decibel/abi/__main__.py +4 -0
  15. decibel/abi/_registry.py +89 -0
  16. decibel/abi/_types.py +55 -0
  17. decibel/abi/generate.py +183 -0
  18. decibel/abi/json/netna.json +2417 -0
  19. decibel/abi/json/testnet.json +2919 -0
  20. decibel/admin.py +868 -0
  21. decibel/py.typed +0 -0
  22. decibel/read/__init__.py +279 -0
  23. decibel/read/_account_overview.py +119 -0
  24. decibel/read/_base.py +137 -0
  25. decibel/read/_candlesticks.py +97 -0
  26. decibel/read/_delegations.py +32 -0
  27. decibel/read/_leaderboard.py +64 -0
  28. decibel/read/_market_contexts.py +35 -0
  29. decibel/read/_market_depth.py +81 -0
  30. decibel/read/_market_prices.py +100 -0
  31. decibel/read/_market_trades.py +81 -0
  32. decibel/read/_markets.py +146 -0
  33. decibel/read/_portfolio_chart.py +48 -0
  34. decibel/read/_trading_points.py +36 -0
  35. decibel/read/_types.py +136 -0
  36. decibel/read/_user_active_twaps.py +70 -0
  37. decibel/read/_user_bulk_orders.py +73 -0
  38. decibel/read/_user_fund_history.py +49 -0
  39. decibel/read/_user_funding_history.py +45 -0
  40. decibel/read/_user_notifications.py +87 -0
  41. decibel/read/_user_open_orders.py +91 -0
  42. decibel/read/_user_order_history.py +101 -0
  43. decibel/read/_user_positions.py +84 -0
  44. decibel/read/_user_subaccounts.py +35 -0
  45. decibel/read/_user_trade_history.py +77 -0
  46. decibel/read/_user_twap_history.py +32 -0
  47. decibel/read/_vaults.py +218 -0
  48. decibel/read/_ws.py +245 -0
  49. decibel/write/__init__.py +1949 -0
  50. decibel/write/_types.py +190 -0
  51. decibel_python_sdk-0.1.0.dist-info/METADATA +255 -0
  52. decibel_python_sdk-0.1.0.dist-info/RECORD +53 -0
  53. decibel_python_sdk-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,183 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import asyncio
5
+ import json
6
+ import logging
7
+ import sys
8
+ from datetime import UTC, datetime
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ from aptos_sdk.account_address import AccountAddress
13
+ from aptos_sdk.async_client import RestClient
14
+
15
+ from decibel._constants import NAMED_CONFIGS, NETNA_CONFIG, TESTNET_CONFIG, DecibelConfig
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+
20
+ def _setup_cli_logging() -> None:
21
+ logging.basicConfig(
22
+ level=logging.INFO,
23
+ format="%(message)s",
24
+ )
25
+
26
+
27
+ SDK_MODULES = [
28
+ "admin_apis",
29
+ "public_apis",
30
+ "dex_accounts",
31
+ "dex_accounts_entry",
32
+ "dex_accounts_vault_extension",
33
+ "perp_engine",
34
+ "usdc",
35
+ "vault",
36
+ "vault_api",
37
+ ]
38
+
39
+
40
+ def get_abi_filename(config: DecibelConfig) -> str:
41
+ if config == NETNA_CONFIG:
42
+ return "netna.json"
43
+ elif config == TESTNET_CONFIG:
44
+ return "testnet.json"
45
+ else:
46
+ return f"{config.network.value}.json"
47
+
48
+
49
+ async def fetch_all_abis(config: DecibelConfig) -> None:
50
+ logger.info("Fetching ABIs for Decibel SDK functions...")
51
+ logger.info("Package: %s", config.deployment.package)
52
+ logger.info("Network: %s", config.network.value)
53
+ logger.info("Fullnode: %s", config.fullnode_url)
54
+ logger.info("")
55
+
56
+ if not config.deployment.package or not config.fullnode_url:
57
+ logger.error("Error: config.package or config.fullnode_url is not set")
58
+ sys.exit(1)
59
+
60
+ client = RestClient(config.fullnode_url)
61
+ abis: dict[str, dict[str, Any]] = {}
62
+ errors: list[dict[str, str]] = []
63
+ package_address = AccountAddress.from_str(config.deployment.package)
64
+
65
+ for module in SDK_MODULES:
66
+ try:
67
+ logger.info("Fetching entire module: %s", module)
68
+
69
+ module_info: dict[str, Any] = await client.account_module( # pyright: ignore[reportUnknownMemberType,reportUnknownVariableType]
70
+ package_address,
71
+ module,
72
+ )
73
+
74
+ abi: dict[str, Any] | None = module_info.get("abi")
75
+ if not abi:
76
+ raise ValueError("Module or ABI not found")
77
+
78
+ exposed_functions: list[dict[str, Any]] = abi.get("exposed_functions", [])
79
+ relevant_functions: list[dict[str, Any]] = [
80
+ f for f in exposed_functions if f.get("is_entry") or f.get("is_view")
81
+ ]
82
+
83
+ logger.info("Found %d exposed functions in %s", len(exposed_functions), module)
84
+ logger.info("Keeping %d functions in %s", len(relevant_functions), module)
85
+
86
+ for func in relevant_functions:
87
+ function_id = f"{config.deployment.package}::{module}::{func['name']}"
88
+ abis[function_id] = func
89
+
90
+ logger.info(
91
+ "Successfully collected %d functions from %s", len(relevant_functions), module
92
+ )
93
+
94
+ except Exception as e:
95
+ error_message = str(e)
96
+ logger.error("Error in %s: %s", module, error_message)
97
+ errors.append({"module": module, "function": "entire_module", "error": error_message})
98
+
99
+ await client.close()
100
+
101
+ total_functions = len(abis)
102
+ successful = total_functions
103
+ failed = len(errors)
104
+
105
+ result: dict[str, Any] = {
106
+ "packageAddress": config.deployment.package,
107
+ "network": config.network.value,
108
+ "fullnodeUrl": config.fullnode_url,
109
+ "fetchedAt": datetime.now(UTC).isoformat().replace("+00:00", "Z"),
110
+ "abis": abis,
111
+ "errors": errors,
112
+ "summary": {
113
+ "totalModules": len(SDK_MODULES),
114
+ "totalFunctions": total_functions,
115
+ "successful": successful,
116
+ "failed": failed,
117
+ },
118
+ "modules": SDK_MODULES,
119
+ }
120
+
121
+ filename = get_abi_filename(config)
122
+ output_path = Path(__file__).parent / "json" / filename
123
+ output_path.parent.mkdir(parents=True, exist_ok=True)
124
+
125
+ with open(output_path, "w") as f:
126
+ json.dump(result, f, indent=2)
127
+
128
+ logger.info("")
129
+ logger.info("Summary:")
130
+ logger.info(" Total modules fetched: %d", len(SDK_MODULES))
131
+ logger.info(" Total functions found: %d", successful)
132
+ logger.info(" Failed modules: %d", failed)
133
+
134
+ if errors:
135
+ logger.info("")
136
+ logger.info("Errors:")
137
+ for err in errors:
138
+ logger.info(" %s::%s: %s", err["module"], err["function"], err["error"])
139
+
140
+ logger.info("")
141
+ logger.info("ABIs saved to: %s", output_path)
142
+ logger.info("")
143
+ logger.info("ABI fetching complete!")
144
+
145
+
146
+ async def main(networks: list[str]) -> None:
147
+ for network in networks:
148
+ config = NAMED_CONFIGS.get(network)
149
+ if not config:
150
+ logger.error("Unknown network: %s", network)
151
+ logger.error("Available networks: %s", ", ".join(NAMED_CONFIGS.keys()))
152
+ sys.exit(1)
153
+
154
+ try:
155
+ await fetch_all_abis(config)
156
+ except Exception as e:
157
+ logger.error("Failed to fetch ABIs for %s: %s", network, e)
158
+
159
+
160
+ def cli() -> None:
161
+ _setup_cli_logging()
162
+ parser = argparse.ArgumentParser(
163
+ description="Fetch ABIs from the Decibel smart contract",
164
+ prog="python -m decibel.abi.generate",
165
+ )
166
+ parser.add_argument(
167
+ "networks",
168
+ nargs="*",
169
+ default=["netna"],
170
+ help="Networks to fetch ABIs for (netna, testnet, all). Default: netna",
171
+ )
172
+
173
+ args = parser.parse_args()
174
+
175
+ networks: list[str] = args.networks
176
+ if "all" in networks:
177
+ networks = ["netna", "testnet"]
178
+
179
+ asyncio.run(main(networks))
180
+
181
+
182
+ if __name__ == "__main__":
183
+ cli()