@mysten/deepbook-v3 1.3.5 → 1.4.0

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 (54) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/contracts/deepbook/account.d.mts +18 -18
  3. package/dist/contracts/deepbook/balances.d.mts +4 -4
  4. package/dist/contracts/deepbook/balances.d.mts.map +1 -1
  5. package/dist/transactions/balanceManager.d.mts +12 -12
  6. package/dist/transactions/deepbook.d.mts +20 -20
  7. package/dist/transactions/deepbookAdmin.d.mts +31 -2
  8. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  9. package/dist/transactions/deepbookAdmin.mjs +34 -2
  10. package/dist/transactions/deepbookAdmin.mjs.map +1 -1
  11. package/dist/transactions/marginAdmin.d.mts +38 -7
  12. package/dist/transactions/marginAdmin.d.mts.map +1 -1
  13. package/dist/transactions/marginAdmin.mjs +48 -0
  14. package/dist/transactions/marginAdmin.mjs.map +1 -1
  15. package/dist/transactions/marginLiquidations.d.mts +3 -3
  16. package/dist/transactions/marginMaintainer.d.mts +5 -5
  17. package/dist/transactions/marginMaintainer.d.mts.map +1 -1
  18. package/dist/transactions/marginMaintainer.mjs +4 -4
  19. package/dist/transactions/marginMaintainer.mjs.map +1 -1
  20. package/dist/transactions/marginManager.d.mts +116 -23
  21. package/dist/transactions/marginManager.d.mts.map +1 -1
  22. package/dist/transactions/marginManager.mjs +133 -1
  23. package/dist/transactions/marginManager.mjs.map +1 -1
  24. package/dist/transactions/marginPool.d.mts +18 -18
  25. package/dist/transactions/marginRegistry.d.mts +15 -15
  26. package/dist/transactions/marginRegistry.d.mts.map +1 -1
  27. package/dist/transactions/marginTPSL.d.mts +14 -11
  28. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  29. package/dist/transactions/marginTPSL.mjs +5 -1
  30. package/dist/transactions/marginTPSL.mjs.map +1 -1
  31. package/dist/transactions/poolProxy.d.mts +19 -9
  32. package/dist/transactions/poolProxy.d.mts.map +1 -1
  33. package/dist/transactions/poolProxy.mjs +31 -21
  34. package/dist/transactions/poolProxy.mjs.map +1 -1
  35. package/dist/types/index.d.mts +1 -1
  36. package/dist/types/index.mjs.map +1 -1
  37. package/dist/utils/config.d.mts +1 -0
  38. package/dist/utils/config.d.mts.map +1 -1
  39. package/dist/utils/config.mjs +3 -0
  40. package/dist/utils/config.mjs.map +1 -1
  41. package/dist/utils/constants.d.mts +3 -0
  42. package/dist/utils/constants.d.mts.map +1 -1
  43. package/dist/utils/constants.mjs +4 -2
  44. package/dist/utils/constants.mjs.map +1 -1
  45. package/package.json +3 -3
  46. package/src/transactions/deepbookAdmin.ts +64 -2
  47. package/src/transactions/marginAdmin.ts +79 -0
  48. package/src/transactions/marginMaintainer.ts +4 -4
  49. package/src/transactions/marginManager.ts +244 -1
  50. package/src/transactions/marginTPSL.ts +10 -3
  51. package/src/transactions/poolProxy.ts +45 -21
  52. package/src/types/index.ts +1 -1
  53. package/src/utils/config.ts +4 -0
  54. package/src/utils/constants.ts +5 -2
