@mysten/deepbook-v3 1.1.5 → 1.2.1

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 (116) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/client.d.mts +58 -763
  3. package/dist/client.d.mts.map +1 -1
  4. package/dist/client.mjs +253 -2127
  5. package/dist/client.mjs.map +1 -1
  6. package/dist/contracts/utils/index.mjs +1 -1
  7. package/dist/index.d.mts +4 -4
  8. package/dist/index.mjs +4 -4
  9. package/dist/pyth/pyth.mjs +1 -1
  10. package/dist/queries/accountQueries.mjs +104 -0
  11. package/dist/queries/accountQueries.mjs.map +1 -0
  12. package/dist/queries/balanceManagerQueries.mjs +113 -0
  13. package/dist/queries/balanceManagerQueries.mjs.map +1 -0
  14. package/dist/queries/context.mjs +15 -0
  15. package/dist/queries/context.mjs.map +1 -0
  16. package/dist/queries/marginManagerQueries.mjs +365 -0
  17. package/dist/queries/marginManagerQueries.mjs.map +1 -0
  18. package/dist/queries/marginPoolQueries.mjs +184 -0
  19. package/dist/queries/marginPoolQueries.mjs.map +1 -0
  20. package/dist/queries/orderQueries.mjs +165 -0
  21. package/dist/queries/orderQueries.mjs.map +1 -0
  22. package/dist/queries/poolQueries.mjs +234 -0
  23. package/dist/queries/poolQueries.mjs.map +1 -0
  24. package/dist/queries/priceFeedQueries.mjs +83 -0
  25. package/dist/queries/priceFeedQueries.mjs.map +1 -0
  26. package/dist/queries/quantityQueries.mjs +216 -0
  27. package/dist/queries/quantityQueries.mjs.map +1 -0
  28. package/dist/queries/referralQueries.mjs +96 -0
  29. package/dist/queries/referralQueries.mjs.map +1 -0
  30. package/dist/queries/registryQueries.mjs +162 -0
  31. package/dist/queries/registryQueries.mjs.map +1 -0
  32. package/dist/queries/tpslQueries.mjs +62 -0
  33. package/dist/queries/tpslQueries.mjs.map +1 -0
  34. package/dist/transactions/balanceManager.d.mts +12 -12
  35. package/dist/transactions/balanceManager.d.mts.map +1 -1
  36. package/dist/transactions/balanceManager.mjs +5 -4
  37. package/dist/transactions/balanceManager.mjs.map +1 -1
  38. package/dist/transactions/deepbook.d.mts +24 -24
  39. package/dist/transactions/deepbook.d.mts.map +1 -1
  40. package/dist/transactions/deepbook.mjs +48 -47
  41. package/dist/transactions/deepbook.mjs.map +1 -1
  42. package/dist/transactions/deepbookAdmin.d.mts +2 -2
  43. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  44. package/dist/transactions/deepbookAdmin.mjs +10 -9
  45. package/dist/transactions/deepbookAdmin.mjs.map +1 -1
  46. package/dist/transactions/flashLoans.d.mts.map +1 -1
  47. package/dist/transactions/flashLoans.mjs +6 -4
  48. package/dist/transactions/flashLoans.mjs.map +1 -1
  49. package/dist/transactions/governance.d.mts.map +1 -1
  50. package/dist/transactions/governance.mjs +5 -4
  51. package/dist/transactions/governance.mjs.map +1 -1
  52. package/dist/transactions/marginAdmin.d.mts +7 -7
  53. package/dist/transactions/marginAdmin.d.mts.map +1 -1
  54. package/dist/transactions/marginAdmin.mjs +8 -7
  55. package/dist/transactions/marginAdmin.mjs.map +1 -1
  56. package/dist/transactions/marginLiquidations.d.mts.map +1 -1
  57. package/dist/transactions/marginLiquidations.mjs +5 -4
  58. package/dist/transactions/marginLiquidations.mjs.map +1 -1
  59. package/dist/transactions/marginMaintainer.d.mts +5 -5
  60. package/dist/transactions/marginMaintainer.d.mts.map +1 -1
  61. package/dist/transactions/marginMaintainer.mjs +15 -14
  62. package/dist/transactions/marginMaintainer.mjs.map +1 -1
  63. package/dist/transactions/marginManager.d.mts +23 -23
  64. package/dist/transactions/marginManager.d.mts.map +1 -1
  65. package/dist/transactions/marginManager.mjs +17 -12
  66. package/dist/transactions/marginManager.mjs.map +1 -1
  67. package/dist/transactions/marginPool.d.mts.map +1 -1
  68. package/dist/transactions/marginPool.mjs +3 -2
  69. package/dist/transactions/marginPool.mjs.map +1 -1
  70. package/dist/transactions/marginTPSL.d.mts +1 -1
  71. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  72. package/dist/transactions/marginTPSL.mjs +6 -8
  73. package/dist/transactions/marginTPSL.mjs.map +1 -1
  74. package/dist/transactions/poolProxy.d.mts.map +1 -1
  75. package/dist/transactions/poolProxy.mjs +13 -13
  76. package/dist/transactions/poolProxy.mjs.map +1 -1
  77. package/dist/types/index.d.mts +189 -52
  78. package/dist/types/index.d.mts.map +1 -1
  79. package/dist/types/index.mjs.map +1 -1
  80. package/dist/utils/constants.d.mts +4 -0
  81. package/dist/utils/constants.d.mts.map +1 -1
  82. package/dist/utils/constants.mjs +12 -5
  83. package/dist/utils/constants.mjs.map +1 -1
  84. package/dist/utils/conversion.mjs +26 -0
  85. package/dist/utils/conversion.mjs.map +1 -0
  86. package/package.json +6 -5
  87. package/src/client.ts +421 -2662
  88. package/src/index.ts +27 -0
  89. package/src/queries/accountQueries.ts +117 -0
  90. package/src/queries/balanceManagerQueries.ts +156 -0
  91. package/src/queries/context.ts +44 -0
  92. package/src/queries/index.ts +16 -0
  93. package/src/queries/marginManagerQueries.ts +575 -0
  94. package/src/queries/marginPoolQueries.ts +226 -0
  95. package/src/queries/orderQueries.ts +202 -0
  96. package/src/queries/poolQueries.ts +266 -0
  97. package/src/queries/priceFeedQueries.ts +141 -0
  98. package/src/queries/quantityQueries.ts +266 -0
  99. package/src/queries/referralQueries.ts +112 -0
  100. package/src/queries/registryQueries.ts +185 -0
  101. package/src/queries/tpslQueries.ts +88 -0
  102. package/src/transactions/balanceManager.ts +5 -4
  103. package/src/transactions/deepbook.ts +98 -84
  104. package/src/transactions/deepbookAdmin.ts +10 -9
  105. package/src/transactions/flashLoans.ts +5 -4
  106. package/src/transactions/governance.ts +5 -4
  107. package/src/transactions/marginAdmin.ts +8 -7
  108. package/src/transactions/marginLiquidations.ts +5 -4
  109. package/src/transactions/marginMaintainer.ts +15 -14
  110. package/src/transactions/marginManager.ts +13 -12
  111. package/src/transactions/marginPool.ts +3 -2
  112. package/src/transactions/marginTPSL.ts +11 -6
  113. package/src/transactions/poolProxy.ts +12 -11
  114. package/src/types/index.ts +200 -53
  115. package/src/utils/constants.ts +12 -5
  116. package/src/utils/conversion.ts +33 -0
@@ -1,3 +1,5 @@
1
+ import { convertQuantity } from "../utils/conversion.mjs";
2
+
1
3
  //#region src/transactions/flashLoans.ts
