@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { convertPrice, convertQuantity, convertRate } from "../utils/conversion.mjs";
|
|
2
2
|
import { FLOAT_SCALAR, MAX_TIMESTAMP } from "../utils/config.mjs";
|
|
3
3
|
import { OrderType, SelfMatchingOptions } from "../types/index.mjs";
|
|
4
|
+
import { cancelAllOrders, cancelOrder, cancelOrders, claimRebates, modifyOrder, placeLimitOrderV2, placeMarketOrderAndRepayLoan, placeMarketOrderV2, placeReduceOnlyLimitOrderAndRepayLoan, placeReduceOnlyLimitOrderV2, placeReduceOnlyMarketOrderAndRepayLoan, placeReduceOnlyMarketOrderV2, stake, submitProposal, unstake, updateCurrentPrice, vote, withdrawSettledAmounts, withdrawSettledAmountsPermissionless } from "../contracts/deepbook_margin/pool_proxy.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/transactions/poolProxy.ts
|
|
6
7
|
/**
|
|
@@ -22,28 +23,27 @@ var PoolProxyContract = class {
|
|
|
22
23
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
23
24
|
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
24
25
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
25
|
-
return tx.
|
|
26
|
-
|
|
27
|
-
arguments:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
],
|
|
26
|
+
return tx.add(placeLimitOrderV2({
|
|
27
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
28
|
+
arguments: {
|
|
29
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
30
|
+
marginManager: manager.address,
|
|
31
|
+
pool: pool.address,
|
|
32
|
+
baseMarginPool: baseMarginPool.address,
|
|
33
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
34
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
35
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
36
|
+
clientOrderId: BigInt(clientOrderId),
|
|
37
|
+
orderType,
|
|
38
|
+
selfMatchingOption,
|
|
39
|
+
price: inputPrice,
|
|
40
|
+
quantity: inputQuantity,
|
|
41
|
+
isBid,
|
|
42
|
+
payWithDeep,
|
|
43
|
+
expireTimestamp: expiration
|
|
44
|
+
},
|
|
45
45
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
46
|
-
});
|
|
46
|
+
}));
|
|
47
47
|
};
|
|
48
48
|
this.placeMarketOrder = (params) => (tx) => {
|
|
49
49
|
const { poolKey, marginManagerKey, clientOrderId, quantity, isBid, selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED, payWithDeep = true } = params;
|
|
@@ -54,25 +54,24 @@ var PoolProxyContract = class {
|
|
|
54
54
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
55
55
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
56
56
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
57
|
-
return tx.
|
|
58
|
-
|
|
59
|
-
arguments:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
],
|
|
57
|
+
return tx.add(placeMarketOrderV2({
|
|
58
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
59
|
+
arguments: {
|
|
60
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
61
|
+
marginManager: manager.address,
|
|
62
|
+
pool: pool.address,
|
|
63
|
+
baseMarginPool: baseMarginPool.address,
|
|
64
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
65
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
66
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
67
|
+
clientOrderId: BigInt(clientOrderId),
|
|
68
|
+
selfMatchingOption,
|
|
69
|
+
quantity: inputQuantity,
|
|
70
|
+
isBid,
|
|
71
|
+
payWithDeep
|
|
72
|
+
},
|
|
74
73
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
75
|
-
});
|
|
74
|
+
}));
|
|
76
75
|
};
|
|
77
76
|
this.placeReduceOnlyLimitOrder = (params) => (tx) => {
|
|
78
77
|
const { poolKey, marginManagerKey, clientOrderId, price, quantity, isBid, expiration = MAX_TIMESTAMP, orderType = OrderType.NO_RESTRICTION, selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED, payWithDeep = true } = params;
|
|
@@ -84,28 +83,27 @@ var PoolProxyContract = class {
|
|
|
84
83
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
85
84
|
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
86
85
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
87
|
-
return tx.
|
|
88
|
-
|
|
89
|
-
arguments:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
],
|
|
86
|
+
return tx.add(placeReduceOnlyLimitOrderV2({
|
|
87
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
88
|
+
arguments: {
|
|
89
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
90
|
+
marginManager: manager.address,
|
|
91
|
+
pool: pool.address,
|
|
92
|
+
baseMarginPool: baseMarginPool.address,
|
|
93
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
94
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
95
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
96
|
+
clientOrderId: BigInt(clientOrderId),
|
|
97
|
+
orderType,
|
|
98
|
+
selfMatchingOption,
|
|
99
|
+
price: inputPrice,
|
|
100
|
+
quantity: inputQuantity,
|
|
101
|
+
isBid,
|
|
102
|
+
payWithDeep,
|
|
103
|
+
expireTimestamp: expiration
|
|
104
|
+
},
|
|
107
105
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
108
|
-
});
|
|
106
|
+
}));
|
|
109
107
|
};
|
|
110
108
|
this.placeReduceOnlyMarketOrder = (params) => (tx) => {
|
|
111
109
|
const { poolKey, marginManagerKey, clientOrderId, quantity, isBid, selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED, payWithDeep = true } = params;
|
|
@@ -116,25 +114,112 @@ var PoolProxyContract = class {
|
|
|
116
114
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
117
115
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
118
116
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
119
|
-
return tx.
|
|
120
|
-
|
|
121
|
-
arguments:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
],
|
|
117
|
+
return tx.add(placeReduceOnlyMarketOrderV2({
|
|
118
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
119
|
+
arguments: {
|
|
120
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
121
|
+
marginManager: manager.address,
|
|
122
|
+
pool: pool.address,
|
|
123
|
+
baseMarginPool: baseMarginPool.address,
|
|
124
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
125
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
126
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
127
|
+
clientOrderId: BigInt(clientOrderId),
|
|
128
|
+
selfMatchingOption,
|
|
129
|
+
quantity: inputQuantity,
|
|
130
|
+
isBid,
|
|
131
|
+
payWithDeep
|
|
132
|
+
},
|
|
136
133
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
137
|
-
});
|
|
134
|
+
}));
|
|
135
|
+
};
|
|
136
|
+
this.placeMarketOrderAndRepayLoan = (params) => (tx) => {
|
|
137
|
+
const { poolKey, marginManagerKey, clientOrderId, quantity, isBid, selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED, payWithDeep = true } = params;
|
|
138
|
+
const pool = this.#config.getPool(poolKey);
|
|
139
|
+
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
140
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
141
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
142
|
+
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
143
|
+
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
144
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
145
|
+
return tx.add(placeMarketOrderAndRepayLoan({
|
|
146
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
147
|
+
arguments: {
|
|
148
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
149
|
+
marginManager: manager.address,
|
|
150
|
+
pool: pool.address,
|
|
151
|
+
baseMarginPool: baseMarginPool.address,
|
|
152
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
153
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
154
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
155
|
+
clientOrderId: BigInt(clientOrderId),
|
|
156
|
+
selfMatchingOption,
|
|
157
|
+
quantity: inputQuantity,
|
|
158
|
+
isBid,
|
|
159
|
+
payWithDeep
|
|
160
|
+
},
|
|
161
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
162
|
+
}));
|
|
163
|
+
};
|
|
164
|
+
this.placeReduceOnlyLimitOrderAndRepayLoan = (params) => (tx) => {
|
|
165
|
+
const { poolKey, marginManagerKey, clientOrderId, price, quantity, isBid, expiration = MAX_TIMESTAMP, orderType = OrderType.NO_RESTRICTION, selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED, payWithDeep = true } = params;
|
|
166
|
+
const pool = this.#config.getPool(poolKey);
|
|
167
|
+
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
168
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
169
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
170
|
+
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
171
|
+
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
172
|
+
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
173
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
174
|
+
return tx.add(placeReduceOnlyLimitOrderAndRepayLoan({
|
|
175
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
176
|
+
arguments: {
|
|
177
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
178
|
+
marginManager: manager.address,
|
|
179
|
+
pool: pool.address,
|
|
180
|
+
baseMarginPool: baseMarginPool.address,
|
|
181
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
182
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
183
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
184
|
+
clientOrderId: BigInt(clientOrderId),
|
|
185
|
+
orderType,
|
|
186
|
+
selfMatchingOption,
|
|
187
|
+
price: inputPrice,
|
|
188
|
+
quantity: inputQuantity,
|
|
189
|
+
isBid,
|
|
190
|
+
payWithDeep,
|
|
191
|
+
expireTimestamp: expiration
|
|
192
|
+
},
|
|
193
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
194
|
+
}));
|
|
195
|
+
};
|
|
196
|
+
this.placeReduceOnlyMarketOrderAndRepayLoan = (params) => (tx) => {
|
|
197
|
+
const { poolKey, marginManagerKey, clientOrderId, quantity, isBid, selfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED, payWithDeep = true } = params;
|
|
198
|
+
const pool = this.#config.getPool(poolKey);
|
|
199
|
+
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
200
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
201
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
202
|
+
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
203
|
+
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
204
|
+
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
205
|
+
return tx.add(placeReduceOnlyMarketOrderAndRepayLoan({
|
|
206
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
207
|
+
arguments: {
|
|
208
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
209
|
+
marginManager: manager.address,
|
|
210
|
+
pool: pool.address,
|
|
211
|
+
baseMarginPool: baseMarginPool.address,
|
|
212
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
213
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
214
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
215
|
+
clientOrderId: BigInt(clientOrderId),
|
|
216
|
+
selfMatchingOption,
|
|
217
|
+
quantity: inputQuantity,
|
|
218
|
+
isBid,
|
|
219
|
+
payWithDeep
|
|
220
|
+
},
|
|
221
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
222
|
+
}));
|
|
138
223
|
};
|
|
139
224
|
this.modifyOrder = (marginManagerKey, orderId, newQuantity) => (tx) => {
|
|
140
225
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
@@ -142,83 +227,79 @@ var PoolProxyContract = class {
|
|
|
142
227
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
143
228
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
144
229
|
const inputQuantity = convertQuantity(newQuantity, baseCoin.scalar);
|
|
145
|
-
tx.
|
|
146
|
-
|
|
147
|
-
arguments:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
],
|
|
230
|
+
tx.add(modifyOrder({
|
|
231
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
232
|
+
arguments: {
|
|
233
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
234
|
+
marginManager: marginManager.address,
|
|
235
|
+
pool: pool.address,
|
|
236
|
+
orderId: BigInt(orderId),
|
|
237
|
+
newQuantity: inputQuantity
|
|
238
|
+
},
|
|
155
239
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
156
|
-
});
|
|
240
|
+
}));
|
|
157
241
|
};
|
|
158
242
|
this.cancelOrder = (marginManagerKey, orderId) => (tx) => {
|
|
159
243
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
160
244
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
161
245
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
162
246
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
163
|
-
tx.
|
|
164
|
-
|
|
165
|
-
arguments:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
],
|
|
247
|
+
tx.add(cancelOrder({
|
|
248
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
249
|
+
arguments: {
|
|
250
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
251
|
+
marginManager: marginManager.address,
|
|
252
|
+
pool: pool.address,
|
|
253
|
+
orderId: BigInt(orderId)
|
|
254
|
+
},
|
|
172
255
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
173
|
-
});
|
|
256
|
+
}));
|
|
174
257
|
};
|
|
175
258
|
this.cancelOrders = (marginManagerKey, orderIds) => (tx) => {
|
|
176
259
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
177
260
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
178
261
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
179
262
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
180
|
-
tx.
|
|
181
|
-
|
|
182
|
-
arguments:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
],
|
|
263
|
+
tx.add(cancelOrders({
|
|
264
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
265
|
+
arguments: {
|
|
266
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
267
|
+
marginManager: marginManager.address,
|
|
268
|
+
pool: pool.address,
|
|
269
|
+
orderIds: orderIds.map(BigInt)
|
|
270
|
+
},
|
|
189
271
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
190
|
-
});
|
|
272
|
+
}));
|
|
191
273
|
};
|
|
192
274
|
this.cancelAllOrders = (marginManagerKey) => (tx) => {
|
|
193
275
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
194
276
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
195
277
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
196
278
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
197
|
-
tx.
|
|
198
|
-
|
|
199
|
-
arguments:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
],
|
|
279
|
+
tx.add(cancelAllOrders({
|
|
280
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
281
|
+
arguments: {
|
|
282
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
283
|
+
marginManager: marginManager.address,
|
|
284
|
+
pool: pool.address
|
|
285
|
+
},
|
|
205
286
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
206
|
-
});
|
|
287
|
+
}));
|
|
207
288
|
};
|
|
208
289
|
this.withdrawSettledAmounts = (marginManagerKey) => (tx) => {
|
|
209
290
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
210
291
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
211
292
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
212
293
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
213
|
-
tx.
|
|
214
|
-
|
|
215
|
-
arguments:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
294
|
+
tx.add(withdrawSettledAmounts({
|
|
295
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
296
|
+
arguments: {
|
|
297
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
298
|
+
marginManager: marginManager.address,
|
|
299
|
+
pool: pool.address
|
|
300
|
+
},
|
|
220
301
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
221
|
-
});
|
|
302
|
+
}));
|
|
222
303
|
};
|
|
223
304
|
this.stake = (marginManagerKey, stakeAmount) => (tx) => {
|
|
224
305
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
@@ -226,31 +307,31 @@ var PoolProxyContract = class {
|
|
|
226
307
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
227
308
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
228
309
|
const stakeInput = convertQuantity(stakeAmount, this.#config.getCoin("DEEP").scalar);
|
|
229
|
-
tx.
|
|
230
|
-
|
|
231
|
-
arguments:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
310
|
+
tx.add(stake({
|
|
311
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
312
|
+
arguments: {
|
|
313
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
314
|
+
marginManager: marginManager.address,
|
|
315
|
+
pool: pool.address,
|
|
316
|
+
amount: stakeInput
|
|
317
|
+
},
|
|
237
318
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
238
|
-
});
|
|
319
|
+
}));
|
|
239
320
|
};
|
|
240
321
|
this.unstake = (marginManagerKey) => (tx) => {
|
|
241
322
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
242
323
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
243
324
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
244
325
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
245
|
-
tx.
|
|
246
|
-
|
|
247
|
-
arguments:
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
326
|
+
tx.add(unstake({
|
|
327
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
328
|
+
arguments: {
|
|
329
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
330
|
+
marginManager: marginManager.address,
|
|
331
|
+
pool: pool.address
|
|
332
|
+
},
|
|
252
333
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
253
|
-
});
|
|
334
|
+
}));
|
|
254
335
|
};
|
|
255
336
|
this.submitProposal = (marginManagerKey, params) => (tx) => {
|
|
256
337
|
const { takerFee, makerFee, stakeRequired } = params;
|
|
@@ -261,63 +342,63 @@ var PoolProxyContract = class {
|
|
|
261
342
|
const stakeInput = convertRate(stakeRequired, FLOAT_SCALAR);
|
|
262
343
|
const takerFeeInput = convertRate(takerFee, FLOAT_SCALAR);
|
|
263
344
|
const makerFeeInput = convertRate(makerFee, FLOAT_SCALAR);
|
|
264
|
-
tx.
|
|
265
|
-
|
|
266
|
-
arguments:
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
345
|
+
tx.add(submitProposal({
|
|
346
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
347
|
+
arguments: {
|
|
348
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
349
|
+
marginManager: marginManager.address,
|
|
350
|
+
pool: pool.address,
|
|
351
|
+
takerFee: takerFeeInput,
|
|
352
|
+
makerFee: makerFeeInput,
|
|
353
|
+
stakeRequired: stakeInput
|
|
354
|
+
},
|
|
274
355
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
275
|
-
});
|
|
356
|
+
}));
|
|
276
357
|
};
|
|
277
358
|
this.vote = (marginManagerKey, proposalId) => (tx) => {
|
|
278
359
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
279
360
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
280
361
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
281
362
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
282
|
-
tx.
|
|
283
|
-
|
|
284
|
-
arguments:
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
363
|
+
tx.add(vote({
|
|
364
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
365
|
+
arguments: {
|
|
366
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
367
|
+
marginManager: marginManager.address,
|
|
368
|
+
pool: pool.address,
|
|
369
|
+
proposalId
|
|
370
|
+
},
|
|
290
371
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
291
|
-
});
|
|
372
|
+
}));
|
|
292
373
|
};
|
|
293
374
|
this.claimRebate = (marginManagerKey) => (tx) => {
|
|
294
375
|
const marginManager = this.#config.getMarginManager(marginManagerKey);
|
|
295
376
|
const pool = this.#config.getPool(marginManager.poolKey);
|
|
296
377
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
297
378
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
298
|
-
tx.
|
|
299
|
-
|
|
300
|
-
arguments:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
379
|
+
tx.add(claimRebates({
|
|
380
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
381
|
+
arguments: {
|
|
382
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
383
|
+
marginManager: marginManager.address,
|
|
384
|
+
pool: pool.address
|
|
385
|
+
},
|
|
305
386
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
306
|
-
});
|
|
387
|
+
}));
|
|
307
388
|
};
|
|
308
389
|
this.withdrawMarginSettledAmounts = (poolKey, marginManagerId) => (tx) => {
|
|
309
390
|
const pool = this.#config.getPool(poolKey);
|
|
310
391
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
311
392
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
312
|
-
tx.
|
|
313
|
-
|
|
314
|
-
arguments:
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
393
|
+
tx.add(withdrawSettledAmountsPermissionless({
|
|
394
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
395
|
+
arguments: {
|
|
396
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
397
|
+
marginManager: marginManagerId,
|
|
398
|
+
pool: pool.address
|
|
399
|
+
},
|
|
319
400
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
320
|
-
});
|
|
401
|
+
}));
|
|
321
402
|
};
|
|
322
403
|
this.updateCurrentPrice = (poolKey) => (tx) => {
|
|
323
404
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -325,17 +406,16 @@ var PoolProxyContract = class {
|
|
|
325
406
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
326
407
|
if (!baseCoin.priceInfoObjectId) throw new Error(`Missing priceInfoObjectId for ${pool.baseCoin}`);
|
|
327
408
|
if (!quoteCoin.priceInfoObjectId) throw new Error(`Missing priceInfoObjectId for ${pool.quoteCoin}`);
|
|
328
|
-
tx.
|
|
329
|
-
|
|
330
|
-
arguments:
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
],
|
|
409
|
+
tx.add(updateCurrentPrice({
|
|
410
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
411
|
+
arguments: {
|
|
412
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
413
|
+
pool: pool.address,
|
|
414
|
+
basePriceInfoObject: baseCoin.priceInfoObjectId,
|
|
415
|
+
quotePriceInfoObject: quoteCoin.priceInfoObjectId
|
|
416
|
+
},
|
|
337
417
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
338
|
-
});
|
|
418
|
+
}));
|
|
339
419
|
};
|
|
340
420
|
this.#config = config;
|
|
341
421
|
}
|