@@ -1 +1 @@
1
- {"version":3,"file":"marginTPSL.mjs","names":["#config"],"sources":["../../src/transactions/marginTPSL.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type {\n\tPendingLimitOrderParams,\n\tPendingMarketOrderParams,\n\tAddConditionalOrderParams,\n} from '../types/index.js';\nimport { OrderType, SelfMatchingOptions } from '../types/index.js';\nimport { MAX_TIMESTAMP, FLOAT_SCALAR } from '../utils/config.js';\nimport { convertQuantity, convertPrice } from '../utils/conversion.js';\n\n/**\n * MarginTPSLContract class for managing Take Profit / Stop Loss operations.\n */\nexport class MarginTPSLContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginTPSLContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t// === Helper Functions ===\n\n\t/**\n\t * @description Create a new condition for a conditional order\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {boolean} triggerBelowPrice Whether to trigger when price is below trigger price\n\t * @param {number} triggerPrice The price at which to trigger the order\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewCondition =\n\t\t(poolKey: string, triggerBelowPrice: boolean, triggerPrice: number | bigint) =>\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 inputPrice = convertPrice(\n\t\t\t\ttriggerPrice,\n\t\t\t\tFLOAT_SCALAR,\n\t\t\t\tquoteCoin.scalar,\n\t\t\t\tbaseCoin.scalar,\n\t\t\t);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_condition`,\n\t\t\t\targuments: [tx.pure.bool(triggerBelowPrice), tx.pure.u64(inputPrice)],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new pending limit order for use in conditional orders\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {PendingLimitOrderParams} params Parameters for the pending limit order\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPendingLimitOrder =\n\t\t(poolKey: string, params: PendingLimitOrderParams) => (tx: Transaction) => {\n\t\t\tconst {\n\t\t\t\tclientOrderId,\n\t\t\t\torderType = OrderType.NO_RESTRICTION,\n\t\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\t\tprice,\n\t\t\t\tquantity,\n\t\t\t\tisBid,\n\t\t\t\tpayWithDeep = true,\n\t\t\t\texpireTimestamp = MAX_TIMESTAMP,\n\t\t\t} = params;\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 inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);\n\t\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_pending_limit_order`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\t\ttx.pure.u8(orderType),\n\t\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\t\ttx.pure.u64(inputPrice),\n\t\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\t\ttx.pure.u64(expireTimestamp),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new pending market order for use in conditional orders\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {PendingMarketOrderParams} params Parameters for the pending market order\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPendingMarketOrder =\n\t\t(poolKey: string, params: PendingMarketOrderParams) => (tx: Transaction) => {\n\t\t\tconst {\n\t\t\t\tclientOrderId,\n\t\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\t\tquantity,\n\t\t\t\tisBid,\n\t\t\t\tpayWithDeep = true,\n\t\t\t} = params;\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_pending_market_order`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t// === Public Functions ===\n\n\t/**\n\t * @description Add a conditional order (take profit or stop loss)\n\t * @param {AddConditionalOrderParams} params Parameters for adding the conditional order\n\t * @returns A function that takes a Transaction object\n\t */\n\taddConditionalOrder = (params: AddConditionalOrderParams) => (tx: Transaction) => {\n\t\tconst { marginManagerKey, conditionalOrderId, triggerBelowPrice, triggerPrice, pendingOrder } =\n\t\t\tparams;\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(manager.poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\t// Create condition\n\t\tconst condition = this.newCondition(manager.poolKey, triggerBelowPrice, triggerPrice)(tx);\n\n\t\t// Create pending order based on type\n\t\tconst isLimitOrder = 'price' in pendingOrder;\n\t\tconst pending = isLimitOrder\n\t\t\t? this.newPendingLimitOrder(manager.poolKey, pendingOrder as PendingLimitOrderParams)(tx)\n\t\t\t: this.newPendingMarketOrder(manager.poolKey, pendingOrder as PendingMarketOrderParams)(tx);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::add_conditional_order`,\n\t\t\targuments: [\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(conditionalOrderId),\n\t\t\t\tcondition,\n\t\t\t\tpending,\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 Cancel all conditional orders for a margin manager\n\t * @param {string} marginManagerKey The key to identify the margin manager\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelAllConditionalOrders = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(manager.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_manager::cancel_all_conditional_orders`,\n\t\t\targuments: [tx.object(manager.address), tx.object.clock()],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Cancel a specific conditional order\n\t * @param {string} marginManagerKey The key to identify the margin manager\n\t * @param {string} conditionalOrderId The ID of the conditional order to cancel\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelConditionalOrder =\n\t\t(marginManagerKey: string, conditionalOrderId: string) => (tx: Transaction) => {\n\t\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\t\tconst pool = this.#config.getPool(manager.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_manager::cancel_conditional_order`,\n\t\t\t\targuments: [tx.object(manager.address), tx.pure.u64(conditionalOrderId), tx.object.clock()],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Execute conditional orders that have been triggered\n\t * This is a permissionless function that can be called by anyone\n\t * @param {string} managerAddress The address of the margin manager\n\t * @param {string} poolKey The key to identify the pool (e.g., 'SUI_USDC')\n\t * @param {number} maxOrdersToExecute Maximum number of orders to execute in this call\n\t * @returns A function that takes a Transaction object\n\t */\n\texecuteConditionalOrders =\n\t\t(managerAddress: string, poolKey: string, maxOrdersToExecute: number) => (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\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::execute_conditional_orders`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(managerAddress),\n\t\t\t\t\ttx.object(pool.address),\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(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.u64(maxOrdersToExecute),\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 all conditional order IDs for a margin manager\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The ID of the margin manager\n\t * @returns A function that takes a Transaction object\n\t */\n\tconditionalOrderIds = (poolKey: string, marginManagerId: 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\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::conditional_order_ids`,\n\t\t\targuments: [tx.object(marginManagerId)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get a specific conditional order by ID\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The ID of the margin manager\n\t * @param {string} conditionalOrderId The ID of the conditional order\n\t * @returns A function that takes a Transaction object\n\t */\n\tconditionalOrder =\n\t\t(poolKey: string, marginManagerId: string, conditionalOrderId: string) => (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\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::conditional_order`,\n\t\t\t\targuments: [tx.object(marginManagerId), tx.pure.u64(conditionalOrderId)],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Get the lowest trigger price for trigger_above orders\n\t * Returns constants::max_u64() if there are no trigger_above orders\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The ID of the margin manager\n\t * @returns A function that takes a Transaction object\n\t */\n\tlowestTriggerAbovePrice = (poolKey: string, marginManagerId: 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\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::lowest_trigger_above_price`,\n\t\t\targuments: [tx.object(marginManagerId)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the highest trigger price for trigger_below orders\n\t * Returns 0 if there are no trigger_below orders\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The ID of the margin manager\n\t * @returns A function that takes a Transaction object\n\t */\n\thighestTriggerBelowPrice = (poolKey: string, marginManagerId: 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\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PAC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AAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;AACtD,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW,CAAC,GAAG,OAAO,gBAAgB,CAAC;IACvC,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;mCAUyB,SAAiB,qBAA6B,OAAoB;GAC7F,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;AACtD,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW,CAAC,GAAG,OAAO,gBAAgB,CAAC;IACvC,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;AAlRF,QAAKA,SAAU"}
1
+ {"version":3,"file":"marginTPSL.mjs","names":["#config"],"sources":["../../src/transactions/marginTPSL.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport type {\n\tPendingLimitOrderParams,\n\tPendingMarketOrderParams,\n\tAddConditionalOrderParams,\n} from '../types/index.js';\nimport { OrderType, SelfMatchingOptions } from '../types/index.js';\nimport { MAX_TIMESTAMP, FLOAT_SCALAR } from '../utils/config.js';\nimport { convertQuantity, convertPrice } from '../utils/conversion.js';\n\n/**\n * MarginTPSLContract class for managing Take Profit / Stop Loss operations.\n */\nexport class MarginTPSLContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for MarginTPSLContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t// === Helper Functions ===\n\n\t/**\n\t * @description Create a new condition for a conditional order\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {boolean} triggerBelowPrice Whether to trigger when price is below trigger price\n\t * @param {number} triggerPrice The price at which to trigger the order\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewCondition =\n\t\t(poolKey: string, triggerBelowPrice: boolean, triggerPrice: number | bigint) =>\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 inputPrice = convertPrice(\n\t\t\t\ttriggerPrice,\n\t\t\t\tFLOAT_SCALAR,\n\t\t\t\tquoteCoin.scalar,\n\t\t\t\tbaseCoin.scalar,\n\t\t\t);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_condition`,\n\t\t\t\targuments: [tx.pure.bool(triggerBelowPrice), tx.pure.u64(inputPrice)],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new pending limit order for use in conditional orders\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {PendingLimitOrderParams} params Parameters for the pending limit order\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPendingLimitOrder =\n\t\t(poolKey: string, params: PendingLimitOrderParams) => (tx: Transaction) => {\n\t\t\tconst {\n\t\t\t\tclientOrderId,\n\t\t\t\torderType = OrderType.NO_RESTRICTION,\n\t\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\t\tprice,\n\t\t\t\tquantity,\n\t\t\t\tisBid,\n\t\t\t\tpayWithDeep = true,\n\t\t\t\texpireTimestamp = MAX_TIMESTAMP,\n\t\t\t} = params;\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 inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);\n\t\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_pending_limit_order`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\t\ttx.pure.u8(orderType),\n\t\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\t\ttx.pure.u64(inputPrice),\n\t\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\t\ttx.pure.u64(expireTimestamp),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Create a new pending market order for use in conditional orders\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {PendingMarketOrderParams} params Parameters for the pending market order\n\t * @returns A function that takes a Transaction object\n\t */\n\tnewPendingMarketOrder =\n\t\t(poolKey: string, params: PendingMarketOrderParams) => (tx: Transaction) => {\n\t\t\tconst {\n\t\t\t\tclientOrderId,\n\t\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\t\tquantity,\n\t\t\t\tisBid,\n\t\t\t\tpayWithDeep = true,\n\t\t\t} = params;\n\t\t\tconst pool = this.#config.getPool(poolKey);\n\t\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::tpsl::new_pending_market_order`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\t],\n\t\t\t});\n\t\t};\n\n\t// === Public Functions ===\n\n\t/**\n\t * @description Add a conditional order (take profit or stop loss)\n\t * @param {AddConditionalOrderParams} params Parameters for adding the conditional order\n\t * @returns A function that takes a Transaction object\n\t */\n\taddConditionalOrder = (params: AddConditionalOrderParams) => (tx: Transaction) => {\n\t\tconst { marginManagerKey, conditionalOrderId, triggerBelowPrice, triggerPrice, pendingOrder } =\n\t\t\tparams;\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(manager.poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\n\t\t// Create condition\n\t\tconst condition = this.newCondition(manager.poolKey, triggerBelowPrice, triggerPrice)(tx);\n\n\t\t// Create pending order based on type\n\t\tconst isLimitOrder = 'price' in pendingOrder;\n\t\tconst pending = isLimitOrder\n\t\t\t? this.newPendingLimitOrder(manager.poolKey, pendingOrder as PendingLimitOrderParams)(tx)\n\t\t\t: this.newPendingMarketOrder(manager.poolKey, pendingOrder as PendingMarketOrderParams)(tx);\n\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::add_conditional_order`,\n\t\t\targuments: [\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.pure.u64(conditionalOrderId),\n\t\t\t\tcondition,\n\t\t\t\tpending,\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 Cancel all conditional orders for a margin manager\n\t * @param {string} marginManagerKey The key to identify the margin manager\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelAllConditionalOrders = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(manager.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_manager::cancel_all_conditional_orders`,\n\t\t\targuments: [tx.object(manager.address), tx.object.clock()],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Cancel a specific conditional order\n\t * @param {string} marginManagerKey The key to identify the margin manager\n\t * @param {string} conditionalOrderId The ID of the conditional order to cancel\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelConditionalOrder =\n\t\t(marginManagerKey: string, conditionalOrderId: string) => (tx: Transaction) => {\n\t\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\t\tconst pool = this.#config.getPool(manager.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_manager::cancel_conditional_order`,\n\t\t\t\targuments: [tx.object(manager.address), tx.pure.u64(conditionalOrderId), tx.object.clock()],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Execute conditional orders that have been triggered.\n\t * Permissionless — anyone can call this. After the inner fill loop, the\n\t * manager's post-trade `risk_ratio` is checked against\n\t * `min_borrow_risk_ratio`; if any triggered fill breaches that floor, the\n\t * whole txn aborts (no partial-state landing).\n\t * @param {string} managerAddress The address of the margin manager\n\t * @param {string} poolKey The key to identify the pool (e.g., 'SUI_USDC')\n\t * @param {number} maxOrdersToExecute Maximum number of orders to execute in this call\n\t * @returns A function that takes a Transaction object\n\t */\n\texecuteConditionalOrders =\n\t\t(managerAddress: string, poolKey: string, maxOrdersToExecute: number) => (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\t\t\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::execute_conditional_orders_v2`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(managerAddress),\n\t\t\t\t\ttx.object(pool.address),\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(baseCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.pure.u64(maxOrdersToExecute),\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 all conditional order IDs for a margin manager\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The ID of the margin manager\n\t * @returns A function that takes a Transaction object\n\t */\n\tconditionalOrderIds = (poolKey: string, marginManagerId: 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\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::conditional_order_ids`,\n\t\t\targuments: [tx.object(marginManagerId)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get a specific conditional order by ID\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The ID of the margin manager\n\t * @param {string} conditionalOrderId The ID of the conditional order\n\t * @returns A function that takes a Transaction object\n\t */\n\tconditionalOrder =\n\t\t(poolKey: string, marginManagerId: string, conditionalOrderId: string) => (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\treturn tx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::conditional_order`,\n\t\t\t\targuments: [tx.object(marginManagerId), tx.pure.u64(conditionalOrderId)],\n\t\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t\t});\n\t\t};\n\n\t/**\n\t * @description Get the lowest trigger price for trigger_above orders\n\t * Returns constants::max_u64() if there are no trigger_above orders\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The ID of the margin manager\n\t * @returns A function that takes a Transaction object\n\t */\n\tlowestTriggerAbovePrice = (poolKey: string, marginManagerId: 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\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::lowest_trigger_above_price`,\n\t\t\targuments: [tx.object(marginManagerId)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Get the highest trigger price for trigger_below orders\n\t * Returns 0 if there are no trigger_below orders\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The ID of the margin manager\n\t * @returns A function that takes a Transaction object\n\t */\n\thighestTriggerBelowPrice = (poolKey: string, marginManagerId: 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\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::highest_trigger_below_price`,\n\t\t\targuments: [tx.object(marginManagerId)],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;;;AAiBA,IAAa,qBAAb,MAAgC;CAC/B;;;;CAKA,YAAY,QAAwB;uBAclC,SAAiB,mBAA4B,kBAC7C,OAAoB;GACpB,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GAEpD,MAAM,aAAa,aAClB,cACA,cAHiB,MAAKA,OAAQ,QAAQ,KAAK,UAAU,CAI3C,QACV,SAAS,OACT;AACD,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW,CAAC,GAAG,KAAK,KAAK,kBAAkB,EAAE,GAAG,KAAK,IAAI,WAAW,CAAC;IACrE,CAAC;;+BAUF,SAAiB,YAAqC,OAAoB;GAC1E,MAAM,EACL,eACA,YAAY,UAAU,gBACtB,qBAAqB,oBAAoB,uBACzC,OACA,UACA,OACA,cAAc,MACd,kBAAkB,kBACf;GACJ,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GAEpD,MAAM,aAAa,aAAa,OAAO,cADrB,MAAKA,OAAQ,QAAQ,KAAK,UAAU,CACS,QAAQ,SAAS,OAAO;GACvF,MAAM,gBAAgB,gBAAgB,UAAU,SAAS,OAAO;AAChE,UAAO,GAAG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KA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;AACtD,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW,CAAC,GAAG,OAAO,gBAAgB,EAAE,GAAG,KAAK,IAAI,mBAAmB,CAAC;IACxE,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;kCAUuB,SAAiB,qBAA6B,OAAoB;GAC5F,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;AACtD,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW,CAAC,GAAG,OAAO,gBAAgB,CAAC;IACvC,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;mCAUyB,SAAiB,qBAA6B,OAAoB;GAC7F,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;AACtD,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW,CAAC,GAAG,OAAO,gBAAgB,CAAC;IACvC,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;AAzRF,QAAKA,SAAU"}
@@ -1,6 +1,6 @@
1
1
  import { MarginProposalParams, PlaceMarginLimitOrderParams, PlaceMarginMarketOrderParams } from "../types/index.mjs";
2
2
  import { DeepBookConfig } from "../utils/config.mjs";
3
- import * as _mysten_sui_transactions79 from "@mysten/sui/transactions";
3
+ import * as _mysten_sui_transactions90 from "@mysten/sui/transactions";
4
4
  import { Transaction } from "@mysten/sui/transactions";
5
5
 
6
6
  //#region src/transactions/poolProxy.d.ts
@@ -14,29 +14,39 @@ declare class PoolProxyContract {
14
14
  */
15
15
  constructor(config: DeepBookConfig);
16
16
  /**
17
- * @description Place a limit order
17
+ * @description Place a limit order. Enforces a post-trade `risk_ratio >=
18
+ * min_borrow_risk_ratio` invariant on the manager (skipped when the manager
19
+ * has no debt).
18
20
  * @param {PlaceMarginLimitOrderParams} params Parameters for placing a limit order
19
21
  * @returns A function that takes a Transaction object
20
22
  */
21
- placeLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions79.TransactionResult;
23
+ placeLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions90.TransactionResult;
22
24
  /**
23
- * @description Place a market order
25
+ * @description Place a market order. Enforces a post-trade `risk_ratio >=
26
+ * min_borrow_risk_ratio` invariant on the manager (skipped when the manager
27
+ * has no debt).
24
28
  * @param {PlaceMarginMarketOrderParams} params Parameters for placing a market order
25
29
  * @returns A function that takes a Transaction object
26
30
  */
27
- placeMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions79.TransactionResult;
31
+ placeMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions90.TransactionResult;
28
32
  /**
29
- * @description Place a reduce only limit order
33
+ * @description Place a reduce only limit order. Requires the manager to have
34
+ * debt on the relevant side; enforces a monotonic `risk_ratio_after >=
35
+ * risk_ratio_before` invariant so the fill cannot leak value to the
36
+ * counterparty.
30
37
  * @param {PlaceMarginLimitOrderParams} params Parameters for placing a reduce only limit order
31
38
  * @returns A function that takes a Transaction object
32
39
  */
33
- placeReduceOnlyLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions79.TransactionResult;
40
+ placeReduceOnlyLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions90.TransactionResult;
34
41
  /**
35
- * @description Place a reduce only market order
42
+ * @description Place a reduce only market order. Requires the manager to
43
+ * have debt on the relevant side; enforces a monotonic `risk_ratio_after >=
44
+ * risk_ratio_before` invariant so the fill cannot leak value to the
45
+ * counterparty.
36
46
  * @param {PlaceMarginMarketOrderParams} params Parameters for placing a reduce only market order
37
47
  * @returns A function that takes a Transaction object
38
48
  */
39
- placeReduceOnlyMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions79.TransactionResult;
49
+ placeReduceOnlyMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions90.TransactionResult;
40
50
  /**
41
51
  * @description Modify an existing order
42
52
  * @param {string} marginManagerKey The key to identify the MarginManager
@@ -1 +1 @@
1
- {"version":3,"file":"poolProxy.d.mts","names":[],"sources":["../../src/transactions/poolProxy.ts"],"mappings":";;;;;;;;;cAiBa,iBAAA;EAAA;;;;cAMA,MAAA,EAAQ,cAAA;EASuD;;;;;EAA3E,eAAA,GAAmB,MAAA,EAAQ,2BAAA,MAAiC,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;EAiFU;;;;;EArCrF,gBAAA,GAAoB,MAAA,EAAQ,4BAAA,MAAkC,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;EAsLP;;;;;EAjJtE,yBAAA,GAA6B,MAAA,EAAQ,2BAAA,MAAiC,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;EAmQnB;;;;;EAlNlE,0BAAA,GAA8B,MAAA,EAAQ,4BAAA,MAAkC,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;EAgT7B;;;;;;;EApQ1D,WAAA,GACE,gBAAA,UAA0B,OAAA,UAAiB,WAAA,cAAyB,EAAA,EAAI,WAAA;EA/KV;;;;;;EA0MhE,WAAA,GAAe,gBAAA,UAA0B,OAAA,c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AAA;;;;;;;;;EAqDrF,0BAAA,GAA8B,MAAA,EAAQ,4BAAA,MAAkC,EAAA,EAAI,WAAA,KAAW,0BAAA,CAAA,iBAAA;EAvJZ;;;;;;;EAoM3E,WAAA,GACE,gBAAA,UAA0B,OAAA,UAAiB,WAAA,cAAyB,EAAA,EAAI,WAAA;EAnGrC;;;;;;EA8HrC,WAAA,GAAe,gBAAA,UAA0B,OAAA,cAAqB,EAAA,EAAI,WAAA;EAzEpC;;;;;;EAiG9B,YAAA,GAAgB,gBAAA,UAA0B,QAAA,gBAAwB,EAAA,EAAI,WAAA;EAnDzB;;;;;EA0E7C,eAAA,GAAmB,gBAAA,cAA8B,EAAA,EAAI,WAAA;EA/Ca;;;;;EAqElE,sBAAA,GAA0B,gBAAA,cAA8B,EAAA,EAAI,WAAA;EA7CM;;;;;;EAmElE,KAAA,GAAS,gBAAA,UAA0B,WAAA,cAAyB,EAAA,EAAI,WAAA;EAtBJ;;;;;EA8C5D,OAAA,GAAW,gBAAA,cAA8B,EAAA,EAAI,WAAA;EAxBe;;;;;;EA8C5D,cAAA,GACE,gBAAA,UAA0B,MAAA,EAAQ,oBAAA,MAA0B,EAAA,EAAI,WAAA;EAA9B;;;;;;EA6BpC,IAAA,GAAQ,gBAAA,UAA0B,UAAA,cAAwB,EAAA,EAAI,WAAA;EAAA;;;;;EAsB9D,WAAA,GAAe,gBAAA,cAA8B,EAAA,EAAI,WAAA;EAsBjD;;;;;;EAAA,4BAAA,GACE,OAAA,UAAiB,eAAA,cAA6B,EAAA,EAAI,WAAA;EAoBL;;;;;EAA/C,kBAAA,GAAsB,OAAA,cAAqB,EAAA,EAAI,WAAA;AAAA"}
@@ -18,14 +18,20 @@ var PoolProxyContract = class {
18
18
  const manager = this.#config.getMarginManager(marginManagerKey);
19
19
  const baseCoin = this.#config.getCoin(pool.baseCoin);
20
20
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
21
+ const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
22
+ const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
21
23
  const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
22
24
  const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
23
25
  return tx.moveCall({
24
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_limit_order`,
26
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_limit_order_v2`,
25
27
  arguments: [
26
28
  tx.object(this.#config.MARGIN_REGISTRY_ID),
27
29
  tx.object(manager.address),
28
30
  tx.object(pool.address),
31
+ tx.object(baseMarginPool.address),
32
+ tx.object(quoteMarginPool.address),
33
+ tx.object(baseCoin.priceInfoObjectId),
34
+ tx.object(quoteCoin.priceInfoObjectId),
29
35
  tx.pure.u64(clientOrderId),
30
36
  tx.pure.u8(orderType),
31
37
  tx.pure.u8(selfMatchingOption),
@@ -45,13 +51,19 @@ var PoolProxyContract = class {
45
51
  const manager = this.#config.getMarginManager(marginManagerKey);
46
52
  const baseCoin = this.#config.getCoin(pool.baseCoin);
47
53
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
54
+ const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
55
+ const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
48
56
  const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
49
57
  return tx.moveCall({
50
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_market_order`,
58
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_market_order_v2`,
51
59
  arguments: [
52
60
  tx.object(this.#config.MARGIN_REGISTRY_ID),
53
61
  tx.object(manager.address),
54
62
  tx.object(pool.address),
63
+ tx.object(baseMarginPool.address),
64
+ tx.object(quoteMarginPool.address),
65
+ tx.object(baseCoin.priceInfoObjectId),
66
+ tx.object(quoteCoin.priceInfoObjectId),
55
67
  tx.pure.u64(clientOrderId),
56
68
  tx.pure.u8(selfMatchingOption),
57
69
  tx.pure.u64(inputQuantity),
@@ -68,17 +80,20 @@ var PoolProxyContract = class {
68
80
  const manager = this.#config.getMarginManager(marginManagerKey);
69
81
  const baseCoin = this.#config.getCoin(pool.baseCoin);
70
82
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
83
+ const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
84
+ const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
71
85
  const inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);
72
86
  const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
73
- const marginPool = isBid ? this.#config.getMarginPool(pool.baseCoin) : this.#config.getMarginPool(pool.quoteCoin);
74
- const debtType = isBid ? baseCoin.type : quoteCoin.type;
75
87
  return tx.moveCall({
76
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_limit_order`,
88
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_limit_order_v2`,
77
89
  arguments: [
78
90
  tx.object(this.#config.MARGIN_REGISTRY_ID),
79
91
  tx.object(manager.address),
80
92
  tx.object(pool.address),
81
- tx.object(marginPool.address),
93
+ tx.object(baseMarginPool.address),
94
+ tx.object(quoteMarginPool.address),
95
+ tx.object(baseCoin.priceInfoObjectId),
96
+ tx.object(quoteCoin.priceInfoObjectId),
82
97
  tx.pure.u64(clientOrderId),
83
98
  tx.pure.u8(orderType),
84
99
  tx.pure.u8(selfMatchingOption),
@@ -89,11 +104,7 @@ var PoolProxyContract = class {
89
104
  tx.pure.u64(expiration),
90
105
  tx.object.clock()
91
106
  ],
92
- typeArguments: [
93
- baseCoin.type,
94
- quoteCoin.type,
95
- debtType
96
- ]
107
+ typeArguments: [baseCoin.type, quoteCoin.type]
97
108
  });
98
109
  };
99
110
  this.placeReduceOnlyMarketOrder = (params) => (tx) => {
@@ -102,16 +113,19 @@ var PoolProxyContract = class {
102
113
  const manager = this.#config.getMarginManager(marginManagerKey);
103
114
  const baseCoin = this.#config.getCoin(pool.baseCoin);
104
115
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
116
+ const baseMarginPool = this.#config.getMarginPool(pool.baseCoin);
117
+ const quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);
105
118
  const inputQuantity = convertQuantity(quantity, baseCoin.scalar);
106
- const marginPool = isBid ? this.#config.getMarginPool(pool.baseCoin) : this.#config.getMarginPool(pool.quoteCoin);
107
- const debtType = isBid ? baseCoin.type : quoteCoin.type;
108
119
  return tx.moveCall({
109
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_market_order`,
120
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_market_order_v2`,
110
121
  arguments: [
111
122
  tx.object(this.#config.MARGIN_REGISTRY_ID),
112
123
  tx.object(manager.address),
113
124
  tx.object(pool.address),
114
- tx.object(marginPool.address),
125
+ tx.object(baseMarginPool.address),
126
+ tx.object(quoteMarginPool.address),
127
+ tx.object(baseCoin.priceInfoObjectId),
128
+ tx.object(quoteCoin.priceInfoObjectId),
115
129
  tx.pure.u64(clientOrderId),
116
130
  tx.pure.u8(selfMatchingOption),
117
131
  tx.pure.u64(inputQuantity),
@@ -119,11 +133,7 @@ var PoolProxyContract = class {
119
133
  tx.pure.bool(payWithDeep),
120
134
  tx.object.clock()
121
135
  ],
122
- typeArguments: [
123
- baseCoin.type,
124
- quoteCoin.type,
125
- debtType
126
- ]
136
+ typeArguments: [baseCoin.type, quoteCoin.type]
127
137
  });
128
138
  };
129
139
  this.modifyOrder = (marginManagerKey, orderId, newQuantity) => (tx) => {
@@ -286,7 +296,7 @@ var PoolProxyContract = class {
286
296
  const baseCoin = this.#config.getCoin(pool.baseCoin);
287
297
  const quoteCoin = this.#config.getCoin(pool.quoteCoin);
288
298
  tx.moveCall({
289
- target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::claim_rebate`,
299
+ target: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::claim_rebates`,
290
300
  arguments: [
291
301
  tx.object(this.#config.MARGIN_REGISTRY_ID),
292
302
  tx.object(marginManager.address),
@@ -1 +1 @@
1
- {"version":3,"file":"poolProxy.mjs","names":["#config"],"sources":["../../src/transactions/poolProxy.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\nimport type {\n\tPlaceMarginLimitOrderParams,\n\tPlaceMarginMarketOrderParams,\n\tMarginProposalParams,\n} from '../types/index.js';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { OrderType, SelfMatchingOptions } from '../types/index.js';\nimport { MAX_TIMESTAMP, FLOAT_SCALAR } from '../utils/config.js';\nimport { convertQuantity, convertPrice, convertRate } from '../utils/conversion.js';\n\n/**\n * PoolProxyContract class for managing PoolProxy operations.\n */\nexport class PoolProxyContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for PoolProxyContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Place a limit order\n\t * @param {PlaceMarginLimitOrderParams} params Parameters for placing a limit order\n\t * @returns A function that takes a Transaction object\n\t */\n\tplaceLimitOrder = (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => {\n\t\tconst {\n\t\t\tpoolKey,\n\t\t\tmarginManagerKey,\n\t\t\tclientOrderId,\n\t\t\tprice,\n\t\t\tquantity,\n\t\t\tisBid,\n\t\t\texpiration = MAX_TIMESTAMP,\n\t\t\torderType = OrderType.NO_RESTRICTION,\n\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\tpayWithDeep = true,\n\t\t} = params;\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);\n\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_limit_order`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\ttx.pure.u8(orderType),\n\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\ttx.pure.u64(inputPrice),\n\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\ttx.pure.u64(expiration),\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 Place a market order\n\t * @param {PlaceMarginMarketOrderParams} params Parameters for placing a market order\n\t * @returns A function that takes a Transaction object\n\t */\n\tplaceMarketOrder = (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => {\n\t\tconst {\n\t\t\tpoolKey,\n\t\t\tmarginManagerKey,\n\t\t\tclientOrderId,\n\t\t\tquantity,\n\t\t\tisBid,\n\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\tpayWithDeep = true,\n\t\t} = params;\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_market_order`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\ttx.pure.bool(payWithDeep),\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 Place a reduce only limit order\n\t * @param {PlaceMarginLimitOrderParams} params Parameters for placing a reduce only limit order\n\t * @returns A function that takes a Transaction object\n\t */\n\tplaceReduceOnlyLimitOrder = (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => {\n\t\tconst {\n\t\t\tpoolKey,\n\t\t\tmarginManagerKey,\n\t\t\tclientOrderId,\n\t\t\tprice,\n\t\t\tquantity,\n\t\t\tisBid,\n\t\t\texpiration = MAX_TIMESTAMP,\n\t\t\torderType = OrderType.NO_RESTRICTION,\n\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\tpayWithDeep = true,\n\t\t} = params;\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);\n\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\tconst marginPool = isBid\n\t\t\t? this.#config.getMarginPool(pool.baseCoin)\n\t\t\t: this.#config.getMarginPool(pool.quoteCoin);\n\t\tconst debtType = isBid ? baseCoin.type : quoteCoin.type;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_limit_order`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\ttx.pure.u8(orderType),\n\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\ttx.pure.u64(inputPrice),\n\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\ttx.pure.u64(expiration),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type, debtType],\n\t\t});\n\t};\n\n\t/**\n\t * @description Place a reduce only market order\n\t * @param {PlaceMarginMarketOrderParams} params Parameters for placing a reduce only market order\n\t * @returns A function that takes a Transaction object\n\t */\n\tplaceReduceOnlyMarketOrder = (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => {\n\t\tconst {\n\t\t\tpoolKey,\n\t\t\tmarginManagerKey,\n\t\t\tclientOrderId,\n\t\t\tquantity,\n\t\t\tisBid,\n\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\tpayWithDeep = true,\n\t\t} = params;\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\tconst marginPool = isBid\n\t\t\t? this.#config.getMarginPool(pool.baseCoin)\n\t\t\t: this.#config.getMarginPool(pool.quoteCoin);\n\t\tconst debtType = isBid ? baseCoin.type : quoteCoin.type;\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_market_order`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(marginPool.address),\n\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\ttx.object.clock(),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type, debtType],\n\t\t});\n\t};\n\n\t/**\n\t * @description Modify an existing order\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {string} orderId Order ID to modify\n\t * @param {number} newQuantity New quantity for the order\n\t * @returns A function that takes a Transaction object\n\t */\n\tmodifyOrder =\n\t\t(marginManagerKey: string, orderId: string, newQuantity: number) => (tx: Transaction) => {\n\t\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\t\tconst pool = this.#config.getPool(marginManager.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 inputQuantity = convertQuantity(newQuantity, baseCoin.scalar);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::modify_order`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(marginManager.address),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\ttx.pure.u128(orderId),\n\t\t\t\t\ttx.pure.u64(inputQuantity),\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 Cancel an existing order\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {string} orderId Order ID to cancel\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelOrder = (marginManagerKey: string, orderId: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::cancel_order`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.u128(orderId),\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 Cancel multiple existing orders\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {string[]} orderIds Order IDs to cancel\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelOrders = (marginManagerKey: string, orderIds: string[]) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::cancel_orders`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.vector('u128', orderIds),\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 Cancel all existing orders\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelAllOrders = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::cancel_all_orders`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\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 Withdraw settled amounts\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawSettledAmounts = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::withdraw_settled_amounts`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Stake in the pool\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {number} stakeAmount The amount to stake\n\t * @returns A function that takes a Transaction object\n\t */\n\tstake = (marginManagerKey: string, stakeAmount: number) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst deepCoin = this.#config.getCoin('DEEP');\n\t\tconst stakeInput = convertQuantity(stakeAmount, deepCoin.scalar);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::stake`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.u64(stakeInput),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Unstake from the pool\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tunstake = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::unstake`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Submit a proposal\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {MarginProposalParams} params Parameters for the proposal\n\t * @returns A function that takes a Transaction object\n\t */\n\tsubmitProposal =\n\t\t(marginManagerKey: string, params: MarginProposalParams) => (tx: Transaction) => {\n\t\t\tconst { takerFee, makerFee, stakeRequired } = params;\n\t\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\t\tconst pool = this.#config.getPool(marginManager.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 stakeInput = convertRate(stakeRequired, FLOAT_SCALAR);\n\t\t\tconst takerFeeInput = convertRate(takerFee, FLOAT_SCALAR);\n\t\t\tconst makerFeeInput = convertRate(makerFee, FLOAT_SCALAR);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::submit_proposal`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(marginManager.address),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\ttx.pure.u64(takerFeeInput),\n\t\t\t\t\ttx.pure.u64(makerFeeInput),\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 Vote on a proposal\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {string} proposalId The ID of the proposal to vote on\n\t * @returns A function that takes a Transaction object\n\t */\n\tvote = (marginManagerKey: string, proposalId: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::vote`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.id(proposalId),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Claim a rebate from a pool\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tclaimRebate = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::claim_rebate`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw settled amounts permissionlessly for a margin manager by ID\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The object ID of the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawMarginSettledAmounts =\n\t\t(poolKey: string, marginManagerId: string) => (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}::pool_proxy::withdraw_settled_amounts_permissionless`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(marginManagerId),\n\t\t\t\t\ttx.object(pool.address),\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 Update the current price for a pool using Pyth oracle\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateCurrentPrice = (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\tif (!baseCoin.priceInfoObjectId) {\n\t\t\tthrow new Error(`Missing priceInfoObjectId for ${pool.baseCoin}`);\n\t\t}\n\t\tif (!quoteCoin.priceInfoObjectId) {\n\t\t\tthrow new Error(`Missing priceInfoObjectId for ${pool.quoteCoin}`);\n\t\t}\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::update_current_price`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(baseCoin.priceInfoObjectId),\n\t\t\t\ttx.object(quoteCoin.priceInfoObjectId),\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"],"mappings":";;;;;;;;AAiBA,IAAa,oBAAb,MAA+B;CAC9B;;;;CAKA,YAAY,QAAwB;0BASjB,YAAyC,OAAoB;GAC/E,MAAM,EACL,SACA,kBACA,eACA,OACA,UACA,OACA,aAAa,eACb,YAAY,UAAU,gBACtB,qBAAqB,oBAAoB,uBACzC,cAAc,SACX;GACJ,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,UAAU,MAAKA,OAAQ,iBAAiB,iBAAiB;GAC/D,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;GACtD,M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AAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;AA9cF,QAAKA,SAAU"}
1
+ {"version":3,"file":"poolProxy.mjs","names":["#config"],"sources":["../../src/transactions/poolProxy.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction } from '@mysten/sui/transactions';\nimport type {\n\tPlaceMarginLimitOrderParams,\n\tPlaceMarginMarketOrderParams,\n\tMarginProposalParams,\n} from '../types/index.js';\n\nimport type { DeepBookConfig } from '../utils/config.js';\nimport { OrderType, SelfMatchingOptions } from '../types/index.js';\nimport { MAX_TIMESTAMP, FLOAT_SCALAR } from '../utils/config.js';\nimport { convertQuantity, convertPrice, convertRate } from '../utils/conversion.js';\n\n/**\n * PoolProxyContract class for managing PoolProxy operations.\n */\nexport class PoolProxyContract {\n\t#config: DeepBookConfig;\n\n\t/**\n\t * @param {DeepBookConfig} config Configuration for PoolProxyContract\n\t */\n\tconstructor(config: DeepBookConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * @description Place a limit order. Enforces a post-trade `risk_ratio >=\n\t * min_borrow_risk_ratio` invariant on the manager (skipped when the manager\n\t * has no debt).\n\t * @param {PlaceMarginLimitOrderParams} params Parameters for placing a limit order\n\t * @returns A function that takes a Transaction object\n\t */\n\tplaceLimitOrder = (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => {\n\t\tconst {\n\t\t\tpoolKey,\n\t\t\tmarginManagerKey,\n\t\t\tclientOrderId,\n\t\t\tprice,\n\t\t\tquantity,\n\t\t\tisBid,\n\t\t\texpiration = MAX_TIMESTAMP,\n\t\t\torderType = OrderType.NO_RESTRICTION,\n\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\tpayWithDeep = true,\n\t\t} = params;\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\t\tconst inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);\n\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_limit_order_v2`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(baseMarginPool.address),\n\t\t\t\ttx.object(quoteMarginPool.address),\n\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\ttx.pure.u8(orderType),\n\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\ttx.pure.u64(inputPrice),\n\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\ttx.pure.u64(expiration),\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 Place a market order. Enforces a post-trade `risk_ratio >=\n\t * min_borrow_risk_ratio` invariant on the manager (skipped when the manager\n\t * has no debt).\n\t * @param {PlaceMarginMarketOrderParams} params Parameters for placing a market order\n\t * @returns A function that takes a Transaction object\n\t */\n\tplaceMarketOrder = (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => {\n\t\tconst {\n\t\t\tpoolKey,\n\t\t\tmarginManagerKey,\n\t\t\tclientOrderId,\n\t\t\tquantity,\n\t\t\tisBid,\n\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\tpayWithDeep = true,\n\t\t} = params;\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_market_order_v2`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(baseMarginPool.address),\n\t\t\t\ttx.object(quoteMarginPool.address),\n\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\ttx.pure.bool(payWithDeep),\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 Place a reduce only limit order. Requires the manager to have\n\t * debt on the relevant side; enforces a monotonic `risk_ratio_after >=\n\t * risk_ratio_before` invariant so the fill cannot leak value to the\n\t * counterparty.\n\t * @param {PlaceMarginLimitOrderParams} params Parameters for placing a reduce only limit order\n\t * @returns A function that takes a Transaction object\n\t */\n\tplaceReduceOnlyLimitOrder = (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => {\n\t\tconst {\n\t\t\tpoolKey,\n\t\t\tmarginManagerKey,\n\t\t\tclientOrderId,\n\t\t\tprice,\n\t\t\tquantity,\n\t\t\tisBid,\n\t\t\texpiration = MAX_TIMESTAMP,\n\t\t\torderType = OrderType.NO_RESTRICTION,\n\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\tpayWithDeep = true,\n\t\t} = params;\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\t\tconst inputPrice = convertPrice(price, FLOAT_SCALAR, quoteCoin.scalar, baseCoin.scalar);\n\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_limit_order_v2`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(baseMarginPool.address),\n\t\t\t\ttx.object(quoteMarginPool.address),\n\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\ttx.pure.u8(orderType),\n\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\ttx.pure.u64(inputPrice),\n\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\ttx.pure.bool(payWithDeep),\n\t\t\t\ttx.pure.u64(expiration),\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 Place a reduce only market order. Requires the manager to\n\t * have debt on the relevant side; enforces a monotonic `risk_ratio_after >=\n\t * risk_ratio_before` invariant so the fill cannot leak value to the\n\t * counterparty.\n\t * @param {PlaceMarginMarketOrderParams} params Parameters for placing a reduce only market order\n\t * @returns A function that takes a Transaction object\n\t */\n\tplaceReduceOnlyMarketOrder = (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => {\n\t\tconst {\n\t\t\tpoolKey,\n\t\t\tmarginManagerKey,\n\t\t\tclientOrderId,\n\t\t\tquantity,\n\t\t\tisBid,\n\t\t\tselfMatchingOption = SelfMatchingOptions.SELF_MATCHING_ALLOWED,\n\t\t\tpayWithDeep = true,\n\t\t} = params;\n\t\tconst pool = this.#config.getPool(poolKey);\n\t\tconst manager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst baseMarginPool = this.#config.getMarginPool(pool.baseCoin);\n\t\tconst quoteMarginPool = this.#config.getMarginPool(pool.quoteCoin);\n\t\tconst inputQuantity = convertQuantity(quantity, baseCoin.scalar);\n\t\treturn tx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::place_reduce_only_market_order_v2`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(manager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(baseMarginPool.address),\n\t\t\t\ttx.object(quoteMarginPool.address),\n\t\t\t\ttx.object(baseCoin.priceInfoObjectId!),\n\t\t\t\ttx.object(quoteCoin.priceInfoObjectId!),\n\t\t\t\ttx.pure.u64(clientOrderId),\n\t\t\t\ttx.pure.u8(selfMatchingOption),\n\t\t\t\ttx.pure.u64(inputQuantity),\n\t\t\t\ttx.pure.bool(isBid),\n\t\t\t\ttx.pure.bool(payWithDeep),\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 Modify an existing order\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {string} orderId Order ID to modify\n\t * @param {number} newQuantity New quantity for the order\n\t * @returns A function that takes a Transaction object\n\t */\n\tmodifyOrder =\n\t\t(marginManagerKey: string, orderId: string, newQuantity: number) => (tx: Transaction) => {\n\t\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\t\tconst pool = this.#config.getPool(marginManager.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 inputQuantity = convertQuantity(newQuantity, baseCoin.scalar);\n\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::modify_order`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(marginManager.address),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\ttx.pure.u128(orderId),\n\t\t\t\t\ttx.pure.u64(inputQuantity),\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 Cancel an existing order\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {string} orderId Order ID to cancel\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelOrder = (marginManagerKey: string, orderId: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::cancel_order`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.u128(orderId),\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 Cancel multiple existing orders\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {string[]} orderIds Order IDs to cancel\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelOrders = (marginManagerKey: string, orderIds: string[]) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::cancel_orders`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.vector('u128', orderIds),\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 Cancel all existing orders\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tcancelAllOrders = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::cancel_all_orders`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\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 Withdraw settled amounts\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawSettledAmounts = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::withdraw_settled_amounts`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Stake in the pool\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {number} stakeAmount The amount to stake\n\t * @returns A function that takes a Transaction object\n\t */\n\tstake = (marginManagerKey: string, stakeAmount: number) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.poolKey);\n\t\tconst baseCoin = this.#config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#config.getCoin(pool.quoteCoin);\n\t\tconst deepCoin = this.#config.getCoin('DEEP');\n\t\tconst stakeInput = convertQuantity(stakeAmount, deepCoin.scalar);\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::stake`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.u64(stakeInput),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Unstake from the pool\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tunstake = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::unstake`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Submit a proposal\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {MarginProposalParams} params Parameters for the proposal\n\t * @returns A function that takes a Transaction object\n\t */\n\tsubmitProposal =\n\t\t(marginManagerKey: string, params: MarginProposalParams) => (tx: Transaction) => {\n\t\t\tconst { takerFee, makerFee, stakeRequired } = params;\n\t\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\t\tconst pool = this.#config.getPool(marginManager.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 stakeInput = convertRate(stakeRequired, FLOAT_SCALAR);\n\t\t\tconst takerFeeInput = convertRate(takerFee, FLOAT_SCALAR);\n\t\t\tconst makerFeeInput = convertRate(makerFee, FLOAT_SCALAR);\n\t\t\ttx.moveCall({\n\t\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::submit_proposal`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(marginManager.address),\n\t\t\t\t\ttx.object(pool.address),\n\t\t\t\t\ttx.pure.u64(takerFeeInput),\n\t\t\t\t\ttx.pure.u64(makerFeeInput),\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 Vote on a proposal\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @param {string} proposalId The ID of the proposal to vote on\n\t * @returns A function that takes a Transaction object\n\t */\n\tvote = (marginManagerKey: string, proposalId: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::vote`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.pure.id(proposalId),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Claim a rebate from a pool\n\t * @param {string} marginManagerKey The key to identify the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\tclaimRebate = (marginManagerKey: string) => (tx: Transaction) => {\n\t\tconst marginManager = this.#config.getMarginManager(marginManagerKey);\n\t\tconst pool = this.#config.getPool(marginManager.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}::pool_proxy::claim_rebates`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(marginManager.address),\n\t\t\t\ttx.object(pool.address),\n\t\t\t],\n\t\t\ttypeArguments: [baseCoin.type, quoteCoin.type],\n\t\t});\n\t};\n\n\t/**\n\t * @description Withdraw settled amounts permissionlessly for a margin manager by ID\n\t * @param {string} poolKey The key to identify the pool\n\t * @param {string} marginManagerId The object ID of the MarginManager\n\t * @returns A function that takes a Transaction object\n\t */\n\twithdrawMarginSettledAmounts =\n\t\t(poolKey: string, marginManagerId: string) => (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}::pool_proxy::withdraw_settled_amounts_permissionless`,\n\t\t\t\targuments: [\n\t\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\t\ttx.object(marginManagerId),\n\t\t\t\t\ttx.object(pool.address),\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 Update the current price for a pool using Pyth oracle\n\t * @param {string} poolKey The key to identify the pool\n\t * @returns A function that takes a Transaction object\n\t */\n\tupdateCurrentPrice = (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\tif (!baseCoin.priceInfoObjectId) {\n\t\t\tthrow new Error(`Missing priceInfoObjectId for ${pool.baseCoin}`);\n\t\t}\n\t\tif (!quoteCoin.priceInfoObjectId) {\n\t\t\tthrow new Error(`Missing priceInfoObjectId for ${pool.quoteCoin}`);\n\t\t}\n\t\ttx.moveCall({\n\t\t\ttarget: `${this.#config.MARGIN_PACKAGE_ID}::pool_proxy::update_current_price`,\n\t\t\targuments: [\n\t\t\t\ttx.object(this.#config.MARGIN_REGISTRY_ID),\n\t\t\t\ttx.object(pool.address),\n\t\t\t\ttx.object(baseCoin.priceInfoObjectId),\n\t\t\t\ttx.object(quoteCoin.priceInfoObjectId),\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"],"mappings":";;;;;;;;AAiBA,IAAa,oBAAb,MAA+B;CAC9B;;;;CAKA,YAAY,QAAwB;0BAWjB,YAAyC,OAAoB;GAC/E,MAAM,EACL,SACA,kBACA,eACA,OACA,UACA,OACA,aAAa,eACb,YAAY,UAAU,gBACtB,qBAAqB,oBAAoB,uBACzC,cAAc,SACX;GACJ,MAAM,OAAO,MAAKA,OAAQ,QAAQ,QAAQ;GAC1C,MAAM,UAAU,MAAKA,OAAQ,iBAAiB,iBAAiB;GAC/D,MAAM,WAAW,MAAKA,OAAQ,QAAQ,KAAK,SAAS;GACpD,MAAM,YAAY,MAAKA,OAAQ,QAAQ,KAAK,UAAU;GACtD,MAAM,iBAAiB,MAAKA,OAAQ,cAAc,KAAK,SAAS;GAChE,MAAM,kBAAkB,MAAKA,OAAQ,cAAc,KAAK,UAAU;GAClE,MAAM,aAAa,aAAa,OAAO,cAAc,UAAU,QAAQ,SAAS,OAAO;GACvF,MAAM,gBAAgB,gBAAgB,UAAU,SAAS,OAAO;AAChE,UAAO,GAAG,SAAS;IAClB,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW;KACV,GAAG,OAAO,MA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M,IAAI,MAAM,iCAAiC,KAAK,YAAY;AAEnE,MAAG,SAAS;IACX,QAAQ,GAAG,MAAKA,OAAQ,kBAAkB;IAC1C,WAAW;KACV,GAAG,OAAO,MAAKA,OAAQ,mBAAmB;KAC1C,GAAG,OAAO,KAAK,QAAQ;KACvB,GAAG,OAAO,SAAS,kBAAkB;KACrC,GAAG,OAAO,UAAU,kBAAkB;KACtC,GAAG,OAAO,OAAO;KACjB;IACD,eAAe,CAAC,SAAS,MAAM,UAAU,KAAK;IAC9C,CAAC;;AAteF,QAAKA,SAAU"}
@@ -186,7 +186,7 @@ interface PoolConfigParams {
186
186
  interface MarginPoolConfigParams {
187
187
  supplyCap: number | bigint;
188
188
  maxUtilizationRate: number | bigint;
189
- referralSpread: number | bigint;
189
+ protocolSpread: number | bigint;
190
190
  minBorrow: number | bigint;
191
191
  rateLimitCapacity?: number | bigint;
192
192
  rateLimitRefillRatePerMs?: number | bigint;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { TransactionArgument, TransactionObjectArgument } from '@mysten/sui/transactions';\n\n// SPDX-License-Identifier: Apache-2.0\nexport interface BalanceManager {\n\taddress: string;\n\ttradeCap?: string;\n\tdepositCap?: string;\n\twithdrawCap?: string;\n}\n\nexport interface MarginManager {\n\taddress: string;\n\tpoolKey: string;\n}\n\nexport interface Coin {\n\taddress: string;\n\ttype: string;\n\tscalar: number;\n\tfeed?: string;\n\tcurrencyId?: string;\n\tpriceInfoObjectId?: string;\n}\n\nexport interface Pool {\n\taddress: string;\n\tbaseCoin: string;\n\tquoteCoin: string;\n}\n\nexport interface MarginPool {\n\taddress: string;\n\ttype: string;\n}\n\n// Trading constants\nexport enum OrderType {\n\tNO_RESTRICTION,\n\tIMMEDIATE_OR_CANCEL,\n\tFILL_OR_KILL,\n\tPOST_ONLY,\n}\n\n// Self matching options\nexport enum SelfMatchingOptions {\n\tSELF_MATCHING_ALLOWED,\n\tCANCEL_TAKER,\n\tCANCEL_MAKER,\n}\n\nexport interface PlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tprice: number | bigint;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface CanPlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tprice: number | bigint;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n\texpireTimestamp: number;\n}\n\nexport interface CanPlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n}\n\nexport interface PlaceMarginLimitOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tprice: number | bigint;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarginMarketOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PendingLimitOrderParams {\n\tclientOrderId: string;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tprice: number | bigint;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n\texpireTimestamp?: number | bigint;\n}\n\nexport interface PendingMarketOrderParams {\n\tclientOrderId: string;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n}\n\nexport interface AddConditionalOrderParams {\n\tmarginManagerKey: string;\n\tconditionalOrderId: string;\n\ttriggerBelowPrice: boolean;\n\ttriggerPrice: number | bigint;\n\tpendingOrder: PendingLimitOrderParams | PendingMarketOrderParams;\n}\n\nexport interface ProposalParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttakerFee: number | bigint;\n\tmakerFee: number | bigint;\n\tstakeRequired: number | bigint;\n}\n\nexport interface MarginProposalParams {\n\ttakerFee: number | bigint;\n\tmakerFee: number | bigint;\n\tstakeRequired: number | bigint;\n}\n\nexport interface SwapParams {\n\tpoolKey: string;\n\tamount: number | bigint;\n\tdeepAmount: number | bigint;\n\tminOut: number | bigint;\n\tdeepCoin?: TransactionObjectArgument;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface SwapWithManagerParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttradeCap: string;\n\tdepositCap: string;\n\twithdrawCap: string;\n\tamount: number | bigint;\n\tminOut: number | bigint;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface StakeParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tamount: number | bigint;\n}\n\nexport interface VoteParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tproposalId: string;\n}\n\nexport interface FlashLoanParams {\n\tpoolKey: string;\n\tamount: number | bigint;\n}\n\nexport interface CreatePoolAdminParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number | bigint;\n\tlotSize: number | bigint;\n\tminSize: number | bigint;\n\twhitelisted: boolean;\n\tstablePool: boolean;\n}\n\nexport interface CreatePermissionlessPoolParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number | bigint;\n\tlotSize: number | bigint;\n\tminSize: number | bigint;\n\tdeepCoin?: TransactionObjectArgument;\n}\n\nexport interface SetEwmaParams {\n\talpha: number | bigint;\n\tzScoreThreshold: number | bigint;\n\tadditionalTakerFee: number | bigint;\n}\n\nexport interface PoolConfigParams {\n\tminWithdrawRiskRatio: number | bigint;\n\tminBorrowRiskRatio: number | bigint;\n\tliquidationRiskRatio: number | bigint;\n\ttargetLiquidationRiskRatio: number | bigint;\n\tuserLiquidationReward: number | bigint;\n\tpoolLiquidationReward: number | bigint;\n}\n\nexport interface MarginPoolConfigParams {\n\tsupplyCap: number | bigint;\n\tmaxUtilizationRate: number | bigint;\n\treferralSpread: number | bigint;\n\tminBorrow: number | bigint;\n\trateLimitCapacity?: number | bigint;\n\trateLimitRefillRatePerMs?: number | bigint;\n\trateLimitEnabled?: boolean;\n}\n\nexport interface InterestConfigParams {\n\tbaseRate: number | bigint;\n\tbaseSlope: number | bigint;\n\toptimalUtilization: number | bigint;\n\texcessSlope: number | bigint;\n}\n\nexport interface Config {\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n}\n\n// === Named Return Types ===\n\n// Balance\nexport interface ManagerBalance {\n\tcoinType: string;\n\tbalance: number;\n}\nexport interface VaultBalances {\n\tbase: number;\n\tquote: number;\n\tdeep: number;\n}\nexport interface LockedBalances {\n\tbase: number;\n\tquote: number;\n\tdeep: number;\n}\nexport interface ReferralBalances {\n\tbase: number;\n\tquote: number;\n\tdeep: number;\n}\n\n// Pool\nexport interface PoolTradeParams {\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\nexport interface PoolBookParams {\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n}\nexport type PoolDeepPrice =\n\t| { asset_is_base: true; deep_per_base: number }\n\t| { asset_is_base: false; deep_per_quote: number };\n\n// Quantity calculations\nexport interface QuoteQuantityOut {\n\tbaseQuantity: number;\n\tbaseOut: number;\n\tquoteOut: number;\n\tdeepRequired: number;\n}\nexport interface BaseQuantityOut {\n\tquoteQuantity: number;\n\tbaseOut: number;\n\tquoteOut: number;\n\tdeepRequired: number;\n}\nexport interface QuantityOut {\n\tbaseQuantity: number;\n\tquoteQuantity: number;\n\tbaseOut: number;\n\tquoteOut: number;\n\tdeepRequired: number;\n}\nexport interface BaseQuantityIn {\n\tbaseIn: number;\n\tquoteOut: number;\n\tdeepRequired: number;\n}\nexport interface QuoteQuantityIn {\n\tbaseOut: number;\n\tquoteIn: number;\n\tdeepRequired: number;\n}\nexport interface OrderDeepRequiredResult {\n\tdeepRequiredTaker: number;\n\tdeepRequiredMaker: number;\n}\n\n// Order book\nexport interface Level2Range {\n\tprices: number[];\n\tquantities: number[];\n}\nexport interface Level2TicksFromMid {\n\tbid_prices: number[];\n\tbid_quantities: number[];\n\task_prices: number[];\n\task_quantities: number[];\n}\n\n// Account\nexport interface AccountBalances {\n\tbase: number;\n\tquote: number;\n\tdeep: number;\n}\nexport interface AccountInfo {\n\tepoch: string;\n\topen_orders: { contents: string[] };\n\ttaker_volume: number;\n\tmaker_volume: number;\n\tactive_stake: number;\n\tinactive_stake: number;\n\tcreated_proposal: boolean;\n\tvoted_proposal: string | null;\n\tunclaimed_rebates: AccountBalances;\n\tsettled_balances: AccountBalances;\n\towed_balances: AccountBalances;\n}\n\n// Order\nexport interface DecodedOrderId {\n\tisBid: boolean;\n\tprice: number;\n\torderId: number;\n}\n\n// Margin\nexport interface MarginManagerState {\n\tmanagerId: string;\n\tdeepbookPoolId: string;\n\triskRatio: number;\n\tbaseAsset: string;\n\tquoteAsset: string;\n\tbaseDebt: string;\n\tquoteDebt: string;\n\tbasePythPrice: string;\n\tbasePythDecimals: number;\n\tquotePythPrice: string;\n\tquotePythDecimals: number;\n\tcurrentPrice: bigint;\n\tlowestTriggerAbovePrice: bigint;\n\thighestTriggerBelowPrice: bigint;\n}\nexport interface MarginManagerAssets {\n\tbaseAsset: string;\n\tquoteAsset: string;\n}\nexport interface MarginManagerDebts {\n\tbaseDebt: string;\n\tquoteDebt: string;\n}\nexport interface MarginManagerBalancesResult {\n\tbase: string;\n\tquote: string;\n\tdeep: string;\n}\nexport interface BorrowedShares {\n\tbaseShares: string;\n\tquoteShares: string;\n}\n\n/**\n * Parameters for depositing into a margin manager.\n * Either `amount` (number) or `coin` (TransactionArgument) must be provided, but not both.\n */\nexport type DepositParams = {\n\tmanagerKey: string;\n} & ({ amount: number | bigint; coin?: never } | { amount?: never; coin: TransactionArgument });\n\n/**\n * Parameters for depositing during margin manager initialization.\n * Either (`coinType` + `amount`) or (`coinType` + `coin`) must be provided.\n * `coinType` should be a coin key from config (e.g., 'SUI', 'DBUSDC', 'DEEP').\n */\nexport type DepositDuringInitParams = {\n\tmanager: TransactionArgument;\n\tpoolKey: string;\n\tcoinType: string;\n} & ({ amount: number | bigint; coin?: never } | { amount?: never; coin: TransactionArgument });\n"],"mappings":";AAuCA,IAAY,kDAAL;AACN;AACA;AACA;AACA;;;AAID,IAAY,sEAAL;AACN;AACA;AACA"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { TransactionArgument, TransactionObjectArgument } from '@mysten/sui/transactions';\n\n// SPDX-License-Identifier: Apache-2.0\nexport interface BalanceManager {\n\taddress: string;\n\ttradeCap?: string;\n\tdepositCap?: string;\n\twithdrawCap?: string;\n}\n\nexport interface MarginManager {\n\taddress: string;\n\tpoolKey: string;\n}\n\nexport interface Coin {\n\taddress: string;\n\ttype: string;\n\tscalar: number;\n\tfeed?: string;\n\tcurrencyId?: string;\n\tpriceInfoObjectId?: string;\n}\n\nexport interface Pool {\n\taddress: string;\n\tbaseCoin: string;\n\tquoteCoin: string;\n}\n\nexport interface MarginPool {\n\taddress: string;\n\ttype: string;\n}\n\n// Trading constants\nexport enum OrderType {\n\tNO_RESTRICTION,\n\tIMMEDIATE_OR_CANCEL,\n\tFILL_OR_KILL,\n\tPOST_ONLY,\n}\n\n// Self matching options\nexport enum SelfMatchingOptions {\n\tSELF_MATCHING_ALLOWED,\n\tCANCEL_TAKER,\n\tCANCEL_MAKER,\n}\n\nexport interface PlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tprice: number | bigint;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface CanPlaceLimitOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tprice: number | bigint;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n\texpireTimestamp: number;\n}\n\nexport interface CanPlaceMarketOrderParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tpayWithDeep: boolean;\n}\n\nexport interface PlaceMarginLimitOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tprice: number | bigint;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\texpiration?: number | bigint;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PlaceMarginMarketOrderParams {\n\tpoolKey: string;\n\tmarginManagerKey: string;\n\tclientOrderId: string;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tpayWithDeep?: boolean;\n}\n\nexport interface PendingLimitOrderParams {\n\tclientOrderId: string;\n\torderType?: OrderType;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tprice: number | bigint;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n\texpireTimestamp?: number | bigint;\n}\n\nexport interface PendingMarketOrderParams {\n\tclientOrderId: string;\n\tselfMatchingOption?: SelfMatchingOptions;\n\tquantity: number | bigint;\n\tisBid: boolean;\n\tpayWithDeep?: boolean;\n}\n\nexport interface AddConditionalOrderParams {\n\tmarginManagerKey: string;\n\tconditionalOrderId: string;\n\ttriggerBelowPrice: boolean;\n\ttriggerPrice: number | bigint;\n\tpendingOrder: PendingLimitOrderParams | PendingMarketOrderParams;\n}\n\nexport interface ProposalParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttakerFee: number | bigint;\n\tmakerFee: number | bigint;\n\tstakeRequired: number | bigint;\n}\n\nexport interface MarginProposalParams {\n\ttakerFee: number | bigint;\n\tmakerFee: number | bigint;\n\tstakeRequired: number | bigint;\n}\n\nexport interface SwapParams {\n\tpoolKey: string;\n\tamount: number | bigint;\n\tdeepAmount: number | bigint;\n\tminOut: number | bigint;\n\tdeepCoin?: TransactionObjectArgument;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface SwapWithManagerParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\ttradeCap: string;\n\tdepositCap: string;\n\twithdrawCap: string;\n\tamount: number | bigint;\n\tminOut: number | bigint;\n\tbaseCoin?: TransactionObjectArgument;\n\tquoteCoin?: TransactionObjectArgument;\n}\n\nexport interface StakeParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tamount: number | bigint;\n}\n\nexport interface VoteParams {\n\tpoolKey: string;\n\tbalanceManagerKey: string;\n\tproposalId: string;\n}\n\nexport interface FlashLoanParams {\n\tpoolKey: string;\n\tamount: number | bigint;\n}\n\nexport interface CreatePoolAdminParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number | bigint;\n\tlotSize: number | bigint;\n\tminSize: number | bigint;\n\twhitelisted: boolean;\n\tstablePool: boolean;\n}\n\nexport interface CreatePermissionlessPoolParams {\n\tbaseCoinKey: string;\n\tquoteCoinKey: string;\n\ttickSize: number | bigint;\n\tlotSize: number | bigint;\n\tminSize: number | bigint;\n\tdeepCoin?: TransactionObjectArgument;\n}\n\nexport interface SetEwmaParams {\n\talpha: number | bigint;\n\tzScoreThreshold: number | bigint;\n\tadditionalTakerFee: number | bigint;\n}\n\nexport interface PoolConfigParams {\n\tminWithdrawRiskRatio: number | bigint;\n\tminBorrowRiskRatio: number | bigint;\n\tliquidationRiskRatio: number | bigint;\n\ttargetLiquidationRiskRatio: number | bigint;\n\tuserLiquidationReward: number | bigint;\n\tpoolLiquidationReward: number | bigint;\n}\n\nexport interface MarginPoolConfigParams {\n\tsupplyCap: number | bigint;\n\tmaxUtilizationRate: number | bigint;\n\tprotocolSpread: number | bigint;\n\tminBorrow: number | bigint;\n\trateLimitCapacity?: number | bigint;\n\trateLimitRefillRatePerMs?: number | bigint;\n\trateLimitEnabled?: boolean;\n}\n\nexport interface InterestConfigParams {\n\tbaseRate: number | bigint;\n\tbaseSlope: number | bigint;\n\toptimalUtilization: number | bigint;\n\texcessSlope: number | bigint;\n}\n\nexport interface Config {\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n}\n\n// === Named Return Types ===\n\n// Balance\nexport interface ManagerBalance {\n\tcoinType: string;\n\tbalance: number;\n}\nexport interface VaultBalances {\n\tbase: number;\n\tquote: number;\n\tdeep: number;\n}\nexport interface LockedBalances {\n\tbase: number;\n\tquote: number;\n\tdeep: number;\n}\nexport interface ReferralBalances {\n\tbase: number;\n\tquote: number;\n\tdeep: number;\n}\n\n// Pool\nexport interface PoolTradeParams {\n\ttakerFee: number;\n\tmakerFee: number;\n\tstakeRequired: number;\n}\nexport interface PoolBookParams {\n\ttickSize: number;\n\tlotSize: number;\n\tminSize: number;\n}\nexport type PoolDeepPrice =\n\t| { asset_is_base: true; deep_per_base: number }\n\t| { asset_is_base: false; deep_per_quote: number };\n\n// Quantity calculations\nexport interface QuoteQuantityOut {\n\tbaseQuantity: number;\n\tbaseOut: number;\n\tquoteOut: number;\n\tdeepRequired: number;\n}\nexport interface BaseQuantityOut {\n\tquoteQuantity: number;\n\tbaseOut: number;\n\tquoteOut: number;\n\tdeepRequired: number;\n}\nexport interface QuantityOut {\n\tbaseQuantity: number;\n\tquoteQuantity: number;\n\tbaseOut: number;\n\tquoteOut: number;\n\tdeepRequired: number;\n}\nexport interface BaseQuantityIn {\n\tbaseIn: number;\n\tquoteOut: number;\n\tdeepRequired: number;\n}\nexport interface QuoteQuantityIn {\n\tbaseOut: number;\n\tquoteIn: number;\n\tdeepRequired: number;\n}\nexport interface OrderDeepRequiredResult {\n\tdeepRequiredTaker: number;\n\tdeepRequiredMaker: number;\n}\n\n// Order book\nexport interface Level2Range {\n\tprices: number[];\n\tquantities: number[];\n}\nexport interface Level2TicksFromMid {\n\tbid_prices: number[];\n\tbid_quantities: number[];\n\task_prices: number[];\n\task_quantities: number[];\n}\n\n// Account\nexport interface AccountBalances {\n\tbase: number;\n\tquote: number;\n\tdeep: number;\n}\nexport interface AccountInfo {\n\tepoch: string;\n\topen_orders: { contents: string[] };\n\ttaker_volume: number;\n\tmaker_volume: number;\n\tactive_stake: number;\n\tinactive_stake: number;\n\tcreated_proposal: boolean;\n\tvoted_proposal: string | null;\n\tunclaimed_rebates: AccountBalances;\n\tsettled_balances: AccountBalances;\n\towed_balances: AccountBalances;\n}\n\n// Order\nexport interface DecodedOrderId {\n\tisBid: boolean;\n\tprice: number;\n\torderId: number;\n}\n\n// Margin\nexport interface MarginManagerState {\n\tmanagerId: string;\n\tdeepbookPoolId: string;\n\triskRatio: number;\n\tbaseAsset: string;\n\tquoteAsset: string;\n\tbaseDebt: string;\n\tquoteDebt: string;\n\tbasePythPrice: string;\n\tbasePythDecimals: number;\n\tquotePythPrice: string;\n\tquotePythDecimals: number;\n\tcurrentPrice: bigint;\n\tlowestTriggerAbovePrice: bigint;\n\thighestTriggerBelowPrice: bigint;\n}\nexport interface MarginManagerAssets {\n\tbaseAsset: string;\n\tquoteAsset: string;\n}\nexport interface MarginManagerDebts {\n\tbaseDebt: string;\n\tquoteDebt: string;\n}\nexport interface MarginManagerBalancesResult {\n\tbase: string;\n\tquote: string;\n\tdeep: string;\n}\nexport interface BorrowedShares {\n\tbaseShares: string;\n\tquoteShares: string;\n}\n\n/**\n * Parameters for depositing into a margin manager.\n * Either `amount` (number) or `coin` (TransactionArgument) must be provided, but not both.\n */\nexport type DepositParams = {\n\tmanagerKey: string;\n} & ({ amount: number | bigint; coin?: never } | { amount?: never; coin: TransactionArgument });\n\n/**\n * Parameters for depositing during margin manager initialization.\n * Either (`coinType` + `amount`) or (`coinType` + `coin`) must be provided.\n * `coinType` should be a coin key from config (e.g., 'SUI', 'DBUSDC', 'DEEP').\n */\nexport type DepositDuringInitParams = {\n\tmanager: TransactionArgument;\n\tpoolKey: string;\n\tcoinType: string;\n} & ({ amount: number | bigint; coin?: never } | { amount?: never; coin: TransactionArgument });\n"],"mappings":";AAuCA,IAAY,kDAAL;AACN;AACA;AACA;AACA;;;AAID,IAAY,sEAAL;AACN;AACA;AACA"}
@@ -28,6 +28,7 @@ declare class DeepBookConfig {
28
28
  REGISTRY_ID: string;
29
29
  DEEP_TREASURY_ID: string;
30
30
  MARGIN_PACKAGE_ID: string;
31
+ MARGIN_V1: string;
31
32
  MARGIN_REGISTRY_ID: string;
32
33
  LIQUIDATION_PACKAGE_ID: string;
33
34
  adminCap?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.mts","names":[],"sources":["../../src/utils/config.ts"],"mappings":";;;;;;cAuBa,YAAA;AAAA,cACA,WAAA;AAAA,cAGA,aAAA;AAAA,cACA,4BAAA;AAAA,cAGA,UAAA;AAAA,cACA,sBA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EAAA;EAIZ,OAAA,EAAS,cAAA,CAAe,OAAA;EACxB,eAAA;IAAA,CAAoB,GAAA,WAAc,cAAA;EAAA;EAClC,cAAA;IAAA,CAAmB,GAAA,WAAc,aAAA;EAAA;EACjC,OAAA;EACA,IAAA;IACC,WAAA;IACA,eAAA;EAAA;EAGD,mBAAA;EACA,WAAA;EACA,gBAAA;EACA,iBAAA;EACA,SAAA;EACA,kBAAA;EACA,sBAAA;EACA,QAAA;EACA,cAAA;EACA,mBAAA;EAEA,cAAA,EAAgB,sBAAA;;IAGf,OAAA;IACA,OAAA;IACA,QAAA;IACA,cAAA;IACA,mBAAA;IACA,eAAA;IACA,cAAA;IACA,KAAA;IACA,KAAA;IACA,WAAA;IACA,UAAA;IACA;EAAA;IAEA,OAAA,EAAS,cAAA,CAAe,OAAA;IACxB,OAAA;IACA,QAAA;IACA,cAAA;IACA,mBAAA;IACA,eAAA;MAAA,CAAqB,GAAA,WAAc,cAAA;IAAA;IACnC,cAAA;MAAA,CAAoB,GAAA,WAAc,aAAA;IAAA;IAClC,KAAA,GAAQ,OAAA;IACR,KAAA,GAAQ,OAAA;IACR,WAAA,GAAc,aAAA;IACd,UAAA,GAAa,kBAAA;IACb,IAAA;MAAS,WAAA;MAAqB,eAAA;IAAA;EAAA;EAuD/B,WAAA,CAAA;EASA,OAAA,CAAQ,GAAA,WAAc,IAAA;EAStB,OAAA,CAAQ,GAAA,WAAc,IAAA;EAStB,aAAA,CAAc,GAAA,WAAc,UAAA;EApFb;;;;;EAkGf,iBAAA,CAAkB,UAAA,WAAqB,cAAA;EAaD;;;;;EAAtC,gBAAA,CAAiB,UAAA,WAAqB,aAAA;AAAA"}
@@ -27,6 +27,7 @@ var DeepBookConfig = class {
27
27
  this.REGISTRY_ID = packageIds.REGISTRY_ID || "";
28
28
  this.DEEP_TREASURY_ID = packageIds.DEEP_TREASURY_ID || "";
29
29
  this.MARGIN_PACKAGE_ID = packageIds.MARGIN_PACKAGE_ID || "";
30
+ this.MARGIN_V1 = packageIds.MARGIN_V1 || "";
30
31
  this.MARGIN_REGISTRY_ID = packageIds.MARGIN_REGISTRY_ID || "";
31
32
  this.LIQUIDATION_PACKAGE_ID = packageIds.LIQUIDATION_PACKAGE_ID || "";
32
33
  this.#coins = coins || {};
@@ -44,6 +45,7 @@ var DeepBookConfig = class {
44
45
  this.REGISTRY_ID = mainnetPackageIds.REGISTRY_ID;
45
46
  this.DEEP_TREASURY_ID = mainnetPackageIds.DEEP_TREASURY_ID;
46
47
  this.MARGIN_PACKAGE_ID = mainnetPackageIds.MARGIN_PACKAGE_ID;
48
+ this.MARGIN_V1 = mainnetPackageIds.MARGIN_V1;
47
49
  this.MARGIN_REGISTRY_ID = mainnetPackageIds.MARGIN_REGISTRY_ID;
48
50
  this.LIQUIDATION_PACKAGE_ID = mainnetPackageIds.LIQUIDATION_PACKAGE_ID;
49
51
  this.pyth = mainnetPythConfigs;
@@ -55,6 +57,7 @@ var DeepBookConfig = class {
55
57
  this.REGISTRY_ID = testnetPackageIds.REGISTRY_ID;
56
58
  this.DEEP_TREASURY_ID = testnetPackageIds.DEEP_TREASURY_ID;
57
59
  this.MARGIN_PACKAGE_ID = testnetPackageIds.MARGIN_PACKAGE_ID;
60
+ this.MARGIN_V1 = testnetPackageIds.MARGIN_V1;
58
61
  this.MARGIN_REGISTRY_ID = testnetPackageIds.MARGIN_REGISTRY_ID;
59
62
  this.LIQUIDATION_PACKAGE_ID = testnetPackageIds.LIQUIDATION_PACKAGE_ID;
60
63
  this.pyth = testnetPythConfigs;
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","names":["#coins","#pools","#marginPools"],"sources":["../../src/utils/config.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { SuiClientTypes } from '@mysten/sui/client';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nimport { BalanceManagerContract } from '../transactions/balanceManager.js';\nimport type { BalanceManager, MarginManager, Coin, Pool, MarginPool } from '../types/index.js';\nimport type { CoinMap, PoolMap, MarginPoolMap, DeepbookPackageIds } from './constants.js';\nimport { ResourceNotFoundError, ConfigurationError, ErrorMessages } from './errors.js';\nimport {\n\tmainnetCoins,\n\tmainnetPackageIds,\n\tmainnetPools,\n\ttestnetCoins,\n\ttestnetPackageIds,\n\ttestnetPools,\n\tmainnetMarginPools,\n\ttestnetMarginPools,\n\tmainnetPythConfigs,\n\ttestnetPythConfigs,\n} from './constants.js';\n\n// Constants for numerical precision and scaling\nexport const FLOAT_SCALAR = 1_000_000_000; // 10^9 - Used for floating point representation\nexport const DEEP_SCALAR = 1_000_000; // 10^6 - DEEP token decimal places\n\n// Time-related constants\nexport const MAX_TIMESTAMP = 1_844_674_407_370_955_161n; // Maximum Unix timestamp (approximately year 2554)\nexport const PRICE_INFO_OBJECT_MAX_AGE_MS = 30_000; // 30 seconds in milliseconds\n\n// Transaction and fee constants\nexport const GAS_BUDGET = 250_000_000; // 0.25 SUI (0.5 * 500M MIST)\nexport const POOL_CREATION_FEE_DEEP = 500_000_000; // 500 DEEP tokens (500 * 10^6)\n\nexport class DeepBookConfig {\n\t#coins: CoinMap;\n\t#pools: PoolMap;\n\t#marginPools: MarginPoolMap;\n\tnetwork: SuiClientTypes.Network;\n\tbalanceManagers: { [key: string]: BalanceManager };\n\tmarginManagers: { [key: string]: MarginManager };\n\taddress: string;\n\tpyth: {\n\t\tpythStateId: string;\n\t\twormholeStateId: string;\n\t};\n\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n\tMARGIN_PACKAGE_ID: string;\n\tMARGIN_REGISTRY_ID: string;\n\tLIQUIDATION_PACKAGE_ID: string;\n\tadminCap?: string;\n\tmarginAdminCap?: string;\n\tmarginMaintainerCap?: string;\n\n\tbalanceManager: BalanceManagerContract;\n\n\tconstructor({\n\t\tnetwork,\n\t\taddress,\n\t\tadminCap,\n\t\tmarginAdminCap,\n\t\tmarginMaintainerCap,\n\t\tbalanceManagers,\n\t\tmarginManagers,\n\t\tcoins,\n\t\tpools,\n\t\tmarginPools,\n\t\tpackageIds,\n\t\tpyth,\n\t}: {\n\t\tnetwork: SuiClientTypes.Network;\n\t\taddress: string;\n\t\tadminCap?: string;\n\t\tmarginAdminCap?: string;\n\t\tmarginMaintainerCap?: string;\n\t\tbalanceManagers?: { [key: string]: BalanceManager };\n\t\tmarginManagers?: { [key: string]: MarginManager };\n\t\tcoins?: CoinMap;\n\t\tpools?: PoolMap;\n\t\tmarginPools?: MarginPoolMap;\n\t\tpackageIds?: DeepbookPackageIds;\n\t\tpyth?: { pythStateId: string; wormholeStateId: string };\n\t}) {\n\t\tthis.network = network;\n\t\tthis.address = normalizeSuiAddress(address);\n\t\tthis.adminCap = adminCap;\n\t\tthis.marginAdminCap = marginAdminCap;\n\t\tthis.marginMaintainerCap = marginMaintainerCap;\n\t\tthis.balanceManagers = balanceManagers || {};\n\t\tthis.marginManagers = marginManagers || {};\n\n\t\tif (packageIds) {\n\t\t\tthis.DEEPBOOK_PACKAGE_ID = packageIds.DEEPBOOK_PACKAGE_ID || '';\n\t\t\tthis.REGISTRY_ID = packageIds.REGISTRY_ID || '';\n\t\t\tthis.DEEP_TREASURY_ID = packageIds.DEEP_TREASURY_ID || '';\n\t\t\tthis.MARGIN_PACKAGE_ID = packageIds.MARGIN_PACKAGE_ID || '';\n\t\t\tthis.MARGIN_REGISTRY_ID = packageIds.MARGIN_REGISTRY_ID || '';\n\t\t\tthis.LIQUIDATION_PACKAGE_ID = packageIds.LIQUIDATION_PACKAGE_ID || '';\n\t\t\tthis.#coins = coins || {};\n\t\t\tthis.#pools = pools || {};\n\t\t\tthis.#marginPools = marginPools || {};\n\t\t\tthis.pyth = pyth || { pythStateId: '', wormholeStateId: '' };\n\t\t} else if (network === 'mainnet') {\n\t\t\tthis.#coins = coins || mainnetCoins;\n\t\t\tthis.#pools = pools || mainnetPools;\n\t\t\tthis.#marginPools = marginPools || mainnetMarginPools;\n\t\t\tthis.DEEPBOOK_PACKAGE_ID = mainnetPackageIds.DEEPBOOK_PACKAGE_ID;\n\t\t\tthis.REGISTRY_ID = mainnetPackageIds.REGISTRY_ID;\n\t\t\tthis.DEEP_TREASURY_ID = mainnetPackageIds.DEEP_TREASURY_ID;\n\t\t\tthis.MARGIN_PACKAGE_ID = mainnetPackageIds.MARGIN_PACKAGE_ID;\n\t\t\tthis.MARGIN_REGISTRY_ID = mainnetPackageIds.MARGIN_REGISTRY_ID;\n\t\t\tthis.LIQUIDATION_PACKAGE_ID = mainnetPackageIds.LIQUIDATION_PACKAGE_ID;\n\t\t\tthis.pyth = mainnetPythConfigs;\n\t\t} else if (network === 'testnet') {\n\t\t\tthis.#coins = coins || testnetCoins;\n\t\t\tthis.#pools = pools || testnetPools;\n\t\t\tthis.#marginPools = marginPools || testnetMarginPools;\n\t\t\tthis.DEEPBOOK_PACKAGE_ID = testnetPackageIds.DEEPBOOK_PACKAGE_ID;\n\t\t\tthis.REGISTRY_ID = testnetPackageIds.REGISTRY_ID;\n\t\t\tthis.DEEP_TREASURY_ID = testnetPackageIds.DEEP_TREASURY_ID;\n\t\t\tthis.MARGIN_PACKAGE_ID = testnetPackageIds.MARGIN_PACKAGE_ID;\n\t\t\tthis.MARGIN_REGISTRY_ID = testnetPackageIds.MARGIN_REGISTRY_ID;\n\t\t\tthis.LIQUIDATION_PACKAGE_ID = testnetPackageIds.LIQUIDATION_PACKAGE_ID;\n\t\t\tthis.pyth = testnetPythConfigs;\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Network '${network}' is not supported by default. Provide custom 'packageIds' for non-standard networks.`,\n\t\t\t);\n\t\t}\n\n\t\tthis.balanceManager = new BalanceManagerContract(this);\n\t}\n\n\trequirePyth() {\n\t\tif (!this.pyth.pythStateId || !this.pyth.wormholeStateId) {\n\t\t\tthrow new ConfigurationError(\n\t\t\t\t\"Pyth configuration is required for price feed operations. Provide 'pyth' when using custom packageIds.\",\n\t\t\t);\n\t\t}\n\t}\n\n\t// Getters\n\tgetCoin(key: string): Coin {\n\t\tconst coin = this.#coins[key];\n\t\tif (!coin) {\n\t\t\tthrow new ResourceNotFoundError('Coin', key);\n\t\t}\n\n\t\treturn coin;\n\t}\n\n\tgetPool(key: string): Pool {\n\t\tconst pool = this.#pools[key];\n\t\tif (!pool) {\n\t\t\tthrow new ResourceNotFoundError('Pool', key);\n\t\t}\n\n\t\treturn pool;\n\t}\n\n\tgetMarginPool(key: string): MarginPool {\n\t\tconst pool = this.#marginPools[key];\n\t\tif (!pool) {\n\t\t\tthrow new ResourceNotFoundError('Margin pool', key);\n\t\t}\n\n\t\treturn pool;\n\t}\n\n\t/**\n\t * @description Get the balance manager by key\n\t * @param managerKey Key of the balance manager\n\t * @returns The BalanceManager object\n\t */\n\tgetBalanceManager(managerKey: string): BalanceManager {\n\t\tif (!Object.hasOwn(this.balanceManagers, managerKey)) {\n\t\t\tthrow new Error(ErrorMessages.BALANCE_MANAGER_NOT_FOUND(managerKey));\n\t\t}\n\n\t\treturn this.balanceManagers[managerKey];\n\t}\n\n\t/**\n\t * @description Get the margin manager by key\n\t * @param managerKey Key of the margin manager\n\t * @returns The MarginManager object\n\t */\n\tgetMarginManager(managerKey: string): MarginManager {\n\t\tif (!Object.hasOwn(this.marginManagers, managerKey)) {\n\t\t\tthrow new Error(ErrorMessages.MARGIN_MANAGER_NOT_FOUND(managerKey));\n\t\t}\n\n\t\treturn this.marginManagers[managerKey];\n\t}\n}\n"],"mappings":";;;;;;AAuBA,MAAa,eAAe;AAC5B,MAAa,cAAc;AAG3B,MAAa,gBAAgB;AAC7B,MAAa,+BAA+B;AAG5C,MAAa,aAAa;AAC1B,MAAa,yBAAyB;AAEtC,IAAa,iBAAb,MAA4B;CAC3B;CACA;CACA;CAsBA,YAAY,EACX,SACA,SACA,UACA,gBACA,qBACA,iBACA,gBACA,OACA,OACA,aACA,YACA,QAcE;AACF,OAAK,UAAU;AACf,OAAK,UAAU,oBAAoB,QAAQ;A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AK,gBACxC,OAAM,IAAI,mBACT,yGACA;;CAKH,QAAQ,KAAmB;EAC1B,MAAM,OAAO,MAAKF,MAAO;AACzB,MAAI,CAAC,KACJ,OAAM,IAAI,sBAAsB,QAAQ,IAAI;AAG7C,SAAO;;CAGR,QAAQ,KAAmB;EAC1B,MAAM,OAAO,MAAKC,MAAO;AACzB,MAAI,CAAC,KACJ,OAAM,IAAI,sBAAsB,QAAQ,IAAI;AAG7C,SAAO;;CAGR,cAAc,KAAyB;EACtC,MAAM,OAAO,MAAKC,YAAa;AAC/B,MAAI,CAAC,KACJ,OAAM,IAAI,sBAAsB,eAAe,IAAI;AAGpD,SAAO;;;;;;;CAQR,kBAAkB,YAAoC;AACrD,MAAI,CAAC,OAAO,OAAO,KAAK,iBAAiB,WAAW,CACnD,OAAM,IAAI,MAAM,cAAc,0BAA0B,WAAW,CAAC;AAGrE,SAAO,KAAK,gBAAgB;;;;;;;CAQ7B,iBAAiB,YAAmC;AACnD,MAAI,CAAC,OAAO,OAAO,KAAK,gBAAgB,WAAW,CAClD,OAAM,IAAI,MAAM,cAAc,yBAAyB,WAAW,CAAC;AAGpE,SAAO,KAAK,eAAe"}
1
+ {"version":3,"file":"config.mjs","names":["#coins","#pools","#marginPools"],"sources":["../../src/utils/config.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { SuiClientTypes } from '@mysten/sui/client';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nimport { BalanceManagerContract } from '../transactions/balanceManager.js';\nimport type { BalanceManager, MarginManager, Coin, Pool, MarginPool } from '../types/index.js';\nimport type { CoinMap, PoolMap, MarginPoolMap, DeepbookPackageIds } from './constants.js';\nimport { ResourceNotFoundError, ConfigurationError, ErrorMessages } from './errors.js';\nimport {\n\tmainnetCoins,\n\tmainnetPackageIds,\n\tmainnetPools,\n\ttestnetCoins,\n\ttestnetPackageIds,\n\ttestnetPools,\n\tmainnetMarginPools,\n\ttestnetMarginPools,\n\tmainnetPythConfigs,\n\ttestnetPythConfigs,\n} from './constants.js';\n\n// Constants for numerical precision and scaling\nexport const FLOAT_SCALAR = 1_000_000_000; // 10^9 - Used for floating point representation\nexport const DEEP_SCALAR = 1_000_000; // 10^6 - DEEP token decimal places\n\n// Time-related constants\nexport const MAX_TIMESTAMP = 1_844_674_407_370_955_161n; // Maximum Unix timestamp (approximately year 2554)\nexport const PRICE_INFO_OBJECT_MAX_AGE_MS = 30_000; // 30 seconds in milliseconds\n\n// Transaction and fee constants\nexport const GAS_BUDGET = 250_000_000; // 0.25 SUI (0.5 * 500M MIST)\nexport const POOL_CREATION_FEE_DEEP = 500_000_000; // 500 DEEP tokens (500 * 10^6)\n\nexport class DeepBookConfig {\n\t#coins: CoinMap;\n\t#pools: PoolMap;\n\t#marginPools: MarginPoolMap;\n\tnetwork: SuiClientTypes.Network;\n\tbalanceManagers: { [key: string]: BalanceManager };\n\tmarginManagers: { [key: string]: MarginManager };\n\taddress: string;\n\tpyth: {\n\t\tpythStateId: string;\n\t\twormholeStateId: string;\n\t};\n\n\tDEEPBOOK_PACKAGE_ID: string;\n\tREGISTRY_ID: string;\n\tDEEP_TREASURY_ID: string;\n\tMARGIN_PACKAGE_ID: string;\n\tMARGIN_V1: string;\n\tMARGIN_REGISTRY_ID: string;\n\tLIQUIDATION_PACKAGE_ID: string;\n\tadminCap?: string;\n\tmarginAdminCap?: string;\n\tmarginMaintainerCap?: string;\n\n\tbalanceManager: BalanceManagerContract;\n\n\tconstructor({\n\t\tnetwork,\n\t\taddress,\n\t\tadminCap,\n\t\tmarginAdminCap,\n\t\tmarginMaintainerCap,\n\t\tbalanceManagers,\n\t\tmarginManagers,\n\t\tcoins,\n\t\tpools,\n\t\tmarginPools,\n\t\tpackageIds,\n\t\tpyth,\n\t}: {\n\t\tnetwork: SuiClientTypes.Network;\n\t\taddress: string;\n\t\tadminCap?: string;\n\t\tmarginAdminCap?: string;\n\t\tmarginMaintainerCap?: string;\n\t\tbalanceManagers?: { [key: string]: BalanceManager };\n\t\tmarginManagers?: { [key: string]: MarginManager };\n\t\tcoins?: CoinMap;\n\t\tpools?: PoolMap;\n\t\tmarginPools?: MarginPoolMap;\n\t\tpackageIds?: DeepbookPackageIds;\n\t\tpyth?: { pythStateId: string; wormholeStateId: string };\n\t}) {\n\t\tthis.network = network;\n\t\tthis.address = normalizeSuiAddress(address);\n\t\tthis.adminCap = adminCap;\n\t\tthis.marginAdminCap = marginAdminCap;\n\t\tthis.marginMaintainerCap = marginMaintainerCap;\n\t\tthis.balanceManagers = balanceManagers || {};\n\t\tthis.marginManagers = marginManagers || {};\n\n\t\tif (packageIds) {\n\t\t\tthis.DEEPBOOK_PACKAGE_ID = packageIds.DEEPBOOK_PACKAGE_ID || '';\n\t\t\tthis.REGISTRY_ID = packageIds.REGISTRY_ID || '';\n\t\t\tthis.DEEP_TREASURY_ID = packageIds.DEEP_TREASURY_ID || '';\n\t\t\tthis.MARGIN_PACKAGE_ID = packageIds.MARGIN_PACKAGE_ID || '';\n\t\t\tthis.MARGIN_V1 = packageIds.MARGIN_V1 || '';\n\t\t\tthis.MARGIN_REGISTRY_ID = packageIds.MARGIN_REGISTRY_ID || '';\n\t\t\tthis.LIQUIDATION_PACKAGE_ID = packageIds.LIQUIDATION_PACKAGE_ID || '';\n\t\t\tthis.#coins = coins || {};\n\t\t\tthis.#pools = pools || {};\n\t\t\tthis.#marginPools = marginPools || {};\n\t\t\tthis.pyth = pyth || { pythStateId: '', wormholeStateId: '' };\n\t\t} else if (network === 'mainnet') {\n\t\t\tthis.#coins = coins || mainnetCoins;\n\t\t\tthis.#pools = pools || mainnetPools;\n\t\t\tthis.#marginPools = marginPools || mainnetMarginPools;\n\t\t\tthis.DEEPBOOK_PACKAGE_ID = mainnetPackageIds.DEEPBOOK_PACKAGE_ID;\n\t\t\tthis.REGISTRY_ID = mainnetPackageIds.REGISTRY_ID;\n\t\t\tthis.DEEP_TREASURY_ID = mainnetPackageIds.DEEP_TREASURY_ID;\n\t\t\tthis.MARGIN_PACKAGE_ID = mainnetPackageIds.MARGIN_PACKAGE_ID;\n\t\t\tthis.MARGIN_V1 = mainnetPackageIds.MARGIN_V1;\n\t\t\tthis.MARGIN_REGISTRY_ID = mainnetPackageIds.MARGIN_REGISTRY_ID;\n\t\t\tthis.LIQUIDATION_PACKAGE_ID = mainnetPackageIds.LIQUIDATION_PACKAGE_ID;\n\t\t\tthis.pyth = mainnetPythConfigs;\n\t\t} else if (network === 'testnet') {\n\t\t\tthis.#coins = coins || testnetCoins;\n\t\t\tthis.#pools = pools || testnetPools;\n\t\t\tthis.#marginPools = marginPools || testnetMarginPools;\n\t\t\tthis.DEEPBOOK_PACKAGE_ID = testnetPackageIds.DEEPBOOK_PACKAGE_ID;\n\t\t\tthis.REGISTRY_ID = testnetPackageIds.REGISTRY_ID;\n\t\t\tthis.DEEP_TREASURY_ID = testnetPackageIds.DEEP_TREASURY_ID;\n\t\t\tthis.MARGIN_PACKAGE_ID = testnetPackageIds.MARGIN_PACKAGE_ID;\n\t\t\tthis.MARGIN_V1 = testnetPackageIds.MARGIN_V1;\n\t\t\tthis.MARGIN_REGISTRY_ID = testnetPackageIds.MARGIN_REGISTRY_ID;\n\t\t\tthis.LIQUIDATION_PACKAGE_ID = testnetPackageIds.LIQUIDATION_PACKAGE_ID;\n\t\t\tthis.pyth = testnetPythConfigs;\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Network '${network}' is not supported by default. Provide custom 'packageIds' for non-standard networks.`,\n\t\t\t);\n\t\t}\n\n\t\tthis.balanceManager = new BalanceManagerContract(this);\n\t}\n\n\trequirePyth() {\n\t\tif (!this.pyth.pythStateId || !this.pyth.wormholeStateId) {\n\t\t\tthrow new ConfigurationError(\n\t\t\t\t\"Pyth configuration is required for price feed operations. Provide 'pyth' when using custom packageIds.\",\n\t\t\t);\n\t\t}\n\t}\n\n\t// Getters\n\tgetCoin(key: string): Coin {\n\t\tconst coin = this.#coins[key];\n\t\tif (!coin) {\n\t\t\tthrow new ResourceNotFoundError('Coin', key);\n\t\t}\n\n\t\treturn coin;\n\t}\n\n\tgetPool(key: string): Pool {\n\t\tconst pool = this.#pools[key];\n\t\tif (!pool) {\n\t\t\tthrow new ResourceNotFoundError('Pool', key);\n\t\t}\n\n\t\treturn pool;\n\t}\n\n\tgetMarginPool(key: string): MarginPool {\n\t\tconst pool = this.#marginPools[key];\n\t\tif (!pool) {\n\t\t\tthrow new ResourceNotFoundError('Margin pool', key);\n\t\t}\n\n\t\treturn pool;\n\t}\n\n\t/**\n\t * @description Get the balance manager by key\n\t * @param managerKey Key of the balance manager\n\t * @returns The BalanceManager object\n\t */\n\tgetBalanceManager(managerKey: string): BalanceManager {\n\t\tif (!Object.hasOwn(this.balanceManagers, managerKey)) {\n\t\t\tthrow new Error(ErrorMessages.BALANCE_MANAGER_NOT_FOUND(managerKey));\n\t\t}\n\n\t\treturn this.balanceManagers[managerKey];\n\t}\n\n\t/**\n\t * @description Get the margin manager by key\n\t * @param managerKey Key of the margin manager\n\t * @returns The MarginManager object\n\t */\n\tgetMarginManager(managerKey: string): MarginManager {\n\t\tif (!Object.hasOwn(this.marginManagers, managerKey)) {\n\t\t\tthrow new Error(ErrorMessages.MARGIN_MANAGER_NOT_FOUND(managerKey));\n\t\t}\n\n\t\treturn this.marginManagers[managerKey];\n\t}\n}\n"],"mappings":";;;;;;AAuBA,MAAa,eAAe;AAC5B,MAAa,cAAc;AAG3B,MAAa,gBAAgB;AAC7B,MAAa,+BAA+B;AAG5C,MAAa,aAAa;AAC1B,MAAa,yBAAyB;AAEtC,IAAa,iBAAb,MAA4B;CAC3B;CACA;CACA;CAuBA,YAAY,EACX,SACA,SACA,UACA,gBACA,qBACA,iBACA,gBACA,OACA,OACA,aACA,YACA,QAcE;AACF,OAAK,UAAU;AACf,OAAK,UAAU,oBAAoB,QAAQ;AAC3C,OAAK,WAAW;AAChB,OAAK,iBAAiB;AACtB,OAAK,sBAAsB;AAC3B,OAAK,kBAAkB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,KAAK,gBACxC,OAAM,IAAI,mBACT,yGACA;;CAKH,QAAQ,KAAmB;EAC1B,MAAM,OAAO,MAAKF,MAAO;AACzB,MAAI,CAAC,KACJ,OAAM,IAAI,sBAAsB,QAAQ,IAAI;AAG7C,SAAO;;CAGR,QAAQ,KAAmB;EAC1B,MAAM,OAAO,MAAKC,MAAO;AACzB,MAAI,CAAC,KACJ,OAAM,IAAI,sBAAsB,QAAQ,IAAI;AAG7C,SAAO;;CAGR,cAAc,KAAyB;EACtC,MAAM,OAAO,MAAKC,YAAa;AAC/B,MAAI,CAAC,KACJ,OAAM,IAAI,sBAAsB,eAAe,IAAI;AAGpD,SAAO;;;;;;;CAQR,kBAAkB,YAAoC;AACrD,MAAI,CAAC,OAAO,OAAO,KAAK,iBAAiB,WAAW,CACnD,OAAM,IAAI,MAAM,cAAc,0BAA0B,WAAW,CAAC;AAGrE,SAAO,KAAK,gBAAgB;;;;;;;CAQ7B,iBAAiB,YAAmC;AACnD,MAAI,CAAC,OAAO,OAAO,KAAK,gBAAgB,WAAW,CAClD,OAAM,IAAI,MAAM,cAAc,yBAAyB,WAAW,CAAC;AAGpE,SAAO,KAAK,eAAe"}
@@ -9,6 +9,7 @@ interface DeepbookPackageIds {
9
9
  REGISTRY_ID?: string;
10
10
  DEEP_TREASURY_ID?: string;
11
11
  MARGIN_PACKAGE_ID?: string;
12
+ MARGIN_V1?: string;
12
13
  MARGIN_REGISTRY_ID?: string;
13
14
  LIQUIDATION_PACKAGE_ID?: string;
14
15
  }
@@ -17,6 +18,7 @@ declare const testnetPackageIds: {
17
18
  REGISTRY_ID: string;
18
19
  DEEP_TREASURY_ID: string;
19
20
  MARGIN_PACKAGE_ID: string;
21
+ MARGIN_V1: string;
20
22
  MARGIN_REGISTRY_ID: string;
21
23
  LIQUIDATION_PACKAGE_ID: string;
22
24
  };
@@ -25,6 +27,7 @@ declare const mainnetPackageIds: {
25
27
  REGISTRY_ID: string;
26
28
  DEEP_TREASURY_ID: string;
27
29
  MARGIN_PACKAGE_ID: string;
30
+ MARGIN_V1: string;
28
31
  MARGIN_REGISTRY_ID: string;
29
32
  LIQUIDATION_PACKAGE_ID: string;
30
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/utils/constants.ts"],"mappings":";;;KAKY,OAAA,GAAU,MAAA,SAAe,IAAA;AAAA,KACzB,OAAA,GAAU,MAAA,SAAe,IAAA;AAAA,KACzB,aAAA,GAAgB,MAAA,SAAe,UAAA;AAAA,UAC1B,kBAAA;EAChB,mBAAA;EACA,WAAA;EACA,gBAAA;EACA,iBAAA;EACA,kBAAA;EACA,sBAAA;AAAA;AAAA,cAGY,iBAAA;;;;;;;;cASA,iBAAA;;;;;;;;cASA,YAAA,EAAc,OAAA;AAAA,cA6Cd,YAAA,EAAc,OAAA;AAAA,cAiId,YAAA,EAAc,OAAA;AAAA,cAsCd,YAAA,EAAc,OAAA;AAAA,cA2Hd,kBAAA;;;;;;;;;;;;;;;;;;cAmBA,kBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+BA,kBAAA;EAGZ,WAAA;EAAA,eAAA;AAAA;AAAA,cAEY,kBAAA;EAGZ,WAAA;EAAA,eAAA;AAAA"}
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/utils/constants.ts"],"mappings":";;;KAKY,OAAA,GAAU,MAAA,SAAe,IAAA;AAAA,KACzB,OAAA,GAAU,MAAA,SAAe,IAAA;AAAA,KACzB,aAAA,GAAgB,MAAA,SAAe,UAAA;AAAA,UAC1B,kBAAA;EAChB,mBAAA;EACA,WAAA;EACA,gBAAA;EACA,iBAAA;EACA,SAAA;EACA,kBAAA;EACA,sBAAA;AAAA;AAAA,cAGY,iBAAA;;;;;;;;;cAUA,iBAAA;;;;;;;;;cAUA,YAAA,EAAc,OAAA;AAAA,cA6Cd,YAAA,EAAc,OAAA;AAAA,cAiId,YAAA,EAAc,OAAA;AAAA,cAsCd,YAAA,EAAc,OAAA;AAA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