2
4
  /**
3
5
  * FlashLoanContract class for managing flash loans.
@@ -12,7 +14,7 @@ var FlashLoanContract = class {
12
14
  const pool = this.#config.getPool(poolKey);
13
15
  const baseCoin = this.#config.getCoin(pool.baseCoin);
14
16
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
15
- const inputQuantity = Math.round(borrowAmount * baseCoin.scalar);
17
+ const inputQuantity = convertQuantity(borrowAmount, baseCoin.scalar);
16
18
  const [baseCoinResult, flashLoan] = tx.moveCall({
17
19
  target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`,
18
20
  arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
@@ -25,7 +27,7 @@ var FlashLoanContract = class {
25
27
  const baseCoin = this.#config.getCoin(pool.baseCoin);
26
28
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
27
29
  const borrowScalar = baseCoin.scalar;
28
- const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [tx.pure.u64(Math.round(borrowAmount * borrowScalar))]);
30
+ const [baseCoinReturn] = tx.splitCoins(baseCoinInput, [tx.pure.u64(convertQuantity(borrowAmount, borrowScalar))]);
29
31
  tx.moveCall({
30
32
  target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_base`,
31
33
  arguments: [
@@ -41,7 +43,7 @@ var FlashLoanContract = class {
41
43
  const pool = this.#config.getPool(poolKey);
42
44
  const baseCoin = this.#config.getCoin(pool.baseCoin);
43
45
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
44
- const inputQuantity = Math.round(borrowAmount * quoteCoin.scalar);
46
+ const inputQuantity = convertQuantity(borrowAmount, quoteCoin.scalar);
45
47
  const [quoteCoinResult, flashLoan] = tx.moveCall({
46
48
  target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`,
47
49
  arguments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],
@@ -54,7 +56,7 @@ var FlashLoanContract = class {
54
56
  const baseCoin = this.#config.getCoin(pool.baseCoin);
55
57
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
56
58
  const borrowScalar = quoteCoin.scalar;
57
- const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [tx.pure.u64(Math.round(borrowAmount * borrowScalar))]);
59
+ const [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [tx.pure.u64(convertQuantity(borrowAmount, borrowScalar))]);
58
60
  tx.moveCall({
59
61
  target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_quote`,
60
62
  arguments: [
@@ -1 +1 @@
1
- {"version":3,"file":"flashLoans.mjs","names":["#config"],"sources":["../../src/transactions/flashLoans.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\n\n/**\n * FlashLoanContract class for managing flash loans.\n */\nexport class FlashLoanContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration object for DeepBook\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Borrow base asset from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount to borrow\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowBaseAsset = (poolKey: string, borrowAmount: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst inputQuantity = Math.round(borrowAmount * baseCoin.scalar);\n\t\tconst [baseCoinResult, flashLoan] = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`,\n\t\t\targuments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t\treturn [baseCoinResult, flashLoan] as const;\n\t};\n\n\t/**\n\t * @description Return base asset to the pool after a flash loan.\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount of the base asset to return\n\t * @param {TransactionObjectArgument} baseCoinInput Coin object representing the base asset to be returned\n\t * @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled\n\t * @returns A function that takes a Transaction object\n\t */\n\treturnBaseAsset =\n\t\t(\n\t\t\tpoolKey: string,\n\t\t\tborrowAmount: number,\n\t\t\tbaseCoinInput: TransactionObjectArgument,\n\t\t\tflashLoan: TransactionObjectArgument,\n\t\t) =>\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 borrowScalar = baseCoin.scalar;\n\n\t\t\tconst [baseCoinReturn] = tx.splitCoins(baseCoinInput, [\n\t\t\t\ttx.pure.u64(Math.round(borrowAmount * borrowScalar)),\n\t\t\t]);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_base`,\n\t\t\t\targuments: [tx.object(pool.address), baseCoinReturn, flashLoan],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\n\t\t\treturn baseCoinInput;\n\t\t};\n\n\t/**\n\t * @description Borrow quote asset from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount to borrow\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowQuoteAsset = (poolKey: string, borrowAmount: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst inputQuantity = Math.round(borrowAmount * quoteCoin.scalar);\n\t\tconst [quoteCoinResult, flashLoan] = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`,\n\t\t\targuments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t\treturn [quoteCoinResult, flashLoan] as const;\n\t};\n\n\t/**\n\t * @description Return quote asset to the pool after a flash loan.\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount of the quote asset to return\n\t * @param {TransactionObjectArgument} quoteCoinInput Coin object representing the quote asset to be returned\n\t * @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled\n\t * @returns A function that takes a Transaction object\n\t */\n\treturnQuoteAsset =\n\t\t(\n\t\t\tpoolKey: string,\n\t\t\tborrowAmount: number,\n\t\t\tquoteCoinInput: TransactionObjectArgument,\n\t\t\tflashLoan: TransactionObjectArgument,\n\t\t) =>\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 borrowScalar = quoteCoin.scalar;\n\n\t\t\tconst [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [\n\t\t\t\ttx.pure.u64(Math.round(borrowAmount * borrowScalar)),\n\t\t\t]);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_quote`,\n\t\t\t\targuments: [tx.object(pool.address), quoteCoinReturn, flashLoan],\n\t\t\t\ttypeAr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AAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;GACtD,MAAM,gBAAgB,KAAK,MAAM,eAAe,UAAU,OAAO;GACjE,MAAM,CAAC,iBAAiB,aAAa,GAAG,SAAS;IAChD,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW,CAAC,GAAG,OAAO,KAAK,QAAQ,EAAE,GAAG,KAAK,IAAI,cAAc,CAAC;IAChE,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;AACF,UAAO,CAAC,iBAAiB,UAAU;;2BAalC,SACA,cACA,gBACA,eAEA,OAAoB;GACpB,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;GACtD,MAAM,eAAe,UAAU;GAE/B,MAAM,CAAC,mBAAmB,GAAG,WAAW,gBAAgB,CACvD,GAAG,KAAK,IAAI,KAAK,MAAM,eAAe,aAAa,CAAC,CACpD,CAAC;AACF,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW;KAAC,GAAG,OAAO,KAAK,QAAQ;KAAE;KAAiB;KAAU;IAChE,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;AAEF,UAAO;;AAxGR,QAAKA,SAAU"}
1
+ {"version":3,"file":"flashLoans.mjs","names":["#config"],"sources":["../../src/transactions/flashLoans.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { convertQuantity } from '../utils/conversion.js';\n\n/**\n * FlashLoanContract class for managing flash loans.\n */\nexport class FlashLoanContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration object for DeepBook\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Borrow base asset from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount to borrow\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowBaseAsset = (poolKey: string, borrowAmount: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst inputQuantity = convertQuantity(borrowAmount, baseCoin.scalar);\n\t\tconst [baseCoinResult, flashLoan] = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_base`,\n\t\t\targuments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t\treturn [baseCoinResult, flashLoan] as const;\n\t};\n\n\t/**\n\t * @description Return base asset to the pool after a flash loan.\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount of the base asset to return\n\t * @param {TransactionObjectArgument} baseCoinInput Coin object representing the base asset to be returned\n\t * @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled\n\t * @returns A function that takes a Transaction object\n\t */\n\treturnBaseAsset =\n\t\t(\n\t\t\tpoolKey: string,\n\t\t\tborrowAmount: number,\n\t\t\tbaseCoinInput: TransactionObjectArgument,\n\t\t\tflashLoan: TransactionObjectArgument,\n\t\t) =>\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 borrowScalar = baseCoin.scalar;\n\n\t\t\tconst [baseCoinReturn] = tx.splitCoins(baseCoinInput, [\n\t\t\t\ttx.pure.u64(convertQuantity(borrowAmount, borrowScalar)),\n\t\t\t]);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_base`,\n\t\t\t\targuments: [tx.object(pool.address), baseCoinReturn, flashLoan],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\n\t\t\treturn baseCoinInput;\n\t\t};\n\n\t/**\n\t * @description Borrow quote asset from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount to borrow\n\t * @returns A function that takes a Transaction object\n\t */\n\tborrowQuoteAsset = (poolKey: string, borrowAmount: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst inputQuantity = convertQuantity(borrowAmount, quoteCoin.scalar);\n\t\tconst [quoteCoinResult, flashLoan] = tx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::borrow_flashloan_quote`,\n\t\t\targuments: [tx.object(pool.address), tx.pure.u64(inputQuantity)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t\treturn [quoteCoinResult, flashLoan] as const;\n\t};\n\n\t/**\n\t * @description Return quote asset to the pool after a flash loan.\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} borrowAmount The amount of the quote asset to return\n\t * @param {TransactionObjectArgument} quoteCoinInput Coin object representing the quote asset to be returned\n\t * @param {TransactionObjectArgument} flashLoan FlashLoan object representing the loan to be settled\n\t * @returns A function that takes a Transaction object\n\t */\n\treturnQuoteAsset =\n\t\t(\n\t\t\tpoolKey: string,\n\t\t\tborrowAmount: number,\n\t\t\tquoteCoinInput: TransactionObjectArgument,\n\t\t\tflashLoan: TransactionObjectArgument,\n\t\t) =>\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 borrowScalar = quoteCoin.scalar;\n\n\t\t\tconst [quoteCoinReturn] = tx.splitCoins(quoteCoinInput, [\n\t\t\t\ttx.pure.u64(convertQuantity(borrowAmount, borrowScalar)),\n\t\t\t]);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::return_flashloan_quote`,\n\t\t\t\targuments: [tx.object(pool.address), quoteCoinReturn, flashLoan],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\n\t\t\treturn quoteCoinInput;\n\t\t};\n}\n"],"mappings":";;;;;;AAUA,IAAa,oBAAb,MAA+B;CAC9B;;;;CAKA,YAAY,QAAwB;0BAUjB,SAAiB,kBAA0B,OAAoB;GACjF,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;GACtD,MAAM,gBAAgB,gBAAgB,cAAc,SAAS,OAAO;GACpE,MAAM,CAAC,gBAAgB,aAAa,GAAG,SAAS;IAC/C,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW,CAAC,GAAG,OAAO,KAAK,QAAQ,EAAE,GAAG,KAAK,IAAI,cAAc,CAAC;IAChE,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;AACF,UAAO,CAAC,gBAAgB,UAAU;;0BAajC,SACA,cACA,eACA,eAEA,OAAoB;GACpB,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ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,OAAO,KAAK,QAAQ;KAAE;KAAiB;KAAU;IAChE,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;AAEF,UAAO;;AAxGR,QAAKA,SAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"governance.d.mts","names":[],"sources":["../../src/transactions/governance.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAWA;AAMqB,cANR,kBAAA,CAMQ;EAYuD,CAAA,OAAA;EA0BZ;;;EAiDkB,WAAA,CAAA,MAAA,EAvF7D,cAuF6D;EAAW;;;;;;;mFA3EjB;;;;;;;gEA0BZ;;;;;;2BAmBrC,wBAAwB;;;;;;;;kFA8B+B"}
1
+ {"version":3,"file":"governance.d.mts","names":[],"sources":["../../src/transactions/governance.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAYA;AAMqB,cANR,kBAAA,CAMQ;EAYuD,CAAA,OAAA;EA0BZ;;;EAiDkB,WAAA,CAAA,MAAA,EAvF7D,cAuF6D;EAAW;;;;;;;mFA3EjB;;;;;;;gEA0BZ;;;;;;2BAmBrC,wBAAwB;;;;;;;;kFA8B+B"}
@@ -1,3 +1,4 @@
1
+ import { convertQuantity, convertRate } from "../utils/conversion.mjs";
1
2
  import { DEEP_SCALAR, FLOAT_SCALAR } from "../utils/config.mjs";
2
3
 
3
4
  //#region src/transactions/governance.ts
@@ -16,7 +17,7 @@ var GovernanceContract = class {
16
17
  const tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));
17
18
  const baseCoin = this.#config.getCoin(pool.baseCoin);
18
19
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
19
- const stakeInput = Math.round(stakeAmount * DEEP_SCALAR);
20
+ const stakeInput = convertQuantity(stakeAmount, DEEP_SCALAR);
20
21
  tx.moveCall({
21
22
  target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::stake`,
