@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,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,20 +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
|
-
tx.object.clock()
|
|
331
|
-
],
|
|
332
|
-
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
333
|
-
});
|
|
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
|
+
}));
|
|
334
329
|
};
|
|
335
330
|
this.repayQuote = (managerKey, amount) => (tx) => {
|
|
336
331
|
const manager = this.#config.getMarginManager(managerKey);
|
|
@@ -338,20 +333,16 @@ var MarginManagerContract = class {
|
|
|
338
333
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
339
334
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
340
335
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
341
|
-
return tx.
|
|
342
|
-
|
|
343
|
-
arguments:
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
tx.object.clock()
|
|
352
|
-
],
|
|
353
|
-
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
354
|
-
});
|
|
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
|
+
}));
|
|
355
346
|
};
|
|
356
347
|
this.liquidate = (managerAddress, poolKey, debtIsBase, repayCoin) => (tx) => {
|
|
357
348
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -360,136 +351,144 @@ var MarginManagerContract = class {
|
|
|
360
351
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
361
352
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
362
353
|
const marginPool = debtIsBase ? baseMarginPool : quoteMarginPool;
|
|
363
|
-
return tx.
|
|
364
|
-
|
|
365
|
-
arguments:
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
repayCoin
|
|
373
|
-
|
|
374
|
-
],
|
|
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
|
+
},
|
|
375
365
|
typeArguments: [
|
|
376
366
|
baseCoin.type,
|
|
377
367
|
quoteCoin.type,
|
|
378
368
|
debtIsBase ? baseCoin.type : quoteCoin.type
|
|
379
369
|
]
|
|
380
|
-
});
|
|
370
|
+
}));
|
|
381
371
|
};
|
|
382
372
|
this.setMarginManagerReferral = (managerKey, referral) => (tx) => {
|
|
383
373
|
const manager = this.#config.getMarginManager(managerKey);
|
|
384
374
|
const pool = this.#config.getPool(manager.poolKey);
|
|
385
375
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
386
376
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
387
|
-
tx.
|
|
388
|
-
|
|
389
|
-
arguments:
|
|
377
|
+
tx.add(setMarginManagerReferral({
|
|
378
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
379
|
+
arguments: {
|
|
380
|
+
self: manager.address,
|
|
381
|
+
referralCap: referral
|
|
382
|
+
},
|
|
390
383
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
391
|
-
});
|
|
384
|
+
}));
|
|
392
385
|
};
|
|
393
386
|
this.unsetMarginManagerReferral = (managerKey, poolKey) => (tx) => {
|
|
394
387
|
const manager = this.#config.getMarginManager(managerKey);
|
|
395
388
|
const pool = this.#config.getPool(poolKey);
|
|
396
389
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
397
390
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
398
|
-
tx.
|
|
399
|
-
|
|
400
|
-
arguments:
|
|
391
|
+
tx.add(unsetMarginManagerReferral({
|
|
392
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
393
|
+
arguments: {
|
|
394
|
+
self: manager.address,
|
|
395
|
+
poolId: pool.address
|
|
396
|
+
},
|
|
401
397
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
402
|
-
});
|
|
398
|
+
}));
|
|
403
399
|
};
|
|
404
400
|
this.ownerByPoolKey = (poolKey, marginManagerId) => (tx) => {
|
|
405
401
|
const pool = this.#config.getPool(poolKey);
|
|
406
402
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
407
403
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
408
|
-
return tx.
|
|
409
|
-
|
|
410
|
-
arguments:
|
|
404
|
+
return tx.add(owner({
|
|
405
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
406
|
+
arguments: { self: marginManagerId },
|
|
411
407
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
412
|
-
});
|
|
408
|
+
}));
|
|
413
409
|
};
|
|
414
410
|
this.deepbookPool = (poolKey, marginManagerId) => (tx) => {
|
|
415
411
|
const pool = this.#config.getPool(poolKey);
|
|
416
412
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
417
413
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
418
|
-
return tx.
|
|
419
|
-
|
|
420
|
-
arguments:
|
|
414
|
+
return tx.add(deepbookPool({
|
|
415
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
416
|
+
arguments: { self: marginManagerId },
|
|
421
417
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
422
|
-
});
|
|
418
|
+
}));
|
|
423
419
|
};
|
|
424
420
|
this.marginPoolId = (poolKey, marginManagerId) => (tx) => {
|
|
425
421
|
const pool = this.#config.getPool(poolKey);
|
|
426
422
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
427
423
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
428
|
-
return tx.
|
|
429
|
-
|
|
430
|
-
arguments:
|
|
424
|
+
return tx.add(marginPoolId({
|
|
425
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
426
|
+
arguments: { self: marginManagerId },
|
|
431
427
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
432
|
-
});
|
|
428
|
+
}));
|
|
433
429
|
};
|
|
434
430
|
this.borrowedShares = (poolKey, marginManagerId) => (tx) => {
|
|
435
431
|
const pool = this.#config.getPool(poolKey);
|
|
436
432
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
437
433
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
438
|
-
return tx.
|
|
439
|
-
|
|
440
|
-
arguments:
|
|
434
|
+
return tx.add(borrowedShares({
|
|
435
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
436
|
+
arguments: { self: marginManagerId },
|
|
441
437
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
442
|
-
});
|
|
438
|
+
}));
|
|
443
439
|
};
|
|
444
440
|
this.borrowedBaseShares = (poolKey, marginManagerId) => (tx) => {
|
|
445
441
|
const pool = this.#config.getPool(poolKey);
|
|
446
442
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
447
443
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
448
|
-
return tx.
|
|
449
|
-
|
|
450
|
-
arguments:
|
|
444
|
+
return tx.add(borrowedBaseShares({
|
|
445
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
446
|
+
arguments: { self: marginManagerId },
|
|
451
447
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
452
|
-
});
|
|
448
|
+
}));
|
|
453
449
|
};
|
|
454
450
|
this.borrowedQuoteShares = (poolKey, marginManagerId) => (tx) => {
|
|
455
451
|
const pool = this.#config.getPool(poolKey);
|
|
456
452
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
457
453
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
458
|
-
return tx.
|
|
459
|
-
|
|
460
|
-
arguments:
|
|
454
|
+
return tx.add(borrowedQuoteShares({
|
|
455
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
456
|
+
arguments: { self: marginManagerId },
|
|
461
457
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
462
|
-
});
|
|
458
|
+
}));
|
|
463
459
|
};
|
|
464
460
|
this.hasBaseDebt = (poolKey, marginManagerId) => (tx) => {
|
|
465
461
|
const pool = this.#config.getPool(poolKey);
|
|
466
462
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
467
463
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
468
|
-
return tx.
|
|
469
|
-
|
|
470
|
-
arguments:
|
|
464
|
+
return tx.add(hasBaseDebt({
|
|
465
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
466
|
+
arguments: { self: marginManagerId },
|
|
471
467
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
472
|
-
});
|
|
468
|
+
}));
|
|
473
469
|
};
|
|
474
470
|
this.balanceManager = (poolKey, marginManagerId) => (tx) => {
|
|
475
471
|
const pool = this.#config.getPool(poolKey);
|
|
476
472
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
477
473
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
478
|
-
return tx.
|
|
479
|
-
|
|
480
|
-
arguments:
|
|
474
|
+
return tx.add(balanceManager({
|
|
475
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
476
|
+
arguments: { self: marginManagerId },
|
|
481
477
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
482
|
-
});
|
|
478
|
+
}));
|
|
483
479
|
};
|
|
484
480
|
this.calculateAssets = (poolKey, marginManagerId) => (tx) => {
|
|
485
481
|
const pool = this.#config.getPool(poolKey);
|
|
486
482
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
487
483
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
488
|
-
return tx.
|
|
489
|
-
|
|
490
|
-
arguments:
|
|
484
|
+
return tx.add(calculateAssets({
|
|
485
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
486
|
+
arguments: {
|
|
487
|
+
self: marginManagerId,
|
|
488
|
+
pool: pool.address
|
|
489
|
+
},
|
|
491
490
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
492
|
-
});
|
|
491
|
+
}));
|
|
493
492
|
};
|
|
494
493
|
this.calculateDebts = (poolKey, coinKey, marginManagerId) => (tx) => {
|
|
495
494
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -497,19 +496,18 @@ var MarginManagerContract = class {
|
|
|
497
496
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
498
497
|
const debtCoin = this.#config.getCoin(coinKey);
|
|
499
498
|
const marginPool = this.#config.getMarginPool(coinKey);
|
|
500
|
-
return tx.
|
|
501
|
-
|
|
502
|
-
arguments:
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
],
|
|
499
|
+
return tx.add(calculateDebts({
|
|
500
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
501
|
+
arguments: {
|
|
502
|
+
self: marginManagerId,
|
|
503
|
+
marginPool: marginPool.address
|
|
504
|
+
},
|
|
507
505
|
typeArguments: [
|
|
508
506
|
baseCoin.type,
|
|
509
507
|
quoteCoin.type,
|
|
510
508
|
debtCoin.type
|
|
511
509
|
]
|
|
512
|
-
});
|
|
510
|
+
}));
|
|
513
511
|
};
|
|
514
512
|
this.managerState = (poolKey, marginManagerId) => (tx) => {
|
|
515
513
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -517,120 +515,137 @@ var MarginManagerContract = class {
|
|
|
517
515
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
518
516
|
const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
|
|
519
517
|
const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
|
|
520
|
-
return tx.
|
|
521
|
-
|
|
522
|
-
arguments:
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
]
|
|
532
|
-
|
|
533
|
-
});
|
|
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
|
+
}));
|
|
534
531
|
};
|
|
535
532
|
this.baseBalance = (poolKey, marginManagerId) => (tx) => {
|
|
536
533
|
const pool = this.#config.getPool(poolKey);
|
|
537
534
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
538
535
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
539
|
-
return tx.
|
|
540
|
-
|
|
541
|
-
arguments:
|
|
536
|
+
return tx.add(baseBalance({
|
|
537
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
538
|
+
arguments: { self: marginManagerId },
|
|
542
539
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
543
|
-
});
|
|
540
|
+
}));
|
|
544
541
|
};
|
|
545
542
|
this.quoteBalance = (poolKey, marginManagerId) => (tx) => {
|
|
546
543
|
const pool = this.#config.getPool(poolKey);
|
|
547
544
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
548
545
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
549
|
-
return tx.
|
|
550
|
-
|
|
551
|
-
arguments:
|
|
546
|
+
return tx.add(quoteBalance({
|
|
547
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
548
|
+
arguments: { self: marginManagerId },
|
|
552
549
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
553
|
-
});
|
|
550
|
+
}));
|
|
554
551
|
};
|
|
555
552
|
this.deepBalance = (poolKey, marginManagerId) => (tx) => {
|
|
556
553
|
const pool = this.#config.getPool(poolKey);
|
|
557
554
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
558
555
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
559
|
-
return tx.
|
|
560
|
-
|
|
561
|
-
arguments:
|
|
556
|
+
return tx.add(deepBalance({
|
|
557
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
558
|
+
arguments: { self: marginManagerId },
|
|
562
559
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
563
|
-
});
|
|
560
|
+
}));
|
|
564
561
|
};
|
|
565
562
|
this.balanceManagerId = (poolKey, marginManagerId) => (tx) => {
|
|
566
563
|
const pool = this.#config.getPool(poolKey);
|
|
567
564
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
568
565
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
569
|
-
return tx.
|
|
570
|
-
|
|
571
|
-
arguments:
|
|
566
|
+
return tx.add(balanceManagerId({
|
|
567
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
568
|
+
arguments: { self: marginManagerId },
|
|
572
569
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
573
|
-
});
|
|
570
|
+
}));
|
|
574
571
|
};
|
|
575
572
|
this.getBalanceManagerReferralId = (poolKey, marginManagerId) => (tx) => {
|
|
576
573
|
const pool = this.#config.getPool(poolKey);
|
|
577
574
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
578
575
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
579
|
-
return tx.
|
|
580
|
-
|
|
581
|
-
arguments:
|
|
576
|
+
return tx.add(getBalanceManagerReferralId({
|
|
577
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
578
|
+
arguments: {
|
|
579
|
+
self: marginManagerId,
|
|
580
|
+
poolId: pool.address
|
|
581
|
+
},
|
|
582
582
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
583
|
-
});
|
|
583
|
+
}));
|
|
584
584
|
};
|
|
585
585
|
this.accountExists = (poolKey, marginManagerId) => (tx) => {
|
|
586
586
|
const pool = this.#config.getPool(poolKey);
|
|
587
587
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
588
588
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
589
|
-
return tx.
|
|
590
|
-
|
|
591
|
-
arguments:
|
|
589
|
+
return tx.add(accountExists({
|
|
590
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
591
|
+
arguments: {
|
|
592
|
+
self: marginManagerId,
|
|
593
|
+
pool: pool.address
|
|
594
|
+
},
|
|
592
595
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
593
|
-
});
|
|
596
|
+
}));
|
|
594
597
|
};
|
|
595
598
|
this.account = (poolKey, marginManagerId) => (tx) => {
|
|
596
599
|
const pool = this.#config.getPool(poolKey);
|
|
597
600
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
598
601
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
599
|
-
return tx.
|
|
600
|
-
|
|
601
|
-
arguments:
|
|
602
|
+
return tx.add(account({
|
|
603
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
604
|
+
arguments: {
|
|
605
|
+
self: marginManagerId,
|
|
606
|
+
pool: pool.address
|
|
607
|
+
},
|
|
602
608
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
603
|
-
});
|
|
609
|
+
}));
|
|
604
610
|
};
|
|
605
611
|
this.accountOpenOrders = (poolKey, marginManagerId) => (tx) => {
|
|
606
612
|
const pool = this.#config.getPool(poolKey);
|
|
607
613
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
608
614
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
609
|
-
return tx.
|
|
610
|
-
|
|
611
|
-
arguments:
|
|
615
|
+
return tx.add(accountOpenOrders({
|
|
616
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
617
|
+
arguments: {
|
|
618
|
+
self: marginManagerId,
|
|
619
|
+
pool: pool.address
|
|
620
|
+
},
|
|
612
621
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
613
|
-
});
|
|
622
|
+
}));
|
|
614
623
|
};
|
|
615
624
|
this.getAccountOrderDetails = (poolKey, marginManagerId) => (tx) => {
|
|
616
625
|
const pool = this.#config.getPool(poolKey);
|
|
617
626
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
618
627
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
619
|
-
return tx.
|
|
620
|
-
|
|
621
|
-
arguments:
|
|
628
|
+
return tx.add(getAccountOrderDetails({
|
|
629
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
630
|
+
arguments: {
|
|
631
|
+
self: marginManagerId,
|
|
632
|
+
pool: pool.address
|
|
633
|
+
},
|
|
622
634
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
623
|
-
});
|
|
635
|
+
}));
|
|
624
636
|
};
|
|
625
637
|
this.lockedBalance = (poolKey, marginManagerId) => (tx) => {
|
|
626
638
|
const pool = this.#config.getPool(poolKey);
|
|
627
639
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
628
640
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
629
|
-
return tx.
|
|
630
|
-
|
|
631
|
-
arguments:
|
|
641
|
+
return tx.add(lockedBalance({
|
|
642
|
+
package: this.#config.MARGIN_PACKAGE_ID,
|
|
643
|
+
arguments: {
|
|
644
|
+
self: marginManagerId,
|
|
645
|
+
pool: pool.address
|
|
646
|
+
},
|
|
632
647
|
typeArguments: [baseCoin.type, quoteCoin.type]
|
|
633
|
-
});
|
|
648
|
+
}));
|
|
634
649
|
};
|
|
635
650
|
this.canPlaceLimitOrder = (poolKey, marginManagerId, price, quantity, isBid, payWithDeep, expireTimestamp) => (tx) => {
|
|
636
651
|
const pool = this.#config.getPool(poolKey);
|
|
@@ -638,38 +653,36 @@ var MarginManagerContract = class {
|
|
|
638
653
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
639
654
|
const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
|
|
640
655
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
641
|
-
return tx.
|
|
642
|
-
|
|
643
|
-
arguments:
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
]
|
|
653
|
-
|
|
654
|
-
});
|
|
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
|
+
}));
|
|
655
669
|
};
|
|
656
670
|
this.canPlaceMarketOrder = (poolKey, marginManagerId, quantity, isBid, payWithDeep) => (tx) => {
|
|
657
671
|
const pool = this.#config.getPool(poolKey);
|
|
658
672
|
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
659
673
|
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
660
674
|
const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
|
|
661
|
-
return tx.
|
|
662
|
-
|
|
663
|
-
arguments:
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
]
|
|
671
|
-
|
|
672
|
-
});
|
|
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
|
+
}));
|
|
673
686
|
};
|
|
674
687
|
this.#config = config;
|
|
675
688
|
}
|