@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.
Files changed (182) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/dist/client.d.mts +5 -0
  3. package/dist/client.d.mts.map +1 -1
  4. package/dist/client.mjs +7 -0
  5. package/dist/client.mjs.map +1 -1
  6. package/dist/contracts/deepbook/account.d.mts +18 -18
  7. package/dist/contracts/deepbook/account.d.mts.map +1 -1
  8. package/dist/contracts/deepbook/balance_manager.mjs +413 -0
  9. package/dist/contracts/deepbook/balance_manager.mjs.map +1 -0
  10. package/dist/contracts/deepbook/big_vector.mjs +43 -0
  11. package/dist/contracts/deepbook/big_vector.mjs.map +1 -0
  12. package/dist/contracts/deepbook/book.mjs +29 -0
  13. package/dist/contracts/deepbook/book.mjs.map +1 -0
  14. package/dist/contracts/deepbook/deep_price.d.mts +3 -3
  15. package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
  16. package/dist/contracts/deepbook/deep_price.mjs +1 -1
  17. package/dist/contracts/deepbook/deps/std/type_name.mjs +17 -0
  18. package/dist/contracts/deepbook/deps/std/type_name.mjs.map +1 -0
  19. package/dist/contracts/deepbook/deps/sui/bag.mjs +43 -0
  20. package/dist/contracts/deepbook/deps/sui/bag.mjs.map +1 -0
  21. package/dist/contracts/deepbook/deps/sui/balance.mjs +21 -0
  22. package/dist/contracts/deepbook/deps/sui/balance.mjs.map +1 -0
  23. package/dist/contracts/deepbook/deps/sui/table.mjs +38 -0
  24. package/dist/contracts/deepbook/deps/sui/table.mjs.map +1 -0
  25. package/dist/contracts/deepbook/deps/sui/vec_map.mjs +37 -0
  26. package/dist/contracts/deepbook/deps/sui/vec_map.mjs.map +1 -0
  27. package/dist/contracts/deepbook/deps/sui/versioned.mjs +19 -0
  28. package/dist/contracts/deepbook/deps/sui/versioned.mjs.map +1 -0
  29. package/dist/contracts/deepbook/governance.mjs +49 -0
  30. package/dist/contracts/deepbook/governance.mjs.map +1 -0
  31. package/dist/contracts/deepbook/history.mjs +56 -0
  32. package/dist/contracts/deepbook/history.mjs.map +1 -0
  33. package/dist/contracts/deepbook/order.d.mts +12 -12
  34. package/dist/contracts/deepbook/pool.mjs +1739 -0
  35. package/dist/contracts/deepbook/pool.mjs.map +1 -0
  36. package/dist/contracts/deepbook/registry.mjs +295 -0
  37. package/dist/contracts/deepbook/registry.mjs.map +1 -0
  38. package/dist/contracts/deepbook/state.mjs +89 -0
  39. package/dist/contracts/deepbook/state.mjs.map +1 -0
  40. package/dist/contracts/deepbook/trade_params.mjs +21 -0
  41. package/dist/contracts/deepbook/trade_params.mjs.map +1 -0
  42. package/dist/contracts/deepbook/vault.mjs +42 -0
  43. package/dist/contracts/deepbook/vault.mjs.map +1 -0
  44. package/dist/contracts/deepbook_margin/deps/deepbook/balance_manager.mjs +53 -0
  45. package/dist/contracts/deepbook_margin/deps/deepbook/balance_manager.mjs.map +1 -0
  46. package/dist/contracts/deepbook_margin/deps/std/type_name.mjs +17 -0
  47. package/dist/contracts/deepbook_margin/deps/std/type_name.mjs.map +1 -0
  48. package/dist/contracts/deepbook_margin/deps/sui/bag.mjs +43 -0
  49. package/dist/contracts/deepbook_margin/deps/sui/bag.mjs.map +1 -0
  50. package/dist/contracts/deepbook_margin/deps/sui/balance.mjs +21 -0
  51. package/dist/contracts/deepbook_margin/deps/sui/balance.mjs.map +1 -0
  52. package/dist/contracts/deepbook_margin/deps/sui/table.mjs +38 -0
  53. package/dist/contracts/deepbook_margin/deps/sui/table.mjs.map +1 -0
  54. package/dist/contracts/deepbook_margin/deps/sui/vec_map.mjs +37 -0
  55. package/dist/contracts/deepbook_margin/deps/sui/vec_map.mjs.map +1 -0
  56. package/dist/contracts/deepbook_margin/deps/sui/vec_set.mjs +26 -0
  57. package/dist/contracts/deepbook_margin/deps/sui/vec_set.mjs.map +1 -0
  58. package/dist/contracts/deepbook_margin/deps/sui/versioned.mjs +19 -0
  59. package/dist/contracts/deepbook_margin/deps/sui/versioned.mjs.map +1 -0
  60. package/dist/contracts/deepbook_margin/margin_manager.mjs +989 -0
  61. package/dist/contracts/deepbook_margin/margin_manager.mjs.map +1 -0
  62. package/dist/contracts/deepbook_margin/margin_pool.mjs +550 -0
  63. package/dist/contracts/deepbook_margin/margin_pool.mjs.map +1 -0
  64. package/dist/contracts/deepbook_margin/margin_registry.mjs +786 -0
  65. package/dist/contracts/deepbook_margin/margin_registry.mjs.map +1 -0
  66. package/dist/contracts/deepbook_margin/margin_state.mjs +30 -0
  67. package/dist/contracts/deepbook_margin/margin_state.mjs.map +1 -0
  68. package/dist/contracts/deepbook_margin/oracle.mjs +82 -0
  69. package/dist/contracts/deepbook_margin/oracle.mjs.map +1 -0
  70. package/dist/contracts/deepbook_margin/pool_proxy.mjs +644 -0
  71. package/dist/contracts/deepbook_margin/pool_proxy.mjs.map +1 -0
  72. package/dist/contracts/deepbook_margin/position_manager.mjs +32 -0
  73. package/dist/contracts/deepbook_margin/position_manager.mjs.map +1 -0
  74. package/dist/contracts/deepbook_margin/protocol_config.mjs +122 -0
  75. package/dist/contracts/deepbook_margin/protocol_config.mjs.map +1 -0
  76. package/dist/contracts/deepbook_margin/protocol_fees.mjs +58 -0
  77. package/dist/contracts/deepbook_margin/protocol_fees.mjs.map +1 -0
  78. package/dist/contracts/deepbook_margin/rate_limiter.mjs +26 -0
  79. package/dist/contracts/deepbook_margin/rate_limiter.mjs.map +1 -0
  80. package/dist/contracts/deepbook_margin/tpsl.mjs +171 -0
  81. package/dist/contracts/deepbook_margin/tpsl.mjs.map +1 -0
  82. package/dist/contracts/margin_liquidation/deps/sui/bag.mjs +43 -0
  83. package/dist/contracts/margin_liquidation/deps/sui/bag.mjs.map +1 -0
  84. package/dist/contracts/margin_liquidation/liquidation_vault.mjs +179 -0
  85. package/dist/contracts/margin_liquidation/liquidation_vault.mjs.map +1 -0
  86. package/dist/contracts/utils/index.d.mts +1 -1
  87. package/dist/contracts/utils/index.mjs +92 -3
  88. package/dist/contracts/utils/index.mjs.map +1 -1
  89. package/dist/queries/registryQueries.mjs +13 -0
  90. package/dist/queries/registryQueries.mjs.map +1 -1
  91. package/dist/transactions/balanceManager.d.mts.map +1 -1
  92. package/dist/transactions/balanceManager.mjs +119 -100
  93. package/dist/transactions/balanceManager.mjs.map +1 -1
  94. package/dist/transactions/deepbook.d.mts.map +1 -1
  95. package/dist/transactions/deepbook.mjs +464 -439
  96. package/dist/transactions/deepbook.mjs.map +1 -1
  97. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  98. package/dist/transactions/deepbookAdmin.mjs +151 -135
  99. package/dist/transactions/deepbookAdmin.mjs.map +1 -1
  100. package/dist/transactions/flashLoans.d.mts.map +1 -1
  101. package/dist/transactions/flashLoans.mjs +29 -22
  102. package/dist/transactions/flashLoans.mjs.map +1 -1
  103. package/dist/transactions/governance.d.mts.map +1 -1
  104. package/dist/transactions/governance.mjs +34 -33
  105. package/dist/transactions/governance.mjs.map +1 -1
  106. package/dist/transactions/marginAdmin.d.mts +17 -7
  107. package/dist/transactions/marginAdmin.d.mts.map +1 -1
  108. package/dist/transactions/marginAdmin.mjs +186 -169
  109. package/dist/transactions/marginAdmin.mjs.map +1 -1
  110. package/dist/transactions/marginLiquidations.d.mts +3 -3
  111. package/dist/transactions/marginLiquidations.d.mts.map +1 -1
  112. package/dist/transactions/marginLiquidations.mjs +53 -54
  113. package/dist/transactions/marginLiquidations.mjs.map +1 -1
  114. package/dist/transactions/marginMaintainer.d.mts +5 -5
  115. package/dist/transactions/marginMaintainer.d.mts.map +1 -1
  116. package/dist/transactions/marginMaintainer.mjs +83 -83
  117. package/dist/transactions/marginMaintainer.mjs.map +1 -1
  118. package/dist/transactions/marginManager.d.mts +32 -32
  119. package/dist/transactions/marginManager.d.mts.map +1 -1
  120. package/dist/transactions/marginManager.mjs +330 -317
  121. package/dist/transactions/marginManager.mjs.map +1 -1
  122. package/dist/transactions/marginPool.d.mts +18 -18
  123. package/dist/transactions/marginPool.d.mts.map +1 -1
  124. package/dist/transactions/marginPool.mjs +93 -89
  125. package/dist/transactions/marginPool.mjs.map +1 -1
  126. package/dist/transactions/marginRegistry.d.mts +22 -15
  127. package/dist/transactions/marginRegistry.d.mts.map +1 -1
  128. package/dist/transactions/marginRegistry.mjs +101 -68
  129. package/dist/transactions/marginRegistry.mjs.map +1 -1
  130. package/dist/transactions/marginTPSL.d.mts +27 -9
  131. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  132. package/dist/transactions/marginTPSL.mjs +108 -82
  133. package/dist/transactions/marginTPSL.mjs.map +1 -1
  134. package/dist/transactions/poolProxy.d.mts +37 -5
  135. package/dist/transactions/poolProxy.d.mts.map +1 -1
  136. package/dist/transactions/poolProxy.mjs +269 -189
  137. package/dist/transactions/poolProxy.mjs.map +1 -1
  138. package/dist/utils/constants.mjs +4 -4
  139. package/dist/utils/constants.mjs.map +1 -1
  140. package/package.json +3 -3
  141. package/src/client.ts +8 -0
  142. package/src/contracts/deepbook/balance_manager.ts +46 -5
  143. package/src/contracts/deepbook/constants.ts +13 -0
  144. package/src/contracts/deepbook/pool.ts +133 -0
  145. package/src/contracts/deepbook/registry.ts +136 -1
  146. package/src/contracts/deepbook_margin/deps/deepbook/balance_manager.ts +49 -0
  147. package/src/contracts/deepbook_margin/deps/std/type_name.ts +24 -0
  148. package/src/contracts/deepbook_margin/deps/sui/bag.ts +41 -0
  149. package/src/contracts/deepbook_margin/deps/sui/balance.ts +19 -0
  150. package/src/contracts/deepbook_margin/deps/sui/table.ts +36 -0
  151. package/src/contracts/deepbook_margin/deps/sui/vec_map.ts +33 -0
  152. package/src/contracts/deepbook_margin/deps/sui/vec_set.ts +22 -0
  153. package/src/contracts/deepbook_margin/deps/sui/versioned.ts +13 -0
  154. package/src/contracts/deepbook_margin/margin_constants.ts +329 -0
  155. package/src/contracts/deepbook_margin/margin_manager.ts +1772 -0
  156. package/src/contracts/deepbook_margin/margin_pool.ts +1129 -0
  157. package/src/contracts/deepbook_margin/margin_registry.ts +1207 -0
  158. package/src/contracts/deepbook_margin/margin_state.ts +26 -0
  159. package/src/contracts/deepbook_margin/oracle.ts +99 -0
  160. package/src/contracts/deepbook_margin/pool_proxy.ts +1298 -0
  161. package/src/contracts/deepbook_margin/position_manager.ts +28 -0
  162. package/src/contracts/deepbook_margin/protocol_config.ts +163 -0
  163. package/src/contracts/deepbook_margin/protocol_fees.ts +153 -0
  164. package/src/contracts/deepbook_margin/rate_limiter.ts +80 -0
  165. package/src/contracts/deepbook_margin/tpsl.ts +559 -0
  166. package/src/contracts/margin_liquidation/deps/sui/bag.ts +41 -0
  167. package/src/contracts/margin_liquidation/liquidation_vault.ts +401 -0
  168. package/src/queries/registryQueries.ts +15 -0
  169. package/src/transactions/balanceManager.ts +140 -90
  170. package/src/transactions/deepbook.ts +586 -494
  171. package/src/transactions/deepbookAdmin.ts +154 -146
  172. package/src/transactions/flashLoans.ts +29 -20
  173. package/src/transactions/governance.ts +50 -37
  174. package/src/transactions/marginAdmin.ts +247 -188
  175. package/src/transactions/marginLiquidations.ts +70 -55
  176. package/src/transactions/marginMaintainer.ts +106 -88
  177. package/src/transactions/marginManager.ts +414 -348
  178. package/src/transactions/marginPool.ts +140 -103
  179. package/src/transactions/marginRegistry.ts +103 -70
  180. package/src/transactions/marginTPSL.ts +151 -87
  181. package/src/transactions/poolProxy.ts +384 -205
  182. package/src/utils/constants.ts +4 -4
