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/admin.py
ADDED
|
@@ -0,0 +1,868 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
from aptos_sdk.account_address import AccountAddress
|
|
7
|
+
|
|
8
|
+
from ._base import BaseSDK, BaseSDKSync
|
|
9
|
+
from ._transaction_builder import InputEntryFunctionData
|
|
10
|
+
from ._utils import get_market_addr
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from aptos_sdk.account import Account
|
|
14
|
+
|
|
15
|
+
from ._base import BaseSDKOptions, BaseSDKOptionsSync
|
|
16
|
+
from ._constants import DecibelConfig
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"DecibelAdminDex",
|
|
20
|
+
"DecibelAdminDexSync",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DecibelAdminDex(BaseSDK):
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
config: DecibelConfig,
|
|
28
|
+
account: Account,
|
|
29
|
+
opts: BaseSDKOptions | None = None,
|
|
30
|
+
) -> None:
|
|
31
|
+
super().__init__(config, account, opts)
|
|
32
|
+
|
|
33
|
+
async def initialize(
|
|
34
|
+
self,
|
|
35
|
+
collateral_token_addr: str,
|
|
36
|
+
backstop_liquidator_addr: str,
|
|
37
|
+
) -> dict[str, Any]:
|
|
38
|
+
pkg = self._config.deployment.package
|
|
39
|
+
return await self._send_tx(
|
|
40
|
+
InputEntryFunctionData(
|
|
41
|
+
function=f"{pkg}::admin_apis::initialize",
|
|
42
|
+
type_arguments=[],
|
|
43
|
+
function_arguments=[
|
|
44
|
+
collateral_token_addr,
|
|
45
|
+
backstop_liquidator_addr,
|
|
46
|
+
],
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def get_protocol_vault_address(self) -> AccountAddress:
|
|
51
|
+
package_addr = AccountAddress.from_str(self._config.deployment.package)
|
|
52
|
+
vault_config_addr = AccountAddress.for_named_object(package_addr, b"GlobalVaultConfig")
|
|
53
|
+
return AccountAddress.for_named_object(vault_config_addr, b"Decibel Protocol Vault")
|
|
54
|
+
|
|
55
|
+
async def initialize_protocol_vault(
|
|
56
|
+
self,
|
|
57
|
+
collateral_token_addr: str,
|
|
58
|
+
initial_funding: int,
|
|
59
|
+
) -> dict[str, Any]:
|
|
60
|
+
pkg = self._config.deployment.package
|
|
61
|
+
return await self._send_tx(
|
|
62
|
+
InputEntryFunctionData(
|
|
63
|
+
function=f"{pkg}::vault_api::create_and_fund_vault",
|
|
64
|
+
type_arguments=[],
|
|
65
|
+
function_arguments=[
|
|
66
|
+
self.get_primary_subaccount_address(self._account.address()),
|
|
67
|
+
collateral_token_addr,
|
|
68
|
+
"Decibel Protocol Vault",
|
|
69
|
+
"(description)",
|
|
70
|
+
[],
|
|
71
|
+
"DPV",
|
|
72
|
+
"",
|
|
73
|
+
"",
|
|
74
|
+
0, # fee_bps
|
|
75
|
+
0, # fee_interval
|
|
76
|
+
3 * 24 * 60 * 60, # contribution_lockup_duration_s
|
|
77
|
+
initial_funding,
|
|
78
|
+
True, # accepts_contributions
|
|
79
|
+
False, # delegate_to_creator
|
|
80
|
+
],
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
async def delegate_protocol_vault_trading_to(
|
|
85
|
+
self,
|
|
86
|
+
vault_address: str,
|
|
87
|
+
account_to_delegate_to: str,
|
|
88
|
+
) -> dict[str, Any]:
|
|
89
|
+
pkg = self._config.deployment.package
|
|
90
|
+
return await self._send_tx(
|
|
91
|
+
InputEntryFunctionData(
|
|
92
|
+
function=f"{pkg}::vault_admin_api::delegate_dex_actions_to",
|
|
93
|
+
type_arguments=[],
|
|
94
|
+
function_arguments=[vault_address, account_to_delegate_to, None],
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
async def update_vault_use_global_redemption_slippage_adjustment(
|
|
99
|
+
self,
|
|
100
|
+
vault_address: str,
|
|
101
|
+
use_global_redemption_slippage_adjustment: bool,
|
|
102
|
+
) -> dict[str, Any]:
|
|
103
|
+
pkg = self._config.deployment.package
|
|
104
|
+
return await self._send_tx(
|
|
105
|
+
InputEntryFunctionData(
|
|
106
|
+
function=f"{pkg}::vault_admin_api::update_vault_use_global_redemption_slippage_adjustment",
|
|
107
|
+
type_arguments=[],
|
|
108
|
+
function_arguments=[vault_address, use_global_redemption_slippage_adjustment],
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
async def authorize_oracle_and_mark_update(
|
|
113
|
+
self,
|
|
114
|
+
internal_oracle_updater: str,
|
|
115
|
+
) -> dict[str, Any]:
|
|
116
|
+
pkg = self._config.deployment.package
|
|
117
|
+
return await self._send_tx(
|
|
118
|
+
InputEntryFunctionData(
|
|
119
|
+
function=f"{pkg}::admin_apis::add_oracle_and_mark_update_permission",
|
|
120
|
+
type_arguments=[],
|
|
121
|
+
function_arguments=[internal_oracle_updater],
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
async def add_access_control_admin(
|
|
126
|
+
self,
|
|
127
|
+
delegated_admin: str,
|
|
128
|
+
) -> dict[str, Any]:
|
|
129
|
+
pkg = self._config.deployment.package
|
|
130
|
+
return await self._send_tx(
|
|
131
|
+
InputEntryFunctionData(
|
|
132
|
+
function=f"{pkg}::admin_apis::add_access_control_admin",
|
|
133
|
+
type_arguments=[],
|
|
134
|
+
function_arguments=[delegated_admin],
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
async def add_market_list_admin(
|
|
139
|
+
self,
|
|
140
|
+
delegated_admin: str,
|
|
141
|
+
) -> dict[str, Any]:
|
|
142
|
+
pkg = self._config.deployment.package
|
|
143
|
+
return await self._send_tx(
|
|
144
|
+
InputEntryFunctionData(
|
|
145
|
+
function=f"{pkg}::admin_apis::add_market_list_admin",
|
|
146
|
+
type_arguments=[],
|
|
147
|
+
function_arguments=[delegated_admin],
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
async def add_market_risk_governor(
|
|
152
|
+
self,
|
|
153
|
+
delegated_admin: str,
|
|
154
|
+
) -> dict[str, Any]:
|
|
155
|
+
pkg = self._config.deployment.package
|
|
156
|
+
return await self._send_tx(
|
|
157
|
+
InputEntryFunctionData(
|
|
158
|
+
function=f"{pkg}::admin_apis::add_market_risk_governor",
|
|
159
|
+
type_arguments=[],
|
|
160
|
+
function_arguments=[delegated_admin],
|
|
161
|
+
)
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
async def register_market_with_internal_oracle(
|
|
165
|
+
self,
|
|
166
|
+
name: str,
|
|
167
|
+
sz_decimals: int,
|
|
168
|
+
min_size: int,
|
|
169
|
+
lot_size: int,
|
|
170
|
+
ticker_size: int,
|
|
171
|
+
max_open_interest: int,
|
|
172
|
+
max_leverage: int,
|
|
173
|
+
margin_call_fee_pct: int,
|
|
174
|
+
taker_in_next_block: bool = True,
|
|
175
|
+
initial_oracle_price: int = 1,
|
|
176
|
+
max_staleness_secs: int = 60,
|
|
177
|
+
) -> dict[str, Any]:
|
|
178
|
+
pkg = self._config.deployment.package
|
|
179
|
+
return await self._send_tx(
|
|
180
|
+
InputEntryFunctionData(
|
|
181
|
+
function=f"{pkg}::admin_apis::register_market_with_internal_oracle",
|
|
182
|
+
type_arguments=[],
|
|
183
|
+
function_arguments=[
|
|
184
|
+
name,
|
|
185
|
+
sz_decimals,
|
|
186
|
+
min_size,
|
|
187
|
+
lot_size,
|
|
188
|
+
ticker_size,
|
|
189
|
+
max_open_interest,
|
|
190
|
+
max_leverage,
|
|
191
|
+
margin_call_fee_pct,
|
|
192
|
+
taker_in_next_block,
|
|
193
|
+
initial_oracle_price,
|
|
194
|
+
max_staleness_secs,
|
|
195
|
+
],
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
async def register_market_with_pyth_oracle(
|
|
200
|
+
self,
|
|
201
|
+
name: str,
|
|
202
|
+
sz_decimals: int,
|
|
203
|
+
min_size: int,
|
|
204
|
+
lot_size: int,
|
|
205
|
+
ticker_size: int,
|
|
206
|
+
max_open_interest: int,
|
|
207
|
+
max_leverage: int,
|
|
208
|
+
margin_call_fee_pct: int,
|
|
209
|
+
pyth_identifier_bytes: list[int],
|
|
210
|
+
pyth_max_staleness_secs: int,
|
|
211
|
+
pyth_confidence_interval_threshold: int,
|
|
212
|
+
pyth_decimals: int,
|
|
213
|
+
taker_in_next_block: bool = True,
|
|
214
|
+
) -> dict[str, Any]:
|
|
215
|
+
pkg = self._config.deployment.package
|
|
216
|
+
return await self._send_tx(
|
|
217
|
+
InputEntryFunctionData(
|
|
218
|
+
function=f"{pkg}::admin_apis::register_market_with_pyth_oracle",
|
|
219
|
+
type_arguments=[],
|
|
220
|
+
function_arguments=[
|
|
221
|
+
name,
|
|
222
|
+
sz_decimals,
|
|
223
|
+
min_size,
|
|
224
|
+
lot_size,
|
|
225
|
+
ticker_size,
|
|
226
|
+
max_open_interest,
|
|
227
|
+
max_leverage,
|
|
228
|
+
margin_call_fee_pct,
|
|
229
|
+
taker_in_next_block,
|
|
230
|
+
pyth_identifier_bytes,
|
|
231
|
+
pyth_max_staleness_secs,
|
|
232
|
+
pyth_confidence_interval_threshold,
|
|
233
|
+
pyth_decimals,
|
|
234
|
+
],
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
async def register_market_with_composite_oracle_primary_pyth(
|
|
239
|
+
self,
|
|
240
|
+
name: str,
|
|
241
|
+
sz_decimals: int,
|
|
242
|
+
min_size: int,
|
|
243
|
+
lot_size: int,
|
|
244
|
+
ticker_size: int,
|
|
245
|
+
max_open_interest: int,
|
|
246
|
+
max_leverage: int,
|
|
247
|
+
margin_call_fee_pct: int,
|
|
248
|
+
pyth_identifier_bytes: list[int],
|
|
249
|
+
pyth_max_staleness_secs: int,
|
|
250
|
+
pyth_confidence_interval_threshold: int,
|
|
251
|
+
pyth_decimals: int,
|
|
252
|
+
internal_initial_price: int,
|
|
253
|
+
internal_max_staleness_secs: int,
|
|
254
|
+
oracles_deviation_bps: int,
|
|
255
|
+
consecutive_deviation_count: int,
|
|
256
|
+
taker_in_next_block: bool = True,
|
|
257
|
+
) -> dict[str, Any]:
|
|
258
|
+
pkg = self._config.deployment.package
|
|
259
|
+
return await self._send_tx(
|
|
260
|
+
InputEntryFunctionData(
|
|
261
|
+
function=f"{pkg}::admin_apis::register_market_with_composite_oracle_primary_pyth",
|
|
262
|
+
type_arguments=[],
|
|
263
|
+
function_arguments=[
|
|
264
|
+
name,
|
|
265
|
+
sz_decimals,
|
|
266
|
+
min_size,
|
|
267
|
+
lot_size,
|
|
268
|
+
ticker_size,
|
|
269
|
+
max_open_interest,
|
|
270
|
+
max_leverage,
|
|
271
|
+
margin_call_fee_pct,
|
|
272
|
+
taker_in_next_block,
|
|
273
|
+
pyth_identifier_bytes,
|
|
274
|
+
pyth_max_staleness_secs,
|
|
275
|
+
pyth_confidence_interval_threshold,
|
|
276
|
+
pyth_decimals,
|
|
277
|
+
internal_initial_price,
|
|
278
|
+
internal_max_staleness_secs,
|
|
279
|
+
oracles_deviation_bps,
|
|
280
|
+
consecutive_deviation_count,
|
|
281
|
+
],
|
|
282
|
+
)
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
async def register_market_with_composite_oracle_primary_chainlink(
|
|
286
|
+
self,
|
|
287
|
+
name: str,
|
|
288
|
+
sz_decimals: int,
|
|
289
|
+
min_size: int,
|
|
290
|
+
lot_size: int,
|
|
291
|
+
ticker_size: int,
|
|
292
|
+
max_open_interest: int,
|
|
293
|
+
max_leverage: int,
|
|
294
|
+
margin_call_fee_pct: int,
|
|
295
|
+
rescale_decimals: int,
|
|
296
|
+
chainlink_feed_id_bytes: list[int],
|
|
297
|
+
chainlink_max_staleness_secs: int,
|
|
298
|
+
internal_max_staleness_secs: int,
|
|
299
|
+
internal_initial_price: int,
|
|
300
|
+
oracles_deviation_bps: int,
|
|
301
|
+
consecutive_deviation_count: int,
|
|
302
|
+
taker_in_next_block: bool = True,
|
|
303
|
+
) -> dict[str, Any]:
|
|
304
|
+
pkg = self._config.deployment.package
|
|
305
|
+
return await self._send_tx(
|
|
306
|
+
InputEntryFunctionData(
|
|
307
|
+
function=f"{pkg}::admin_apis::register_market_with_composite_oracle_primary_chainlink",
|
|
308
|
+
type_arguments=[],
|
|
309
|
+
function_arguments=[
|
|
310
|
+
name,
|
|
311
|
+
sz_decimals,
|
|
312
|
+
min_size,
|
|
313
|
+
lot_size,
|
|
314
|
+
ticker_size,
|
|
315
|
+
max_open_interest,
|
|
316
|
+
max_leverage,
|
|
317
|
+
margin_call_fee_pct,
|
|
318
|
+
taker_in_next_block,
|
|
319
|
+
chainlink_feed_id_bytes,
|
|
320
|
+
chainlink_max_staleness_secs,
|
|
321
|
+
rescale_decimals,
|
|
322
|
+
internal_initial_price,
|
|
323
|
+
internal_max_staleness_secs,
|
|
324
|
+
oracles_deviation_bps,
|
|
325
|
+
consecutive_deviation_count,
|
|
326
|
+
],
|
|
327
|
+
)
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
async def update_internal_oracle_price(
|
|
331
|
+
self,
|
|
332
|
+
market_name: str,
|
|
333
|
+
oracle_price: int,
|
|
334
|
+
) -> dict[str, Any]:
|
|
335
|
+
pkg = self._config.deployment.package
|
|
336
|
+
market_addr = get_market_addr(market_name, self._config.deployment.perp_engine_global)
|
|
337
|
+
return await self._send_tx(
|
|
338
|
+
InputEntryFunctionData(
|
|
339
|
+
function=f"{pkg}::admin_apis::update_mark_for_internal_oracle",
|
|
340
|
+
type_arguments=[],
|
|
341
|
+
function_arguments=[market_addr, oracle_price, [], [], True],
|
|
342
|
+
)
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
async def update_pyth_oracle_price(
|
|
346
|
+
self,
|
|
347
|
+
market_name: str,
|
|
348
|
+
vaa: list[int],
|
|
349
|
+
) -> dict[str, Any]:
|
|
350
|
+
pkg = self._config.deployment.package
|
|
351
|
+
market_addr = get_market_addr(market_name, self._config.deployment.perp_engine_global)
|
|
352
|
+
return await self._send_tx(
|
|
353
|
+
InputEntryFunctionData(
|
|
354
|
+
function=f"{pkg}::admin_apis::update_mark_for_pyth_oracle",
|
|
355
|
+
type_arguments=[],
|
|
356
|
+
function_arguments=[market_addr, vaa, [], [], True],
|
|
357
|
+
)
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
async def set_market_adl_trigger_threshold(
|
|
361
|
+
self,
|
|
362
|
+
market_name: str,
|
|
363
|
+
threshold: int,
|
|
364
|
+
) -> dict[str, Any]:
|
|
365
|
+
pkg = self._config.deployment.package
|
|
366
|
+
market_addr = get_market_addr(market_name, self._config.deployment.perp_engine_global)
|
|
367
|
+
return await self._send_tx(
|
|
368
|
+
InputEntryFunctionData(
|
|
369
|
+
function=f"{pkg}::admin_apis::set_market_adl_trigger_threshold",
|
|
370
|
+
type_arguments=[],
|
|
371
|
+
function_arguments=[market_addr, threshold],
|
|
372
|
+
)
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
async def update_price_to_pyth_only(
|
|
376
|
+
self,
|
|
377
|
+
vaas: list[list[int]],
|
|
378
|
+
) -> dict[str, Any]:
|
|
379
|
+
pkg = self._config.deployment.package
|
|
380
|
+
return await self._send_tx(
|
|
381
|
+
InputEntryFunctionData(
|
|
382
|
+
function=f"{pkg}::pyth::update_price_feeds_with_funder",
|
|
383
|
+
type_arguments=[],
|
|
384
|
+
function_arguments=[vaas],
|
|
385
|
+
)
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
async def update_price_to_chainlink_only(
|
|
389
|
+
self,
|
|
390
|
+
signed_report: list[int],
|
|
391
|
+
) -> dict[str, Any]:
|
|
392
|
+
pkg = self._config.deployment.package
|
|
393
|
+
return await self._send_tx(
|
|
394
|
+
InputEntryFunctionData(
|
|
395
|
+
function=f"{pkg}::chainlink_state::verify_and_store_single_price",
|
|
396
|
+
type_arguments=[],
|
|
397
|
+
function_arguments=[signed_report],
|
|
398
|
+
)
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
async def mint_usdc(
|
|
402
|
+
self,
|
|
403
|
+
to_addr: str | AccountAddress,
|
|
404
|
+
amount: int,
|
|
405
|
+
) -> dict[str, Any]:
|
|
406
|
+
pkg = self._config.deployment.package
|
|
407
|
+
addr = str(to_addr) if isinstance(to_addr, AccountAddress) else to_addr
|
|
408
|
+
return await self._send_tx(
|
|
409
|
+
InputEntryFunctionData(
|
|
410
|
+
function=f"{pkg}::usdc::mint",
|
|
411
|
+
type_arguments=[],
|
|
412
|
+
function_arguments=[addr, amount],
|
|
413
|
+
)
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
async def set_public_minting(
|
|
417
|
+
self,
|
|
418
|
+
allow: bool,
|
|
419
|
+
) -> dict[str, Any]:
|
|
420
|
+
pkg = self._config.deployment.package
|
|
421
|
+
return await self._send_tx(
|
|
422
|
+
InputEntryFunctionData(
|
|
423
|
+
function=f"{pkg}::usdc::set_public_minting",
|
|
424
|
+
type_arguments=[],
|
|
425
|
+
function_arguments=[allow],
|
|
426
|
+
)
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
async def usdc_balance(
|
|
430
|
+
self,
|
|
431
|
+
addr: str | AccountAddress,
|
|
432
|
+
) -> int:
|
|
433
|
+
addr_str = str(addr) if isinstance(addr, AccountAddress) else addr
|
|
434
|
+
result = await self._aptos.view(
|
|
435
|
+
"0x1::primary_fungible_store::balance",
|
|
436
|
+
["0x1::fungible_asset::Metadata"],
|
|
437
|
+
[addr_str, self._config.deployment.usdc],
|
|
438
|
+
)
|
|
439
|
+
return int(result[0])
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
class DecibelAdminDexSync(BaseSDKSync):
|
|
443
|
+
def __init__(
|
|
444
|
+
self,
|
|
445
|
+
config: DecibelConfig,
|
|
446
|
+
account: Account,
|
|
447
|
+
opts: BaseSDKOptionsSync | None = None,
|
|
448
|
+
) -> None:
|
|
449
|
+
super().__init__(config, account, opts)
|
|
450
|
+
|
|
451
|
+
def initialize(
|
|
452
|
+
self,
|
|
453
|
+
collateral_token_addr: str,
|
|
454
|
+
backstop_liquidator_addr: str,
|
|
455
|
+
) -> dict[str, Any]:
|
|
456
|
+
pkg = self._config.deployment.package
|
|
457
|
+
return self._send_tx(
|
|
458
|
+
InputEntryFunctionData(
|
|
459
|
+
function=f"{pkg}::admin_apis::initialize",
|
|
460
|
+
type_arguments=[],
|
|
461
|
+
function_arguments=[
|
|
462
|
+
collateral_token_addr,
|
|
463
|
+
backstop_liquidator_addr,
|
|
464
|
+
],
|
|
465
|
+
)
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
def get_protocol_vault_address(self) -> AccountAddress:
|
|
469
|
+
package_addr = AccountAddress.from_str(self._config.deployment.package)
|
|
470
|
+
vault_config_addr = AccountAddress.for_named_object(package_addr, b"GlobalVaultConfig")
|
|
471
|
+
return AccountAddress.for_named_object(vault_config_addr, b"Decibel Protocol Vault")
|
|
472
|
+
|
|
473
|
+
def initialize_protocol_vault(
|
|
474
|
+
self,
|
|
475
|
+
collateral_token_addr: str,
|
|
476
|
+
initial_funding: int,
|
|
477
|
+
) -> dict[str, Any]:
|
|
478
|
+
pkg = self._config.deployment.package
|
|
479
|
+
return self._send_tx(
|
|
480
|
+
InputEntryFunctionData(
|
|
481
|
+
function=f"{pkg}::vault_api::create_and_fund_vault",
|
|
482
|
+
type_arguments=[],
|
|
483
|
+
function_arguments=[
|
|
484
|
+
self.get_primary_subaccount_address(self._account.address()),
|
|
485
|
+
collateral_token_addr,
|
|
486
|
+
"Decibel Protocol Vault",
|
|
487
|
+
"(description)",
|
|
488
|
+
[],
|
|
489
|
+
"DPV",
|
|
490
|
+
"",
|
|
491
|
+
"",
|
|
492
|
+
0, # fee_bps
|
|
493
|
+
0, # fee_interval
|
|
494
|
+
3 * 24 * 60 * 60, # contribution_lockup_duration_s
|
|
495
|
+
initial_funding,
|
|
496
|
+
True, # accepts_contributions
|
|
497
|
+
False, # delegate_to_creator
|
|
498
|
+
],
|
|
499
|
+
)
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
def delegate_protocol_vault_trading_to(
|
|
503
|
+
self,
|
|
504
|
+
vault_address: str,
|
|
505
|
+
account_to_delegate_to: str,
|
|
506
|
+
) -> dict[str, Any]:
|
|
507
|
+
pkg = self._config.deployment.package
|
|
508
|
+
return self._send_tx(
|
|
509
|
+
InputEntryFunctionData(
|
|
510
|
+
function=f"{pkg}::vault_admin_api::delegate_dex_actions_to",
|
|
511
|
+
type_arguments=[],
|
|
512
|
+
function_arguments=[vault_address, account_to_delegate_to, None],
|
|
513
|
+
)
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
def update_vault_use_global_redemption_slippage_adjustment(
|
|
517
|
+
self,
|
|
518
|
+
vault_address: str,
|
|
519
|
+
use_global_redemption_slippage_adjustment: bool,
|
|
520
|
+
) -> dict[str, Any]:
|
|
521
|
+
pkg = self._config.deployment.package
|
|
522
|
+
return self._send_tx(
|
|
523
|
+
InputEntryFunctionData(
|
|
524
|
+
function=f"{pkg}::vault_admin_api::update_vault_use_global_redemption_slippage_adjustment",
|
|
525
|
+
type_arguments=[],
|
|
526
|
+
function_arguments=[vault_address, use_global_redemption_slippage_adjustment],
|
|
527
|
+
)
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
def authorize_oracle_and_mark_update(
|
|
531
|
+
self,
|
|
532
|
+
internal_oracle_updater: str,
|
|
533
|
+
) -> dict[str, Any]:
|
|
534
|
+
pkg = self._config.deployment.package
|
|
535
|
+
return self._send_tx(
|
|
536
|
+
InputEntryFunctionData(
|
|
537
|
+
function=f"{pkg}::admin_apis::add_oracle_and_mark_update_permission",
|
|
538
|
+
type_arguments=[],
|
|
539
|
+
function_arguments=[internal_oracle_updater],
|
|
540
|
+
)
|
|
541
|
+
)
|
|
542
|
+
|
|
543
|
+
def add_access_control_admin(
|
|
544
|
+
self,
|
|
545
|
+
delegated_admin: str,
|
|
546
|
+
) -> dict[str, Any]:
|
|
547
|
+
pkg = self._config.deployment.package
|
|
548
|
+
return self._send_tx(
|
|
549
|
+
InputEntryFunctionData(
|
|
550
|
+
function=f"{pkg}::admin_apis::add_access_control_admin",
|
|
551
|
+
type_arguments=[],
|
|
552
|
+
function_arguments=[delegated_admin],
|
|
553
|
+
)
|
|
554
|
+
)
|
|
555
|
+
|
|
556
|
+
def add_market_list_admin(
|
|
557
|
+
self,
|
|
558
|
+
delegated_admin: str,
|
|
559
|
+
) -> dict[str, Any]:
|
|
560
|
+
pkg = self._config.deployment.package
|
|
561
|
+
return self._send_tx(
|
|
562
|
+
InputEntryFunctionData(
|
|
563
|
+
function=f"{pkg}::admin_apis::add_market_list_admin",
|
|
564
|
+
type_arguments=[],
|
|
565
|
+
function_arguments=[delegated_admin],
|
|
566
|
+
)
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
def add_market_risk_governor(
|
|
570
|
+
self,
|
|
571
|
+
delegated_admin: str,
|
|
572
|
+
) -> dict[str, Any]:
|
|
573
|
+
pkg = self._config.deployment.package
|
|
574
|
+
return self._send_tx(
|
|
575
|
+
InputEntryFunctionData(
|
|
576
|
+
function=f"{pkg}::admin_apis::add_market_risk_governor",
|
|
577
|
+
type_arguments=[],
|
|
578
|
+
function_arguments=[delegated_admin],
|
|
579
|
+
)
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
def register_market_with_internal_oracle(
|
|
583
|
+
self,
|
|
584
|
+
name: str,
|
|
585
|
+
sz_decimals: int,
|
|
586
|
+
min_size: int,
|
|
587
|
+
lot_size: int,
|
|
588
|
+
ticker_size: int,
|
|
589
|
+
max_open_interest: int,
|
|
590
|
+
max_leverage: int,
|
|
591
|
+
margin_call_fee_pct: int,
|
|
592
|
+
taker_in_next_block: bool = True,
|
|
593
|
+
initial_oracle_price: int = 1,
|
|
594
|
+
max_staleness_secs: int = 60,
|
|
595
|
+
) -> dict[str, Any]:
|
|
596
|
+
pkg = self._config.deployment.package
|
|
597
|
+
return self._send_tx(
|
|
598
|
+
InputEntryFunctionData(
|
|
599
|
+
function=f"{pkg}::admin_apis::register_market_with_internal_oracle",
|
|
600
|
+
type_arguments=[],
|
|
601
|
+
function_arguments=[
|
|
602
|
+
name,
|
|
603
|
+
sz_decimals,
|
|
604
|
+
min_size,
|
|
605
|
+
lot_size,
|
|
606
|
+
ticker_size,
|
|
607
|
+
max_open_interest,
|
|
608
|
+
max_leverage,
|
|
609
|
+
margin_call_fee_pct,
|
|
610
|
+
taker_in_next_block,
|
|
611
|
+
initial_oracle_price,
|
|
612
|
+
max_staleness_secs,
|
|
613
|
+
],
|
|
614
|
+
)
|
|
615
|
+
)
|
|
616
|
+
|
|
617
|
+
def register_market_with_pyth_oracle(
|
|
618
|
+
self,
|
|
619
|
+
name: str,
|
|
620
|
+
sz_decimals: int,
|
|
621
|
+
min_size: int,
|
|
622
|
+
lot_size: int,
|
|
623
|
+
ticker_size: int,
|
|
624
|
+
max_open_interest: int,
|
|
625
|
+
max_leverage: int,
|
|
626
|
+
margin_call_fee_pct: int,
|
|
627
|
+
pyth_identifier_bytes: list[int],
|
|
628
|
+
pyth_max_staleness_secs: int,
|
|
629
|
+
pyth_confidence_interval_threshold: int,
|
|
630
|
+
pyth_decimals: int,
|
|
631
|
+
taker_in_next_block: bool = True,
|
|
632
|
+
) -> dict[str, Any]:
|
|
633
|
+
pkg = self._config.deployment.package
|
|
634
|
+
return self._send_tx(
|
|
635
|
+
InputEntryFunctionData(
|
|
636
|
+
function=f"{pkg}::admin_apis::register_market_with_pyth_oracle",
|
|
637
|
+
type_arguments=[],
|
|
638
|
+
function_arguments=[
|
|
639
|
+
name,
|
|
640
|
+
sz_decimals,
|
|
641
|
+
min_size,
|
|
642
|
+
lot_size,
|
|
643
|
+
ticker_size,
|
|
644
|
+
max_open_interest,
|
|
645
|
+
max_leverage,
|
|
646
|
+
margin_call_fee_pct,
|
|
647
|
+
taker_in_next_block,
|
|
648
|
+
pyth_identifier_bytes,
|
|
649
|
+
pyth_max_staleness_secs,
|
|
650
|
+
pyth_confidence_interval_threshold,
|
|
651
|
+
pyth_decimals,
|
|
652
|
+
],
|
|
653
|
+
)
|
|
654
|
+
)
|
|
655
|
+
|
|
656
|
+
def register_market_with_composite_oracle_primary_pyth(
|
|
657
|
+
self,
|
|
658
|
+
name: str,
|
|
659
|
+
sz_decimals: int,
|
|
660
|
+
min_size: int,
|
|
661
|
+
lot_size: int,
|
|
662
|
+
ticker_size: int,
|
|
663
|
+
max_open_interest: int,
|
|
664
|
+
max_leverage: int,
|
|
665
|
+
margin_call_fee_pct: int,
|
|
666
|
+
pyth_identifier_bytes: list[int],
|
|
667
|
+
pyth_max_staleness_secs: int,
|
|
668
|
+
pyth_confidence_interval_threshold: int,
|
|
669
|
+
pyth_decimals: int,
|
|
670
|
+
internal_initial_price: int,
|
|
671
|
+
internal_max_staleness_secs: int,
|
|
672
|
+
oracles_deviation_bps: int,
|
|
673
|
+
consecutive_deviation_count: int,
|
|
674
|
+
taker_in_next_block: bool = True,
|
|
675
|
+
) -> dict[str, Any]:
|
|
676
|
+
pkg = self._config.deployment.package
|
|
677
|
+
return self._send_tx(
|
|
678
|
+
InputEntryFunctionData(
|
|
679
|
+
function=f"{pkg}::admin_apis::register_market_with_composite_oracle_primary_pyth",
|
|
680
|
+
type_arguments=[],
|
|
681
|
+
function_arguments=[
|
|
682
|
+
name,
|
|
683
|
+
sz_decimals,
|
|
684
|
+
min_size,
|
|
685
|
+
lot_size,
|
|
686
|
+
ticker_size,
|
|
687
|
+
max_open_interest,
|
|
688
|
+
max_leverage,
|
|
689
|
+
margin_call_fee_pct,
|
|
690
|
+
taker_in_next_block,
|
|
691
|
+
pyth_identifier_bytes,
|
|
692
|
+
pyth_max_staleness_secs,
|
|
693
|
+
pyth_confidence_interval_threshold,
|
|
694
|
+
pyth_decimals,
|
|
695
|
+
internal_initial_price,
|
|
696
|
+
internal_max_staleness_secs,
|
|
697
|
+
oracles_deviation_bps,
|
|
698
|
+
consecutive_deviation_count,
|
|
699
|
+
],
|
|
700
|
+
)
|
|
701
|
+
)
|
|
702
|
+
|
|
703
|
+
def register_market_with_composite_oracle_primary_chainlink(
|
|
704
|
+
self,
|
|
705
|
+
name: str,
|
|
706
|
+
sz_decimals: int,
|
|
707
|
+
min_size: int,
|
|
708
|
+
lot_size: int,
|
|
709
|
+
ticker_size: int,
|
|
710
|
+
max_open_interest: int,
|
|
711
|
+
max_leverage: int,
|
|
712
|
+
margin_call_fee_pct: int,
|
|
713
|
+
rescale_decimals: int,
|
|
714
|
+
chainlink_feed_id_bytes: list[int],
|
|
715
|
+
chainlink_max_staleness_secs: int,
|
|
716
|
+
internal_max_staleness_secs: int,
|
|
717
|
+
internal_initial_price: int,
|
|
718
|
+
oracles_deviation_bps: int,
|
|
719
|
+
consecutive_deviation_count: int,
|
|
720
|
+
taker_in_next_block: bool = True,
|
|
721
|
+
) -> dict[str, Any]:
|
|
722
|
+
pkg = self._config.deployment.package
|
|
723
|
+
return self._send_tx(
|
|
724
|
+
InputEntryFunctionData(
|
|
725
|
+
function=f"{pkg}::admin_apis::register_market_with_composite_oracle_primary_chainlink",
|
|
726
|
+
type_arguments=[],
|
|
727
|
+
function_arguments=[
|
|
728
|
+
name,
|
|
729
|
+
sz_decimals,
|
|
730
|
+
min_size,
|
|
731
|
+
lot_size,
|
|
732
|
+
ticker_size,
|
|
733
|
+
max_open_interest,
|
|
734
|
+
max_leverage,
|
|
735
|
+
margin_call_fee_pct,
|
|
736
|
+
taker_in_next_block,
|
|
737
|
+
chainlink_feed_id_bytes,
|
|
738
|
+
chainlink_max_staleness_secs,
|
|
739
|
+
rescale_decimals,
|
|
740
|
+
internal_initial_price,
|
|
741
|
+
internal_max_staleness_secs,
|
|
742
|
+
oracles_deviation_bps,
|
|
743
|
+
consecutive_deviation_count,
|
|
744
|
+
],
|
|
745
|
+
)
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
def update_internal_oracle_price(
|
|
749
|
+
self,
|
|
750
|
+
market_name: str,
|
|
751
|
+
oracle_price: int,
|
|
752
|
+
) -> dict[str, Any]:
|
|
753
|
+
pkg = self._config.deployment.package
|
|
754
|
+
market_addr = get_market_addr(market_name, self._config.deployment.perp_engine_global)
|
|
755
|
+
return self._send_tx(
|
|
756
|
+
InputEntryFunctionData(
|
|
757
|
+
function=f"{pkg}::admin_apis::update_mark_for_internal_oracle",
|
|
758
|
+
type_arguments=[],
|
|
759
|
+
function_arguments=[market_addr, oracle_price, [], [], True],
|
|
760
|
+
)
|
|
761
|
+
)
|
|
762
|
+
|
|
763
|
+
def update_pyth_oracle_price(
|
|
764
|
+
self,
|
|
765
|
+
market_name: str,
|
|
766
|
+
vaa: list[int],
|
|
767
|
+
) -> dict[str, Any]:
|
|
768
|
+
pkg = self._config.deployment.package
|
|
769
|
+
market_addr = get_market_addr(market_name, self._config.deployment.perp_engine_global)
|
|
770
|
+
return self._send_tx(
|
|
771
|
+
InputEntryFunctionData(
|
|
772
|
+
function=f"{pkg}::admin_apis::update_mark_for_pyth_oracle",
|
|
773
|
+
type_arguments=[],
|
|
774
|
+
function_arguments=[market_addr, vaa, [], [], True],
|
|
775
|
+
)
|
|
776
|
+
)
|
|
777
|
+
|
|
778
|
+
def set_market_adl_trigger_threshold(
|
|
779
|
+
self,
|
|
780
|
+
market_name: str,
|
|
781
|
+
threshold: int,
|
|
782
|
+
) -> dict[str, Any]:
|
|
783
|
+
pkg = self._config.deployment.package
|
|
784
|
+
market_addr = get_market_addr(market_name, self._config.deployment.perp_engine_global)
|
|
785
|
+
return self._send_tx(
|
|
786
|
+
InputEntryFunctionData(
|
|
787
|
+
function=f"{pkg}::admin_apis::set_market_adl_trigger_threshold",
|
|
788
|
+
type_arguments=[],
|
|
789
|
+
function_arguments=[market_addr, threshold],
|
|
790
|
+
)
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
def update_price_to_pyth_only(
|
|
794
|
+
self,
|
|
795
|
+
vaas: list[list[int]],
|
|
796
|
+
) -> dict[str, Any]:
|
|
797
|
+
pkg = self._config.deployment.package
|
|
798
|
+
return self._send_tx(
|
|
799
|
+
InputEntryFunctionData(
|
|
800
|
+
function=f"{pkg}::pyth::update_price_feeds_with_funder",
|
|
801
|
+
type_arguments=[],
|
|
802
|
+
function_arguments=[vaas],
|
|
803
|
+
)
|
|
804
|
+
)
|
|
805
|
+
|
|
806
|
+
def update_price_to_chainlink_only(
|
|
807
|
+
self,
|
|
808
|
+
signed_report: list[int],
|
|
809
|
+
) -> dict[str, Any]:
|
|
810
|
+
pkg = self._config.deployment.package
|
|
811
|
+
return self._send_tx(
|
|
812
|
+
InputEntryFunctionData(
|
|
813
|
+
function=f"{pkg}::chainlink_state::verify_and_store_single_price",
|
|
814
|
+
type_arguments=[],
|
|
815
|
+
function_arguments=[signed_report],
|
|
816
|
+
)
|
|
817
|
+
)
|
|
818
|
+
|
|
819
|
+
def mint_usdc(
|
|
820
|
+
self,
|
|
821
|
+
to_addr: str | AccountAddress,
|
|
822
|
+
amount: int,
|
|
823
|
+
) -> dict[str, Any]:
|
|
824
|
+
pkg = self._config.deployment.package
|
|
825
|
+
addr = str(to_addr) if isinstance(to_addr, AccountAddress) else to_addr
|
|
826
|
+
return self._send_tx(
|
|
827
|
+
InputEntryFunctionData(
|
|
828
|
+
function=f"{pkg}::usdc::mint",
|
|
829
|
+
type_arguments=[],
|
|
830
|
+
function_arguments=[addr, amount],
|
|
831
|
+
)
|
|
832
|
+
)
|
|
833
|
+
|
|
834
|
+
def set_public_minting(
|
|
835
|
+
self,
|
|
836
|
+
allow: bool,
|
|
837
|
+
) -> dict[str, Any]:
|
|
838
|
+
pkg = self._config.deployment.package
|
|
839
|
+
return self._send_tx(
|
|
840
|
+
InputEntryFunctionData(
|
|
841
|
+
function=f"{pkg}::usdc::set_public_minting",
|
|
842
|
+
type_arguments=[],
|
|
843
|
+
function_arguments=[allow],
|
|
844
|
+
)
|
|
845
|
+
)
|
|
846
|
+
|
|
847
|
+
def usdc_balance(
|
|
848
|
+
self,
|
|
849
|
+
addr: str | AccountAddress,
|
|
850
|
+
) -> int:
|
|
851
|
+
addr_str = str(addr) if isinstance(addr, AccountAddress) else addr
|
|
852
|
+
|
|
853
|
+
def make_request(client: httpx.Client) -> int:
|
|
854
|
+
response = client.post(
|
|
855
|
+
f"{self._config.fullnode_url}/view",
|
|
856
|
+
json={
|
|
857
|
+
"function": "0x1::primary_fungible_store::balance",
|
|
858
|
+
"type_arguments": ["0x1::fungible_asset::Metadata"],
|
|
859
|
+
"arguments": [addr_str, self._config.deployment.usdc],
|
|
860
|
+
},
|
|
861
|
+
)
|
|
862
|
+
data = cast("list[Any]", response.json())
|
|
863
|
+
return int(data[0])
|
|
864
|
+
|
|
865
|
+
if self._http_client is not None:
|
|
866
|
+
return make_request(self._http_client)
|
|
867
|
+
with httpx.Client() as client:
|
|
868
|
+
return make_request(client)
|