@mysten/deepbook-v3 1.5.9 → 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 +60 -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/balance_manager.mjs +413 -0
- package/dist/contracts/deepbook/balance_manager.mjs.map +1 -0
- package/dist/contracts/deepbook/balances.d.mts +4 -4
- 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.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 +10 -0
- 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.map +1 -1
- package/dist/transactions/marginMaintainer.mjs +83 -83
- package/dist/transactions/marginMaintainer.mjs.map +1 -1
- package/dist/transactions/marginManager.d.mts.map +1 -1
- package/dist/transactions/marginManager.mjs +330 -311
- package/dist/transactions/marginManager.mjs.map +1 -1
- 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 +32 -0
- 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 +2 -2
- 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,5 +1,6 @@
|
|
|
1
1
|
import { convertPrice, convertQuantity } from "../utils/conversion.mjs";
|
|
2
2
|
import { FLOAT_SCALAR } from "../utils/config.mjs";
|
|
3
|
+
import { _new, account, accountExists, accountOpenOrders, balanceManager, balanceManagerId, baseBalance, borrowBase, borrowQuote, borrowedBaseShares, borrowedQuoteShares, borrowedShares, calculateAssets, calculateDebts, canPlaceLimitOrder, canPlaceMarketOrder, deepBalance, deepbookPool, deposit, getAccountOrderDetails, getBalanceManagerReferralId, hasBaseDebt, liquidate, lockedBalance, managerState, marginPoolId, newWithInitializer, owner, quoteBalance, registerMarginManager, repayBase, repayQuote, setMarginManagerReferral, share, unregisterMarginManager, unsetMarginManagerReferral, withdraw } from "../contracts/deepbook_margin/margin_manager.mjs";
|
|
3
4
|
import { coinWithBalance } from "@mysten/sui/transactions";
|
|
4
5
|
|
|
5
6
|
//#region src/transactions/marginManager.ts
|
|
@@ -16,31 +17,29 @@ var MarginManagerContract = class {
|
|
|
16
17
|
const pool = this.#config.getPool(poolKey);
|
|
17
18
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
18
19
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
19
|
-
tx.
|
|
20
|
-
|
|
21
|
-
arguments:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
],
|
|
20
|
+
tx.add(_new({
|
|
21
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
22
|
+
arguments: {
|
|
23
|
+
pool: pool.address,
|
|
24
|
+
deepbookRegistry: this.#config.REGISTRY_ID,
|
|
25
|
+
marginRegistry: this.#config.MARGIN_REGISTRY_ID
|
|
26
|
+
},
|
|
27
27
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
28
|
-
});
|
|
28
|
+
}));
|
|
29
29
|
};
|
|
30
30
|
this.newMarginManagerWithInitializer = (poolKey) => (tx) => {
|
|
31
31
|
const pool = this.#config.getPool(poolKey);
|
|
32
32
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
33
33
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
34
|
-
const [manager, initializer] = tx.
|
|
35
|
-
|
|
36
|
-
arguments:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
],
|
|
34
|
+
const [manager, initializer] = tx.add(newWithInitializer({
|
|
35
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
36
|
+
arguments: {
|
|
37
|
+
pool: pool.address,
|
|
38
|
+
deepbookRegistry: this.#config.REGISTRY_ID,
|
|
39
|
+
marginRegistry: this.#config.MARGIN_REGISTRY_ID
|
|
40
|
+
},
|
|
42
41
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
43
|
-
});
|
|
42
|
+
}));
|
|
44
43
|
return {
|
|
45
44
|
manager,
|
|
46
45
|
initializer
|
|
@@ -50,33 +49,42 @@ var MarginManagerContract = class {
|
|
|
50
49
|
const pool = this.#config.getPool(poolKey);
|
|
51
50
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
52
51
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
53
|
-
tx.
|
|
54
|
-
|
|
55
|
-
arguments:
|
|
52
|
+
tx.add(share({
|
|
53
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
54
|
+
arguments: {
|
|
55
|
+
manager,
|
|
56
|
+
initializer
|
|
57
|
+
},
|
|
56
58
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
57
|
-
});
|
|
59
|
+
}));
|
|
58
60
|
};
|
|
59
61
|
this.registerMarginManager = (managerKey) => (tx) => {
|
|
60
62
|
const manager = this.#config.getMarginManager(managerKey);
|
|
61
63
|
const pool = this.#config.getPool(manager.poolKey);
|
|
62
64
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
63
65
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
64
|
-
tx.
|
|
65
|
-
|
|
66
|
-
arguments:
|
|
66
|
+
tx.add(registerMarginManager({
|
|
67
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
68
|
+
arguments: {
|
|
69
|
+
self: manager.address,
|
|
70
|
+
marginRegistry: this.#config.MARGIN_REGISTRY_ID
|
|
71
|
+
},
|
|
67
72
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
68
|
-
});
|
|
73
|
+
}));
|
|
69
74
|
};
|
|
70
75
|
this.unregisterMarginManager = (managerKey) => (tx) => {
|
|
71
76
|
const manager = this.#config.getMarginManager(managerKey);
|
|
72
77
|
const pool = this.#config.getPool(manager.poolKey);
|
|
73
78
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
74
79
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
75
|
-
tx.
|
|
76
|
-
|
|
77
|
-
arguments:
|
|
80
|
+
tx.add(unregisterMarginManager({
|
|
81
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
82
|
+
arguments: {
|
|
83
|
+
self: manager.address,
|
|
84
|
+
marginRegistry: this.#config.MARGIN_REGISTRY_ID
|
|
85
|
+
},
|
|
78
86
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
79
|
-
});
|
|
87
|
+
}));
|
|
80
88
|
};
|
|
81
89
|
this.depositDuringInitialization = (params) => (tx) => {
|
|
82
90
|
const { manager, poolKey, coinType } = params;
|
|
@@ -88,22 +96,21 @@ var MarginManagerContract = class {
|
|
|
88
96
|
type: depositCoin.type,
|
|
89
97
|
balance: convertQuantity(params.amount, depositCoin.scalar)
|
|
90
98
|
}) : params.coin;
|
|
91
|
-
tx.
|
|
92
|
-
|
|
93
|
-
arguments:
|
|
94
|
-
manager,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
coin
|
|
99
|
-
|
|
100
|
-
],
|
|
99
|
+
tx.add(deposit({
|
|
100
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
101
|
+
arguments: {
|
|
102
|
+
self: manager,
|
|
103
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
104
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
105
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
106
|
+
coin
|
|
107
|
+
},
|
|
101
108
|
typeArguments: [
|
|
102
109
|
baseCoin.type,
|
|
103
110
|
quoteCoin.type,
|
|
104
111
|
depositCoin.type
|
|
105
112
|
]
|
|
106
|
-
});
|
|
113
|
+
}));
|
|
107
114
|
};
|
|
108
115
|
this.depositBase = (params) => (tx) => {
|
|
109
116
|
const { managerKey } = params;
|
|
@@ -115,22 +122,21 @@ var MarginManagerContract = class {
|
|
|
115
122
|
type: baseCoin.type,
|
|
116
123
|
balance: convertQuantity(params.amount, baseCoin.scalar)
|
|
117
124
|
}) : params.coin;
|
|
118
|
-
tx.
|
|
119
|
-
|
|
120
|
-
arguments:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
coin
|
|
126
|
-
|
|
127
|
-
],
|
|
125
|
+
tx.add(deposit({
|
|
126
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
127
|
+
arguments: {
|
|
128
|
+
self: manager.address,
|
|
129
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
130
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
131
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
132
|
+
coin
|
|
133
|
+
},
|
|
128
134
|
typeArguments: [
|
|
129
135
|
baseCoin.type,
|
|
130
136
|
quoteCoin.type,
|
|
131
137
|
baseCoin.type
|
|
132
138
|
]
|
|
133
|
-
});
|
|
139
|
+
}));
|
|
134
140
|
};
|
|
135
141
|
this.depositQuote = (params) => (tx) => {
|
|
136
142
|
const { managerKey } = params;
|
|
@@ -142,22 +148,21 @@ var MarginManagerContract = class {
|
|
|
142
148
|
type: quoteCoin.type,
|
|
143
149
|
balance: convertQuantity(params.amount, quoteCoin.scalar)
|
|
144
150
|
}) : params.coin;
|
|
145
|
-
tx.
|
|
146
|
-
|
|
147
|
-
arguments:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
coin
|
|
153
|
-
|
|
154
|
-
],
|
|
151
|
+
tx.add(deposit({
|
|
152
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
153
|
+
arguments: {
|
|
154
|
+
self: manager.address,
|
|
155
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
156
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
157
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
158
|
+
coin
|
|
159
|
+
},
|
|
155
160
|
typeArguments: [
|
|
156
161
|
baseCoin.type,
|
|
157
162
|
quoteCoin.type,
|
|
158
163
|
quoteCoin.type
|
|
159
164
|
]
|
|
160
|
-
});
|
|
165
|
+
}));
|
|
161
166
|
};
|
|
162
167
|
this.depositDeep = (params) => (tx) => {
|
|
163
168
|
const { managerKey } = params;
|
|
@@ -170,22 +175,21 @@ var MarginManagerContract = class {
|
|
|
170
175
|
type: deepCoin.type,
|
|
171
176
|
balance: convertQuantity(params.amount, deepCoin.scalar)
|
|
172
177
|
}) : params.coin;
|
|
173
|
-
tx.
|
|
174
|
-
|
|
175
|
-
arguments:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
coin
|
|
181
|
-
|
|
182
|
-
],
|
|
178
|
+
tx.add(deposit({
|
|
179
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
180
|
+
arguments: {
|
|
181
|
+
self: manager.address,
|
|
182
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
183
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
184
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
185
|
+
coin
|
|
186
|
+
},
|
|
183
187
|
typeArguments: [
|
|
184
188
|
baseCoin.type,
|
|
185
189
|
quoteCoin.type,
|
|
186
190
|
deepCoin.type
|
|
187
191
|
]
|
|
188
|
-
});
|
|
192
|
+
}));
|
|
189
193
|
};
|
|
190
194
|
this.withdrawBase = (managerKey, amount) => (tx) => {
|
|
191
195
|
const manager = this.#config.getMarginManager(managerKey);
|
|
@@ -194,25 +198,24 @@ var MarginManagerContract = class {
|
|
|
194
198
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
195
199
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
196
200
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
197
|
-
return tx.
|
|
198
|
-
|
|
199
|
-
arguments:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
],
|
|
201
|
+
return tx.add(withdraw({
|
|
202
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
203
|
+
arguments: {
|
|
204
|
+
self: manager.address,
|
|
205
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
206
|
+
baseMarginPool: baseMarginPool.address,
|
|
207
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
208
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
209
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
210
|
+
pool: pool.address,
|
|
211
|
+
withdrawAmount: convertQuantity(amount, baseCoin.scalar)
|
|
212
|
+
},
|
|
210
213
|
typeArguments: [
|
|
211
214
|
baseCoin.type,
|
|
212
215
|
quoteCoin.type,
|
|
213
216
|
baseCoin.type
|
|
214
217
|
]
|
|
215
|
-
});
|
|
218
|
+
}));
|
|
216
219
|
};
|
|
217
220
|
this.withdrawQuote = (managerKey, amount) => (tx) => {
|
|
218
221
|
const manager = this.#config.getMarginManager(managerKey);
|
|
@@ -221,25 +224,24 @@ var MarginManagerContract = class {
|
|
|
221
224
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
222
225
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
223
226
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
224
|
-
return tx.
|
|
225
|
-
|
|
226
|
-
arguments:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
],
|
|
227
|
+
return tx.add(withdraw({
|
|
228
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
229
|
+
arguments: {
|
|
230
|
+
self: manager.address,
|
|
231
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
232
|
+
baseMarginPool: baseMarginPool.address,
|
|
233
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
234
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
235
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
236
|
+
pool: pool.address,
|
|
237
|
+
withdrawAmount: convertQuantity(amount, quoteCoin.scalar)
|
|
238
|
+
},
|
|
237
239
|
typeArguments: [
|
|
238
240
|
baseCoin.type,
|
|
239
241
|
quoteCoin.type,
|
|
240
242
|
quoteCoin.type
|
|
241
243
|
]
|
|
242
|
-
});
|
|
244
|
+
}));
|
|
243
245
|
};
|
|
244
246
|
this.withdrawDeep = (managerKey, amount) => (tx) => {
|
|
245
247
|
const manager = this.#config.getMarginManager(managerKey);
|
|
@@ -249,25 +251,24 @@ var MarginManagerContract = class {
|
|
|
249
251
|
const deepCoin = this.#config.getCoin("DEEP");
|
|
250
252
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
251
253
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
252
|
-
return tx.
|
|
253
|
-
|
|
254
|
-
arguments:
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
],
|
|
254
|
+
return tx.add(withdraw({
|
|
255
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
256
|
+
arguments: {
|
|
257
|
+
self: manager.address,
|
|
258
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
259
|
+
baseMarginPool: baseMarginPool.address,
|
|
260
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
261
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
262
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
263
|
+
pool: pool.address,
|
|
264
|
+
withdrawAmount: convertQuantity(amount, deepCoin.scalar)
|
|
265
|
+
},
|
|
265
266
|
typeArguments: [
|
|
266
267
|
baseCoin.type,
|
|
267
268
|
quoteCoin.type,
|
|
268
269
|
deepCoin.type
|
|
269
270
|
]
|
|
270
|
-
});
|
|
271
|
+
}));
|
|
271
272
|
};
|
|
272
273
|
this.borrowBase = (managerKey, amount) => (tx) => {
|
|
273
274
|
const manager = this.#config.getMarginManager(managerKey);
|
|
@@ -275,20 +276,19 @@ var MarginManagerContract = class {
|
|
|
275
276
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
276
277
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
277
278
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
278
|
-
return tx.
|
|
279
|
-
|
|
280
|
-
arguments:
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
]
|
|
290
|
-
|
|
291
|
-
});
|
|
279
|
+
return tx.add(borrowBase({
|
|
280
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
281
|
+
arguments: {
|
|
282
|
+
self: manager.address,
|
|
283
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
284
|
+
baseMarginPool: baseMarginPool.address,
|
|
285
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
286
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
287
|
+
pool: pool.address,
|
|
288
|
+
loanAmount: convertQuantity(amount, baseCoin.scalar)
|
|
289
|
+
},
|
|
290
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
291
|
+
}));
|
|
292
292
|
};
|
|
293
293
|
this.borrowQuote = (managerKey, amount) => (tx) => {
|
|
294
294
|
const manager = this.#config.getMarginManager(managerKey);
|
|
@@ -296,20 +296,19 @@ var MarginManagerContract = class {
|
|
|
296
296
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
297
297
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
298
298
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
299
|
-
return tx.
|
|
300
|
-
|
|
301
|
-
arguments:
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
]
|
|
311
|
-
|
|
312
|
-
});
|
|
299
|
+
return tx.add(borrowQuote({
|
|
300
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
301
|
+
arguments: {
|
|
302
|
+
self: manager.address,
|
|
303
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
304
|
+
quoteMarginPool: quoteMarginPool.address,
|
|
305
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
306
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
307
|
+
pool: pool.address,
|
|
308
|
+
loanAmount: convertQuantity(amount, quoteCoin.scalar)
|
|
309
|
+
},
|
|
310
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
311
|
+
}));
|
|
313
312
|
};
|
|
314
313
|
this.repayBase = (managerKey, amount) => (tx) => {
|
|
315
314
|
const manager = this.#config.getMarginManager(managerKey);
|
|
@@ -317,17 +316,16 @@ var MarginManagerContract = class {
|
|
|
317
316
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
318
317
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
319
318
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
320
|
-
return tx.
|
|
321
|
-
|
|
322
|
-
arguments:
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
]
|
|
329
|
-
|
|
330
|
-
});
|
|
319
|
+
return tx.add(repayBase({
|
|
320
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
321
|
+
arguments: {
|
|
322
|
+
self: manager.address,
|
|
323
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
324
|
+
marginPool: baseMarginPool.address,
|
|
325
|
+
amount: amount !== void 0 ? convertQuantity(amount, baseCoin.scalar) : null
|
|
326
|
+
},
|
|
327
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
328
|
+
}));
|
|
331
329
|
};
|
|
332
330
|
this.repayQuote = (managerKey, amount) => (tx) => {
|
|
333
331
|
const manager = this.#config.getMarginManager(managerKey);
|
|
@@ -335,17 +333,16 @@ var MarginManagerContract = class {
|
|
|
335
333
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
336
334
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
337
335
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
338
|
-
return tx.
|
|
339
|
-
|
|
340
|
-
arguments:
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
]
|
|
347
|
-
|
|
348
|
-
});
|
|
336
|
+
return tx.add(repayQuote({
|
|
337
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
338
|
+
arguments: {
|
|
339
|
+
self: manager.address,
|
|
340
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
341
|
+
marginPool: quoteMarginPool.address,
|
|
342
|
+
amount: amount !== void 0 ? convertQuantity(amount, quoteCoin.scalar) : null
|
|
343
|
+
},
|
|
344
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
345
|
+
}));
|
|
349
346
|
};
|
|
350
347
|
this.liquidate = (managerAddress, poolKey, debtIsBase, repayCoin) => (tx) => {
|
|
351
348
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -354,136 +351,144 @@ var MarginManagerContract = class {
|
|
|
354
351
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
355
352
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
356
353
|
const marginPool = debtIsBase ? baseMarginPool : quoteMarginPool;
|
|
357
|
-
return tx.
|
|
358
|
-
|
|
359
|
-
arguments:
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
repayCoin
|
|
367
|
-
|
|
368
|
-
],
|
|
354
|
+
return tx.add(liquidate({
|
|
355
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
356
|
+
arguments: {
|
|
357
|
+
self: managerAddress,
|
|
358
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
359
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
360
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
361
|
+
marginPool: marginPool.address,
|
|
362
|
+
pool: pool.address,
|
|
363
|
+
repayCoin
|
|
364
|
+
},
|
|
369
365
|
typeArguments: [
|
|
370
366
|
baseCoin.type,
|
|
371
367
|
quoteCoin.type,
|
|
372
368
|
debtIsBase ? baseCoin.type : quoteCoin.type
|
|
373
369
|
]
|
|
374
|
-
});
|
|
370
|
+
}));
|
|
375
371
|
};
|
|
376
372
|
this.setMarginManagerReferral = (managerKey, referral) => (tx) => {
|
|
377
373
|
const manager = this.#config.getMarginManager(managerKey);
|
|
378
374
|
const pool = this.#config.getPool(manager.poolKey);
|
|
379
375
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
380
376
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
381
|
-
tx.
|
|
382
|
-
|
|
383
|
-
arguments:
|
|
377
|
+
tx.add(setMarginManagerReferral({
|
|
378
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
379
|
+
arguments: {
|
|
380
|
+
self: manager.address,
|
|
381
|
+
referralCap: referral
|
|
382
|
+
},
|
|
384
383
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
385
|
-
});
|
|
384
|
+
}));
|
|
386
385
|
};
|
|
387
386
|
this.unsetMarginManagerReferral = (managerKey, poolKey) => (tx) => {
|
|
388
387
|
const manager = this.#config.getMarginManager(managerKey);
|
|
389
388
|
const pool = this.#config.getPool(poolKey);
|
|
390
389
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
391
390
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
392
|
-
tx.
|
|
393
|
-
|
|
394
|
-
arguments:
|
|
391
|
+
tx.add(unsetMarginManagerReferral({
|
|
392
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
393
|
+
arguments: {
|
|
394
|
+
self: manager.address,
|
|
395
|
+
poolId: pool.address
|
|
396
|
+
},
|
|
395
397
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
396
|
-
});
|
|
398
|
+
}));
|
|
397
399
|
};
|
|
398
400
|
this.ownerByPoolKey = (poolKey, marginManagerId) => (tx) => {
|
|
399
401
|
const pool = this.#config.getPool(poolKey);
|
|
400
402
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
401
403
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
402
|
-
return tx.
|
|
403
|
-
|
|
404
|
-
arguments:
|
|
404
|
+
return tx.add(owner({
|
|
405
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
406
|
+
arguments: { self: marginManagerId },
|
|
405
407
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
406
|
-
});
|
|
408
|
+
}));
|
|
407
409
|
};
|
|
408
410
|
this.deepbookPool = (poolKey, marginManagerId) => (tx) => {
|
|
409
411
|
const pool = this.#config.getPool(poolKey);
|
|
410
412
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
411
413
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
412
|
-
return tx.
|
|
413
|
-
|
|
414
|
-
arguments:
|
|
414
|
+
return tx.add(deepbookPool({
|
|
415
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
416
|
+
arguments: { self: marginManagerId },
|
|
415
417
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
416
|
-
});
|
|
418
|
+
}));
|
|
417
419
|
};
|
|
418
420
|
this.marginPoolId = (poolKey, marginManagerId) => (tx) => {
|
|
419
421
|
const pool = this.#config.getPool(poolKey);
|
|
420
422
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
421
423
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
422
|
-
return tx.
|
|
423
|
-
|
|
424
|
-
arguments:
|
|
424
|
+
return tx.add(marginPoolId({
|
|
425
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
426
|
+
arguments: { self: marginManagerId },
|
|
425
427
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
426
|
-
});
|
|
428
|
+
}));
|
|
427
429
|
};
|
|
428
430
|
this.borrowedShares = (poolKey, marginManagerId) => (tx) => {
|
|
429
431
|
const pool = this.#config.getPool(poolKey);
|
|
430
432
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
431
433
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
432
|
-
return tx.
|
|
433
|
-
|
|
434
|
-
arguments:
|
|
434
|
+
return tx.add(borrowedShares({
|
|
435
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
436
|
+
arguments: { self: marginManagerId },
|
|
435
437
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
436
|
-
});
|
|
438
|
+
}));
|
|
437
439
|
};
|
|
438
440
|
this.borrowedBaseShares = (poolKey, marginManagerId) => (tx) => {
|
|
439
441
|
const pool = this.#config.getPool(poolKey);
|
|
440
442
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
441
443
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
442
|
-
return tx.
|
|
443
|
-
|
|
444
|
-
arguments:
|
|
444
|
+
return tx.add(borrowedBaseShares({
|
|
445
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
446
|
+
arguments: { self: marginManagerId },
|
|
445
447
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
446
|
-
});
|
|
448
|
+
}));
|
|
447
449
|
};
|
|
448
450
|
this.borrowedQuoteShares = (poolKey, marginManagerId) => (tx) => {
|
|
449
451
|
const pool = this.#config.getPool(poolKey);
|
|
450
452
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
451
453
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
452
|
-
return tx.
|
|
453
|
-
|
|
454
|
-
arguments:
|
|
454
|
+
return tx.add(borrowedQuoteShares({
|
|
455
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
456
|
+
arguments: { self: marginManagerId },
|
|
455
457
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
456
|
-
});
|
|
458
|
+
}));
|
|
457
459
|
};
|
|
458
460
|
this.hasBaseDebt = (poolKey, marginManagerId) => (tx) => {
|
|
459
461
|
const pool = this.#config.getPool(poolKey);
|
|
460
462
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
461
463
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
462
|
-
return tx.
|
|
463
|
-
|
|
464
|
-
arguments:
|
|
464
|
+
return tx.add(hasBaseDebt({
|
|
465
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
466
|
+
arguments: { self: marginManagerId },
|
|
465
467
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
466
|
-
});
|
|
468
|
+
}));
|
|
467
469
|
};
|
|
468
470
|
this.balanceManager = (poolKey, marginManagerId) => (tx) => {
|
|
469
471
|
const pool = this.#config.getPool(poolKey);
|
|
470
472
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
471
473
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
472
|
-
return tx.
|
|
473
|
-
|
|
474
|
-
arguments:
|
|
474
|
+
return tx.add(balanceManager({
|
|
475
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
476
|
+
arguments: { self: marginManagerId },
|
|
475
477
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
476
|
-
});
|
|
478
|
+
}));
|
|
477
479
|
};
|
|
478
480
|
this.calculateAssets = (poolKey, marginManagerId) => (tx) => {
|
|
479
481
|
const pool = this.#config.getPool(poolKey);
|
|
480
482
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
481
483
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
482
|
-
return tx.
|
|
483
|
-
|
|
484
|
-
arguments:
|
|
484
|
+
return tx.add(calculateAssets({
|
|
485
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
486
|
+
arguments: {
|
|
487
|
+
self: marginManagerId,
|
|
488
|
+
pool: pool.address
|
|
489
|
+
},
|
|
485
490
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
486
|
-
});
|
|
491
|
+
}));
|
|
487
492
|
};
|
|
488
493
|
this.calculateDebts = (poolKey, coinKey, marginManagerId) => (tx) => {
|
|
489
494
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -491,19 +496,18 @@ var MarginManagerContract = class {
|
|
|
491
496
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
492
497
|
const debtCoin = this.#config.getCoin(coinKey);
|
|
493
498
|
const marginPool = this.#config.getMarginPool(coinKey);
|
|
494
|
-
return tx.
|
|
495
|
-
|
|
496
|
-
arguments:
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
],
|
|
499
|
+
return tx.add(calculateDebts({
|
|
500
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
501
|
+
arguments: {
|
|
502
|
+
self: marginManagerId,
|
|
503
|
+
marginPool: marginPool.address
|
|
504
|
+
},
|
|
501
505
|
typeArguments: [
|
|
502
506
|
baseCoin.type,
|
|
503
507
|
quoteCoin.type,
|
|
504
508
|
debtCoin.type
|
|
505
509
|
]
|
|
506
|
-
});
|
|
510
|
+
}));
|
|
507
511
|
};
|
|
508
512
|
this.managerState = (poolKey, marginManagerId) => (tx) => {
|
|
509
513
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -511,120 +515,137 @@ var MarginManagerContract = class {
|
|
|
511
515
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
512
516
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
513
517
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
514
|
-
return tx.
|
|
515
|
-
|
|
516
|
-
arguments:
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
]
|
|
526
|
-
|
|
527
|
-
});
|
|
518
|
+
return tx.add(managerState({
|
|
519
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
520
|
+
arguments: {
|
|
521
|
+
self: marginManagerId,
|
|
522
|
+
registry: this.#config.MARGIN_REGISTRY_ID,
|
|
523
|
+
baseOracle: baseCoin.priceInfoObjectId,
|
|
524
|
+
quoteOracle: quoteCoin.priceInfoObjectId,
|
|
525
|
+
pool: pool.address,
|
|
526
|
+
baseMarginPool: baseMarginPool.address,
|
|
527
|
+
quoteMarginPool: quoteMarginPool.address
|
|
528
|
+
},
|
|
529
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
530
|
+
}));
|
|
528
531
|
};
|
|
529
532
|
this.baseBalance = (poolKey, marginManagerId) => (tx) => {
|
|
530
533
|
const pool = this.#config.getPool(poolKey);
|
|
531
534
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
532
535
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
533
|
-
return tx.
|
|
534
|
-
|
|
535
|
-
arguments:
|
|
536
|
+
return tx.add(baseBalance({
|
|
537
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
538
|
+
arguments: { self: marginManagerId },
|
|
536
539
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
537
|
-
});
|
|
540
|
+
}));
|
|
538
541
|
};
|
|
539
542
|
this.quoteBalance = (poolKey, marginManagerId) => (tx) => {
|
|
540
543
|
const pool = this.#config.getPool(poolKey);
|
|
541
544
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
542
545
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
543
|
-
return tx.
|
|
544
|
-
|
|
545
|
-
arguments:
|
|
546
|
+
return tx.add(quoteBalance({
|
|
547
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
548
|
+
arguments: { self: marginManagerId },
|
|
546
549
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
547
|
-
});
|
|
550
|
+
}));
|
|
548
551
|
};
|
|
549
552
|
this.deepBalance = (poolKey, marginManagerId) => (tx) => {
|
|
550
553
|
const pool = this.#config.getPool(poolKey);
|
|
551
554
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
552
555
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
553
|
-
return tx.
|
|
554
|
-
|
|
555
|
-
arguments:
|
|
556
|
+
return tx.add(deepBalance({
|
|
557
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
558
|
+
arguments: { self: marginManagerId },
|
|
556
559
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
557
|
-
});
|
|
560
|
+
}));
|
|
558
561
|
};
|
|
559
562
|
this.balanceManagerId = (poolKey, marginManagerId) => (tx) => {
|
|
560
563
|
const pool = this.#config.getPool(poolKey);
|
|
561
564
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
562
565
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
563
|
-
return tx.
|
|
564
|
-
|
|
565
|
-
arguments:
|
|
566
|
+
return tx.add(balanceManagerId({
|
|
567
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
568
|
+
arguments: { self: marginManagerId },
|
|
566
569
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
567
|
-
});
|
|
570
|
+
}));
|
|
568
571
|
};
|
|
569
572
|
this.getBalanceManagerReferralId = (poolKey, marginManagerId) => (tx) => {
|
|
570
573
|
const pool = this.#config.getPool(poolKey);
|
|
571
574
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
572
575
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
573
|
-
return tx.
|
|
574
|
-
|
|
575
|
-
arguments:
|
|
576
|
+
return tx.add(getBalanceManagerReferralId({
|
|
577
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
578
|
+
arguments: {
|
|
579
|
+
self: marginManagerId,
|
|
580
|
+
poolId: pool.address
|
|
581
|
+
},
|
|
576
582
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
577
|
-
});
|
|
583
|
+
}));
|
|
578
584
|
};
|
|
579
585
|
this.accountExists = (poolKey, marginManagerId) => (tx) => {
|
|
580
586
|
const pool = this.#config.getPool(poolKey);
|
|
581
587
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
582
588
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
583
|
-
return tx.
|
|
584
|
-
|
|
585
|
-
arguments:
|
|
589
|
+
return tx.add(accountExists({
|
|
590
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
591
|
+
arguments: {
|
|
592
|
+
self: marginManagerId,
|
|
593
|
+
pool: pool.address
|
|
594
|
+
},
|
|
586
595
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
587
|
-
});
|
|
596
|
+
}));
|
|
588
597
|
};
|
|
589
598
|
this.account = (poolKey, marginManagerId) => (tx) => {
|
|
590
599
|
const pool = this.#config.getPool(poolKey);
|
|
591
600
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
592
601
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
593
|
-
return tx.
|
|
594
|
-
|
|
595
|
-
arguments:
|
|
602
|
+
return tx.add(account({
|
|
603
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
604
|
+
arguments: {
|
|
605
|
+
self: marginManagerId,
|
|
606
|
+
pool: pool.address
|
|
607
|
+
},
|
|
596
608
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
597
|
-
});
|
|
609
|
+
}));
|
|
598
610
|
};
|
|
599
611
|
this.accountOpenOrders = (poolKey, marginManagerId) => (tx) => {
|
|
600
612
|
const pool = this.#config.getPool(poolKey);
|
|
601
613
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
602
614
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
603
|
-
return tx.
|
|
604
|
-
|
|
605
|
-
arguments:
|
|
615
|
+
return tx.add(accountOpenOrders({
|
|
616
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
617
|
+
arguments: {
|
|
618
|
+
self: marginManagerId,
|
|
619
|
+
pool: pool.address
|
|
620
|
+
},
|
|
606
621
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
607
|
-
});
|
|
622
|
+
}));
|
|
608
623
|
};
|
|
609
624
|
this.getAccountOrderDetails = (poolKey, marginManagerId) => (tx) => {
|
|
610
625
|
const pool = this.#config.getPool(poolKey);
|
|
611
626
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
612
627
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
613
|
-
return tx.
|
|
614
|
-
|
|
615
|
-
arguments:
|
|
628
|
+
return tx.add(getAccountOrderDetails({
|
|
629
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
630
|
+
arguments: {
|
|
631
|
+
self: marginManagerId,
|
|
632
|
+
pool: pool.address
|
|
633
|
+
},
|
|
616
634
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
617
|
-
});
|
|
635
|
+
}));
|
|
618
636
|
};
|
|
619
637
|
this.lockedBalance = (poolKey, marginManagerId) => (tx) => {
|
|
620
638
|
const pool = this.#config.getPool(poolKey);
|
|
621
639
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
622
640
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
623
|
-
return tx.
|
|
624
|
-
|
|
625
|
-
arguments:
|
|
641
|
+
return tx.add(lockedBalance({
|
|
642
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
643
|
+
arguments: {
|
|
644
|
+
self: marginManagerId,
|
|
645
|
+
pool: pool.address
|
|
646
|
+
},
|
|
626
647
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
627
|
-
});
|
|
648
|
+
}));
|
|
628
649
|
};
|
|
629
650
|
this.canPlaceLimitOrder = (poolKey, marginManagerId, price, quantity, isBid, payWithDeep, expireTimestamp) => (tx) => {
|
|
630
651
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -632,38 +653,36 @@ var MarginManagerContract = class {
|
|
|
632
653
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
633
654
|
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
634
655
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
635
|
-
return tx.
|
|
636
|
-
|
|
637
|
-
arguments:
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
]
|
|
647
|
-
|
|
648
|
-
});
|
|
656
|
+
return tx.add(canPlaceLimitOrder({
|
|
657
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
658
|
+
arguments: {
|
|
659
|
+
self: marginManagerId,
|
|
660
|
+
pool: pool.address,
|
|
661
|
+
price: inputPrice,
|
|
662
|
+
quantity: inputQuantity,
|
|
663
|
+
isBid,
|
|
664
|
+
payWithDeep,
|
|
665
|
+
expireTimestamp
|
|
666
|
+
},
|
|
667
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
668
|
+
}));
|
|
649
669
|
};
|
|
650
670
|
this.canPlaceMarketOrder = (poolKey, marginManagerId, quantity, isBid, payWithDeep) => (tx) => {
|
|
651
671
|
const pool = this.#config.getPool(poolKey);
|
|
652
672
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
653
673
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
654
674
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
655
|
-
return tx.
|
|
656
|
-
|
|
657
|
-
arguments:
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
]
|
|
665
|
-
|
|
666
|
-
});
|
|
675
|
+
return tx.add(canPlaceMarketOrder({
|
|
676
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
677
|
+
arguments: {
|
|
678
|
+
self: marginManagerId,
|
|
679
|
+
pool: pool.address,
|
|
680
|
+
quantity: inputQuantity,
|
|
681
|
+
isBid,
|
|
682
|
+
payWithDeep
|
|
683
|
+
},
|
|
684
|
+
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
685
|
+
}));
|
|
667
686
|
};
|
|
668
687
|
this.#config = config;
|
|
669
688
|
}
|