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.
- decibel/__init__.py +247 -0
- decibel/_base.py +726 -0
- decibel/_constants.py +164 -0
- decibel/_fee_pay.py +301 -0
- decibel/_gas_price_manager.py +262 -0
- decibel/_order_status.py +138 -0
- decibel/_order_types.py +109 -0
- decibel/_pagination.py +82 -0
- decibel/_subaccount_types.py +43 -0
- decibel/_transaction_builder.py +325 -0
- decibel/_utils.py +432 -0
- decibel/_version.py +1 -0
- decibel/abi/__init__.py +23 -0
- decibel/abi/__main__.py +4 -0
- decibel/abi/_registry.py +89 -0
- decibel/abi/_types.py +55 -0
- decibel/abi/generate.py +183 -0
- decibel/abi/json/netna.json +2417 -0
- decibel/abi/json/testnet.json +2919 -0
- decibel/admin.py +868 -0
- decibel/py.typed +0 -0
- decibel/read/__init__.py +279 -0
- decibel/read/_account_overview.py +119 -0
- decibel/read/_base.py +137 -0
- decibel/read/_candlesticks.py +97 -0
- decibel/read/_delegations.py +32 -0
- decibel/read/_leaderboard.py +64 -0
- decibel/read/_market_contexts.py +35 -0
- decibel/read/_market_depth.py +81 -0
- decibel/read/_market_prices.py +100 -0
- decibel/read/_market_trades.py +81 -0
- decibel/read/_markets.py +146 -0
- decibel/read/_portfolio_chart.py +48 -0
- decibel/read/_trading_points.py +36 -0
- decibel/read/_types.py +136 -0
- decibel/read/_user_active_twaps.py +70 -0
- decibel/read/_user_bulk_orders.py +73 -0
- decibel/read/_user_fund_history.py +49 -0
- decibel/read/_user_funding_history.py +45 -0
- decibel/read/_user_notifications.py +87 -0
- decibel/read/_user_open_orders.py +91 -0
- decibel/read/_user_order_history.py +101 -0
- decibel/read/_user_positions.py +84 -0
- decibel/read/_user_subaccounts.py +35 -0
- decibel/read/_user_trade_history.py +77 -0
- decibel/read/_user_twap_history.py +32 -0
- decibel/read/_vaults.py +218 -0
- decibel/read/_ws.py +245 -0
- decibel/write/__init__.py +1949 -0
- decibel/write/_types.py +190 -0
- decibel_python_sdk-0.1.0.dist-info/METADATA +255 -0
- decibel_python_sdk-0.1.0.dist-info/RECORD +53 -0
- decibel_python_sdk-0.1.0.dist-info/WHEEL +4 -0
decibel/abi/generate.py
ADDED
|
@@ -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()
|