@@ -5,6 +5,7 @@ import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transac
5
5
 
6
6
  import type { DeepBookConfig } from '../utils/config.js';
7
7
  import { convertQuantity } from '../utils/conversion.js';
8
+ import * as marginPoolMoveCalls from '../contracts/deepbook_margin/margin_pool.js';
8
9
 
9
10
  /**
10
11
  * MarginPoolContract class for managing MarginPool operations.
@@ -24,10 +25,12 @@ export class MarginPoolContract {
24
25
  * @returns A function that takes a Transaction object
25
26
  */
26
27
  mintSupplierCap = () => (tx: Transaction) => {
27
- return tx.moveCall({
28
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supplier_cap`,
29
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object.clock()],
30
- });
28
+ return tx.add(
29
+ marginPoolMoveCalls.mintSupplierCap({
30
+ package: this.#config.MARGIN_PACKAGE_ID,
31
+ arguments: { registry: this.#config.MARGIN_REGISTRY_ID },
32
+ }),
33
+ );
31
34
  };
32
35
 
33
36
  /**
@@ -55,6 +58,11 @@ export class MarginPoolContract {
55
58
  balance: depositInput,
56
59
  });
57
60
 
61
+ // NOTE: left as a positional moveCall (not codegen). This builder's
62
+ // coinWithBalance + `tx.object.option` (an on-chain option::none MoveCall
63
+ // for the Option<ID> referral) interleave commands in a way that a
64
+ // generated named-arg call reorders — so migrating it would change the
65
+ // emitted PTB. Kept verbatim to stay byte-identical.
58
66
  tx.moveCall({
59
67
  target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply`,
60
68
  arguments: [
@@ -86,17 +94,18 @@ export class MarginPoolContract {
86
94
  const coin = this.#config.getCoin(coinKey);
87
95
  const withdrawInput =
88
96
  amountToWithdraw !== undefined ? convertQuantity(amountToWithdraw, coin.scalar) : null;
89
- return tx.moveCall({
90
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw`,
91
- arguments: [
92
- tx.object(marginPool.address),
93
- tx.object(this.#config.MARGIN_REGISTRY_ID),
94
- supplierCap,
95
- tx.pure.option('u64', withdrawInput),
96
- tx.object.clock(),
97
- ],
98
- typeArguments: [marginPool.type],
99
- });
97
+ return tx.add(
98
+ marginPoolMoveCalls.withdraw({
99
+ package: this.#config.MARGIN_PACKAGE_ID,
100
+ arguments: {
101
+ self: marginPool.address,
102
+ registry: this.#config.MARGIN_REGISTRY_ID,
103
+ supplierCap,
104
+ amount: withdrawInput,
105
+ },
106
+ typeArguments: [marginPool.type],
107
+ }),
108
+ );
100
109
  };
101
110
 
102
111
  /**
@@ -106,15 +115,13 @@ export class MarginPoolContract {
106
115
  */
107
116
  mintSupplyReferral = (coinKey: string) => (tx: Transaction) => {
108
117
  const marginPool = this.#config.getMarginPool(coinKey);
109
- tx.moveCall({
110
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::mint_supply_referral`,
111
- arguments: [
112
- tx.object(marginPool.address),
113
- tx.object(this.#config.MARGIN_REGISTRY_ID),
114
- tx.object.clock(),
115
- ],
116
- typeArguments: [marginPool.type],
117
- });
118
+ tx.add(
119
+ marginPoolMoveCalls.mintSupplyReferral({
120
+ package: this.#config.MARGIN_PACKAGE_ID,
121
+ arguments: { self: marginPool.address, registry: this.#config.MARGIN_REGISTRY_ID },
122
+ typeArguments: [marginPool.type],
123
+ }),
124
+ );
118
125
  };
119
126
 
120
127
  /**
@@ -125,15 +132,17 @@ export class MarginPoolContract {
125
132
  */
126
133
  withdrawReferralFees = (coinKey: string, referralId: string) => (tx: Transaction) => {
127
134
  const marginPool = this.#config.getMarginPool(coinKey);
128
- return tx.moveCall({
129
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::withdraw_referral_fees`,
130
- arguments: [
131
- tx.object(marginPool.address),
132
- tx.object(this.#config.MARGIN_REGISTRY_ID),
133
- tx.object(referralId),
134
- ],
135
- typeArguments: [marginPool.type],
136
- });
135
+ return tx.add(
136
+ marginPoolMoveCalls.withdrawReferralFees({
137
+ package: this.#config.MARGIN_PACKAGE_ID,
138
+ arguments: {
139
+ self: marginPool.address,
140
+ registry: this.#config.MARGIN_REGISTRY_ID,
141
+ referral: referralId,
142
+ },
143
+ typeArguments: [marginPool.type],
144
+ }),
145
+ );
137
146
  };
138
147
 
139
148
  // === Read-only/View Functions ===
@@ -145,11 +154,13 @@ export class MarginPoolContract {
145
154
  */
146
155
  getId = (coinKey: string) => (tx: Transaction) => {
147
156
  const marginPool = this.#config.getMarginPool(coinKey);
148
- return tx.moveCall({
149
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::id`,
150
- arguments: [tx.object(marginPool.address)],
151
- typeArguments: [marginPool.type],
152
- });
157
+ return tx.add(
158
+ marginPoolMoveCalls.id({
159
+ package: this.#config.MARGIN_PACKAGE_ID,
160
+ arguments: { self: marginPool.address },
161
+ typeArguments: [marginPool.type],
162
+ }),
163
+ );
153
164
  };
154
165
 
155
166
  /**
@@ -160,11 +171,13 @@ export class MarginPoolContract {
160
171
  */
161
172
  deepbookPoolAllowed = (coinKey: string, deepbookPoolId: string) => (tx: Transaction) => {
162
173
  const marginPool = this.#config.getMarginPool(coinKey);
163
- return tx.moveCall({
164
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::deepbook_pool_allowed`,
165
- arguments: [tx.object(marginPool.address), tx.pure.id(deepbookPoolId)],
166
- typeArguments: [marginPool.type],
167
- });
174
+ return tx.add(
175
+ marginPoolMoveCalls.deepbookPoolAllowed({
176
+ package: this.#config.MARGIN_PACKAGE_ID,
177
+ arguments: { self: marginPool.address, deepbookPoolId },
178
+ typeArguments: [marginPool.type],
179
+ }),
180
+ );
168
181
  };
169
182
 
170
183
  /**
@@ -174,11 +187,13 @@ export class MarginPoolContract {
174
187
  */
175
188
  totalSupply = (coinKey: string) => (tx: Transaction) => {
176
189
  const marginPool = this.#config.getMarginPool(coinKey);
177
- return tx.moveCall({
178
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_supply`,
179
- arguments: [tx.object(marginPool.address)],
180
- typeArguments: [marginPool.type],
181
- });
190
+ return tx.add(
191
+ marginPoolMoveCalls.totalSupply({
192
+ package: this.#config.MARGIN_PACKAGE_ID,
193
+ arguments: { self: marginPool.address },
194
+ typeArguments: [marginPool.type],
195
+ }),
196
+ );
182
197
  };
183
198
 
184
199
  /**
@@ -188,11 +203,13 @@ export class MarginPoolContract {
188
203
  */
189
204
  supplyShares = (coinKey: string) => (tx: Transaction) => {
190
205
  const marginPool = this.#config.getMarginPool(coinKey);
191
- return tx.moveCall({
192
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_shares`,
193
- arguments: [tx.object(marginPool.address)],
194
- typeArguments: [marginPool.type],
195
- });
206
+ return tx.add(
207
+ marginPoolMoveCalls.supplyShares({
208
+ package: this.#config.MARGIN_PACKAGE_ID,
209
+ arguments: { self: marginPool.address },
210
+ typeArguments: [marginPool.type],
211
+ }),
212
+ );
196
213
  };
197
214
 
198
215
  /**
@@ -202,11 +219,13 @@ export class MarginPoolContract {
202
219
  */
203
220
  totalBorrow = (coinKey: string) => (tx: Transaction) => {
204
221
  const marginPool = this.#config.getMarginPool(coinKey);
205
- return tx.moveCall({
206
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::total_borrow`,
207
- arguments: [tx.object(marginPool.address)],
208
- typeArguments: [marginPool.type],
209
- });
222
+ return tx.add(
223
+ marginPoolMoveCalls.totalBorrow({
224
+ package: this.#config.MARGIN_PACKAGE_ID,
225
+ arguments: { self: marginPool.address },
226
+ typeArguments: [marginPool.type],
227
+ }),
228
+ );
210
229
  };
211
230
 
212
231
  /**
@@ -216,11 +235,13 @@ export class MarginPoolContract {
216
235
  */
217
236
  borrowShares = (coinKey: string) => (tx: Transaction) => {
218
237
  const marginPool = this.#config.getMarginPool(coinKey);
219
- return tx.moveCall({
220
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::borrow_shares`,
221
- arguments: [tx.object(marginPool.address)],
222
- typeArguments: [marginPool.type],
223
- });
238
+ return tx.add(
239
+ marginPoolMoveCalls.borrowShares({
240
+ package: this.#config.MARGIN_PACKAGE_ID,
241
+ arguments: { self: marginPool.address },
242
+ typeArguments: [marginPool.type],
243
+ }),
244
+ );
224
245
  };
225
246
 
226
247
  /**
@@ -230,11 +251,13 @@ export class MarginPoolContract {
230
251
  */
231
252
  lastUpdateTimestamp = (coinKey: string) => (tx: Transaction) => {
232
253
  const marginPool = this.#config.getMarginPool(coinKey);
233
- return tx.moveCall({
234
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::last_update_timestamp`,
235
- arguments: [tx.object(marginPool.address)],
236
- typeArguments: [marginPool.type],
237
- });
254
+ return tx.add(
255
+ marginPoolMoveCalls.lastUpdateTimestamp({
256
+ package: this.#config.MARGIN_PACKAGE_ID,
257
+ arguments: { self: marginPool.address },
258
+ typeArguments: [marginPool.type],
259
+ }),
260
+ );
238
261
  };
239
262
 
240
263
  /**
@@ -244,11 +267,13 @@ export class MarginPoolContract {
244
267
  */
245
268
  supplyCap = (coinKey: string) => (tx: Transaction) => {
246
269
  const marginPool = this.#config.getMarginPool(coinKey);
247
- return tx.moveCall({
248
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::supply_cap`,
249
- arguments: [tx.object(marginPool.address)],
250
- typeArguments: [marginPool.type],
251
- });
270
+ return tx.add(
271
+ marginPoolMoveCalls.supplyCap({
272
+ package: this.#config.MARGIN_PACKAGE_ID,
273
+ arguments: { self: marginPool.address },
274
+ typeArguments: [marginPool.type],
275
+ }),
276
+ );
252
277
  };
253
278
 
254
279
  /**
@@ -258,11 +283,13 @@ export class MarginPoolContract {
258
283
  */
259
284
  maxUtilizationRate = (coinKey: string) => (tx: Transaction) => {
260
285
  const marginPool = this.#config.getMarginPool(coinKey);
261
- return tx.moveCall({
262
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::max_utilization_rate`,
263
- arguments: [tx.object(marginPool.address)],
264
- typeArguments: [marginPool.type],
265
- });
286
+ return tx.add(
287
+ marginPoolMoveCalls.maxUtilizationRate({
288
+ package: this.#config.MARGIN_PACKAGE_ID,
289
+ arguments: { self: marginPool.address },
290
+ typeArguments: [marginPool.type],
291
+ }),
292
+ );
266
293
  };
267
294
 
268
295
  /**
@@ -272,11 +299,13 @@ export class MarginPoolContract {
272
299
  */
273
300
  protocolSpread = (coinKey: string) => (tx: Transaction) => {
274
301
  const marginPool = this.#config.getMarginPool(coinKey);
275
- return tx.moveCall({
276
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::protocol_spread`,
277
- arguments: [tx.object(marginPool.address)],
278
- typeArguments: [marginPool.type],
279
- });
302
+ return tx.add(
303
+ marginPoolMoveCalls.protocolSpread({
304
+ package: this.#config.MARGIN_PACKAGE_ID,
305
+ arguments: { self: marginPool.address },
306
+ typeArguments: [marginPool.type],
307
+ }),
308
+ );
280
309
  };
281
310
 
282
311
  /**
@@ -286,11 +315,13 @@ export class MarginPoolContract {
286
315
  */
287
316
  minBorrow = (coinKey: string) => (tx: Transaction) => {
288
317
  const marginPool = this.#config.getMarginPool(coinKey);
289
- return tx.moveCall({
290
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::min_borrow`,
291
- arguments: [tx.object(marginPool.address)],
292
- typeArguments: [marginPool.type],
293
- });
318
+ return tx.add(
319
+ marginPoolMoveCalls.minBorrow({
320
+ package: this.#config.MARGIN_PACKAGE_ID,
321
+ arguments: { self: marginPool.address },
322
+ typeArguments: [marginPool.type],
323
+ }),
324
+ );
294
325
  };
295
326
 
296
327
  /**
@@ -300,11 +331,13 @@ export class MarginPoolContract {
300
331
  */
301
332
  interestRate = (coinKey: string) => (tx: Transaction) => {
302
333
  const marginPool = this.#config.getMarginPool(coinKey);
303
- return tx.moveCall({
304
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::interest_rate`,
305
- arguments: [tx.object(marginPool.address)],
306
- typeArguments: [marginPool.type],
307
- });
334
+ return tx.add(
335
+ marginPoolMoveCalls.interestRate({
336
+ package: this.#config.MARGIN_PACKAGE_ID,
337
+ arguments: { self: marginPool.address },
338
+ typeArguments: [marginPool.type],
339
+ }),
340
+ );
308
341
  };
309
342
 
310
343
  /**
@@ -315,11 +348,13 @@ export class MarginPoolContract {
315
348
  */
316
349
  userSupplyShares = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {
317
350
  const marginPool = this.#config.getMarginPool(coinKey);
318
- return tx.moveCall({
319
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_shares`,
320
- arguments: [tx.object(marginPool.address), tx.pure.id(supplierCapId)],
321
- typeArguments: [marginPool.type],
322
- });
351
+ return tx.add(
352
+ marginPoolMoveCalls.userSupplyShares({
353
+ package: this.#config.MARGIN_PACKAGE_ID,
354
+ arguments: { self: marginPool.address, supplierCapId },
355
+ typeArguments: [marginPool.type],
356
+ }),
357
+ );
323
358
  };
324
359
 
325
360
  /**
@@ -330,10 +365,12 @@ export class MarginPoolContract {
330
365
  */
331
366
  userSupplyAmount = (coinKey: string, supplierCapId: string) => (tx: Transaction) => {
332
367
  const marginPool = this.#config.getMarginPool(coinKey);
333
- return tx.moveCall({
334
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::user_supply_amount`,
335
- arguments: [tx.object(marginPool.address), tx.pure.id(supplierCapId), tx.object.clock()],
336
- typeArguments: [marginPool.type],
337
- });
368
+ return tx.add(
369
+ marginPoolMoveCalls.userSupplyAmount({
370
+ package: this.#config.MARGIN_PACKAGE_ID,
371
+ arguments: { self: marginPool.address, supplierCapId },
372
+ typeArguments: [marginPool.type],
373
+ }),
374
+ );
338
375
  };
339
376
  }
@@ -3,6 +3,7 @@
3
3
  import type { Transaction } from '@mysten/sui/transactions';
4
4
 
5
5
  import type { DeepBookConfig } from '../utils/config.js';
6
+ import * as marginRegistryMoveCalls from '../contracts/deepbook_margin/margin_registry.js';
6
7
 
7
8
  /**
8
9
  * MarginRegistryContract class for managing MarginRegistry read-only operations.
@@ -26,11 +27,13 @@ export class MarginRegistryContract {
26
27
  const pool = this.#config.getPool(poolKey);
27
28
  const baseCoin = this.#config.getCoin(pool.baseCoin);
28
29
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
29
- return tx.moveCall({
30
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::pool_enabled`,
31
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object(pool.address)],
32
- typeArguments: [baseCoin.type, quoteCoin.type],
33
- });
30
+ return tx.add(
31
+ marginRegistryMoveCalls.poolEnabled({
32
+ package: this.#config.MARGIN_PACKAGE_ID,
33
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, pool: pool.address },
34
+ typeArguments: [baseCoin.type, quoteCoin.type],
35
+ }),
36
+ );
34
37
  };
35
38
 
36
39
  /**
@@ -40,11 +43,13 @@ export class MarginRegistryContract {
40
43
  */
41
44
  getMarginPoolId = (coinKey: string) => (tx: Transaction) => {
42
45
  const coin = this.#config.getCoin(coinKey);
43
- return tx.moveCall({
44
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::get_margin_pool_id`,
45
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID)],
46
- typeArguments: [coin.type],
47
- });
46
+ return tx.add(
47
+ marginRegistryMoveCalls.getMarginPoolId({
48
+ package: this.#config.MARGIN_PACKAGE_ID,
49
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID },
50
+ typeArguments: [coin.type],
51
+ }),
52
+ );
48
53
  };
49
54
 
50
55
  /**
@@ -54,11 +59,12 @@ export class MarginRegistryContract {
54
59
  */
55
60
  getDeepbookPoolMarginPoolIds = (poolKey: string) => (tx: Transaction) => {
56
61
  const pool = this.#config.getPool(poolKey);
57
- return tx.moveCall({
58
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::get_deepbook_pool_margin_pool_ids`,
59
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
60
- typeArguments: [],
61
- });
62
+ return tx.add(
63
+ marginRegistryMoveCalls.getDeepbookPoolMarginPoolIds({
64
+ package: this.#config.MARGIN_PACKAGE_ID,
65
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
66
+ }),
67
+ );
62
68
  };
63
69
 
64
70
  /**
@@ -67,11 +73,12 @@ export class MarginRegistryContract {
67
73
  * @returns A function that takes a Transaction object
68
74
  */
69
75
  getMarginManagerIds = (owner: string) => (tx: Transaction) => {
70
- return tx.moveCall({
71
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::get_margin_manager_ids`,
72
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.address(owner)],
73
- typeArguments: [],
74
- });
76
+ return tx.add(
77
+ marginRegistryMoveCalls.getMarginManagerIds({
78
+ package: this.#config.MARGIN_PACKAGE_ID,
79
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, owner },
80
+ }),
81
+ );
75
82
  };
76
83
 
77
84
  /**
@@ -81,11 +88,12 @@ export class MarginRegistryContract {
81
88
  */
82
89
  baseMarginPoolId = (poolKey: string) => (tx: Transaction) => {
83
90
  const pool = this.#config.getPool(poolKey);
84
- return tx.moveCall({
85
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::base_margin_pool_id`,
86
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
87
- typeArguments: [],
88
- });
91
+ return tx.add(
92
+ marginRegistryMoveCalls.baseMarginPoolId({
93
+ package: this.#config.MARGIN_PACKAGE_ID,
94
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
95
+ }),
96
+ );
89
97
  };
90
98
 
91
99
  /**
@@ -95,11 +103,12 @@ export class MarginRegistryContract {
95
103
  */
96
104
  quoteMarginPoolId = (poolKey: string) => (tx: Transaction) => {
97
105
  const pool = this.#config.getPool(poolKey);
98
- return tx.moveCall({
99
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::quote_margin_pool_id`,
100
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
101
- typeArguments: [],
102
- });
106
+ return tx.add(
107
+ marginRegistryMoveCalls.quoteMarginPoolId({
108
+ package: this.#config.MARGIN_PACKAGE_ID,
109
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
110
+ }),
111
+ );
103
112
  };
104
113
 
105
114
  /**
@@ -109,11 +118,12 @@ export class MarginRegistryContract {
109
118
  */
110
119
  minWithdrawRiskRatio = (poolKey: string) => (tx: Transaction) => {
111
120
  const pool = this.#config.getPool(poolKey);
112
- return tx.moveCall({
113
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::min_withdraw_risk_ratio`,
114
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
115
- typeArguments: [],
116
- });
121
+ return tx.add(
122
+ marginRegistryMoveCalls.minWithdrawRiskRatio({
123
+ package: this.#config.MARGIN_PACKAGE_ID,
124
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
125
+ }),
126
+ );
117
127
  };
118
128
 
119
129
  /**
@@ -123,11 +133,28 @@ export class MarginRegistryContract {
123
133
  */
124
134
  minBorrowRiskRatio = (poolKey: string) => (tx: Transaction) => {
125
135
  const pool = this.#config.getPool(poolKey);
126
- return tx.moveCall({
127
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::min_borrow_risk_ratio`,
128
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
129
- typeArguments: [],
130
- });
136
+ return tx.add(
137
+ marginRegistryMoveCalls.minBorrowRiskRatio({
138
+ package: this.#config.MARGIN_PACKAGE_ID,
139
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
140
+ }),
141
+ );
142
+ };
143
+
144
+ /**
145
+ * @description Get the minimum risk ratio required to open a new position on
146
+ * a deepbook pool. Distinct from `minBorrowRiskRatio`, which gates borrowing.
147
+ * @param {string} poolKey The key to identify the pool
148
+ * @returns A function that takes a Transaction object
149
+ */
150
+ minOpenRiskRatio = (poolKey: string) => (tx: Transaction) => {
151
+ const pool = this.#config.getPool(poolKey);
152
+ return tx.add(
153
+ marginRegistryMoveCalls.minOpenRiskRatio({
154
+ package: this.#config.MARGIN_PACKAGE_ID,
155
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
156
+ }),
157
+ );
131
158
  };
132
159
 
133
160
  /**
@@ -137,11 +164,12 @@ export class MarginRegistryContract {
137
164
  */
138
165
  liquidationRiskRatio = (poolKey: string) => (tx: Transaction) => {
139
166
  const pool = this.#config.getPool(poolKey);
140
- return tx.moveCall({
141
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::liquidation_risk_ratio`,
142
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
143
- typeArguments: [],
144
- });
167
+ return tx.add(
168
+ marginRegistryMoveCalls.liquidationRiskRatio({
169
+ package: this.#config.MARGIN_PACKAGE_ID,
170
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
171
+ }),
172
+ );
145
173
  };
146
174
 
147
175
  /**
@@ -151,11 +179,12 @@ export class MarginRegistryContract {
151
179
  */
152
180
  targetLiquidationRiskRatio = (poolKey: string) => (tx: Transaction) => {
153
181
  const pool = this.#config.getPool(poolKey);
154
- return tx.moveCall({
155
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::target_liquidation_risk_ratio`,
156
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
157
- typeArguments: [],
158
- });
182
+ return tx.add(
183
+ marginRegistryMoveCalls.targetLiquidationRiskRatio({
184
+ package: this.#config.MARGIN_PACKAGE_ID,
185
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
186
+ }),
187
+ );
159
188
  };
160
189
 
161
190
  /**
@@ -165,11 +194,12 @@ export class MarginRegistryContract {
165
194
  */
166
195
  userLiquidationReward = (poolKey: string) => (tx: Transaction) => {
167
196
  const pool = this.#config.getPool(poolKey);
168
- return tx.moveCall({
169
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::user_liquidation_reward`,
170
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
171
- typeArguments: [],
172
- });
197
+ return tx.add(
198
+ marginRegistryMoveCalls.userLiquidationReward({
199
+ package: this.#config.MARGIN_PACKAGE_ID,
200
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
201
+ }),
202
+ );
173
203
  };
174
204
 
175
205
  /**
@@ -179,11 +209,12 @@ export class MarginRegistryContract {
179
209
  */
180
210
  poolLiquidationReward = (poolKey: string) => (tx: Transaction) => {
181
211
  const pool = this.#config.getPool(poolKey);
182
- return tx.moveCall({
183
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::pool_liquidation_reward`,
184
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.id(pool.address)],
185
- typeArguments: [],
186
- });
212
+ return tx.add(
213
+ marginRegistryMoveCalls.poolLiquidationReward({
214
+ package: this.#config.MARGIN_PACKAGE_ID,
215
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID, deepbookPoolId: pool.address },
216
+ }),
217
+ );
187
218
  };
188
219
 
189
220
  /**
@@ -191,11 +222,12 @@ export class MarginRegistryContract {
191
222
  * @returns A function that takes a Transaction object
192
223
  */
193
224
  allowedMaintainers = () => (tx: Transaction) => {
194
- return tx.moveCall({
195
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::allowed_maintainers`,
196
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID)],
197
- typeArguments: [],
198
- });
225
+ return tx.add(
226
+ marginRegistryMoveCalls.allowedMaintainers({
227
+ package: this.#config.MARGIN_PACKAGE_ID,
228
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID },
229
+ }),
230
+ );
199
231
  };
200
232
 
201
233
  /**
@@ -203,10 +235,11 @@ export class MarginRegistryContract {
203
235
  * @returns A function that takes a Transaction object
204
236
  */
205
237
  allowedPauseCaps = () => (tx: Transaction) => {
206
- return tx.moveCall({
207
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::allowed_pause_caps`,
208
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID)],
209
- typeArguments: [],
210
- });
238
+ return tx.add(
239
+ marginRegistryMoveCalls.allowedPauseCaps({
240
+ package: this.#config.MARGIN_PACKAGE_ID,
241
+ arguments: { self: this.#config.MARGIN_REGISTRY_ID },
242
+ }),
243
+ );
211
244
  };
212
245
  }