@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
|
@@ -11,6 +11,7 @@ import type { DeepBookConfig } from '../utils/config.js';
|
|
|
11
11
|
import { OrderType, SelfMatchingOptions } from '../types/index.js';
|
|
12
12
|
import { MAX_TIMESTAMP, FLOAT_SCALAR } from '../utils/config.js';
|
|
13
13
|
import { convertQuantity, convertPrice, convertRate } from '../utils/conversion.js';
|
|
14
|
+
import * as poolProxyMoveCalls from '../contracts/deepbook_margin/pool_proxy.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* PoolProxyContract class for managing PoolProxy operations.
|
|
@@ -53,28 +54,29 @@ export class PoolProxyContract {
|
|
|
53
54
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
54
55
|
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
55
56
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
56
|
-
return tx.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
return tx.add(
|
|
58
|
+
poolProxyMoveCalls.placeLimitOrderV2({
|
|
59
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
60
|
+
arguments: {
|
|
61
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
62
|
+
marginManager: manager.address,
|
|
63
|
+
pool: pool.address,
|
|
64
|
+
baseMarginPool: baseMarginPool.address,
|
|
65
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
66
|
+
baseOracle: baseCoin.priceInfoObjectId!,
|
|
67
|
+
quoteOracle: quoteCoin.priceInfoObjectId!,
|
|
68
|
+
clientOrderId: BigInt(clientOrderId),
|
|
69
|
+
orderType,
|
|
70
|
+
selfMatchingOption,
|
|
71
|
+
price: inputPrice,
|
|
72
|
+
quantity: inputQuantity,
|
|
73
|
+
isBid,
|
|
74
|
+
payWithDeep,
|
|
75
|
+
expireTimestamp: expiration,
|
|
76
|
+
},
|
|
77
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
/**
|
|
@@ -101,25 +103,26 @@ export class PoolProxyContract {
|
|
|
101
103
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
102
104
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
103
105
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
104
|
-
return tx.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
106
|
+
return tx.add(
|
|
107
|
+
poolProxyMoveCalls.placeMarketOrderV2({
|
|
108
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
109
|
+
arguments: {
|
|
110
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
111
|
+
marginManager: manager.address,
|
|
112
|
+
pool: pool.address,
|
|
113
|
+
baseMarginPool: baseMarginPool.address,
|
|
114
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
115
|
+
baseOracle: baseCoin.priceInfoObjectId!,
|
|
116
|
+
quoteOracle: quoteCoin.priceInfoObjectId!,
|
|
117
|
+
clientOrderId: BigInt(clientOrderId),
|
|
118
|
+
selfMatchingOption,
|
|
119
|
+
quantity: inputQuantity,
|
|
120
|
+
isBid,
|
|
121
|
+
payWithDeep,
|
|
122
|
+
},
|
|
123
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
123
126
|
};
|
|
124
127
|
|
|
125
128
|
/**
|
|
@@ -151,28 +154,29 @@ export class PoolProxyContract {
|
|
|
151
154
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
152
155
|
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
153
156
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
154
|
-
return tx.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
return tx.add(
|
|
158
|
+
poolProxyMoveCalls.placeReduceOnlyLimitOrderV2({
|
|
159
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
160
|
+
arguments: {
|
|
161
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
162
|
+
marginManager: manager.address,
|
|
163
|
+
pool: pool.address,
|
|
164
|
+
baseMarginPool: baseMarginPool.address,
|
|
165
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
166
|
+
baseOracle: baseCoin.priceInfoObjectId!,
|
|
167
|
+
quoteOracle: quoteCoin.priceInfoObjectId!,
|
|
168
|
+
clientOrderId: BigInt(clientOrderId),
|
|
169
|
+
orderType,
|
|
170
|
+
selfMatchingOption,
|
|
171
|
+
price: inputPrice,
|
|
172
|
+
quantity: inputQuantity,
|
|
173
|
+
isBid,
|
|
174
|
+
payWithDeep,
|
|
175
|
+
expireTimestamp: expiration,
|
|
176
|
+
},
|
|
177
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
176
180
|
};
|
|
177
181
|
|
|
178
182
|
/**
|
|
@@ -200,27 +204,183 @@ export class PoolProxyContract {
|
|
|
200
204
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
201
205
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
202
206
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
203
|
-
return tx.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
207
|
+
return tx.add(
|
|
208
|
+
poolProxyMoveCalls.placeReduceOnlyMarketOrderV2({
|
|
209
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
210
|
+
arguments: {
|
|
211
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
212
|
+
marginManager: manager.address,
|
|
213
|
+
pool: pool.address,
|
|
214
|
+
baseMarginPool: baseMarginPool.address,
|
|
215
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
216
|
+
baseOracle: baseCoin.priceInfoObjectId!,
|
|
217
|
+
quoteOracle: quoteCoin.priceInfoObjectId!,
|
|
218
|
+
clientOrderId: BigInt(clientOrderId),
|
|
219
|
+
selfMatchingOption,
|
|
220
|
+
quantity: inputQuantity,
|
|
221
|
+
isBid,
|
|
222
|
+
payWithDeep,
|
|
223
|
+
},
|
|
224
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
225
|
+
}),
|
|
226
|
+
);
|
|
222
227
|
};
|
|
223
228
|
|
|
229
|
+
/**
|
|
230
|
+
* @description Place a market order and repay the loan from the fill proceeds.
|
|
231
|
+
* The taker fill settles into the manager's balance, so the proceeds (plus any
|
|
232
|
+
* idle balance) are repaid into the debt side before the risk check; the gate
|
|
233
|
+
* is then the *net* post-repay `risk_ratio` being at least the pre-fill ratio.
|
|
234
|
+
* Unlike {@link placeMarketOrder}, which checks the post-trade ratio against
|
|
235
|
+
* `min_borrow_risk_ratio`, this lets a deleveraging fill go through in the
|
|
236
|
+
* `liquidation..min_borrow` band, where a swap alone would be rejected.
|
|
237
|
+
* @param {PlaceMarginMarketOrderParams} params Parameters for placing a market order
|
|
238
|
+
* @returns A function that takes a Transaction object
|
|
239
|
+
*/
|
|
240
|
+
placeMarketOrderAndRepayLoan = (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => {
|
|
241
|
+
const {
|
|
242
|
+
poolKey,
|
|
243
|
+
marginManagerKey,
|
|
244
|
+
clientOrderId,
|
|
245
|
+
quantity,
|
|
246
|
+
isBid,
|
|
247
|
+
selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,
|
|
248
|
+
payWithDeep = true,
|
|
249
|
+
} = params;
|
|
250
|
+
const pool = this.#config.getPool(poolKey);
|
|
251
|
+
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
252
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
253
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
254
|
+
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
255
|
+
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
256
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
257
|
+
return tx.add(
|
|
258
|
+
poolProxyMoveCalls.placeMarketOrderAndRepayLoan({
|
|
259
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
260
|
+
arguments: {
|
|
261
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
262
|
+
marginManager: manager.address,
|
|
263
|
+
pool: pool.address,
|
|
264
|
+
baseMarginPool: baseMarginPool.address,
|
|
265
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
266
|
+
baseOracle: baseCoin.priceInfoObjectId!,
|
|
267
|
+
quoteOracle: quoteCoin.priceInfoObjectId!,
|
|
268
|
+
clientOrderId: BigInt(clientOrderId),
|
|
269
|
+
selfMatchingOption,
|
|
270
|
+
quantity: inputQuantity,
|
|
271
|
+
isBid,
|
|
272
|
+
payWithDeep,
|
|
273
|
+
},
|
|
274
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
275
|
+
}),
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @description Place a reduce only limit order and repay the loan from the
|
|
281
|
+
* fill proceeds. Requires debt on the relevant side (a bid needs base debt; an
|
|
282
|
+
* ask needs quote debt and sells at most the gross base held); the repay
|
|
283
|
+
* happens before the monotonic `risk_ratio` gate, so the check is on the net
|
|
284
|
+
* post-repay ratio.
|
|
285
|
+
* @param {PlaceMarginLimitOrderParams} params Parameters for placing a reduce only limit order
|
|
286
|
+
* @returns A function that takes a Transaction object
|
|
287
|
+
*/
|
|
288
|
+
placeReduceOnlyLimitOrderAndRepayLoan =
|
|
289
|
+
(params: PlaceMarginLimitOrderParams) => (tx: Transaction) => {
|
|
290
|
+
const {
|
|
291
|
+
poolKey,
|
|
292
|
+
marginManagerKey,
|
|
293
|
+
clientOrderId,
|
|
294
|
+
price,
|
|
295
|
+
quantity,
|
|
296
|
+
isBid,
|
|
297
|
+
expiration = MAX_TIMESTAMP,
|
|
298
|
+
orderType = OrderType.NO_RESTRICTION,
|
|
299
|
+
selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,
|
|
300
|
+
payWithDeep = true,
|
|
301
|
+
} = params;
|
|
302
|
+
const pool = this.#config.getPool(poolKey);
|
|
303
|
+
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
304
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
305
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
306
|
+
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
307
|
+
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
308
|
+
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
309
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
310
|
+
return tx.add(
|
|
311
|
+
poolProxyMoveCalls.placeReduceOnlyLimitOrderAndRepayLoan({
|
|
312
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
313
|
+
arguments: {
|
|
314
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
315
|
+
marginManager: manager.address,
|
|
316
|
+
pool: pool.address,
|
|
317
|
+
baseMarginPool: baseMarginPool.address,
|
|
318
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
319
|
+
baseOracle: baseCoin.priceInfoObjectId!,
|
|
320
|
+
quoteOracle: quoteCoin.priceInfoObjectId!,
|
|
321
|
+
clientOrderId: BigInt(clientOrderId),
|
|
322
|
+
orderType,
|
|
323
|
+
selfMatchingOption,
|
|
324
|
+
price: inputPrice,
|
|
325
|
+
quantity: inputQuantity,
|
|
326
|
+
isBid,
|
|
327
|
+
payWithDeep,
|
|
328
|
+
expireTimestamp: expiration,
|
|
329
|
+
},
|
|
330
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
331
|
+
}),
|
|
332
|
+
);
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* @description Place a reduce only market order and repay the loan from the
|
|
337
|
+
* fill proceeds. Same reduce-only direction guard as
|
|
338
|
+
* {@link placeReduceOnlyMarketOrder}, but the settled proceeds are repaid into
|
|
339
|
+
* the debt side before the monotonic `risk_ratio` gate, so the check is on the
|
|
340
|
+
* net post-repay ratio.
|
|
341
|
+
* @param {PlaceMarginMarketOrderParams} params Parameters for placing a reduce only market order
|
|
342
|
+
* @returns A function that takes a Transaction object
|
|
343
|
+
*/
|
|
344
|
+
placeReduceOnlyMarketOrderAndRepayLoan =
|
|
345
|
+
(params: PlaceMarginMarketOrderParams) => (tx: Transaction) => {
|
|
346
|
+
const {
|
|
347
|
+
poolKey,
|
|
348
|
+
marginManagerKey,
|
|
349
|
+
clientOrderId,
|
|
350
|
+
quantity,
|
|
351
|
+
isBid,
|
|
352
|
+
selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,
|
|
353
|
+
payWithDeep = true,
|
|
354
|
+
} = params;
|
|
355
|
+
const pool = this.#config.getPool(poolKey);
|
|
356
|
+
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
357
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
358
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
359
|
+
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
360
|
+
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
361
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
362
|
+
return tx.add(
|
|
363
|
+
poolProxyMoveCalls.placeReduceOnlyMarketOrderAndRepayLoan({
|
|
364
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
365
|
+
arguments: {
|
|
366
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
367
|
+
marginManager: manager.address,
|
|
368
|
+
pool: pool.address,
|
|
369
|
+
baseMarginPool: baseMarginPool.address,
|
|
370
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
371
|
+
baseOracle: baseCoin.priceInfoObjectId!,
|
|
372
|
+
quoteOracle: quoteCoin.priceInfoObjectId!,
|
|
373
|
+
clientOrderId: BigInt(clientOrderId),
|
|
374
|
+
selfMatchingOption,
|
|
375
|
+
quantity: inputQuantity,
|
|
376
|
+
isBid,
|
|
377
|
+
payWithDeep,
|
|
378
|
+
},
|
|
379
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
380
|
+
}),
|
|
381
|
+
);
|
|
382
|
+
};
|
|
383
|
+
|
|
224
384
|
/**
|
|
225
385
|
* @description Modify an existing order
|
|
226
386
|
* @param {string} marginManagerKey The key to identify the MarginManager
|
|
@@ -236,18 +396,19 @@ export class PoolProxyContract {
|
|
|
236
396
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
237
397
|
const inputQuantity = convertQuantity(newQuantity, baseCoin.scalar);
|
|
238
398
|
|
|
239
|
-
tx.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
399
|
+
tx.add(
|
|
400
|
+
poolProxyMoveCalls.modifyOrder({
|
|
401
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
402
|
+
arguments: {
|
|
403
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
404
|
+
marginManager: marginManager.address,
|
|
405
|
+
pool: pool.address,
|
|
406
|
+
orderId: BigInt(orderId),
|
|
407
|
+
newQuantity: inputQuantity,
|
|
408
|
+
},
|
|
409
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
410
|
+
}),
|
|
411
|
+
);
|
|
251
412
|
};
|
|
252
413
|
|
|
253
414
|
/**
|
|
@@ -261,17 +422,18 @@ export class PoolProxyContract {
|
|
|
261
422
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
262
423
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
263
424
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
264
|
-
tx.
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
425
|
+
tx.add(
|
|
426
|
+
poolProxyMoveCalls.cancelOrder({
|
|
427
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
428
|
+
arguments: {
|
|
429
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
430
|
+
marginManager: marginManager.address,
|
|
431
|
+
pool: pool.address,
|
|
432
|
+
orderId: BigInt(orderId),
|
|
433
|
+
},
|
|
434
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
435
|
+
}),
|
|
436
|
+
);
|
|
275
437
|
};
|
|
276
438
|
|
|
277
439
|
/**
|
|
@@ -285,17 +447,18 @@ export class PoolProxyContract {
|
|
|
285
447
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
286
448
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
287
449
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
288
|
-
tx.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
450
|
+
tx.add(
|
|
451
|
+
poolProxyMoveCalls.cancelOrders({
|
|
452
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
453
|
+
arguments: {
|
|
454
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
455
|
+
marginManager: marginManager.address,
|
|
456
|
+
pool: pool.address,
|
|
457
|
+
orderIds: orderIds.map(BigInt),
|
|
458
|
+
},
|
|
459
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
460
|
+
}),
|
|
461
|
+
);
|
|
299
462
|
};
|
|
300
463
|
|
|
301
464
|
/**
|
|
@@ -308,16 +471,17 @@ export class PoolProxyContract {
|
|
|
308
471
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
309
472
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
310
473
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
311
|
-
tx.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
474
|
+
tx.add(
|
|
475
|
+
poolProxyMoveCalls.cancelAllOrders({
|
|
476
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
477
|
+
arguments: {
|
|
478
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
479
|
+
marginManager: marginManager.address,
|
|
480
|
+
pool: pool.address,
|
|
481
|
+
},
|
|
482
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
483
|
+
}),
|
|
484
|
+
);
|
|
321
485
|
};
|
|
322
486
|
|
|
323
487
|
/**
|
|
@@ -330,15 +494,17 @@ export class PoolProxyContract {
|
|
|
330
494
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
331
495
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
332
496
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
333
|
-
tx.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
497
|
+
tx.add(
|
|
498
|
+
poolProxyMoveCalls.withdrawSettledAmounts({
|
|
499
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
500
|
+
arguments: {
|
|
501
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
502
|
+
marginManager: marginManager.address,
|
|
503
|
+
pool: pool.address,
|
|
504
|
+
},
|
|
505
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
506
|
+
}),
|
|
507
|
+
);
|
|
342
508
|
};
|
|
343
509
|
|
|
344
510
|
/**
|
|
@@ -354,16 +520,18 @@ export class PoolProxyContract {
|
|
|
354
520
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
355
521
|
const deepCoin = this.#config.getCoin('DEEP');
|
|
356
522
|
const stakeInput = convertQuantity(stakeAmount, deepCoin.scalar);
|
|
357
|
-
tx.
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
523
|
+
tx.add(
|
|
524
|
+
poolProxyMoveCalls.stake({
|
|
525
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
526
|
+
arguments: {
|
|
527
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
528
|
+
marginManager: marginManager.address,
|
|
529
|
+
pool: pool.address,
|
|
530
|
+
amount: stakeInput,
|
|
531
|
+
},
|
|
532
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
533
|
+
}),
|
|
534
|
+
);
|
|
367
535
|
};
|
|
368
536
|
|
|
369
537
|
/**
|
|
@@ -376,15 +544,17 @@ export class PoolProxyContract {
|
|
|
376
544
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
377
545
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
378
546
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
379
|
-
tx.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
547
|
+
tx.add(
|
|
548
|
+
poolProxyMoveCalls.unstake({
|
|
549
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
550
|
+
arguments: {
|
|
551
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
552
|
+
marginManager: marginManager.address,
|
|
553
|
+
pool: pool.address,
|
|
554
|
+
},
|
|
555
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
556
|
+
}),
|
|
557
|
+
);
|
|
388
558
|
};
|
|
389
559
|
|
|
390
560
|
/**
|
|
@@ -403,18 +573,20 @@ export class PoolProxyContract {
|
|
|
403
573
|
const stakeInput = convertRate(stakeRequired, FLOAT_SCALAR);
|
|
404
574
|
const takerFeeInput = convertRate(takerFee, FLOAT_SCALAR);
|
|
405
575
|
const makerFeeInput = convertRate(makerFee, FLOAT_SCALAR);
|
|
406
|
-
tx.
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
576
|
+
tx.add(
|
|
577
|
+
poolProxyMoveCalls.submitProposal({
|
|
578
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
579
|
+
arguments: {
|
|
580
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
581
|
+
marginManager: marginManager.address,
|
|
582
|
+
pool: pool.address,
|
|
583
|
+
takerFee: takerFeeInput,
|
|
584
|
+
makerFee: makerFeeInput,
|
|
585
|
+
stakeRequired: stakeInput,
|
|
586
|
+
},
|
|
587
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
588
|
+
}),
|
|
589
|
+
);
|
|
418
590
|
};
|
|
419
591
|
|
|
420
592
|
/**
|
|
@@ -428,16 +600,18 @@ export class PoolProxyContract {
|
|
|
428
600
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
429
601
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
430
602
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
431
|
-
tx.
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
603
|
+
tx.add(
|
|
604
|
+
poolProxyMoveCalls.vote({
|
|
605
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
606
|
+
arguments: {
|
|
607
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
608
|
+
marginManager: marginManager.address,
|
|
609
|
+
pool: pool.address,
|
|
610
|
+
proposalId,
|
|
611
|
+
},
|
|
612
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
613
|
+
}),
|
|
614
|
+
);
|
|
441
615
|
};
|
|
442
616
|
|
|
443
617
|
/**
|
|
@@ -450,15 +624,17 @@ export class PoolProxyContract {
|
|
|
450
624
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
451
625
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
452
626
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
453
|
-
tx.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
627
|
+
tx.add(
|
|
628
|
+
poolProxyMoveCalls.claimRebates({
|
|
629
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
630
|
+
arguments: {
|
|
631
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
632
|
+
marginManager: marginManager.address,
|
|
633
|
+
pool: pool.address,
|
|
634
|
+
},
|
|
635
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
636
|
+
}),
|
|
637
|
+
);
|
|
462
638
|
};
|
|
463
639
|
|
|
464
640
|
/**
|
|
@@ -472,15 +648,17 @@ export class PoolProxyContract {
|
|
|
472
648
|
const pool = this.#config.getPool(poolKey);
|
|
473
649
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
474
650
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
475
|
-
tx.
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
651
|
+
tx.add(
|
|
652
|
+
poolProxyMoveCalls.withdrawSettledAmountsPermissionless({
|
|
653
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
654
|
+
arguments: {
|
|
655
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
656
|
+
marginManager: marginManagerId,
|
|
657
|
+
pool: pool.address,
|
|
658
|
+
},
|
|
659
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
660
|
+
}),
|
|
661
|
+
);
|
|
484
662
|
};
|
|
485
663
|
|
|
486
664
|
/**
|
|
@@ -498,16 +676,17 @@ export class PoolProxyContract {
|
|
|
498
676
|
if (!quoteCoin.priceInfoObjectId) {
|
|
499
677
|
throw new Error(`Missing priceInfoObjectId for ${pool.quoteCoin}`);
|
|
500
678
|
}
|
|
501
|
-
tx.
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
679
|
+
tx.add(
|
|
680
|
+
poolProxyMoveCalls.updateCurrentPrice({
|
|
681
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
682
|
+
arguments: {
|
|
683
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
684
|
+
pool: pool.address,
|
|
685
|
+
basePriceInfoObject: baseCoin.priceInfoObjectId,
|
|
686
|
+
quotePriceInfoObject: quoteCoin.priceInfoObjectId,
|
|
687
|
+
},
|
|
688
|
+
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
689
|
+
}),
|
|
690
|
+
);
|
|
512
691
|
};
|
|
513
692
|
}
|