22
23
  arguments: [
@@ -57,9 +58,9 @@ var GovernanceContract = class {
57
58
  tx.object(pool.address),
58
59
  tx.object(balanceManager.address),
59
60
  tradeProof,
60
- tx.pure.u64(Math.round(takerFee * FLOAT_SCALAR)),
61
- tx.pure.u64(Math.round(makerFee * FLOAT_SCALAR)),
62
- tx.pure.u64(Math.round(stakeRequired * DEEP_SCALAR))
61
+ tx.pure.u64(convertRate(takerFee, FLOAT_SCALAR)),
62
+ tx.pure.u64(convertRate(makerFee, FLOAT_SCALAR)),
63
+ tx.pure.u64(convertQuantity(stakeRequired, DEEP_SCALAR))
63
64
  ],
64
65
  typeArguments: [baseCoin.type, quoteCoin.type]
65
66
  });
@@ -1 +1 @@
1
- {"version":3,"file":"governance.mjs","names":["#config"],"sources":["../../src/transactions/governance.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { ProposalParams } from '../types/index.js';\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';\n\n/**\n * GovernanceContract class for managing governance operations in DeepBook.\n */\nexport class GovernanceContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for GovernanceContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Stake a specified amount in the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @param {number} stakeAmount The amount to stake\n\t * @returns A function that takes a Transaction object\n\t */\n\tstake =\n\t\t(poolKey: string, balanceManagerKey: string, stakeAmount: number) => (tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst stakeInput = Math.round(stakeAmount * DEEP_SCALAR);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::stake`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\ttx.object(balanceManager.address),\n\t\t\t\t\ttradeProof,\n\t\t\t\t\ttx.pure.u64(stakeInput),\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 Unstake from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tunstake = (poolKey: string, balanceManagerKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::unstake`,\n\t\t\targuments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Submit a governance proposal\n\t * @param {ProposalParams} params Parameters for the proposal\n\t * @returns A function that takes a Transaction object\n\t */\n\tsubmitProposal = (params: ProposalParams) => (tx: Transaction) => {\n\t\tconst { poolKey, balanceManagerKey, takerFee, makerFee, stakeRequired } = params;\n\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::submit_proposal`,\n\t\t\targuments: [\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(balanceManager.address),\n\t\t\t\ttradeProof,\n\t\t\t\ttx.pure.u64(Math.round(takerFee * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(makerFee * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(stakeRequired * DEEP_SCALAR)),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Vote on a proposal\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @param {string} proposal_id The ID of the proposal to vote on\n\t * @returns A function that takes a Transaction object\n\t */\n\tvote = (poolKey: string, balanceManagerKey: string, proposal_id: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::vote`,\n\t\t\targuments: [\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(balanceManager.address),\n\t\t\t\ttradeProof,\n\t\t\t\ttx.pure.id(proposal_id),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;AAWA,IAAa,qBAAb,MAAgC;CAC/B;;;;CAKA,YAAY,QAAwB;gBAYlC,SAAiB,mBAA2B,iBAAyB,OAAoB;GACzF,MAAM,OAAO,MAAKA,OAAQ,QA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,OAAQ,eAAe,cAAc,kBAAkB,CAAC;GACvF,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;AAEtD,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW;KACV,GAAG,OAAO,KAAK,QAAQ;KACvB,GAAG,OAAO,eAAe,QAAQ;KACjC;KACA,GAAG,KAAK,IAAI,KAAK,MAAM,WAAW,aAAa,CAAC;KAChD,GAAG,KAAK,IAAI,KAAK,MAAM,WAAW,aAAa,CAAC;KAChD,GAAG,KAAK,IAAI,KAAK,MAAM,gBAAgB,YAAY,CAAC;KACpD;IACD,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;eAUK,SAAiB,mBAA2B,iBAAyB,OAAoB;GAChG,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,iBAAiB,MAAKA,OAAQ,kBAAkB,kBAAkB;GACxE,MAAM,aAAa,GAAG,IAAI,MAAKA,OAAQ,eAAe,cAAc,kBAAkB,CAAC;GACvF,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;AAEtD,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW;KACV,GAAG,OAAO,KAAK,QAAQ;KACvB,GAAG,OAAO,eAAe,QAAQ;KACjC;KACA,GAAG,KAAK,GAAG,YAAY;KACvB;IACD,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;AAtGF,QAAKA,SAAU"}
1
+ {"version":3,"file":"governance.mjs","names":["#config"],"sources":["../../src/transactions/governance.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { ProposalParams } from '../types/index.js';\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';\nimport { convertQuantity, convertRate } from '../utils/conversion.js';\n\n/**\n * GovernanceContract class for managing governance operations in DeepBook.\n */\nexport class GovernanceContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for GovernanceContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Stake a specified amount in the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @param {number} stakeAmount The amount to stake\n\t * @returns A function that takes a Transaction object\n\t */\n\tstake =\n\t\t(poolKey: string, balanceManagerKey: string, stakeAmount: number) => (tx: Transaction) => {\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\t\tconst stakeInput = convertQuantity(stakeAmount, DEEP_SCALAR);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::stake`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\ttx.object(balanceManager.address),\n\t\t\t\t\ttradeProof,\n\t\t\t\t\ttx.pure.u64(stakeInput),\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 Unstake from the pool\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tunstake = (poolKey: string, balanceManagerKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::unstake`,\n\t\t\targuments: [tx.object(pool.address), tx.object(balanceManager.address), tradeProof],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Submit a governance proposal\n\t * @param {ProposalParams} params Parameters for the proposal\n\t * @returns A function that takes a Transaction object\n\t */\n\tsubmitProposal = (params: ProposalParams) => (tx: Transaction) => {\n\t\tconst { poolKey, balanceManagerKey, takerFee, makerFee, stakeRequired } = params;\n\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::submit_proposal`,\n\t\t\targuments: [\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(balanceManager.address),\n\t\t\t\ttradeProof,\n\t\t\t\ttx.pure.u64(convertRate(takerFee, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(makerFee, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertQuantity(stakeRequired, DEEP_SCALAR)),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Vote on a proposal\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} balanceManagerKey The key to identify the BalanceManager\n\t * @param {string} proposal_id The ID of the proposal to vote on\n\t * @returns A function that takes a Transaction object\n\t */\n\tvote = (poolKey: string, balanceManagerKey: string, proposal_id: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst balanceManager = this.#config.getBalanceManager(balanceManagerKey);\n\t\tconst tradeProof = tx.add(this.#config.balanceManager.generateProof(balanceManagerKey));\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::vote`,\n\t\t\targuments: [\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(balanceManager.address),\n\t\t\t\ttradeProof,\n\t\t\t\ttx.pure.id(proposal_id),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;;AAYA,IAAa,qBAAb,MAAgC;CAC/B;;;;CAKA,YAAY,QAAwB;gBAYlC,SAAiB,mBAA2B,iBAAyB,OAAoB;GACzF,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,iBAAiB,MAAKA,OAAQ,kBAAkB,kBAAkB;GACxE,MAAM,aAAa,GAAG,IAAI,MAAKA,OAAQ,eAAe,cAAc,kBAAkB,CAAC;GACvF,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;GACtD,MAAM,aAAa,gBAAgB,aAAa,YAAY;AAE5D,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW;KACV,GAAG,OAAO,KAAK,QAAQ;KACvB,GAAG,OAAO,eAAe,QAAQ;KACjC;KACA,GAAG,KAAK,IAAI,WAAW;KACvB;IACD,eAAe,CAAC,SAAS,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CAAC;;eAUK,SAAiB,mBAA2B,iBAAyB,OAAoB;GAChG,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,iBAAiB,MAAKA,OAAQ,kBAAkB,kBAAkB;GACxE,MAAM,aAAa,GAAG,IAAI,MAAKA,OAAQ,eAAe,cAAc,kBAAkB,CAAC;GACvF,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;AAEtD,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,oBAAoB;IAC5C,WAAW;KACV,GAAG,OAAO,KAAK,QAAQ;KACvB,GAAG,OAAO,eAAe,QAAQ;KACjC;KACA,GAAG,KAAK,GAAG,YAAY;KACvB;IACD,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;AAtGF,QAAKA,SAAU"}
@@ -1,6 +1,6 @@
1
1
  import { PoolConfigParams } from "../types/index.mjs";
2
2
  import { DeepBookConfig } from "../utils/config.mjs";
3
- import * as _mysten_sui_transactions30 from "@mysten/sui/transactions";
3
+ import * as _mysten_sui_transactions52 from "@mysten/sui/transactions";
4
4
  import { Transaction, TransactionArgument } from "@mysten/sui/transactions";
5
5
 
6
6
  //#region src/transactions/marginAdmin.d.ts
@@ -18,7 +18,7 @@ declare class MarginAdminContract {
18
18
  * @description Mint a maintainer cap
19
19
  * @returns A function that takes a Transaction object
20
20
  */
21
- mintMaintainerCap: () => (tx: Transaction) => _mysten_sui_transactions30.TransactionResult;
21
+ mintMaintainerCap: () => (tx: Transaction) => _mysten_sui_transactions52.TransactionResult;
22
22
  /**
23
23
  * @description Revoke a maintainer cap
24
24
  * @returns A function that takes a Transaction object
@@ -81,7 +81,7 @@ declare class MarginAdminContract {
81
81
  * @param {PoolConfigParams} poolConfigParams The parameters for the pool config
82
82
  * @returns A function that takes a Transaction object
83
83
  */
84
- newPoolConfig: (poolKey: string, poolConfigParams: PoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions30.TransactionResult;
84
+ newPoolConfig: (poolKey: string, poolConfigParams: PoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions52.TransactionResult;
85
85
  /**
86
86
  * @description Create a new pool config with leverage
87
87
  * @param {string} poolKey The key to identify the pool
@@ -96,7 +96,7 @@ declare class MarginAdminContract {
96
96
  * @param {number} maxEwmaDifferenceBps The maximum EWMA difference in basis points
97
97
  * @returns A function that takes a Transaction object
98
98
  */
99
- newCoinTypeData: (coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number) => (tx: Transaction) => _mysten_sui_transactions30.TransactionResult;
99
+ newCoinTypeData: (coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number) => (tx: Transaction) => _mysten_sui_transactions52.TransactionResult;
100
100
  /**
101
101
  * @description Create a new Pyth config
102
102
  * @param {Array<{coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number}>} coinSetups The coins with their oracle config to be added to the Pyth config
@@ -107,12 +107,12 @@ declare class MarginAdminContract {
107
107
  coinKey: string;
108
108
  maxConfBps: number;
109
109
  maxEwmaDifferenceBps: number;
110
- }>, maxAgeSeconds: number) => (tx: Transaction) => _mysten_sui_transactions30.TransactionResult;
110
+ }>, maxAgeSeconds: number) => (tx: Transaction) => _mysten_sui_transactions52.TransactionResult;
111
111
  /**
112
112
  * @description Mint a pause cap
113
113
  * @returns A function that takes a Transaction object
114
114
  */
115
- mintPauseCap: () => (tx: Transaction) => _mysten_sui_transactions30.TransactionResult;
115
+ mintPauseCap: () => (tx: Transaction) => _mysten_sui_transactions52.TransactionResult;
116
116
  /**
117
117
  * @description Revoke a pause cap
118
118
  * @param {string} pauseCapId The ID of the pause cap to revoke
@@ -132,7 +132,7 @@ declare class MarginAdminContract {
132
132
  * @param {string} coinKey The key to identify the margin pool
133
133
  * @returns A function that takes a Transaction object and returns a Coin<Asset>
134
134
  */
135
- adminWithdrawDefaultReferralFees: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions30.TransactionResult;
135
+ adminWithdrawDefaultReferralFees: (coinKey: string) => (tx: Transaction) => _mysten_sui_transactions52.TransactionResult;
136
136
  }
137
137
  //#endregion
138
138
  export { MarginAdminContract };
@@ -1 +1 @@
1
- {"version":3,"file":"marginAdmin.d.mts","names":[],"sources":["../../src/transactions/marginAdmin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAcA;AAMqB,cANR,mBAAA,CAMQ;EAoBW,CAAA,OAAA;EAAW;;;EAkCkB,WAAA,CAAA,MAAA,EAtDxC,cAsDwC;EAsBb;;;;EAkE1B,iBAAA,EAAA,GAAA,GAAA,CAAA,EAAA,EA1HU,WA0HV,EAAA,GA1HqB,0BAAA,CAAA,iBA0HrB;EAA6B;;;;EA+DE,mBAAA,EAAA,CAAA,eAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EAAA,EA1KI,WA0KJ,EAAA,GAAA,IAAA;EAA0B;;;;;;EAsFxE,oBAAA,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,UAAA,EA7OyB,mBA6OzB,EAAA,GAAA,CAAA,EAAA,EA7OsD,WA6OtD,EAAA,GAAA,IAAA;EAAW;;;;;EA0E4C,kBAAA,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EAAA,EAjSd,WAiSc,EAAA,GAAA,IAAA;EAAW;;;;;iDA5QxB;;;;;;;kDAsBC,6BAA6B;;;;;;;sBAuBzD,6BAA6B;;;;;;2BAiBxB;;;;;;2CAagB;;;;;;4CAgBC;;;;;;;qDAiBS,0BAA0B,gBAAW,0BAAA,CAAA;;;;;;;yEAiCjB;;;;;;;;+FAsBK,gBAAW,0BAAA,CAAA;;;;;;;8BA4B1E;;;;qCAGR,gBAAW,0BAAA,CAAA;;;;;2BAuBS,gBAAW,0BAAA,CAAA;;;;;;+CAgBS;;;;;;;wEAkByB;;;;;;;8DAiBV,gBAAW,0BAAA,CAAA"}
1
+ {"version":3,"file":"marginAdmin.d.mts","names":[],"sources":["../../src/transactions/marginAdmin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAeA;AAMqB,cANR,mBAAA,CAMQ;EAoBW,CAAA,OAAA;EAAW;;;EAkCkB,WAAA,CAAA,MAAA,EAtDxC,cAsDwC;EAsBb;;;;EAkE1B,iBAAA,EAAA,GAAA,GAAA,CAAA,EAAA,EA1HU,WA0HV,EAAA,GA1HqB,0BAAA,CAAA,iBA0HrB;EAA6B;;;;EA+DE,mBAAA,EAAA,CAAA,eAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EAAA,EA1KI,WA0KJ,EAAA,GAAA,IAAA;EAA0B;;;;;;EAsFxE,oBAAA,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,UAAA,EA7OyB,mBA6OzB,EAAA,GAAA,CAAA,EAAA,EA7OsD,WA6OtD,EAAA,GAAA,IAAA;EAAW;;;;;EA0E4C,kBAAA,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EAAA,EAjSd,WAiSc,EAAA,GAAA,IAAA;EAAW;;;;;iDA5QxB;;;;;;;kDAsBC,6BAA6B;;;;;;;sBAuBzD,6BAA6B;;;;;;2BAiBxB;;;;;;2CAagB;;;;;;4CAgBC;;;;;;;qDAiBS,0BAA0B,gBAAW,0BAAA,CAAA;;;;;;;yEAiCjB;;;;;;;;+FAsBK,gBAAW,0BAAA,CAAA;;;;;;;8BA4B1E;;;;qCAGR,gBAAW,0BAAA,CAAA;;;;;2BAuBS,gBAAW,0BAAA,CAAA;;;;;;+CAgBS;;;;;;;wEAkByB;;;;;;;8DAiBV,gBAAW,0BAAA,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { convertRate } from "../utils/conversion.mjs";
1
2
  import { FLOAT_SCALAR } from "../utils/config.mjs";
2
3
  import { hexToBytes } from "@noble/hashes/utils.js";
3
4
 
@@ -141,12 +142,12 @@ var MarginAdminContract = class {
141
142
  target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config`,
142
143
  arguments: [
143
144
  tx.object(this.#config.MARGIN_REGISTRY_ID),
144
- tx.pure.u64(Math.round(minWithdrawRiskRatio * FLOAT_SCALAR)),
145
- tx.pure.u64(Math.round(minBorrowRiskRatio * FLOAT_SCALAR)),
146
- tx.pure.u64(Math.round(liquidationRiskRatio * FLOAT_SCALAR)),
147
- tx.pure.u64(Math.round(targetLiquidationRiskRatio * FLOAT_SCALAR)),
148
- tx.pure.u64(Math.round(userLiquidationReward * FLOAT_SCALAR)),
149
- tx.pure.u64(Math.round(poolLiquidationReward * FLOAT_SCALAR))
145
+ tx.pure.u64(convertRate(minWithdrawRiskRatio, FLOAT_SCALAR)),
146
+ tx.pure.u64(convertRate(minBorrowRiskRatio, FLOAT_SCALAR)),
147
+ tx.pure.u64(convertRate(liquidationRiskRatio, FLOAT_SCALAR)),
148
+ tx.pure.u64(convertRate(targetLiquidationRiskRatio, FLOAT_SCALAR)),
149
+ tx.pure.u64(convertRate(userLiquidationReward, FLOAT_SCALAR)),
150
+ tx.pure.u64(convertRate(poolLiquidationReward, FLOAT_SCALAR))
150
151
  ],
151
152
  typeArguments: [baseCoin.type, quoteCoin.type]
152
153
  });
@@ -157,7 +158,7 @@ var MarginAdminContract = class {
157
158
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
158
159
  tx.moveCall({
159
160
  target: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config_with_leverage`,
160
- arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.u64(Math.round(leverage * FLOAT_SCALAR))],
161
+ arguments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.pure.u64(convertRate(leverage, FLOAT_SCALAR))],
161
162
  typeArguments: [baseCoin.type, quoteCoin.type]
162
163
  });
163
164
  };
@@ -1 +1 @@
1
- {"version":3,"file":"marginAdmin.mjs","names":["#config","#marginAdminCap","config"],"sources":["../../src/transactions/marginAdmin.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type { TransactionArgument } from '@mysten/sui/transactions';\nimport type { PoolConfigParams } from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\nimport { hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * MarginAdminContract class for managing admin actions.\n */\nexport class MarginAdminContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginAdminContract\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#marginAdminCap() {\n\t\tconst marginAdminCap = this.#config.marginAdminCap;\n\t\tif (!marginAdminCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginAdminCap;\n\t}\n\n\t/**\n\t * @description Mint a maintainer cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintMaintainerCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::mint_maintainer_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Revoke a maintainer cap\n\t * @returns A function that takes a Transaction object\n\t */\n\trevokeMaintainerCap = (maintainerCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::revoke_maintainer_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(maintainerCapId),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Register a deepbook pool\n\t * @param {string} poolKey The key of the pool to be registered\n\t * @param {TransactionArgument} poolConfig The configuration of the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tregisterDeepbookPool =\n\t\t(poolKey: string, poolConfig: TransactionArgument) => (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\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::register_deepbook_pool`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\tpoolConfig,\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 Enable a deepbook pool for margin trading\n\t * @param {string} poolKey The key of the pool to be enabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPool = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::enable_deepbook_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a deepbook pool from margin trading\n\t * @param {string} poolKey The key of the pool to be disabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPool = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_deepbook_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Update the risk parameters for a margin\n\t * @param {string} poolKey The key of the pool to be updated\n\t * @param {TransactionArgument} poolConfig The configuration of the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateRiskParams = (poolKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::update_risk_params`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Add the PythConfig to the margin registry\n\t * @param {Transaction} tx The transaction object\n\t * @param {TransactionArgument} config The config to be added\n\t * @returns A function that takes a Transaction object\n\t */\n\taddConfig = (config: TransactionArgument) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::add_config`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\tconfig,\n\t\t\t],\n\t\t\ttypeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::oracle::PythConfig`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Remove the PythConfig from the margin registry\n\t * @param {Transaction} tx The transaction object\n\t * @returns A function that takes a Transaction object\n\t */\n\tremoveConfig = () => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::remove_config`,\n\t\t\targuments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object(this.#marginAdminCap())],\n\t\t\ttypeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::oracle::PythConfig`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a specific version\n\t * @param {number} version The version to be enabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableVersion = (version: number) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::enable_version`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a specific version\n\t * @param {number} version The version to be disabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableVersion = (version: number) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_version`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new pool config\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {PoolConfigParams} poolConfigParams The parameters for the pool config\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPoolConfig = (poolKey: string, poolConfigParams: PoolConfigParams) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst {\n\t\t\tminWithdrawRiskRatio,\n\t\t\tminBorrowRiskRatio,\n\t\t\tliquidationRiskRatio,\n\t\t\ttargetLiquidationRiskRatio,\n\t\t\tuserLiquidationReward,\n\t\t\tpoolLiquidationReward,\n\t\t} = poolConfigParams;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(Math.round(minWithdrawRiskRatio * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(minBorrowRiskRatio * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(liquidationRiskRatio * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(targetLiquidationRiskRatio * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(userLiquidationReward * FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(Math.round(poolLiquidationReward * FLOAT_SCALAR)),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new pool config with leverage\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} leverage The leverage for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPoolConfigWithLeverage = (poolKey: string, leverage: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config_with_leverage`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(Math.round(leverage * FLOAT_SCALAR)),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new coin type data\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {number} maxConfBps The maximum confidence interval in basis points\n\t * @param {number} maxEwmaDifferenceBps The maximum EWMA difference in basis points\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewCoinTypeData =\n\t\t(coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tif (!coin.feed) {\n\t\t\t\tthrow new Error('Coin feed not found');\n\t\t\t}\n\t\t\tconst priceFeedInput = new Uint8Array(\n\t\t\t\thexToBytes(coin['feed']!.startsWith('0x') ? coin.feed!.slice(2) : coin['feed']),\n\t\t\t);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::oracle::new_coin_type_data_from_currency`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(coin.currencyId!),\n\t\t\t\t\ttx.pure.vector('u8', priceFeedInput),\n\t\t\t\t\ttx.pure.u64(maxConfBps),\n\t\t\t\t\ttx.pure.u64(maxEwmaDifferenceBps),\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 Create a new Pyth config\n\t * @param {Array<{coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number}>} coinSetups The coins with their oracle config to be added to the Pyth config\n\t * @param {number} maxAgeSeconds The max age in seconds for the Pyth config\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPythConfig =\n\t\t(\n\t\t\tcoinSetups: Array<{ coinKey: string; maxConfBps: number; maxEwmaDifferenceBps: number }>,\n\t\t\tmaxAgeSeconds: number,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coinTypeDataList = [];\n\t\t\tfor (const setup of coinSetups) {\n\t\t\t\tcoinTypeDataList.push(\n\t\t\t\t\tthis.newCoinTypeData(setup.coinKey, setup.maxConfBps, setup.maxEwmaDifferenceBps)(tx),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::oracle::new_pyth_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.makeMoveVec({\n\t\t\t\t\t\telements: coinTypeDataList,\n\t\t\t\t\t\ttype: `${this.#config.MARGIN_PACKAGE_ID}::oracle::CoinTypeData`,\n\t\t\t\t\t}),\n\t\t\t\t\ttx.pure.u64(maxAgeSeconds),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Mint a pause cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintPauseCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::mint_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Revoke a pause cap\n\t * @param {string} pauseCapId The ID of the pause cap to revoke\n\t * @returns A function that takes a Transaction object\n\t */\n\trevokePauseCap = (pauseCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::revoke_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t\ttx.pure.id(pauseCapId),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a version using pause cap\n\t * @param {number} version The version to disable\n\t * @param {string} pauseCapId The ID of the pause cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableVersionPauseCap = (version: number, pauseCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_version_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(pauseCapId),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw the default referral fees (admin only)\n\t * The default referral at 0x0 doesn't have a SupplyReferral object\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @returns A function that takes a Transaction object and returns a Coin<Asset>\n\t */\n\tadminWithdrawDefaultReferralFees = (coinKey: string) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::admin_withdraw_default_referral_fees`,\n\t\t\targuments: [\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t],\n\t\t\ttypeArguments: [coin.type],\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;;AAcA,IAAa,sBAAb,MAAiC;CAChC;;;;CAKA,YAAY,QAAwB;kCAoBT,OAAoB;AAC9C,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW;KACV,GAAG,OAAO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AAC;KACjC;IACD,eAAe,CAAC,KAAK,KAAK;IAC1B,CAAC;;AAvXF,QAAKD,SAAU;;;;;;CAOhB,kBAAkB;EACjB,MAAM,iBAAiB,MAAKA,OAAQ;AACpC,MAAI,CAAC,eACJ,OAAM,IAAI,MAAM,gDAAgD;AAEjE,SAAO"}
1
+ {"version":3,"file":"marginAdmin.mjs","names":["#config","#marginAdminCap","config"],"sources":["../../src/transactions/marginAdmin.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type { TransactionArgument } from '@mysten/sui/transactions';\nimport type { PoolConfigParams } from '../types/index.js';\nimport { FLOAT_SCALAR } from '../utils/config.js';\nimport { convertRate } from '../utils/conversion.js';\nimport { hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * MarginAdminContract class for managing admin actions.\n */\nexport class MarginAdminContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginAdminContract\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#marginAdminCap() {\n\t\tconst marginAdminCap = this.#config.marginAdminCap;\n\t\tif (!marginAdminCap) {\n\t\t\tthrow new Error('MARGIN_ADMIN_CAP environment variable not set');\n\t\t}\n\t\treturn marginAdminCap;\n\t}\n\n\t/**\n\t * @description Mint a maintainer cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintMaintainerCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::mint_maintainer_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Revoke a maintainer cap\n\t * @returns A function that takes a Transaction object\n\t */\n\trevokeMaintainerCap = (maintainerCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::revoke_maintainer_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(maintainerCapId),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Register a deepbook pool\n\t * @param {string} poolKey The key of the pool to be registered\n\t * @param {TransactionArgument} poolConfig The configuration of the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tregisterDeepbookPool =\n\t\t(poolKey: string, poolConfig: TransactionArgument) => (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\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::register_deepbook_pool`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\tpoolConfig,\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 Enable a deepbook pool for margin trading\n\t * @param {string} poolKey The key of the pool to be enabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableDeepbookPool = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::enable_deepbook_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a deepbook pool from margin trading\n\t * @param {string} poolKey The key of the pool to be disabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableDeepbookPool = (poolKey: string) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_deepbook_pool`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Update the risk parameters for a margin\n\t * @param {string} poolKey The key of the pool to be updated\n\t * @param {TransactionArgument} poolConfig The configuration of the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateRiskParams = (poolKey: string, poolConfig: TransactionArgument) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::update_risk_params`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\tpoolConfig,\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Add the PythConfig to the margin registry\n\t * @param {Transaction} tx The transaction object\n\t * @param {TransactionArgument} config The config to be added\n\t * @returns A function that takes a Transaction object\n\t */\n\taddConfig = (config: TransactionArgument) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::add_config`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\tconfig,\n\t\t\t],\n\t\t\ttypeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::oracle::PythConfig`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Remove the PythConfig from the margin registry\n\t * @param {Transaction} tx The transaction object\n\t * @returns A function that takes a Transaction object\n\t */\n\tremoveConfig = () => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::remove_config`,\n\t\t\targuments: [tx.object(this.#config.MARGIN_REGISTRY_ID), tx.object(this.#marginAdminCap())],\n\t\t\ttypeArguments: [`${this.#config.MARGIN_PACKAGE_ID}::oracle::PythConfig`],\n\t\t});\n\t};\n\n\t/**\n\t * @description Enable a specific version\n\t * @param {number} version The version to be enabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tenableVersion = (version: number) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::enable_version`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a specific version\n\t * @param {number} version The version to be disabled\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableVersion = (version: number) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_version`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new pool config\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {PoolConfigParams} poolConfigParams The parameters for the pool config\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPoolConfig = (poolKey: string, poolConfigParams: PoolConfigParams) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst {\n\t\t\tminWithdrawRiskRatio,\n\t\t\tminBorrowRiskRatio,\n\t\t\tliquidationRiskRatio,\n\t\t\ttargetLiquidationRiskRatio,\n\t\t\tuserLiquidationReward,\n\t\t\tpoolLiquidationReward,\n\t\t} = poolConfigParams;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(convertRate(minWithdrawRiskRatio, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(minBorrowRiskRatio, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(liquidationRiskRatio, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(targetLiquidationRiskRatio, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(userLiquidationReward, FLOAT_SCALAR)),\n\t\t\t\ttx.pure.u64(convertRate(poolLiquidationReward, FLOAT_SCALAR)),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new pool config with leverage\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {number} leverage The leverage for the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPoolConfigWithLeverage = (poolKey: string, leverage: number) => (tx: Transaction) => {\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::new_pool_config_with_leverage`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(convertRate(leverage, FLOAT_SCALAR)),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Create a new coin type data\n\t * @param {string} coinKey The key to identify the coin\n\t * @param {number} maxConfBps The maximum confidence interval in basis points\n\t * @param {number} maxEwmaDifferenceBps The maximum EWMA difference in basis points\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewCoinTypeData =\n\t\t(coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number) => (tx: Transaction) => {\n\t\t\tconst coin = this.#config.getCoin(coinKey);\n\t\t\tif (!coin.feed) {\n\t\t\t\tthrow new Error('Coin feed not found');\n\t\t\t}\n\t\t\tconst priceFeedInput = new Uint8Array(\n\t\t\t\thexToBytes(coin['feed']!.startsWith('0x') ? coin.feed!.slice(2) : coin['feed']),\n\t\t\t);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::oracle::new_coin_type_data_from_currency`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(coin.currencyId!),\n\t\t\t\t\ttx.pure.vector('u8', priceFeedInput),\n\t\t\t\t\ttx.pure.u64(maxConfBps),\n\t\t\t\t\ttx.pure.u64(maxEwmaDifferenceBps),\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 Create a new Pyth config\n\t * @param {Array<{coinKey: string, maxConfBps: number, maxEwmaDifferenceBps: number}>} coinSetups The coins with their oracle config to be added to the Pyth config\n\t * @param {number} maxAgeSeconds The max age in seconds for the Pyth config\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPythConfig =\n\t\t(\n\t\t\tcoinSetups: Array<{ coinKey: string; maxConfBps: number; maxEwmaDifferenceBps: number }>,\n\t\t\tmaxAgeSeconds: number,\n\t\t) =>\n\t\t(tx: Transaction) => {\n\t\t\tconst coinTypeDataList = [];\n\t\t\tfor (const setup of coinSetups) {\n\t\t\t\tcoinTypeDataList.push(\n\t\t\t\t\tthis.newCoinTypeData(setup.coinKey, setup.maxConfBps, setup.maxEwmaDifferenceBps)(tx),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::oracle::new_pyth_config`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.makeMoveVec({\n\t\t\t\t\t\telements: coinTypeDataList,\n\t\t\t\t\t\ttype: `${this.#config.MARGIN_PACKAGE_ID}::oracle::CoinTypeData`,\n\t\t\t\t\t}),\n\t\t\t\t\ttx.pure.u64(maxAgeSeconds),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Mint a pause cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tmintPauseCap = () => (tx: Transaction) => {\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::mint_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Revoke a pause cap\n\t * @param {string} pauseCapId The ID of the pause cap to revoke\n\t * @returns A function that takes a Transaction object\n\t */\n\trevokePauseCap = (pauseCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::revoke_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(this.#marginAdminCap()),\n\t\t\t\ttx.object.clock(),\n\t\t\t\ttx.pure.id(pauseCapId),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Disable a version using pause cap\n\t * @param {number} version The version to disable\n\t * @param {string} pauseCapId The ID of the pause cap\n\t * @returns A function that takes a Transaction object\n\t */\n\tdisableVersionPauseCap = (version: number, pauseCapId: string) => (tx: Transaction) => {\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_registry::disable_version_pause_cap`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(version),\n\t\t\t\ttx.object(pauseCapId),\n\t\t\t],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw the default referral fees (admin only)\n\t * The default referral at 0x0 doesn't have a SupplyReferral object\n\t * @param {string} coinKey The key to identify the margin pool\n\t * @returns A function that takes a Transaction object and returns a Coin<Asset>\n\t */\n\tadminWithdrawDefaultReferralFees = (coinKey: string) => (tx: Transaction) => {\n\t\tconst coin = this.#config.getCoin(coinKey);\n\t\tconst marginPool = this.#config.getMarginPool(coinKey);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_pool::admin_withdraw_default_referral_fees`,\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ACD,CAAC;;2CASiC,aAAqB,OAAoB;GAC5E,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,aAAa,MAAKA,OAAQ,cAAc,QAAQ;AACtD,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW;KACV,GAAG,OAAO,WAAW,QAAQ;KAC7B,GAAG,OAAO,MAAKA,OAAQ,mBAAmB;KAC1C,GAAG,OAAO,MAAKC,gBAAiB,CAAC;KACjC;IACD,eAAe,CAAC,KAAK,KAAK;IAC1B,CAAC;;AAvXF,QAAKD,SAAU;;;;;;CAOhB,kBAAkB;EACjB,MAAM,iBAAiB,MAAKA,OAAQ;AACpC,MAAI,CAAC,eACJ,OAAM,IAAI,MAAM,gDAAgD;AAEjE,SAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"marginLiquidations.d.mts","names":[],"sources":["../../src/transactions/marginLiquidations.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAUa,cAAA,0BAAA,CAA0B;EAMlB,CAAA,OAAA;EAS2C;;;EAwC9C,WAAA,CAAA,MAAA,EAjDG,cAiDH;EAuBX;;;;;gEA/DyD;;;;;;;;;mGAiBzD;;;;;;;;;oGAuBA,gBAAW,0BAAA,CAAA;;;;;;;;;0GAuBX;;;;;;;;;2GAwCA;;;;;;;sDAsC+C,gBAAW,0BAAA,CAAA"}
1
+ {"version":3,"file":"marginLiquidations.d.mts","names":[],"sources":["../../src/transactions/marginLiquidations.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAWa,cAAA,0BAAA,CAA0B;EAMlB,CAAA,OAAA;EAS2C;;;EAwC9C,WAAA,CAAA,MAAA,EAjDG,cAiDH;EAuBX;;;;;gEA/DyD;;;;;;;;;mGAiBzD;;;;;;;;;oGAuBA,gBAAW,0BAAA,CAAA;;;;;;;;;0GAuBX;;;;;;;;;2GAwCA;;;;;;;sDAsC+C,gBAAW,0BAAA,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { convertQuantity } from "../utils/conversion.mjs";
1
2
  import { coinWithBalance } from "@mysten/sui/transactions";
2
3
 
3
4
  //#region src/transactions/marginLiquidations.ts
@@ -20,7 +21,7 @@ var MarginLiquidationsContract = class {
20
21
  const coin = this.#config.getCoin(coinKey);
21
22
  const depositCoin = coinWithBalance({
22
23
  type: coin.type,
23
- balance: amount * coin.scalar
24
+ balance: convertQuantity(amount, coin.scalar)
24
25
  });
25
26
  tx.moveCall({
26
27
  target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::deposit`,
@@ -39,7 +40,7 @@ var MarginLiquidationsContract = class {
39
40
  arguments: [
40
41
  tx.object(vaultId),
41
42
  tx.object(liquidationAdminCap),
42
- tx.pure.u64(amount * coin.scalar)
43
+ tx.pure.u64(convertQuantity(amount, coin.scalar))
43
44
  ],
44
45
  typeArguments: [coin.type]
45
46
  });
@@ -50,7 +51,7 @@ var MarginLiquidationsContract = class {
50
51
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
51
52
  const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
52
53
  const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
53
- const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", BigInt(Math.floor(repayAmount * baseCoin.scalar))) : tx.pure.option("u64", null);
54
+ const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", convertQuantity(repayAmount, baseCoin.scalar)) : tx.pure.option("u64", null);
54
55
  tx.moveCall({
55
56
  target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_base`,
56
57
  arguments: [
@@ -74,7 +75,7 @@ var MarginLiquidationsContract = class {
74
75
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
75
76
  const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
76
77
  const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
77
- const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", BigInt(Math.floor(repayAmount * quoteCoin.scalar))) : tx.pure.option("u64", null);
78
+ const repayAmountArg = repayAmount !== void 0 ? tx.pure.option("u64", convertQuantity(repayAmount, quoteCoin.scalar)) : tx.pure.option("u64", null);
78
79
  tx.moveCall({
79
80
  target: `${this.#config.LIQUIDATION_PACKAGE_ID}::liquidation_vault::liquidate_quote`,
80
81
  arguments: [
@@ -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';\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: 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(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', BigInt(Math.floor(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', BigInt(Math.floor(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":";;;;;;AAUA,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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KA,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":["#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,GA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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,6 +1,6 @@
1
1
  import { InterestConfigParams, MarginPoolConfigParams } from "../types/index.mjs";
2
2
  import { DeepBookConfig } from "../utils/config.mjs";
3
- import * as _mysten_sui_transactions36 from "@mysten/sui/transactions";
3
+ import * as _mysten_sui_transactions58 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_transactions36.TransactionResult;
30
+ newProtocolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams, interestConfig: InterestConfigParams) => (tx: Transaction) => _mysten_sui_transactions58.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_transactions36.TransactionResult;
37
+ newMarginPoolConfig: (coinKey: string, marginPoolConfig: MarginPoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions58.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_transactions36.TransactionResult;
44
+ newMarginPoolConfigWithRateLimit: (coinKey: string, marginPoolConfig: Required<Pick<MarginPoolConfigParams, "rateLimitCapacity" | "rateLimitRefillRatePerMs" | "rateLimitEnabled">> & MarginPoolConfigParams) => (tx: Transaction) => _mysten_sui_transactions58.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_transactions36.TransactionResult;
50
+ newInterestConfig: (interestConfig: InterestConfigParams) => (tx: Transaction) => _mysten_sui_transactions58.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"],"sourcesContent":[],"mappings":";;;;;;;;;AAgBa,cAAA,wBAAA,CAAwB;EAMhB,CAAA,OAAA;EAsB6B;;;EAyB/B,WAAA,CAAA,MAAA,EA/CE,cA+CF;EAEZ;;;;;;EAmDH,gBAAA,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,UAAA,EA9E8C,mBA8E9C,EAAA,GAAA,CAAA,EAAA,EA9E2E,WA8E3E,EAAA,GAAA,IAAA;EADiB;;;;;;;EA2DuC,iBAAA,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,gBAAA,EAhHvC,sBAgHuC,EAAA,cAAA,EA/GzC,oBA+GyC,EAAA,GAAA,CAAA,EAAA,EA7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,gBAAW,0BAAA,CAAA;;;;;;;;uFAqBnB,mCACrD;;;;;;;;wFAwBqD,mCACrD;;;;;;;;yDA0BW,2CACC,8BAEZ;;;;;;;;2DA0BW,6CACG,gCAEd"}
@@ -1,3 +1,4 @@
1
+ import { convertQuantity, convertRate } from "../utils/conversion.mjs";
1
2
  import { FLOAT_SCALAR } from "../utils/config.mjs";
2
3
 
3
4
  //#region src/transactions/marginMaintainer.ts
@@ -42,10 +43,10 @@ var MarginMaintainerContract = class {
42
43
  return tx.moveCall({
43
44
  target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config`,
44
45
  arguments: [
45
- tx.pure.u64(Math.round(supplyCap * coin.scalar)),
46
- tx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),
47
- tx.pure.u64(Math.round(referralSpread * FLOAT_SCALAR)),
48
- tx.pure.u64(Math.round(minBorrow * coin.scalar))
46
+ tx.pure.u64(convertQuantity(supplyCap, coin.scalar)),
47
+ tx.pure.u64(convertRate(maxUtilizationRate, FLOAT_SCALAR)),
48
+ tx.pure.u64(convertRate(referralSpread, FLOAT_SCALAR)),
49
+ tx.pure.u64(convertQuantity(minBorrow, coin.scalar))
49
50
  ]
50
51
  });
51
52
  };
@@ -55,12 +56,12 @@ var MarginMaintainerContract = class {
55
56
  return tx.moveCall({
56
57
  target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_margin_pool_config_with_rate_limit`,
57
58
  arguments: [
58
- tx.pure.u64(Math.round(supplyCap * coin.scalar)),
59
- tx.pure.u64(Math.round(maxUtilizationRate * FLOAT_SCALAR)),
60
- tx.pure.u64(Math.round(referralSpread * FLOAT_SCALAR)),
61
- tx.pure.u64(Math.round(minBorrow * coin.scalar)),
62
- tx.pure.u64(Math.round(rateLimitCapacity * coin.scalar)),
63
- tx.pure.u64(Math.round(rateLimitRefillRatePerMs * coin.scalar)),
59
+ tx.pure.u64(convertQuantity(supplyCap, coin.scalar)),
60
+ tx.pure.u64(convertRate(maxUtilizationRate, FLOAT_SCALAR)),
61
+ tx.pure.u64(convertRate(referralSpread, 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)),
64
65
  tx.pure.bool(rateLimitEnabled)
65
66
  ]
66
67
  });
@@ -70,10 +71,10 @@ var MarginMaintainerContract = class {
70
71
  return tx.moveCall({
71
72
  target: `${this.#config.MARGIN_PACKAGE_ID}::protocol_config::new_interest_config`,
72
73
  arguments: [
73
- tx.pure.u64(Math.round(baseRate * FLOAT_SCALAR)),
74
- tx.pure.u64(Math.round(baseSlope * FLOAT_SCALAR)),
75
- tx.pure.u64(Math.round(optimalUtilization * FLOAT_SCALAR)),
76
- tx.pure.u64(Math.round(excessSlope * FLOAT_SCALAR))
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))
77
78
  ]
78
79
  });
79
80
  };