@mysten/deepbook-v3 1.5.8 → 1.6.2
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.
- package/CHANGELOG.md +73 -0
- package/dist/client.d.mts +5 -0
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +7 -0
- package/dist/client.mjs.map +1 -1
- package/dist/contracts/deepbook/account.d.mts +18 -18
- package/dist/contracts/deepbook/account.d.mts.map +1 -1
- package/dist/contracts/deepbook/balance_manager.mjs +413 -0
- package/dist/contracts/deepbook/balance_manager.mjs.map +1 -0
- package/dist/contracts/deepbook/big_vector.mjs +43 -0
- package/dist/contracts/deepbook/big_vector.mjs.map +1 -0
- package/dist/contracts/deepbook/book.mjs +29 -0
- package/dist/contracts/deepbook/book.mjs.map +1 -0
- package/dist/contracts/deepbook/deep_price.d.mts +3 -3
- package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
- package/dist/contracts/deepbook/deep_price.mjs +1 -1
- package/dist/contracts/deepbook/deps/std/type_name.mjs +17 -0
- package/dist/contracts/deepbook/deps/std/type_name.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/bag.mjs +43 -0
- package/dist/contracts/deepbook/deps/sui/bag.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/balance.mjs +21 -0
- package/dist/contracts/deepbook/deps/sui/balance.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/table.mjs +38 -0
- package/dist/contracts/deepbook/deps/sui/table.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/vec_map.mjs +37 -0
- package/dist/contracts/deepbook/deps/sui/vec_map.mjs.map +1 -0
- package/dist/contracts/deepbook/deps/sui/versioned.mjs +19 -0
- package/dist/contracts/deepbook/deps/sui/versioned.mjs.map +1 -0
- package/dist/contracts/deepbook/governance.mjs +49 -0
- package/dist/contracts/deepbook/governance.mjs.map +1 -0
- package/dist/contracts/deepbook/history.mjs +56 -0
- package/dist/contracts/deepbook/history.mjs.map +1 -0
- package/dist/contracts/deepbook/order.d.mts +12 -12
- package/dist/contracts/deepbook/pool.mjs +1739 -0
- package/dist/contracts/deepbook/pool.mjs.map +1 -0
- package/dist/contracts/deepbook/registry.mjs +295 -0
- package/dist/contracts/deepbook/registry.mjs.map +1 -0
- package/dist/contracts/deepbook/state.mjs +89 -0
- package/dist/contracts/deepbook/state.mjs.map +1 -0
- package/dist/contracts/deepbook/trade_params.mjs +21 -0
- package/dist/contracts/deepbook/trade_params.mjs.map +1 -0
- package/dist/contracts/deepbook/vault.mjs +42 -0
- package/dist/contracts/deepbook/vault.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/deepbook/balance_manager.mjs +53 -0
- package/dist/contracts/deepbook_margin/deps/deepbook/balance_manager.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/std/type_name.mjs +17 -0
- package/dist/contracts/deepbook_margin/deps/std/type_name.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/bag.mjs +43 -0
- package/dist/contracts/deepbook_margin/deps/sui/bag.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/balance.mjs +21 -0
- package/dist/contracts/deepbook_margin/deps/sui/balance.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/table.mjs +38 -0
- package/dist/contracts/deepbook_margin/deps/sui/table.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/vec_map.mjs +37 -0
- package/dist/contracts/deepbook_margin/deps/sui/vec_map.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/vec_set.mjs +26 -0
- package/dist/contracts/deepbook_margin/deps/sui/vec_set.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/deps/sui/versioned.mjs +19 -0
- package/dist/contracts/deepbook_margin/deps/sui/versioned.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/margin_manager.mjs +989 -0
- package/dist/contracts/deepbook_margin/margin_manager.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/margin_pool.mjs +550 -0
- package/dist/contracts/deepbook_margin/margin_pool.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/margin_registry.mjs +786 -0
- package/dist/contracts/deepbook_margin/margin_registry.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/margin_state.mjs +30 -0
- package/dist/contracts/deepbook_margin/margin_state.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/oracle.mjs +82 -0
- package/dist/contracts/deepbook_margin/oracle.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/pool_proxy.mjs +644 -0
- package/dist/contracts/deepbook_margin/pool_proxy.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/position_manager.mjs +32 -0
- package/dist/contracts/deepbook_margin/position_manager.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/protocol_config.mjs +122 -0
- package/dist/contracts/deepbook_margin/protocol_config.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/protocol_fees.mjs +58 -0
- package/dist/contracts/deepbook_margin/protocol_fees.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/rate_limiter.mjs +26 -0
- package/dist/contracts/deepbook_margin/rate_limiter.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/tpsl.mjs +171 -0
- package/dist/contracts/deepbook_margin/tpsl.mjs.map +1 -0
- package/dist/contracts/margin_liquidation/deps/sui/bag.mjs +43 -0
- package/dist/contracts/margin_liquidation/deps/sui/bag.mjs.map +1 -0
- package/dist/contracts/margin_liquidation/liquidation_vault.mjs +179 -0
- package/dist/contracts/margin_liquidation/liquidation_vault.mjs.map +1 -0
- package/dist/contracts/utils/index.d.mts +1 -1
- package/dist/contracts/utils/index.mjs +92 -3
- package/dist/contracts/utils/index.mjs.map +1 -1
- package/dist/queries/registryQueries.mjs +13 -0
- package/dist/queries/registryQueries.mjs.map +1 -1
- package/dist/transactions/balanceManager.d.mts.map +1 -1
- package/dist/transactions/balanceManager.mjs +119 -100
- package/dist/transactions/balanceManager.mjs.map +1 -1
- package/dist/transactions/deepbook.d.mts.map +1 -1
- package/dist/transactions/deepbook.mjs +464 -439
- package/dist/transactions/deepbook.mjs.map +1 -1
- package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
- package/dist/transactions/deepbookAdmin.mjs +151 -135
- package/dist/transactions/deepbookAdmin.mjs.map +1 -1
- package/dist/transactions/flashLoans.d.mts.map +1 -1
- package/dist/transactions/flashLoans.mjs +29 -22
- package/dist/transactions/flashLoans.mjs.map +1 -1
- package/dist/transactions/governance.d.mts.map +1 -1
- package/dist/transactions/governance.mjs +34 -33
- package/dist/transactions/governance.mjs.map +1 -1
- package/dist/transactions/marginAdmin.d.mts +17 -7
- package/dist/transactions/marginAdmin.d.mts.map +1 -1
- package/dist/transactions/marginAdmin.mjs +186 -169
- package/dist/transactions/marginAdmin.mjs.map +1 -1
- package/dist/transactions/marginLiquidations.d.mts +3 -3
- package/dist/transactions/marginLiquidations.d.mts.map +1 -1
- package/dist/transactions/marginLiquidations.mjs +53 -54
- package/dist/transactions/marginLiquidations.mjs.map +1 -1
- package/dist/transactions/marginMaintainer.d.mts +5 -5
- package/dist/transactions/marginMaintainer.d.mts.map +1 -1
- package/dist/transactions/marginMaintainer.mjs +83 -83
- package/dist/transactions/marginMaintainer.mjs.map +1 -1
- package/dist/transactions/marginManager.d.mts +32 -32
- package/dist/transactions/marginManager.d.mts.map +1 -1
- package/dist/transactions/marginManager.mjs +330 -317
- package/dist/transactions/marginManager.mjs.map +1 -1
- package/dist/transactions/marginPool.d.mts +18 -18
- package/dist/transactions/marginPool.d.mts.map +1 -1
- package/dist/transactions/marginPool.mjs +93 -89
- package/dist/transactions/marginPool.mjs.map +1 -1
- package/dist/transactions/marginRegistry.d.mts +22 -15
- package/dist/transactions/marginRegistry.d.mts.map +1 -1
- package/dist/transactions/marginRegistry.mjs +101 -68
- package/dist/transactions/marginRegistry.mjs.map +1 -1
- package/dist/transactions/marginTPSL.d.mts +27 -9
- package/dist/transactions/marginTPSL.d.mts.map +1 -1
- package/dist/transactions/marginTPSL.mjs +108 -82
- package/dist/transactions/marginTPSL.mjs.map +1 -1
- package/dist/transactions/poolProxy.d.mts +37 -5
- package/dist/transactions/poolProxy.d.mts.map +1 -1
- package/dist/transactions/poolProxy.mjs +269 -189
- package/dist/transactions/poolProxy.mjs.map +1 -1
- package/dist/utils/constants.mjs +4 -4
- package/dist/utils/constants.mjs.map +1 -1
- package/package.json +3 -3
- package/src/client.ts +8 -0
- package/src/contracts/deepbook/balance_manager.ts +46 -5
- package/src/contracts/deepbook/constants.ts +13 -0
- package/src/contracts/deepbook/pool.ts +133 -0
- package/src/contracts/deepbook/registry.ts +136 -1
- package/src/contracts/deepbook_margin/deps/deepbook/balance_manager.ts +49 -0
- package/src/contracts/deepbook_margin/deps/std/type_name.ts +24 -0
- package/src/contracts/deepbook_margin/deps/sui/bag.ts +41 -0
- package/src/contracts/deepbook_margin/deps/sui/balance.ts +19 -0
- package/src/contracts/deepbook_margin/deps/sui/table.ts +36 -0
- package/src/contracts/deepbook_margin/deps/sui/vec_map.ts +33 -0
- package/src/contracts/deepbook_margin/deps/sui/vec_set.ts +22 -0
- package/src/contracts/deepbook_margin/deps/sui/versioned.ts +13 -0
- package/src/contracts/deepbook_margin/margin_constants.ts +329 -0
- package/src/contracts/deepbook_margin/margin_manager.ts +1772 -0
- package/src/contracts/deepbook_margin/margin_pool.ts +1129 -0
- package/src/contracts/deepbook_margin/margin_registry.ts +1207 -0
- package/src/contracts/deepbook_margin/margin_state.ts +26 -0
- package/src/contracts/deepbook_margin/oracle.ts +99 -0
- package/src/contracts/deepbook_margin/pool_proxy.ts +1298 -0
- package/src/contracts/deepbook_margin/position_manager.ts +28 -0
- package/src/contracts/deepbook_margin/protocol_config.ts +163 -0
- package/src/contracts/deepbook_margin/protocol_fees.ts +153 -0
- package/src/contracts/deepbook_margin/rate_limiter.ts +80 -0
- package/src/contracts/deepbook_margin/tpsl.ts +559 -0
- package/src/contracts/margin_liquidation/deps/sui/bag.ts +41 -0
- package/src/contracts/margin_liquidation/liquidation_vault.ts +401 -0
- package/src/queries/registryQueries.ts +15 -0
- package/src/transactions/balanceManager.ts +140 -90
- package/src/transactions/deepbook.ts +586 -494
- package/src/transactions/deepbookAdmin.ts +154 -146
- package/src/transactions/flashLoans.ts +29 -20
- package/src/transactions/governance.ts +50 -37
- package/src/transactions/marginAdmin.ts +247 -188
- package/src/transactions/marginLiquidations.ts +70 -55
- package/src/transactions/marginMaintainer.ts +106 -88
- package/src/transactions/marginManager.ts +414 -348
- package/src/transactions/marginPool.ts +140 -103
- package/src/transactions/marginRegistry.ts +103 -70
- package/src/transactions/marginTPSL.ts +151 -87
- package/src/transactions/poolProxy.ts +384 -205
- package/src/utils/constants.ts +4 -4
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
import { MoveStruct, normalizeMoveArguments } from "../utils/index.mjs";
|
|
2
|
+
import { VecMap } from "./deps/sui/vec_map.mjs";
|
|
3
|
+
import { TypeName } from "./deps/std/type_name.mjs";
|
|
4
|
+
import { BalanceManager, DepositCap, TradeCap, WithdrawCap } from "./deps/deepbook/balance_manager.mjs";
|
|
5
|
+
import { TakeProfitStopLoss } from "./tpsl.mjs";
|
|
6
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
7
|
+
|
|
8
|
+
//#region src/contracts/deepbook_margin/margin_manager.ts
|
|
9
|
+
/**************************************************************
|
|
10
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
11
|
+
**************************************************************/
|
|
12
|
+
const $moduleName = "@deepbook/margin::margin_manager";
|
|
13
|
+
const MarginApp = new MoveStruct({
|
|
14
|
+
name: `${$moduleName}::MarginApp`,
|
|
15
|
+
fields: { dummy_field: bcs.bool() }
|
|
16
|
+
});
|
|
17
|
+
const MarginManager = new MoveStruct({
|
|
18
|
+
name: `${$moduleName}::MarginManager<phantom BaseAsset, phantom QuoteAsset>`,
|
|
19
|
+
fields: {
|
|
20
|
+
id: bcs.Address,
|
|
21
|
+
owner: bcs.Address,
|
|
22
|
+
deepbook_pool: bcs.Address,
|
|
23
|
+
margin_pool_id: bcs.option(bcs.Address),
|
|
24
|
+
balance_manager: BalanceManager,
|
|
25
|
+
deposit_cap: DepositCap,
|
|
26
|
+
withdraw_cap: WithdrawCap,
|
|
27
|
+
trade_cap: TradeCap,
|
|
28
|
+
borrowed_base_shares: bcs.u64(),
|
|
29
|
+
borrowed_quote_shares: bcs.u64(),
|
|
30
|
+
take_profit_stop_loss: TakeProfitStopLoss,
|
|
31
|
+
extra_fields: VecMap(bcs.string(), bcs.u64())
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const ManagerInitializer = new MoveStruct({
|
|
35
|
+
name: `${$moduleName}::ManagerInitializer`,
|
|
36
|
+
fields: { margin_manager_id: bcs.Address }
|
|
37
|
+
});
|
|
38
|
+
const MarginManagerCreatedEvent = new MoveStruct({
|
|
39
|
+
name: `${$moduleName}::MarginManagerCreatedEvent`,
|
|
40
|
+
fields: {
|
|
41
|
+
margin_manager_id: bcs.Address,
|
|
42
|
+
balance_manager_id: bcs.Address,
|
|
43
|
+
deepbook_pool_id: bcs.Address,
|
|
44
|
+
owner: bcs.Address,
|
|
45
|
+
timestamp: bcs.u64()
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const LoanBorrowedEvent = new MoveStruct({
|
|
49
|
+
name: `${$moduleName}::LoanBorrowedEvent`,
|
|
50
|
+
fields: {
|
|
51
|
+
margin_manager_id: bcs.Address,
|
|
52
|
+
margin_pool_id: bcs.Address,
|
|
53
|
+
loan_amount: bcs.u64(),
|
|
54
|
+
loan_shares: bcs.u64(),
|
|
55
|
+
timestamp: bcs.u64()
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const LoanRepaidEvent = new MoveStruct({
|
|
59
|
+
name: `${$moduleName}::LoanRepaidEvent`,
|
|
60
|
+
fields: {
|
|
61
|
+
margin_manager_id: bcs.Address,
|
|
62
|
+
margin_pool_id: bcs.Address,
|
|
63
|
+
repay_amount: bcs.u64(),
|
|
64
|
+
repay_shares: bcs.u64(),
|
|
65
|
+
timestamp: bcs.u64()
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const LiquidationEvent = new MoveStruct({
|
|
69
|
+
name: `${$moduleName}::LiquidationEvent`,
|
|
70
|
+
fields: {
|
|
71
|
+
margin_manager_id: bcs.Address,
|
|
72
|
+
margin_pool_id: bcs.Address,
|
|
73
|
+
liquidation_amount: bcs.u64(),
|
|
74
|
+
pool_reward: bcs.u64(),
|
|
75
|
+
pool_default: bcs.u64(),
|
|
76
|
+
risk_ratio: bcs.u64(),
|
|
77
|
+
remaining_base_asset: bcs.u64(),
|
|
78
|
+
remaining_quote_asset: bcs.u64(),
|
|
79
|
+
remaining_base_debt: bcs.u64(),
|
|
80
|
+
remaining_quote_debt: bcs.u64(),
|
|
81
|
+
base_pyth_price: bcs.u64(),
|
|
82
|
+
base_pyth_decimals: bcs.u8(),
|
|
83
|
+
quote_pyth_price: bcs.u64(),
|
|
84
|
+
quote_pyth_decimals: bcs.u8(),
|
|
85
|
+
timestamp: bcs.u64()
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const DepositCollateralEvent = new MoveStruct({
|
|
89
|
+
name: `${$moduleName}::DepositCollateralEvent`,
|
|
90
|
+
fields: {
|
|
91
|
+
margin_manager_id: bcs.Address,
|
|
92
|
+
amount: bcs.u64(),
|
|
93
|
+
asset: TypeName,
|
|
94
|
+
pyth_price: bcs.u64(),
|
|
95
|
+
pyth_decimals: bcs.u8(),
|
|
96
|
+
timestamp: bcs.u64()
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const WithdrawCollateralEvent = new MoveStruct({
|
|
100
|
+
name: `${$moduleName}::WithdrawCollateralEvent`,
|
|
101
|
+
fields: {
|
|
102
|
+
margin_manager_id: bcs.Address,
|
|
103
|
+
amount: bcs.u64(),
|
|
104
|
+
asset: TypeName,
|
|
105
|
+
withdraw_base_asset: bcs.bool(),
|
|
106
|
+
remaining_base_asset: bcs.u64(),
|
|
107
|
+
remaining_quote_asset: bcs.u64(),
|
|
108
|
+
remaining_base_debt: bcs.u64(),
|
|
109
|
+
remaining_quote_debt: bcs.u64(),
|
|
110
|
+
base_pyth_price: bcs.u64(),
|
|
111
|
+
base_pyth_decimals: bcs.u8(),
|
|
112
|
+
quote_pyth_price: bcs.u64(),
|
|
113
|
+
quote_pyth_decimals: bcs.u8(),
|
|
114
|
+
timestamp: bcs.u64()
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Add a conditional order (take-profit / stop-loss). Specifies the condition under
|
|
119
|
+
* which it triggers and the pending order to place when it does.
|
|
120
|
+
*
|
|
121
|
+
* Lifetime: the conditional order itself is never clamped — it rests in the queue
|
|
122
|
+
* until it triggers or is cancelled. A _market_ pending order
|
|
123
|
+
* (`tpsl::new_pending_market_order`) has no expiry, so it is the "until cancelled"
|
|
124
|
+
* stop: it waits indefinitely and, when triggered, fires and deleverages via
|
|
125
|
+
* `execute_conditional_orders_v3` (so it can protect even in the danger band). A
|
|
126
|
+
* _limit_ pending order is intentionally transient — when it triggers, the resting
|
|
127
|
+
* order it places is clamped to `max_order_ttl_ms` (default 3 days) by
|
|
128
|
+
* `clamp_expire_timestamp`, the same stale-price guard as any margin limit order.
|
|
129
|
+
* For a permanent stop, use a market pending order.
|
|
130
|
+
*/
|
|
131
|
+
function addConditionalOrder(options) {
|
|
132
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
133
|
+
const argumentsTypes = [
|
|
134
|
+
null,
|
|
135
|
+
null,
|
|
136
|
+
null,
|
|
137
|
+
null,
|
|
138
|
+
null,
|
|
139
|
+
"u64",
|
|
140
|
+
null,
|
|
141
|
+
null,
|
|
142
|
+
"0x2::clock::Clock"
|
|
143
|
+
];
|
|
144
|
+
const parameterNames = [
|
|
145
|
+
"self",
|
|
146
|
+
"pool",
|
|
147
|
+
"basePriceInfoObject",
|
|
148
|
+
"quotePriceInfoObject",
|
|
149
|
+
"registry",
|
|
150
|
+
"conditionalOrderId",
|
|
151
|
+
"condition",
|
|
152
|
+
"pendingOrder"
|
|
153
|
+
];
|
|
154
|
+
return (tx) => tx.moveCall({
|
|
155
|
+
package: packageAddress,
|
|
156
|
+
module: "margin_manager",
|
|
157
|
+
function: "add_conditional_order",
|
|
158
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
159
|
+
typeArguments: options.typeArguments
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** Cancel all conditional orders. */
|
|
163
|
+
function cancelAllConditionalOrders(options) {
|
|
164
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
165
|
+
const argumentsTypes = [null, "0x2::clock::Clock"];
|
|
166
|
+
const parameterNames = ["self"];
|
|
167
|
+
return (tx) => tx.moveCall({
|
|
168
|
+
package: packageAddress,
|
|
169
|
+
module: "margin_manager",
|
|
170
|
+
function: "cancel_all_conditional_orders",
|
|
171
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
172
|
+
typeArguments: options.typeArguments
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/** Cancel a conditional order. */
|
|
176
|
+
function cancelConditionalOrder(options) {
|
|
177
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
178
|
+
const argumentsTypes = [
|
|
179
|
+
null,
|
|
180
|
+
"u64",
|
|
181
|
+
"0x2::clock::Clock"
|
|
182
|
+
];
|
|
183
|
+
const parameterNames = ["self", "conditionalOrderId"];
|
|
184
|
+
return (tx) => tx.moveCall({
|
|
185
|
+
package: packageAddress,
|
|
186
|
+
module: "margin_manager",
|
|
187
|
+
function: "cancel_conditional_order",
|
|
188
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
189
|
+
typeArguments: options.typeArguments
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Execute conditional orders and return the order infos. This is a permissionless
|
|
194
|
+
* function that can be called by anyone.
|
|
195
|
+
*
|
|
196
|
+
* v2 adds `base_margin_pool` + `quote_margin_pool` parameters and enforces a
|
|
197
|
+
* post-fill `risk_ratio >= min_borrow_risk_ratio` invariant inside the inner loop.
|
|
198
|
+
* If any single triggered fill would breach that floor, the entire txn aborts — no
|
|
199
|
+
* partial-state landing.
|
|
200
|
+
*/
|
|
201
|
+
function executeConditionalOrdersV2(options) {
|
|
202
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
203
|
+
const argumentsTypes = [
|
|
204
|
+
null,
|
|
205
|
+
null,
|
|
206
|
+
null,
|
|
207
|
+
null,
|
|
208
|
+
null,
|
|
209
|
+
null,
|
|
210
|
+
null,
|
|
211
|
+
"u64",
|
|
212
|
+
"0x2::clock::Clock"
|
|
213
|
+
];
|
|
214
|
+
const parameterNames = [
|
|
215
|
+
"self",
|
|
216
|
+
"pool",
|
|
217
|
+
"baseMarginPool",
|
|
218
|
+
"quoteMarginPool",
|
|
219
|
+
"basePriceInfoObject",
|
|
220
|
+
"quotePriceInfoObject",
|
|
221
|
+
"registry",
|
|
222
|
+
"maxOrdersToExecute"
|
|
223
|
+
];
|
|
224
|
+
return (tx) => tx.moveCall({
|
|
225
|
+
package: packageAddress,
|
|
226
|
+
module: "margin_manager",
|
|
227
|
+
function: "execute_conditional_orders_v2",
|
|
228
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
229
|
+
typeArguments: options.typeArguments
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Execute conditional orders, deleveraging on each market-type fill.
|
|
234
|
+
* Permissionless, like `execute_conditional_orders_v2`, with the same trigger and
|
|
235
|
+
* cancellation handling — but takes the margin pools as `&mut` and repays the loan
|
|
236
|
+
* with the market proceeds before gating on the net (post-repay) `risk_ratio`
|
|
237
|
+
* being at least the pre-fill ratio.
|
|
238
|
+
*
|
|
239
|
+
* This is what lets a stop-loss fire in the `liquidation..min_borrow` danger band:
|
|
240
|
+
* a swap alone only lowers the oracle-valued ratio (so the v2 borrow-floor gate
|
|
241
|
+
* rejects it), while repaying actually improves it. If a single triggered fill
|
|
242
|
+
* would worsen net solvency the whole txn aborts — no partial-state landing.
|
|
243
|
+
*/
|
|
244
|
+
function executeConditionalOrdersV3(options) {
|
|
245
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
246
|
+
const argumentsTypes = [
|
|
247
|
+
null,
|
|
248
|
+
null,
|
|
249
|
+
null,
|
|
250
|
+
null,
|
|
251
|
+
null,
|
|
252
|
+
null,
|
|
253
|
+
null,
|
|
254
|
+
"u64",
|
|
255
|
+
"0x2::clock::Clock"
|
|
256
|
+
];
|
|
257
|
+
const parameterNames = [
|
|
258
|
+
"self",
|
|
259
|
+
"pool",
|
|
260
|
+
"baseMarginPool",
|
|
261
|
+
"quoteMarginPool",
|
|
262
|
+
"basePriceInfoObject",
|
|
263
|
+
"quotePriceInfoObject",
|
|
264
|
+
"registry",
|
|
265
|
+
"maxOrdersToExecute"
|
|
266
|
+
];
|
|
267
|
+
return (tx) => tx.moveCall({
|
|
268
|
+
package: packageAddress,
|
|
269
|
+
module: "margin_manager",
|
|
270
|
+
function: "execute_conditional_orders_v3",
|
|
271
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
272
|
+
typeArguments: options.typeArguments
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/** Creates a new margin manager and shares it. */
|
|
276
|
+
function _new(options) {
|
|
277
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
278
|
+
const argumentsTypes = [
|
|
279
|
+
null,
|
|
280
|
+
null,
|
|
281
|
+
null,
|
|
282
|
+
"0x2::clock::Clock"
|
|
283
|
+
];
|
|
284
|
+
const parameterNames = [
|
|
285
|
+
"pool",
|
|
286
|
+
"deepbookRegistry",
|
|
287
|
+
"marginRegistry"
|
|
288
|
+
];
|
|
289
|
+
return (tx) => tx.moveCall({
|
|
290
|
+
package: packageAddress,
|
|
291
|
+
module: "margin_manager",
|
|
292
|
+
function: "new",
|
|
293
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
294
|
+
typeArguments: options.typeArguments
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Creates a new margin manager and returns it along with an initializer. The
|
|
299
|
+
* initializer is used to ensure the margin manager is shared after creation.
|
|
300
|
+
*/
|
|
301
|
+
function newWithInitializer(options) {
|
|
302
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
303
|
+
const argumentsTypes = [
|
|
304
|
+
null,
|
|
305
|
+
null,
|
|
306
|
+
null,
|
|
307
|
+
"0x2::clock::Clock"
|
|
308
|
+
];
|
|
309
|
+
const parameterNames = [
|
|
310
|
+
"pool",
|
|
311
|
+
"deepbookRegistry",
|
|
312
|
+
"marginRegistry"
|
|
313
|
+
];
|
|
314
|
+
return (tx) => tx.moveCall({
|
|
315
|
+
package: packageAddress,
|
|
316
|
+
module: "margin_manager",
|
|
317
|
+
function: "new_with_initializer",
|
|
318
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
319
|
+
typeArguments: options.typeArguments
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/** Shares the margin manager. The initializer is dropped in the process. */
|
|
323
|
+
function share(options) {
|
|
324
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
325
|
+
const argumentsTypes = [null, null];
|
|
326
|
+
const parameterNames = ["manager", "initializer"];
|
|
327
|
+
return (tx) => tx.moveCall({
|
|
328
|
+
package: packageAddress,
|
|
329
|
+
module: "margin_manager",
|
|
330
|
+
function: "share",
|
|
331
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
332
|
+
typeArguments: options.typeArguments
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/** Register the margin manager back to the margin registry. */
|
|
336
|
+
function registerMarginManager(options) {
|
|
337
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
338
|
+
const argumentsTypes = [null, null];
|
|
339
|
+
const parameterNames = ["self", "marginRegistry"];
|
|
340
|
+
return (tx) => tx.moveCall({
|
|
341
|
+
package: packageAddress,
|
|
342
|
+
module: "margin_manager",
|
|
343
|
+
function: "register_margin_manager",
|
|
344
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
345
|
+
typeArguments: options.typeArguments
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
/** Unregister the margin manager from the margin registry. */
|
|
349
|
+
function unregisterMarginManager(options) {
|
|
350
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
351
|
+
const argumentsTypes = [null, null];
|
|
352
|
+
const parameterNames = ["self", "marginRegistry"];
|
|
353
|
+
return (tx) => tx.moveCall({
|
|
354
|
+
package: packageAddress,
|
|
355
|
+
module: "margin_manager",
|
|
356
|
+
function: "unregister_margin_manager",
|
|
357
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
358
|
+
typeArguments: options.typeArguments
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/** Set the referral for the margin manager. */
|
|
362
|
+
function setMarginManagerReferral(options) {
|
|
363
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
364
|
+
const argumentsTypes = [null, null];
|
|
365
|
+
const parameterNames = ["self", "referralCap"];
|
|
366
|
+
return (tx) => tx.moveCall({
|
|
367
|
+
package: packageAddress,
|
|
368
|
+
module: "margin_manager",
|
|
369
|
+
function: "set_margin_manager_referral",
|
|
370
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
371
|
+
typeArguments: options.typeArguments
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
/** Unset the referral for the margin manager. */
|
|
375
|
+
function unsetMarginManagerReferral(options) {
|
|
376
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
377
|
+
const argumentsTypes = [null, "0x2::object::ID"];
|
|
378
|
+
const parameterNames = ["self", "poolId"];
|
|
379
|
+
return (tx) => tx.moveCall({
|
|
380
|
+
package: packageAddress,
|
|
381
|
+
module: "margin_manager",
|
|
382
|
+
function: "unset_margin_manager_referral",
|
|
383
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
384
|
+
typeArguments: options.typeArguments
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Deposit a coin into the margin manager. The coin must be of the same type as
|
|
389
|
+
* either the base, quote, or DEEP.
|
|
390
|
+
*/
|
|
391
|
+
function deposit(options) {
|
|
392
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
393
|
+
const argumentsTypes = [
|
|
394
|
+
null,
|
|
395
|
+
null,
|
|
396
|
+
null,
|
|
397
|
+
null,
|
|
398
|
+
null,
|
|
399
|
+
"0x2::clock::Clock"
|
|
400
|
+
];
|
|
401
|
+
const parameterNames = [
|
|
402
|
+
"self",
|
|
403
|
+
"registry",
|
|
404
|
+
"baseOracle",
|
|
405
|
+
"quoteOracle",
|
|
406
|
+
"coin"
|
|
407
|
+
];
|
|
408
|
+
return (tx) => tx.moveCall({
|
|
409
|
+
package: packageAddress,
|
|
410
|
+
module: "margin_manager",
|
|
411
|
+
function: "deposit",
|
|
412
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
413
|
+
typeArguments: options.typeArguments
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Withdraw a specified amount of an asset from the margin manager. The asset must
|
|
418
|
+
* be of the same type as either the base, quote, or DEEP. The withdrawal is
|
|
419
|
+
* subject to the risk ratio limit.
|
|
420
|
+
*/
|
|
421
|
+
function withdraw(options) {
|
|
422
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
423
|
+
const argumentsTypes = [
|
|
424
|
+
null,
|
|
425
|
+
null,
|
|
426
|
+
null,
|
|
427
|
+
null,
|
|
428
|
+
null,
|
|
429
|
+
null,
|
|
430
|
+
null,
|
|
431
|
+
"u64",
|
|
432
|
+
"0x2::clock::Clock"
|
|
433
|
+
];
|
|
434
|
+
const parameterNames = [
|
|
435
|
+
"self",
|
|
436
|
+
"registry",
|
|
437
|
+
"baseMarginPool",
|
|
438
|
+
"quoteMarginPool",
|
|
439
|
+
"baseOracle",
|
|
440
|
+
"quoteOracle",
|
|
441
|
+
"pool",
|
|
442
|
+
"withdrawAmount"
|
|
443
|
+
];
|
|
444
|
+
return (tx) => tx.moveCall({
|
|
445
|
+
package: packageAddress,
|
|
446
|
+
module: "margin_manager",
|
|
447
|
+
function: "withdraw",
|
|
448
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
449
|
+
typeArguments: options.typeArguments
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
/** Borrow the base asset using the margin manager. */
|
|
453
|
+
function borrowBase(options) {
|
|
454
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
455
|
+
const argumentsTypes = [
|
|
456
|
+
null,
|
|
457
|
+
null,
|
|
458
|
+
null,
|
|
459
|
+
null,
|
|
460
|
+
null,
|
|
461
|
+
null,
|
|
462
|
+
"u64",
|
|
463
|
+
"0x2::clock::Clock"
|
|
464
|
+
];
|
|
465
|
+
const parameterNames = [
|
|
466
|
+
"self",
|
|
467
|
+
"registry",
|
|
468
|
+
"baseMarginPool",
|
|
469
|
+
"baseOracle",
|
|
470
|
+
"quoteOracle",
|
|
471
|
+
"pool",
|
|
472
|
+
"loanAmount"
|
|
473
|
+
];
|
|
474
|
+
return (tx) => tx.moveCall({
|
|
475
|
+
package: packageAddress,
|
|
476
|
+
module: "margin_manager",
|
|
477
|
+
function: "borrow_base",
|
|
478
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
479
|
+
typeArguments: options.typeArguments
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
/** Borrow the quote asset using the margin manager. */
|
|
483
|
+
function borrowQuote(options) {
|
|
484
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
485
|
+
const argumentsTypes = [
|
|
486
|
+
null,
|
|
487
|
+
null,
|
|
488
|
+
null,
|
|
489
|
+
null,
|
|
490
|
+
null,
|
|
491
|
+
null,
|
|
492
|
+
"u64",
|
|
493
|
+
"0x2::clock::Clock"
|
|
494
|
+
];
|
|
495
|
+
const parameterNames = [
|
|
496
|
+
"self",
|
|
497
|
+
"registry",
|
|
498
|
+
"quoteMarginPool",
|
|
499
|
+
"baseOracle",
|
|
500
|
+
"quoteOracle",
|
|
501
|
+
"pool",
|
|
502
|
+
"loanAmount"
|
|
503
|
+
];
|
|
504
|
+
return (tx) => tx.moveCall({
|
|
505
|
+
package: packageAddress,
|
|
506
|
+
module: "margin_manager",
|
|
507
|
+
function: "borrow_quote",
|
|
508
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
509
|
+
typeArguments: options.typeArguments
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Repay the base asset loan using the margin manager. Returns the total amount
|
|
514
|
+
* repaid
|
|
515
|
+
*/
|
|
516
|
+
function repayBase(options) {
|
|
517
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
518
|
+
const argumentsTypes = [
|
|
519
|
+
null,
|
|
520
|
+
null,
|
|
521
|
+
null,
|
|
522
|
+
"0x1::option::Option<u64>",
|
|
523
|
+
"0x2::clock::Clock"
|
|
524
|
+
];
|
|
525
|
+
const parameterNames = [
|
|
526
|
+
"self",
|
|
527
|
+
"registry",
|
|
528
|
+
"marginPool",
|
|
529
|
+
"amount"
|
|
530
|
+
];
|
|
531
|
+
return (tx) => tx.moveCall({
|
|
532
|
+
package: packageAddress,
|
|
533
|
+
module: "margin_manager",
|
|
534
|
+
function: "repay_base",
|
|
535
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
536
|
+
typeArguments: options.typeArguments
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Repay the quote asset loan using the margin manager. Returns the total amount
|
|
541
|
+
* repaid
|
|
542
|
+
*/
|
|
543
|
+
function repayQuote(options) {
|
|
544
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
545
|
+
const argumentsTypes = [
|
|
546
|
+
null,
|
|
547
|
+
null,
|
|
548
|
+
null,
|
|
549
|
+
"0x1::option::Option<u64>",
|
|
550
|
+
"0x2::clock::Clock"
|
|
551
|
+
];
|
|
552
|
+
const parameterNames = [
|
|
553
|
+
"self",
|
|
554
|
+
"registry",
|
|
555
|
+
"marginPool",
|
|
556
|
+
"amount"
|
|
557
|
+
];
|
|
558
|
+
return (tx) => tx.moveCall({
|
|
559
|
+
package: packageAddress,
|
|
560
|
+
module: "margin_manager",
|
|
561
|
+
function: "repay_quote",
|
|
562
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
563
|
+
typeArguments: options.typeArguments
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
function liquidate(options) {
|
|
567
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
568
|
+
const argumentsTypes = [
|
|
569
|
+
null,
|
|
570
|
+
null,
|
|
571
|
+
null,
|
|
572
|
+
null,
|
|
573
|
+
null,
|
|
574
|
+
null,
|
|
575
|
+
null,
|
|
576
|
+
"0x2::clock::Clock"
|
|
577
|
+
];
|
|
578
|
+
const parameterNames = [
|
|
579
|
+
"self",
|
|
580
|
+
"registry",
|
|
581
|
+
"baseOracle",
|
|
582
|
+
"quoteOracle",
|
|
583
|
+
"marginPool",
|
|
584
|
+
"pool",
|
|
585
|
+
"repayCoin"
|
|
586
|
+
];
|
|
587
|
+
return (tx) => tx.moveCall({
|
|
588
|
+
package: packageAddress,
|
|
589
|
+
module: "margin_manager",
|
|
590
|
+
function: "liquidate",
|
|
591
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
592
|
+
typeArguments: options.typeArguments
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
function balanceManager(options) {
|
|
596
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
597
|
+
const argumentsTypes = [null];
|
|
598
|
+
const parameterNames = ["self"];
|
|
599
|
+
return (tx) => tx.moveCall({
|
|
600
|
+
package: packageAddress,
|
|
601
|
+
module: "margin_manager",
|
|
602
|
+
function: "balance_manager",
|
|
603
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
604
|
+
typeArguments: options.typeArguments
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
function baseBalance(options) {
|
|
608
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
609
|
+
const argumentsTypes = [null];
|
|
610
|
+
const parameterNames = ["self"];
|
|
611
|
+
return (tx) => tx.moveCall({
|
|
612
|
+
package: packageAddress,
|
|
613
|
+
module: "margin_manager",
|
|
614
|
+
function: "base_balance",
|
|
615
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
616
|
+
typeArguments: options.typeArguments
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
function quoteBalance(options) {
|
|
620
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
621
|
+
const argumentsTypes = [null];
|
|
622
|
+
const parameterNames = ["self"];
|
|
623
|
+
return (tx) => tx.moveCall({
|
|
624
|
+
package: packageAddress,
|
|
625
|
+
module: "margin_manager",
|
|
626
|
+
function: "quote_balance",
|
|
627
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
628
|
+
typeArguments: options.typeArguments
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
function deepBalance(options) {
|
|
632
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
633
|
+
const argumentsTypes = [null];
|
|
634
|
+
const parameterNames = ["self"];
|
|
635
|
+
return (tx) => tx.moveCall({
|
|
636
|
+
package: packageAddress,
|
|
637
|
+
module: "margin_manager",
|
|
638
|
+
function: "deep_balance",
|
|
639
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
640
|
+
typeArguments: options.typeArguments
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
/** Returns (base_asset, quote_asset) for margin manager. */
|
|
644
|
+
function calculateAssets(options) {
|
|
645
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
646
|
+
const argumentsTypes = [null, null];
|
|
647
|
+
const parameterNames = ["self", "pool"];
|
|
648
|
+
return (tx) => tx.moveCall({
|
|
649
|
+
package: packageAddress,
|
|
650
|
+
module: "margin_manager",
|
|
651
|
+
function: "calculate_assets",
|
|
652
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
653
|
+
typeArguments: options.typeArguments
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
function calculateDebts(options) {
|
|
657
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
658
|
+
const argumentsTypes = [
|
|
659
|
+
null,
|
|
660
|
+
null,
|
|
661
|
+
"0x2::clock::Clock"
|
|
662
|
+
];
|
|
663
|
+
const parameterNames = ["self", "marginPool"];
|
|
664
|
+
return (tx) => tx.moveCall({
|
|
665
|
+
package: packageAddress,
|
|
666
|
+
module: "margin_manager",
|
|
667
|
+
function: "calculate_debts",
|
|
668
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
669
|
+
typeArguments: options.typeArguments
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Returns comprehensive state information for a margin manager. Returns
|
|
674
|
+
* (manager_id, deepbook_pool_id, risk_ratio, base_asset, quote_asset, base_debt,
|
|
675
|
+
* quote_debt, base_pyth_price, base_pyth_decimals, quote_pyth_price,
|
|
676
|
+
* quote_pyth_decimals, current_price, lowest_trigger_above_price,
|
|
677
|
+
* highest_trigger_below_price)
|
|
678
|
+
*/
|
|
679
|
+
function managerState(options) {
|
|
680
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
681
|
+
const argumentsTypes = [
|
|
682
|
+
null,
|
|
683
|
+
null,
|
|
684
|
+
null,
|
|
685
|
+
null,
|
|
686
|
+
null,
|
|
687
|
+
null,
|
|
688
|
+
null,
|
|
689
|
+
"0x2::clock::Clock"
|
|
690
|
+
];
|
|
691
|
+
const parameterNames = [
|
|
692
|
+
"self",
|
|
693
|
+
"registry",
|
|
694
|
+
"baseOracle",
|
|
695
|
+
"quoteOracle",
|
|
696
|
+
"pool",
|
|
697
|
+
"baseMarginPool",
|
|
698
|
+
"quoteMarginPool"
|
|
699
|
+
];
|
|
700
|
+
return (tx) => tx.moveCall({
|
|
701
|
+
package: packageAddress,
|
|
702
|
+
module: "margin_manager",
|
|
703
|
+
function: "manager_state",
|
|
704
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
705
|
+
typeArguments: options.typeArguments
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
function owner(options) {
|
|
709
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
710
|
+
const argumentsTypes = [null];
|
|
711
|
+
const parameterNames = ["self"];
|
|
712
|
+
return (tx) => tx.moveCall({
|
|
713
|
+
package: packageAddress,
|
|
714
|
+
module: "margin_manager",
|
|
715
|
+
function: "owner",
|
|
716
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
717
|
+
typeArguments: options.typeArguments
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
function deepbookPool(options) {
|
|
721
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
722
|
+
const argumentsTypes = [null];
|
|
723
|
+
const parameterNames = ["self"];
|
|
724
|
+
return (tx) => tx.moveCall({
|
|
725
|
+
package: packageAddress,
|
|
726
|
+
module: "margin_manager",
|
|
727
|
+
function: "deepbook_pool",
|
|
728
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
729
|
+
typeArguments: options.typeArguments
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
function marginPoolId(options) {
|
|
733
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
734
|
+
const argumentsTypes = [null];
|
|
735
|
+
const parameterNames = ["self"];
|
|
736
|
+
return (tx) => tx.moveCall({
|
|
737
|
+
package: packageAddress,
|
|
738
|
+
module: "margin_manager",
|
|
739
|
+
function: "margin_pool_id",
|
|
740
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
741
|
+
typeArguments: options.typeArguments
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
function borrowedShares(options) {
|
|
745
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
746
|
+
const argumentsTypes = [null];
|
|
747
|
+
const parameterNames = ["self"];
|
|
748
|
+
return (tx) => tx.moveCall({
|
|
749
|
+
package: packageAddress,
|
|
750
|
+
module: "margin_manager",
|
|
751
|
+
function: "borrowed_shares",
|
|
752
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
753
|
+
typeArguments: options.typeArguments
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
function borrowedBaseShares(options) {
|
|
757
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
758
|
+
const argumentsTypes = [null];
|
|
759
|
+
const parameterNames = ["self"];
|
|
760
|
+
return (tx) => tx.moveCall({
|
|
761
|
+
package: packageAddress,
|
|
762
|
+
module: "margin_manager",
|
|
763
|
+
function: "borrowed_base_shares",
|
|
764
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
765
|
+
typeArguments: options.typeArguments
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
function borrowedQuoteShares(options) {
|
|
769
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
770
|
+
const argumentsTypes = [null];
|
|
771
|
+
const parameterNames = ["self"];
|
|
772
|
+
return (tx) => tx.moveCall({
|
|
773
|
+
package: packageAddress,
|
|
774
|
+
module: "margin_manager",
|
|
775
|
+
function: "borrowed_quote_shares",
|
|
776
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
777
|
+
typeArguments: options.typeArguments
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
function hasBaseDebt(options) {
|
|
781
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
782
|
+
const argumentsTypes = [null];
|
|
783
|
+
const parameterNames = ["self"];
|
|
784
|
+
return (tx) => tx.moveCall({
|
|
785
|
+
package: packageAddress,
|
|
786
|
+
module: "margin_manager",
|
|
787
|
+
function: "has_base_debt",
|
|
788
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
789
|
+
typeArguments: options.typeArguments
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
function conditionalOrderIds(options) {
|
|
793
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
794
|
+
const argumentsTypes = [null];
|
|
795
|
+
const parameterNames = ["self"];
|
|
796
|
+
return (tx) => tx.moveCall({
|
|
797
|
+
package: packageAddress,
|
|
798
|
+
module: "margin_manager",
|
|
799
|
+
function: "conditional_order_ids",
|
|
800
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
801
|
+
typeArguments: options.typeArguments
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
function conditionalOrder(options) {
|
|
805
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
806
|
+
const argumentsTypes = [null, "u64"];
|
|
807
|
+
const parameterNames = ["self", "conditionalOrderId"];
|
|
808
|
+
return (tx) => tx.moveCall({
|
|
809
|
+
package: packageAddress,
|
|
810
|
+
module: "margin_manager",
|
|
811
|
+
function: "conditional_order",
|
|
812
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
813
|
+
typeArguments: options.typeArguments
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Returns the lowest trigger price for trigger_above orders Returns
|
|
818
|
+
* constants::max_u64() if there are no trigger_above orders
|
|
819
|
+
*/
|
|
820
|
+
function lowestTriggerAbovePrice(options) {
|
|
821
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
822
|
+
const argumentsTypes = [null];
|
|
823
|
+
const parameterNames = ["self"];
|
|
824
|
+
return (tx) => tx.moveCall({
|
|
825
|
+
package: packageAddress,
|
|
826
|
+
module: "margin_manager",
|
|
827
|
+
function: "lowest_trigger_above_price",
|
|
828
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
829
|
+
typeArguments: options.typeArguments
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Returns the highest trigger price for trigger_below orders Returns 0 if there
|
|
834
|
+
* are no trigger_below orders
|
|
835
|
+
*/
|
|
836
|
+
function highestTriggerBelowPrice(options) {
|
|
837
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
838
|
+
const argumentsTypes = [null];
|
|
839
|
+
const parameterNames = ["self"];
|
|
840
|
+
return (tx) => tx.moveCall({
|
|
841
|
+
package: packageAddress,
|
|
842
|
+
module: "margin_manager",
|
|
843
|
+
function: "highest_trigger_below_price",
|
|
844
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
845
|
+
typeArguments: options.typeArguments
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
function getAccountOrderDetails(options) {
|
|
849
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
850
|
+
const argumentsTypes = [null, null];
|
|
851
|
+
const parameterNames = ["self", "pool"];
|
|
852
|
+
return (tx) => tx.moveCall({
|
|
853
|
+
package: packageAddress,
|
|
854
|
+
module: "margin_manager",
|
|
855
|
+
function: "get_account_order_details",
|
|
856
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
857
|
+
typeArguments: options.typeArguments
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
function accountOpenOrders(options) {
|
|
861
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
862
|
+
const argumentsTypes = [null, null];
|
|
863
|
+
const parameterNames = ["self", "pool"];
|
|
864
|
+
return (tx) => tx.moveCall({
|
|
865
|
+
package: packageAddress,
|
|
866
|
+
module: "margin_manager",
|
|
867
|
+
function: "account_open_orders",
|
|
868
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
869
|
+
typeArguments: options.typeArguments
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
function lockedBalance(options) {
|
|
873
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
874
|
+
const argumentsTypes = [null, null];
|
|
875
|
+
const parameterNames = ["self", "pool"];
|
|
876
|
+
return (tx) => tx.moveCall({
|
|
877
|
+
package: packageAddress,
|
|
878
|
+
module: "margin_manager",
|
|
879
|
+
function: "locked_balance",
|
|
880
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
881
|
+
typeArguments: options.typeArguments
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
function balanceManagerId(options) {
|
|
885
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
886
|
+
const argumentsTypes = [null];
|
|
887
|
+
const parameterNames = ["self"];
|
|
888
|
+
return (tx) => tx.moveCall({
|
|
889
|
+
package: packageAddress,
|
|
890
|
+
module: "margin_manager",
|
|
891
|
+
function: "balance_manager_id",
|
|
892
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
893
|
+
typeArguments: options.typeArguments
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
function getBalanceManagerReferralId(options) {
|
|
897
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
898
|
+
const argumentsTypes = [null, "0x2::object::ID"];
|
|
899
|
+
const parameterNames = ["self", "poolId"];
|
|
900
|
+
return (tx) => tx.moveCall({
|
|
901
|
+
package: packageAddress,
|
|
902
|
+
module: "margin_manager",
|
|
903
|
+
function: "get_balance_manager_referral_id",
|
|
904
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
905
|
+
typeArguments: options.typeArguments
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
function accountExists(options) {
|
|
909
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
910
|
+
const argumentsTypes = [null, null];
|
|
911
|
+
const parameterNames = ["self", "pool"];
|
|
912
|
+
return (tx) => tx.moveCall({
|
|
913
|
+
package: packageAddress,
|
|
914
|
+
module: "margin_manager",
|
|
915
|
+
function: "account_exists",
|
|
916
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
917
|
+
typeArguments: options.typeArguments
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
function account(options) {
|
|
921
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
922
|
+
const argumentsTypes = [null, null];
|
|
923
|
+
const parameterNames = ["self", "pool"];
|
|
924
|
+
return (tx) => tx.moveCall({
|
|
925
|
+
package: packageAddress,
|
|
926
|
+
module: "margin_manager",
|
|
927
|
+
function: "account",
|
|
928
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
929
|
+
typeArguments: options.typeArguments
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
function canPlaceLimitOrder(options) {
|
|
933
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
934
|
+
const argumentsTypes = [
|
|
935
|
+
null,
|
|
936
|
+
null,
|
|
937
|
+
"u64",
|
|
938
|
+
"u64",
|
|
939
|
+
"bool",
|
|
940
|
+
"bool",
|
|
941
|
+
"u64",
|
|
942
|
+
"0x2::clock::Clock"
|
|
943
|
+
];
|
|
944
|
+
const parameterNames = [
|
|
945
|
+
"self",
|
|
946
|
+
"pool",
|
|
947
|
+
"price",
|
|
948
|
+
"quantity",
|
|
949
|
+
"isBid",
|
|
950
|
+
"payWithDeep",
|
|
951
|
+
"expireTimestamp"
|
|
952
|
+
];
|
|
953
|
+
return (tx) => tx.moveCall({
|
|
954
|
+
package: packageAddress,
|
|
955
|
+
module: "margin_manager",
|
|
956
|
+
function: "can_place_limit_order",
|
|
957
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
958
|
+
typeArguments: options.typeArguments
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
function canPlaceMarketOrder(options) {
|
|
962
|
+
const packageAddress = options.package ?? "@deepbook/margin";
|
|
963
|
+
const argumentsTypes = [
|
|
964
|
+
null,
|
|
965
|
+
null,
|
|
966
|
+
"u64",
|
|
967
|
+
"bool",
|
|
968
|
+
"bool",
|
|
969
|
+
"0x2::clock::Clock"
|
|
970
|
+
];
|
|
971
|
+
const parameterNames = [
|
|
972
|
+
"self",
|
|
973
|
+
"pool",
|
|
974
|
+
"quantity",
|
|
975
|
+
"isBid",
|
|
976
|
+
"payWithDeep"
|
|
977
|
+
];
|
|
978
|
+
return (tx) => tx.moveCall({
|
|
979
|
+
package: packageAddress,
|
|
980
|
+
module: "margin_manager",
|
|
981
|
+
function: "can_place_market_order",
|
|
982
|
+
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
983
|
+
typeArguments: options.typeArguments
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
//#endregion
|
|
988
|
+
export { _new, account, accountExists, accountOpenOrders, addConditionalOrder, balanceManager, balanceManagerId, baseBalance, borrowBase, borrowQuote, borrowedBaseShares, borrowedQuoteShares, borrowedShares, calculateAssets, calculateDebts, canPlaceLimitOrder, canPlaceMarketOrder, cancelAllConditionalOrders, cancelConditionalOrder, conditionalOrder, conditionalOrderIds, deepBalance, deepbookPool, deposit, executeConditionalOrdersV2, executeConditionalOrdersV3, getAccountOrderDetails, getBalanceManagerReferralId, hasBaseDebt, highestTriggerBelowPrice, liquidate, lockedBalance, lowestTriggerAbovePrice, managerState, marginPoolId, newWithInitializer, owner, quoteBalance, registerMarginManager, repayBase, repayQuote, setMarginManagerReferral, share, unregisterMarginManager, unsetMarginManagerReferral, withdraw };
|
|
989
|
+
//# sourceMappingURL=margin_manager.mjs.map
|