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