@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,4 +1,5 @@
1
1
  import { convertQuantity } from "../utils/conversion.mjs";
2
+ import { balance, createLiquidationVault, deposit, liquidateBase, liquidateQuote, withdraw } from "../contracts/margin_liquidation/liquidation_vault.mjs";
2
3
  import { coinWithBalance } from "@mysten/sui/transactions";
3
4
 
4
5
  //#region src/transactions/marginLiquidations.ts
@@ -12,10 +13,10 @@ var MarginLiquidationsContract = class {
12
13
  */
13
14
  constructor(config) {
14
15
  this.createLiquidationVault = (liquidationAdminCap) => (tx) => {
15
- tx.moveCall({
16
- target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::create_liquidation_vault`,
17
- arguments: [tx.object(liquidationAdminCap)]
18
- });
16
+ tx.add(createLiquidationVault({
17
+ package: this.#config.LIQUIDATION_PACKAGE_ID,
18
+ arguments: { LiquidationCap: liquidationAdminCap }
19
+ }));
19
20
  };
20
21
  this.deposit = (vaultId, liquidationAdminCap, coinKey, amount) => (tx) => {
21
22
  const coin = this.#config.getCoin(coinKey);
@@ -23,27 +24,27 @@ var MarginLiquidationsContract = class {
23
24
  type: coin.type,
24
25
  balance: convertQuantity(amount, coin.scalar)
25
26
  });
26
- tx.moveCall({
27
- target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::deposit`,
28
- arguments: [
29
- tx.object(vaultId),
30
- tx.object(liquidationAdminCap),
31
- depositCoin
32
- ],
27
+ tx.add(deposit({
28
+ package: this.#config.LIQUIDATION_PACKAGE_ID,
29
+ arguments: {
30
+ self: vaultId,
31
+ LiquidationCap: liquidationAdminCap,
32
+ coin: depositCoin
33
+ },
33
34
  typeArguments: [coin.type]
34
- });
35
+ }));
35
36
  };
36
37
  this.withdraw = (vaultId, liquidationAdminCap, coinKey, amount) => (tx) => {
37
38
  const coin = this.#config.getCoin(coinKey);
38
- return tx.moveCall({
39
- target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::withdraw`,
40
- arguments: [
41
- tx.object(vaultId),
42
- tx.object(liquidationAdminCap),
43
- tx.pure.u64(convertQuantity(amount, coin.scalar))
44
- ],
39
+ return tx.add(withdraw({
40
+ package: this.#config.LIQUIDATION_PACKAGE_ID,
41
+ arguments: {
42
+ self: vaultId,
43
+ LiquidationCap: liquidationAdminCap,
44
+ amount: convertQuantity(amount, coin.scalar)
45
+ },
45
46
  typeArguments: [coin.type]
46
- });
47
+ }));
47
48
  };
48
49
  this.liquidateBase = (vaultId, managerAddress, poolKey, repayAmount) => (tx) => {
49
50
  const pool = this.#config.getPool(poolKey);
@@ -52,22 +53,21 @@ var MarginLiquidationsContract = class {
52
53
  const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
53
54
  const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
54
55
  const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", convertQuantity(repayAmount, baseCoin.scalar)) : tx.pure.option("u64", null);
55
- tx.moveCall({
56
- target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_base`,
57
- arguments: [
58
- tx.object(vaultId),
59
- tx.object(managerAddress),
60
- tx.object(this.#config.MARGIN_REGISTRY_ID),
61
- tx.object(baseCoin.priceInfoObjectId),
62
- tx.object(quoteCoin.priceInfoObjectId),
63
- tx.object(baseMarginPool.address),
64
- tx.object(quoteMarginPool.address),
65
- tx.object(pool.address),
66
- repayAmountArg,
67
- tx.object.clock()
68
- ],
56
+ tx.add(liquidateBase({
57
+ package: this.#config.LIQUIDATION_PACKAGE_ID,
58
+ arguments: {
59
+ self: vaultId,
60
+ marginManager: managerAddress,
61
+ registry: this.#config.MARGIN_REGISTRY_ID,
62
+ baseOracle: baseCoin.priceInfoObjectId,
63
+ quoteOracle: quoteCoin.priceInfoObjectId,
64
+ baseMarginPool: baseMarginPool.address,
65
+ quoteMarginPool: quoteMarginPool.address,
66
+ pool: pool.address,
67
+ repayAmount: repayAmountArg
68
+ },
69
69
  typeArguments: [baseCoin.type, quoteCoin.type]
70
- });
70
+ }));
71
71
  };
72
72
  this.liquidateQuote = (vaultId, managerAddress, poolKey, repayAmount) => (tx) => {
73
73
  const pool = this.#config.getPool(poolKey);
@@ -76,30 +76,29 @@ var MarginLiquidationsContract = class {
76
76
  const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
77
77
  const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
78
78
  const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", convertQuantity(repayAmount, quoteCoin.scalar)) : tx.pure.option("u64", null);
79
- tx.moveCall({
80
- target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_quote`,
81
- arguments: [
82
- tx.object(vaultId),
83
- tx.object(managerAddress),
84
- tx.object(this.#config.MARGIN_REGISTRY_ID),
85
- tx.object(baseCoin.priceInfoObjectId),
86
- tx.object(quoteCoin.priceInfoObjectId),
87
- tx.object(baseMarginPool.address),
88
- tx.object(quoteMarginPool.address),
89
- tx.object(pool.address),
90
- repayAmountArg,
91
- tx.object.clock()
92
- ],
79
+ tx.add(liquidateQuote({
80
+ package: this.#config.LIQUIDATION_PACKAGE_ID,
81
+ arguments: {
82
+ self: vaultId,
83
+ marginManager: managerAddress,
84
+ registry: this.#config.MARGIN_REGISTRY_ID,
85
+ baseOracle: baseCoin.priceInfoObjectId,
86
+ quoteOracle: quoteCoin.priceInfoObjectId,
87
+ baseMarginPool: baseMarginPool.address,
88
+ quoteMarginPool: quoteMarginPool.address,
89
+ pool: pool.address,
90
+ repayAmount: repayAmountArg
91
+ },
93
92
  typeArguments: [baseCoin.type, quoteCoin.type]
94
- });
93
+ }));
95
94
  };
96
95
  this.balance = (vaultId, coinKey) => (tx) => {
97
96
  const coin = this.#config.getCoin(coinKey);
98
- return tx.moveCall({
99
- target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::balance`,
100
- arguments: [tx.object(vaultId)],
97
+ return tx.add(balance({
98
+ package: this.#config.LIQUIDATION_PACKAGE_ID,
99
+ arguments: { self: vaultId },
101
100
  typeArguments: [coin.type]
102
- });
101
+ }));
103
102
  };
104
103
  this.#config = config;
105
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"marginLiquidations.mjs","names":["#config"],"sources":["../../src/transactions/marginLiquidations.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\nimport { coinWithBalance } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { convertQuantity } from '../utils/conversion.js';\n\n/**\n * MarginLiquidationsContract class for managing LiquidationVault operations.\n */\nexport class MarginLiquidationsContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginLiquidationsContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Create a new liquidation vault\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateLiquidationVault = (liquidationAdminCap: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::create_liquidation_vault`,\n\t\t\targuments: [tx.object(liquidationAdminCap)],\n\t\t});\n\t};\n\n\t/**\n\t * @description Deposit coins into a liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @param {number} amount The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdeposit =\n\t\t(vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositCoin = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: convertQuantity(amount, coin.scalar),\n\t\t\t});\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::deposit`,\n\t\t\t\targuments: [tx.object(vaultId), tx.object(liquidationAdminCap), depositCoin],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Withdraw coins from a liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @param {number} amount The amount to withdraw\n\t * @returns A function that takes a Transaction object and returns the withdrawn coin\n\t */\n\twithdraw =\n\t\t(vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::withdraw`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(vaultId),\n\t\t\t\t\ttx.object(liquidationAdminCap),\n\t\t\t\t\ttx.pure.u64(convertQuantity(amount, coin.scalar)),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Liquidate a margin manager by repaying base debt\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} managerAddress The margin manager address to liquidate\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} [repayAmount] The amount to repay (in base asset units), or undefined for full liquidation\n\t * @returns A function that takes a Transaction object\n\t */\n\tliquidateBase =\n\t\t(vaultId: string, managerAddress: string, poolKey: string, repayAmount?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\n\t\t\tconst repayAmountArg =\n\t\t\t\trepayAmount !== undefined\n\t\t\t\t\t? tx.pure.option('u64', convertQuantity(repayAmount, baseCoin.scalar))\n\t\t\t\t\t: tx.pure.option('u64', null);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_base`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(vaultId),\n\t\t\t\t\ttx.object(managerAddress),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(baseMarginPool.address),\n\t\t\t\t\ttx.object(quoteMarginPool.address),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\trepayAmountArg,\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Liquidate a margin manager by repaying quote debt\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} managerAddress The margin manager address to liquidate\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} [repayAmount] The amount to repay (in quote asset units), or undefined for full liquidation\n\t * @returns A function that takes a Transaction object\n\t */\n\tliquidateQuote =\n\t\t(vaultId: string, managerAddress: string, poolKey: string, repayAmount?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\n\t\t\tconst repayAmountArg =\n\t\t\t\trepayAmount !== undefined\n\t\t\t\t\t? tx.pure.option('u64', convertQuantity(repayAmount, quoteCoin.scalar))\n\t\t\t\t\t: tx.pure.option('u64', null);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_quote`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(vaultId),\n\t\t\t\t\ttx.object(managerAddress),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(baseMarginPool.address),\n\t\t\t\t\ttx.object(quoteMarginPool.address),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\trepayAmountArg,\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t// === Read-Only Functions ===\n\n\t/**\n\t * @description Get the balance of a specific coin type in the liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalance = (vaultId: string, coinKey: string) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::balance`,\n\t\t\targuments: [tx.object(vaultId)],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;;AAWA,IAAa,6BAAb,MAAwC;CACvC;;;;CAKA,YAAY,QAAwB;iCASV,yBAAiC,OAAoB;AAC9E,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,uBAAuB;IAC/C,WAAW,CAAC,GAAG,OAAO,oBAAoB,CAAC;IAC3C,CAAC;;kBAYD,SAAiB,qBAA6B,SAAiB,YAC/D,OAAoB;GACpB,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,cAAc,gBAAgB;IACnC,MAAM,KAAK;IACX,SAAS,gBAAgB,QAAQ,KAAK,OAAO;IAC7C,CAAC;AACF,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,uBAAuB;IAC/C,WAAW;KAAC,GAAG,OAAO,QAAQ;KAAE,GAAG,OAAO,oBAAoB;KAAE;KAAY;IAC5E,eAAe,CAAC,KAAK,KAAK;IAC1B,CAAC;;mBAYF,SAAiB,qBAA6B,SAAiB,YAC/D,OAAoB;GACpB,MAAM,OAAO,MAAKA,OAAQ,QAAQ,Q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;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;GACtD,MAAM,iBAAiB,MAAKA,OAAQ,cAAc,KAAK,SAAS;GAChE,MAAM,kBAAkB,MAAKA,OAAQ,cAAc,KAAK,UAAU;GAElE,MAAM,iBACL,gBAAgB,SACb,GAAG,KAAK,OAAO,OAAO,gBAAgB,aAAa,UAAU,OAAO,CAAC,GACrE,GAAG,KAAK,OAAO,OAAO,KAAK;AAE/B,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,uBAAuB;IAC/C,WAAW;KACV,GAAG,OAAO,QAAQ;KAClB,GAAG,OAAO,eAAe;KACzB,GAAG,OAAO,MAAKA,OAAQ,mBAAmB;KAC1C,GAAG,OAAO,SAAS,kBAAmB;KACtC,GAAG,OAAO,UAAU,kBAAmB;KACvC,GAAG,OAAO,eAAe,QAAQ;KACjC,GAAG,OAAO,gBAAgB,QAAQ;KAClC,GAAG,OAAO,KAAK,QAAQ;KACvB;KACA,GAAG,OAAO,OAAO;KACjB;IACD,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;kBAWO,SAAiB,aAAqB,OAAoB;GACpE,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;AAC1C,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,uBAAuB;IAC/C,WAAW,CAAC,GAAG,OAAO,QAAQ,CAAC;IAC/B,eAAe,CAAC,KAAK,KAAK;IAC1B,CAAC;;AA3JF,QAAKA,SAAU"}
1
+ {"version":3,"file":"marginLiquidations.mjs","names":["liquidationVaultMoveCalls.createLiquidationVault","#config","liquidationVaultMoveCalls.deposit","liquidationVaultMoveCalls.withdraw","liquidationVaultMoveCalls.liquidateBase","liquidationVaultMoveCalls.liquidateQuote","liquidationVaultMoveCalls.balance"],"sources":["../../src/transactions/marginLiquidations.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\nimport { coinWithBalance } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { convertQuantity } from '../utils/conversion.js';\nimport * as liquidationVaultMoveCalls from '../contracts/margin_liquidation/liquidation_vault.js';\n\n/**\n * MarginLiquidationsContract class for managing LiquidationVault operations.\n */\nexport class MarginLiquidationsContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginLiquidationsContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Create a new liquidation vault\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateLiquidationVault = (liquidationAdminCap: string) => (tx: Transaction) => {\n\t\ttx.add(\n\t\t\tliquidationVaultMoveCalls.createLiquidationVault({\n\t\t\t\tpackage: this.#config.LIQUIDATION_PACKAGE_ID,\n\t\t\t\targuments: { LiquidationCap: liquidationAdminCap },\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Deposit coins into a liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @param {number} amount The amount to deposit\n\t * @returns A function that takes a Transaction object\n\t */\n\tdeposit =\n\t\t(vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst depositCoin = coinWithBalance({\n\t\t\t\ttype: coin.type,\n\t\t\t\tbalance: convertQuantity(amount, coin.scalar),\n\t\t\t});\n\t\t\ttx.add(\n\t\t\t\tliquidationVaultMoveCalls.deposit({\n\t\t\t\t\tpackage: this.#config.LIQUIDATION_PACKAGE_ID,\n\t\t\t\t\targuments: { self: vaultId, LiquidationCap: liquidationAdminCap, coin: depositCoin },\n\t\t\t\t\ttypeArguments: [coin.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Withdraw coins from a liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} liquidationAdminCap The liquidation admin cap object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @param {number} amount The amount to withdraw\n\t * @returns A function that takes a Transaction object and returns the withdrawn coin\n\t */\n\twithdraw =\n\t\t(vaultId: string, liquidationAdminCap: string, coinKey: string, amount: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\treturn tx.add(\n\t\t\t\tliquidationVaultMoveCalls.withdraw({\n\t\t\t\t\tpackage: this.#config.LIQUIDATION_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tself: vaultId,\n\t\t\t\t\t\tLiquidationCap: liquidationAdminCap,\n\t\t\t\t\t\tamount: convertQuantity(amount, coin.scalar),\n\t\t\t\t\t},\n\t\t\t\t\ttypeArguments: [coin.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Liquidate a margin manager by repaying base debt\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} managerAddress The margin manager address to liquidate\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} [repayAmount] The amount to repay (in base asset units), or undefined for full liquidation\n\t * @returns A function that takes a Transaction object\n\t */\n\tliquidateBase =\n\t\t(vaultId: string, managerAddress: string, poolKey: string, repayAmount?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\n\t\t\t// Build the Option arg first so its pure input registers ahead of the\n\t\t\t// object inputs (matches the original positional ordering — byte-identical).\n\t\t\tconst repayAmountArg =\n\t\t\t\trepayAmount !== undefined\n\t\t\t\t\t? tx.pure.option('u64', convertQuantity(repayAmount, baseCoin.scalar))\n\t\t\t\t\t: tx.pure.option('u64', null);\n\n\t\t\ttx.add(\n\t\t\t\tliquidationVaultMoveCalls.liquidateBase({\n\t\t\t\t\tpackage: this.#config.LIQUIDATION_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tself: vaultId,\n\t\t\t\t\t\tmarginManager: managerAddress,\n\t\t\t\t\t\tregistry: this.#config.MARGIN_REGISTRY_ID,\n\t\t\t\t\t\tbaseOracle: baseCoin.priceInfoObjectId!,\n\t\t\t\t\t\tquoteOracle: quoteCoin.priceInfoObjectId!,\n\t\t\t\t\t\tbaseMarginPool: baseMarginPool.address,\n\t\t\t\t\t\tquoteMarginPool: quoteMarginPool.address,\n\t\t\t\t\t\tpool: pool.address,\n\t\t\t\t\t\trepayAmount: repayAmountArg,\n\t\t\t\t\t},\n\t\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Liquidate a margin manager by repaying quote debt\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} managerAddress The margin manager address to liquidate\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} [repayAmount] The amount to repay (in quote asset units), or undefined for full liquidation\n\t * @returns A function that takes a Transaction object\n\t */\n\tliquidateQuote =\n\t\t(vaultId: string, managerAddress: string, poolKey: string, repayAmount?: number) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\n\t\t\t// Build the Option arg first so its pure input registers ahead of the\n\t\t\t// object inputs (matches the original positional ordering — byte-identical).\n\t\t\tconst repayAmountArg =\n\t\t\t\trepayAmount !== undefined\n\t\t\t\t\t? tx.pure.option('u64', convertQuantity(repayAmount, quoteCoin.scalar))\n\t\t\t\t\t: tx.pure.option('u64', null);\n\n\t\t\ttx.add(\n\t\t\t\tliquidationVaultMoveCalls.liquidateQuote({\n\t\t\t\t\tpackage: this.#config.LIQUIDATION_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tself: vaultId,\n\t\t\t\t\t\tmarginManager: managerAddress,\n\t\t\t\t\t\tregistry: this.#config.MARGIN_REGISTRY_ID,\n\t\t\t\t\t\tbaseOracle: baseCoin.priceInfoObjectId!,\n\t\t\t\t\t\tquoteOracle: quoteCoin.priceInfoObjectId!,\n\t\t\t\t\t\tbaseMarginPool: baseMarginPool.address,\n\t\t\t\t\t\tquoteMarginPool: quoteMarginPool.address,\n\t\t\t\t\t\tpool: pool.address,\n\t\t\t\t\t\trepayAmount: repayAmountArg,\n\t\t\t\t\t},\n\t\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t// === Read-Only Functions ===\n\n\t/**\n\t * @description Get the balance of a specific coin type in the liquidation vault\n\t * @param {string} vaultId The liquidation vault object ID\n\t * @param {string} coinKey The key to identify the coin type\n\t * @returns A function that takes a Transaction object\n\t */\n\tbalance = (vaultId: string, coinKey: string) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\treturn tx.add(\n\t\t\tliquidationVaultMoveCalls.balance({\n\t\t\t\tpackage: this.#config.LIQUIDATION_PACKAGE_ID,\n\t\t\t\targuments: { self: vaultId },\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t}),\n\t\t);\n\t};\n}\n"],"mappings":";;;;;;;;AAYA,IAAa,6BAAb,MAAwC;CACvC;;;;CAKA,YAAY,QAAwB;iCASV,yBAAiC,OAAoB;AAC9E,MAAG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2
  import { DeepBookConfig } from "../utils/config.mjs";
3
- import * as _mysten_sui_transactions46 from "@mysten/sui/transactions";
3
+ import * as _mysten_sui_transactions38 from "@mysten/sui/transactions";
4
4
  import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
5
5
 
6
6
  //#region src/transactions/marginMaintainer.d.ts
@@ -27,27 +27,27 @@ declare class MarginMaintainerContract {
27
27
  * @param {InterestConfigParams} interestConfig The configuration for the interest
28
28
  * @returns A function that takes a Transaction object
29
29
  */
30
- newProtocolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams, interestConfig: InterestConfigParams) => (tx: Transaction) => _mysten_sui_transactions46.TransactionResult;
30
+ newProtocolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams, interestConfig: InterestConfigParams) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
31
31
  /**
32
32
  * @description Create a new margin pool config
33
33
  * @param {string} coinKey The key to identify the coin
34
34
  * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool
35
35
  * @returns A function that takes a Transaction object
36
36
  */
37
- newMarginPoolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions46.TransactionResult;
37
+ newMarginPoolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
38
38
  /**
39
39
  * @description Create a new margin pool config with rate limit
40
40
  * @param {string} coinKey The key to identify the coin
41
41
  * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit
42
42
  * @returns A function that takes a Transaction object
43
43
  */
44
- newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: Required<Pick<MarginPoolConfigParams, "rateLimitCapacity" | "rateLimitRefillRatePerMs" | "rateLimitEnabled">> & MarginPoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions46.TransactionResult;
44
+ newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: Required<Pick<MarginPoolConfigParams, "rateLimitCapacity" | "rateLimitRefillRatePerMs" | "rateLimitEnabled">> & MarginPoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
45
45
  /**
46
46
  * @description Create a new interest config
47
47
  * @param {InterestConfigParams} interestConfig The configuration for the interest
48
48
  * @returns A function that takes a Transaction object
49
49
  */
50
- newInterestConfig: (interestConfig: InterestConfigParams) => (tx: Transaction) => _mysten_sui_transactions46.TransactionResult;
50
+ newInterestConfig: (interestConfig: InterestConfigParams) => (tx: Transaction) => _mysten_sui_transactions38.TransactionResult;
51
51
  /**
52
52
  * @description Enable a deepbook pool for loan
53
53
  * @param {string} deepbookPoolKey The key to identify the deepbook pool
@@ -1 +1 @@
1
- {"version":3,"file":"marginMaintainer.d.mts","names":[],"sources":["../../src/transactions/marginMaintainer.ts"],"mappings":";;;;;;;;;cAiBa,wBAAA;EAAA;;;;cAMA,MAAA,EAAQ,cAAA;EA8CA;;;;;;EAxBpB,gBAAA,GAAoB,OAAA,UAAiB,UAAA,EAAY,mBAAA,MAAyB,EAAA,EAAI,WAAA;EA+E1E;;;;;;;EA1DJ,iBAAA,GAEE,OAAA,UACA,gBAAA,EAAkB,sBAAA,EAClB,cAAA,EAAgB,oBAAA,MAEhB,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;EAwF6D;;;;;;EA9D9E,mBAAA,GACE,OAAA,UAAiB,gBAAA,EAAkB,sBAAA,MAA4B,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;EAyI1E;;;;;;EArHN,gCAAA,GAEE,OAAA,UACA,gBAAA,EAAkB,QAAA,CACjB,IAAA,CACC,sBAAA,4EAID,sBAAA,MAED,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;;;;;;EA8BjB,iBAAA,GAAqB,cAAA,EAAgB,oBAAA,MAA0B,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;EAnHzC;;;;;;;EAuIrC,y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A,UAAiB,aAAA,EAAe,yBAAA,MACzD,EAAA,EAAI,WAAA;EA3HJ;;;;;;;EAmJF,0BAAA,GACE,eAAA,UAAyB,OAAA,UAAiB,aAAA,EAAe,yBAAA,MACzD,EAAA,EAAI,WAAA;EAnH+D;;;;;;;EA2IrE,oBAAA,GAEE,OAAA,UACA,aAAA,EAAe,yBAAA,EACf,cAAA,EAAgB,oBAAA,MAEhB,EAAA,EAAI,WAAA;EAlHH;;;;;;;EA0IH,sBAAA,GAEE,OAAA,UACA,aAAA,EAAe,yBAAA,EACf,gBAAA,EAAkB,sBAAA,MAElB,EAAA,EAAI,WAAA;AAAA"}
@@ -1,5 +1,7 @@
1
1
  import { convertQuantity, convertRate } from "../utils/conversion.mjs";
2
2
  import { FLOAT_SCALAR } from "../utils/config.mjs";
3
+ import { newInterestConfig, newMarginPoolConfig, newMarginPoolConfigWithRateLimit, newProtocolConfig } from "../contracts/deepbook_margin/protocol_config.mjs";
4
+ import { createMarginPool, disableDeepbookPoolForLoan, enableDeepbookPoolForLoan, updateInterestParams, updateMarginPoolConfig } from "../contracts/deepbook_margin/margin_pool.mjs";
3
5
 
4
6
  //#region src/transactions/marginMaintainer.ts
5
7
  /**
@@ -13,16 +15,15 @@ var MarginMaintainerContract = class {
13
15
  constructor(config) {
14
16
  this.createMarginPool = (coinKey, poolConfig) => (tx) => {
15
17
  const coin = this.#config.getCoin(coinKey);
16
- tx.moveCall({
17
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::create_margin_pool`,
18
- arguments: [
19
- tx.object(this.#config.MARGIN_REGISTRY_ID),
20
- poolConfig,
21
- tx.object(this.#marginMaintainerCap()),
22
- tx.object.clock()
23
- ],
18
+ tx.add(createMarginPool({
19
+ package: this.#config.MARGIN_PACKAGE_ID,
20
+ arguments: {
21
+ registry: this.#config.MARGIN_REGISTRY_ID,
22
+ config: poolConfig,
23
+ maintainerCap: this.#marginMaintainerCap()
24
+ },
24
25
  typeArguments: [coin.type]
25
- });
26
+ }));
26
27
  };
27
28
  this.newProtocolConfig = (coinKey, marginPoolConfig, interestConfig) => (tx) => {
28
29
  const marginPoolConfigObject = marginPoolConfig.rateLimitCapacity !== void 0 && marginPoolConfig.rateLimitRefillRatePerMs !== void 0 && marginPoolConfig.rateLimitEnabled !== void 0 ? this.newMarginPoolConfigWithRateLimit(coinKey, {
@@ -32,96 +33,96 @@ var MarginMaintainerContract = class {
32
33
  rateLimitEnabled: marginPoolConfig.rateLimitEnabled
33
34
  })(tx) : this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
34
35
  const interestConfigObject = this.newInterestConfig(interestConfig)(tx);
35
- return tx.moveCall({
36
- target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,
37
- arguments: [marginPoolConfigObject, interestConfigObject]
38
- });
36
+ return tx.add(newProtocolConfig({
37
+ package: this.#config.MARGIN_PACKAGE_ID,
38
+ arguments: {
39
+ marginPoolConfig: marginPoolConfigObject,
40
+ interestConfig: interestConfigObject
41
+ }
42
+ }));
39
43
  };
40
44
  this.newMarginPoolConfig = (coinKey, marginPoolConfig) => (tx) => {
41
45
  const coin = this.#config.getCoin(coinKey);
42
46
  const { supplyCap, maxUtilizationRate, protocolSpread, minBorrow } = marginPoolConfig;
43
- return tx.moveCall({
44
- target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,
45
- arguments: [
46
- tx.pure.u64(convertQuantity(supplyCap, coin.scalar)),
47
- tx.pure.u64(convertRate(maxUtilizationRate, FLOAT_SCALAR)),
48
- tx.pure.u64(convertRate(protocolSpread, FLOAT_SCALAR)),
49
- tx.pure.u64(convertQuantity(minBorrow, coin.scalar))
50
- ]
51
- });
47
+ return tx.add(newMarginPoolConfig({
48
+ package: this.#config.MARGIN_PACKAGE_ID,
49
+ arguments: {
50
+ supplyCap: convertQuantity(supplyCap, coin.scalar),
51
+ maxUtilizationRate: convertRate(maxUtilizationRate, FLOAT_SCALAR),
52
+ protocolSpread: convertRate(protocolSpread, FLOAT_SCALAR),
53
+ minBorrow: convertQuantity(minBorrow, coin.scalar)
54
+ }
55
+ }));
52
56
  };
53
57
  this.newMarginPoolConfigWithRateLimit = (coinKey, marginPoolConfig) => (tx) => {
54
58
  const coin = this.#config.getCoin(coinKey);
55
59
  const { supplyCap, maxUtilizationRate, protocolSpread, minBorrow, rateLimitCapacity, rateLimitRefillRatePerMs, rateLimitEnabled } = marginPoolConfig;
56
- return tx.moveCall({
57
- target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,
58
- arguments: [
59
- tx.pure.u64(convertQuantity(supplyCap, coin.scalar)),
60
- tx.pure.u64(convertRate(maxUtilizationRate, FLOAT_SCALAR)),
61
- tx.pure.u64(convertRate(protocolSpread, FLOAT_SCALAR)),
62
- tx.pure.u64(convertQuantity(minBorrow, coin.scalar)),
63
- tx.pure.u64(convertQuantity(rateLimitCapacity, coin.scalar)),
64
- tx.pure.u64(convertQuantity(rateLimitRefillRatePerMs, coin.scalar)),
65
- tx.pure.bool(rateLimitEnabled)
66
- ]
67
- });
60
+ return tx.add(newMarginPoolConfigWithRateLimit({
61
+ package: this.#config.MARGIN_PACKAGE_ID,
62
+ arguments: {
63
+ supplyCap: convertQuantity(supplyCap, coin.scalar),
64
+ maxUtilizationRate: convertRate(maxUtilizationRate, FLOAT_SCALAR),
65
+ protocolSpread: convertRate(protocolSpread, FLOAT_SCALAR),
66
+ minBorrow: convertQuantity(minBorrow, coin.scalar),
67
+ rateLimitCapacity: convertQuantity(rateLimitCapacity, coin.scalar),
68
+ rateLimitRefillRatePerMs: convertQuantity(rateLimitRefillRatePerMs, coin.scalar),
69
+ rateLimitEnabled
70
+ }
71
+ }));
68
72
  };
69
73
  this.newInterestConfig = (interestConfig) => (tx) => {
70
74
  const { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;
71
- return tx.moveCall({
72
- target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,
73
- arguments: [
74
- tx.pure.u64(convertRate(baseRate, FLOAT_SCALAR)),
75
- tx.pure.u64(convertRate(baseSlope, FLOAT_SCALAR)),
76
- tx.pure.u64(convertRate(optimalUtilization, FLOAT_SCALAR)),
77
- tx.pure.u64(convertRate(excessSlope, FLOAT_SCALAR))
78
- ]
79
- });
75
+ return tx.add(newInterestConfig({
76
+ package: this.#config.MARGIN_PACKAGE_ID,
77
+ arguments: {
78
+ baseRate: convertRate(baseRate, FLOAT_SCALAR),
79
+ baseSlope: convertRate(baseSlope, FLOAT_SCALAR),
80
+ optimalUtilization: convertRate(optimalUtilization, FLOAT_SCALAR),
81
+ excessSlope: convertRate(excessSlope, FLOAT_SCALAR)
82
+ }
83
+ }));
80
84
  };
81
85
  this.enableDeepbookPoolForLoan = (deepbookPoolKey, coinKey, marginPoolCap) => (tx) => {
82
86
  const deepbookPool = this.#config.getPool(deepbookPoolKey);
83
87
  const marginPool = this.#config.getMarginPool(coinKey);
84
- tx.moveCall({
85
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::enable_deepbook_pool_for_loan`,
86
- arguments: [
87
- tx.object(marginPool.address),
88
- tx.object(this.#config.MARGIN_REGISTRY_ID),
89
- tx.pure.id(deepbookPool.address),
90
- tx.object(marginPoolCap),
91
- tx.object.clock()
92
- ],
88
+ tx.add(enableDeepbookPoolForLoan({
89
+ package: this.#config.MARGIN_PACKAGE_ID,
90
+ arguments: {
91
+ self: marginPool.address,
92
+ registry: this.#config.MARGIN_REGISTRY_ID,
93
+ deepbookPoolId: deepbookPool.address,
94
+ marginPoolCap
95
+ },
93
96
  typeArguments: [marginPool.type]
94
- });
97
+ }));
95
98
  };
96
99
  this.disableDeepbookPoolForLoan = (deepbookPoolKey, coinKey, marginPoolCap) => (tx) => {
97
100
  const deepbookPool = this.#config.getPool(deepbookPoolKey);
98
101
  const marginPool = this.#config.getMarginPool(coinKey);
99
- tx.moveCall({
100
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::disable_deepbook_pool_for_loan`,
101
- arguments: [
102
- tx.object(marginPool.address),
103
- tx.object(this.#config.MARGIN_REGISTRY_ID),
104
- tx.pure.id(deepbookPool.address),
105
- tx.object(marginPoolCap),
106
- tx.object.clock()
107
- ],
102
+ tx.add(disableDeepbookPoolForLoan({
103
+ package: this.#config.MARGIN_PACKAGE_ID,
104
+ arguments: {
105
+ self: marginPool.address,
106
+ registry: this.#config.MARGIN_REGISTRY_ID,
107
+ deepbookPoolId: deepbookPool.address,
108
+ marginPoolCap
109
+ },
108
110
  typeArguments: [marginPool.type]
109
- });
111
+ }));
110
112
  };
111
113
  this.updateInterestParams = (coinKey, marginPoolCap, interestConfig) => (tx) => {
112
114
  const marginPool = this.#config.getMarginPool(coinKey);
113
115
  const interestConfigObject = this.newInterestConfig(interestConfig)(tx);
114
- tx.moveCall({
115
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_interest_params`,
116
- arguments: [
117
- tx.object(marginPool.address),
118
- tx.object(this.#config.MARGIN_REGISTRY_ID),
119
- interestConfigObject,
120
- tx.object(marginPoolCap),
121
- tx.object.clock()
122
- ],
116
+ tx.add(updateInterestParams({
117
+ package: this.#config.MARGIN_PACKAGE_ID,
118
+ arguments: {
119
+ self: marginPool.address,
120
+ registry: this.#config.MARGIN_REGISTRY_ID,
121
+ interestConfig: interestConfigObject,
122
+ marginPoolCap
123
+ },
123
124
  typeArguments: [marginPool.type]
124
- });
125
+ }));
125
126
  };
126
127
  this.updateMarginPoolConfig = (coinKey, marginPoolCap, marginPoolConfig) => (tx) => {
127
128
  const marginPool = this.#config.getMarginPool(coinKey);
@@ -131,17 +132,16 @@ var MarginMaintainerContract = class {
131
132
  rateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs,
132
133
  rateLimitEnabled: marginPoolConfig.rateLimitEnabled
133
134
  })(tx) : this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);
134
- tx.moveCall({
135
- target: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,
136
- arguments: [
137
- tx.object(marginPool.address),
138
- tx.object(this.#config.MARGIN_REGISTRY_ID),
139
- marginPoolConfigObject,
140
- tx.object(marginPoolCap),
141
- tx.object.clock()
142
- ],
135
+ tx.add(updateMarginPoolConfig({
136
+ package: this.#config.MARGIN_PACKAGE_ID,
137
+ arguments: {
138
+ self: marginPool.address,
139
+ registry: this.#config.MARGIN_REGISTRY_ID,
140
+ marginPoolConfig: marginPoolConfigObject,
141
+ marginPoolCap
142
+ },
143
143
  typeArguments: [marginPool.type]
144
- });
144
+ }));
145
145
  };
146
146
  this.#config = config;
147
147
  }
@@ -1 +1 @@
1
- {"version":3,"file":"marginMaintainer.mjs","names":["#config","#marginMaintainerCap"],"sources":["../../src/transactions/marginMaintainer.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransaction,\n\tTransactionArgument,\n\tTransactionObjectArgument,\n} from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\nimport { convertQuantity, convertRate } from '../utils/conversion.js';\n\n/**\n * DeepBookMaintainerContract class for managing maintainer actions.\n */\nexport class MarginMaintainerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginMaintainerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#marginMaintainerCap() {\n\t\tconst marginMaintainerCap = this.#config.marginMaintainerCap;\n\t\tif (!marginMaintainerCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginMaintainerCap;\n\t}\n\n\t/**\n\t * @description Create a new margin pool\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {TransactionArgument} poolConfig The configuration for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateMarginPool = (coinKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::create_margin_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object(this.#marginMaintainerCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new protocol config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewProtocolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst hasRateLimit =\n\t\t\t\tmarginPoolConfig.rateLimitCapacity !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitRefillRatePerMs !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitEnabled !== undefined;\n\t\t\tconst marginPoolConfigObject = hasRateLimit\n\t\t\t\t? this.newMarginPoolConfigWithRateLimit(coinKey, {\n\t\t\t\t\t\t...marginPoolConfig,\n\t\t\t\t\t\trateLimitCapacity: marginPoolConfig.rateLimitCapacity!,\n\t\t\t\t\t\trateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs!,\n\t\t\t\t\t\trateLimitEnabled: marginPoolConfig.rateLimitEnabled!,\n\t\t\t\t\t})(tx)\n\t\t\t\t: this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_protocol_config`,\n\t\t\t\targuments: [marginPoolConfigObject, interestConfigObject],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfig =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst { supplyCap, maxUtilizationRate, protocolSpread, minBorrow } = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(convertQuantity(supplyCap, coin.scalar)),\n\t\t\t\t\ttx.pure.u64(convertRate(maxUtilizationRate, FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(convertRate(protocolSpread, FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(convertQuantity(minBorrow, coin.scalar)),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config with rate limit\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfigWithRateLimit =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: Required<\n\t\t\t\tPick<\n\t\t\t\t\tMarginPoolConfigParams,\n\t\t\t\t\t'rateLimitCapacity' | 'rateLimitRefillRatePerMs' | 'rateLimitEnabled'\n\t\t\t\t>\n\t\t\t> &\n\t\t\t\tMarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst {\n\t\t\t\tsupplyCap,\n\t\t\t\tmaxUtilizationRate,\n\t\t\t\tprotocolSpread,\n\t\t\t\tminBorrow,\n\t\t\t\trateLimitCapacity,\n\t\t\t\trateLimitRefillRatePerMs,\n\t\t\t\trateLimitEnabled,\n\t\t\t} = marginPoolConfig;\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(convertQuantity(supplyCap, coin.scalar)),\n\t\t\t\t\ttx.pure.u64(convertRate(maxUtilizationRate, FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(convertRate(protocolSpread, FLOAT_SCALAR)),\n\t\t\t\t\ttx.pure.u64(convertQuantity(minBorrow, coin.scalar)),\n\t\t\t\t\ttx.pure.u64(convertQuantity(rateLimitCapacity, coin.scalar)),\n\t\t\t\t\ttx.pure.u64(convertQuantity(rateLimitRefillRatePerMs, coin.scalar)),\n\t\t\t\t\ttx.pure.bool(rateLimitEnabled),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new interest config\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewInterestConfig = (interestConfig: InterestConfigParams) => (tx: Transaction) => {\n\t\tconst { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,\n\t\t\targuments: [\n\t\t\t\ttx.pure.u64(convertRate(baseRate, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(baseSlope, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(optimalUtilization, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(excessSlope, FLOAT_SCALAR)),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::enable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Disable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::disable_deepbook_pool_for_loan`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.id(deepbookPool.address),\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the interest params\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateInterestParams =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_interest_params`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tinterestConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Update the margin pool config\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateMarginPoolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst hasRateLimit =\n\t\t\t\tmarginPoolConfig.rateLimitCapacity !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitRefillRatePerMs !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitEnabled !== undefined;\n\t\t\tconst marginPoolConfigObject = hasRateLimit\n\t\t\t\t? this.newMarginPoolConfigWithRateLimit(coinKey, {\n\t\t\t\t\t\t...marginPoolConfig,\n\t\t\t\t\t\trateLimitCapacity: marginPoolConfig.rateLimitCapacity!,\n\t\t\t\t\t\trateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs!,\n\t\t\t\t\t\trateLimitEnabled: marginPoolConfig.rateLimitEnabled!,\n\t\t\t\t\t})(tx)\n\t\t\t\t: this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::update_margin_pool_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(marginPool.address),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\tmarginPoolConfigObject,\n\t\t\t\t\ttx.object(marginPoolCap),\n\t\t\t\t\ttx.object.clock(),\n\t\t\t\t],\n\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t});\n\t\t};\n}\n"],"mappings":";;;;;;;AAiBA,IAAa,2BAAb,MAAsC;CACrC;;;;CAKA,YAAY,QAAwB;2BAsBhB,SAAiB,gBAAqC,OAAoB;GAC7F,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;AAC1C,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW;KACV,GAAG,OAAO,MAAKA,OAAQ,mBAAmB;KAC1C;KACA,GAAG,OAAO,MAAKC,qBAAsB,CAAC;KACtC,GAAG,OAAO,OAAO;KACjB;IACD,eAAe,CAAC,KA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;;;;;CAOhB,uBAAuB;EACtB,MAAM,sBAAsB,MAAKA,OAAQ;AACzC,MAAI,CAAC,oBACJ,OAAM,IAAI,MAAM,gDAAgD;AAEjE,SAAO"}
1
+ {"version":3,"file":"marginMaintainer.mjs","names":["#config","marginPoolMoveCalls.createMarginPool","#marginMaintainerCap","protocolConfigMoveCalls.newProtocolConfig","protocolConfigMoveCalls.newMarginPoolConfig","protocolConfigMoveCalls.newMarginPoolConfigWithRateLimit","protocolConfigMoveCalls.newInterestConfig","marginPoolMoveCalls.enableDeepbookPoolForLoan","marginPoolMoveCalls.disableDeepbookPoolForLoan","marginPoolMoveCalls.updateInterestParams","marginPoolMoveCalls.updateMarginPoolConfig"],"sources":["../../src/transactions/marginMaintainer.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tTransaction,\n\tTransactionArgument,\n\tTransactionObjectArgument,\n} from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type { MarginPoolConfigParams, InterestConfigParams } from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\nimport { convertQuantity, convertRate } from '../utils/conversion.js';\nimport * as marginPoolMoveCalls from '../contracts/deepbook_margin/margin_pool.js';\nimport * as protocolConfigMoveCalls from '../contracts/deepbook_margin/protocol_config.js';\n\n/**\n * DeepBookMaintainerContract class for managing maintainer actions.\n */\nexport class MarginMaintainerContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginMaintainerContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @returns The admin capability required for admin operations\n\t * @throws Error if the admin capability is not set\n\t */\n\t#marginMaintainerCap() {\n\t\tconst marginMaintainerCap = this.#config.marginMaintainerCap;\n\t\tif (!marginMaintainerCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginMaintainerCap;\n\t}\n\n\t/**\n\t * @description Create a new margin pool\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {TransactionArgument} poolConfig The configuration for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tcreateMarginPool = (coinKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\ttx.add(\n\t\t\tmarginPoolMoveCalls.createMarginPool({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: {\n\t\t\t\t\tregistry: this.#config.MARGIN_REGISTRY_ID,\n\t\t\t\t\tconfig: poolConfig,\n\t\t\t\t\tmaintainerCap: this.#marginMaintainerCap(),\n\t\t\t\t},\n\t\t\t\ttypeArguments: [coin.type],\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Create a new protocol config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewProtocolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst hasRateLimit =\n\t\t\t\tmarginPoolConfig.rateLimitCapacity !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitRefillRatePerMs !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitEnabled !== undefined;\n\t\t\tconst marginPoolConfigObject = hasRateLimit\n\t\t\t\t? this.newMarginPoolConfigWithRateLimit(coinKey, {\n\t\t\t\t\t\t...marginPoolConfig,\n\t\t\t\t\t\trateLimitCapacity: marginPoolConfig.rateLimitCapacity!,\n\t\t\t\t\t\trateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs!,\n\t\t\t\t\t\trateLimitEnabled: marginPoolConfig.rateLimitEnabled!,\n\t\t\t\t\t})(tx)\n\t\t\t\t: this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\treturn tx.add(\n\t\t\t\tprotocolConfigMoveCalls.newProtocolConfig({\n\t\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tmarginPoolConfig: marginPoolConfigObject,\n\t\t\t\t\t\tinterestConfig: interestConfigObject,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfig =\n\t\t(coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst { supplyCap, maxUtilizationRate, protocolSpread, minBorrow } = marginPoolConfig;\n\t\t\treturn tx.add(\n\t\t\t\tprotocolConfigMoveCalls.newMarginPoolConfig({\n\t\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tsupplyCap: convertQuantity(supplyCap, coin.scalar),\n\t\t\t\t\t\tmaxUtilizationRate: convertRate(maxUtilizationRate, FLOAT_SCALAR),\n\t\t\t\t\t\tprotocolSpread: convertRate(protocolSpread, FLOAT_SCALAR),\n\t\t\t\t\t\tminBorrow: convertQuantity(minBorrow, coin.scalar),\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Create a new margin pool config with rate limit\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool with rate limit\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewMarginPoolConfigWithRateLimit =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolConfig: Required<\n\t\t\t\tPick<\n\t\t\t\t\tMarginPoolConfigParams,\n\t\t\t\t\t'rateLimitCapacity' | 'rateLimitRefillRatePerMs' | 'rateLimitEnabled'\n\t\t\t\t>\n\t\t\t> &\n\t\t\t\tMarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tconst {\n\t\t\t\tsupplyCap,\n\t\t\t\tmaxUtilizationRate,\n\t\t\t\tprotocolSpread,\n\t\t\t\tminBorrow,\n\t\t\t\trateLimitCapacity,\n\t\t\t\trateLimitRefillRatePerMs,\n\t\t\t\trateLimitEnabled,\n\t\t\t} = marginPoolConfig;\n\t\t\treturn tx.add(\n\t\t\t\tprotocolConfigMoveCalls.newMarginPoolConfigWithRateLimit({\n\t\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tsupplyCap: convertQuantity(supplyCap, coin.scalar),\n\t\t\t\t\t\tmaxUtilizationRate: convertRate(maxUtilizationRate, FLOAT_SCALAR),\n\t\t\t\t\t\tprotocolSpread: convertRate(protocolSpread, FLOAT_SCALAR),\n\t\t\t\t\t\tminBorrow: convertQuantity(minBorrow, coin.scalar),\n\t\t\t\t\t\trateLimitCapacity: convertQuantity(rateLimitCapacity, coin.scalar),\n\t\t\t\t\t\trateLimitRefillRatePerMs: convertQuantity(rateLimitRefillRatePerMs, coin.scalar),\n\t\t\t\t\t\trateLimitEnabled,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Create a new interest config\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewInterestConfig = (interestConfig: InterestConfigParams) => (tx: Transaction) => {\n\t\tconst { baseRate, baseSlope, optimalUtilization, excessSlope } = interestConfig;\n\t\treturn tx.add(\n\t\t\tprotocolConfigMoveCalls.newInterestConfig({\n\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\targuments: {\n\t\t\t\t\tbaseRate: convertRate(baseRate, FLOAT_SCALAR),\n\t\t\t\t\tbaseSlope: convertRate(baseSlope, FLOAT_SCALAR),\n\t\t\t\t\toptimalUtilization: convertRate(optimalUtilization, FLOAT_SCALAR),\n\t\t\t\t\texcessSlope: convertRate(excessSlope, FLOAT_SCALAR),\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t};\n\n\t/**\n\t * @description Enable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.add(\n\t\t\t\tmarginPoolMoveCalls.enableDeepbookPoolForLoan({\n\t\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tself: marginPool.address,\n\t\t\t\t\t\tregistry: this.#config.MARGIN_REGISTRY_ID,\n\t\t\t\t\t\tdeepbookPoolId: deepbookPool.address,\n\t\t\t\t\t\tmarginPoolCap,\n\t\t\t\t\t},\n\t\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Disable a deepbook pool for loan\n\t * @param {string} deepbookPoolKey The key to identify the deepbook pool\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPoolForLoan =\n\t\t(deepbookPoolKey: string, coinKey: string, marginPoolCap: TransactionObjectArgument) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst deepbookPool = this.#config.getPool(deepbookPoolKey);\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\ttx.add(\n\t\t\t\tmarginPoolMoveCalls.disableDeepbookPoolForLoan({\n\t\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tself: marginPool.address,\n\t\t\t\t\t\tregistry: this.#config.MARGIN_REGISTRY_ID,\n\t\t\t\t\t\tdeepbookPoolId: deepbookPool.address,\n\t\t\t\t\t\tmarginPoolCap,\n\t\t\t\t\t},\n\t\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Update the interest params\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {InterestConfigParams} interestConfig The configuration for the interest\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateInterestParams =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tinterestConfig: InterestConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst interestConfigObject = this.newInterestConfig(interestConfig)(tx);\n\t\t\ttx.add(\n\t\t\t\tmarginPoolMoveCalls.updateInterestParams({\n\t\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tself: marginPool.address,\n\t\t\t\t\t\tregistry: this.#config.MARGIN_REGISTRY_ID,\n\t\t\t\t\t\tinterestConfig: interestConfigObject,\n\t\t\t\t\t\tmarginPoolCap,\n\t\t\t\t\t},\n\t\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\n\t/**\n\t * @description Update the margin pool config\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @param {TransactionObjectArgument} marginPoolCap The margin pool cap\n\t * @param {MarginPoolConfigParams} marginPoolConfig The configuration for the margin pool (with optional rate limit)\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateMarginPoolConfig =\n\t\t(\n\t\t\tcoinKey: string,\n\t\t\tmarginPoolCap: TransactionObjectArgument,\n\t\t\tmarginPoolConfig: MarginPoolConfigParams,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\t\tconst hasRateLimit =\n\t\t\t\tmarginPoolConfig.rateLimitCapacity !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitRefillRatePerMs !== undefined &&\n\t\t\t\tmarginPoolConfig.rateLimitEnabled !== undefined;\n\t\t\tconst marginPoolConfigObject = hasRateLimit\n\t\t\t\t? this.newMarginPoolConfigWithRateLimit(coinKey, {\n\t\t\t\t\t\t...marginPoolConfig,\n\t\t\t\t\t\trateLimitCapacity: marginPoolConfig.rateLimitCapacity!,\n\t\t\t\t\t\trateLimitRefillRatePerMs: marginPoolConfig.rateLimitRefillRatePerMs!,\n\t\t\t\t\t\trateLimitEnabled: marginPoolConfig.rateLimitEnabled!,\n\t\t\t\t\t})(tx)\n\t\t\t\t: this.newMarginPoolConfig(coinKey, marginPoolConfig)(tx);\n\t\t\ttx.add(\n\t\t\t\tmarginPoolMoveCalls.updateMarginPoolConfig({\n\t\t\t\t\tpackage: this.#config.MARGIN_PACKAGE_ID,\n\t\t\t\t\targuments: {\n\t\t\t\t\t\tself: marginPool.address,\n\t\t\t\t\t\tregistry: this.#config.MARGIN_REGISTRY_ID,\n\t\t\t\t\t\tmarginPoolConfig: marginPoolConfigObject,\n\t\t\t\t\t\tmarginPoolCap,\n\t\t\t\t\t},\n\t\t\t\t\ttypeArguments: [marginPool.type],\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n}\n"],"m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